[U-Boot-Users] [PATCH] Fix NAND erase progress error

Hugo Villeneuve
2008-05-16T01:58:53Z

diff --git a/drivers/mtd/nand/nand_util.c b/drivers/mtd/nand/nand_util.c
index 6c5624a..bd21e04 100644
--- a/drivers/mtd/nand/nand_util.c
+++ b/drivers/mtd/nand/nand_util.c
@@ -209,10 +209,15 @@ int nand_erase_opts(nand_info_t *meminfo, const nand_erase_options_t *opts)
}

if (!opts->quiet) {
- unsigned long long n =(unsigned long long)
- (erase.addr + meminfo->erasesize - opts->offset)
- * 100;
+ unsigned long long n;
int percent;
+ size_t erased_size = erase.addr - opts->offset + meminfo->erasesize;
+
+ if (erased_size > erase_length) {
+ erased_size = erase_length;
+ }
+
+ n = (unsigned long long) erased_size * 100;

do_div(n, erase_length);
percent = (int)n;