Tyler Wang has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/81928?usp=email )
Change subject: util/ifdtool: Add support for checking GPR0 status ......................................................................
util/ifdtool: Add support for checking GPR0 status
This patch adds support for the new command-line option `-c` to the ifdtool, which is able to check GPR0 status.
User can use ifdtool with '-c' option to check whether GPR0 is set to enable or disable in the binary file.
BUG=none TEST=(1)Run `ifdtool -p mtl -c image.bin` on a locked karis image, show "GPRO status: Enabled". (2)Run `ifdtool -p mtl -c unlock_image.bin` on a unlocked karis image, show "GPRO status: Disabled".
Change-Id: I6b3af973be784200b965a68e5f6b7737cba03ed7 Signed-off-by: Tyler Wang tyler.wang@quanta.corp-partner.google.com --- M util/ifdtool/ifdtool.c 1 file changed, 35 insertions(+), 4 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/28/81928/1
diff --git a/util/ifdtool/ifdtool.c b/util/ifdtool/ifdtool.c index 516570e..b09f63c 100644 --- a/util/ifdtool/ifdtool.c +++ b/util/ifdtool/ifdtool.c @@ -1784,6 +1784,29 @@ printf("GPR0 protection is now enabled\n"); }
+static void check_gpr0(char *image, int size) +{ + struct fpsba *fpsba = find_fpsba(image, size); + if (!fpsba) + exit(EXIT_FAILURE); + + uint32_t gpr0_offset = get_gpr0_offset(); + if (gpr0_offset == 0xffffffff) { + fprintf(stderr, "Checking GPR0 not supported on this platform\n"); + exit(EXIT_FAILURE); + } + + union gprd reg; + /* If bit 31 is set then GPR0 protection is enable */ + reg.value = fpsba->pchstrp[gpr0_offset]; + if (reg.data.write_protect_en) + printf("GPR0 status: Enabled\n\n"); + else + printf("GPR0 status: Disabled\n\n"); + + return; +} + static void set_pchstrap(struct fpsba *fpsba, const struct fdbar *fdb, const int strap, const unsigned int value) { @@ -2125,6 +2148,7 @@ " -u | --unlock Unlock firmware descriptor and ME region\n" " -g | --gpr0-disable Disable GPR0 (Global Protected Range) register\n" " -E | --gpr0-enable Enable GPR0 (Global Protected Range) register\n" + " -c | --gpr0-status Checking GPR0 (Global Protected Range) register status\n" " -M | --altmedisable <0|1> Set the MeDisable and AltMeDisable (or HAP for skylake or newer platform)\n" " bits to disable ME\n" " -p | --platform Add platform-specific quirks\n" @@ -2158,7 +2182,7 @@ int mode_em100 = 0, mode_locked = 0, mode_unlocked = 0, mode_validate = 0; int mode_layout = 0, mode_newlayout = 0, mode_density = 0, mode_setstrap = 0; int mode_read = 0, mode_altmedisable = 0, altmedisable = 0, mode_fmap_template = 0; - int mode_gpr0_disable = 0, mode_gpr0_enable = 0; + int mode_gpr0_disable = 0, mode_gpr0_enable = 0, mode_gpr0_status = 0; char *region_type_string = NULL, *region_fname = NULL; const char *layout_fname = NULL; char *new_filename = NULL; @@ -2186,6 +2210,7 @@ {"unlock", 0, NULL, 'u'}, {"gpr0-disable", 0, NULL, 'g'}, {"gpr0-enable", 0, NULL, 'E'}, + {"gpr0-status", 0, NULL, 'c'}, {"version", 0, NULL, 'v'}, {"help", 0, NULL, 'h'}, {"platform", 1, NULL, 'p'}, @@ -2195,7 +2220,7 @@ {0, 0, 0, 0} };
- while ((opt = getopt_long(argc, argv, "S:V:df:F:D:C:M:xi:n:O:s:p:elrugEvth?", + while ((opt = getopt_long(argc, argv, "S:V:df:F:D:C:M:xi:n:O:s:p:elrugEcvth?", long_options, &option_index)) != EOF) { switch (opt) { case 'd': @@ -2404,6 +2429,9 @@ case 'E': mode_gpr0_enable = 1; break; + case 'c': + mode_gpr0_status = 1; + break; case 'p': if (!strcmp(optarg, "aplk")) { platform = PLATFORM_APL; @@ -2457,7 +2485,7 @@ if ((mode_dump + mode_layout + mode_fmap_template + mode_extract + mode_inject + mode_setstrap + mode_newlayout + (mode_spifreq | mode_em100 | mode_unlocked | mode_locked) + mode_altmedisable + mode_validate + - (mode_gpr0_disable | mode_gpr0_enable)) > 1) { + (mode_gpr0_disable | mode_gpr0_enable) + mode_gpr0_status) > 1) { fprintf(stderr, "You may not specify more than one mode.\n\n"); fprintf(stderr, "run '%s -h' for usage\n", argv[0]); exit(EXIT_FAILURE); @@ -2466,7 +2494,7 @@ if ((mode_dump + mode_layout + mode_fmap_template + mode_extract + mode_inject + mode_setstrap + mode_newlayout + mode_spifreq + mode_em100 + mode_locked + mode_unlocked + mode_density + mode_altmedisable + - mode_validate + (mode_gpr0_disable | mode_gpr0_enable)) == 0) { + mode_validate + (mode_gpr0_disable | mode_gpr0_enable) + mode_gpr0_status) == 0) { fprintf(stderr, "You need to specify a mode.\n\n"); fprintf(stderr, "run '%s -h' for usage\n", argv[0]); exit(EXIT_FAILURE); @@ -2569,6 +2597,9 @@ if (mode_gpr0_enable) enable_gpr0(new_filename, image, size);
+ if (mode_gpr0_status) + check_gpr0(image, size); + if (mode_setstrap) { struct fpsba *fpsba = find_fpsba(image, size); const struct fdbar *fdb = find_fd(image, size);