summaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--82802ab.c13
-rw-r--r--flashrom.c6
-rw-r--r--include/chipdrivers.h23
-rw-r--r--include/flash.h57
-rw-r--r--printlock.c19
-rw-r--r--spi25_statusreg.c75
-rw-r--r--tests/chip.c9
-rw-r--r--tests/chip_wp.c2
8 files changed, 130 insertions, 74 deletions
diff --git a/82802ab.c b/82802ab.c
index 90c9cf0d0..a440bd45b 100644
--- a/82802ab.c
+++ b/82802ab.c
@@ -142,7 +142,7 @@ int write_82802ab(struct flashctx *flash, const uint8_t *src, unsigned int start
return 0;
}
-int unlock_28f004s5(struct flashctx *flash)
+static int unlock_28f004s5(struct flashctx *flash)
{
chipaddr bios = flash->virtual_memory;
uint8_t mcfg, bcfg;
@@ -195,7 +195,7 @@ int unlock_28f004s5(struct flashctx *flash)
return 0;
}
-int unlock_lh28f008bjt(struct flashctx *flash)
+static int unlock_lh28f008bjt(struct flashctx *flash)
{
chipaddr bios = flash->virtual_memory;
uint8_t mcfg, bcfg;
@@ -249,3 +249,12 @@ int unlock_lh28f008bjt(struct flashctx *flash)
return 0;
}
+
+blockprotect_func_t *lookup_82802ab_blockprotect_func_ptr(const struct flashchip *const chip)
+{
+ switch (chip->unlock) {
+ case UNLOCK_28F004S5: return unlock_28f004s5;
+ case UNLOCK_LH28F008BJT: return unlock_lh28f008bjt;
+ default: return NULL; /* fallthough */
+ };
+}
diff --git a/flashrom.c b/flashrom.c
index 3cf67f1d0..c5b795c19 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -2080,9 +2080,9 @@ int prepare_flash_access(struct flashctx *const flash,
if (ret)
msg_cerr("Failed to unlock flash status reg with wp support.\n");
}
- if (ret && flash->chip->unlock) {
- flash->chip->unlock(flash);
- }
+ blockprotect_func_t *bp_func = lookup_blockprotect_func_ptr(flash->chip);
+ if (ret && bp_func)
+ bp_func(flash);
flash->address_high_byte = -1;
flash->in_4ba_mode = false;
diff --git a/include/chipdrivers.h b/include/chipdrivers.h
index c485aafa0..bac778509 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 3db38d256..10c297530 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;
diff --git a/printlock.c b/printlock.c
index d05251e98..f6eea7f46 100644
--- a/printlock.c
+++ b/printlock.c
@@ -186,17 +186,17 @@ static int unlock_regspace2_uniform(struct flashctx *flash, unsigned long block_
return regspace2_walk_unlockblocks(flash, blocks, &unlock_regspace2_block_generic);
}
-int unlock_regspace2_uniform_64k(struct flashctx *flash)
+static int unlock_regspace2_uniform_64k(struct flashctx *flash)
{
return unlock_regspace2_uniform(flash, 64 * 1024);
}
-int unlock_regspace2_uniform_32k(struct flashctx *flash)
+static int unlock_regspace2_uniform_32k(struct flashctx *flash)
{
return unlock_regspace2_uniform(flash, 32 * 1024);
}
-int unlock_regspace2_block_eraser_0(struct flashctx *flash)
+static int unlock_regspace2_block_eraser_0(struct flashctx *flash)
{
// FIXME: this depends on the eraseblocks not to be filled up completely (i.e. to be null-terminated).
const struct unlockblock *unlockblocks =
@@ -204,10 +204,21 @@ int unlock_regspace2_block_eraser_0(struct flashctx *flash)
return regspace2_walk_unlockblocks(flash, unlockblocks, &unlock_regspace2_block_generic);
}
-int unlock_regspace2_block_eraser_1(struct flashctx *flash)
+static int unlock_regspace2_block_eraser_1(struct flashctx *flash)
{
// FIXME: this depends on the eraseblocks not to be filled up completely (i.e. to be null-terminated).
const struct unlockblock *unlockblocks =
(const struct unlockblock *)flash->chip->block_erasers[1].eraseblocks;
return regspace2_walk_unlockblocks(flash, unlockblocks, &unlock_regspace2_block_generic);
}
+
+blockprotect_func_t *lookup_jedec_blockprotect_func_ptr(const struct flashchip *const chip)
+{
+ switch (chip->unlock) {
+ case UNLOCK_REGSPACE2_BLOCK_ERASER_0: return unlock_regspace2_block_eraser_0;
+ case UNLOCK_REGSPACE2_BLOCK_ERASER_1: return unlock_regspace2_block_eraser_1;
+ case UNLOCK_REGSPACE2_UNIFORM_32K: return unlock_regspace2_uniform_32k;
+ case UNLOCK_REGSPACE2_UNIFORM_64K: return unlock_regspace2_uniform_64k;
+ default: return NULL; /* fallthough */
+ };
+}
diff --git a/spi25_statusreg.c b/spi25_statusreg.c
index d452416c7..21a1a1519 100644
--- a/spi25_statusreg.c
+++ b/spi25_statusreg.c
@@ -363,12 +363,12 @@ static int spi_disable_blockprotect_generic(struct flashctx *flash, uint8_t bp_m
}
/* A common block protection disable that tries to unset the status register bits masked by 0x3C. */
-int spi_disable_blockprotect(struct flashctx *flash)
+static int spi_disable_blockprotect(struct flashctx *flash)
{
return spi_disable_blockprotect_generic(flash, 0x3C, 0, 0, 0xFF);
}
-int spi_disable_blockprotect_sst26_global_unprotect(struct flashctx *flash)
+static int spi_disable_blockprotect_sst26_global_unprotect(struct flashctx *flash)
{
int result = spi_write_enable(flash);
if (result)
@@ -383,7 +383,7 @@ int spi_disable_blockprotect_sst26_global_unprotect(struct flashctx *flash)
/* A common block protection disable that tries to unset the status register bits masked by 0x0C (BP0-1) and
* protected/locked by bit #7. Useful when bits 4-5 may be non-0). */
-int spi_disable_blockprotect_bp1_srwd(struct flashctx *flash)
+static int spi_disable_blockprotect_bp1_srwd(struct flashctx *flash)
{
return spi_disable_blockprotect_generic(flash, 0x0C, 1 << 7, 0, 0xFF);
}
@@ -391,21 +391,21 @@ int spi_disable_blockprotect_bp1_srwd(struct flashctx *flash)
/* A common block protection disable that tries to unset the status register bits masked by 0x1C (BP0-2) and
* protected/locked by bit #7. Useful when bit #5 is neither a protection bit nor reserved (and hence possibly
* non-0). */
-int spi_disable_blockprotect_bp2_srwd(struct flashctx *flash)
+static int spi_disable_blockprotect_bp2_srwd(struct flashctx *flash)
{
return spi_disable_blockprotect_generic(flash, 0x1C, 1 << 7, 0, 0xFF);
}
/* A common block protection disable that tries to unset the status register bits masked by 0x3C (BP0-3) and
* protected/locked by bit #7. */
-int spi_disable_blockprotect_bp3_srwd(struct flashctx *flash)
+static int spi_disable_blockprotect_bp3_srwd(struct flashctx *flash)
{
return spi_disable_blockprotect_generic(flash, 0x3C, 1 << 7, 0, 0xFF);
}
/* A common block protection disable that tries to unset the status register bits masked by 0x7C (BP0-4) and
* protected/locked by bit #7. */
-int spi_disable_blockprotect_bp4_srwd(struct flashctx *flash)
+static int spi_disable_blockprotect_bp4_srwd(struct flashctx *flash)
{
return spi_disable_blockprotect_generic(flash, 0x7C, 1 << 7, 0, 0xFF);
}
@@ -825,39 +825,39 @@ int spi_prettyprint_status_register_at26df081a(struct flashctx *flash)
* sectors at once by writing 0 not only the protection bits (2 and 3) but also completely unrelated bits (4 and
* 5) which normally are not touched.
* Affected are all known Atmel chips matched by AT2[56]D[FLQ]..1A? but the AT26DF041. */
-int spi_disable_blockprotect_at2x_global_unprotect(struct flashctx *flash)
+static int spi_disable_blockprotect_at2x_global_unprotect(struct flashctx *flash)
{
return spi_disable_blockprotect_generic(flash, 0x0C, 1 << 7, 1 << 4, 0x00);
}
-int spi_disable_blockprotect_at2x_global_unprotect_sec(struct flashctx *flash)
+static int spi_disable_blockprotect_at2x_global_unprotect_sec(struct flashctx *flash)
{
/* FIXME: We should check the security lockdown. */
msg_cinfo("Ignoring security lockdown (if present)\n");
return spi_disable_blockprotect_at2x_global_unprotect(flash);
}
-int spi_disable_blockprotect_at25f(struct flashctx *flash)
+static int spi_disable_blockprotect_at25f(struct flashctx *flash)
{
return spi_disable_blockprotect_generic(flash, 0x0C, 1 << 7, 0, 0xFF);
}
-int spi_disable_blockprotect_at25f512a(struct flashctx *flash)
+static int spi_disable_blockprotect_at25f512a(struct flashctx *flash)
{
return spi_disable_blockprotect_generic(flash, 0x04, 1 << 7, 0, 0xFF);
}
-int spi_disable_blockprotect_at25f512b(struct flashctx *flash)
+static int spi_disable_blockprotect_at25f512b(struct flashctx *flash)
{
return spi_disable_blockprotect_generic(flash, 0x04, 1 << 7, 1 << 4, 0xFF);
}
-int spi_disable_blockprotect_at25fs010(struct flashctx *flash)
+static int spi_disable_blockprotect_at25fs010(struct flashctx *flash)
{
return spi_disable_blockprotect_generic(flash, 0x6C, 1 << 7, 0, 0xFF);
}
-int spi_disable_blockprotect_at25fs040(struct flashctx *flash)
+static int spi_disable_blockprotect_at25fs040(struct flashctx *flash)
{
return spi_disable_blockprotect_generic(flash, 0x7C, 1 << 7, 0, 0xFF);
}
@@ -881,7 +881,7 @@ int spi_prettyprint_status_register_en25s_wp(struct flashctx *flash)
/* === Intel/Numonyx/Micron - Spansion === */
-int spi_disable_blockprotect_n25q(struct flashctx *flash)
+static int spi_disable_blockprotect_n25q(struct flashctx *flash)
{
return spi_disable_blockprotect_generic(flash, 0x5C, 1 << 7, 0, 0xFF);
}
@@ -908,11 +908,56 @@ int spi_prettyprint_status_register_n25q(struct flashctx *flash)
/* Used by Intel/Numonyx S33 and Spansion S25FL-S chips */
/* TODO: Clear P_FAIL and E_FAIL with Clear SR Fail Flags Command (30h) here? */
-int spi_disable_blockprotect_bp2_ep_srwd(struct flashctx *flash)
+static int spi_disable_blockprotect_bp2_ep_srwd(struct flashctx *flash)
{
return spi_disable_blockprotect_bp2_srwd(flash);
}
+/* special unit-test hook */
+blockprotect_func_t *g_test_unlock_injector;
+
+blockprotect_func_t *lookup_blockprotect_func_ptr(const struct flashchip *const chip)
+{
+ switch (chip->unlock) {
+ case SPI_DISABLE_BLOCKPROTECT: return spi_disable_blockprotect;
+ case SPI_DISABLE_BLOCKPROTECT_BP2_EP_SRWD: return spi_disable_blockprotect_bp2_ep_srwd;
+ case SPI_DISABLE_BLOCKPROTECT_BP1_SRWD: return spi_disable_blockprotect_bp1_srwd;
+ case SPI_DISABLE_BLOCKPROTECT_BP2_SRWD: return spi_disable_blockprotect_bp2_srwd;
+ case SPI_DISABLE_BLOCKPROTECT_BP3_SRWD: return spi_disable_blockprotect_bp3_srwd;
+ case SPI_DISABLE_BLOCKPROTECT_BP4_SRWD: return spi_disable_blockprotect_bp4_srwd;
+ case SPI_DISABLE_BLOCKPROTECT_AT45DB: return spi_disable_blockprotect_at45db; /* at45db.c */
+ case SPI_DISABLE_BLOCKPROTECT_AT25F: return spi_disable_blockprotect_at25f;
+ case SPI_DISABLE_BLOCKPROTECT_AT25FS010: return spi_disable_blockprotect_at25fs010;
+ case SPI_DISABLE_BLOCKPROTECT_AT25FS040: return spi_disable_blockprotect_at25fs040;
+ case SPI_DISABLE_BLOCKPROTECT_AT25F512A: return spi_disable_blockprotect_at25f512a;
+ case SPI_DISABLE_BLOCKPROTECT_AT25F512B: return spi_disable_blockprotect_at25f512b;
+ case SPI_DISABLE_BLOCKPROTECT_AT2X_GLOBAL_UNPROTECT: return spi_disable_blockprotect_at2x_global_unprotect;
+ case SPI_DISABLE_BLOCKPROTECT_AT2X_GLOBAL_UNPROTECT_SEC: return spi_disable_blockprotect_at2x_global_unprotect_sec;
+ case SPI_DISABLE_BLOCKPROTECT_SST26_GLOBAL_UNPROTECT: return spi_disable_blockprotect_sst26_global_unprotect;
+ case SPI_DISABLE_BLOCKPROTECT_N25Q: return spi_disable_blockprotect_n25q;
+ /* fallthough to lookup_jedec_blockprotect_func_ptr() */
+ case UNLOCK_REGSPACE2_BLOCK_ERASER_0:
+ case UNLOCK_REGSPACE2_BLOCK_ERASER_1:
+ case UNLOCK_REGSPACE2_UNIFORM_32K:
+ case UNLOCK_REGSPACE2_UNIFORM_64K:
+ return lookup_jedec_blockprotect_func_ptr(chip);
+ /* fallthough to lookup_82802ab_blockprotect_func_ptr() */
+ case UNLOCK_28F004S5:
+ case UNLOCK_LH28F008BJT:
+ return lookup_82802ab_blockprotect_func_ptr(chip);
+ case UNLOCK_SST_FWHUB: return unlock_sst_fwhub; /* sst_fwhub.c */
+ case UNPROTECT_28SF040: return unprotect_28sf040; /* sst28sf040.c */
+ case TEST_UNLOCK_INJECTOR: return g_test_unlock_injector;
+ /* default: non-total function, 0 indicates no unlock function set.
+ * We explicitly do not want a default catch-all case in the switch
+ * to ensure unhandled enum's are compiler warnings.
+ */
+ case NO_BLOCKPROTECT_FUNC: return NULL;
+ };
+
+ return NULL;
+}
+
/* Used by Intel/Numonyx S33 and Spansion S25FL-S chips */
int spi_prettyprint_status_register_bp2_ep_srwd(struct flashctx *flash)
{
diff --git a/tests/chip.c b/tests/chip.c
index ad0d7701d..6a17d8627 100644
--- a/tests/chip.c
+++ b/tests/chip.c
@@ -149,6 +149,7 @@ static void teardown(struct flashrom_layout **layout)
extern write_func_t *g_test_write_injector;
extern read_func_t *g_test_read_injector;
extern erasefunc_t *g_test_erase_injector;
+extern blockprotect_func_t *g_test_unlock_injector;
static const struct flashchip chip_8MiB = {
.vendor = "aklm",
@@ -156,7 +157,7 @@ static const struct flashchip chip_8MiB = {
.tested = TEST_OK_PREW,
.read = TEST_READ_INJECTOR,
.write = TEST_WRITE_INJECTOR,
- .unlock = unlock_chip,
+ .unlock = TEST_UNLOCK_INJECTOR,
.block_erasers =
{{
/* All blocks within total size of the chip. */
@@ -172,7 +173,7 @@ static const struct flashchip chip_W25Q128_V = {
.tested = TEST_OK_PREW,
.read = SPI_CHIP_READ,
.write = SPI_CHIP_WRITE256,
- .unlock = spi_disable_blockprotect,
+ .unlock = SPI_DISABLE_BLOCKPROTECT,
.page_size = 256,
.block_erasers =
{
@@ -210,6 +211,7 @@ void erase_chip_test_success(void **state)
g_test_write_injector = write_chip;
g_test_read_injector = read_chip;
g_test_erase_injector = block_erase_chip;
+ g_test_unlock_injector = unlock_chip;
struct flashrom_flashctx flashctx = { 0 };
struct flashrom_layout *layout;
struct flashchip mock_chip = chip_8MiB;
@@ -269,6 +271,7 @@ void read_chip_test_success(void **state)
g_test_write_injector = write_chip;
g_test_read_injector = read_chip;
g_test_erase_injector = block_erase_chip;
+ g_test_unlock_injector = unlock_chip;
struct flashrom_flashctx flashctx = { 0 };
struct flashrom_layout *layout;
struct flashchip mock_chip = chip_8MiB;
@@ -344,6 +347,7 @@ void write_chip_test_success(void **state)
g_test_write_injector = write_chip;
g_test_read_injector = read_chip;
g_test_erase_injector = block_erase_chip;
+ g_test_unlock_injector = unlock_chip;
struct flashrom_flashctx flashctx = { 0 };
struct flashrom_layout *layout;
struct flashchip mock_chip = chip_8MiB;
@@ -535,6 +539,7 @@ void verify_chip_test_success(void **state)
g_test_write_injector = write_chip;
g_test_read_injector = read_chip;
g_test_erase_injector = block_erase_chip;
+ g_test_unlock_injector = unlock_chip;
struct flashrom_flashctx flashctx = { 0 };
struct flashrom_layout *layout;
struct flashchip mock_chip = chip_8MiB;
diff --git a/tests/chip_wp.c b/tests/chip_wp.c
index 9607a96ed..2686f4463 100644
--- a/tests/chip_wp.c
+++ b/tests/chip_wp.c
@@ -67,7 +67,7 @@ static const struct flashchip chip_W25Q128_V = {
.tested = TEST_OK_PREW,
.read = SPI_CHIP_READ,
.write = SPI_CHIP_WRITE256,
- .unlock = spi_disable_blockprotect,
+ .unlock = SPI_DISABLE_BLOCKPROTECT,
.feature_bits = FEATURE_WRSR_WREN | FEATURE_OTP | FEATURE_WRSR_EXT2 | FEATURE_WRSR2 | FEATURE_WRSR3,
.block_erasers =
{