diff mbox series

[v3,1/1] arm: apple: Switch to fully dynamic mem layout

Message ID 20220219130519.16947-1-j@jannau.net
State Accepted
Delegated to: Tom Rini
Headers show
Series [v3,1/1] arm: apple: Switch to fully dynamic mem layout | expand

Commit Message

Janne Grunau Feb. 19, 2022, 1:05 p.m. UTC
Support for Apple M1 Pro and Max will allow using a single binary for
all M1 SoCs. The M1 Pro/Max have a different memory layout. The RAM
start address is 0x100_0000_0000 instead of 0x8_0000_0000.
Replace the hardcoded memory layout with dynamic initialized
environment variables in board_late_init().

Tested on Mac Mini (2020) and Macbook Pro 14-inch (2021).

Signed-off-by: Janne Grunau <j@jannau.net>
Reviewed-by: Mark Kettenis <kettenis@openbsd.org>
---
Changes compared to v2:
 - rebased to master + Mark's "arm: apple: Add M1 Pro/Max support"
   20220208210009.46165-1-kettenis@openbsd.org
   Resolves conflicts merged Apple NVME patch and follows the order
   proposed by Mark
 - added kernel_comp_{addr_r,size} for compressed kernel support

 arch/arm/mach-apple/board.c | 33 +++++++++++++++++++++++++++++++++
 configs/apple_m1_defconfig  |  3 ++-
 include/configs/apple.h     |  5 -----
 3 files changed, 35 insertions(+), 6 deletions(-)

Comments

Tom Rini Feb. 28, 2022, 8:47 p.m. UTC | #1
On Sat, Feb 19, 2022 at 02:05:19PM +0100, Janne Grunau wrote:

> Support for Apple M1 Pro and Max will allow using a single binary for
> all M1 SoCs. The M1 Pro/Max have a different memory layout. The RAM
> start address is 0x100_0000_0000 instead of 0x8_0000_0000.
> Replace the hardcoded memory layout with dynamic initialized
> environment variables in board_late_init().
> 
> Tested on Mac Mini (2020) and Macbook Pro 14-inch (2021).
> 
> Signed-off-by: Janne Grunau <j@jannau.net>
> Reviewed-by: Mark Kettenis <kettenis@openbsd.org>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/arch/arm/mach-apple/board.c b/arch/arm/mach-apple/board.c
index f9f8a2f278..54005f3adf 100644
--- a/arch/arm/mach-apple/board.c
+++ b/arch/arm/mach-apple/board.c
@@ -265,3 +265,36 @@  u64 get_page_table_size(void)
 {
 	return SZ_256K;
 }
+
+int board_late_init(void)
+{
+	unsigned long base;
+	unsigned long top;
+	u32 status = 0;
+
+	/* Reserve 4M each for scriptaddr and pxefile_addr_r at the top of RAM
+	 * at least 1M below the stack.
+	 */
+	top = gd->start_addr_sp - CONFIG_STACK_SIZE - SZ_8M - SZ_1M;
+	top = ALIGN_DOWN(top, SZ_8M);
+
+	status |= env_set_hex("scriptaddr", top + SZ_4M);
+	status |= env_set_hex("pxefile_addr_r", top);
+
+	/* somewhat based on the Linux Kernel boot requirements:
+	 * align by 2M and maximal FDT size 2M
+	 */
+	base = ALIGN(gd->ram_base, SZ_2M);
+
+	status |= env_set_hex("fdt_addr_r", base);
+	status |= env_set_hex("kernel_addr_r", base + SZ_2M);
+	status |= env_set_hex("ramdisk_addr_r", base + SZ_128M);
+	status |= env_set_hex("loadaddr", base + SZ_2G);
+	status |= env_set_hex("kernel_comp_addr_r", base + SZ_2G - SZ_128M);
+	status |= env_set_hex("kernel_comp_size", SZ_128M);
+
+	if (status)
+		log_warning("late_init: Failed to set run time variables\n");
+
+	return 0;
+}
diff --git a/configs/apple_m1_defconfig b/configs/apple_m1_defconfig
index 8583e4ad8c..ef5b7ffd1a 100644
--- a/configs/apple_m1_defconfig
+++ b/configs/apple_m1_defconfig
@@ -4,10 +4,11 @@  CONFIG_DEFAULT_DEVICE_TREE="t8103-j274"
 CONFIG_DEBUG_UART_BASE=0x235200000
 CONFIG_DEBUG_UART_CLOCK=24000000
 CONFIG_DEBUG_UART=y
-CONFIG_SYS_LOAD_ADDR=0x880000000
+CONFIG_SYS_LOAD_ADDR=0x0
 CONFIG_USE_PREBOOT=y
 # CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
+CONFIG_BOARD_LATE_INIT=y
 # CONFIG_NET is not set
 # CONFIG_MMC is not set
 CONFIG_DEBUG_UART_ANNOUNCE=y
diff --git a/include/configs/apple.h b/include/configs/apple.h
index f12e9bdef5..b06660add4 100644
--- a/include/configs/apple.h
+++ b/include/configs/apple.h
@@ -9,10 +9,6 @@ 
 	"stdout=serial,vidconsole\0" \
 	"stderr=serial,vidconsole\0"
 
-#define ENV_MEM_LAYOUT_SETTINGS \
-	"fdt_addr_r=0x960100000\0" \
-	"kernel_addr_r=0x960200000\0"
-
 #if CONFIG_IS_ENABLED(CMD_NVME)
 	#define BOOT_TARGET_NVME(func) func(NVME, nvme, 0)
 #else
@@ -33,7 +29,6 @@ 
 
 #define CONFIG_EXTRA_ENV_SETTINGS \
 	ENV_DEVICE_SETTINGS \
-	ENV_MEM_LAYOUT_SETTINGS \
 	BOOTENV
 
 #endif