From 9a042e9ca512beaaa2cb450274313fc477141241 Mon Sep 17 00:00:00 2001 From: Jerry Van Baren Date: Sat, 8 Mar 2008 13:48:01 -0500 Subject: Flash programming progress countdown. Signed-off-by: Gerald Van Baren --- drivers/mtd/cfi_flash.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index 439c950..48286e5 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -1180,6 +1180,22 @@ void flash_print_info (flash_info_t * info) } /*----------------------------------------------------------------------- + * This is used in a few places in write_buf() to show programming + * progress. Making it a function is nasty because it needs to do side + * effect updates to digit and dots. Repeated code is nasty too, so + * we define it once here. + */ +#define FLASH_SHOW_PROGRESS(scale, dots, digit) \ + if ((scale > 0) && (dots <= 0)) { \ + if ((digit % 5) == 0) \ + printf ("%d", digit / 5); \ + else \ + putc ('.'); \ + digit--; \ + dots += scale; \ + } + +/*----------------------------------------------------------------------- * Copy memory to flash, returns: * 0 - OK * 1 - write timeout @@ -1192,10 +1208,23 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt) int aln; cfiword_t cword; int i, rc; - #ifdef CFG_FLASH_USE_BUFFER_WRITE int buffered_size; #endif +#ifdef CONFIG_FLASH_SHOW_PROGRESS + int digit = CONFIG_FLASH_SHOW_PROGRESS; + int scale = 0; + int dots = 0; + + /* + * Suppress if there are fewer than CONFIG_FLASH_SHOW_PROGRESS writes. + */ + if (cnt >= CONFIG_FLASH_SHOW_PROGRESS) { + scale = (int)((cnt + CONFIG_FLASH_SHOW_PROGRESS - 1) / + CONFIG_FLASH_SHOW_PROGRESS); + } +#endif + /* get lower aligned address */ wp = (addr & ~(info->portwidth - 1)); @@ -1219,6 +1248,10 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt) return rc; wp += i; +#ifdef CONFIG_FLASH_SHOW_PROGRESS + dots -= i; + FLASH_SHOW_PROGRESS(scale, dots, digit); +#endif } /* handle the aligned part */ @@ -1248,6 +1281,10 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt) wp += i; src += i; cnt -= i; +#ifdef CONFIG_FLASH_SHOW_PROGRESS + dots -= i; + FLASH_SHOW_PROGRESS(scale, dots, digit); +#endif } #else while (cnt >= info->portwidth) { @@ -1259,8 +1296,13 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt) return rc; wp += info->portwidth; cnt -= info->portwidth; +#ifdef CONFIG_FLASH_SHOW_PROGRESS + dots -= info->portwidth; + FLASH_SHOW_PROGRESS(scale, dots, digit); +#endif } #endif /* CFG_FLASH_USE_BUFFER_WRITE */ + if (cnt == 0) { return (0); } -- cgit v1.1 From f0105727d132f56a21fa3ed8b162309cca6cac44 Mon Sep 17 00:00:00 2001 From: Stefan Roese Date: Wed, 19 Mar 2008 07:09:26 +0100 Subject: CFI: Small cleanup for FLASH_SHOW_PROGRESS With this patch we don't need that many #ifdef's in the code. It moves the subtraction into the macro and defines a NOP-macro when CONFIG_FLASH_SHOW_PROGRESS is not defined. Signed-off-by: Stefan Roese Acked-by: Gerald Van Baren --- drivers/mtd/cfi_flash.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index 48286e5..f04c72d 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -1185,7 +1185,9 @@ void flash_print_info (flash_info_t * info) * effect updates to digit and dots. Repeated code is nasty too, so * we define it once here. */ -#define FLASH_SHOW_PROGRESS(scale, dots, digit) \ +#ifdef CONFIG_FLASH_SHOW_PROGRESS +#define FLASH_SHOW_PROGRESS(scale, dots, digit, dots_sub) \ + dots -= dots_sub; \ if ((scale > 0) && (dots <= 0)) { \ if ((digit % 5) == 0) \ printf ("%d", digit / 5); \ @@ -1194,6 +1196,9 @@ void flash_print_info (flash_info_t * info) digit--; \ dots += scale; \ } +#else +#define FLASH_SHOW_PROGRESS(scale, dots, digit, dots_sub) +#endif /*----------------------------------------------------------------------- * Copy memory to flash, returns: @@ -1248,10 +1253,7 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt) return rc; wp += i; -#ifdef CONFIG_FLASH_SHOW_PROGRESS - dots -= i; - FLASH_SHOW_PROGRESS(scale, dots, digit); -#endif + FLASH_SHOW_PROGRESS(scale, dots, digit, i); } /* handle the aligned part */ @@ -1281,10 +1283,7 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt) wp += i; src += i; cnt -= i; -#ifdef CONFIG_FLASH_SHOW_PROGRESS - dots -= i; - FLASH_SHOW_PROGRESS(scale, dots, digit); -#endif + FLASH_SHOW_PROGRESS(scale, dots, digit, i); } #else while (cnt >= info->portwidth) { @@ -1296,10 +1295,7 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt) return rc; wp += info->portwidth; cnt -= info->portwidth; -#ifdef CONFIG_FLASH_SHOW_PROGRESS - dots -= info->portwidth; - FLASH_SHOW_PROGRESS(scale, dots, digit); -#endif + FLASH_SHOW_PROGRESS(scale, dots, digit, info->portwidth); } #endif /* CFG_FLASH_USE_BUFFER_WRITE */ -- cgit v1.1