From patchwork Tue Mar 12 08:24:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1910885 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=0UNf/n0e; 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=Xkdtp0da; 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 4Tv6FD5x26z1yWy for ; Tue, 12 Mar 2024 19:26:56 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=6gGmhq6+R1SPbeKQzWutZqTfLIxzjWlhZ9+UcZ+dDd8=; b=0UNf/n0eSDorrA LDhTqHsyHDaUMaVm+BUFWC1jTbxTF0zPxJlpR5cb81QY8OS3Cir3MTcFzqiJUYP3WSW5aHo+EiWWc LxViyxoUMMx7RTb6bkSF95ZKzyrw3VFhqXehUF9MOqgQPpZX2cEsZQgPtTbFjUYVrvEp90gsbNf0o moaIuWRZiiEnKLtW0kiVKl9cjuYJ6dZl25pX3sPi+AV3zvRkLeiy8ANFI/ZpXubKn1Ue4+B3LTyCv JhCeP8CKgL58nGKNAl1b0JDUvzC0jAgKOU4Jh/jpS/CRgyKeTpja41IxB9vkgua4ETQsKw2Bq6Zwu C9FLCNkLq267YXDmeCAQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rjxTD-00000004sZX-0Dlp; Tue, 12 Mar 2024 08:26:47 +0000 Received: from m16.mail.126.com ([220.197.31.9]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rjxT9-00000004sXn-45UF for opensbi@lists.infradead.org; Tue, 12 Mar 2024 08:26:46 +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=HMOiG 0aIjj7eNFp8iYQJeGhjCNi+9ywEol5o2quhwAE=; b=Xkdtp0daCCUbl8Jw3Ib+L FQUl12xPb+FICmYotw6vvN7rsSqXnhXSdhERr0EiGudInj3qguJoag8NjvMBgHVB XgS6kR+ijzdk2xPsbq20owLRWf6Bi6e8+3oDVVg9R3Y+qELyju3A5lZsKOLx5jGP PE2XErruGvFN7KMAJIHfw0= Received: from T490.lan (unknown [112.83.183.140]) by gzga-smtp-mta-g0-3 (Coremail) with SMTP id _____wD3X4uDEfBlPHKwAA--.22788S3; Tue, 12 Mar 2024 16:25:41 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Subject: [PATCH v3 1/2] firmware: remove copy-base relocation Date: Tue, 12 Mar 2024 16:24:59 +0800 Message-ID: <20240312082504.499847-2-wxjstz@126.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240312082504.499847-1-wxjstz@126.com> References: <20240312082504.499847-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wD3X4uDEfBlPHKwAA--.22788S3 X-Coremail-Antispam: 1Uf129KBjvJXoW3Wr1UZryrAw4rtr1fWFyUJrb_yoW3Ar15pa 1fG3W7tFs5Gw1rXr97u3W8ur4jgws8XrZrurW29FyrA34fZrn3Za48tFZ5Xa4kJ34xAw45 uFy2kr17Aay5AF7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRnmRbUUUUU= X-Originating-IP: [112.83.183.140] X-CM-SenderInfo: pz0m23b26rjloofrz/xtbBdQifOmSdL0nx+QABsO X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240312_012644_378905_EC96CA84 X-CRM114-Status: GOOD ( 14.66 ) 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: Remove copy-base relocations that are no longer needed. Signed-off-by: Xiang W Reviewed-by: Samuel Holland Tested-by: Samuel Holland --- Makefile | 8 +++- README.md | 3 +- docs/firmware/fw.md | 6 --- firmware/fw_base.S | 98 ++ [...] 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 [220.197.31.9 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.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 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 -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wxjstz(at)126.com] -0.0 T_SCC_BODY_TEXT_LINE No description available. 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: , Cc: Xiang W , jrtc27@jrtc27.com Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Remove copy-base relocations that are no longer needed. Signed-off-by: Xiang W Reviewed-by: Samuel Holland Tested-by: Samuel Holland Reviewed-by: Anup Patel --- Makefile | 8 +++- README.md | 3 +- docs/firmware/fw.md | 6 --- firmware/fw_base.S | 98 ++------------------------------------------- firmware/objects.mk | 11 ----- 5 files changed, 11 insertions(+), 115 deletions(-) diff --git a/Makefile b/Makefile index 680c19a..50f634e 100644 --- a/Makefile +++ b/Makefile @@ -179,6 +179,10 @@ CC_SUPPORT_STRICT_ALIGN := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib # Check whether the assembler and the compiler support the Zicsr and Zifencei extensions CC_SUPPORT_ZICSR_ZIFENCEI := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)imafd_zicsr_zifencei -x c /dev/null -o /dev/null 2>&1 | grep "zicsr\|zifencei" > /dev/null && echo n || echo y) +ifneq ($(OPENSBI_LD_PIE),y) +$(error Your linker does not support creating PIEs, opensbi requires this.) +endif + # Build Info: # OPENSBI_BUILD_TIME_STAMP -- the compilation time stamp # OPENSBI_BUILD_COMPILER_VERSION -- the compiler version info @@ -356,7 +360,7 @@ CFLAGS += -mcmodel=$(PLATFORM_RISCV_CODE_MODEL) CFLAGS += $(RELAX_FLAG) CFLAGS += $(GENFLAGS) CFLAGS += $(platform-cflags-y) -CFLAGS += -fno-pie -no-pie +CFLAGS += -fPIE -pie CFLAGS += $(firmware-cflags-y) CPPFLAGS += $(GENFLAGS) @@ -365,6 +369,7 @@ CPPFLAGS += $(firmware-cppflags-y) ASFLAGS = -g -Wall -nostdlib ASFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls +ASFLAGS += -fPIE # Optionally supported flags ifeq ($(CC_SUPPORT_SAVE_RESTORE),y) ASFLAGS += -mno-save-restore @@ -391,6 +396,7 @@ ifeq ($(OPENSBI_LD_EXCLUDE_LIBS),y) ELFFLAGS += -Wl,--exclude-libs,ALL endif ELFFLAGS += -Wl,--build-id=none +ELFFLAGS += -Wl,--no-dynamic-linker -Wl,-pie ELFFLAGS += $(platform-ldflags-y) ELFFLAGS += $(firmware-ldflags-y) diff --git a/README.md b/README.md index 73de8ea..cbae73a 100644 --- a/README.md +++ b/README.md @@ -276,8 +276,7 @@ document. NOTE: Using Clang with a `riscv*-linux-gnu` GNU binutils linker has been seen to produce broken binaries with missing relocations; it is therefore currently -recommended that this combination be avoided or *FW_PIC=n* be used to disable -building OpenSBI as a position-independent binary. +recommended that this combination be avoided. Building with timestamp and compiler info ----------------------------------------- diff --git a/docs/firmware/fw.md b/docs/firmware/fw.md index 38351c8..2f4deb5 100644 --- a/docs/firmware/fw.md +++ b/docs/firmware/fw.md @@ -69,12 +69,6 @@ parameters: argument by the prior booting stage. * **FW_FDT_PADDING** - Optional zero bytes padding to the embedded flattened device tree binary file specified by **FW_FDT_PATH** option. -* **FW_PIC** - "FW_PIC=y" generates position independent executable firmware - images. OpenSBI can run at arbitrary address with appropriate alignment. - Therefore, the original relocation mechanism ("FW_PIC=n") will be skipped. - In other words, OpenSBI will directly run at the load address without any - code movement. This option requires a toolchain with PIE support, and it - is on by default. Additionally, each firmware type as a set of type specific configuration parameters. Detailed information for each firmware type can be found in the diff --git a/firmware/fw_base.S b/firmware/fw_base.S index 126b067..6013db3 100644 --- a/firmware/fw_base.S +++ b/firmware/fw_base.S @@ -15,8 +15,7 @@ #include #define BOOT_STATUS_LOTTERY_DONE 1 -#define BOOT_STATUS_RELOCATE_DONE 2 -#define BOOT_STATUS_BOOT_HART_DONE 3 +#define BOOT_STATUS_BOOT_HART_DONE 2 .macro MOV_3R __d0, __s0, __d1, __s1, __d2, __s2 add \__d0, \__s0, zero @@ -32,17 +31,6 @@ add \__d4, \__s4, zero .endm -/* - * If __start_reg <= __check_reg and __check_reg < __end_reg then - * jump to __pass - */ -.macro BRANGE __start_reg, __end_reg, __check_reg, __jump_lable - blt \__check_reg, \__start_reg, 999f - bge \__check_reg, \__end_reg, 999f - j \__jump_lable -999: -.endm - .section .entry, "ax", %progbits .align 3 .globl _start @@ -56,15 +44,14 @@ _start: li a7, -1 beq a6, a7, _try_lottery /* Jump to relocation wait loop if we are not boot hart */ - bne a0, a6, _wait_relocate_copy_done + bne a0, a6, _wait_for_boot_hart _try_lottery: /* Jump to relocation wait loop if we don't get relocation lottery */ lla a6, _boot_status li a7, BOOT_STATUS_LOTTERY_DONE amoswap.w a6, a7, (a6) - bnez a6, _wait_relocate_copy_done + bnez a6, _wait_for_boot_hart -#ifdef FW_PIC /* relocate the global table content */ li t0, FW_TEXT_START /* link start */ lla t1, _fw_start /* load start */ @@ -85,86 +72,7 @@ _try_lottery: 3: addi t0, t0, (REGBYTES * 3) blt t0, t1, 2b - j _relocate_done -_wait_relocate_copy_done: - j _wait_for_boot_hart -#else - /* Relocate if load address != link address */ -_relocate: - li t0, FW_TEXT_START /* link start */ - lla t2, _fw_start /* load start */ - lla t3, _fw_reloc_end /* load end */ - sub t6, t2, t0 /* load offset */ - sub t1, t3, t6 /* link end */ - beq t0, t2, _relocate_done - lla t4, _relocate_done - sub t4, t4, t6 - blt t2, t0, _relocate_copy_to_upper -_relocate_copy_to_lower: - ble t1, t2, _relocate_copy_to_lower_loop - lla t3, _boot_status - BRANGE t2, t1, t3, _start_hang - lla t3, _relocate - lla t5, _relocate_done - BRANGE t2, t1, t3, _start_hang - BRANGE t2, t1, t5, _start_hang - BRANGE t3, t5, t2, _start_hang -_relocate_copy_to_lower_loop: - REG_L t3, 0(t2) - REG_S t3, 0(t0) - add t0, t0, __SIZEOF_POINTER__ - add t2, t2, __SIZEOF_POINTER__ - blt t0, t1, _relocate_copy_to_lower_loop - jr t4 -_relocate_copy_to_upper: - ble t3, t0, _relocate_copy_to_upper_loop - lla t2, _boot_status - BRANGE t0, t3, t2, _start_hang - lla t2, _relocate - lla t5, _relocate_done - BRANGE t0, t3, t2, _start_hang - BRANGE t0, t3, t5, _start_hang - BRANGE t2, t5, t0, _start_hang -_relocate_copy_to_upper_loop: - add t3, t3, -__SIZEOF_POINTER__ - add t1, t1, -__SIZEOF_POINTER__ - REG_L t2, 0(t3) - REG_S t2, 0(t1) - blt t0, t1, _relocate_copy_to_upper_loop - jr t4 -_wait_relocate_copy_done: - lla t0, _fw_start - li t1, FW_TEXT_START - beq t0, t1, _wait_for_boot_hart - lla t2, _boot_status - lla t3, _wait_for_boot_hart - sub t3, t3, t0 - add t3, t3, t1 -1: - /* waitting for relocate copy done (_boot_status == 1) */ - li t4, BOOT_STATUS_RELOCATE_DONE - REG_L t5, 0(t2) - /* Reduce the bus traffic so that boot hart may proceed faster */ - nop - nop - nop - bgt t4, t5, 1b - jr t3 -#endif _relocate_done: - - /* - * Mark relocate copy done - * Use _boot_status copy relative to the load address - */ - lla t0, _boot_status -#ifndef FW_PIC - add t0, t0, t6 -#endif - li t1, BOOT_STATUS_RELOCATE_DONE - REG_S t1, 0(t0) - fence rw, rw - /* At this point we are running from link address */ /* Reset all registers except ra, a0, a1, a2, a3 and a4 for boot HART */ diff --git a/firmware/objects.mk b/firmware/objects.mk index 3ae0a28..e6b364b 100644 --- a/firmware/objects.mk +++ b/firmware/objects.mk @@ -13,17 +13,6 @@ firmware-cflags-y += firmware-asflags-y += firmware-ldflags-y += -ifndef FW_PIC -FW_PIC := $(OPENSBI_LD_PIE) -endif - -ifeq ($(FW_PIC),y) -firmware-genflags-y += -DFW_PIC -firmware-asflags-y += -fpic -firmware-cflags-y += -fPIE -pie -firmware-ldflags-y += -Wl,--no-dynamic-linker -Wl,-pie -endif - ifdef FW_TEXT_START firmware-genflags-y += -DFW_TEXT_START=$(FW_TEXT_START) endif From patchwork Tue Mar 12 08:25:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1910886 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=oa7OSjCm; 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=GOH3wBgv; 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 4Tv6FF3TTcz23qn for ; Tue, 12 Mar 2024 19:26:57 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=6IJ/rRCRWC9WRIe1YwXpPy8mwaChRj30eCAAeT0GZ5c=; b=oa7OSjCmjrjKhE lcpa3OcWuNnGaRrU3WZ79kS6+UtCtMWT5tmDcNZkL552eHCmlbQRgFMBFvAaWQUUX3kF1Zv5PVGNr xbNrg9XkO1kgmxR8HHuenAXH4gMYW/CSk6nx9ZRI1VAnnjN9LhgGZFt4HbnBpmpG0+4j+FK6gTgMv 4rJnYb1640jsGRBdV3ZFoXarD3aOR72eNYNOp7aujnrK9TTzZ9SzuFGTYTJGWvAAhPvbJcu29Ghgk QZwFTxWlFPBDn4u0wLLaUVbsvY0cZCKisKBxB26xk8cK48BtMT0nhTnVbx2og464MoW21pPge4tZn s5cxe+nq4GWtMZ8Va0aQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rjxTD-00000004sZj-28Rw; Tue, 12 Mar 2024 08:26:47 +0000 Received: from m16.mail.126.com ([117.135.210.9]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rjxT9-00000004sXj-2lkP for opensbi@lists.infradead.org; Tue, 12 Mar 2024 08:26:46 +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=WYtoK cTGFMky4YYS9urFFP3h+VLioTYbi7EN9vm9h+E=; b=GOH3wBgvbNd6w6nps5vSK dEKoMkGDDRImB0WUSUTYQSUmd+hW7eWz91ETENNpIRV63JlWFMIjiYkQpjmcI2dl CxNXxX1XZu9GyQP0bjGodNe/bwVoiuKHxpvXDH7FAhMuQzlZhi1TM45EQ3gc1daP jlRK/WZgRtfAR3Y1xXzWmw= Received: from T490.lan (unknown [112.83.183.140]) by gzga-smtp-mta-g0-3 (Coremail) with SMTP id _____wD3X4uDEfBlPHKwAA--.22788S4; Tue, 12 Mar 2024 16:25:41 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Subject: [PATCH v3 2/2] firmware: remove fixed address Date: Tue, 12 Mar 2024 16:25:00 +0800 Message-ID: <20240312082504.499847-3-wxjstz@126.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240312082504.499847-1-wxjstz@126.com> References: <20240312082504.499847-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wD3X4uDEfBlPHKwAA--.22788S4 X-Coremail-Antispam: 1Uf129KBjvAXoW3ZrW8KF1UKr45Ar4DGw1Dtrb_yoW8AF45Co W7ur97Cr1xKr4UW397Krn7WFWxXa409a1xtr48JFy7uF17Xa4qkws0yF1q9w45AFnxCFn3 Wa43Gw18G3WIyF93n29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7v73VFW2AGmfu7bjvjm3 AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvjxU15l8UUUUU X-Originating-IP: [112.83.183.140] X-CM-SenderInfo: pz0m23b26rjloofrz/xtbBdQifOmSdL0nx+AAAsO X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240312_012644_214708_E59B97AF X-CRM114-Status: GOOD ( 23.24 ) 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: Now opensbi can run at any address via dynamic relocation. We can remove fixed addresses:FW_TEXT_START, FW_JUMP_ADDR, FW_JUMP_FDT_ADDR and FW_PAYLOAD_FDT_ADDR Signed-off-by: Xiang W --- docs/firmware/fw.md | 2 -- docs/firmware/fw_jump.md | 39 +++ docs/firmware/fw_payload.md | 20 +++++ docs/platform/generic.md | 11 +++- [...] 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.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 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 -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wxjstz(at)126.com] -0.0 T_SCC_BODY_TEXT_LINE No description available. 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: , Cc: Xiang W , jrtc27@jrtc27.com Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Now opensbi can run at any address via dynamic relocation. We can remove fixed addresses:FW_TEXT_START, FW_JUMP_ADDR, FW_JUMP_FDT_ADDR and FW_PAYLOAD_FDT_ADDR Signed-off-by: Xiang W --- docs/firmware/fw.md | 2 -- docs/firmware/fw_jump.md | 39 +++--------------------------- docs/firmware/fw_payload.md | 20 +++++---------- docs/platform/generic.md | 11 +++------ firmware/fw_base.S | 4 +-- firmware/fw_base.ldS | 3 +-- firmware/fw_jump.S | 20 +++------------ firmware/fw_payload.S | 4 +-- firmware/fw_payload.elf.ldS | 2 +- firmware/objects.mk | 13 ---------- firmware/payloads/test.elf.ldS | 2 +- platform/fpga/ariane/objects.mk | 9 +++---- platform/fpga/openpiton/objects.mk | 9 +++---- platform/generic/objects.mk | 3 +-- platform/kendryte/k210/objects.mk | 1 - platform/nuclei/ux600/objects.mk | 7 +++--- platform/template/objects.mk | 19 +-------------- 17 files changed, 35 insertions(+), 133 deletions(-) diff --git a/docs/firmware/fw.md b/docs/firmware/fw.md index 2f4deb5..3cc0262 100644 --- a/docs/firmware/fw.md +++ b/docs/firmware/fw.md @@ -61,8 +61,6 @@ Firmware Configuration and Compilation All firmware types support the following common compile time configuration parameters: -* **FW_TEXT_START** - Defines the execution address of the OpenSBI firmware. - This configuration parameter is mandatory. * **FW_FDT_PATH** - Path to an external flattened device tree binary file to be embedded in the *.rodata* section of the final firmware. If this option is not provided then the firmware will expect the FDT to be passed as an diff --git a/docs/firmware/fw_jump.md b/docs/firmware/fw_jump.md index 2ee6b29..c6a14fc 100644 --- a/docs/firmware/fw_jump.md +++ b/docs/firmware/fw_jump.md @@ -29,44 +29,13 @@ parameters to be defined using either the top level `make` command line or the target platform *objects.mk* configuration file. The possible parameters are as follows: -* **FW_JUMP_ADDR** - Address of the entry point of the booting stage to be - executed following OpenSBI firmware. This address generally corresponds - exactly to the address where this next booting stage was loaded. - At least one of *FW_JUMP_ADDR* and *FW_JUMP_OFFSET* (see below) should be - defined. Compilation errors will result from not defining one of them. - -* **FW_JUMP_OFFSET** - Address offset from the *FW_TEXT_START* where the +* **FW_JUMP_OFFSET** - Address offset from opensbi's load address where the entry point of the next booting stage is located. This offset is used as - relocatable address of the next booting stage entry point. If *FW_JUMP_ADDR* - is also defined, the firmware will prefer *FW_JUMP_ADDR*. - -* **FW_JUMP_FDT_ADDR** - Address where the *flattened device tree (FDT file)* - passed by the prior booting stage will be placed in memory before executing - the booting stage following the OpenSBI firmware. If this option is not - provided, then the OpenSBI firmware will pass the FDT address passed by the - previous booting stage to the next booting stage. - - When using the default *FW_JUMP_FDT_ADDR* with *PLATFORM=generic*, you must - ensure *FW_JUMP_FDT_ADDR* is set high enough to avoid overwriting the kernel. - You can use the following method (e.g., using bash or zsh): - - ``` - ${CROSS_COMPILE}objdump -h $KERNEL_ELF | sort -k 5,5 | awk -n ' - /^ +[0-9]+ / {addr="0x"$3; size="0x"$5; printf "0x""%x\n",addr+size}' | - (( `tail -1` > (FW_JUMP_FDT_ADDR - FW_JUMP_ADDR) )) && - echo fdt overlaps kernel, increase FW_JUMP_FDT_ADDR - - ${LLVM}objdump -h --show-lma $KERNEL_ELF | sort -k 5,5 | awk -n ' - /^ +[0-9]+ / {addr="0x"$3; size="0x"$5; printf "0x""%x\n",addr+size}' | - (( `tail -1` > (FW_JUMP_FDT_ADDR - FW_JUMP_ADDR) )) && - echo fdt overlaps kernel, increase FW_JUMP_FDT_ADDR - ``` + relocatable address of the next booting stage entry point. -* **FW_JUMP_FDT_OFFSET** - Address offset from the *FW_TEXT_START* where +* **FW_JUMP_FDT_OFFSET** - Address offset from opensbi's load address where the FDT will be passed to the next booting stage. This offset is used - as relocatable address of the FDT passed to the next booting stage. If - *FW_JUMP_FDT_ADDR* is also defined, the firmware will prefer - *FW_JUMP_FDT_ADDR*. + as relocatable address of the FDT passed to the next booting stage. *FW_JUMP* Example ----------------- diff --git a/docs/firmware/fw_payload.md b/docs/firmware/fw_payload.md index a67fc50..da69d1b 100644 --- a/docs/firmware/fw_payload.md +++ b/docs/firmware/fw_payload.md @@ -36,10 +36,10 @@ options. These configuration parameters can be defined using either the top level `make` command line or the target platform *objects.mk* configuration file. The parameters currently defined are as follows: -* **FW_PAYLOAD_OFFSET** - Offset from *FW_TEXT_START* where the payload binary - will be linked in the final *FW_PAYLOAD* firmware binary image. This - configuration parameter is mandatory if *FW_PAYLOAD_ALIGN* is not defined. - Compilation errors will result from an incorrect definition of +* **FW_PAYLOAD_OFFSET** - Address offset from opensbi's load address where + the payload binary will be linked in the final *FW_PAYLOAD* firmware binary + image. This configuration parameter is mandatory if *FW_PAYLOAD_ALIGN* is not + defined. Compilation errors will result from an incorrect definition of *FW_PAYLOAD_OFFSET* or of *FW_PAYLOAD_ALIGN*, or if neither of these parameters are defined. @@ -55,17 +55,9 @@ file. The parameters currently defined are as follows: automatically generated and used as a payload. This test payload executes an infinite `while (1)` loop after printing a message on the platform console. -* **FW_PAYLOAD_FDT_ADDR** - Address where the FDT passed by the prior booting - stage or specified by the *FW_FDT_PATH* parameter and embedded in the - *.rodata* section will be placed before executing the next booting stage, - that is, the payload firmware. If this option is not provided, then the - firmware will pass the FDT address passed by the previous booting stage - to the next booting stage. - -* **FW_PAYLOAD_FDT_OFFSET** - Address offset from the *FW_TEXT_START* where +* **FW_PAYLOAD_FDT_OFFSET** - Address offset from opensbi's load address where the FDT will be passed to the next booting stage. This offset is used as - relocatable address of the FDT passed to the next booting stage. If - *FW_PAYLOAD_FDT_ADDR* is also defined, the firmware will prefer *FW_PAYLOAD_FDT_ADDR*. + relocatable address of the FDT passed to the next booting stage. *FW_PAYLOAD* Example -------------------- diff --git a/docs/platform/generic.md b/docs/platform/generic.md index c29eb04..709b436 100644 --- a/docs/platform/generic.md +++ b/docs/platform/generic.md @@ -9,10 +9,9 @@ boards. By default, the generic FDT platform makes following assumptions: -1. platform FW_TEXT_START is 0x80000000 -2. platform features are default -3. platform stack size is default -4. platform has no quirks or work-arounds +1. platform features are default +2. platform stack size is default +3. platform has no quirks or work-arounds The above assumptions (except 1) can be overridden by adding special platform callbacks which will be called based on FDT root node compatible string. @@ -33,10 +32,6 @@ Users of the generic FDT platform will have to ensure that: To build the platform-specific library and firmware images, provide the *PLATFORM=generic* parameter to the top level `make` command. -For custom FW_TEXT_START, we can build the platform-specific library and -firmware images by passing *PLATFORM=generic FW_TEXT_START=* -parameter to the top level `make` command. - Platform Options ---------------- diff --git a/firmware/fw_base.S b/firmware/fw_base.S index 6013db3..16047ff 100644 --- a/firmware/fw_base.S +++ b/firmware/fw_base.S @@ -53,9 +53,7 @@ _try_lottery: bnez a6, _wait_for_boot_hart /* relocate the global table content */ - li t0, FW_TEXT_START /* link start */ - lla t1, _fw_start /* load start */ - sub t2, t1, t0 /* load offset */ + lla t2, _fw_start lla t0, __rel_dyn_start lla t1, __rel_dyn_end beq t0, t1, _relocate_done diff --git a/firmware/fw_base.ldS b/firmware/fw_base.ldS index fb47984..0abddd7 100644 --- a/firmware/fw_base.ldS +++ b/firmware/fw_base.ldS @@ -7,8 +7,7 @@ * Anup Patel */ - . = FW_TEXT_START; - /* Don't add any section between FW_TEXT_START and _fw_start */ + /* Don't add any section between before _fw_start */ PROVIDE(_fw_start = .); . = ALIGN(0x1000); /* Need this to create proper sections */ diff --git a/firmware/fw_jump.S b/firmware/fw_jump.S index ebf297f..873105f 100644 --- a/firmware/fw_jump.S +++ b/firmware/fw_jump.S @@ -44,9 +44,7 @@ fw_save_info: * The next arg1 should be returned in 'a0'. */ fw_next_arg1: -#ifdef FW_JUMP_FDT_ADDR - li a0, FW_JUMP_FDT_ADDR -#elif defined(FW_JUMP_FDT_OFFSET) +#if defined(FW_JUMP_FDT_OFFSET) lla a0, _fw_start li a1, FW_JUMP_FDT_OFFSET add a0, a0, a1 @@ -63,16 +61,12 @@ fw_next_arg1: * The next address should be returned in 'a0'. */ fw_next_addr: -#ifdef FW_JUMP_ADDR - lla a0, _jump_addr - REG_L a0, (a0) -#elif defined(FW_JUMP_OFFSET) +#if !defined(FW_JUMP_OFFSET) +#error "FW_JUMP_OFFSET must be defined" +#endif lla a0, _fw_start li a1, FW_JUMP_OFFSET add a0, a0, a1 -#else -#error "Must define at least FW_JUMP_ADDR or FW_JUMP_OFFSET" -#endif ret .section .entry, "ax", %progbits @@ -98,9 +92,3 @@ fw_options: add a0, zero, zero ret -#ifdef FW_JUMP_ADDR - .section .rodata - .align 3 -_jump_addr: - RISCV_PTR FW_JUMP_ADDR -#endif diff --git a/firmware/fw_payload.S b/firmware/fw_payload.S index 3c8433e..5a149e6 100644 --- a/firmware/fw_payload.S +++ b/firmware/fw_payload.S @@ -44,9 +44,7 @@ fw_save_info: * The next arg1 should be returned in 'a0'. */ fw_next_arg1: -#ifdef FW_PAYLOAD_FDT_ADDR - li a0, FW_PAYLOAD_FDT_ADDR -#elif defined(FW_PAYLOAD_FDT_OFFSET) +#if defined(FW_PAYLOAD_FDT_OFFSET) lla a0, _fw_start li a1, FW_PAYLOAD_FDT_OFFSET add a0, a0, a1 diff --git a/firmware/fw_payload.elf.ldS b/firmware/fw_payload.elf.ldS index f1a544b..94e1ac6 100644 --- a/firmware/fw_payload.elf.ldS +++ b/firmware/fw_payload.elf.ldS @@ -15,7 +15,7 @@ SECTIONS #include "fw_base.ldS" #ifdef FW_PAYLOAD_OFFSET - . = FW_TEXT_START + FW_PAYLOAD_OFFSET; + . = FW_PAYLOAD_OFFSET; #else . = ALIGN(FW_PAYLOAD_ALIGN); #endif diff --git a/firmware/objects.mk b/firmware/objects.mk index e6b364b..121b754 100644 --- a/firmware/objects.mk +++ b/firmware/objects.mk @@ -13,10 +13,6 @@ firmware-cflags-y += firmware-asflags-y += firmware-ldflags-y += -ifdef FW_TEXT_START -firmware-genflags-y += -DFW_TEXT_START=$(FW_TEXT_START) -endif - ifdef FW_FDT_PATH firmware-genflags-y += -DFW_FDT_PATH=\"$(FW_FDT_PATH)\" ifdef FW_FDT_PADDING @@ -30,15 +26,9 @@ firmware-bins-$(FW_JUMP) += fw_jump.bin ifdef FW_JUMP_OFFSET firmware-genflags-$(FW_JUMP) += -DFW_JUMP_OFFSET=$(FW_JUMP_OFFSET) endif -ifdef FW_JUMP_ADDR -firmware-genflags-$(FW_JUMP) += -DFW_JUMP_ADDR=$(FW_JUMP_ADDR) -endif ifdef FW_JUMP_FDT_OFFSET firmware-genflags-$(FW_JUMP) += -DFW_JUMP_FDT_OFFSET=$(FW_JUMP_FDT_OFFSET) endif -ifdef FW_JUMP_FDT_ADDR -firmware-genflags-$(FW_JUMP) += -DFW_JUMP_FDT_ADDR=$(FW_JUMP_FDT_ADDR) -endif firmware-bins-$(FW_PAYLOAD) += fw_payload.bin ifdef FW_PAYLOAD_PATH @@ -57,9 +47,6 @@ endif ifdef FW_PAYLOAD_FDT_OFFSET firmware-genflags-$(FW_PAYLOAD) += -DFW_PAYLOAD_FDT_OFFSET=$(FW_PAYLOAD_FDT_OFFSET) endif -ifdef FW_PAYLOAD_FDT_ADDR -firmware-genflags-$(FW_PAYLOAD) += -DFW_PAYLOAD_FDT_ADDR=$(FW_PAYLOAD_FDT_ADDR) -endif ifdef FW_OPTIONS firmware-genflags-y += -DFW_OPTIONS=$(FW_OPTIONS) diff --git a/firmware/payloads/test.elf.ldS b/firmware/payloads/test.elf.ldS index 2328a1b..08e008f 100644 --- a/firmware/payloads/test.elf.ldS +++ b/firmware/payloads/test.elf.ldS @@ -13,7 +13,7 @@ ENTRY(_start) SECTIONS { #ifdef FW_PAYLOAD_OFFSET - . = FW_TEXT_START + FW_PAYLOAD_OFFSET; + . = FW_PAYLOAD_OFFSET; #else . = ALIGN(FW_PAYLOAD_ALIGN); #endif diff --git a/platform/fpga/ariane/objects.mk b/platform/fpga/ariane/objects.mk index 83581ac..38fdd00 100644 --- a/platform/fpga/ariane/objects.mk +++ b/platform/fpga/ariane/objects.mk @@ -17,17 +17,16 @@ platform-objs-y += platform.o PLATFORM_RISCV_XLEN = 64 # Blobs to build -FW_TEXT_START=0x80000000 FW_JUMP=n ifeq ($(PLATFORM_RISCV_XLEN), 32) # This needs to be 4MB aligned for 32-bit support - FW_JUMP_ADDR=0x80400000 + FW_JUMP_OFFSET=0x400000 else # This needs to be 2MB aligned for 64-bit support - FW_JUMP_ADDR=0x80200000 + FW_JUMP_OFFSET=0x200000 endif -FW_JUMP_FDT_ADDR=0x82200000 +FW_JUMP_FDT_OFFSET=0x2200000 # Firmware with payload configuration. FW_PAYLOAD=y @@ -39,5 +38,5 @@ else # This needs to be 2MB aligned for 64-bit support FW_PAYLOAD_OFFSET=0x200000 endif -FW_PAYLOAD_FDT_ADDR=0x82200000 +FW_PAYLOAD_FDT_OFFSET=0x2200000 FW_PAYLOAD_ALIGN=0x1000 diff --git a/platform/fpga/openpiton/objects.mk b/platform/fpga/openpiton/objects.mk index c8c345a..b7833c3 100644 --- a/platform/fpga/openpiton/objects.mk +++ b/platform/fpga/openpiton/objects.mk @@ -16,17 +16,16 @@ platform-objs-y += platform.o PLATFORM_RISCV_XLEN = 64 # Blobs to build -FW_TEXT_START=0x80000000 FW_JUMP=n ifeq ($(PLATFORM_RISCV_XLEN), 32) # This needs to be 4MB aligned for 32-bit support - FW_JUMP_ADDR=0x80400000 + FW_JUMP_OFFSET=0x400000 else # This needs to be 2MB aligned for 64-bit support - FW_JUMP_ADDR=0x80200000 + FW_JUMP_OFFSET=0x200000 endif -FW_JUMP_FDT_ADDR=0x82200000 +FW_JUMP_FDT_OFFSET=0x2200000 # Firmware with payload configuration. FW_PAYLOAD=y @@ -38,5 +37,5 @@ else # This needs to be 2MB aligned for 64-bit support FW_PAYLOAD_OFFSET=0x200000 endif -FW_PAYLOAD_FDT_ADDR=0x82200000 +FW_PAYLOAD_FDT_OFFSET=0x2200000 FW_PAYLOAD_ALIGN=0x1000 diff --git a/platform/generic/objects.mk b/platform/generic/objects.mk index 85aa723..c215935 100644 --- a/platform/generic/objects.mk +++ b/platform/generic/objects.mk @@ -15,14 +15,13 @@ platform-ldflags-y = # Command for platform specific "make run" platform-runcmd = qemu-system-riscv$(PLATFORM_RISCV_XLEN) -M virt -m 256M \ - -nographic -bios $(build_dir)/platform/generic/firmware/fw_payload.elf + -nographic -bios $(build_dir)/platform/generic/firmware/fw_payload.bin # Objects to build platform-objs-y += platform.o platform-objs-y += platform_override_modules.o # Blobs to build -FW_TEXT_START=0x80000000 FW_DYNAMIC=y FW_JUMP=y ifeq ($(PLATFORM_RISCV_XLEN), 32) diff --git a/platform/kendryte/k210/objects.mk b/platform/kendryte/k210/objects.mk index 1bfb898..efac3d2 100644 --- a/platform/kendryte/k210/objects.mk +++ b/platform/kendryte/k210/objects.mk @@ -21,6 +21,5 @@ platform-varprefix-k210.o = dt_k210 platform-padding-k210.o = 2048 # Blobs to build -FW_TEXT_START=0x80000000 FW_PAYLOAD=y FW_PAYLOAD_ALIGN=0x1000 diff --git a/platform/nuclei/ux600/objects.mk b/platform/nuclei/ux600/objects.mk index 7c429e0..5ce94e7 100644 --- a/platform/nuclei/ux600/objects.mk +++ b/platform/nuclei/ux600/objects.mk @@ -22,12 +22,11 @@ platform-runcmd = xl_spike \ platform-objs-y += platform.o # Blobs to build -FW_TEXT_START=0xA0000000 FW_DYNAMIC=y FW_JUMP=y -FW_JUMP_ADDR=0xA0200000 -FW_JUMP_FDT_ADDR=0xA8000000 +FW_JUMP_OFFSET=0x200000 +FW_JUMP_FDT_OFFSET=0x8000000 FW_PAYLOAD=y FW_PAYLOAD_OFFSET=0x200000 -FW_PAYLOAD_FDT_ADDR=0xA8000000 +FW_PAYLOAD_FDT_OFFSET=0x8000000 diff --git a/platform/template/objects.mk b/platform/template/objects.mk index b143cbc..526e6f5 100644 --- a/platform/template/objects.mk +++ b/platform/template/objects.mk @@ -41,9 +41,6 @@ platform-objs-y += platform.o # # platform-objs-y +=
.o -# Firmware load address configuration. This is mandatory. -FW_TEXT_START=0x80000000 - # Optional parameter for path to external FDT # FW_FDT_PATH="path to platform flattened device tree file" @@ -69,16 +66,6 @@ FW_JUMP= # endif # FW_JUMP_FDT_OFFSET=0x2200000 # -# You can use fixed address for jump firmware as an alternative option, -# but this may fail when setting wrong FW_TEXT_START. Use with caution. -# SBI will prefer "_ADDR" if both "_ADDR" and "_OFFSET" are -# defined -# ifeq ($(PLATFORM_RISCV_XLEN), 32) -# FW_JUMP_ADDR=0x80400000 -# else -# FW_JUMP_ADDR=0x80200000 -# endif -# FW_JUMP_FDT_ADDR=0x82200000 # # Firmware with payload configuration. @@ -97,8 +84,4 @@ endif # FW_PAYLOAD_PATH="path to next boot stage binary image file" # FW_PAYLOAD_FDT_OFFSET=0x2200000 # -# You can use fixed address for payload firmware as an alternative option, -# but this may fail when setting wrong FW_TEXT_START. Use with caution. -# SBI will prefer "FW_PAYLOAD_FDT_ADDR" if both "FW_PAYLOAD_FDT_OFFSET" -# and "FW_PAYLOAD_FDT_ADDR" are defined. -# FW_PAYLOAD_FDT_ADDR=0x82200000 +