Commit 42f2d0c4 authored by Daisuke Nojiri's avatar Daisuke Nojiri Committed by chrome-bot
Browse files

crosEC: Do not add padding when writing to flash

When Depthcharge writes to flash through EC, it adds padding to make
the data size equal to write_block_size of the SPI flash. Though this
might be necessary for a certain board (Pit as described in CL:62895),
this fails if we're writing to the end of the SPI flash because EC
checks whether (offset + size) exceeds the flash size or not

I think we should play this trick (padding to write block size) on the
EC side. That is, if EC receives a short packet, it should add padding
by itself if it's required.

Pit has been removed from the crosEC tree. If this patch breaks another
board, we'll fix it differently (as suggested above).

TEST=Let Depthcharge on Fizz write a RW image to the slot B, which is
located at the end.

Change-Id: I2f51917976189ea01de8c5787f6329f0a45c7f74
Signed-off-by: default avatarDaisuke Nojiri <>

Reviewed-by: default avatarAaron Durbin <>
Reviewed-by: default avatarRandall Spangler <>
parent a843f262
......@@ -889,18 +889,9 @@ static int ec_flash_write(CrosEc *me, const uint8_t *data, uint32_t offset,
end = offset + size;
for (off = offset; off < end; off += burst, data += burst) {
uint32_t todo = MIN(end - off, burst);
if (todo < burst) {
uint8_t *buf = xmalloc(burst);
memcpy(buf, data, todo);
// Pad the buffer with a decent guess for erased data
// value.
memset(buf + todo, 0xff, burst - todo);
ret = ec_flash_write_block(me, buf, off, burst);
} else {
ret = ec_flash_write_block(me, data, off, burst);
/* If SPI flash needs to add padding to make a legitimate write
* block, do so on EC. */
ret = ec_flash_write_block(me, data, off, todo);
if (ret)
return ret;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment