sandbox: align LMB memory
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Sun, 8 Jun 2025 07:54:27 +0000 (09:54 +0200)
committerTom Rini <trini@konsulko.com>
Thu, 26 Jun 2025 19:45:33 +0000 (13:45 -0600)
To implement the EFI_SYSTEM_TABLE_POINTER we need 4 MiB aligned
memory.

On the sandbox LMB uses addresses relative to the start of a page aligned
RAM buffer allocated with mmap(). This leads to a mismatch of alignment
between EFI which uses pointers and LMB which uses phys_addr_t.

Ensure that the RAM buffer used for LMB is 4 MiB aligned.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
arch/sandbox/cpu/state.c
arch/sandbox/include/asm/state.h
include/configs/sandbox.h

index 49236db..6a15c8b 100644 (file)
@@ -480,7 +480,9 @@ int state_init(void)
        state = &main_state;
 
        state->ram_size = CFG_SYS_SDRAM_SIZE;
-       state->ram_buf = os_malloc(state->ram_size);
+       state->mmap_addr = os_malloc(state->ram_size + SB_SDRAM_ALIGN);
+       state->ram_buf = (uint8_t *)ALIGN((uintptr_t)state->mmap_addr,
+                                         SB_SDRAM_ALIGN);
        if (!state->ram_buf) {
                printf("Out of memory\n");
                os_exit(1);
@@ -533,7 +535,7 @@ int state_uninit(void)
                trace_set_enabled(0);
 
        os_free(state->state_fdt);
-       os_free(state->ram_buf);
+       os_free(state->mmap_addr);
        memset(state, '\0', sizeof(*state));
 
        return 0;
index dc21a62..9dea098 100644 (file)
@@ -75,6 +75,7 @@ struct sandbox_state {
        char **argv;                    /* Command line arguments */
        const char *jumped_fname;       /* Jumped from previous U-Boot */
        const char *prog_fname;         /* U-Boot executable filename */
+       uint8_t *mmap_addr;             /* Memory allocated via mmap */
        uint8_t *ram_buf;               /* Emulated RAM buffer */
        unsigned long ram_size;         /* Size of RAM buffer */
        const char *ram_buf_fname;      /* Filename to use for RAM buffer */
index db2ac7f..44d4960 100644 (file)
@@ -14,6 +14,8 @@
 #define CFG_SYS_SDRAM_BASE             0
 #define CFG_SYS_SDRAM_SIZE \
                (SB_TO_UL(CONFIG_SANDBOX_RAM_SIZE_MB) << 20)
+/** define SB_SDRAM_ALIGN - Alignment of emulated RAM */
+#define SB_SDRAM_ALIGN                 0x400000
 
 #define CFG_SYS_BAUDRATE_TABLE {4800, 9600, 19200, 38400, 57600,\
                                        115200}