U-Boot 2020.2 啟動問題
最近有客戶反饋,U-Boot 2020.2 啟動有問題。 SD卡里有BOOT.BIN, image.ub等文件,也不能正常啟動。
下面是常見的啟動信息。 U-Boot報告多個錯誤,最主要的錯誤是“Wrong image format for "source" command”。
U-Boot 2020.01 (Nov 20 2020 - 19:24:17 +0000)
Model: ZynqMP ZCU106 RevA
Board: Xilinx ZynqMP
DRAM: 4 GiB
PMUFW: v1.1
EL Level: EL2
Chip ID: zu7ev
NAND: 0 MiB
MMC: mmc@ff170000: 0
In: serial@ff000000
Out: serial@ff000000
Err: serial@ff000000
Bootmode: LVL_SHFT_SD_MODE1
Reset reason: EXTERNAL
Net:
ZYNQ GEM: ff0e0000, mdio bus ff0e0000, phyaddr 12, interface rgmii-id
Warning: ethernet@ff0e0000 using MAC address from ROM
eth0: ethernet@ff0e0000
Hit any key to stop autoboot: 0
switch to partitions #0, OK
mmc0 is current device
Scanning mmc 0:1...
JTAG: Trying to boot script at 0x20000000
## Executing script at 20000000
Wrong image format for "source" command
JTAG: SCRIPT FAILED: continuing...
switch to partitions #0, OK
mmc0 is current device
Scanning mmc 0:1...
MMC Device 1 not found
no mmc device at slot 1
SF: Detected n25q512a with page size 512 Bytes, erase size 128 KiB, total 128 MiB
device 0 offset 0x3e80000, size 0x80000
SF: 524288 bytes @ 0x3e80000 Read: OK
QSPI: Trying to boot script at 0x20000000
## Executing script at 20000000
Wrong image format for "source" command
QSPI: SCRIPT FAILED: continuing...
no devices available
NAND: SCRIPT FAILED: continuing...
starting USB...
Bus dwc3@fe200000: usb maximum-speed not found
Register 2000440 NbrPorts 2
Starting the controller
USB XHCI 1.00
scanning bus dwc3@fe200000 for devices... 1 USB Device(s) found
scanning usb for storage devices... 0 Storage Device(s) found
Device 0: unknown device
Device 1: unknown device
scanning bus for devices...
SATA link 0 timeout.
SATA link 1 timeout.
AHCI 0001.0301 32 slots 2 ports 6 Gbps 0x3 impl SATA mode
flags: 64bit ncq pm clo only pmp fbss pio slum part ccc apst
Device 0: unknown device
BOOTP broadcast 1
DHCP client bound to address 10.164.16.148 (166 ms)
*** ERROR: `serverip' not set
Cannot autoload with TFTPGET
missing environment variable: pxeuuid
Retrieving file: pxelinux.cfg/01-00-0a-35-04-d2-38
*** ERROR: `serverip' not set
Retrieving file: pxelinux.cfg/0AA41094
*** ERROR: `serverip' not set
Retrieving file: pxelinux.cfg/0AA4109
*** ERROR: `serverip' not set
Retrieving file: pxelinux.cfg/0AA410
*** ERROR: `serverip' not set
Retrieving file: pxelinux.cfg/0AA41
*** ERROR: `serverip' not set
Retrieving file: pxelinux.cfg/0AA4
*** ERROR: `serverip' not set
Retrieving file: pxelinux.cfg/0AA
*** ERROR: `serverip' not set
Retrieving file: pxelinux.cfg/0A
*** ERROR: `serverip' not set
Retrieving file: pxelinux.cfg/0
*** ERROR: `serverip' not set
Retrieving file: pxelinux.cfg/default-arm-zynqmp-zynqmp
*** ERROR: `serverip' not set
Retrieving file: pxelinux.cfg/default-arm-zynqmp
*** ERROR: `serverip' not set
Retrieving file: pxelinux.cfg/default-arm
*** ERROR: `serverip' not set
Retrieving file: pxelinux.cfg/default
*** ERROR: `serverip' not set
Config file not found
BOOTP broadcast 1
DHCP client bound to address 10.164.16.148 (164 ms)
*** ERROR: `serverip' not set
Cannot autoload with TFTPGET
BOOTP broadcast 1
DHCP client bound to address 10.164.16.148 (176 ms)
*** ERROR: `serverip' not set
Cannot autoload with TFTPGET
問題原因和解決辦法
上述問題是在啟動設(shè)備里沒有文件“boot.scr”導(dǎo)致的。 如果在SD卡里,提供文件 boot.scr,就能正常啟動。
U-Boot 2020.01 (Nov 20 2020 - 19:24:17 +0000)
Model: ZynqMP ZCU106 RevA
Board: Xilinx ZynqMP
DRAM: 4 GiB
PMUFW: v1.1
EL Level: EL2
Chip ID: zu7ev
NAND: 0 MiB
MMC: mmc@ff170000: 0
In: serial@ff000000
Out: serial@ff000000
Err: serial@ff000000
Bootmode: LVL_SHFT_SD_MODE1
Reset reason: EXTERNAL
Net:
ZYNQ GEM: ff0e0000, mdio bus ff0e0000, phyaddr 12, interface rgmii-id
Warning: ethernet@ff0e0000 using MAC address from ROM
eth0: ethernet@ff0e0000
Hit any key to stop autoboot: 0
switch to partitions #0, OK
mmc0 is current device
Scanning mmc 0:1...
Found U-Boot script /boot.scr
1718 bytes read in 21 ms (79.1 KiB/s)
## Executing script at 20000000
124511736 bytes read in 8225 ms (14.4 MiB/s)
## Loading kernel from FIT Image at 10000000 ...
Using 'conf@system-top.dtb' configuration
Trying 'kernel@1' kernel subimage
......
U-Boot 2020.2 啟動流程分析
U-Boot 文檔
U-Boot為了支持各種Linux發(fā)行版,增加通用性,增加了啟動時的Script的功能。 詳細(xì)信息可以參考文檔文件doc/develop/distro.rst和Generic Distro Configuration Concept。
U-Boot對Script是逐步完善的。軟件代碼文件“include/config_distro_bootcmd.h”在2015.01就已經(jīng)存在。文檔文件“doc/develop/distro.rst”在2022.01里加入。
業(yè)界對Script功能也逐步接受,目前很多芯片都都已經(jīng)默認(rèn)使能,比如AMD的MPSoC的U-Boot。
如果不想使用Script功能,可以禁止選項(xiàng)CONFIG_DISTRO_DEFAULTS。
U-Boot啟動命令
沒有人工參與的自動啟動,或者直接執(zhí)行命令“boot”, U-Boot啟動命令都是“bootcmd”。
超時啟動代碼
下面是沒有人工參與,超時啟動時選擇啟動命令的代碼。
const char *bootdelay_process(void)
{
char *s;
int bootdelay;
bootcount_inc();
s = env_get("bootdelay");
bootdelay = s ? (int)simple_strtol(s, NULL, 10) : CONFIG_BOOTDELAY;
if (IS_ENABLED(CONFIG_OF_CONTROL)) {
bootdelay = ofnode_conf_read_int("bootdelay", bootdelay);
}
debug("### main_loop entered: bootdelay=%dnn", bootdelay);
if (IS_ENABLED(CONFIG_AUTOBOOT_MENU_SHOW)) {
bootdelay = menu_show(bootdelay);
}
bootretry_init_cmd_timeout();
#ifdef CONFIG_POST
if (gd->flags & GD_FLG_POSTFAIL) {
s = env_get("failbootcmd");
} else
#endif /* CONFIG_POST */
if (bootcount_error()) {
s = env_get("altbootcmd");
} else {
s = env_get("bootcmd");
}
if (IS_ENABLED(CONFIG_OF_CONTROL)) {
process_fdt_options(gd->fdt_blob);
}
stored_bootdelay = bootdelay;
return s;
}
命令“boot”的啟動代碼
下面是直接執(zhí)行命令“boot”選擇啟動命令的代碼。
int do_bootd(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
{
return run_command(env_get("bootcmd"), flag);
}
U_BOOT_CMD(
boot, 1, 1, do_bootd,
"boot default, i.e., run 'bootcmd'",
""
);
/* keep old command name "bootd" for backward compatibility */
U_BOOT_CMD(
bootd, 1, 1, do_bootd,
"boot default, i.e., run 'bootcmd'",
""
);
命令distro_bootcmd
啟動命令“bootcmd”通常是“run distro_bootcmd”。 它在“bootKconfig”中定義,能在配置U-Boot時更改。
config BOOTCOMMAND
string "bootcmd value"
depends on USE_BOOTCOMMAND && !USE_DEFAULT_ENV_FILE
default "run distro_bootcmd" if DISTRO_DEFAULTS
help
This is the string of commands that will be used as bootcmd and if
AUTOBOOT is set, automatically run.
“distro_bootcmd”的定義在includeConfig_distro_bootcmd.h里。
"distro_bootcmd=" BOOTENV_SET_SCSI_NEED_INIT
BOOTENV_SET_NVME_NEED_INIT
BOOTENV_SET_IDE_NEED_INIT
BOOTENV_SET_VIRTIO_NEED_INIT
"for target in ${boot_targets}; do "
"run bootcmd_${target}; "
"done?"
在U-Boot啟動時,使用鍵盤進(jìn)入U-Boot的命令行界面,使用命令“printenv”也可以查看真實(shí)的“distro_bootcmd”。 與“distro_bootcmd”相關(guān)的環(huán)境變量如下:
boot_a_script=load ${devtype} ${devnum}:${distro_bootpart} ${scriptaddr} ${prefix}${script}; source ${scriptaddr}
boot_scripts=boot.scr.uimg boot.scr
boot_targets=mmc0 jtag mmc0 mmc1 qspi0 nand0 usb0 usb1 scsi0 pxe dhcp
bootcmd=run distro_bootcmd
bootcmd_jtag=echo JTAG: Trying to boot script at ${scriptaddr} && source ${scriptaddr}; echo JTAG: SCRIPT FAILED: continuing...;
bootcmd_mmc0=devnum=0; run mmc_boot
bootcmd_mmc1=devnum=1; run mmc_boot
bootcmd_qspi0=sf probe 0 0 0 && sf read $scriptaddr $script_offset_f $script_size_f && echo QSPI: Trying to boot script at ${scriptaddr} && source ${scriptaddr}; echo QSPI: SCRIPT FAILED: continuing...;
distro_bootcmd=scsi_need_init=; for target in ${boot_targets}; do run bootcmd_${target}; done
mmc_boot=if mmc dev ${devnum}; then devtype=mmc; run scan_dev_for_boot_part; fi
modeboot=sdboot
scan_dev_for_boot=echo Scanning ${devtype} ${devnum}:${distro_bootpart}...; for prefix in ${boot_prefixes}; do run scan_dev_for_extlinux; run scan_dev_for_scripts; done;run scan_dev_for_efi;
scan_dev_for_boot_part=part list ${devtype} ${devnum} -bootable devplist; env exists devplist || setenv devplist 1; for distro_bootpart in ${devplist}; do if fstype ${devtype} ${devnum}:${distro_bootpart} bootfstype; then run scan_dev_for_boot; fi; done; setenv devplist
scan_dev_for_scripts=for script in ${boot_scripts}; do if test -e ${devtype} ${devnum}:${distro_bootpart} ${prefix}${script}; then echo Found U-Boot script ${prefix}${script}; run boot_a_script; echo SCRIPT FAILED: continuing...; fi; done
script_offset_f=3e80000
script_size_f=0x80000
scriptaddr=0x20000000
可以看到,U-Boot會依次執(zhí)行bootcmd_mmc0, bootcmd_jtag, bootcmd_mmc0, bootcmd_mmc1, bootcmd_qspi0,與上述的錯誤信息中的設(shè)備啟動順序一致。也說明U-Boot能從各種設(shè)備啟動Linux。
另外bootcmd_mmc0會依次調(diào)用mmc_boot, scan_dev_for_boot_part, scan_dev_for_boot, scan_dev_for_scripts。最后scan_dev_for_scripts檢查U-Boot script,也就是前述的“boot.scr”。如果發(fā)現(xiàn),就會輸出“Found U-Boot script”,并執(zhí)行“boot_a_script”。 對于ZCU106單板,mmc0就是SD卡。 如果沒有前述的“boot.scr”,就會嘗試后續(xù)的啟動設(shè)備。
因此,默認(rèn)的U-Boot啟動過程中,需要“boot.scr”。如果不想使用“boot.scr”,可以在配置U-Boot時禁止選項(xiàng)CONFIG_DISTRO_DEFAULTS,或者把替換啟動命令“bootcmd”成直接從某個固定設(shè)備啟動Linux的命令。當(dāng)然,也可以在運(yùn)行時,直接修改U-Boot環(huán)境變量中的命令“bootcmd”,讓它直接從某個固定設(shè)備啟動Linux。
審核編輯:湯梓紅
-
amd
+關(guān)注
關(guān)注
25文章
5466瀏覽量
134110 -
Linux
+關(guān)注
關(guān)注
87文章
11296瀏覽量
209358 -
Xilinx
+關(guān)注
關(guān)注
71文章
2167瀏覽量
121321 -
文件
+關(guān)注
關(guān)注
1文章
565瀏覽量
24732 -
u-boot
+關(guān)注
關(guān)注
0文章
121瀏覽量
38222
發(fā)布評論請先 登錄
相關(guān)推薦
評論