From patchwork Sat Apr 18 19:32:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1272706 X-Patchwork-Delegate: uboot@andestech.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; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=fjIHjH6m; 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) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 494NRt4l64z9sRN for ; Sun, 19 Apr 2020 05:33:46 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AED9E81C6B; Sat, 18 Apr 2020 21:33:18 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=wdc.com 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=wdc.com header.i=@wdc.com header.b="fjIHjH6m"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6950581C75; Sat, 18 Apr 2020 21:33:08 +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,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) (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 824C881C59 for ; Sat, 18 Apr 2020 21:33:02 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=wdc.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=prvs=370d05252=atish.patra@wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1587238382; x=1618774382; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FfjW8KHbQsOLAHvSwbpw8fZE6GlFVrZL5p//DkhAKR0=; b=fjIHjH6mx7K9UNUDMXM3bcjyfrfoZEN4vJG7kDhOHx9cemWJ3Vl5tbVt VDxm66Inml9+Z1X1bKkAJz+4hwYRlCIChC31eP6Q06bdkcGMQ6X5LC2wV oTA+eCx54GF4qhkWIXoyLYXjPGoxqUVsqacvo7SdJyFrwT8zzfk4X0AtL kCJxcI3F2REC3bQAu3TTLIcTZHXUFRrrW/mpOxl9cBMmQoE/P755OJ8k0 nMk+cXQIO0SBLLzoVFHxHODeWY8L3V1VODAXFAhT9hmUvpARaUQEz+L3g WYL4YR//l6jzkhx5Swsv8SMEGf+S6nEEnRdT53vEYK3ecRtF6byVAMtHk g==; IronPort-SDR: zqWK53hqfgc/o1Y7BM6d1cAGRhH8kNYltut9i3TMmzAHYMBlMtSWwFuNnAU6S+oKyB+dJffKpz xoWO3+X4lyivyLYFq4YOLGB/xipi4++Yz1sb1TYzG5T+WQ5fAhxMUrFeXsUO6ADTTJR51NpToF hsSYc7X9CAULTcYfR8B0vVPKCSBFGAlKFYezDcpssGUr1XkxqwkoYNr4oJELhuT3g1dZAtUCq7 KZiEHQe3e0pcmqz0WMVP0XbVeVt61/5MTfsjPNBb3LyImEdQ0/6Nh4lvZgCg+MQDYg9qMH56G8 z8A= X-IronPort-AV: E=Sophos;i="5.72,400,1580745600"; d="scan'208";a="244312813" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Apr 2020 03:32:40 +0800 IronPort-SDR: jI4fmXWQa9C2w6jcXzjehjFgoxw+/QMjVJBnrov3z+eZx3FtMpCOhc9bVMZEX0QP3nQtUwv6wo lqW5nKumuTPQmR14Nk78c68ab1F7mKp5E= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Apr 2020 12:23:37 -0700 IronPort-SDR: kmLmqFR81WLodfZFsEkFay2t63Fg4PMCRKSzuQPadpn5KayNLNVI0tn9r8oQOBAin5006HAycU 6fJFdjiC66GQ== WDCIronportException: Internal Received: from cnf007834.ad.shared (HELO yoda.hgst.com) ([10.86.56.8]) by uls-op-cesaip01.wdc.com with ESMTP; 18 Apr 2020 12:32:41 -0700 From: Atish Patra To: u-boot@lists.denx.de Cc: Atish Patra , Rick Chen , Bin Meng , Heinrich Schuchardt , Anup Patel , Lukas Auer , agraf@csgraf.de, ard.biesheuvel@linaro.org, Marcus Comstedt , Paul Walmsley , palmer@dabbelt.com Subject: [PATCH v6 1/6] riscv: Add boot hartid to device tree Date: Sat, 18 Apr 2020 12:32:23 -0700 Message-Id: <20200418193228.44209-2-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200418193228.44209-1-atish.patra@wdc.com> References: <20200418193228.44209-1-atish.patra@wdc.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.2 at phobos.denx.de X-Virus-Status: Clean Linux booting protocol mandates that register "a0" contains the hartid. However, U-Boot can not pass the hartid via a0 during via standard UEFI protocol. DT nodes are commonly used to pass such information to the OS. Add a DT node under chosen node to indicate the boot hartid. EFI stub in Linux kernel will parse this node and pass it to the real kernel in "a0" before jumping to it. Signed-off-by: Atish Patra Reviewed-by: Rick Chen Reviewed-by: Bin Meng Tested-by: Heinrich Schuchardt Tested-by: Bin Meng --- arch/riscv/lib/bootm.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/arch/riscv/lib/bootm.c b/arch/riscv/lib/bootm.c index fad16901c5f2..87cadad5016d 100644 --- a/arch/riscv/lib/bootm.c +++ b/arch/riscv/lib/bootm.c @@ -28,6 +28,28 @@ __weak void board_quiesce_devices(void) int arch_fixup_fdt(void *blob) { +#ifdef CONFIG_EFI_LOADER + int err; + u32 size; + int chosen_offset; + + size = fdt_totalsize(blob); + err = fdt_open_into(blob, blob, size + 32); + if (err < 0) { + printf("Device Tree can't be expanded to accommodate new node"); + return err; + } + chosen_offset = fdt_path_offset(blob, "/chosen"); + if (chosen_offset < 0) { + err = fdt_add_subnode(blob, 0, "chosen"); + if (err < 0) { + printf("chosen node can not be added\n"); + return err; + } + } + /* Overwrite the boot-hartid as U-Boot is the last stage BL */ + fdt_setprop_u32(blob, chosen_offset, "boot-hartid", gd->arch.boot_hart); +#endif return 0; } From patchwork Sat Apr 18 19:32:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1272705 X-Patchwork-Delegate: uboot@andestech.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=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=JI5MIh7p; 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 494NRd0gQrz9sRN for ; Sun, 19 Apr 2020 05:33:29 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8597981C77; Sat, 18 Apr 2020 21:33:13 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=wdc.com 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=wdc.com header.i=@wdc.com header.b="JI5MIh7p"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 40A1F81C78; Sat, 18 Apr 2020 21:33:07 +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,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) (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 BCFAB81C51 for ; Sat, 18 Apr 2020 21:33:00 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=wdc.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=prvs=370d05252=atish.patra@wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1587238380; x=1618774380; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Kuk7gYxNo+UDb64Xin7JQNQQTK5FJgDzOdCv/7o68i8=; b=JI5MIh7pCKrNF8uNX30QXgv3rgkzadNp7MhDzSiZvEkAiapd6A68at2k CAebUy4KTJk839kztyLqnoT8knvGpRLiaY3hY/SnHpLUAZ8fcRJn/g19C D7Cg//KKhweITcbehBjswxMwKQ7oGFG8OcKzxPBFbEwp7t8QO7Ae0R3hu QbMAt/WoknzKdj0vzmbqzrXI3axxTFW/6L2CngzW01wFaBEk2PDt1vCn2 NwUGSrDI/tEFk/nLz1yGS47JIE9tIBmjJBCOyCAPUayKGkhJI8zzJpIko HbLK9ttrrwrmfbIK4pPTYJEIHqdOvNZNKvOGxRM+YfYAS6VtXgG/8iaUJ Q==; IronPort-SDR: sPdEj2P02vUs83gXA5+3PsPnOWZ1ZH/aGxUuwV/RyFGFY+fvWz98wx2SQ1zuicpZuAzfdDqZBn 2N/6g1evZKVVvEyqnHb/McUNQ0q5o/TZcrRJBAEzer/S1iGWyp+Bid1WuiiDHv84C31KfeAgS3 b2iQH2nLesUVgDxx8F6soDvrcyU4s/jLGrmNcSE29edPY44VTdDveSFnDsBy/oX/leFzjaKs13 /3u0B5RCFY88wcr+BsK9oam7WFHBl6h32N/5lYV3EJHz2ZZvj3rlxt1iiHUhgY93Y+WK9Xql8b kUU= X-IronPort-AV: E=Sophos;i="5.72,400,1580745600"; d="scan'208";a="244312814" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Apr 2020 03:32:41 +0800 IronPort-SDR: 6EsIdYj35Ubrqnwj/3iOrUszID8+2efOGf8XWL56im2cPcCDEpjT9EQTPF9KHlJ+kSLM+CD/xF VZqgkG5sEW2PbZqvkhlvjaQWIaP8m27Eg= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Apr 2020 12:23:38 -0700 IronPort-SDR: jF228DW4bKfN6R1EIQbdUhgNRHOvNEFBFaNANPZPDZfDKtNJSui6fdvp2ZZkksevEZcCKN4NkP 9qGej0qWFBXQ== WDCIronportException: Internal Received: from cnf007834.ad.shared (HELO yoda.hgst.com) ([10.86.56.8]) by uls-op-cesaip01.wdc.com with ESMTP; 18 Apr 2020 12:32:41 -0700 From: Atish Patra To: u-boot@lists.denx.de Cc: Atish Patra , Bin Meng , Anup Patel , Lukas Auer , Heinrich Schuchardt , agraf@csgraf.de, ard.biesheuvel@linaro.org, Marcus Comstedt , Paul Walmsley , Rick Chen , palmer@dabbelt.com Subject: [PATCH v6 2/6] fdtdec: Fix boundary check Date: Sat, 18 Apr 2020 12:32:24 -0700 Message-Id: <20200418193228.44209-3-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200418193228.44209-1-atish.patra@wdc.com> References: <20200418193228.44209-1-atish.patra@wdc.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.2 at phobos.denx.de X-Virus-Status: Clean In U-Boot, the reserved memory end address is considered as a inclusive address. This notion is followed while adding a reserved memory node to the DT. For example: end_address = start_address + size - 1 Follow the same notion and fix the end address computation while checking for existing nodes. Signed-off-by: Atish Patra Reviewed-by: Bin Meng Tested-by: Bin Meng --- lib/fdtdec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/fdtdec.c b/lib/fdtdec.c index eb11fc898e30..07ba9f5c97e9 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -1311,7 +1311,8 @@ int fdtdec_add_reserved_memory(void *blob, const char *basename, continue; } - if (addr == carveout->start && (addr + size) == carveout->end) { + if (addr == carveout->start && (addr + size - 1) == + carveout->end) { if (phandlep) *phandlep = fdt_get_phandle(blob, node); return 0; From patchwork Sat Apr 18 19:32:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1272710 X-Patchwork-Delegate: uboot@andestech.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=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=PFGB0pJv; 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 RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 494NSn1Mr7z9sRN for ; Sun, 19 Apr 2020 05:34:33 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1CD8281C91; Sat, 18 Apr 2020 21:33:51 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=wdc.com 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=wdc.com header.i=@wdc.com header.b="PFGB0pJv"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 233DF81C78; Sat, 18 Apr 2020 21:33:17 +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,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) (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 4443681C6B for ; Sat, 18 Apr 2020 21:33:04 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=wdc.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=prvs=370d05252=atish.patra@wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1587238384; x=1618774384; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dk8YREZ+nHTUaDfKpIHc4F/HHsJpRHmg1POS+1pmU+Y=; b=PFGB0pJvoK7T4yRndYsGShk9+5bf0vaIQLEpkqiKvta3dClhwzuLSBh+ SqxjtwJ7+0AXlYAQ32Ya9TqnAMs2MN2sn0BEygomx2fflea6j6FDgaEt9 lfVQWegNCB+XMXmAbnp5HTHH+Yx2puM4rlkO2jqvrJl79SXGZUvi7OYfe xNE+wWOgQjP+XVfkuxnDuE67MIDT/rv5GSX85GBIOrfQfWATu7D5dC6sY RnXp28U1btrMp38sQWAkSMfmIrmv/iHvk3kOftN2UUXuljDScKh0yd8ml G/dJFR7HlAokd2jdRFczb8q/rb6k0xx069j0l/+EU8VXJt3BSwToq5Ncb Q==; IronPort-SDR: GcIuFjrDDmBoBt2bGZzRIen88cz4JQnHoP0PQZ6mBZHka9FMtslE0jTmhV/+5GoGvFKmvk8Iw6 M6cA6n09Oro1fD8Huptr/uQZt8EPJA/7BqsuW9eYX+RaspDncuCZ23UX86kqFqTG6vV2BVQv9k Q9z+fxTIcscgcXkP6q1G6/AjPrq7a2kUj+FOyszhgRhZBg37mWfLgw8OoktJ9ubqgrzcLpudl7 Tl/fzQE/DzbINm9ANiH9YxXf1178ZeuWjvWDYzPUgvmlpeH0L7GFVrpeJcQCIagh7rSevmtiLe SxU= X-IronPort-AV: E=Sophos;i="5.72,400,1580745600"; d="scan'208";a="244312815" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Apr 2020 03:32:42 +0800 IronPort-SDR: xDxaFVWuAjuI1PlTmBAjY7sHAaLJF7Ng13GK9VlYW/VLnAGfvO7ZcBScP6vT1wrC6ih0XVR/0Y uU2jGTKdKMkvTpIq6gdHvMDuYYaIZB+5o= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Apr 2020 12:23:39 -0700 IronPort-SDR: WObGmuebhK9nLi22sMtkz1nvxVneL+sDHunW8pUr4sJaVlZzkp1wqM2KQl9RIeU2W8qRMRoj9d iGc42A1O0CBw== WDCIronportException: Internal Received: from cnf007834.ad.shared (HELO yoda.hgst.com) ([10.86.56.8]) by uls-op-cesaip01.wdc.com with ESMTP; 18 Apr 2020 12:32:42 -0700 From: Atish Patra To: u-boot@lists.denx.de Cc: Atish Patra , Bin Meng , Anup Patel , Lukas Auer , Heinrich Schuchardt , agraf@csgraf.de, ard.biesheuvel@linaro.org, Marcus Comstedt , Paul Walmsley , Rick Chen , palmer@dabbelt.com Subject: [PATCH v6 3/6] riscv: Provide a mechanism to fix DT for reserved memory Date: Sat, 18 Apr 2020 12:32:25 -0700 Message-Id: <20200418193228.44209-4-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200418193228.44209-1-atish.patra@wdc.com> References: <20200418193228.44209-1-atish.patra@wdc.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.2 at phobos.denx.de X-Virus-Status: Clean In RISC-V, M-mode software can reserve physical memory regions by setting appropriate physical memory protection (PMP) csr. As the PMP csr are accessible only in M-mode, S-mode U-Boot can not read this configuration directly. However, M-mode software can pass this information via reserved-memory node in device tree so that S-mode software can access this information. This patch provides a framework to copy to the reserved-memory node from one DT to another. This will be used to update the DT used by U-Boot and the DT passed to the next stage OS. Signed-off-by: Atish Patra Reviewed-by: Bin Meng Tested-by: Bin Meng --- arch/riscv/cpu/start.S | 1 + arch/riscv/include/asm/global_data.h | 1 + arch/riscv/include/asm/u-boot-riscv.h | 2 + arch/riscv/lib/Makefile | 1 + arch/riscv/lib/asm-offsets.c | 1 + arch/riscv/lib/fdt_fixup.c | 102 ++++++++++++++++++++++++++ 6 files changed, 108 insertions(+) create mode 100644 arch/riscv/lib/fdt_fixup.c diff --git a/arch/riscv/cpu/start.S b/arch/riscv/cpu/start.S index 6b3ff99c3882..0282685c2906 100644 --- a/arch/riscv/cpu/start.S +++ b/arch/riscv/cpu/start.S @@ -121,6 +121,7 @@ call_board_init_f_0: jal board_init_f_init_reserve + SREG s1, GD_FIRMWARE_FDT_ADDR(gp) /* save the boot hart id to global_data */ SREG tp, GD_BOOT_HART(gp) diff --git a/arch/riscv/include/asm/global_data.h b/arch/riscv/include/asm/global_data.h index b74bd7e738bb..51ac8d1c98e2 100644 --- a/arch/riscv/include/asm/global_data.h +++ b/arch/riscv/include/asm/global_data.h @@ -15,6 +15,7 @@ /* Architecture-specific global data */ struct arch_global_data { long boot_hart; /* boot hart id */ + phys_addr_t firmware_fdt_addr; #ifdef CONFIG_SIFIVE_CLINT void __iomem *clint; /* clint base address */ #endif diff --git a/arch/riscv/include/asm/u-boot-riscv.h b/arch/riscv/include/asm/u-boot-riscv.h index 49febd588102..543a1688db8f 100644 --- a/arch/riscv/include/asm/u-boot-riscv.h +++ b/arch/riscv/include/asm/u-boot-riscv.h @@ -17,5 +17,7 @@ int cleanup_before_linux(void); /* board/.../... */ int board_init(void); void board_quiesce_devices(void); +int riscv_board_reserved_mem_fixup(void *fdt); +int riscv_fdt_copy_resv_mem_node(const void *src_fdt, void *dest_fdt); #endif /* _U_BOOT_RISCV_H_ */ diff --git a/arch/riscv/lib/Makefile b/arch/riscv/lib/Makefile index adadbf4bcbef..d132b59ce32c 100644 --- a/arch/riscv/lib/Makefile +++ b/arch/riscv/lib/Makefile @@ -24,6 +24,7 @@ obj-y += reset.o obj-y += setjmp.o obj-$(CONFIG_SMP) += smp.o obj-$(CONFIG_SPL_BUILD) += spl.o +obj-y += fdt_fixup.o # For building EFI apps CFLAGS_$(EFI_CRT0) := $(CFLAGS_EFI) diff --git a/arch/riscv/lib/asm-offsets.c b/arch/riscv/lib/asm-offsets.c index 4fa4fd371473..7301c1b98e23 100644 --- a/arch/riscv/lib/asm-offsets.c +++ b/arch/riscv/lib/asm-offsets.c @@ -14,6 +14,7 @@ int main(void) { DEFINE(GD_BOOT_HART, offsetof(gd_t, arch.boot_hart)); + DEFINE(GD_FIRMWARE_FDT_ADDR, offsetof(gd_t, arch.firmware_fdt_addr)); #ifndef CONFIG_XIP DEFINE(GD_AVAILABLE_HARTS, offsetof(gd_t, arch.available_harts)); #endif diff --git a/arch/riscv/lib/fdt_fixup.c b/arch/riscv/lib/fdt_fixup.c new file mode 100644 index 000000000000..1fce41490973 --- /dev/null +++ b/arch/riscv/lib/fdt_fixup.c @@ -0,0 +1,102 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2020 Western Digital Corporation or its affiliates + * + */ + +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +/** + * riscv_fdt_copy_resv_mem_node() - Copy reserve memory node entry + * @src: Pointer to the source device tree from which reserved memory node + * needs to be copied. + * @dst: Pointer to the destination device tree to which reserved memory node + * needs to be copied. + * + * Return: 0 on success or if source doesn't have reserved memory node. + * Error if copy process failed. + */ +int riscv_fdt_copy_resv_mem_node(const void *src, void *dst) +{ + u32 phandle; + struct fdt_memory pmp_mem; + fdt_addr_t addr; + fdt_size_t size; + int offset, node, err, rmem_offset; + bool nomap = true; + char basename[32] = {0}; + int bname_len; + int max_len = sizeof(basename); + const char *name; + char *temp; + + offset = fdt_path_offset(src, "/reserved-memory"); + if (offset < 0) { + printf("No reserved memory region found in source FDT\n"); + return 0; + } + + fdt_for_each_subnode(node, src, offset) { + name = fdt_get_name(src, node, NULL); + + addr = fdtdec_get_addr_size_auto_noparent(src, node, + "reg", 0, &size, + false); + if (addr == FDT_ADDR_T_NONE) { + debug("failed to read address/size for %s\n", name); + continue; + } + strncpy(basename, name, max_len); + temp = strchr(basename, '@'); + if (temp) { + bname_len = strnlen(basename, max_len) - strnlen(temp, + max_len); + *(basename + bname_len) = '\0'; + } + pmp_mem.start = addr; + pmp_mem.end = addr + size - 1; + err = fdtdec_add_reserved_memory(dst, basename, &pmp_mem, + &phandle); + if (err < 0) { + printf("failed to add reserved memory: %d\n", err); + return err; + } + if (!fdt_getprop(src, node, "no-map", NULL)) + nomap = false; + if (nomap) { + rmem_offset = fdt_node_offset_by_phandle(dst, phandle); + fdt_setprop_empty(dst, rmem_offset, "no-map"); + } + } + + return 0; +} + +/** + * riscv_board_reserved_mem_fixup() - Fix up reserved memory node for a board + * @fdt: Pointer to the device tree in which reserved memory node needs to be + * added. + * + * In RISC-V, any board compiled with OF_SEPARATE needs to copy the reserved + * memory node from the device tree provided by the firmware to the device tree + * used by U-Boot. This is a common function that individual board fixup + * functions can invoke. + * + * Return: 0 on success or error otherwise. + */ +int riscv_board_reserved_mem_fixup(void *fdt) +{ + int err; + void *src_fdt_addr; + + src_fdt_addr = map_sysmem(gd->arch.firmware_fdt_addr, 0); + err = riscv_fdt_copy_resv_mem_node(src_fdt_addr, fdt); + if (err < 0) + return err; + + return 0; +} From patchwork Sat Apr 18 19:32:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1272708 X-Patchwork-Delegate: uboot@andestech.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; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=pRxzCdmA; 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 494NSL0Rw3z9sRN for ; Sun, 19 Apr 2020 05:34:09 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 74F7881C81; Sat, 18 Apr 2020 21:33:42 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=wdc.com 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=wdc.com header.i=@wdc.com header.b="pRxzCdmA"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 22A2981C7C; Sat, 18 Apr 2020 21:33:15 +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,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) (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 4E8CE81C71 for ; Sat, 18 Apr 2020 21:33:05 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=wdc.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=prvs=370d05252=atish.patra@wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1587238385; x=1618774385; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=INqDrVuwYship83XFDgO24F1ldKXKcjB20L27Sgxaz4=; b=pRxzCdmAzfxzg14GvZE1wUMRLlbxO3VpWvNgCoSfpntW5ImeMmh9bgeW FrcwZ8JNWRwSclSpaXqgqaRS926+6CDF18NKeIhpUszBgLdU9Qn+T+KJR Yp+1IY0+T2PWXjFztAkE+l5CJkr4Kdyj5genVihf+YfgPokv2mGHFIPFe J/8bm2bqkrCV8wYkrUPmtKcSI0gFE8Uf3ZtCGFKSHBE3wTatAKm/NTAVQ pxjkX3DuvKc46ah7GsfFII0m8I9cZsVu6h1dDQeK6xySktUyWcHpsgnjO q4ZHTRFTggKLKiO39TBYzkYkm5CfF+T6njSVxUedI9zDk0P8tFH7or3MS Q==; IronPort-SDR: uUUnhURLu0WElDZzWsdCKREepy/8qzNwdxMaAixNvxLkUTR2PeqOmRR2ktTuZYJfAq3OB+ufQF X3cteTMbhyOj+78S5ayNnYTT5X0zgDeMa4VAPdyJ8GweXojVK2+bO/GROkv4cXg1mm+HU0WWiF 0IBiTXmAnodeznP3OOAKpf0QW1XGzhXHENF6TOOv+04k+OOrOiFysBm2DCVZhDizM3vI6u6CbA 1UYhzhe2sBL8Bos5kBS4UdBm1GCz75jVdhJObhYNTsnoAxZNMv0ER9sld+xzseNLmfJdMlpwqR K7M= X-IronPort-AV: E=Sophos;i="5.72,400,1580745600"; d="scan'208";a="244312817" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Apr 2020 03:32:42 +0800 IronPort-SDR: eEx9rDOFkhEB5D0fykpRa1DXB07Igi003Pl/3qm4VFuIM85XySTDJVtalw3qshRWF1S4LqeCZw BMMxSMegKrZ3dexxc7LDjPLow+ascyL0k= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Apr 2020 12:23:39 -0700 IronPort-SDR: Y2MJPaLCpVWoW49tcFrta6tvaEk2+84bw48onUSQDYC1T8i6Xo3kG2Z+3fJrwdFyGmiSuzjzL9 QeVQqliKzmAg== WDCIronportException: Internal Received: from cnf007834.ad.shared (HELO yoda.hgst.com) ([10.86.56.8]) by uls-op-cesaip01.wdc.com with ESMTP; 18 Apr 2020 12:32:42 -0700 From: Atish Patra To: u-boot@lists.denx.de Cc: Atish Patra , Bin Meng , Anup Patel , Lukas Auer , Heinrich Schuchardt , agraf@csgraf.de, ard.biesheuvel@linaro.org, Marcus Comstedt , Paul Walmsley , Rick Chen , palmer@dabbelt.com Subject: [PATCH v6 4/6] riscv: Setup reserved-memory node for FU540 Date: Sat, 18 Apr 2020 12:32:26 -0700 Message-Id: <20200418193228.44209-5-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200418193228.44209-1-atish.patra@wdc.com> References: <20200418193228.44209-1-atish.patra@wdc.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.2 at phobos.denx.de X-Virus-Status: Clean FU540 uses OF_SEPARATE instead of OF_PRIOR_STAGE. Enable OF_BOARD_FIXUP to update the DT with reserved-memory node. Signed-off-by: Atish Patra Reviewed-by: Bin Meng Tested-by: Bin Meng --- arch/riscv/lib/fdt_fixup.c | 15 +++++++++++++++ configs/sifive_fu540_defconfig | 1 + 2 files changed, 16 insertions(+) diff --git a/arch/riscv/lib/fdt_fixup.c b/arch/riscv/lib/fdt_fixup.c index 1fce41490973..af12e484db9b 100644 --- a/arch/riscv/lib/fdt_fixup.c +++ b/arch/riscv/lib/fdt_fixup.c @@ -100,3 +100,18 @@ int riscv_board_reserved_mem_fixup(void *fdt) return 0; } + +#ifdef CONFIG_OF_BOARD_FIXUP +int board_fix_fdt(void *fdt) +{ + int err; + + err = riscv_board_reserved_mem_fixup(fdt); + if (err < 0) { + printf("failed to fixup DT for reserved memory: %d\n", err); + return err; + } + + return 0; +} +#endif diff --git a/configs/sifive_fu540_defconfig b/configs/sifive_fu540_defconfig index 6d61e6c960ee..f805aacc7afd 100644 --- a/configs/sifive_fu540_defconfig +++ b/configs/sifive_fu540_defconfig @@ -9,6 +9,7 @@ CONFIG_FIT=y CONFIG_MISC_INIT_R=y CONFIG_DISPLAY_CPUINFO=y CONFIG_DISPLAY_BOARDINFO=y +CONFIG_OF_BOARD_FIXUP=y CONFIG_DEFAULT_DEVICE_TREE="hifive-unleashed-a00" CONFIG_SYS_RELOC_GD_ENV_ADDR=y CONFIG_DM_MTD=y From patchwork Sat Apr 18 19:32:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1272711 X-Patchwork-Delegate: uboot@andestech.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=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=XcCpmZ57; 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 RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 494NT06vmwz9sP7 for ; Sun, 19 Apr 2020 05:34:44 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7457481C76; Sat, 18 Apr 2020 21:33:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=wdc.com 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=wdc.com header.i=@wdc.com header.b="XcCpmZ57"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5B68781C5E; Sat, 18 Apr 2020 21:33:17 +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,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) (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 5F05181C72 for ; Sat, 18 Apr 2020 21:33:05 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=wdc.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=prvs=370d05252=atish.patra@wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1587238385; x=1618774385; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=15wEaSM5+aJTlTiM9DMRllUUNc6sZN1168dhM8zY40U=; b=XcCpmZ57zZVcqYJnvIBrrY24HHejDJRi3lX3f9wVddRtX2IwmchdxVRx ThRZ4ks5IEEVcD4Q4830O12dFqvd0K0ziJx4jwWF7qsNAlNguRsQuzFlD LHSeEbSJwbDQgIX+Iorr75SJ50LB+G/yGTw20Zr6/oRn2RgNKWWYbzDgl 9EBJQSwjs1pEi5JrXqJ96+rGElfU2Y56nOLdEZ2yMh3KBWBG9frKzhJx1 0Y5GGNJO3GHd2+K9d1ao/BnNTerZMmC+oKiyrS6mUC6k8JplckuBPssuO b4DUs8Lx27RTBwk/JN8hjAeUiZMe+oXew3GYwVxJUkChEWBm44qO0FYxs g==; IronPort-SDR: rDquwtU1PYWO0l5zjlfvKuFZ4HHDcxFwWVq8oosBK49m2+1A//c0aI2TOukFU7bQWb57hMDhXN PQTP1RmrmMg27AQIIiTl5/1bkvYXfCmcorZZ0IoGRTy8s7Pm1OsKmVyfDRLA4ODWI4JUJiSueq SbDmgnae1OkDmW9WPCOD00i0XiCBFFZ5j1PQGXuPUMYESNOi+Ug1uJ2ZYAAcKD3Spxp+/Zg9X+ LKGkSZeWyqHT8IlRtFd32b/Ok92RKkbv9nMsBq+WxCMKiKm3OdtzYEpbqkzBlQIOC5mTUx+QHY MQA= X-IronPort-AV: E=Sophos;i="5.72,400,1580745600"; d="scan'208";a="244312818" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Apr 2020 03:32:43 +0800 IronPort-SDR: 6iZcBZq/vsJYbWM+GQwKKcnwEfMWHxmTfOj+/oZTQvOK+KfFWOo3QFCHVx2BcB3neqzQ8MJGcE 7I3CzGes7/qj7MlndvknCkaJecCJsn9uc= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Apr 2020 12:23:40 -0700 IronPort-SDR: SRbsH59gwtxJyw+0D85Qq548XdaEqPVdsEWUvfu6ibATRdHWHicikhsL/61BO0MYt67lqU042a oywOe7dQjOzw== WDCIronportException: Internal Received: from cnf007834.ad.shared (HELO yoda.hgst.com) ([10.86.56.8]) by uls-op-cesaip01.wdc.com with ESMTP; 18 Apr 2020 12:32:43 -0700 From: Atish Patra To: u-boot@lists.denx.de Cc: Atish Patra , Bin Meng , Anup Patel , Lukas Auer , Heinrich Schuchardt , agraf@csgraf.de, ard.biesheuvel@linaro.org, Marcus Comstedt , Paul Walmsley , Rick Chen , palmer@dabbelt.com Subject: [PATCH v6 5/6] riscv: Copy the reserved-memory nodes to final DT Date: Sat, 18 Apr 2020 12:32:27 -0700 Message-Id: <20200418193228.44209-6-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200418193228.44209-1-atish.patra@wdc.com> References: <20200418193228.44209-1-atish.patra@wdc.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.2 at phobos.denx.de X-Virus-Status: Clean The DT used by U-Boot may be different from the DT being passed to the OS if the DT is loaded from external media such as network or mmc. In that case, the reserved-memory node needs to be copied to the DT passed to the OS. Signed-off-by: Atish Patra Reviewed-by: Bin Meng Tested-by: Bin Meng --- arch/riscv/lib/bootm.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/riscv/lib/bootm.c b/arch/riscv/lib/bootm.c index 87cadad5016d..8ff8db6bf533 100644 --- a/arch/riscv/lib/bootm.c +++ b/arch/riscv/lib/bootm.c @@ -28,8 +28,8 @@ __weak void board_quiesce_devices(void) int arch_fixup_fdt(void *blob) { -#ifdef CONFIG_EFI_LOADER int err; +#ifdef CONFIG_EFI_LOADER u32 size; int chosen_offset; @@ -50,6 +50,12 @@ int arch_fixup_fdt(void *blob) /* Overwrite the boot-hartid as U-Boot is the last stage BL */ fdt_setprop_u32(blob, chosen_offset, "boot-hartid", gd->arch.boot_hart); #endif + + /* Copy the reserved-memory node to the DT used by OS */ + err = riscv_fdt_copy_resv_mem_node(gd->fdt_blob, blob); + if (err < 0) + return err; + return 0; } From patchwork Sat Apr 18 19:32:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1272709 X-Patchwork-Delegate: uboot@andestech.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; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=kpGfDba5; 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 494NSY53vMz9sSG for ; Sun, 19 Apr 2020 05:34:21 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 12CFF81C8B; Sat, 18 Apr 2020 21:33:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=wdc.com 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=wdc.com header.i=@wdc.com header.b="kpGfDba5"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B50E681C7F; Sat, 18 Apr 2020 21:33:16 +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,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) (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 4681081C74 for ; Sat, 18 Apr 2020 21:33:06 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=wdc.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=prvs=370d05252=atish.patra@wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1587238386; x=1618774386; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=z8CGjJF2UQihHs927Igkajd9xRVmjHuVwfs+ZEExYjM=; b=kpGfDba5UdVcr78qNmwfNR0GHD291O2hIq4qDurtFi/dLg54gPIgms7U cVN4gyp+S7BlUv/yEdAFIwGRXJ3HQlD4+ZgfKtOq9zZbnwS2D5AXRaoFI AM13h8TABgFhk6uuP97sG6z4B7N6wIrqCj+qlwvTk/mlSeUUWmwqckOIC E+9dwv/m4eedODygeVBiR6i+bWPt41rsXVOYFTvnx3zgXVfEXjf2TVjEW OFsPpvkKedYUHgaQ6k2dZH+BpNhSntYHzc8fEhvCm6HIbLCaii2Ur8RUn qF4ZZQoko+5KjTM3ku8iniR3yDhsRjBrBn/x6Gw3D51f5PcNqu8TYlVkQ Q==; IronPort-SDR: wuXbynL+tuAVDoZpbjDzbYppOLMWbgSt+ZIaf3jMGOui5wrzapHiHiYnKrNjLBxeZfuOFQjY6j 9/Zv4aj0IB3lPmcfDU3pIFSCqqT1baCmi9wN12veR/8Wqd/fGepZ8yrIlW7wtMt0sRIT6x6z3x KvocgyVG/rjeAzhOPqq+MKOAxQ9e8ynYyVBlNUrNFEiEw0nXh4LuqBKHgiX6Y8dqGJpYXdJ0/V LtZD7UWfOLCd3+Hg6Ww8SIhOfma85GzSvEIjUR7+G/EVK/wVqPfg/2a6UsP3iLNtWY3BhGQChV WAk= X-IronPort-AV: E=Sophos;i="5.72,400,1580745600"; d="scan'208";a="244312820" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Apr 2020 03:32:43 +0800 IronPort-SDR: hfv8AtZa8XFpqR/IQTiztMKrR6eG7fsMEEmm190iONA9ypSJVJNUQdQ9AWukr47GiYbt+GW1Fe Ovf3odjr4uyNdMJYES9kfEpvntNVx+7HI= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Apr 2020 12:23:40 -0700 IronPort-SDR: ZSzO2LQvIyVD9jiE4/PYDvPDp1bIX80/3riqFurpzjZZ2xUQxfVxrGJ+mBoxNHtfd0Rzzd+S24 nuZ55NzR0t7A== WDCIronportException: Internal Received: from cnf007834.ad.shared (HELO yoda.hgst.com) ([10.86.56.8]) by uls-op-cesaip01.wdc.com with ESMTP; 18 Apr 2020 12:32:44 -0700 From: Atish Patra To: u-boot@lists.denx.de Cc: Atish Patra , Bin Meng , Anup Patel , Lukas Auer , Heinrich Schuchardt , agraf@csgraf.de, ard.biesheuvel@linaro.org, Marcus Comstedt , Paul Walmsley , Rick Chen , palmer@dabbelt.com Subject: [PATCH v6 6/6] riscv: Move all fdt fixups together Date: Sat, 18 Apr 2020 12:32:28 -0700 Message-Id: <20200418193228.44209-7-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200418193228.44209-1-atish.patra@wdc.com> References: <20200418193228.44209-1-atish.patra@wdc.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.2 at phobos.denx.de X-Virus-Status: Clean Keep all the fdt fixups together for better code management. Signed-off-by: Atish Patra Reviewed-by: Bin Meng --- arch/riscv/lib/bootm.c | 33 --------------------------------- arch/riscv/lib/fdt_fixup.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/arch/riscv/lib/bootm.c b/arch/riscv/lib/bootm.c index 8ff8db6bf533..0d06095da11a 100644 --- a/arch/riscv/lib/bootm.c +++ b/arch/riscv/lib/bootm.c @@ -26,39 +26,6 @@ __weak void board_quiesce_devices(void) { } -int arch_fixup_fdt(void *blob) -{ - int err; -#ifdef CONFIG_EFI_LOADER - u32 size; - int chosen_offset; - - size = fdt_totalsize(blob); - err = fdt_open_into(blob, blob, size + 32); - if (err < 0) { - printf("Device Tree can't be expanded to accommodate new node"); - return err; - } - chosen_offset = fdt_path_offset(blob, "/chosen"); - if (chosen_offset < 0) { - err = fdt_add_subnode(blob, 0, "chosen"); - if (err < 0) { - printf("chosen node can not be added\n"); - return err; - } - } - /* Overwrite the boot-hartid as U-Boot is the last stage BL */ - fdt_setprop_u32(blob, chosen_offset, "boot-hartid", gd->arch.boot_hart); -#endif - - /* Copy the reserved-memory node to the DT used by OS */ - err = riscv_fdt_copy_resv_mem_node(gd->fdt_blob, blob); - if (err < 0) - return err; - - return 0; -} - /** * announce_and_cleanup() - Print message and prepare for kernel boot * diff --git a/arch/riscv/lib/fdt_fixup.c b/arch/riscv/lib/fdt_fixup.c index af12e484db9b..20e0759f135b 100644 --- a/arch/riscv/lib/fdt_fixup.c +++ b/arch/riscv/lib/fdt_fixup.c @@ -115,3 +115,36 @@ int board_fix_fdt(void *fdt) return 0; } #endif + +int arch_fixup_fdt(void *blob) +{ + int err; +#ifdef CONFIG_EFI_LOADER + u32 size; + int chosen_offset; + + size = fdt_totalsize(blob); + err = fdt_open_into(blob, blob, size + 32); + if (err < 0) { + printf("Device Tree can't be expanded to accommodate new node"); + return err; + } + chosen_offset = fdt_path_offset(blob, "/chosen"); + if (chosen_offset < 0) { + err = fdt_add_subnode(blob, 0, "chosen"); + if (err < 0) { + printf("chosen node can not be added\n"); + return err; + } + } + /* Overwrite the boot-hartid as U-Boot is the last stage BL */ + fdt_setprop_u32(blob, chosen_offset, "boot-hartid", gd->arch.boot_hart); +#endif + + /* Copy the reserved-memory node to the DT used by OS */ + err = riscv_fdt_copy_resv_mem_node(gd->fdt_blob, blob); + if (err < 0) + return err; + + return 0; +}