From patchwork Tue Mar 5 17:09:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1908385 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=c0LcgxVv; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=mmdEf9Oh; 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=kvm-riscv-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 4Tq29M61MYz23cb for ; Wed, 6 Mar 2024 04:09:27 +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=apB0hhEyLveHvIsjdoov661S8KCqHfXglYTEvnr8jD0=; b=c0LcgxVv1wBv4z 6dZRo4/2hgXMLTpJCNMskRDpy1M/hVISYyKp9mdPTnPO1prFa0QzwVm1Soe9n5ejX2SrTNuSpytA5 kVbBGv3sz4u2qvXopyi+KCg8hpt+JKLUZAxUwmRX+g1bvHYgEhVzgSnSbbArExnvE5RtpSebpMtmX vtawf/tCNd0fsJaBJyZEtSATrwxxvqlawlY2NRi1gmCzA1SVV4/Xhr0+yEB1NqCg8848GUhpQ2ib/ chPrQVTEWx8ZyP6ohPkcMpDGGWoElA0dBHcBdBIhz36vBDjPYhc0p2B1xJt/os1vxxQbQBCzIgl9v ue3O4SFcvfqCdaNSuvqw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rhYIA-0000000Ecoq-1PAt; Tue, 05 Mar 2024 17:09:26 +0000 Received: from out-184.mta0.migadu.com ([91.218.175.184]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rhYI6-0000000Ecjz-1QBm for kvm-riscv@lists.infradead.org; Tue, 05 Mar 2024 17:09:25 +0000 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1709658559; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mC+XlKr2wuD4Jt3JyCwAi5RF7Z+b/5X3cQTUHW9SzKY=; b=mmdEf9Ohm5Zj75UQXFhHhL8tuq/0CWD1Tj69IAgaSEmQpDL435NcE16VzjfGsuaHMAXze+ vkOwv5dK+PxGu7C6BS98TYCzWlfQKlp4k9CWgR8LaRCYZVPqJQkc63ZdWU0SiXHQjFfKL4 rCGL2Gs/mRSUcW2EdaYNIA3OrlCos58= From: Andrew Jones To: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Cc: pbonzini@redhat.com, thuth@redhat.com Subject: [kvm-unit-tests PATCH v2 07/13] riscv: Enable building for EFI Date: Tue, 5 Mar 2024 18:09:06 +0100 Message-ID: <20240305170858.395836-22-andrew.jones@linux.dev> In-Reply-To: <20240305170858.395836-15-andrew.jones@linux.dev> References: <20240305170858.395836-15-andrew.jones@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240305_090922_937696_447B95D9 X-CRM114-Status: GOOD ( 10.58 ) 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: Mimicking arm64 support, add configure and makefile changes to build for EFI. Since the linker script is replaced also replace the initial cstart code (also done like arm64). Finally, provide a stub f [...] 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_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.0 T_SCC_BODY_TEXT_LINE No description available. X-BeenThere: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Mimicking arm64 support, add configure and makefile changes to build for EFI. Since the linker script is replaced also replace the initial cstart code (also done like arm64). Finally, provide a stub for setup_efi() in order to allow compiling to complete (even though tests can't yet run). Signed-off-by: Andrew Jones --- configure | 3 ++- lib/riscv/asm/setup.h | 5 +++++ riscv/Makefile | 27 +++++++++++++++++++++++++-- riscv/cstart.S | 4 ++++ 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/configure b/configure index 51edee8cd21b..c1d0fe4adbb0 100755 --- a/configure +++ b/configure @@ -231,7 +231,8 @@ else fi fi -if [ "$efi" ] && [ "$arch" != "x86_64" ] && [ "$arch" != "arm64" ]; then +if [ "$efi" ] && [ "$arch" != "x86_64" ] && + [ "$arch" != "arm64" ] && [ "$arch" != "riscv64" ]; then echo "--[enable|disable]-efi is not supported for $arch" usage fi diff --git a/lib/riscv/asm/setup.h b/lib/riscv/asm/setup.h index e58dd53071ae..dfc8875fbb3b 100644 --- a/lib/riscv/asm/setup.h +++ b/lib/riscv/asm/setup.h @@ -12,4 +12,9 @@ int hartid_to_cpu(unsigned long hartid); void io_init(void); void setup(const void *fdt, phys_addr_t freemem_start); +#ifdef CONFIG_EFI +#include +static inline efi_status_t setup_efi(efi_bootinfo_t *efi_bootinfo) { return 0; } +#endif + #endif /* _ASMRISCV_SETUP_H_ */ diff --git a/riscv/Makefile b/riscv/Makefile index 85bbca151739..919a3ebb5211 100644 --- a/riscv/Makefile +++ b/riscv/Makefile @@ -17,7 +17,8 @@ tests += $(TEST_DIR)/sieve.$(exe) all: $(tests) -$(TEST_DIR)/sieve.elf: AUXFLAGS = 0x1 +# When built for EFI sieve needs extra memory, run with e.g. '-m 256' on QEMU +$(TEST_DIR)/sieve.$(exe): AUXFLAGS = 0x1 cstart.o = $(TEST_DIR)/cstart.o @@ -85,7 +86,29 @@ include $(SRCDIR)/scripts/asm-offsets.mak -DPROGNAME=\"$(notdir $(@:.aux.o=.$(exe)))\" -DAUXFLAGS=$(AUXFLAGS) ifeq ($(CONFIG_EFI),y) - # TODO +# avoid jump tables before all relocations have been processed +riscv/efi/reloc_riscv64.o: CFLAGS += -fno-jump-tables +cflatobjs += riscv/efi/reloc_riscv64.o +cflatobjs += lib/acpi.o +cflatobjs += lib/efi.o + +.PRECIOUS: %.so + +%.so: EFI_LDFLAGS += -defsym=EFI_SUBSYSTEM=0xa --no-undefined +%.so: %.o $(FLATLIBS) $(SRCDIR)/riscv/efi/elf_riscv64_efi.lds $(cstart.o) %.aux.o + $(LD) $(EFI_LDFLAGS) -o $@ -T $(SRCDIR)/riscv/efi/elf_riscv64_efi.lds \ + $(filter %.o, $^) $(FLATLIBS) $(EFI_LIBS) + +%.efi: %.so + $(call arch_elf_check, $^) + $(OBJCOPY) --only-keep-debug $^ $@.debug + $(OBJCOPY) --strip-debug $^ + $(OBJCOPY) --add-gnu-debuglink=$@.debug $^ + $(OBJCOPY) \ + -j .text -j .sdata -j .data -j .rodata -j .dynamic -j .dynsym \ + -j .rel -j .rela -j .rel.* -j .rela.* -j .rel* -j .rela* \ + -j .reloc \ + -O binary $^ $@ else %.elf: LDFLAGS += -pie -n -z notext %.elf: %.o $(FLATLIBS) $(SRCDIR)/riscv/flat.lds $(cstart.o) %.aux.o diff --git a/riscv/cstart.S b/riscv/cstart.S index c935467ff6a1..10b5da5779b0 100644 --- a/riscv/cstart.S +++ b/riscv/cstart.S @@ -42,6 +42,9 @@ 9997: .endm +#ifdef CONFIG_EFI +#include "efi/crt0-efi-riscv64.S" +#else .section .init /* @@ -109,6 +112,7 @@ start: call exit j halt +#endif /* !CONFIG_EFI */ .text .balign 4