Nikolai Artemiev has uploaded this change for review.
[RFC] writeprotect.h: add structure to represent chip wp state
Adds a wp_chip_state structure to capture the complete state of a chip's
wp-related status bits and serve as an intermediate representation
throughout writeprotect code.
Also adds a function that fills out the wp_chip_state strucutre by
reading the chip's registers and intrepreting them using the status
register bit map.
BUG=b:195381327,b:153800563
TEST=writeprotect commands
BRANCH=none
Change-Id: I17dee630248ce7b51e624a6e46d7097d5d0de809
Signed-off-by: Nikolai Artemiev <nartemiev@google.com>
---
M writeprotect.c
M writeprotect.h
2 files changed, 67 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/78/58478/1
diff --git a/writeprotect.c b/writeprotect.c
index 1d907f6..24239db 100644
--- a/writeprotect.c
+++ b/writeprotect.c
@@ -23,6 +23,54 @@
#include "chipdrivers.h"
#include "writeprotect.h"
+
+static int read_reg_bit(
+ const struct flashctx *flash,
+ const struct reg_bit_info bit,
+ uint8_t *value,
+ bool *present)
+{
+ *value = 0;
+ *present = bit.reg != INVALID_REG;
+
+ if (*present) {
+ if (spi_read_register(flash, bit.reg, value))
+ return 1;
+ *value = (*value >> bit.bit_index) & 1;
+ }
+
+ return 0;
+}
+
+static int read_wp_chip_state(struct flashctx *flash, struct wp_chip_state *wpst)
+{
+ const struct reg_bit_map *bits = &flash->chip->reg_bits;
+ bool tmp;
+
+ *wpst = (struct wp_chip_state) {0};
+
+ int ret = 0;
+ ret |= read_reg_bit(flash, bits->tb, &wpst->tb, &wpst->tb_bit_present);
+ ret |= read_reg_bit(flash, bits->sec, &wpst->sec, &wpst->sec_bit_present);
+ ret |= read_reg_bit(flash, bits->cmp, &wpst->cmp, &wpst->cmp_bit_present);
+
+ for(size_t i = 0; bits->bp[i].reg != INVALID_REG; i++) {
+ ret |= read_reg_bit(flash, bits->bp[i], &wpst->bp[i], &tmp);
+ wpst->bp_bit_count = i + 1;
+ }
+
+ for(size_t i = 0; bits->srp[i].reg != INVALID_REG; i++) {
+ ret |= read_reg_bit(flash, bits->srp[i], &wpst->srp[i], &tmp);
+ wpst->srp_bit_count = i + 1;
+ }
+
+ if (ret)
+ msg_gerr("Reading write protection configuration failed!\n");
+
+ return ret;
+}
+void *suppress_unused_warning_for_read_wp_chip_state = read_wp_chip_state;
+
bool wp_supported(struct flashctx *flash)
{
/* TODO */
diff --git a/writeprotect.h b/writeprotect.h
index db7f3aa..21d1484 100644
--- a/writeprotect.h
+++ b/writeprotect.h
@@ -42,4 +42,23 @@
int wp_list_ranges(struct flashctx *flash);
int wp_print_status(struct flashctx *flash);
+/* Complete description of a chip's wp-related state */
+struct wp_chip_state {
+ size_t srp_bit_count;
+ uint8_t srp[MAX_SRP_BITS];
+
+ size_t bp_bit_count;
+ uint8_t bp[MAX_BP_BITS];
+
+ bool tb_bit_present;
+ uint8_t tb;
+
+ bool sec_bit_present;
+ uint8_t sec;
+
+ bool cmp_bit_present;
+ uint8_t cmp;
+
+ /* TODO: WPS, sector registers */
+};
#endif
To view, visit change 58478. To unsubscribe, or for help writing mail filters, visit settings.