[U-Boot-Users] [PATCH] Make sleep shell command is reliable for all architectures

Jason McMullan mcmullan at netapp.com
Tue May 20 15:57:26 CEST 2008


On some architectures (MIPS is a good example), the timebase
rolls over every few seconds. This patch alters the 'sleep'
shell command to use a total counter of the udelay(100)
sleeps instead of an end time marker to determine the end
of the sleep, making the 'sleep' command capable of sleeping
for any number of seconds on all architectures.

Signed-off-by: Jason McMullan <mcmullan at netapp.com>
---
 common/cmd_misc.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/common/cmd_misc.c b/common/cmd_misc.c
index 126b538..2b84896 100644
--- a/common/cmd_misc.c
+++ b/common/cmd_misc.c
@@ -29,7 +29,6 @@
 
 int do_sleep (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
-	ulong start = get_timer(0);
 	ulong delay;
 
 	if (argc != 2) {
@@ -37,13 +36,18 @@ int do_sleep (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 		return 1;
 	}
 
-	delay = simple_strtoul(argv[1], NULL, 10) * CFG_HZ;
+	/* Sleep in 100ms increments, as some the time base of
+	 * some architectures can roll over after only a few
+	 * seconds (MIPS is a good example of this)
+	 */
+	delay = simple_strtoul(argv[1], NULL, 10) * 10;
 
-	while (get_timer(start) < delay) {
+	while (delay > 0) {
 		if (ctrlc ()) {
 			return (-1);
 		}
 		udelay (100);
+		delay--;
 	}
 
 	return 0;
-- 
1.5.4.3





More information about the U-Boot mailing list