spi25.c: Add function to return opcode of passed erase fucntion pointer
There is a function, spi_get_erasefn_from_opcode, which returns the
erase function for given opcode. Add a function which does the opposite
i.e. returns the opcode for given erase function.
Change-Id: Ia3aefc9b9465efdd16b1678bb2ada9a23f00d316
Signed-off-by: Aarya Chaumal <aarya.chaumal@gmail.com>
Original-Reviewed-on: https://review.coreboot.org/c/flashrom/+/65355
Original-Reviewed-by: Nico Huber <nico.h@gmx.de>
Original-Reviewed-by: Thomas Heijligen <src@posteo.de>
Reviewed-on: https://review.coreboot.org/c/flashrom-stable/+/72538
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
diff --git a/include/chipdrivers.h b/include/chipdrivers.h
index 1637e51..22068ec 100644
--- a/include/chipdrivers.h
+++ b/include/chipdrivers.h
@@ -53,6 +53,7 @@
int spi_block_erase_db(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
int spi_block_erase_dc(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
erasefunc_t *spi_get_erasefn_from_opcode(uint8_t opcode);
+uint8_t spi_get_opcode_from_erasefn(erasefunc_t *func);
int spi_chip_write_1(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
int spi_nbyte_read(struct flashctx *flash, unsigned int addr, uint8_t *bytes, unsigned int len);
int spi_read_chunked(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len, unsigned int chunksize);
diff --git a/spi25.c b/spi25.c
index be612c6..17de949 100644
--- a/spi25.c
+++ b/spi25.c
@@ -633,6 +633,18 @@
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-stable@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);