Skip to contentSkip to conversation

PPC: e500: Use u-boot as firmware

PATCH In review Alexander Graf 2 participants 17 messages May 15, 2014 – May 16, 2014

lore
Share & tools
lore
#0 lore raw

cover PPC: e500: Use u-boot as firmware

Today we don't run any firmware on our e500 platform. You're either running a Linux kernel directly through -kernel or you don't boot the VM at all.

This is bad for multiple reasons. The normal firmware on e500 based systems is u-boot. Some OSes (IIRC FreeBSD) rely on u-boot for their 2nd stage boot loader. Since that relies on interfaces u-boot provides we can't execute it today.

The other case where we're falling short of expectations that I'm aware of is network boot. With a firmware you can actually pxe boot a virtual machine.

This patch set implements all the pieces necessary to run u-boot as the firmware for our e500 platforms: mpc8544ds and e500plat. It is based on upstream u-boot code that implements a target specific for the simplified system QEMU implements.

Due to popular demand the default -kernel booting has *not* been changed from directly booting into the kernel. This is possible because we don't need to run firmware to provide run time services.

However, whenever the user explicitly defines a -bios blob, we run it. That means if you want to route a -kernel boot through u-boot you have to pass in -bios pc-bios/u-boot.e500 -kernel uImage.

Please try out as many things as you're able to try.

Known missing bits:

- -boot doesn't get interpreted yet
- pflash is missing, so the environment is volatile
- no block drivers available (ata_piix is broken in u-boot and virtio-blk is missing)
- KVM patches to support u-boot are probably going to hit 3.16

Alex

Alexander Graf (9):
PPC: Make all e500 CPUs SVR aware
PPC: Add definitions for GIVORs
PPC: Fix SPR access control of L1CFG0
PPC: Add L1CFG1 SPR emulation
PPC: Properly emulate L1CSR0 and L1CSR1
PPC: Add dcbtls emulation
PPC: e500: Expose kernel load address in dt
PPC: Add u-boot firmware for e500
PPC: e500: Move to u-boot as firmware

 .gitmodules                 |   3 +
 hw/ppc/e500.c               | 134 ++++++++++++++++++++++++++++++--------------
 pc-bios/README              |   5 ++
 pc-bios/u-boot.e500         | Bin 0 -> 264848 bytes
 roms/u-boot                 |   1 +
 target-ppc/cpu-models.c     |  28 ++++-----
 target-ppc/cpu.h            |  19 +++++++
 target-ppc/translate.c      |  12 ++++
 target-ppc/translate_init.c |  30 +++++++---
 9 files changed, 168 insertions(+), 64 deletions(-)
 create mode 100755 pc-bios/u-boot.e500
 create mode 160000 roms/u-boot
Signature · 1 line
1.8.1.4
#1 lore raw

PATCH 1/9 PPC: Make all e500 CPUs SVR aware

Our pre-e500mc e500 CPU types didn't get instanciated with SVR information, even though those systems do support the SVR register.

Spawn them with the SVR tag so that they don't get confused when someone tries to read SPR_SVR.

---
 target-ppc/cpu-models.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
target-ppc/cpu-models.c +14 -14
index 57cb4e4..9a66c03 100644
@@ -671,20 +671,20 @@
     POWERPC_DEF_SVR("MPC8379E", "MPC8379E",
                     CPU_POWERPC_MPC837x,      POWERPC_SVR_8379E,     e300)
     /* e500 family                                                           */
-    POWERPC_DEF("e500_v10",      CPU_POWERPC_e500v1_v10,             e500v1,
-                "PowerPC e500 v1.0 core")
-    POWERPC_DEF("e500_v20",      CPU_POWERPC_e500v1_v20,             e500v1,
-                "PowerPC e500 v2.0 core")
-    POWERPC_DEF("e500v2_v10",    CPU_POWERPC_e500v2_v10,             e500v2,
-                "PowerPC e500v2 v1.0 core")
-    POWERPC_DEF("e500v2_v20",    CPU_POWERPC_e500v2_v20,             e500v2,
-                "PowerPC e500v2 v2.0 core")
-    POWERPC_DEF("e500v2_v21",    CPU_POWERPC_e500v2_v21,             e500v2,
-                "PowerPC e500v2 v2.1 core")
-    POWERPC_DEF("e500v2_v22",    CPU_POWERPC_e500v2_v22,             e500v2,
-                "PowerPC e500v2 v2.2 core")
-    POWERPC_DEF("e500v2_v30",    CPU_POWERPC_e500v2_v30,             e500v2,
-                "PowerPC e500v2 v3.0 core")
+    POWERPC_DEF_SVR("e500_v10", "PowerPC e500 v1.0 core",
+                    CPU_POWERPC_e500v1_v10,   POWERPC_SVR_E500,      e500v1);
+    POWERPC_DEF_SVR("e500_v20", "PowerPC e500 v2.0 core",
+                    CPU_POWERPC_e500v1_v20,   POWERPC_SVR_E500,      e500v1);
+    POWERPC_DEF_SVR("e500v2_v10", "PowerPC e500v2 v1.0 core",
+                    CPU_POWERPC_e500v2_v10,   POWERPC_SVR_E500,      e500v2);
+    POWERPC_DEF_SVR("e500v2_v20", "PowerPC e500v2 v2.0 core",
+                    CPU_POWERPC_e500v2_v20,   POWERPC_SVR_E500,      e500v2);
+    POWERPC_DEF_SVR("e500v2_v21", "PowerPC e500v2 v2.1 core",
+                    CPU_POWERPC_e500v2_v21,   POWERPC_SVR_E500,      e500v2);
+    POWERPC_DEF_SVR("e500v2_v22", "PowerPC e500v2 v2.2 core",
+                    CPU_POWERPC_e500v2_v22,   POWERPC_SVR_E500,      e500v2);
+    POWERPC_DEF_SVR("e500v2_v30", "PowerPC e500v2 v3.0 core",
+                    CPU_POWERPC_e500v2_v30,   POWERPC_SVR_E500,      e500v2);
     POWERPC_DEF_SVR("e500mc", "e500mc",
                     CPU_POWERPC_e500mc,       POWERPC_SVR_E500,      e500mc)
 #ifdef TARGET_PPC64
Signature · 1 line
1.8.1.4
#2 lore raw

PATCH 2/9 PPC: Add definitions for GIVORs

In reply to Alexander Graf

We're missing SPR definitions for GIVORs. Add them to the list of SPRs.

---
 target-ppc/cpu.h | 6 ++++++
 1 file changed, 6 insertions(+)
target-ppc/cpu.h +6 -0
index 75ed5fa..178fc55 100644
@@ -1365,6 +1365,12 @@ static inline int cpu_mmu_index (CPUPPCState *env)
 #define SPR_BOOKE_IVOR40      (0x1B2)
 #define SPR_BOOKE_IVOR41      (0x1B3)
 #define SPR_BOOKE_IVOR42      (0x1B4)
+#define SPR_BOOKE_GIVOR2      (0x1B8)
+#define SPR_BOOKE_GIVOR3      (0x1B9)
+#define SPR_BOOKE_GIVOR4      (0x1BA)
+#define SPR_BOOKE_GIVOR8      (0x1BB)
+#define SPR_BOOKE_GIVOR13     (0x1BC)
+#define SPR_BOOKE_GIVOR14     (0x1BD)
 #define SPR_BOOKE_SPEFSCR     (0x200)
 #define SPR_Exxx_BBEAR        (0x201)
 #define SPR_Exxx_BBTAR        (0x202)
Signature · 1 line
1.8.1.4
#3 lore raw

PATCH 3/9 PPC: Fix SPR access control of L1CFG0

In reply to Alexander Graf

The L1CFG0 register on e200 and e500 is "User RO" according to the specifications. So let's make it user readable and world unwritable.

---
 target-ppc/translate_init.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
target-ppc/translate_init.c +4 -4
index 1d64ec9..07f723d 100644
@@ -4433,8 +4433,8 @@ static void init_proc_e200 (CPUPPCState *env)
                  0x00000000);
     /* XXX : not implemented */
     spr_register(env, SPR_Exxx_L1CFG0, "L1CFG0",
-                 SPR_NOACCESS, SPR_NOACCESS,
-                 &spr_read_generic, &spr_write_generic,
+                 &spr_read_generic, SPR_NOACCESS,
+                 &spr_read_generic, SPR_NOACCESS,
                  0x00000000);
     /* XXX : not implemented */
     spr_register(env, SPR_Exxx_L1CSR0, "L1CSR0",
@@ -4766,8 +4766,8 @@ static void init_proc_e500 (CPUPPCState *env, int version)
                  0x00000000);
     /* XXX : not implemented */
     spr_register(env, SPR_Exxx_L1CFG0, "L1CFG0",
-                 SPR_NOACCESS, SPR_NOACCESS,
-                 &spr_read_generic, &spr_write_generic,
+                 &spr_read_generic, SPR_NOACCESS,
+                 &spr_read_generic, SPR_NOACCESS,
                  l1cfg0);
     /* XXX : not implemented */
     spr_register(env, SPR_Exxx_L1CSR0, "L1CSR0",
Signature · 1 line
1.8.1.4
#4 lore raw

PATCH 4/9 PPC: Add L1CFG1 SPR emulation

In reply to Alexander Graf

In addition to the L1 data cache configuration register L1CFG0 there is also another one for the L1 instruction cache called L1CFG1.

Emulate that one with the same values as the data one.

---

v1 -> v2:

- correct permission access to USER_RO

---
 target-ppc/cpu.h            | 1 +
 target-ppc/translate_init.c | 8 +++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)
target-ppc/cpu.h +1 -0
index 178fc55..f36c90b 100644
@@ -1375,6 +1375,7 @@ static inline int cpu_mmu_index (CPUPPCState *env)
 #define SPR_Exxx_BBEAR        (0x201)
 #define SPR_Exxx_BBTAR        (0x202)
 #define SPR_Exxx_L1CFG0       (0x203)
+#define SPR_Exxx_L1CFG1       (0x204)
 #define SPR_Exxx_NPIDR        (0x205)
 #define SPR_ATBL              (0x20E)
 #define SPR_ATBU              (0x20F)
target-ppc/translate_init.c +7 -1
index 07f723d..fc9d932 100644
@@ -4651,6 +4651,8 @@ static void init_proc_e500 (CPUPPCState *env, int version)
     uint64_t ivpr_mask = 0xFFFF0000ULL;
     uint32_t l1cfg0 = 0x3800  /* 8 ways */
                     | 0x0020; /* 32 kb */
+    uint32_t l1cfg1 = 0x3800  /* 8 ways */
+                    | 0x0020; /* 32 kb */
 #if !defined(CONFIG_USER_ONLY)
     int i;
 #endif
@@ -4719,6 +4721,7 @@ static void init_proc_e500 (CPUPPCState *env, int version)
         env->dcache_line_size = 64;
         env->icache_line_size = 64;
         l1cfg0 |= 0x1000000; /* 64 byte cache block size */
+        l1cfg1 |= 0x1000000; /* 64 byte cache block size */
         break;
     default:
         cpu_abort(CPU(cpu), "Unknown CPU: " TARGET_FMT_lx "\n", env->spr[SPR_PVR]);
@@ -4769,7 +4772,10 @@ static void init_proc_e500 (CPUPPCState *env, int version)
                  &spr_read_generic, SPR_NOACCESS,
                  &spr_read_generic, SPR_NOACCESS,
                  l1cfg0);
-    /* XXX : not implemented */
+    spr_register(env, SPR_Exxx_L1CFG1, "L1CFG1",
+                 &spr_read_generic, SPR_NOACCESS,
+                 &spr_read_generic, SPR_NOACCESS,
+                 l1cfg1);
     spr_register(env, SPR_Exxx_L1CSR0, "L1CSR0",
                  SPR_NOACCESS, SPR_NOACCESS,
                  &spr_read_generic, &spr_write_e500_l1csr0,
Signature · 1 line
1.8.1.4
#5 lore raw

PATCH 5/9 PPC: Properly emulate L1CSR0 and L1CSR1

In reply to Alexander Graf

There are 2 L1 cache control registers - one for data (L1CSR0) and one for instructions (L1CSR1).

Emulate both of them well enough to give the guest the illusion that it could actually do anything about its caches.

---
 target-ppc/cpu.h            | 12 ++++++++++++
 target-ppc/translate_init.c | 14 +++++++++++---
 2 files changed, 23 insertions(+), 3 deletions(-)
target-ppc/cpu.h +12 -0
index f36c90b..b035e91 100644
@@ -1716,6 +1716,18 @@ static inline int cpu_mmu_index (CPUPPCState *env)
 /* External Input Interrupt Directed to Guest State */
 #define EPCR_EXTGS            (1 << 31)
 
+#define   L1CSR0_CPE		0x00010000	/* Data Cache Parity Enable */
+#define   L1CSR0_CUL		0x00000400	/* (D-)Cache Unable to Lock */
+#define   L1CSR0_DCLFR		0x00000100	/* D-Cache Lock Flash Reset */
+#define   L1CSR0_DCFI		0x00000002	/* Data Cache Flash Invalidate */
+#define   L1CSR0_DCE		0x00000001	/* Data Cache Enable */
+
+#define   L1CSR1_CPE		0x00010000	/* Instruction Cache Parity Enable */
+#define   L1CSR1_ICUL		0x00000400	/* I-Cache Unable to Lock */
+#define   L1CSR1_ICLFR		0x00000100	/* I-Cache Lock Flash Reset */
+#define   L1CSR1_ICFI		0x00000002	/* Instruction Cache Flash Invalidate */
+#define   L1CSR1_ICE		0x00000001	/* Instruction Cache Enable */
+
 /*****************************************************************************/
 /* PowerPC Instructions types definitions                                    */
 enum {
target-ppc/translate_init.c +11 -3
index fc9d932..0f9dec7 100644
@@ -1448,7 +1448,16 @@ static void spr_write_e500_l1csr0 (void *opaque, int sprn, int gprn)
 {
     TCGv t0 = tcg_temp_new();
 
-    tcg_gen_andi_tl(t0, cpu_gpr[gprn], ~256);
+    tcg_gen_andi_tl(t0, cpu_gpr[gprn], L1CSR0_DCE | L1CSR0_CPE);
+    gen_store_spr(sprn, t0);
+    tcg_temp_free(t0);
+}
+
+static void spr_write_e500_l1csr1(void *opaque, int sprn, int gprn)
+{
+    TCGv t0 = tcg_temp_new();
+
+    tcg_gen_andi_tl(t0, cpu_gpr[gprn], L1CSR1_ICE | L1CSR1_CPE);
     gen_store_spr(sprn, t0);
     tcg_temp_free(t0);
 }
@@ -4780,10 +4789,9 @@ static void init_proc_e500 (CPUPPCState *env, int version)
                  SPR_NOACCESS, SPR_NOACCESS,
                  &spr_read_generic, &spr_write_e500_l1csr0,
                  0x00000000);
-    /* XXX : not implemented */
     spr_register(env, SPR_Exxx_L1CSR1, "L1CSR1",
                  SPR_NOACCESS, SPR_NOACCESS,
-                 &spr_read_generic, &spr_write_generic,
+                 &spr_read_generic, &spr_write_e500_l1csr1,
                  0x00000000);
     spr_register(env, SPR_BOOKE_MCSRR0, "MCSRR0",
                  SPR_NOACCESS, SPR_NOACCESS,
Signature · 1 line
1.8.1.4
#6 lore raw

PATCH 6/9 PPC: Add dcbtls emulation

In reply to Alexander Graf

The dcbtls instruction is able to lock data inside the L1 cache.

Unfortunately we don't emulate any caches, so we have to tell the guest that its locking attempt failed.

However, by implementing the instruction we at least don't give the guest a program exception which it definitely does not expect.

---
 target-ppc/translate.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
target-ppc/translate.c +12 -0
index e9e7812..0cf1417 100644
@@ -4481,6 +4481,17 @@ static void gen_dcbtst(DisasContext *ctx)
      */
 }
 
+/* dcbtls */
+static void gen_dcbtls(DisasContext *ctx)
+{
+    /* Always fails locking the cache */
+    TCGv t0 = tcg_temp_new();
+    gen_load_spr(t0, SPR_Exxx_L1CSR0);
+    tcg_gen_ori_tl(t0, t0, L1CSR0_CUL);
+    gen_store_spr(SPR_Exxx_L1CSR0, t0);
+    tcg_temp_free(t0);
+}
+
 /* dcbz */
 static void gen_dcbz(DisasContext *ctx)
 {
@@ -10215,6 +10226,7 @@ GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE),
 GEN_HANDLER(dcbst, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE),
 GEN_HANDLER(dcbt, 0x1F, 0x16, 0x08, 0x00000001, PPC_CACHE),
 GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x00000001, PPC_CACHE),
+GEN_HANDLER_E(dcbtls, 0x1F, 0x06, 0x05, 0x02000001, PPC_BOOKE, PPC2_BOOKE206),
 GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ),
 GEN_HANDLER(dst, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC),
 GEN_HANDLER(dstst, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC),
Signature · 1 line
1.8.1.4
#7 lore raw

PATCH 7/9 PPC: e500: Expose kernel load address in dt

In reply to Alexander Graf

We want to move to a model where firmware loads our kernel. To achieve this we need to be able to tell firmware where the kernel lies.

Let's copy the mechanism we already use for -M pseries and expose the kernel load address and size through the device tree.

---
 hw/ppc/e500.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)
hw/ppc/e500.c +22 -4
index 853a6bc..d543934 100644
@@ -128,6 +128,8 @@ static int ppce500_load_device_tree(QEMUMachineInitArgs *args,
                                     hwaddr addr,
                                     hwaddr initrd_base,
                                     hwaddr initrd_size,
+                                    hwaddr kernel_base,
+                                    hwaddr kernel_size,
                                     bool dry_run)
 {
     CPUPPCState *env = first_cpu->env_ptr;
@@ -204,6 +206,13 @@ static int ppce500_load_device_tree(QEMUMachineInitArgs *args,
         if (ret < 0) {
             fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n");
         }
+
+    }
+
+    if (kernel_base != -1ULL) {
+        qemu_fdt_setprop_cells(fdt, "/chosen", "qemu,boot-kernel",
+                                     kernel_base >> 32, kernel_base,
+                                     kernel_size >> 32, kernel_size);
     }
 
     ret = qemu_fdt_setprop_string(fdt, "/chosen", "bootargs",
@@ -392,20 +401,25 @@ typedef struct DeviceTreeParams {
     hwaddr addr;
     hwaddr initrd_base;
     hwaddr initrd_size;
+    hwaddr kernel_base;
+    hwaddr kernel_size;
 } DeviceTreeParams;
 
 static void ppce500_reset_device_tree(void *opaque)
 {
     DeviceTreeParams *p = opaque;
     ppce500_load_device_tree(&p->args, &p->params, p->addr, p->initrd_base,
-                             p->initrd_size, false);
+                             p->initrd_size, p->kernel_base, p->kernel_size,
+                             false);
 }
 
 static int ppce500_prep_device_tree(QEMUMachineInitArgs *args,
                                     PPCE500Params *params,
                                     hwaddr addr,
                                     hwaddr initrd_base,
-                                    hwaddr initrd_size)
+                                    hwaddr initrd_size,
+                                    hwaddr kernel_base,
+                                    hwaddr kernel_size)
 {
     DeviceTreeParams *p = g_new(DeviceTreeParams, 1);
     p->args = *args;
@@ -413,12 +427,15 @@ static int ppce500_prep_device_tree(QEMUMachineInitArgs *args,
     p->addr = addr;
     p->initrd_base = initrd_base;
     p->initrd_size = initrd_size;
+    p->kernel_base = kernel_base;
+    p->kernel_size = kernel_size;
 
     qemu_register_reset(ppce500_reset_device_tree, p);
 
     /* Issue the device tree loader once, so that we get the size of the blob */
     return ppce500_load_device_tree(args, params, addr, initrd_base,
-                                    initrd_size, true);
+                                    initrd_size, kernel_base, kernel_size,
+                                    true);
 }
 
 /* Create -kernel TLB entries for BookE.  */
@@ -787,7 +804,8 @@ void ppce500_init(QEMUMachineInitArgs *args, PPCE500Params *params)
         int dt_size;
 
         dt_size = ppce500_prep_device_tree(args, params, dt_base,
-                                           initrd_base, initrd_size);
+                                           initrd_base, initrd_size,
+                                           loadaddr, kernel_size);
         if (dt_size < 0) {
             fprintf(stderr, "couldn't load device tree\n");
             exit(1);
Signature · 1 line
1.8.1.4
#8 lore raw

PATCH 8/9 PPC: Add u-boot firmware for e500

In reply to Alexander Graf

This adds a special build of u-boot tailored for the e500 platforms we emulate. It is based on the current version of upstream u-boot which contains all the code necessary to drive our QEMU provided machines.

---

v1 -> v2:

- Update to newer version
- Add git submodule

---
 .gitmodules         |   3 +++
 pc-bios/README      |   5 +++++
 pc-bios/u-boot.e500 | Bin 0 -> 264848 bytes
 roms/u-boot         |   1 +
 4 files changed, 9 insertions(+)
 create mode 100755 pc-bios/u-boot.e500
 create mode 160000 roms/u-boot
.gitmodules +3 -0
index 444c24a..9da9ede 100644
@@ -28,3 +28,6 @@
 [submodule "dtc"]
 	path = dtc
 	url = git://git.qemu-project.org/dtc.git
+[submodule "roms/u-boot"]
+	path = roms/u-boot
+	url = git://git.qemu-project.org/u-boot.git
pc-bios/README +5 -0
index 4381718..49cdacf 100644
@@ -41,3 +41,8 @@
 
 - The sources for the Alpha palcode image is available from:
   git://github.com/rth7680/qemu-palcode.git
+
+- The u-boot binary for e500 comes from the upstream denx u-boot project where
+  it was compiled using the qemu-ppce500 target.
+  A git mirror is available at: git://git.qemu-project.org/u-boot.git
+  The hash used to compile the current version is: 2072e72
pc-bios/u-boot.e500 new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..fc997a5552c82d2168daa35cafb8846b4bd19f1c
GIT binary patch
roms/u-boot new file +1 -0
new file mode 160000
index 0000000..2072e72
@@ -0,0 +1 @@
+Subproject commit 2072e7262965bb48d7fffb1e283101e6ed8b21a8
Signature · 1 line
1.8.1.4
#9 lore raw

Re: [Qemu-devel] [PATCH 8/9] PPC: Add u-boot firmware for e500

Quoted 5 lines · Alexander Graf

This adds a special build of u-boot tailored for the e500 platforms we emulate. It is based on the current version of upstream u-boot which contains all the code necessary to drive our QEMU provided machines.

Adding build rules to roms/Makefile would be nice, so you can just do "make -C roms uboot" to build it.

cheers,
Gerd

#10 lore raw

Re: [Qemu-devel] [PATCH 8/9] PPC: Add u-boot firmware for e500

Quoted 8 lines · Gerd Hoffmann
Quoted 5 lines · Alexander Graf

This adds a special build of u-boot tailored for the e500 platforms we emulate. It is based on the current version of upstream u-boot which contains all the code necessary to drive our QEMU provided machines.

Adding build rules to roms/Makefile would be nice, so you can just do "make -C roms uboot" to build it.

Good idea. How about something like this? I had to jump through some hoops to make it work with a biarch 64/32 compiler because upstream u-boot assumes you always have a cross compiler for a specific target architecture which is not the case in normal enterprise distributions.

If you think this approach is fine (I do ;)), then I'll squash it into this patch but won't resend the patch - I don't want to clutter people's inboxes with random binary blobs.

Alex

roms/Makefile +15 -0
index 2721b02..1b6996c 100644
@@ -55,6 +55,7 @@ default:
     @echo "  efirom         -- update nic roms (bios+efi, this needs"
     @echo "                    the EfiRom utility from edk2 / tianocore)"
     @echo "  slof           -- update slof.bin"
+    @echo "  u-boot.e500    -- update u-boot.e500"
 
 bios: build-seabios-config-seabios-128k build-seabios-config-seabios-256k
     cp seabios/builds/seabios-128k/bios.bin ../pc-bios/bios.bin
@@ -132,6 +133,19 @@ slof:
     $(MAKE) -C SLOF CROSS=$(powerpc64_cross_prefix) qemu
     cp SLOF/boot_rom.bin ../pc-bios/slof.bin
 
+u-boot.e500:
+    # examples fail to honor cflags, just remove them
+    rm -rf u-boot/examples
+    sed -i 's/examples//g' u-boot/Makefile
+    # Make linker script biarch aware
+    sed -i 's/OUTPUT_ARCH(powerpc)/OUTPUT_ARCH(powerpc:common)/' \
+        u-boot/arch/powerpc/cpu/mpc85xx/u-boot.lds
+    # Compile u-boot
+    $(MAKE) -C u-boot O=build.e500 qemu-ppce500_config
+    $(MAKE) -C u-boot CROSS_COMPILE=$(powerpc64_cross_prefix) \
+        O=build.e500 KCFLAGS=-m32 KAFLAGS=-m32 \
+        LDFLAGS=-melf32ppc KCPPFLAGS=-m32 V=1 u-boot.bin
+    strip u-boot/build.e500/u-boot -o ../pc-bios/u-boot.e500
 
 clean:
     rm -rf seabios/.config seabios/out seabios/builds
@@ -141,3 +155,4 @@ clean:
     rm -f sgabios/.depend
     $(MAKE) -C ipxe/src veryclean
     $(MAKE) -C SLOF clean
+    rm -rf u-boot/build.e500
#11 lore raw

Re: [Qemu-devel] [PATCH 8/9] PPC: Add u-boot firmware for e500

Hi,

roms/Makefile slof: · line 142

Quoted 7 lines
roms/Makefile +7 -0
+u-boot.e500:
+    # examples fail to honor cflags, just remove them
+    rm -rf u-boot/examples
+    sed -i 's/examples//g' u-boot/Makefile
+    # Make linker script biarch aware
+    sed -i 's/OUTPUT_ARCH(powerpc)/OUTPUT_ARCH(powerpc:common)/' \
+        u-boot/arch/powerpc/cpu/mpc85xx/u-boot.lds

Hmm. Mucking with the source tree like this will leave the u-boot git tree in a dirty state, which isn't exactly nice. Fixable by sprinkling in a "git reset --hard", but that obviously has other downsides, such as seriously disturbing people trying to build a u-boot tree with local changes.

Any chance to fix that without patching the source tree, by passing SUBDIRS="<list-dirs-without-examples>" to $(MAKE) for example? Or send patches to u-boot upstream to tackle this?

roms/Makefile slof: · line 148

Quoted 6 lines
roms/Makefile +6 -0
+    # Compile u-boot
+    $(MAKE) -C u-boot O=build.e500 qemu-ppce500_config
+    $(MAKE) -C u-boot CROSS_COMPILE=$(powerpc64_cross_prefix) \
+        O=build.e500 KCFLAGS=-m32 KAFLAGS=-m32 \
+        LDFLAGS=-melf32ppc KCPPFLAGS=-m32 V=1 u-boot.bin
+    strip u-boot/build.e500/u-boot -o ../pc-bios/u-boot.e500

$(powerpc64_cross_prefix)strip I guess ...

cheers,
Gerd

#12 lore raw

Re: [Qemu-devel] [PATCH 8/9] PPC: Add u-boot firmware for e500

Quoted 19 lines · Gerd Hoffmann
   Hi,

Review

Quoted 7 lines
(quoted diff) +7 -0
+u-boot.e500:
+    # examples fail to honor cflags, just remove them
+    rm -rf u-boot/examples
+    sed -i 's/examples//g' u-boot/Makefile
+    # Make linker script biarch aware
+    sed -i 's/OUTPUT_ARCH(powerpc)/OUTPUT_ARCH(powerpc:common)/' \
+        u-boot/arch/powerpc/cpu/mpc85xx/u-boot.lds

Hmm. Mucking with the source tree like this will leave the u-boot git tree in a dirty state, which isn't exactly nice. Fixable by sprinkling in a "git reset --hard", but that obviously has other downsides, such as seriously disturbing people trying to build a u-boot tree with local changes.

Any chance to fix that without patching the source tree, by passing SUBDIRS="<list-dirs-without-examples>" to $(MAKE) for example? Or send patches to u-boot upstream to tackle this?

Quoted 7 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+    # Compile u-boot
+    $(MAKE) -C u-boot O=build.e500 qemu-ppce500_config
+    $(MAKE) -C u-boot CROSS_COMPILE=$(powerpc64_cross_prefix) \
+        O=build.e500 KCFLAGS=-m32 KAFLAGS=-m32 \
+        LDFLAGS=-melf32ppc KCPPFLAGS=-m32 V=1 u-boot.bin
+    strip u-boot/build.e500/u-boot -o ../pc-bios/u-boot.e500

$(powerpc64_cross_prefix)strip I guess ...

This is getting too messy. I guess we can live without supporting biarch compilers and just ask people to have a 32bit ppc compiler handy. Then things become a lot more sane.

Alex

roms/Makefile +1 -0
index 2721b02..610b534 100644
@@ -31,6 +31,7 @@ find-cross-gcc = $(firstword $(wildcard $(patsubst %ld,%gcc,$(call find-cross-ld
 find-cross-prefix = $(subst gcc,,$(notdir $(call find-cross-gcc,$(1))))
 
 powerpc64_cross_prefix := $(call find-cross-prefix,powerpc64)
+powerpc_cross_prefix := $(call find-cross-prefix,powerpc)
 x86_64_cross_prefix := $(call find-cross-prefix,x86_64)
 
 #
@@ -55,6 +56,7 @@ default:
        @echo "  efirom         -- update nic roms (bios+efi, this needs"
        @echo "                    the EfiRom utility from edk2 / 

tianocore)"

        @echo "  slof           -- update slof.bin"
+       @echo "  u-boot.e500    -- update u-boot.e500"

bios: build-seabios-config-seabios-128k build-seabios-config-seabios-256k
cp seabios/builds/seabios-128k/bios.bin ../pc-bios/bios.bin
@@ -132,6 +134,12 @@ slof:
$(MAKE) -C SLOF CROSS=$(powerpc64_cross_prefix) qemu cp SLOF/boot_rom.bin ../pc-bios/slof.bin

+u-boot.e500:
+ $(MAKE) -C u-boot O=build.e500 qemu-ppce500_config
+ $(MAKE) -C u-boot CROSS_COMPILE=$(powerpc_cross_prefix) \
+ O=build.e500
+ $(powerpc_cross_prefix)strip u-boot/build.e500/u-boot -o \
+ ../pc-bios/u-boot.e500

clean:
rm -rf seabios/.config seabios/out seabios/builds
@@ -141,3 +149,4 @@ clean:

        rm -f sgabios/.depend
        $(MAKE) -C ipxe/src veryclean
        $(MAKE) -C SLOF clean

+ rm -rf u-boot/build.e500

#13 lore raw

Re: [Qemu-devel] [PATCH 8/9] PPC: Add u-boot firmware for e500

Hi,

Quoted 3 lines

This is getting too messy. I guess we can live without supporting biarch compilers and just ask people to have a 32bit ppc compiler handy. Then things become a lot more sane.

I actually like biarch compiler support, especially as the fedora cross compilers are biarch too. But without getting biarch compiler support into upstream u-boot it'll be pretty messy indeed ...

cheers,
Gerd

#14 lore raw

Re: [Qemu-devel] [PATCH 8/9] PPC: Add u-boot firmware for e500

Quoted 8 lines · Gerd Hoffmann
   Hi,
Quoted 3 lines

This is getting too messy. I guess we can live without supporting biarch compilers and just ask people to have a 32bit ppc compiler handy. Then things become a lot more sane.

I actually like biarch compiler support, especially as the fedora cross compilers are biarch too. But without getting biarch compiler support into upstream u-boot it'll be pretty messy indeed ...

Yes, and supporting biarch properly would create quite some headaches. U-boot does support targets that are 64bit, so we can't just always declare the link target 32bit.

And the subdir thing didn't work for me either. However I did spot a good number of places where the makefile assumes that subdirs mean you only want to create a module and behave differently, so again it's fragile wrt updates.

I really think we're safest off ignoring biarch for now. When someone who knows the toolchain well wants to take another stab at it, he at least knows where to start based on my earlier patches ;)

Alex

#15 lore raw

PATCH 9/9 PPC: e500: Move to u-boot as firmware

In reply to Alexander Graf

Almost all platforms QEMU emulates have some sort of firmware they can load to expose a guest environment that closely resembles the way it would look like on real hardware.

This patch introduces such a firmware on our e500 platforms. U-boot is the default firmware for most of these systems and as such our preferred choice.

For backwards compatibility reasons (and speed and simplicity) we skip u-boot when you use -kernel and don't pass in -bios. For all other combinations like -kernel and -bios or no -kernel you get u-boot as firmware.

This allows you to modify the boot environment, execute a networked boot through the e1000 emulation and execute u-boot payloads.

---

v1 -> v2:

- skip u-boot when -kernel and no -bios are given

---
 hw/ppc/e500.c | 112 +++++++++++++++++++++++++++++++++++++---------------------
 1 file changed, 72 insertions(+), 40 deletions(-)
hw/ppc/e500.c +72 -40
index d543934..8ae28d0 100644
@@ -39,7 +39,6 @@
 
 #define EPAPR_MAGIC                (0x45504150)
 #define BINARY_DEVICE_TREE_FILE    "mpc8544ds.dtb"
-#define UIMAGE_LOAD_BASE           0
 #define DTC_LOAD_PAD               0x1800000
 #define DTC_PAD_MASK               0xFFFFF
 #define DTB_MAX_SIZE               (8 * 1024 * 1024)
@@ -620,15 +619,18 @@ void ppce500_init(QEMUMachineInitArgs *args, PPCE500Params *params)
     MemoryRegion *ram = g_new(MemoryRegion, 1);
     PCIBus *pci_bus;
     CPUPPCState *env = NULL;
-    uint64_t elf_entry;
-    uint64_t elf_lowaddr;
-    hwaddr entry=0;
-    hwaddr loadaddr=UIMAGE_LOAD_BASE;
-    target_long kernel_size=0;
-    target_ulong dt_base = 0;
-    target_ulong initrd_base = 0;
-    target_long initrd_size = 0;
-    target_ulong cur_base = 0;
+    uint64_t loadaddr;
+    hwaddr kernel_base = -1LL;
+    int kernel_size = 0;
+    hwaddr dt_base = 0;
+    hwaddr initrd_base = 0;
+    int initrd_size = 0;
+    hwaddr cur_base = 0;
+    char *filename;
+    hwaddr bios_entry = 0;
+    target_long bios_size;
+    struct boot_info *boot_info;
+    int dt_size;
     int i;
     /* irq num for pin INTA, INTB, INTC and INTD is 1, 2, 3 and
      * 4 respectively */
@@ -758,29 +760,24 @@ void ppce500_init(QEMUMachineInitArgs *args, PPCE500Params *params)
     /* Register spinning region */
     sysbus_create_simple("e500-spin", MPC8544_SPIN_BASE, NULL);
 
+    if (cur_base < (32 * 1024 * 1024)) {
+        /* u-boot occupies memory up to 32MB, so load blobs above */
+        cur_base = (32 * 1024 * 1024);
+    }
+
     /* Load kernel. */
     if (args->kernel_filename) {
-        kernel_size = load_uimage(args->kernel_filename, &entry,
-                                  &loadaddr, NULL);
-        if (kernel_size < 0) {
-            kernel_size = load_elf(args->kernel_filename, NULL, NULL,
-                                   &elf_entry, &elf_lowaddr, NULL, 1,
-                                   ELF_MACHINE, 0);
-            entry = elf_entry;
-            loadaddr = elf_lowaddr;
-        }
-        /* XXX try again as binary */
+        kernel_base = cur_base;
+        kernel_size = load_image_targphys(args->kernel_filename,
+                                          cur_base,
+                                          ram_size - cur_base);
         if (kernel_size < 0) {
             fprintf(stderr, "qemu: could not load kernel '%s'\n",
                     args->kernel_filename);
             exit(1);
         }
 
-        cur_base = loadaddr + kernel_size;
-
-        /* Reserve space for dtb */
-        dt_base = (cur_base + DTC_LOAD_PAD) & ~DTC_PAD_MASK;
-        cur_base += DTB_MAX_SIZE;
+        cur_base += kernel_size;
     }
 
     /* Load initrd. */
@@ -798,25 +795,60 @@ void ppce500_init(QEMUMachineInitArgs *args, PPCE500Params *params)
         cur_base = initrd_base + initrd_size;
     }
 
-    /* If we're loading a kernel directly, we must load the device tree too. */
-    if (args->kernel_filename) {
-        struct boot_info *boot_info;
-        int dt_size;
-
-        dt_size = ppce500_prep_device_tree(args, params, dt_base,
-                                           initrd_base, initrd_size,
-                                           loadaddr, kernel_size);
-        if (dt_size < 0) {
-            fprintf(stderr, "couldn't load device tree\n");
+    /*
+     * Smart firmware defaults ahead!
+     *
+     * We follow the following table to select which payload we execute.
+     *
+     *  -kernel | -bios | payload
+     * ---------+-------+---------
+     *     N    |   Y   | u-boot
+     *     N    |   N   | u-boot
+     *     Y    |   Y   | u-boot
+     *     Y    |   N   | kernel
+     *
+     * This ensures backwards compatibility with how we used to expose
+     * -kernel to users but allows them to run through u-boot as well.
+     */
+    if (bios_name == NULL) {
+        if (args->kernel_filename) {
+            bios_name = args->kernel_filename;
+        } else {
+            bios_name = "u-boot.e500";
+        }
+    }
+    filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
+
+    bios_size = load_elf(filename, NULL, NULL, &bios_entry, &loadaddr, NULL,
+                         1, ELF_MACHINE, 0);
+    if (bios_size < 0) {
+        /*
+         * Hrm. No ELF image? Try a uImage, maybe someone is giving us an
+         * ePAPR compliant kernel
+         */
+        kernel_size = load_uimage(filename, &bios_entry, &loadaddr, NULL);
+        if (kernel_size < 0) {
+            fprintf(stderr, "qemu: could not load firmware '%s'\n", filename);
             exit(1);
         }
-        assert(dt_size < DTB_MAX_SIZE);
+    }
+
+    /* Reserve space for dtb */
+    dt_base = (loadaddr + bios_size + DTC_LOAD_PAD) & ~DTC_PAD_MASK;
 
-        boot_info = env->load_info;
-        boot_info->entry = entry;
-        boot_info->dt_base = dt_base;
-        boot_info->dt_size = dt_size;
+    dt_size = ppce500_prep_device_tree(args, params, dt_base,
+                                       initrd_base, initrd_size,
+                                       kernel_base, kernel_size);
+    if (dt_size < 0) {
+        fprintf(stderr, "couldn't load device tree\n");
+        exit(1);
     }
+    assert(dt_size < DTB_MAX_SIZE);
+
+    boot_info = env->load_info;
+    boot_info->entry = bios_entry;
+    boot_info->dt_base = dt_base;
+    boot_info->dt_size = dt_size;
 
     if (kvm_enabled()) {
         kvmppc_init();
Signature · 1 line
1.8.1.4
#16 lore raw
In reply to Alexander Graf
Quoted 26 lines · Alexander Graf

Today we don't run any firmware on our e500 platform. You're either running a Linux kernel directly through -kernel or you don't boot the VM at all.

This is bad for multiple reasons. The normal firmware on e500 based systems is u-boot. Some OSes (IIRC FreeBSD) rely on u-boot for their 2nd stage boot loader. Since that relies on interfaces u-boot provides we can't execute it today.

The other case where we're falling short of expectations that I'm aware of is network boot. With a firmware you can actually pxe boot a virtual machine.

This patch set implements all the pieces necessary to run u-boot as the firmware for our e500 platforms: mpc8544ds and e500plat. It is based on upstream u-boot code that implements a target specific for the simplified system QEMU implements.

Due to popular demand the default -kernel booting has *not* been changed from directly booting into the kernel. This is possible because we don't need to run firmware to provide run time services.

However, whenever the user explicitly defines a -bios blob, we run it. That means if you want to route a -kernel boot through u-boot you have to pass in -bios pc-bios/u-boot.e500 -kernel uImage.

Please try out as many things as you're able to try.

Quoted 7 lines

Known missing bits:

- -boot doesn't get interpreted yet
- pflash is missing, so the environment is volatile
- no block drivers available (ata_piix is broken in u-boot and virtio-blk is missing)
- KVM patches to support u-boot are probably going to hit 3.16

This is v2 of the patch set.

v1 -> v2:

- correct permission access to USER_RO
- Update to newer u-boot version
- Add git submodule for u-boot
- skip u-boot when -kernel and no -bios are given

Alex