[Skiboot] [PATCH 2/2] libflash: Blocklevel sanity checking of erase block sizes

Cyril Bur cyril.bur at au1.ibm.com
Thu Jun 4 10:36:04 AEST 2015


Blocklevel has no way to check that backends init the erase_mask correctly
and as such must trust them.

When a user calls blocklevel_get_info(), blocklevel has a chance to inspect
the return value and warn if the values do not match. This check happens on
every call which should be fine as it is doubtful that
blocklevel_get_info() will be called much.

Signed-off-by: Cyril Bur <cyril.bur at au1.ibm.com>
---
 libflash/blocklevel.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/libflash/blocklevel.c b/libflash/blocklevel.c
index 320ffac..bc03b9b 100644
--- a/libflash/blocklevel.c
+++ b/libflash/blocklevel.c
@@ -54,8 +54,17 @@ int blocklevel_erase(struct blocklevel_device *bl, uint32_t pos, uint32_t len)
 int blocklevel_get_info(struct blocklevel_device *bl, const char **name, uint32_t *total_size,
 		uint32_t *erase_granule)
 {
+	int rc;
+
 	if (!bl || !bl->get_info)
 		return -1;
 
-	return bl->get_info(bl, name, total_size, erase_granule);
+	rc = bl->get_info(bl, name, total_size, erase_granule);
+
+	/* Check the validity of what we are being told */
+	if (erase_granule && *erase_granule != bl->erase_mask + 1)
+		fprintf(stderr, "blocklevel_get_info: WARNING: erase_granule (0x%08x) and erase_mask"
+				" (0x%08x) don't match\n", *erase_granule, bl->erase_mask + 1);
+
+	return rc;
 }
-- 
1.9.1



More information about the Skiboot mailing list