Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33D7FC07E9B for ; Wed, 7 Jul 2021 10:59:17 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 1C5B461CAC for ; Wed, 7 Jul 2021 10:59:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1C5B461CAC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=gerhold.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 00FB382BD7; Wed, 7 Jul 2021 12:59:09 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gerhold.net Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gerhold.net header.i=@gerhold.net header.b="mgprgPsR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9C40482DDD; Wed, 7 Jul 2021 12:59:07 +0200 (CEST) Received: from mo4-p00-ob.smtp.rzone.de (mo4-p00-ob.smtp.rzone.de [85.215.255.20]) (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 728E382B30 for ; Wed, 7 Jul 2021 12:59:04 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gerhold.net Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=stephan@gerhold.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1625655543; s=strato-dkim-0002; d=gerhold.net; h=Message-Id:Date:Subject:Cc:To:From:Cc:Date:From:Subject:Sender; bh=1QLd+dZh5If27Um3femF9ZYet89E0CvJIfd0tQ5o+Yc=; b=mgprgPsRvjt2RvXbbBR0WgVZ22U5BxuA/Y3aFIf524klo0XqQvEscXz8/lsmsDgSHf gCOhgbesK8ScA94ur2+ua4Z5f0LRFfuTzQwtoSa/ARBbt+2IlFY67miZdFndMxg9uh3b e3LngjbypFGGUq33n+go/YqV5lgF42FmRcYQHIRRHRrqcQNcW6lXuc6CmL5uV6zDJi7p bD0ALm91l+VlBPBeWQtp/ByF1hnAKyLtt4VfadjNfuI5kJDNt4bnzC9i77O2uQKP+Bw9 O8qUv8Y5ZPXcapj3L1k823QdKZn3Y7nGos/lSnI0C9Y5VBD+c9lLSfNn+dZknXOXskWH 2ImA== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":P3gBZUipdd93FF5ZZvYFPugejmSTVR2nRPhVORvLd4SsytBXS7IYBkLahKxB4m6O53fv" X-RZG-CLASS-ID: mo00 Received: from droid.. by smtp.strato.de (RZmta 47.28.1 DYNA|AUTH) with ESMTPSA id Y070ccx67Ax3hRR (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Wed, 7 Jul 2021 12:59:03 +0200 (CEST) From: Stephan Gerhold To: u-boot@lists.denx.de Cc: Linus Walleij , Stephan Gerhold Subject: [PATCH 1/2] board: stemmy: Parse atags to get available memory Date: Wed, 7 Jul 2021 12:58:54 +0200 Message-Id: <20210707105855.89260-1-stephan@gerhold.net> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.2 at phobos.denx.de X-Virus-Status: Clean At the moment the "stemmy" board attempts to detect the RAM size with a simple memory test (get_ram_size()). Unfortunately, this does not work correctly for devices with 768 MiB RAM (e.g. Samsung Galaxy Ace 2 (GT-I8160), "codina"). Reading/writing memory after the 768 MiB RAM succeeds but actually overwrites some earlier parts of the memory. For U-Boot this does not result in any major problems, but on Linux this will eventually lead to strange crashes because of the memory corruption. Since the "stemmy" U-Boot port is designed to be chainloaded from the original Samsung bootloader, the most reliable way to get the available amount of RAM is to look at the ATAGS passed by the Samsung bootloader. Fortunately, the header used to generate ATAGS in U-Boot (asm/setup.h) can also be easily used to parse them. Also clarify and simplify stemmy.h a bit to make it more clear where some of the magic values in there are actually coming from. Signed-off-by: Stephan Gerhold --- arch/arm/mach-u8500/Kconfig | 1 + board/ste/stemmy/README | 1 + board/ste/stemmy/stemmy.c | 62 ++++++++++++++++++++++++++++++++++++- configs/stemmy_defconfig | 2 +- include/configs/stemmy.h | 23 ++++++-------- 5 files changed, 74 insertions(+), 15 deletions(-) diff --git a/arch/arm/mach-u8500/Kconfig b/arch/arm/mach-u8500/Kconfig index 7478deb25f..372fbeb80f 100644 --- a/arch/arm/mach-u8500/Kconfig +++ b/arch/arm/mach-u8500/Kconfig @@ -15,6 +15,7 @@ config TARGET_STEMMY - Samsung Galaxy S III mini (GT-I8190) "golden" - Samsung Galaxy S Advance (GT-I9070) "janice" - Samsung Galaxy Xcover 2 (GT-S7710) "skomer" + - Samsung Galaxy Ace 2 (GT-I8160) "codina" and likely others as well (untested). diff --git a/board/ste/stemmy/README b/board/ste/stemmy/README index 81f72426f2..1b83b833c0 100644 --- a/board/ste/stemmy/README +++ b/board/ste/stemmy/README @@ -7,6 +7,7 @@ the ST-Ericsson NovaThor U8500 SoC, e.g. - Samsung Galaxy S III mini (GT-I8190) "golden" - Samsung Galaxy S Advance (GT-I9070) "janice" - Samsung Galaxy Xcover 2 (GT-S7710) "skomer" + - Samsung Galaxy Ace 2 (GT-I8160) "codina" and likely others as well (untested). diff --git a/board/ste/stemmy/stemmy.c b/board/ste/stemmy/stemmy.c index b9b2a6fddc..9e6c8e208e 100644 --- a/board/ste/stemmy/stemmy.c +++ b/board/ste/stemmy/stemmy.c @@ -4,17 +4,77 @@ */ #include #include +#include #include +#include +#include DECLARE_GLOBAL_DATA_PTR; +/* Parse atags provided by Samsung bootloader to get available memory */ +static ulong fw_mach __section(".data"); +static ulong fw_atags __section(".data"); + +void save_boot_params(ulong r0, ulong r1, ulong r2, ulong r3) +{ + fw_mach = r1; + fw_atags = r2; + save_boot_params_ret(); +} + +static const struct tag *fw_atags_get(void) +{ + const struct tag *tags = (const struct tag *)fw_atags; + + if (tags->hdr.tag != ATAG_CORE) { + log_err("Invalid atags: tag 0x%x at %p\n", tags->hdr.tag, tags); + return NULL; + } + + return tags; +} + int dram_init(void) { - gd->ram_size = get_ram_size(CONFIG_SYS_SDRAM_BASE, CONFIG_SYS_SDRAM_SIZE); + const struct tag *t, *tags = fw_atags_get(); + + if (!tags) + return -EINVAL; + + for_each_tag(t, tags) { + if (t->hdr.tag != ATAG_MEM) + continue; + + debug("Memory: %#x-%#x (size %#x)\n", t->u.mem.start, + t->u.mem.start + t->u.mem.size, t->u.mem.size); + gd->ram_size += t->u.mem.size; + } + return 0; +} + +int dram_init_banksize(void) +{ + const struct tag *t, *tags = fw_atags_get(); + unsigned int bank = 0; + + if (!tags) + return -EINVAL; + + for_each_tag(t, tags) { + if (t->hdr.tag != ATAG_MEM) + continue; + + gd->bd->bi_dram[bank].start = t->u.mem.start; + gd->bd->bi_dram[bank].size = t->u.mem.size; + if (++bank == CONFIG_NR_DRAM_BANKS) + break; + } return 0; } int board_init(void) { + gd->bd->bi_arch_number = fw_mach; + gd->bd->bi_boot_params = fw_atags; return 0; } diff --git a/configs/stemmy_defconfig b/configs/stemmy_defconfig index 79c05acc6a..f31960b814 100644 --- a/configs/stemmy_defconfig +++ b/configs/stemmy_defconfig @@ -1,7 +1,7 @@ CONFIG_ARM=y CONFIG_ARCH_U8500=y CONFIG_SYS_TEXT_BASE=0x100000 -CONFIG_NR_DRAM_BANKS=1 +CONFIG_NR_DRAM_BANKS=2 CONFIG_DEFAULT_DEVICE_TREE="ste-ux500-samsung-stemmy" CONFIG_SYS_CONSOLE_INFO_QUIET=y CONFIG_HUSH_PARSER=y diff --git a/include/configs/stemmy.h b/include/configs/stemmy.h index 922eec43ee..c446b09270 100644 --- a/include/configs/stemmy.h +++ b/include/configs/stemmy.h @@ -7,23 +7,20 @@ #include -#define CONFIG_SKIP_LOWLEVEL_INIT /* Loaded by another bootloader */ -#define CONFIG_SYS_MALLOC_LEN SZ_2M +/* + * The "stemmy" U-Boot port is designed to be chainloaded by the Samsung + * bootloader on devices based on ST-Ericsson Ux500. Therefore, we skip most + * low-level initialization and rely on configuration provided by the Samsung + * bootloader. New images are loaded at the same address for compatibility. + */ +#define CONFIG_SKIP_LOWLEVEL_INIT +#define CONFIG_SYS_INIT_SP_ADDR CONFIG_SYS_TEXT_BASE +#define CONFIG_SYS_LOAD_ADDR CONFIG_SYS_TEXT_BASE -/* Physical Memory Map */ -#define PHYS_SDRAM_1 0x00000000 /* DDR-SDRAM Bank #1 */ -#define CONFIG_SYS_SDRAM_BASE PHYS_SDRAM_1 -#define CONFIG_SYS_SDRAM_SIZE SZ_1G -#define CONFIG_SYS_INIT_RAM_SIZE 0x00100000 -#define CONFIG_SYS_GBL_DATA_OFFSET (CONFIG_SYS_SDRAM_BASE + \ - CONFIG_SYS_INIT_RAM_SIZE - \ - GENERATED_GBL_DATA_SIZE) -#define CONFIG_SYS_INIT_SP_ADDR CONFIG_SYS_GBL_DATA_OFFSET +#define CONFIG_SYS_MALLOC_LEN SZ_2M /* FIXME: This should be loaded from device tree... */ #define CONFIG_SYS_L2_PL310 #define CONFIG_SYS_PL310_BASE 0xa0412000 -#define CONFIG_SYS_LOAD_ADDR 0x00100000 - #endif -- 2.32.0