Aarya has uploaded this change for review.

View Change

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. Also add opcode and erasefn for AT45 and S25F to the lookup list.

Change-Id: Ief25932120f940dea0ffe161a79219deecb2e8ab
Signed-off-by: Aarya Chaumal <aarya.chaumal@gmail.com>
---
M spi.c
M spi25.c
2 files changed, 69 insertions(+), 45 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/54/67354/1
diff --git a/spi.c b/spi.c
index eeb1362..82bb324 100644
--- a/spi.c
+++ b/spi.c
@@ -26,6 +26,62 @@
#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},
+ //AT45CS1282 opcodes and erasefn
+ {&spi_erase_at45cs_sector, 0x7c},
+ {&spi_erase_at45cs_sector, 0x50},
+ //AT45DB** opcodes and erasefn
+ {&spi_erase_at45db_page, 0x81},
+ {&spi_erase_at45db_block, 0x50},
+ {&spi_erase_at45db_sector, 0x7c},
+ {&spi_erase_at45db_chip, 0xc7},
+ //SF25F** opcodes and erasefn
+ {&s25fl_block_erase, 0xdc},
+ {&s25fs_block_erase_d8, 0xd8},
+};
+
+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);

To view, visit change 67354. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Ief25932120f940dea0ffe161a79219deecb2e8ab
Gerrit-Change-Number: 67354
Gerrit-PatchSet: 1
Gerrit-Owner: Aarya <aarya.chaumal@gmail.com>
Gerrit-MessageType: newchange