This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit fd8c6bac585c458092f3c3db11094da397c478d1
Author: qinwei1 <[email protected]>
AuthorDate: Sat Mar 21 00:10:43 2026 +0800

    arch/arm64/src/qemu: Modify fixed addresses
    
    When supporting the arcn-hypervisor running on QEMU,
    two choices arise: implement new board code or reuse the
    existing QEMU-ARMV8A board configuration code.
    
    Using the existing QEMU-ARMV8A configuration means
    adjusting the kernel load address. In the arcn example,
    the load address needs to change from 0x40280000
    to 0x42280000. However, in the existing QEMU-ARMV8A
    implementation, many addresses are hardcoded.
    
    This change modifies these hardcoded addresses,
    making them uniformly configurable via `CONFIG_RAM_START`
    in `defconfig`, thus achieving the goal of modifying
    only the load address while retaining  the existing
    QEMU-ARMV8A board configuration code.
    
    Signed-off-by: qinwei1 <[email protected]>
---
 arch/arm64/include/qemu/chip.h                      | 21 +++++++++++++++++++--
 boards/arm64/qemu/qemu-armv8a/scripts/dramboot.ld   |  3 ++-
 .../arm64/qemu/qemu-armv8a/scripts/ld-kernel.script |  7 +++++--
 3 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/arch/arm64/include/qemu/chip.h b/arch/arm64/include/qemu/chip.h
index ebd3e3b7afa..cb32bbcede9 100644
--- a/arch/arm64/include/qemu/chip.h
+++ b/arch/arm64/include/qemu/chip.h
@@ -58,8 +58,23 @@
 
 #endif /* CONFIG_ARM64_GIC_VERSION */
 
+/* QEMU virt machine physical RAM always starts at 0x40000000.
+ * RAMBANK1 must cover from physical RAM base through the end of
+ * NuttX's configured RAM region (CONFIG_RAM_START + CONFIG_RAM_SIZE)
+ * so that the MMU mapping is large enough.
+ *
+ * When CONFIG_RAM_START > 0x40000000 (e.g. running under a hypervisor),
+ * the RAMBANK1 mapping still starts at 0x40000000 to keep the DTB
+ * accessible, and extends to cover CONFIG_RAM_END.
+ *
+ * The user must ensure QEMU is launched with enough RAM via -m option:
+ *   -m <size>  where size >=
+ *   (CONFIG_RAM_START - 0x40000000 + CONFIG_RAM_SIZE)
+ */
+
 #define CONFIG_RAMBANK1_ADDR       0x40000000
-#define CONFIG_RAMBANK1_SIZE       MB(128)
+#define CONFIG_RAMBANK1_SIZE       (CONFIG_RAM_START - CONFIG_RAMBANK1_ADDR + \
+                                    CONFIG_RAM_SIZE)
 
 #define CONFIG_DEVICEIO_BASEADDR   0x7000000
 #define CONFIG_DEVICEIO_SIZE       MB(512)
@@ -73,7 +88,9 @@
 #define CONFIG_PCI_IO_BASEADDR     0x3eff0000
 #define CONFIG_PCI_IO_SIZE         KB(64)
 
-#define CONFIG_LOAD_BASE           0x40280000
+/* Load base is 0x280000 (2.5MB) offset from CONFIG_RAM_START */
+
+#define CONFIG_LOAD_BASE           (CONFIG_RAM_START + 0x280000)
 
 #define MPID_TO_CLUSTER_ID(mpid)   ((mpid) & ~0xff)
 
diff --git a/boards/arm64/qemu/qemu-armv8a/scripts/dramboot.ld 
b/boards/arm64/qemu/qemu-armv8a/scripts/dramboot.ld
index 82b1e1d9085..46a1961cf8f 100644
--- a/boards/arm64/qemu/qemu-armv8a/scripts/dramboot.ld
+++ b/boards/arm64/qemu/qemu-armv8a/scripts/dramboot.ld
@@ -21,6 +21,7 @@
  ****************************************************************************/
 
 #include <nuttx/config.h>
+#include <arch/chip/chip.h>
 
 OUTPUT_ARCH(aarch64)
 
@@ -33,7 +34,7 @@ PHDRS
 
 SECTIONS
 {
-  . = 0x40280000;  /* uboot load address */
+  . = CONFIG_LOAD_BASE;  /* load address derived from CONFIG_RAM_START */
 
   /* where the global variable out-of-bounds detection information located */
 
diff --git a/boards/arm64/qemu/qemu-armv8a/scripts/ld-kernel.script 
b/boards/arm64/qemu/qemu-armv8a/scripts/ld-kernel.script
index 23cf067e27c..0031ead57fc 100644
--- a/boards/arm64/qemu/qemu-armv8a/scripts/ld-kernel.script
+++ b/boards/arm64/qemu/qemu-armv8a/scripts/ld-kernel.script
@@ -20,6 +20,9 @@
  *
  ****************************************************************************/
 
+#include <nuttx/config.h>
+#include <arch/chip/chip.h>
+
 OUTPUT_ARCH(aarch64)
 
 ENTRY(__start)
@@ -27,8 +30,8 @@ EXTERN(__start)
 
 MEMORY
 {
-  dram (rwx)  : ORIGIN = 0x40280000, LENGTH = 2M
-  pgram (rwx) : ORIGIN = 0x40800000, LENGTH = 4M   /* w/ cache */
+  dram (rwx)  : ORIGIN = CONFIG_LOAD_BASE, LENGTH = 2M
+  pgram (rwx) : ORIGIN = CONFIG_RAM_START + 0x800000, LENGTH = 4M
 }
 
 PHDRS

Reply via email to