qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Lankes <slankes@eonerc.rwth-aachen.de>
To: <qemu-devel@nongnu.org>
Cc: <peter.maydell@linaro.org>, <qemu-arm@nongnu.org>,
	Stefan Lankes <slankes@eonerc.rwth-aachen.de>
Subject: [RFC 1/1] add support of `--initrd` for ELF-ARM kernels
Date: Fri, 14 Apr 2023 09:34:32 +0200	[thread overview]
Message-ID: <20230414073432.36000-2-slankes@eonerc.rwth-aachen.de> (raw)
In-Reply-To: <20230414073432.36000-1-slankes@eonerc.rwth-aachen.de>

Currently, the flag `--initrd` is only support for Linux ARM kernels.
However, also other ELF kernels could depend on an initial ramdisk.
This PR loads also the initrd for ELF kernels and announce the
location by the nodes "/chosen/initrd-start" and
"/chosen/initrd-end" within the device tree.

Signed-off-by: Stefan Lankes <slankes@eonerc.rwth-aachen.de>
---
 hw/arm/boot.c | 106 +++++++++++++++++++++++++++++---------------------
 1 file changed, 62 insertions(+), 44 deletions(-)

diff --git a/hw/arm/boot.c b/hw/arm/boot.c
index 54f6a3e0b3..f767a4809e 100644
--- a/hw/arm/boot.c
+++ b/hw/arm/boot.c
@@ -657,20 +657,38 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
     }
 
     if (binfo->initrd_size) {
-        rc = qemu_fdt_setprop_sized_cells(fdt, "/chosen", "linux,initrd-start",
+        if (binfo->is_linux) {
+            rc = qemu_fdt_setprop_sized_cells(fdt, "/chosen", "linux,initrd-start",
                                           acells, binfo->initrd_start);
-        if (rc < 0) {
-            fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n");
-            goto fail;
-        }
+            if (rc < 0) {
+                fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n");
+                goto fail;
+            }
 
-        rc = qemu_fdt_setprop_sized_cells(fdt, "/chosen", "linux,initrd-end",
-                                          acells,
-                                          binfo->initrd_start +
-                                          binfo->initrd_size);
-        if (rc < 0) {
-            fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n");
-            goto fail;
+            rc = qemu_fdt_setprop_sized_cells(fdt, "/chosen", "linux,initrd-end",
+                                              acells,
+                                              binfo->initrd_start +
+                                              binfo->initrd_size);
+            if (rc < 0) {
+                fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n");
+                goto fail;
+            }
+        } else {
+            rc = qemu_fdt_setprop_sized_cells(fdt, "/chosen", "initrd-start",
+                                          acells, binfo->initrd_start);
+            if (rc < 0) {
+                fprintf(stderr, "couldn't set /chosen/initrd-start\n");
+                goto fail;
+            }
+
+            rc = qemu_fdt_setprop_sized_cells(fdt, "/chosen", "initrd-end",
+                                              acells,
+                                              binfo->initrd_start +
+                                              binfo->initrd_size);
+            if (rc < 0) {
+                fprintf(stderr, "couldn't set /chosen/initrd-end\n");
+                goto fail;
+            }
         }
     }
 
@@ -1099,41 +1117,41 @@ static void arm_setup_direct_kernel_boot(ARMCPU *cpu,
     }
     info->initrd_start = TARGET_PAGE_ALIGN(info->initrd_start);
 
-    if (is_linux) {
-        uint32_t fixupcontext[FIXUP_MAX];
-
-        if (info->initrd_filename) {
+    if (info->initrd_filename) {
 
-            if (info->initrd_start >= ram_end) {
-                error_report("not enough space after kernel to load initrd");
-                exit(1);
-            }
+        if (info->initrd_start >= ram_end) {
+            error_report("not enough space after kernel to load initrd");
+            exit(1);
+        }
 
-            initrd_size = load_ramdisk_as(info->initrd_filename,
-                                          info->initrd_start,
-                                          ram_end - info->initrd_start, as);
-            if (initrd_size < 0) {
-                initrd_size = load_image_targphys_as(info->initrd_filename,
-                                                     info->initrd_start,
-                                                     ram_end -
-                                                     info->initrd_start,
-                                                     as);
-            }
-            if (initrd_size < 0) {
-                error_report("could not load initrd '%s'",
-                             info->initrd_filename);
-                exit(1);
-            }
-            if (info->initrd_start + initrd_size > ram_end) {
-                error_report("could not load initrd '%s': "
-                             "too big to fit into RAM after the kernel",
-                             info->initrd_filename);
-                exit(1);
-            }
-        } else {
-            initrd_size = 0;
+        initrd_size = load_ramdisk_as(info->initrd_filename,
+                                      info->initrd_start,
+                                      ram_end - info->initrd_start, as);
+        if (initrd_size < 0) {
+            initrd_size = load_image_targphys_as(info->initrd_filename,
+                                                 info->initrd_start,
+                                                 ram_end -
+                                                 info->initrd_start,
+                                                 as);
+        }
+        if (initrd_size < 0) {
+            error_report("could not load initrd '%s'",
+                         info->initrd_filename);
+            exit(1);
+        }
+        if (info->initrd_start + initrd_size > ram_end) {
+            error_report("could not load initrd '%s': "
+                         "too big to fit into RAM after the kernel",
+                         info->initrd_filename);
+            exit(1);
         }
-        info->initrd_size = initrd_size;
+    } else {
+        initrd_size = 0;
+    }
+    info->initrd_size = initrd_size;
+
+    if (is_linux) {
+        uint32_t fixupcontext[FIXUP_MAX];
 
         fixupcontext[FIXUP_BOARDID] = info->board_id;
         fixupcontext[FIXUP_BOARD_SETUP] = info->board_setup_addr;
-- 
2.39.2 (Apple Git-143)



  reply	other threads:[~2023-04-14  7:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-14  7:34 [RFC 0/1] add support of `--initrd` for ELF-ARM kernels Stefan Lankes
2023-04-14  7:34 ` Stefan Lankes [this message]
2023-04-14  8:54   ` [RFC 1/1] " Alex Bennée
2023-04-14 12:34     ` Lankes, Stefan
2023-04-15  7:51       ` Lankes, Stefan
2023-04-14  9:02   ` Peter Maydell
2023-04-14  9:26     ` Lankes, Stefan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230414073432.36000-2-slankes@eonerc.rwth-aachen.de \
    --to=slankes@eonerc.rwth-aachen.de \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).