Patch queue for efi - 2018-10-17

A few bug fixes for the 2018.11 release:
 
   - Fix block seeking on 32bit
   - Fix execution with DEBUG set
   - Fix a few Coverity found bugs
   - Fix warnings
 
 Heinrich Schuchardt (13):
       efi_loader: fix relocation on x86_64
       efi_loader: correct signature of GetPosition, SetPosition
       efi_loader: execute efi_save_gd() first
       efi_loader: efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, ...)
       efi_loader: error handling in read_console()
       efi_loader: return type efi_console_register()
       efi_loader: superfluous statement in is_dir()
       efi_loader: memory leak in efi_set_variable()
       efi_loader: remove lcd.h from efi_net.c
       arm: do not include efi_loader.h twice
       efi_loader: fix typo in efi_boottime.c
       efi_selftest: creating new handle in controller test
       efi_loader: efi_dp_get_next_instance() superfluous statement
 
 Tom Rini (2):
       efi_loader: Fix warning in efi_load_image()
       fs: fat: Fix warning in normalize_longname()
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2
 
 iQIcBAABAgAGBQJbxuNeAAoJECszeR4D/txgI0gP/j26hOIDGYqrzm043Y8eA21b
 +R5TkqgvrNF8eu0Zfgl2Wf9WqqYuTDaNVFbyOQDmppb9brhqeKtsimBNFJhWNa42
 5hoEh8lWuOU3rTpvF2PQikNMwTjtVuOyf09UdBrmCYf2QB5s3UznyKLqzKTSvqYS
 zmwptfgpCIPhXfAxfPb9UmVpFrmnTaVuDDOmtDlSW8PdggI8EEASS7KTYRR1oJ3w
 nBybxnyCIJY71t7Rttf5zjDvr2avXzliEUe5PaWekjKab5IUr2V6C2Eeq+zWfKn4
 xTYXdzpcVpJKJ+PMWFot0gr46SizqwytWC0vYmlKjXT8ZJvkxhFkdFPSwJa+ihZC
 WKDQwF20VZBL46HOPJ1AvEp8G3weMGONgyYoiy8uyHXkxYxKDGAs8qBo2qM+vZEb
 dg/DBk5u9z+deJQn3SW7QwF8AuIWLhpXrXQRQ35ZhGwJck9I34Bxdm/s667J0J57
 fEU6s4r41ZT7X4V9CEjSRh5UTv1N3acA0Y5GUMUpEf4zrocRn1XpOMZRVF9s0lqs
 gZJdZ44hSRn0RxrzdyUim239nEU2iPZoCB3xggSBCyUxPtZJnOIKkTEtXGs4KEW3
 Cvuc4EXS6jfIhqInuAEThFTk/rhHLpbfXd4fGA6cN/Q18Ad0txSqEs09lNXilrgq
 VW7JkaqIsvSjwkuPgO0B
 =CIpq
 -----END PGP SIGNATURE-----

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

Patch queue for efi - 2018-10-17

A few bug fixes for the 2018.11 release:

  - Fix block seeking on 32bit
  - Fix execution with DEBUG set
  - Fix a few Coverity found bugs
  - Fix warnings

Heinrich Schuchardt (13):
      efi_loader: fix relocation on x86_64
      efi_loader: correct signature of GetPosition, SetPosition
      efi_loader: execute efi_save_gd() first
      efi_loader: efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, ...)
      efi_loader: error handling in read_console()
      efi_loader: return type efi_console_register()
      efi_loader: superfluous statement in is_dir()
      efi_loader: memory leak in efi_set_variable()
      efi_loader: remove lcd.h from efi_net.c
      arm: do not include efi_loader.h twice
      efi_loader: fix typo in efi_boottime.c
      efi_selftest: creating new handle in controller test
      efi_loader: efi_dp_get_next_instance() superfluous statement

Tom Rini (2):
      efi_loader: Fix warning in efi_load_image()
      fs: fat: Fix warning in normalize_longname()
lime2-spi
Tom Rini 6 years ago
commit e3beca3a2f
  1. 1
      arch/arm/lib/interrupts.c
  2. 24
      cmd/bootefi.c
  3. 2
      fs/fat/fat_write.c
  4. 4
      include/efi_api.h
  5. 2
      include/efi_loader.h
  6. 11
      lib/charset.c
  7. 10
      lib/efi_loader/efi_boottime.c
  8. 4
      lib/efi_loader/efi_console.c
  9. 1
      lib/efi_loader/efi_device_path.c
  10. 48
      lib/efi_loader/efi_file.c
  11. 1
      lib/efi_loader/efi_net.c
  12. 16
      lib/efi_loader/efi_runtime.c
  13. 6
      lib/efi_loader/efi_variable.c
  14. 30
      lib/efi_selftest/efi_selftest_block_device.c
  15. 2
      lib/efi_selftest/efi_selftest_controllers.c

@ -22,7 +22,6 @@
#include <efi_loader.h> #include <efi_loader.h>
#include <asm/proc-armv/ptrace.h> #include <asm/proc-armv/ptrace.h>
#include <asm/u-boot-arm.h> #include <asm/u-boot-arm.h>
#include <efi_loader.h>
DECLARE_GLOBAL_DATA_PTR; DECLARE_GLOBAL_DATA_PTR;

@ -40,6 +40,13 @@ efi_status_t efi_init_obj_list(void)
{ {
efi_status_t ret = EFI_SUCCESS; efi_status_t ret = EFI_SUCCESS;
/*
* On the ARM architecture gd is mapped to a fixed register (r9 or x18).
* As this register may be overwritten by an EFI payload we save it here
* and restore it on every callback entered.
*/
efi_save_gd();
/* Initialize once only */ /* Initialize once only */
if (efi_obj_list_initialized != OBJ_LIST_NOT_INITIALIZED) if (efi_obj_list_initialized != OBJ_LIST_NOT_INITIALIZED)
return efi_obj_list_initialized; return efi_obj_list_initialized;
@ -374,12 +381,6 @@ static efi_status_t do_bootefi_exec(void *efi,
if (ret != EFI_SUCCESS) if (ret != EFI_SUCCESS)
goto exit; goto exit;
/*
* gd lives in a fixed register which may get clobbered while we execute
* the payload. So save it here and restore it on every callback entry
*/
efi_save_gd();
/* Transfer environment variable bootargs as load options */ /* Transfer environment variable bootargs as load options */
set_load_options(loaded_image_info, "bootargs"); set_load_options(loaded_image_info, "bootargs");
/* Load the EFI payload */ /* Load the EFI payload */
@ -460,12 +461,6 @@ static int do_bootefi_bootmgr_exec(void)
void *addr; void *addr;
efi_status_t r; efi_status_t r;
/*
* gd lives in a fixed register which may get clobbered while we execute
* the payload. So save it here and restore it on every callback entry
*/
efi_save_gd();
addr = efi_bootmgr_load(&device_path, &file_path); addr = efi_bootmgr_load(&device_path, &file_path);
if (!addr) if (!addr)
return 1; return 1;
@ -547,11 +542,6 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
if (r != EFI_SUCCESS) if (r != EFI_SUCCESS)
return CMD_RET_FAILURE; return CMD_RET_FAILURE;
/*
* gd lives in a fixed register which may get clobbered while we
* execute the payload. So save it here and restore it on every
* callback entry
*/
efi_save_gd(); efi_save_gd();
/* Transfer environment variable efi_selftest as load options */ /* Transfer environment variable efi_selftest as load options */
set_load_options(loaded_image_info, "efi_selftest"); set_load_options(loaded_image_info, "efi_selftest");

@ -1012,7 +1012,7 @@ again:
static int normalize_longname(char *l_filename, const char *filename) static int normalize_longname(char *l_filename, const char *filename)
{ {
const char *p, legal[] = "!#$%&\'()-.@^`_{}~"; const char *p, legal[] = "!#$%&\'()-.@^`_{}~";
char c; unsigned char c;
int name_len; int name_len;
/* Check that the filename is valid */ /* Check that the filename is valid */

@ -914,9 +914,9 @@ struct efi_file_handle {
efi_status_t (EFIAPI *write)(struct efi_file_handle *file, efi_status_t (EFIAPI *write)(struct efi_file_handle *file,
efi_uintn_t *buffer_size, void *buffer); efi_uintn_t *buffer_size, void *buffer);
efi_status_t (EFIAPI *getpos)(struct efi_file_handle *file, efi_status_t (EFIAPI *getpos)(struct efi_file_handle *file,
efi_uintn_t *pos); u64 *pos);
efi_status_t (EFIAPI *setpos)(struct efi_file_handle *file, efi_status_t (EFIAPI *setpos)(struct efi_file_handle *file,
efi_uintn_t pos); u64 pos);
efi_status_t (EFIAPI *getinfo)(struct efi_file_handle *file, efi_status_t (EFIAPI *getinfo)(struct efi_file_handle *file,
const efi_guid_t *info_type, efi_uintn_t *buffer_size, const efi_guid_t *info_type, efi_uintn_t *buffer_size,
void *buffer); void *buffer);

@ -236,7 +236,7 @@ efi_status_t efi_root_node_register(void);
/* Called by bootefi to initialize runtime */ /* Called by bootefi to initialize runtime */
efi_status_t efi_initialize_system_table(void); efi_status_t efi_initialize_system_table(void);
/* Called by bootefi to make console interface available */ /* Called by bootefi to make console interface available */
int efi_console_register(void); efi_status_t efi_console_register(void);
/* Called by bootefi to make all disk storage accessible as EFI objects */ /* Called by bootefi to make all disk storage accessible as EFI objects */
efi_status_t efi_disk_register(void); efi_status_t efi_disk_register(void);
/* Create handles and protocols for the partitions of a block device */ /* Create handles and protocols for the partitions of a block device */

@ -97,12 +97,17 @@ static u8 read_string(void *data)
/** /**
* read_console() - read byte from console * read_console() - read byte from console
* *
* @src - not used, needed to match interface * @data - not used, needed to match interface
* Return: - byte read * Return: - byte read or 0 on error
*/ */
static u8 read_console(void *data) static u8 read_console(void *data)
{ {
return getc(); int ch;
ch = getc();
if (ch < 0)
ch = 0;
return ch;
} }
int console_read_unicode(s32 *code) int console_read_unicode(s32 *code)

@ -1599,7 +1599,7 @@ static efi_status_t EFIAPI efi_load_image(bool boot_policy,
efi_uintn_t source_size, efi_uintn_t source_size,
efi_handle_t *image_handle) efi_handle_t *image_handle)
{ {
struct efi_loaded_image *info; struct efi_loaded_image *info = NULL;
struct efi_loaded_image_obj **image_obj = struct efi_loaded_image_obj **image_obj =
(struct efi_loaded_image_obj **)image_handle; (struct efi_loaded_image_obj **)image_handle;
efi_status_t ret; efi_status_t ret;
@ -2023,7 +2023,7 @@ static efi_status_t EFIAPI efi_open_protocol_information(
/* Copy entries */ /* Copy entries */
buffer_size = count * sizeof(struct efi_open_protocol_info_entry); buffer_size = count * sizeof(struct efi_open_protocol_info_entry);
r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, buffer_size, r = efi_allocate_pool(EFI_BOOT_SERVICES_DATA, buffer_size,
(void **)entry_buffer); (void **)entry_buffer);
if (r != EFI_SUCCESS) if (r != EFI_SUCCESS)
goto out; goto out;
@ -2080,7 +2080,7 @@ static efi_status_t EFIAPI efi_protocols_per_handle(
size_t j = 0; size_t j = 0;
buffer_size = sizeof(efi_guid_t *) * *protocol_buffer_count; buffer_size = sizeof(efi_guid_t *) * *protocol_buffer_count;
r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, buffer_size, r = efi_allocate_pool(EFI_BOOT_SERVICES_DATA, buffer_size,
(void **)protocol_buffer); (void **)protocol_buffer);
if (r != EFI_SUCCESS) if (r != EFI_SUCCESS)
return EFI_EXIT(r); return EFI_EXIT(r);
@ -2133,7 +2133,7 @@ static efi_status_t EFIAPI efi_locate_handle_buffer(
*buffer); *buffer);
if (r != EFI_BUFFER_TOO_SMALL) if (r != EFI_BUFFER_TOO_SMALL)
goto out; goto out;
r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, buffer_size, r = efi_allocate_pool(EFI_BOOT_SERVICES_DATA, buffer_size,
(void **)buffer); (void **)buffer);
if (r != EFI_SUCCESS) if (r != EFI_SUCCESS)
goto out; goto out;
@ -2506,7 +2506,7 @@ static efi_status_t efi_protocol_open(
if (item->info.attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) if (item->info.attributes & EFI_OPEN_PROTOCOL_BY_DRIVER)
opened_by_driver = true; opened_by_driver = true;
} }
/* Only one controller can be conncected */ /* Only one controller can be connected */
if (opened_by_driver) if (opened_by_driver)
return EFI_ACCESS_DENIED; return EFI_ACCESS_DENIED;
} }

@ -1045,8 +1045,10 @@ static void EFIAPI efi_key_notify(struct efi_event *event, void *context)
* efi_console_register() - install the console protocols * efi_console_register() - install the console protocols
* *
* This function is called from do_bootefi_exec(). * This function is called from do_bootefi_exec().
*
* Return: status code
*/ */
int efi_console_register(void) efi_status_t efi_console_register(void)
{ {
efi_status_t r; efi_status_t r;
struct efi_object *efi_console_output_obj; struct efi_object *efi_console_output_obj;

@ -382,7 +382,6 @@ struct efi_device_path *efi_dp_get_next_instance(struct efi_device_path **dp,
*size = 0; *size = 0;
if (!dp || !*dp) if (!dp || !*dp)
return NULL; return NULL;
p = *dp;
sz = efi_dp_instance_size(*dp); sz = efi_dp_instance_size(*dp);
p = dp_alloc(sz + sizeof(END)); p = dp_alloc(sz + sizeof(END));
if (!p) if (!p)

@ -52,11 +52,18 @@ static int set_blk_dev(struct file_handle *fh)
return fs_set_blk_dev_with_part(fh->fs->desc, fh->fs->part); return fs_set_blk_dev_with_part(fh->fs->desc, fh->fs->part);
} }
/**
* is_dir() - check if file handle points to directory
*
* We assume that set_blk_dev(fh) has been called already.
*
* @fh: file handle
* Return: true if file handle points to a directory
*/
static int is_dir(struct file_handle *fh) static int is_dir(struct file_handle *fh)
{ {
struct fs_dir_stream *dirs; struct fs_dir_stream *dirs;
set_blk_dev(fh);
dirs = fs_opendir(fh->path); dirs = fs_opendir(fh->path);
if (!dirs) if (!dirs)
return 0; return 0;
@ -436,28 +443,51 @@ error:
return EFI_EXIT(ret); return EFI_EXIT(ret);
} }
/**
* efi_file_getpos() - get current position in file
*
* This function implements the GetPosition service of the EFI file protocol.
* See the UEFI spec for details.
*
* @file: file handle
* @pos: pointer to file position
* Return: status code
*/
static efi_status_t EFIAPI efi_file_getpos(struct efi_file_handle *file, static efi_status_t EFIAPI efi_file_getpos(struct efi_file_handle *file,
efi_uintn_t *pos) u64 *pos)
{ {
efi_status_t ret = EFI_SUCCESS;
struct file_handle *fh = to_fh(file); struct file_handle *fh = to_fh(file);
EFI_ENTRY("%p, %p", file, pos); EFI_ENTRY("%p, %p", file, pos);
if (fh->offset <= SIZE_MAX) { if (fh->isdir) {
*pos = fh->offset; ret = EFI_UNSUPPORTED;
return EFI_EXIT(EFI_SUCCESS); goto out;
} else {
return EFI_EXIT(EFI_DEVICE_ERROR);
} }
*pos = fh->offset;
out:
return EFI_EXIT(ret);
} }
/**
* efi_file_setpos() - set current position in file
*
* This function implements the SetPosition service of the EFI file protocol.
* See the UEFI spec for details.
*
* @file: file handle
* @pos: new file position
* Return: status code
*/
static efi_status_t EFIAPI efi_file_setpos(struct efi_file_handle *file, static efi_status_t EFIAPI efi_file_setpos(struct efi_file_handle *file,
efi_uintn_t pos) u64 pos)
{ {
struct file_handle *fh = to_fh(file); struct file_handle *fh = to_fh(file);
efi_status_t ret = EFI_SUCCESS; efi_status_t ret = EFI_SUCCESS;
EFI_ENTRY("%p, %zu", file, pos); EFI_ENTRY("%p, %llu", file, pos);
if (fh->isdir) { if (fh->isdir) {
if (pos != 0) { if (pos != 0) {

@ -7,7 +7,6 @@
#include <common.h> #include <common.h>
#include <efi_loader.h> #include <efi_loader.h>
#include <lcd.h>
#include <malloc.h> #include <malloc.h>
static const efi_guid_t efi_net_guid = EFI_SIMPLE_NETWORK_GUID; static const efi_guid_t efi_net_guid = EFI_SIMPLE_NETWORK_GUID;

@ -41,9 +41,13 @@ static efi_status_t __efi_runtime EFIAPI efi_invalid_parameter(void);
#elif defined(__arm__) #elif defined(__arm__)
#define R_RELATIVE R_ARM_RELATIVE #define R_RELATIVE R_ARM_RELATIVE
#define R_MASK 0xffULL #define R_MASK 0xffULL
#elif defined(__x86_64__) || defined(__i386__) #elif defined(__i386__)
#define R_RELATIVE R_386_RELATIVE #define R_RELATIVE R_386_RELATIVE
#define R_MASK 0xffULL #define R_MASK 0xffULL
#elif defined(__x86_64__)
#define R_RELATIVE R_X86_64_RELATIVE
#define R_MASK 0xffffffffULL
#define IS_RELA 1
#elif defined(__riscv) #elif defined(__riscv)
#define R_RELATIVE R_RISCV_RELATIVE #define R_RELATIVE R_RISCV_RELATIVE
#define R_MASK 0xffULL #define R_MASK 0xffULL
@ -358,7 +362,8 @@ void efi_runtime_relocate(ulong offset, struct efi_mem_desc *map)
p = (void*)((ulong)rel->offset - base) + gd->relocaddr; p = (void*)((ulong)rel->offset - base) + gd->relocaddr;
debug("%s: rel->info=%#lx *p=%#lx rel->offset=%p\n", __func__, rel->info, *p, rel->offset); debug("%s: rel->info=%#lx *p=%#lx rel->offset=%p\n", __func__,
rel->info, *p, rel->offset);
switch (rel->info & R_MASK) { switch (rel->info & R_MASK) {
case R_RELATIVE: case R_RELATIVE:
@ -377,6 +382,9 @@ void efi_runtime_relocate(ulong offset, struct efi_mem_desc *map)
} }
#endif #endif
default: default:
if (!efi_runtime_tobedetached(p))
printf("%s: Unknown relocation type %llx\n",
__func__, rel->info & R_MASK);
continue; continue;
} }
@ -385,8 +393,8 @@ void efi_runtime_relocate(ulong offset, struct efi_mem_desc *map)
newaddr > (map->virtual_start + newaddr > (map->virtual_start +
(map->num_pages << EFI_PAGE_SHIFT)))) { (map->num_pages << EFI_PAGE_SHIFT)))) {
if (!efi_runtime_tobedetached(p)) if (!efi_runtime_tobedetached(p))
printf("U-Boot EFI: Relocation at %p is out of " printf("%s: Relocation at %p is out of "
"range (%lx)\n", p, newaddr); "range (%lx)\n", __func__, p, newaddr);
continue; continue;
} }

@ -294,8 +294,10 @@ efi_status_t EFIAPI efi_set_variable(u16 *variable_name, efi_guid_t *vendor,
} }
val = malloc(2 * data_size + strlen("{ro,run,boot}(blob)") + 1); val = malloc(2 * data_size + strlen("{ro,run,boot}(blob)") + 1);
if (!val) if (!val) {
return EFI_EXIT(EFI_OUT_OF_RESOURCES); ret = EFI_OUT_OF_RESOURCES;
goto out;
}
s = val; s = val;

@ -308,6 +308,7 @@ static int execute(void)
} system_info; } system_info;
efi_uintn_t buf_size; efi_uintn_t buf_size;
char buf[16] __aligned(ARCH_DMA_MINALIGN); char buf[16] __aligned(ARCH_DMA_MINALIGN);
u64 pos;
/* Connect controller to virtual disk */ /* Connect controller to virtual disk */
ret = boottime->connect_controller(disk_handle, NULL, NULL, 1); ret = boottime->connect_controller(disk_handle, NULL, NULL, 1);
@ -392,21 +393,36 @@ static int execute(void)
efi_st_error("Failed to open file\n"); efi_st_error("Failed to open file\n");
return EFI_ST_FAILURE; return EFI_ST_FAILURE;
} }
ret = file->setpos(file, 1);
if (ret != EFI_SUCCESS) {
efi_st_error("SetPosition failed\n");
return EFI_ST_FAILURE;
}
buf_size = sizeof(buf) - 1; buf_size = sizeof(buf) - 1;
ret = file->read(file, &buf_size, buf); ret = file->read(file, &buf_size, buf);
if (ret != EFI_SUCCESS) { if (ret != EFI_SUCCESS) {
efi_st_error("Failed to read file\n"); efi_st_error("Failed to read file\n");
return EFI_ST_FAILURE; return EFI_ST_FAILURE;
} }
if (buf_size != 13) { if (buf_size != 12) {
efi_st_error("Wrong number of bytes read: %u\n", efi_st_error("Wrong number of bytes read: %u\n",
(unsigned int)buf_size); (unsigned int)buf_size);
return EFI_ST_FAILURE; return EFI_ST_FAILURE;
} }
if (efi_st_memcmp(buf, "Hello world!", 12)) { if (efi_st_memcmp(buf, "ello world!", 11)) {
efi_st_error("Unexpected file content\n"); efi_st_error("Unexpected file content\n");
return EFI_ST_FAILURE; return EFI_ST_FAILURE;
} }
ret = file->getpos(file, &pos);
if (ret != EFI_SUCCESS) {
efi_st_error("GetPosition failed\n");
return EFI_ST_FAILURE;
}
if (pos != 13) {
efi_st_error("GetPosition returned %u, expected 13\n",
(unsigned int)pos);
return EFI_ST_FAILURE;
}
ret = file->close(file); ret = file->close(file);
if (ret != EFI_SUCCESS) { if (ret != EFI_SUCCESS) {
efi_st_error("Failed to close file\n"); efi_st_error("Failed to close file\n");
@ -434,6 +450,16 @@ static int execute(void)
efi_st_error("Failed to close file\n"); efi_st_error("Failed to close file\n");
return EFI_ST_FAILURE; return EFI_ST_FAILURE;
} }
ret = file->getpos(file, &pos);
if (ret != EFI_SUCCESS) {
efi_st_error("GetPosition failed\n");
return EFI_ST_FAILURE;
}
if (pos != 7) {
efi_st_error("GetPosition returned %u, expected 7\n",
(unsigned int)pos);
return EFI_ST_FAILURE;
}
/* Verify file */ /* Verify file */
boottime->set_mem(buf, sizeof(buf), 0); boottime->set_mem(buf, sizeof(buf), 0);

@ -134,6 +134,8 @@ static efi_status_t EFIAPI start(
/* Create child controllers */ /* Create child controllers */
for (i = 0; i < NUMBER_OF_CHILD_CONTROLLERS; ++i) { for (i = 0; i < NUMBER_OF_CHILD_CONTROLLERS; ++i) {
/* Creating a new handle for the child controller */
handle_child_controller[i] = 0;
ret = boottime->install_protocol_interface( ret = boottime->install_protocol_interface(
&handle_child_controller[i], &guid_child_controller, &handle_child_controller[i], &guid_child_controller,
EFI_NATIVE_INTERFACE, NULL); EFI_NATIVE_INTERFACE, NULL);

Loading…
Cancel
Save