Aarya has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/67368 )
Change subject: spi.c: Move spi_get_erasefn_from_opcode to spi.c ......................................................................
spi.c: Move spi_get_erasefn_from_opcode to spi.c
Move spi_get_erasefn_from_opcode and spi_get_opcode_from_erasefn to spi.c.
Change-Id: I3263b7642c35e7fd1da0002175123e5560d94752 Signed-off-by: Aarya Chaumal aarya.chaumal@gmail.com --- M spi.c M spi25.c 2 files changed, 58 insertions(+), 45 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/68/67368/1
diff --git a/spi.c b/spi.c index eeb1362..a5b1e2f 100644 --- a/spi.c +++ b/spi.c @@ -26,6 +26,51 @@ #include "programmer.h" #include "spi.h"
+static const struct { + erasefunc_t *func; + uint8_t opcode; +} function_opcode_list[] = { + {&spi_block_erase_20, 0x20}, + {&spi_block_erase_21, 0x21}, + {&spi_block_erase_50, 0x50}, + {&spi_block_erase_52, 0x52}, + {&spi_block_erase_53, 0x53}, + {&spi_block_erase_5c, 0x5c}, + {&spi_block_erase_60, 0x60}, + {&spi_block_erase_62, 0x62}, + {&spi_block_erase_81, 0x81}, + {&spi_block_erase_c4, 0xc4}, + {&spi_block_erase_c7, 0xc7}, + {&spi_block_erase_d7, 0xd7}, + {&spi_block_erase_d8, 0xd8}, + {&spi_block_erase_db, 0xdb}, + {&spi_block_erase_dc, 0xdc}, +}; + +erasefunc_t *spi_get_erasefn_from_opcode(uint8_t opcode) +{ + size_t i; + for (i = 0; i < ARRAY_SIZE(function_opcode_list); i++) { + if (function_opcode_list[i].opcode == opcode) + return function_opcode_list[i].func; + } + msg_cinfo("%s: unknown erase opcode (0x%02x). Please report " + "this at flashrom@flashrom.org\n", __func__, opcode); + return NULL; +} + +uint8_t spi_get_opcode_from_erasefn(erasefunc_t *func) +{ + size_t i; + for (i = 0; i < ARRAY_SIZE(function_opcode_list); i++) { + if (function_opcode_list[i].func == func) + return function_opcode_list[i].opcode; + } + msg_cinfo("%s: unknown erase function (0x%p). Please report " + "this at flashrom@flashrom.org\n", __func__, func); + return 0x00; //Assuming 0x00 is not a erase function opcode +} + int spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr) diff --git a/spi25.c b/spi25.c index 4454106..c6ffe78 100644 --- a/spi25.c +++ b/spi25.c @@ -618,51 +618,6 @@ return spi_write_cmd(flash, 0xdc, true, addr, NULL, 0, 100 * 1000); }
-static const struct { - erasefunc_t *func; - uint8_t opcode; -} function_opcode_list[] = { - {&spi_block_erase_20, 0x20}, - {&spi_block_erase_21, 0x21}, - {&spi_block_erase_50, 0x50}, - {&spi_block_erase_52, 0x52}, - {&spi_block_erase_53, 0x53}, - {&spi_block_erase_5c, 0x5c}, - {&spi_block_erase_60, 0x60}, - {&spi_block_erase_62, 0x62}, - {&spi_block_erase_81, 0x81}, - {&spi_block_erase_c4, 0xc4}, - {&spi_block_erase_c7, 0xc7}, - {&spi_block_erase_d7, 0xd7}, - {&spi_block_erase_d8, 0xd8}, - {&spi_block_erase_db, 0xdb}, - {&spi_block_erase_dc, 0xdc}, -}; - -erasefunc_t *spi_get_erasefn_from_opcode(uint8_t opcode) -{ - size_t i; - for (i = 0; i < ARRAY_SIZE(function_opcode_list); i++) { - if (function_opcode_list[i].opcode == opcode) - return function_opcode_list[i].func; - } - msg_cinfo("%s: unknown erase opcode (0x%02x). Please report " - "this at flashrom@flashrom.org\n", __func__, opcode); - return NULL; -} - -uint8_t spi_get_opcode_from_erasefn(erasefunc_t *func) -{ - size_t i; - for (i = 0; i < ARRAY_SIZE(function_opcode_list); i++) { - if (function_opcode_list[i].func == func) - return function_opcode_list[i].opcode; - } - msg_cinfo("%s: unknown erase function (0x%p). Please report " - "this at flashrom@flashrom.org\n", __func__, func); - return 0x00; //Assuming 0x00 is not a erase function opcode -} - static int spi_nbyte_program(struct flashctx *flash, unsigned int addr, const uint8_t *bytes, unsigned int len) { const bool native_4ba = flash->chip->feature_bits & FEATURE_4BA_WRITE && spi_master_4ba(flash);