Linux utilities

在Linux底下讀取 SPI flash 資料

由於Bootloader 相關參數是放在SPI flash中, 有時需要在Linux存取相關參數.
以往我都是直接read/write /dev/mtdblock, 但是後來發現原來有現成套件可以輕鬆讀寫mtdblock

1. 安裝套件 (主要需要 fw_printenv以及 fw_setenv 這兩支binary)

apt-get install u-boot-tools

2. 檢查系統mtd size

cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00080000 00010000 "MLO"
mtd1: 00100000 00010000 "U-Boot"
mtd2: 00020000 00010000 "U-Boot Env"

3. 根據上述 mtd size填寫設定檔

vi /etc/fw_env.config

# MTD device name       Device offset   Env. size       Flash sector size Number of sectors
/dev/mtd2               0x0000  0x20000 0x010000

4. 執行 fw_printenv 讀取資料

root@szlin:~ fw_printenv
baudrate=115200
bootdelay=1
...

4. 執行 fw_printenv 寫入資料

root@szlin:~ fw_setenv bootdelay 2
End of range reached, aborting
Error: can't write fw_env to flash

寫入失敗 查了一下, 發現是fw_setenv的bug.
https://github.com/boundarydevices/u-boot-imx6/commit/4b774ff

從Debian抓source code回來patch 後, 即可寫入資料!

root@szlin:~ fw_setenv bootdelay 2
root@szlin:~ fw_printenv
baudrate=115200
bootdelay=2

成功讀寫SPI flash

ref:
http://processors.wiki.ti.com/index.php/Update_U-Boot_Environment_Variables_stored_in_SPI_Flash_from_Linux

廣告

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com 標誌

您的留言將使用 WordPress.com 帳號。 登出 /  變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 /  變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 /  變更 )

連結到 %s