Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2F99FC433EF for ; Tue, 8 Feb 2022 21:02:22 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 228A983DCF; Tue, 8 Feb 2022 22:02:20 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=jannau.net Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 2C10C83DD6; Tue, 8 Feb 2022 22:02:19 +0100 (CET) Received: from soltyk.jannau.net (soltyk.jannau.net [144.76.91.90]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2B9AA83DB8 for ; Tue, 8 Feb 2022 22:02:16 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=jannau.net Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=j@jannau.net Received: from coburn.home.jannau.net (p579ad520.dip0.t-ipconnect.de [87.154.213.32]) by soltyk.jannau.net (Postfix) with ESMTPSA id BAFA326E38A; Tue, 8 Feb 2022 22:02:15 +0100 (CET) From: Janne Grunau To: u-boot@lists.denx.de Cc: Mark Kettenis , Tom Rini , sjg@chromium.com Subject: [PATCH v2 1/1] arm: apple: Switch to fully dynamic mem layout Date: Tue, 8 Feb 2022 22:02:15 +0100 Message-Id: <20220208210215.8612-1-j@jannau.net> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean 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 Reviewed-by: Mark Kettenis --- Changed in v2: - ensure adresses are aligned - added space between addresses at the top and stack - added loadaddr and set the default to 0 - pick up Mark's Reviewed-by - whitespace fixes arch/arm/mach-apple/board.c | 31 +++++++++++++++++++++++++++++++ configs/apple_m1_defconfig | 3 ++- include/configs/apple.h | 5 ----- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/arch/arm/mach-apple/board.c b/arch/arm/mach-apple/board.c index b7e8d212f1..46877569af 100644 --- a/arch/arm/mach-apple/board.c +++ b/arch/arm/mach-apple/board.c @@ -136,3 +136,34 @@ ulong board_get_usable_ram_top(ulong total_size) */ return 0x980000000; } + +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); + + 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 cb235e4e7d..b96d31db2c 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=240000 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 3e5fb495f1..f73f4f047b 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_USB) #define BOOT_TARGET_USB(func) func(USB, usb, 0) #else @@ -26,7 +22,6 @@ #define CONFIG_EXTRA_ENV_SETTINGS \ ENV_DEVICE_SETTINGS \ - ENV_MEM_LAYOUT_SETTINGS \ BOOTENV #endif -- 2.35.1