Skip to contentSkip to conversation

x86: efi: payload: Various fixes

PATCH New Bin Meng 2 participants 20 messages Jun 22, 2018 – Jun 24, 2018 x86

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

cover x86: efi: payload: Various fixes

This series includes 3 patches that were previously sent to ML but not applied, along with some new patches with various fixes on efi x86 payload support.

For [01: efi.h: Do not use config options] and [02: x86: Change __kernel_size_t conditionals to use compiler provided defines], the changes are mainly adding some comments to describe the changes in more details.

This series is available at u-boot-x86/efi2-working for testing.

Alexander Graf (1):
efi.h: Do not use config options

Bin Meng (5):
x86: Change __kernel_size_t conditionals to use compiler provided
defines
efi: stub: Move the use_uart assignment immediately after
exit_boot_services() call
x86: efi-x86_payload: Enable PRE_CONSOLE_BUFFER
x86: efi: payload: Count in conventional memory above 4GB in DRAM bank
cmd: efi: Fix wrong memory descriptor end address

 arch/x86/cpu/efi/payload.c          |  3 +--
 arch/x86/include/asm/posix_types.h  |  3 ++-
 cmd/efi.c                           |  2 +-
 configs/efi-x86_payload32_defconfig |  2 ++
 configs/efi-x86_payload64_defconfig |  2 ++
 include/efi.h                       | 24 +++++++++++-------------
 lib/efi/Makefile                    |  4 ++--
 lib/efi/efi_stub.c                  |  6 +++---
 8 files changed, 24 insertions(+), 22 deletions(-)
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH 1/6 efi.h: Do not use config options

From: Alexander Graf <[email protected]>

Currently efi.h determines a few bits of its environment according to config options. This falls apart with the efi stub support which may result in efi.h getting pulled into the stub as well as real U-Boot code. In that case, one may be 32bit while the other one is 64bit.

This patch changes the conditionals to use compiler provided defines instead. That way we always adhere to the build environment we're in and the definitions adjust automatically.

[bmeng: added some comments to describe the __x86_64__ check]

---

 include/efi.h    | 24 +++++++++++-------------
 lib/efi/Makefile |  4 ++--
 2 files changed, 13 insertions(+), 15 deletions(-)
include/efi.h +11 -13
index 2448dde..0fe15e6 100644
@@ -19,12 +19,19 @@
 #include <linux/string.h>
 #include <linux/types.h>
 
-#if CONFIG_EFI_STUB_64BIT || (!defined(CONFIG_EFI_STUB) && defined(__x86_64__))
-/* EFI uses the Microsoft ABI which is not the default for GCC */
+/*
+ * EFI on x86_64 uses the Microsoft ABI which is not the default for GCC.
+ *
+ * There are two scenarios for EFI on x86_64: building a 64-bit EFI stub
+ * codes (CONFIG_EFI_STUB_64BIT) and building a 64-bit U-Boot (CONFIG_X86_64).
+ * Either needs to be properly built with the '-m64' compiler flag, and hence
+ * it is enough to only check the compiler provided define __x86_64__ here.
+ */
+#ifdef __x86_64__
 #define EFIAPI __attribute__((ms_abi))
 #else
 #define EFIAPI asmlinkage
-#endif
+#endif /* __x86_64__ */
 
 struct efi_device_path;
 
@@ -32,16 +39,7 @@ typedef struct {
 	u8 b[16];
 } efi_guid_t;
 
-#define EFI_BITS_PER_LONG	BITS_PER_LONG
-
-/*
- * With 64-bit EFI stub, EFI_BITS_PER_LONG has to be 64. EFI_STUB is set
- * in lib/efi/Makefile, when building the stub.
- */
-#if defined(CONFIG_EFI_STUB_64BIT) && defined(EFI_STUB)
-#undef EFI_BITS_PER_LONG
-#define EFI_BITS_PER_LONG	64
-#endif
+#define EFI_BITS_PER_LONG	(sizeof(long) * 8)
 
 /* Bit mask for EFI status code with error */
 #define EFI_ERROR_MASK (1UL << (EFI_BITS_PER_LONG - 1))
lib/efi/Makefile +2 -2
index f1a3929..a790d2d 100644
@@ -7,11 +7,11 @@ obj-$(CONFIG_EFI_STUB) += efi_info.o
 
 CFLAGS_REMOVE_efi_stub.o := -mregparm=3 \
 	$(if $(CONFIG_EFI_STUB_64BIT),-march=i386 -m32)
-CFLAGS_efi_stub.o := -fpic -fshort-wchar -DEFI_STUB \
+CFLAGS_efi_stub.o := -fpic -fshort-wchar \
 	$(if $(CONFIG_EFI_STUB_64BIT),-m64)
 CFLAGS_REMOVE_efi.o := -mregparm=3 \
 	$(if $(CONFIG_EFI_STUB_64BIT),-march=i386 -m32)
-CFLAGS_efi.o := -fpic -fshort-wchar -DEFI_STUB \
+CFLAGS_efi.o := -fpic -fshort-wchar \
 	$(if $(CONFIG_EFI_STUB_64BIT),-m64)
 
 extra-$(CONFIG_EFI_STUB) += efi_stub.o efi.o
Signature · 1 line
2.7.4
#2 lore raw

PATCH 1/6 efi.h: Do not use config options

Quoted 17 lines · Bin Meng

From: Alexander Graf <[email protected]>

Currently efi.h determines a few bits of its environment according to config options. This falls apart with the efi stub support which may result in efi.h getting pulled into the stub as well as real U-Boot code. In that case, one may be 32bit while the other one is 64bit.

This patch changes the conditionals to use compiler provided defines instead. That way we always adhere to the build environment we're in and the definitions adjust automatically.

[bmeng: added some comments to describe the __x86_64__ check]
Quoted 5 lines

---

 include/efi.h    | 24 +++++++++++-------------
 lib/efi/Makefile |  4 ++--
 2 files changed, 13 insertions(+), 15 deletions(-)
author
#3 lore raw

PATCH 1/6 efi.h: Do not use config options

Quoted 18 lines · Simon Glass
Quoted 17 lines · Bin Meng

From: Alexander Graf <[email protected]>

Currently efi.h determines a few bits of its environment according to config options. This falls apart with the efi stub support which may result in efi.h getting pulled into the stub as well as real U-Boot code. In that case, one may be 32bit while the other one is 64bit.

This patch changes the conditionals to use compiler provided defines instead. That way we always adhere to the build environment we're in and the definitions adjust automatically.

[bmeng: added some comments to describe the __x86_64__ check]
Quoted 7 lines
Quoted 5 lines

---

 include/efi.h    | 24 +++++++++++-------------
 lib/efi/Makefile |  4 ++--
 2 files changed, 13 insertions(+), 15 deletions(-)

applied to u-boot-x86, thanks!

author
#4 lore raw

PATCH 2/6 x86: Change __kernel_size_t conditionals to use compiler provided defines

In reply to Bin Meng

Since commit bb0bb91cf0aa ("efi_stub: Use efi_uintn_t"), EFI x86 64-bit payload does not work anymore. The call to GetMemoryMap() in efi_stub.c fails with return code EFI_INVALID_PARAMETER. Since the payload itself is still 32-bit U-Boot, efi_uintn_t gets wrongly interpreted as int, but it should actually be long in a 64-bit EFI environment.

This changes the x86 __kernel_size_t conditionals to use compiler provided defines instead. That way we always adhere to the build environment we're in and the definitions adjust automatically.

Fixes bb0bb91cf0aa ("efi_stub: Use efi_uintn_t")

---

 arch/x86/include/asm/posix_types.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/include/asm/posix_types.h +2 -1
index 717f6cb..dbcea7f 100644
@@ -16,7 +16,8 @@ typedef int		__kernel_pid_t;
 typedef unsigned short	__kernel_ipc_pid_t;
 typedef unsigned short	__kernel_uid_t;
 typedef unsigned short	__kernel_gid_t;
-#if CONFIG_IS_ENABLED(X86_64)
+/* checking against __x86_64__ covers both 64-bit EFI stub and 64-bit U-Boot */
+#if defined(__x86_64__)
 typedef unsigned long	__kernel_size_t;
 typedef long		__kernel_ssize_t;
 #else
Signature · 1 line
2.7.4
#5 lore raw

PATCH 2/6 x86: Change __kernel_size_t conditionals to use compiler provided defines

Quoted 11 lines · Bin Meng

Since commit bb0bb91cf0aa ("efi_stub: Use efi_uintn_t"), EFI x86 64-bit payload does not work anymore. The call to GetMemoryMap() in efi_stub.c fails with return code EFI_INVALID_PARAMETER. Since the payload itself is still 32-bit U-Boot, efi_uintn_t gets wrongly interpreted as int, but it should actually be long in a 64-bit EFI environment.

This changes the x86 __kernel_size_t conditionals to use compiler provided defines instead. That way we always adhere to the build environment we're in and the definitions adjust automatically.

Quoted 6 lines
Fixes bb0bb91cf0aa ("efi_stub: Use efi_uintn_t")

---

 arch/x86/include/asm/posix_types.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
author
#6 lore raw

PATCH 2/6 x86: Change __kernel_size_t conditionals to use compiler provided defines

Quoted 12 lines · Simon Glass
Quoted 11 lines · Bin Meng

Since commit bb0bb91cf0aa ("efi_stub: Use efi_uintn_t"), EFI x86 64-bit payload does not work anymore. The call to GetMemoryMap() in efi_stub.c fails with return code EFI_INVALID_PARAMETER. Since the payload itself is still 32-bit U-Boot, efi_uintn_t gets wrongly interpreted as int, but it should actually be long in a 64-bit EFI environment.

This changes the x86 __kernel_size_t conditionals to use compiler provided defines instead. That way we always adhere to the build environment we're in and the definitions adjust automatically.

Quoted 8 lines
Quoted 6 lines
Fixes bb0bb91cf0aa ("efi_stub: Use efi_uintn_t")

---

 arch/x86/include/asm/posix_types.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

applied to u-boot-x86, thanks!

author
#7 lore raw

PATCH 3/6 efi: stub: Move the use_uart assignment immediately after exit_boot_services() call

In reply to Bin Meng

The use_uart assignment should follow immediately after the call to exit_boot_services(), in case we want some debug output after that.

---

 lib/efi/efi_stub.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/efi/efi_stub.c +3 -3
index 262fc56..1b495ec 100644
@@ -361,14 +361,14 @@ efi_status_t EFIAPI efi_main(efi_handle_t image,
 		}
 	}
 
+	/* The EFI UART won't work now, switch to a debug one */
+	use_uart = true;
+
 	map.version = version;
 	map.desc_size = desc_size;
 	add_entry_addr(priv, EFIET_MEMORY_MAP, &map, sizeof(map), desc, size);
 	add_entry_addr(priv, EFIET_END, NULL, 0, 0, 0);
 
-	/* The EFI UART won't work now, switch to a debug one */
-	use_uart = true;
-
 	memcpy((void *)CONFIG_SYS_TEXT_BASE, _binary_u_boot_bin_start,
 	       (ulong)_binary_u_boot_bin_end -
 	       (ulong)_binary_u_boot_bin_start);
Signature · 1 line
2.7.4
#8 lore raw

PATCH 3/6 efi: stub: Move the use_uart assignment immediately after exit_boot_services() call

Quoted 8 lines · Bin Meng

The use_uart assignment should follow immediately after the call to exit_boot_services(), in case we want some debug output after that.

---

 lib/efi/efi_stub.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
author
#9 lore raw

PATCH 3/6 efi: stub: Move the use_uart assignment immediately after exit_boot_services() call

Quoted 11 lines · Simon Glass
Quoted 8 lines · Bin Meng

The use_uart assignment should follow immediately after the call to exit_boot_services(), in case we want some debug output after that.

---

 lib/efi/efi_stub.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

applied to u-boot-x86, thanks!

author
#10 lore raw

PATCH 4/6 x86: efi-x86_payload: Enable PRE_CONSOLE_BUFFER

In reply to Bin Meng

Enable PRE_CONSOLE_BUFFER so that the full boot output can be viewed on the video console for the EFI payload.

---

 configs/efi-x86_payload32_defconfig | 2 ++
 configs/efi-x86_payload64_defconfig | 2 ++
 2 files changed, 4 insertions(+)
configs/efi-x86_payload32_defconfig +2 -0
index 7f0cab0..5b6f125 100644
@@ -6,6 +6,8 @@ CONFIG_FIT=y
 CONFIG_FIT_SIGNATURE=y
 CONFIG_USE_BOOTARGS=y
 CONFIG_BOOTARGS="root=/dev/sdb3 init=/sbin/init rootwait ro"
+CONFIG_PRE_CONSOLE_BUFFER=y
+CONFIG_PRE_CON_BUF_ADDR=0x100000
 CONFIG_SYS_CONSOLE_INFO_QUIET=y
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_LAST_STAGE_INIT=y
configs/efi-x86_payload64_defconfig +2 -0
index 8d7f3f0..71fdb5c 100644
@@ -6,6 +6,8 @@ CONFIG_FIT=y
 CONFIG_FIT_SIGNATURE=y
 CONFIG_USE_BOOTARGS=y
 CONFIG_BOOTARGS="root=/dev/sdb3 init=/sbin/init rootwait ro"
+CONFIG_PRE_CONSOLE_BUFFER=y
+CONFIG_PRE_CON_BUF_ADDR=0x100000
 CONFIG_SYS_CONSOLE_INFO_QUIET=y
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_LAST_STAGE_INIT=y
Signature · 1 line
2.7.4
#11 lore raw

PATCH 4/6 x86: efi-x86_payload: Enable PRE_CONSOLE_BUFFER

Quoted 9 lines · Bin Meng

Enable PRE_CONSOLE_BUFFER so that the full boot output can be viewed on the video console for the EFI payload.

---

 configs/efi-x86_payload32_defconfig | 2 ++
 configs/efi-x86_payload64_defconfig | 2 ++
 2 files changed, 4 insertions(+)
author
#12 lore raw

PATCH 4/6 x86: efi-x86_payload: Enable PRE_CONSOLE_BUFFER

Quoted 4 lines · Simon Glass
Quoted 3 lines · Bin Meng

Enable PRE_CONSOLE_BUFFER so that the full boot output can be viewed on the video console for the EFI payload.

Quoted 8 lines
Quoted 6 lines

---

 configs/efi-x86_payload32_defconfig | 2 ++
 configs/efi-x86_payload64_defconfig | 2 ++
 2 files changed, 4 insertions(+)

applied to u-boot-x86, thanks!

author
#13 lore raw

PATCH 5/6 x86: efi: payload: Count in conventional memory above 4GB in DRAM bank

In reply to Bin Meng

At present in dram_init_banksize() it ignores conventional memory below 4GB. This leads to wrong DRAM size is printed during boot. Remove such limitation.

---

 arch/x86/cpu/efi/payload.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/x86/cpu/efi/payload.c +1 -2
index e3f0f82..4649bfe 100644
@@ -109,11 +109,10 @@ int dram_init_banksize(void)
 	     desc < end && num_banks < CONFIG_NR_DRAM_BANKS;
 	     desc = efi_get_next_mem_desc(map, desc)) {
 		/*
-		 * We only use conventional memory below 4GB, and ignore
+		 * We only use conventional memory and ignore
 		 * anything less than 1MB.
 		 */
 		if (desc->type != EFI_CONVENTIONAL_MEMORY ||
-		    desc->physical_start >= 1ULL << 32 ||
 		    (desc->num_pages << EFI_PAGE_SHIFT) < 1 << 20)
 			continue;
 		gd->bd->bi_dram[num_banks].start = desc->physical_start;
Signature · 1 line
2.7.4
#14 lore raw

PATCH 5/6 x86: efi: payload: Count in conventional memory above 4GB in DRAM bank

Quoted 9 lines · Bin Meng

At present in dram_init_banksize() it ignores conventional memory below 4GB. This leads to wrong DRAM size is printed during boot. Remove such limitation.

---

 arch/x86/cpu/efi/payload.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
author
#15 lore raw

PATCH 5/6 x86: efi: payload: Count in conventional memory above 4GB in DRAM bank

Quoted 3 lines · Simon Glass
Quoted 2 lines · Bin Meng

At present in dram_init_banksize() it ignores conventional memory below 4GB. This leads to wrong DRAM size is printed during boot.

This should be "above" 4GB.

Quoted 9 lines
Quoted 7 lines

Remove such limitation.

---

 arch/x86/cpu/efi/payload.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Fixed the commit message, and

applied to u-boot-x86, thanks!

author
#16 lore raw

PATCH 6/6 cmd: efi: Fix wrong memory descriptor end address

In reply to Bin Meng

Each entry of the EFI memory descriptors occupies map->desc_size, not sizeof(struct efi_mem_desc).

---

 cmd/efi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
cmd/efi.c +1 -1
index 2511c6c..6c1eb88 100644
@@ -83,7 +83,7 @@ void *efi_build_mem_table(struct efi_entry_memmap *map, int size, bool skip_bs)
 	prev = NULL;
 	addr = 0;
 	dest = base;
-	end = base + count;
+	end = (struct efi_mem_desc *)((ulong)base + count * map->desc_size);
 	for (desc = base; desc < end; desc = efi_get_next_mem_desc(map, desc)) {
 		bool merge = true;
 		int type = desc->type;
Signature · 1 line
2.7.4
author
#18 lore raw

PATCH 6/6 cmd: efi: Fix wrong memory descriptor end address

Quoted 4 lines · Simon Glass
Quoted 3 lines · Bin Meng

Each entry of the EFI memory descriptors occupies map->desc_size, not sizeof(struct efi_mem_desc).

Quoted 8 lines
Quoted 6 lines

---

 cmd/efi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

applied to u-boot-x86, thanks!

author
#19 lore raw

cover x86: efi: payload: Various fixes

In reply to Bin Meng

Hi Simon,

Quoted 4 lines · Bin Meng

This series includes 3 patches that were previously sent to ML but not applied, along with some new patches with various fixes on efi x86 payload support.

I see your have reviewed the other 3 patches. Thanks a lot!

Quoted 5 lines

For [01: efi.h: Do not use config options] and [02: x86: Change __kernel_size_t conditionals to use compiler provided defines], the changes are mainly adding some comments to describe the changes in more details.

For patch [01] & [02], does the added comments look good to you?

Quoted 2 lines

This series is available at u-boot-x86/efi2-working for testing.

Regards,
Bin