[U-Boot-Users] [PATCH] CFI: fix timeout calculations

Anders Larsen al at alarsen.net
Thu Mar 30 14:29:45 CEST 2006


This patch fixes two problems with the cfi_flash timeout handling:
1) Correctly handle the cases where CFG_HZ != 1000 (several XScale-based boards)
2) Fix the timeout calculation of buffered writes (off by a factor of 1000)

Additionally, the patch trivially removes a redundant call of getenv()

Signed-off-by: Anders Larsen <al at alarsen.net>

---

 drivers/cfi_flash.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/cfi_flash.c b/drivers/cfi_flash.c
index a989d34..c7c9983 100644
--- a/drivers/cfi_flash.c
+++ b/drivers/cfi_flash.c
@@ -360,7 +360,7 @@ #ifdef CFG_FLASH_PROTECTION
 		else {
 			char *s = getenv("unlock");
 
-			if (((s = getenv("unlock")) != NULL) && (strcmp(s, "yes") == 0)) {
+			if ((s != NULL) && (strcmp(s, "yes") == 0)) {
 				/*
 				 * Only the U-Boot image and it's environment is protected,
 				 * all other sectors are unprotected (unlocked) if flash
@@ -746,6 +746,10 @@ static int flash_status_check (flash_inf
 {
 	ulong start;
 
+#if CFG_HZ != 1000
+	tout *= CFG_HZ/1000;
+#endif
+
 	/* Wait for command completion */
 	start = get_timer (0);
 	while (flash_is_busy (info, sector)) {
@@ -1160,8 +1164,9 @@ #endif
 		info->buffer_size = (1 << flash_read_ushort (info, 0, FLASH_OFFSET_BUFFER_SIZE));
 		tmp = 1 << flash_read_uchar (info, FLASH_OFFSET_ETOUT);
 		info->erase_blk_tout = (tmp * (1 << flash_read_uchar (info, FLASH_OFFSET_EMAX_TOUT)));
-		tmp = 1 << flash_read_uchar (info, FLASH_OFFSET_WBTOUT);
-		info->buffer_write_tout = (tmp * (1 << flash_read_uchar (info, FLASH_OFFSET_WBMAX_TOUT)));
+		tmp = (1 << flash_read_uchar (info, FLASH_OFFSET_WBTOUT)) *
+		      (1 << flash_read_uchar (info, FLASH_OFFSET_WBMAX_TOUT));
+		info->buffer_write_tout = tmp / 1000 + (tmp % 1000 ? 1 : 0); /* round up when converting to ms */
 		tmp = (1 << flash_read_uchar (info, FLASH_OFFSET_WTOUT)) *
 		      (1 << flash_read_uchar (info, FLASH_OFFSET_WMAX_TOUT));
 		info->write_tout = tmp / 1000 + (tmp % 1000 ? 1 : 0); /* round up when converting to ms */





More information about the U-Boot mailing list