qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] arm: Create /chosen and /memory devicetree nodes if necessary
@ 2016-11-17  1:30 Guenter Roeck
  2016-11-28 11:46 ` [Qemu-devel] [Qemu-arm] " Peter Maydell
  0 siblings, 1 reply; 2+ messages in thread
From: Guenter Roeck @ 2016-11-17  1:30 UTC (permalink / raw)
  To: Peter Crosthwaite; +Cc: Alexander Graf, qemu-devel, qemu-arm, Guenter Roeck

While customary, the /chosen and /memory devicetree nodes do not have to
exist. Create if necessary. Also create the /memory/device_type property
if needed.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
The problem is seen with the latest version of the Linux kernel in
linux-next (next-20161116), where many of the /chosen and /memory nodes
in arm devicetree files have been removed. This results in a kernel hang
(sabrelite) or qemu abort (imx25-pdk).

 hw/arm/boot.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/hw/arm/boot.c b/hw/arm/boot.c
index 942416d..ff621e4 100644
--- a/hw/arm/boot.c
+++ b/hw/arm/boot.c
@@ -9,6 +9,7 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
+#include <libfdt.h>
 #include "hw/hw.h"
 #include "hw/arm/arm.h"
 #include "hw/arm/linux-boot-if.h"
@@ -486,6 +487,17 @@ static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
             g_free(nodename);
         }
     } else {
+        Error *err = NULL;
+
+        rc = fdt_path_offset(fdt, "/memory");
+        if (rc < 0) {
+            qemu_fdt_add_subnode(fdt, "/memory");
+        }
+
+        if (!qemu_fdt_getprop(fdt, "/memory", "device_type", NULL, &err)) {
+            qemu_fdt_setprop_string(fdt, "/memory", "device_type", "memory");
+        }
+
         rc = qemu_fdt_setprop_sized_cells(fdt, "/memory", "reg",
                                           acells, binfo->loader_start,
                                           scells, binfo->ram_size);
@@ -495,6 +507,11 @@ static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
         }
     }
 
+    rc = fdt_path_offset(fdt, "/chosen");
+    if (rc < 0) {
+        qemu_fdt_add_subnode(fdt, "/chosen");
+    }
+
     if (binfo->kernel_cmdline && *binfo->kernel_cmdline) {
         rc = qemu_fdt_setprop_string(fdt, "/chosen", "bootargs",
                                      binfo->kernel_cmdline);
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [Qemu-arm] [PATCH] arm: Create /chosen and /memory devicetree nodes if necessary
  2016-11-17  1:30 [Qemu-devel] [PATCH] arm: Create /chosen and /memory devicetree nodes if necessary Guenter Roeck
@ 2016-11-28 11:46 ` Peter Maydell
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Maydell @ 2016-11-28 11:46 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Peter Crosthwaite, qemu-arm, Alexander Graf, QEMU Developers

On 17 November 2016 at 01:30, Guenter Roeck <linux@roeck-us.net> wrote:
> While customary, the /chosen and /memory devicetree nodes do not have to
> exist. Create if necessary. Also create the /memory/device_type property
> if needed.
>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
> The problem is seen with the latest version of the Linux kernel in
> linux-next (next-20161116), where many of the /chosen and /memory nodes
> in arm devicetree files have been removed. This results in a kernel hang
> (sabrelite) or qemu abort (imx25-pdk).

The lack of a memory node sounds to me like a bug in the Linux device
trees. The 0.1 specification at http://www.devicetree.org/specifications/
says on page 21 "the following nodes shall be present at the root of all
devicetrees: [...] At least one memory node".

There's no harm in QEMU being robust against bogus input, though,
especially if the dtbs are common in the wild, so this patch is
worth having. (And 'chosen' is definitely optional.)

I've applied this patch to target-arm.next.

thanks
-- PMM

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-11-28 11:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-17  1:30 [Qemu-devel] [PATCH] arm: Create /chosen and /memory devicetree nodes if necessary Guenter Roeck
2016-11-28 11:46 ` [Qemu-devel] [Qemu-arm] " Peter Maydell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).