u-boot:无法启动 linux 内核,尽管内核小于最大值 BOOTM_LEN

u-boot: cannot boot linux kernel despite kernel being less than maximum BOOTM_LEN

我有一个带 u-boot 的 MIPS 系统 (VSC7427),我正在尝试引导比供应商在其 GPL 版本(boots just fine)中提供的内核更新的内核。

内核 FIT 映像看起来很正常,从输出来看我认为它应该是可启动的:

U-Boot 2019.10 (Mar 28 2021 - 20:41:55 +0000)

MSCC VCore-III MIPS 24Kec
Model: Cisco Meraki MS220-8P
DRAM:  128 MiB
Loading Environment from SPI Flash... SF: Detected mx25l12805d with page size 256 Bytes, erase size 64 KiB, total 16 MiB
OK
In:    serial@10100000
Out:   serial@10100000
Err:   serial@10100000
Net:   
Warning: switch@1010000 (eth0) using random MAC address - b2:6b:53:af:2d:a0
eth0: switch@1010000
luton # dhcp
(snipped)
luton # tftp vmlinux.gz.itb
Using switch@1010000 device
TFTP from server 192.168.1.60; our IP address is 192.168.1.154
Filename 'vmlinux.gz.itb'.
Load address: 0x80100000
Loading: #################################################################
(snipped)
done
Bytes transferred = 5172244 (4eec14 hex)
luton # iminfo 0x80100000

## Checking Image at 80100000 ...
   FIT image found
   FIT description: Linux 5.11.11
    Image 0 (kernel@0)
     Description:  Linux 5.11.11
     Type:         Kernel Image
     Compression:  gzip compressed
     Data Start:   0x801000c0
     Data Size:    5167511 Bytes = 4.9 MiB
     Architecture: MIPS
     OS:           Linux
     Load Address: 0x80100000
     Entry Point:  0x809898f4
     Hash algo:    sha1
     Hash value:   b963ed48f45e332bd5df263dd69d69c3818e6586
    Image 1 (fdt@luton_pcb091)
     Description:  MSCC Luton PCB091 Device Tree
     Type:         Flat Device Tree
     Compression:  uncompressed
     Data Start:   0x805edb60
     Data Size:    2851 Bytes = 2.8 KiB
     Architecture: MIPS
     Hash algo:    sha1
     Hash value:   5283ae4322294e594a7be5e6de65e4f039ff36a5
    Default Configuration: 'conf@default'
    Configuration 0 (conf@default)
     Description:  Generic Linux kernel
     Kernel:       kernel@0
    Configuration 1 (pcb091)
     Description:  Luton Linux kernel
     Kernel:       kernel@0
     FDT:          fdt@luton_pcb091
## Checking hash(es) for FIT Image at 80100000 ...
   Hash(es) for Image 0 (kernel@0): sha1+ 
   Hash(es) for Image 1 (fdt@luton_pcb091): sha1+

然而,当我尝试启动内核时,u-boot 给出了以下错误:

luton # bootm 0x80100000
## Loading kernel from FIT Image at 80100000 ...
   Using 'conf@default' configuration
   Trying 'kernel@0' kernel subimage
     Description:  Linux 5.11.11
     Type:         Kernel Image
     Compression:  gzip compressed
     Data Start:   0x801000c0
     Data Size:    5167511 Bytes = 4.9 MiB
     Architecture: MIPS
     OS:           Linux
     Load Address: 0x80100000
     Entry Point:  0x809898f4
     Hash algo:    sha1
     Hash value:   b963ed48f45e332bd5df263dd69d69c3818e6586
   Verifying Hash Integrity ... sha1+ OK
   Uncompressing Kernel Image
Error: inflate() returned -3
gzip compressed: uncompress error -1
Must RESET board to recover

内核的大小远低于 CONFIG_SYS_BOOTM_LEN (16MB) 定义的限制,因此我认为这不是导致此错误的根本原因。

用于生成 itbvmlinux.bin.gz 是有效的 gzip 压缩文件,解压后的大小也小于 CONFIG_SYS_BOOTM_LEN 限制:

$ file vmlinux.bin.gz
vmlinux.bin.gz: gzip compressed data, max compression, from Unix, original size modulo 2^32 11494800

我尝试使用未压缩的 vmlinux.bin 创建 itb 文件(我只是将 vmlinux.its 编辑为 data = /incbin/("vmlinux.bin");compression = "none"; 以及入口地址readelf -h vmlinux) 表示,但我在尝试启动时收到以下错误:

luton # bootm ${loadaddr}
## Loading kernel from FIT Image at 80100000 ...
   Using 'conf@luton_pcb091' configuration
   Trying 'kernel@0' kernel subimage
     Description:  Linux 5.11.0
     Type:         Kernel Image
     Compression:  uncompressed
     Data Start:   0x801000c0
     Data Size:    11584912 Bytes = 11 MiB
     Architecture: MIPS
     OS:           Linux
     Load Address: 0x80100000
     Entry Point:  0x809898f4
     Hash algo:    sha1
     Hash value:   d13175476fd38269a02a3e85bef53419092c01e1
   Verifying Hash Integrity ... sha1+ OK
## Loading fdt from FIT Image at 80100000 ...
   Using 'conf@luton_pcb091' configuration
   Trying 'fdt@luton_pcb091' fdt subimage
     Description:  img,luton_pcb091 Device Tree
     Type:         Flat Device Tree
     Compression:  uncompressed
     Data Start:   0x80c0c758
     Data Size:    2303 Bytes = 2.2 KiB
     Architecture: MIPS
     Hash algo:    sha1
     Hash value:   daa8a8147bbce692d81383af7b748a763212bb24
   Verifying Hash Integrity ... sha1+ OK
   Booting using the fdt blob at 0x80c0c758
   Loading Kernel Image
ERROR: new format image overwritten - must RESET the board to recover

查看 common/bootm.c 中的 bootm_load_os 似乎这个错误告诉我我正在尝试启动的内核之间有一些重叠......有些东西,我不是确定什么。

这里是内核5.11生成的vmlinux.its

/* SPDX-License-Identifier: GPL-2.0 */
/dts-v1/;
/ {
 description = "Linux 5.11.11";
 #address-cells = <1>;
 images {
  kernel@0 {
   description = "Linux 5.11.11";
   data = /incbin/("vmlinux.bin.gz");
   type = "kernel";
   arch = "mips";
   os = "linux";
   compression = "gzip";
   load = /bits/ 32 <0xffffffff80100000>;
   entry = /bits/ 32 <0xffffffff809898f4>;
   hash@0 {
    algo = "sha1";
   };
  };
 };
 configurations {
  default = "conf@default";
  conf@default {
   description = "Generic Linux kernel";
   kernel = "kernel@0";
  };
 };
};
/* SPDX-License-Identifier: (GPL-2.0 OR MIT) */
/ {
 images {
  fdt@luton_pcb091 {
   description = "MSCC Luton PCB091 Device Tree";
   data = /incbin/("boot/dts/mscc/luton_pcb091.dtb");
   type = "flat_dt";
   arch = "mips";
   compression = "none";
   hash@0 {
    algo = "sha1";
   };
  };
 };
 configurations {
  pcb091 {
   description = "Luton Linux kernel";
   kernel = "kernel@0";
   fdt = "fdt@luton_pcb091";
  };
 };
};

binwalk不表示ITB中的gzip数据无效:

$ binwalk vmlinux.gz.itb 

DECIMAL       HEXADECIMAL     DESCRIPTION
--------------------------------------------------------------------------------
0             0x0             device tree image (dtb)
192           0xC0            gzip compressed data, maximum compression, from Unix, last modified: 1970-01-01 00:00:00 (null date)
3960903       0x3C7047        MySQL ISAM compressed data file Version 10
5167968       0x4EDB60        device tree image (dtb)

mkimage version 2020.01 由 buildroot 作为 host-uboot-tools-2020.01

的一部分构建

根据 Tom Rini 的建议,我更改了 FIT 映像的 loadaddr 并且不再收到 uncompress 错误,但是系统似乎仍然没有启动。我已将其移至 .

你 运行 最后一个问题是:

ERROR: new format image overwritten - must RESET the board to recover

是因为你已经将图像加载到内存中与入口点相同的位置,但你需要将它加载到内存中其他地方,以便 U-Boot 可以解压图像并将内容放在它们的位置加载地址设置为。由于您有 128MB 的内存,因此您应该能够从一开始就将其设置为 +32 或 +64MB,然后一切正常。