nxp-imx / imx-kobs

Tool to create and write Freescale/NXP I.MX NAND boot related boot data structure to nand flash
GNU General Public License v2.0
29 stars 26 forks source link

Fix incorrect failing on mtd_erase #27

Closed LarsML closed 4 years ago

LarsML commented 4 years ago

In the event where the mtd_erase function also needs to erase the last block of an mtd device, the erasing goes well but the ofs check causes the function to fail even though the erasing of the block went well.

This commit ensures that checking whether ofs does not overrun the mtd size happens as early as possible, thus allowing the mtd_erase function to return properly when everything went right in erasing the last block of an mtd device.

LarsML commented 4 years ago

For an mtd device that goes all the way to 0x200000:

Error log before fix:

mtd: erasing @0:0x140000-0x160000
mtd: erasing @0:0x160000-0x180000
mtd: erasing @0:0x180000-0x1a0000
mtd: erasing @0:0x1a0000-0x1c0000
mtd: erasing @0:0x1c0000-0x1e0000
mtd: erasing @0:0x1e0000-0x200000
mtd: erase stepping bounds
mtd: Failed to erase block@0x1e0000
mtd: mtd_write_page failed
Failed to write safe page

Error log after fix:

mtd: erasing @0:0x140000-0x160000
mtd: erasing @0:0x160000-0x180000
mtd: erasing @0:0x180000-0x1a0000
mtd: erasing @0:0x1a0000-0x1c0000
mtd: erasing @0:0x1c0000-0x1e0000
mtd: erasing @0:0x1e0000-0x200000
mtd: We write one page for save guard. *
allenxh commented 4 years ago

Thanks, will merge the patch.