From patchwork Mon Aug 29 13:44:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 1671470 X-Patchwork-Delegate: sr@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=Yp1eeIoe; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MGWtP33KSz1ygV for ; Mon, 29 Aug 2022 23:46:03 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EB9158483C; Mon, 29 Aug 2022 15:45:51 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org 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=kernel.org header.i=@kernel.org header.b="Yp1eeIoe"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0CD2B8483C; Mon, 29 Aug 2022 15:45:51 +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.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id A14A88480A for ; Mon, 29 Aug 2022 15:45:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=pali@kernel.org Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 43A16B81087; Mon, 29 Aug 2022 13:45:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C36B4C433D6; Mon, 29 Aug 2022 13:45:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661780747; bh=wIIs8comvMj3KavZXBvaBf16WNqer56gmTahzhGnuTw=; h=From:To:Cc:Subject:Date:From; b=Yp1eeIoezGH62/xThVv8OWk/lfWUp+BqR6gkzpM4+O+59imjII+YQZTkkKWW9FudH Q3rN5dKui6wl4zUaRVSYiddsVgnH8WGv6wxWNDQRF4tK81aMru52oytgkRb0AbmqV3 lnieVaGX3aLaiixhulGAWInzPLBOxvY0vjqb4ST19pxnM6H+mgLG2zdURnQ5nX4oHo HgzFYfUoGWAiFe96GoIEoau673edqvIbI/jFs/zffp3UQA0ECDduWQ5NDTQeckKrs3 +OetsKxF8A4TkFj8TptEu7dMwUK5GlGk7Ow0tVOEZrksjS7gXh7RQ92qrXQsw8cE6o A29JlCNobjSjA== Received: by pali.im (Postfix) id AB9D07DE; Mon, 29 Aug 2022 15:45:43 +0200 (CEST) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: =?utf-8?q?Marek_Beh=C3=BAn?= , Stefan Roese Cc: u-boot@lists.denx.de Subject: [PATCH] arm: mvebu: turris_mox: Add support for distroboot $fdt_addr Date: Mon, 29 Aug 2022 15:44:48 +0200 Message-Id: <20220829134448.11570-1-pali@kernel.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 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.6 at phobos.denx.de X-Virus-Status: Clean $fdt_addr is mandatory for systems which provides DTB in HW (e.g. ROM) and wishes to pass that DTB to Linux. Turris Mox contains DTB binary in SPI NOR memory at "dtb" partition which starts at offset 0x7f0000 and is 0x10000 bytes long. Armada 3700 CPU does not allow mapping SPI NOR memory into physical address space like on other architectures and therefore set $fdt_addr variable to memory range in RAM and loads this DTB binary from SPI NOR in misc_init_r() function. Signed-off-by: Pali Rohár Reviewed-by: Stefan Roese --- board/CZ.NIC/turris_mox/turris_mox.c | 48 ++++++++++++++++++++++++++++ include/configs/turris_mox.h | 1 + 2 files changed, 49 insertions(+) diff --git a/board/CZ.NIC/turris_mox/turris_mox.c b/board/CZ.NIC/turris_mox/turris_mox.c index 3dbd68e52366..3402515bbae2 100644 --- a/board/CZ.NIC/turris_mox/turris_mox.c +++ b/board/CZ.NIC/turris_mox/turris_mox.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "mox_sp.h" @@ -339,6 +340,51 @@ static int get_reset_gpio(struct gpio_desc *reset_gpio) return 0; } +/* Load default system DTB binary to $fdr_addr */ +static void load_spi_dtb(void) +{ + const char *const env_name[1] = { "fdt_addr" }; + unsigned long size, offset; + struct udevice *spi_dev; + struct spi_flash *flash; + const char *addr_str; + unsigned long addr; + void *buf; + + addr_str = env_get(env_name[0]); + if (!addr_str) { + env_set_default_vars(1, (char * const *)env_name, 0); + addr_str = env_get(env_name[0]); + } + + if (!addr_str) + return; + + addr = hextoul(addr_str, NULL); + if (!addr) + return; + + spi_flash_probe_bus_cs(CONFIG_SF_DEFAULT_BUS, CONFIG_SF_DEFAULT_CS, &spi_dev); + flash = dev_get_uclass_priv(spi_dev); + if (!flash) + return; + + /* + * SPI NOR "dtb" partition offset & size hardcoded for now because the + * mtd subsystem does not offer finding the partition yet and we do not + * want to reimplement OF partition parser here. + */ + offset = 0x7f0000; + size = 0x10000; + + buf = map_physmem(addr, size, MAP_WRBACK); + if (!buf) + return; + + spi_flash_read(flash, offset, size, buf); + unmap_physmem(buf, size); +} + int misc_init_r(void) { u8 mac[2][6]; @@ -358,6 +404,8 @@ int misc_init_r(void) eth_env_set_enetaddr_by_index("eth", i, mac[i]); } + load_spi_dtb(); + return 0; } diff --git a/include/configs/turris_mox.h b/include/configs/turris_mox.h index b8ff705ac923..f549f9f7ad06 100644 --- a/include/configs/turris_mox.h +++ b/include/configs/turris_mox.h @@ -36,6 +36,7 @@ "bootm 0x5800000" #define CONFIG_EXTRA_ENV_SETTINGS \ + "fdt_addr=0x4c00000\0" \ "scriptaddr=0x4d00000\0" \ "pxefile_addr_r=0x4e00000\0" \ "fdt_addr_r=0x4f00000\0" \