efi_loader: simplify ifdefs
Subsystems (4)
PATCH v3 1/3 efi_loader: simplify ifdefs
From: Stephen Warren <[email protected]>
Use CONFIG_IS_ENABLED(EFI_LOADER) to avoid explicitly checking CONFIG_SPL too. This simplifies the conditional.
---
v3: New patch.
--- arch/arm/cpu/armv8/fsl-layerscape/cpu.c | 2 +- arch/arm/cpu/armv8/fsl-layerscape/fdt.c | 2 +- arch/x86/lib/e820.c | 4 ++-- include/efi_loader.h | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-)
arch/arm/cpu/armv8/fsl-layerscape/cpu.c +1 -1
@@ -835,7 +835,7 @@ int dram_init_banksize(void)return 0 ; } -#if defined(CONFIG_EFI_LOADER ) && !defined(CONFIG_SPL_BUILD ) +#if CONFIG_IS_ENABLED (EFI_LOADER )void efi_add_known_memory (void ) {int i;
arch/arm/cpu/armv8/fsl-layerscape/fdt.c +1 -1
@@ -135,7 +135,7 @@ remove_psci_node:fdt_add_mem_rsv (blob, (uintptr_t )&secondary_boot_code, *boot_code_size); -#if defined(CONFIG_EFI_LOADER ) && !defined(CONFIG_SPL_BUILD ) +#if CONFIG_IS_ENABLED (EFI_LOADER )efi_add_memory_map ((uintptr_t )&secondary_boot_code,ALIGN (*boot_code_size,EFI_PAGE_SIZE ) >>EFI_PAGE_SHIFT ,EFI_RESERVED_MEMORY_TYPE , false);
arch/x86/lib/e820.c +2 -2
@@ -36,7 +36,7 @@ __weak unsigned int install_e820_map(unsigned int max_entries,return 4 ; } -#if defined(CONFIG_EFI_LOADER ) && !defined(CONFIG_SPL_BUILD ) +#if CONFIG_IS_ENABLED (EFI_LOADER )void efi_add_known_memory (void ) {struct e820_entry e820[E820MAX ];
@@ -72,4 +72,4 @@ void efi_add_known_memory(void) efi_add_memory_map(start, pages, type, false); } } -#endif /* defined(EFI_LOADER) && !defined(CONFIG_SPL_BUILD) */ +#endif /* CONFIG_IS_ENABLED(EFI_LOADER) */
include/efi_loader.h +3 -3
@@ -13,7 +13,7 @@#include <efi_api.h> /* No need for efi loader support in SPL */ -#if defined(CONFIG_EFI_LOADER ) && !defined(CONFIG_SPL_BUILD ) +#if CONFIG_IS_ENABLED (EFI_LOADER )#include <linux/list.h>
@@ -460,7 +460,7 @@ efi_status_t EFIAPI efi_set_variable(u16 *variable_name, efi_guid_t *vendor,void *efi_bootmgr_load (struct efi_device_path **device_path,struct efi_device_path **file_path); -#else /* defined(EFI_LOADER) && !defined(CONFIG_SPL_BUILD) */ +#else /* CONFIG_IS_ENABLED(EFI_LOADER) */ /* Without CONFIG_EFI_LOADER we don't have a runtime section, stub it out */ #define __efi_runtime_data
@@ -477,6 +477,6 @@ static inline void efi_set_bootdev(const char *dev, const char *devnr,static inline void efi_net_set_dhcp_ack (void *pkt,int len) { }static inline void efi_print_image_infos (void *pc) { } -#endif /* CONFIG_EFI_LOADER && !CONFIG_SPL_BUILD */ +#endif /* CONFIG_IS_ENABLED(EFI_LOADER) */ #endif /* _EFI_LOADER_H */
Signature · 1 line
2.18.0
PATCH v3 2/3 ARM: tegra: reserve unmapped RAM so EFI doesn't use it
From: Stephen Warren <[email protected]>
Tegra U-Boot ensures that board_get_usable_ram_top() never returns a value over 4GB, since some peripherals can't access such addresses. However, on systems with more than 2GB of RAM, RAM bank 1 does describe this extra RAM, so that Linux (or whatever OS) can use it, subject to DMA limitations. Since board_get_usable_ram_top() points at the top of RAM bank 0, the memory locations describes by RAM bank 1 are not mapped by U-Boot's MMU configuration, and so cannot be used for anything.
For some completely inexplicable reason, U-Boot's EFI support ignores the value returned by board_get_usable_ram_top(), and EFI memory allocation routines will return values above U-Boot's RAM top. This causes U-Boot to crash when it accesses that RAM, since it isn't mapped by the MMU. One use-case where this happens is TFTP download of a file on Jetson TX1 (p2371-2180).
This change explicitly tells the EFI code that this extra RAM should not be used, thus avoiding the crash.
A previous attempt to make EFI honor board_get_usable_ram_top() was rejected. So, this patch will need to be replicated for any board that implements board_get_usable_ram_top().
---
v3:
- Use shift not divide for page count calculation.
- Enhance ifdef to avoid EFI references from SPL builds. v2:
- Don't hard-code EFI page size.
- Register RAM as a boot services data rather than reserved.
--- arch/arm/mach-tegra/board2.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
arch/arm/mach-tegra/board2.c +14 -0
@@ -6,6 +6,7 @@#include <common.h> #include <dm.h> +#include <efi_loader.h> #include <errno.h> #include <ns16550.h> #include <usb.h>
@@ -210,6 +211,19 @@ int board_early_init_f(void)int board_late_init (void ) { +#if CONFIG_IS_ENABLED (EFI_LOADER ) +if (gd->bd->bi_dram[1 ].start) { +/* +* Only bank 0 is below board_get_usable_ram_top(), so all of +* bank 1 is not mapped by the U-Boot MMU configuration, and so +* we must prevent EFI from using it. +*/ +efi_add_memory_map (gd->bd->bi_dram[1 ].start, + gd->bd->bi_dram[1 ].size >>EFI_PAGE_SHIFT , +EFI_BOOT_SERVICES_DATA , false); + } +#endif +#if defined(CONFIG_TEGRA_SUPPORT_NON_SECURE )if (tegra_cpu_is_non_secure ()) {printf ("CPU is in NS mode\n" );
Signature · 1 line
2.18.0
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v3 2/3 ARM: tegra: reserve unmapped RAM so EFI doesn't use it
Quoted 20 lines · Alexander Graf
Quoted 20 lines
From: Stephen Warren <[email protected]>
Tegra U-Boot ensures that
board_get_usable_ram_top()never returns a value over 4GB, since some peripherals can't access such addresses. However, on systems with more than 2GB of RAM, RAM bank 1 does describe this extra RAM, so that Linux (or whatever OS) can use it, subject to DMA limitations. Sinceboard_get_usable_ram_top()points at the top of RAM bank 0, the memory locations describes by RAM bank 1 are not mapped by U-Boot's MMU configuration, and so cannot be used for anything.For some completely inexplicable reason, U-Boot's EFI support ignores the value returned by
board_get_usable_ram_top(), and EFI memory allocation routines will return values above U-Boot's RAM top. This causes U-Boot to crash when it accesses that RAM, since it isn't mapped by the MMU. One use-case where this happens is TFTP download of a file on Jetson TX1 (p2371-2180).This change explicitly tells the EFI code that this extra RAM should not be used, thus avoiding the crash.
Quoted 8 lines
Quoted 6 lines
A previous attempt to make EFI honor
board_get_usable_ram_top()was rejected. So, this patch will need to be replicated for any board that implementsboard_get_usable_ram_top().Fixes aa909462d018 ("efi_loader: efi_allocate_pages is too restrictive")Signed-off-by Stephen Warren <[email protected]>Thanks, applied to efi-next
They don't seem to have shown up in u-boot/master though...
PATCH v3 2/3 ARM: tegra: reserve unmapped RAM so EFI doesn't use it
Quoted 29 lines · Stephen Warren
Quoted 28 lines · Alexander Graf
Quoted 28 lines
From: Stephen Warren <[email protected]>
Tegra U-Boot ensures that
board_get_usable_ram_top()never returns a value
over 4GB, since some peripherals can't access such addresses. However, on
systems with more than 2GB of RAM, RAM bank 1 does describe this extra RAM, so that Linux (or whatever OS) can use it, subject to DMA limitations. Sinceboard_get_usable_ram_top()points at the top of RAM bank 0, the memory locations describes by RAM bank 1 are not mapped by U-Boot's MMU configuration, and so cannot be used for anything.For some completely inexplicable reason, U-Boot's EFI support ignores the
value returned byboard_get_usable_ram_top(), and EFI memory allocation routines will return values above U-Boot's RAM top. This causes U-Boot to
crash when it accesses that RAM, since it isn't mapped by the MMU. One use-case where this happens is TFTP download of a file on Jetson TX1 (p2371-2180).This change explicitly tells the EFI code that this extra RAM should not be used, thus avoiding the crash.
A previous attempt to make EFI honor
board_get_usable_ram_top()was rejected. So, this patch will need to be replicated for any board that implementsboard_get_usable_ram_top().
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Fixes aa909462d018 ("efi_loader: efi_allocate_pages is toorestrictive")
Signed-off-by Stephen Warren <[email protected]>Thanks, applied to efi-next
They don't seem to have shown up in u-boot/master though...
Yes, thanks to the new sandbox support we were able to run more tests than before and suddenly caught one that only got fixed very recently. Because of that we didn't pass travis and I didn't want to send a pull request that would break our automated testing :)
Should be on its way soon (today if things work out as planned).
Alex
PATCH v3 3/3 Revert "Revert "efi_loader: efi_allocate_pages is too restrictive""
In reply to Stephen WarrenFrom: Stephen Warren <[email protected]>
This reverts commit ccfc78b820e5e431c5bd73b072e7536a972e1710.
Now that the underlying issue is fixed, we can revert the revert and hence restore the original EFI code.
---
v3: No change.
v2: No change.
--- lib/efi_loader/efi_memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/efi_loader/efi_memory.c +1 -1
@@ -304,7 +304,7 @@ efi_status_t efi_allocate_pages(int type, int memory_type,switch (type) {case EFI_ALLOCATE_ANY_PAGES :/* Any page */ - addr =efi_find_free_memory (len, gd->start_addr_sp); + addr =efi_find_free_memory (len,-1ULL );if (!addr) { r =EFI_NOT_FOUND ;break ;
Signature · 1 line
2.18.0