[Skiboot] [PATCH v2 10/19] external/pflash: Correct erase alignment checks
Cyril Bur
cyril.bur at au1.ibm.com
Fri Jul 28 16:46:28 AEST 2017
pflash should check the alignment of addresses and sizes when asked to
erase. There are two possibilities:
1. The user has specified sizes manually in which case pflash should
be as flexible as possible, blocklevel_smart_erase() permits this. To
prevent possible mistakes pflash will require --force to perform a
manual erase of unaligned sizes.
2. The user used -P to specify a partition, partitions aren't
necessarily erase granule aligned anymore, blocklevel_smart_erase() can
handle. In this it doesn't make sense to warn/error about misalignment
since the misalignment is inherent to the FFS partition and not really
user input.
Signed-off-by: Cyril Bur <cyril.bur at au1.ibm.com>
---
external/pflash/pflash.c | 40 +++++++++++++---------------------------
1 file changed, 13 insertions(+), 27 deletions(-)
diff --git a/external/pflash/pflash.c b/external/pflash/pflash.c
index 657e814b..f5e6a067 100644
--- a/external/pflash/pflash.c
+++ b/external/pflash/pflash.c
@@ -610,7 +610,6 @@ int main(int argc, char *argv[])
{
const char *pname = argv[0];
uint32_t address = 0, read_size = 0, write_size = 0, detail_id = UINT_MAX;
- uint32_t erase_start = 0, erase_size = 0;
bool erase = false, do_clear = false;
bool program = false, erase_all = false, info = false, do_read = false;
bool enable_4B = false, disable_4B = false;
@@ -981,33 +980,20 @@ int main(int argc, char *argv[])
goto out;
}
-
- /* If erasing, check partition alignment */
- if (erase && ((pstart | pmaxsz) & 0xfff)) {
- fprintf(stderr,"Partition not aligned properly\n");
- goto out;
- }
-
/* Set address */
address = pstart;
- }
-
- /* Align erase boundaries */
- if (erase && !erase_all) {
- uint32_t mask = 0xfff;
- uint32_t erase_end;
-
- /* Dummy size for erase, will be adjusted later */
- if (!write_size)
- write_size = 1;
- erase_start = address & ~mask;
- erase_end = ((address + write_size) + mask) & ~mask;
- erase_size = erase_end - erase_start;
-
- if (erase_start != address || erase_size != write_size)
- fprintf(stderr, "WARNING: Erase region adjusted"
- " to 0x%08x..0x%08x\n",
- erase_start, erase_end);
+ } else if (erase) {
+ if ((address | write_size) & (fl_erase_granule - 1)) {
+ if (must_confirm) {
+ printf("ERROR: Erase at 0x%08x for 0x%08x isn't erase block aligned\n",
+ address, write_size);
+ printf("Use --force to force\n");
+ goto out;
+ } else {
+ printf("WARNING: Erase at 0x%08x for 0x%08x isn't erase block aligned\n",
+ address, write_size);
+ }
+ }
}
/* Process commands */
@@ -1041,7 +1027,7 @@ int main(int argc, char *argv[])
if (erase_all)
erase_chip();
else if (erase)
- erase_range(erase_start, erase_size, program);
+ erase_range(address, write_size, program);
if (program)
program_file(write_file, address, write_size);
if (do_clear)
--
2.13.3
More information about the Skiboot
mailing list