From 3352b306bf63f79f2dc261b950be12bd41ba8bb1 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 15 Jun 2019 12:42:46 +0200 Subject: [PATCH 01/16] efi_loader: Blt() with incorrect BltOperation If EFI_GRAPHICS_OUTPUT_PROTOCOL.Blt() is called with an invalid value of BltOperation return EFI_INVALID_PARAMETER. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_gop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_gop.c b/lib/efi_loader/efi_gop.c index e003823b60..9428c3b83c 100644 --- a/lib/efi_loader/efi_gop.c +++ b/lib/efi_loader/efi_gop.c @@ -367,7 +367,7 @@ efi_status_t EFIAPI gop_blt(struct efi_gop *this, struct efi_gop_pixel *buffer, dy, width, height, delta, vid_bpp); break; default: - ret = EFI_UNSUPPORTED; + ret = EFI_INVALID_PARAMETER; } if (ret != EFI_SUCCESS) From 997c2ce5cf9e669ca2d6713954e50af29ceea914 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 15 Jun 2019 12:52:35 +0200 Subject: [PATCH 02/16] efi_loader: QueryMode() check parameters Check the parameters of EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode(). Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_gop.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_gop.c b/lib/efi_loader/efi_gop.c index 9428c3b83c..c44a1cfc47 100644 --- a/lib/efi_loader/efi_gop.c +++ b/lib/efi_loader/efi_gop.c @@ -41,14 +41,21 @@ static efi_status_t EFIAPI gop_query_mode(struct efi_gop *this, u32 mode_number, struct efi_gop_mode_info **info) { struct efi_gop_obj *gopobj; + efi_status_t ret = EFI_SUCCESS; EFI_ENTRY("%p, %x, %p, %p", this, mode_number, size_of_info, info); + if (!this || !size_of_info || !info || mode_number) { + ret = EFI_INVALID_PARAMETER; + goto out; + } + gopobj = container_of(this, struct efi_gop_obj, ops); *size_of_info = sizeof(gopobj->info); *info = &gopobj->info; - return EFI_EXIT(EFI_SUCCESS); +out: + return EFI_EXIT(ret); } static efi_status_t EFIAPI gop_set_mode(struct efi_gop *this, u32 mode_number) From 1f7a8b3389d66f279bf75fcfdd10c1c7d2561d6e Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 15 Jun 2019 12:58:30 +0200 Subject: [PATCH 03/16] efi_loader: SetMode() parameters check If EFI_GRAPHICS_OUTPUT_PROTOCOL.SetMode() is called with an invalid mode, return EFI_UNSUPPORTED. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_gop.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/efi_loader/efi_gop.c b/lib/efi_loader/efi_gop.c index c44a1cfc47..676463f2de 100644 --- a/lib/efi_loader/efi_gop.c +++ b/lib/efi_loader/efi_gop.c @@ -60,12 +60,14 @@ out: static efi_status_t EFIAPI gop_set_mode(struct efi_gop *this, u32 mode_number) { + efi_status_t ret = EFI_SUCCESS; + EFI_ENTRY("%p, %x", this, mode_number); - if (mode_number != 0) - return EFI_EXIT(EFI_INVALID_PARAMETER); + if (mode_number) + ret = EFI_UNSUPPORTED; - return EFI_EXIT(EFI_SUCCESS); + return EFI_EXIT(ret); } static __always_inline struct efi_gop_pixel efi_vid16_to_blt_col(u16 vid) From 97cf20861ac2a359bcde930d4ab17cec70da81f7 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 15 Jun 2019 14:07:40 +0200 Subject: [PATCH 04/16] efi_loader: QueryMode() must allocate buffer EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode() must allocate a buffer for the mode information structure. Adjust the unit test to free the buffer. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_gop.c | 6 +++++- lib/efi_selftest/efi_selftest_gop.c | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_gop.c b/lib/efi_loader/efi_gop.c index 676463f2de..2385c0f3b1 100644 --- a/lib/efi_loader/efi_gop.c +++ b/lib/efi_loader/efi_gop.c @@ -51,8 +51,12 @@ static efi_status_t EFIAPI gop_query_mode(struct efi_gop *this, u32 mode_number, } gopobj = container_of(this, struct efi_gop_obj, ops); + ret = efi_allocate_pool(EFI_BOOT_SERVICES_DATA, sizeof(gopobj->info), + (void **)info); + if (ret != EFI_SUCCESS) + goto out; *size_of_info = sizeof(gopobj->info); - *info = &gopobj->info; + memcpy(*info, &gopobj->info, sizeof(gopobj->info)); out: return EFI_EXIT(ret); diff --git a/lib/efi_selftest/efi_selftest_gop.c b/lib/efi_selftest/efi_selftest_gop.c index 4ad043c597..d64294ac79 100644 --- a/lib/efi_selftest/efi_selftest_gop.c +++ b/lib/efi_selftest/efi_selftest_gop.c @@ -80,6 +80,11 @@ static int execute(void) } efi_st_printf("Mode %u: %u x %u\n", i, info->width, info->height); + ret = boottime->free_pool(info); + if (ret != EFI_SUCCESS) { + efi_st_printf("FreePool failed"); + return EFI_ST_FAILURE; + } } return EFI_ST_SUCCESS; From 21b6b540d607a8731b311ae798918ff8c19f579d Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 15 Jun 2019 14:47:25 +0200 Subject: [PATCH 05/16] efi_loader: EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL definition EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset() is a function and not a void * pointer. Signed-off-by: Heinrich Schuchardt --- include/efi_api.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/efi_api.h b/include/efi_api.h index d7d95edd4d..4de5d208f5 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -577,7 +577,9 @@ struct simple_text_output_mode { #define EFI_ATTR_BG(attr) (((attr) >> 4) & 0x7) struct efi_simple_text_output_protocol { - void *reset; + efi_status_t (EFIAPI *reset)( + struct efi_simple_text_output_protocol *this, + char extended_verification); efi_status_t (EFIAPI *output_string)( struct efi_simple_text_output_protocol *this, const efi_string_t str); From 3c783bfbfb8204da644693b2f5d4552b53aff340 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 15 Jun 2019 14:51:06 +0200 Subject: [PATCH 06/16] efi_loader: system table setup When setting up the system table avoid superfluous void * conversions. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_boottime.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index b26291b919..d104cc6b31 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -3620,11 +3620,11 @@ struct efi_system_table __efi_runtime_data systab = { }, .fw_vendor = firmware_vendor, .fw_revision = FW_VERSION << 16 | FW_PATCHLEVEL << 8, - .con_in = (void *)&efi_con_in, - .con_out = (void *)&efi_con_out, - .std_err = (void *)&efi_con_out, - .runtime = (void *)&efi_runtime_services, - .boottime = (void *)&efi_boot_services, + .con_in = &efi_con_in, + .con_out = &efi_con_out, + .std_err = &efi_con_out, + .runtime = &efi_runtime_services, + .boottime = &efi_boot_services, .nr_tables = 0, .tables = NULL, }; From 40c8f112f5a9ff74a60d2046ed6054def8e812f7 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 15 Jun 2019 14:52:53 +0200 Subject: [PATCH 07/16] efi_loader: SetMode() must blank screen EFI_GRAPHICS_OUTPUT_PROTOCOL.SetMode() must blank the screen. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_gop.c | 50 ++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/lib/efi_loader/efi_gop.c b/lib/efi_loader/efi_gop.c index 2385c0f3b1..c1a814cd43 100644 --- a/lib/efi_loader/efi_gop.c +++ b/lib/efi_loader/efi_gop.c @@ -62,18 +62,6 @@ out: return EFI_EXIT(ret); } -static efi_status_t EFIAPI gop_set_mode(struct efi_gop *this, u32 mode_number) -{ - efi_status_t ret = EFI_SUCCESS; - - EFI_ENTRY("%p, %x", this, mode_number); - - if (mode_number) - ret = EFI_UNSUPPORTED; - - return EFI_EXIT(ret); -} - static __always_inline struct efi_gop_pixel efi_vid16_to_blt_col(u16 vid) { struct efi_gop_pixel blt = { @@ -322,6 +310,44 @@ static efi_status_t gop_blt_vid_to_buf(struct efi_gop *this, dx, dy, width, height, delta, vid_bpp); } +/** + * gop_set_mode() - set graphical output mode + * + * This function implements the SetMode() service. + * + * See the Unified Extensible Firmware Interface (UEFI) specification for + * details. + * + * @this: the graphical output protocol + * @model_number: the mode to be set + * Return: status code + */ +static efi_status_t EFIAPI gop_set_mode(struct efi_gop *this, u32 mode_number) +{ + struct efi_gop_obj *gopobj; + struct efi_gop_pixel buffer = {0, 0, 0, 0}; + efi_uintn_t vid_bpp; + efi_status_t ret = EFI_SUCCESS; + + EFI_ENTRY("%p, %x", this, mode_number); + + if (!this) { + ret = EFI_INVALID_PARAMETER; + goto out; + } + if (mode_number) { + ret = EFI_UNSUPPORTED; + goto out; + } + gopobj = container_of(this, struct efi_gop_obj, ops); + vid_bpp = gop_get_bpp(this); + ret = gop_blt_video_fill(this, &buffer, EFI_BLT_VIDEO_FILL, 0, 0, 0, 0, + gopobj->info.width, gopobj->info.height, 0, + vid_bpp); +out: + return EFI_EXIT(ret); +} + /* * Copy rectangle. * From db311f06751797f73fc9ecce2d5326f9c9edc06c Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 15 Jun 2019 14:52:53 +0200 Subject: [PATCH 08/16] efi_loader: GOP: provide accurate mode information For 5:6:5 modes provide correct frame buffer information. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_gop.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/efi_loader/efi_gop.c b/lib/efi_loader/efi_gop.c index c1a814cd43..cad509bfea 100644 --- a/lib/efi_loader/efi_gop.c +++ b/lib/efi_loader/efi_gop.c @@ -503,26 +503,26 @@ efi_status_t efi_gop_register(void) gopobj->mode.info = &gopobj->info; gopobj->mode.info_size = sizeof(gopobj->info); + gopobj->mode.fb_base = fb_base; + gopobj->mode.fb_size = fb_size; + + gopobj->info.version = 0; + gopobj->info.width = col; + gopobj->info.height = row; #ifdef CONFIG_DM_VIDEO if (bpix == VIDEO_BPP32) #else if (bpix == LCD_COLOR32) #endif { - /* - * With 32bit color space we can directly expose the frame - * buffer - */ - gopobj->mode.fb_base = fb_base; - gopobj->mode.fb_size = fb_size; + gopobj->info.pixel_format = EFI_GOT_BGRA8; + } else { + gopobj->info.pixel_format = EFI_GOT_BITMASK; + gopobj->info.pixel_bitmask[0] = 0xf800; /* red */ + gopobj->info.pixel_bitmask[1] = 0x07e0; /* green */ + gopobj->info.pixel_bitmask[2] = 0x001f; /* blue */ } - - gopobj->info.version = 0; - gopobj->info.width = col; - gopobj->info.height = row; - gopobj->info.pixel_format = EFI_GOT_BGRA8; gopobj->info.pixels_per_scanline = col; - gopobj->bpix = bpix; gopobj->fb = fb; From 3b2b2de8ee7b18b119f3ca96fcaefa7f72ba499c Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 16 Jun 2019 21:41:13 +0200 Subject: [PATCH 09/16] efi_loader: alternative scan codes for F5, END, HOME Depending on the key board alternative scan codes are used for F5, END, and HOME. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_console.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/efi_loader/efi_console.c b/lib/efi_loader/efi_console.c index 706e6ad31e..a04cbf678a 100644 --- a/lib/efi_loader/efi_console.c +++ b/lib/efi_loader/efi_console.c @@ -563,10 +563,13 @@ static efi_status_t efi_cin_read_key(struct efi_key_data *key) case cESC: /* ESC */ pressed_key.scan_code = 23; break; - case 'O': /* F1 - F4 */ + case 'O': /* F1 - F4, End */ ch = getc(); /* consider modifiers */ - if (ch < 'P') { + if (ch == 'F') { /* End */ + pressed_key.scan_code = 6; + break; + } else if (ch < 'P') { set_shift_mask(ch - '0', &key->key_state); ch = getc(); } @@ -590,17 +593,20 @@ static efi_status_t efi_cin_read_key(struct efi_key_data *key) case '1'...'5': /* F1 - F5 */ pressed_key.scan_code = ch - '1' + 11; break; - case '7'...'9': /* F6 - F8 */ - pressed_key.scan_code = ch - '7' + 16; + case '6'...'9': /* F5 - F8 */ + pressed_key.scan_code = ch - '6' + 15; break; case 'A'...'D': /* up, down right, left */ pressed_key.scan_code = ch - 'A' + 1; break; - case 'F': - pressed_key.scan_code = 6; /* End */ + case 'F': /* End */ + pressed_key.scan_code = 6; break; - case 'H': - pressed_key.scan_code = 5; /* Home */ + case 'H': /* Home */ + pressed_key.scan_code = 5; + break; + case '~': /* Home */ + pressed_key.scan_code = 5; break; } break; From 3b435c1193fe6da3649fc041e99acd45e43fdada Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 16 Jun 2019 22:33:20 +0200 Subject: [PATCH 10/16] efi_loader: console incorrectly advertised left logo key Avoid to signal that the left logo key is pressed, when it is not. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_console.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/efi_loader/efi_console.c b/lib/efi_loader/efi_console.c index a04cbf678a..6c8229da42 100644 --- a/lib/efi_loader/efi_console.c +++ b/lib/efi_loader/efi_console.c @@ -481,10 +481,8 @@ void set_shift_mask(int mod, struct efi_key_state *key_state) key_state->key_shift_state |= EFI_LEFT_ALT_PRESSED; if (mod & 4) key_state->key_shift_state |= EFI_LEFT_CONTROL_PRESSED; - if (mod & 8) + if (!mod || (mod & 8)) key_state->key_shift_state |= EFI_LEFT_LOGO_PRESSED; - } else { - key_state->key_shift_state |= EFI_LEFT_LOGO_PRESSED; } } From c974ab0ecb1c47678219395d053d385b7f5b61f0 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Mon, 17 Jun 2019 20:46:29 +0200 Subject: [PATCH 11/16] efi_loader: ListPackageLists() return EFI_NOT_FOUND If no matching package list is found in ListPackageLists(), return EFI_NOT_FOUND. If we do not support a package type, we will not find a matching package list. Remove the unreachable EFI_PRINTF() statements. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_hii.c | 49 ++++++++++++---------------------------- 1 file changed, 14 insertions(+), 35 deletions(-) diff --git a/lib/efi_loader/efi_hii.c b/lib/efi_loader/efi_hii.c index 61b71dec62..77e330285a 100644 --- a/lib/efi_loader/efi_hii.c +++ b/lib/efi_loader/efi_hii.c @@ -581,18 +581,22 @@ list_package_lists(const struct efi_hii_database_protocol *this, struct efi_hii_packagelist *hii = (struct efi_hii_packagelist *)handle; int package_cnt, package_max; - efi_status_t ret = EFI_SUCCESS; + efi_status_t ret = EFI_NOT_FOUND; EFI_ENTRY("%p, %u, %pUl, %p, %p", this, package_type, package_guid, handle_buffer_length, handle); if (!handle_buffer_length || - (*handle_buffer_length && !handle)) - return EFI_EXIT(EFI_INVALID_PARAMETER); + (*handle_buffer_length && !handle)) { + ret = EFI_INVALID_PARAMETER; + goto out; + } if ((package_type != EFI_HII_PACKAGE_TYPE_GUID && package_guid) || - (package_type == EFI_HII_PACKAGE_TYPE_GUID && !package_guid)) - return EFI_EXIT(EFI_INVALID_PARAMETER); + (package_type == EFI_HII_PACKAGE_TYPE_GUID && !package_guid)) { + ret = EFI_INVALID_PARAMETER; + goto out; + } EFI_PRINT("package type=%x, guid=%pUl, length=%zu\n", (int)package_type, package_guid, *handle_buffer_length); @@ -607,53 +611,28 @@ list_package_lists(const struct efi_hii_database_protocol *this, if (!list_empty(&hii->guid_list)) break; continue; - case EFI_HII_PACKAGE_FORMS: - EFI_PRINT("Form package not supported\n"); - ret = EFI_INVALID_PARAMETER; - continue; case EFI_HII_PACKAGE_STRINGS: if (!list_empty(&hii->string_tables)) break; continue; - case EFI_HII_PACKAGE_FONTS: - EFI_PRINT("Font package not supported\n"); - ret = EFI_INVALID_PARAMETER; - continue; - case EFI_HII_PACKAGE_IMAGES: - EFI_PRINT("Image package not supported\n"); - ret = EFI_INVALID_PARAMETER; - continue; - case EFI_HII_PACKAGE_SIMPLE_FONTS: - EFI_PRINT("Simple font package not supported\n"); - ret = EFI_INVALID_PARAMETER; - continue; - case EFI_HII_PACKAGE_DEVICE_PATH: - EFI_PRINT("Device path package not supported\n"); - ret = EFI_INVALID_PARAMETER; - continue; case EFI_HII_PACKAGE_KEYBOARD_LAYOUT: if (!list_empty(&hii->keyboard_packages)) break; continue; - case EFI_HII_PACKAGE_ANIMATIONS: - EFI_PRINT("Animation package not supported\n"); - ret = EFI_INVALID_PARAMETER; - continue; - case EFI_HII_PACKAGE_END: - case EFI_HII_PACKAGE_TYPE_SYSTEM_BEGIN: - case EFI_HII_PACKAGE_TYPE_SYSTEM_END: default: continue; } package_cnt++; - if (package_cnt <= package_max) + if (package_cnt <= package_max) { *handle++ = hii; - else + ret = EFI_SUCCESS; + } else { ret = EFI_BUFFER_TOO_SMALL; + } } *handle_buffer_length = package_cnt * sizeof(*handle); - +out: return EFI_EXIT(ret); } From fa390810e1fc6b80f936f57c4bed4a7056f18296 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Mon, 17 Jun 2019 22:00:13 +0200 Subject: [PATCH 12/16] efi_loader: Delete() return EFI_WARN_DELETE_FAILURE If EFI_FILE_PROTOCOL.Delete() fails, always close the handle and return EFI_WARN_DELETE_FAILURE. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_file.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c index 182d735e6b..36ca719a82 100644 --- a/lib/efi_loader/efi_file.c +++ b/lib/efi_loader/efi_file.c @@ -307,16 +307,10 @@ static efi_status_t EFIAPI efi_file_delete(struct efi_file_handle *file) EFI_ENTRY("%p", file); - if (set_blk_dev(fh)) { - ret = EFI_DEVICE_ERROR; - goto error; - } + if (set_blk_dev(fh) || fs_unlink(fh->path)) + ret = EFI_WARN_DELETE_FAILURE; - if (fs_unlink(fh->path)) - ret = EFI_DEVICE_ERROR; file_close(fh); - -error: return EFI_EXIT(ret); } From ee88eacbdd840199a3dec707234579fb15ddd46a Mon Sep 17 00:00:00 2001 From: Mian Yousaf Kaukab Date: Tue, 18 Jun 2019 15:03:44 +0200 Subject: [PATCH 13/16] fs: do_load: pass device path for efi payload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fatload command can be used to load the EFI payload since EFI system partition is always a FAT partition. Call into EFI code from do_load() to set the device path from which the last binary was loaded. An EFI application like grub2 can’t find its configuration file without the device path set. Since device path is now set in do_load() there is no need to set it in do_load_wrapper() for the load command. Signed-off-by: Mian Yousaf Kaukab Reviewed-by: Heinrich Schuchardt --- cmd/fs.c | 5 ----- fs/fs.c | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/fs.c b/cmd/fs.c index aaafbf9b52..db74767b7b 100644 --- a/cmd/fs.c +++ b/cmd/fs.c @@ -8,7 +8,6 @@ #include #include #include -#include static int do_size_wrapper(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { @@ -26,10 +25,6 @@ U_BOOT_CMD( static int do_load_wrapper(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { -#ifdef CONFIG_CMD_BOOTEFI - efi_set_bootdev(argv[1], (argc > 2) ? argv[2] : "", - (argc > 4) ? argv[4] : ""); -#endif return do_load(cmdtp, flag, argc, argv, FS_TYPE_ANY); } diff --git a/fs/fs.c b/fs/fs.c index 736ebef4a9..48d8f1f6da 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -17,6 +17,7 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -700,6 +701,10 @@ int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], else pos = 0; +#ifdef CONFIG_CMD_BOOTEFI + efi_set_bootdev(argv[1], (argc > 2) ? argv[2] : "", + (argc > 4) ? argv[4] : ""); +#endif time = get_timer(0); ret = _fs_read(filename, addr, pos, bytes, 1, &len_read); time = get_timer(time); From 428a470a27733cce9751224c5fee7aec28504282 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 20 Jun 2019 12:48:04 +0200 Subject: [PATCH 14/16] efi_loader: consistent types in efidebug.c efi_status_t and int are of different size. Use separate variables for return codes of different type. Signed-off-by: Heinrich Schuchardt --- cmd/efidebug.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/cmd/efidebug.c b/cmd/efidebug.c index e657226254..479e37714c 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -505,7 +505,8 @@ static int do_efi_boot_add(cmd_tbl_t *cmdtp, int flag, struct efi_load_option lo; void *data = NULL; efi_uintn_t size; - int ret; + efi_status_t ret; + int r; if (argc < 6 || argc > 7) return CMD_RET_USAGE; @@ -538,7 +539,7 @@ static int do_efi_boot_add(cmd_tbl_t *cmdtp, int flag, if (ret != EFI_SUCCESS) { printf("Cannot create device path for \"%s %s\"\n", argv[3], argv[4]); - ret = CMD_RET_FAILURE; + r = CMD_RET_FAILURE; goto out; } lo.file_path = file_path; @@ -553,7 +554,7 @@ static int do_efi_boot_add(cmd_tbl_t *cmdtp, int flag, size = efi_serialize_load_option(&lo, (u8 **)&data); if (!size) { - ret = CMD_RET_FAILURE; + r = CMD_RET_FAILURE; goto out; } @@ -562,14 +563,14 @@ static int do_efi_boot_add(cmd_tbl_t *cmdtp, int flag, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, size, data)); - ret = (ret == EFI_SUCCESS ? CMD_RET_SUCCESS : CMD_RET_FAILURE); + r = (ret == EFI_SUCCESS ? CMD_RET_SUCCESS : CMD_RET_FAILURE); out: free(data); efi_free_pool(device_path); efi_free_pool(file_path); free(lo.label); - return ret; + return r; } /** @@ -896,6 +897,7 @@ static int do_efi_boot_next(cmd_tbl_t *cmdtp, int flag, char *endp; efi_guid_t guid; efi_status_t ret; + int r; if (argc != 2) return CMD_RET_USAGE; @@ -903,7 +905,7 @@ static int do_efi_boot_next(cmd_tbl_t *cmdtp, int flag, bootnext = (u16)simple_strtoul(argv[1], &endp, 16); if (*endp != '\0' || bootnext > 0xffff) { printf("invalid value: %s\n", argv[1]); - ret = CMD_RET_FAILURE; + r = CMD_RET_FAILURE; goto out; } @@ -914,9 +916,9 @@ static int do_efi_boot_next(cmd_tbl_t *cmdtp, int flag, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, size, &bootnext)); - ret = (ret == EFI_SUCCESS ? CMD_RET_SUCCESS : CMD_RET_FAILURE); + r = (ret == EFI_SUCCESS ? CMD_RET_SUCCESS : CMD_RET_FAILURE); out: - return ret; + return r; } /** @@ -941,6 +943,7 @@ static int do_efi_boot_order(cmd_tbl_t *cmdtp, int flag, char *endp; efi_guid_t guid; efi_status_t ret; + int r; if (argc == 1) return show_efi_boot_order(); @@ -957,7 +960,7 @@ static int do_efi_boot_order(cmd_tbl_t *cmdtp, int flag, id = (int)simple_strtoul(argv[i], &endp, 16); if (*endp != '\0' || id > 0xffff) { printf("invalid value: %s\n", argv[i]); - ret = CMD_RET_FAILURE; + r = CMD_RET_FAILURE; goto out; } @@ -970,11 +973,11 @@ static int do_efi_boot_order(cmd_tbl_t *cmdtp, int flag, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, size, bootorder)); - ret = (ret == EFI_SUCCESS ? CMD_RET_SUCCESS : CMD_RET_FAILURE); + r = (ret == EFI_SUCCESS ? CMD_RET_SUCCESS : CMD_RET_FAILURE); out: free(bootorder); - return ret; + return r; } static cmd_tbl_t cmd_efidebug_boot_sub[] = { From a332f25198447a306c32e810a54946d39e373c40 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 20 Jun 2019 12:59:45 +0200 Subject: [PATCH 15/16] efi_loader: consistent error handling in efidebug.c If a variable cannot be set, always show an information message. Signed-off-by: Heinrich Schuchardt --- cmd/efidebug.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/cmd/efidebug.c b/cmd/efidebug.c index 479e37714c..cb152b3339 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -506,7 +506,7 @@ static int do_efi_boot_add(cmd_tbl_t *cmdtp, int flag, void *data = NULL; efi_uintn_t size; efi_status_t ret; - int r; + int r = CMD_RET_SUCCESS; if (argc < 6 || argc > 7) return CMD_RET_USAGE; @@ -563,7 +563,10 @@ static int do_efi_boot_add(cmd_tbl_t *cmdtp, int flag, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, size, data)); - r = (ret == EFI_SUCCESS ? CMD_RET_SUCCESS : CMD_RET_FAILURE); + if (ret != EFI_SUCCESS) { + printf("Cannot set %ls\n", var_name16); + r = CMD_RET_FAILURE; + } out: free(data); efi_free_pool(device_path); @@ -610,7 +613,7 @@ static int do_efi_boot_rm(cmd_tbl_t *cmdtp, int flag, ret = EFI_CALL(RT->set_variable(var_name16, &guid, 0, 0, NULL)); if (ret) { - printf("cannot remove Boot%04X", id); + printf("Cannot remove Boot%04X", id); return CMD_RET_FAILURE; } } @@ -897,7 +900,7 @@ static int do_efi_boot_next(cmd_tbl_t *cmdtp, int flag, char *endp; efi_guid_t guid; efi_status_t ret; - int r; + int r = CMD_RET_SUCCESS; if (argc != 2) return CMD_RET_USAGE; @@ -916,7 +919,10 @@ static int do_efi_boot_next(cmd_tbl_t *cmdtp, int flag, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, size, &bootnext)); - r = (ret == EFI_SUCCESS ? CMD_RET_SUCCESS : CMD_RET_FAILURE); + if (ret != EFI_SUCCESS) { + printf("Cannot set BootNext\n"); + r = CMD_RET_FAILURE; + } out: return r; } @@ -943,7 +949,7 @@ static int do_efi_boot_order(cmd_tbl_t *cmdtp, int flag, char *endp; efi_guid_t guid; efi_status_t ret; - int r; + int r = CMD_RET_SUCCESS; if (argc == 1) return show_efi_boot_order(); @@ -973,7 +979,10 @@ static int do_efi_boot_order(cmd_tbl_t *cmdtp, int flag, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, size, bootorder)); - r = (ret == EFI_SUCCESS ? CMD_RET_SUCCESS : CMD_RET_FAILURE); + if (ret != EFI_SUCCESS) { + printf("Cannot set BootOrder\n"); + r = CMD_RET_FAILURE; + } out: free(bootorder); From 8f89a574a9f4be2ff1402b35f49fcd2e1c6518fd Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 20 Jun 2019 12:03:53 +0200 Subject: [PATCH 16/16] efi_loader: fix typo in efi_variable.c %s/efi_efi_/efi_/ Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_variable.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c index 1d1b23b0e5..d6b75ca02e 100644 --- a/lib/efi_loader/efi_variable.c +++ b/lib/efi_loader/efi_variable.c @@ -148,7 +148,7 @@ static const char *parse_attr(const char *str, u32 *attrp) } /** - * efi_efi_get_variable() - retrieve value of a UEFI variable + * efi_get_variable() - retrieve value of a UEFI variable * * This function implements the GetVariable runtime service. * @@ -404,7 +404,7 @@ efi_status_t EFIAPI efi_get_next_variable_name(efi_uintn_t *variable_name_size, } /** - * efi_efi_set_variable() - set value of a UEFI variable + * efi_set_variable() - set value of a UEFI variable * * This function implements the SetVariable runtime service. *