uboot中如果有支援 spi/qspi flash, 就可以使用 sf 的 erase, read, write 等指令操作 spi flash
sf read: 讀取 flash資料到記憶體
sf write: 寫入記憶體資料到flash
sf erase:刪除指定位置,指定長度的 flash 内容, 刪除後内容全為 1
使用說明
sf probe [[bus:]cs] [hz] [mode] - init flash device on given SPI bus and chip select
sf read addr offset len - read 'len' bytes starting at 'offset' to memory at 'addr'
sf write addr offset len - write 'len' bytes from memor at 'addr' to flash at 'offset'
sf erase offset [+]len - erase 'len' bytes from 'offset' + 'len' round up 'len' to block size
sf update addr offset len - erase and write 'len' bytes from memory at 'addr' to flash at 'offset'
使用範例
sf probe
在使用sf read sf write之前,一定要先用sf probe
sf write 0x20000000 0x0 0x10
把記憶體中0x2000 0000的資料, 寫入flash的0x0, 寫入資料長度為0x10, (注意:flash的位置以及寫入長度度最單位位是Byte)
sf read 0x20000000 0x10000 0x10
把flash位置0x10000, 長度为0x10的資料, 寫入到記憶體0x20000000, (注意:flash的位置以及寫入長度度最單位是Byte)
sf erase 0x0 0x10000
刪除flash的0x0, 長度為0x10000的資料, 刪除是以erase block為單位, offset和len參數必須要跟erase block對齊的。
驗證讀寫結果
可以结合uboot md命令, 可以用md查看記憶體中的資料
md.l 0x20000000 0x10
印出記憶體位置0x20000000, 長度為0x10的資料
2018年1月26日 星期五
2017年12月28日 星期四
install vim-go(on Mac OSX)
install vim-go 的插件
編輯 .vimrc
# vim ~/.vimrc
在 vimrc 中加入下列三行後儲存離開
reference:
https://github.com/fatih/vim-go-tutorial
# curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
# git clone https://github.com/fatih/vim-go.git ~/.vim/plugged/vim-go
編輯 .vimrc
# vim ~/.vimrc
在 vimrc 中加入下列三行後儲存離開
call plug#begin() Plug 'fatih/vim-go', { 'do': ':GoInstallBinaries' } call plug#end()
最後再用 vim 去看 golang 的 code 就可以發現已經安裝好了
note: 注意 vim 的版本,若安裝失敗有可能是 vim 版本太舊請先更新
# brew upgrade vim
使用方式:
執行,直接在 vim 底下輸入“:GoRun“ 即可看到結果.
編譯,在 vim 底下輸入“:GoBuild”,若成功可以看到 “vim-go: [build] SUCCESS”
reference:
https://github.com/fatih/vim-go-tutorial
http://www.evanlin.com/switch-ide-to-vim/
http://fealonelei.github.io/2015/08/18/MAC-Vim-IDE-for-Go(lang).html
2017年12月13日 星期三
golang mkdir permission error
今天在Linux底下執行golang的os.Mkdir發生資料夾權限問題,透過ls -al去看才發現資料夾的權限跟我在os.Mkdir所設定的權限完全不一樣.後來發現建立資料夾時除了需要指定權限外,也需要加上系統的Umask.
原code:
原code:
package mainimport ("fmt""os")func main() {err := os.MkdirAll("gotest/", 0777)if err != nil {panic(err)}}
修正後:
package mainimport ("fmt""os""syscall")func main() {mask := syscall.Umask(0)defer syscall.Umask(mask)err := os.MkdirAll("gotest/", 0777)if err != nil {panic(err)}}
2017年11月16日 星期四
設定CentOS時間與NTP伺服器時間同步
將系統與NTP 的伺服器同步
設定步驟
1.以root 的身分登入
2. 執行下面的指令安裝NTP
# yum install ntp
3. 啟動服務
#chkconfig ntpd on
4. 設定系統和 time.stdtime.gov.tw 同步 (以time.stdtime.gov.tw為例)
#ntpdate time.stdtime.gov.tw
5.啟動ntp
# service ntpd start
6.可以執行下面的指令確定目前系統的時間
#date
Visual Studio 2017 建立 DLL(Dynamic Linking Library)
以 VS2017 為例
1.檔案 -> 新增 -> 專案
2.已安裝 -> Visual C++ -> Windows Desktop -> Windows 傳統式精靈
3. 應用程式類型 -> 動態連結程式庫(.dll) -> 空白專案
4. 在專案中加入 .cpp 與 .h 檔
5.在 (.h)檔 中加入以下程式碼
#pragma once
__declspec(dllexport) int myadd(int a, int b);
6.在 (.cpp) 檔 中加入以下程式碼
#include "ProjectDll.h"
int myadd(int a, int b) {
return a + b;
}
7. 建制 -> 重建方案 後即可產生 DLL 檔
1.檔案 -> 新增 -> 專案 -> 已安裝 -> Visual C++ -> Windows Desktop -> Windows 傳統式精靈 -> 主控台應用程式
2.先在專案的屬性(property) --> C/C++ --> 一般 (general) -->其他Include目錄
將剛剛編譯的DLL的(.h)檔的位置include進來
3.在連結器(linking) --> 一般(general) --> 其他程式庫目錄
這邊將你剛剛編譯的DLL的(.lib)檔的路徑加進來
4.在連結器(linking) --> 輸入(input) -->其它相依性(additional dependencies)
輸入剛剛編譯的DLL(.lib)檔的名字
5.程式中include你的DLL的(.h)檔即可呼叫DLL中的方法來使用了
#include "xxx.h"
6.compiler完,記得將你剛剛編譯的DLL檔放在你的EXE檔的同一個資料夾中
1.檔案 -> 新增 -> 專案
2.已安裝 -> Visual C++ -> Windows Desktop -> Windows 傳統式精靈
3. 應用程式類型 -> 動態連結程式庫(.dll) -> 空白專案
4. 在專案中加入 .cpp 與 .h 檔
5.在 (.h)檔 中加入以下程式碼
#pragma once
__declspec(dllexport) int myadd(int a, int b);
6.在 (.cpp) 檔 中加入以下程式碼
#include "ProjectDll.h"
int myadd(int a, int b) {
return a + b;
}
7. 建制 -> 重建方案 後即可產生 DLL 檔
呼叫剛剛建置的DLL
2.先在專案的屬性(property) --> C/C++ --> 一般 (general) -->其他Include目錄
將剛剛編譯的DLL的(.h)檔的位置include進來
3.在連結器(linking) --> 一般(general) --> 其他程式庫目錄
這邊將你剛剛編譯的DLL的(.lib)檔的路徑加進來
4.在連結器(linking) --> 輸入(input) -->其它相依性(additional dependencies)
輸入剛剛編譯的DLL(.lib)檔的名字
5.程式中include你的DLL的(.h)檔即可呼叫DLL中的方法來使用了
#include "xxx.h"
2017年11月1日 星期三
GUI applications entirely in Golang(not finish)
golang GUI,隨手筆記
稍微做了點資料搜集,下方列出三種目前找到的第三方套件,目前看來QT對於各個平台支援較為齊全.
但也有人主推HTML5,沒有跨平台的問題.
QT:
https://github.com/therecipe/qt#linux-1
支援平台
Target Arch. Host OS
----------------------------------------------------------
windows. (32 / 64) Any
android(+Wear) arm Any
Linux 64 Any
macOS 64 macOS
iOS (arm + arm64) macOS
Raspberry Pi arm Any
Awesome:
https://awesome-go.com
QML:
https://github.com/go-qml/qml
HTML5:
透過http, websocket 等方式跟go溝通
稍微做了點資料搜集,下方列出三種目前找到的第三方套件,目前看來QT對於各個平台支援較為齊全.
但也有人主推HTML5,沒有跨平台的問題.
QT:
https://github.com/therecipe/qt#linux-1
支援平台
Target Arch. Host OS
----------------------------------------------------------
windows. (32 / 64) Any
android(+Wear) arm Any
Linux 64 Any
macOS 64 macOS
iOS (arm + arm64) macOS
Raspberry Pi arm Any
Awesome:
https://awesome-go.com
QML:
https://github.com/go-qml/qml
HTML5:
透過http, websocket 等方式跟go溝通
2017年6月2日 星期五
調整 vim 設定
編輯 ~/.vimrc 這個檔案(若沒有請自行新增)
在檔案中加入所需要的設定
背景 (預設 set bg=light)
set bg=dark
只在 Normal 以及 Visual 模式使用滑鼠,也就是取消 Insert 模式的滑鼠
set mouse=nv
顯示行號
set number
搜尋不分大小寫
set ic
使用空白取代 Tab
set expandtab
自訂縮排 (Tab) 位元數
set tabstop=2
set shiftwidth=2
字數過長時換行
set wrap
不換行
set nowrap
高亮當前行 (水平)
set cursorline
捲動時保留底下 3 行
set scrolloff=3
儲存後退出即可
更多詳細介紹請看:
http://note.drx.tw/2008/01/vimrc-config.html
如要套用別人的 Color Scheme 可以參考
https://blog.longwin.com.tw/2009/03/choose-vim-color-scheme-2009/
在檔案中加入所需要的設定
背景 (預設 set bg=light)
set bg=dark
只在 Normal 以及 Visual 模式使用滑鼠,也就是取消 Insert 模式的滑鼠
set mouse=nv
顯示行號
set number
搜尋不分大小寫
set ic
使用空白取代 Tab
set expandtab
自訂縮排 (Tab) 位元數
set tabstop=2
set shiftwidth=2
字數過長時換行
set wrap
不換行
set nowrap
高亮當前行 (水平)
set cursorline
捲動時保留底下 3 行
set scrolloff=3
儲存後退出即可
更多詳細介紹請看:
http://note.drx.tw/2008/01/vimrc-config.html
如要套用別人的 Color Scheme 可以參考
https://blog.longwin.com.tw/2009/03/choose-vim-color-scheme-2009/
訂閱:
文章 (Atom)

