如何将 zImage 转换为 uImage 以使用 u-boot 启动 Linux 内核

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

(在本文中,我们将展示如何将 zImage 转换为 uImage 以使用 U-Boot 启动 linux 内核映像。

因此,uImage 与 U-boot 的兼容性比 zImage 高得多,因为 uImage 可以被视为 U-boot 的原生 linux 内核文件。)

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.

(因此,uImage 与 U-boot 的兼容性比 zImage 高得多,因为 uImage 可以被视为 U-boot 的原生 linux 内核文件。)

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.

(为了使 U-boot 从 zImage 引导 Linux 内核映像,需要对源代码进行修改以允许使用 zImage 引导。使用 uImage(同样,U-boot 处理的更原生的文件),无需执行任何修改。)

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.

(在这时你可能会考虑到,zImage 和 uImage 实际上是一回事,除了 uImage 具有 U-boot 使用的标头信息,例如文件名、图像类型(如 arm)、加载地址、入口点等。)

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

(U-boot 使用此元标头数据来简化引导过程。)

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

(在这里,uImage 文件比 zImage 拥有更多的数据,U-boot 用于促进引导过程。)

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.

(但这没关系,因为 linux 操作系统中有一些软件工具允许您将此标头信息添加到 zImage 以创建 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.

(因此,您要做的第一件事是安装u-boot-tools。u-boot-tools软件具有命令mkimage,它允许我们从zImage创建uImage。)

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

(可以使用如下所示的以下代码行安装 u-boot 工具软件。)

sudo apt-get install u-boot-tools

This in the linux terminal is shown below.

(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.

(安装完成后,您需要获取zImage文件并确定其文件路径。对我来说,我去了德州仪器网站,下载了 am335x 芯片的 linux SDK,这是 beaglebone 黑板拥有的芯片。)

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

(此 SDK 包含用于 linux 内核的 zImage 且不包含 uImage。)

This can be seen below.

(请在下面查阅示例)

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.

(请注意,我们需要使用的 zImage 在上图中突出显示。这是我们需要指定的image,以便创建uImage,它将出现在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.

您也可以将 uboot 映像放在引导目录中,但必须指定该文件夹。

因此,现在让我们转到代码,它将创建uImage。如下所示。

mkimage -A arm -O linux -T kernel -C none -a 0x82000000 -e 0x82000000 -n "Linux kernel uImage" -d arch/arm/boot/zImage-5.10.100-g7a7a3af903 uImage

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.

因此,现在让我们回顾一下这段代码。

因此,如前所述,mkimage 是允许我们从 zImage 文件创建 uImage 文件的命令。

mkimage

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

我们首先指定设备的体系架构,在本例中为 ARM 架构。

-A arm -O linux 

We then specify that this is a kernel image.

然后,我们指定这是一个内核映像。

 -T kernel -C none

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.

接下来我们首先指定加载地址,这是 linux 内核将存储在设备的 RAM 中的地址。否则,加载地址是复制内核二进制映像的位置。

-a 0x82000000

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.

然后我们指定入口点地址,这是 U-boot 要执行的复制二进制文件的位置,以启动 linux 内核。这些地址可以是相同的,在这种情况下,它们是相同的。

-e 0x82000000

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".

然后,我们指定要为此uImage文件指定的名称。这可以是一个像“Linux kernel”一样简单和描述性的名称。

-n "Linux kernel uImage"

We then must specify the path to this zImage file.

We then specify, uImage.

然后,我们必须指定需转换的zImage 文件的路径。

然后我们指定uImage。

-d arch/arm/boot/zImage-5.10.100-g7a7a3af903 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.

如果希望 uImage 位于根目录以外的任何文件中,则应指定此 uImage 文件的路径。

此代码在终端中运行如下所示。

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.

您可以看到添加到 zImage 文件的所有标头“元数据”,这使得 U-boot 文件比 zImage 文件更丰富。

运行此代码后,我们现在在根目录中看到 uImage,如下所示。

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.

所以现在这个uImage文件可以直接与U-boot一起使用来引导Linux内核,而无需对U-boot代码进行任何修改。

因此,这就是我们将zImage文件转换为uImage文件以使用U-boot启动Linux内核映像的方法。

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值