summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorNikolai Artemiev <nartemiev@google.com>2023-05-03 11:05:07 +1000
committerAnastasia Klimchuk <aklm@chromium.org>2023-05-09 07:43:23 +0000
commit00c9fac2a66ab2aafc6949166dfc733fd0b747ea (patch)
tree0093e9304ae7d4c657fed35cc47ca7a8ba313921 /tests
parentfc6a09ba1fe76472a5b5959008cd699eeccd25d5 (diff)
downloadflashrom-00c9fac2a66ab2aafc6949166dfc733fd0b747ea.tar.gz
flashrom-00c9fac2a66ab2aafc6949166dfc733fd0b747ea.tar.bz2
flashrom-00c9fac2a66ab2aafc6949166dfc733fd0b747ea.zip
flashrom: Use WP-based unlocking on opaque masters
Flashrom only tries to use WP-based unlocking if it detects that WP operations are supported. However WP support was detected in a way that ignored WP operations provided by opaque masters. This stopped flashrom from automatically unlocking with some opaque masters, particularly linux_mtd. This commit also deletes part of a test that required the chip unlock function to be called before read/write/erase operations because WP unlocking is now used instead of chip unlocking. BUG=b:280111380 BRANCH=none TEST=Checked flashrom automatically unlocked flash on strongbad (MTD) Change-Id: I1774ad64d82ae47cd085df6045e17e283855c01f Signed-off-by: Nikolai Artemiev <nartemiev@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/74930 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org> Reviewed-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/chip.c37
1 files changed, 1 insertions, 36 deletions
diff --git a/tests/chip.c b/tests/chip.c
index 6a17d8627..96be7b108 100644
--- a/tests/chip.c
+++ b/tests/chip.c
@@ -20,7 +20,7 @@
* Example of test: erase_chip_test_success.
*
* 2) Mock chip operations backed by `dummyflasher` emulation.
- * Dummyflasher controls chip state and emulates read/write/unlock/erase.
+ * Dummyflasher controls chip state and emulates read/write/erase.
* `g_chip_state` is NOT used for this type of tests.
* Example of test: erase_chip_with_dummyflasher_test_success.
*/
@@ -40,20 +40,14 @@
#define MOCK_CHIP_CONTENT 0xCC /* 0x00 is a zeroed heap and 0xFF is an erased chip. */
static struct {
- unsigned int unlock_calls; /* how many times unlock function was called */
uint8_t buf[MOCK_CHIP_SIZE]; /* buffer of total size of chip, to emulate a chip */
} g_chip_state = {
- .unlock_calls = 0,
.buf = { 0 },
};
static int read_chip(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len)
{
printf("Read chip called with start=0x%x, len=0x%x\n", start, len);
- if (!g_chip_state.unlock_calls) {
- printf("Error while reading chip: unlock was not called.\n");
- return 1;
- }
assert_in_range(start + len, 0, MOCK_CHIP_SIZE);
@@ -64,10 +58,6 @@ static int read_chip(struct flashctx *flash, uint8_t *buf, unsigned int start, u
static int write_chip(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len)
{
printf("Write chip called with start=0x%x, len=0x%x\n", start, len);
- if (!g_chip_state.unlock_calls) {
- printf("Error while writing chip: unlock was not called.\n");
- return 1;
- }
assert_in_range(start + len, 0, MOCK_CHIP_SIZE);
@@ -75,26 +65,9 @@ static int write_chip(struct flashctx *flash, const uint8_t *buf, unsigned int s
return 0;
}
-static int unlock_chip(struct flashctx *flash)
-{
- printf("Unlock chip called\n");
- g_chip_state.unlock_calls++;
-
- if (g_chip_state.unlock_calls > 1) {
- printf("Error: Unlock called twice\n");
- return -1;
- }
-
- return 0;
-}
-
static int block_erase_chip(struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen)
{
printf("Block erase called with blockaddr=0x%x, blocklen=0x%x\n", blockaddr, blocklen);
- if (!g_chip_state.unlock_calls) {
- printf("Error while erasing chip: unlock was not called.\n");
- return 1;
- }
assert_in_range(blockaddr + blocklen, 0, MOCK_CHIP_SIZE);
@@ -109,7 +82,6 @@ static void setup_chip(struct flashrom_flashctx *flashctx, struct flashrom_layou
flashctx->chip = chip;
- g_chip_state.unlock_calls = 0;
memset(g_chip_state.buf, MOCK_CHIP_CONTENT, sizeof(g_chip_state.buf));
printf("Creating layout with one included region... ");
@@ -149,7 +121,6 @@ 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",
@@ -157,7 +128,6 @@ static const struct flashchip chip_8MiB = {
.tested = TEST_OK_PREW,
.read = TEST_READ_INJECTOR,
.write = TEST_WRITE_INJECTOR,
- .unlock = TEST_UNLOCK_INJECTOR,
.block_erasers =
{{
/* All blocks within total size of the chip. */
@@ -173,7 +143,6 @@ static const struct flashchip chip_W25Q128_V = {
.tested = TEST_OK_PREW,
.read = SPI_CHIP_READ,
.write = SPI_CHIP_WRITE256,
- .unlock = SPI_DISABLE_BLOCKPROTECT,
.page_size = 256,
.block_erasers =
{
@@ -211,7 +180,6 @@ 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;
@@ -271,7 +239,6 @@ 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;
@@ -347,7 +314,6 @@ 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;
@@ -539,7 +505,6 @@ 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;