[coreboot-gerrit] Change in coreboot[master]: spi/flash: Add interface to check software write protection
Patrick Rudolph (Code Review)
gerrit at coreboot.org
Thu Aug 9 18:32:56 CEST 2018
Patrick Rudolph has uploaded this change for review. ( https://review.coreboot.org/27987
Change subject: spi/flash: Add interface to check software write protection
......................................................................
spi/flash: Add interface to check software write protection
* Add a common function to check if the region is write protected by
** SPI controller's "flash protected regions"
** flash status register protection bits
The state of a possible hardware write protection doesn't matter here.
Change-Id: I1a2b75f5c0f183a74d42180dfc0c12d50b9780bb
Signed-off-by: Patrick Rudolph <patrick.rudolph at 9elements.com>
---
M src/drivers/spi/spi_flash.c
M src/include/spi-generic.h
M src/include/spi_flash.h
3 files changed, 50 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/87/27987/1
diff --git a/src/drivers/spi/spi_flash.c b/src/drivers/spi/spi_flash.c
index 87049460..0e8ebd9 100644
--- a/src/drivers/spi/spi_flash.c
+++ b/src/drivers/spi/spi_flash.c
@@ -538,6 +538,36 @@
}
}
+int spi_flash_ctrlr_is_region_protected(const struct spi_flash *flash,
+ const struct region *region)
+{
+ const struct spi_ctrlr *ctrlr;
+ const struct spi_flash_ops *ops;
+ struct region flash_region = { 0 };
+
+ if (!flash)
+ return -1;
+
+ flash_region.size = flash->size;
+
+ if (!region_is_subregion(&flash_region, region))
+ return -1;
+
+ ctrlr = flash->spi.ctrlr;
+ ops = flash->ops;
+
+ /* Check controller's "Protected Regions" */
+ if (ctrlr && ctrlr->is_flash_write_protected)
+ return ctrlr->is_flash_write_protected(flash, region);
+
+ /*
+ * Try to directly check the status register lock-bits in flash.
+ */
+ if (ops && ops->get_write_protection)
+ return ops->get_write_protection(flash, region) > 0;
+
+ return -1;
+}
int spi_flash_ctrlr_protect_region(const struct spi_flash *flash,
const struct region *region)
diff --git a/src/include/spi-generic.h b/src/include/spi-generic.h
index e3e7f82..c95b4ae 100644
--- a/src/include/spi-generic.h
+++ b/src/include/spi-generic.h
@@ -145,6 +145,8 @@
struct spi_flash *flash);
int (*flash_protect)(const struct spi_flash *flash,
const struct region *region);
+ int (*is_flash_write_protected)(const struct spi_flash *flash,
+ const struct region *region);
};
/*-----------------------------------------------------------------------
diff --git a/src/include/spi_flash.h b/src/include/spi_flash.h
index f33b59a..b8bb7bd 100644
--- a/src/include/spi_flash.h
+++ b/src/include/spi_flash.h
@@ -198,6 +198,24 @@
const struct region *region);
/*
+ * Check if provided region is write protected.
+ * It first tries to use its controller, if available.
+ * If the controller doesn't support flash protections, try to query the lock
+ * bits in the status register of the flash device (requires flash vendor
+ * specific support).
+ *
+ * @param flash The flash device to operate on
+ * @param region The region to lock
+ * @Return < 0 on error, 0 if region isn't fully protected else 1 on success.
+ *
+ * Possible errors:
+ * * Invalid region specified
+ * * Requested region layout can't be directly applied on flash
+ * * SPI bus error
+ */
+int spi_flash_ctrlr_is_region_protected(const struct spi_flash *flash,
+ const struct region *region);
+/*
* This function is provided to support spi flash command-response transactions.
* Only 2 vectors are supported and the 'func' is called with appropriate
* write and read buffers together. This can be used for chipsets that
--
To view, visit https://review.coreboot.org/27987
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1a2b75f5c0f183a74d42180dfc0c12d50b9780bb
Gerrit-Change-Number: 27987
Gerrit-PatchSet: 1
Gerrit-Owner: Patrick Rudolph <patrick.rudolph at 9elements.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20180809/052e5822/attachment.html>
More information about the coreboot-gerrit
mailing list