summaryrefslogtreecommitdiff
path: root/futility/cmd_flash_util.c
diff options
context:
space:
mode:
Diffstat (limited to 'futility/cmd_flash_util.c')
-rw-r--r--futility/cmd_flash_util.c38
1 files changed, 37 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);