summaryrefslogtreecommitdiffstats
path: root/libflash/blocklevel.c
diff options
context:
space:
mode:
authorCyril Bur <cyril.bur@au1.ibm.com>2015-06-04 10:36:04 +1000
committerStewart Smith <stewart@linux.vnet.ibm.com>2015-06-09 16:37:33 +1000
commit1cfea56ee83d9c9cd1d5c934e83441aa5f3db9a2 (patch)
treec3d108f506494bc34578c840f79c2029b33cd163 /libflash/blocklevel.c
parent89ec9eb94a0bf4605e73bc3dd1d8588005b7ec4d (diff)
downloadblackbird-skiboot-1cfea56ee83d9c9cd1d5c934e83441aa5f3db9a2.tar.gz
blackbird-skiboot-1cfea56ee83d9c9cd1d5c934e83441aa5f3db9a2.zip
libflash: Blocklevel sanity checking of erase block sizes
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@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Diffstat (limited to 'libflash/blocklevel.c')
-rw-r--r--libflash/blocklevel.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/libflash/blocklevel.c b/libflash/blocklevel.c
index 320ffacc..bc03b9b5 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;
}
OpenPOWER on IntegriCloud