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 C8DEFC433EF for ; Sun, 8 May 2022 15:09:40 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 933FF83E2B; Sun, 8 May 2022 17:08:47 +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="jf3V6qUO"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C655483F35; Sun, 8 May 2022 17:08:39 +0200 (CEST) Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) (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 0349883D62 for ; Sun, 8 May 2022 17:08:33 +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=jbx6244@gmail.com Received: by mail-ej1-x62a.google.com with SMTP id gh6so22547668ejb.0 for ; Sun, 08 May 2022 08:08:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gB/xJvNpwuQDvtPxohIIQcEpRAKBrS8ig+qmz+toRgM=; b=jf3V6qUO3d80rkO+U34jK5pt9DF0cLbljxyqmobswHoLhFlrpwk28L+f4YzK2GLlGp /KMiutgPp+leuoKrNYgUMBgguEzhrla/wOGrX+b58SzIvln1rDkBnNddg/t2lTJ3Vr3a Cu46NAOiJa3FKETc8fY1eZN296R507qs8BX4H17mA91z6gcw64VhFOWeS8wH3QEj/rVU YJtGGlPIosPk6SjVd8Ux5bWiqJtktQ10ML6tzEbbelzZgG36qKd5ixyV07zKtQQzh/uR Z1CMDxZEGUVoPNmH7UnVgmLDSaZvOYGliRg6baDAWt/8DRHpAhAFkOBFvEsYCjOTEIyn QILQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gB/xJvNpwuQDvtPxohIIQcEpRAKBrS8ig+qmz+toRgM=; b=hulxDBEqGpzsVGm5i5AamyTtaTBGQnvYWXhArocv1Vd+pFeqw4ntz73exTUX+726no QpxpMg8UyN68YcPZERQZQahMTSABeJt+h8Qz7hWzj3yNyZWsnUGQSAm50zFjo+YbsY3S LI6d2USWEeHVCWM6UbLhj1T9LyTLWZjeHAWKRZyBf09FNL+LacsHbtsb4Nh3H4KgSpuv dsLY+ZXKppDlkQ2fP6ClmjLYA9HOUtWrphyJ7iw/bko6uubArTfBkGNWJzDGKr65+bXf StEJ/vx5p2D0jLBCbGo0Pwf0KGC9wZu+SuA7lnv4yyFB7YNEbodYyymxmoPVPK3UKwWa TqBQ== X-Gm-Message-State: AOAM5324sNCltaCyX2WyYbpmQHPDf8HEcQAcH89JHb+gk3PUUiIpAEhy nYzcDira4jh8vqLecuBv8bI= X-Google-Smtp-Source: ABdhPJy9c5xnmRrFxb3lEWU0BCIF17pVDYNjakq1ETGB7FTIJAlA5mtpzbBsCF8uXiqABiNcp0iNbA== X-Received: by 2002:a17:907:72c5:b0:6f4:678:8742 with SMTP id du5-20020a17090772c500b006f406788742mr11197128ejc.607.1652022513442; Sun, 08 May 2022 08:08:33 -0700 (PDT) Received: from debian.home (81-204-249-205.fixed.kpn.net. [81.204.249.205]) by smtp.gmail.com with ESMTPSA id yl26-20020a17090693fa00b006f3ef214dc2sm4102721ejb.40.2022.05.08.08.08.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 08:08:33 -0700 (PDT) From: Johan Jonker To: kever.yang@rock-chips.com Cc: sjg@chromium.org, philipp.tomsich@vrull.eu, lukma@denx.de, marex@denx.de, u-boot@lists.denx.de Subject: [PATCH v1 01/17] rockchip: spl: fix reloc gd and FDT blob pointer Date: Sun, 8 May 2022 17:08:09 +0200 Message-Id: <20220508150825.21711-2-jbx6244@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220508150825.21711-1-jbx6244@gmail.com> References: <20220508150825.21711-1-jbx6244@gmail.com> 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 When the Rockchip function dram_init() is called in the spl.c board_init_f() the variable gd->ram_base returns 0. This is problematic for functions after the gd relocation. Fix by adding ram.base to gd->ram_base in sdram.c. After the function spl_relocate_stack_gd is called in crt0.S the pointer gd might be relocated and BSS with the FDT blob is erased. The pointer gd->fdt_blob is no longer valid when enabled SPL_OF_REAL and SPL_MMC, SPL_USB_HOST or SPL_USB_GADGET. This patch makes that FDT properties can be parsed in the board_init_r() function. Fix by setting this pointers simulair to board_f.c and copy the FDT to it's new location at the end of DRAM. Signed-off-by: Johan Jonker --- arch/arm/mach-rockchip/sdram.c | 1 + arch/arm/mach-rockchip/spl.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/arch/arm/mach-rockchip/sdram.c b/arch/arm/mach-rockchip/sdram.c index 705ec7ba..b5972269 100644 --- a/arch/arm/mach-rockchip/sdram.c +++ b/arch/arm/mach-rockchip/sdram.c @@ -198,6 +198,7 @@ int dram_init(void) debug("Cannot get DRAM size: %d\n", ret); return ret; } + gd->ram_base = ram.base; gd->ram_size = ram.size; debug("SDRAM base=%lx, size=%lx\n", (unsigned long)ram.base, (unsigned long)ram.size); diff --git a/arch/arm/mach-rockchip/spl.c b/arch/arm/mach-rockchip/spl.c index 30be6404..ceef9d91 100644 --- a/arch/arm/mach-rockchip/spl.c +++ b/arch/arm/mach-rockchip/spl.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -149,6 +150,21 @@ void board_init_f(ulong dummy) } gd->ram_top = gd->ram_base + get_effective_memsize(); gd->ram_top = board_get_usable_ram_top(gd->ram_size); + + /* Copy FDT blob from BSS to the end of DRAM */ + if (gd->fdt_blob) { + gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob), 32); + unsigned long fdt_addr = ALIGN_DOWN(gd->ram_top - gd->fdt_size, 16); + + gd->new_fdt = map_sysmem(fdt_addr, gd->fdt_size); + + debug("Reserved %lu bytes for FDT at: %08lx\n", gd->fdt_size, fdt_addr); + + if (gd->new_fdt) { + memcpy(gd->new_fdt, gd->fdt_blob, fdt_totalsize(gd->fdt_blob)); + gd->fdt_blob = gd->new_fdt; + } + } #endif preloader_console_init(); } -- 2.20.1