summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorMatthew Blecker <matthewb@chromium.org>2018-12-05 16:47:24 -0800
committerchrome-bot <chrome-bot@chromium.org>2019-03-14 20:53:35 -0700
commit7f0df1604c7a439c1c3bcbfe755468c08420a7ac (patch)
treed22bb872f87943bbb6aadf5fd2f1630c43a38128 /util
parentc24363ce1cd320acff6783bcf98ff8e5165360ec (diff)
downloadchrome-ec-7f0df1604c7a439c1c3bcbfe755468c08420a7ac.tar.gz
iteflash: Error when given a non-page boundary read address.
Previously command_read_pages() would quietly ignore the last byte of the address. This also makes command_read_pages() address calculation look more like command_write_pages() and command_write_pages2(). BRANCH=none BUG=b:79684405 TEST=flash_ec -> iteflash -> servo_v2 -> bip flash_ec -> iteflash -> servo_v4 -> cr50 -> bip (verification step involves reads) Change-Id: I106263d820bd284474412ddb2215820e498a4900 Signed-off-by: Matthew Blecker <matthewb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1364327 Reviewed-by: Namyoon Woo <namyoon@chromium.org>
Diffstat (limited to 'util')
-rw-r--r--util/iteflash.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/util/iteflash.c b/util/iteflash.c
index bda28d4295..1a976b09da 100644
--- a/util/iteflash.c
+++ b/util/iteflash.c
@@ -922,7 +922,13 @@ static int command_read_pages(struct common_hnd *chnd, uint32_t address,
int res = -EIO;
uint32_t remaining = size;
int cnt;
- uint16_t page;
+ uint8_t addr_H, addr_M;
+
+ if (address & 0xFF) {
+ fprintf(stderr, "page read requested at non-page boundary: "
+ "0x%X\n", address);
+ return -EINVAL;
+ }
if (spi_flash_follow_mode(chnd, "fast read") < 0)
goto failed_read;
@@ -931,7 +937,8 @@ static int command_read_pages(struct common_hnd *chnd, uint32_t address,
uint8_t cmd = 0x9;
cnt = (remaining > PAGE_SIZE) ? PAGE_SIZE : remaining;
- page = address / PAGE_SIZE;
+ addr_H = (address >> 16) & 0xFF;
+ addr_M = (address >> 8) & 0xFF;
draw_spinner(remaining, size);
@@ -939,9 +946,9 @@ static int command_read_pages(struct common_hnd *chnd, uint32_t address,
if (spi_flash_command_short(chnd, SPI_CMD_FAST_READ,
"fast read") < 0)
goto failed_read;
- res = i2c_write_byte(chnd, 0x08, page >> 8);
- res += i2c_write_byte(chnd, 0x08, page & 0xff);
- res += i2c_write_byte(chnd, 0x08, 0x00);
+ res = i2c_write_byte(chnd, 0x08, addr_H);
+ res += i2c_write_byte(chnd, 0x08, addr_M);
+ res += i2c_write_byte(chnd, 0x08, 0x00); /* addr_L */
res += i2c_write_byte(chnd, 0x08, 0x00);
if (res < 0) {
fprintf(stderr, "page address set failed\n");