uboot-tools/tegra-efi_loader-simplify-ifdefs.patch
2018-09-04 18:51:09 +01:00

195 lines
7.0 KiB
Diff

From patchwork Thu Aug 30 21:43:43 2018
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: [U-Boot,V3,1/3] efi_loader: simplify ifdefs
X-Patchwork-Submitter: Stephen Warren <swarren@wwwdotorg.org>
X-Patchwork-Id: 964248
X-Patchwork-Delegate: agraf@suse.de
Message-Id: <20180830214345.2475-1-swarren@wwwdotorg.org>
To: Tom Rini <trini@konsulko.com>
Cc: Stephen Warren <swarren@nvidia.com>, xypron.glpk@gmx.de, agraf@suse.de,
u-boot@lists.denx.de, Tom Warren <twarren@nvidia.com>
Date: Thu, 30 Aug 2018 15:43:43 -0600
From: Stephen Warren <swarren@wwwdotorg.org>
List-Id: U-Boot discussion <u-boot.lists.denx.de>
From: Stephen Warren <swarren@nvidia.com>
Use CONFIG_IS_ENABLED(EFI_LOADER) to avoid explicitly checking CONFIG_SPL
too. This simplifies the conditional.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
---
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(-)
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/cpu.c b/arch/arm/cpu/armv8/fsl-layerscape/cpu.c
index 052e0708d454..be00bd55ab68 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/cpu.c
+++ b/arch/arm/cpu/armv8/fsl-layerscape/cpu.c
@@ -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;
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/fdt.c b/arch/arm/cpu/armv8/fsl-layerscape/fdt.c
index fc9de73bcef4..c9c2c3f6d3e8 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/fdt.c
+++ b/arch/arm/cpu/armv8/fsl-layerscape/fdt.c
@@ -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);
diff --git a/arch/x86/lib/e820.c b/arch/x86/lib/e820.c
index 8b34f677d96d..d6ae2c4e9d77 100644
--- a/arch/x86/lib/e820.c
+++ b/arch/x86/lib/e820.c
@@ -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) */
diff --git a/include/efi_loader.h b/include/efi_loader.h
index f162adfff7e2..b46babf9316f 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -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 */
From patchwork Thu Aug 30 21:43:44 2018
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: [U-Boot, V3,
2/3] ARM: tegra: reserve unmapped RAM so EFI doesn't use it
X-Patchwork-Submitter: Stephen Warren <swarren@wwwdotorg.org>
X-Patchwork-Id: 964249
X-Patchwork-Delegate: agraf@suse.de
Message-Id: <20180830214345.2475-2-swarren@wwwdotorg.org>
To: Tom Rini <trini@konsulko.com>
Cc: Stephen Warren <swarren@nvidia.com>, xypron.glpk@gmx.de, agraf@suse.de,
u-boot@lists.denx.de, Tom Warren <twarren@nvidia.com>
Date: Thu, 30 Aug 2018 15:43:44 -0600
From: Stephen Warren <swarren@wwwdotorg.org>
List-Id: U-Boot discussion <u-boot.lists.denx.de>
From: Stephen Warren <swarren@nvidia.com>
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().
Fixes: aa909462d018 ("efi_loader: efi_allocate_pages is too restrictive")
Signed-off-by: Stephen Warren <swarren@nvidia.com>
---
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(+)
diff --git a/arch/arm/mach-tegra/board2.c b/arch/arm/mach-tegra/board2.c
index 421a71b3014d..12257a42b51b 100644
--- a/arch/arm/mach-tegra/board2.c
+++ b/arch/arm/mach-tegra/board2.c
@@ -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");