diff options
author | Edward O'Callaghan <quasisec@google.com> | 2023-04-05 11:03:10 +1000 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-04-13 10:05:41 +0000 |
commit | f28c9d7a5b2485b7346a19763aa4db004480d08d (patch) | |
tree | 38965a504f60ea493efeac41691afa02cfddfa77 | |
parent | 35f50c3154e58821cc027bf13be2b949bc4c90f3 (diff) | |
download | vboot-f28c9d7a5b2485b7346a19763aa4db004480d08d.tar.gz |
futility/: host/lib: Add flash chip info subcommand support
The AP RO verification tooling requires a understanding of the
underlying flashchip information. Provision support in the
flash subcommand to report back this data from the flashrom
driver.
BUG=b:276981092
BRANCH=none
TEST=on Nissa ```
localhost ~ # futility flash --flash-i{nfo}
Warning: Setting BIOS Control at 0xdc from 0x8b to 0x89 failed.
New value is 0x8b.
Flash vendor: Winbond
Flash name: W25Q256JV_M
Flash vid-pid: 0xef00007019
Flash size: 0x02000000
```.
Cq-Depend: chromium:4401775, chromium:4401776
Change-Id: I58e818f06def4904693f61c6967d70b16c62fa37
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/4402370
Auto-Submit: Edward O'Callaghan <quasisec@chromium.org>
Tested-by: Edward O'Callaghan <quasisec@chromium.org>
Commit-Queue: Jakub Czapiga <czapiga@google.com>
Reviewed-by: Nikolai Artemiev <nartemiev@google.com>
-rw-r--r-- | futility/cmd_flash_util.c | 38 | ||||
-rw-r--r-- | host/lib/flashrom_drv.c | 47 | ||||
-rw-r--r-- | host/lib/include/flashrom.h | 17 |
3 files changed, 101 insertions, 1 deletions
diff --git a/futility/cmd_flash_util.c b/futility/cmd_flash_util.c index 783a595e..41554597 100644 --- a/futility/cmd_flash_util.c +++ b/futility/cmd_flash_util.c @@ -7,6 +7,7 @@ #include <stdio.h> #include <stdlib.h> #include <getopt.h> +#include <inttypes.h> #include "fmap.h" #include "futility.h" @@ -27,6 +28,32 @@ static int print_flash_size(struct updater_config *cfg) return 0; } +static int print_flash_info(struct updater_config *cfg) +{ + char *vendor; + char *name; + uint32_t vid; + uint32_t pid; + uint32_t flash_size; + if (flashrom_get_info(cfg->image.programmer, + &vendor, &name, + &vid, &pid, + &flash_size, + cfg->verbosity + 1)) { + ERROR("%s failed.\n", __func__); + return -1; + } + + printf("Flash vendor: %s\n", vendor); + free(vendor); + printf("Flash name: %s\n", name); + free(name); + const uint64_t vidpid = (uint64_t) vid << 32 | pid; + printf("Flash vid-pid: 0x%" PRIx64 "\n", vidpid); + printf("Flash size: %#010x\n", flash_size); + return 0; +} + static int get_ro_range(struct updater_config *cfg, uint32_t *start, uint32_t *len) { @@ -118,6 +145,7 @@ static struct option const long_opts[] = { {"wp-status", 0, NULL, 's'}, {"wp-enable", 0, NULL, 'e'}, {"wp-disable", 0, NULL, 'd'}, + {"flash-info", 0, NULL, 'i'}, {"flash-size", 0, NULL, 'z'}, {NULL, 0, NULL, 0}, }; @@ -135,6 +163,7 @@ static void print_help(int argc, char *argv[]) " --wp-enable \tEnable protection for the RO image section.\n" " --wp-disable \tDisable all write protection.\n" " --flash-size \tGet flash size.\n" + " --flash-info \tGet flash info.\n" "\n" SHARED_FLASH_ARGS_HELP, argv[0]); @@ -150,6 +179,7 @@ static int do_flash(int argc, char *argv[]) bool disable_wp = false; bool get_wp_status = false; bool get_size = false; + bool get_info = false; struct updater_config *cfg = updater_new_config(); assert(cfg); @@ -172,6 +202,9 @@ static int do_flash(int argc, char *argv[]) case 'd': disable_wp = true; break; + case 'i': + get_info = true; + break; case 'z': get_size = true; break; @@ -198,7 +231,7 @@ static int do_flash(int argc, char *argv[]) ERROR("Unexpected arguments.\n"); } - if (!get_size && !enable_wp && !disable_wp && !get_wp_status) { + if (!get_size && !get_info && !enable_wp && !disable_wp && !get_wp_status) { print_help(argc, argv); goto out_free; } @@ -225,6 +258,9 @@ static int do_flash(int argc, char *argv[]) ret = updater_setup_config(cfg, &args, &update_needed); prepare_servo_control(prepare_ctrl_name, 1); + if (!ret && get_info) + ret = print_flash_info(cfg); + if (!ret && get_size) ret = print_flash_size(cfg); diff --git a/host/lib/flashrom_drv.c b/host/lib/flashrom_drv.c index 6eb0de8d..c678dc6a 100644 --- a/host/lib/flashrom_drv.c +++ b/host/lib/flashrom_drv.c @@ -366,6 +366,53 @@ err_init: return ret; } +int flashrom_get_info(const char *prog_with_params, + char **vendor, char **name, + uint32_t *vid, uint32_t *pid, + uint32_t *flash_len, int verbosity) +{ + int r = 0; + + g_verbose_screen = (verbosity == -1) ? FLASHROM_MSG_INFO : verbosity; + + char *programmer, *params; + char *tmp = flashrom_extract_params(prog_with_params, + &programmer, ¶ms); + + struct flashrom_programmer *prog = NULL; + struct flashrom_flashctx *flashctx = NULL; + + flashrom_set_log_callback((flashrom_log_callback *)&flashrom_print_cb); + + if (flashrom_init(1) || + flashrom_programmer_init(&prog, programmer, params)) { + r = -1; + goto err_init; + } + if (flashrom_flash_probe(&flashctx, prog, NULL)) { + r = -1; + goto err_probe; + } + + struct flashrom_flashchip_info info; + flashrom_flash_getinfo(flashctx, &info); + + *vendor = strdup(info.vendor); + *name = strdup(info.name); + *vid = info.manufacture_id; + *pid = info.model_id; + *flash_len = info.total_size * 1024; + + flashrom_flash_release(flashctx); + +err_probe: + r |= flashrom_programmer_shutdown(prog); + +err_init: + free(tmp); + return r; +} + int flashrom_get_size(const char *prog_with_params, uint32_t *flash_len, int verbosity) { diff --git a/host/lib/include/flashrom.h b/host/lib/include/flashrom.h index 4b61d199..a2efe7b6 100644 --- a/host/lib/include/flashrom.h +++ b/host/lib/include/flashrom.h @@ -104,6 +104,23 @@ int flashrom_set_wp(const char *programmer, bool wp_mode, uint32_t wp_start, uint32_t wp_len, int verbosity); /** + * Get flash info using flashrom. + * + * @param programmer The name of the programmer to use. + * @param vendor The chip vendor name, non-NULLable. + * @param name The chip product name, non-NULLable. + * @param vid The chip vendor id, non-NULLable. + * @param pid The chip product id, non-NULLable. + * @param flash_len Pointer to a uint32_t to store chip length, non-NULLable. + * + * @return 0 on success, or a relevant error. + */ +int flashrom_get_info(const char *prog_with_params, + char **vendor, char **name, + uint32_t *vid, uint32_t *pid, + uint32_t *flash_len, int verbosity); + +/** * Get flash size using flashrom. * * @param programmer The name of the programmer to use. |