Skip to contentSkip to conversation

spapr: Kill SLOF

PATCH Superseded Alexey Kardashevskiy 2 participants 15 messages Feb 20, 2020 – Mar 6, 2020

v7 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v7 cover spapr: Kill SLOF

This is another attempt to implement minimalistic
Open Firmware Client Interface in QEMU.

With this thing, I can boot unmodified Ubuntu 18.04 and Fedora 30 directly from the disk without SLOF.

A useful discussion happened esrlier:
https://lore.kernel.org/qemu-devel/[email protected]/

5/5 is kind of controvertial though. This respin does not include networking.

This is based on sha1
015fb0ead60d Chen Qun "hw/ppc/virtex_ml507:fix leak of fdevice tree blob".

Please comment. Thanks.

Alexey Kardashevskiy (5):
ppc/spapr: Move GPRs setup to one place spapr/spapr: Make vty_getchars public spapr/cas: Separate CAS handling from rebuilding the FDT
spapr: Implement Open Firmware client interface spapr/vof: Add basic support for MBR/GPT/GRUB

 hw/ppc/Makefile.objs            |    1 +
 pc-bios/vof/Makefile            |   18 +
 include/hw/ppc/spapr.h          |   27 +-
 include/hw/ppc/spapr_cpu_core.h |    4 +-
 include/hw/ppc/spapr_vio.h      |    1 +
 pc-bios/vof/vof.h               |   63 ++
 hw/char/spapr_vty.c             |    2 +-
 hw/ppc/spapr.c                  |   69 +-
 hw/ppc/spapr_cpu_core.c         |    6 +-
 hw/ppc/spapr_hcall.c            |   73 +-
 hw/ppc/spapr_of_client.c        | 1285 +++++++++++++++++++++++++++++++
 hw/ppc/spapr_rtas.c             |    2 +-
 pc-bios/vof/bootblock.c         |  242 ++++++
 pc-bios/vof/bootmem.c           |   13 +
 pc-bios/vof/ci.c                |  147 ++++
 pc-bios/vof/elf32.c             |  273 +++++++
 pc-bios/vof/libc.c              |   91 +++
 pc-bios/vof/main.c              |   24 +
 hw/ppc/trace-events             |   25 +
 pc-bios/README                  |    2 +
 pc-bios/vof.bin                 |  Bin 0 -> 9180 bytes
 pc-bios/vof/entry.S             |   58 ++
 pc-bios/vof/l.lds               |   48 ++
 23 files changed, 2429 insertions(+), 45 deletions(-)
 create mode 100644 pc-bios/vof/Makefile
 create mode 100644 pc-bios/vof/vof.h
 create mode 100644 hw/ppc/spapr_of_client.c
 create mode 100644 pc-bios/vof/bootblock.c
 create mode 100644 pc-bios/vof/bootmem.c
 create mode 100644 pc-bios/vof/ci.c
 create mode 100644 pc-bios/vof/elf32.c
 create mode 100644 pc-bios/vof/libc.c
 create mode 100644 pc-bios/vof/main.c
 create mode 100755 pc-bios/vof.bin
 create mode 100644 pc-bios/vof/entry.S
 create mode 100644 pc-bios/vof/l.lds
Signature · 1 line
2.17.1
#1 lore raw

PATCH v7 1/5 ppc/spapr: Move GPRs setup to one place

At the moment "pseries" starts in SLOF which only expects the FDT blob pointer in r3. As we are going to introduce a OpenFirmware support in QEMU, we will be booting OF clients directly and these expect a stack pointer in r1, Linux looks at r3/r4 for the initramdisk location (although vmlinux can find this from the device tree but zImage from distro kernels cannot).

This extends spapr_cpu_set_entry_state() to take more registers. This should cause no behavioral change.

---
Changes:
v7:
* removed r5 as it points to prom entry which is now provided by a new firmware in later patches

---
 include/hw/ppc/spapr_cpu_core.h | 4 +++-
 hw/ppc/spapr.c                  | 2 +-
 hw/ppc/spapr_cpu_core.c         | 6 +++++-
 hw/ppc/spapr_rtas.c             | 2 +-
 4 files changed, 10 insertions(+), 4 deletions(-)
include/hw/ppc/spapr_cpu_core.h +3 -1
index 1c4cc6559c52..7aed8f555b4f 100644
@@ -40,7 +40,9 @@ typedef struct SpaprCpuCoreClass {
 } SpaprCpuCoreClass;
 
 const char *spapr_get_cpu_core_type(const char *cpu_type);
-void spapr_cpu_set_entry_state(PowerPCCPU *cpu, target_ulong nip, target_ulong r3);
+void spapr_cpu_set_entry_state(PowerPCCPU *cpu, target_ulong nip,
+                               target_ulong r1, target_ulong r3,
+                               target_ulong r4);
 
 typedef struct SpaprCpuState {
     uint64_t vpa_addr;
hw/ppc/spapr.c +1 -1
index 828e2cc1359a..90b68e2f479e 100644
@@ -1691,7 +1691,7 @@ static void spapr_machine_reset(MachineState *machine)
     spapr->fdt_blob = fdt;
 
     /* Set up the entry state */
-    spapr_cpu_set_entry_state(first_ppc_cpu, SPAPR_ENTRY_POINT, fdt_addr);
+    spapr_cpu_set_entry_state(first_ppc_cpu, SPAPR_ENTRY_POINT, 0, fdt_addr, 0);
     first_ppc_cpu->env.gpr[5] = 0;
 
     spapr->cas_reboot = false;
hw/ppc/spapr_cpu_core.c +5 -1
index d09125d9afd4..590bd70e05cc 100644
@@ -84,13 +84,17 @@ static void spapr_reset_vcpu(PowerPCCPU *cpu)
     spapr_irq_cpu_intc_reset(spapr, cpu);
 }
 
-void spapr_cpu_set_entry_state(PowerPCCPU *cpu, target_ulong nip, target_ulong r3)
+void spapr_cpu_set_entry_state(PowerPCCPU *cpu, target_ulong nip,
+                               target_ulong r1, target_ulong r3,
+                               target_ulong r4)
 {
     PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu);
     CPUPPCState *env = &cpu->env;
 
     env->nip = nip;
+    env->gpr[1] = r1;
     env->gpr[3] = r3;
+    env->gpr[4] = r4;
     kvmppc_set_reg_ppc_online(cpu, 1);
     CPU(cpu)->halted = 0;
     /* Enable Power-saving mode Exit Cause exceptions */
hw/ppc/spapr_rtas.c +1 -1
index 656fdd221665..fe83b50c6629 100644
@@ -190,7 +190,7 @@ static void rtas_start_cpu(PowerPCCPU *callcpu, SpaprMachineState *spapr,
      */
     newcpu->env.tb_env->tb_offset = callcpu->env.tb_env->tb_offset;
 
-    spapr_cpu_set_entry_state(newcpu, start, r3);
+    spapr_cpu_set_entry_state(newcpu, start, 0, r3, 0);
 
     qemu_cpu_kick(CPU(newcpu));
 
Signature · 1 line
2.17.1
#2 lore raw

PATCH v7 2/5 spapr/spapr: Make vty_getchars public

In reply to Alexey Kardashevskiy

A serial device fetches the data from the chardev backend as soon as input happens and stores it in its internal device specific buffer, every char device implements it again. Since there is no unified interface to read such buffer, we will have to read characters directly from VIO_SPAPR_VTY_DEVICE. The OF client is going to need this.

---
 include/hw/ppc/spapr_vio.h | 1 +
 hw/char/spapr_vty.c        | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
include/hw/ppc/spapr_vio.h +1 -0
index bed7df60e35c..77e9b73bdfe0 100644
@@ -130,6 +130,7 @@ int spapr_vio_send_crq(SpaprVioDevice *dev, uint8_t *crq);
 
 SpaprVioDevice *vty_lookup(SpaprMachineState *spapr, target_ulong reg);
 void vty_putchars(SpaprVioDevice *sdev, uint8_t *buf, int len);
+int vty_getchars(SpaprVioDevice *sdev, uint8_t *buf, int max);
 void spapr_vty_create(SpaprVioBus *bus, Chardev *chardev);
 void spapr_vlan_create(SpaprVioBus *bus, NICInfo *nd);
 void spapr_vscsi_create(SpaprVioBus *bus);
hw/char/spapr_vty.c +1 -1
index ecb94f5673ca..1c00da75b4f1 100644
@@ -52,7 +52,7 @@ static void vty_receive(void *opaque, const uint8_t *buf, int size)
     }
 }
 
-static int vty_getchars(SpaprVioDevice *sdev, uint8_t *buf, int max)
+int vty_getchars(SpaprVioDevice *sdev, uint8_t *buf, int max)
 {
     SpaprVioVty *dev = VIO_SPAPR_VTY_DEVICE(sdev);
     int n = 0;
Signature · 1 line
2.17.1
#3 lore raw

PATCH v7 3/5 spapr/cas: Separate CAS handling from rebuilding the FDT

In reply to Alexey Kardashevskiy

At the moment "ibm,client-architecture-support" ("CAS") is implemented in SLOF and QEMU assists via the custom H_CAS hypercall which copies an updated flatten device tree (FDT) blob to the SLOF memory which it then uses to update its internal tree.

When we enable the OpenFirmware client interface in QEMU, we won't need to copy the FDT to the guest as the client is expected to fetch the device tree using the client interface.

This moves FDT rebuild out to a separate helper which is going to be called from the "ibm,client-architecture-support" handler and leaves writing FDT to the guest in the H_CAS handler.

This should not cause any behavioral change.

---
 include/hw/ppc/spapr.h |  7 +++++
 hw/ppc/spapr.c         |  1 -
 hw/ppc/spapr_hcall.c   | 67 ++++++++++++++++++++++++++----------------
 3 files changed, 48 insertions(+), 27 deletions(-)
include/hw/ppc/spapr.h +7 -0
index 09110961a589..7802acee0c85 100644
@@ -102,6 +102,8 @@ typedef enum {
 #define SPAPR_CAP_FIXED_CCD             0x03
 #define SPAPR_CAP_FIXED_NA              0x10 /* Lets leave a bit of a gap... */
 
+#define FDT_MAX_SIZE                    0x100000
+
 typedef struct SpaprCapabilities SpaprCapabilities;
 struct SpaprCapabilities {
     uint8_t caps[SPAPR_CAP_NUM];
@@ -558,6 +560,11 @@ void spapr_register_hypercall(target_ulong opcode, spapr_hcall_fn fn);
 target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode,
                              target_ulong *args);
 
+target_ulong do_client_architecture_support(PowerPCCPU *cpu,
+                                            SpaprMachineState *spapr,
+                                            target_ulong addr,
+                                            target_ulong fdt_bufsize);
+
 /* Virtual Processor Area structure constants */
 #define VPA_MIN_SIZE           640
 #define VPA_SIZE_OFFSET        0x4
hw/ppc/spapr.c +0 -1
index 90b68e2f479e..62d6487c2568 100644
@@ -96,7 +96,6 @@
  *
  * We load our kernel at 4M, leaving space for SLOF initial image
  */
-#define FDT_MAX_SIZE            0x100000
 #define RTAS_MAX_ADDR           0x80000000 /* RTAS must stay below that */
 #define FW_MAX_SIZE             0x400000
 #define FW_FILE_NAME            "slof.bin"
hw/ppc/spapr_hcall.c +41 -26

105 lines not on this page · raw message

Signature · 1 line
2.17.1
#4 lore raw

PATCH v7 4/5 spapr: Implement Open Firmware client interface

In reply to Alexey Kardashevskiy

The PAPR platform which describes an OS environment that's presented by a combination of a hypervisor and firmware. The features it specifies require collaboration between the firmware and the hypervisor.

Since the beginning, the runtime component of the firmware (RTAS) has been implemented as a 20 byte shim which simply forwards it to a hypercall implemented in qemu. The boottime firmware component is SLOF - but a build that's specific to qemu, and has always needed to be updated in sync with it. Even though we've managed to limit the amount of runtime communication we need between qemu and SLOF, there's some, and it's become increasingly awkward to handle as we've implemented new features.

This implements a boot time OF client interface (CI) which is enabled by a new "vof" pseries machine option (stands for "Virtual Open Firmware). When enabled, QEMU implements the custom H_OF_CLIENT hcall which implements Open Firmware Client Interface (OF CI). This allows using a smaller stateless firmware which does not have to manage the device tree.

The new "vof.bin" firmware image is included with source code under pc-bios/. It also includes RTAS blob.

This adds support for a console. For output any serial device can be used, for stdin the support is limited by spapr-vty only as allowing input from a serial device requires device-model specific code (output is simpler).

This implements a handful of CI methods just to get Linux and GRUB going; Linux requires even less. In particular, this implements the device tree fetching, reading from block device, read-write stdout/stdin and ibm,client-architecture-support.

This implements changing some device tree properties which we know how to deal with, the rest is ignored. To allow changes, this skips fdt_pack() when vof=on as not packing the blob leaves some room for appending.

In absence of SLOF, this assigns "phandles" to device tree nodes to make device tree traversing work.

When vof=on, this adds "/chosen" every time QEMU (re)builds a tree.

This implements "claim" (an OF CI memory allocator) and updates "/memory@0/available" to report the client about available memory.

This adds basic instances support which are managed by a hashmap ihandle -> [phandle, DeviceState, CharBackend].

Before the guest started, the used memory is:
0..4000 - the initial firmware
10000..180000 - stack

This OF CI does not implement "interpret".

With this basic support, this can only boot into kernel directly. However this is just enough for the petitboot kernel and initradmdisk to boot from any possible source.

---
Changes:
v7:
* now we have a small firmware which loads at 0 as SLOF and starts from 0x100 as SLOF
* no MBR/ELF/GRUB business in QEMU anymore
* blockdev is a separate patch
* networking is a separate patch

v6:
* borrowed a big chunk of commit log introduction from David
* fixed initial stack pointer (points to the highest address of stack)
* traces for "interpret" and others
* disabled translate_kernel_address() hack so grub can load (work in progress)
* added "milliseconds" for grub
* fixed "claim" allocator again
* moved FDT_MAX_SIZE to spapr.h as spapr_of_client.c wants it too for CAS
* moved the most code possible from spapr.c to spapr_of_client.c, such as RTAS, prom entry and FDT build/finalize
* separated blobs
* GRUB now proceeds to its console prompt (there are still other issues)
* parse MBR/GPT to find PReP and load GRUB

v5:
* made instances keep device and chardev pointers
* removed VIO dependencies
* print error if RTAS memory is not claimed as it should have been
* pack FDT as "quiesce"

v4:
* fixed open
* validate ihandles in "call-method"

v3:
* fixed phandles allocation
* s/__be32/uint32_t/ as we do not normally have __be32 type in qemu
* fixed size of /chosen/stdout
* bunch of renames
* do not create rtas properties at all, let the client deal with it; instead setprop allows changing these in the FDT
* no more packing FDT when bios=off - nobody needs it and getprop does not work otherwise
* allow updating initramdisk device tree properties (for zImage)
* added instances
* fixed stdout on OF's "write"
* removed special handling for stdout in OF client, spapr-vty handles it instead

v2:
* fixed claim()
* added "setprop"
* cleaner client interface and RTAS blobs management
* boots to petitboot and further to the target system
* more trace points

---
 hw/ppc/Makefile.objs     |    1 +
 pc-bios/vof/Makefile     |   18 +
 include/hw/ppc/spapr.h   |   20 +-
 pc-bios/vof/vof.h        |   48 ++
 hw/ppc/spapr.c           |   68 ++-
 hw/ppc/spapr_hcall.c     |    6 +-
 hw/ppc/spapr_of_client.c | 1221 ++++++++++++++++++++++++++++++++++++++
 pc-bios/vof/bootmem.c    |   13 +
 pc-bios/vof/ci.c         |  136 +++++
 pc-bios/vof/libc.c       |   91 +++
 pc-bios/vof/main.c       |   23 +
 hw/ppc/trace-events      |   21 +
 pc-bios/README           |    2 +
 pc-bios/vof.bin          |  Bin 0 -> 4272 bytes
 pc-bios/vof/entry.S      |   58 ++
 pc-bios/vof/l.lds        |   48 ++
 16 files changed, 1760 insertions(+), 14 deletions(-)
 create mode 100644 pc-bios/vof/Makefile
 create mode 100644 pc-bios/vof/vof.h
 create mode 100644 hw/ppc/spapr_of_client.c
 create mode 100644 pc-bios/vof/bootmem.c
 create mode 100644 pc-bios/vof/ci.c
 create mode 100644 pc-bios/vof/libc.c
 create mode 100644 pc-bios/vof/main.c
 create mode 100755 pc-bios/vof.bin
 create mode 100644 pc-bios/vof/entry.S
 create mode 100644 pc-bios/vof/l.lds
hw/ppc/Makefile.objs +1 -0
index c3d3cc56eb51..70aa7918ba8a 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_PSERIES) += spapr_hcall.o spapr_iommu.o spapr_rtas.o
 obj-$(CONFIG_PSERIES) += spapr_pci.o spapr_rtc.o spapr_drc.o
 obj-$(CONFIG_PSERIES) += spapr_cpu_core.o spapr_ovec.o spapr_irq.o
 obj-$(CONFIG_PSERIES) += spapr_tpm_proxy.o spapr_nvdimm.o
+obj-$(CONFIG_PSERIES) += spapr_of_client.o
 obj-$(CONFIG_SPAPR_RNG) +=  spapr_rng.o
 obj-$(call land,$(CONFIG_PSERIES),$(CONFIG_LINUX)) += spapr_pci_vfio.o spapr_pci_nvlink2.o
 # IBM PowerNV
pc-bios/vof/Makefile new file +18 -0
new file mode 100644
index 000000000000..49f7e240eeff
@@ -0,0 +1,18 @@
+all: build-all
+
+build-all: vof.bin
+
+%.o: %.S
+	cc -m32 -mbig-endian -c -o $@ $<
+
+%.o: %.c
+	cc -m32 -mbig-endian -c -fno-stack-protector -Wno-builtin-declaration-mismatch -o $@ $<
+
+vof.elf: entry.o main.o libc.o ci.o bootmem.o
+	ld -nostdlib -e_start -Tl.lds -EB -o $@ $^
+
+%.bin: %.elf
+	objcopy -O binary -j .text -j .data -j .toc -j .got2 $^ $@
+
+clean:
+	rm -f *.o *.bin *.elf *~
include/hw/ppc/spapr.h +19 -1
index 7802acee0c85..5ef4c865695a 100644
@@ -109,6 +109,11 @@ struct SpaprCapabilities {
     uint8_t caps[SPAPR_CAP_NUM];
 };
 
+typedef struct {
+    uint64_t start;
+    uint64_t size;
+} SpaprOfClaimed;
+
 /**
  * SpaprMachineClass:
  */
@@ -165,6 +170,14 @@ struct SpaprMachineState {
     long kernel_size;
     bool kernel_le;
     uint64_t kernel_addr;
+    bool vof; /* Virtual Open Firmware */
+    uint32_t rtas_base;
+    GArray *claimed; /* array of SpaprOfClaimed */
+    uint64_t claimed_base;
+    GHashTable *of_instances; /* ihandle -> SpaprOfInstance */
+    uint32_t of_instance_last;
+    Notifier machine_ready;
+    char *bootargs;
     uint32_t initrd_base;
     long initrd_size;
     uint64_t rtc_offset; /* Now used only during incoming migration */
@@ -532,7 +545,8 @@ struct SpaprMachineState {
 /* Client Architecture support */
 #define KVMPPC_H_CAS            (KVMPPC_HCALL_BASE + 0x2)
 #define KVMPPC_H_UPDATE_DT      (KVMPPC_HCALL_BASE + 0x3)
-#define KVMPPC_HCALL_MAX        KVMPPC_H_UPDATE_DT
+#define KVMPPC_H_OF_CLIENT      (KVMPPC_HCALL_BASE + 0x5)
+#define KVMPPC_HCALL_MAX        KVMPPC_H_OF_CLIENT
 
 /*
  * The hcall range 0xEF00 to 0xEF80 is reserved for use in facilitating
@@ -801,6 +815,10 @@ struct SpaprEventLogEntry {
 void *spapr_build_fdt(SpaprMachineState *spapr, bool reset, size_t space);
 void spapr_events_init(SpaprMachineState *sm);
 void spapr_dt_events(SpaprMachineState *sm, void *fdt);
+void spapr_setup_of_client(SpaprMachineState *spapr, target_ulong *stack_ptr);
+void spapr_of_client_dt(SpaprMachineState *spapr, void *fdt);
+void spapr_of_client_dt_finalize(SpaprMachineState *spapr);
+void spapr_of_client_machine_init(SpaprMachineState *spapr);
 void close_htab_fd(SpaprMachineState *spapr);
 void spapr_setup_hpt_and_vrma(SpaprMachineState *spapr);
 void spapr_free_hpt(SpaprMachineState *spapr);
pc-bios/vof/vof.h new file +48 -0

48 lines not on this page · raw message

hw/ppc/spapr.c +56 -12

117 lines not on this page · raw message

hw/ppc/spapr_hcall.c +5 -1
index 35de3ab95f42..63446db411f5 100644
@@ -1844,12 +1844,16 @@ target_ulong do_client_architecture_support(PowerPCCPU *cpu,
             spapr_setup_hpt_and_vrma(spapr);
         }
 
-        fdt = spapr_build_fdt(spapr, false, fdt_bufsize);
+        fdt = spapr_build_fdt(spapr, spapr->vof, fdt_bufsize);
 
         g_free(spapr->fdt_blob);
         spapr->fdt_size = fdt_totalsize(fdt);
         spapr->fdt_initial_size = spapr->fdt_size;
         spapr->fdt_blob = fdt;
+
+        if (spapr->vof) {
+            spapr_of_client_dt_finalize(spapr);
+        }
     }
 
     if (spapr->cas_reboot) {
hw/ppc/spapr_of_client.c new file +1221 -0

1,221 lines not on this page · raw message

pc-bios/vof/bootmem.c new file +13 -0
new file mode 100644
index 000000000000..de7d5fc76431
@@ -0,0 +1,13 @@
+#include "vof.h"
+
+void boot_from_memory(uint64_t initrd, uint64_t initrdsize)
+{
+	uint64_t kern[2];
+	phandle chosen = ci_finddevice("/chosen");
+
+	if (ci_getprop(chosen, "qemu,boot-kernel", kern, sizeof(kern)) !=
+			sizeof(kern))
+		return;
+
+	do_boot(kern[0], initrd, initrdsize);
+}
pc-bios/vof/ci.c new file +136 -0

136 lines not on this page · raw message

pc-bios/vof/libc.c new file +91 -0

91 lines not on this page · raw message

pc-bios/vof/main.c new file +23 -0
new file mode 100644
index 000000000000..eb9aa8b78a8f
@@ -0,0 +1,23 @@
+#include "vof.h"
+
+
+void do_boot(unsigned long addr, unsigned long _r3, unsigned long _r4)
+{
+	register unsigned long r3 __asm__("r3") = _r3;
+	register unsigned long r4 __asm__("r4") = _r4;
+	register unsigned long r5 __asm__("r5") = (unsigned long) _prom_entry;
+
+	((client *)(uint32_t)addr)();
+}
+
+void entry_c(void)
+{
+	register unsigned long r3 __asm__("r3");
+	register unsigned long r4 __asm__("r4");
+	register unsigned long r5 __asm__("r5");
+	uint64_t initrd = r3, initrdsize = r4;
+
+	ci_stdout("*** Virtual Open Firmware ***\n");
+	boot_from_memory(initrd, initrdsize);
+	ci_panic("*** No boot target ***\n");
+}
hw/ppc/trace-events +21 -0
index 9ea620f23c85..640d0649394d 100644
@@ -21,6 +21,27 @@ spapr_update_dt(unsigned cb) "New blob %u bytes"
 spapr_update_dt_failed_size(unsigned cbold, unsigned cbnew, unsigned magic) "Old blob %u bytes, new blob %u bytes, magic 0x%x"
 spapr_update_dt_failed_check(unsigned cbold, unsigned cbnew, unsigned magic) "Old blob %u bytes, new blob %u bytes, magic 0x%x"
 
+# spapr_client.c
+spapr_of_client_error_str_truncated(const char *s, int len) "%s truncated to %d"
+spapr_of_client_error_param(const char *method, int nargscheck, int nretcheck, int nargs, int nret) "%s takes/returns %d/%d, not %d/%d"
+spapr_of_client_error_unknown_service(const char *service, int nargs, int nret) "\"%s\" args=%d rets=%d"
+spapr_of_client_error_unknown_method(const char *method) "\"%s\""
+spapr_of_client_error_unknown_ihandle_close(uint32_t ih) "ih=0x%x"
+spapr_of_client_error_unknown_path(const char *path) "\"%s\""
+spapr_of_client_finddevice(const char *path, uint32_t ph) "\"%s\" => ph=0x%x"
+spapr_of_client_canon(const char *path) "\"%s\""
+spapr_of_client_claim(uint32_t virt, uint32_t size, uint32_t align, uint32_t ret) "virt=0x%x size=0x%x align=0x%x => 0x%x"
+spapr_of_client_release(uint32_t virt, uint32_t size, uint32_t ret) "virt=0x%x size=0x%x => 0x%x"
+spapr_of_client_method(uint32_t ihandle, const char *method, uint32_t param, uint32_t ret, uint32_t ret2) "ih=0x%x \"%s\"(0x%x) => 0x%x 0x%x"
+spapr_of_client_getprop(uint32_t ph, const char *prop, uint32_t ret, const char *val) "ph=0x%x \"%s\" => len=%d [%s]"
+spapr_of_client_getproplen(uint32_t ph, const char *prop, uint32_t ret) "ph=0x%x \"%s\" => len=%d"
+spapr_of_client_setprop(uint32_t ph, const char *prop, const char *val, uint32_t ret) "ph=0x%x \"%s\" [%s] => len=%d"
+spapr_of_client_open(const char *path, uint32_t ph, uint32_t ih) "%s ph=0x%x => ih=0x%x"
+spapr_of_client_interpret(const char *cmd, uint32_t param1, uint32_t param2, uint32_t ret, uint32_t ret2) "[%s] 0x%x 0x%x => 0x%x 0x%x"
+spapr_of_client_package_to_path(uint32_t ph, const char *tmp, uint32_t ret) "ph=0x%x => %s len=%d"
+spapr_of_client_instance_to_path(uint32_t ih, uint32_t ph, const char *tmp, uint32_t ret) "ih=0x%x ph=0x%x => %s len=%d"
+spapr_of_client_instance_to_package(uint32_t ih, uint32_t ph) "ih=0x%x => ph=0x%x"
+
 # spapr_hcall_tpm.c
 spapr_h_tpm_comm(const char *device_path, uint64_t operation) "tpm_device_path=%s operation=0x%"PRIu64
 spapr_tpm_execute(uint64_t data_in, uint64_t data_in_sz, uint64_t data_out, uint64_t data_out_sz) "data_in=0x%"PRIx64", data_in_sz=%"PRIu64", data_out=0x%"PRIx64", data_out_sz=%"PRIu64
pc-bios/README +2 -0
index 193aa375fc63..ea10610c708e 100644
@@ -16,6 +16,8 @@
   https://github.com/aik/SLOF, and the image currently in qemu is
   built from git tag qemu-slof-20200217.
 
+- vof is a minimalistic firmware to work with -machine pseries,vof=on.
+
 - sgabios (the Serial Graphics Adapter option ROM) provides a means for
   legacy x86 software to communicate with an attached serial console as
   if a video card were attached.  The master sources reside in a subversion
pc-bios/vof.bin new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..152d86a094ce376ee8962c3f26afeccc9e7cae58
GIT binary patch
pc-bios/vof/entry.S new file +58 -0

58 lines not on this page · raw message

pc-bios/vof/l.lds new file +48 -0

48 lines not on this page · raw message

Signature · 1 line
2.17.1
#5 lore raw

PATCH v7 5/5 spapr/vof: Add basic support for MBR/GPT/GRUB

In reply to Alexey Kardashevskiy

This hooks up disks to block backends so vof.bin can read MBR/GPT, find a bootloader and run it. This bypasses the device drivers and goes straight to the backend.

This implements basic support for 32bit big endian bootloader; tested on GRUB.

---
 pc-bios/vof/Makefile     |   2 +-
 pc-bios/vof/vof.h        |  15 +++
 hw/ppc/spapr_of_client.c |  64 +++++++++
 pc-bios/vof/bootblock.c  | 242 ++++++++++++++++++++++++++++++++++
 pc-bios/vof/ci.c         |  11 ++
 pc-bios/vof/elf32.c      | 273 +++++++++++++++++++++++++++++++++++++++
 pc-bios/vof/main.c       |   1 +
 hw/ppc/trace-events      |   4 +
 pc-bios/vof.bin          | Bin 4272 -> 9180 bytes
 9 files changed, 611 insertions(+), 1 deletion(-)
 create mode 100644 pc-bios/vof/bootblock.c
 create mode 100644 pc-bios/vof/elf32.c
pc-bios/vof/Makefile +1 -1
index 49f7e240eeff..7e4227bb2cc6 100644
@@ -8,7 +8,7 @@ build-all: vof.bin
 %.o: %.c
 	cc -m32 -mbig-endian -c -fno-stack-protector -Wno-builtin-declaration-mismatch -o $@ $<
 
-vof.elf: entry.o main.o libc.o ci.o bootmem.o
+vof.elf: entry.o main.o libc.o ci.o bootmem.o bootblock.o elf32.o
 	ld -nostdlib -e_start -Tl.lds -EB -o $@ $^
 
 %.bin: %.elf
pc-bios/vof/vof.h +15 -0
index 738b2539aa19..b16270b289b7 100644
@@ -37,6 +37,8 @@ phandle ci_finddevice(const char *path);
 uint32_t ci_getprop(phandle ph, const char *propname, void *prop, int len);
 ihandle ci_open(const char *path);
 void ci_close(ihandle ih);
+uint32_t ci_block_size(ihandle ih);
+uint32_t ci_seek(ihandle ih, uint64_t offset);
 uint32_t ci_read(ihandle ih, void *buf, int len);
 uint32_t ci_write(ihandle ih, const void *buf, int len);
 void ci_stdout(const char *buf);
@@ -44,5 +46,18 @@ void ci_stdoutn(const char *buf, int len);
 void *ci_claim(void *virt, uint32_t size, uint32_t align);
 uint32_t ci_release(void *virt, uint32_t size);
 
+/* ELF */
+int elf_load_file(void *file_addr, uint32_t *entry,
+                  int (*pre_load)(void*, long),
+                  void (*post_load)(void*, long));
+
+/* booting from blockdev */
+void boot_block(void);
+
 /* booting from -kernel */
 void boot_from_memory(uint64_t initrd, uint64_t initrdsize);
+
+/* bswap */
+#define le16_to_cpu(x) __builtin_bswap16(x)
+#define le32_to_cpu(x) __builtin_bswap32(x)
+#define le64_to_cpu(x) __builtin_bswap64(x)
hw/ppc/spapr_of_client.c +64 -0

112 lines not on this page · raw message

pc-bios/vof/bootblock.c new file +242 -0

242 lines not on this page · raw message

pc-bios/vof/ci.c +11 -0
index 143676421984..584776b2ff5b 100644
@@ -96,6 +96,17 @@ void ci_close(ihandle ih)
 	call_prom("close", 1, 0, ih);
 }
 
+uint32_t ci_block_size(ihandle ih)
+{
+	return 512;
+}
+
+uint32_t ci_seek(ihandle ih, uint64_t offset)
+{
+	return call_prom("seek", 3, 1, ih, (prom_arg_t)(offset >> 32),
+			(prom_arg_t)(offset & 0xFFFFFFFFUL));
+}
+
 uint32_t ci_read(ihandle ih, void *buf, int len)
 {
 	return call_prom("read", 3, 1, ih, buf, len);
pc-bios/vof/elf32.c new file +273 -0

273 lines not on this page · raw message

pc-bios/vof/main.c +1 -0
index eb9aa8b78a8f..d0935e78edd8 100644
@@ -19,5 +19,6 @@ void entry_c(void)
 
 	ci_stdout("*** Virtual Open Firmware ***\n");
 	boot_from_memory(initrd, initrdsize);
+	boot_block();
 	ci_panic("*** No boot target ***\n");
 }
hw/ppc/trace-events +4 -0
index 640d0649394d..9405d7fb2b84 100644
@@ -38,6 +38,10 @@ spapr_of_client_getproplen(uint32_t ph, const char *prop, uint32_t ret) "ph=0x%x
 spapr_of_client_setprop(uint32_t ph, const char *prop, const char *val, uint32_t ret) "ph=0x%x \"%s\" [%s] => len=%d"
 spapr_of_client_open(const char *path, uint32_t ph, uint32_t ih) "%s ph=0x%x => ih=0x%x"
 spapr_of_client_interpret(const char *cmd, uint32_t param1, uint32_t param2, uint32_t ret, uint32_t ret2) "[%s] 0x%x 0x%x => 0x%x 0x%x"
+spapr_of_client_blk_write(uint32_t ih, uint32_t len) "0x%x => len=%d"
+spapr_of_client_blk_read(uint32_t ih, uint64_t pos, uint32_t len, uint32_t ret) "ih=0x%x @0x%"PRIx64" size=%d => %d"
+spapr_of_client_blk_seek(uint32_t ih, uint64_t pos, uint32_t ret) "ih=0x%x 0x%"PRIx64" => %d"
+spapr_of_client_blk_bootloader_read(uint64_t offset, uint64_t size) "0x%"PRIx64" size=0x%"PRIx64
 spapr_of_client_package_to_path(uint32_t ph, const char *tmp, uint32_t ret) "ph=0x%x => %s len=%d"
 spapr_of_client_instance_to_path(uint32_t ih, uint32_t ph, const char *tmp, uint32_t ret) "ih=0x%x ph=0x%x => %s len=%d"
 spapr_of_client_instance_to_package(uint32_t ih, uint32_t ph) "ih=0x%x => ph=0x%x"
pc-bios/vof.bin binary +0 -0
index 152d86a094ce376ee8962c3f26afeccc9e7cae58..2c6629d2c72d5d1657c5e6791c15dabbc7aecb48 100755
GIT binary patch
Signature · 1 line
2.17.1
#6 lore raw
In reply to Alexey Kardashevskiy
Quoted 6 lines · Alexey Kardashevskiy

This is another attempt to implement minimalistic
Open Firmware Client Interface in QEMU.

With this thing, I can boot unmodified Ubuntu 18.04 and Fedora 30 directly from the disk without SLOF.

Quoted 8 lines

A useful discussion happened esrlier:
https://lore.kernel.org/qemu-devel/[email protected]/

5/5 is kind of controvertial though. This respin does not include networking.

This is based on sha1
015fb0ead60d Chen Qun "hw/ppc/virtex_ml507:fix leak of fdevice tree blob".

I would like to play with this. Can you provide a disk image that just reads the first sector of the disk using an OpenFirmware read command, and dumps it to stdout? (Also, I lost the pointer to your super-minimal pSeries firmware).

Thanks,

Paolo

#7 lore raw
Quoted 13 lines · Paolo Bonzini
Quoted 12 lines · Alexey Kardashevskiy

This is another attempt to implement minimalistic
Open Firmware Client Interface in QEMU.

With this thing, I can boot unmodified Ubuntu 18.04 and Fedora 30 directly from the disk without SLOF.

A useful discussion happened esrlier:
https://lore.kernel.org/qemu-devel/[email protected]/

5/5 is kind of controvertial though. This respin does not include networking.

Quoted 6 lines
Quoted 2 lines

This is based on sha1
015fb0ead60d Chen Qun "hw/ppc/virtex_ml507:fix leak of fdevice tree blob".

I would like to play with this. Can you provide a disk image that just reads the first sector of the disk using an OpenFirmware read command, and dumps it to stdout?

I am not quite sure I understood the request. Write my own small firmware and replace GRUB with it? The firmware from 5/5 reads first 2 sectors and the entire PReP, I could add there stuff if that helps (I have "work in progress" patch for the firmware with printk/etc borrowed from SLOF).

Quoted 2 lines

(Also, I lost the pointer to your super-minimal
pSeries firmware).

It is incorporated into these patches under /pc-bios/vof - 4/5 has the minimum (may be even too much), 5/5 has MBR+GPT+ELF.

Signature · 1 line
Alexey
#8 lore raw
Quoted 5 lines · Alexey Kardashevskiy

I am not quite sure I understood the request. Write my own small firmware and replace GRUB with it? The firmware from 5/5 reads first 2 sectors and the entire PReP, I could add there stuff if that helps (I have "work in progress" patch for the firmware with printk/etc borrowed from SLOF).

Okay, that's great! I'll take a look next week.

Thanks,

Paolo

Quoted 5 lines
Quoted 2 lines

(Also, I lost the pointer to your super-minimal
pSeries firmware).

It is incorporated into these patches under /pc-bios/vof - 4/5 has the minimum (may be even too much), 5/5 has MBR+GPT+ELF.

#9 lore raw
Quoted 8 lines · Paolo Bonzini
Quoted 5 lines · Alexey Kardashevskiy

I am not quite sure I understood the request. Write my own small firmware and replace GRUB with it? The firmware from 5/5 reads first 2 sectors and the entire PReP, I could add there stuff if that helps (I have "work in progress" patch for the firmware with printk/etc borrowed from SLOF).

Okay, that's great! I'll take a look next week.

Just to make sure I understood - you'll take a look on this series, you do not expect other patches on top, right?

ps. while I have your attention, what was the practical reason for including capstone to QEMU? Thanks,

Quoted 12 lines

Thanks,

Paolo

Quoted 5 lines
Quoted 2 lines

(Also, I lost the pointer to your super-minimal
pSeries firmware).

It is incorporated into these patches under /pc-bios/vof - 4/5 has the minimum (may be even too much), 5/5 has MBR+GPT+ELF.

Signature · 1 line
Alexey
#10 lore raw
Quoted 10 lines · Alexey Kardashevskiy
Quoted 7 lines · Paolo Bonzini
Quoted 5 lines · Alexey Kardashevskiy

I am not quite sure I understood the request. Write my own small firmware and replace GRUB with it? The firmware from 5/5 reads first 2 sectors and the entire PReP, I could add there stuff if that helps (I have "work in progress" patch for the firmware with printk/etc borrowed from SLOF).

Quoted 4 lines
Quoted 1 line

Okay, that's great! I'll take a look next week.

Just to make sure I understood - you'll take a look on this series, you do not expect other patches on top, right?

No, thanks.

Quoted 2 lines

ps. while I have your attention, what was the practical reason for including capstone to QEMU? Thanks,

Newer versions of the binutils disassembler are GPLv3.

Paolo

#11 lore raw
Quoted 16 lines · Paolo Bonzini
Quoted 10 lines · Alexey Kardashevskiy
Quoted 7 lines · Paolo Bonzini
Quoted 5 lines · Alexey Kardashevskiy

I am not quite sure I understood the request. Write my own small firmware and replace GRUB with it? The firmware from 5/5 reads first 2 sectors and the entire PReP, I could add there stuff if that helps (I have "work in progress" patch for the firmware with printk/etc borrowed from SLOF).

Quoted 4 lines
Quoted 1 line

Okay, that's great! I'll take a look next week.

Just to make sure I understood - you'll take a look on this series, you do not expect other patches on top, right?

Quoted 6 lines

No, thanks.

Quoted 2 lines

ps. while I have your attention, what was the practical reason for including capstone to QEMU? Thanks,

Newer versions of the binutils disassembler are GPLv3.

but why does qemu need this kind of disassembler at all? tcg does execution and it is not replaced by capstone.

Signature · 1 line
Alexey
#12 lore raw
Quoted 21 lines · Alexey Kardashevskiy
Quoted 18 lines · Paolo Bonzini
Quoted 10 lines · Alexey Kardashevskiy
Quoted 7 lines · Paolo Bonzini
Quoted 5 lines · Alexey Kardashevskiy

I am not quite sure I understood the request. Write my own small firmware and replace GRUB with it? The firmware from 5/5 reads first 2 sectors and the entire PReP, I could add there stuff if that helps (I have "work in progress" patch for the firmware with printk/etc borrowed from SLOF).

Quoted 4 lines
Quoted 1 line

Okay, that's great! I'll take a look next week.

Just to make sure I understood - you'll take a look on this series, you do not expect other patches on top, right?

No, thanks.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

ps. while I have your attention, what was the practical reason for including capstone to QEMU? Thanks,

Newer versions of the binutils disassembler are GPLv3.

but why does qemu need this kind of disassembler at all? tcg does execution and it is not replaced by capstone.

For debugging (e.g. "x/5i $pc" from the monitor, or "-d in_asm" if you're using TCG).

Paolo

#13 lore raw
Quoted 8 lines · Paolo Bonzini
Quoted 7 lines · Alexey Kardashevskiy
Quoted 4 lines · Paolo Bonzini
Quoted 3 lines · Alexey Kardashevskiy

On 21/02/2020 19:27, Paolo Bonzini wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines · Alexey Kardashevskiy
Quoted 5 lines

I am not quite sure I understood the request. Write my own small firmware and replace GRUB with it? The firmware from 5/5 reads first 2 sectors and the entire PReP, I could add there stuff if that helps (I have "work in progress" patch for the firmware with printk/etc borrowed from SLOF).

Okay, that's great! I'll take a look next week.

Any luck with this?

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 3 lines

Just to make sure I understood - you'll take a look on this series, you do not expect other patches on top, right?

No, thanks.

Quoted 2 lines

ps. while I have your attention, what was the practical reason for including capstone to QEMU? Thanks,

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Newer versions of the binutils disassembler are GPLv3.

but why does qemu need this kind of disassembler at all? tcg does execution and it is not replaced by capstone.

For debugging (e.g. "x/5i $pc" from the monitor, or "-d in_asm" if you're using TCG).

Ah, this is the only use, ok. We could just install it from packages then or (for PPC) grab from Linux's ppc xmon but ok :) Thanks,

Signature · 1 line
Alexey
#14 lore raw
Quoted 3 lines · Alexey Kardashevskiy
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Okay, that's great! I'll take a look next week.

Any luck with this?

Not really, perhaps today. But I don't object to already including a minimal version of this in 5.0 as long as:

- it doesn't implement read and write

- it is called x-vof instead of vof.

I know it's kinda useless (though perhaps you can already boot with -kernel?) but I don't want to make maintenance of the series too hard.

Paolo

Quoted 18 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

Just to make sure I understood - you'll take a look on this series, you do not expect other patches on top, right?

No, thanks.

Quoted 2 lines

ps. while I have your attention, what was the practical reason for including capstone to QEMU? Thanks,

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Newer versions of the binutils disassembler are GPLv3.

but why does qemu need this kind of disassembler at all? tcg does execution and it is not replaced by capstone.

For debugging (e.g. "x/5i $pc" from the monitor, or "-d in_asm" if you're using TCG).

Ah, this is the only use, ok. We could just install it from packages then or (for PPC) grab from Linux's ppc xmon but ok :) Thanks,