update image on the board for uboot

本文介绍如何在线更新嵌入式系统的U-Boot及Linux内核,包括使用TFTP协议下载镜像到内存,利用USB设备加载镜像,以及更新flash上的固件等方法。

  Updating image on the board

本章节主要讨论如何更新flash上的image,包括uboot和linux。当然,前提条件是不将flash取出,而是在线刷写flash。刷写的方式有多种,包括通过tftp协议将镜像从ftp server上download到板子上;使用fatload指令从fat格式的接口device中加载到内存上; 或者使用console 的kermit 协议传输文件到板子内存中。

 

 

4.1 Update u-bootusing console

 

u-boot提供命令接口loadb让用户使用console协议来传输image到板子内存中。需要用户连接的主机支持kermit传输协议,比如超级终端是默认支持的。更新过程步骤如下:

 

Step 1: Use kermit protocolto transmit file into the targetsystem.

 

uBoot> loadb

 

use Kermit protocol transmit file.

 

## Total Size = 0x0003b8a0 = 243872 Bytes

 

## Start Addr  = 0x00100000

 

Step 2: Update bootcode by command run bootloader_flash_updateor bootloaderupdate

 

uBoot> run bootloader_flash_update

 

Un-Protected   5 sectors

..... done

Erased  5 sectors

 

Copy to Flash...4....3....2....1....done.

 

 

当所有的步骤完成之后,显示update done,则可以使用reset指令来完成重启系统。


4.2 Update u-boot using TFTP

 

u-boot中另外还提供一种更新flash的途径:tftp协议。一般情况下还是推荐使用这种方式,应为这种方式是所有途径中传输速率最快。

在download image之前,必须保证TFTP server已经准备好,可以正常工作了。在linux下可以使用重定向到ftp来实现ftp服务器传输。Windows下推荐使用工具tftpd32.exe来完成ftp server的建立。最后两端的ip必须设置清晰,比如默认情况下,板端IP为192.168.1.1. 而server端IP为192.168.1.100 。在uboot每次启动之后,默认在uboot下工作的是ethact=octmgmt0,所以在使用其他LAN接口的时候,请用setenv调整工作lan。比如:

 

command                                                                  meaning

 

setenv  ipaddr <ip>                                               Set device IP.

 

setenv  serverip  <ip>                                           Set TFTP server IP.

 

setenv  ethact  <interface>                                  Set network interface, octmgmt0 is manage

port, octeth0-3 is LAN  fromSGMII0.

octeth4-7  from GMII1

 

saveenv                                                                  Save settings to ENV area.

 

同样,更新flash的步骤也是两个:

 

Step 1: Using tftpboot command to download bootloader image to memory

 

uBoot> tftpboot $(loadaddr)   u-boot.bin

 

Using octeth0 device

 

TFTP from server192.168.1.100; our IP address is 192.168.1.1

 

Filename  ’u-boot.bin’. Load address: 0x20000000

Loading:  ##########  done

 

Bytes transferred   = 388256 (5eca0 hex), 12230 Kbytes/sec

 

 

Step 2: Update bootcode by command run bootloader_flash_updateor bootloaderupdate

 

uBoot> run bootloader_flash_update

 

Un-Protected   3 sectors

... done

 

Erased  3 sectors

 

Copy to Flash...4....3....2....1....done

Un-Protected   1 sectors

 

. done

 

Erased  1 sectors

 

当所有的步骤完成之后,显示update done,则可以使用reset指令来完成重启系统。


4.3 Update BSP image using TFTP

 

针对Linux kernel的update,可以参考u-boot image更新的方式来实现。当然这种方式只使用与Linux系统存放在flash的情况下。有些时候flash有可能是放入CF卡或者u盘中的。

 

command                                                                  meaning

 

setenv  ipaddr <ip>                                             Set device IP.

 

setenv  serverip  <ip>                                         Set TFTP server IP.

 

setenv  ethact  <interface>                                Set network interface, octmgmt0 is manage

port, octeth0-3 is LAN  fromSGMII0.

octeth4-7  fromGMII1

 

saveenv                                                                  Save settings to ENV area.

 

 

同样,更新flash的步骤也是两个:

 

Step 1: Using tftpboot command to download BSP image to memory

 

uBoot> tftpboot $(loadaddr)   vmlinux.64

 

Using octeth0 device

 

TFTP from server192.168.1.100; our IP address is 192.168.1.1

 

Filename  ’vmlinux.64’. Load address: 0x20000000

Loading:  ########################

 

done

 

Bytes transferred   = 388256 (5eca0 hex), 12230 Kbytes/sec

 

 

Step 2: Update BSPimage by command run linux_update

 

uBoot> run linux_update

 

Un-Protected  192 sectors

  

................................................ Erased  192 sectors

Copy to Flash...4....3....2....1....done

 

 

当所有的步骤完成之后,显示update done,则可以使用reset指令来完成重启系统.。


4.4  Update BSP image using USB

 

这里介绍另外的一种更新Linux image的方式,同样使用与更新u-boot image。Download 镜像的方式是一样的。都是通过fat格式的u盘来加载镜像到内存中。

通过help usb来获得usb指令的详细帮助:

 

图4.1 usb指令的使用帮助

 

针对usb的指令主要会用到如下三个:

 

Syntax

Description  / Parameters  / Example

usb reset/start

Description:

To reset or rescan USBcontroller.

 

Parameters:

Example:

uBoot> usb reset

(Re)start USB...

USB: (port 0) scanning bus for devices...  1 USB Devices found scanning bus for storage  devices...

Device 0: Vendor:  USB 2.0 Prod.:  Flash Disk Rev: 0.00

Type: Removable  Hard Disk

Capacity:  496.0 MB = 0.4 GB (1015808 x 512)

Fatls

<interface><dev[:part]>   [directory]

Description:

List files in USB device.

 

 

Parameters:

<interface>:  Decide what  interface  you want  to list.

<dev[:part]>:  Decide USB list port.

 

 

Example:

uBoot> fatls usb 0

18121896 vmlinux.64

..

1 file(s), 0 dir(s)

fatload

<interface>

<dev[:part]>   <addr>

<filename>  [bytes]

 

Description:

Load file in USB device to address.

 

 

Parameters:

<interface>:  Decide what  interface you want  to list.

<dev[:part]>:  Decide USB list port.

<addr>:    Load address.

<filename>:  Load file name. Example:

uBoot> fatload  usb 0:1 $(loadaddr) vmlinux.64

reading vmlinux.64

....................

 

 

18121896 bytes read

 

Table 4.1: u-Boot USB commands.

 

同样,更新flash的步骤也是两个:

 

Step 1: Using fatload command to download BSP image to memory

 

uBoot> fatload usb 0 $(loadaddr)vmlinux.64

 

reading vmlinux.64

 

........................................

 

 

18121896 bytes read

 

Step 2: Update BSPimage by command run linux_update

 

uBoot> run linux_update

 

Un-Protected   192sectors

  

................................................ Erased  192 sectors

Copy to Flash...4....3....2....1....done

 

 

当所有的步骤完成之后,显示update done,则可以使用reset指令来完成重启系统。

 

报错1: /* 擦除 */ tiangong1 # nand erase.chip NAND erase.chip: device 0 whole chip Erasing at 0xffe0000 -- 100% complete. OK /* esbc */ tiangong1 # bootmenu *** U-Boot Boot Menu *** update rootfs.rw update rootfs.ro update fwk update kernel.images update uboot update esbc reboot uboot update fwk.squashfs U-Boot console Press UP/DOWN to move, ENTER to select, ESC/CTRL+C to quit hsan_mac gemac2@2: gemac2@2 link up, Speed: 1000, full Using pie device TFTP from server 192.168.0.10; our IP address is 192.168.0.1 Filename 'hi_esbc.bin'. Load address: 0x86000000 Loading: ################ 6.7 MiB/s done Bytes transferred = 77004 (12ccc hex) Erasing 0x00000000 ... 0x0007ffff (4 eraseblock(s)) Writing 77004 byte(s) at offset 0x00000000 Size not on a page boundary (0x800), rounding to 0x13000 /* uboot.bin */ tiangong1 # *** U-Boot Boot Menu *** update rootfs.rw update rootfs.ro update fwk update kernel.images update uboot update esbc reboot uboot update fwk.squashfs U-Boot console Press UP/DOWN to move, ENTER to select, ESC/CTRL+C to quit hsan_mac gemac2@2: gemac2@2 link up, Speed: 1000, full Using pie device TFTP from server 192.168.0.10; our IP address is 192.168.0.1 Filename 'hi_uboot.bin'. Load address: 0x86000000 Loading: ################################################################# ################################ 7.9 MiB/s done Bytes transferred = 495132 (78e1c hex) Erasing 0x00000000 ... 0x000fffff (8 eraseblock(s)) Writing 495132 byte(s) at offset 0x00000000 Size not on a page boundary (0x800), rounding to 0x79000 Erasing 0x00000000 ... 0x000fffff (8 eraseblock(s)) Writing 495132 byte(s) at offset 0x00000000 Size not on a page boundary (0x800), rounding to 0x79000 /* reset */ tiangong1 # re resetting ... reset_cpu hi-esbc start boot_info.value a0000..... boot mode 2...... match board TG1C0D8_TYPE1, board_id_val 412121 sec init spi hw init succ �up��0_ boot_info.value a0000..... flash boot mode ...... hi_nand_probe...... Nand Spec : Block[20000B] Page[800B] OOB[40B] page_shift[0b] read_addr_cycle[05] read_if_type[00] read_dummy_num[01] read_cmd[03] uboot_region_size [100000]...... This boot is main region 0 area...... nand read oob: offset 0x80000 nand read: offset 0x80000 size 0x1000 to addr 0x17512cd0 nand read oob: offset 0x80000 nand read oob: offset 0x80000 nand read: offset 0x81000 size 0x100 to addr 0x17513cd0 nand read oob: offset 0x80000 nand read oob: offset 0x80000 nand read: offset 0x81100 size 0x1bf0 to addr 0x17513dd0 normal boot...... no secure boot, dont check sign...... no secure boot, dont check code image..... start ddrinit from addr 17513dd0 ddrinit finish This boot is main region 0 area...... nand read oob: offset 0x80000 nand read oob: offset 0x80000 nand read: offset 0x82cf0 size 0x1000 to addr 0x80100f00 nand read oob: offset 0x80000 nand read oob: offset 0x80000 nand read: offset 0x83cf0 size 0x100 to addr 0x80101f00 nand read oob: offset 0x80000 nand read oob: offset 0x80000 nand read oob: offset 0xa0000 nand read oob: offset 0xc0000 nand read oob: offset 0xe0000 nand read: offset 0x83df0 size 0x7502c to addr 0x80102000 dont decrypt boot code...... no secure boot, dont check sign...... no secure boot, dont check code image..... check nvcnt...... check version start...... There is no version in efuse dice not support...... subkey_id = 0x00 esbc_mask = 0x01 bl_nvcnt = 0x01 start to uboot...... U-Boot 2022.07 (Aug 28 2025 - 11:08:19 +0800) for tiangong1 Watchdog enabled DRAM: 224 MiB Core: 139 devices, 17 uclasses, devicetree: separate NAND: device found, Manufacturer ID: 0xc8, Chip ID: 0x92 GigaDevice GD5F2GM7UEYIGR GigaDevice GD5F2GM7UEYIGR 256 MiB, MLC, erase size: 128 KiB, page size: 2048, OOB size: 128 256 MiB Loading Environment from NAND... Scanning device for bad blocks *** Warning - bad CRC, using default environment In: uart1@10119000 Out: uart1@10119000 Err: uart1@10119000 invalid bootflag, using default Saving Environment to NAND... Erasing redundant NAND... Erasing at 0x360000 -- 100% complete. Writing to redundant NAND... OK OK Reset Info: Uboot reset cmd to reset Net: lsw_dp lsw_dp: lsw_dp probe succ lsw_pfe lsw_pfe: get reset bulk failed lsw_pfe lsw_pfe: lsw_pfe probe succ hsan_mac gemac0@0: gemac0@0 probe succ mdio_bus mdio0@0: mdio_register mdio0@0 mdio_bus mdio0@0: mdio0@0 probe succ Genius Phy hwVer:0x20669a22 fwVer:0x6e01 hsan_mac gemac1@1: gemac1@1 probe succ hsan_mac gemac2@2: gemac2@2 probe succ hsan_mac gemac3@3: gemac3@3 probe succ hsan_mac gemac@8: gemac@8 probe succ mdio_bus mdio1@1: mdio_register mdio1@1 mdio_bus mdio1@1: mdio1@1 probe succ Could not get PHY for mdio1@1: addr 1 hsan_mac gemac@8: gemac@8 no phy device hsan_pie pie: pie probe succ Warning: pie (eth0) using random MAC address - 5a:60:6c:f7:b9:c3 eth0: pie bootflag a bootreg 10 hsan_mac gemac2@2: gemac2@2 link up, Speed: 1000, full multiupg detect bootdelay is 3000 Hit any key to stop autoboot: 0 /* uboot */ tiangong1 # bootmenu *** U-Boot Boot Menu *** update rootfs.rw update rootfs.ro update fwk update kernel.images update uboot update esbc reboot uboot update fwk.squashfs U-Boot console Press UP/DOWN to move, ENTER to select, ESC/CTRL+C to quit hsan_mac gemac2@2: gemac2@2 link up, Speed: 1000, full Using pie device TFTP from server 192.168.0.10; our IP address is 192.168.0.1 Filename 'hi_uboot.bin'. Load address: 0x86000000 Loading: ################################################################# ################################ 7.7 MiB/s done Bytes transferred = 495132 (78e1c hex) Erasing 0x00000000 ... 0x000fffff (8 eraseblock(s)) Writing 495132 byte(s) at offset 0x00000000 Size not on a page boundary (0x800), rounding to 0x79000 Erasing 0x00000000 ... 0x000fffff (8 eraseblock(s)) Writing 495132 byte(s) at offset 0x00000000 Size not on a page boundary (0x800), rounding to 0x79000 /* reset */ tiangong1 # re resetting ... reset_cpu hi-esbc start boot_info.value a0000..... boot mode 2...... match board TG1C0D8_TYPE1, board_id_val 412121 sec init spi hw init succ �oo��0_ boot_info.value a0000..... flash boot mode ...... hi_nand_probe...... Nand Spec : Block[20000B] Page[800B] OOB[40B] page_shift[0b] read_addr_cycle[05] read_if_type[00] read_dummy_num[01] read_cmd[03] uboot_region_size [100000]...... This boot is main region 0 area...... nand read oob: offset 0x80000 nand read: offset 0x80000 size 0x1000 to addr 0x17512cd0 [err] ECC error in page_addr: 0x80000, flash_status 00 nand read fail at 0x%08x Nand read from offset 0x80000 failed 1879048192 flash read ddrinit head [80000] fail...... flash boot fail...... hi-esbc start fail 70000000 hi-esbc start boot_info.value a0000..... boot mode 2...... match board TG1C0D8_TYPE1, board_id_val 412121 sec init spi hw init succ �e ��0_ boot_info.value a0000..... flash boot mode ...... hi_nand_probe...... Nand Spec : Block[20000B] Page[800B] OOB[40B] page_shift[0b] read_addr_cycle[05] read_if_type[00] read_dummy_num[01] read_cmd[03] uboot_region_size [100000]...... This boot is standby region 0 area...... nand read oob: offset 0x180000 nand read: offset 0x180000 size 0x1000 to addr 0x17512cd0 [err] ECC error in page_addr: 0x180000, flash_status 00 nand read fail at 0x%08x Nand read from offset 0x180000 failed 1879048192 flash read ddrinit head [180000] fail...... flash boot fail...... hi-esbc start fail 70000000 hi-esbc start boot_info.value a0000..... boot mode 2...... match board TG1C0D8_TYPE1, board_id_val 412121 sec init spi hw init succ �e ��0_ boot_info.value a0000..... flash boot mode ...... hi_nand_probe...... Nand Spec : Block[20000B] Page[800B] OOB[40B] page_shift[0b] read_addr_cycle[05] read_if_type[00] read_dummy_num[01] read_cmd[03] uboot_region_size [100000]...... This boot is main region 0 area...... nand read oob: offset 0x80000 nand read: offset 0x80000 size 0x1000 to addr 0x17512cd0 [err] ECC error in page_addr: 0x80000, flash_status 00 nand read fail at 0x%08x Nand read from offset 0x80000 failed 1879048192 flash read ddrinit head [80000] fail...... flash boot fail...... hi-esbc start fail 70000000 报错2: /* 擦除 */ tiangong1 # mtd erase nand0 Erasing 0x00000000 ... 0x0fffffff (2048 eraseblock(s)) attempt to erase a bad block at page 0x00007380 Skipping bad block at 0x039c0000 /* esbc */ tiangong1 # bootmenu *** U-Boot Boot Menu *** update rootfs.rw update rootfs.ro update fwk update kernel.images update uboot update esbc reboot uboot update fwk.squashfs U-Boot console Press UP/DOWN to move, ENTER to select, ESC/CTRL+C to quit hsan_mac gemac2@2: gemac2@2 link up, Speed: 1000, full Using pie device TFTP from server 192.168.0.10; our IP address is 192.168.0.1 Filename 'hi_esbc.bin'. Load address: 0x86000000 Loading: ########### 6.6 MiB/s done Bytes transferred = 55420 (d87c hex) Erasing 0x00000000 ... 0x0007ffff (4 eraseblock(s)) Writing 55420 byte(s) at offset 0x00000000 Size not on a page boundary (0x800), rounding to 0xe000 /* uboot */ tiangong1 # *** U-Boot Boot Menu *** update rootfs.rw update rootfs.ro update fwk update kernel.images update uboot update esbc reboot uboot update fwk.squashfs U-Boot console Press UP/DOWN to move, ENTER to select, ESC/CTRL+C to quit hsan_mac gemac2@2: gemac2@2 link up, Speed: 1000, full Using pie device TFTP from server 192.168.0.10; our IP address is 192.168.0.1 Filename 'hi_uboot.bin'. Load address: 0x86000000 Loading: ################################################################# ################################ 7.8 MiB/s done Bytes transferred = 495892 (79114 hex) Erasing 0x00000000 ... 0x000fffff (8 eraseblock(s)) Writing 495892 byte(s) at offset 0x00000000 Size not on a page boundary (0x800), rounding to 0x79800 Erasing 0x00000000 ... 0x000fffff (8 eraseblock(s)) Writing 495892 byte(s) at offset 0x00000000 Size not on a page boundary (0x800), rounding to 0x79800 /* reset */ tiangong1 # re resetting ... reset_cpu hi-esbc start spi hw init succ �un�� hit succ U-Boot 2022.07 (Aug 25 2025 - 19:01:33 +0800) for tiangong1 Watchdog enabled DRAM: 224 MiB Core: 140 devices, 17 uclasses, devicetree: separate NAND: device found, Manufacturer ID: 0xc8, Chip ID: 0x92 GigaDevice GD5F2GM7UEYIGR GigaDevice GD5F2GM7UEYIGR 256 MiB, MLC, erase size: 128 KiB, page size: 2048, OOB size: 128 256 MiB Loading Environment from NAND... Scanning device for bad blocks Bad eraseblock 462 at 0x0000039c0000 *** Warning - bad CRC, using default environment In: uart1@10119000 Out: uart1@10119000 Err: uart1@10119000 invalid bootflag, using default Saving Environment to NAND... Erasing redundant NAND... Erasing at 0x360000 -- 100% complete. Writing to redundant NAND... OK OK Reset Info: Uboot reset cmd to reset Net: lsw_dp lsw_dp: lsw_dp probe succ lsw_pfe lsw_pfe: lsw_pfe probe succ hsan_mac gemac0@0: gemac0@0 probe succ mdio_bus mdio0@0: mdio_register mdio0@0 mdio_bus mdio0@0: mdio0@0 probe succ Genius Phy hwVer:0x20669a22 fwVer:0x6e01 hsan_mac gemac1@1: gemac1@1 probe succ hsan_mac gemac2@2: gemac2@2 probe succ hsan_mac gemac3@3: gemac3@3 probe succ hsan_mac gemac@8: gemac@8 probe succ mdio_bus mdio1@1: mdio_register mdio1@1 mdio_bus mdio1@1: mdio1@1 probe succ Could not get PHY for mdio1@1: addr 1 hsan_mac gemac@8: gemac@8 no phy device hsan_pie pie: pie probe succ Warning: pie (eth0) using random MAC address - 96:a1:cb:b9:1c:36 eth0: pie bootflag a bootreg 10 hsan_mac gemac2@2: gemac2@2 link up, Speed: 1000, full multiupg detect bootdelay is 3000 Hit any key to stop autoboot: 0 /* uboot */ tiangong1 # bootmenu *** U-Boot Boot Menu *** update rootfs.rw update rootfs.ro update fwk update kernel.images update uboot update esbc reboot uboot update fwk.squashfs U-Boot console Press UP/DOWN to move, ENTER to select, ESC/CTRL+C to quit hsan_mac gemac2@2: gemac2@2 link up, Speed: 1000, full Using pie device TFTP from server 192.168.0.10; our IP address is 192.168.0.1 Filename 'hi_uboot.bin'. Load address: 0x86000000 Loading: ################################################################# ################################ 7.3 MiB/s done Bytes transferred = 495892 (79114 hex) Erasing 0x00000000 ... 0x000fffff (8 eraseblock(s)) Writing 495892 byte(s) at offset 0x00000000 Size not on a page boundary (0x800), rounding to 0x79800 Erasing 0x00000000 ... 0x000fffff (8 eraseblock(s)) Writing 495892 byte(s) at offset 0x00000000 Size not on a page boundary (0x800), rounding to 0x79800 /* reset */ tiangong1 # re resetting ... reset_cpu hi-esbc start spi hw init succ hi-esbc start fail 70000000 hi-esbc start spi hw init succ hi-esbc start fail 70000000 hi-esbc start spi hw init succ �i ��pihi-esbc start fail 70000000 hi-esbc start spi hw init succ 问:以上两个报错有什么区别?如果没有区别,告诉我报错的可能原因
最新发布
09-02
由于没有提供具体的两个报错日志,无法直接分析它们的区别。不过,下面为你列举在更新 esbc 和 uboot 过程中可能出现报错的一些常见原因。 ### 硬件方面 - **存储设备故障**:存储设备如硬盘、闪存等出现坏道、损坏等问题,可能导致更新文件无法正常写入或读取,从而引发报错。例如,闪存芯片的物理损坏会使得数据写入失败。 - **电源问题**:不稳定的电源供应可能导致更新过程中设备突然断电,或者电压、电流异常,影响更新的正常进行。比如电源适配器故障,输出电压不稳定。 - **硬件连接问题**:设备之间的连接松动、接口损坏等,可能造成数据传输中断或错误。像数据线接触不良,会导致更新文件传输不完整。 ### 软件方面 - **文件损坏**:用于更新的 esbc 和 uboot 文件在下载、传输过程中可能损坏,导致更新时无法正确解析文件内容。例如,网络传输中的干扰可能使文件校验失败。 - **版本不兼容**:更新的 esbc 和 uboot 版本与 tiangong1 设备不兼容,可能会导致更新过程中出现冲突或无法正常工作。比如新版本的 uboot 对硬件有新的要求,而设备不满足。 - **系统异常**:设备的操作系统或其他软件出现异常,可能干扰更新过程。例如,系统内存不足,无法为更新操作提供足够的资源。 ### 环境方面 - **电磁干扰**:周围环境中的强电磁干扰可能影响设备的正常运行和数据传输。比如设备附近有大型电机、变压器等产生强电磁场的设备。 - **温度和湿度**:过高或过低的温度、湿度可能影响设备的性能和稳定性。例如,高温环境可能导致设备过热,影响存储设备的读写性能。 ```python # 以下是一个简单的模拟检查更新文件完整性的代码示例 import hashlib def check_file_integrity(file_path, expected_hash): hash_object = hashlib.sha256() with open(file_path, 'rb') as file: for chunk in iter(lambda: file.read(4096), b""): hash_object.update(chunk) calculated_hash = hash_object.hexdigest() return calculated_hash == expected_hash # 使用示例 file_path = 'esbc_update_file.bin' expected_hash = '123456789abcdef...' # 替换为实际的预期哈希值 is_integrity = check_file_integrity(file_path, expected_hash) print(f"文件完整性检查结果: {is_integrity}") ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值