From patchwork Mon Jan 15 15:19:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1886730 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=M8jerHTn; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=126.com header.i=@126.com header.a=rsa-sha256 header.s=s110527 header.b=dWe50asM; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TDG6r1ZSYz23dX for ; Tue, 16 Jan 2024 02:20:35 +1100 (AEDT) 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=qMJU2yx0OXWll72K1q4Yu7hltiH6dXuk6IrLseia35c=; b=M8jerHTnZkWWf3 GaYs2z4+Id2NLCh5KxH/cvby9r+kusRFruF79w07lNJi0KTn96L6NupeRX2RU/dtgURuU11X4kPx2 6UhIPdyxVAgeAYDbR79wnphL6Z/b5428o0qi5TW92aOopcincLGUspyacYUlplKly7kiz+S0rgjeO lPTkrrinJaM7csO6blc1VPip0kDkP2JyVEnP9F5nhlV+s9erf9bLhU5PBqHMStvEUnURmvHtNZG+8 6BscPJPHzgkSP2UBY7+kAODJ2cIt1hsKeeyyzDATTIsA4M5Al87Uy7xbbwwxohgAj6yFnauCNle4M DiO4nQc2M0jNKVj49+MA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rPOl3-009NJ7-2a; Mon, 15 Jan 2024 15:20:13 +0000 Received: from m16.mail.126.com ([220.197.31.8]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rPOl1-009NHb-0q for opensbi@lists.infradead.org; Mon, 15 Jan 2024 15:20:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version; bh=D/zcO KiTSBMEbT97Dp0p0m92BcZbpWTGDfY7OMWKhPY=; b=dWe50asMCGiwV3SkXRWr/ yI/Nv70LY/yAXc664oNAZz0y87h5g+UakpTPdHxSmiGYW4cYeebuViD3olKegREx mhszR7dhZZzmon07HYBbdPyPD61Riy60EHWfar1211PBfvn1kGjf3j+4D8Vj03Qw CDxbMX/Lx1qOI2C0WDkNfk= Received: from T490.lan (unknown [112.83.182.118]) by gzga-smtp-mta-g1-3 (Coremail) with SMTP id _____wD3X9QcTaVlISS4AA--.61052S6; Mon, 15 Jan 2024 23:20:06 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W Subject: [PATCH v2 4/4] firmware: fw_base.S: Simplify relocate Date: Mon, 15 Jan 2024 23:19:20 +0800 Message-ID: <20240115151930.392299-5-wxjstz@126.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240115151930.392299-1-wxjstz@126.com> References: <20240115151930.392299-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wD3X9QcTaVlISS4AA--.61052S6 X-Coremail-Antispam: 1Uf129KBjvJXoWxJF45GF1DuF4DXw4DWFyUWrg_yoW5Xw1rpr 43Ca43KanIqa48XFy0k3WUGr45Xa1DXF9rW3y7KFWrAr1rZr15A3W8JryFy3sIq3y0qwsY qFy2kr13Cay2yFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0p_sjjkUUUUU= X-Originating-IP: [112.83.182.118] X-CM-SenderInfo: pz0m23b26rjloofrz/xtbBcwdmOmSQAhfi9QABsf X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240115_072011_679153_491F5681 X-CRM114-Status: UNSURE ( 7.99 ) 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: Regardless of whether the FW_PIC macro is defined or not, the starting address of load/link and the runtime offset are required. Regardless of whether it is boot hart or not, the runtime offset are re [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -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 [wxjstz[at]126.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 Regardless of whether the FW_PIC macro is defined or not, the starting address of load/link and the runtime offset are required. Regardless of whether it is boot hart or not, the runtime offset are required. so the code to obtain these values is moved forward. Signed-off-by: Xiang W --- firmware/fw_base.S | 41 +++++++++++------------------------------ 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/firmware/fw_base.S b/firmware/fw_base.S index 3d88704..18dd0c5 100644 --- a/firmware/fw_base.S +++ b/firmware/fw_base.S @@ -52,6 +52,12 @@ _start: call fw_boot_hart add a6, a0, zero MOV_3R a0, s0, a1, s1, a2, s2 + + lla t2, _fw_start /* load start */ + lla t0, _link_start + REG_L t0, 0(t0) /* link start */ + sub t6, t2, t0 /* runtime offset */ + li a7, -1 beq a6, a7, _try_lottery /* Jump to relocation wait loop if we are not boot hart */ @@ -63,17 +69,7 @@ _try_lottery: amoadd.w a6, a7, (a6) bnez a6, _wait_relocate_copy_done - /* Save load address */ - lla t0, _load_start - lla t1, _fw_start - REG_S t1, 0(t0) - #ifdef FW_PIC - /* relocate the global table content */ - lla t0, _link_start - REG_L t0, 0(t0) - /* t1 shall has the address of _fw_start */ - sub t2, t1, t0 lla t0, __rel_dyn_start lla t1, __rel_dyn_end beq t0, t1, _relocate_done @@ -83,8 +79,8 @@ _try_lottery: bne t5, t3, 3f REG_L t3, 0(t0) REG_L t5, (REGBYTES * 2)(t0) /* t5 <-- addend */ - add t5, t5, t2 - add t3, t3, t2 + add t5, t5, t6 + add t3, t3, t6 REG_S t5, 0(t3) /* store runtime address to the GOT entry */ 3: @@ -96,11 +92,7 @@ _wait_relocate_copy_done: #else /* Relocate if load address != link address */ _relocate: - lla t0, _link_start - REG_L t0, 0(t0) /* link start */ - lla t2, _fw_start /* load start */ beq t0, t2, _relocate_done - sub t6, t2, t0 /* runtime offset */ lla t3, _fw_reloc_end /* load end */ lla t4, _relocate_done sub t1, t3, t6 /* link end */ @@ -143,14 +135,10 @@ _relocate_copy_to_upper_loop: blt t0, t1, _relocate_copy_to_upper_loop jr t4 _wait_relocate_copy_done: - lla t0, _fw_start - lla t1, _link_start - REG_L t1, 0(t1) - beq t0, t1, _wait_for_boot_hart + beq t0, t2, _wait_for_boot_hart lla t2, _boot_status lla t3, _wait_for_boot_hart - sub t3, t3, t0 - add t3, t3, t1 + sub t3, t3, t6 1: /* waitting for relocate copy done (_boot_status == 1) */ li t4, BOOT_STATUS_RELOCATE_DONE @@ -170,12 +158,7 @@ _relocate_done: */ lla t0, _boot_status #ifndef FW_PIC - lla t1, _link_start - REG_L t1, 0(t1) - lla t2, _load_start - REG_L t2, 0(t2) - sub t0, t0, t1 - add t0, t0, t2 + add t0, t0, t6 #endif li t1, BOOT_STATUS_RELOCATE_DONE REG_S t1, 0(t0) @@ -499,8 +482,6 @@ _relocate_lottery: RISCV_PTR 0 _boot_status: RISCV_PTR 0 -_load_start: - RISCV_PTR _fw_start _link_start: RISCV_PTR FW_TEXT_START