Skip to contentSkip to conversation

Add mach-virt platform

PATCH New John Rigby 2 participants 6 messages May 10, 2013 – Jun 13, 2013

lore
Share & tools
lore

John Rigby

author
#0 lore raw

v3 cover Add mach-virt platform

Modify arm fdt handling so boards can provide a blob rather than requiring one on command line.

Allow dumping of fdt blob as ppc e500 already does.

Next add mach-virt platform that creates fdt blob from scratch describing its minimal hw which is a pl011 uart and a sp804 timer.

Tested on amd64 host with full system emulation and also using kvm on an arndale board

v2 changes:
- remove bogus cruft from mach-virt.c that was leftover from checkpatch fixing

v3 changes:
- split first patch into two
- rename from mach-virt to virt
- collect scattered constants into a machine info structure
- put qemu device creation and fdt nod creation near one another to make it easier to keep them in sync
- use CONFIG_KVM and kvm_enabled() to differentiate between tcg and kvm dependent code
- move memory to 0x0 and io up to 0xfff00000

John Rigby (3):
ARM: Allow boards to provide an fdt blob
ARM: Allow dumping of device tree
ARM: Add mach-virt platform

 hw/arm/Makefile.objs |   2 +-
 hw/arm/boot.c        |  31 ++--
 hw/arm/virt.c        | 434 +++++++++++++++++++++++++++++++++++++++++++++++++++
 include/hw/arm/arm.h |   6 +
 4 files changed, 461 insertions(+), 12 deletions(-)
 create mode 100644 hw/arm/virt.c
Signature · 1 line
1.8.2.2
author
#1 lore raw

PATCH v3 1/3 ARM: Allow boards to provide an fdt blob

If no fdt is provided on command line and the new field get_dtb in struct arm_boot_info is set then call it to get a device tree blob.

---

changes in v3:
- split patch

 hw/arm/boot.c        | 30 +++++++++++++++++++-----------
 include/hw/arm/arm.h |  6 ++++++
 2 files changed, 25 insertions(+), 11 deletions(-)
hw/arm/boot.c +19 -11
index f451529..64b56ac 100644
@@ -235,19 +235,27 @@ static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo)
     int size, rc;
     uint32_t acells, scells, hival;
 
-    filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, binfo->dtb_filename);
-    if (!filename) {
-        fprintf(stderr, "Couldn't open dtb file %s\n", binfo->dtb_filename);
-        return -1;
-    }
+    if (binfo->dtb_filename) {
+        filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, binfo->dtb_filename);
+        if (!filename) {
+            fprintf(stderr, "Couldn't open dtb file %s\n", binfo->dtb_filename);
+            return -1;
+        }
 
-    fdt = load_device_tree(filename, &size);
-    if (!fdt) {
-        fprintf(stderr, "Couldn't open dtb file %s\n", filename);
+        fdt = load_device_tree(filename, &size);
+        if (!fdt) {
+            fprintf(stderr, "Couldn't open dtb file %s\n", filename);
+            g_free(filename);
+            return -1;
+        }
         g_free(filename);
-        return -1;
+    } else if (binfo->get_dtb) {
+        fdt = binfo->get_dtb(addr, binfo, &size);
+        if (!fdt) {
+            fprintf(stderr, "Couldn't get dtb blob from board func\n");
+            return -1;
+        }
     }
-    g_free(filename);
 
     acells = qemu_devtree_getprop_cell(fdt, "/", "#address-cells");
     scells = qemu_devtree_getprop_cell(fdt, "/", "#size-cells");
@@ -440,7 +448,7 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info)
         /* for device tree boot, we pass the DTB directly in r2. Otherwise
          * we point to the kernel args.
          */
-        if (info->dtb_filename) {
+        if (info->dtb_filename || info->get_dtb) {
             /* Place the DTB after the initrd in memory. Note that some
              * kernels will trash anything in the 4K page the initrd
              * ends in, so make sure the DTB isn't caught up in that.
include/hw/arm/arm.h +6 -0
index 7b2b02d..4c56a1b 100644
@@ -31,6 +31,10 @@ struct arm_boot_info {
     const char *kernel_cmdline;
     const char *initrd_filename;
     const char *dtb_filename;
+    /* if a board is able to create a dtb without a dtb file then it
+     * sets get_dtb.  This will only be used if no dtb file is provided.
+     */
+    void *(*get_dtb)(hwaddr addr, const struct arm_boot_info *binfo, int *size);
     hwaddr loader_start;
     /* multicore boards that use the default secondary core boot functions
      * need to put the address of the secondary boot code, the boot reg,
@@ -59,6 +63,8 @@ struct arm_boot_info {
     int is_linux;
     hwaddr initrd_start;
     hwaddr initrd_size;
+    void *dtb_blob;
+    int dtb_blob_size;
     hwaddr entry;
 };
 void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info);
Signature · 1 line
1.8.2.2
#2 lore raw

Re: [Qemu-devel] [PATCH v3 1/3] ARM: Allow boards to provide an fdt blob

(I've taken this work over from John so these review comments are more in the nature of "notes to myself" than anything else ;-)

Quoted 9 lines · John Rigby

If no fdt is provided on command line and the new field get_dtb in struct arm_boot_info is set then call it to get a device tree blob.

include/hw/arm/arm.h +0 -0
index 7b2b02d..4c56a1b 100644

include/hw/arm/arm.h struct arm_boot_info { · line 37

Quoted 7 lines
include/hw/arm/arm.h +4 -0
@@ -31,6 +31,10 @@ struct arm_boot_info {
     const char *kernel_cmdline;
     const char *initrd_filename;
     const char *dtb_filename;
+    /* if a board is able to create a dtb without a dtb file then it
+     * sets get_dtb.  This will only be used if no dtb file is provided.
+     */
+    void *(*get_dtb)(hwaddr addr, const struct arm_boot_info *binfo, int *size);

The general idea here is OK, but it's not clear to me why we need to pass in the addr to the hook function (certainly the example in part 3 doesn't need it). I think we can just move to
void *(*get_dtb)(const struct arm_boot_info *binfo, int *size);

As with load_device_tree(), we should require (and document!) that the returned blob is in memory freeable with g_free().

NB: we don't actually free the blob in load_dtb(), either for load_device_tree() or for this; we should (separate patch).

include/hw/arm/arm.h struct arm_boot_info { · line 67

Quoted 9 lines
include/hw/arm/arm.h +2 -0
     hwaddr loader_start;
     /* multicore boards that use the default secondary core boot functions
      * need to put the address of the secondary boot code, the boot reg,
@@ -59,6 +63,8 @@ struct arm_boot_info {
     int is_linux;
     hwaddr initrd_start;
     hwaddr initrd_size;
+    void *dtb_blob;
+    int dtb_blob_size;

These appear to be relics from a previous version -- they're not used and can be dropped.

thanks
-- PMM

author
#3 lore raw

PATCH v3 2/3 ARM: Allow dumping of device tree

In reply to John Rigby

By calling qemu_devtree_dumpdtb near the end of load_dtb.

---

changes in v3:
- split patch

 hw/arm/boot.c | 1 +
 1 file changed, 1 insertion(+)
hw/arm/boot.c +1 -0
index 64b56ac..de71edf 100644
@@ -312,6 +312,7 @@ static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo)
             fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n");
         }
     }
+    qemu_devtree_dumpdtb(fdt, size);
 
     cpu_physical_memory_write(addr, fdt, size);
 
Signature · 1 line
1.8.2.2
Reviewed-by on v3 2/3
#4 lore raw

Re: [Qemu-devel] [PATCH v3 2/3] ARM: Allow dumping of device tree

Quoted 3 lines · John Rigby

By calling qemu_devtree_dumpdtb near the end of load_dtb.

I'm just going to put this in arm-devs.next now, since it makes '-machine dumpdtb=filename' work rather than be silently ignored.

thanks
-- PMM

author
#5 lore raw

PATCH v3 3/3 ARM: Add mach-virt platform

In reply to John Rigby

Add mach-virt platform support corresponding to /arch/arm/mach-virt in kernel tree.

For now it is not virtual but instantiates a pl011 uart and an sp804 timer. The uart is need for a console the timer is needed when running without kvm and there is no arch timer.

---

changes in v2:
- remove bogus cruft from mach-virt.c that was leftwover from checkpatch fixing

changes in v3:
- rename from mach-virt to virt
- collect scattered constants into a machine info structure
- put qemu device creation and fdt node creation near one another to make it easier to keep them in sync
- use CONFIG_KVM and kvm_enabled() to differentiate between tcg and kvm dependent code
- move memory to 0x0 and io up to 0xfff00000

 hw/arm/Makefile.objs |   2 +-
 hw/arm/virt.c        | 434 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 435 insertions(+), 1 deletion(-)
 create mode 100644 hw/arm/virt.c
hw/arm/Makefile.objs +1 -1
index 9e3a06f..744484f 100644
@@ -1,7 +1,7 @@
 obj-y += boot.o collie.o exynos4_boards.o gumstix.o highbank.o
 obj-y += integratorcp.o kzm.o mainstone.o musicpal.o nseries.o
 obj-y += omap_sx1.o palm.o pic_cpu.o realview.o spitz.o stellaris.o
-obj-y += tosa.o versatilepb.o vexpress.o xilinx_zynq.o z2.o
+obj-y += tosa.o versatilepb.o vexpress.o virt.o xilinx_zynq.o z2.o
 
 obj-y += armv7m.o exynos4210.o pxa2xx.o pxa2xx_gpio.o pxa2xx_pic.o
 obj-y += omap1.o omap2.o strongarm.o
hw/arm/virt.c new file +434 -0

434 lines not on this page · raw message

Signature · 1 line
1.8.2.2