由於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