public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Jones <andrew.jones@linux.dev>
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	[thread overview]
Message-ID: <20240305170858.395836-22-andrew.jones@linux.dev> (raw)
In-Reply-To: <20240305170858.395836-15-andrew.jones@linux.dev>

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 <andrew.jones@linux.dev>
---
 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 <efi.h>
+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
-- 
2.44.0


  parent reply	other threads:[~2024-03-05 17:09 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-05 17:08 [kvm-unit-tests PATCH v2 00/13] Enable EFI support Andrew Jones
2024-03-05 17:09 ` [kvm-unit-tests PATCH v2 01/13] riscv: Call abort instead of assert on unhandled exceptions Andrew Jones
2024-03-05 17:09 ` [kvm-unit-tests PATCH v2 02/13] riscv: show_regs: Prepare for EFI images Andrew Jones
2024-03-05 17:09 ` [kvm-unit-tests PATCH v2 03/13] treewide: lib/stack: Fix backtrace Andrew Jones
2024-03-05 17:09 ` [kvm-unit-tests PATCH v2 04/13] treewide: lib/stack: Make base_address arch specific Andrew Jones
2024-03-12  5:45   ` Nicholas Piggin
2024-03-05 17:09 ` [kvm-unit-tests PATCH v2 05/13] riscv: Import gnu-efi files Andrew Jones
2024-03-05 17:09 ` [kvm-unit-tests PATCH v2 06/13] riscv: Tweak the gnu-efi imported code Andrew Jones
2024-03-05 17:09 ` Andrew Jones [this message]
2024-03-05 17:09 ` [kvm-unit-tests PATCH v2 08/13] riscv: efi: Switch stack in _start Andrew Jones
2024-03-05 17:09 ` [kvm-unit-tests PATCH v2 09/13] efi: Add support for obtaining the boot hartid Andrew Jones
2024-03-05 17:09 ` [kvm-unit-tests PATCH v2 10/13] riscv: Refactor setup code Andrew Jones
2024-03-05 17:09 ` [kvm-unit-tests PATCH v2 11/13] riscv: Enable EFI boot Andrew Jones
2024-03-05 17:09 ` [kvm-unit-tests PATCH v2 12/13] riscv: efi: Add run script Andrew Jones
2024-03-05 17:09 ` [kvm-unit-tests PATCH v2 13/13] riscv: efi: Use efi-direct by default Andrew Jones
2024-03-18 17:28 ` [kvm-unit-tests PATCH v2 00/13] Enable EFI support Andrew Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240305170858.395836-22-andrew.jones@linux.dev \
    --to=andrew.jones@linux.dev \
    --cc=kvm-riscv@lists.infradead.org \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox