embarc_osp icon indicating copy to clipboard operation
embarc_osp copied to clipboard

Fix last-address calculate error in norflash_erase

Open CosmicRoach opened this issue 10 months ago • 3 comments

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.

CosmicRoach avatar Apr 25 '24 12:04 CosmicRoach

Assigned to @xxkent for review.

abrodkin avatar May 02 '24 09:05 abrodkin

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

xxkent avatar May 02 '24 10:05 xxkent

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.

CosmicRoach avatar May 06 '24 02:05 CosmicRoach