Skip to contentSkip to conversation

riscv: Enable efi_loader support

PATCH Superseded Alexander Graf 3 participants 15 messages Apr 19, 2018 – Apr 23, 2018 1 message not in the archive RISC-V

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover riscv: Enable efi_loader support

We now have RISC-V support in U-Boot - which is great!

However, not that we're finally making progress to converge on efi_loader and distro boot for booting on ARM platforms, we really want to make sure there is no technical reason not to do the same on RISC-V as well.

So this patch set introduces distro boot and efi_loader support for RISC-V!

So far, I've only tested it with the selftest and hello world target in U-Boot, as the number of target binaries to run is still slim. But it should at least give us a good starting point.

v1 -> v2:

- Allow 32bit target
- Also save/restore ra, sp
- Use edk2 default boot file names
- Enable hello world binary
- remove patch: efi_loader: selftest: Do not build relocation tests for risc-v
- new patch: riscv: Add EFI application infrastructure

Alexander Graf (8):
riscv: Add setjmp/longjmp code
riscv: Enable function sections
riscv: Add EFI application infrastructure
riscv: Add board_quiesce_devices stub
efi_loader: Use EFI_CACHELINE_SIZE in the image loader too
distro: Extend with RISC-V defines
riscv: nx25: Enable distro boot
efi_loader: Enable RISC-V support

 arch/riscv/config.mk                  |  7 ++-
 arch/riscv/cpu/nx25/u-boot.lds        | 16 ++++++
 arch/riscv/include/asm/setjmp.h       | 26 ++++++++++
 arch/riscv/include/asm/u-boot-riscv.h |  1 +
 arch/riscv/lib/Makefile               | 12 +++++
 arch/riscv/lib/bootm.c                |  4 ++
 arch/riscv/lib/elf_riscv32_efi.lds    | 70 +++++++++++++++++++++++++
 arch/riscv/lib/elf_riscv64_efi.lds    | 70 +++++++++++++++++++++++++
 arch/riscv/lib/reloc_riscv_efi.c      | 97 +++++++++++++++++++++++++++++++++++
 arch/riscv/lib/setjmp.S               | 66 ++++++++++++++++++++++++
 cmd/Kconfig                           |  2 +-
 configs/nx25-ae250_defconfig          |  1 +
 include/config_distro_bootcmd.h       | 14 ++++-
 include/configs/nx25-ae250.h          | 17 ++++++
 include/efi_loader.h                  |  7 +++
 lib/efi_loader/Kconfig                |  2 +-
 lib/efi_loader/efi_image_loader.c     |  2 +-
 lib/efi_loader/efi_runtime.c          | 48 ++++++++++++-----
 18 files changed, 445 insertions(+), 17 deletions(-)
 create mode 100644 arch/riscv/include/asm/setjmp.h
 create mode 100644 arch/riscv/lib/elf_riscv32_efi.lds
 create mode 100644 arch/riscv/lib/elf_riscv64_efi.lds
 create mode 100644 arch/riscv/lib/reloc_riscv_efi.c
 create mode 100644 arch/riscv/lib/setjmp.S
Signature · 1 line
2.12.3
#1 lore raw

PATCH v2 1/8 riscv: Add setjmp/longjmp code

To support efi_loader we need to have platform support for setjmp/longjmp. Add it here.

---

v1 -> v2:

- Allow 32bit target
- Also save/restore ra, sp

---
 arch/riscv/include/asm/setjmp.h | 26 ++++++++++++++++
 arch/riscv/lib/Makefile         |  1 +
 arch/riscv/lib/setjmp.S         | 66 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 93 insertions(+)
 create mode 100644 arch/riscv/include/asm/setjmp.h
 create mode 100644 arch/riscv/lib/setjmp.S
arch/riscv/include/asm/setjmp.h new file +26 -0
new file mode 100644
index 0000000000..01ad6d081f
@@ -0,0 +1,26 @@
+/*
+ * (C) Copyright 2018 Alexander Graf <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef _SETJMP_H_
+#define _SETJMP_H_	1
+
+/*
+ * This really should be opaque, but the EFI implementation wrongly
+ * assumes that a 'struct jmp_buf_data' is defined.
+ */
+struct jmp_buf_data {
+	/* x2, x8, x9, x18, x19, x20, x21, x22, x23, x24, x25, x26, x27, sp */
+	unsigned long s_regs[12];	/* s0 - s11 */
+	unsigned long ra;
+	unsigned long sp;
+};
+
+typedef struct jmp_buf_data jmp_buf[1];
+
+int setjmp(jmp_buf jmp);
+void longjmp(jmp_buf jmp, int ret);
+
+#endif /* _SETJMP_H_ */
arch/riscv/lib/Makefile +1 -0
index 323cf3e835..6d97aa2719 100644
@@ -12,3 +12,4 @@ obj-$(CONFIG_CMD_BOOTM) += bootm.o
 obj-$(CONFIG_CMD_GO) += boot.o
 obj-y	+= cache.o
 obj-y	+= interrupts.o
+obj-y   += setjmp.o
arch/riscv/lib/setjmp.S new file +66 -0

66 lines not on this page · raw message

Signature · 1 line
2.12.3
#2 lore raw

PATCH v2 2/8 riscv: Enable function sections

In reply to Alexander Graf

The linker can remove sections that are never addressed, so it makes a lot of sense to declare every function as an individual section.

This reduces the output U-Boot code size by ~30kb for me.

---
 arch/riscv/config.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/config.mk +1 -1
index 6b681c4286..69f4cf6ce8 100644
@@ -29,5 +29,5 @@ CONFIG_STANDALONE_LOAD_ADDR = 0x00000000 \
 			      -T $(srctree)/examples/standalone/riscv.lds
 
 PLATFORM_CPPFLAGS	+= -ffixed-gp -fpic
-PLATFORM_RELFLAGS += -fno-strict-aliasing -fno-common -gdwarf-2
+PLATFORM_RELFLAGS += -fno-strict-aliasing -fno-common -gdwarf-2 -ffunction-sections
 LDFLAGS_u-boot += --gc-sections -static -pie
Signature · 1 line
2.12.3
#3 lore raw

PATCH v2 3/8 riscv: Add EFI application infrastructure

In reply to Alexander Graf

The hello world binary and a few selftests require to build EFI target binaries, not just the EFI host environment.

This patch adds all required files to generate an EFI binary for RISC-V.

---

new in v2

---
 arch/riscv/config.mk               |  5 ++
 arch/riscv/lib/Makefile            | 11 +++++
 arch/riscv/lib/elf_riscv32_efi.lds | 70 +++++++++++++++++++++++++++
 arch/riscv/lib/elf_riscv64_efi.lds | 70 +++++++++++++++++++++++++++
 arch/riscv/lib/reloc_riscv_efi.c   | 97 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 253 insertions(+)
 create mode 100644 arch/riscv/lib/elf_riscv32_efi.lds
 create mode 100644 arch/riscv/lib/elf_riscv64_efi.lds
 create mode 100644 arch/riscv/lib/reloc_riscv_efi.c
arch/riscv/config.mk +5 -0
index 69f4cf6ce8..9175aa765d 100644
@@ -19,10 +19,12 @@ endif
 
 ifdef CONFIG_32BIT
 PLATFORM_LDFLAGS	+= -m $(32bit-emul)
+EFI_LDS			:= elf_riscv32_efi.lds
 endif
 
 ifdef CONFIG_64BIT
 PLATFORM_LDFLAGS	+= -m $(64bit-emul)
+EFI_LDS			:= elf_riscv64_efi.lds
 endif
 
 CONFIG_STANDALONE_LOAD_ADDR = 0x00000000 \
@@ -31,3 +33,6 @@ CONFIG_STANDALONE_LOAD_ADDR = 0x00000000 \
 PLATFORM_CPPFLAGS	+= -ffixed-gp -fpic
 PLATFORM_RELFLAGS += -fno-strict-aliasing -fno-common -gdwarf-2 -ffunction-sections
 LDFLAGS_u-boot += --gc-sections -static -pie
+
+EFI_CRT0		:= crt0_riscv_efi.o
+EFI_RELOC		:= reloc_riscv_efi.o
arch/riscv/lib/Makefile +11 -0
index 6d97aa2719..33f80ebdca 100644
@@ -13,3 +13,14 @@ obj-$(CONFIG_CMD_GO) += boot.o
 obj-y	+= cache.o
 obj-y	+= interrupts.o
 obj-y   += setjmp.o
+
+# For building EFI apps
+CFLAGS_$(EFI_CRT0) := $(CFLAGS_EFI)
+CFLAGS_REMOVE_$(EFI_CRT0) := $(CFLAGS_NON_EFI)
+
+CFLAGS_$(EFI_RELOC) := $(CFLAGS_EFI)
+CFLAGS_REMOVE_$(EFI_RELOC) := $(CFLAGS_NON_EFI)
+
+extra-$(CONFIG_CMD_BOOTEFI_HELLO_COMPILE) += $(EFI_CRT0) $(EFI_RELOC)
+extra-$(CONFIG_CMD_BOOTEFI_SELFTEST) += $(EFI_CRT0) $(EFI_RELOC)
+extra-$(CONFIG_EFI) += $(EFI_CRT0) $(EFI_RELOC)
arch/riscv/lib/elf_riscv32_efi.lds new file +70 -0

70 lines not on this page · raw message

arch/riscv/lib/elf_riscv64_efi.lds new file +70 -0

70 lines not on this page · raw message

arch/riscv/lib/reloc_riscv_efi.c new file +97 -0

97 lines not on this page · raw message

Signature · 1 line
2.12.3

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw

PATCH v2 3/8 riscv: Add EFI application infrastructure

Quoted 37 lines

The hello world binary and a few selftests require to build EFI target binaries, not just the EFI host environment.

This patch adds all required files to generate an EFI binary for RISC-V.

---

new in v2

---
 arch/riscv/config.mk               |  5 ++
 arch/riscv/lib/Makefile            | 11 +++++
 arch/riscv/lib/elf_riscv32_efi.lds | 70 +++++++++++++++++++++++++++  arch/riscv/lib/elf_riscv64_efi.lds | 70 +++++++++++++++++++++++++++
 arch/riscv/lib/reloc_riscv_efi.c   | 97 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 253 insertions(+)
 create mode 100644 arch/riscv/lib/elf_riscv32_efi.lds
 create mode 100644 arch/riscv/lib/elf_riscv64_efi.lds
 create mode 100644 arch/riscv/lib/reloc_riscv_efi.c
arch/riscv/config.mk +2 -0
@@ -19,10 +19,12 @@ endif
 
 ifdef CONFIG_32BIT
 PLATFORM_LDFLAGS       += -m $(32bit-emul)
+EFI_LDS                        := elf_riscv32_efi.lds
 endif
 
 ifdef CONFIG_64BIT
 PLATFORM_LDFLAGS       += -m $(64bit-emul)
+EFI_LDS                        := elf_riscv64_efi.lds
 endif
 
 CONFIG_STANDALONE_LOAD_ADDR = 0x00000000 \ @@ -31,3 +33,6 @@ CONFIG_STANDALONE_LOAD_ADDR = 0x00000000 \

PLATFORM_CPPFLAGS += -ffixed-gp -fpic
PLATFORM_RELFLAGS += -fno-strict-aliasing -fno-common -gdwarf-2 -ffunction-sections LDFLAGS_u-boot += --gc-sections -static -pie

arch/riscv/config.mk CONFIG_STANDALONE_LOAD_ADDR = 0x00000000 \ · line 38

Quoted 3 lines
arch/riscv/config.mk +3 -0
+
+EFI_CRT0               := crt0_riscv_efi.o
+EFI_RELOC              := reloc_riscv_efi.o

Hi Alexander

make fail as below

make[1]: *** No rule to make target 'arch/riscv/lib/crt0_riscv_efi.o', needed by '__build'. Stop.
Makefile:1340: recipe for target 'arch/riscv/lib' failed

Shall crt0_riscv_efi.c be uploaded there ?

B.R.

Rick

Quoted 274 lines
arch/riscv/lib/Makefile +11 -0
@@ -13,3 +13,14 @@ obj-$(CONFIG_CMD_GO) += boot.o
 obj-y  += cache.o
 obj-y  += interrupts.o
 obj-y   += setjmp.o
+
+# For building EFI apps
+CFLAGS_$(EFI_CRT0) := $(CFLAGS_EFI)
+CFLAGS_REMOVE_$(EFI_CRT0) := $(CFLAGS_NON_EFI)
+
+CFLAGS_$(EFI_RELOC) := $(CFLAGS_EFI)
+CFLAGS_REMOVE_$(EFI_RELOC) := $(CFLAGS_NON_EFI)
+
+extra-$(CONFIG_CMD_BOOTEFI_HELLO_COMPILE) += $(EFI_CRT0) $(EFI_RELOC)
+extra-$(CONFIG_CMD_BOOTEFI_SELFTEST) += $(EFI_CRT0) $(EFI_RELOC)
+extra-$(CONFIG_EFI) += $(EFI_CRT0) $(EFI_RELOC)
arch/riscv/lib/elf_riscv32_efi.lds new file +70 -0
new file mode 100644
index 0000000000..96d11985b0
@@ -0,0 +1,70 @@
+/*
+ * U-Boot riscv32 EFI linker script
+ *
+ * SPDX-License-Identifier:    BSD-2-Clause
+ *
+ * Modified from arch/arm/lib/elf_aarch64_efi.lds  */
+
+OUTPUT_FORMAT("elf32-littleriscv", "elf32-littleriscv",
+"elf32-littleriscv")
+OUTPUT_ARCH(riscv)
+ENTRY(_start)
+SECTIONS
+{
+       .text 0x0 : {
+               _text = .;
+               *(.text.head)
+               *(.text)
+               *(.text.*)
+               *(.gnu.linkonce.t.*)
+               *(.srodata)
+               *(.rodata*)
+               . = ALIGN(16);
+       }
+       _etext = .;
+       _text_size = . - _text;
+       .dynamic  : { *(.dynamic) }
+       .data : {
+               _data = .;
+               *(.sdata)
+               *(.data)
+               *(.data1)
+               *(.data.*)
+               *(.got.plt)
+               *(.got)
+
+               /*
+                * The EFI loader doesn't seem to like a .bss section, so we
+                * stick it all into .data:
+                */
+               . = ALIGN(16);
+               _bss = .;
+               *(.sbss)
+               *(.scommon)
+               *(.dynbss)
+               *(.bss)
+               *(.bss.*)
+               *(COMMON)
+               . = ALIGN(16);
+               _bss_end = .;
+               _edata = .;
+       }
+       .rela.dyn : { *(.rela.dyn) }
+       .rela.plt : { *(.rela.plt) }
+       .rela.got : { *(.rela.got) }
+       .rela.data : { *(.rela.data) *(.rela.data*) }
+       _data_size = . - _etext;
+
+       . = ALIGN(4096);
+       .dynsym   : { *(.dynsym) }
+       . = ALIGN(4096);
+       .dynstr   : { *(.dynstr) }
+       . = ALIGN(4096);
+       .note.gnu.build-id : { *(.note.gnu.build-id) }
+       /DISCARD/ : {
+               *(.rel.reloc)
+               *(.eh_frame)
+               *(.note.GNU-stack)
+       }
+       .comment 0 : { *(.comment) }
+}
arch/riscv/lib/elf_riscv64_efi.lds new file +70 -0
new file mode 100644
index 0000000000..25c863de8a
@@ -0,0 +1,70 @@
+/*
+ * U-Boot riscv64 EFI linker script
+ *
+ * SPDX-License-Identifier:    BSD-2-Clause
+ *
+ * Modified from arch/arm/lib/elf_aarch64_efi.lds  */
+
+OUTPUT_FORMAT("elf64-littleriscv", "elf64-littleriscv",
+"elf64-littleriscv")
+OUTPUT_ARCH(riscv)
+ENTRY(_start)
+SECTIONS
+{
+       .text 0x0 : {
+               _text = .;
+               *(.text.head)
+               *(.text)
+               *(.text.*)
+               *(.gnu.linkonce.t.*)
+               *(.srodata)
+               *(.rodata*)
+               . = ALIGN(16);
+       }
+       _etext = .;
+       _text_size = . - _text;
+       .dynamic  : { *(.dynamic) }
+       .data : {
+               _data = .;
+               *(.sdata)
+               *(.data)
+               *(.data1)
+               *(.data.*)
+               *(.got.plt)
+               *(.got)
+
+               /*
+                * The EFI loader doesn't seem to like a .bss section, so we
+                * stick it all into .data:
+                */
+               . = ALIGN(16);
+               _bss = .;
+               *(.sbss)
+               *(.scommon)
+               *(.dynbss)
+               *(.bss)
+               *(.bss.*)
+               *(COMMON)
+               . = ALIGN(16);
+               _bss_end = .;
+               _edata = .;
+       }
+       .rela.dyn : { *(.rela.dyn) }
+       .rela.plt : { *(.rela.plt) }
+       .rela.got : { *(.rela.got) }
+       .rela.data : { *(.rela.data) *(.rela.data*) }
+       _data_size = . - _etext;
+
+       . = ALIGN(4096);
+       .dynsym   : { *(.dynsym) }
+       . = ALIGN(4096);
+       .dynstr   : { *(.dynstr) }
+       . = ALIGN(4096);
+       .note.gnu.build-id : { *(.note.gnu.build-id) }
+       /DISCARD/ : {
+               *(.rel.reloc)
+               *(.eh_frame)
+               *(.note.GNU-stack)
+       }
+       .comment 0 : { *(.comment) }
+}
arch/riscv/lib/reloc_riscv_efi.c new file +96 -1
new file mode 100644
index 0000000000..d80ffc975c
@@ -0,0 +1,97 @@
+/* reloc_riscv.c - position independent ELF shared object relocator
+   Copyright (C) 2018 Alexander Graf <[email protected]>
+   Copyright (C) 2014 Linaro Ltd. <[email protected]>
+   Copyright (C) 1999 Hewlett-Packard Co.
+       Contributed by David Mosberger <[email protected]>.
+
+    All rights reserved.
+
+    Redistribution and use in source and binary forms, with or without
+    modification, are permitted provided that the following conditions
+    are met:
+
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above
+      copyright notice, this list of conditions and the following
+      disclaimer in the documentation and/or other materials
+      provided with the distribution.
+    * Neither the name of Hewlett-Packard Co. nor the names of its
+      contributors may be used to endorse or promote products derived
+      from this software without specific prior written permission.
+
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+    CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+    MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+    BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+    TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+    THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+    SUCH DAMAGE.
+*/
+
+#include <efi.h>
+
+#include <elf.h>
+
+#if __riscv_xlen == 64
+#define Elf_Dyn                Elf64_Dyn
+#define Elf_Rela       Elf64_Rela
+#define ELF_R_TYPE     ELF64_R_TYPE
+#else
+#define Elf_Dyn                Elf32_Dyn
+#define Elf_Rela       Elf32_Rela
+#define ELF_R_TYPE     ELF32_R_TYPE
+#endif
+
+efi_status_t _relocate(long ldbase, Elf_Dyn *dyn, efi_handle_t image,
+                      struct efi_system_table *systab) {
+       long relsz = 0, relent = 0;
+       Elf_Rela *rel = 0;
+       unsigned long *addr;
+       int i;
+
+       for (i = 0; dyn[i].d_tag != DT_NULL; ++i) {
+               switch (dyn[i].d_tag) {
+               case DT_RELA:
+                       rel = (Elf_Rela *)((ulong)dyn[i].d_un.d_ptr + ldbase);
+                       break;
+               case DT_RELASZ:
+                       relsz = dyn[i].d_un.d_val;
+                       break;
+               case DT_RELAENT:
+                       relent = dyn[i].d_un.d_val;
+                       break;
+               default:
+                       break;
+               }
+       }
+
+       if (!rel && relent == 0)
+               return EFI_SUCCESS;
+
+       if (!rel || relent == 0)
+               return EFI_LOAD_ERROR;
+
+       while (relsz > 0) {
+               /* apply the relocs */
+               switch (ELF_R_TYPE(rel->r_info)) {
+               case R_RISCV_RELATIVE:
+                       addr = (ulong *)(ldbase + rel->r_offset);
+                       *addr = ldbase + rel->r_addend;
+                       break;
+               default:
+                       /* Panic */
+                       while (1) ;
+               }
+               rel = (Elf_Rela *)((char *)rel + relent);
+               relsz -= relent;
+       }
+       return EFI_SUCCESS;
+}
--

2.12.3

#6 lore raw

PATCH v2 3/8 riscv: Add EFI application infrastructure

Quoted 43 lines · 陳建志
Quoted 37 lines

The hello world binary and a few selftests require to build EFI target binaries, not just the EFI host environment.

This patch adds all required files to generate an EFI binary for RISC-V.

---

new in v2

---
 arch/riscv/config.mk               |  5 ++
 arch/riscv/lib/Makefile            | 11 +++++
 arch/riscv/lib/elf_riscv32_efi.lds | 70 +++++++++++++++++++++++++++  arch/riscv/lib/elf_riscv64_efi.lds | 70 +++++++++++++++++++++++++++
 arch/riscv/lib/reloc_riscv_efi.c   | 97 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 253 insertions(+)
 create mode 100644 arch/riscv/lib/elf_riscv32_efi.lds
 create mode 100644 arch/riscv/lib/elf_riscv64_efi.lds
 create mode 100644 arch/riscv/lib/reloc_riscv_efi.c
arch/riscv/config.mk +2 -0
@@ -19,10 +19,12 @@ endif
 
 ifdef CONFIG_32BIT
 PLATFORM_LDFLAGS       += -m $(32bit-emul)
+EFI_LDS                        := elf_riscv32_efi.lds
 endif
 
 ifdef CONFIG_64BIT
 PLATFORM_LDFLAGS       += -m $(64bit-emul)
+EFI_LDS                        := elf_riscv64_efi.lds
 endif
 
 CONFIG_STANDALONE_LOAD_ADDR = 0x00000000 \ @@ -31,3 +33,6 @@ CONFIG_STANDALONE_LOAD_ADDR = 0x00000000 \

PLATFORM_CPPFLAGS += -ffixed-gp -fpic
PLATFORM_RELFLAGS += -fno-strict-aliasing -fno-common -gdwarf-2 -ffunction-sections LDFLAGS_u-boot += --gc-sections -static -pie

arch/riscv/config.mk CONFIG_STANDALONE_LOAD_ADDR = 0x00000000 \ · line 38

Quoted 3 lines
arch/riscv/config.mk +3 -0
+
+EFI_CRT0               := crt0_riscv_efi.o
+EFI_RELOC              := reloc_riscv_efi.o

Hi Alexander

Quoted 7 lines

make fail as below

make[1]: *** No rule to make target 'arch/riscv/lib/crt0_riscv_efi.o', needed by '__build'. Stop.
Makefile:1340: recipe for target 'arch/riscv/lib' failed

Shall crt0_riscv_efi.c be uploaded there ?

Sorry, I forgot to send out v3 where I fixed that bit :). I'll do that immediately.

Alex

#7 lore raw

PATCH v2 4/8 riscv: Add board_quiesce_devices stub

In reply to Alexander Graf

This patch adds an empty stub for board_quiesce_devices() which allows boards to quiesce their devices before we boot into an OS in a platform agnostic way.

---
 arch/riscv/include/asm/u-boot-riscv.h | 1 +
 arch/riscv/lib/bootm.c                | 4 ++++
 2 files changed, 5 insertions(+)
arch/riscv/include/asm/u-boot-riscv.h +1 -0
index 18099cd260..0b6428b1ae 100644
@@ -17,5 +17,6 @@ int cleanup_before_linux(void);
 
 /* board/.../... */
 int board_init(void);
+void board_quiesce_devices(void);
 
 #endif	/* _U_BOOT_RISCV_H_ */
arch/riscv/lib/bootm.c +4 -0
index 9242fa891a..b80274adba 100644
@@ -16,6 +16,10 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+__weak void board_quiesce_devices(void)
+{
+}
+
 int arch_fixup_fdt(void *blob)
 {
 	return 0;
Signature · 1 line
2.12.3
#8 lore raw

PATCH v2 5/8 efi_loader: Use EFI_CACHELINE_SIZE in the image loader too

In reply to Alexander Graf

We were using our EFI_CACHELINE_SIZE define only in the runtime service code, but left the image loader to use plain CONFIG_SYS_CACHELINE_SIZE.

This patch moves EFI_CACHELINE_SIZE into efi_loader.h and converts the image loader to use it.

---
 include/efi_loader.h              | 7 +++++++
 lib/efi_loader/efi_image_loader.c | 2 +-
 lib/efi_loader/efi_runtime.c      | 7 -------
 3 files changed, 8 insertions(+), 8 deletions(-)
include/efi_loader.h +7 -0
index 17f9d3d1ef..0b1b3df55a 100644
@@ -76,6 +76,13 @@ const char *__efi_nesting_dec(void);
 		##__VA_ARGS__); \
 	})
 
+#ifdef CONFIG_SYS_CACHELINE_SIZE
+#define EFI_CACHELINE_SIZE CONFIG_SYS_CACHELINE_SIZE
+#else
+/* Just use the greatest cache flush alignment requirement I'm aware of */
+#define EFI_CACHELINE_SIZE 128
+#endif
+
 extern struct efi_runtime_services efi_runtime_services;
 extern struct efi_system_table systab;
 
lib/efi_loader/efi_image_loader.c +1 -1
index d5fbba3138..2476a97a6a 100644
@@ -290,7 +290,7 @@ void *efi_load_pe(void *efi, struct efi_loaded_image *loaded_image_info)
 
 	/* Flush cache */
 	flush_cache((ulong)efi_reloc,
-		    ALIGN(virt_size, CONFIG_SYS_CACHELINE_SIZE));
+		    ALIGN(virt_size, EFI_CACHELINE_SIZE));
 	invalidate_icache_all();
 
 	/* Populate the loaded image interface bits */
lib/efi_loader/efi_runtime.c +0 -7
index 8558124c0a..573a5d6ac1 100644
@@ -30,13 +30,6 @@ static efi_status_t __efi_runtime EFIAPI efi_unimplemented(void);
 static efi_status_t __efi_runtime EFIAPI efi_device_error(void);
 static efi_status_t __efi_runtime EFIAPI efi_invalid_parameter(void);
 
-#ifdef CONFIG_SYS_CACHELINE_SIZE
-#define EFI_CACHELINE_SIZE CONFIG_SYS_CACHELINE_SIZE
-#else
-/* Just use the greatest cache flush alignment requirement I'm aware of */
-#define EFI_CACHELINE_SIZE 128
-#endif
-
 #if defined(CONFIG_ARM64)
 #define R_RELATIVE	1027
 #define R_MASK		0xffffffffULL
Signature · 1 line
2.12.3
#9 lore raw

PATCH v2 6/8 distro: Extend with RISC-V defines

In reply to Alexander Graf

While we don't have VCI or UEFI naming conventions for RISC-V file paths yet, we need to search for something. So let's make up a few defines that at least allow us to get started until the specs officially include RISC-V.

---

v1 -> v2:

- Use edk2 default boot file names

---
 include/config_distro_bootcmd.h | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
include/config_distro_bootcmd.h +13 -1
index f567cebd38..eefdfb51cc 100644
@@ -100,6 +100,10 @@
 #define BOOTEFI_NAME "bootia32.efi"
 #elif defined(CONFIG_X86_RUN_64BIT)
 #define BOOTEFI_NAME "bootx64.efi"
+#elif defined(CONFIG_CPU_RISCV_32)
+#define BOOTEFI_NAME "bootriscv32.efi"
+#elif defined(CONFIG_CPU_RISCV_64)
+#define BOOTEFI_NAME "bootriscv64.efi"
 #endif
 #endif
 
@@ -250,7 +254,15 @@
 #elif defined(CONFIG_X86)
 /* Always assume we're running 64bit */
 #define BOOTENV_EFI_PXE_ARCH "0x7"
-#define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:00007:UNDI:003000"
+#define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:0000:UNDI:003000"
+#elif defined(CONFIG_CPU_RISCV_32)
+/* TODO: Register VCI identifier via RFC */
+#define BOOTENV_EFI_PXE_ARCH "0x5032"
+#define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:5032:UNDI:003000"
+#elif defined(CONFIG_CPU_RISCV_64)
+/* TODO: Register VCI identifier via RFC */
+#define BOOTENV_EFI_PXE_ARCH "0x5064"
+#define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:5064:UNDI:003000"
 #else
 #error Please specify an EFI client identifier
 #endif
Signature · 1 line
2.12.3
#10 lore raw

PATCH v2 6/8 distro: Extend with RISC-V defines

Quoted 20 lines · Alexander Graf

While we don't have VCI or UEFI naming conventions for RISC-V file paths yet, we need to search for something. So let's make up a few defines that at least allow us to get started until the specs officially include RISC-V.

---

v1 -> v2:

- Use edk2 default boot file names

---
  include/config_distro_bootcmd.h | 14 +++++++++++++-
  1 file changed, 13 insertions(+), 1 deletion(-)
include/config_distro_bootcmd.h +0 -0
index f567cebd38..eefdfb51cc 100644

include/config_distro_bootcmd.h line 106

Quoted 7 lines
include/config_distro_bootcmd.h +4 -0
@@ -100,6 +100,10 @@
  #define BOOTEFI_NAME "bootia32.efi"
  #elif defined(CONFIG_X86_RUN_64BIT)
  #define BOOTEFI_NAME "bootx64.efi"
+#elif defined(CONFIG_CPU_RISCV_32)
+#define BOOTEFI_NAME "bootriscv32.efi"
+#elif defined(CONFIG_CPU_RISCV_64)
+#define BOOTEFI_NAME "bootriscv64.efi"

Thanks for updating this.

include/config_distro_bootcmd.h line 257

Quoted 9 lines
include/config_distro_bootcmd.h +1 -1
  #endif
  #endif
 
@@ -250,7 +254,15 @@
  #elif defined(CONFIG_X86)
  /* Always assume we're running 64bit */
  #define BOOTENV_EFI_PXE_ARCH "0x7"
-#define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:00007:UNDI:003000"
+#define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:0000:UNDI:003000"

Did you inadvertently modify this line? The change does not relate to the commit message.

include/config_distro_bootcmd.h line 261

Quoted 4 lines
include/config_distro_bootcmd.h +4 -0
+#elif defined(CONFIG_CPU_RISCV_32)
+/* TODO: Register VCI identifier via RFC */
+#define BOOTENV_EFI_PXE_ARCH "0x5032"
+#define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:5032:UNDI:003000"

Should this be 05032? X86 uses 5 digits.

include/config_distro_bootcmd.h line 265

Quoted 4 lines
include/config_distro_bootcmd.h +4 -0
+#elif defined(CONFIG_CPU_RISCV_64)
+/* TODO: Register VCI identifier via RFC */
+#define BOOTENV_EFI_PXE_ARCH "0x5064"
+#define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:5064:UNDI:003000"

Same here.

Regards

Heinrich

Quoted 4 lines
include/config_distro_bootcmd.h +0 -0
  #else
  #error Please specify an EFI client identifier
  #endif
#11 lore raw

PATCH v2 6/8 distro: Extend with RISC-V defines

Quoted 36 lines · Heinrich Schuchardt
Quoted 23 lines · Alexander Graf

While we don't have VCI or UEFI naming conventions for RISC-V file paths yet,
we need to search for something. So let's make up a few defines that at least
allow us to get started until the specs officially include RISC-V.

---

v1 -> v2:

   - Use edk2 default boot file names
---
  include/config_distro_bootcmd.h | 14 +++++++++++++-

  1 file changed, 13 insertions(+), 1 deletion(-)
include/config_distro_bootcmd.h +0 -0
index f567cebd38..eefdfb51cc 100644

include/config_distro_bootcmd.h line 106

Quoted 7 lines
include/config_distro_bootcmd.h +4 -0
@@ -100,6 +100,10 @@
   #define BOOTEFI_NAME "bootia32.efi"
   #elif defined(CONFIG_X86_RUN_64BIT)
   #define BOOTEFI_NAME "bootx64.efi"
+#elif defined(CONFIG_CPU_RISCV_32)
+#define BOOTEFI_NAME "bootriscv32.efi"
+#elif defined(CONFIG_CPU_RISCV_64)
+#define BOOTEFI_NAME "bootriscv64.efi"

Thanks for updating this.

Quoted 11 lines

include/config_distro_bootcmd.h line 257

Quoted 8 lines
include/config_distro_bootcmd.h +0 -0
   #endif
   #endif

  @@ -250,7 +254,15 @@
  #elif defined(CONFIG_X86)
  /* Always assume we're running 64bit */
  #define BOOTENV_EFI_PXE_ARCH "0x7"

include/config_distro_bootcmd.h +1 -1
-#define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:00007:UNDI:003000"
+#define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:0000:UNDI:003000"

Did you inadvertently modify this line? The change does not relate to the commit message.

Ouch, not intentional of course :). I've fixed it up for v3, but will wait for more comments before I send it.

Quoted 7 lines

include/config_distro_bootcmd.h line 261

Quoted 5 lines
include/config_distro_bootcmd.h +4 -0
+#elif defined(CONFIG_CPU_RISCV_32)
+/* TODO: Register VCI identifier via RFC */
+#define BOOTENV_EFI_PXE_ARCH "0x5032"
+#define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:5032:UNDI:003000"

Should this be 05032? X86 uses 5 digits.

Yes, thanks for the catch!

Alex

#12 lore raw

PATCH v2 6/8 distro: Extend with RISC-V defines

In reply to Heinrich Schuchardt
Quoted 48 lines · Heinrich Schuchardt
Quoted 23 lines · Alexander Graf

While we don't have VCI or UEFI naming conventions for RISC-V file paths yet,
we need to search for something. So let's make up a few defines that at least
allow us to get started until the specs officially include RISC-V.

---

v1 -> v2:

   - Use edk2 default boot file names
---
  include/config_distro_bootcmd.h | 14 +++++++++++++-

  1 file changed, 13 insertions(+), 1 deletion(-)
include/config_distro_bootcmd.h +0 -0
index f567cebd38..eefdfb51cc 100644

include/config_distro_bootcmd.h line 106

Quoted 7 lines
include/config_distro_bootcmd.h +4 -0
@@ -100,6 +100,10 @@
   #define BOOTEFI_NAME "bootia32.efi"
   #elif defined(CONFIG_X86_RUN_64BIT)
   #define BOOTEFI_NAME "bootx64.efi"
+#elif defined(CONFIG_CPU_RISCV_32)
+#define BOOTEFI_NAME "bootriscv32.efi"
+#elif defined(CONFIG_CPU_RISCV_64)
+#define BOOTEFI_NAME "bootriscv64.efi"

Thanks for updating this.

include/config_distro_bootcmd.h line 257

Quoted 8 lines
include/config_distro_bootcmd.h +1 -1
   #endif
   #endif
@@ -250,7 +254,15 @@
   #elif defined(CONFIG_X86)
   /* Always assume we're running 64bit */
   #define BOOTENV_EFI_PXE_ARCH "0x7"
-#define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:00007:UNDI:003000"
+#define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:0000:UNDI:003000"

Did you inadvertently modify this line? The change does not relate to the commit message.

Quoted 6 lines

include/config_distro_bootcmd.h line 261

Quoted 4 lines
include/config_distro_bootcmd.h +4 -0
+#elif defined(CONFIG_CPU_RISCV_32)
+/* TODO: Register VCI identifier via RFC */
+#define BOOTENV_EFI_PXE_ARCH "0x5032"
+#define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:5032:UNDI:003000"

Should this be 05032? X86 uses 5 digits.

These are decimal numbers so this should be
PXEClient:Arch:20530:UNDI:003000

Quoted 7 lines

include/config_distro_bootcmd.h line 265

Quoted 5 lines
include/config_distro_bootcmd.h +4 -0
+#elif defined(CONFIG_CPU_RISCV_64)
+/* TODO: Register VCI identifier via RFC */
+#define BOOTENV_EFI_PXE_ARCH "0x5064"
+#define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:5064:UNDI:003000"

Same here.

PXEClient:Arch:20580:UNDI:003000

Regards

Heinrich

Quoted 10 lines

Regards

Heinrich

Quoted 4 lines
include/config_distro_bootcmd.h +0 -0
   #else
   #error Please specify an EFI client identifier
   #endif
#13 lore raw

PATCH v2 6/8 distro: Extend with RISC-V defines

Quoted 58 lines · Heinrich Schuchardt
Quoted 48 lines · Heinrich Schuchardt
Quoted 23 lines · Alexander Graf

While we don't have VCI or UEFI naming conventions for RISC-V file paths yet,
we need to search for something. So let's make up a few defines that at least
allow us to get started until the specs officially include RISC-V.

---

v1 -> v2:

   - Use edk2 default boot file names
---
  include/config_distro_bootcmd.h | 14 +++++++++++++-

  1 file changed, 13 insertions(+), 1 deletion(-)
include/config_distro_bootcmd.h +0 -0
index f567cebd38..eefdfb51cc 100644

include/config_distro_bootcmd.h line 106

Quoted 7 lines
include/config_distro_bootcmd.h +4 -0
@@ -100,6 +100,10 @@
   #define BOOTEFI_NAME "bootia32.efi"
   #elif defined(CONFIG_X86_RUN_64BIT)
   #define BOOTEFI_NAME "bootx64.efi"
+#elif defined(CONFIG_CPU_RISCV_32)
+#define BOOTEFI_NAME "bootriscv32.efi"
+#elif defined(CONFIG_CPU_RISCV_64)
+#define BOOTEFI_NAME "bootriscv64.efi"

Thanks for updating this.

include/config_distro_bootcmd.h line 257

Quoted 8 lines
include/config_distro_bootcmd.h +1 -1
   #endif
   #endif
@@ -250,7 +254,15 @@
   #elif defined(CONFIG_X86)
   /* Always assume we're running 64bit */
   #define BOOTENV_EFI_PXE_ARCH "0x7"
-#define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:00007:UNDI:003000"
+#define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:0000:UNDI:003000"

Did you inadvertently modify this line? The change does not relate to the commit message.

Quoted 6 lines

include/config_distro_bootcmd.h line 261

Quoted 4 lines
include/config_distro_bootcmd.h +4 -0
+#elif defined(CONFIG_CPU_RISCV_32)
+/* TODO: Register VCI identifier via RFC */
+#define BOOTENV_EFI_PXE_ARCH "0x5032"
+#define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:5032:UNDI:003000"

Should this be 05032? X86 uses 5 digits.

Quoted 2 lines

These are decimal numbers so this should be
PXEClient:Arch:20530:UNDI:003000

Turns out there are values defined:

http://www.iana.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xml

I'll update it accordingly.

Alex

#14 lore raw

PATCH v2 7/8 riscv: nx25: Enable distro boot

In reply to Alexander Graf

Distro boot allows for a common boot path on systems that allow distributions to easily boot from a default configuration.

This patch enables distro boot for the nx25-ae250. Hopefully this can serve as a good example for new boards, so they enable it as well.

---
 configs/nx25-ae250_defconfig |  1 +
 include/configs/nx25-ae250.h | 17 +++++++++++++++++
 2 files changed, 18 insertions(+)
configs/nx25-ae250_defconfig +1 -0
index 4f9bd58f75..437083231b 100644
@@ -37,3 +37,4 @@ CONFIG_DM_SPI=y
 CONFIG_ATCSPI200_SPI=y
 CONFIG_TIMER=y
 CONFIG_ATCPIT100_TIMER=y
+CONFIG_DISTRO_DEFAULTS=y
include/configs/nx25-ae250.h +17 -0
index 0e4c431cab..a90c75abc4 100644
@@ -105,4 +105,21 @@
 /* Increase max gunzip size */
 #define CONFIG_SYS_BOOTM_LEN	(64 << 20)
 
+/* When we use RAM as ENV */
+#define CONFIG_ENV_SIZE 0x2000
+
+/* Enable distro boot */
+#define BOOT_TARGET_DEVICES(func) \
+	func(MMC, mmc, 0) \
+	func(DHCP, dhcp, na)
+#include <config_distro_bootcmd.h>
+
+#define CONFIG_EXTRA_ENV_SETTINGS	\
+				"kernel_addr_r=0x00080000\0" \
+				"pxefile_addr_r=0x01f00000\0" \
+				"scriptaddr=0x01f00000\0" \
+				"fdt_addr_r=0x02000000\0" \
+				"ramdisk_addr_r=0x02800000\0" \
+				BOOTENV
+
 #endif /* __CONFIG_H */
Signature · 1 line
2.12.3
#15 lore raw

PATCH v2 8/8 efi_loader: Enable RISC-V support

In reply to Alexander Graf

We have almost all pieces needed to support RISC-V UEFI binaries in place already. The only missing piece are ELF relocations for runtime code and data.

This patch adds respective support in the linker script and the runtime relocation code. It also allows users to enable the EFI_LOADER configuration switch on RISC-V platforms.

---

v1 -> v2:

- Enable hello world binary

---
 arch/riscv/cpu/nx25/u-boot.lds | 16 ++++++++++++++++
 cmd/Kconfig                    |  2 +-
 lib/efi_loader/Kconfig         |  2 +-
 lib/efi_loader/efi_runtime.c   | 41 ++++++++++++++++++++++++++++++++++++-----
 4 files changed, 54 insertions(+), 7 deletions(-)
arch/riscv/cpu/nx25/u-boot.lds +16 -0
index 936fd779aa..508fa7e58d 100644
@@ -38,6 +38,22 @@ SECTIONS
 		KEEP(*(SORT(.u_boot_list*)));
 	}
 
+	. = ALIGN(4);
+
+	.efi_runtime : {
+                __efi_runtime_start = .;
+		*(efi_runtime_text)
+		*(efi_runtime_data)
+                __efi_runtime_stop = .;
+	}
+
+	.efi_runtime_rel : {
+                __efi_runtime_rel_start = .;
+		*(.relaefi_runtime_text)
+		*(.relaefi_runtime_data)
+                __efi_runtime_rel_stop = .;
+	}
+
     . = ALIGN(4);
 
     /DISCARD/ : { *(.rela.plt*) }
cmd/Kconfig +1 -1
index bc1d2f31c0..c9883a40e7 100644
@@ -228,7 +228,7 @@ config CMD_BOOTEFI
 
 config CMD_BOOTEFI_HELLO_COMPILE
 	bool "Compile a standard EFI hello world binary for testing"
-	depends on CMD_BOOTEFI && (ARM || X86)
+	depends on CMD_BOOTEFI && (ARM || X86 || RISCV)
 	default y
 	help
 	  This compiles a standard EFI hello world application with U-Boot so
lib/efi_loader/Kconfig +1 -1
index 83d75c4fdc..9de58bb012 100644
@@ -1,6 +1,6 @@
 config EFI_LOADER
 	bool "Support running EFI Applications in U-Boot"
-	depends on (ARM || X86) && OF_LIBFDT
+	depends on (ARM || X86 || RISCV) && OF_LIBFDT
 	# We need EFI_STUB_64BIT to be set on x86_64 with EFI_STUB
 	depends on !EFI_STUB || !X86_64 || EFI_STUB_64BIT
 	# We need EFI_STUB_32BIT to be set on x86_32 with EFI_STUB
lib/efi_loader/efi_runtime.c +36 -5

57 lines not on this page · raw message

Signature · 1 line
2.12.3