From patchwork Sat Jul 10 14:28:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 1503476 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=O3dMQnJg; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=YslJW8uN; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 4GMXT2565fz9sRR for ; Sun, 11 Jul 2021 00:28:38 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=azSXX6oy2M3M7s1T+rMT6WLSLpXDSIo+xt8GIUIF7tA=; b=O3dMQnJg0jzqSa x7KowtcRMKZ/6bVWYkQQWoafy6iu6fAommihXOiNwp+wDZvxogz0cPOO/0ehVYAK21EKhENgxuX0I CzG1jiOL9hPL6pwaz8evlSPqqp5MAk2ffHfNThTltOyjK2oQ5hdb/cGneV8XcsKdCHidRkEUPSH2J aNpb66nobF1EZKIoKkUmBpZzYHdIZw7RBfIXJgjmwSKHiyo7EmK8zadQT5JC39SpbI8zQt6l7GV3z HMSjMan/5Wjbs/9s1SrY5TvG9JNaOFlhKxAT8AIAKKShNq80tasEN5gdw0y31ZQJ+FhNDf5y1/wZo ZLIjm1sMVAEmY/AHxvVg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m2Dy5-003kFG-NQ; Sat, 10 Jul 2021 14:28:33 +0000 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m2Dy3-003kEe-E5 for opensbi@lists.infradead.org; Sat, 10 Jul 2021 14:28:32 +0000 Received: by mail-pl1-x62d.google.com with SMTP id a14so6586537pls.4 for ; Sat, 10 Jul 2021 07:28:29 -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=S5nr5FMqk0FZzv+mlAEnS5/CU8Wdrvpj09OLr9Emz2k=; b=YslJW8uNsKfafVViG8zGLC1GUZNdDw6j9ruWoFVx+yFySriiu2drJpOrCYbJ941zkd V1AOjAJjCbUDMWmRv4giNturB+AkmDVlbCht4UmHdovPY5kxox5aZ9GqdBUGZVzU4lZE mGT24HF4wmAAXXttbY2H+21gm4/aEKc/OVAg0Ku1Iw8Wure2jXcnWgwuoEovYMeFDR7x KLaYQ63HxwgaaRBkSTuUcXEG3KfttAJwgR9rtpGc+7S1fpkYetmqq+1KnxADjL2xhfm2 wKlL9LACSzb5ksnw+w+G5dESQT7qaUKacOaVa42SHEUDg5wGaxwoV8hqRv8ceCLyez2n 9pQA== 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=S5nr5FMqk0FZzv+mlAEnS5/CU8Wdrvpj09OLr9Emz2k=; b=rqBBsAzdBrQMhRH5QgRkR4dqwuEzoq3jgiILzT3biGhlTa/ngjDJC/DXGE5v4pUBQZ mHSnQ/x/2V4YevjdXs+IoWaV1cc2LOwWU2zP8Yw7snvVX0jq5FTNSc0kbl/xv1zoObIP xVswAf3rpvnlDf7qW0vJ1YvWlIt5h3eu0PM13untP2TmbDqFfT0Yl56JOnYk2gd0WqTA Xau2aCw/y2KLopVbhN+ne6IZdQmiTkFNNlcLryagVF7PDDfudIhd0vHhSifHHx81vS6j 4sMcUlyTlmv1B/ztr3fvr5aIeumxmgiXsDsxdGeaQnFH0HHtavII1I8dgqw9o8DnPFnK eOow== X-Gm-Message-State: AOAM530+AUpRlxW+DelO6ZXbJWMkr/vuFyWcOdrMtdg3OnZF6BGFKRnc 0DuteDh5rEwRFuRaWDUkqZE= X-Google-Smtp-Source: ABdhPJzH9zfd/1ooGPwr1lKvlKfeGA9ryTDGyfmY0eg+h78RfGkFDg0VxxsWgVO+YyeJHjheugHMWQ== X-Received: by 2002:a17:90a:de8b:: with SMTP id n11mr43718640pjv.11.1625927308660; Sat, 10 Jul 2021 07:28:28 -0700 (PDT) Received: from i9-aorus-gtx1080.localdomain (144.168.56.201.16clouds.com. [144.168.56.201]) by smtp.gmail.com with ESMTPSA id 31sm11066734pgu.17.2021.07.10.07.28.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jul 2021 07:28:28 -0700 (PDT) From: Bin Meng To: Anup Patel , opensbi@lists.infradead.org Cc: Bin Meng Subject: [PATCH 1/2] firmware: Remove the unhelpful alignment codes before fdt relocation Date: Sat, 10 Jul 2021 22:28:20 +0800 Message-Id: <20210710142821.4168-1-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210710_072831_538266_638C4796 X-CRM114-Status: UNSURE ( 9.75 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: If the device tree is at an address that is not __SIZEOF_POINTER__ aligned, the fdt relocation code tries to align both source and destination address to __SIZEOF_POINTER__ before the memory copy. But [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:62d listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [bmeng.cn[at]gmail.com] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org If the device tree is at an address that is not __SIZEOF_POINTER__ aligned, the fdt relocation code tries to align both source and destination address to __SIZEOF_POINTER__ before the memory copy. But such alignment can lead to unexpected results if either source or destination address is not aligned. In fact libfdt requires that the device tree must be at an 8-byte aligned address. Hence remove the unhelpful alignment codes. Signed-off-by: Bin Meng Reviewed-by: Anup Patel --- firmware/fw_base.S | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/firmware/fw_base.S b/firmware/fw_base.S index 8e40562..abf21cd 100644 --- a/firmware/fw_base.S +++ b/firmware/fw_base.S @@ -349,8 +349,7 @@ _scratch_init: * previous booting stage. */ beqz a1, _fdt_reloc_done - /* Mask values in a3 and a4 */ - li a3, ~(__SIZEOF_POINTER__ - 1) + /* Mask values in a4 */ li a4, 0xff /* t1 = destination FDT start address */ MOV_3R s0, a0, s1, a1, s2, a2 @@ -359,10 +358,8 @@ _scratch_init: MOV_3R a0, s0, a1, s1, a2, s2 beqz t1, _fdt_reloc_done beq t1, a1, _fdt_reloc_done - and t1, t1, a3 /* t0 = source FDT start address */ add t0, a1, zero - and t0, t0, a3 /* t2 = source FDT size in big-endian */ #if __riscv_xlen == 64 lwu t2, 4(t0) From patchwork Sat Jul 10 14:28:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 1503477 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=M+uRQlZU; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=MgPUbRty; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 4GMXT33Skxz9sSs for ; Sun, 11 Jul 2021 00:28:39 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=3P5O/iWxgYaNMgrhsBJ5fK76WWUhmc0Ki74HgiUc258=; b=M+uRQlZUFYaXSt JA1lbYeTK5wVGmKBmDov05z9qjbKrbwM+llg8R4Rnuo+Ai9R2DebbCJDdzDPDy489yG6hO9ZUHKHu bxFCNPH4HPChIqJ9mklUQm/v1rC+zfbZjImLgh1rP34I9NVTIdEOFNWlWO0VH8AUbPjQLl6XuEW0l fF/Fqef3jmYI6grdHF+beKpp/lv3sOaR0bEgzrtnek7FdpLZnMauAfjX8C5ftefJFuorSjhMx14TQ hW5oDML5icQzmhuL2+sBWuAcRP+J12p1fb6kN4KC3hR9zUTFf8OJ8RK8ewqnhn7hpZ0DdIFusLjgq ipqiJATFKrjot4KRq4rQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m2Dy6-003kFN-3N; Sat, 10 Jul 2021 14:28:34 +0000 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m2Dy3-003kEg-Ii for opensbi@lists.infradead.org; Sat, 10 Jul 2021 14:28:32 +0000 Received: by mail-pj1-x102b.google.com with SMTP id i16-20020a17090acf90b02901736d9d2218so2732376pju.1 for ; Sat, 10 Jul 2021 07:28:30 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=Z5g81e0EIVqmR7XnZR3veBy/eNJhT8Jpo7GLNzVm7hw=; b=MgPUbRtyBIIZTMoLq3ymhCDKA+y3Y0vls0VMoX3I4sv+POgW5Yx+Z+jFgzaZzVxsHM QIfb9vczjVJuNn4CRhVXjx/l4MNVrB+6Yv2QPitvtPQqmn3+r4WocvxKuiUrNzd9HtEj /BrznhyiGBT1DsnH3Pl+RgE808nIe3PmY3s7HQ2mfqQlc+CE3gPhpq0r21RZ0LAigIgS KW9vZmiDV4pS0uma6CtfboPqqy4Vngufj1DMC43VWxxbJypQKbwikQlk37aHR5enfz/L 15T5YD9m6aVk7K7TKVz9QRhxJF+IfozWYTCZKpFKcKe0D+bNMveRUwRTmtvDVVVvnji2 ueLg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=Z5g81e0EIVqmR7XnZR3veBy/eNJhT8Jpo7GLNzVm7hw=; b=WcEVRAxOCOY8Z0fKqDbnOcj22TcCmuVa5esXEjBahX+3j21Zk0HUW8ViFAZnRQWQIL YRVQkYdgJbj2qBb80q+G4LqD1JmgOfsUURUC9N8GLqPKzlRAs9Ce6kKwaL0zLV9wvrD+ v4axzesNuka9huULgTDyw7HnXYcSMPRVTTU1FFr+SqIqbR8CtNE4jS01CQmCrpWoviM0 tG4PcQvEwK7EyYQ04KtIiqURfwesmJ2dIYBd4iLmIrBgzQOZdGdHUtJvOdM1Sf6w0+Sj VH+cKivzfN46SyOKb6OJ0ADZtSk7E3mu5vo0Q8yc+z2x/gF67ocicZypDTC0vWrb3RTd VuHw== X-Gm-Message-State: AOAM532yjpOqZx53SaCT7X74qOB+r/YwE6nYifgmtGi65uab/HefsGWE bEkEX94FSRD2q/B4z5Femsw= X-Google-Smtp-Source: ABdhPJwjKiSpA1CgRDOypOpXsc4mpvVB+E17o/ZCSv6EfLRycRxtBSjihqMNKh+dMHoVBnoV+07i/w== X-Received: by 2002:a17:90a:bd06:: with SMTP id y6mr44008653pjr.6.1625927310424; Sat, 10 Jul 2021 07:28:30 -0700 (PDT) Received: from i9-aorus-gtx1080.localdomain (144.168.56.201.16clouds.com. [144.168.56.201]) by smtp.gmail.com with ESMTPSA id 31sm11066734pgu.17.2021.07.10.07.28.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jul 2021 07:28:30 -0700 (PDT) From: Bin Meng To: Anup Patel , opensbi@lists.infradead.org Cc: Bin Meng Subject: [PATCH 2/2] docs: firmware: Document parameters passed to firmware and alignment requirement Date: Sat, 10 Jul 2021 22:28:21 +0800 Message-Id: <20210710142821.4168-2-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210710142821.4168-1-bmeng.cn@gmail.com> References: <20210710142821.4168-1-bmeng.cn@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210710_072831_659884_C8C664E2 X-CRM114-Status: GOOD ( 10.38 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: This updates documentation to describe parameters passed to firmware from previous booting stage, and corresponding address alignment requirement. This also fixes a typo in fw_dynamic.md (it's => its). Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:102b listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [bmeng.cn[at]gmail.com] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This updates documentation to describe parameters passed to firmware from previous booting stage, and corresponding address alignment requirement. This also fixes a typo in fw_dynamic.md (it's => its). Signed-off-by: Bin Meng Reviewed-by: Anup Patel --- docs/firmware/fw.md | 7 +++++++ docs/firmware/fw_dynamic.md | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/firmware/fw.md b/docs/firmware/fw.md index cc0cc9e..a3bb70c 100644 --- a/docs/firmware/fw.md +++ b/docs/firmware/fw.md @@ -9,6 +9,13 @@ OpenSBI generic library code. The supported firmwares type will differ in how the arguments passed by the platform early boot stage are handled, as well as how the boot stage following the firmware will be handled and executed. +The previous booting stage will pass information via the following registers +of RISC-V CPU: + +* hartid via *a0* register +* device tree blob address in memory via *a1* register. The address must be + aligned to 8 bytes. + OpenSBI currently supports three different types of firmwares. Firmware with Dynamic Information (*FW_DYNAMIC*) diff --git a/docs/firmware/fw_dynamic.md b/docs/firmware/fw_dynamic.md index 01f43f9..7b9b192 100644 --- a/docs/firmware/fw_dynamic.md +++ b/docs/firmware/fw_dynamic.md @@ -6,8 +6,9 @@ information about next booting stage (e.g. a bootloader or an OS) and runtime OpenSBI library options from previous booting stage. The previous booting stage will pass information to *FW_DYNAMIC* by creating -*struct fw_dynamic_info* in memory and passing it's address to *FW_DYNAMIC* -via *a2* register of RISC-V CPU. +*struct fw_dynamic_info* in memory and passing its address to *FW_DYNAMIC* +via *a2* register of RISC-V CPU. The address must be aligned to 8 bytes on +RV64 and 4 bytes on RV32. A *FW_DYNAMIC* firmware is particularly useful when the booting stage executed prior to OpenSBI firmware is capable of loading both the OpenSBI firmware and