From patchwork Tue Apr 20 14:17:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaobo Tian X-Patchwork-Id: 1468356 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=tyOF6Asb; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FPm4f6K1Pz9vDk for ; Wed, 21 Apr 2021 00:18:26 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8153382B01; Tue, 20 Apr 2021 16:18:23 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="tyOF6Asb"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F246882B08; Tue, 20 Apr 2021 16:18:21 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E8BF182AFE for ; Tue, 20 Apr 2021 16:18:16 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=peterwillcn@gmail.com Received: by mail-pj1-x102c.google.com with SMTP id nm3-20020a17090b19c3b029014e1bbf6c60so16328812pjb.4 for ; Tue, 20 Apr 2021 07:18:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ArhzsibN3tUBolf4AllPV18+mGmTN2kxyiO/XImZots=; b=tyOF6AsbUNhjXWEmR/QKMJ0ZE5pqktzr4pZN09OXQeOE/4dbtfEuNZBVbqIjn/Cdhn BgABnVIPTfCWMfyHprvbtFdOv67tdOV1bGdpOVkdVSNbji9MZom4hbXr307kut2DhS64 +IlZY+WyzSwmTA9kYQ5bAK2IhQjSq80iVWrNADjx3SgZmBDdy7KS5w5TMYj7B91OA/yS V3/TA/dGwgpXsOgpNXb6d8herIKPYBUli3DNbGFsGX9qVXjjhV3uDAG+C4P8U0GwmMU0 N+a4fhUBXyLYvnHZU4dJW67hOSFNb5B67MAQ0otsSuxNyTwwAQD591xJ66fSHGPLnhbe M+tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ArhzsibN3tUBolf4AllPV18+mGmTN2kxyiO/XImZots=; b=JnkAJDvY038L77iJuImj4GN+WNvfxC4bvfMSuMQvAjCokwqUC5pSk5VcRJ7ADUpJfw j2HMPUniMk38NmakdIlMKGZVxhd0LExgEZZlERHFvnP1pcyfrGwWT0jYtnUTqJerjWtL jhSXT79bpCjvYnVqIBHRN4F4K+sRa9D217Cv8Fpfd0jBbNtT5xZlswE+De9KrL15LHvL VQhK2jGq+DZjEqWRZRsXl5ZJlatLspZh05Vhn/5WKvtNzEdtgpVmkXphGY0+QcCXQaiG h86AEoP0R12nMyOhnEUHSq1GpQAdMtNEJpbnP47fdFkI4zGQOiLon4rFOA99RD8yQVE+ ZwkA== X-Gm-Message-State: AOAM532IzKLhX16/sHtJ1Cu2QA3CBtCFBdqG9RAvwTH5meLqP7quELJU cGfXp7zrAfBp6pGvOZvP1lwMqYjZCNvvng== X-Google-Smtp-Source: ABdhPJwh+BlYYD6gkBL9tgMjkcHUuS4Be1YbaypXQr2ooy2qOENw+Im39eKbL/qgq4+Z8y1Yy+HqOQ== X-Received: by 2002:a17:90a:540b:: with SMTP id z11mr5330628pjh.133.1618928295099; Tue, 20 Apr 2021 07:18:15 -0700 (PDT) Received: from MacBook-Pro.lan (li1891-139.members.linode.com. [172.105.237.139]) by smtp.gmail.com with ESMTPSA id p10sm6498041pfo.210.2021.04.20.07.17.32 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Apr 2021 07:17:34 -0700 (PDT) From: xiaobo To: u-boot@lists.denx.de, trini@konsulko.com, kever.yang@rock-chips.com, wens@kernel.org, patrick@blueri.se Cc: Alexandru Gagniuc Subject: [PATCH] Revert "spl: Drop bd_info in the data section" Date: Tue, 20 Apr 2021 22:17:19 +0800 Message-Id: <20210420141719.45182-1-peterwillcn@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 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.102.4 at phobos.denx.de X-Virus-Status: Clean From: Alexandru Gagniuc This reverts commit 38d6b7ebdaee3e0e8426ef1b9df88bdce8ae2e75. struct global_data contains a pointer to the bd_info structure. This pointer was populated spl_set_bd() to a pre-allocated bd_info in the ".data" section. The referenced commit replaced this mechanism to one that uses malloc(). That new mechanism is only used if SPL_ALLOC_BD=y. which very few boards do. The result is that (struct global_data)->bd is NULL in SPL on most platforms. This breaks falcon mode, since arch_fixup_fdt() tries to access (struct global_data)->bd and set the "/memory" node in the devicetree. The result is that the "/memory" node contains garbage values, causing linux to panic() as it sets up the page table. Instead of trying to fix the mess, potentially causing other issues, revert to the code that worked, while this change is reworked. Signed-off-by: Alexandru Gagniuc --- arch/arm/cpu/armv8/fsl-layerscape/spl.c | 5 +---- common/spl/Kconfig | 9 --------- common/spl/spl.c | 20 ++++++++------------ include/spl.h | 10 +--------- 4 files changed, 10 insertions(+), 34 deletions(-) diff --git a/arch/arm/cpu/armv8/fsl-layerscape/spl.c b/arch/arm/cpu/armv8/fsl-layerscape/spl.c index 5b43a2a231..b3f1148f9d 100644 --- a/arch/arm/cpu/armv8/fsl-layerscape/spl.c +++ b/arch/arm/cpu/armv8/fsl-layerscape/spl.c @@ -41,9 +41,6 @@ u32 spl_boot_device(void) #ifdef CONFIG_SPL_BUILD -/* Define board data structure */ -static struct bd_info bdata __attribute__ ((section(".data"))); - void spl_board_init(void) { #if defined(CONFIG_NXP_ESBC) && defined(CONFIG_FSL_LSCH2) @@ -89,7 +86,7 @@ void board_init_f(ulong dummy) get_clocks(); preloader_console_init(); - gd->bd = &bdata; + spl_set_bd(); #ifdef CONFIG_SYS_I2C #ifdef CONFIG_SPL_I2C_SUPPORT diff --git a/common/spl/Kconfig b/common/spl/Kconfig index 0f528f346f..df5468f1ac 100644 --- a/common/spl/Kconfig +++ b/common/spl/Kconfig @@ -113,15 +113,6 @@ config SPL_FSL_PBL Create boot binary having SPL binary in PBI format concatenated with u-boot binary. -config SPL_ALLOC_BD - bool "Allocate memory for bd_info" - default y if X86 || SANDBOX - help - Some boards don't allocate space for this in their board_init_f() - code. In this case U-Boot can allocate space for gd->bd in the - standard SPL flow (board_init_r()). Enable this option to support - this feature. - endmenu config HANDOFF diff --git a/common/spl/spl.c b/common/spl/spl.c index 8c4cd933cf..a0a608fd77 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -55,6 +55,9 @@ binman_sym_declare(ulong, spl, image_pos); binman_sym_declare(ulong, spl, size); #endif +/* Define board data structure */ +static struct bd_info bdata __attribute__ ((section(".data"))); + /* * Board-specific Platform code can reimplement show_boot_progress () if needed */ @@ -490,19 +493,14 @@ static int spl_common_init(bool setup_malloc) return 0; } -int spl_alloc_bd(void) +void spl_set_bd(void) { /* * NOTE: On some platforms (e.g. x86) bdata may be in flash and not * writeable. */ - if (!gd->bd) { - gd->bd = malloc(sizeof(*gd->bd)); - if (!gd->bd) - return -ENOMEM; - } - - return 0; + if (!gd->bd) + gd->bd = &bdata; } int spl_early_init(void) @@ -652,6 +650,8 @@ void board_init_r(gd_t *dummy1, ulong dummy2) debug(">>" SPL_TPL_PROMPT "board_init_r()\n"); + spl_set_bd(); + #if defined(CONFIG_SYS_SPL_MALLOC_START) mem_malloc_init(CONFIG_SYS_SPL_MALLOC_START, CONFIG_SYS_SPL_MALLOC_SIZE); @@ -661,10 +661,6 @@ void board_init_r(gd_t *dummy1, ulong dummy2) if (spl_init()) hang(); } - if (IS_ENABLED(CONFIG_SPL_ALLOC_BD) && spl_alloc_bd()) { - puts("Cannot alloc bd\n"); - hang(); - } #if !defined(CONFIG_PPC) && !defined(CONFIG_ARCH_MX6) /* * timer_init() does not exist on PPC systems. The timer is initialized diff --git a/include/spl.h b/include/spl.h index 4f6e0e53f5..cee9a42ddb 100644 --- a/include/spl.h +++ b/include/spl.h @@ -357,15 +357,7 @@ u32 spl_mmc_boot_mode(const u32 boot_device); * If not overridden, it is weakly defined in common/spl/spl_mmc.c. */ int spl_mmc_boot_partition(const u32 boot_device); - -/** - * spl_alloc_bd() - Allocate space for bd_info - * - * This sets up the gd->bd pointer by allocating memory for it - * - * @return 0 if OK, -ENOMEM if out of memory - */ -int spl_alloc_bd(void); +void spl_set_bd(void); /** * spl_set_header_raw_uboot() - Set up a standard SPL image structure