[Skiboot] [PATCH 09/17] external/pflash: Correct erase alignment checks
Samuel Mendoza-Jonas
sam at mendozajonas.com
Wed Jul 26 15:47:20 AEST 2017
On Fri, 2017-07-21 at 16:36 +1000, Cyril Bur wrote:
> Either 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.
> Alternatively they would have used -P to specify a partition, partitions
> aren't necessarily erase granule aligned anymore, pflash should still
> work, blocklevel_smart_erase() will handle - skip the checks in this
> case.
This took me three goes to understand - please English v2 :(
>
> This commit also starts using write_sizes and standard addresses to pass
> to the erase code since pflash no longer needs to handle erase
> alignment.
>
> 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 c0a63fca..f73ba1c5 100644
> --- a/external/pflash/pflash.c
> +++ b/external/pflash/pflash.c
> @@ -608,7 +608,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;
> @@ -979,33 +978,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 */
> @@ -1039,7 +1025,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)
More information about the Skiboot
mailing list