diff options
author | Tom Rini <trini@konsulko.com> | 2020-09-07 08:49:50 -0400 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2020-09-07 08:49:50 -0400 |
commit | 06193ca210c6f0c864d68a0743d77880bf8d0564 (patch) | |
tree | aae9a01c66cb18600cd903ef1ca904c6c6091268 | |
parent | e5df264e7aaca0d94428586837a1f70a23479d16 (diff) | |
parent | d2a885720be6eb66595a26754d075cfd5e868420 (diff) |
Merge tag 'efi-2020-10-rc4' of https://gitlab.denx.de/u-boot/custodians/u-boot-efi
Pull request for UEFI sub-system for efi-2020-10-rc4
Bug fixes are provided in the following areas:
* convert file system debug and print messages go log messages
* convert UEFI booting messages to log messages
* UEFI related code clean up and simplification
-rw-r--r-- | cmd/bootefi.c | 12 | ||||
-rw-r--r-- | cmd/efi.c | 26 | ||||
-rw-r--r-- | fs/fs.c | 16 | ||||
-rw-r--r-- | fs/fs_internal.c | 16 | ||||
-rw-r--r-- | include/efi.h | 14 | ||||
-rw-r--r-- | lib/efi_loader/efi_boottime.c | 4 | ||||
-rw-r--r-- | lib/efi_loader/efi_image_loader.c | 50 | ||||
-rw-r--r-- | lib/efi_selftest/Makefile | 6 |
8 files changed, 75 insertions, 69 deletions
diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 06563d28ca..40d5ef2b3a 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -433,7 +433,9 @@ efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size) { efi_handle_t mem_handle = NULL, handle; struct efi_device_path *file_path = NULL; + struct efi_device_path *msg_path; efi_status_t ret; + u16 *load_options; if (!bootefi_device_path || !bootefi_image_path) { /* @@ -456,17 +458,21 @@ efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size) file_path); if (ret != EFI_SUCCESS) goto out; + msg_path = file_path; } else { file_path = efi_dp_append(bootefi_device_path, bootefi_image_path); + msg_path = bootefi_image_path; } + log_info("Booting %pD\n", msg_path); + ret = EFI_CALL(efi_load_image(false, efi_root, file_path, source_buffer, source_size, &handle)); - if (ret != EFI_SUCCESS) + if (ret != EFI_SUCCESS) { + log_err("Loading image failed\n"); goto out; - - u16 *load_options; + } /* Transfer environment variable as load options */ ret = efi_env_set_load_options(handle, "bootargs", &load_options); @@ -71,7 +71,19 @@ static int h_cmp_entry(const void *v1, const void *v2) return diff < 0 ? -1 : diff > 0 ? 1 : 0; } -void *efi_build_mem_table(struct efi_entry_memmap *map, int size, bool skip_bs) +/** + * efi_build_mem_table() - make a sorted copy of the memory table + * + * @map: Pointer to EFI memory map table + * @size: Size of table in bytes + * @skip_bs: True to skip boot-time memory and merge it with conventional + * memory. This will significantly reduce the number of table + * entries. + * Return: pointer to the new table. It should be freed with free() by the + * caller. + */ +static void *efi_build_mem_table(struct efi_entry_memmap *map, int size, + bool skip_bs) { struct efi_mem_desc *desc, *end, *base, *dest, *prev; int count; @@ -92,7 +104,13 @@ void *efi_build_mem_table(struct efi_entry_memmap *map, int size, bool skip_bs) end = (struct efi_mem_desc *)((ulong)base + count * map->desc_size); for (desc = base; desc < end; desc = efi_get_next_mem_desc(map, desc)) { bool merge = true; - int type = desc->type; + u32 type = desc->type; + + if (type >= EFI_MAX_MEMORY_TYPE) { + printf("Memory map contains invalid entry type %u\n", + type); + continue; + } if (skip_bs && is_boot_services(desc->type)) type = EFI_CONVENTIONAL_MEMORY; @@ -119,7 +137,7 @@ void *efi_build_mem_table(struct efi_entry_memmap *map, int size, bool skip_bs) } /* Mark the end */ - dest->type = EFI_TABLE_END; + dest->type = EFI_MAX_MEMORY_TYPE; return base; } @@ -138,7 +156,7 @@ static void efi_print_mem_table(struct efi_entry_memmap *map, /* Keep track of all the different attributes we have seen */ attr_seen_count = 0; addr = 0; - for (upto = 0; desc->type != EFI_TABLE_END; + for (upto = 0; desc->type != EFI_MAX_MEMORY_TYPE; upto++, desc = efi_get_next_mem_desc(map, desc)) { const char *name; u64 size; @@ -3,6 +3,8 @@ * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. */ +#define LOG_CATEGORY LOGC_CORE + #include <command.h> #include <config.h> #include <errno.h> @@ -34,7 +36,7 @@ static int fs_type = FS_TYPE_ANY; static inline int fs_probe_unsupported(struct blk_desc *fs_dev_desc, struct disk_partition *fs_partition) { - printf("** Unrecognized filesystem type **\n"); + log_err("** Unrecognized filesystem type **\n"); return -1; } @@ -508,7 +510,7 @@ static int fs_read_lmb_check(const char *filename, ulong addr, loff_t offset, if (lmb_alloc_addr(&lmb, addr, read_len) == addr) return 0; - printf("** Reading file would overwrite reserved memory **\n"); + log_err("** Reading file would overwrite reserved memory **\n"); return -ENOSPC; } #endif @@ -538,7 +540,7 @@ static int _fs_read(const char *filename, ulong addr, loff_t offset, loff_t len, /* If we requested a specific number of bytes, check we got it */ if (ret == 0 && len && *actread != len) - debug("** %s shorter than offset + len **\n", filename); + log_debug("** %s shorter than offset + len **\n", filename); fs_close(); return ret; @@ -562,7 +564,7 @@ int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len, unmap_sysmem(buf); if (ret < 0 && len != *actwrite) { - printf("** Unable to write file %s **\n", filename); + log_err("** Unable to write file %s **\n", filename); ret = -1; } fs_close(); @@ -656,7 +658,7 @@ int fs_ln(const char *fname, const char *target) ret = info->ln(fname, target); if (ret < 0) { - printf("** Unable to create link %s -> %s **\n", fname, target); + log_err("** Unable to create link %s -> %s **\n", fname, target); ret = -1; } fs_close(); @@ -737,7 +739,7 @@ int do_load(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], ret = _fs_read(filename, addr, pos, bytes, 1, &len_read); time = get_timer(time); if (ret < 0) { - printf("Failed to load '%s'\n", filename); + log_err("Failed to load '%s'\n", filename); return 1; } @@ -902,7 +904,7 @@ int do_mkdir(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], ret = fs_mkdir(argv[3]); if (ret) { - printf("** Unable to create a directory \"%s\" **\n", argv[3]); + log_err("** Unable to create a directory \"%s\" **\n", argv[3]); return 1; } diff --git a/fs/fs_internal.c b/fs/fs_internal.c index 8b19811a63..bfc35c996c 100644 --- a/fs/fs_internal.c +++ b/fs/fs_internal.c @@ -5,6 +5,8 @@ * Derived from code in ext4/dev.c, which was based on reiserfs/dev.c */ +#define LOG_CATEGORY LOGC_CORE + #include <common.h> #include <blk.h> #include <compiler.h> @@ -19,7 +21,7 @@ int fs_devread(struct blk_desc *blk, struct disk_partition *partition, int log2blksz; ALLOC_CACHE_ALIGN_BUFFER(char, sec_buf, (blk ? blk->blksz : 0)); if (blk == NULL) { - printf("** Invalid Block Device Descriptor (NULL)\n"); + log_err("** Invalid Block Device Descriptor (NULL)\n"); return 0; } log2blksz = blk->log2blksz; @@ -27,8 +29,8 @@ int fs_devread(struct blk_desc *blk, struct disk_partition *partition, /* Check partition boundaries */ if ((sector + ((byte_offset + byte_len - 1) >> log2blksz)) >= partition->size) { - printf("%s read outside partition " LBAFU "\n", __func__, - sector); + log_err("%s read outside partition " LBAFU "\n", __func__, + sector); return 0; } @@ -36,14 +38,14 @@ int fs_devread(struct blk_desc *blk, struct disk_partition *partition, sector += byte_offset >> log2blksz; byte_offset &= blk->blksz - 1; - debug(" <" LBAFU ", %d, %d>\n", sector, byte_offset, byte_len); + log_debug(" <" LBAFU ", %d, %d>\n", sector, byte_offset, byte_len); if (byte_offset != 0) { int readlen; /* read first part which isn't aligned with start of sector */ if (blk_dread(blk, partition->start + sector, 1, (void *)sec_buf) != 1) { - printf(" ** %s read error **\n", __func__); + log_err(" ** %s read error **\n", __func__); return 0; } readlen = min((int)blk->blksz - byte_offset, @@ -73,7 +75,7 @@ int fs_devread(struct blk_desc *blk, struct disk_partition *partition, if (blk_dread(blk, partition->start + sector, block_len >> log2blksz, (void *)buf) != block_len >> log2blksz) { - printf(" ** %s read error - block\n", __func__); + log_err(" ** %s read error - block\n", __func__); return 0; } block_len = byte_len & ~(blk->blksz - 1); @@ -85,7 +87,7 @@ int fs_devread(struct blk_desc *blk, struct disk_partition *partition, /* read rest of data which are not in whole sector */ if (blk_dread(blk, partition->start + sector, 1, (void *)sec_buf) != 1) { - printf("* %s read error - last part\n", __func__); + log_err("* %s read error - last part\n", __func__); return 0; } memcpy(buf, sec_buf, byte_len); diff --git a/include/efi.h b/include/efi.h index f986aad877..5695273ce9 100644 --- a/include/efi.h +++ b/include/efi.h @@ -180,7 +180,6 @@ enum efi_mem_type { EFI_PERSISTENT_MEMORY_TYPE, EFI_MAX_MEMORY_TYPE, - EFI_TABLE_END, /* For efi_build_mem_table() */ }; /* Attribute values */ @@ -481,17 +480,4 @@ void efi_putc(struct efi_priv *priv, const char ch); */ int efi_info_get(enum efi_entry_t type, void **datap, int *sizep); -/** - * efi_build_mem_table() - make a sorted copy of the memory table - * - * @map: Pointer to EFI memory map table - * @size: Size of table in bytes - * @skip_bs: True to skip boot-time memory and merge it with conventional - * memory. This will significantly reduce the number of table - * entries. - * @return pointer to the new table. It should be freed with free() by the - * caller - */ -void *efi_build_mem_table(struct efi_entry_memmap *map, int size, bool skip_bs); - #endif /* _LINUX_EFI_H */ diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index d49145fc76..dcd3eec894 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -1883,10 +1883,6 @@ efi_status_t EFIAPI efi_load_image(bool boot_policy, if (ret != EFI_SUCCESS) goto error; } else { - if (!source_size) { - ret = EFI_LOAD_ERROR; - goto error; - } dest_buffer = source_buffer; } /* split file_path which contains both the device and file parts */ diff --git a/lib/efi_loader/efi_image_loader.c b/lib/efi_loader/efi_image_loader.c index eea42cc204..94f76ef6b8 100644 --- a/lib/efi_loader/efi_image_loader.c +++ b/lib/efi_loader/efi_image_loader.c @@ -7,9 +7,12 @@ * Copyright (c) 2016 Alexander Graf */ +#define LOG_CATEGORY LOGC_EFI + #include <common.h> #include <cpu_func.h> #include <efi_loader.h> +#include <log.h> #include <malloc.h> #include <pe.h> #include <sort.h> @@ -153,14 +156,14 @@ static efi_status_t efi_loader_relocate(const IMAGE_BASE_RELOCATION *rel, case IMAGE_REL_BASED_RISCV_LOW12S: /* We know that we're 4k aligned */ if (delta & 0xfff) { - printf("Unsupported reloc offset\n"); + log_err("Unsupported reloc offset\n"); return EFI_LOAD_ERROR; } break; #endif default: - printf("Unknown Relocation off %x type %x\n", - offset, type); + log_err("Unknown Relocation off %x type %x\n", + offset, type); return EFI_LOAD_ERROR; } relocs++; @@ -202,7 +205,7 @@ static void efi_set_code_and_data_type( loaded_image_info->image_data_type = EFI_RUNTIME_SERVICES_DATA; break; default: - printf("%s: invalid image type: %u\n", __func__, image_type); + log_err("invalid image type: %u\n", image_type); /* Let's assume it is an application */ loaded_image_info->image_code_type = EFI_LOADER_CODE; loaded_image_info->image_data_type = EFI_LOADER_DATA; @@ -499,7 +502,7 @@ static bool efi_image_authenticate(void *efi, size_t efi_size) size_t new_efi_size, auth_size; bool ret = false; - debug("%s: Enter, %d\n", __func__, ret); + EFI_PRINT("%s: Enter, %d\n", __func__, ret); if (!efi_secure_boot_enabled()) return true; @@ -645,14 +648,14 @@ static bool efi_image_authenticate(void *efi, size_t efi_size) break; } - debug("Signature was not verified by \"db\"\n"); + EFI_PRINT("Signature was not verified by \"db\"\n"); if (efi_signature_lookup_digest(regs, db)) { ret = true; break; } - debug("Image's digest was not found in \"db\" or \"dbx\"\n"); + EFI_PRINT("Image's digest was not found in \"db\" or \"dbx\"\n"); } err: @@ -662,7 +665,7 @@ err: free(regs); free(new_efi); - debug("%s: Exit, %d\n", __func__, ret); + EFI_PRINT("%s: Exit, %d\n", __func__, ret); return ret; } #else @@ -704,14 +707,14 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle, /* Sanity check for a file header */ if (efi_size < sizeof(*dos)) { - printf("%s: Truncated DOS Header\n", __func__); + log_err("Truncated DOS Header\n"); ret = EFI_LOAD_ERROR; goto err; } dos = efi; if (dos->e_magic != IMAGE_DOS_SIGNATURE) { - printf("%s: Invalid DOS Signature\n", __func__); + log_err("Invalid DOS Signature\n"); ret = EFI_LOAD_ERROR; goto err; } @@ -722,14 +725,14 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle, * of the 64bit header which is longer than the 32bit header. */ if (efi_size < dos->e_lfanew + sizeof(IMAGE_NT_HEADERS64)) { - printf("%s: Invalid offset for Extended Header\n", __func__); + log_err("Invalid offset for Extended Header\n"); ret = EFI_LOAD_ERROR; goto err; } nt = (void *) ((char *)efi + dos->e_lfanew); if (nt->Signature != IMAGE_NT_SIGNATURE) { - printf("%s: Invalid NT Signature\n", __func__); + log_err("Invalid NT Signature\n"); ret = EFI_LOAD_ERROR; goto err; } @@ -741,8 +744,8 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle, } if (!supported) { - printf("%s: Machine type 0x%04x is not supported\n", - __func__, nt->FileHeader.Machine); + log_err("Machine type 0x%04x is not supported\n", + nt->FileHeader.Machine); ret = EFI_LOAD_ERROR; goto err; } @@ -753,17 +756,18 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle, if (efi_size < ((void *)sections + sizeof(sections[0]) * num_sections - efi)) { - printf("%s: Invalid number of sections: %d\n", - __func__, num_sections); + log_err("Invalid number of sections: %d\n", num_sections); ret = EFI_LOAD_ERROR; goto err; } /* Authenticate an image */ - if (efi_image_authenticate(efi, efi_size)) + if (efi_image_authenticate(efi, efi_size)) { handle->auth_status = EFI_IMAGE_AUTH_PASSED; - else + } else { handle->auth_status = EFI_IMAGE_AUTH_FAILED; + log_err("Image not authenticated\n"); + } /* Calculate upper virtual address boundary */ for (i = num_sections - 1; i >= 0; i--) { @@ -782,8 +786,7 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle, efi_reloc = efi_alloc(virt_size, loaded_image_info->image_code_type); if (!efi_reloc) { - printf("%s: Could not allocate %lu bytes\n", - __func__, virt_size); + log_err("Out of memory\n"); ret = EFI_OUT_OF_RESOURCES; goto err; } @@ -799,8 +802,7 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle, efi_reloc = efi_alloc(virt_size, loaded_image_info->image_code_type); if (!efi_reloc) { - printf("%s: Could not allocate %lu bytes\n", - __func__, virt_size); + log_err("Out of memory\n"); ret = EFI_OUT_OF_RESOURCES; goto err; } @@ -809,8 +811,8 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle, rel = efi_reloc + opt->DataDirectory[rel_idx].VirtualAddress; virt_size = ALIGN(virt_size, opt->SectionAlignment); } else { - printf("%s: Invalid optional header magic %x\n", __func__, - nt->OptionalHeader.Magic); + log_err("Invalid optional header magic %x\n", + nt->OptionalHeader.Magic); ret = EFI_LOAD_ERROR; goto err; } diff --git a/lib/efi_selftest/Makefile b/lib/efi_selftest/Makefile index 85fe8e1216..06d66cfdd1 100644 --- a/lib/efi_selftest/Makefile +++ b/lib/efi_selftest/Makefile @@ -62,10 +62,6 @@ ifeq ($(CONFIG_BLK)$(CONFIG_DOS_PARTITION),yy) obj-y += efi_selftest_block_device.o endif -# TODO: As of v2019.10 the relocation code for the EFI application cannot -# be built on ARMv7-M. -ifeq ($(CONFIG_CPU_V7M),) - obj-y += \ efi_selftest_exception.o \ efi_selftest_loadimage.o \ @@ -99,5 +95,3 @@ $(obj)/efi_selftest_exception.o: $(obj)/efi_miniapp_file_image_exception.h $(obj)/efi_selftest_startimage_exit.o: $(obj)/efi_miniapp_file_image_exit.h $(obj)/efi_selftest_startimage_return.o: $(obj)/efi_miniapp_file_image_return.h - -endif |