[U-Boot] [PATCH 1/4] cmd_mem.c: add a memory wait (mwait) command

jacquiot.aurelien at gmail.com jacquiot.aurelien at gmail.com
Tue Nov 10 13:13:17 CET 2015


From: Aurelien Jacquiot <a-jacquiot at ti.com>

This new memory command allows to wait a given value in memory.
It can be useful when U-Boot is used in a slave mode (another device
is pushing images to the local memory) such as RapidIO or any
RDMA kind of transport. We can then be notified that images have been
loaded to our memory before booting.

Usage is: mwait[.b, .w, .l, .q] address value

Signed-off-by: Aurelien Jacquiot <a-jacquiot at ti.com>
---
 common/cmd_mem.c |   69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 69 insertions(+), 0 deletions(-)

diff --git a/common/cmd_mem.c b/common/cmd_mem.c
index 43c3fb6..af6e39d 100644
--- a/common/cmd_mem.c
+++ b/common/cmd_mem.c
@@ -1238,6 +1238,65 @@ static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 #endif
 
+static int
+do_mem_mwait(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	ulong addr;
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+	u64   val, readval;
+#else
+	ulong val, readval;
+#endif
+	int   size;
+
+	if (argc != 3)
+		return CMD_RET_USAGE;
+
+	/* check for size specification */
+	size = cmd_get_data_size(argv[0], 4);
+	if (size < 1)
+		return 1;
+
+	/* first arg: address */
+	addr = simple_strtoul(argv[1], NULL, 16);
+
+	/* second arg: expected value */
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+	val = simple_strtoull(argv[2], NULL, 16);
+	printf("waiting 0x%llx at 0x%lx...\n", val, addr);
+#else
+	val = simple_strtoul(argv[2], NULL, 16);
+	printf("waiting 0x%lx at 0x%lx...\n", val, addr);
+#endif
+
+	for (;;) {
+		if (size == 4)
+			readval = *((u32 *)addr);
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+		else if (size == 8)
+			readval = *((u64 *)addr);
+#endif
+		else if (size == 2)
+			readval = *((u16 *)addr);
+		else
+			readval = *((u8 *)addr);
+
+		if (readval == val)
+			return 0;
+
+		/* check for ctrl-c to abort... */
+		if (ctrlc()) {
+			puts("Abort\n");
+			return 0;
+		}
+
+		WATCHDOG_RESET();
+		udelay(1000);
+	}
+
+	return 0;
+}
+
 /**************************************************/
 U_BOOT_CMD(
 	md,	3,	1,	do_mem_md,
@@ -1399,6 +1458,16 @@ U_BOOT_CMD(
 );
 #endif /* CONFIG_MX_CYCLIC */
 
+U_BOOT_CMD(
+	mwait,	3,	1,	do_mem_mwait,
+	"memory wait for value",
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+	"[.b, .w, .l, .q] address value\n"
+#else
+	"[.b, .w, .l] address value\n"
+#endif
+);
+
 #ifdef CONFIG_CMD_MEMINFO
 U_BOOT_CMD(
 	meminfo,	3,	1,	do_mem_info,
-- 
1.6.2.1



More information about the U-Boot mailing list