linux - 为什么使用 uImage 而不是 zImage

标签 linux kernel boot u-boot

我正在尝试了解 zImage 和 uImage 之间的区别。

在我的理解中,uImage 是通过在 Image 上运行 mkimage 得到的,结果它添加了一个 U-Boot 包装器(我不'知道它到底包含什么)包含一个header加上加载地址和入口点,也许还有我不知道的“额外信息”。

另一方面,zImage 是压缩的 Image,它不包含加载地址和入口点(我的想法,如果我是,请纠正我错误)而且 U-Boot 也可以使用 bootz 加载它。

  • 在这种情况下,为什么要使用 uImage 而不是 zImage

  • 我很想知道 zImage 和 uImage 的格式是什么,您能推荐一些引用资料吗?

最佳答案

In my understanding uImage is got by running mkimage on the Image

你的理解只对了一部分。
uImage 可以包含任何类型的文件,并不限于 Linux Image 文件。事实上,它不太可能是(未压缩的)Image 文件(因为这不是传统的 ma​​ke 选项)。

In the other hand the zImage is the compressed Image, it doesn't contain the load address and entry point(what i think, correct me if i'am [sic] wrong)

你错了,zImage 确实包含内核的加载地址和入口点。需要加载地址才能将内核镜像解压缩到正确的 RAM 地址。解压后需要内核的入口点来执行。
在为 ARM 构建 Image 和 zImage 时,Makefile 使用

ZRELADDR == virt_to_phys(PAGE_OFFSET + TEXT_OFFSET)

应该转换为物理内存的开始 + 0x8000。

zImage 本身(即自解压程序)是 PIC,位置无关代码。 zImage 可以加载到 RAM 中的任何位置,并在它的首地址执行,即它的入口点是它的加载地址。

In this case why using a uImage instead of a zImage?

对于旧版本的 U-Boot,别无选择,因为 bootz 命令可能不适用于 Linux 内核。
现在这可能是一个主观的选择。

请注意,Linux 内核社区对在内核中支持 U-Boot 存在一些不满。 IOW 如果有人按照他们的方式行事,我的印象是您将无法从主线源构建 uImage

I'am [sic] curious to learn what are the formats of a zImage and a uImage could you please suggest some references ?

zImage 的布局基本上由其链接器规范指定。
对于 ARM,请参阅 arch/arm/boot/compressed/vmlinux.lds.S .
请注意,_magic_start 包含无意义的加载地址。 Vincent Sanders 的第 5 节中也提到了这一点 Booting ARM Linux

The zImage has a magic number and some useful information near its beginning.

Table 2. Useful fields in zImage head code
Offset into zImage  Value       Description
    0x24        0x016F2818      Magic number used to identify this is an ARM Linux zImage
    0x28        start address   The address the zImage starts at
    0x2C        end address     The address the zImage ends at

The start and end offsets can be used to determine the length of the compressed image (size = end - start).  
 ...  
The start address is usually 0 as the zImage code is position independent.

但请注意,ARM 启动要求已被 Russel King 的 Documentation/arm/booting 取代

uImage 的布局只是 U-Boot header 加上图像文件,无论是什么。

(希望我写的没有和 Tom Rini 写的相矛盾。)

关于linux - 为什么使用 uImage 而不是 zImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45314335/

相关文章:

linux - 了解 bootmem 的工作原理

linux - 如何为现有的 SVN 颠覆服务器添加新用户帐户?

c - 将目录依赖项指定为百分比规则时,Linux 上的 Make 行为非常奇怪

linux - 使用 Gambas 处理 Linux SIGnals

c - 通过串行端口将 GDB 连接到 KGDB 构建内核的问题

java - 调试在启动时运行的应用程序

linux - 存储 ls -ltr| 的倒数第二个目录的名称tail -2 输出到变量中

linux-kernel - 将 mmap 内核引导参数保留的内存映射到用户空间

c - 如何将测试用例添加到 ltp

operating-system - 基本启动条款