How to Convert a zImage to a uImage to Boot a Linux Kernel with U-Boot

Beaglebone black board






In this article, we will show how to convert a zImage to a uImage to boot a linux kernel image with U-Boot.

So a uImage is much more compatible with U-boot than a zImage, because uImage can be seen as the more native linux kernel file to U-boot.

In order for U-boot to boot a linux kernel image from a zImage, modifications will need to be done to the source code to allow for booting with a zImage. With a uImage (again, the more native file that U-boot deals with), no modifications need to be performed.

Just in case you're wondering, a zImage and a uImage are really the same thing, with the exception that a uImage has header information that U-boot uses, such as the name of the file, the image type (such as arm), the load address, the entry point, etc.

U-boot uses this meta header data to facilitate the booting process.

In this way, a uImage file has more data that U-boot uses to faciltate the booting process than a zImage has.

But that's ok, because there are software tools available in the linux operating system that allows you to add this header information to a zImage to create a uImage.

So the first thing that you are to do is install the u-boot-tools. The u-boot-tools software has the command mkimage, which allows us to create a uImage from a zImage.

The u-boot-tools software can be installed using the following line of code shown below.





This in the linux terminal is shown below.


Installing u-boot-tools in linux


Once you have this installed, then you need to take your zImage file and determine its file path.

For me, I went to Texas Instruments site and downloaded the linux SDK for am335x chips, which is the chip that the beaglebone black board has.

This SDK contained a zImage for the linux kernel and did not contain a uImage.

This can be seen below.


zImage file in the boot folder of the AM335x linux SDK


Notice that the zImage that we need to work with is highlighted in the image above. This is the image we need to specify in order to create a uImage, which will appear in the root directory of the AM335x linux SDK.

You can also place the uboot image in the boot directory, but you would have to specify that folder.

So let's now go to the code, which will create the uImage. This is shown below.





So let's now review this code.

So, as stated previously, the mkimage is the command that allows us to create a uImage image file from a zImage file.

We first specify the architecture of the device, which in this case is ARM architecture.

We then specify that this is a kernel image.

Next we first specify the load address, which is the address where the linux kernel will be stored in the RAM of the device. Or otherwise, it the load address is where the kernel binary image is copied.

We then specify the entry point address, which is the location of the copied binary to be executed by U-boot to boot the linux kernel. These addresses can be the same and in this case, they are.

We then specify the name that we want to give to this uImage file. This can be a name as simple and descriptive as "Linux kernel".

We then must specify the path to this zImage file.

We then specify, uImage.

If you want uImage to be in any file other than the root directory, then you would specify the path to this uImage file.

This code run in the terminal is shown below.


Converting a zImage to a uImage using the mkimage command in linux


You can see all the header "meta data" that is added to the zImage file, making a U-boot file more data rich than a zImage file.

After running this code, we now see the uImage in the root directory, as shown below.


uImage file created from zImage file using the mkimage command in linux


So now this uImage file can be used directly with U-boot to boot a linux kernel without needed any modifications to the U-boot code.

So this is how we can convert a zImage file to a uImage file to boot a linux kernel image with U-boot.



Related Resources





HTML Comment Box is loading comments...