summaryrefslogtreecommitdiff
path: root/util/iteflash.c
diff options
context:
space:
mode:
authorMatthew Blecker <matthewb@chromium.org>2018-12-05 10:58:46 -0800
committerchrome-bot <chrome-bot@chromium.org>2019-03-14 20:53:34 -0700
commitc24363ce1cd320acff6783bcf98ff8e5165360ec (patch)
tree225aa2270d3f731d7f5643bcc26a152290abec2d /util/iteflash.c
parenta1a58a9d0af00118e36e8b0ba9794604de69b45d (diff)
downloadchrome-ec-c24363ce1cd320acff6783bcf98ff8e5165360ec.tar.gz
iteflash: Fix command_write_pages2() program page address calculation.
Previously this function assumed block_write_size was a multiple of 256 B. This is analogous to the command_write_pages() change in: https://crrev.com/c/1195309 BRANCH=none BUG=b:79684405 TEST=flash_ec -> iteflash -> servo_v2 -> bip flash_ec -> iteflash -> servo_v4 -> cr50 -> bip When combined with further changes to use iteflash -> i2c-dev -> i2c-pseudo -> servod -> servo_micro -> DUT programming path, this fixes block alignment corruption when writing ampton EC firmware. Change-Id: I4aa208559973845ef5e4205935ce7979f98d9d4a Signed-off-by: Matthew Blecker <matthewb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1363890 Reviewed-by: Namyoon Woo <namyoon@chromium.org>
Diffstat (limited to 'util/iteflash.c')
-rw-r--r--util/iteflash.c30
1 files changed, 13 insertions, 17 deletions
diff --git a/util/iteflash.c b/util/iteflash.c
index 62265421b1..bda28d4295 100644
--- a/util/iteflash.c
+++ b/util/iteflash.c
@@ -977,7 +977,7 @@ static int command_write_pages(struct common_hnd *chnd, uint32_t address,
uint32_t remaining = size;
int cnt;
uint8_t addr_H, addr_M, addr_L;
- uint8_t cmd;
+ uint8_t data;
if (spi_flash_follow_mode(chnd, "AAI write") < 0)
goto failed_write;
@@ -987,7 +987,7 @@ static int command_write_pages(struct common_hnd *chnd, uint32_t address,
block_write_size : remaining;
addr_H = (address >> 16) & 0xFF;
addr_M = (address >> 8) & 0xFF;
- addr_L = (address) & 0xFF;
+ addr_L = address & 0xFF;
draw_spinner(remaining, size);
@@ -1029,8 +1029,8 @@ static int command_write_pages(struct common_hnd *chnd, uint32_t address,
goto failed_write;
}
- cmd = 0xff;
- res = i2c_byte_transfer(chnd, I2C_DATA_ADDR, &cmd, 1, 1);
+ data = 0xFF;
+ res = i2c_byte_transfer(chnd, I2C_DATA_ADDR, &data, 1, 1);
res |= i2c_write_byte(chnd, 0x10, 0x00);
if (res < 0) {
fprintf(stderr, "Flash end data write FAILED (%d)\n",
@@ -1073,12 +1073,8 @@ static int command_write_pages2(struct common_hnd *chnd, uint32_t address,
int block_write_size)
{
int res = 0;
- uint8_t BA, A1, A0, data;
-
- /*
- * TODOD(b/<>):
- * The code will merge to the original function
- */
+ uint8_t addr_H, addr_M, addr_L;
+ uint8_t data;
res |= i2c_write_byte(chnd, 0x07, 0x7f);
res |= i2c_write_byte(chnd, 0x06, 0xff);
@@ -1112,13 +1108,13 @@ static int command_write_pages2(struct common_hnd *chnd, uint32_t address,
goto failed_write;
}
- BA = address>>16;
- A1 = address>>8;
- A0 = 0;
+ addr_H = (address >> 16) & 0xFF;
+ addr_M = (address >> 8) & 0xFF;
+ addr_L = address & 0xFF;
- res = i2c_byte_transfer(chnd, I2C_DATA_ADDR, &BA, 1, 1);
- res |= i2c_byte_transfer(chnd, I2C_DATA_ADDR, &A1, 1, 1);
- res |= i2c_byte_transfer(chnd, I2C_DATA_ADDR, &A0, 1, 1);
+ res = i2c_byte_transfer(chnd, I2C_DATA_ADDR, &addr_H, 1, 1);
+ res |= i2c_byte_transfer(chnd, I2C_DATA_ADDR, &addr_M, 1, 1);
+ res |= i2c_byte_transfer(chnd, I2C_DATA_ADDR, &addr_L, 1, 1);
res |= i2c_byte_transfer(chnd, I2C_DATA_ADDR, buffer++, 1, 1);
res |= i2c_byte_transfer(chnd, I2C_DATA_ADDR, buffer++, 1, 1);
@@ -1133,7 +1129,7 @@ static int command_write_pages2(struct common_hnd *chnd, uint32_t address,
/* No error so far */
res = size;
- data = 0xff;
+ data = 0xFF;
res = i2c_byte_transfer(chnd, I2C_DATA_ADDR, &data, 1, 1);
res = i2c_write_byte(chnd, 0x10, 0x00);