* [U-Boot] [PATCH 0/8] riscv: Enable efi_loader support
@ 2018-04-18 13:40 Alexander Graf
2018-04-18 13:40 ` [U-Boot] [PATCH 1/8] riscv: Add setjmp/longjmp code Alexander Graf
` (7 more replies)
0 siblings, 8 replies; 14+ messages in thread
From: Alexander Graf @ 2018-04-18 13:40 UTC (permalink / raw)
To: u-boot
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, as the number of
target binaries to run is still slim. But it should at least give
us a good starting point.
Alexander Graf (8):
riscv: Add setjmp/longjmp code
riscv: Enable function sections
efi_loader: selftest: Do not build relocation tests for risc-v
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 | 2 +-
arch/riscv/cpu/nx25/u-boot.lds | 16 +++++++++++
arch/riscv/include/asm/setjmp.h | 24 ++++++++++++++++
arch/riscv/include/asm/u-boot-riscv.h | 1 +
arch/riscv/lib/Makefile | 1 +
arch/riscv/lib/bootm.c | 4 +++
arch/riscv/lib/setjmp.S | 54 +++++++++++++++++++++++++++++++++++
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 +++++++++++++++++++++++--------
lib/efi_selftest/Makefile | 11 ++++---
15 files changed, 184 insertions(+), 20 deletions(-)
create mode 100644 arch/riscv/include/asm/setjmp.h
create mode 100644 arch/riscv/lib/setjmp.S
--
2.12.3
^ permalink raw reply [flat|nested] 14+ messages in thread
* [U-Boot] [PATCH 1/8] riscv: Add setjmp/longjmp code
2018-04-18 13:40 [U-Boot] [PATCH 0/8] riscv: Enable efi_loader support Alexander Graf
@ 2018-04-18 13:40 ` Alexander Graf
2018-04-18 13:40 ` [U-Boot] [PATCH 2/8] riscv: Enable function sections Alexander Graf
` (6 subsequent siblings)
7 siblings, 0 replies; 14+ messages in thread
From: Alexander Graf @ 2018-04-18 13:40 UTC (permalink / raw)
To: u-boot
To support efi_loader we need to have platform support for setjmp/longjmp.
Add it here.
Signed-off-by: Alexander Graf <agraf@suse.de>
---
arch/riscv/include/asm/setjmp.h | 24 ++++++++++++++++++
arch/riscv/lib/Makefile | 1 +
arch/riscv/lib/setjmp.S | 54 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 79 insertions(+)
create mode 100644 arch/riscv/include/asm/setjmp.h
create mode 100644 arch/riscv/lib/setjmp.S
diff --git a/arch/riscv/include/asm/setjmp.h b/arch/riscv/include/asm/setjmp.h
new file mode 100644
index 0000000000..37e8281aaa
--- /dev/null
+++ b/arch/riscv/include/asm/setjmp.h
@@ -0,0 +1,24 @@
+/*
+ * (C) Copyright 2018 Alexander Graf <agraf@suse.de>
+ *
+ * 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 */
+ u64 regs[13];
+};
+
+typedef struct jmp_buf_data jmp_buf[1];
+
+int setjmp(jmp_buf jmp);
+void longjmp(jmp_buf jmp, int ret);
+
+#endif /* _SETJMP_H_ */
diff --git a/arch/riscv/lib/Makefile b/arch/riscv/lib/Makefile
index 323cf3e835..6d97aa2719 100644
--- a/arch/riscv/lib/Makefile
+++ b/arch/riscv/lib/Makefile
@@ -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
diff --git a/arch/riscv/lib/setjmp.S b/arch/riscv/lib/setjmp.S
new file mode 100644
index 0000000000..55c5128163
--- /dev/null
+++ b/arch/riscv/lib/setjmp.S
@@ -0,0 +1,54 @@
+/*
+ * (C) 2018 Alexander Graf <agraf@suse.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <config.h>
+#include <linux/linkage.h>
+
+.pushsection .text.setjmp, "ax"
+ENTRY(setjmp)
+ /* Preserve all callee-saved registers and the SP */
+ sd s0, 0(a0)
+ sd s1, 8(a0)
+ sd s2, 16(a0)
+ sd s3, 24(a0)
+ sd s4, 32(a0)
+ sd s5, 40(a0)
+ sd s6, 48(a0)
+ sd s7, 56(a0)
+ sd s8, 64(a0)
+ sd s9, 72(a0)
+ sd s10, 80(a0)
+ sd s11, 88(a0)
+ li a0, 0
+ ret
+ENDPROC(setjmp)
+.popsection
+
+.pushsection .text.longjmp, "ax"
+ENTRY(longjmp)
+ ld s0, 0(a0)
+ ld s1, 8(a0)
+ ld s2, 16(a0)
+ ld s3, 24(a0)
+ ld s4, 32(a0)
+ ld s5, 40(a0)
+ ld s6, 48(a0)
+ ld s7, 56(a0)
+ ld s8, 64(a0)
+ ld s9, 72(a0)
+ ld s10, 80(a0)
+ ld s11, 88(a0)
+
+ /* Move the return value in place, but return 1 if passed 0. */
+ beq a1, zero, longjmp_1
+ mv a0, a1
+ ret
+
+ longjmp_1:
+ li a0, 1
+ ret
+ENDPROC(longjmp)
+.popsection
--
2.12.3
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [U-Boot] [PATCH 2/8] riscv: Enable function sections
2018-04-18 13:40 [U-Boot] [PATCH 0/8] riscv: Enable efi_loader support Alexander Graf
2018-04-18 13:40 ` [U-Boot] [PATCH 1/8] riscv: Add setjmp/longjmp code Alexander Graf
@ 2018-04-18 13:40 ` Alexander Graf
2018-04-18 13:40 ` [U-Boot] [PATCH 3/8] efi_loader: selftest: Do not build relocation tests for risc-v Alexander Graf
` (5 subsequent siblings)
7 siblings, 0 replies; 14+ messages in thread
From: Alexander Graf @ 2018-04-18 13:40 UTC (permalink / raw)
To: u-boot
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.
Signed-off-by: Alexander Graf <agraf@suse.de>
---
arch/riscv/config.mk | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/riscv/config.mk b/arch/riscv/config.mk
index 6b681c4286..69f4cf6ce8 100644
--- a/arch/riscv/config.mk
+++ b/arch/riscv/config.mk
@@ -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
--
2.12.3
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [U-Boot] [PATCH 3/8] efi_loader: selftest: Do not build relocation tests for risc-v
2018-04-18 13:40 [U-Boot] [PATCH 0/8] riscv: Enable efi_loader support Alexander Graf
2018-04-18 13:40 ` [U-Boot] [PATCH 1/8] riscv: Add setjmp/longjmp code Alexander Graf
2018-04-18 13:40 ` [U-Boot] [PATCH 2/8] riscv: Enable function sections Alexander Graf
@ 2018-04-18 13:40 ` Alexander Graf
2018-04-18 15:48 ` Heinrich Schuchardt
2018-04-19 5:57 ` Heinrich Schuchardt
2018-04-18 13:40 ` [U-Boot] [PATCH 4/8] riscv: Add board_quiesce_devices stub Alexander Graf
` (4 subsequent siblings)
7 siblings, 2 replies; 14+ messages in thread
From: Alexander Graf @ 2018-04-18 13:40 UTC (permalink / raw)
To: u-boot
The relocation selftest doesn't compile for me on RISC-V. Disable for now.
Signed-off-by: Alexander Graf <agraf@suse.de>
---
lib/efi_selftest/Makefile | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/lib/efi_selftest/Makefile b/lib/efi_selftest/Makefile
index 31b444fc8b..ede7831449 100644
--- a/lib/efi_selftest/Makefile
+++ b/lib/efi_selftest/Makefile
@@ -35,9 +35,10 @@ ifeq ($(CONFIG_BLK)$(CONFIG_PARTITIONS),yy)
obj-$(CONFIG_CMD_BOOTEFI_SELFTEST) += efi_selftest_block_device.o
endif
-# TODO: As of v2018.01 the relocation code for the EFI application cannot
-# be built on x86_64.
+# TODO: As of v2018.05 the relocation code for the EFI application cannot
+# be built on x86_64 / RISC-V.
ifeq ($(CONFIG_X86_64),)
+ifeq ($(CONFIG_RISCV),)
ifneq ($(CONFIG_CMD_BOOTEFI_SELFTEST),)
@@ -63,6 +64,8 @@ $(obj)/efi_selftest_startimage_exit.o: $(obj)/efi_miniapp_file_image_exit.h
$(obj)/efi_selftest_startimage_return.o: $(obj)/efi_miniapp_file_image_return.h
-endif
+endif # CONFIG_CMD_BOOTEFI_SELFTEST
-endif
+endif # !CONFIG_RISCV
+
+endif # !CONFIG_X86_64
--
2.12.3
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [U-Boot] [PATCH 4/8] riscv: Add board_quiesce_devices stub
2018-04-18 13:40 [U-Boot] [PATCH 0/8] riscv: Enable efi_loader support Alexander Graf
` (2 preceding siblings ...)
2018-04-18 13:40 ` [U-Boot] [PATCH 3/8] efi_loader: selftest: Do not build relocation tests for risc-v Alexander Graf
@ 2018-04-18 13:40 ` Alexander Graf
2018-04-18 13:40 ` [U-Boot] [PATCH 5/8] efi_loader: Use EFI_CACHELINE_SIZE in the image loader too Alexander Graf
` (3 subsequent siblings)
7 siblings, 0 replies; 14+ messages in thread
From: Alexander Graf @ 2018-04-18 13:40 UTC (permalink / raw)
To: u-boot
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.
Signed-off-by: Alexander Graf <agraf@suse.de>
---
arch/riscv/include/asm/u-boot-riscv.h | 1 +
arch/riscv/lib/bootm.c | 4 ++++
2 files changed, 5 insertions(+)
diff --git a/arch/riscv/include/asm/u-boot-riscv.h b/arch/riscv/include/asm/u-boot-riscv.h
index 18099cd260..0b6428b1ae 100644
--- a/arch/riscv/include/asm/u-boot-riscv.h
+++ b/arch/riscv/include/asm/u-boot-riscv.h
@@ -17,5 +17,6 @@ int cleanup_before_linux(void);
/* board/.../... */
int board_init(void);
+void board_quiesce_devices(void);
#endif /* _U_BOOT_RISCV_H_ */
diff --git a/arch/riscv/lib/bootm.c b/arch/riscv/lib/bootm.c
index 9242fa891a..b80274adba 100644
--- a/arch/riscv/lib/bootm.c
+++ b/arch/riscv/lib/bootm.c
@@ -16,6 +16,10 @@
DECLARE_GLOBAL_DATA_PTR;
+__weak void board_quiesce_devices(void)
+{
+}
+
int arch_fixup_fdt(void *blob)
{
return 0;
--
2.12.3
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [U-Boot] [PATCH 5/8] efi_loader: Use EFI_CACHELINE_SIZE in the image loader too
2018-04-18 13:40 [U-Boot] [PATCH 0/8] riscv: Enable efi_loader support Alexander Graf
` (3 preceding siblings ...)
2018-04-18 13:40 ` [U-Boot] [PATCH 4/8] riscv: Add board_quiesce_devices stub Alexander Graf
@ 2018-04-18 13:40 ` Alexander Graf
2018-04-18 13:40 ` [U-Boot] [PATCH 6/8] distro: Extend with RISC-V defines Alexander Graf
` (2 subsequent siblings)
7 siblings, 0 replies; 14+ messages in thread
From: Alexander Graf @ 2018-04-18 13:40 UTC (permalink / raw)
To: u-boot
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.
Signed-off-by: Alexander Graf <agraf@suse.de>
---
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(-)
diff --git a/include/efi_loader.h b/include/efi_loader.h
index 17f9d3d1ef..0b1b3df55a 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -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;
diff --git a/lib/efi_loader/efi_image_loader.c b/lib/efi_loader/efi_image_loader.c
index d5fbba3138..2476a97a6a 100644
--- a/lib/efi_loader/efi_image_loader.c
+++ b/lib/efi_loader/efi_image_loader.c
@@ -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 */
diff --git a/lib/efi_loader/efi_runtime.c b/lib/efi_loader/efi_runtime.c
index 8558124c0a..573a5d6ac1 100644
--- a/lib/efi_loader/efi_runtime.c
+++ b/lib/efi_loader/efi_runtime.c
@@ -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
--
2.12.3
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [U-Boot] [PATCH 6/8] distro: Extend with RISC-V defines
2018-04-18 13:40 [U-Boot] [PATCH 0/8] riscv: Enable efi_loader support Alexander Graf
` (4 preceding siblings ...)
2018-04-18 13:40 ` [U-Boot] [PATCH 5/8] efi_loader: Use EFI_CACHELINE_SIZE in the image loader too Alexander Graf
@ 2018-04-18 13:40 ` Alexander Graf
2018-04-18 15:43 ` Heinrich Schuchardt
2018-04-18 13:40 ` [U-Boot] [PATCH 7/8] riscv: nx25: Enable distro boot Alexander Graf
2018-04-18 13:40 ` [U-Boot] [PATCH 8/8] efi_loader: Enable RISC-V support Alexander Graf
7 siblings, 1 reply; 14+ messages in thread
From: Alexander Graf @ 2018-04-18 13:40 UTC (permalink / raw)
To: u-boot
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.
Signed-off-by: Alexander Graf <agraf@suse.de>
---
include/config_distro_bootcmd.h | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/include/config_distro_bootcmd.h b/include/config_distro_bootcmd.h
index f567cebd38..7b95872958 100644
--- a/include/config_distro_bootcmd.h
+++ b/include/config_distro_bootcmd.h
@@ -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 "bootrv32.efi"
+#elif defined(CONFIG_CPU_RISCV_64)
+#define BOOTEFI_NAME "bootrv64.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
--
2.12.3
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [U-Boot] [PATCH 7/8] riscv: nx25: Enable distro boot
2018-04-18 13:40 [U-Boot] [PATCH 0/8] riscv: Enable efi_loader support Alexander Graf
` (5 preceding siblings ...)
2018-04-18 13:40 ` [U-Boot] [PATCH 6/8] distro: Extend with RISC-V defines Alexander Graf
@ 2018-04-18 13:40 ` Alexander Graf
2018-04-18 13:40 ` [U-Boot] [PATCH 8/8] efi_loader: Enable RISC-V support Alexander Graf
7 siblings, 0 replies; 14+ messages in thread
From: Alexander Graf @ 2018-04-18 13:40 UTC (permalink / raw)
To: u-boot
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.
Signed-off-by: Alexander Graf <agraf@suse.de>
---
configs/nx25-ae250_defconfig | 1 +
include/configs/nx25-ae250.h | 17 +++++++++++++++++
2 files changed, 18 insertions(+)
diff --git a/configs/nx25-ae250_defconfig b/configs/nx25-ae250_defconfig
index 4f9bd58f75..437083231b 100644
--- a/configs/nx25-ae250_defconfig
+++ b/configs/nx25-ae250_defconfig
@@ -37,3 +37,4 @@ CONFIG_DM_SPI=y
CONFIG_ATCSPI200_SPI=y
CONFIG_TIMER=y
CONFIG_ATCPIT100_TIMER=y
+CONFIG_DISTRO_DEFAULTS=y
diff --git a/include/configs/nx25-ae250.h b/include/configs/nx25-ae250.h
index 0e4c431cab..a90c75abc4 100644
--- a/include/configs/nx25-ae250.h
+++ b/include/configs/nx25-ae250.h
@@ -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 */
--
2.12.3
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [U-Boot] [PATCH 8/8] efi_loader: Enable RISC-V support
2018-04-18 13:40 [U-Boot] [PATCH 0/8] riscv: Enable efi_loader support Alexander Graf
` (6 preceding siblings ...)
2018-04-18 13:40 ` [U-Boot] [PATCH 7/8] riscv: nx25: Enable distro boot Alexander Graf
@ 2018-04-18 13:40 ` Alexander Graf
2018-04-19 5:14 ` Heinrich Schuchardt
7 siblings, 1 reply; 14+ messages in thread
From: Alexander Graf @ 2018-04-18 13:40 UTC (permalink / raw)
To: u-boot
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.
Signed-off-by: Alexander Graf <agraf@suse.de>
---
arch/riscv/cpu/nx25/u-boot.lds | 16 ++++++++++++++++
lib/efi_loader/Kconfig | 2 +-
lib/efi_loader/efi_runtime.c | 41 ++++++++++++++++++++++++++++++++++++-----
3 files changed, 53 insertions(+), 6 deletions(-)
diff --git a/arch/riscv/cpu/nx25/u-boot.lds b/arch/riscv/cpu/nx25/u-boot.lds
index 936fd779aa..508fa7e58d 100644
--- a/arch/riscv/cpu/nx25/u-boot.lds
+++ b/arch/riscv/cpu/nx25/u-boot.lds
@@ -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*) }
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index 83d75c4fdc..9de58bb012 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -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
diff --git a/lib/efi_loader/efi_runtime.c b/lib/efi_loader/efi_runtime.c
index 573a5d6ac1..33bbc8d6cc 100644
--- a/lib/efi_loader/efi_runtime.c
+++ b/lib/efi_loader/efi_runtime.c
@@ -41,6 +41,25 @@ static efi_status_t __efi_runtime EFIAPI efi_invalid_parameter(void);
#include <asm/elf.h>
#define R_RELATIVE R_386_RELATIVE
#define R_MASK 0xffULL
+#elif defined(CONFIG_RISCV)
+#include <elf.h>
+#define R_RELATIVE R_RISCV_RELATIVE
+#define R_MASK 0xffULL
+#define IS_RELA 1
+
+struct dyn_sym {
+ ulong foo1;
+ ulong addr;
+ u32 foo2;
+ u32 foo3;
+};
+#ifdef CONFIG_CPU_RISCV_32
+#define R_ABSOLUTE R_RISCV_32
+#define SYM_INDEX 8
+#else
+#define R_ABSOLUTE R_RISCV_64
+#define SYM_INDEX 32
+#endif
#else
#error Need to add relocation awareness
#endif
@@ -247,15 +266,27 @@ void efi_runtime_relocate(ulong offset, struct efi_mem_desc *map)
p = (void*)((ulong)rel->offset - base) + gd->relocaddr;
- if ((rel->info & R_MASK) != R_RELATIVE) {
- continue;
- }
+ debug("%s: rel->info=%#lx *p=%#lx rel->offset=%p\n", __func__, rel->info, *p, rel->offset);
+ switch (rel->info & R_MASK) {
+ case R_RELATIVE:
#ifdef IS_RELA
- newaddr = rel->addend + offset - CONFIG_SYS_TEXT_BASE;
+ newaddr = rel->addend + offset - CONFIG_SYS_TEXT_BASE;
#else
- newaddr = *p - lastoff + offset;
+ newaddr = *p - lastoff + offset;
#endif
+ break;
+#ifdef R_ABSOLUTE
+ case R_ABSOLUTE: {
+ ulong symidx = rel->info >> SYM_INDEX;
+ extern struct dyn_sym __dyn_sym_start[];
+ newaddr = __dyn_sym_start[symidx].addr + offset;
+ break;
+ }
+#endif
+ default:
+ continue;
+ }
/* Check if the relocation is inside bounds */
if (map && ((newaddr < map->virtual_start) ||
--
2.12.3
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [U-Boot] [PATCH 6/8] distro: Extend with RISC-V defines
2018-04-18 13:40 ` [U-Boot] [PATCH 6/8] distro: Extend with RISC-V defines Alexander Graf
@ 2018-04-18 15:43 ` Heinrich Schuchardt
0 siblings, 0 replies; 14+ messages in thread
From: Heinrich Schuchardt @ 2018-04-18 15:43 UTC (permalink / raw)
To: u-boot
On 04/18/2018 03:40 PM, Alexander Graf wrote:
> 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.
>
> Signed-off-by: Alexander Graf <agraf@suse.de>
> ---
> include/config_distro_bootcmd.h | 14 +++++++++++++-
> 1 file changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/include/config_distro_bootcmd.h b/include/config_distro_bootcmd.h
> index f567cebd38..7b95872958 100644
> --- a/include/config_distro_bootcmd.h
> +++ b/include/config_distro_bootcmd.h
> @@ -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 "bootrv32.efi"
> +#elif defined(CONFIG_CPU_RISCV_64)
> +#define BOOTEFI_NAME "bootrv64.efi"
Hello Alex,
I suggest to use the same values as the RISC-V branch of EDK2.
https://github.com/tianocore/edk2-staging/blob/RISC-V/MdePkg/Include/Uefi/UefiSpec.h#L2171
BOOTRISCV32.EFI
BOOTRISCV64.EFI
These values are not standardized yet. But we have not better hint of
what to expect in the next version of the spec.
Best regards
Heinrich
> #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
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* [U-Boot] [PATCH 3/8] efi_loader: selftest: Do not build relocation tests for risc-v
2018-04-18 13:40 ` [U-Boot] [PATCH 3/8] efi_loader: selftest: Do not build relocation tests for risc-v Alexander Graf
@ 2018-04-18 15:48 ` Heinrich Schuchardt
2018-04-18 16:41 ` Alexander Graf
2018-04-19 5:57 ` Heinrich Schuchardt
1 sibling, 1 reply; 14+ messages in thread
From: Heinrich Schuchardt @ 2018-04-18 15:48 UTC (permalink / raw)
To: u-boot
On 04/18/2018 03:40 PM, Alexander Graf wrote:
> The relocation selftest doesn't compile for me on RISC-V. Disable for now.
Can this problem be reproduced with one of the qemu targets?
Does loading a binary work?
>
> Signed-off-by: Alexander Graf <agraf@suse.de>
> ---
> lib/efi_selftest/Makefile | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/lib/efi_selftest/Makefile b/lib/efi_selftest/Makefile
> index 31b444fc8b..ede7831449 100644
> --- a/lib/efi_selftest/Makefile
> +++ b/lib/efi_selftest/Makefile
> @@ -35,9 +35,10 @@ ifeq ($(CONFIG_BLK)$(CONFIG_PARTITIONS),yy)
> obj-$(CONFIG_CMD_BOOTEFI_SELFTEST) += efi_selftest_block_device.o
> endif
>
> -# TODO: As of v2018.01 the relocation code for the EFI application cannot
> -# be built on x86_64.
> +# TODO: As of v2018.05 the relocation code for the EFI application cannot
> +# be built on x86_64 / RISC-V.
> ifeq ($(CONFIG_X86_64),)
> +ifeq ($(CONFIG_RISCV),)
Elsewhere we abbreviate (!A && !B) as:
ifeq ($(CONFIG_X86_64)$(CONFIG_RISCV),)
Regards
Heinrich
>
> ifneq ($(CONFIG_CMD_BOOTEFI_SELFTEST),)
>
> @@ -63,6 +64,8 @@ $(obj)/efi_selftest_startimage_exit.o: $(obj)/efi_miniapp_file_image_exit.h
>
> $(obj)/efi_selftest_startimage_return.o: $(obj)/efi_miniapp_file_image_return.h
>
> -endif
> +endif # CONFIG_CMD_BOOTEFI_SELFTEST
>
> -endif
> +endif # !CONFIG_RISCV
> +
> +endif # !CONFIG_X86_64
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* [U-Boot] [PATCH 3/8] efi_loader: selftest: Do not build relocation tests for risc-v
2018-04-18 15:48 ` Heinrich Schuchardt
@ 2018-04-18 16:41 ` Alexander Graf
0 siblings, 0 replies; 14+ messages in thread
From: Alexander Graf @ 2018-04-18 16:41 UTC (permalink / raw)
To: u-boot
> Am 18.04.2018 um 17:48 schrieb Heinrich Schuchardt <xypron.glpk@gmx.de>:
>
>> On 04/18/2018 03:40 PM, Alexander Graf wrote:
>> The relocation selftest doesn't compile for me on RISC-V. Disable for now.
>
> Can this problem be reproduced with one of the qemu targets?
It already fails to compile, you don‘t need to run it ;).
> Does loading a binary work?
That‘s the next step. I wanted to get this out as a first step, then see what binary I could make work. The goal is obviously a grub port.
Alex
^ permalink raw reply [flat|nested] 14+ messages in thread
* [U-Boot] [PATCH 8/8] efi_loader: Enable RISC-V support
2018-04-18 13:40 ` [U-Boot] [PATCH 8/8] efi_loader: Enable RISC-V support Alexander Graf
@ 2018-04-19 5:14 ` Heinrich Schuchardt
0 siblings, 0 replies; 14+ messages in thread
From: Heinrich Schuchardt @ 2018-04-19 5:14 UTC (permalink / raw)
To: u-boot
On 04/18/2018 03:40 PM, Alexander Graf wrote:
> 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.
>
> Signed-off-by: Alexander Graf <agraf@suse.de>
The patch is not applicable after my pending patch for ARMV7_NONSEC.
Could you, please, have a look at
"efi_loader: no support for ARMV7_NONSEC=y"
https://patchwork.ozlabs.org/patch/896962/
and decide if you will accept it. This is only a question of sequence in
efi_next.
Best regards
Heinrich
> ---
> arch/riscv/cpu/nx25/u-boot.lds | 16 ++++++++++++++++
> lib/efi_loader/Kconfig | 2 +-
> lib/efi_loader/efi_runtime.c | 41 ++++++++++++++++++++++++++++++++++++-----
> 3 files changed, 53 insertions(+), 6 deletions(-)
>
> diff --git a/arch/riscv/cpu/nx25/u-boot.lds b/arch/riscv/cpu/nx25/u-boot.lds
> index 936fd779aa..508fa7e58d 100644
> --- a/arch/riscv/cpu/nx25/u-boot.lds
> +++ b/arch/riscv/cpu/nx25/u-boot.lds
> @@ -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*) }
> diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
> index 83d75c4fdc..9de58bb012 100644
> --- a/lib/efi_loader/Kconfig
> +++ b/lib/efi_loader/Kconfig
> @@ -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
> diff --git a/lib/efi_loader/efi_runtime.c b/lib/efi_loader/efi_runtime.c
> index 573a5d6ac1..33bbc8d6cc 100644
> --- a/lib/efi_loader/efi_runtime.c
> +++ b/lib/efi_loader/efi_runtime.c
> @@ -41,6 +41,25 @@ static efi_status_t __efi_runtime EFIAPI efi_invalid_parameter(void);
> #include <asm/elf.h>
> #define R_RELATIVE R_386_RELATIVE
> #define R_MASK 0xffULL
> +#elif defined(CONFIG_RISCV)
> +#include <elf.h>
> +#define R_RELATIVE R_RISCV_RELATIVE
> +#define R_MASK 0xffULL
> +#define IS_RELA 1
> +
> +struct dyn_sym {
> + ulong foo1;
> + ulong addr;
> + u32 foo2;
> + u32 foo3;
> +};
> +#ifdef CONFIG_CPU_RISCV_32
> +#define R_ABSOLUTE R_RISCV_32
> +#define SYM_INDEX 8
> +#else
> +#define R_ABSOLUTE R_RISCV_64
> +#define SYM_INDEX 32
> +#endif
> #else
> #error Need to add relocation awareness
> #endif
> @@ -247,15 +266,27 @@ void efi_runtime_relocate(ulong offset, struct efi_mem_desc *map)
>
> p = (void*)((ulong)rel->offset - base) + gd->relocaddr;
>
> - if ((rel->info & R_MASK) != R_RELATIVE) {
> - continue;
> - }
> + debug("%s: rel->info=%#lx *p=%#lx rel->offset=%p\n", __func__, rel->info, *p, rel->offset);
>
> + switch (rel->info & R_MASK) {
> + case R_RELATIVE:
> #ifdef IS_RELA
> - newaddr = rel->addend + offset - CONFIG_SYS_TEXT_BASE;
> + newaddr = rel->addend + offset - CONFIG_SYS_TEXT_BASE;
> #else
> - newaddr = *p - lastoff + offset;
> + newaddr = *p - lastoff + offset;
> #endif
> + break;
> +#ifdef R_ABSOLUTE
> + case R_ABSOLUTE: {
> + ulong symidx = rel->info >> SYM_INDEX;
> + extern struct dyn_sym __dyn_sym_start[];
> + newaddr = __dyn_sym_start[symidx].addr + offset;
> + break;
> + }
> +#endif
> + default:
> + continue;
> + }
>
> /* Check if the relocation is inside bounds */
> if (map && ((newaddr < map->virtual_start) ||
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* [U-Boot] [PATCH 3/8] efi_loader: selftest: Do not build relocation tests for risc-v
2018-04-18 13:40 ` [U-Boot] [PATCH 3/8] efi_loader: selftest: Do not build relocation tests for risc-v Alexander Graf
2018-04-18 15:48 ` Heinrich Schuchardt
@ 2018-04-19 5:57 ` Heinrich Schuchardt
1 sibling, 0 replies; 14+ messages in thread
From: Heinrich Schuchardt @ 2018-04-19 5:57 UTC (permalink / raw)
To: u-boot
On 04/18/2018 03:40 PM, Alexander Graf wrote:
> The relocation selftest doesn't compile for me on RISC-V. Disable for now.
This is the command that fails:
riscv64-linux-gnu-ld.bfd -nostdlib -znocombreloc -T ./arch/riscv/lib/ \
-shared -Bsymbolic lib/efi_selftest/efi_selftest_miniapp_return.o \
arch/riscv/lib/ -o lib/efi_selftest/efi_selftest_miniapp_return_efi.so
riscv64-linux-gnu-ld.bfd: read in flex scanner failed
In arch/riscv/lib/ the linker scripts (*.lds) are missing.
So I suggest instead of not building the unit test the missing files
should be created.
Best regards
Heinrich
>
> Signed-off-by: Alexander Graf <agraf@suse.de>
> ---
> lib/efi_selftest/Makefile | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/lib/efi_selftest/Makefile b/lib/efi_selftest/Makefile
> index 31b444fc8b..ede7831449 100644
> --- a/lib/efi_selftest/Makefile
> +++ b/lib/efi_selftest/Makefile
> @@ -35,9 +35,10 @@ ifeq ($(CONFIG_BLK)$(CONFIG_PARTITIONS),yy)
> obj-$(CONFIG_CMD_BOOTEFI_SELFTEST) += efi_selftest_block_device.o
> endif
>
> -# TODO: As of v2018.01 the relocation code for the EFI application cannot
> -# be built on x86_64.
> +# TODO: As of v2018.05 the relocation code for the EFI application cannot
> +# be built on x86_64 / RISC-V.
> ifeq ($(CONFIG_X86_64),)
> +ifeq ($(CONFIG_RISCV),)
>
> ifneq ($(CONFIG_CMD_BOOTEFI_SELFTEST),)
>
> @@ -63,6 +64,8 @@ $(obj)/efi_selftest_startimage_exit.o: $(obj)/efi_miniapp_file_image_exit.h
>
> $(obj)/efi_selftest_startimage_return.o: $(obj)/efi_miniapp_file_image_return.h
>
> -endif
> +endif # CONFIG_CMD_BOOTEFI_SELFTEST
>
> -endif
> +endif # !CONFIG_RISCV
> +
> +endif # !CONFIG_X86_64
>
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2018-04-19 5:57 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-18 13:40 [U-Boot] [PATCH 0/8] riscv: Enable efi_loader support Alexander Graf
2018-04-18 13:40 ` [U-Boot] [PATCH 1/8] riscv: Add setjmp/longjmp code Alexander Graf
2018-04-18 13:40 ` [U-Boot] [PATCH 2/8] riscv: Enable function sections Alexander Graf
2018-04-18 13:40 ` [U-Boot] [PATCH 3/8] efi_loader: selftest: Do not build relocation tests for risc-v Alexander Graf
2018-04-18 15:48 ` Heinrich Schuchardt
2018-04-18 16:41 ` Alexander Graf
2018-04-19 5:57 ` Heinrich Schuchardt
2018-04-18 13:40 ` [U-Boot] [PATCH 4/8] riscv: Add board_quiesce_devices stub Alexander Graf
2018-04-18 13:40 ` [U-Boot] [PATCH 5/8] efi_loader: Use EFI_CACHELINE_SIZE in the image loader too Alexander Graf
2018-04-18 13:40 ` [U-Boot] [PATCH 6/8] distro: Extend with RISC-V defines Alexander Graf
2018-04-18 15:43 ` Heinrich Schuchardt
2018-04-18 13:40 ` [U-Boot] [PATCH 7/8] riscv: nx25: Enable distro boot Alexander Graf
2018-04-18 13:40 ` [U-Boot] [PATCH 8/8] efi_loader: Enable RISC-V support Alexander Graf
2018-04-19 5:14 ` Heinrich Schuchardt
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.