[PATCH 2/4 v6] cmd: efi: ESRT table debug print
Heinrich Schuchardt
xypron.glpk at gmx.de
Wed Mar 10 20:56:46 CET 2021
On 3/8/21 12:29 PM, Jose Marinho wrote:
> This commit enables the ESRT printing from the u-boot shell by invoking:
> - efidebug capsule esrt
>
> CC: Heinrich Schuchardt <xypron.glpk at gmx.de>
> CC: Sughosh Ganu <sughosh.ganu at linaro.org>
> CC: AKASHI Takahiro <takahiro.akashi at linaro.org>
> CC: Ilias Apalodimas <ilias.apalodimas at linaro.org>
> CC: Andre Przywara <andre.przywara at arm.com>
> CC: Alexander Graf <agraf at csgraf.de>
> CC: nd at arm.com
> Signed-off-by: Jose Marinho <jose.marinho at arm.com>
> ---
> cmd/efidebug.c | 66 +++++++++++++++++++++++++++++++++++++++
> include/efi_api.h | 12 +++++++
> lib/efi_loader/efi_esrt.c | 8 +++++
> 3 files changed, 86 insertions(+)
>
> diff --git a/cmd/efidebug.c b/cmd/efidebug.c
> index b3d7bd8897..5e3d1f42f9 100644
> --- a/cmd/efidebug.c
> +++ b/cmd/efidebug.c
> @@ -129,6 +129,63 @@ static int do_efi_capsule_show(struct cmd_tbl *cmdtp, int flag,
> return CMD_RET_SUCCESS;
> }
>
> +#ifdef CONFIG_EFI_ESRT
> +/**
> + * do_efi_capsule_esrt() - manage UEFI capsules
> + *
> + * @cmdtp: Command table
> + * @flag: Command flag
> + * @argc: Number of arguments
> + * @argv: Argument array
> + * Return: CMD_RET_SUCCESS on success,
> + * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
> + *
> + * Implement efidebug "capsule esrt" sub-command.
> + * The prints the current ESRT table.
> + *
> + * efidebug capsule esrt
> + */
> +static int do_efi_capsule_esrt(struct cmd_tbl *cmdtp, int flag,
> + int argc, char * const argv[])
> +{
> + struct efi_system_resource_table *esrt = NULL;
> +
> + if (argc != 1)
> + return CMD_RET_USAGE;
> +
> + for (int idx = 0; idx < systab.nr_tables; idx++)
> + if (!guidcmp(&efi_esrt_guid, &systab.tables[idx].guid))
> + esrt = (struct efi_system_resource_table *)systab.tables[idx].table;
> +
> + if (!esrt) {
> + log_info("ESRT: table not present\n");
> + return CMD_RET_SUCCESS;
> + }
> +
> + printf("========================================\n");
> + printf("ESRT: fw_resource_count=%d\n", esrt->fw_resource_count);
> + printf("ESRT: fw_resource_count_max=%d\n", esrt->fw_resource_count_max);
> + printf("ESRT: fw_resource_version=%lld\n", esrt->fw_resource_version);
> +
> + for (int idx = 0; idx < esrt->fw_resource_count; idx++) {
> + printf("[entry %d]==============================\n", idx);
> + printf("ESRT: fw_class=%pUL\n", &esrt->entries[idx].fw_class);
> + printf("ESRT: fw_type=%s\n", EFI_FW_TYPE_STR_GET(esrt->entries[idx].fw_type));
> + printf("ESRT: fw_version=%d\n", esrt->entries[idx].fw_version);
> + printf("ESRT: lowest_supported_fw_version=%d\n",
> + esrt->entries[idx].lowest_supported_fw_version);
> + printf("ESRT: capsule_flags=%d\n",
> + esrt->entries[idx].capsule_flags);
> + printf("ESRT: last_attempt_version=%d\n",
> + esrt->entries[idx].last_attempt_version);
> + printf("ESRT: last_attempt_status=%s\n",
> + EFI_FW_STATUS_STR_GET(esrt->entries[idx].last_attempt_status));
> + }
> + printf("========================================\n");
> +
> + return CMD_RET_SUCCESS;
> +}
> +#endif /* CONFIG_EFI_ESRT */
> /**
> * do_efi_capsule_res() - show a capsule update result
> *
> @@ -221,6 +278,10 @@ static struct cmd_tbl cmd_efidebug_capsule_sub[] = {
> "", ""),
> U_BOOT_CMD_MKENT(show, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_show,
> "", ""),
> +#ifdef CONFIG_EFI_ESRT
> + U_BOOT_CMD_MKENT(esrt, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_esrt,
> + "", ""),
> +#endif
> U_BOOT_CMD_MKENT(disk-update, 0, 0, do_efi_capsule_on_disk_update,
> "", ""),
> U_BOOT_CMD_MKENT(result, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_res,
> @@ -256,6 +317,7 @@ static int do_efi_capsule(struct cmd_tbl *cmdtp, int flag,
>
> return cp->cmd(cmdtp, flag, argc, argv);
> }
> +
> #endif /* CONFIG_EFI_HAVE_CAPSULE_SUPPORT */
>
> /**
> @@ -1584,6 +1646,10 @@ static char efidebug_help_text[] =
> " - show capsule information\n"
> "efidebug capsule result [<capsule result var>]\n"
> " - show a capsule update result\n"
> +#ifdef CONFIG_EFI_ESRT
> + "efidebug capsule esrt\n"
> + " - print the ESRT\n"
> +#endif
> "\n"
> #endif
> "efidebug devices\n"
> diff --git a/include/efi_api.h b/include/efi_api.h
> index fb53637419..092f5fa1d3 100644
> --- a/include/efi_api.h
> +++ b/include/efi_api.h
> @@ -1757,6 +1757,12 @@ struct efi_system_resource_table {
> #define ESRT_FW_TYPE_DEVICEFIRMWARE 0x00000002
> #define ESRT_FW_TYPE_UEFIDRIVER 0x00000003
>
> +#define EFI_FW_TYPE_NUM 4
> +extern char *efi_fw_type_str[EFI_FW_TYPE_NUM];
> +#define EFI_FW_TYPE_STR_GET(idx) (\
> +EFI_FW_TYPE_NUM > (idx) ? efi_fw_type_str[(idx)] : "error"\
> +)
> +
> #define EFI_SYSTEM_RESOURCE_TABLE_GUID\
> EFI_GUID(0xb122a263, 0x3661, 0x4f68,\
> 0x99, 0x29, 0x78, 0xf8, 0xb0, 0xd6, 0x21, 0x80)
> @@ -1772,6 +1778,12 @@ struct efi_system_resource_table {
> #define LAST_ATTEMPT_STATUS_ERROR_PWR_EVT_BATT 0x00000007
> #define LAST_ATTEMPT_STATUS_ERROR_UNSATISFIED_DEPENDENCIES 0x00000008
>
> +#define EFI_UPDATE_STATUS_NUM 9
> +extern char *efi_update_status_str[EFI_UPDATE_STATUS_NUM];
> +#define EFI_FW_STATUS_STR_GET(idx) (\
> +EFI_UPDATE_STATUS_NUM > (idx) ? efi_update_status_str[(idx)] : "error"\
> +)
> +
> /*
> * The LastAttemptStatus values of 0x1000 - 0x4000 are reserved for vendor
> * usage.
> diff --git a/lib/efi_loader/efi_esrt.c b/lib/efi_loader/efi_esrt.c
> index 947bdb5e95..3a47d09ac9 100644
> --- a/lib/efi_loader/efi_esrt.c
> +++ b/lib/efi_loader/efi_esrt.c
> @@ -15,6 +15,14 @@ const efi_guid_t efi_esrt_guid = EFI_SYSTEM_RESOURCE_TABLE_GUID;
>
> static struct efi_system_resource_table *esrt;
>
> +char *efi_fw_type_str[EFI_FW_TYPE_NUM] = {"unknown", "system FW", "device FW",
> + "UEFI driver"};
> +
> +char *efi_update_status_str[EFI_UPDATE_STATUS_NUM] = {"success", "unsuccessful",
> + "insufficient resources", "incorrect version", "invalid format",
> + "auth error", "power event (AC)", "power event (batt)",
> + "unsatisfied dependencies"};
> +
These tables are only used by the efidebug command and are not needed if
CONFIG_CMD_EFIDEBUG=n. So shouldn't they better be moved to cmd/efidebug?
Best regards
Heinrich
> #define EFI_ESRT_VERSION 1
>
> /**
>
More information about the U-Boot
mailing list