aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--arch/arm/lib/crt0_aarch64_efi.S4
-rw-r--r--arch/arm/lib/crt0_arm_efi.S48
-rw-r--r--arch/arm/lib/elf_arm_efi.lds28
-rw-r--r--arch/riscv/lib/crt0_riscv_efi.S4
-rw-r--r--include/asm-generic/pe.h3
-rw-r--r--lib/efi_driver/Makefile1
-rw-r--r--lib/efi_driver/efi_reset_riscv.c29
-rw-r--r--lib/efi_loader/Kconfig2
8 files changed, 100 insertions, 19 deletions
diff --git a/arch/arm/lib/crt0_aarch64_efi.S b/arch/arm/lib/crt0_aarch64_efi.S
index 3c2cef6ec73..fe6eca576ec 100644
--- a/arch/arm/lib/crt0_aarch64_efi.S
+++ b/arch/arm/lib/crt0_aarch64_efi.S
@@ -66,7 +66,11 @@ extra_header_fields:
.long _start - ImageBase /* SizeOfHeaders */
.long 0 /* CheckSum */
.short IMAGE_SUBSYSTEM_EFI_APPLICATION /* Subsystem */
+#if CONFIG_VENDOR_EFI
.short 0 /* DllCharacteristics */
+#else
+ .short IMAGE_DLLCHARACTERISTICS_NX_COMPAT
+#endif
.quad 0 /* SizeOfStackReserve */
.quad 0 /* SizeOfStackCommit */
.quad 0 /* SizeOfHeapReserve */
diff --git a/arch/arm/lib/crt0_arm_efi.S b/arch/arm/lib/crt0_arm_efi.S
index 75ee37b7d31..b5dfd4e3819 100644
--- a/arch/arm/lib/crt0_arm_efi.S
+++ b/arch/arm/lib/crt0_arm_efi.S
@@ -23,7 +23,7 @@ pe_header:
.long IMAGE_NT_SIGNATURE /* 'PE' */
coff_header:
.short IMAGE_FILE_MACHINE_THUMB /* Mixed ARM/Thumb */
- .short 2 /* nr_sections */
+ .short 3 /* nr_sections */
.long 0 /* TimeDateStamp */
.long 0 /* PointerToSymbolTable */
.long 0 /* NumberOfSymbols */
@@ -65,7 +65,11 @@ extra_header_fields:
.long _start - image_base /* SizeOfHeaders */
.long 0 /* CheckSum */
.short IMAGE_SUBSYSTEM_EFI_APPLICATION /* Subsystem */
+#if CONFIG_VENDOR_EFI
.short 0 /* DllCharacteristics */
+#else
+ .short IMAGE_DLLCHARACTERISTICS_NX_COMPAT
+#endif
.long 0 /* SizeOfStackReserve */
.long 0 /* SizeOfStackCommit */
.long 0 /* SizeOfHeapReserve */
@@ -98,31 +102,53 @@ section_table:
.long 0 /* PointerToLineNumbers */
.short 0 /* NumberOfRelocations */
.short 0 /* NumberOfLineNumbers */
- .long 0x42100040 /* Characteristics (section flags) */
+ /* Characteristics (section flags) */
+ .long (IMAGE_SCN_MEM_READ | \
+ IMAGE_SCN_MEM_DISCARDABLE | \
+ IMAGE_SCN_CNT_INITIALIZED_DATA)
.ascii ".text"
.byte 0
.byte 0
.byte 0 /* end of 0 padding of section name */
- .long _edata - _start /* VirtualSize */
+ .long _text_size /* VirtualSize */
.long _start - image_base /* VirtualAddress */
- .long _edata - _start /* SizeOfRawData */
+ .long _text_size /* SizeOfRawData */
.long _start - image_base /* PointerToRawData */
+ .long 0 /* PointerToRelocations */
+ .long 0 /* PointerToLineNumbers */
+ .short 0 /* NumberOfRelocations */
+ .short 0 /* NumberOfLineNumbers */
+ /* Characteristics (section flags) */
+ .long (IMAGE_SCN_MEM_READ | \
+ IMAGE_SCN_MEM_EXECUTE | \
+ IMAGE_SCN_CNT_CODE)
- .long 0 /* PointerToRelocations (0 for executables) */
- .long 0 /* PointerToLineNumbers (0 for executables) */
- .short 0 /* NumberOfRelocations (0 for executables) */
- .short 0 /* NumberOfLineNumbers (0 for executables) */
- .long 0xe0500020 /* Characteristics (section flags) */
+ .ascii ".data"
+ .byte 0
+ .byte 0
+ .byte 0 /* end of 0 padding of section name */
+ .long _data_size /* VirtualSize */
+ .long _data - image_base /* VirtualAddress */
+ .long _data_size /* SizeOfRawData */
+ .long _data - image_base /* PointerToRawData */
+ .long 0 /* PointerToRelocations */
+ .long 0 /* PointerToLineNumbers */
+ .short 0 /* NumberOfRelocations */
+ .short 0 /* NumberOfLineNumbers */
+ /* Characteristics (section flags) */
+ .long (IMAGE_SCN_MEM_WRITE | \
+ IMAGE_SCN_MEM_READ | \
+ IMAGE_SCN_CNT_INITIALIZED_DATA)
- .align 9
+ .align 12
_start:
stmfd sp!, {r0-r2, lr}
adr r1, .L_DYNAMIC
ldr r0, [r1]
add r1, r0, r1
- adr r0, image_base
+ adrl r0, image_base
bl _relocate
teq r0, #0
bne 0f
diff --git a/arch/arm/lib/elf_arm_efi.lds b/arch/arm/lib/elf_arm_efi.lds
index 767ebda6351..41440594aa6 100644
--- a/arch/arm/lib/elf_arm_efi.lds
+++ b/arch/arm/lib/elf_arm_efi.lds
@@ -7,6 +7,12 @@
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)
+
+PHDRS
+{
+ data PT_LOAD FLAGS(3); /* PF_W | PF_X */
+}
+
ENTRY(_start)
SECTIONS
{
@@ -18,11 +24,13 @@ SECTIONS
*(.gnu.linkonce.t.*)
*(.srodata)
*(.rodata*)
+ . = ALIGN(16);
+ *(.dynamic);
. = ALIGN(512);
}
_etext = .;
_text_size = . - _text;
- .dynamic : { *(.dynamic) }
+ . = ALIGN(4096);
.data : {
_data = .;
*(.sdata)
@@ -47,14 +55,20 @@ SECTIONS
. = ALIGN(512);
_bss_end = .;
_edata = .;
- }
- .rel.dyn : { *(.rel.dyn) }
- .rel.plt : { *(.rel.plt) }
- .rel.got : { *(.rel.got) }
- .rel.data : { *(.rel.data) *(.rel.data*) }
- _data_size = . - _etext;
+ } :data
+ _data_size = . - _data;
/DISCARD/ : {
+ /*
+ * We don't support relocations. These would have to be
+ * translated from ELF to PE format and added to the .reloc
+ * section.
+ */
+ *(.rel.dyn)
+ *(.rel.plt)
+ *(.rel.got)
+ *(.rel.data)
+ *(.rel.data*)
*(.rel.reloc)
*(.eh_frame)
*(.note.GNU-stack)
diff --git a/arch/riscv/lib/crt0_riscv_efi.S b/arch/riscv/lib/crt0_riscv_efi.S
index 46b08552371..c7a4559eac8 100644
--- a/arch/riscv/lib/crt0_riscv_efi.S
+++ b/arch/riscv/lib/crt0_riscv_efi.S
@@ -96,7 +96,11 @@ extra_header_fields:
.long _start - ImageBase /* SizeOfHeaders */
.long 0 /* CheckSum */
.short IMAGE_SUBSYSTEM_EFI_APPLICATION /* Subsystem */
+#if CONFIG_VENDOR_EFI
.short 0 /* DllCharacteristics */
+#else
+ .short IMAGE_DLLCHARACTERISTICS_NX_COMPAT
+#endif
#if __riscv_xlen == 32
.long 0 /* SizeOfStackReserve */
.long 0 /* SizeOfStackCommit */
diff --git a/include/asm-generic/pe.h b/include/asm-generic/pe.h
index b9d674b6da4..cd5b6ad62bf 100644
--- a/include/asm-generic/pe.h
+++ b/include/asm-generic/pe.h
@@ -51,6 +51,9 @@
#define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12
#define IMAGE_SUBSYSTEM_EFI_ROM 13
+/* DLL characteristics */
+#define IMAGE_DLLCHARACTERISTICS_NX_COMPAT 0x100
+
/* Section flags */
#define IMAGE_SCN_CNT_CODE 0x00000020
#define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040
diff --git a/lib/efi_driver/Makefile b/lib/efi_driver/Makefile
index f2b6c05cc24..0da20fe91d3 100644
--- a/lib/efi_driver/Makefile
+++ b/lib/efi_driver/Makefile
@@ -9,3 +9,4 @@ obj-y += efi_uclass.o
ifeq ($(CONFIG_PARTITIONS),y)
obj-y += efi_block_device.o
endif
+obj-$(CONFIG_SYSRESET_SBI) += efi_reset_riscv.o
diff --git a/lib/efi_driver/efi_reset_riscv.c b/lib/efi_driver/efi_reset_riscv.c
new file mode 100644
index 00000000000..89b23522e95
--- /dev/null
+++ b/lib/efi_driver/efi_reset_riscv.c
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <efi_loader.h>
+#include <asm/sbi.h>
+
+void __efi_runtime EFIAPI efi_reset_system(enum efi_reset_type reset_type,
+ efi_status_t reset_status,
+ unsigned long data_size,
+ void *reset_data)
+{
+ register unsigned long eid asm("a7") = SBI_EXT_SRST;
+ register unsigned long fid asm("a6") = SBI_EXT_SRST_RESET;
+ register unsigned long type asm("a0");
+ register unsigned long reason asm("a1") = SBI_SRST_RESET_REASON_NONE;
+
+ switch (reset_type) {
+ case EFI_RESET_WARM:
+ type = SBI_SRST_RESET_TYPE_WARM_REBOOT;
+ break;
+ case EFI_RESET_SHUTDOWN:
+ type = SBI_SRST_RESET_TYPE_SHUTDOWN;
+ break;
+ default:
+ type = SBI_SRST_RESET_TYPE_COLD_REBOOT;
+ break;
+ }
+ asm volatile ("ecall\n"
+ : : "r" (eid), "r" (fid), "r" (type), "r" (reason));
+}
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index db5571de1d9..a7c3e05c13a 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -366,7 +366,7 @@ config EFI_HAVE_RUNTIME_RESET
bool
default y
depends on ARCH_BCM283X || FSL_LAYERSCAPE || PSCI_RESET || \
- SANDBOX || SYSRESET_X86
+ SANDBOX || SYSRESET_SBI || SYSRESET_X86
config EFI_GRUB_ARM32_WORKAROUND
bool "Workaround for GRUB on 32bit ARM"