diff options
author | Josie Nordrum <josienordrum@google.com> | 2023-03-10 23:53:24 +0000 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-03-11 01:38:54 +0000 |
commit | 6507b863e6c34b6bfc2810a702bc15f4d792d5f9 (patch) | |
tree | 2d785479bbfa895b27b3f6474b88d66d05fd9152 /util/ectool.cc | |
parent | cefc03b4cf98127db38dd8f07d20569d18624317 (diff) | |
download | chrome-ec-6507b863e6c34b6bfc2810a702bc15f4d792d5f9.tar.gz |
Revert "util: Use libec for EC_VER_FLASH_PROTECT"
This reverts commit b03820fc23e64a4141283ae198415a918d50ba5f.
Reason for revert: http://b/272648081
Original change's description:
> util: Use libec for EC_VER_FLASH_PROTECT
>
> BRANCH=none
> BUG=b:116396469
> TEST=rm -rf build && make BOARD=host utils
> TEST=tast run localhost:2200 firmware.Fp{AddEntropy,BioWash,
> CheckWriteProtect,RDP0,ROOnlyBootsValidRW,RWNoUpdateRO,
> ReadFlash,RebootToRO,SoftwareWriteProtect}
>
> Change-Id: I1a2da399af50ed70d06d407da76de78f0cc25e1f
> Signed-off-by: Firas Sammoura <fsammoura@google.com>
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4261963
> Reviewed-by: Tom Hughes <tomhughes@chromium.org>
Bug: b:116396469
Change-Id: I6637a85a5ed7c179d34075ea029a4b4060cdde6d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4329102
Reviewed-by: Tom Hughes <tomhughes@chromium.org>
Commit-Queue: Josie Nordrum <josienordrum@google.com>
Tested-by: Josie Nordrum <josienordrum@google.com>
Diffstat (limited to 'util/ectool.cc')
-rw-r--r-- | util/ectool.cc | 92 |
1 files changed, 56 insertions, 36 deletions
diff --git a/util/ectool.cc b/util/ectool.cc index f0567e8db5..44871cf9b4 100644 --- a/util/ectool.cc +++ b/util/ectool.cc @@ -37,7 +37,6 @@ #include "usb_pd.h" #include <libec/add_entropy_command.h> -#include <libec/flash_protect_command.h> /* Maximum flash size (16 MB, conservative) */ #define MAX_FLASH_SIZE 0x1000000 @@ -1747,62 +1746,83 @@ int cmd_flash_erase(int argc, char *argv[]) return 0; } +static void print_flash_protect_flags(const char *desc, uint32_t flags) +{ + printf("%s 0x%08x", desc, flags); + if (flags & EC_FLASH_PROTECT_GPIO_ASSERTED) + printf(" wp_gpio_asserted"); + if (flags & EC_FLASH_PROTECT_RO_AT_BOOT) + printf(" ro_at_boot"); + if (flags & EC_FLASH_PROTECT_RW_AT_BOOT) + printf(" rw_at_boot"); + if (flags & EC_FLASH_PROTECT_ROLLBACK_AT_BOOT) + printf(" rollback_at_boot"); + if (flags & EC_FLASH_PROTECT_ALL_AT_BOOT) + printf(" all_at_boot"); + if (flags & EC_FLASH_PROTECT_RO_NOW) + printf(" ro_now"); + if (flags & EC_FLASH_PROTECT_RW_NOW) + printf(" rw_now"); + if (flags & EC_FLASH_PROTECT_ROLLBACK_NOW) + printf(" rollback_now"); + if (flags & EC_FLASH_PROTECT_ALL_NOW) + printf(" all_now"); + if (flags & EC_FLASH_PROTECT_ERROR_STUCK) + printf(" STUCK"); + if (flags & EC_FLASH_PROTECT_ERROR_INCONSISTENT) + printf(" INCONSISTENT"); + if (flags & EC_FLASH_PROTECT_ERROR_UNKNOWN) + printf(" UNKNOWN_ERROR"); + printf("\n"); +} + int cmd_flash_protect(int argc, char *argv[]) { + struct ec_params_flash_protect p; + struct ec_response_flash_protect r; + int rv, i; + /* - * Set up requested flags. If no flags were specified, mask will - * be flash_protect::Flags::kNone and nothing will change. + * Set up requested flags. If no flags were specified, p.mask will + * be 0 and nothing will change. */ - ec::flash_protect::Flags flags = ec::flash_protect::Flags::kNone; - ec::flash_protect::Flags mask = ec::flash_protect::Flags::kNone; - - for (int i = 1; i < argc; i++) { + p.mask = p.flags = 0; + for (i = 1; i < argc; i++) { if (!strcasecmp(argv[i], "now")) { - mask |= ec::flash_protect::Flags::kAllNow; - flags |= ec::flash_protect::Flags::kAllNow; + p.mask |= EC_FLASH_PROTECT_ALL_NOW; + p.flags |= EC_FLASH_PROTECT_ALL_NOW; } else if (!strcasecmp(argv[i], "enable")) { - mask |= ec::flash_protect::Flags::kRoAtBoot; - flags |= ec::flash_protect::Flags::kRoAtBoot; + p.mask |= EC_FLASH_PROTECT_RO_AT_BOOT; + p.flags |= EC_FLASH_PROTECT_RO_AT_BOOT; } else if (!strcasecmp(argv[i], "disable")) - mask |= ec::flash_protect::Flags::kRoAtBoot; + p.mask |= EC_FLASH_PROTECT_RO_AT_BOOT; } - ec::FlashProtectCommand flash_protect_command(flags, mask); - if (!flash_protect_command.Run(comm_get_fd())) { - int rv = -EECRESULT - flash_protect_command.Result(); - fprintf(stderr, "Flash protect returned with errors: %d\n", rv); + rv = ec_command(EC_CMD_FLASH_PROTECT, EC_VER_FLASH_PROTECT, &p, + sizeof(p), &r, sizeof(r)); + if (rv < 0) return rv; + if (rv < sizeof(r)) { + fprintf(stderr, "Too little data returned.\n"); + return -1; } /* Print returned flags */ - printf("Flash protect flags: 0x%08x %s\n", - flash_protect_command.GetFlags(), - (ec::FlashProtectCommand::ParseFlags( - flash_protect_command.GetFlags())) - .c_str()); - printf("Valid flags: 0x%08x %s\n", - flash_protect_command.GetValidFlags(), - (ec::FlashProtectCommand::ParseFlags( - flash_protect_command.GetValidFlags())) - .c_str()); - printf("Writable flags: 0x%08x %s\n", - flash_protect_command.GetWritableFlags(), - (ec::FlashProtectCommand::ParseFlags( - flash_protect_command.GetWritableFlags())) - .c_str()); + print_flash_protect_flags("Flash protect flags:", r.flags); + print_flash_protect_flags("Valid flags: ", r.valid_flags); + print_flash_protect_flags("Writable flags: ", r.writable_flags); /* Check if we got all the flags we asked for */ - if ((flash_protect_command.GetFlags() & mask) != (flags & mask)) { + if ((r.flags & p.mask) != (p.flags & p.mask)) { fprintf(stderr, "Unable to set requested flags " "(wanted mask 0x%08x flags 0x%08x)\n", - mask, flags); - if ((mask & ~flash_protect_command.GetWritableFlags()) != - ec::flash_protect::Flags::kNone) + p.mask, p.flags); + if (p.mask & ~r.writable_flags) fprintf(stderr, "Which is expected, because writable " "mask is 0x%08x.\n", - flash_protect_command.GetWritableFlags()); + r.writable_flags); return -1; } |