Merge tag 'signed-efi-next' of git://github.com/agraf/u-boot

Patch queue for efi - 2018-09-26

A lot of goodness in this release. We're *very* close to running the
UEFI Shell and SCT natively. The only missing piece are HII protocols.

  - FAT write support (needed for SCT)
  - improved FAT directory support (needed for SCT)
  - RTC support with QEMU -M virt
  - Sandbox support (run UEFI binaries in Linux - yay)
  - Proper UTF-16 support
  - EFI_UNICODE_COLLATION_PROTOCOL support (for UEFI Shell)
  - EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL support (for UEFI Shell)
  - Fix window size determination
  - Fix Tegra by explicitly unmapping RAM
  - Clean up handle entanglement
  - Lots of generic code cleanup

[trini: Fixup merge conflict in include/configs/qemu-arm.h]
Signed-off-by: Tom Rini <trini@konsulko.com>
This commit is contained in:
Tom Rini
2018-09-26 15:14:02 -04:00
81 changed files with 8086 additions and 1288 deletions

View File

@@ -747,6 +747,8 @@ config ARCH_QEMU
select OF_CONTROL
select PL01X_SERIAL
imply CMD_DM
imply DM_RTC
imply RTC_PL031
config ARCH_RMOBILE
bool "Renesas ARM SoCs"

View File

@@ -835,7 +835,7 @@ int dram_init_banksize(void)
return 0;
}
#if defined(CONFIG_EFI_LOADER) && !defined(CONFIG_SPL_BUILD)
#if CONFIG_IS_ENABLED(EFI_LOADER)
void efi_add_known_memory(void)
{
int i;

View File

@@ -135,7 +135,7 @@ remove_psci_node:
fdt_add_mem_rsv(blob, (uintptr_t)&secondary_boot_code,
*boot_code_size);
#if defined(CONFIG_EFI_LOADER) && !defined(CONFIG_SPL_BUILD)
#if CONFIG_IS_ENABLED(EFI_LOADER)
efi_add_memory_map((uintptr_t)&secondary_boot_code,
ALIGN(*boot_code_size, EFI_PAGE_SIZE) >> EFI_PAGE_SHIFT,
EFI_RESERVED_MEMORY_TYPE, false);

View File

@@ -6,6 +6,7 @@
#include <common.h>
#include <dm.h>
#include <efi_loader.h>
#include <errno.h>
#include <ns16550.h>
#include <usb.h>
@@ -210,6 +211,19 @@ int board_early_init_f(void)
int board_late_init(void)
{
#if CONFIG_IS_ENABLED(EFI_LOADER)
if (gd->bd->bi_dram[1].start) {
/*
* Only bank 0 is below board_get_usable_ram_top(), so all of
* bank 1 is not mapped by the U-Boot MMU configuration, and so
* we must prevent EFI from using it.
*/
efi_add_memory_map(gd->bd->bi_dram[1].start,
gd->bd->bi_dram[1].size >> EFI_PAGE_SHIFT,
EFI_BOOT_SERVICES_DATA, false);
}
#endif
#if defined(CONFIG_TEGRA_SUPPORT_NON_SECURE)
if (tegra_cpu_is_non_secure()) {
printf("CPU is in NS mode\n");

View File

@@ -57,14 +57,104 @@ int cleanup_before_linux_select(int flags)
return 0;
}
void *phys_to_virt(phys_addr_t paddr)
/**
* is_in_sandbox_mem() - Checks if a pointer is within sandbox's emulated DRAM
*
* This provides a way to check if a pointer is owned by sandbox (and is within
* its RAM) or not. Sometimes pointers come from a test which conceptually runs
* output sandbox, potentially with direct access to the C-library malloc()
* function, or the sandbox stack (which is not actually within the emulated
* DRAM.
*
* Such pointers obviously cannot be mapped into sandbox's DRAM, so we must
* detect them an process them separately, by recording a mapping to a tag,
* which we can use to map back to the pointer later.
*
* @ptr: Pointer to check
* @return true if this is within sandbox emulated DRAM, false if not
*/
static bool is_in_sandbox_mem(const void *ptr)
{
return (void *)(gd->arch.ram_buf + paddr);
return (const uint8_t *)ptr >= gd->arch.ram_buf &&
(const uint8_t *)ptr < gd->arch.ram_buf + gd->ram_size;
}
phys_addr_t virt_to_phys(void *vaddr)
/**
* phys_to_virt() - Converts a sandbox RAM address to a pointer
*
* Sandbox uses U-Boot addresses from 0 to the size of DRAM. These index into
* the emulated DRAM buffer used by sandbox. This function converts such an
* address to a pointer into this buffer, which can be used to access the
* memory.
*
* If the address is outside this range, it is assumed to be a tag
*/
void *phys_to_virt(phys_addr_t paddr)
{
return (phys_addr_t)((uint8_t *)vaddr - gd->arch.ram_buf);
struct sandbox_mapmem_entry *mentry;
struct sandbox_state *state;
/* If the address is within emulated DRAM, calculate the value */
if (paddr < gd->ram_size)
return (void *)(gd->arch.ram_buf + paddr);
/*
* Otherwise search out list of tags for the correct pointer previously
* created by map_to_sysmem()
*/
state = state_get_current();
list_for_each_entry(mentry, &state->mapmem_head, sibling_node) {
if (mentry->tag == paddr) {
printf("%s: Used map from %lx to %p\n", __func__,
(ulong)paddr, mentry->ptr);
return mentry->ptr;
}
}
printf("%s: Cannot map sandbox address %lx (SDRAM from 0 to %lx)\n",
__func__, (ulong)paddr, (ulong)gd->ram_size);
os_abort();
/* Not reached */
return NULL;
}
struct sandbox_mapmem_entry *find_tag(const void *ptr)
{
struct sandbox_mapmem_entry *mentry;
struct sandbox_state *state = state_get_current();
list_for_each_entry(mentry, &state->mapmem_head, sibling_node) {
if (mentry->ptr == ptr) {
debug("%s: Used map from %p to %lx\n", __func__, ptr,
mentry->tag);
return mentry;
}
}
return NULL;
}
phys_addr_t virt_to_phys(void *ptr)
{
struct sandbox_mapmem_entry *mentry;
/*
* If it is in emulated RAM, don't bother looking for a tag. Just
* calculate the pointer using the provides offset into the RAM buffer.
*/
if (is_in_sandbox_mem(ptr))
return (phys_addr_t)((uint8_t *)ptr - gd->arch.ram_buf);
mentry = find_tag(ptr);
if (!mentry) {
/* Abort so that gdb can be used here */
printf("%s: Cannot map sandbox address %p (SDRAM from 0 to %lx)\n",
__func__, ptr, (ulong)gd->ram_size);
os_abort();
}
printf("%s: Used map from %p to %lx\n", __func__, ptr, mentry->tag);
return mentry->tag;
}
void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
@@ -87,26 +177,59 @@ void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
return phys_to_virt(paddr);
}
void unmap_physmem(const void *vaddr, unsigned long flags)
void unmap_physmem(const void *ptr, unsigned long flags)
{
#ifdef CONFIG_PCI
if (map_dev) {
pci_unmap_physmem(vaddr, map_len, map_dev);
pci_unmap_physmem(ptr, map_len, map_dev);
map_dev = NULL;
}
#endif
}
phys_addr_t map_to_sysmem(const void *ptr)
{
struct sandbox_mapmem_entry *mentry;
/*
* If it is in emulated RAM, don't bother creating a tag. Just return
* the offset into the RAM buffer.
*/
if (is_in_sandbox_mem(ptr))
return (u8 *)ptr - gd->arch.ram_buf;
/*
* See if there is an existing tag with this pointer. If not, set up a
* new one.
*/
mentry = find_tag(ptr);
if (!mentry) {
struct sandbox_state *state = state_get_current();
mentry = malloc(sizeof(*mentry));
if (!mentry) {
printf("%s: Error: Out of memory\n", __func__);
os_exit(ENOMEM);
}
mentry->tag = state->next_tag++;
mentry->ptr = (void *)ptr;
list_add_tail(&mentry->sibling_node, &state->mapmem_head);
debug("%s: Added map from %p to %lx\n", __func__, ptr,
(ulong)mentry->tag);
}
/*
* Return the tag as the address to use. A later call to map_sysmem()
* will return ptr
*/
return mentry->tag;
}
void sandbox_set_enable_pci_map(int enable)
{
enable_pci_map = enable;
}
phys_addr_t map_to_sysmem(const void *ptr)
{
return (u8 *)ptr - gd->arch.ram_buf;
}
void flush_dcache_range(unsigned long start, unsigned long stop)
{
}
@@ -165,15 +288,3 @@ ulong timer_get_boot_us(void)
return (count - base_count) / 1000;
}
int setjmp(jmp_buf jmp)
{
return os_setjmp((ulong *)jmp, sizeof(*jmp));
}
void longjmp(jmp_buf jmp, int ret)
{
os_longjmp((ulong *)jmp, ret);
while (1)
;
}

View File

@@ -143,14 +143,16 @@ void os_tty_raw(int fd, bool allow_sigs)
void *os_malloc(size_t length)
{
struct os_mem_hdr *hdr;
int page_size = getpagesize();
hdr = mmap(NULL, length + sizeof(*hdr), PROT_READ | PROT_WRITE,
hdr = mmap(NULL, length + page_size,
PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (hdr == MAP_FAILED)
return NULL;
hdr->length = length;
return hdr + 1;
return (void *)hdr + page_size;
}
void os_free(void *ptr)
@@ -630,24 +632,7 @@ void os_localtime(struct rtc_time *rt)
rt->tm_isdst = tm->tm_isdst;
}
int os_setjmp(ulong *jmp, int size)
void os_abort(void)
{
jmp_buf dummy;
/*
* We cannot rely on the struct name that jmp_buf uses, so use a
* local variable here
*/
if (size < sizeof(dummy)) {
printf("setjmp: jmpbuf is too small (%d bytes, need %d)\n",
size, sizeof(jmp_buf));
return -ENOSPC;
}
return setjmp((struct __jmp_buf_tag *)jmp);
}
void os_longjmp(ulong *jmp, int ret)
{
longjmp((struct __jmp_buf_tag *)jmp, ret);
abort();
}

View File

@@ -359,6 +359,14 @@ void state_reset_for_test(struct sandbox_state *state)
memset(&state->wdt, '\0', sizeof(state->wdt));
memset(state->spi, '\0', sizeof(state->spi));
/*
* Set up the memory tag list. Use the top of emulated SDRAM for the
* first tag number, since that address offset is outside the legal
* range, and can be assumed to be a tag.
*/
INIT_LIST_HEAD(&state->mapmem_head);
state->next_tag = state->ram_size;
}
int state_init(void)

View File

@@ -24,6 +24,11 @@ struct jmp_buf_data {
typedef struct jmp_buf_data jmp_buf[1];
/*
* We have to directly link with the system versions of
* setjmp/longjmp, because setjmp must not return as otherwise
* the stack may become invalid.
*/
int setjmp(jmp_buf jmp);
__noreturn void longjmp(jmp_buf jmp, int ret);

View File

@@ -9,6 +9,7 @@
#include <config.h>
#include <sysreset.h>
#include <stdbool.h>
#include <linux/list.h>
#include <linux/stringify.h>
/**
@@ -45,6 +46,23 @@ struct sandbox_wdt_info {
bool running;
};
/**
* struct sandbox_mapmem_entry - maps pointers to/from U-Boot addresses
*
* When map_to_sysmem() is called with an address outside sandbox's emulated
* RAM, a record is created with a tag that can be used to reference that
* pointer. When map_sysmem() is called later with that tag, the pointer will
* be returned, just as it would for a normal sandbox address.
*
* @tag: Address tag (a value which U-Boot uses to refer to the address)
* @ptr: Associated pointer for that tag
*/
struct sandbox_mapmem_entry {
ulong tag;
void *ptr;
struct list_head sibling_node;
};
/* The complete state of the test system */
struct sandbox_state {
const char *cmd; /* Command to execute */
@@ -78,6 +96,9 @@ struct sandbox_state {
/* Information about Watchdog */
struct sandbox_wdt_info wdt;
ulong next_tag; /* Next address tag to allocate */
struct list_head mapmem_head; /* struct sandbox_mapmem_entry */
};
/* Minimum space we guarantee in the state FDT when calling read/write*/

View File

@@ -36,7 +36,7 @@ __weak unsigned int install_e820_map(unsigned int max_entries,
return 4;
}
#if defined(CONFIG_EFI_LOADER) && !defined(CONFIG_SPL_BUILD)
#if CONFIG_IS_ENABLED(EFI_LOADER)
void efi_add_known_memory(void)
{
struct e820_entry e820[E820MAX];
@@ -72,4 +72,4 @@ void efi_add_known_memory(void)
efi_add_memory_map(start, pages, type, false);
}
}
#endif /* defined(EFI_LOADER) && !defined(CONFIG_SPL_BUILD) */
#endif /* CONFIG_IS_ENABLED(EFI_LOADER) */