Sergii Dmytruk has uploaded this change for review.

View Change

dummyflasher: make RO status of SPI_SR_WEL explicit

It was read-only before this commit because it's reset at the bottom of
emulate_spi_chip_response() for any command that's not WREN or EWSR.
However, the code looked like it could be set by WRSR.

This also adds a test which passes with and without this commit, but is
probably still useful for the peace of mind.

Change-Id: I5dce77e22a1f9cd29f40ec0881d2b1238a985e97
Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
---
M dummyflasher.c
A tests/dummyflasher.c
M tests/meson.build
M tests/tests.c
M tests/tests.h
5 files changed, 103 insertions(+), 1 deletion(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/24/60224/1
diff --git a/dummyflasher.c b/dummyflasher.c
index 2311576..5f393f9 100644
--- a/dummyflasher.c
+++ b/dummyflasher.c
@@ -317,7 +317,7 @@
break;
}
/* FIXME: add some reasonable simulation of the busy flag */
- data->emu_status = writearr[1] & ~SPI_SR_WIP;
+ data->emu_status = writearr[1] & ~(SPI_SR_WEL | SPI_SR_WIP);
msg_pdbg2("WRSR wrote 0x%02x.\n", data->emu_status);
break;
case JEDEC_READ:
diff --git a/tests/dummyflasher.c b/tests/dummyflasher.c
new file mode 100644
index 0000000..e7e9694
--- /dev/null
+++ b/tests/dummyflasher.c
@@ -0,0 +1,93 @@
+/*
+ * This file is part of the flashrom project.
+ *
+ * Copyright (C) 2021 3mdeb Embedded Systems Consulting
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <include/test.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "chipdrivers.h"
+#include "flash.h"
+#include "programmer.h"
+#include "spi.h"
+
+static void setup_chip(struct flashrom_flashctx *flashctx, struct flashchip *chip, const char *programmer_param)
+{
+ flashctx->chip = chip;
+
+ assert_int_equal(0, programmer_init(&programmer_dummy, programmer_param));
+
+ /* Assignment below normally happens while probing, but this test is not probing. */
+ flashctx->mst = &registered_masters[0];
+}
+
+static void teardown(void)
+{
+ assert_int_equal(0, programmer_shutdown());
+}
+
+/* Setup the struct for W25Q128.V, all values come from flashchips.c */
+static const struct flashchip chip_W25Q128_V = {
+ .vendor = "aklm&dummyflasher",
+ .total_size = 16 * 1024,
+ .tested = TEST_OK_PREW,
+ .read = spi_chip_read,
+ .write = spi_chip_write_256,
+ .unlock = spi_disable_blockprotect,
+ .page_size = 256,
+ .block_erasers =
+ {
+ {
+ .eraseblocks = { {4 * 1024, 4096} },
+ .block_erase = spi_block_erase_20,
+ }, {
+ .eraseblocks = { {32 * 1024, 512} },
+ .block_erase = spi_block_erase_52,
+ }, {
+ .eraseblocks = { {64 * 1024, 256} },
+ .block_erase = spi_block_erase_d8,
+ }, {
+ .eraseblocks = { {16 * 1024 * 1024, 1} },
+ .block_erase = spi_block_erase_60,
+ }, {
+ .eraseblocks = { {16 * 1024 * 1024, 1} },
+ .block_erase = spi_block_erase_c7,
+ }
+ },
+};
+
+void wel_is_ro_in_dummyflasher_test_success(void **state)
+{
+ (void) state; /* unused */
+
+ struct flashrom_flashctx flashctx = { 0 };
+ struct flashchip mock_chip = chip_W25Q128_V;
+ /*
+ * Dummyflasher is capable to emulate W25Q128.V, so we ask it to do this.
+ * Nothing to mock, dummy is taking care of this already.
+ */
+ char *param_dup = strdup("bus=spi,emulate=W25Q128FV");
+
+ setup_chip(&flashctx, &mock_chip, param_dup);
+
+ const uint8_t status = spi_read_status_register(&flashctx) & SPI_SR_WEL;
+ assert_int_equal(0, status & SPI_SR_WEL);
+
+ assert_int_equal(0, spi_write_status_register(&flashctx, status | SPI_SR_WEL));
+ assert_int_equal(0, spi_read_status_register(&flashctx) & SPI_SR_WEL);
+
+ teardown();
+
+ free(param_dup);
+}
diff --git a/tests/meson.build b/tests/meson.build
index 5bb6ac9..b2ff313 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -23,6 +23,7 @@
'init_shutdown.c',
'layout.c',
'chip.c',
+ 'dummyflasher.c',
]

mocks = [
diff --git a/tests/tests.c b/tests/tests.c
index a4a312e..164a770 100644
--- a/tests/tests.c
+++ b/tests/tests.c
@@ -379,5 +379,10 @@
};
ret |= cmocka_run_group_tests_name("chip.c tests", chip_tests, NULL, NULL);

+ const struct CMUnitTest dummyflasher_tests[] = {
+ cmocka_unit_test(wel_is_ro_in_dummyflasher_test_success),
+ };
+ ret |= cmocka_run_group_tests_name("dummyflasher.c tests", dummyflasher_tests, NULL, NULL);
+
return ret;
}
diff --git a/tests/tests.h b/tests/tests.h
index 16974af..a5f5380 100644
--- a/tests/tests.h
+++ b/tests/tests.h
@@ -65,4 +65,7 @@
void write_chip_test_success(void **state);
void write_chip_with_dummyflasher_test_success(void **state);

+/* dummyflasher.c */
+void wel_is_ro_in_dummyflasher_test_success(void **state);
+
#endif /* TESTS_H */

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

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I5dce77e22a1f9cd29f40ec0881d2b1238a985e97
Gerrit-Change-Number: 60224
Gerrit-PatchSet: 1
Gerrit-Owner: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
Gerrit-MessageType: newchange