一般来说, 更新bootloader 推荐直接在bootloader中更新, 这种方法请参考我们不同板子对应镜像的更新方法.

如果需要在linux下更新bootloader, 可参考以下方法对bootloader进行更新, 以下以phycore-am335x 核心板为例说明.

在linux下查看分区信息

root@phycore-am335x-1:~# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00020000 00010000 "xload"
mtd1: 00080000 00010000 "barebox"
mtd2: 00020000 00010000 "bareboxenv"
mtd3: 00020000 00010000 "oftree"
mtd4: 00720000 00010000 "kernel"
mtd5: 00020000 00020000 "xload"
mtd6: 00020000 00020000 "xload_backup1"
mtd7: 00020000 00020000 "xload_backup2"
mtd8: 00020000 00020000 "xload_backup3"
mtd9: 00080000 00020000 "barebox"
mtd10: 00080000 00020000 "barebox_backup"
mtd11: 00040000 00020000 "bareboxenv"
mtd12: 1fe40000 00020000 "root"


root@phycore-am335x-1:~# mtdinfo /dev/mtd0
mtd0
Name:                           xload
Type:                           nor
Eraseblock size:                65536 bytes, 64.0 KiB
Amount of eraseblocks:          2 (131072 bytes, 128.0 KiB)
Minimum input/output unit size: 1 byte
Sub-page size:                  1 byte
Character device major/minor:   90:0
Bad blocks are allowed:         false
Device is writable:             true

root@phycore-am335x-1:~# mtdinfo /dev/mtd1
mtd1
Name:                           barebox
Type:                           nor
Eraseblock size:                65536 bytes, 64.0 KiB
Amount of eraseblocks:          8 (524288 bytes, 512.0 KiB)
Minimum input/output unit size: 1 byte
Sub-page size:                  1 byte
Character device major/minor:   90:2
Bad blocks are allowed:         false
Device is writable:             true

root@phycore-am335x-1:~# mtdinfo /dev/mtd2
mtd2
Name:                           bareboxenv
Type:                           nor
Eraseblock size:                65536 bytes, 64.0 KiB
Amount of eraseblocks:          2 (131072 bytes, 128.0 KiB)
Minimum input/output unit size: 1 byte
Sub-page size:                  1 byte
Character device major/minor:   90:4
Bad blocks are allowed:         false
Device is writable:             true

root@phycore-am335x-1:~# mtdinfo /dev/mtd5
mtd5
Name:                           xload
Type:                           nand
Eraseblock size:                131072 bytes, 128.0 KiB
Amount of eraseblocks:          1 (131072 bytes, 128.0 KiB)
Minimum input/output unit size: 2048 bytes
Sub-page size:                  512 bytes
OOB size:                       64 bytes
Character device major/minor:   90:10
Bad blocks are allowed:         true
Device is writable:             true

root@phycore-am335x-1:~# mtdinfo /dev/mtd6
mtd6
Name:                           xload_backup1
Type:                           nand
Eraseblock size:                131072 bytes, 128.0 KiB
Amount of eraseblocks:          1 (131072 bytes, 128.0 KiB)
Minimum input/output unit size: 2048 bytes
Sub-page size:                  512 bytes
OOB size:                       64 bytes
Character device major/minor:   90:12
Bad blocks are allowed:         true
Device is writable:             true

root@phycore-am335x-1:~# mtdinfo /dev/mtd7
mtd7
Name:                           xload_backup2
Type:                           nand
Eraseblock size:                131072 bytes, 128.0 KiB
Amount of eraseblocks:          1 (131072 bytes, 128.0 KiB)
Minimum input/output unit size: 2048 bytes
Sub-page size:                  512 bytes
OOB size:                       64 bytes
Character device major/minor:   90:14
Bad blocks are allowed:         true
Device is writable:             true

root@phycore-am335x-1:~# mtdinfo /dev/mtd8
mtd8
Name:                           xload_backup3
Type:                           nand
Eraseblock size:                131072 bytes, 128.0 KiB
Amount of eraseblocks:          1 (131072 bytes, 128.0 KiB)
Minimum input/output unit size: 2048 bytes
Sub-page size:                  512 bytes
OOB size:                       64 bytes
Character device major/minor:   90:16
Bad blocks are allowed:         true
Device is writable:             true

root@phycore-am335x-1:~# mtdinfo /dev/mtd9
mtd9
Name:                           barebox
Type:                           nand
Eraseblock size:                131072 bytes, 128.0 KiB
Amount of eraseblocks:          4 (524288 bytes, 512.0 KiB)
Minimum input/output unit size: 2048 bytes
Sub-page size:                  512 bytes
OOB size:                       64 bytes
Character device major/minor:   90:18
Bad blocks are allowed:         true
Device is writable:             true

root@phycore-am335x-1:~# mtdinfo /dev/mtd10
mtd10
Name:                           barebox_backup
Type:                           nand
Eraseblock size:                131072 bytes, 128.0 KiB
Amount of eraseblocks:          4 (524288 bytes, 512.0 KiB)
Minimum input/output unit size: 2048 bytes
Sub-page size:                  512 bytes
OOB size:                       64 bytes
Character device major/minor:   90:20
Bad blocks are allowed:         true
Device is writable:             true

root@phycore-am335x-1:~# mtdinfo /dev/mtd11
mtd11
Name:                           bareboxenv
Type:                           nand
Eraseblock size:                131072 bytes, 128.0 KiB
Amount of eraseblocks:          2 (262144 bytes, 256.0 KiB)
Minimum input/output unit size: 2048 bytes
Sub-page size:                  512 bytes
OOB size:                       64 bytes
Character device major/minor:   90:22
Bad blocks are allowed:         true
Device is writable:             true

从上面mtd信息看出mtd0~mtd2 是nor flash的bootloader的分区, 而mtd5~mtd11是nand flash的bootloader分区.

在linux下更新nand flash的bootloader

更新nand的分区时, 需要先使用flash_eraseall 擦除分区内容, 在使用nandwrite命令写入nand分区.

更新nand flash的MLO

从mtdinfo可看出mtd5~mtd8都是mlo分区, 都需要更新

root@phycore-am335x-1:~# flash_eraseall /dev/mtd5
flash_eraseall has been replaced by `flash_erase <mtddev> 0 0`; please use it
Erasing 128 Kibyte @ 6400000000 -- -1 % complete 
root@phycore-am335x-1:~# flash_eraseall /dev/mtd6
flash_eraseall has been replaced by `flash_erase <mtddev> 0 0`; please use it
Erasing 128 Kibyte @ 6400000000 -- -1 % complete 
root@phycore-am335x-1:~# flash_eraseall /dev/mtd7
flash_eraseall has been replaced by `flash_erase <mtddev> 0 0`; please use it
Erasing 128 Kibyte @ 6400000000 -- -1 % complete 
root@phycore-am335x-1:~# flash_eraseall /dev/mtd8
flash_eraseall has been replaced by `flash_erase <mtddev> 0 0`; please use it
Erasing 128 Kibyte @ 6400000000 -- -1 % complete
root@phycore-am335x-1:~# nandwrite -p /dev/mtd5 MLO
Writing data to block 0 at offset 0x0
root@phycore-am335x-1:~# nandwrite -p /dev/mtd6 MLO                                                                                                                                           
Writing data to block 0 at offset 0x0
root@phycore-am335x-1:~# nandwrite -p /dev/mtd7 MLO                                                                                                                                           
Writing data to block 0 at offset 0x0
root@phycore-am335x-1:~# nandwrite -p /dev/mtd8 MLO                                                                                                                                           
Writing data to block 0 at offset 0x0

更新nand flash的barebox

mtd9~mtd10是nand的barebox分区

root@phycore-am335x-1:~# flash_eraseall /dev/mtd9
flash_eraseall has been replaced by `flash_erase <mtddev> 0 0`; please use it
Erasing 128 Kibyte @ 6400060000 -- -1 % complete 
root@phycore-am335x-1:~# flash_eraseall /dev/mtd10
flash_eraseall has been replaced by `flash_erase <mtddev> 0 0`; please use it
Erasing 128 Kibyte @ 6400060000 -- -1 % complete 
root@phycore-am335x-1:~# nandwrite -p /dev/mtd9 barebox.bin 
Writing data to block 0 at offset 0x0
Writing data to block 1 at offset 0x20000
Writing data to block 2 at offset 0x40000
Writing data to block 3 at offset 0x60000
root@phycore-am335x-1:~# nandwrite -p /dev/mtd10 barebox.bin                                                                                                                                  
Writing data to block 0 at offset 0x0
Writing data to block 1 at offset 0x20000
Writing data to block 2 at offset 0x40000
Writing data to block 3 at offset 0x60000

更新nand flash的barebox环境

mtd11 是nand的bareboxenv分区, 更新mlo和barebox后, 需要擦除原来的环境, barebox的环境才会更新.

root@phycore-am335x-1:~# flash_eraseall /dev/mtd11
flash_eraseall has been replaced by `flash_erase <mtddev> 0 0`; please use it
Erasing 128 Kibyte @ 6400020000 -- -1 % complete

经过以上操作后,重启开发板后nand的mlo和barebox都会更新.

在linux下更新nor flash的bootloader

擦除 nor flash 分区 使用flase_eraseall 命令, 写nor flash 分区使用 flashcp 命令.

更新nor flash的mlo

在am335x bsp 手册中, 更新spi nor flash 章节中 https://www.phytec.de/documents/l-818e-4-am335x-bsp-manual/#Updating_SPI_NOR_Flash_from_Network 

有以下注意事项

Note: When booting from SPI Flash the AM335x expects the MLO in a big endian format. The barebox_update command with the MLO.spi type, takes the MLO image and converts it on the fly to the correct format and flashes it to SPI. If you can not use the barebox_update command you can take directly the MLO.spi file which also drops out of the image build.

在linux 上更新 nor flash 的 mlo 时, 需要使用正确的MLO.spi 镜像文件,

MLO.spi 文件编译方法可参考 :  https://wiki.phytec.com/pages/viewpage.action?pageId=69501808#barebox使用教程-为am335x平台编译MLO.spi文件

mtd0 是 nor flash 的mlo 分区

root@phycore-am335x-1:~# flash_eraseall /dev/mtd0
flash_eraseall has been replaced by `flash_erase <mtddev> 0 0`; please use it
Erasing 64 Kibyte @ 6400010000 -- -1 % complete 
root@phycore-am335x-1:~# flashcp MLO.spi /dev/mtd0

更新nor flash的barebox

mtd1是nor flash的 barebox 分区

root@phycore-am335x-1:~# flash_eraseall /dev/mtd1
flash_eraseall has been replaced by `flash_erase <mtddev> 0 0`; please use it
Erasing 64 Kibyte @ 6400070000 -- -1 % complete 
root@phycore-am335x-1:~# flashcp barebox.bin /dev/mtd1

更新 nor flash 的 barebox环境

mtd2是nor flash的 bareboxenv 分区

root@phycore-am335x-1:~# flash_eraseall /dev/mtd2
flash_eraseall has been replaced by `flash_erase <mtddev> 0 0`; please use it
Erasing 64 Kibyte @ 6400010000 -- -1 % complete

经过以上操作之后, 重启之后nor flash 的barebox 和 mlo 都会更新了.

  • No labels