Skip to contentSkip to conversation

These two patches add some flexibilities to the arm bootloader.

PATCH In review Peter A. G. Crosthwaite 2 participants 10 messages Jun 18, 2012 – Jun 22, 2012

lore
Share & tools
lore
#0 lore raw

v2 cover These two patches add some flexibilities to the arm bootloader.

Set up the the bootloader so that if -dtb is specified, then the Linux bootflow is assumed.

Conditionalised dtb command line update on there being a -append argument. Means you can use a dtb with a command line already present and boot without QEMU nuking your command line.

The patches are independent. A block on patch one whould not block patch 2 and vice versa. Sent as one series for reviewer convenience.

changed since v1:
replaced old patch one (used to be cmd line arg for linux - now is just dtb implies linux) tweaked implementation of patch 2

Peter A. G. Crosthwaite (2):
arm_boot: Assume Linux boot flow when -dtb given
arm_boot: Conditionalised DTB command line update

 hw/arm_boot.c |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)
Signature · 1 line
1.7.3.2
#1 lore raw

PATCH v2 1/2 arm_boot: Assume Linux boot flow when -dtb given

If the user boots with a -dtb assume the Linux boot flow, even when handling an elf.

---
 hw/arm_boot.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
hw/arm_boot.c +5 -0
index 7447f5c..f0fa23c 100644
@@ -360,6 +360,11 @@ void arm_load_kernel(CPUARMState *env, struct arm_boot_info *info)
         exit(1);
     }
     info->entry = entry;
+
+    if (info->dtb_filename) {
+        is_linux = 1;
+    }
+
     if (is_linux) {
         if (info->initrd_filename) {
             initrd_size = load_image_targphys(info->initrd_filename,
Signature · 1 line
1.7.3.2
#2 lore raw

Re: [Qemu-devel] [PATCH v2 1/2] arm_boot: Assume Linux boot flow when -dtb given

Quoted 2 lines · Peter A. G. Crosthwaite

If the user boots with a -dtb assume the Linux boot flow, even when handling an elf.

We don't do this for -initrd, why should we do it for -dtb ?

-- PMM

#3 lore raw

Re: [Qemu-devel] [PATCH v2 1/2] arm_boot: Assume Linux boot flow when -dtb given

It matches my flow in the real hardware.

Heres the scenario where we need this (FYI applies to both microblaze and arm):

User creates a Linux elf that includes a built in dtb. Slave mode bootloader boots the real hardware with the elf (my actual real JTAG bootloader work with elfs).

However QEMU doesn't support all the hardware devices the kernel supports, so we need the QEMU linux bootloader to override the built in DTB (with -dtb) to stop the kernel probing non-existent devices. So, if the user specifies a dtb, adopt the linux bootloader flow instead, before jumping to the elf entry point. r2 get set to the -dtb argument and it boots with the modified dtb.

Make sense?

It all comes down to I need a bootloader functionality (mainly dtb but SMP stuff would be nice too) before booting my elf.

Every time i touch this arm bootloader we end up in a discussion about how it needs to be rewritten cos of flawed assumptions etc (like elfs are not Linux). Can we just accept this and throw it out with the trash when someone refactors the arm bootloader properly?

Regards,
Peter

Quoted 6 lines · Peter Maydell
Quoted 2 lines · Peter A. G. Crosthwaite

If the user boots with a -dtb assume the Linux boot flow, even when handling an elf.

We don't do this for -initrd, why should we do it for -dtb ?

Maybe we should do it for initrd too. If the user specifies either of these options they are trying to boot Linux.

Quoted 2 lines

-- PMM

#4 lore raw

Re: [Qemu-devel] [PATCH v2 1/2] arm_boot: Assume Linux boot flow when -dtb given

Ping!

Any thoughts Peter?

Regards,
Peter

Quoted 42 lines · Peter Crosthwaite

It matches my flow in the real hardware.

Heres the scenario where we need this (FYI applies to both microblaze and arm):

User creates a Linux elf that includes a built in dtb. Slave mode bootloader boots the real hardware with the elf (my actual real JTAG bootloader work with elfs).

However QEMU doesn't support all the hardware devices the kernel supports, so we need the QEMU linux bootloader to override the built in DTB (with -dtb) to stop the kernel probing non-existent devices. So, if the user specifies a dtb, adopt the linux bootloader flow instead, before jumping to the elf entry point. r2 get set to the -dtb argument and it boots with the modified dtb.

Make sense?

It all comes down to I need a bootloader functionality (mainly dtb but SMP stuff would be nice too) before booting my elf.

Every time i touch this arm bootloader we end up in a discussion about how it needs to be rewritten cos of flawed assumptions etc (like elfs are not Linux). Can we just accept this and throw it out with the trash when someone refactors the arm bootloader properly?

Regards,
Peter

Quoted 6 lines · Peter Maydell
Quoted 2 lines · Peter A. G. Crosthwaite

If the user boots with a -dtb assume the Linux boot flow, even when handling an elf.

We don't do this for -initrd, why should we do it for -dtb ?

Maybe we should do it for initrd too. If the user specifies either of these options they are trying to boot Linux.

Quoted 2 lines

-- PMM

#5 lore raw

Re: [Qemu-devel] [PATCH v2 1/2] arm_boot: Assume Linux boot flow when -dtb given

Quoted 3 lines · Peter Crosthwaite

Ping!

Any thoughts Peter?

Still sounds too specific to your odd use case and hardware to me.

I'd accept some reasonable way of saying "this ELF file is a Linux kernel", but magically doing it if you also said -dtb isn't it. I also care about backcompat with previous command lines and with being consistent about how -kernel works across architectures where possible. (I know this is a somewhat contradictory set of requirements.)

-- PMM

#6 lore raw

Re: [Qemu-devel] [PATCH v2 1/2] arm_boot: Assume Linux boot flow when -dtb given

Quoted 10 lines · Peter Maydell
Quoted 3 lines · Peter Crosthwaite

Ping!

Any thoughts Peter?

Still sounds too specific to your odd use case and hardware to me.

I'd accept some reasonable way of saying "this ELF file is a Linux kernel", but magically doing it if you also said -dtb isn't it.

Then is there no objection to v1 of this series where I made a is_linux machine opt? I made this patch as a less intrusive workaround to this problem...

I also care about

Quoted 5 lines

backcompat with previous command lines and with being consistent about how -kernel works across architectures where possible. (I know this is a somewhat contradictory set of requirements.)

-- PMM

#7 lore raw

Re: [Qemu-devel] [PATCH v2 1/2] arm_boot: Assume Linux boot flow when -dtb given

In reply to Peter Maydell
Quoted 4 lines · Peter Maydell
Quoted 2 lines · Peter Crosthwaite

Ping!

Quoted 8 lines
Quoted 1 line

Any thoughts Peter?

Still sounds too specific to your odd use case and hardware to me.

I'd accept some reasonable way of saying "this ELF file is a Linux kernel", but magically doing it if you also said -dtb isn't it. I also care about backcompat with previous command lines and with being consistent about how -kernel works across architectures where possible.

Speaking of other archs, microblaze will accept -dtb with an elf and implement the r2=foo style behviour before loading the elf entry. A provocative thought, how bout always using a Linux style bootloader no matter what? Does it really matter if your elf is bootstrapped by half a dozen instructions?

Further to that, can we get rid of the bootloader blob altogether and just setup the cpu->env like other architectures do?

23 /* The worlds second smallest bootloader. Set r0-r2, then jump
to kernel. */
24 static uint32_t bootloader[] = {

  25   0xe3a00000, /* mov     r0, #0 */
  26   0xe59f1004, /* ldr     r1, [pc, #4] */
  27   0xe59f2004, /* ldr     r2, [pc, #4] */
  28   0xe59ff004, /* ldr     pc, [pc, #4] */
  29   0, /* Board ID */
  30   0, /* Address of kernel args.  Set by integratorcp_init.  */
  31   0  /* Kernel entry point.  Set by integratorcp_init.  */

32 };

All this code does is set registers and an entry point, which several bootloaders do just though cpu->env manipulation.

Quoted 3 lines

a somewhat contradictory set of requirements.)

-- PMM

#8 lore raw

PATCH v2 2/2 arm_boot: Conditionalised DTB command line update

In reply to Peter A. G. Crosthwaite

The DTB command line should only be overwritten if the user provides a command line with -apend. Otherwise whatever command line was in the DTB should stay unchanged.

---
changed since v1:
checked cmd line string in binfo rather than machine opt

 hw/arm_boot.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
hw/arm_boot.c +6 -4
index f0fa23c..1b110ca 100644
@@ -240,10 +240,12 @@ static int load_dtb(target_phys_addr_t addr, const struct arm_boot_info *binfo)
         fprintf(stderr, "couldn't set /memory/reg\n");
     }
 
-    rc = qemu_devtree_setprop_string(fdt, "/chosen", "bootargs",
-                                      binfo->kernel_cmdline);
-    if (rc < 0) {
-        fprintf(stderr, "couldn't set /chosen/bootargs\n");
+    if (binfo->kernel_cmdline && *binfo->kernel_cmdline) {
+        rc = qemu_devtree_setprop_string(fdt, "/chosen", "bootargs",
+                                          binfo->kernel_cmdline);
+        if (rc < 0) {
+            fprintf(stderr, "couldn't set /chosen/bootargs\n");
+        }
     }
 
     if (binfo->initrd_size) {
Signature · 1 line
1.7.3.2
Reviewed-by on v2 2/2
#9 lore raw

Re: [Qemu-devel] [PATCH v2 2/2] arm_boot: Conditionalised DTB command line update

Quoted 8 lines · Peter A. G. Crosthwaite

The DTB command line should only be overwritten if the user provides a command line with -apend. Otherwise whatever command line was in the DTB should stay unchanged.

---
changed since v1:
checked cmd line string in binfo rather than machine opt

Yep, this looks nicer and matches how we handle it in the ATAGS code path.

-- PMM