From patchwork Thu Feb 2 09:24:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 649657 Delivered-To: patch@linaro.org Received: by 2002:a17:522:d8c:b0:4be:c3dc:14d8 with SMTP id d12csp135771pva; Thu, 2 Feb 2023 01:26:44 -0800 (PST) X-Google-Smtp-Source: AK7set+q97OfVnZITufx0cllf/Ypx3xetx0CWdigd+7iChhZ00bOa1bFQTekoj3nfAG+9PYEqTgH X-Received: by 2002:a05:6870:f222:b0:169:c549:6843 with SMTP id t34-20020a056870f22200b00169c5496843mr1603019oao.46.1675330004546; Thu, 02 Feb 2023 01:26:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675330004; cv=none; d=google.com; s=arc-20160816; b=sPm9pUissdxk/DpqhK/0+OVOq9JRRITZhwpyT7rMD7D/5SsVU3xFemEvRt78ADR+sQ UZ/QS7YOSxFCwa7APSspzPBVj2wXPMObg3Ei3ST7K2KhDJPENldKIzco7SV6I9wYSjYC w6JpB438hHwUWKyt1pk34sebmmx2wSrXGCpDi7VsYkseMvKk/LwEYTq8AT3Fm+CPS27p nzUcW7c8/0w4FSdqkQAaQ9gehbwh1cnavAp1tAEKBKyIADbVCWWhlpcSO+8YthogeirJ 9ul0uXbD1jb/rlDLhROAH+RyV+b9TJbYp/JwD9LAoVk3LmJQXExEtAIdHXl73oGvAuXk mPTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=O454GUKk8eX6u2PaM/DvjAWEIf/pXOvNvuc59IeZG6w=; b=SGleA69tv0h1fov2tR/dbUHWddloHykyIcvNqkUBOIs5wFbhRve2YIWcRsCNeQ8bh+ WfEvnzpzL1LSHnJZQkQfmyFUh11Cc58EpSLuHiOkeMUBzF3xhWGQTCEgPlA0X4i0aorI ccAjId83bYtoNnq4UheWtBJdga/0NMuM4pUhVs0QgeHHD+6KGMqTqSd0+cBsDlnIhXuh pBvEXHh/YnRAEGlTG4zhxaK7qQFTTo5aP89OTMfUIRekZnW9Pgx+M62U54wSHb+oPUyA vlH6E0UsTP4vRehGMRtJs9i0Eicytcr1XBfnMsUgbc+5cRCBg/BJtSTILeeYaBhCsM4Y omdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bpIgBjzs; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id pb6-20020a0568701e8600b0014ff15936bbsi19416368oab.268.2023.02.02.01.26.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 01:26:44 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bpIgBjzs; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3A5DC85EF1; Thu, 2 Feb 2023 10:26:11 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="bpIgBjzs"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9DBF385EE9; Thu, 2 Feb 2023 10:25:25 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 761BF85EE1 for ; Thu, 2 Feb 2023 10:25:16 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pj1-x102c.google.com with SMTP id 88so1331280pjo.3 for ; Thu, 02 Feb 2023 01:25:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=O454GUKk8eX6u2PaM/DvjAWEIf/pXOvNvuc59IeZG6w=; b=bpIgBjzso8L0btTnATQQOUn87Swu7JanP/4g2bdc63H6yiFNF+hitn3f00PfGhCIrX tqNXK+m+SQioKNb3uZdstWTdVwZaHo2AxdLGkeHYAXgQUMxXUDnXKcaUSd8PKFnwzsh5 1bnsgCxnSaqKs+1sRUjDEPdaBaM70ZYFrMdoSnKvyeW1m9bg7s4yz4KYvZWVbMC75Fz2 hchJQCoJqStPc0l+xcqySxMAEJP+ebJJSgNJpO0NYHrm/R40pQHGkIOkFLYDBbJd/02R m040YHnyb4VKeuM0nGd291LoINYy9BBA3LbvtCk++64SaesQG8iCZ0f2PTbmXxpMNup5 R4Aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=O454GUKk8eX6u2PaM/DvjAWEIf/pXOvNvuc59IeZG6w=; b=qSH7FVsCseNYRj32tKgEO2JO52jHYW70/PpMxXBsjTCZjy+4fs/ncbXGzFQfFjfL3e ogMZWO8sNQS1Zzfvh8vHr8enq7Nz4UYfMmg0R6IaMVjGWmWlh7oAs4Qi9a2dlQwa6JWx G+akjxfT8GblPMLc541rGHjWK1PFBFVfZHaxWaco1Lvfen9plFVIgxg0gYnNEf8+5Wcj LVjHOrOT70Mse4Mx2JvwV6ZcNh+IsobGMVXh7yH512rlCVa4kl+L4InNxf+Qw0n9NUeC pTXr0BWrsB4WZnk6IM9SVMFSrsoK9b1Kg6lJPl5yLa/wVcbvCJueTQoDrpS39eotnf/n HdfQ== X-Gm-Message-State: AO0yUKWz2q+jeZC7zt/zT4DD0TWz2vW1iLMQ2ErJqa6kHCW4wyEKoMlx KnpC8p574KDICxNEIbQpxIYVUWytQ9uhYIaAY7E= X-Received: by 2002:a17:902:ce8e:b0:196:341b:ed7 with SMTP id f14-20020a170902ce8e00b00196341b0ed7mr7134108plg.15.1675329915627; Thu, 02 Feb 2023 01:25:15 -0800 (PST) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id w4-20020a170902a70400b0019619f27525sm13120349plq.302.2023.02.02.01.25.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 01:25:15 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima Subject: [PATCH 4/5] eficonfig: include EFI_STATUS string in error message Date: Thu, 2 Feb 2023 18:24:46 +0900 Message-Id: <20230202092447.28590-5-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230202092447.28590-1-masahisa.kojima@linaro.org> References: <20230202092447.28590-1-masahisa.kojima@linaro.org> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Current eficonfig_print_msg() does not show the return value of EFI Boot/Runtime Services when the service call fails. With this commit, user can know EFI_STATUS in the error message. Signed-off-by: Masahisa Kojima --- cmd/eficonfig.c | 95 +++++++++++++++++++++++++++++++++++++------ cmd/eficonfig_sbkey.c | 16 ++++---- include/efi_config.h | 2 +- 3 files changed, 93 insertions(+), 20 deletions(-) diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index 0a17b8cf34..b0c8637676 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -151,19 +151,90 @@ static void eficonfig_menu_adjust(struct efimenu *efi_menu, bool add) #define eficonfig_menu_up(_a) eficonfig_menu_adjust(_a, false) #define eficonfig_menu_down(_a) eficonfig_menu_adjust(_a, true) +struct efi_status_str { + efi_status_t status; + char *str; +}; + +static const struct efi_status_str status_str_table[] = { + {EFI_LOAD_ERROR, "Load Error"}, + {EFI_INVALID_PARAMETER, "Invalid Parameter"}, + {EFI_UNSUPPORTED, "Unsupported"}, + {EFI_BAD_BUFFER_SIZE, "Bad Buffer Size"}, + {EFI_BUFFER_TOO_SMALL, "Buffer Too Small"}, + {EFI_NOT_READY, "Not Ready"}, + {EFI_DEVICE_ERROR, "Device Error"}, + {EFI_WRITE_PROTECTED, "Write Protected"}, + {EFI_OUT_OF_RESOURCES, "Out of Resources"}, + {EFI_VOLUME_CORRUPTED, "Volume Corrupted"}, + {EFI_VOLUME_FULL, "Volume Full"}, + {EFI_NO_MEDIA, "No Media"}, + {EFI_MEDIA_CHANGED, "Media Changed"}, + {EFI_NOT_FOUND, "Not Found"}, + {EFI_ACCESS_DENIED, "Access Denied"}, + {EFI_NO_RESPONSE, "No Response"}, + {EFI_NO_MAPPING, "No Mapping"}, + {EFI_TIMEOUT, "Timeout"}, + {EFI_NOT_STARTED, "Not Started"}, + {EFI_ALREADY_STARTED, "Already Started"}, + {EFI_ABORTED, "Aborted"}, + {EFI_ICMP_ERROR, "ICMP Error"}, + {EFI_TFTP_ERROR, "TFTP Error"}, + {EFI_PROTOCOL_ERROR, "Protocol Error"}, + {EFI_INCOMPATIBLE_VERSION, "Incompatible Version"}, + {EFI_SECURITY_VIOLATION, "Security Violation"}, + {EFI_CRC_ERROR, "CRC Error"}, + {EFI_END_OF_MEDIA, "End of Media"}, + {EFI_END_OF_FILE, "End of File"}, + {EFI_INVALID_LANGUAGE, "Invalid Language"}, + {EFI_COMPROMISED_DATA, "Compromised Data"}, + {EFI_IP_ADDRESS_CONFLICT, "IP Address Conflict"}, + {EFI_HTTP_ERROR, "HTTP Error"}, + {EFI_WARN_UNKNOWN_GLYPH, "Warn Unknown Glyph"}, + {EFI_WARN_DELETE_FAILURE, "Warn Delete Failure"}, + {EFI_WARN_WRITE_FAILURE, "Warn Write Failure"}, + {EFI_WARN_BUFFER_TOO_SMALL, "Warn Buffer Too Small"}, + {EFI_WARN_STALE_DATA, "Warn Stale Data"}, + {EFI_WARN_FILE_SYSTEM, "Warn File System"}, + {EFI_WARN_RESET_REQUIRED, "Warn Reset Required"}, + {0, ""}, +}; + +/** + * struct get_status_str - get status string + * + * @status: efi_status_t value to covert to string + * Return: pointer to the string + */ +static char *get_error_str(efi_status_t status) +{ + u32 i; + + for (i = 0; status_str_table[i].status != 0; i++) { + if (status == status_str_table[i].status) + return status_str_table[i].str; + } + return status_str_table[i].str; +} + /** * eficonfig_print_msg() - print message * * display the message to the user, user proceeds the screen * with any key press. * - * @items: pointer to the structure of each menu entry - * @count: the number of menu entry - * @menu_header: pointer to the menu header string - * Return: status code + * @msg: pointer to the error message + * @status: efi status code, set 0 if no status string output */ -void eficonfig_print_msg(char *msg) +void eficonfig_print_msg(const char *msg, efi_status_t status) { + char str[128]; + + if (status == 0) + snprintf(str, sizeof(str), "%s", msg); + else + snprintf(str, sizeof(str), "%s (%s)", msg, get_error_str(status)); + /* Flush input */ while (tstc()) getchar(); @@ -171,7 +242,7 @@ void eficonfig_print_msg(char *msg) printf(ANSI_CURSOR_HIDE ANSI_CLEAR_CONSOLE ANSI_CURSOR_POSITION - "%s\n\n Press any key to continue", 3, 4, msg); + "%s\n\n Press any key to continue", 3, 4, str); getchar(); } @@ -580,7 +651,7 @@ static efi_status_t eficonfig_file_selected(void *data) new_len = u16_strlen(info->file_info->current_path) + strlen(info->file_name); if (new_len >= EFICONFIG_FILE_PATH_MAX) { - eficonfig_print_msg("File path is too long!"); + eficonfig_print_msg("File path is too long!", 0); return EFI_INVALID_PARAMETER; } tmp = &info->file_info->current_path[u16_strlen(info->file_info->current_path)]; @@ -626,7 +697,7 @@ static efi_status_t eficonfig_select_volume(struct eficonfig_select_file_info *f ret = efi_locate_handle_buffer_int(BY_PROTOCOL, &efi_simple_file_system_protocol_guid, NULL, &count, (efi_handle_t **)&volume_handles); if (ret != EFI_SUCCESS) { - eficonfig_print_msg("No block device found!"); + eficonfig_print_msg("No block device found!", ret); return ret; } @@ -850,7 +921,7 @@ static efi_status_t eficonfig_show_file_selection(struct eficonfig_select_file_i ret = EFI_CALL(root->open(root, &f, file_info->current_path, EFI_FILE_MODE_READ, 0)); if (ret != EFI_SUCCESS) { - eficonfig_print_msg("Reading volume failed!"); + eficonfig_print_msg("Reading volume failed!", ret); free(efi_menu); ret = EFI_ABORTED; goto out; @@ -990,12 +1061,12 @@ static efi_status_t eficonfig_boot_edit_save(void *data) struct eficonfig_boot_option *bo = data; if (u16_strlen(bo->description) == 0) { - eficonfig_print_msg("Boot Description is empty!"); + eficonfig_print_msg("Boot Description is empty!", 0); bo->edit_completed = false; return EFI_NOT_READY; } if (u16_strlen(bo->file_info.current_path) == 0) { - eficonfig_print_msg("File is not selected!"); + eficonfig_print_msg("File is not selected!", 0); bo->edit_completed = false; return EFI_NOT_READY; } @@ -2658,7 +2729,7 @@ static efi_status_t eficonfig_init(void) avail_row = rows - (EFICONFIG_MENU_HEADER_ROW_NUM + EFICONFIG_MENU_DESC_ROW_NUM); if (avail_row <= 0) { - eficonfig_print_msg("Console size is too small!"); + eficonfig_print_msg("Console size is too small!", 0); return EFI_INVALID_PARAMETER; } /* TODO: Should we check the minimum column size? */ diff --git a/cmd/eficonfig_sbkey.c b/cmd/eficonfig_sbkey.c index caca27495e..7ae1953567 100644 --- a/cmd/eficonfig_sbkey.c +++ b/cmd/eficonfig_sbkey.c @@ -150,7 +150,7 @@ static efi_status_t eficonfig_process_enroll_key(void *data) free(buf); if (!size) { - eficonfig_print_msg("ERROR! File is empty."); + eficonfig_print_msg("ERROR! File is empty.", 0); ret = EFI_INVALID_PARAMETER; goto out; } @@ -163,11 +163,13 @@ static efi_status_t eficonfig_process_enroll_key(void *data) ret = EFI_CALL(f->read(f, &size, buf)); if (ret != EFI_SUCCESS) { - eficonfig_print_msg("ERROR! Failed to read file."); + eficonfig_print_msg("ERROR! Failed to read file.", ret); goto out; } if (!file_have_auth_header(buf, size)) { - eficonfig_print_msg("ERROR! Invalid file format. Only .auth variables is allowed."); + eficonfig_print_msg( + "ERROR! Invalid file format. Only .auth variables is allowed.", + 0); ret = EFI_INVALID_PARAMETER; goto out; } @@ -175,7 +177,7 @@ static efi_status_t eficonfig_process_enroll_key(void *data) ret = file_is_null_key((struct efi_variable_authentication_2 *)buf, size, &null_key); if (ret != EFI_SUCCESS) { - eficonfig_print_msg("ERROR! Invalid file format."); + eficonfig_print_msg("ERROR! Invalid file format.", ret); goto out; } @@ -202,7 +204,7 @@ static efi_status_t eficonfig_process_enroll_key(void *data) ret = efi_set_variable_int((u16 *)data, efi_auth_var_get_guid((u16 *)data), attr, size, buf, false); if (ret != EFI_SUCCESS) - eficonfig_print_msg("ERROR! Failed to update signature database"); + eficonfig_print_msg("ERROR! Failed to update signature database", ret); out: free(file_info.current_path); @@ -283,7 +285,7 @@ static efi_status_t eficonfig_process_show_siglist(void *data) break; } default: - eficonfig_print_msg("ERROR! Unsupported format."); + eficonfig_print_msg("ERROR! Unsupported format.", 0); return EFI_INVALID_PARAMETER; } } @@ -394,7 +396,7 @@ static efi_status_t enumerate_and_show_signature_database(void *varname) db = efi_get_var(varname, efi_auth_var_get_guid(varname), &db_size); if (!db) { - eficonfig_print_msg("There is no entry in the signature database."); + eficonfig_print_msg("There is no entry in the signature database.", 0); return EFI_NOT_FOUND; } diff --git a/include/efi_config.h b/include/efi_config.h index 01ce9b2b06..19b1686907 100644 --- a/include/efi_config.h +++ b/include/efi_config.h @@ -93,7 +93,7 @@ struct eficonfig_select_file_info { bool file_selected; }; -void eficonfig_print_msg(char *msg); +void eficonfig_print_msg(const char *msg, efi_status_t status); void eficonfig_print_entry(void *data); void eficonfig_display_statusline(struct menu *m); char *eficonfig_choice_entry(void *data);