1

我正在做一个项目,我想用 U-Boot 创建自己的嵌入式 linux。因此,我正在使用我最近开始学习的 buildroot。在成功创建我自己的 rasberrypi4_defconfig 后,我目前正在努力解决这个问题,以使 u-boot 正常工作。

我正在使用哪些版本:

  1. 圆周率 4
  2. buildroot-2019.11
  3. u-boot(因此我每天都拉新的变化)

工作现状:

我建立在 Ubuntu(32 位)上。我使用raspberrypi4_defconfig配置 buildroot并使其无需更改。然后我为 rpi_4_32b_defconfig 创建一个 u-boot defconfig创建 u-boot.binmake CROSS_COMPILE=arm-linux-gnueabihf- u-boot.bin 现在我的下一步是配置 config.txt 并使用以下内容交换内容:

enalbe_uart=1
kernel=u-boot.bin

此外,我将我的 u-boot.bin 复制到了我的 SD 卡中。

我实际做的最后一步是使用以下内容构建我自己的 boot.scr.uimg

fatload mmc O:1 ${fdt_addr_r} bcm2711-rpi-4-b.dtb
fatload mmc 0:1 ${kernel_addr_r} Image.4.8
setenv bootargs console=ttyS0, 115200 \
root=/dev/mmcblk0p2 rootfstype=ext4 rootwait rw
bootz ${kernel_addr_r} - ${fdt_addr_r}

问题 到目前为止,我正在归档以到达 U-boot 菜单,但在启动时出现错误:zimage Bad Magic 我实际上认为我的 boot.scr.uimg 可能不正确但不明白。

引导日志

调用引导后打印以下内容:

    U-Boot 2020.01-rc4-00066-g7e5ee346fc (Dec 05 2019 - 16:55:27 +0100)

    DRAM:  948 MiB
    RPI 4 Model B (0xc03111)
    MMC:   emmc2@7e340000: 0, mmcnr@7e300000: 1
    Loading Environment from FAT... *** Warning - bad CRC, using default environment

    In:    serial
    Out:   serial
    Err:   serial
    Net:   Net Initialization Skipped
    No ethernet found.
    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.uimg
    291 bytes read in 17 ms (16.6 KiB/s)
    ## Executing script at 02400000
    40559 bytes read in 33 ms (1.2 MiB/s)
    zimage: Bad magic!
    SCRIPT FAILED: continuing...
    40559 bytes read in 29 ms (1.3 MiB/s)
    Card did not respond to voltage select!
    No ethernet found.
    missing environment variable: pxeuuid
    missing environment variable: bootfile
    Retrieving file: pxelinux.cfg/00000000
    No ethernet found.
    missing environment variable: bootfile
    Retrieving file: pxelinux.cfg/0000000
    No ethernet found.
    missing environment variable: bootfile
    Retrieving file: pxelinux.cfg/000000
    No ethernet found.
    missing environment variable: bootfile
    Retrieving file: pxelinux.cfg/00000
    No ethernet found.
    missing environment variable: bootfile
    Retrieving file: pxelinux.cfg/0000
    No ethernet found.
    missing environment variable: bootfile
    Retrieving file: pxelinux.cfg/000
    No ethernet found.
    missing environment variable: bootfile
    Retrieving file: pxelinux.cfg/00
    No ethernet found.
    missing environment variable: bootfile
    Retrieving file: pxelinux.cfg/0
    No ethernet found.
    missing environment variable: bootfile
    Retrieving file: pxelinux.cfg/default-arm-bcm283x-rpi
    No ethernet found.
    missing environment variable: bootfile
    Retrieving file: pxelinux.cfg/default-arm-bcm283x
    No ethernet found.
    missing environment variable: bootfile
    Retrieving file: pxelinux.cfg/default-arm
    No ethernet found.
    missing environment variable: bootfile
    Retrieving file: pxelinux.cfg/default
    No ethernet found.
    Config file not found
    No ethernet found.
    No ethernet found.

环境

arch=arm
baudrate=115200
board=rpi
board_name=4 Model B
board_rev=0x11
board_rev_scheme=1
board_revision=0xC03111
boot_a_script=load ${devtype} ${devnum}:${distro_bootpart} ${scriptaddr} ${prefix}${script}; source ${scriptaddr}
boot_efi_binary=if fdt addr ${fdt_addr_r}; then bootefi bootmgr ${fdt_addr_r};else bootefi bootmgr ${fdtcontroladdr};fi;load ${devty
pe} ${devnum}:${distro_bootpart} ${kernel_addr_r} efi/boot/bootarm.efi; if fdt addr ${fdt_addr_r}; then bootefi ${kernel_addr_r} ${f
dt_addr_r};else bootefi ${kernel_addr_r} ${fdtcontroladdr};fi
boot_extlinux=sysboot ${devtype} ${devnum}:${distro_bootpart} any ${scriptaddr} ${prefix}${boot_syslinux_conf}
boot_prefixes=/ /boot/
boot_script_dhcp=boot.scr.uimg
boot_scripts=boot.scr.uimg boot.scr
boot_syslinux_conf=extlinux/extlinux.conf
boot_targets=mmc0 mmc1 pxe dhcp
bootargs=console=ttyS0,115200 \
root=/dev/mmcblk0p2 rootfstype=ext4 rootwait rw
bootcmd=run distro_bootcmd
bootcmd_dhcp=if dhcp ${scriptaddr} ${boot_script_dhcp}; then source ${scriptaddr}; fi;setenv efi_fdtfile ${fdtfile}; if test -z "${f
dtfile}" -a -n "${soc}"; then setenv efi_fdtfile ${soc}-${board}${boardver}.dtb; fi; setenv efi_old_vci ${bootp_vci};setenv efi_old_
arch ${bootp_arch};setenv bootp_vci PXEClient:Arch:00010:UNDI:003000;setenv bootp_arch 0xa;if dhcp ${kernel_addr_r}; then tftpboot $
{fdt_addr_r} dtb/${efi_fdtfile};if fdt addr ${fdt_addr_r}; then bootefi ${kernel_addr_r} ${fdt_addr_r}; else bootefi ${kernel_addr_r
} ${fdtcontroladdr};fi;fi;setenv bootp_vci ${efi_old_vci};setenv bootp_arch ${efi_old_arch};setenv efi_fdtfile;setenv efi_old_arch;s
etenv efi_old_vci;
bootcmd_mmc0=devnum=0; run mmc_boot
bootcmd_mmc1=devnum=1; run mmc_boot
bootcmd_pxe=dhcp; if pxe get; then pxe boot; fi
bootdelay=2
bootfstype=fat
cpu=armv7
dhcpuboot=usb start; dhcp u-boot.uimg; bootm
distro_bootcmd=for target in ${boot_targets}; do run bootcmd_${target}; done
efi_dtb_prefixes=/ /dtb/ /dtb/current/
ethaddr=dc:a6:32:45:1f:d1
fdt_addr=2eff5d00
fdt_addr_r=0x02600000
fdt_high=ffffffff
fdtcontroladdr=3af6ac98
fdtfile=bcm2711-rpi-4-b.dtb
fileaddr=2600000
filesize=9e6f
initrd_high=ffffffff
kernel_addr_r=0x00080000
load_efi_dtb=load ${devtype} ${devnum}:${distro_bootpart} ${fdt_addr_r} ${prefix}${efi_fdtfile}
loadaddr=0x00200000
mmc_boot=if mmc dev ${devnum}; then devtype=mmc; run scan_dev_for_boot_part; fi
pxefile_addr_r=0x02500000
ramdisk_addr_r=0x02700000
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_efi=setenv efi_fdtfile ${fdtfile}; if test -z "${fdtfile}" -a -n "${soc}"; then setenv efi_fdtfile ${soc}-${board}${boardver}.dtb; fi; for prefix in ${efi_dtb_prefixes}; do if test -e ${devtype} ${devnum}:${distro_bootpart} ${prefix}${efi_fdtfile}; then run load_efi_dtb; fi;done;if test -e ${devtype} ${devnum}:${distro_bootpart} efi/boot/bootarm.efi; then echo Found EFI removable media binary efi/boot/bootarm.efi; run boot_efi_binary; echo EFI LOAD FAILED: continuing...; fi; setenv efi_fdtfile
scan_dev_for_extlinux=if test -e ${devtype} ${devnum}:${distro_bootpart} ${prefix}${boot_syslinux_conf}; then echo Found ${prefix}${boot_syslinux_conf}; run boot_extlinux; echo SCRIPT FAILED: continuing...; fi
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
scriptaddr=0x02400000
serial#=10000000f58b842c
soc=bcm283x
stderr=serial,vidconsole
stdin=serial,usbkbd
stdout=serial,vidconsole
usbethaddr=dc:a6:32:45:1f:d1
vendor=raspberrypi

Environment size: 3996/16380 bytes
4

1 回答 1

0

到目前为止,我正在归档以到达 U-boot 菜单,但在启动时出现错误:zimage Bad Magic 我实际上认为我的 boot.scr.uimg 可能不正确但不明白。

该错误消息可追溯到boot.scr.uimg的内容:

fatload mmc 0:1 ${kernel_addr_r} Image.4.8
...  
bootz ${kernel_addr_r} - ${fdt_addr_r}

bootz命令需要一个位于第一个内存地址的zImage文件。
但是之前的fatload命令已经将一个名为Image.4.8的文件复制到了内存中。
按照惯例,Image文件是通用的 Linux 内核二进制映像文件,而zImage文件是自解压的 Linux 内核映像的压缩版本。

您需要将您构建的zImage (而不是Image文件)安装到 SD 卡。编辑您的boot.scr.uimg以指示正确的文件类型/名称。


附录

U-Boot 确实有一个用于通用 Linux 内核二进制映像文件的booti命令,但该命令仅适用于 ARM64,例如内置帮助文本是. 请参阅配置该命令的补丁boot arm64 Linux Image image from memory

于 2019-12-06T22:08:52.273 回答