Support u-boot noload images for arm as used by, NetBSD/evbarm GENERIC kernel.
PATCH v3 1/1 Support u-boot noload images for arm as used by, NetBSD/evbarm GENERIC kernel.
noload kernels are loaded with the u-boot image header and as a result the header size needs adding to the entry point. Fake up a hdr so the kernel image is loaded at the right address and the entry point is adjusted appropriately.
The bootloader fits in the space that the uboot header would have occupied.
Clarify the load_uimage API to state the passing of a load address when an image doesn't specify one, or when loading a ramdisk is expected.
Adjust callers of load_uimage, etc.
---
hw/arm/boot.c | 8 +++++---
hw/core/loader.c | 19 ++++++++++++++++---
hw/core/uboot_image.h | 1 +
hw/microblaze/boot.c | 2 +-
hw/nios2/boot.c | 2 +-
hw/ppc/e500.c | 1 +
hw/ppc/ppc440_bamboo.c | 2 +-
hw/ppc/sam460ex.c | 2 +-
include/hw/loader.h | 7 ++++++-
9 files changed, 33 insertions(+), 11 deletions(-)
hw/arm/boot.c +0 -0
@@ -30,8 +30,9 @@
* Documentation/arm/Booting and Documentation/arm64/booting.txt
* They have different preferred image load offsets from system RAM base. */
-#define KERNEL_ARGS_ADDR 0x100
-#define KERNEL_LOAD_ADDR 0x00010000
+#define KERNEL_ARGS_ADDR 0x100
+#define KERNEL_NOLOAD_ADDR 0x00000000
+#define KERNEL_LOAD_ADDR 0x00010000
#define KERNEL64_LOAD_ADDR 0x00080000
#define ARM64_TEXT_OFFSET_OFFSET 8
@@ -1078,7 +1079,8 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info) }
entry = elf_entry;
if (kernel_size < 0) {
- kernel_size = load_uimage_as(info->kernel_filename, &entry, NULL, + uint64_t loadaddr = info->loader_start + KERNEL_NOLOAD_ADDR; + kernel_size = load_uimage_as(info->kernel_filename, &entry, &loadaddr, &is_linux, NULL, NULL, as);
}
if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64) && kernel_size < 0) {
hw/core/loader.c +0 -0
@@ -638,13 +638,26 @@ static int load_uboot_image(const char *filename, hwaddr *ep, hwaddr *loadaddr,
goto out;
if (hdr->ih_type != image_type) {
- fprintf(stderr, "Wrong image type %d, expected %d\n", hdr->ih_type, - image_type);
- goto out;
+ if (image_type != IH_TYPE_KERNEL &&
+ hdr->ih_type != IH_TYPE_KERNEL_NOLOAD) {
+ fprintf(stderr, "Wrong image type %d, expected %d\n", hdr->ih_type, + image_type);
+ goto out;
+ }
}
/* TODO: Implement other image types. */
switch (hdr->ih_type) {
+ case IH_TYPE_KERNEL_NOLOAD:
+ if (!loadaddr || *loadaddr == LOAD_UIMAGE_LOADADDR_INVALID) { + fprintf(stderr, "this image format (kernel_noload) cannot be " + "loaded on this machine type");
+ goto out;
+ }
+
+ hdr->ih_load = *loadaddr + sizeof(*hdr);
+ hdr->ih_ep += hdr->ih_load;
+ /* fall through */
case IH_TYPE_KERNEL:
address = hdr->ih_load;
if (translate_fn) {
hw/core/uboot_image.h +0 -0
@@ -124,6 +124,7 @@
#define IH_TYPE_SCRIPT 6 /* Script file */ #define IH_TYPE_FILESYSTEM 7 /* Filesystem Image (any type) */ #define IH_TYPE_FLATDT 8 /* Binary Flat Device Tree Blob */ +#define IH_TYPE_KERNEL_NOLOAD 14 /* OS Kernel Image (noload) */
/*
* Compression Types
hw/microblaze/boot.c +0 -0
@@ -156,7 +156,7 @@ void microblaze_load_kernel(MicroBlazeCPU *cpu, hwaddr ddr_base,
/* If it wasn't an ELF image, try an u-boot image. */ if (kernel_size < 0) {
- hwaddr uentry, loadaddr;
+ hwaddr uentry, loadaddr = LOAD_UIMAGE_LOADADDR_INVALID;
kernel_size = load_uimage(kernel_filename, &uentry, &loadaddr, 0, NULL, NULL);
hw/nios2/boot.c +0 -0
@@ -161,7 +161,7 @@ void nios2_load_kernel(Nios2CPU *cpu, hwaddr ddr_base,
/* If it wasn't an ELF image, try an u-boot image. */ if (kernel_size < 0) {
- hwaddr uentry, loadaddr;
+ hwaddr uentry, loadaddr = LOAD_UIMAGE_LOADADDR_INVALID;
kernel_size = load_uimage(kernel_filename, &uentry, &loadaddr, 0, NULL, NULL);
hw/ppc/e500.c +0 -0
@@ -997,6 +997,7 @@ void ppce500_init(MachineState *machine)
* Hrm. No ELF image? Try a uImage, maybe someone is giving us an
* ePAPR compliant kernel
*/
+ loadaddr = LOAD_UIMAGE_LOADADDR_INVALID;
payload_size = load_uimage(filename, &bios_entry, &loadaddr, NULL, NULL, NULL);
if (payload_size < 0) {
hw/ppc/ppc440_bamboo.c +0 -0
@@ -180,7 +180,7 @@ static void bamboo_init(MachineState *machine)
CPUPPCState *env;
uint64_t elf_entry;
uint64_t elf_lowaddr;
- hwaddr loadaddr = 0;
+ hwaddr loadaddr = LOAD_UIMAGE_LOADADDR_INVALID; target_long initrd_size = 0; DeviceState *dev;
int success;
hw/ppc/sam460ex.c +0 -0
@@ -402,7 +402,7 @@ static void sam460ex_init(MachineState *machine)
CPUPPCState *env;
PPC4xxI2CState *i2c[2];
hwaddr entry = UBOOT_ENTRY;
- hwaddr loadaddr = 0;
+ hwaddr loadaddr = LOAD_UIMAGE_LOADADDR_INVALID; target_long initrd_size = 0; DeviceState *dev;
SysBusDevice *sbdev;
include/hw/loader.h +0 -0
@@ -160,10 +160,15 @@ void load_elf_hdr(const char *filename, void *hdr, bool *is64, Error **errp);
int load_aout(const char *filename, hwaddr addr, int max_sz, int bswap_needed, hwaddr target_page_size);
+#define LOAD_UIMAGE_LOADADDR_INVALID (-1)
+
/** load_uimage_as:
* @filename: Path of uimage file
* @ep: Populated with program entry point. Ignored if NULL.
- * @loadaddr: Populated with the load address. Ignored if NULL.
+ * @loadaddr: load address if none specified in the image or when loading a ramdisk.
+ * Populated with the the load address. Ignored if NULL or
+ * LOAD_UIMAGE_LOADADDR_INVALID (images which do not specify a load address
+ * will not be loadable).
* @is_linux: Is set to true if the image loaded is Linux. Ignored if NULL.
* @translate_fn: optional function to translate load addresses
* @translate_opaque: opaque data passed to @translate_fn
Signature · 1 line
2.17.1
ping
Quoted 196 lines · Nick Hudson
noload kernels are loaded with the u-boot image header and as a result the header size needs adding to the entry point. Fake up a hdr so the kernel image is loaded at the right address and the entry point is adjusted appropriately.
The bootloader fits in the space that the uboot header would have occupied.
Clarify the
load_uimageAPI to state the passing of a load address when an image doesn't specify one, or when loading a ramdisk is expected.Adjust callers of
load_uimage, etc.Signed-off-by Nick Hudson<[email protected]>---
hw/arm/boot.c | 8 +++++---
hw/core/loader.c | 19 ++++++++++++++++---
hw/core/uboot_image.h | 1 +
hw/microblaze/boot.c | 2 +-
hw/nios2/boot.c | 2 +-
hw/ppc/e500.c | 1 +
hw/ppc/ppc440_bamboo.c | 2 +-
hw/ppc/sam460ex.c | 2 +-
include/hw/loader.h | 7 ++++++-9 files changed, 33 insertions(+), 11 deletions(-)hw/arm/boot.c +5
-3@@ -30,8 +30,9 @@* Documentation/arm/Booting and Documentation/arm64/booting.txt * They have different preferred image load offsets from system RAM base. */ -#define KERNEL_ARGS_ADDR 0x100 -#define KERNEL_LOAD_ADDR 0x00010000 +#define KERNEL_ARGS_ADDR 0x100 +#define KERNEL_NOLOAD_ADDR 0x00000000 +#define KERNEL_LOAD_ADDR 0x00010000 #define KERNEL64_LOAD_ADDR 0x00080000 #define ARM64_TEXT_OFFSET_OFFSET 8@@ -1078,7 +1079,8 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info) } entry = elf_entry; if (kernel_size < 0) { - kernel_size = load_uimage_as(info->kernel_filename, &entry,NULL , + uint64_t loadaddr = info->loader_start + KERNEL_NOLOAD_ADDR; + kernel_size = load_uimage_as(info->kernel_filename, &entry, &loadaddr,
&is_linux, NULL, NULL, as); }
if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)&&kernel_size< 0) {hw/core/loader.c +9
-3@@ -638,13 +638,26 @@ static int load_uboot_image(const char *filename, hwaddr *ep, hwaddr *loadaddr, goto out; if (hdr->ih_type != image_type) { - fprintf(stderr, "Wrong image type %d, expected %d\n", hdr->ih_type, - image_type); - goto out; + if (image_type != IH_TYPE_KERNEL && + hdr->ih_type != IH_TYPE_KERNEL_NOLOAD) { + fprintf(stderr, "Wrong image type %d, expected %d\n", hdr->ih_type, + image_type); + goto out; + } } /* TODO: Implement other image types. */ switch (hdr->ih_type) { + case IH_TYPE_KERNEL_NOLOAD: + if (!loadaddr || *loadaddr == LOAD_UIMAGE_LOADADDR_INVALID) { + fprintf(stderr, "this image format (kernel_noload) cannotbe "
+ "loaded on this machine type"); + goto out;
+ }
+
+hdr->ih_load= *loadaddr +sizeof(*hdr); +hdr->ih_ep+=hdr->ih_load;
+ /* fall through */
caseIH_TYPE_KERNEL:
address =hdr->ih_load;
if (translate_fn) {hw/core/uboot_image.h +1
-0@@ -124,6 +124,7 @@ #define IH_TYPE_SCRIPT 6 /* Script file */ #define IH_TYPE_FILESYSTEM 7 /* Filesystem Image (any type) */ #define IH_TYPE_FLATDT 8 /* Binary Flat Device Tree Blob */ +#define IH_TYPE_KERNEL_NOLOAD 14/* OS Kernel Image (noload) */ /** Compression Types hw/microblaze/boot.c +1
-1@@ -156,7 +156,7 @@ void microblaze_load_kernel(MicroBlazeCPU *cpu,hwaddr ddr_base, /* If it wasn't an ELF image, try an u-boot image. */ if (kernel_size < 0) { - hwaddr uentry, loadaddr; + hwaddr uentry, loadaddr = LOAD_UIMAGE_LOADADDR_INVALID; kernel_size = load_uimage(kernel_filename, &uentry, &loadaddr, 0,NULL, NULL);
hw/nios2/boot.c +1
-1@@ -161,7 +161,7 @@ void nios2_load_kernel(Nios2CPU *cpu, hwaddr ddr_base, /* If it wasn't an ELF image, try an u-boot image. */ if (kernel_size < 0) { - hwaddr uentry, loadaddr; + hwaddr uentry, loadaddr = LOAD_UIMAGE_LOADADDR_INVALID; kernel_size = load_uimage(kernel_filename, &uentry, &loadaddr, 0,NULL, NULL);
hw/ppc/e500.c +1
-0@@ -997,6 +997,7 @@ void ppce500_init(MachineState *machine)* Hrm. No ELF image? Try a uImage, maybe someone is giving us an * ePAPR compliant kernel */ + loadaddr = LOAD_UIMAGE_LOADADDR_INVALID; payload_size = load_uimage(filename, &bios_entry, &loadaddr, NULL, NULL, NULL); if (payload_size < 0) {hw/ppc/ppc440_bamboo.c +1
-1@@ -180,7 +180,7 @@ static void bamboo_init(MachineState *machine) CPUPPCState *env; uint64_t elf_entry; uint64_t elf_lowaddr; - hwaddr loadaddr = 0; + hwaddr loadaddr = LOAD_UIMAGE_LOADADDR_INVALID; target_long initrd_size = 0; DeviceState *dev; int success;hw/ppc/sam460ex.c +1
-1@@ -402,7 +402,7 @@ static void sam460ex_init(MachineState *machine) CPUPPCState *env; PPC4xxI2CState *i2c[2]; hwaddr entry = UBOOT_ENTRY; - hwaddr loadaddr = 0; + hwaddr loadaddr = LOAD_UIMAGE_LOADADDR_INVALID; target_long initrd_size = 0; DeviceState *dev; SysBusDevice *sbdev;include/hw/loader.h +3
-1@@ -160,10 +160,15 @@ void load_elf_hdr(const char *filename, void *hdr, bool *is64, Error **errp); int load_aout(const char *filename, hwaddr addr, int max_sz, int bswap_needed, hwaddr target_page_size); +#define LOAD_UIMAGE_LOADADDR_INVALID (-1) + /** load_uimage_as:* @filename: Path of uimage file * @ep: Populated with program entry point. Ignored if NULL. -* @loadaddr: Populated with the load address. Ignored if NULL. +* @loadaddr: load address if none specified in the image or when loading a ramdisk.
+ * Populated with the the load address. Ignored if NULL or
+ *LOAD_UIMAGE_LOADADDR_INVALID(images which do not specify a load address
+ * will not be loadable).
* @is_linux: Is set to true if the image loaded is Linux. Ignored if NULL.
* @translate_fn: optional function to translate load addresses
* @translate_opaque: opaque data passed to @translate_fn
Quoted 2 lines · Nick Hudson
ping
Thanks for the ping. This is on my to-review list but I'm not going to be doing any code review until after I get back to work in January now...
thanks
-- PMM
Quoted 16 lines · Nick Hudson
noload kernels are loaded with the u-boot image header and as a result the header size needs adding to the entry point. Fake up a hdr so the kernel image is loaded at the right address and the entry point is adjusted appropriately.
The bootloader fits in the space that the uboot header would have occupied.
Clarify the
load_uimageAPI to state the passing of a load address when an image doesn't specify one, or when loading a ramdisk is expected.Adjust callers of
load_uimage, etc.Signed-off-by Nick Hudson<[email protected]>
Quoted 11 lines
--- hw/arm/boot.c | 8 +++++--- hw/core/loader.c | 19 ++++++++++++++++--- hw/core/uboot_image.h | 1 + hw/microblaze/boot.c | 2 +- hw/nios2/boot.c | 2 +- hw/ppc/e500.c | 1 + hw/ppc/ppc440_bamboo.c | 2 +- hw/ppc/sam460ex.c | 2 +- include/hw/loader.h | 7 ++++++- 9 files changed, 33 insertions(+), 11 deletions(-)
Hi; I tried applying your patch, but unfortunately it looks like your email client has mangled it to the point that it can't
be applied:
* it is format=flowed, so long lines have been wrapped
* some whitespace has been turned into UTF-8 non-breaking space characters
I tried to manually fix these up, but didn't succeed.
It looks like you're using Thunderbird -- the kernel docs have some config setting suggestions that might help:
https://www.kernel.org/doc/html/v4.11/process/email-clients.html#thunderbird-gui
or you could try switching to 'git send-email'.
I've reviewed the patch for content and it's mostly good:
I just have a couple more questions below.
hw/arm/boot.c line 34
Quoted 12 lines
hw/arm/boot.c +2
-2@@ -30,8 +30,9 @@* Documentation/arm/Booting and Documentation/arm64/booting.txt * They have different preferred image load offsets from system RAM base. */ -#define KERNEL_ARGS_ADDR 0x100 -#define KERNEL_LOAD_ADDR 0x00010000 +#define KERNEL_ARGS_ADDR 0x100 +#define KERNEL_NOLOAD_ADDR 0x00000000
If I'm reading the code right, this requests that noload images are loaded at offset zero into RAM, yes ? That's not a great choice, because we put our little mini bootloader at offset 0, and so the two will clash. Can we put them somewhere else (above BOOTLOADER_MAX_SIZE, probably at a 64K page boundary) ?
If they must go at offset 0 then we'd need to refuse to load noload images if they set is_linux to true. (We only load the mini bootloader if is_linux is true, so that's the only case where there's a clash.)
Quoted 21 lines
hw/arm/boot.c +3
-1+#define KERNEL_LOAD_ADDR 0x00010000#define KERNEL64_LOAD_ADDR 0x00080000#define ARM64_TEXT_OFFSET_OFFSET 8@@ -1078,7 +1079,8 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info) } entry = elf_entry;if (kernel_size <0 ) { - kernel_size =load_uimage_as (info->kernel_filename, &entry,NULL , +uint64_t loadaddr = info->loader_start +KERNEL_NOLOAD_ADDR ; + kernel_size =load_uimage_as (info->kernel_filename, &entry, &loadaddr, &is_linux,NULL ,NULL , as);} if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64) && kernel_size < 0) {hw/core/loader.c +0
-0
hw/core/loader.c static int load_uboot_image(const char *filename, · line 643
Quoted 9 lines
hw/core/loader.c +2
-3@@ -638,13 +638,26 @@ static int load_uboot_image(const char *filename, hwaddr *ep, hwaddr *loadaddr, goto out;if (hdr->ih_type != image_type) { -fprintf (stderr,"Wrong image type %d, expected %d\n" , hdr->ih_type, - image_type); - goto out; +if (image_type !=IH_TYPE_KERNEL && + hdr->ih_type !=IH_TYPE_KERNEL_NOLOAD ) {
I think you have this condition wrong. Suppose we are trying to load image_type == IH_TYPE_KERNEL and we are passed a hdr->ih_type == IH_TYPE_RAMDISK. With this change we'll stop rejecting that as an error.
I think you want:
if (!(image_type == IH_TYPE_KERNEL &&
hdr->ih_type == IH_TYPE_KERNEL_NOLOAD)) {because the only kind of mismatch we want to accept is "we're looking for KERNEL and we got KERNEL_NOLOAD".
Quoted 24 lines
hw/core/loader.c +4
-0+fprintf (stderr,"Wrong image type %d, expected %d\n" , hdr->ih_type, + image_type); + goto out; + } }index
f5720f979e..70428b1865100644hw/ppc/ppc440_bamboo.c +1
-1@@ -180,7 +180,7 @@ static void bamboo_init(MachineState *machine)CPUPPCState *env;uint64_t elf_entry;uint64_t elf_lowaddr; -hwaddr loadaddr =0 ; +hwaddr loadaddr =LOAD_UIMAGE_LOADADDR_INVALID ;target_long initrd_size =0 ;DeviceState *dev;int success;hw/ppc/sam460ex.c +0
-0
hw/ppc/sam460ex.c static void sam460ex_init(MachineState *machine) · line 408
Quoted 8 lines
hw/ppc/sam460ex.c +1
-1@@ -402,7 +402,7 @@ static void sam460ex_init(MachineState *machine)CPUPPCState *env;PPC4xxI2CState *i2c[2 ];hwaddr entry =UBOOT_ENTRY ; -hwaddr loadaddr =0 ; +hwaddr loadaddr =LOAD_UIMAGE_LOADADDR_INVALID ;target_long initrd_size =0 ;DeviceState *dev;SysBusDevice *sbdev;
In both of these cases we could in fact remove the 'loadaddr' variable entirely (and pass NULL to the load_uimage() 3rd argument) because the code doesn't ever read the loadaddr value that is set. But this is the simple minimal change so it's OK:
we can do the cleanup later (or not at all).
thanks
-- PMM
Quoted 44 lines · Peter Maydell
Quoted 16 lines · Nick Hudson
noload kernels are loaded with the u-boot image header and as a result the header size needs adding to the entry point. Fake up a hdr so the kernel image is loaded at the right address and the entry point is adjusted appropriately.
The bootloader fits in the space that the uboot header would have occupied.
Clarify the
load_uimageAPI to state the passing of a load address when an image doesn't specify one, or when loading a ramdisk is expected.Adjust callers of
load_uimage, etc.Signed-off-by Nick Hudson<[email protected]>Quoted 11 lines
--- hw/arm/boot.c | 8 +++++--- hw/core/loader.c | 19 ++++++++++++++++--- hw/core/uboot_image.h | 1 + hw/microblaze/boot.c | 2 +- hw/nios2/boot.c | 2 +- hw/ppc/e500.c | 1 + hw/ppc/ppc440_bamboo.c | 2 +- hw/ppc/sam460ex.c | 2 +- include/hw/loader.h | 7 ++++++- 9 files changed, 33 insertions(+), 11 deletions(-)Hi; I tried applying your patch, but unfortunately it looks like your email client has mangled it to the point that it can't
be applied:
* it is format=flowed, so long lines have been wrapped
* some whitespace has been turned into UTF-8 non-breaking space characters
I tried to manually fix these up, but didn't succeed.It looks like you're using Thunderbird -- the kernel docs have some config setting suggestions that might help:
https://www.kernel.org/doc/html/v4.11/process/email-clients.html#thunderbird-gui
or you could try switching to 'git send-email'.I've reviewed the patch for content and it's mostly good:
I just have a couple more questions below.
Quoted 15 lines
hw/arm/boot.c line 34
Quoted 12 lines
hw/arm/boot.c +2
-2@@ -30,8 +30,9 @@* Documentation/arm/Booting and Documentation/arm64/booting.txt * They have different preferred image load offsets from system RAM base. */ -#define KERNEL_ARGS_ADDR 0x100 -#define KERNEL_LOAD_ADDR 0x00010000 +#define KERNEL_ARGS_ADDR 0x100 +#define KERNEL_NOLOAD_ADDR 0x00000000If I'm reading the code right, this requests that noload images are loaded at offset zero into RAM, yes ?
Not quite.
They're loaded as if the full noload image (including uboot header) was loaded at offset zero, but as load_uboot_image doesn't load the header then the image body (minus the header) is loaded at offset zero + the size of the u-boot header, i.e. 0x40.
Quoted 3 lines
That's not a great
choice, because we put our little mini bootloader at offset 0, and so the two will clash.
Fortuntately, the bootloader fits in the space that the uboot header would have occupied.
My commit message has
"The bootloader fits in the space that the uboot header would have occupied."
to try and described this. I could add more of a description if required?
Quoted 2 lines
Can we put them somewhere else
(aboveBOOTLOADER_MAX_SIZE, probably at a 64K page boundary) ?
I don't think this is necessary.
Quoted 4 lines
If they must go at offset 0 then we'd need to refuse to load noload images if they set
is_linuxto true. (We only load the mini bootloader ifis_linuxis true, so that's the only case where there's a clash.)
Nor this.
Quoted 37 lines
Quoted 22 lines
hw/arm/boot.c +3
-1+#define KERNEL_LOAD_ADDR 0x00010000#define KERNEL64_LOAD_ADDR 0x00080000#define ARM64_TEXT_OFFSET_OFFSET 8@@ -1078,7 +1079,8 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info) } entry = elf_entry;if (kernel_size <0 ) { - kernel_size =load_uimage_as (info->kernel_filename, &entry,NULL , +uint64_t loadaddr = info->loader_start +KERNEL_NOLOAD_ADDR ; + kernel_size =load_uimage_as (info->kernel_filename, &entry, &loadaddr, &is_linux,NULL ,NULL , as);} if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64) && kernel_size < 0) {hw/core/loader.c +0
-0hw/core/loader.c static int load_uboot_image(const char *filename, · line 643
Quoted 9 lines
hw/core/loader.c +2
-3@@ -638,13 +638,26 @@ static int load_uboot_image(const char *filename, hwaddr *ep, hwaddr *loadaddr, goto out;if (hdr->ih_type != image_type) { -fprintf (stderr,"Wrong image type %d, expected %d\n" , hdr->ih_type, - image_type); - goto out; +if (image_type !=IH_TYPE_KERNEL && + hdr->ih_type !=IH_TYPE_KERNEL_NOLOAD ) {I think you have this condition wrong. Suppose we are trying to load
image_type==IH_TYPE_KERNELand we are passed ahdr->ih_type==IH_TYPE_RAMDISK. With this change we'll stop rejecting that as an error.
I think you want:
Quoted 5 lines
if (!(image_type == IH_TYPE_KERNEL && hdr->ih_type == IH_TYPE_KERNEL_NOLOAD)) {because the only kind of mismatch we want to accept is "we're looking for KERNEL and we got
KERNEL_NOLOAD".
yeah, thanks.
[snip]
Quoted 4 lines
thanks
-- PMM
thanks for the review.
I'll send v4 with only the condition fixed and more descritive commit message (and correct formatting). ok?
Nick
Quoted 27 lines · Nick Hudson
Quoted 14 lines · Peter Maydell
hw/arm/boot.c line 34
Quoted 10 lines · Nick Hudson
hw/arm/boot.c +2
-2@@ -30,8 +30,9 @@* Documentation/arm/Booting and Documentation/arm64/booting.txt * They have different preferred image load offsets from system RAM base. */ -#define KERNEL_ARGS_ADDR 0x100 -#define KERNEL_LOAD_ADDR 0x00010000 +#define KERNEL_ARGS_ADDR 0x100 +#define KERNEL_NOLOAD_ADDR 0x00000000If I'm reading the code right, this requests that noload images are loaded at offset zero into RAM, yes ?
Not quite.
They're loaded as if the full noload image (including uboot header) was loaded at offset zero, but as
load_uboot_imagedoesn't load the header then the image body (minus the header) is loaded at offset zero + the size of the u-boot header, i.e.0x40.Quoted 3 lines
That's not a great
choice, because we put our little mini bootloader at offset 0, and so the two will clash.
Quoted 8 lines
Fortuntately, the bootloader fits in the space that the uboot header would have occupied.
My commit message has
"The bootloader fits in the space that the uboot header would have occupied."
to try and described this. I could add more of a description if required?
Ah, I missed that. This seems very fragile to me -- 0x40 is only 64 bytes, which is 16 instructions. Currently our boot loader code is less than that, but only by four insns or so, so it's very plausible that some future enhancement to the loader code would take it over the 0x40 boundary, at which point handling of noload images will silently fail. At a minimum we should have an assertion that we stay below 0x40; but I'm not keen on restricting ourselves to 16-instruction bootloaders.
Will a noload image ever in practice also be a Linux kernel (ie hdr->ih_os == IH_OS_LINUX) ? If not, then we don't lose anything by not allowing those to be loaded. (And if anybody does in future complain that their image doesn't work, we could make it supported by allowing the mini-bootloader to be placed elsewhere in RAM.)
thanks
-- PMM
Quoted 37 lines · Peter Maydell
Quoted 27 lines · Nick Hudson
Quoted 14 lines · Peter Maydell
hw/arm/boot.c line 34
Quoted 10 lines · Nick Hudson
hw/arm/boot.c +2
-2@@ -30,8 +30,9 @@* Documentation/arm/Booting and Documentation/arm64/booting.txt * They have different preferred image load offsets from system RAM base. */ -#define KERNEL_ARGS_ADDR 0x100 -#define KERNEL_LOAD_ADDR 0x00010000 +#define KERNEL_ARGS_ADDR 0x100 +#define KERNEL_NOLOAD_ADDR 0x00000000If I'm reading the code right, this requests that noload images are loaded at offset zero into RAM, yes ?
Not quite.
They're loaded as if the full noload image (including uboot header) was loaded at offset zero, but as
load_uboot_imagedoesn't load the header then the image body (minus the header) is loaded at offset zero + the size of the u-boot header, i.e.0x40.Quoted 3 lines
That's not a great
choice, because we put our little mini bootloader at offset 0, and so the two will clash.Quoted 8 lines
Fortuntately, the bootloader fits in the space that the uboot header would have occupied.
My commit message has
"The bootloader fits in the space that the uboot header would have occupied."
to try and described this. I could add more of a description if required?
Quoted 9 lines
Ah, I missed that. This seems very fragile to me --
0x40is only 64 bytes, which is 16 instructions. Currently our boot loader code is less than that, but only by four insns or so, so it's very plausible that some future enhancement to the loader code would take it over the0x40boundary, at which point handling of noload images will silently fail. At a minimum we should have an assertion that we stay below0x40; but I'm not keen on restricting ourselves to 16-instruction bootloaders.
I can add an assertion.
Kernels often like to be 2MiB aligned to allow for more simple
translation tables. This and the fact that the bootloader hasn't changed in 3 years I'd like to kick this can down the road.
Quoted 3 lines
Will a noload image ever in practice also be a Linux kernel (ie
hdr->ih_os==IH_OS_LINUX) ?
NetBSD/FreeBSD/OpenBSD (ab)use IH_OS_LINUX. They and Linux
Quoted 9 lines
If not, then we don't lose
anything by not allowing those to be loaded. (And if anybody does in future complain that their image doesn't work, we could make it supported by allowing the mini-bootloader to be placed elsewhere in RAM.)
Quoted 3 lines
thanks
-- PMM
thanks,
Nick