Linux 内核镜像
What is the difference between Image vs zImage vs uImage?
I know that u-boot needs a kernel in uImage format.
The system I use first boots from stage 1 loader and then it calls u-boot. I want to discard u-boot and directly boot from stage 1 loader. Which type of kernel image do I have to use?
Image: the generic Linux kernel binary image file.
zImage: a compressed version of the Linux kernel image that is self-extracting.
uImage: an image file that has a U-Boot wrapper (installed by the mkimage utility) that includes the OS type and loader information. A very common practice (e.g. the typical Linux kernel Makefile) is to use a zImage file. Since a zImage file is self-extracting (i.e. needs no external decompressors), the wrapper would indicate that this kernel is "not compressed" even though it actually is.
Actually it's pretty stupid to use a zImage inside an uImage. It is much better to use normal (uncompressed) kernel image, compress it using just gzip, and use this as poayload for mkimage. This way U-Boot does the uncompresiong instead of including yet another uncompressor with each kernel image.
实际上,在 uImage 中使用 zImage 是相当愚蠢的。最好使用普通(未压缩的)内核映像,使用 gzip 压缩它,并将其作为 mkimage 的 poayload。这样 U-Boot 就可以解压缩,而不是在每 个内核映像中包含另一个解压缩器。
Which type of kernel image do I have to use?
You could choose whatever you want to program for. For economy of storage, you should probably chose a compressed image over the uncompressed one. Beware that executing the kernel (presumably the Linux kernel) involves more than just loading the kernel image into memory. Depending on the architecture (e.g. ARM) and the Linux kernel version (e.g. with or without DTB), there are registers and memory buffers that may have to be prepared for the kernel. In one instance there was also hardware initialization that U-Boot performed that had to be replicated.
I know that u-boot needs a kernel in uImage format.
That is accurate for all versions of U-Boot which only have the bootm command. But more recent versions of U-Boot could also have the bootz command that can boot a zImage.
My undrestanding is zImage = compressed Image uImage = Image + uBoot wrapper, correct me if i 'am wrong, the uBoot wrapper contains uBoot header and extra informations such boot device load address, entry point, but i couldn't find references showing the whole format of a uImage could you please share links on that
Thank you for the feedback, I have found resources about uImage header format. What i didn't understand is:1- where can i find the load address (boot device load addres) and entry point in the uImage (they don't exist in the header) 2- does a zImage contains these informations (load address and entry point), these is why i'am asking about the formats of both a zImage and a uImage
内核编译(make)之后会生成两个文件,一个Image,一个zImage,其中Image为内核映像文件,而zImage为内核的一种映像压缩文件,Image大约为4M,而zImage不到2M。
uImage是uboot专用的映像文件,它是在zImage之前加上一个长度为64字节的“头”,说明这个内核的版本、加载位置、生成时间、大小等信息;其0x40之后与zImage没区别。
制作uImage文件首先在uboot的/tools目录下寻找mkimage文件,把其copy到系统/usr/local/bin目录下,这样就完成制作工具。然后在内核目录下运行make uImage。
如果成功,便可以在arch/arm/boot/目录下发现uImage文件,其大小比zImage多64个字节。 也可以在kernel下生成zImage后手动执行mkimage来生成uImage,不过需要一些参数。
其实就是一个自动跟手动的区别,有了uImage头部的描述,u-boot就知道对应Image的信息,如果没有头部则需要自己手动去搞那些参数。 U-boot的U是“通用”的意思。
zImage是ARM Linux常用的一种压缩映像文件,uImage是U-boot专用的映像文件,它是在zImage之前加上一个长度为0x40的“头”,说明这个映像文件的类型、加载位置、生成时间、大小等信息。
换句话说,如果直接从uImage的0x40位置开始执行,zImage和uImage没有任何区别。另外,Linux2.4内核不支持uImage,Linux2.6内核加入了很多对嵌入式系统的支持,但是uImage的生成也需要设置。
几种 linux 内核文件的区别:
- vmlinux 编译出来的最原始的内核elf文件,未压缩。
- zImage 是vmlinux经过objcopy gzip压缩后的文件, objcopy实现由vmlinux的elf文件拷贝成纯二进制数据文件。
- bzImage bz表示“big zImage”,不是用bzip2压缩的。两者的不同之处在于,zImage解压缩内核到低端内存(第一个640K),bzImage解压缩内核到高端内存(1M以上)。如果内核比较小,那么采用zImage或bzImage都行,如果比较大应该用bzImage。
- uImage U-boot专用的映像文件,它是在zImage之前加上一个长度为0x40的tag。
- vmlinuz 是bzImage/zImage文件的拷贝或指向bzImage/zImage的链接。
- initrd 是“initial ramdisk”的简写。一般被用来临时的引导硬件到实际内核vmlinuz能够接管并继续引导的状态。 一般情况下都在生成 vmlinux 后,再对内核进行压缩成为 zImage,压缩的目录是 kernel/arch/arm/boot。
zImage由vmlinux objcopy出来的纯二进制文件以及解压缩程序组成,zImage自带了解压缩程序,大体结构如下:
内核编译(make)之后会生成两个文件,一个Image,一个zImage,其中Image为内核映像文件,而zImage为内核的一种映像压缩文件,Image大约为4M,而zImage不到2M。
那么uImage又是什么的?它是uboot专用的映像文件,它是在zImage之前加上一个长度为64字节的“头”,说明这个内核的版本、加载位置、生成时间、大小等信息;其0x40之后与zImage没区别。
zImage是ARM Linux常用的一种压缩映像文件,uImage是U-boot专用的映像文件,它是在zImage之前加上一个长度为0x40的“头”,说明这个映像文件的类型、加载位置、生成时间、大小等信息。换句话说,如果直接从uImage的0x40位置开始执行,zImage和uImage没有任何区别。