Skip to contentSkip to conversation

Extend 'bootm' to support Linux kernel generated images

RFC In review Tom Rini 4 participants 10 messages May 21, 2014 – Jul 8, 2014 Arm (32-bit)

lore
Share & tools
lore

Tom Rini

author
#0 lore raw

RFC 1/1 Extend 'bootm' to support Linux kernel generated images

Hey all,

Something that Rob mentioned to me at ELC, and others have mentioned before is that it would be nice if 'bootm' (which says "boot application image stored in memory" in the help, even) would just work with zImage or Image or whatever is spit directly out of the kernel.

The following shows roughly what I'm thinking about how we would handle this:

arch/arm/lib/bootm.c +11 -0
index 0706086..14319b2 100644
@@ -332,6 +332,17 @@ struct zimage_header {
 
 #define	LINUX_ARM_ZIMAGE_MAGIC	0x016f2818
 
+int check_image_linux_kernel(ulong image)
+{
+	struct zimage_header *zi;
+
+	zi = (struct zimage_header *)map_sysmem(image, 0);
+	if (zi->zi_magic == LINUX_ARM_ZIMAGE_MAGIC)
+		return 0;
+
+	return 1;
+}
+
 int bootz_setup(ulong image, ulong *start, ulong *end)
 {
 	struct zimage_header *zi;
common/cmd_bootm.c +10 -0
index 30fd643..6bed825 100644
@@ -274,6 +274,11 @@ static int bootm_find_os(cmd_tbl_t *cmdtp, int flag, int argc,
 		}
 		break;
 #endif
+#ifdef CONFIG_BOOTM_LINUX_RAW
+	case IMAGE_FORMAT_LINUX:
+		/* Call something to set images.os.things */
+		return 0;
+#endif
 	default:
 		puts("ERROR: unknown image format type!\n");
 		return 1;
@@ -1002,6 +1007,11 @@ static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
 		images->fit_noffset_os = os_noffset;
 		break;
 #endif
+#ifdef CONFIG_BOOTM_LINUX_RAW
+	case IMAGE_FORMAT_LINUX:
+		/* Set loadaddr? */
+		return 0;
+#endif
 	default:
 		printf("Wrong Image Format for %s command\n", cmdtp->name);
 		bootstage_error(BOOTSTAGE_ID_FIT_KERNEL_INFO);
common/image.c +4 -0
index fcc5a9c..32237a3 100644
@@ -665,6 +665,10 @@ int genimg_get_format(const void *img_addr)
 			format = IMAGE_FORMAT_FIT;
 	}
 #endif
+#ifdef CONFIG_BOOTM_LINUX_RAW
+	if (check_image_linux_kernel((ulong)img_addr) == 0)
+		return IMAGE_FORMAT_LINUX;
+#endif
 
 	return format;
 }
include/image.h +10 -0
index b278778..985c6f0 100644
@@ -411,6 +411,7 @@ enum fit_load_op {
 #ifndef USE_HOSTCC
 /* Image format types, returned by _get_format() routine */
 #define IMAGE_FORMAT_INVALID	0x00
+#define IMAGE_FORMAT_LINUX	0xFF	/* Linux kernel defined formats */
 #define IMAGE_FORMAT_LEGACY	0x01	/* legacy image_header based format */
 #define IMAGE_FORMAT_FIT	0x02	/* new, libfdt based format */
 
@@ -660,6 +661,15 @@ int image_setup_libfdt(bootm_headers_t *images, void *blob,
 int image_setup_linux(bootm_headers_t *images);
 
 /**
+ * Check if the given location has some form of Linux-kernel generated
+ * image.
+ *
+ * @param image		Potential image location
+ * @return 0 if OK, 1 if not a known Linux-kernel generated image.
+ */
+int check_image_linux_kernel(ulong image);
+
+/**
  * bootz_setup() - Extract stat and size of a Linux xImage
  *
  * @image: Address of image

It of course doesn't work and just shows where I think we would need to fill things in and probably provide some __weak functions for other arches. Looking over how we do bootz today, and how I wrote booti for arm64, it should be possible to do the correct callouts at the correct places for "oh, we don't have a legacy or FIT header, we have a per Linux architecture defined header".

What does everyone think about extending things in this direction?

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140521/9b392459/attachment.pgp>
#1 lore raw

Dear Tom Rini,

Quoted 5 lines · In message <20140521195824.GE1752@bill-the-cat> you wrote:

Something that Rob mentioned to me at ELC, and others have mentioned before is that it would be nice if 'bootm' (which says "boot application image stored in memory" in the help, even) would just work with zImage or Image or whatever is spit directly out of the kernel.

I don;t think this is a good idea. "application image" is supposed to mean "one of the U-Boot image formats", which means the old legacy image format (with the 64 byte header), or FIT images. To boot a zImage file, we have the "bootz" command.

I also think such a patch is pushing into the wrong direction. We should rather try and improve the kernel support for FIT images.

arch/arm/lib/bootm.c struct zimage_header { · line 341

Quoted 3 lines
arch/arm/lib/bootm.c +3 -0
+	zi = (struct zimage_header *)map_sysmem(image, 0);
+	if (zi->zi_magic == LINUX_ARM_ZIMAGE_MAGIC)
+		return 0;

I smell endianess issues here?

Quoted 1 line

+#ifdef CONFIG_BOOTM_LINUX_RAW

LINUX_RAW ?

Quoted 5 lines

/* Image format types, returned by _get_format() routine */
#define IMAGE_FORMAT_INVALID 0x00
+#define IMAGE_FORMAT_LINUX 0xFF /* Linux kernel defined formats */
#define IMAGE_FORMAT_LEGACY 0x01 /* legacy image_header based format */
#define IMAGE_FORMAT_FIT 0x02 /* new, libfdt based format */

This does not look clean to me.

Quoted 8 lines

It of course doesn't work and just shows where I think we would need to fill things in and probably provide some __weak functions for other arches. Looking over how we do bootz today, and how I wrote booti for arm64, it should be possible to do the correct callouts at the correct places for "oh, we don't have a legacy or FIT header, we have a per Linux architecture defined header".

What does everyone think about extending things in this direction?

I am no real friend of trying to be clever and automatically guess image formats. In my opinion it is more reliable to be able to verify if an image os OK or corrupted, instead of passing a corrupted image on to guesswork which might then belive it could be some other image format (without checksums or such) and try to run it.

The user should give U-Boot a clear hint which image format to expect, and allow U-Boot to complain otherwise.

If someone really wants such a trial and error approach, he can still do this without adding code that affects everybody with just a little scripting - like "bootm $addr || bootz $addr || ...".

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Conscious is when you are aware of something, and conscience is  when
you wish you weren't.
author
#2 lore raw
Quoted 9 lines · Wolfgang Denk

Dear Tom Rini,

Quoted 5 lines · In message <20140521195824.GE1752@bill-the-cat> you wrote:

Something that Rob mentioned to me at ELC, and others have mentioned before is that it would be nice if 'bootm' (which says "boot application image stored in memory" in the help, even) would just work with zImage or Image or whatever is spit directly out of the kernel.

Quoted 4 lines

I don;t think this is a good idea. "application image" is supposed to mean "one of the U-Boot image formats", which means the old legacy image format (with the 64 byte header), or FIT images. To boot a zImage file, we have the "bootz" command.

Yes, it's historically meant something with an essentially (technically no, practically, yes) U-Boot centric header on it. But that's not what the help text says. And yes we have bootz for zImages and I added booti for Image images. That resulted in "You mean I have to type different things for arm and arm64? *sigh*" when explaining this in person.

Quoted 2 lines

I also think such a patch is pushing into the wrong direction. We should rather try and improve the kernel support for FIT images.

That's neither here nor there. You can create and boot FIT images today, anywhere it's enabled (including arm64). You can do the same with legacy images (which also resulted in sighs when I mentioned this). The kernel doesn't want any of this in the kernel tree. Developers want to have as few steps between "build my kernel" and "now I'm testing my kernel". Adding in "create / grab stub FIT file, run mkimage" results in more unhappy developers.

Quoted 5 lines

arch/arm/lib/bootm.c struct zimage_header { · line 341

Quoted 3 lines
arch/arm/lib/bootm.c +3 -0
+	zi = (struct zimage_header *)map_sysmem(image, 0);
+	if (zi->zi_magic == LINUX_ARM_ZIMAGE_MAGIC)
+		return 0;

I smell endianess issues here?

We don't do BE ARM atm anyhow, so one more in the pile of many, most likely.

Quoted 3 lines
Quoted 1 line

+#ifdef CONFIG_BOOTM_LINUX_RAW

LINUX_RAW ?

Yeah. We can grab the color wheel for the bikeshed later, if we go down this path :)

Quoted 7 lines
Quoted 5 lines

/* Image format types, returned by _get_format() routine */
#define IMAGE_FORMAT_INVALID 0x00
+#define IMAGE_FORMAT_LINUX 0xFF /* Linux kernel defined formats */
#define IMAGE_FORMAT_LEGACY 0x01 /* legacy image_header based format */
#define IMAGE_FORMAT_FIT 0x02 /* new, libfdt based format */

This does not look clean to me.

I could call it 0x03 too. I was trying to signify that it's basically a lack of well defined header. A legacy image is a legacy image, a FIT image is a FIT image, a Linux image depends on what arch you're talking about.

Quoted 7 lines
Quoted 7 lines

It of course doesn't work and just shows where I think we would need to fill things in and probably provide some __weak functions for other arches. Looking over how we do bootz today, and how I wrote booti for arm64, it should be possible to do the correct callouts at the correct places for "oh, we don't have a legacy or FIT header, we have a per Linux architecture defined header".

Quoted 7 lines
Quoted 1 line

What does everyone think about extending things in this direction?

I am no real friend of trying to be clever and automatically guess image formats. In my opinion it is more reliable to be able to verify if an image os OK or corrupted, instead of passing a corrupted image on to guesswork which might then belive it could be some other image format (without checksums or such) and try to run it.

It is not impossible that a FIT image could become corrupt in just the wrong way to have the zImage (or Image or whatever the arch supports) magic value and then go horribly awry. It seems exceedingly unlikely however.

Quoted 6 lines

The user should give U-Boot a clear hint which image format to expect, and allow U-Boot to complain otherwise.

If someone really wants such a trial and error approach, he can still do this without adding code that affects everybody with just a little scripting - like "bootm $addr || bootz $addr || ...".

That's not the usecase really. The usecase is roughly "I just want to boot what the kernel build spit out and not have to guess the command".

How about if we added a new command, 'boota[uto]' to make a few stabs at guessing the format? The first problem that pops to mind here is passing around some flag to make sure that bootm doesn't get this new behaviour.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140521/0fa01f6e/attachment.pgp>
#3 lore raw

Hi Tom,

Quoted 24 lines · Tom Rini
Quoted 9 lines · Wolfgang Denk

Dear Tom Rini,

Quoted 5 lines · In message <20140521195824.GE1752@bill-the-cat> you wrote:

Something that Rob mentioned to me at ELC, and others have mentioned before is that it would be nice if 'bootm' (which says "boot application image stored in memory" in the help, even) would just work with zImage or Image or whatever is spit directly out of the kernel.

Quoted 4 lines

I don;t think this is a good idea. "application image" is supposed to mean "one of the U-Boot image formats", which means the old legacy image format (with the 64 byte header), or FIT images. To boot a zImage file, we have the "bootz" command.

Yes, it's historically meant something with an essentially (technically no, practically, yes) U-Boot centric header on it. But that's not what the help text says. And yes we have bootz for zImages and I added booti for Image images. That resulted in "You mean I have to type different things for arm and arm64? *sigh*" when explaining this in person.

Quoted 2 lines

I also think such a patch is pushing into the wrong direction. We should rather try and improve the kernel support for FIT images.

Quoted 7 lines

That's neither here nor there. You can create and boot FIT images today, anywhere it's enabled (including arm64). You can do the same with legacy images (which also resulted in sighs when I mentioned this). The kernel doesn't want any of this in the kernel tree. Developers want to have as few steps between "build my kernel" and "now I'm testing my kernel". Adding in "create / grab stub FIT file, run mkimage" results in more unhappy developers.

Unless I'm imagining it, some years ago I could type 'make fit_image' or similar for the kernel and get an image ready to boot. Did someone remove that feature from Linux and expect the number of steps needed to build a kernel to stay the same?

It surprises me the lengths to which people are going to try to shoehorn .dtbs, compression, multiple dtbs, multi-arch etc. into the kenel zImage format. The decompression header is ugly, plus it is slower than doing these things in U-Boot.

Regards,
Simon

author
#4 lore raw
Quoted 35 lines · Simon Glass

Hi Tom,

Quoted 24 lines · Tom Rini
Quoted 9 lines · Wolfgang Denk

Dear Tom Rini,

Quoted 5 lines · In message <20140521195824.GE1752@bill-the-cat> you wrote:

Something that Rob mentioned to me at ELC, and others have mentioned before is that it would be nice if 'bootm' (which says "boot application image stored in memory" in the help, even) would just work with zImage or Image or whatever is spit directly out of the kernel.

Quoted 4 lines

I don;t think this is a good idea. "application image" is supposed to mean "one of the U-Boot image formats", which means the old legacy image format (with the 64 byte header), or FIT images. To boot a zImage file, we have the "bootz" command.

Yes, it's historically meant something with an essentially (technically no, practically, yes) U-Boot centric header on it. But that's not what the help text says. And yes we have bootz for zImages and I added booti for Image images. That resulted in "You mean I have to type different things for arm and arm64? *sigh*" when explaining this in person.

Quoted 2 lines

I also think such a patch is pushing into the wrong direction. We should rather try and improve the kernel support for FIT images.

Quoted 7 lines

That's neither here nor there. You can create and boot FIT images today, anywhere it's enabled (including arm64). You can do the same with legacy images (which also resulted in sighs when I mentioned this). The kernel doesn't want any of this in the kernel tree. Developers want to have as few steps between "build my kernel" and "now I'm testing my kernel". Adding in "create / grab stub FIT file, run mkimage" results in more unhappy developers.

Quoted 4 lines

Unless I'm imagining it, some years ago I could type 'make fit_image' or similar for the kernel and get an image ready to boot. Did someone remove that feature from Linux and expect the number of steps needed to build a kernel to stay the same?

It wasn't in mainline, I'm fairly certain. Or maybe it was an arch/ppc thing that got dropped along the way.

Quoted 4 lines

It surprises me the lengths to which people are going to try to shoehorn .dtbs, compression, multiple dtbs, multi-arch etc. into the kenel zImage format. The decompression header is ugly, plus it is slower than doing these things in U-Boot.

Well, with arm64 the kernel is just getting out of the business, hence booti (or however we add Image support) and not do the zImage dance.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140524/96dcde0c/attachment.pgp>
#5 lore raw

Hi Tom,

Quoted 41 lines · Tom Rini
Quoted 10 lines · Simon Glass

Hi Tom,

Quoted 7 lines · Tom Rini
Quoted 6 lines · Wolfgang Denk

Dear Tom Rini,

Quoted 3 lines · In message <20140521195824.GE1752@bill-the-cat> you wrote:

Something that Rob mentioned to me at ELC, and others have mentioned before is that it would be nice if 'bootm' (which says "boot

application

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

image stored in memory" in the help, even) would just work with

zImage

Quoted 10 lines
Quoted 10 lines
Quoted 6 lines
Quoted 1 line

or Image or whatever is spit directly out of the kernel.

I don;t think this is a good idea. "application image" is supposed to mean "one of the U-Boot image formats", which means the old legacy image format (with the 64 byte header), or FIT images. To boot a zImage file, we have the "bootz" command.

Yes, it's historically meant something with an essentially (technically no, practically, yes) U-Boot centric header on it. But that's not what the help text says. And yes we have bootz for zImages and I added

booti

Quoted 9 lines
Quoted 9 lines

for Image images. That resulted in "You mean I have to type different things for arm and arm64? *sigh*" when explaining this in person.

Quoted 2 lines

I also think such a patch is pushing into the wrong direction. We should rather try and improve the kernel support for FIT images.

That's neither here nor there. You can create and boot FIT images today, anywhere it's enabled (including arm64). You can do the same with legacy images (which also resulted in sighs when I mentioned

this).

Quoted 1 line
Quoted 1 line

The kernel doesn't want any of this in the kernel tree. Developers

want

Quoted 4 lines
Quoted 3 lines

to have as few steps between "build my kernel" and "now I'm testing my kernel". Adding in "create / grab stub FIT file, run mkimage" results in more unhappy developers.

Quoted 8 lines
Quoted 4 lines

Unless I'm imagining it, some years ago I could type 'make fit_image' or similar for the kernel and get an image ready to boot. Did someone remove that feature from Linux and expect the number of steps needed to build a kernel to stay the same?

It wasn't in mainline, I'm fairly certain. Or maybe it was an arch/ppc thing that got dropped along the way.

I took at look and now think I just imagined it, or perhaps had some patches applied.

Quoted 9 lines
Quoted 5 lines

It surprises me the lengths to which people are going to try to shoehorn .dtbs, compression, multiple dtbs, multi-arch etc. into the kenel zImage format. The decompression header is ugly, plus it is slower than doing these things in U-Boot.

Well, with arm64 the kernel is just getting out of the business, hence booti (or however we add Image support) and not do the zImage dance.

Does this mean a clean Image with no add-ons?

Regards,
Simon

author
#6 lore raw
Quoted 5 lines · Simon Glass

Hi Tom,

Quoted 1 line · Tom Rini

On Fri, May 23, 2014 at 03:57:34PM -1000, Simon Glass wrote:

[snip]

Quoted 9 lines
Quoted 7 lines
Quoted 4 lines

It surprises me the lengths to which people are going to try to shoehorn .dtbs, compression, multiple dtbs, multi-arch etc. into the kenel zImage format. The decompression header is ugly, plus it is slower than doing these things in U-Boot.

Well, with arm64 the kernel is just getting out of the business, hence booti (or however we add Image support) and not do the zImage dance.

Does this mean a clean Image with no add-ons?

Yes, Image only, and different from arch/arm/boot/Image. Leaving the details of how to find/place the device tree and initrd up to the bootloader.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140603/4e2cf5af/attachment.pgp>
#7 lore raw

Hi Tom,

Quoted 12 lines · Tom Rini
Quoted 5 lines · Simon Glass

Hi Tom,

Quoted 1 line · Tom Rini

On Fri, May 23, 2014 at 03:57:34PM -1000, Simon Glass wrote:

[snip]

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

It surprises me the lengths to which people are going to try to shoehorn .dtbs, compression, multiple dtbs, multi-arch etc. into the kenel zImage format. The decompression header is ugly, plus it is slower than doing these things in U-Boot.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Well, with arm64 the kernel is just getting out of the business, hence booti (or however we add Image support) and not do the zImage dance.

Does this mean a clean Image with no add-ons?

Yes, Image only, and different from arch/arm/boot/Image. Leaving the details of how to find/place the device tree and initrd up to the bootloader.

That sounds promising. So no more decompression / serial UART / cache-enable header?

Regards,
Simon

author
#8 lore raw
Quoted 18 lines · Simon Glass

Hi Tom,

Quoted 15 lines · Tom Rini
Quoted 5 lines · Simon Glass

Hi Tom,

Quoted 1 line · Tom Rini

On Fri, May 23, 2014 at 03:57:34PM -1000, Simon Glass wrote:

[snip]

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

It surprises me the lengths to which people are going to try to shoehorn .dtbs, compression, multiple dtbs, multi-arch etc. into the kenel zImage format. The decompression header is ugly, plus it is slower than doing these things in U-Boot.

Well, with arm64 the kernel is just getting out of the business, hence booti (or however we add Image support) and not do the zImage dance.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Does this mean a clean Image with no add-ons?

Yes, Image only, and different from arch/arm/boot/Image. Leaving the details of how to find/place the device tree and initrd up to the bootloader.

That sounds promising. So no more decompression / serial UART / cache-enable header?

For the time being, yes. We'll see what happens when more people are using real hardware rather than simulator and not the boot-wrapper tool.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140603/d06c7211/attachment.pgp>
#9 lore raw
In reply to Tom Rini
Quoted 5 lines
Quoted 4 lines

If someone really wants such a trial and error approach, he can still do this without adding code that affects everybody with just a little scripting - like "bootm $addr || bootz $addr || ...".

Quoted 7 lines

That's not the usecase really. The usecase is roughly "I just want to boot what the kernel build spit out and not have to guess the command".

How about if we added a new command, 'boota[uto]' to make a few stabs at guessing the format? The first problem that pops to mind here is passing around some flag to make sure that bootm doesn't get this new behaviour.

For the record, boota would be nice. Count me as one of developers that dislike the extra steps...

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html