embarc_osp
embarc_osp copied to clipboard
Fix last-address calculate error in norflash_erase
Summary
- Fix issue: https://github.com/foss-for-synopsys-dwc-arc-processors/embarc_osp/issues/179#issue-2260797778
ToDos
- I only fixed 3 norflash-related code issues, and there are probably similar bugs somewhere.
Assigned to @xxkent for review.
Looks good to me, in case of caller set sz > 0.
Checking the input parameters (address and size) is another matter, here we should make sure that address>=0
and size>0
;
Assuming a correct parameter input, if we do not subtract 1 when calculating the last address of the erase, it will cause us to erase one more sector when the size of the erase is exactly one or more sectors-size.
Examples of errors:
When address=0x0, size=4096, dev->sector_sz=4096
, this means that the user wants to erase the first sector,
So, last_address = (address + size) & (~(dev-> sector_sz-1))=4096
; however, because of the loop condition while (address <= last_address);
We enter two loops, causing the second sector to be erased by mistake.