1、常见的升级方式

1.1、应用程序升级

优点:在图形化界面操作,只需要选中升级文件并点击升级即可,操作简单;
缺点:应用程序必须能正常启动,当程序出现bug就不能升级,可靠性差;
总结:操作简单,适合用户;

1.2、uboot下tftp升级

优点:只要uboot能正常运行就可以通过tftp升级,可靠性高;
缺点:需要连接串口和网线,并需要在局域网搭建tftp服务器,操作麻烦;
总结:适用于开发人员,当应用程序起不来的时候去升级;

1.3、uboot下U盘自动升级

优点:只需要将升级文件拷贝到U盘,插上U盘并重启,只要uboot能正常工作即可自动升级,操作简单,可靠性高;
缺点:设备每次启动都要去探测U盘,增加启动时间;
总结:U盘自动升级适用于当设备出现问题并且不方便搭建网络升级环境时使用;

2、uboot下U盘自动升级的步骤

(1)将提供的镜像文件拷贝到自备的U盘;
(2)插上U盘;
(3)重启设备;
(4)等待升级完成;

3、流程设计

QTAndroid U盘升级_网络

4、uboot移植

4.1、uboot需要支持的功能

(1)使能USB OHCI:支持uboot识别U盘;
(2)MMC驱动移植:uboot能初始化U盘;
(3)FAT文件系统支持:uboot能挂载U盘,并以FAT32格式去读取U盘上的内容;

4.2、uboot移植的步骤

(1)uboot代码先使能USB OHCI、移植MMC驱动、支持FAT文件系统;
(2)在uboot的命令行,通过手动敲命令去测试U盘,先达到能正确识别并挂载U盘,能把U盘里的内容读取到内存或者烧写到flash中;
(3)将第二步的测试过程,封装成uboot下的一个命令,然后在bootcmd里添加这个命令,这样每次uboot启动都会去尝试U盘升级;

5、手动实现U盘升级程序

System startup

Uncompress Ok!

U-Boot 2020.01 (Nov 26 2022 - 10:18:53 +0800)

DRAM:  Relocation Offset is: 1771a000
Relocating to 5ff1a000, new gd at 5fe79df8, sp at 5fe79de0
SPI Nor:  Boot Media isn't SPI Nor
NAND:  fmc_ip_ver_check(34): Check Flash Memory Controller v100 ...fmc_ip_ver_check(40):  Found
SPI Nand ID Table Version 2.7
SPI Nand(cs 0) ID: 0xc2 0x90 Name:"MX35UF1G14AC"
Block:128KB Page:2KB OOB:64B ECC:4bit/512 
Chipsize:128 MiB
MMC:   Card did not respond to voltage select!
No EMMC device found !
bsp-sdhci: 0
Loading Environment from SPI Flash... Boot Media isn't SPI Nor
*** Warning - spi_flash_probe() failed, using default environment

Loading Environment from NAND... OK
In:    serial
Out:   serial
Err:   serial

Net:   gmac0, gmac1
Error: gmac1 address not set.

Hit any key to stop autoboot:  0 
# usb device
Install USB Device...
# usb start
starting USB...
USB0:   Register 2000140 NbrPorts 2
Starting the controller
USB XHCI 1.10
scanning bus 0 for devices... 1 USB Device(s) found
USB1:   Register 2000140 NbrPorts 2
Starting the controller
USB XHCI 1.10
scanning bus 1 for devices... 2 USB Device(s) found
       scanning usb for storage devices... 1 Storage Device(s) found
# usb tree
USB device tree:
  1  Hub (5 Gb/s, 0mA)
     U-Boot XHCI Host Controller 
   
  2  Hub (5 Gb/s, 0mA)
  |  U-Boot XHCI Host Controller 
  |
  +-3  Mass Storage (480 Mb/s, 100mA)
       USB2.0 Flash Disk 2013110511330078
     
# 
# fatls usb 0
            System Volume Information/
      402   config
      765   config_debug.txt
   327680   u-boot.bin

 30007296   vmcore

16 file(s), 1 dir(s)

# fatload usb 0 0x43000000 u-boot.bin
1071412 bytes read in 82 ms (12.5 MiB/s)

(1)usb device:按照USB设备;
(2)usb start:初始化并检索USB存储设备;
(2)usb tree:例举当前识别到的USB设备;
(3)fatls usb 0:用FAT32格式去查看usb 0里的文件;
(4)fatload usb 0 0x43000000 u-boot.bin:将usb 0设备的u-boot.bin文件写到内存地址0x43000000处;

6、实现开机自动识别U盘并升级程序

#原来的bootcmd
bootcmd=partload kernel;bootm 0x44000000

# 支持U盘自动升级的bootcmd
bootcmd=usbupdate;partload kernel;bootm 0x44000000

(1)将uboot终端下手动升级的过程封装成一个命令,假设是usbupdate命令;
(2)在bootcmd中添加usbupdate命令,这样每次uboot在启动内核前都会去执行U盘自动升级的过程;

7、U盘识别失败:## Valid DOS partition found

参考博客:《uboot下识别FAT32格式的U盘报错:## Valid DOS partition found ##》;