为什么内核的加载地址,ramdisk在引导中很重要?

why is load address of kernel, ramdisk important in booting?

我正在处理 android boot.img,它是压缩内核、ramdisk 和 dtb 的组合。我从 uboot 的串行控制台日志中看到有关启动过程的信息,这是触发我好奇心的部分

CPU:   Freescale i.MX6Q rev1.2 at 792 MHz
CPU:   Temperature 27 C
Reset cause: POR
Board: MX6-SabreSD
I2C:   ready
DRAM:  1 GiB
PMIC:  PFUZE100 ID=0x10
MMC:   FSL_SDHC: 0, FSL_SDHC: 1, FSL_SDHC: 2
No panel detected: default to Hannstar-XGA
Display: Hannstar-XGA (1024x768)
In:    serial
Out:   serial
Err:   serial
check_and_clean: reg 0, flag_set 0
Fastboot: Normal
flash target is MMC:1
Net:   FEC [PRIME]
Normal Boot
Hit any key to stop autoboot:  3  2  1  0 
boota mmc1 
kernel   @ 14008000 (7272352)
ramdisk  @ 15000000 (869937)
fdt      @ 14f00000 (44072)
## Booting Android Image at 0x12000000 ...
Kernel load addr 0x14008000 size 7102 KiB
Kernel command line: console=ttymxc0,115200 init=/init video=mxcfb0:dev=hdmi,1920x1080M@60,bpp=32 video=mxcfb1:off video=mxcfb:off video=mxcfb3:off vmalloc=256M androidboot.console=ttymxc0 consolebalank=0 androidboot.hardware=freescale cma=384M
## Flattened Device Tree blob at 14f00000
   Booting using the fdt blob at 0x14f00000
   Loading Kernel Image ... OK
   Using Device Tree in place at 14f00000, end 14f0dc27
switch to ldo_bypass mode!

Starting kernel ...

内核地址为14008000,ramdisk 15000000,fdt 14f00000。 我发现这些值保存在 boot.img header 中,当我手动修改这些值时,即使实际内容没有被修改,图像也不会启动。

为什么这个地址如此重要?为什么必须是这些值?为什么不是其他值?

我自己的一个猜测是: 这些加载地址值在内核中被硬编码,所以如果我在 boot.img header 中更改它,它将导致 side-effects。详细说明我自己的理论,将内核加载到 'modified' 加载地址不会有问题。但是当实际执行这些行时,它会导致严重的问题,因为这些代码是固定的,可以使用正确的 'load addr'.

我的理论错了吗?如果是这样,请指正。

U-boot 完成后,需要将进一步的执行移交给内核,以便内核处理所有后续进程。另外,内核有一些例程,这些例程对于初始化电路板是必不可少的。
这组例程有一个入口点start_kernel(). Before this some other routines are also called to execute start_kernel. That can be identified by this linker script and this init.S

为了保持这个程序的执行,内核需要从一个特定的地址启动,而且它的数据段和其他内存也与之相连,以便加载和运行所有这些以适当的方式,准确需要提供内存位置。

这个内核需要设备树 blob 来探测连接到它的设备和 rootfs 来调出用户 space,在这里加载设备树和 rootfs 需要精确的偏移量以便任何数据不应遗漏或损坏。每个字节对于所有这些执行都很重要。

因此,为了安全启动,所有这些值都存储在引导加载程序的配置中。