LINUX系统下UBOOT利用U盘升级程序
前言:
要实现标题中的功能需要uboot支持识别U盘和文件系统
1、uboot移植
uboot需要支持的功能
(1)使能USB OHCI:支持uboot识别U盘;
(2)MMC驱动移植:uboot能初始化U盘;
(3)FAT文件系统支持:uboot能挂载U盘,并以FAT32格式去读取U盘上的内容;
uboot移植的步骤
(1)uboot代码先使能USB OHCI、移植MMC驱动、支持FAT文件系统;
(2)在uboot的命令行,通过手动敲命令去测试U盘,先达到能正确识别并挂载U盘,能把U盘里的内容读取到内存或者烧写到flash中;
(3)将第二步的测试过程,封装成uboot下的一个命令,然后在bootcmd里添加这个命令,这样每次uboot启动都会去尝试U盘升级;
2、手动实现uboot下的U盘升级
(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处;
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)
3、实现开机自动识别U盘并完成升级
(1)将uboot终端下手动升级的过程封装成一个命令,假设是usbupdate命令;
(2)在bootcmd中添加usbupdate命令,这样每次uboot在启动内核前都会去执行U盘自动升级的过程;
#原来的bootcmd
bootcmd=partload kernel;bootm 0x44000000
# 支持U盘自动升级的bootcmd
bootcmd=usbupdate;partload kernel;bootm 0x44000000