From 43ab0587f36ef40aba334b94489dfe4225fe1bbb Mon Sep 17 00:00:00 2001 From: Evan Benn Date: Thu, 12 Jan 2023 17:22:57 +1100 Subject: 2lib: Add vb2_get_gbb_flag_description Add a function to convert a gbb flag to the name and description of that flag. Use this function in cmd_gbb to format a help page and implement --explicit. BUG=b:260531154 BRANCH=None TEST=futility gbb --get /dev/bios -e TEST=futility gbb --help Change-Id: I884b6e0e7322128409f8d62d76824d8e6e6ca330 Signed-off-by: Evan Benn Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/4161092 Reviewed-by: Yu-Ping Wu Reviewed-by: Edward O'Callaghan --- firmware/2lib/2gbb.c | 83 ++++++++++++++++++++++++++++++++++++++ firmware/2lib/include/2gbb_flags.h | 6 +++ futility/cmd_gbb_utility.c | 43 +++++++++++++++++++- 3 files changed, 130 insertions(+), 2 deletions(-) diff --git a/firmware/2lib/2gbb.c b/firmware/2lib/2gbb.c index b64c5acf..d5c46dce 100644 --- a/firmware/2lib/2gbb.c +++ b/firmware/2lib/2gbb.c @@ -117,3 +117,86 @@ vb2_gbb_flags_t vb2api_gbb_get_flags(struct vb2_context *ctx) struct vb2_gbb_header *gbb = vb2_get_gbb(ctx); return gbb->flags; } + +vb2_error_t vb2_get_gbb_flag_description(enum vb2_gbb_flag flag, + const char **name, + const char **description) +{ + switch (flag) { + case VB2_GBB_FLAG_DEV_SCREEN_SHORT_DELAY: + *name = "VB2_GBB_FLAG_DEV_SCREEN_SHORT_DELAY"; + *description = "Reduce the dev screen delay to 2 sec from 30 sec."; + break; + case VB2_GBB_FLAG_LOAD_OPTION_ROMS: + *name = "VB2_GBB_FLAG_LOAD_OPTION_ROMS"; + *description = "BIOS should load option ROMs from arbitrary PCI devices."; + break; + case VB2_GBB_FLAG_ENABLE_ALTERNATE_OS: + *name = "VB2_GBB_FLAG_ENABLE_ALTERNATE_OS"; + *description = "Boot a non-ChromeOS kernel."; + break; + case VB2_GBB_FLAG_FORCE_DEV_SWITCH_ON: + *name = "VB2_GBB_FLAG_FORCE_DEV_SWITCH_ON"; + *description = "Force dev switch on, regardless of physical/keyboard dev switch."; + break; + case VB2_GBB_FLAG_FORCE_DEV_BOOT_USB: + *name = "VB2_GBB_FLAG_FORCE_DEV_BOOT_USB"; + *description = "Allow booting from external disk even if dev_boot_usb=0."; + break; + case VB2_GBB_FLAG_DISABLE_FW_ROLLBACK_CHECK: + *name = "VB2_GBB_FLAG_DISABLE_FW_ROLLBACK_CHECK"; + *description = "Disable firmware rollback protection."; + break; + case VB2_GBB_FLAG_ENTER_TRIGGERS_TONORM: + *name = "VB2_GBB_FLAG_ENTER_TRIGGERS_TONORM"; + *description = "Allow Enter key to trigger dev->tonorm screen transition."; + break; + case VB2_GBB_FLAG_FORCE_DEV_BOOT_ALTFW: + *name = "VB2_GBB_FLAG_FORCE_DEV_BOOT_ALTFW"; + *description = + "Allow booting Legacy OSes even if dev_boot_altfw=0."; + break; + case VB2_GBB_FLAG_RUNNING_FAFT: + *name = "VB2_GBB_FLAG_RUNNING_FAFT"; + *description = "Currently running FAFT tests."; + break; + case VB2_GBB_FLAG_DISABLE_EC_SOFTWARE_SYNC: + *name = "VB2_GBB_FLAG_DISABLE_EC_SOFTWARE_SYNC"; + *description = "Disable EC software sync."; + break; + case VB2_GBB_FLAG_DEFAULT_DEV_BOOT_ALTFW: + *name = "VB2_GBB_FLAG_DEFAULT_DEV_BOOT_ALTFW"; + *description = "Default to booting legacy OS when dev screen times out."; + break; + case VB2_GBB_FLAG_DISABLE_AUXFW_SOFTWARE_SYNC: + *name = "VB2_GBB_FLAG_DISABLE_AUXFW_SOFTWARE_SYNC"; + *description = + "Disable auxiliary firmware (auxfw) software sync."; + break; + case VB2_GBB_FLAG_DISABLE_LID_SHUTDOWN: + *name = "VB2_GBB_FLAG_DISABLE_LID_SHUTDOWN"; + *description = "Disable shutdown on lid closed."; + break; + case VB2_GBB_FLAG_DEPRECATED_FORCE_DEV_BOOT_FASTBOOT_FULL_CAP: + *name = "VB2_GBB_FLAG_DEPRECATED_FORCE_DEV_BOOT_FASTBOOT_FULL_CAP"; + *description = "Allow full fastboot capability in firmware even if dev_boot_fastboot_full_cap=0."; + break; + case VB2_GBB_FLAG_FORCE_MANUAL_RECOVERY: + *name = "VB2_GBB_FLAG_FORCE_MANUAL_RECOVERY"; + *description = "Recovery mode always assumes manual recovery, even if EC_IN_RW=1."; + break; + case VB2_GBB_FLAG_DISABLE_FWMP: + *name = "VB2_GBB_FLAG_DISABLE_FWMP"; + *description = "Disable FWMP."; + break; + case VB2_GBB_FLAG_ENABLE_UDC: + *name = "VB2_GBB_FLAG_ENABLE_UDC"; + *description = "Enable USB Device Controller."; + break; + default: + *name = NULL; + *description = NULL; + return VB2_ERROR_UNKNOWN; + } + return VB2_SUCCESS; +} diff --git a/firmware/2lib/include/2gbb_flags.h b/firmware/2lib/include/2gbb_flags.h index a7c6fb99..5c92950b 100644 --- a/firmware/2lib/include/2gbb_flags.h +++ b/firmware/2lib/include/2gbb_flags.h @@ -10,6 +10,8 @@ #ifndef VBOOT_REFERENCE_2GBB_FLAGS_H_ #define VBOOT_REFERENCE_2GBB_FLAGS_H_ +#include "2return_codes.h" + enum vb2_gbb_flag { /* * Reduce the dev screen delay to 2 sec from 30 sec to speed up @@ -93,4 +95,8 @@ enum vb2_gbb_flag { VB2_GBB_FLAG_ENABLE_UDC = 1 << 16, }; +vb2_error_t vb2_get_gbb_flag_description(enum vb2_gbb_flag flag, + const char **name, + const char **description); + #endif /* VBOOT_REFERENCE_2GBB_FLAGS_H_ */ diff --git a/futility/cmd_gbb_utility.c b/futility/cmd_gbb_utility.c index 3ca93b94..b40cceda 100644 --- a/futility/cmd_gbb_utility.c +++ b/futility/cmd_gbb_utility.c @@ -18,6 +18,7 @@ #include "futility.h" #include "updater.h" #include "updater_utils.h" +#include "2gbb_flags.h" #ifdef USE_FLASHROM #define FLASH_ARG_HELP \ @@ -50,6 +51,7 @@ static void print_help(int argc, char *argv[]) " -k, --rootkey=FILE \tFile name to export Root Key.\n" " -b, --bmpfv=FILE \tFile name to export Bitmap FV.\n" " -r --recoverykey=FILE\tFile name to export Recovery Key.\n" + " -e --explicit \tReport header flags by name.\n" "\n" "SET MODE:\n" "-s, --set \tSet (write) to flash or file, " @@ -71,8 +73,21 @@ static void print_help(int argc, char *argv[]) " %s -g bios.bin\n" " %s --set --hwid='New Model' -k key.bin" " bios.bin newbios.bin\n" - " %s -c 0x100,0x1000,0x03DE80,0x1000 gbb.blob\n\n", + " %s -c 0x100,0x1000,0x03DE80,0x1000 gbb.blob\n\n" + "GBB Flags:\n" + " To get a developer-friendly device, try 0x18 (dev_mode boot_usb).\n" + " For early bringup development, try 0x40b9.\n", argv[0], argv[0], argv[0], argv[0]); + for (vb2_gbb_flags_t flag = 1; flag; flag <<= 1) { + const char *name; + const char *description; + if (vb2_get_gbb_flag_description(flag, &name, &description) != + VB2_SUCCESS) + break; + printf(" 0x%08x\t%s\n" + " \t%s\n", + flag, name, description); + } } enum { @@ -96,13 +111,14 @@ static struct option long_opts[] = { {"recoverykey", 1, NULL, 'r'}, {"hwid", 0, NULL, OPT_HWID}, {"flags", 0, NULL, OPT_FLAGS}, + {"explicit", 0, NULL, 'e'}, {"digest", 0, NULL, OPT_DIGEST}, {"flash", 0, NULL, OPT_FLASH}, {"help", 0, NULL, OPT_HELP}, {NULL, 0, NULL, 0}, }; -static const char *short_opts = ":gsc:o:k:b:r:" SHARED_FLASH_ARGS_SHORTOPTS; +static const char *short_opts = ":gsc:o:k:b:r:e" SHARED_FLASH_ARGS_SHORTOPTS; /* Change the has_arg field of a long_opts entry */ static void opt_has_arg(const char *name, int val) @@ -443,6 +459,7 @@ static int do_gbb(int argc, char *argv[]) int sel_hwid = 0; int sel_digest = 0; int sel_flags = 0; + int explicit_flags = 0; uint8_t *inbuf = NULL; off_t filesize; uint8_t *outbuf = NULL; @@ -497,6 +514,10 @@ static int do_gbb(int argc, char *argv[]) opt_flags = optarg; sel_flags = 1; break; + case 'e': + sel_flags = 1; + explicit_flags = 1; + break; case OPT_DIGEST: sel_digest = 1; break; @@ -628,6 +649,24 @@ static int do_gbb(int argc, char *argv[]) errorcnt++; break; } + if (explicit_flags) { + vb2_gbb_flags_t remaining_flags = gbb->flags; + while (remaining_flags) { + vb2_gbb_flags_t lsb_flag = + remaining_flags & -remaining_flags; + remaining_flags &= ~lsb_flag; + const char *name; + const char *description; + if (vb2_get_gbb_flag_description( + lsb_flag, &name, &description) == + VB2_SUCCESS) { + printf("%s\n", name); + } else { + printf("unknown set flag: 0x%08x\n", + lsb_flag); + } + } + } break; case DO_SET: -- cgit v1.2.1