[U-Boot-Users] [PATCH] Memory Functions

Ladislav Michl ladis at linux-mips.org
Wed Sep 8 19:19:56 CEST 2004


Hi,

did anyone ever used md command? Patch below does following:

# md 400000
00400000: ea000012    ....
# md 400000 4
00400000: ea000012 e59ff014 e59ff014 e59ff014    ................
# md .w 40000
00040000: 7b55    U{
# md .w 40000 4
00040000: 7b55 7e24 47b4 67e1    U{$~.G.g

Wrong parameters are handled too :)

Once there, a question comes to mind. Why was this format choosen?
md [.b, .w, .l] address [# of objects]
First optional parameter makes parsing a bit more difcult. And why is
width specifier prefixed with dot? And what is .s specifier good for?
Well, more that one question, I know... ;-)

I implemented cmd_get_data_size2, because cmd_get_data_size simply
doesn't work and all it's users are broken too (do_pci looks good), just
grep for function name and you'll see what needs fixing.

My proposal is to replace cmd_get_data_size with cmd_get_data_size2 and
fix all bugs in its users. How should it be done depends on answers to
questions above.

Best regars,
	ladis

--- u-boot/common/cmd_mem.c.orig	2004-09-08 18:43:16.000000000 +0200
+++ u-boot/common/cmd_mem.c	2004-09-08 19:00:18.000000000 +0200
@@ -62,6 +62,33 @@
 	}
 	return default_size;
 }
+
+/* Check for a size specification .b, .w or .l.
+ * Returns:	-1 if arg is not size specifier
+ *		 0 if specifier was recognized (size is set approriately)
+ *		 1 if arg is unknown specifier
+ */
+int cmd_get_data_size2(char* arg, int *size)
+{
+	if (!(strlen(arg) > 1 && arg[0] == '.'))
+		return -1;
+	switch(arg[1]) {
+	case 'b':
+		*size = 1;
+		break;
+	case 'w':
+		*size = 2;
+		break;
+	case 'l':
+		*size = 4;
+		break;
+	default:
+		return 1;
+	}
+	return 0;
+}
+
+
 #endif
 
 #if (CONFIG_COMMANDS & CFG_CMD_MEMORY)
@@ -105,27 +132,32 @@
 	length = dp_last_length;
 
 	if (argc < 2) {
+error:
 		printf ("Usage:\n%s\n", cmdtp->usage);
 		return 1;
 	}
 
 	if ((flag & CMD_FLAG_REPEAT) == 0) {
+		int idx = 1;
 		/* New command specified.  Check for a size specification.
 		 * Defaults to long if no or incorrect specification.
 		 */
-		if ((size = cmd_get_data_size(argv[0], 4)) < 0)
-			return 1;
+		size = 4;
+		if (cmd_get_data_size2(argv[idx], &size) >= 0)
+			idx++;
+		if (idx >= argc)
+			goto error;
 
-		/* Address is specified since argc > 1
-		*/
-		addr = simple_strtoul(argv[1], NULL, 16);
+		addr = simple_strtoul(argv[idx++], NULL, 16);
 		addr += base_address;
 
 		/* If another parameter, it is the length to display.
 		 * Length is the number of objects, not number of bytes.
 		 */
-		if (argc > 2)
-			length = simple_strtoul(argv[2], NULL, 16);
+		if (idx < argc)
+			length = simple_strtoul(argv[idx], NULL, 16);
+		else
+			length = 1;
 	}
 
 	/* Print the lines.
@@ -1128,7 +1160,7 @@
 /**************************************************/
 #if (CONFIG_COMMANDS & CFG_CMD_MEMORY)
 U_BOOT_CMD(
-	md,     3,     1,      do_mem_md,
+	md,	4,	1,	do_mem_md,
 	"md      - memory display\n",
 	"[.b, .w, .l] address [# of objects]\n    - memory display\n"
 );




More information about the U-Boot mailing list