foss-for-synopsys-dwc-arc-processors / embarc_osp

embARC Open Software Platform (OSP) - An embedded software distribution for IoT and other embedded applications for ARC
https://www.embarc.org/
BSD 3-Clause "New" or "Revised" License
70 stars 63 forks source link

Fix last-address calculate error in norflash_erase #180

Open CosmicRoach opened 5 months ago

CosmicRoach commented 5 months ago

Summary

ToDos

abrodkin commented 5 months ago

Assigned to @xxkent for review.

xxkent commented 5 months ago

Looks good to me, in case of caller set sz > 0.

CosmicRoach commented 5 months ago

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.