Skip to contentSkip to conversation

Memory Functions

PATCH New Ladislav Michl 2 participants 3 messages Sep 8, 2004

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Memory Functions

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

common/cmd_mem.c renamed from common/cmd_mem.c.orig +40 -8
@@ -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"
 );
#1 lore raw

PATCH 1/1 Memory Functions

Quoted 2 lines · In message <20040908171956.GA7946@umax645sx> you wrote:

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

Of course, I use it a lot.

Quoted 10 lines
# 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 :)

Why do you introduce a new command format? At least stick with the existing one!

Also, what exactly is the benefit of this change?

Quoted 1 line

Once there, a question comes to mind. Why was this format choosen?

Compatibility to exiting tools. See the BDI2000 for example.

Quoted 4 lines

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... ;-)

You misunderstand (and mis-implement) the format.

It's "cp" and "cp.b" or "cp.l" or "cp.w". No space inbetween.

Quoted 3 lines

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.

I tend to say that the effort (increased memory footprint) is not worth the additional options.

Best regards,

Wolfgang Denk

Signature · 4 lines
Software Engineering:  Embedded and Realtime Systems,  Embedded Linux
Phone: (+49)-8142-4596-87  Fax: (+49)-8142-4596-88  Email: wd at denx.de
I really hate this damned machine     It never does quite what I want
I wish that they would sell it.              But only what I tell it.
#2 lore raw

PATCH 1/1 Memory Functions

Quoted 3 lines · Wolfgang Denk

You misunderstand (and mis-implement) the format.

It's "cp" and "cp.b" or "cp.l" or "cp.w". No space inbetween.

Ahh... It's clear now. (I implemented it a way that help string says, with your additional explanation I have admit it's done right way. I'm sorry for confusion)

Best regards,
ladis