From 8d6bbaf73d3271ee3ae74b22e2bf3bd5b8fba3e8 Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Tue, 17 Jul 2018 10:03:26 +0800 Subject: ectool: Allow for chips with more than 1 MB of flash ectool currently assumes any offset >= 0x100000 (1MB) is invalid, this is not true on STM32H7. BRANCH=none BUG=none TEST=ectool --name=cros_fp flasherase 0x120000 131072 does not fail with "Bad offset." Change-Id: I5f8e29b03dbc4c1a3f1566b0e78d4466f4a44565 Signed-off-by: Nicolas Boichat Reviewed-on: https://chromium-review.googlesource.com/1139951 Reviewed-by: Randall Spangler --- util/ectool.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'util/ectool.c') diff --git a/util/ectool.c b/util/ectool.c index bbabd7332a..cc4aaa8bdc 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -30,6 +30,9 @@ #include "ps8xxx.h" #include "usb_pd.h" +/* Maximum flash size (16 MB, conservative) */ +#define MAX_FLASH_SIZE 0x1000000 + /* Command line options */ enum { OPT_DEV = 1000, @@ -676,7 +679,7 @@ int cmd_read_test(int argc, char *argv[]) } offset = strtol(argv[1], &e, 0); size = strtol(argv[2], &e, 0); - if ((e && *e) || size <= 0 || size > 0x100000) { + if ((e && *e) || size <= 0 || size > MAX_FLASH_SIZE) { fprintf(stderr, "Bad size.\n"); return -1; } @@ -852,12 +855,12 @@ int cmd_flash_read(int argc, char *argv[]) return -1; } offset = strtol(argv[1], &e, 0); - if ((e && *e) || offset < 0 || offset > 0x100000) { + if ((e && *e) || offset < 0 || offset > MAX_FLASH_SIZE) { fprintf(stderr, "Bad offset.\n"); return -1; } size = strtol(argv[2], &e, 0); - if ((e && *e) || size <= 0 || size > 0x100000) { + if ((e && *e) || size <= 0 || size > MAX_FLASH_SIZE) { fprintf(stderr, "Bad size.\n"); return -1; } @@ -898,7 +901,7 @@ int cmd_flash_write(int argc, char *argv[]) } offset = strtol(argv[1], &e, 0); - if ((e && *e) || offset < 0 || offset > 0x100000) { + if ((e && *e) || offset < 0 || offset > MAX_FLASH_SIZE) { fprintf(stderr, "Bad offset.\n"); return -1; } @@ -934,13 +937,13 @@ int cmd_flash_erase(int argc, char *argv[]) } offset = strtol(argv[1], &e, 0); - if ((e && *e) || offset < 0 || offset > 0x100000) { + if ((e && *e) || offset < 0 || offset > MAX_FLASH_SIZE) { fprintf(stderr, "Bad offset.\n"); return -1; } size = strtol(argv[2], &e, 0); - if ((e && *e) || size <= 0 || size > 0x100000) { + if ((e && *e) || size <= 0 || size > MAX_FLASH_SIZE) { fprintf(stderr, "Bad size.\n"); return -1; } -- cgit v1.2.1