summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdward O'Callaghan <quasisec@google.com>2020-12-29 19:00:24 +1100
committerEdward O'Callaghan <quasisec@chromium.org>2021-01-01 23:47:26 +0000
commite3afd77087b317253114b231be96eec6aadf5565 (patch)
treeaee280c22e23bb781f61480ee5d7e78f3f3d27da
parentc9b31f5738db9bf2f4d82bd3db2ec78dc2bb4f14 (diff)
downloadflashrom-e3afd77087b317253114b231be96eec6aadf5565.tar.gz
flashrom-e3afd77087b317253114b231be96eec6aadf5565.tar.bz2
flashrom-e3afd77087b317253114b231be96eec6aadf5565.zip
realtek_mst_i2c_spi.c: Consolidate shifts to the one fn
To avoid further incorrect mappings ensure all the shifting happens within realtek_mst_i2c_spi_map_page() itself. BUG=none BRANCH=none TEST=builds Change-Id: I96c595b1abae044347fb0c2c91b891a60dd3675e Signed-off-by: Edward O'Callaghan <quasisec@google.com> Suggested-by: Angel Pons <th3fanbus@gmail.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/48975 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Angel Pons <th3fanbus@gmail.com>
-rw-r--r--realtek_mst_i2c_spi.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/realtek_mst_i2c_spi.c b/realtek_mst_i2c_spi.c
index 3e84b2381..a0cd7c6e6 100644
--- a/realtek_mst_i2c_spi.c
+++ b/realtek_mst_i2c_spi.c
@@ -289,9 +289,14 @@ static int realtek_mst_i2c_spi_send_command(const struct flashctx *flash,
return ret;
}
-static int realtek_mst_i2c_spi_map_page(int fd, uint8_t block_idx, uint8_t page_idx, uint8_t byte_idx)
+static int realtek_mst_i2c_spi_map_page(int fd, uint32_t addr)
{
int ret = 0;
+
+ uint8_t block_idx = (addr >> 16) & 0xff;
+ uint8_t page_idx = (addr >> 8) & 0xff;
+ uint8_t byte_idx = addr & 0xff;
+
ret |= realtek_mst_i2c_spi_write_register(fd, MAP_PAGE_BYTE2, block_idx);
ret |= realtek_mst_i2c_spi_write_register(fd, MAP_PAGE_BYTE1, page_idx);
ret |= realtek_mst_i2c_spi_write_register(fd, MAP_PAGE_BYTE0, byte_idx);
@@ -330,10 +335,7 @@ static int realtek_mst_i2c_spi_read(struct flashctx *flash, uint8_t *buf,
start--;
ret |= realtek_mst_i2c_spi_write_register(fd, 0x60, 0x46); // **
ret |= realtek_mst_i2c_spi_write_register(fd, 0x61, OPCODE_READ);
- uint8_t block_idx = (start >> 16) & 0xff;
- uint8_t page_idx = (start >> 8) & 0xff;
- uint8_t byte_idx = start & 0xff;
- ret |= realtek_mst_i2c_spi_map_page(fd, block_idx, page_idx, byte_idx);
+ ret |= realtek_mst_i2c_spi_map_page(fd, start);
ret |= realtek_mst_i2c_spi_write_register(fd, 0x6a, 0x03);
ret |= realtek_mst_i2c_spi_write_register(fd, 0x60, 0x47); // **
if (ret)
@@ -384,10 +386,7 @@ static int realtek_mst_i2c_spi_write_256(struct flashctx *flash, const uint8_t *
uint16_t page_len = min(len - i, PAGE_SIZE);
if (len - i < PAGE_SIZE)
ret |= realtek_mst_i2c_spi_write_register(fd, 0x71, page_len-1);
- uint8_t block_idx = ((start + i) >> 16) & 0xff;
- uint8_t page_idx = ((start + i) >> 8) & 0xff;
- uint8_t byte_idx = (start + i) & 0xff;
- ret |= realtek_mst_i2c_spi_map_page(fd, block_idx, page_idx, byte_idx);
+ ret |= realtek_mst_i2c_spi_map_page(fd, start + i);
if (ret)
break;