All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hang Xu <xuhang@eswincomputing.com>
To: qemu-riscv@nongnu.org
Cc: alistair.francis@wdc.com, bmeng@tinylab.org, philmd@linaro.org,
	Hang Xu <xuhang@eswincomputing.com>
Subject: [PATCH] hw/riscv: Fix the bug of maximum size limit when put initrd to RAM
Date: Mon, 27 Feb 2023 02:39:16 +0000	[thread overview]
Message-ID: <20230227023916.7374-1-xuhang@eswincomputing.com> (raw)

The space available for initrd is "ram_size + ram_base - start"
instead of "ram_size - start"

Signed-off-by: Hang Xu <xuhang@eswincomputing.com>
---
 hw/riscv/boot.c            | 8 +++++---
 hw/riscv/microchip_pfsoc.c | 2 +-
 hw/riscv/sifive_u.c        | 2 +-
 hw/riscv/spike.c           | 2 +-
 hw/riscv/virt.c            | 2 +-
 include/hw/riscv/boot.h    | 3 ++-
 6 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
index c7e0e50bd8..749dba5360 100644
--- a/hw/riscv/boot.c
+++ b/hw/riscv/boot.c
@@ -209,7 +209,8 @@ target_ulong riscv_load_kernel(MachineState *machine,
     exit(1);
 }
 
-void riscv_load_initrd(MachineState *machine, uint64_t kernel_entry)
+void riscv_load_initrd(MachineState *machine, uint64_t kernel_entry,
+                       uint64_t mem_base)
 {
     const char *filename = machine->initrd_filename;
     uint64_t mem_size = machine->ram_size;
@@ -231,10 +232,11 @@ void riscv_load_initrd(MachineState *machine, uint64_t kernel_entry)
      * the initrd at 128MB.
      */
     start = kernel_entry + MIN(mem_size / 2, 128 * MiB);
+    uint64_t max_size = mem_size + mem_base - start;
 
-    size = load_ramdisk(filename, start, mem_size - start);
+    size = load_ramdisk(filename, start, max_size);
     if (size == -1) {
-        size = load_image_targphys(filename, start, mem_size - start);
+        size = load_image_targphys(filename, start, max_size);
         if (size == -1) {
             error_report("could not load ramdisk '%s'", filename);
             exit(1);
diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c
index 2b91e49561..965d155fd3 100644
--- a/hw/riscv/microchip_pfsoc.c
+++ b/hw/riscv/microchip_pfsoc.c
@@ -632,7 +632,7 @@ static void microchip_icicle_kit_machine_init(MachineState *machine)
         kernel_entry = riscv_load_kernel(machine, kernel_start_addr, NULL);
 
         if (machine->initrd_filename) {
-            riscv_load_initrd(machine, kernel_entry);
+            riscv_load_initrd(machine, kernel_entry, memmap[MICROCHIP_PFSOC_DRAM_LO].base);
         }
 
         if (machine->kernel_cmdline && *machine->kernel_cmdline) {
diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c
index d3ab7a9cda..aa5d5bc610 100644
--- a/hw/riscv/sifive_u.c
+++ b/hw/riscv/sifive_u.c
@@ -601,7 +601,7 @@ static void sifive_u_machine_init(MachineState *machine)
         kernel_entry = riscv_load_kernel(machine, kernel_start_addr, NULL);
 
         if (machine->initrd_filename) {
-            riscv_load_initrd(machine, kernel_entry);
+            riscv_load_initrd(machine, kernel_entry, memmap[SIFIVE_U_DEV_DRAM].base);
         }
 
         if (machine->kernel_cmdline && *machine->kernel_cmdline) {
diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c
index cc3f6dac17..729f6f91fd 100644
--- a/hw/riscv/spike.c
+++ b/hw/riscv/spike.c
@@ -309,7 +309,7 @@ static void spike_board_init(MachineState *machine)
                                          htif_symbol_callback);
 
         if (machine->initrd_filename) {
-            riscv_load_initrd(machine, kernel_entry);
+            riscv_load_initrd(machine, kernel_entry, memmap[SPIKE_DRAM].base);
         }
 
         if (machine->kernel_cmdline && *machine->kernel_cmdline) {
diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
index b81081c70b..2342de646e 100644
--- a/hw/riscv/virt.c
+++ b/hw/riscv/virt.c
@@ -1280,7 +1280,7 @@ static void virt_machine_done(Notifier *notifier, void *data)
         kernel_entry = riscv_load_kernel(machine, kernel_start_addr, NULL);
 
         if (machine->initrd_filename) {
-            riscv_load_initrd(machine, kernel_entry);
+            riscv_load_initrd(machine, kernel_entry, memmap[VIRT_DRAM].base);
         }
 
         if (machine->kernel_cmdline && *machine->kernel_cmdline) {
diff --git a/include/hw/riscv/boot.h b/include/hw/riscv/boot.h
index 511390f60e..14db53ef13 100644
--- a/include/hw/riscv/boot.h
+++ b/include/hw/riscv/boot.h
@@ -46,7 +46,8 @@ target_ulong riscv_load_firmware(const char *firmware_filename,
 target_ulong riscv_load_kernel(MachineState *machine,
                                target_ulong firmware_end_addr,
                                symbol_fn_t sym_cb);
-void riscv_load_initrd(MachineState *machine, uint64_t kernel_entry);
+void riscv_load_initrd(MachineState *machine, uint64_t kernel_entry,
+                       uint64_t mem_base);
 uint64_t riscv_compute_fdt_addr(hwaddr dram_start, uint64_t dram_size,
                                 MachineState *ms);
 void riscv_load_fdt(hwaddr fdt_addr, void *fdt);
-- 
2.17.1



             reply	other threads:[~2023-02-27  4:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-27  2:39 Hang Xu [this message]
2023-02-27 13:29 ` [PATCH] hw/riscv: Fix the bug of maximum size limit when put initrd to RAM Daniel Henrique Barboza
2023-02-28  3:44   ` Hang Xu
2023-02-28 13:17     ` Daniel Henrique Barboza
2023-03-05 11:11       ` Hang Xu

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=20230227023916.7374-1-xuhang@eswincomputing.com \
    --to=xuhang@eswincomputing.com \
    --cc=alistair.francis@wdc.com \
    --cc=bmeng@tinylab.org \
    --cc=philmd@linaro.org \
    --cc=qemu-riscv@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.