EFI payload / application support
Subsystems (7)
v5 cover EFI payload / application support
This is my (now very late) Christmas present for my openSUSE friends :).
U-Boot is a great project for embedded devices. However, convincing everyone involved that only for "a few oddball ARM devices" we need to support different configuration formats from grub2 when all other platforms (PPC, System Z, x86) are standardized on a single format is a nightmare.
So we started to explore alternatives. At first, people tried to get grub2 running using the u-boot api interface. However, that one didn't support relocations, so you had to know where to link grub2 to at compile time. It also seems to be broken more often than not. And on top of it all, it's a one-off interface, so yet another thing to maintain.
That led to a nifty idea. What if we can just implement the EFI application protocol on top of U-Boot? Then we could compile a single grub2 binary for uEFI based systems and U-Boot based systems and as soon as that one's loaded, everything looks and feels (almost) the same.
This patch set is the result of pursuing this endeavor.
- I am successfully able to run grub2 and Linux EFI binaries with this code.
- When enabled, the resulting U-Boot binary only grows by ~10kb, so it's very light weight.
- It works on 32bit ARM and AArch64.
- All storage devices are directly accessible
- No EFI variables
- Removable media booting (search for /efi/boot/boota{a64,arm}.efi)
- Everything in place for runtime service support
Of course, there are still a few things one could do on top:
- Improve disk media detection (don't scan, use what information we have)
- Add EFI variable support using NVRAM
- Add GFX support
- Make EFI Shell work ;)
- Network device support
- Support for payload exit
But so far, I'm very happy with the state of the patches. They completely eliminate potential arguments against U-Boot internally and give users the chance to run with the same level of comfort on all firmware types.
Version 5 was successfully tested to boot grub2 and Linux from there on a beagle-xm. Please apply the arm64 mmu patch set if you want to run this on an AArch64 system.
If you read this far and want to try out the patches, feel free to grab the source from git at:
https://github.com/agraf/u-boot efi-v5
v1 -> v2:
- move memory allocation to separate patch
- limit 32/64 to hosts that support it
- check 32bit optional nt header magic
- switch to GPLv2+
- Fix typo s/does now/does not/
- Add #ifdefs around header to allow inclusion when efi_loader is disabled
- Add stub efi_restore_gd() function when efi_loader is disabled
- Disable debug
- Mark runtime region as such
- Fix up memory map
- Allow efi_restore_gd to be called before first efi entry
- Add 32bit arm cache workaround
- Move memory map to separate patch
- Change BTS version to 2.5
- Fix return values for a few callbacks to more EFI compliant ones
- Change vendor to "Das U-Boot"
- Add warning when truncating timer trigger
- Add runtime detach
- Enable runtime relocations
- Add get_time
- Fix relocation
- Fix 32bit
- Add am335x support
- Move section definition to header
- Add systab to runtime section
- Add self-relocation hook table
- Relocate efi_runtime section early during bootup
- Fix return values for a number of callbacks to be more UEFI compliant
- Move to block_drvr array
- Fix header order
- Document efi block object struct
- Use calloc rather than malloc & memset
- Default to y
- New patches:
- disk/part.c: Expose list of available block drivers
- arm64: Allow exceptions to return
- arm64: Allow EFI payload code to take exceptions
- efi_loader: Add DCACHE_OFF support for arm64
- efi_loader: Add distro boot script for removable media
v2 -> v3:
- Add EFIAPI to notify_function
- Add access denied code
- use efi_alloc
- add EFIAPI to function prototypes
- remove unused macros
- reorder header inclusion
- split relocation code into function
- flush cache after loading
- Use external efi_memory helpers
- Add EFIAPI to function prototypes
- Initialize event timer to -1ULL to prevent early firing
- Document header
- Move obj list to lib
- Remove implicit guid table
- Add guid compare function
- Fix return values
- Implement efi_wait_for_event
- Add EFIAPI to function prototypes
- Patch reset to NULL
- Add EFIAPI to function prototypes
- Document header
- Add dm.h include
- Remove non-dm rtc support
- Return DEVICE_ERROR in rtc path
- Adapt to newer u-boot block API
- Add EFIAPI to function prototypes
- Document header
- Check for DEV_TYPE_UNKNOWN
- Document 16byte limit for dp string
- Move to new cmd directory
- Add kconfig option
- Fix comment style
- Add help text
- s/-1/-ENOENT
- Move obj list to lib
- Rewrite memory allocation and map
- Document header
- Add memory file
- New files:
- README patch
- MAINTAINERS patch
v3 -> v4:
- Add EFI_PAGE_MASK define
- Use EFI_PAGE_SHIFT define
- Flush icache after image load
- Fix white space in pe header
- s/polimorphic/polymorphic
- return EFI_SUCCESS in efi_cout_enable_cursor()
- Use EFI_PAGE_.* defines
- Return EFI_OUT_OF_RESOURCES in efi_allocate_pages
- Add readme section about config options
- s/10kb/10KB/
v4 -> v5:
- Provide icache flush stub for archs which don't have it
- Mark fdt memory as boot services data
- new patch: arm64: Replace fdt_name env variables with fdtfile
- new patch: arm: Allow EFI payload code to take exceptions
- new patch: efi_loader: Call fdt preparation functions
- new patch: efi_loader: Pass proper device path in on boot
- PoC converted JeOS-beagle and JeOS-beaglebone images to EFI
-> http://download.opensuse.org/repositories/home:/algraf:/arm-efi/images/
Alexander Graf (30):
thunderx: Calculate TCR dynamically
arm64: Disable TTBR1 maps in EL1
arm64: Make full va map code more dynamic
thunderx: Move mmu table into board file
zymqmp: Replace home grown mmu code with generic table approach
tegra: Replace home grown mmu code with generic table approach
vexpress64: Add MMU tables
dwmmc: Increase retry timeout
hikey: Add MMU tables
arm64: Remove non-full-va map code
arm64: Only allow dcache disabled in SPL builds disk/part.c: Expose list of available block drivers include/efi_api.h: Add more detailed API definitions
efi_loader: Add PE image loader
efi_loader: Add boot time services
efi_loader: Add console interface
efi_loader: Add runtime services
efi_loader: Add disk interfaces
efi_loader: Add "bootefi" command
efi_loader: Implement memory allocation and map
arm64: Allow exceptions to return
arm64: Allow EFI payload code to take exceptions
efi_loader: hook up in build environment
efi_loader: Add distro boot script for removable media
efi_loader: Add README section in README.efi
efi_loader: Add MAINTAINERS entry
arm64: Replace fdt_name env variables with fdtfile
arm: Allow EFI payload code to take exceptions
efi_loader: Call fdt preparation functions
efi_loader: Pass proper device path in on boot
MAINTAINERS | 7 + arch/arm/config.mk | 4 + arch/arm/cpu/armv8/cache.S | 54 ++ arch/arm/cpu/armv8/cache_v8.c | 551 +++++++++++++---- arch/arm/cpu/armv8/exceptions.S | 34 ++ arch/arm/cpu/armv8/fsl-layerscape/cpu.c | 37 +- arch/arm/cpu/armv8/u-boot.lds | 16 + arch/arm/cpu/armv8/zynqmp/cpu.c | 217 ++----- arch/arm/cpu/u-boot.lds | 30 + arch/arm/include/asm/arch-fsl-layerscape/cpu.h | 94 +-- arch/arm/include/asm/armv8/mmu.h | 123 +--- arch/arm/include/asm/global_data.h | 7 +- arch/arm/include/asm/system.h | 12 +- arch/arm/lib/interrupts.c | 8 + arch/arm/lib/interrupts_64.c | 9 + arch/arm/lib/sections.c | 4 + arch/arm/mach-tegra/arm64-mmu.c | 132 +---- board/armltd/vexpress64/vexpress64.c | 21 + board/cavium/thunderx/thunderx.c | 24 + board/hisilicon/hikey/hikey.c | 21 + board/ti/am335x/u-boot.lds | 30 + cmd/Kconfig | 7 + cmd/Makefile | 1 + cmd/bootefi.c | 202 +++++++ cmd/fs.c | 2 + common/board_r.c | 7 + common/image-fdt.c | 8 +- disk/part.c | 7 +- doc/README.arm64 | 20 - doc/README.efi | 83 ++- drivers/mmc/dw_mmc.c | 2 +- include/config_distro_bootcmd.h | 47 +- include/configs/hikey.h | 6 +- include/configs/thunderx_88xx.h | 30 - include/configs/vexpress_aemv8a.h | 15 +- include/efi.h | 2 + include/efi_api.h | 198 +++++-- include/efi_loader.h | 157 +++++ include/part.h | 8 + include/pe.h | 263 +++++++++ lib/Kconfig | 1 + lib/Makefile | 1 + lib/efi_loader/Kconfig | 9 + lib/efi_loader/Makefile | 12 + lib/efi_loader/efi_boottime.c | 781 +++++++++++++++++++++++++ lib/efi_loader/efi_console.c | 360 ++++++++++++ lib/efi_loader/efi_disk.c | 212 +++++++ lib/efi_loader/efi_image_loader.c | 188 ++++++ lib/efi_loader/efi_memory.c | 319 ++++++++++ lib/efi_loader/efi_runtime.c | 290 +++++++++ 50 files changed, 4003 insertions(+), 670 deletions(-) create mode 100644 cmd/bootefi.c create mode 100644 include/efi_loader.h create mode 100644 include/pe.h create mode 100644 lib/efi_loader/Kconfig create mode 100644 lib/efi_loader/Makefile create mode 100644 lib/efi_loader/efi_boottime.c create mode 100644 lib/efi_loader/efi_console.c create mode 100644 lib/efi_loader/efi_disk.c create mode 100644 lib/efi_loader/efi_image_loader.c create mode 100644 lib/efi_loader/efi_memory.c create mode 100644 lib/efi_loader/efi_runtime.c
Signature · 1 line
1.8.5.6
PATCH v5 1/30 thunderx: Calculate TCR dynamically
Based on the memory map we can determine a lot of hard coded fields of TCR, like the maximum VA and max PA we want to support. Calculate those dynamically to reduce the chance for pit falls.
--- arch/arm/cpu/armv8/cache_v8.c | 59 +++++++++++++++++++++++++++++++++++++++- arch/arm/include/asm/armv8/mmu.h | 6 +--- include/configs/thunderx_88xx.h | 3 -- 3 files changed, 59 insertions(+), 9 deletions(-)
arch/arm/cpu/armv8/cache_v8.c +58 -1
@@ -38,6 +38,58 @@ static struct mm_region mem_map[] = CONFIG_SYS_MEM_MAP;#define PTL1_ENTRIES CONFIG_SYS_PTL1_ENTRIES#define PTL2_ENTRIES CONFIG_SYS_PTL2_ENTRIES +static u64 get_tcr (int el,u64 *pips,u64 *pva_bits) +{ +u64 max_addr =0 ; +u64 ips, va_bits; +u64 tcr; +int i; + +/* Find the largest address we need to support */ +for (i =0 ; i <ARRAY_SIZE (mem_map); i++) + max_addr =max (max_addr, mem_map[i].base + mem_map[i].size); + +/* Calculate the maximum physical (and thus virtual) address */ +if (max_addr > (1ULL <<44 )) { + ips =5 ; + va_bits =48 ; + }else if (max_addr > (1ULL <<42 )) { + ips =4 ; + va_bits =44 ; + }else if (max_addr > (1ULL <<40 )) { + ips =3 ; + va_bits =42 ; + }else if (max_addr > (1ULL <<36 )) { + ips =2 ; + va_bits =40 ; + }else if (max_addr > (1ULL <<32 )) { + ips =1 ; + va_bits =36 ; + }else { + ips =0 ; + va_bits =32 ; + } + +if (el ==1 ) { + tcr =TCR_EL1_RSVD | (ips <<32 ); + }else if (el ==2 ) { + tcr =TCR_EL2_RSVD | (ips <<16 ); + }else { + tcr =TCR_EL3_RSVD | (ips <<16 ); + } + +/* PTWs cacheable, inner/outer WBWA and inner shareable */ + tcr |=TCR_TG0_64K |TCR_SHARED_INNER |TCR_ORGN_WBWA |TCR_IRGN_WBWA ; + tcr |=TCR_T0SZ (VA_BITS ); + +if (pips) + *pips = ips; +if (pva_bits) + *pva_bits = va_bits; + +return tcr; +} +static void setup_pgtables (void ) {int l1_e, l2_e;
@@ -110,6 +162,10 @@ __weak void mmu_setup(void)/* Set up page tables only on BSP */ if (coreid ==BSP_COREID )setup_pgtables (); + + el =current_el (); +set_ttbr_tcr_mair (el, gd->arch.tlb_addr,get_tcr (el,NULL ,NULL ), +MEMORY_ATTRIBUTES );#else /* Setup an identity-mapping for all spaces */ for (i =0 ; i < (PGTABLE_SIZE >>3 ); i++) {
@@ -128,7 +184,6 @@ __weak void mmu_setup(void) } } -#endif /* load TTBR0 */ el =current_el ();if (el ==1 ) {
@@ -144,6 +199,8 @@ __weak void mmu_setup(void)TCR_EL3_RSVD |TCR_FLAGS |TCR_EL3_IPS_BITS , MEMORY_ATTRIBUTES); } +#endif +/* enable the mmu */ set_sctlr (get_sctlr () |CR_M ); }
arch/arm/include/asm/armv8/mmu.h +1 -5
@@ -159,11 +159,6 @@#define TCR_EL1_IPS_BITS (UL(3) << 32)/* 42 bits physical address */ #define TCR_EL2_IPS_BITS (3 << 16)/* 42 bits physical address */ #define TCR_EL3_IPS_BITS (3 << 16)/* 42 bits physical address */ -#else -#define TCR_EL1_IPS_BITS CONFIG_SYS_TCR_EL1_IPS_BITS -#define TCR_EL2_IPS_BITS CONFIG_SYS_TCR_EL2_IPS_BITS -#define TCR_EL3_IPS_BITS CONFIG_SYS_TCR_EL3_IPS_BITS -#endif /* PTWs cacheable, inner/outer WBWA and inner shareable */ #define TCR_FLAGS (TCR_TG0_64K | \
@@ -171,6 +166,7 @@ TCR_ORGN_WBWA | \ TCR_IRGN_WBWA | \ TCR_T0SZ(VA_BITS)) +#endif #define TCR_EL1_RSVD (1 << 31)#define TCR_EL2_RSVD (1 << 31 | 1 << 23)
include/configs/thunderx_88xx.h +0 -3
@@ -50,9 +50,6 @@#define CONFIG_SYS_PGTABLE_SIZE \ ((CONFIG_SYS_PTL1_ENTRIES + \ CONFIG_SYS_MEM_MAP_SIZE * CONFIG_SYS_PTL2_ENTRIES) * 8) -#define CONFIG_SYS_TCR_EL1_IPS_BITS (5UL << 32) -#define CONFIG_SYS_TCR_EL2_IPS_BITS (5 << 16) -#define CONFIG_SYS_TCR_EL3_IPS_BITS (5 << 16)/* Link Definitions */ #define CONFIG_SYS_TEXT_BASE 0x00500000
Signature · 1 line
1.8.5.6
PATCH v5 2/30 arm64: Disable TTBR1 maps in EL1
In reply to Alexander GrafWhen running in EL1, AArch64 knows two page table maps. One with addresses that start with all zeros (TTBR0) and one with addresses that start with all ones (TTBR1).
In U-Boot we don't care about the high up maps, so just disable them to ensure we don't walk an invalid page table by accident.
--- arch/arm/cpu/armv8/cache_v8.c | 2 +- arch/arm/include/asm/armv8/mmu.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
arch/arm/cpu/armv8/cache_v8.c +1 -1
@@ -71,7 +71,7 @@ static u64 get_tcr(int el, u64 *pips, u64 *pva_bits) }if (el ==1 ) { - tcr =TCR_EL1_RSVD | (ips <<32 ); + tcr =TCR_EL1_RSVD | (ips <<32 ) |TCR_EPD1_DISABLE ; }else if (el ==2 ) { tcr =TCR_EL2_RSVD | (ips <<16 ); }else {
arch/arm/include/asm/armv8/mmu.h +1 -0
@@ -154,6 +154,7 @@#define TCR_TG0_4K (0 << 14)#define TCR_TG0_64K (1 << 14)#define TCR_TG0_16K (2 << 14) +#define TCR_EPD1_DISABLE (1 << 23)#ifndef CONFIG_SYS_FULL_VA #define TCR_EL1_IPS_BITS (UL(3) << 32)/* 42 bits physical address */
Signature · 1 line
1.8.5.6
PATCH v5 3/30 arm64: Make full va map code more dynamic
In reply to Alexander GrafThe idea to generate our pages tables from an array of memory ranges is very sound. However, instead of hard coding the code to create up to 2 levels of 64k granule page tables, we really should just create normal 4k page tables that allow us to set caching attributes on 2M or 4k level later on.
So this patch moves the full_va mapping code to 4k page size and makes it fully flexible to dynamically create as many levels as necessary for a map (including dynamic 1G/2M pages). It also adds support to dynamically split a large map into smaller ones when some code wants to set dcache attributes.
With all this in place, there is very little reason to create your own page tables in board specific files.
---
v1 -> v2:
- Fix comment for create_table()
- Rework page table size calculation
- s/DPRINTF/debug/g
- Improve panic messages
v2 -> v3:
- Move PGTABLE_SIZE out of the ASSEMBLY section
- Run pte splitting code in separate page table
- Replace is_level in count_required_pts with more obvious pte_type
v3 -> v4:
- Lv3 PTEs are always of type table
--- arch/arm/cpu/armv8/cache.S | 54 +++++ arch/arm/cpu/armv8/cache_v8.c | 453 ++++++++++++++++++++++++++++++++----- arch/arm/include/asm/armv8/mmu.h | 68 +++--- arch/arm/include/asm/global_data.h | 5 +- arch/arm/include/asm/system.h | 14 +- include/configs/thunderx_88xx.h | 14 +- 6 files changed, 500 insertions(+), 108 deletions(-)
arch/arm/cpu/armv8/cache.S +54 -0
@@ -10,6 +10,7 @@ #include <asm-offsets.h> #include <config.h> #include <asm/macro.h> +#include <asm/system.h> #include <linux/linkage.h> /*
@@ -160,3 +161,56 @@ ENTRY(__asm_flush_l3_cache) ret ENDPROC(__asm_flush_l3_cache) .weak __asm_flush_l3_cache + +/* + * void __asm_switch_ttbr(ulong new_ttbr) + * + * Safely switches to a new page table. + */ +ENTRY(__asm_switch_ttbr) + /* x2 = SCTLR (alive throghout the function) */ + switch_el x4, 3f, 2f, 1f +3: mrs x2, sctlr_el3 + b 0f +2: mrs x2, sctlr_el2 + b 0f +1: mrs x2, sctlr_el1 +0: + + /* Unset CR_M | CR_C | CR_I from SCTLR to disable all caches */ + movn x1, #(CR_M | CR_C | CR_I) + and x1, x2, x1 + switch_el x4, 3f, 2f, 1f +3: msr sctlr_el3, x1 + b 0f +2: msr sctlr_el2, x1 + b 0f +1: msr sctlr_el1, x1 +0: isb + + /* This call only clobbers x30 (lr) and x9 (unused) */ + mov x3, x30 + bl __asm_invalidate_tlb_all + + /* From here on we're running safely with caches disabled */ + + /* Set TTBR to our first argument */ + switch_el x4, 3f, 2f, 1f +3: msr ttbr0_el3, x0 + b 0f +2: msr ttbr0_el2, x0 + b 0f +1: msr ttbr0_el1, x0 +0: isb + + /* Restore original SCTLR and thus enable caches again */ + switch_el x4, 3f, 2f, 1f +3: msr sctlr_el3, x2 + b 0f +2: msr sctlr_el2, x2 + b 0f +1: msr sctlr_el1, x2 +0: isb + + ret x3 +ENDPROC(__asm_switch_ttbr)
arch/arm/cpu/armv8/cache_v8.c +398 -55
499 lines not on this page · raw message
arch/arm/include/asm/armv8/mmu.h +31 -37
95 lines not on this page · raw message
arch/arm/include/asm/global_data.h +3 -2
@@ -38,10 +38,11 @@ struct arch_global_data {unsigned long long timer_reset_value;#if !(defined(CONFIG_SYS_ICACHE_OFF ) && defined(CONFIG_SYS_DCACHE_OFF ))unsigned long tlb_addr; +unsigned long tlb_size;#if defined(CONFIG_SYS_FULL_VA ) -unsigned long pmd_addr[CONFIG_SYS_PTL1_ENTRIES ]; +unsigned long tlb_fillptr; +unsigned long tlb_emerg;#endif -unsigned long tlb_size;#endif #ifdef CONFIG_OMAP_COMMON
arch/arm/include/asm/system.h +8 -6
@@ -17,18 +17,19 @@#define CR_WXN (1 << 19)/* Write Permision Imply XN */ #define CR_EE (1 << 25)/* Exception (Big) Endian */ -#ifndef CONFIG_SYS_FULL_VA -#define PGTABLE_SIZE (0x10000) -#else -#define PGTABLE_SIZE CONFIG_SYS_PGTABLE_SIZE -#endif -/* 2MB granularity */ #define MMU_SECTION_SHIFT 21#define MMU_SECTION_SIZE (1 << MMU_SECTION_SHIFT)#ifndef __ASSEMBLY__ +#ifndef CONFIG_SYS_FULL_VA +#define PGTABLE_SIZE (0x10000) +#else +u64 get_page_table_size (void ); +#define PGTABLE_SIZE get_page_table_size() +#endif +enum dcache_option {DCACHE_OFF =0x3 , };
@@ -97,6 +98,7 @@ void __asm_flush_dcache_range(u64 start, u64 end);void __asm_invalidate_tlb_all (void );void __asm_invalidate_icache_all (void );int __asm_flush_l3_cache (void ); +void __asm_switch_ttbr (u64 new_ttbr);void armv8_switch_to_el2 (void );void armv8_switch_to_el1 (void );
include/configs/thunderx_88xx.h +6 -8
@@ -22,21 +22,19 @@#define MEM_BASE 0x00500000 -#define CONFIG_COREID_MASK 0xffffff -#define CONFIG_SYS_FULL_VA #define CONFIG_SYS_LOWMEM_BASE MEM_BASE#define CONFIG_SYS_MEM_MAP {{0x000000000000UL, 0x40000000000UL, \ - PTL2_MEMTYPE(MT_NORMAL) | \ - PTL2_BLOCK_NON_SHARE}, \ + PTE_BLOCK_MEMTYPE(MT_NORMAL) | \ + PTE_BLOCK_NON_SHARE}, \ {0x800000000000UL, 0x40000000000UL, \ - PTL2_MEMTYPE(MT_DEVICE_NGNRNE) | \ - PTL2_BLOCK_NON_SHARE}, \ + PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | \ + PTE_BLOCK_NON_SHARE}, \ {0x840000000000UL, 0x40000000000UL, \ - PTL2_MEMTYPE(MT_DEVICE_NGNRNE) | \ - PTL2_BLOCK_NON_SHARE}, \ + PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | \ + PTE_BLOCK_NON_SHARE}, \ }#define CONFIG_SYS_MEM_MAP_SIZE 3
Signature · 1 line
1.8.5.6
PATCH v5 4/30 thunderx: Move mmu table into board file
In reply to Alexander GrafThe MMU range table can vary depending on things we may only find out at runtime. While the very simple ThunderX variant does not change, other boards will, so move the definition from a static entry in a header file to the board file.
--- arch/arm/cpu/armv8/cache_v8.c | 8 +++----- arch/arm/include/asm/armv8/mmu.h | 2 ++ board/cavium/thunderx/thunderx.c | 24 ++++++++++++++++++++++++ include/configs/thunderx_88xx.h | 11 ----------- 4 files changed, 29 insertions(+), 16 deletions(-)
arch/arm/cpu/armv8/cache_v8.c +3 -5
@@ -36,8 +36,6 @@ DECLARE_GLOBAL_DATA_PTR;*/ #ifdef CONFIG_SYS_FULL_VA -static struct mm_region mem_map[] =CONFIG_SYS_MEM_MAP ; -static u64 get_tcr (int el,u64 *pips,u64 *pva_bits) {u64 max_addr =0 ;
@@ -46,7 +44,7 @@ static u64 get_tcr(int el, u64 *pips, u64 *pva_bits)int i;/* Find the largest address we need to support */ -for (i =0 ; i <ARRAY_SIZE (mem_map); i++) +for (i =0 ; mem_map[i].size || mem_map[i].attrs; i++) max_addr =max (max_addr, mem_map[i].base + mem_map[i].size);/* Calculate the maximum physical (and thus virtual) address */
@@ -266,7 +264,7 @@ static int count_required_pts(u64 addr, int level, u64 maxaddr)int i;enum pte_type pte_type =PTE_INVAL ; -for (i =0 ; i <ARRAY_SIZE (mem_map); i++) { +for (i =0 ; mem_map[i].size || mem_map[i].attrs; i++) {struct mm_region *map = &mem_map[i];u64 start = map->base;u64 end = start + map->size;
@@ -364,7 +362,7 @@ static void setup_pgtables(void)create_table ();/* Now add all MMU table entries one after another to the table */ -for (i =0 ; i <ARRAY_SIZE (mem_map); i++) +for (i =0 ; mem_map[i].size || mem_map[i].attrs; i++)add_map (&mem_map[i]);/* Create the same thing once more for our emergency page table */
arch/arm/include/asm/armv8/mmu.h +2 -0
@@ -203,6 +203,8 @@ struct mm_region {u64 size;u64 attrs; }; + +extern struct mm_region *mem_map;#endif #endif /* _ASM_ARMV8_MMU_H_ */
board/cavium/thunderx/thunderx.c +24 -0
@@ -10,6 +10,7 @@#include <linux/compiler.h> #include <cavium/atf.h> +#include <asm/armv8/mmu.h> #if !CONFIG_IS_ENABLED (OF_CONTROL )#include <dm/platdata.h>
@@ -42,6 +43,29 @@ U_BOOT_DEVICE(thunderx_serial1) = {DECLARE_GLOBAL_DATA_PTR ; +static struct mm_region thunderx_mem_map[] = { + { + .base =0x000000000000UL , + .size =0x40000000000UL , + .attrs =PTE_BLOCK_MEMTYPE (MT_NORMAL ) |PTE_BLOCK_NON_SHARE , + }, { + .base =0x800000000000UL , + .size =0x40000000000UL , + .attrs =PTE_BLOCK_MEMTYPE (MT_DEVICE_NGNRNE ) | +PTE_BLOCK_NON_SHARE , + }, { + .base =0x840000000000UL , + .size =0x40000000000UL , + .attrs =PTE_BLOCK_MEMTYPE (MT_DEVICE_NGNRNE ) | +PTE_BLOCK_NON_SHARE , + }, { +/* List terminator */ +0 , + } +}; + +struct mm_region *mem_map = thunderx_mem_map; +int board_init (void ) {return 0 ;
include/configs/thunderx_88xx.h +0 -11
@@ -26,17 +26,6 @@#define CONFIG_SYS_LOWMEM_BASE MEM_BASE -#define CONFIG_SYS_MEM_MAP {{0x000000000000UL, 0x40000000000UL, \ - PTE_BLOCK_MEMTYPE(MT_NORMAL) | \ - PTE_BLOCK_NON_SHARE}, \ - {0x800000000000UL, 0x40000000000UL, \ - PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | \ - PTE_BLOCK_NON_SHARE}, \ - {0x840000000000UL, 0x40000000000UL, \ - PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | \ - PTE_BLOCK_NON_SHARE}, \ - } -#define CONFIG_SYS_MEM_MAP_SIZE 3#define CONFIG_SYS_VA_BITS 48
Signature · 1 line
1.8.5.6
PATCH v5 5/30 zymqmp: Replace home grown mmu code with generic table approach
In reply to Alexander GrafNow that we have nice table driven page table creating code that gives us everything we need, move to that.
---
v1 -> v2:
- Move mmu tables into board file
--- arch/arm/cpu/armv8/zynqmp/cpu.c | 217 +++++++++------------------------------- include/configs/xilinx_zynqmp.h | 2 + 2 files changed, 50 insertions(+), 169 deletions(-)
arch/arm/cpu/armv8/zynqmp/cpu.c +48 -169
@@ -8,6 +8,7 @@#include <common.h> #include <asm/arch/hardware.h> #include <asm/arch/sys_proto.h> +#include <asm/armv8/mmu.h> #include <asm/io.h> #define ZYNQ_SILICON_VER_MASK 0xF000
@@ -15,6 +16,53 @@DECLARE_GLOBAL_DATA_PTR ; +static struct mm_region zynqmp_mem_map[] = { + { + .base =0x0UL , + .size =0x80000000UL , + .attrs =PTE_BLOCK_MEMTYPE (MT_NORMAL ) | +PTE_BLOCK_INNER_SHARE + }, { + .base =0x80000000UL , + .size =0x70000000UL , + .attrs =PTE_BLOCK_MEMTYPE (MT_DEVICE_NGNRNE ) | +PTE_BLOCK_NON_SHARE | +PTE_BLOCK_PXN |PTE_BLOCK_UXN + }, { + .base =0xf8000000UL , + .size =0x07e00000UL , + .attrs =PTE_BLOCK_MEMTYPE (MT_DEVICE_NGNRNE ) | +PTE_BLOCK_NON_SHARE | +PTE_BLOCK_PXN |PTE_BLOCK_UXN + }, { + .base =0xffe00000UL , + .size =0x00200000UL , + .attrs =PTE_BLOCK_MEMTYPE (MT_NORMAL ) | +PTE_BLOCK_INNER_SHARE + }, { + .base =0x400000000UL , + .size =0x200000000UL , + .attrs =PTE_BLOCK_MEMTYPE (MT_DEVICE_NGNRNE ) | +PTE_BLOCK_NON_SHARE | +PTE_BLOCK_PXN |PTE_BLOCK_UXN + }, { + .base =0x600000000UL , + .size =0x800000000UL , + .attrs =PTE_BLOCK_MEMTYPE (MT_NORMAL ) | +PTE_BLOCK_INNER_SHARE + }, { + .base =0xe00000000UL , + .size =0xf200000000UL , + .attrs =PTE_BLOCK_MEMTYPE (MT_DEVICE_NGNRNE ) | +PTE_BLOCK_NON_SHARE | +PTE_BLOCK_PXN |PTE_BLOCK_UXN + }, { +/* List terminator */ +0 , + } +}; +struct mm_region *mem_map = zynqmp_mem_map; +static unsigned int zynqmp_get_silicon_version_secure (void ) {u32 ver;
@@ -44,172 +92,3 @@ unsigned int zynqmp_get_silicon_version(void)return ZYNQMP_CSU_VERSION_SILICON ; } - -#ifndef CONFIG_SYS_DCACHE_OFF -#include <asm/armv8/mmu.h> - -#define SECTION_SHIFT_L1 30UL -#define SECTION_SHIFT_L2 21UL -#define BLOCK_SIZE_L0 0x8000000000UL -#define BLOCK_SIZE_L1 (1 << SECTION_SHIFT_L1) -#define BLOCK_SIZE_L2 (1 << SECTION_SHIFT_L2) - -#define TCR_TG1_4K (1 << 31) -#define TCR_EPD1_DISABLE (1 << 23) -#define ZYNQMO_VA_BITS 40 -#define ZYNQMP_TCR TCR_TG1_4K | \ - TCR_EPD1_DISABLE | \ - TCR_SHARED_OUTER | \ - TCR_SHARED_INNER | \ - TCR_IRGN_WBWA | \ - TCR_ORGN_WBWA | \ - TCR_T0SZ(ZYNQMO_VA_BITS) - -#define MEMORY_ATTR PMD_SECT_AF | PMD_SECT_INNER_SHARE | \ - PMD_ATTRINDX(MT_NORMAL) | \ - PMD_TYPE_SECT -#define DEVICE_ATTR PMD_SECT_AF | PMD_SECT_PXN | \ - PMD_SECT_UXN | PMD_ATTRINDX(MT_DEVICE_NGNRNE) | \ - PMD_TYPE_SECT - -/* 4K size is required to place 512 entries in each level */ -#define TLB_TABLE_SIZE 0x1000 - -struct attr_tbl { -u32 num; -u64 attr; -}; - -static struct attr_tbl attr_tbll1t0[4 ] = { {16 ,0x0 }, - {8 ,DEVICE_ATTR }, - {32 ,MEMORY_ATTR }, - {456 ,DEVICE_ATTR } - }; -static struct attr_tbl attr_tbll2t3[4 ] = { {0x180 ,DEVICE_ATTR }, - {0x40 ,0x0 }, - {0x3F ,DEVICE_ATTR }, - {0x1 ,MEMORY_ATTR } - }; - -/* -* This mmu table looks as below -* Level 0 table contains two entries to 512GB sizes. One is Level1 Table 0 -* and other Level1 Table1. -* Level1 Table0 contains entries for each 1GB from 0 to 511GB. -* Level1 Table1 contains entries for each 1GB from 512GB to 1TB. -* Level2 Table0, Level2 Table1, Level2 Table2 and Level2 Table3 contains -* entries for each 2MB starting from 0GB, 1GB, 2GB and 3GB respectively. -*/ -static void zynqmp_mmu_setup (void ) -{ -int el; -u32 index_attr; -u64 i, section_l1t0, section_l1t1; -u64 section_l2t0, section_l2t1, section_l2t2, section_l2t3; -u64 *level0_table = (u64 *)gd->arch.tlb_addr; -u64 *level1_table_0 = (u64 *)(gd->arch.tlb_addr +TLB_TABLE_SIZE ); -u64 *level1_table_1 = (u64 *)(gd->arch.tlb_addr + (2 *TLB_TABLE_SIZE )); -u64 *level2_table_0 = (u64 *)(gd->arch.tlb_addr + (3 *TLB_TABLE_SIZE )); -u64 *level2_table_1 = (u64 *)(gd->arch.tlb_addr + (4 *TLB_TABLE_SIZE )); -u64 *level2_table_2 = (u64 *)(gd->arch.tlb_addr + (5 *TLB_TABLE_SIZE )); -u64 *level2_table_3 = (u64 *)(gd->arch.tlb_addr + (6 *TLB_TABLE_SIZE )); - - level0_table[0 ] = - (u64 )level1_table_0 |PMD_TYPE_TABLE ; - level0_table[1 ] = - (u64 )level1_table_1 |PMD_TYPE_TABLE ; - -/* -* set level 1 table 0, covering 0 to 512GB -* set level 1 table 1, covering 512GB to 1TB -*/ - section_l1t0 =0 ; - section_l1t1 =BLOCK_SIZE_L0 ; - - index_attr =0 ; -for (i =0 ; i <512 ; i++) { - level1_table_0[i] = section_l1t0; - level1_table_0[i] |= attr_tbll1t0[index_attr].attr; - attr_tbll1t0[index_attr].num--; -if (attr_tbll1t0[index_attr].num ==0 ) - index_attr++; - level1_table_1[i] = section_l1t1; - level1_table_1[i] |=DEVICE_ATTR ; - section_l1t0 +=BLOCK_SIZE_L1 ; - section_l1t1 +=BLOCK_SIZE_L1 ; - } - - level1_table_0[0 ] = - (u64 )level2_table_0 |PMD_TYPE_TABLE ; - level1_table_0[1 ] = - (u64 )level2_table_1 |PMD_TYPE_TABLE ; - level1_table_0[2 ] = - (u64 )level2_table_2 |PMD_TYPE_TABLE ; - level1_table_0[3 ] = - (u64 )level2_table_3 |PMD_TYPE_TABLE ; - - section_l2t0 =0 ; - section_l2t1 = section_l2t0 +BLOCK_SIZE_L1 ;/* 1GB */ - section_l2t2 = section_l2t1 +BLOCK_SIZE_L1 ;/* 2GB */ - section_l2t3 = section_l2t2 +BLOCK_SIZE_L1 ;/* 3GB */ - - index_attr =0 ; - -for (i =0 ; i <512 ; i++) { - level2_table_0[i] = section_l2t0 |MEMORY_ATTR ; - level2_table_1[i] = section_l2t1 |MEMORY_ATTR ; - level2_table_2[i] = section_l2t2 |DEVICE_ATTR ; - level2_table_3[i] = section_l2t3 | - attr_tbll2t3[index_attr].attr; - attr_tbll2t3[index_attr].num--; -if (attr_tbll2t3[index_attr].num ==0 ) - index_attr++; - section_l2t0 +=BLOCK_SIZE_L2 ; - section_l2t1 +=BLOCK_SIZE_L2 ; - section_l2t2 +=BLOCK_SIZE_L2 ; - section_l2t3 +=BLOCK_SIZE_L2 ; - } - -/* flush new MMU table */ -flush_dcache_range (gd->arch.tlb_addr, - gd->arch.tlb_addr + gd->arch.tlb_size); - -/* point TTBR to the new table */ - el =current_el (); -set_ttbr_tcr_mair (el, gd->arch.tlb_addr, -ZYNQMP_TCR ,MEMORY_ATTRIBUTES ); - -set_sctlr (get_sctlr () |CR_M ); -} - -int arch_cpu_init (void ) -{ -icache_enable (); -__asm_invalidate_dcache_all (); -__asm_invalidate_tlb_all (); -return 0 ; -} - -/* -* This function is called from lib/board.c. -* It recreates MMU table in main memory. MMU and d-cache are enabled earlier. -* There is no need to disable d-cache for this operation. -*/ -void enable_caches (void ) -{ -/* The data cache is not active unless the mmu is enabled */ -if (!(get_sctlr () &CR_M )) { -invalidate_dcache_all (); -__asm_invalidate_tlb_all (); -zynqmp_mmu_setup (); - } -puts ("Enabling Caches...\n" ); - -set_sctlr (get_sctlr () |CR_C ); -} - -u64 *arch_get_page_table (void ) -{ -return (u64 *)(gd->arch.tlb_addr +0x3000 ); -} -#endif
include/configs/xilinx_zynqmp.h +2 -0
@@ -29,6 +29,8 @@#define CONFIG_SYS_MEMTEST_START CONFIG_SYS_SDRAM_BASE#define CONFIG_SYS_MEMTEST_END CONFIG_SYS_SDRAM_SIZE +#define CONFIG_SYS_FULL_VA +/* Have release address at the end of 256MB for now */ #define CPU_RELEASE_ADDR 0xFFFFFF0
Signature · 1 line
1.8.5.6
PATCH v5 6/30 tegra: Replace home grown mmu code with generic table approach
In reply to Alexander GrafNow that we have nice table driven page table creating code that gives us everything we need, move to that.
---
v1 -> v2:
- Move mmu tables into .c file
--- arch/arm/mach-tegra/arm64-mmu.c | 132 +++++--------------------------------- include/configs/tegra210-common.h | 2 + 2 files changed, 19 insertions(+), 115 deletions(-)
arch/arm/mach-tegra/arm64-mmu.c +17 -115
@@ -12,120 +12,22 @@#include <asm/system.h> #include <asm/armv8/mmu.h> -DECLARE_GLOBAL_DATA_PTR ; - -#define SECTION_SHIFT_L1 30UL -#define SECTION_SHIFT_L2 21UL -#define BLOCK_SIZE_L0 0x8000000000UL -#define BLOCK_SIZE_L1 (1 << SECTION_SHIFT_L1) -#define BLOCK_SIZE_L2 (1 << SECTION_SHIFT_L2) - -#define TCR_TG1_4K (1 << 31) -#define TCR_EPD1_DISABLE (1 << 23) -#define TEGRA_VA_BITS 40 -#define TEGRA_TCR TCR_TG1_4K | \ - TCR_EPD1_DISABLE | \ - TCR_SHARED_OUTER | \ - TCR_SHARED_INNER | \ - TCR_IRGN_WBWA | \ - TCR_ORGN_WBWA | \ - TCR_T0SZ(TEGRA_VA_BITS) - -#define MEMORY_ATTR PMD_SECT_AF | PMD_SECT_INNER_SHARE | \ - PMD_ATTRINDX(MT_NORMAL) | \ - PMD_TYPE_SECT -#define DEVICE_ATTR PMD_SECT_AF | PMD_SECT_PXN | \ - PMD_SECT_UXN | PMD_ATTRINDX(MT_DEVICE_NGNRNE) | \ - PMD_TYPE_SECT - -/* 4K size is required to place 512 entries in each level */ -#define TLB_TABLE_SIZE 0x1000 - -/* -* This mmu table looks as below -* Level 0 table contains two entries to 512GB sizes. One is Level1 Table 0 -* and other Level1 Table1. -* Level1 Table0 contains entries for each 1GB from 0 to 511GB. -* Level1 Table1 contains entries for each 1GB from 512GB to 1TB. -* Level2 Table0, Level2 Table1, Level2 Table2 and Level2 Table3 contains -* entries for each 2MB starting from 0GB, 1GB, 2GB and 3GB respectively. -*/ -void mmu_setup (void ) -{ -int el; -u64 i, section_l1t0, section_l1t1; -u64 section_l2t0, section_l2t1, section_l2t2, section_l2t3; -u64 *level0_table = (u64 *)gd->arch.tlb_addr; -u64 *level1_table_0 = (u64 *)(gd->arch.tlb_addr +TLB_TABLE_SIZE ); -u64 *level1_table_1 = (u64 *)(gd->arch.tlb_addr + (2 *TLB_TABLE_SIZE )); -u64 *level2_table_0 = (u64 *)(gd->arch.tlb_addr + (3 *TLB_TABLE_SIZE )); -u64 *level2_table_1 = (u64 *)(gd->arch.tlb_addr + (4 *TLB_TABLE_SIZE )); -u64 *level2_table_2 = (u64 *)(gd->arch.tlb_addr + (5 *TLB_TABLE_SIZE )); -u64 *level2_table_3 = (u64 *)(gd->arch.tlb_addr + (6 *TLB_TABLE_SIZE )); - -/* Invalidate all table entries */ -memset (level0_table,0 ,PGTABLE_SIZE ); - - level0_table[0 ] = - (u64 )level1_table_0 |PMD_TYPE_TABLE ; - level0_table[1 ] = - (u64 )level1_table_1 |PMD_TYPE_TABLE ; - -/* -* set level 1 table 0, covering 0 to 512GB -* set level 1 table 1, covering 512GB to 1TB -*/ - section_l1t0 =0 ; - section_l1t1 =BLOCK_SIZE_L0 ; - -for (i =0 ; i <512 ; i++) { - level1_table_0[i] = section_l1t0; -if (i >=4 ) - level1_table_0[i] |=MEMORY_ATTR ; - level1_table_1[i] = section_l1t1; - level1_table_1[i] |=MEMORY_ATTR ; - section_l1t0 +=BLOCK_SIZE_L1 ; - section_l1t1 +=BLOCK_SIZE_L1 ; +static struct mm_region tegra_mem_map[] = { + { + .base =0x0UL , + .size =0x80000000UL , + .attrs =PTE_BLOCK_MEMTYPE (MT_DEVICE_NGNRNE ) | +PTE_BLOCK_NON_SHARE | +PTE_BLOCK_PXN |PTE_BLOCK_UXN + }, { + .base =0x80000000UL , + .size =0xff80000000UL , + .attrs =PTE_BLOCK_MEMTYPE (MT_NORMAL ) | +PTE_BLOCK_INNER_SHARE + }, { +/* List terminator */ +0 , } +}; - level1_table_0[0 ] = - (u64 )level2_table_0 |PMD_TYPE_TABLE ; - level1_table_0[1 ] = - (u64 )level2_table_1 |PMD_TYPE_TABLE ; - level1_table_0[2 ] = - (u64 )level2_table_2 |PMD_TYPE_TABLE ; - level1_table_0[3 ] = - (u64 )level2_table_3 |PMD_TYPE_TABLE ; - - section_l2t0 =0 ; - section_l2t1 = section_l2t0 +BLOCK_SIZE_L1 ;/* 1GB */ - section_l2t2 = section_l2t1 +BLOCK_SIZE_L1 ;/* 2GB */ - section_l2t3 = section_l2t2 +BLOCK_SIZE_L1 ;/* 3GB */ - -for (i =0 ; i <512 ; i++) { - level2_table_0[i] = section_l2t0 |DEVICE_ATTR ; - level2_table_1[i] = section_l2t1 |DEVICE_ATTR ; - level2_table_2[i] = section_l2t2 |MEMORY_ATTR ; - level2_table_3[i] = section_l2t3 |MEMORY_ATTR ; - section_l2t0 +=BLOCK_SIZE_L2 ; - section_l2t1 +=BLOCK_SIZE_L2 ; - section_l2t2 +=BLOCK_SIZE_L2 ; - section_l2t3 +=BLOCK_SIZE_L2 ; - } - -/* flush new MMU table */ -flush_dcache_range (gd->arch.tlb_addr, - gd->arch.tlb_addr + gd->arch.tlb_size); - -/* point TTBR to the new table */ - el =current_el (); -set_ttbr_tcr_mair (el, gd->arch.tlb_addr, -TEGRA_TCR ,MEMORY_ATTRIBUTES ); - -set_sctlr (get_sctlr () |CR_M ); -} - -u64 *arch_get_page_table (void ) -{ -return (u64 *)(gd->arch.tlb_addr + (3 *TLB_TABLE_SIZE )); -} +struct mm_region *mem_map = tegra_mem_map;
include/configs/tegra210-common.h +2 -0
@@ -13,6 +13,8 @@/* Cortex-A57 uses a cache line size of 64 bytes */ #define CONFIG_SYS_CACHELINE_SIZE 64 +#define CONFIG_SYS_FULL_VA +/* * NS16550 Configuration */
Signature · 1 line
1.8.5.6
PATCH v5 7/30 vexpress64: Add MMU tables
In reply to Alexander GrafThere's no good excuse for running with caches disabled on AArch64, so let's just move the vexpress64 target to enable the MMU and run with caches on.
---
v1 -> v2:
- Move tables to .c file
--- board/armltd/vexpress64/vexpress64.c | 21 +++++++++++++++++++++ include/configs/vexpress_aemv8a.h | 6 +++--- 2 files changed, 24 insertions(+), 3 deletions(-)
board/armltd/vexpress64/vexpress64.c +21 -0
@@ -14,6 +14,7 @@#include <dm/platdata.h> #include <dm/platform_data/serial_pl01x.h> #include "pcie.h" +#include <asm/armv8/mmu.h> DECLARE_GLOBAL_DATA_PTR ;
@@ -28,6 +29,26 @@ U_BOOT_DEVICE(vexpress_serials) = { .platdata = &serial_platdata, }; +static struct mm_region vexpress64_mem_map[] = { + { + .base =0x0UL , + .size =0x80000000UL , + .attrs =PTE_BLOCK_MEMTYPE (MT_DEVICE_NGNRNE ) | +PTE_BLOCK_NON_SHARE | +PTE_BLOCK_PXN |PTE_BLOCK_UXN + }, { + .base =0x80000000UL , + .size =0xff80000000UL , + .attrs =PTE_BLOCK_MEMTYPE (MT_NORMAL ) | +PTE_BLOCK_INNER_SHARE + }, { +/* List terminator */ +0 , + } +}; + +struct mm_region *mem_map = vexpress64_mem_map; +/* This function gets replaced by platforms supporting PCIe. * The replacement function, eg. on Juno, initialises the PCIe bus. */
include/configs/vexpress_aemv8a.h +3 -3
@@ -19,9 +19,9 @@#define CONFIG_SUPPORT_RAW_INITRD -/* Cache Definitions */ -#define CONFIG_SYS_DCACHE_OFF -#define CONFIG_SYS_ICACHE_OFF +/* MMU Definitions */ +#define CONFIG_SYS_CACHELINE_SIZE 64 +#define CONFIG_SYS_FULL_VA #define CONFIG_IDENT_STRING " vexpress_aemv8a"#define CONFIG_BOOTP_VCI_STRING "U-Boot.armv8.vexpress_aemv8a"
Signature · 1 line
1.8.5.6
PATCH v5 8/30 dwmmc: Increase retry timeout
In reply to Alexander GrafWhen enable dcache on HiKey, we're running into MMC command timeouts because our retry loop is now faster than the eMMC (or an external SD card) can answer.
Increase the retry count to the same as the timeout value for status reports.
The real fix is obviously to not base this whole thing on a cycle counter but on real wall time, but that would be slightly more intrusive.
--- drivers/mmc/dw_mmc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/dw_mmc.c +1 -1
@@ -189,7 +189,7 @@ static int dwmci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, data ? DIV_ROUND_UP(data->blocks, 8) : 0);int ret =0 , flags =0 , i;unsigned int timeout =100000 ; -u32 retry =10000 ; +u32 retry =100000 ;u32 mask, ctrl;ulong start =get_timer (0 );struct bounce_buffer bbstate;
Signature · 1 line
1.8.5.6
PATCH v5 9/30 hikey: Add MMU tables
In reply to Alexander GrafThe hikey runs with dcache disabled today. There really should be no reason not to use caches on AArch64, so let's add MMU definitions and enable the dcache.
---
v1 -> v2:
- Move tables to .c file
--- board/hisilicon/hikey/hikey.c | 21 +++++++++++++++++++++ include/configs/hikey.h | 5 +++-- 2 files changed, 24 insertions(+), 2 deletions(-)
board/hisilicon/hikey/hikey.c +21 -0
@@ -19,6 +19,7 @@#include <asm/arch/periph.h> #include <asm/arch/pinmux.h> #include <asm/arch/hi6220.h> +#include <asm/armv8/mmu.h> /*TODO drop this table in favour of device tree */ static const struct hikey_gpio_platdata hi6220_gpio[] = {
@@ -87,6 +88,26 @@ U_BOOT_DEVICE(hikey_seriala) = { .platdata = &serial_platdata, }; +static struct mm_region hikey_mem_map[] = { + { + .base =0x0UL , + .size =0x80000000UL , + .attrs =PTE_BLOCK_MEMTYPE (MT_NORMAL ) | +PTE_BLOCK_INNER_SHARE + }, { + .base =0x80000000UL , + .size =0x80000000UL , + .attrs =PTE_BLOCK_MEMTYPE (MT_DEVICE_NGNRNE ) | +PTE_BLOCK_NON_SHARE | +PTE_BLOCK_PXN |PTE_BLOCK_UXN + }, { +/* List terminator */ +0 , + } +}; + +struct mm_region *mem_map = hikey_mem_map; +#ifdef CONFIG_BOARD_EARLY_INIT_F int board_uart_init (void ) {
include/configs/hikey.h +3 -2
@@ -21,8 +21,9 @@#define CONFIG_SUPPORT_RAW_INITRD -/* Cache Definitions */ -#define CONFIG_SYS_DCACHE_OFF +/* MMU Definitions */ +#define CONFIG_SYS_CACHELINE_SIZE 64 +#define CONFIG_SYS_FULL_VA #define CONFIG_IDENT_STRING "hikey"
Signature · 1 line
1.8.5.6
PATCH v5 10/30 arm64: Remove non-full-va map code
In reply to Alexander GrafBy now the code to only have a single page table level with 64k page size and 42 bit address space is no longer used by any board in tree, so we can safely remove it.
To clean up code, move the layerscape mmu code to the new defines, removing redundant field definitions.
---
v1 -> v2:
- Add layerscape empty mmu table in .c file
--- arch/arm/cpu/armv8/cache_v8.c | 90 ------------------------ arch/arm/cpu/armv8/fsl-layerscape/cpu.c | 37 ++++++++-- arch/arm/include/asm/arch-fsl-layerscape/cpu.h | 94 +++++++++++++------------- arch/arm/include/asm/armv8/mmu.h | 66 +----------------- arch/arm/include/asm/global_data.h | 2 +- arch/arm/include/asm/system.h | 12 ++-- doc/README.arm64 | 20 ------ include/configs/hikey.h | 1 - include/configs/tegra210-common.h | 2 - include/configs/thunderx_88xx.h | 14 ---- include/configs/vexpress_aemv8a.h | 1 - include/configs/xilinx_zynqmp.h | 2 - 12 files changed, 85 insertions(+), 256 deletions(-)
arch/arm/cpu/armv8/cache_v8.c +0 -90
@@ -35,7 +35,6 @@ DECLARE_GLOBAL_DATA_PTR;* off: FFF */ -#ifdef CONFIG_SYS_FULL_VA static u64 get_tcr (int el,u64 *pips,u64 *pva_bits) {u64 max_addr =0 ;
@@ -386,38 +385,11 @@ static void setup_all_pgtables(void) gd->arch.tlb_addr = tlb_addr; } -#else - -inline void set_pgtable_section (u64 *page_table,u64 index,u64 section, -u64 memory_type,u64 attribute) -{ -u64 value; - - value = section |PMD_TYPE_SECT |PMD_SECT_AF ; - value |=PMD_ATTRINDX (memory_type); - value |= attribute; - page_table[index] = value; -} - -inline void set_pgtable_table (u64 *page_table,u64 index,u64 *table_addr) -{ -u64 value; - - value = (u64 )table_addr |PMD_TYPE_TABLE ; - page_table[index] = value; -} -#endif -/* to activate the MMU we need to set up virtual memory */ __weak void mmu_setup (void ) { -#ifndef CONFIG_SYS_FULL_VA -bd_t *bd = gd->bd; -u64 *page_table = (u64 *)gd->arch.tlb_addr, i, j; -#endif int el; -#ifdef CONFIG_SYS_FULL_VA /* Set up page tables only once */ if (!gd->arch.tlb_fillptr)setup_all_pgtables ();
@@ -425,40 +397,6 @@ __weak void mmu_setup(void) el =current_el ();set_ttbr_tcr_mair (el, gd->arch.tlb_addr,get_tcr (el,NULL ,NULL ),MEMORY_ATTRIBUTES ); -#else -/* Setup an identity-mapping for all spaces */ -for (i =0 ; i < (PGTABLE_SIZE >>3 ); i++) { -set_pgtable_section (page_table, i, i <<SECTION_SHIFT , -MT_DEVICE_NGNRNE ,PMD_SECT_NON_SHARE ); - } - -/* Setup an identity-mapping for all RAM space */ -for (i =0 ; i <CONFIG_NR_DRAM_BANKS ; i++) { -ulong start = bd->bi_dram[i].start; -ulong end = bd->bi_dram[i].start + bd->bi_dram[i].size; -for (j = start >>SECTION_SHIFT ; - j < end >>SECTION_SHIFT ; j++) { -set_pgtable_section (page_table, j, j <<SECTION_SHIFT , -MT_NORMAL ,PMD_SECT_NON_SHARE ); - } - } - -/* load TTBR0 */ - el =current_el (); -if (el ==1 ) { -set_ttbr_tcr_mair (el, gd->arch.tlb_addr, -TCR_EL1_RSVD |TCR_FLAGS |TCR_EL1_IPS_BITS , -MEMORY_ATTRIBUTES ); - }else if (el ==2 ) { -set_ttbr_tcr_mair (el, gd->arch.tlb_addr, -TCR_EL2_RSVD |TCR_FLAGS |TCR_EL2_IPS_BITS , -MEMORY_ATTRIBUTES ); - }else { -set_ttbr_tcr_mair (el, gd->arch.tlb_addr, -TCR_EL3_RSVD |TCR_FLAGS |TCR_EL3_IPS_BITS , -MEMORY_ATTRIBUTES ); - } -#endif /* enable the mmu */ set_sctlr (get_sctlr () |CR_M );
@@ -544,33 +482,6 @@ u64 *__weak arch_get_page_table(void) {return NULL ; } -#ifndef CONFIG_SYS_FULL_VA -void mmu_set_region_dcache_behaviour (phys_addr_t start,size_t size, -enum dcache_option option) -{ -u64 *page_table =arch_get_page_table (); -u64 upto, end; - -if (page_table ==NULL ) -return ; - - end =ALIGN (start + size, (1 <<MMU_SECTION_SHIFT )) >> -MMU_SECTION_SHIFT ; - start = start >>MMU_SECTION_SHIFT ; -for (upto = start; upto < end; upto++) { - page_table[upto] &= ~PMD_ATTRINDX_MASK ; - page_table[upto] |=PMD_ATTRINDX (option); - } - asmvolatile ("dsb sy" ); -__asm_invalidate_tlb_all (); - asmvolatile ("dsb sy" ); - asmvolatile ("isb" ); - start = start <<MMU_SECTION_SHIFT ; - end = end <<MMU_SECTION_SHIFT ; -flush_dcache_range (start, end); - asmvolatile ("dsb sy" ); -} -#else static bool is_aligned (u64 addr,u64 size,u64 align) {return !(addr & (align -1 )) && !(size & (align -1 ));
@@ -652,7 +563,6 @@ void mmu_set_region_dcache_behaviour(phys_addr_t start, size_t size,*/ flush_dcache_range(real_start, real_start + real_size); } -#endif #else /* CONFIG_SYS_DCACHE_OFF */
arch/arm/cpu/armv8/fsl-layerscape/cpu.c +32 -5
@@ -26,6 +26,14 @@DECLARE_GLOBAL_DATA_PTR ; +static struct mm_region layerscape_mem_map[] = { + { +/* List terminator */ +0 , + } +}; +struct mm_region *mem_map = layerscape_mem_map; +void cpu_name (char *name) {struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR );
@@ -48,6 +56,25 @@ void cpu_name(char *name) }#ifndef CONFIG_SYS_DCACHE_OFF +static void set_pgtable_section (u64 *page_table,u64 index,u64 section, +u64 memory_type,u64 attribute) +{ +u64 value; + + value = section |PTE_TYPE_BLOCK |PTE_BLOCK_AF ; + value |=PMD_ATTRINDX (memory_type); + value |= attribute; + page_table[index] = value; +} + +static void set_pgtable_table (u64 *page_table,u64 index,u64 *table_addr) +{ +u64 value; + + value = (u64 )table_addr |PTE_TYPE_TABLE ; + page_table[index] = value; +} +/* * Set the block entries according to the information of the table. */
@@ -114,10 +141,10 @@ static int find_table(const struct sys_mmu_table *list, temp_base -= block_size; -if ((level_table[index -1 ] &PMD_TYPE_MASK ) == -PMD_TYPE_TABLE ) { +if ((level_table[index -1 ] &PTE_TYPE_MASK ) == +PTE_TYPE_TABLE ) { level_table = (u64 *)(level_table[index -1 ] & - ~PMD_TYPE_MASK ); + ~PTE_TYPE_MASK ); level++;continue ; }else {
@@ -220,7 +247,7 @@ static inline int final_secure_ddr(u64 *level0_table,struct table_info table = {};struct sys_mmu_table ddr_entry = {0 ,0 ,BLOCK_SIZE_L1 ,MT_NORMAL , -PMD_SECT_OUTER_SHARE |PMD_SECT_NS +PTE_BLOCK_OUTER_SHARE |PTE_BLOCK_NS };u64 index;
@@ -243,7 +270,7 @@ static inline int final_secure_ddr(u64 *level0_table, ddr_entry.virt_addr = phys_addr; ddr_entry.phys_addr = phys_addr; ddr_entry.size =CONFIG_SYS_MEM_RESERVE_SECURE ; - ddr_entry.attribute =PMD_SECT_OUTER_SHARE ; + ddr_entry.attribute =PTE_BLOCK_OUTER_SHARE ; ret =find_table (&ddr_entry, &table, level0_table);if (ret) {printf ("MMU error: could not find secure ddr table\n" );
arch/arm/include/asm/arch-fsl-layerscape/cpu.h +47 -47
191 lines not on this page · raw message
arch/arm/include/asm/armv8/mmu.h +1 -65
113 lines not on this page · raw message
arch/arm/include/asm/global_data.h +1 -1
@@ -39,7 +39,7 @@ struct arch_global_data {#if !(defined(CONFIG_SYS_ICACHE_OFF ) && defined(CONFIG_SYS_DCACHE_OFF ))unsigned long tlb_addr;unsigned long tlb_size; -#if defined(CONFIG_SYS_FULL_VA ) +#if defined(CONFIG_ARM64 )unsigned long tlb_fillptr;unsigned long tlb_emerg;#endif
arch/arm/include/asm/system.h +4 -8
@@ -17,18 +17,14 @@#define CR_WXN (1 << 19)/* Write Permision Imply XN */ #define CR_EE (1 << 25)/* Exception (Big) Endian */ -/* 2MB granularity */ -#define MMU_SECTION_SHIFT 21 -#define MMU_SECTION_SIZE (1 << MMU_SECTION_SHIFT) -#ifndef __ASSEMBLY__ -#ifndef CONFIG_SYS_FULL_VA -#define PGTABLE_SIZE (0x10000) -#else u64 get_page_table_size (void );#define PGTABLE_SIZE get_page_table_size() -#endif + +/* 2MB granularity */ +#define MMU_SECTION_SHIFT 21 +#define MMU_SECTION_SIZE (1 << MMU_SECTION_SHIFT)enum dcache_option { DCACHE_OFF = 0x3,
doc/README.arm64 +0 -20
@@ -36,26 +36,6 @@ Notes 6. CONFIG_ARM64 instead of CONFIG_ARMV8 is used to distinguish aarch64 and aarch32 specific codes. -7. CONFIG_SYS_FULL_VA is used to enable 2-level page tables. For cores - supporting 64k pages it allows usage of full 48+ virtual/physical addresses - - Enabling this option requires the following ones to be defined: - - CONFIG_SYS_MEM_MAP - an array of 'struct mm_region' describing the - system memory map (start, length, attributes) - - CONFIG_SYS_MEM_MAP_SIZE - number of entries in CONFIG_SYS_MEM_MAP - - CONFIG_SYS_PTL1_ENTRIES - number of 1st level page table entries - - CONFIG_SYS_PTL2_ENTRIES - number of 1nd level page table entries - for the largest CONFIG_SYS_MEM_MAP entry - - CONFIG_COREID_MASK - the mask value used to get the core from the - MPIDR_EL1 register - - CONFIG_SYS_PTL2_BITS - number of bits addressed by the 2nd level - page tables - - CONFIG_SYS_BLOCK_SHIFT - number of bits addressed by a single block - entry from L2 page tables - - CONFIG_SYS_PGTABLE_SIZE - total size of the page table - - CONFIG_SYS_TCR_EL{1,2,3}_IPS_BITS - the IPS field of the TCR_EL{1,2,3} - - Contributor
include/configs/hikey.h +0 -1
@@ -23,7 +23,6 @@/* MMU Definitions */ #define CONFIG_SYS_CACHELINE_SIZE 64 -#define CONFIG_SYS_FULL_VA #define CONFIG_IDENT_STRING "hikey"
include/configs/tegra210-common.h +0 -2
@@ -13,8 +13,6 @@/* Cortex-A57 uses a cache line size of 64 bytes */ #define CONFIG_SYS_CACHELINE_SIZE 64 -#define CONFIG_SYS_FULL_VA -/* * NS16550 Configuration */
include/configs/thunderx_88xx.h +0 -14
@@ -22,22 +22,8 @@#define MEM_BASE 0x00500000 -#define CONFIG_SYS_FULL_VA -#define CONFIG_SYS_LOWMEM_BASE MEM_BASE -#define CONFIG_SYS_MEM_MAP_SIZE 3 - -#define CONFIG_SYS_VA_BITS 48 -#define CONFIG_SYS_PTL2_BITS 42 -#define CONFIG_SYS_BLOCK_SHIFT 29 -#define CONFIG_SYS_PTL1_ENTRIES 64 -#define CONFIG_SYS_PTL2_ENTRIES 8192 - -#define CONFIG_SYS_PGTABLE_SIZE \ - ((CONFIG_SYS_PTL1_ENTRIES + \ - CONFIG_SYS_MEM_MAP_SIZE * CONFIG_SYS_PTL2_ENTRIES) * 8) -/* Link Definitions */ #define CONFIG_SYS_TEXT_BASE 0x00500000#define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_SDRAM_BASE + 0x7fff0)
include/configs/vexpress_aemv8a.h +0 -1
@@ -21,7 +21,6 @@/* MMU Definitions */ #define CONFIG_SYS_CACHELINE_SIZE 64 -#define CONFIG_SYS_FULL_VA #define CONFIG_IDENT_STRING " vexpress_aemv8a"#define CONFIG_BOOTP_VCI_STRING "U-Boot.armv8.vexpress_aemv8a"
include/configs/xilinx_zynqmp.h +0 -2
@@ -29,8 +29,6 @@#define CONFIG_SYS_MEMTEST_START CONFIG_SYS_SDRAM_BASE#define CONFIG_SYS_MEMTEST_END CONFIG_SYS_SDRAM_SIZE -#define CONFIG_SYS_FULL_VA -/* Have release address@the end of 256MB for now */ #define CPU_RELEASE_ADDR 0xFFFFFF0
Signature · 1 line
1.8.5.6
PATCH v5 11/30 arm64: Only allow dcache disabled in SPL builds
In reply to Alexander GrafNow that we have an easy way to describe memory regions and enable the MMU, there really shouldn't be anything holding people back from running with caches enabled on AArch64. To make sure people catch early if they're missing on the caching fun, give them a compile error.
--- arch/arm/cpu/armv8/cache_v8.c | 9 +++++++++ 1 file changed, 9 insertions(+)
arch/arm/cpu/armv8/cache_v8.c +9 -0
@@ -566,6 +566,15 @@ void mmu_set_region_dcache_behaviour(phys_addr_t start, size_t size,#else /* CONFIG_SYS_DCACHE_OFF */ +/* +* For SPL builds, we may want to not have dcache enabled. Any real U-Boot +* running however really wants to have dcache and the MMU active. Check that +* everything is sane and give the developer a hint if it isn't. +*/ +#ifndef CONFIG_SPL_BUILD +#error Please describe your MMU layout in CONFIG_SYS_MEM_MAP and enable dcache. +#endif +void invalidate_dcache_all (void ) { }
Signature · 1 line
1.8.5.6
PATCH v5 12/30 disk/part.c: Expose list of available block drivers
In reply to Alexander GrafWe have a pretty nice and generic interface to ask for a specific block device. However, that one is still based around the magic notion that we know the driver name.
In order to be able to write fully generic disk access code, expose the currently internal list to other source files so that they can scan through all available block drivers.
--- disk/part.c | 7 +------ include/part.h | 8 ++++++++ 2 files changed, 9 insertions(+), 6 deletions(-)
disk/part.c +1 -6
@@ -20,13 +20,8 @@ #define PRINTF(fmt,args...)#endif -struct block_drvr { -char *name; -block_dev_desc_t * (*get_dev)(int dev); -int (*select_hwpart)(int dev_num,int hwpart); -}; -static const struct block_drvr block_drvr[] = { +const struct block_drvr block_drvr[] = {#if defined(CONFIG_CMD_IDE ) { .name = "ide", .get_dev = ide_get_dev, }, #endif
include/part.h +8 -0
@@ -42,6 +42,12 @@ struct block_dev_desc {void *priv;/* driver private struct pointer */ }; +struct block_drvr { +char *name; +block_dev_desc_t * (*get_dev)(int dev); +int (*select_hwpart)(int dev_num,int hwpart); +}; +#define BLOCK_CNT (size, block_dev_desc) (PAD_COUNT(size, block_dev_desc->blksz))#define PAD_TO_BLOCKSIZE (size, block_dev_desc) \ (PAD_SIZE(size, block_dev_desc->blksz))
@@ -123,6 +129,8 @@ int get_device(const char *ifname, const char *dev_str,int get_device_and_partition (const char *ifname,const char *dev_part_str,block_dev_desc_t **dev_desc,disk_partition_t *info,int allow_whole_dev); + +extern const struct block_drvr block_drvr[];#else static inline block_dev_desc_t *get_dev (const char *ifname,int dev) {return NULL ; }
Signature · 1 line
1.8.5.6
PATCH v5 13/30 include/efi_api.h: Add more detailed API definitions
In reply to Alexander GrafThe EFI API header is great, but missing a good chunk of function prototype, GUID defines and enum declarations.
This patch extends it to cover more of the EFI API. It's still not 100% complete, but sufficient enough for our EFI payload interface.
---
v2 -> v3:
- Add EFIAPI to notify_function
- Add access denied code
v3 -> v4:
- Add EFI_PAGE_MASK define
--- include/efi.h | 2 + include/efi_api.h | 198 ++++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 163 insertions(+), 37 deletions(-)
include/efi.h +2 -0
@@ -38,6 +38,7 @@ struct efi_device_path;#define EFI_WRITE_PROTECTED (8 | (1UL << (BITS_PER_LONG - 1)))#define EFI_OUT_OF_RESOURCES (9 | (1UL << (BITS_PER_LONG - 1)))#define EFI_NOT_FOUND (14 | (1UL << (BITS_PER_LONG - 1))) +#define EFI_ACCESS_DENIED (15 | (1UL << (BITS_PER_LONG - 1)))#define EFI_SECURITY_VIOLATION (26 | (1UL << (BITS_PER_LONG - 1)))typedef unsigned long efi_status_t ;
@@ -139,6 +140,7 @@ enum {#define EFI_PAGE_SHIFT 12#define EFI_PAGE_SIZE (1UL << EFI_PAGE_SHIFT) +#define EFI_PAGE_MASK (EFI_PAGE_SIZE - 1)struct efi_mem_desc {u32 type;
include/efi_api.h +161 -37
305 lines not on this page · raw message
Signature · 1 line
1.8.5.6
PATCH v5 14/30 efi_loader: Add PE image loader
In reply to Alexander GrafEFI uses the PE binary format for its application images. Add support to EFI PE binaries as well as all necessary bits for the "EFI image loader" interfaces.
---
v1 -> v2:
- move memory allocation to separate patch
- limit 32/64 to hosts that support it
- check 32bit optional nt header magic
- switch to GPL2+
v2 -> v3:
- use efi_alloc
- add EFIAPI to function prototypes
- remove unused macros
- reorder header inclusion
- split relocation code into function
- flush cache after loading
v3 -> v4:
- Use EFI_PAGE_SHIFT define
- Flush icache after image load
- Fix white space in pe header
v4 -> v5:
- Provide icache flush stub for archs which don't have it
--- include/efi_loader.h | 20 +++ include/pe.h | 263 ++++++++++++++++++++++++++++++++++++++ lib/efi_loader/efi_image_loader.c | 188 +++++++++++++++++++++++++++ 3 files changed, 471 insertions(+) create mode 100644 include/efi_loader.h create mode 100644 include/pe.h create mode 100644 lib/efi_loader/efi_image_loader.c
include/efi_loader.h new file +20 -0
@@ -0,0 +1,20 @@ +/* +* EFI application loader +* +* Copyright (c) 2016 Alexander Graf +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <part_efi.h> +#include <efi_api.h> +#include <linux/list.h> + +extern const efi_guid_t efi_guid_device_path; +extern const efi_guid_t efi_guid_loaded_image; + +efi_status_t efi_return_handle (void *handle, +efi_guid_t *protocol,void **protocol_interface, +void *agent_handle,void *controller_handle, +uint32_t attributes); +void *efi_load_pe (void *efi,struct efi_loaded_image *loaded_image_info);
include/pe.h new file +263 -0
263 lines not on this page · raw message
lib/efi_loader/efi_image_loader.c new file +188 -0
188 lines not on this page · raw message
Signature · 1 line
1.8.5.6
PATCH v5 15/30 efi_loader: Add boot time services
In reply to Alexander GrafWhen an EFI application runs, it has access to a few descriptor and callback tables to instruct the EFI compliant firmware to do things for it. The bulk of those interfaces are "boot time services". They handle all object management, and memory allocation.
This patch adds support for the boot time services and also exposes a system table, which is the point of entry descriptor table for EFI payloads.
---
v1 -> v2:
- Fix typo s/does now/does not/
- Add #ifdefs around header to allow inclusion when efi_loader is disabled
- Add stub efi_restore_gd() function when efi_loader is disabled
- Disable debug
- Mark runtime region as such
- Fix up memory map
- Allow efi_restore_gd to be called before first efi entry
- Add 32bit arm cache workaround
- Move memory map to separate patch
- Change BTS version to 2.5
- Fix return values for a few callbacks to more EFI compliant ones
- Change vendor to "Das U-Boot"
- Add warning when truncating timer trigger
- Move to GPLv2+
v2 -> v3:
- Use external efi_memory helpers
- Add EFIAPI to function prototypes
- Initialize event timer to -1ULL to prevent early firing
- Document header
- Move obj list to lib
- Remove implicit guid table
- Add guid compare function
- Fix return values
- Implement efi_wait_for_event
- Implement efi_install_configuration_table
v3 -> v4:
- s/polimorphic/polymorphic
--- include/efi_loader.h | 84 +++++ lib/efi_loader/efi_boottime.c | 781 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 865 insertions(+) create mode 100644 lib/efi_loader/efi_boottime.c
include/efi_loader.h +84 -0
@@ -6,15 +6,99 @@* SPDX-License-Identifier: GPL-2.0+ */ +#include <common.h> #include <part_efi.h> #include <efi_api.h> + +#ifdef CONFIG_EFI_LOADER +#include <linux/list.h> +/* #define DEBUG_EFI */ + +#ifdef DEBUG_EFI +#define EFI_ENTRY (format, ...) do { \ + efi_restore_gd(); \ + printf("EFI: Entry %s(" format ")\n", __func__, ##__VA_ARGS__); \ + } while(0) +#else +#define EFI_ENTRY (format, ...) do { \ + efi_restore_gd(); \ + } while(0) +#endif + +#define EFI_EXIT (ret) efi_exit_func(ret); + +extern struct efi_system_table systab; +extern const efi_guid_t efi_guid_device_path;extern const efi_guid_t efi_guid_loaded_image; +/* +* While UEFI objects can have callbacks, you can also call functions on +* protocols (classes) themselves. This struct maps a protocol GUID to its +* interface (usually a struct with callback functions). +*/ +struct efi_class_map { +const efi_guid_t *guid; +const void *interface; +}; + +/* +* When the UEFI payload wants to open a protocol on an object to get its +* interface (usually a struct with callback functions), this struct maps the +* protocol GUID to the respective protocol handler open function for that +* object protocol combination. +*/ +struct efi_handler { +const efi_guid_t *guid; + efi_status_t (EFIAPI *open)(void *handle, + efi_guid_t *protocol, void **protocol_interface, + void *agent_handle, void *controller_handle, + uint32_t attributes); +}; + +/* +* UEFI has a poor man's OO model where one "object" can be polymorphic and have +* multiple different protocols (classes) attached to it. +* +* This struct is the parent struct for all of our actual implementation objects +* that can include it to make themselves an EFI object +*/ +struct efi_object { +/* Every UEFI object is part of a global object list */ +struct list_head link; +/* We support up to 4 "protocols" an object can be accessed through */ +struct efi_handler protocols[4 ]; +/* The object spawner can either use this for data or as identifier */ +void *handle; +}; + +/* This list contains all UEFI objects we know of */ +extern struct list_head efi_obj_list; + +/* +* Stub implementation for a protocol opener that just returns the handle as +* interface +*/ efi_status_t efi_return_handle (void *handle,efi_guid_t *protocol,void **protocol_interface,void *agent_handle,void *controller_handle,uint32_t attributes); +/* Called from places to check whether a timer expired */ +void efi_timer_check (void ); +/* PE loader implementation */ void *efi_load_pe (void *efi,struct efi_loaded_image *loaded_image_info); +/* Called once to store the pristine gd pointer */ +void efi_save_gd (void ); +/* Called from EFI_ENTRY on callback entry to put gd into the gd register */ +void efi_restore_gd (void ); +/* Called from EFI_EXIT on callback exit to restore the gd register */ +efi_status_t efi_exit_func (efi_status_t ret); + +#else /* defined(EFI_LOADER) */ + +/* No loader configured, stub out EFI_ENTRY */ +static inline void efi_restore_gd (void ) { } + +#endif
lib/efi_loader/efi_boottime.c new file +781 -0
781 lines not on this page · raw message
Signature · 1 line
1.8.5.6
PATCH v5 16/30 efi_loader: Add console interface
In reply to Alexander GrafOne of the basic EFI interfaces is the console interface. Using it an EFI application can interface with the user. This patch implements an EFI console interface using getc() and putc().
Today, we only implement text based consoles. We also convert the EFI Unicode characters to UTF-8 on the fly, hoping that everyone managed to jump on the train by now.
---
v1 -> v2:
- Move to GPLv2+
v2 -> v3:
- Add EFIAPI to function prototypes
v3 -> v4:
- return EFI_SUCCESS in efi_cout_enable_cursor()
--- include/efi_loader.h | 5 + lib/efi_loader/efi_console.c | 360 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 365 insertions(+) create mode 100644 lib/efi_loader/efi_console.c
include/efi_loader.h +5 -0
@@ -31,6 +31,11 @@extern struct efi_system_table systab; +extern const struct efi_simple_text_output_protocol efi_con_out; +extern const struct efi_simple_input_interface efi_con_in; +extern const struct efi_console_control_protocol efi_console_control; + +extern const efi_guid_t efi_guid_console_control;extern const efi_guid_t efi_guid_device_path;extern const efi_guid_t efi_guid_loaded_image;
lib/efi_loader/efi_console.c new file +360 -0
360 lines not on this page · raw message
Signature · 1 line
1.8.5.6
PATCH v5 17/30 efi_loader: Add runtime services
In reply to Alexander GrafAfter booting has finished, EFI allows firmware to still interact with the OS using the "runtime services". These callbacks live in a separate address space, since they are available long after U-Boot has been overwritten by the OS.
This patch adds enough framework for arbitrary code inside of U-Boot to become a runtime service with the right section attributes set. For now, we don't make use of it yet though.
We could maybe in the future map U-boot environment variables to EFI variables here.
---
v1 -> v2:
- Fix runtime service sections
- Add runtime detach
- Enable runtime relocations
- Add get_time
- Fix relocation
- Fix 32bit
- Add am335x support
- Move section definition to header
- Add systab to runtime section
- Add self-relocation hook table
- Fix self-relocation
- Relocate efi_runtime section early during bootup
- Fix return values for a number of callbacks to be more UEFI compliant
- Move to GPLv2+
v2 -> v3:
- Patch reset to NULL
- Add EFIAPI to function prototypes
- Document header
- Add dm.h include
- Remove non-dm rtc support
- Return DEVICE_ERROR in rtc path
--- arch/arm/config.mk | 4 + arch/arm/cpu/armv8/u-boot.lds | 16 +++ arch/arm/cpu/u-boot.lds | 30 +++++ arch/arm/lib/sections.c | 4 + board/ti/am335x/u-boot.lds | 30 +++++ common/board_r.c | 4 + include/efi_loader.h | 17 +++ lib/efi_loader/efi_boottime.c | 6 +- lib/efi_loader/efi_runtime.c | 290 ++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 398 insertions(+), 3 deletions(-) create mode 100644 lib/efi_loader/efi_runtime.c
arch/arm/config.mk +4 -0
@@ -122,6 +122,10 @@ ifdef CONFIG_OF_EMBED OBJCOPYFLAGS += -j .dtb.init.rodata endif +ifdef CONFIG_EFI_LOADER +OBJCOPYFLAGS += -j .efi_runtime -j .efi_runtime_rel +endif + ifneq ($(CONFIG_IMX_CONFIG),) ifdef CONFIG_SPL ifndef CONFIG_SPL_BUILD
arch/arm/cpu/armv8/u-boot.lds +16 -0
@@ -42,6 +42,22 @@ SECTIONS . = ALIGN(8); + .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(8); + .image_copy_end : { *(.__image_copy_end)
arch/arm/cpu/u-boot.lds +30 -0
@@ -90,6 +90,36 @@ SECTIONS . = ALIGN(4); + .__efi_runtime_start : { + *(.__efi_runtime_start) + } + + .efi_runtime : { + *(efi_runtime_text) + *(efi_runtime_data) + } + + .__efi_runtime_stop : { + *(.__efi_runtime_stop) + } + + .efi_runtime_rel_start : + { + *(.__efi_runtime_rel_start) + } + + .efi_runtime_rel : { + *(.relefi_runtime_text) + *(.relefi_runtime_data) + } + + .efi_runtime_rel_stop : + { + *(.__efi_runtime_rel_stop) + } + + . = ALIGN(4); + .image_copy_end : { *(.__image_copy_end)
arch/arm/lib/sections.c +4 -0
@@ -27,4 +27,8 @@ char __rel_dyn_start[0] __attribute__((section(".__rel_dyn_start"))); char __rel_dyn_end[0] __attribute__((section(".__rel_dyn_end"))); char __secure_start[0] __attribute__((section(".__secure_start"))); char __secure_end[0] __attribute__((section(".__secure_end"))); +char __efi_runtime_start[0] __attribute__((section(".__efi_runtime_start"))); +char __efi_runtime_stop[0] __attribute__((section(".__efi_runtime_stop"))); +char __efi_runtime_rel_start[0] __attribute__((section(".__efi_runtime_rel_start"))); +char __efi_runtime_rel_stop[0] __attribute__((section(".__efi_runtime_rel_stop"))); char _end[0] __attribute__((section(".__end")));
board/ti/am335x/u-boot.lds +30 -0
@@ -59,6 +59,36 @@ SECTIONS . = ALIGN(4); + .__efi_runtime_start : { + *(.__efi_runtime_start) + } + + .efi_runtime : { + *(efi_runtime_text) + *(efi_runtime_data) + } + + .__efi_runtime_stop : { + *(.__efi_runtime_stop) + } + + .efi_runtime_rel_start : + { + *(.__efi_runtime_rel_start) + } + + .efi_runtime_rel : { + *(.relefi_runtime_text) + *(.relefi_runtime_data) + } + + .efi_runtime_rel_stop : + { + *(.__efi_runtime_rel_stop) + } + + . = ALIGN(4); + .image_copy_end : { *(.__image_copy_end)
common/board_r.c +4 -0
@@ -65,6 +65,7 @@#ifdef CONFIG_AVR32 #include <asm/arch/mmu.h> #endif +#include <efi_loader.h> DECLARE_GLOBAL_DATA_PTR ;
@@ -177,6 +178,9 @@ static int initr_reloc_global_data(void)*/ gd->fdt_blob += gd->reloc_off;#endif +#ifdef CONFIG_EFI_LOADER +efi_runtime_relocate (gd->relocaddr,NULL ); +#endif return 0 ; }
include/efi_loader.h +17 -0
@@ -29,6 +29,7 @@#define EFI_EXIT (ret) efi_exit_func(ret); +extern struct efi_runtime_services efi_runtime_services;extern struct efi_system_table systab;extern const struct efi_simple_text_output_protocol efi_con_out;
@@ -39,6 +40,9 @@ extern const efi_guid_t efi_guid_console_control;extern const efi_guid_t efi_guid_device_path;extern const efi_guid_t efi_guid_loaded_image; +extern unsigned int __efi_runtime_start, __efi_runtime_stop; +extern unsigned int __efi_runtime_rel_start, __efi_runtime_rel_stop; +/* * While UEFI objects can have callbacks, you can also call functions on * protocols (classes) themselves. This struct maps a protocol GUID to its
@@ -100,9 +104,22 @@ void efi_save_gd(void);void efi_restore_gd (void );/* Called from EFI_EXIT on callback exit to restore the gd register */ efi_status_t efi_exit_func (efi_status_t ret); +/* Call this to relocate the runtime section to an address space */ +void efi_runtime_relocate (ulong offset,struct efi_mem_desc *map); + +/* +* Use these to indicate that your code / data should go into the EFI runtime +* section and thus still be available when the OS is running +*/ +#define EFI_RUNTIME_DATA __attribute__ ((section ("efi_runtime_data"))) +#define EFI_RUNTIME_TEXT __attribute__ ((section ("efi_runtime_text")))#else /* defined(EFI_LOADER) */ +/* Without CONFIG_EFI_LOADER we don't have a runtime section, stub it out */ +#define EFI_RUNTIME_DATA +#define EFI_RUNTIME_TEXT +/* No loader configured, stub out EFI_ENTRY */ static inline void efi_restore_gd (void ) { }
lib/efi_loader/efi_boottime.c +3 -3
@@ -39,7 +39,7 @@ static bool efi_is_direct_boot = true;* In most cases we want to pass an FDT to the payload, so reserve one slot of * config table space for it. The pointer gets populated by do_bootefi_exec(). */ -static struct efi_configuration_table efi_conf_table[1 ]; +static struct efi_configuration_table EFI_RUNTIME_DATA efi_conf_table[1];/* * The "gd" pointer lives in a register on ARM and AArch64 that we declare
@@ -761,10 +761,10 @@ static const struct efi_boot_services efi_boot_services = { }; -static uint16_t firmware_vendor[] = +static uint16_t EFI_RUNTIME_DATA firmware_vendor[] = {'D' ,'a' ,'s' ,' ' ,'U' ,'-' ,'b' ,'o' ,'o' ,'t' ,0 }; -struct efi_system_table systab = { +struct efi_system_table EFI_RUNTIME_DATA systab = { .hdr = { .signature =EFI_SYSTEM_TABLE_SIGNATURE , .revision =0x20005 ,/* 2.5 */
lib/efi_loader/efi_runtime.c new file +290 -0
290 lines not on this page · raw message
Signature · 1 line
1.8.5.6
PATCH v5 18/30 efi_loader: Add disk interfaces
In reply to Alexander GrafA EFI applications usually want to access storage devices to load data from.
This patch adds support for EFI disk interfaces. It loops through all block storage interfaces known to U-Boot and creates an EFI object for each existing one. EFI applications can then through these objects call U-Boot's read and write functions.
---
v1 -> v2:
- Move to block_drvr array
- Move to GPLv2+
- Fix header order
- Document efi block object struct
- Use calloc rather than malloc & memset
v2 -> v3:
- Adapt to newer u-boot block API
- Add EFIAPI to function prototypes
- Document header
- Check for DEV_TYPE_UNKNOWN
- Document 16byte limit for dp string
--- include/efi_loader.h | 2 + lib/efi_loader/efi_disk.c | 218 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 220 insertions(+) create mode 100644 lib/efi_loader/efi_disk.c
include/efi_loader.h +2 -0
@@ -86,6 +86,8 @@ struct efi_object {/* This list contains all UEFI objects we know of */ extern struct list_head efi_obj_list; +/* Called by bootefi to make all disk storage accessible as EFI objects */ +int efi_disk_register (void );/* * Stub implementation for a protocol opener that just returns the handle as * interface
lib/efi_loader/efi_disk.c new file +218 -0
218 lines not on this page · raw message
Signature · 1 line
1.8.5.6
PATCH v5 19/30 efi_loader: Add "bootefi" command
In reply to Alexander GrafIn order to execute an EFI application, we need to bridge the gap between U-Boot's notion of executing images and EFI's notion of doing the same.
The best path forward IMHO here is to stick completely to the way U-Boot deals with payloads. You manually load them using whatever method to RAM and then have a simple boot command to execute them. So in our case, you would do
# load mmc 0:1 $loadaddr grub.efi # bootefi $loadaddr
which then gets you into a grub shell. Fdt information known to U-boot via the fdt addr command is also passed to the EFI payload.
---
v1 -> v2:
- Move to GPLv2+
v2 -> v3:
- Move to new cmd directory
- Add kconfig option
- Fix comment style
- Add help text
- s/-1/-ENOENT
- Move obj list to lib
v4 -> v5:
- Mark fdt memory as boot services data
--- cmd/Kconfig | 7 +++ cmd/Makefile | 1 + cmd/bootefi.c | 178 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 186 insertions(+) create mode 100644 cmd/bootefi.c
cmd/Kconfig +7 -0
@@ -148,6 +148,13 @@ config CMD_BOOTM help Boot an application image from the memory. +config CMD_BOOTEFI + bool "bootefi" + depends on EFI_LOADER + default y + help + Boot an EFI image from memory. + config CMD_ELF bool "bootelf, bootvx" default y
cmd/Makefile +1 -0
@@ -21,6 +21,7 @@ obj-$(CONFIG_CMD_SOURCE) += source.o obj-$(CONFIG_CMD_BDI) += bdinfo.o obj-$(CONFIG_CMD_BEDBUG) += bedbug.o obj-$(CONFIG_CMD_BMP) += bmp.o +obj-$(CONFIG_CMD_BOOTEFI) += bootefi.o obj-$(CONFIG_CMD_BOOTMENU) += bootmenu.o obj-$(CONFIG_CMD_BOOTLDR) += bootldr.o obj-$(CONFIG_CMD_BOOTSTAGE) += bootstage.o
cmd/bootefi.c new file +178 -0
178 lines not on this page · raw message
Signature · 1 line
1.8.5.6
PATCH v5 20/30 efi_loader: Implement memory allocation and map
In reply to Alexander GrafThe EFI loader needs to maintain views of memory - general system memory windows as well as used locations inside those and potential runtime service MMIO windows.
To manage all of these, add a few helpers that maintain an internal representation of the map the similar to how the EFI API later on reports it to the application.
For allocations, the scheme is very simple. We basically allow allocations to replace chunks of previously done maps, so that a new LOADER_DATA allocation for example can remove a piece of the RAM map. When no specific address is given, we just take the highest possible address in the lowest RAM map that fits the allocation size.
---
v2 -> v3:
- Rewrite memory allocation and map
- Document header
v3 -> v4:
- Use EFI_PAGE_.* defines
- Return EFI_OUT_OF_RESOURCES in efi_allocate_pages
--- common/board_r.c | 3 + include/efi_loader.h | 19 +++ lib/efi_loader/efi_memory.c | 319 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 341 insertions(+) create mode 100644 lib/efi_loader/efi_memory.c
common/board_r.c +3 -0
@@ -795,6 +795,9 @@ init_fnc_t init_sequence_r[] = {#ifdef CONFIG_CLOCKS set_cpu_clk_info, /* Setup clock information */#endif +#ifdef CONFIG_EFI_LOADER + efi_memory_init, +#endif stdio_init_tables, initr_serial, initr_announce,
include/efi_loader.h +19 -0
@@ -109,6 +109,25 @@ efi_status_t efi_exit_func(efi_status_t ret);/* Call this to relocate the runtime section to an address space */ void efi_runtime_relocate (ulong offset,struct efi_mem_desc *map); +/* Generic EFI memory allocator, call this to get memory */ +void *efi_alloc (uint64_t len,int memory_type); +/* More specific EFI memory allocator, called by EFI payloads */ +efi_status_t efi_allocate_pages (int type,int memory_type,unsigned long pages, +uint64_t *memory); +/* EFI memory free function. Not implemented today */ +efi_status_t efi_free_pages (uint64_t memory,unsigned long pages); +/* Returns the EFI memory map */ +efi_status_t efi_get_memory_map (unsigned long *memory_map_size, +struct efi_mem_desc *memory_map, +unsigned long *map_key, +unsigned long *descriptor_size, +uint32_t *descriptor_version); +/* Adds a range into the EFI memory map */ +uint64_t efi_add_memory_map (uint64_t start,uint64_t pages,int memory_type, +bool overlap_only_ram); +/* Called by board init to initialize the EFI memory map */ +int efi_memory_init (void ); +/* * Use these to indicate that your code / data should go into the EFI runtime * section and thus still be available when the OS is running
lib/efi_loader/efi_memory.c new file +319 -0
319 lines not on this page · raw message
Signature · 1 line
1.8.5.6
PATCH v5 21/30 arm64: Allow exceptions to return
In reply to Alexander GrafOur current arm64 exception handlers all panic and never return to the exception triggering code.
But if any handler wanted to continue execution after fixups, it would need help from the exception handling code to restore all registers.
This patch implements that help. With this code, exception handlers on aarch64 can successfully return to the place the exception happened (or somewhere else if they modify elr).
--- arch/arm/cpu/armv8/exceptions.S | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
arch/arm/cpu/armv8/exceptions.S +34 -0
@@ -82,31 +82,65 @@ vectors: _do_bad_sync: exception_entry bl do_bad_sync + b exception_exit _do_bad_irq: exception_entry bl do_bad_irq + b exception_exit _do_bad_fiq: exception_entry bl do_bad_fiq + b exception_exit _do_bad_error: exception_entry bl do_bad_error + b exception_exit _do_sync: exception_entry bl do_sync + b exception_exit _do_irq: exception_entry bl do_irq + b exception_exit _do_fiq: exception_entry bl do_fiq + b exception_exit _do_error: exception_entry bl do_error + b exception_exit + +exception_exit: + ldp x2, x0, [sp],#16 + switch_el x11, 3f, 2f, 1f +3: msr elr_el3, x2 + b 0f +2: msr elr_el2, x2 + b 0f +1: msr elr_el1, x2 +0: + ldp x1, x2, [sp],#16 + ldp x3, x4, [sp],#16 + ldp x5, x6, [sp],#16 + ldp x7, x8, [sp],#16 + ldp x9, x10, [sp],#16 + ldp x11, x12, [sp],#16 + ldp x13, x14, [sp],#16 + ldp x15, x16, [sp],#16 + ldp x17, x18, [sp],#16 + ldp x19, x20, [sp],#16 + ldp x21, x22, [sp],#16 + ldp x23, x24, [sp],#16 + ldp x25, x26, [sp],#16 + ldp x27, x28, [sp],#16 + ldp x29, x30, [sp],#16 + eret
Signature · 1 line
1.8.5.6
PATCH v5 22/30 arm64: Allow EFI payload code to take exceptions
In reply to Alexander GrafThere are 2 ways an EFI payload could return into u-boot:
- Callback function
- Exception
While in EFI payload mode, x18 is owned by the payload and may not contain a valid pointer to gd, so we need to fix it up. We do that properly for the payload to callback path already.
This patch also adds gd pointer restoral for the exception path.
--- arch/arm/lib/interrupts_64.c | 9 +++++++++ 1 file changed, 9 insertions(+)
arch/arm/lib/interrupts_64.c +9 -0
@@ -7,6 +7,7 @@#include <common.h> #include <linux/compiler.h> +#include <efi_loader.h> int interrupt_init (void )
@@ -41,6 +42,7 @@ void show_regs(struct pt_regs *regs)*/ void do_bad_sync (struct pt_regs *pt_regs,unsigned int esr) { +efi_restore_gd ();printf ("Bad mode in \"Synchronous Abort\" handler, esr 0x%08x\n" , esr);show_regs (pt_regs);panic ("Resetting CPU ...\n" );
@@ -51,6 +53,7 @@ void do_bad_sync(struct pt_regs *pt_regs, unsigned int esr)*/ void do_bad_irq (struct pt_regs *pt_regs,unsigned int esr) { +efi_restore_gd ();printf ("Bad mode in \"Irq\" handler, esr 0x%08x\n" , esr);show_regs (pt_regs);panic ("Resetting CPU ...\n" );
@@ -61,6 +64,7 @@ void do_bad_irq(struct pt_regs *pt_regs, unsigned int esr)*/ void do_bad_fiq (struct pt_regs *pt_regs,unsigned int esr) { +efi_restore_gd ();printf ("Bad mode in \"Fiq\" handler, esr 0x%08x\n" , esr);show_regs (pt_regs);panic ("Resetting CPU ...\n" );
@@ -71,6 +75,7 @@ void do_bad_fiq(struct pt_regs *pt_regs, unsigned int esr)*/ void do_bad_error (struct pt_regs *pt_regs,unsigned int esr) { +efi_restore_gd ();printf ("Bad mode in \"Error\" handler, esr 0x%08x\n" , esr);show_regs (pt_regs);panic ("Resetting CPU ...\n" );
@@ -81,6 +86,7 @@ void do_bad_error(struct pt_regs *pt_regs, unsigned int esr)*/ void do_sync (struct pt_regs *pt_regs,unsigned int esr) { +efi_restore_gd ();printf ("\"Synchronous Abort\" handler, esr 0x%08x\n" , esr);show_regs (pt_regs);panic ("Resetting CPU ...\n" );
@@ -91,6 +97,7 @@ void do_sync(struct pt_regs *pt_regs, unsigned int esr)*/ void do_irq (struct pt_regs *pt_regs,unsigned int esr) { +efi_restore_gd ();printf ("\"Irq\" handler, esr 0x%08x\n" , esr);show_regs (pt_regs);panic ("Resetting CPU ...\n" );
@@ -101,6 +108,7 @@ void do_irq(struct pt_regs *pt_regs, unsigned int esr)*/ void do_fiq (struct pt_regs *pt_regs,unsigned int esr) { +efi_restore_gd ();printf ("\"Fiq\" handler, esr 0x%08x\n" , esr);show_regs (pt_regs);panic ("Resetting CPU ...\n" );
@@ -114,6 +122,7 @@ void do_fiq(struct pt_regs *pt_regs, unsigned int esr)*/ void __weak do_error (struct pt_regs *pt_regs,unsigned int esr) { +efi_restore_gd ();printf ("\"Error\" handler, esr 0x%08x\n" , esr);show_regs (pt_regs);panic ("Resetting CPU ...\n" );
Signature · 1 line
1.8.5.6
PATCH v5 23/30 efi_loader: hook up in build environment
In reply to Alexander GrafNow that we have all the bits and pieces ready for EFI payload loading support, hook them up in Makefiles and KConfigs so that we can build.
---
v1 -> v2:
- Move to GPLv2+
- Default to y
v2 -> v3:
- Add memory file
--- lib/Kconfig | 1 + lib/Makefile | 1 + lib/efi_loader/Kconfig | 9 +++++++++ lib/efi_loader/Makefile | 12 ++++++++++++ 4 files changed, 23 insertions(+) create mode 100644 lib/efi_loader/Kconfig create mode 100644 lib/efi_loader/Makefile
lib/Kconfig +1 -0
@@ -129,5 +129,6 @@ config ERRNO_STR - if errno is negative - a pointer to errno related message source lib/efi/Kconfig +source lib/efi_loader/Kconfig endmenu
lib/Makefile +1 -0
@@ -8,6 +8,7 @@ ifndef CONFIG_SPL_BUILD obj-$(CONFIG_EFI) += efi/ +obj-$(CONFIG_EFI_LOADER) += efi_loader/ obj-$(CONFIG_RSA) += rsa/ obj-$(CONFIG_LZMA) += lzma/ obj-$(CONFIG_LZO) += lzo/
lib/efi_loader/Kconfig new file +9 -0
@@ -0,0 +1,9 @@ +config EFI_LOADER + bool "Support running EFI Applications in U-Boot" + depends on ARM64 ||?ARM + default y + help + Select this option if you want to run EFI applications (like grub2) + on top of U-Boot. If this option is enabled, U-Boot will expose EFI + interfaces to a loaded EFI application, enabling it to reuse U-Boot's + device drivers.
lib/efi_loader/Makefile new file +12 -0
@@ -0,0 +1,12 @@ +# +# (C) Copyright 2016 Alexander Graf +# +# SPDX-License-Identifier: GPL-2.0+ +# + +# This file only gets included with CONFIG_EFI_LOADER set, so all +# object inclusion implicitly depends on it + +obj-y += efi_image_loader.o efi_boottime.o efi_runtime.o efi_console.o +obj-y += efi_memory.o +obj-$(CONFIG_PARTITIONS) += efi_disk.o
Signature · 1 line
1.8.5.6
PATCH v5 24/30 efi_loader: Add distro boot script for removable media
In reply to Alexander GrafUEFI defines a simple boot protocol for removable media. There we should look at the EFI (first GPT FAT) partition and search for /efi/boot/bootXXX.efi with XXX being different between different platforms (x86, x64, arm, aa64, ...).
This patch implements a simple version of that protocol for the default distro boot script. With this we can automatically boot from valid UEFI enabled removable media.
Because from all I could see U-Boot by default doesn't deliver device tree blobs with its firmware, we also need to load the dtb from somewhere. Traverse the same EFI partition for an fdt file that fits our current board so that an OS receives a valid device tree when booted automatically.
--- include/config_distro_bootcmd.h | 47 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-)
include/config_distro_bootcmd.h +46 -1
@@ -90,6 +90,48 @@ BOOT_TARGET_DEVICES_references_UBIFS_without_CONFIG_CMD_UBIFS#endif +#ifdef CONFIG_EFI_LOADER +#if defined(CONFIG_ARM64 ) +#define BOOTEFI_NAME "bootaa64.efi" +#elif defined(CONFIG_ARM ) +#define BOOTEFI_NAME "bootarm.efi" +#endif +#endif + +#ifdef BOOTEFI_NAME +#define BOOTENV_SHARED_EFI \ + "boot_efi_binary=" \ + "load ${devtype} ${devnum}:${distro_bootpart} " \ + "${kernel_addr_r} efi/boot/"BOOTEFI_NAME"; " \ + "bootefi ${kernel_addr_r}\0" \ + \ + "load_efi_dtb=" \ + "load ${devtype} ${devnum}:${distro_bootpart} " \ + "${fdt_addr_r} ${prefix}${fdt_name}; " \ + "fdt addr ${fdt_addr_r}\0" \ + \ + "efi_dtb_prefixes=/ /dtb/ /dtb/current/\0" \ + "scan_dev_for_efi=" \ + "for prefix in ${efi_dtb_prefixes}; do " \ + "if test -e ${devtype} " \ + "${devnum}:${distro_bootpart} " \ + "${prefix}${fdt_name}; then " \ + "run load_efi_dtb; " \ + "fi;" \ + "done;" \ + "if test -e ${devtype} ${devnum}:${distro_bootpart} " \ + "efi/boot/"BOOTEFI_NAME"; then " \ + "echo Found EFI removable media binary " \ + "efi/boot/"BOOTEFI_NAME"; " \ + "run boot_efi_binary; " \ + "echo EFI LOAD FAILED: continuing...; " \ + "fi; " +#define SCAN_DEV_FOR_EFI "run scan_dev_for_efi;" +#else +#define BOOTENV_SHARED_EFI +#define SCAN_DEV_FOR_EFI +#endif +#ifdef CONFIG_CMD_SATA #define BOOTENV_SHARED_SATA BOOTENV_SHARED_BLKDEV(sata)#define BOOTENV_DEV_SATA BOOTENV_DEV_BLKDEV
@@ -217,6 +259,7 @@BOOTENV_SHARED_SCSI \ BOOTENV_SHARED_IDE \BOOTENV_SHARED_UBIFS \ + BOOTENV_SHARED_EFI \"boot_prefixes=/ /boot/\0" \"boot_scripts=boot.scr.uimg boot.scr\0" \"boot_script_dhcp=boot.scr.uimg\0" \
@@ -258,7 +301,9 @@"for prefix in ${boot_prefixes}; do " \"run scan_dev_for_extlinux; " \"run scan_dev_for_scripts; " \ -"done\0" \ +"done;" \ +SCAN_DEV_FOR_EFI \ +"\0" \ \"scan_dev_for_boot_part=" \"part list ${devtype} ${devnum} -bootable devplist; " \
Signature · 1 line
1.8.5.6
PATCH v5 25/30 efi_loader: Add README section in README.efi
In reply to Alexander GrafTo preserve all cover letter knowledge of the status on UEFI payload support, let's add some sections to README.efi.
v3 -> v4:
- Add section about config options
- s/10kb/10KB/
--- doc/README.efi | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-)
doc/README.efi +82 -1
@@ -4,6 +4,28 @@ # SPDX-License-Identifier: GPL-2.0+ # +=========== Table of Contents =========== + + 1 U-Boot on EFI + 1.1 In God's Name, Why? + 1.2 Status + 1.3 Build Instructions + 1.4 Trying it out + 1.5 Inner workings + 1.6 EFI Application + 1.7 EFI Payload + 1.8 Tables + 1.9 Interrupts + 1.10 32/64-bit + 1.11 Future work + 1.12 Where is the code? + + 2 EFI on U-Boot + 2.1 In God's Name, Why? + 2.2 How do I get it? + 2.3 Status + 2.4 Future work + U-Boot on EFI ============= This document provides information about U-Boot running on top of EFI, either
@@ -234,7 +256,6 @@ board/efi/efi-x86/efi.c common/cmd_efi.c the 'efi' command - -- Ben Stoltz, Simon Glass Google, Inc
@@ -242,3 +263,63 @@ July 2015 [1] http://www.qemu.org [2] http://www.tianocore.org/ovmf/ + +------------------------------------------------------------------------------- + +EFI on U-Boot +============= + +In addition to support for running U-Boot as a UEFI application, U-Boot itself +can also expose the UEFI interfaces and thus allow UEFI payloads to run under +it. + +In God's Name, Why? +------------------- + +With this support in place, you can run any UEFI payload (such as the Linux +kernel, grub2 or gummiboot) on U-Boot. This dramatically simplifies boot loader +configuration, as U-Boot based systems now look and feel (almost) the same way +as TianoCore based systems. + +How do I get it? +---------------- + +EFI support for 32bit ARM and AArch64 is already included in U-Boot. All you +need to do is enable + + CONFIG_CMD_BOOTEFI=y + CONFIG_EFI_LOADER=y + +in your .config file and you will automatically get a bootefi command to run +an efi application as well as snippet in the default distro boot script that +scans for removable media efi binaries as fallback. + +Status +------ + +I am successfully able to run grub2 and Linux EFI binaries with this code on +ARMv7 as well as AArch64 systems. + +When enabled, the resulting U-Boot binary only grows by ~10KB, so it's very +light weight. + +All storage devices are directly accessible from the uEFI payload + +Removable media booting (search for /efi/boot/boota{a64,arm}.efi) is supported. + +Simple use cases like "Plug this SD card into my ARM device and it just +boots into grub which boots into Linux", work very well. + +Future work +----------- + +Of course, there are still a few things one could do on top: + + - Improve disk media detection (don't scan, use what information we +have) + - Add EFI variable support using NVRAM + - Add GFX support + - Make EFI Shell work + - Network device support + - Support for payload exit + - Payload Watchdog support
Signature · 1 line
1.8.5.6
PATCH v5 26/30 efi_loader: Add MAINTAINERS entry
In reply to Alexander GrafNow that everything's in place, let's add myself as the maintainer for the efi payload support.
--- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
@@ -230,6 +230,13 @@ F: drivers/core/ F: include/dm/ F: test/dm/ +EFI PAYLOAD +M: Alexander Graf <[email protected]> +S: Maintained +F: include/efi_loader.h +F: lib/efi_loader/ +F: cmd/bootefi.c + FLATTENED DEVICE TREE M: Simon Glass <[email protected]> S: Maintained
Signature · 1 line
1.8.5.6
PATCH v5 27/30 arm64: Replace fdt_name env variables with fdtfile
In reply to Alexander GrafThe commonly defined environment variable to determine the device tree file name is called fdtfile rather than fdt_name. Replace all occurences of fdt_name with fdtfile.
--- include/config_distro_bootcmd.h | 4 ++-- include/configs/hikey.h | 2 +- include/configs/vexpress_aemv8a.h | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-)
include/config_distro_bootcmd.h +2 -2
@@ -107,7 +107,7 @@ \"load_efi_dtb=" \"load ${devtype} ${devnum}:${distro_bootpart} " \ -"${fdt_addr_r} ${prefix}${fdt_name}; " \ +"${fdt_addr_r} ${prefix}${fdtfile}; " \"fdt addr ${fdt_addr_r}\0" \ \"efi_dtb_prefixes=/ /dtb/ /dtb/current/\0" \
@@ -115,7 +115,7 @@"for prefix in ${efi_dtb_prefixes}; do " \"if test -e ${devtype} " \"${devnum}:${distro_bootpart} " \ -"${prefix}${fdt_name}; then " \ +"${prefix}${fdtfile}; then " \"run load_efi_dtb; " \"fi;" \"done;" \
include/configs/hikey.h +1 -1
@@ -121,7 +121,7 @@#define CONFIG_EXTRA_ENV_SETTINGS \ "kernel_name=Image\0" \ "kernel_addr_r=0x00080000\0" \ - "fdt_name=hi6220-hikey.dtb\0" \ + "fdtfile=hi6220-hikey.dtb\0" \ "fdt_addr_r=0x02000000\0" \ "fdt_high=0xffffffffffffffff\0" \ "initrd_high=0xffffffffffffffff\0" \
include/configs/vexpress_aemv8a.h +5 -5
@@ -191,7 +191,7 @@"kernel_addr=0x80080000\0" \"initrd_name=ramdisk.img\0" \"initrd_addr=0x84000000\0" \ -"fdt_name=board.dtb\0" \ +"fdtfile=board.dtb\0" \"fdt_alt_name=juno\0" \"fdt_addr=0x83000000\0" \"fdt_high=0xffffffffffffffff\0" \
@@ -213,10 +213,10 @@"${kernel_name}; " \" afs load ${kernel_alt_name} ${kernel_addr};" \"fi ; " \ -"afs load ${fdt_name} ${fdt_addr} ; " \ +"afs load ${fdtfile} ${fdt_addr} ; " \"if test $? -eq 1; then " \" echo Loading ${fdt_alt_name} instead of " \ -"${fdt_name}; " \ +"${fdtfile}; " \" afs load ${fdt_alt_name} ${fdt_addr}; " \"fi ; " \"fdt addr ${fdt_addr}; fdt resize; " \
@@ -235,7 +235,7 @@"kernel_addr=0x80080000\0" \"initrd_name=ramdisk.img\0" \"initrd_addr=0x88000000\0" \ -"fdt_name=devtree.dtb\0" \ +"fdtfile=devtree.dtb\0" \"fdt_addr=0x83000000\0" \"fdt_high=0xffffffffffffffff\0" \"initrd_high=0xffffffffffffffff\0"
@@ -245,7 +245,7 @@"loglevel=9" #define CONFIG_BOOTCOMMAND "smhload ${kernel_name} ${kernel_addr}; " \ -"smhload ${fdt_name} ${fdt_addr}; " \ +"smhload ${fdtfile} ${fdt_addr}; " \"smhload ${initrd_name} ${initrd_addr} " \"initrd_end; " \"fdt addr ${fdt_addr}; fdt resize; " \
Signature · 1 line
1.8.5.6
PATCH v5 28/30 arm: Allow EFI payload code to take exceptions
In reply to Alexander GrafThere are 2 ways an EFI payload could return into u-boot:
- Callback function
- Exception
While in EFI payload mode, r9 is owned by the payload and may not contain a valid pointer to gd, so we need to fix it up. We do that properly for the payload to callback path already.
This patch also adds gd pointer restoral for the exception path.
--- arch/arm/lib/interrupts.c | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/arm/lib/interrupts.c +8 -0
@@ -22,6 +22,7 @@#include <common.h> #include <asm/proc-armv/ptrace.h> #include <asm/u-boot-arm.h> +#include <efi_loader.h> DECLARE_GLOBAL_DATA_PTR ;
@@ -165,6 +166,7 @@ void show_regs (struct pt_regs *regs)void do_undefined_instruction (struct pt_regs *pt_regs) { +efi_restore_gd ();printf ("undefined instruction\n" );show_regs (pt_regs);bad_mode ();
@@ -172,6 +174,7 @@ void do_undefined_instruction (struct pt_regs *pt_regs)void do_software_interrupt (struct pt_regs *pt_regs) { +efi_restore_gd ();printf ("software interrupt\n" );show_regs (pt_regs);bad_mode ();
@@ -179,6 +182,7 @@ void do_software_interrupt (struct pt_regs *pt_regs)void do_prefetch_abort (struct pt_regs *pt_regs) { +efi_restore_gd ();printf ("prefetch abort\n" );show_regs (pt_regs);bad_mode ();
@@ -186,6 +190,7 @@ void do_prefetch_abort (struct pt_regs *pt_regs)void do_data_abort (struct pt_regs *pt_regs) { +efi_restore_gd ();printf ("data abort\n" );show_regs (pt_regs);bad_mode ();
@@ -193,6 +198,7 @@ void do_data_abort (struct pt_regs *pt_regs)void do_not_used (struct pt_regs *pt_regs) { +efi_restore_gd ();printf ("not used\n" );show_regs (pt_regs);bad_mode ();
@@ -200,6 +206,7 @@ void do_not_used (struct pt_regs *pt_regs)void do_fiq (struct pt_regs *pt_regs) { +efi_restore_gd ();printf ("fast interrupt request\n" );show_regs (pt_regs);bad_mode ();
@@ -208,6 +215,7 @@ void do_fiq (struct pt_regs *pt_regs)#ifndef CONFIG_USE_IRQ void do_irq (struct pt_regs *pt_regs) { +efi_restore_gd ();printf ("interrupt request\n" );show_regs (pt_regs);bad_mode ();
Signature · 1 line
1.8.5.6
PATCH v5 29/30 efi_loader: Call fdt preparation functions
In reply to Alexander GrafWe have a nice framework around image fils to prepare a device tree for OS execution. That one patches in missing device tree nodes and fixes up the memory range bits.
We need to call that one from the EFI boot path too to get all those nice fixups. This patch adds the call.
--- cmd/bootefi.c | 8 ++++++++ common/image-fdt.c | 8 +++++--- 2 files changed, 13 insertions(+), 3 deletions(-)
cmd/bootefi.c +8 -0
@@ -92,6 +92,7 @@ static unsigned long do_bootefi_exec(void *efi) {ulong (*entry)(void *image_handle,struct efi_system_table *st);ulong fdt_pages, fdt_size, fdt_start, fdt_end; +bootm_headers_t img = {0 };/* * gd lives in a fixed register which may get clobbered while we execute
@@ -102,6 +103,13 @@ static unsigned long do_bootefi_exec(void *efi)/* Update system table to point to our currently loaded FDT */ if (working_fdt) { +/* Prepare fdt for payload */ +if (image_setup_libfdt (&img, working_fdt,0 ,NULL )) { +printf ("ERROR: Failed to process device tree\n" ); +return -EINVAL ; + } + +/* Link to it in the efi tables */ systab.tables[0 ].guid =EFI_FDT_GUID ; systab.tables[0 ].table = working_fdt; systab.nr_tables =1 ;
common/image-fdt.c +5 -3
@@ -502,8 +502,9 @@ int image_setup_libfdt(bootm_headers_t *images, void *blob,fdt_fixup_ethernet (blob);/* Delete the old LMB reservation */ -lmb_free (lmb, (phys_addr_t )(u32 )(uintptr_t )blob, - (phys_size_t )fdt_totalsize (blob)); +if (lmb) +lmb_free (lmb, (phys_addr_t )(u32 )(uintptr_t )blob, + (phys_size_t )fdt_totalsize (blob)); ret =fdt_shrink_to_minimum (blob);if (ret <0 )
@@ -515,7 +516,8 @@ int image_setup_libfdt(bootm_headers_t *images, void *blob,fdt_set_totalsize (blob, of_size); }/* Create a new LMB reservation */ -lmb_reserve (lmb, (ulong )blob, of_size); +if (lmb) +lmb_reserve (lmb, (ulong )blob, of_size);fdt_initrd (blob, *initrd_start, *initrd_end);if (!ft_verify_fdt (blob))
Signature · 1 line
1.8.5.6
PATCH v5 30/30 efi_loader: Pass proper device path in on boot
In reply to Alexander GrafEFI payloads can query for the device they were booted from. Because we have a disconnect between loading binaries and running binaries, we passed in a dummy device path so far.
Unfortunately that breaks grub2's logic to find its configuration file from the same device it was booted from.
This patch adds logic to have the "load" command call into our efi code to set the device path to the one we last loaded a binary from.
With this grub2 properly detects where we got booted from and can find its configuration file, even when searching by-partition.
--- cmd/bootefi.c | 34 +++++++++++++++++++++++++--------- cmd/fs.c | 2 ++ include/efi_loader.h | 10 ++++++++++ lib/efi_loader/efi_disk.c | 6 ------ 4 files changed, 37 insertions(+), 15 deletions(-)
cmd/bootefi.c +25 -9
@@ -21,16 +21,16 @@* In addition to the originating device we also declare the file path * of "bootefi" based loads to be /bootefi. */ -static struct efi_device_path_file_path bootefi_dummy_path[] = { +static struct efi_device_path_file_path bootefi_image_path[] = { { .dp.type =DEVICE_PATH_TYPE_MEDIA_DEVICE , .dp.sub_type =DEVICE_PATH_SUB_TYPE_FILE_PATH , - .dp.length =sizeof (bootefi_dummy_path[0 ]), + .dp.length =sizeof (bootefi_image_path[0 ]), .str = {'b' ,'o' ,'o' ,'t' ,'e' ,'f' ,'i' }, }, { .dp.type =DEVICE_PATH_TYPE_END , .dp.sub_type =DEVICE_PATH_SUB_TYPE_END , - .dp.length =sizeof (bootefi_dummy_path[0 ]), + .dp.length =sizeof (bootefi_image_path[0 ]), } };
@@ -38,14 +38,14 @@ static efi_status_t bootefi_open_dp(void *handle, efi_guid_t *protocol, void **protocol_interface, void *agent_handle, void *controller_handle, uint32_t attributes) { - *protocol_interface = bootefi_dummy_path; + *protocol_interface = bootefi_image_path;return EFI_SUCCESS ; }/* The EFI loaded_image interface for the image executed via "bootefi" */ static struct efi_loaded_image loaded_image_info = { - .device_handle = bootefi_dummy_path, - .file_path = bootefi_dummy_path, + .device_handle = bootefi_image_path, + .file_path = bootefi_image_path, };/* The EFI object struct for the image executed via "bootefi" */
@@ -63,7 +63,7 @@ static struct efi_object loaded_image_info_obj = { {/* * When asking for the device path interface, return -* bootefi_dummy_path +* bootefi_image_path */ .guid = &efi_guid_device_path, .open = &bootefi_open_dp,
@@ -73,11 +73,11 @@ static struct efi_object loaded_image_info_obj = {/* The EFI object struct for the device the "bootefi" image was loaded from */ static struct efi_object bootefi_device_obj = { - .handle = bootefi_dummy_path, + .handle = bootefi_image_path, .protocols = { {/* When asking for the device path interface, return -* bootefi_dummy_path */ +* bootefi_image_path */ .guid = &efi_guid_device_path, .open = &bootefi_open_dp, }
@@ -184,3 +184,19 @@ U_BOOT_CMD("Boots an EFI payload from memory\n" , bootefi_help_text ); + +void efi_set_bootdev (const char *dev,const char *devnr) +{ +char devname[16 ] = {0 };/* dp->str is u16[16] long */ +char *colon; + +/* Assemble the condensed device name we use in efi_disk.c */ +snprintf (devname,sizeof (devname),"%s%s" , dev, devnr); + colon =strchr (devname,':' ); +if (colon) + *colon ='\0' ; + +/* Patch the bootefi_image_path to the target device */ +memset (bootefi_image_path[0 ].str,0 ,sizeof (bootefi_image_path[0 ].str)); +ascii2unicode (bootefi_image_path[0 ].str, devname); +}
cmd/fs.c +2 -0
@@ -9,6 +9,7 @@#include <common.h> #include <command.h> #include <fs.h> +#include <efi_loader.h> static int do_size_wrapper (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) {
@@ -26,6 +27,7 @@ U_BOOT_CMD(static int do_load_wrapper (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) { +efi_set_bootdev (argv[1 ], (argc >2 ) ? argv[2 ] :"" );return do_load (cmdtp, flag, argc, argv,FS_TYPE_ANY ); }
include/efi_loader.h +10 -0
@@ -108,6 +108,8 @@ void efi_restore_gd(void);efi_status_t efi_exit_func (efi_status_t ret);/* Call this to relocate the runtime section to an address space */ void efi_runtime_relocate (ulong offset,struct efi_mem_desc *map); +/* Call this to set the current device name */ +void efi_set_bootdev (const char *dev,const char *devnr);/* Generic EFI memory allocator, call this to get memory */ void *efi_alloc (uint64_t len,int memory_type);
@@ -128,6 +130,13 @@ uint64_t efi_add_memory_map(uint64_t start, uint64_t pages, int memory_type,/* Called by board init to initialize the EFI memory map */ int efi_memory_init (void ); +/* Convert strings from normal C strings to uEFI strings */ +static inline void ascii2unicode (u16 *unicode,char *ascii) +{ +while (*ascii) + *(unicode++) = *(ascii++); +} +/* * Use these to indicate that your code / data should go into the EFI runtime * section and thus still be available when the OS is running
@@ -143,5 +152,6 @@ int efi_memory_init(void);/* No loader configured, stub out EFI_ENTRY */ static inline void efi_restore_gd (void ) { } +static inline void efi_set_bootdev (const char *dev,const char *devnr) { }#endif
lib/efi_loader/efi_disk.c +0 -6
@@ -29,12 +29,6 @@ struct efi_disk_obj {struct efi_device_path_file_path *dp; }; -static void ascii2unicode (u16 *unicode,char *ascii) -{ -while (*ascii) - *(unicode++) = *(ascii++); -} -static efi_status_t efi_disk_open_block (void *handle,efi_guid_t *protocol,void **protocol_interface,void *agent_handle,void *controller_handle,uint32_t attributes)
Signature · 1 line
1.8.5.6
PATCH 1/1 efi_loader: Reserve 2 additional pages for fdt
In reply to Alexander GrafWe mark the device tree as reserved today, spanning exactly the amount of space it needs. If some other piece of code (like grub2) comes in and wants to modify the device tree to for example add a kernel command line though, it might assume that it has some space to do so.
So let's just reserve 2 additional pages for the device tree to play nicely.
--- cmd/bootefi.c | 2 ++ 1 file changed, 2 insertions(+)
cmd/bootefi.c +2 -0
@@ -119,6 +119,8 @@ static unsigned long do_bootefi_exec(void *efi) fdt_end = ((ulong )working_fdt) +fdt_totalsize (working_fdt); fdt_size = (fdt_end - fdt_start) +EFI_PAGE_MASK ; fdt_pages = fdt_size >>EFI_PAGE_SHIFT ; +/* Give a bootloader the chance to modify the device tree */ + fdt_pages +=2 ;efi_add_memory_map (fdt_start, fdt_pages,EFI_BOOT_SERVICES_DATA , true);
Signature · 1 line
1.8.5.6
PATCH 1/1 efi_loader: Reserve 2 additional pages for fdt
Quoted 6 lines · Alexander Graf
We mark the device tree as reserved today, spanning exactly the amount of space it needs. If some other piece of code (like grub2) comes in and wants to modify the device tree to for example add a kernel command line though, it might assume that it has some space to do so.
So let's just reserve 2 additional pages for the device tree to play nicely.
I presume this was triggered by something you found on AArch32 grub, booting a kernel without EFI stub?
If so, the issue will go away once I fix the AArch32 grub to use the AArch64 loader for kernel images with the EFI stub. Could you possibly send an email to grub-devel, or raise a ticket directly on the savannah bugtracker if you have an account?
This fix really should go into 2.02 release.
Regardless, this seems like it provides a potential optimisation opportunity for such agents, to use the tree in place instead of always allocating more memory.
Quoted 21 lines
Signed-off-by Alexander Graf <[email protected]>--- cmd/bootefi.c | 2 ++ 1 file changed, 2 insertions(+)cmd/bootefi.c +2
-0@@ -119,6 +119,8 @@ static unsigned long do_bootefi_exec(void *efi) fdt_end = ((ulong )working_fdt) +fdt_totalsize (working_fdt); fdt_size = (fdt_end - fdt_start) +EFI_PAGE_MASK ; fdt_pages = fdt_size >>EFI_PAGE_SHIFT ; +/* Give a bootloader the chance to modify the device tree */ + fdt_pages +=2 ;efi_add_memory_map (fdt_start, fdt_pages,EFI_BOOT_SERVICES_DATA , true);Signature · 1 line
1.8.5.6
PATCH v5 24/30 efi_loader: Add distro boot script for removable media
In reply to Alexander GrafQuoted 53 lines · Alexander Graf
UEFI defines a simple boot protocol for removable media. There we should look at the EFI (first GPT FAT) partition and search for /efi/boot/bootXXX.efi with XXX being different between different platforms (x86, x64, arm, aa64, ...).
This patch implements a simple version of that protocol for the default distro boot script. With this we can automatically boot from valid UEFI enabled removable media.
Because from all I could see U-Boot by default doesn't deliver device tree blobs with its firmware, we also need to load the dtb from somewhere. Traverse the same EFI partition for an fdt file that fits our current board so that an OS receives a valid device tree when booted automatically.
Signed-off-by Alexander Graf <[email protected]>Reviewed-by Simon Glass <[email protected]>--- include/config_distro_bootcmd.h | 47 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-)include/config_distro_bootcmd.h +26
-0@@ -90,6 +90,48 @@ BOOT_TARGET_DEVICES_references_UBIFS_without_CONFIG_CMD_UBIFS#endif +#ifdef CONFIG_EFI_LOADER +#if defined(CONFIG_ARM64 ) +#define BOOTEFI_NAME "bootaa64.efi" +#elif defined(CONFIG_ARM ) +#define BOOTEFI_NAME "bootarm.efi" +#endif +#endif + +#ifdef BOOTEFI_NAME +#define BOOTENV_SHARED_EFI \ + "boot_efi_binary=" \ + "load ${devtype} ${devnum}:${distro_bootpart} " \ + "${kernel_addr_r} efi/boot/"BOOTEFI_NAME"; " \ + "bootefi ${kernel_addr_r}\0" \ + \ + "load_efi_dtb=" \ + "load ${devtype} ${devnum}:${distro_bootpart} " \ + "${fdt_addr_r} ${prefix}${fdt_name}; " \ + "fdt addr ${fdt_addr_r}\0" \ + \ + "efi_dtb_prefixes=/ /dtb/ /dtb/current/\0" \ + "scan_dev_for_efi=" \ + "for prefix in ${efi_dtb_prefixes}; do " \ + "if test -e ${devtype} " \ + "${devnum}:${distro_bootpart} " \ + "${prefix}${fdt_name}; then " \
include/config_distro_bootcmd.h line 128
Quoted 10 lines
include/config_distro_bootcmd.h +10
-0+"run load_efi_dtb; " \ +"fi;" \ +"done;" \ +"if test -e ${devtype} ${devnum}:${distro_bootpart} " \ +"efi/boot/" BOOTEFI_NAME "; then " \ +"echo Found EFI removable media binary " \ +"efi/boot/" BOOTEFI_NAME "; " \ +"run boot_efi_binary; " \ +"echo EFI LOAD FAILED: continuing...; " \ +"fi; "
Whoever applies this, please also apply the patch below on top and squash it in (or tell me to resend). Without the fix, we end up slurping the boot_prefix variable into the scan_dev_for_efi variable.
Alex
(quoted diff) +0 -0
b/include/config_distro_bootcmd.h
index e7d7002..ad9045e 100644
include/config_distro_bootcmd.h +1 -1
@@ -125,7 +125,7 @@"efi/boot/" BOOTEFI_NAME "; " \"run boot_efi_binary; " \"echo EFI LOAD FAILED: continuing...; " \ - "fi; " + "fi; \0"#define SCAN_DEV_FOR_EFI "run scan_dev_for_efi;"#else #define BOOTENV_SHARED_EFI
PATCH v5 24/30 efi_loader: Add distro boot script for removable media
Quoted 80 lines · Alexander Graf
Quoted 53 lines · Alexander Graf
UEFI defines a simple boot protocol for removable media. There we should look at the EFI (first GPT FAT) partition and search for /efi/boot/bootXXX.efi with XXX being different between different platforms (x86, x64, arm, aa64, ...).
This patch implements a simple version of that protocol for the default distro boot script. With this we can automatically boot from valid UEFI enabled removable media.
Because from all I could see U-Boot by default doesn't deliver device tree blobs with its firmware, we also need to load the dtb from somewhere. Traverse the same EFI partition for an fdt file that fits our current board so that an OS receives a valid device tree when booted automatically.
Signed-off-by Alexander Graf <[email protected]>Reviewed-by Simon Glass <[email protected]>--- include/config_distro_bootcmd.h | 47 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-)include/config_distro_bootcmd.h +26
-0@@ -90,6 +90,48 @@ BOOT_TARGET_DEVICES_references_UBIFS_without_CONFIG_CMD_UBIFS#endif +#ifdef CONFIG_EFI_LOADER +#if defined(CONFIG_ARM64 ) +#define BOOTEFI_NAME "bootaa64.efi" +#elif defined(CONFIG_ARM ) +#define BOOTEFI_NAME "bootarm.efi" +#endif +#endif + +#ifdef BOOTEFI_NAME +#define BOOTENV_SHARED_EFI \ + "boot_efi_binary=" \ + "load ${devtype} ${devnum}:${distro_bootpart} " \ + "${kernel_addr_r} efi/boot/"BOOTEFI_NAME"; " \ + "bootefi ${kernel_addr_r}\0" \ + \ + "load_efi_dtb=" \ + "load ${devtype} ${devnum}:${distro_bootpart} " \ + "${fdt_addr_r} ${prefix}${fdt_name}; " \ + "fdt addr ${fdt_addr_r}\0" \ + \ + "efi_dtb_prefixes=/ /dtb/ /dtb/current/\0" \ + "scan_dev_for_efi=" \ + "for prefix in ${efi_dtb_prefixes}; do " \ + "if test -e ${devtype} " \ + "${devnum}:${distro_bootpart} " \ + "${prefix}${fdt_name}; then " \include/config_distro_bootcmd.h line 128
Quoted 10 lines
include/config_distro_bootcmd.h +10
-0+"run load_efi_dtb; " \ +"fi;" \ +"done;" \ +"if test -e ${devtype} ${devnum}:${distro_bootpart} " \ +"efi/boot/" BOOTEFI_NAME "; then " \ +"echo Found EFI removable media binary " \ +"efi/boot/" BOOTEFI_NAME "; " \ +"run boot_efi_binary; " \ +"echo EFI LOAD FAILED: continuing...; " \ +"fi; " Whoever applies this, please also apply the patch below on top and squash it in (or tell me to resend). Without the fix, we end up slurping the
boot_prefixvariable into thescan_dev_for_efivariable.Alex
include/config_distro_bootcmd.h +0
-0
include/config_distro_bootcmd.h line 131
Quoted 8 lines
include/config_distro_bootcmd.h +1
-1@@ -125,7 +125,7 @@"efi/boot/" BOOTEFI_NAME "; " \"run boot_efi_binary; " \"echo EFI LOAD FAILED: continuing...; " \ - "fi; " + "fi; \0"#define SCAN_DEV_FOR_EFI "run scan_dev_for_efi;"#else #define BOOTENV_SHARED_EFI
Please make just a v6 of this patch and re-post, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160309/b5772c93/attachment.sig>
PATCH v6 24/30 efi_loader: Add distro boot script for removable media
UEFI defines a simple boot protocol for removable media. There we should look at the EFI (first GPT FAT) partition and search for /efi/boot/bootXXX.efi with XXX being different between different platforms (x86, x64, arm, aa64, ...).
This patch implements a simple version of that protocol for the default distro boot script. With this we can automatically boot from valid UEFI enabled removable media.
Because from all I could see U-Boot by default doesn't deliver device tree blobs with its firmware, we also need to load the dtb from somewhere. Traverse the same EFI partition for an fdt file that fits our current board so that an OS receives a valid device tree when booted automatically.
---
v5 -> v6:
- Fix missing 0-terminator
--- include/config_distro_bootcmd.h | 47 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-)
include/config_distro_bootcmd.h +46 -1
@@ -90,6 +90,48 @@ BOOT_TARGET_DEVICES_references_UBIFS_without_CONFIG_CMD_UBIFS#endif +#ifdef CONFIG_EFI_LOADER +#if defined(CONFIG_ARM64 ) +#define BOOTEFI_NAME "bootaa64.efi" +#elif defined(CONFIG_ARM ) +#define BOOTEFI_NAME "bootarm.efi" +#endif +#endif + +#ifdef BOOTEFI_NAME +#define BOOTENV_SHARED_EFI \ + "boot_efi_binary=" \ + "load ${devtype} ${devnum}:${distro_bootpart} " \ + "${kernel_addr_r} efi/boot/"BOOTEFI_NAME"; " \ + "bootefi ${kernel_addr_r}\0" \ + \ + "load_efi_dtb=" \ + "load ${devtype} ${devnum}:${distro_bootpart} " \ + "${fdt_addr_r} ${prefix}${fdt_name}; " \ + "fdt addr ${fdt_addr_r}\0" \ + \ + "efi_dtb_prefixes=/ /dtb/ /dtb/current/\0" \ + "scan_dev_for_efi=" \ + "for prefix in ${efi_dtb_prefixes}; do " \ + "if test -e ${devtype} " \ + "${devnum}:${distro_bootpart} " \ + "${prefix}${fdt_name}; then " \ + "run load_efi_dtb; " \ + "fi;" \ + "done;" \ + "if test -e ${devtype} ${devnum}:${distro_bootpart} " \ + "efi/boot/"BOOTEFI_NAME"; then " \ + "echo Found EFI removable media binary " \ + "efi/boot/"BOOTEFI_NAME"; " \ + "run boot_efi_binary; " \ + "echo EFI LOAD FAILED: continuing...; " \ + "fi; \0" +#define SCAN_DEV_FOR_EFI "run scan_dev_for_efi;" +#else +#define BOOTENV_SHARED_EFI +#define SCAN_DEV_FOR_EFI +#endif +#ifdef CONFIG_CMD_SATA #define BOOTENV_SHARED_SATA BOOTENV_SHARED_BLKDEV(sata)#define BOOTENV_DEV_SATA BOOTENV_DEV_BLKDEV
@@ -217,6 +259,7 @@BOOTENV_SHARED_SCSI \ BOOTENV_SHARED_IDE \BOOTENV_SHARED_UBIFS \ + BOOTENV_SHARED_EFI \"boot_prefixes=/ /boot/\0" \"boot_scripts=boot.scr.uimg boot.scr\0" \"boot_script_dhcp=boot.scr.uimg\0" \
@@ -258,7 +301,9 @@"for prefix in ${boot_prefixes}; do " \"run scan_dev_for_extlinux; " \"run scan_dev_for_scripts; " \ -"done\0" \ +"done;" \ +SCAN_DEV_FOR_EFI \ +"\0" \ \"scan_dev_for_boot_part=" \"part list ${devtype} ${devnum} -bootable devplist; " \
Signature · 1 line
1.8.5.6
PATCH v6 19/30 efi_loader: Add "bootefi" command
In reply to Alexander GrafIn order to execute an EFI application, we need to bridge the gap between U-Boot's notion of executing images and EFI's notion of doing the same.
The best path forward IMHO here is to stick completely to the way U-Boot deals with payloads. You manually load them using whatever method to RAM and then have a simple boot command to execute them. So in our case, you would do
# load mmc 0:1 $loadaddr grub.efi # bootefi $loadaddr
which then gets you into a grub shell. Fdt information known to U-boot via the fdt addr command is also passed to the EFI payload.
---
v1 -> v2:
- Move to GPLv2+
v2 -> v3:
- Move to new cmd directory
- Add kconfig option
- Fix comment style
- Add help text
- s/-1/-ENOENT
- Move obj list to lib
v4 -> v5:
- Mark fdt memory as boot services data
v5 -> v6:
- Reserve 2 additional pages for fdt
--- cmd/Kconfig | 7 +++ cmd/Makefile | 1 + cmd/bootefi.c | 180 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 188 insertions(+) create mode 100644 cmd/bootefi.c
cmd/Kconfig +7 -0
@@ -148,6 +148,13 @@ config CMD_BOOTM help Boot an application image from the memory. +config CMD_BOOTEFI + bool "bootefi" + depends on EFI_LOADER + default y + help + Boot an EFI image from memory. + config CMD_ELF bool "bootelf, bootvx" default y
cmd/Makefile +1 -0
@@ -21,6 +21,7 @@ obj-$(CONFIG_CMD_SOURCE) += source.o obj-$(CONFIG_CMD_BDI) += bdinfo.o obj-$(CONFIG_CMD_BEDBUG) += bedbug.o obj-$(CONFIG_CMD_BMP) += bmp.o +obj-$(CONFIG_CMD_BOOTEFI) += bootefi.o obj-$(CONFIG_CMD_BOOTMENU) += bootmenu.o obj-$(CONFIG_CMD_BOOTLDR) += bootldr.o obj-$(CONFIG_CMD_BOOTSTAGE) += bootstage.o
cmd/bootefi.c new file +180 -0
180 lines not on this page · raw message
Signature · 1 line
1.8.5.6
PATCH v5 1/30 thunderx: Calculate TCR dynamically
In reply to Alexander GrafQuoted 5 lines · Alexander Graf
Based on the memory map we can determine a lot of hard coded fields of TCR, like the maximum VA and max PA we want to support. Calculate those dynamically to reduce the chance for pit falls.
Signed-off-by Alexander Graf <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/6f4dd32f/attachment.sig>
PATCH v5 2/30 arm64: Disable TTBR1 maps in EL1
In reply to Alexander GrafQuoted 9 lines · Alexander Graf
When running in EL1, AArch64 knows two page table maps. One with addresses that start with all zeros (TTBR0) and one with addresses that start with all ones (TTBR1).
In U-Boot we don't care about the high up maps, so just disable them to ensure we don't walk an invalid page table by accident.
Reported-by Mark Rutland <[email protected]>Signed-off-by Alexander Graf <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/f86cdedd/attachment.sig>
PATCH v5 3/30 arm64: Make full va map code more dynamic
In reply to Alexander GrafQuoted 12 lines · Alexander Graf
The idea to generate our pages tables from an array of memory ranges is very sound. However, instead of hard coding the code to create up to 2 levels of 64k granule page tables, we really should just create normal 4k page tables that allow us to set caching attributes on 2M or 4k level later on.
So this patch moves the
full_vamapping code to 4k page size and makes it fully flexible to dynamically create as many levels as necessary for a map (including dynamic 1G/2M pages). It also adds support to dynamically split a large map into smaller ones when some code wants to set dcache attributes.
Quoted 4 lines
With all this in place, there is very little reason to create your own page tables in board specific files.
Signed-off-by Alexander Graf <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/2d4e847a/attachment.sig>
PATCH v5 4/30 thunderx: Move mmu table into board file
In reply to Alexander GrafQuoted 6 lines · Alexander Graf
The MMU range table can vary depending on things we may only find out at runtime. While the very simple ThunderX variant does not change, other boards will, so move the definition from a static entry in a header file to the board file.
Signed-off-by Alexander Graf <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/f1232861/attachment.sig>
PATCH v5 5/30 zymqmp: Replace home grown mmu code with generic table approach
In reply to Alexander GrafQuoted 4 lines · Alexander Graf
Now that we have nice table driven page table creating code that gives us everything we need, move to that.
Signed-off-by Alexander Graf <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/bcec26ea/attachment.sig>
PATCH v5 6/30 tegra: Replace home grown mmu code with generic table approach
In reply to Alexander GrafQuoted 4 lines · Alexander Graf
Now that we have nice table driven page table creating code that gives us everything we need, move to that.
Signed-off-by Alexander Graf <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/32b650b5/attachment.sig>
PATCH v5 7/30 vexpress64: Add MMU tables
In reply to Alexander GrafQuoted 5 lines · Alexander Graf
There's no good excuse for running with caches disabled on AArch64, so let's just move the vexpress64 target to enable the MMU and run with caches on.
Signed-off-by Alexander Graf <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/ac25d195/attachment.sig>
PATCH v5 8/30 dwmmc: Increase retry timeout
In reply to Alexander GrafQuoted 11 lines · Alexander Graf
When enable dcache on HiKey, we're running into MMC command timeouts because our retry loop is now faster than the eMMC (or an external SD card) can answer.
Increase the retry count to the same as the timeout value for status reports.
The real fix is obviously to not base this whole thing on a cycle counter but on real wall time, but that would be slightly more intrusive.
Signed-off-by Alexander Graf <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/46cdcc3c/attachment.sig>
PATCH v5 9/30 hikey: Add MMU tables
In reply to Alexander GrafQuoted 5 lines · Alexander Graf
The hikey runs with dcache disabled today. There really should be no reason not to use caches on AArch64, so let's add MMU definitions and enable the dcache.
Signed-off-by Alexander Graf <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/c47cc1c0/attachment.sig>
PATCH v5 10/30 arm64: Remove non-full-va map code
In reply to Alexander GrafQuoted 8 lines · Alexander Graf
By now the code to only have a single page table level with 64k page size and 42 bit address space is no longer used by any board in tree, so we can safely remove it.
To clean up code, move the layerscape mmu code to the new defines, removing redundant field definitions.
Signed-off-by Alexander Graf <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/20fec9e0/attachment.sig>
PATCH v5 11/30 arm64: Only allow dcache disabled in SPL builds
In reply to Alexander GrafQuoted 6 lines · Alexander Graf
Now that we have an easy way to describe memory regions and enable the MMU, there really shouldn't be anything holding people back from running with caches enabled on AArch64. To make sure people catch early if they're missing on the caching fun, give them a compile error.
Signed-off-by Alexander Graf <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/1ff15e5a/attachment.sig>
PATCH v5 12/30 disk/part.c: Expose list of available block drivers
In reply to Alexander GrafQuoted 11 lines · Alexander Graf
We have a pretty nice and generic interface to ask for a specific block device. However, that one is still based around the magic notion that we know the driver name.
In order to be able to write fully generic disk access code, expose the currently internal list to other source files so that they can scan through all available block drivers.
Signed-off-by Alexander Graf <[email protected]>Reviewed-by Simon Glass <[email protected]>Tested-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/b44c76cc/attachment.sig>
PATCH v5 13/30 include/efi_api.h: Add more detailed API definitions
In reply to Alexander GrafQuoted 9 lines · Alexander Graf
The EFI API header is great, but missing a good chunk of function prototype, GUID defines and enum declarations.
This patch extends it to cover more of the EFI API. It's still not 100% complete, but sufficient enough for our EFI payload interface.
Signed-off-by Alexander Graf <[email protected]>Reviewed-by Simon Glass <[email protected]>Tested-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/7a984def/attachment.sig>
PATCH v5 14/30 efi_loader: Add PE image loader
In reply to Alexander GrafQuoted 6 lines · Alexander Graf
EFI uses the PE binary format for its application images. Add support to EFI PE binaries as well as all necessary bits for the "EFI image loader" interfaces.
Signed-off-by Alexander Graf <[email protected]>Reviewed-by Simon Glass <[email protected]>Tested-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/fc2e2354/attachment-0001.sig>
PATCH v5 15/30 efi_loader: Add boot time services
In reply to Alexander GrafQuoted 11 lines · Alexander Graf
When an EFI application runs, it has access to a few descriptor and callback tables to instruct the EFI compliant firmware to do things for it. The bulk of those interfaces are "boot time services". They handle all object management, and memory allocation.
This patch adds support for the boot time services and also exposes a system table, which is the point of entry descriptor table for EFI payloads.
Signed-off-by Alexander Graf <[email protected]>Reviewed-by Simon Glass <[email protected]>Tested-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/ae89449e/attachment-0001.sig>
PATCH v5 16/30 efi_loader: Add console interface
In reply to Alexander GrafQuoted 11 lines · Alexander Graf
One of the basic EFI interfaces is the console interface. Using it an EFI application can interface with the user. This patch implements an EFI console interface using
getc()andputc().Today, we only implement text based consoles. We also convert the EFI Unicode characters to UTF-8 on the fly, hoping that everyone managed to jump on the train by now.
Signed-off-by Alexander Graf <[email protected]>Reviewed-by Simon Glass <[email protected]>Tested-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/6ecf6de8/attachment-0001.sig>
PATCH v5 17/30 efi_loader: Add runtime services
In reply to Alexander GrafQuoted 8 lines · Alexander Graf
After booting has finished, EFI allows firmware to still interact with the OS using the "runtime services". These callbacks live in a separate address space, since they are available long after U-Boot has been overwritten by the OS.
This patch adds enough framework for arbitrary code inside of U-Boot to become a runtime service with the right section attributes set. For now, we don't make use of it yet though.
Quoted 6 lines
We could maybe in the future map U-boot environment variables to EFI variables here.
Signed-off-by Alexander Graf <[email protected]>Reviewed-by Simon Glass <[email protected]>Tested-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/22ba2053/attachment-0001.sig>
PATCH v5 18/30 efi_loader: Add disk interfaces
In reply to Alexander GrafQuoted 10 lines · Alexander Graf
A EFI applications usually want to access storage devices to load data from.
This patch adds support for EFI disk interfaces. It loops through all block storage interfaces known to U-Boot and creates an EFI object for each existing one. EFI applications can then through these objects call U-Boot's read and write functions.
Signed-off-by Alexander Graf <[email protected]>Reviewed-by Simon Glass <[email protected]>Tested-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/a3446ccc/attachment-0001.sig>
PATCH v6 19/30 efi_loader: Add "bootefi" command
In reply to Alexander GrafQuoted 11 lines · Alexander Graf
In order to execute an EFI application, we need to bridge the gap between U-Boot's notion of executing images and EFI's notion of doing the same.
The best path forward IMHO here is to stick completely to the way U-Boot deals with payloads. You manually load them using whatever method to RAM and then have a simple boot command to execute them. So in our case, you would do
# load mmc 0:1 $loadaddr grub.efi # bootefi $loadaddr
Quoted 6 lines
which then gets you into a grub shell. Fdt information known to U-boot via the fdt addr command is also passed to the EFI payload.
Signed-off-by Alexander Graf <[email protected]>Reviewed-by Simon Glass <[email protected]>Tested-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/3a7de93a/attachment-0001.sig>
PATCH v5 20/30 efi_loader: Implement memory allocation and map
In reply to Alexander GrafQuoted 8 lines · Alexander Graf
The EFI loader needs to maintain views of memory - general system memory windows as well as used locations inside those and potential runtime service MMIO windows.
To manage all of these, add a few helpers that maintain an internal representation of the map the similar to how the EFI API later on reports it to the application.
Quoted 8 lines
For allocations, the scheme is very simple. We basically allow allocations to replace chunks of previously done maps, so that a new
LOADER_DATAallocation for example can remove a piece of the RAM map. When no specific address is given, we just take the highest possible address in the lowest RAM map that fits the allocation size.Signed-off-by Alexander Graf <[email protected]>Tested-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/81f00d57/attachment-0001.sig>
PATCH v5 21/30 arm64: Allow exceptions to return
In reply to Alexander GrafQuoted 11 lines · Alexander Graf
Our current arm64 exception handlers all panic and never return to the exception triggering code.
But if any handler wanted to continue execution after fixups, it would need help from the exception handling code to restore all registers.
This patch implements that help. With this code, exception handlers on aarch64 can successfully return to the place the exception happened (or somewhere else if they modify elr).
Signed-off-by Alexander Graf <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/3a603b01/attachment-0001.sig>
PATCH v5 22/30 arm64: Allow EFI payload code to take exceptions
In reply to Alexander GrafQuoted 5 lines · Alexander Graf
There are 2 ways an EFI payload could return into u-boot:
- Callback function
- Exception
Quoted 7 lines
While in EFI payload mode, x18 is owned by the payload and may not contain a valid pointer to gd, so we need to fix it up. We do that properly for the payload to callback path already.
This patch also adds gd pointer restoral for the exception path.
Signed-off-by Alexander Graf <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/2c02556d/attachment-0001.sig>
PATCH v5 23/30 efi_loader: hook up in build environment
In reply to Alexander GrafQuoted 6 lines · Alexander Graf
Now that we have all the bits and pieces ready for EFI payload loading support, hook them up in Makefiles and KConfigs so that we can build.
Signed-off-by Alexander Graf <[email protected]>Reviewed-by Simon Glass <[email protected]>Tested-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/1e10d4f7/attachment.sig>
PATCH v6 24/30 efi_loader: Add distro boot script for removable media
In reply to Alexander GrafQuoted 8 lines · Alexander Graf
UEFI defines a simple boot protocol for removable media. There we should look at the EFI (first GPT FAT) partition and search for /efi/boot/bootXXX.efi with XXX being different between different platforms (x86, x64, arm, aa64, ...).
This patch implements a simple version of that protocol for the default distro boot script. With this we can automatically boot from valid UEFI enabled removable media.
Quoted 7 lines
Because from all I could see U-Boot by default doesn't deliver device tree blobs with its firmware, we also need to load the dtb from somewhere. Traverse the same EFI partition for an fdt file that fits our current board so that an OS receives a valid device tree when booted automatically.
Signed-off-by Alexander Graf <[email protected]>Reviewed-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/05aec607/attachment.sig>
PATCH v5 25/30 efi_loader: Add README section in README.efi
In reply to Alexander GrafQuoted 9 lines · Alexander Graf
To preserve all cover letter knowledge of the status on UEFI payload support, let's add some sections to README.efi.
Signed-off-by Alexander Graf <[email protected]>v3 -> v4:
- Add section about config options
- s/10kb/10KB/
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/0e157d73/attachment.sig>
PATCH v5 26/30 efi_loader: Add MAINTAINERS entry
In reply to Alexander GrafQuoted 5 lines · Alexander Graf
Now that everything's in place, let's add myself as the maintainer for the efi payload support.
Signed-off-by Alexander Graf <[email protected]>Reviewed-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/51d42a2c/attachment.sig>
PATCH v5 27/30 arm64: Replace fdt_name env variables with fdtfile
In reply to Alexander GrafQuoted 5 lines · Alexander Graf
The commonly defined environment variable to determine the device tree file name is called fdtfile rather than
fdt_name. Replace all occurences offdt_namewith fdtfile.Signed-off-by Alexander Graf <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/ec817184/attachment.sig>
PATCH v5 28/30 arm: Allow EFI payload code to take exceptions
In reply to Alexander GrafQuoted 5 lines · Alexander Graf
There are 2 ways an EFI payload could return into u-boot:
- Callback function
- Exception
Quoted 7 lines
While in EFI payload mode, r9 is owned by the payload and may not contain a valid pointer to gd, so we need to fix it up. We do that properly for the payload to callback path already.
This patch also adds gd pointer restoral for the exception path.
Signed-off-by Alexander Graf <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/eb705dbc/attachment.sig>
PATCH v5 29/30 efi_loader: Call fdt preparation functions
In reply to Alexander GrafQuoted 8 lines · Alexander Graf
We have a nice framework around image fils to prepare a device tree for OS execution. That one patches in missing device tree nodes and fixes up the memory range bits.
We need to call that one from the EFI boot path too to get all those nice fixups. This patch adds the call.
Signed-off-by Alexander Graf <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/e8250d7e/attachment.sig>
PATCH v5 30/30 efi_loader: Pass proper device path in on boot
In reply to Alexander GrafQuoted 7 lines · Alexander Graf
EFI payloads can query for the device they were booted from. Because we have a disconnect between loading binaries and running binaries, we passed in a dummy device path so far.
Unfortunately that breaks grub2's logic to find its configuration file from the same device it was booted from.
Quoted 7 lines
This patch adds logic to have the "load" command call into our efi code to set the device path to the one we last loaded a binary from.
With this grub2 properly detects where we got booted from and can find its configuration file, even when searching by-partition.
Signed-off-by Alexander Graf <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160316/be3ca1a1/attachment.sig>