aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorEdward O'Callaghan <quasisec@google.com>2022-11-23 22:36:53 +1100
committerEdward O'Callaghan <quasisec@chromium.org>2023-03-20 00:36:56 +0000
commit0c774d6b6a075f37f21ca9c3506141cb0d4ae34b (patch)
tree695a252de5954213b1ceeffecef302394f26c2e6 /include
parent028099dbfd92e62eb0c6227d1194ff714f55e67c (diff)
downloadflashrom-0c774d6b6a075f37f21ca9c3506141cb0d4ae34b.tar.gz
flashrom-0c774d6b6a075f37f21ca9c3506141cb0d4ae34b.tar.bz2
flashrom-0c774d6b6a075f37f21ca9c3506141cb0d4ae34b.zip
tree/: Convert unlock func ptr into enumerate values
Converting the blockprotect unlock function pointer within the flashchip struct into enum values allows for the flashchips db to be turn into pure, declarative data. A nice side-effect of this is to reduce link-time symbol space of chipdrivers and increase modularity of the spi25_statusreg.c and related implementations. BUG=none TEST=ninja test. Change-Id: Ie5c5db1b09d07e1a549990d6f5a622fae4c83233 Signed-off-by: Edward O'Callaghan <quasisec@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/69933 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Sam McNally <sammc@google.com> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Diffstat (limited to 'include')
-rw-r--r--include/chipdrivers.h23
-rw-r--r--include/flash.h57
2 files changed, 33 insertions, 47 deletions
diff --git a/include/chipdrivers.h b/include/chipdrivers.h
index c485aafa..bac77850 100644
--- a/include/chipdrivers.h
+++ b/include/chipdrivers.h
@@ -76,11 +76,6 @@ int spi_prettyprint_status_register_bp3_srwd(struct flashctx *flash);
int spi_prettyprint_status_register_bp4_srwd(struct flashctx *flash);
int spi_prettyprint_status_register_bp2_bpl(struct flashctx *flash);
int spi_prettyprint_status_register_bp2_tb_bpl(struct flashctx *flash);
-int spi_disable_blockprotect(struct flashctx *flash);
-int spi_disable_blockprotect_bp1_srwd(struct flashctx *flash);
-int spi_disable_blockprotect_bp2_srwd(struct flashctx *flash);
-int spi_disable_blockprotect_bp3_srwd(struct flashctx *flash);
-int spi_disable_blockprotect_bp4_srwd(struct flashctx *flash);
int spi_prettyprint_status_register_amic_a25l032(struct flashctx *flash);
int spi_prettyprint_status_register_at25df(struct flashctx *flash);
int spi_prettyprint_status_register_at25df_sec(struct flashctx *flash);
@@ -91,22 +86,12 @@ int spi_prettyprint_status_register_at25f4096(struct flashctx *flash);
int spi_prettyprint_status_register_at25fs010(struct flashctx *flash);
int spi_prettyprint_status_register_at25fs040(struct flashctx *flash);
int spi_prettyprint_status_register_at26df081a(struct flashctx *flash);
-int spi_disable_blockprotect_at2x_global_unprotect(struct flashctx *flash);
-int spi_disable_blockprotect_at2x_global_unprotect_sec(struct flashctx *flash);
-int spi_disable_blockprotect_at25f(struct flashctx *flash);
-int spi_disable_blockprotect_at25f512a(struct flashctx *flash);
-int spi_disable_blockprotect_at25f512b(struct flashctx *flash);
-int spi_disable_blockprotect_at25fs010(struct flashctx *flash);
-int spi_disable_blockprotect_at25fs040(struct flashctx *flash);
int spi_prettyprint_status_register_en25s_wp(struct flashctx *flash);
int spi_prettyprint_status_register_n25q(struct flashctx *flash);
-int spi_disable_blockprotect_n25q(struct flashctx *flash);
int spi_prettyprint_status_register_bp2_ep_srwd(struct flashctx *flash);
-int spi_disable_blockprotect_bp2_ep_srwd(struct flashctx *flash);
int spi_prettyprint_status_register_sst25(struct flashctx *flash);
int spi_prettyprint_status_register_sst25vf016(struct flashctx *flash);
int spi_prettyprint_status_register_sst25vf040b(struct flashctx *flash);
-int spi_disable_blockprotect_sst26_global_unprotect(struct flashctx *flash);
/* sfdp.c */
int probe_spi_sfdp(struct flashctx *flash);
@@ -136,8 +121,7 @@ int probe_82802ab(struct flashctx *flash);
int erase_block_82802ab(struct flashctx *flash, unsigned int page, unsigned int pagesize);
int write_82802ab(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
void print_status_82802ab(uint8_t status);
-int unlock_28f004s5(struct flashctx *flash);
-int unlock_lh28f008bjt(struct flashctx *flash);
+blockprotect_func_t *lookup_82802ab_blockprotect_func_ptr(const struct flashchip *const chip);
/* jedec.c */
uint8_t oddparity(uint8_t val);
@@ -151,10 +135,7 @@ int erase_sector_jedec(struct flashctx *flash, unsigned int page, unsigned int p
int erase_block_jedec(struct flashctx *flash, unsigned int page, unsigned int blocksize);
int erase_chip_block_jedec(struct flashctx *flash, unsigned int page, unsigned int blocksize);
-int unlock_regspace2_uniform_32k(struct flashctx *flash);
-int unlock_regspace2_uniform_64k(struct flashctx *flash);
-int unlock_regspace2_block_eraser_0(struct flashctx *flash);
-int unlock_regspace2_block_eraser_1(struct flashctx *flash);
+blockprotect_func_t *lookup_jedec_blockprotect_func_ptr(const struct flashchip *const chip);
int printlock_regspace2_uniform_64k(struct flashctx *flash);
int printlock_regspace2_block_eraser_0(struct flashctx *flash);
int printlock_regspace2_block_eraser_1(struct flashctx *flash);
diff --git a/include/flash.h b/include/flash.h
index 3db38d25..10c29753 100644
--- a/include/flash.h
+++ b/include/flash.h
@@ -322,31 +322,34 @@ enum block_erase_func {
TEST_ERASE_INJECTOR, /* special case must come last. */
};
-#define NO_BLOCKPROTECT_FUNC NULL
-#define SPI_DISABLE_BLOCKPROTECT spi_disable_blockprotect
-#define SPI_DISABLE_BLOCKPROTECT_BP2_EP_SRWD spi_disable_blockprotect_bp2_ep_srwd
-#define SPI_DISABLE_BLOCKPROTECT_BP1_SRWD spi_disable_blockprotect_bp1_srwd
-#define SPI_DISABLE_BLOCKPROTECT_BP2_SRWD spi_disable_blockprotect_bp2_srwd
-#define SPI_DISABLE_BLOCKPROTECT_BP3_SRWD spi_disable_blockprotect_bp3_srwd
-#define SPI_DISABLE_BLOCKPROTECT_BP4_SRWD spi_disable_blockprotect_bp4_srwd
-#define SPI_DISABLE_BLOCKPROTECT_AT45DB spi_disable_blockprotect_at45db
-#define SPI_DISABLE_BLOCKPROTECT_AT25F spi_disable_blockprotect_at25f
-#define SPI_DISABLE_BLOCKPROTECT_AT25FS010 spi_disable_blockprotect_at25fs010
-#define SPI_DISABLE_BLOCKPROTECT_AT25FS040 spi_disable_blockprotect_at25fs040
-#define SPI_DISABLE_BLOCKPROTECT_AT25F512A spi_disable_blockprotect_at25f512a
-#define SPI_DISABLE_BLOCKPROTECT_AT25F512B spi_disable_blockprotect_at25f512b
-#define SPI_DISABLE_BLOCKPROTECT_AT2X_GLOBAL_UNPROTECT spi_disable_blockprotect_at2x_global_unprotect
-#define SPI_DISABLE_BLOCKPROTECT_AT2X_GLOBAL_UNPROTECT_SEC spi_disable_blockprotect_at2x_global_unprotect_sec
-#define SPI_DISABLE_BLOCKPROTECT_SST26_GLOBAL_UNPROTECT spi_disable_blockprotect_sst26_global_unprotect
-#define SPI_DISABLE_BLOCKPROTECT_N25Q spi_disable_blockprotect_n25q
-#define UNLOCK_REGSPACE2_BLOCK_ERASER_0 unlock_regspace2_block_eraser_0
-#define UNLOCK_REGSPACE2_BLOCK_ERASER_1 unlock_regspace2_block_eraser_1
-#define UNLOCK_REGSPACE2_UNIFORM_32K unlock_regspace2_uniform_32k
-#define UNLOCK_REGSPACE2_UNIFORM_64K unlock_regspace2_uniform_64k
-#define UNLOCK_28F004S5 unlock_28f004s5
-#define UNLOCK_LH28F008BJT unlock_lh28f008bjt
-#define UNLOCK_SST_FWHUB unlock_sst_fwhub
-#define UNPROTECT_28SF040 unprotect_28sf040
+enum blockprotect_func {
+ NO_BLOCKPROTECT_FUNC = 0, /* 0 indicates no unlock function set. */
+ SPI_DISABLE_BLOCKPROTECT,
+ SPI_DISABLE_BLOCKPROTECT_BP2_EP_SRWD,
+ SPI_DISABLE_BLOCKPROTECT_BP1_SRWD,
+ SPI_DISABLE_BLOCKPROTECT_BP2_SRWD,
+ SPI_DISABLE_BLOCKPROTECT_BP3_SRWD,
+ SPI_DISABLE_BLOCKPROTECT_BP4_SRWD,
+ SPI_DISABLE_BLOCKPROTECT_AT45DB,
+ SPI_DISABLE_BLOCKPROTECT_AT25F,
+ SPI_DISABLE_BLOCKPROTECT_AT25FS010,
+ SPI_DISABLE_BLOCKPROTECT_AT25FS040,
+ SPI_DISABLE_BLOCKPROTECT_AT25F512A,
+ SPI_DISABLE_BLOCKPROTECT_AT25F512B,
+ SPI_DISABLE_BLOCKPROTECT_AT2X_GLOBAL_UNPROTECT,
+ SPI_DISABLE_BLOCKPROTECT_AT2X_GLOBAL_UNPROTECT_SEC,
+ SPI_DISABLE_BLOCKPROTECT_SST26_GLOBAL_UNPROTECT,
+ SPI_DISABLE_BLOCKPROTECT_N25Q,
+ UNLOCK_REGSPACE2_BLOCK_ERASER_0,
+ UNLOCK_REGSPACE2_BLOCK_ERASER_1,
+ UNLOCK_REGSPACE2_UNIFORM_32K,
+ UNLOCK_REGSPACE2_UNIFORM_64K,
+ UNLOCK_28F004S5,
+ UNLOCK_LH28F008BJT,
+ UNLOCK_SST_FWHUB,
+ UNPROTECT_28SF040,
+ TEST_UNLOCK_INJECTOR, /* special case must come last. */
+};
#define NO_PRINTLOCK_FUNC NULL
#define PRINTLOCK_AT49F printlock_at49f
@@ -458,7 +461,7 @@ struct flashchip {
} block_erasers[NUM_ERASEFUNCTIONS];
int (*printlock) (struct flashctx *flash);
- int (*unlock) (struct flashctx *flash);
+ enum blockprotect_func unlock;
enum write_func write;
enum read_func read;
struct voltage {
@@ -510,6 +513,8 @@ struct flashchip {
};
typedef int (*chip_restore_fn_cb_t)(struct flashctx *flash, void *data);
+typedef int (blockprotect_func_t)(struct flashctx *flash);
+blockprotect_func_t *lookup_blockprotect_func_ptr(const struct flashchip *const chip);
struct flashrom_flashctx {
struct flashchip *chip;