Nikolai Artemiev has uploaded this change for review.
WIP: Allow opaque programmers to provide status register access
This framework allows opaque programmers to expose read/write access to
the status register and a function for checking if accesses to a given
ranges are valid. Currently used by ichspi in cros flashrom.
Change-Id: I11a03c84363ec68a8edcbb9b10c7ca115e222fe0
Signed-off-by: Nikolai Artemiev <nartemiev@google.com>
---
M chipdrivers.h
M flash.h
M flashchips.c
M opaque.c
M programmer.h
5 files changed, 32 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/48/53948/1
diff --git a/chipdrivers.h b/chipdrivers.h
index e1d6aa9..ccab841 100644
--- a/chipdrivers.h
+++ b/chipdrivers.h
@@ -113,6 +113,9 @@
int read_opaque(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
int write_opaque(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
int erase_opaque(struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
+uint8_t read_status_opaque(const struct flashctx *flash);
+int write_status_opaque(const struct flashctx *flash, int status);
+int check_access_opaque(const struct flashctx *flash, unsigned int start, unsigned int len, int read);
/* at45db.c */
int probe_spi_at45db(struct flashctx *flash);
diff --git a/flash.h b/flash.h
index dd8e156..99f3cd1 100644
--- a/flash.h
+++ b/flash.h
@@ -238,6 +238,7 @@
int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
uint8_t (*read_status) (const struct flashctx *flash);
int (*write_status) (const struct flashctx *flash, int status);
+ int (*check_access) (const struct flashctx *flash, unsigned int start, unsigned int len, int read);
struct voltage {
uint16_t min;
uint16_t max;
diff --git a/flashchips.c b/flashchips.c
index 6482f67..fa5da48 100644
--- a/flashchips.c
+++ b/flashchips.c
@@ -19424,6 +19424,10 @@
},
.write = write_opaque,
.read = read_opaque,
+ .read_status = read_status_opaque,
+ .write_status = write_status_opaque,
+ .check_access = check_access_opaque,
+ .unlock = &spi_disable_blockprotect,
},
{
diff --git a/opaque.c b/opaque.c
index e3103c8..7a19512 100644
--- a/opaque.c
+++ b/opaque.c
@@ -46,6 +46,27 @@
return flash->mst->opaque.erase(flash, blockaddr, blocklen);
}
+uint8_t read_status_opaque(const struct flashctx *flash)
+{
+ if (flash->mst->opaque.read_status)
+ return flash->mst->opaque.read_status(flash);
+ return 1;
+}
+
+int write_status_opaque(const struct flashctx *flash, int status)
+{
+ if (flash->mst->opaque.write_status)
+ return flash->mst->opaque.write_status(flash, status);
+ return 1;
+}
+
+int check_access_opaque(const struct flashctx *flash, unsigned int start, unsigned int len, int rw)
+{
+ if (flash->mst->opaque.check_access)
+ return flash->mst->opaque.check_access(flash, start, len, rw);
+ return 0;
+}
+
int register_opaque_master(const struct opaque_master *mst)
{
struct registered_master rmst = {0};
diff --git a/programmer.h b/programmer.h
index 675a259..2e56766 100644
--- a/programmer.h
+++ b/programmer.h
@@ -722,6 +722,9 @@
int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
int (*write) (struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
int (*erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
+ uint8_t (*read_status) (const struct flashctx *flash);
+ int (*write_status) (const struct flashctx *flash, int status);
+ int (*check_access) (const struct flashctx *flash, unsigned int start, unsigned int len, int read);
void *data;
};
int register_opaque_master(const struct opaque_master *mst);
To view, visit change 53948. To unsubscribe, or for help writing mail filters, visit settings.