Skip to contentSkip to conversation

hw/arm: xlnx-zcu102: Disable unsupported FDT firmware nodes

PATCH Applied Edgar E. Iglesias 2 participants 6 messages Apr 23, 2020 – Apr 27, 2020

lore
Share & tools
lore
#0 lore raw

v2 cover hw/arm: xlnx-zcu102: Disable unsupported FDT firmware nodes

From: "Edgar E. Iglesias" <[email protected]>

When users try direct Linux runs on the ZynqMP models without enabling EL3 (and using appropriate FW) they run into trouble because the upstream kernel device-tree has EL3 based firmware nodes by default. PSCI firmware nodes work because we emulate the firmware in QEMU.

This series avoids that problem by disabling firmware nodes that the machine cannot support due to lack of EL3 or EL2 support.

This means we can now (without manually editing DTBs) run the following in a current Linux tree:

qemu-system-aarch64 -M xlnx-zcu102 -m 2G -dtb arch/arm64/boot/dts/xilinx/zynqmp-zcu102-rev1.0.dtb -serial mon:stdio -kernel arch/arm64/boot/Image -initrd zu-rootfs.cpio.gz -append rdinit=/bin/sh

Cheers,
Edgar

ChangeLog:

v1 -> v2:
* Constify compat in qemu_fdt_node_path().

Edgar E. Iglesias (4):
device_tree: Allow name wildcards in qemu_fdt_node_path()
device_tree: Constify compat in qemu_fdt_node_path() hw/arm: xlnx-zcu102: Move arm_boot_info into XlnxZCU102 hw/arm: xlnx-zcu102: Disable unsupported FDT firmware nodes

 device_tree.c                |  4 ++--
 hw/arm/xlnx-zcu102.c         | 39 ++++++++++++++++++++++++++++++++----
 include/sysemu/device_tree.h |  5 ++++-
 3 files changed, 41 insertions(+), 7 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH v2 1/4 device_tree: Allow name wildcards in qemu_fdt_node_path()

From: "Edgar E. Iglesias" <[email protected]>

Allow name wildcards in qemu_fdt_node_path(). This is useful to find all nodes with a given compatibility string.

---
 device_tree.c                | 2 +-
 include/sysemu/device_tree.h | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)
device_tree.c +1 -1
index bba6cc2164..f5b4699aed 100644
@@ -308,7 +308,7 @@ char **qemu_fdt_node_path(void *fdt, const char *name, char *compat,
             offset = len;
             break;
         }
-        if (!strcmp(iter_name, name)) {
+        if (!name || !strcmp(iter_name, name)) {
             char *path;
 
             path = g_malloc(path_len);
include/sysemu/device_tree.h +3 -0
index c16fd69bc0..7c53ef7634 100644
@@ -39,6 +39,9 @@ void *load_device_tree_from_sysfs(void);
  * NULL. If there is no error but no matching node was found, the
  * returned array contains a single element equal to NULL. If an error
  * was encountered when parsing the blob, the function returns NULL
+ *
+ * @name may be NULL to wildcard names and only match compatibility
+ * strings.
  */
 char **qemu_fdt_node_path(void *fdt, const char *name, char *compat,
                           Error **errp);
Signature · 1 line
2.20.1
#2 lore raw

PATCH v2 2/4 device_tree: Constify compat in qemu_fdt_node_path()

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

Make compat in qemu_fdt_node_path() const char *.

---
 device_tree.c                | 2 +-
 include/sysemu/device_tree.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
device_tree.c +1 -1
index f5b4699aed..b335dae707 100644
@@ -291,7 +291,7 @@ char **qemu_fdt_node_unit_path(void *fdt, const char *name, Error **errp)
     return path_array;
 }
 
-char **qemu_fdt_node_path(void *fdt, const char *name, char *compat,
+char **qemu_fdt_node_path(void *fdt, const char *name, const char *compat,
                           Error **errp)
 {
     int offset, len, ret;
include/sysemu/device_tree.h +1 -1
index 7c53ef7634..982c89345f 100644
@@ -43,7 +43,7 @@ void *load_device_tree_from_sysfs(void);
  * @name may be NULL to wildcard names and only match compatibility
  * strings.
  */
-char **qemu_fdt_node_path(void *fdt, const char *name, char *compat,
+char **qemu_fdt_node_path(void *fdt, const char *name, const char *compat,
                           Error **errp);
 
 /**
Signature · 1 line
2.20.1
#3 lore raw

PATCH v2 3/4 hw/arm: xlnx-zcu102: Move arm_boot_info into XlnxZCU102

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

Move arm_boot_info into XlnxZCU102.

---
 hw/arm/xlnx-zcu102.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
hw/arm/xlnx-zcu102.c +5 -4
index bd645ad818..4eb117c755 100644
@@ -31,13 +31,14 @@ typedef struct XlnxZCU102 {
 
     bool secure;
     bool virt;
+
+    struct arm_boot_info binfo;
 } XlnxZCU102;
 
 #define TYPE_ZCU102_MACHINE   MACHINE_TYPE_NAME("xlnx-zcu102")
 #define ZCU102_MACHINE(obj) \
     OBJECT_CHECK(XlnxZCU102, (obj), TYPE_ZCU102_MACHINE)
 
-static struct arm_boot_info xlnx_zcu102_binfo;
 
 static bool zcu102_get_secure(Object *obj, Error **errp)
 {
@@ -166,9 +167,9 @@ static void xlnx_zcu102_init(MachineState *machine)
 
     /* TODO create and connect IDE devices for ide_drive_get() */
 
-    xlnx_zcu102_binfo.ram_size = ram_size;
-    xlnx_zcu102_binfo.loader_start = 0;
-    arm_load_kernel(s->soc.boot_cpu_ptr, machine, &xlnx_zcu102_binfo);
+    s->binfo.ram_size = ram_size;
+    s->binfo.loader_start = 0;
+    arm_load_kernel(s->soc.boot_cpu_ptr, machine, &s->binfo);
 }
 
 static void xlnx_zcu102_machine_instance_init(Object *obj)
Signature · 1 line
2.20.1
#4 lore raw

PATCH v2 4/4 hw/arm: xlnx-zcu102: Disable unsupported FDT firmware nodes

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

Disable unsupported FDT firmware nodes if a user passes us a DTB with nodes enabled that the machine cannot support due to lack of EL3 or EL2 support.

---
 hw/arm/xlnx-zcu102.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
hw/arm/xlnx-zcu102.c +30 -0
index 4eb117c755..a798e228b7 100644
@@ -23,6 +23,7 @@
 #include "qemu/error-report.h"
 #include "qemu/log.h"
 #include "sysemu/qtest.h"
+#include "sysemu/device_tree.h"
 
 typedef struct XlnxZCU102 {
     MachineState parent_obj;
@@ -68,6 +69,34 @@ static void zcu102_set_virt(Object *obj, bool value, Error **errp)
     s->virt = value;
 }
 
+static void zcu102_modify_dtb(const struct arm_boot_info *binfo, void *fdt)
+{
+    XlnxZCU102 *s = container_of(binfo, XlnxZCU102, binfo);
+    bool method_is_hvc;
+    char **node_path;
+    const char *r;
+    int prop_len;
+    int i;
+
+    /* If EL3 is enabled, we keep all firmware nodes active.  */
+    if (!s->secure) {
+        node_path = qemu_fdt_node_path(fdt, NULL, "xlnx,zynqmp-firmware",
+                                       &error_fatal);
+
+        for (i = 0; node_path && node_path[i]; i++) {
+            r = qemu_fdt_getprop(fdt, node_path[i], "method", &prop_len, NULL);
+            method_is_hvc = r && !strcmp("hvc", r);
+
+            /* Allow HVC based firmware if EL2 is enabled.  */
+            if (method_is_hvc && s->virt) {
+                continue;
+            }
+            qemu_fdt_setprop_string(fdt, node_path[i], "status", "disabled");
+        }
+        g_strfreev(node_path);
+    }
+}
+
 static void xlnx_zcu102_init(MachineState *machine)
 {
     XlnxZCU102 *s = ZCU102_MACHINE(machine);
@@ -169,6 +198,7 @@ static void xlnx_zcu102_init(MachineState *machine)
 
     s->binfo.ram_size = ram_size;
     s->binfo.loader_start = 0;
+    s->binfo.modify_dtb = zcu102_modify_dtb;
     arm_load_kernel(s->soc.boot_cpu_ptr, machine, &s->binfo);
 }
 
Signature · 1 line
2.20.1
#5 lore raw
In reply to Edgar E. Iglesias
Quoted 11 lines · Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

When users try direct Linux runs on the ZynqMP models without enabling EL3 (and using appropriate FW) they run into trouble because the upstream kernel device-tree has EL3 based firmware nodes by default. PSCI firmware nodes work because we emulate the firmware in QEMU.

This series avoids that problem by disabling firmware nodes that the machine cannot support due to lack of EL3 or EL2 support.

Quoted 7 lines

This means we can now (without manually editing DTBs) run the following in a current Linux tree:

qemu-system-aarch64 -M xlnx-zcu102 -m 2G -dtb arch/arm64/boot/dts/xilinx/zynqmp-zcu102-rev1.0.dtb -serial mon:stdio -kernel arch/arm64/boot/Image -initrd zu-rootfs.cpio.gz -append rdinit=/bin/sh

Cheers,
Edgar

Applied to target-arm.next, thanks.

-- PMM