summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2020-07-28 19:41:14 -0600
committerTom Rini <trini@konsulko.com>2020-08-07 22:31:32 -0400
commit550a9e7902ce2a6103d97d70a22bad64e4fab7fd (patch)
tree4314ea6e2a497862ed0f0fb8d417396a2b4f5442 /cmd
parent132644f56ebb7399fb139d6b9c9e54ef0c218ea9 (diff)
downloadu-boot-550a9e7902ce2a6103d97d70a22bad64e4fab7fd.tar.gz
cmd: Update the memory-search command
Add various fixes and improvements to this command that were missed in the original version. Unfortunately I forgot to send v2. - Fix Kconfig name - Use a separate variable for the remaining search length - Correct a minor bug - Move into a separate test suite - Add -q flag to the 'quiet' test to test operation when console is enabled - Enable the feature for sandbox Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/Kconfig2
-rw-r--r--cmd/mem.c30
2 files changed, 19 insertions, 13 deletions
diff --git a/cmd/Kconfig b/cmd/Kconfig
index e11176451b..6ac274e620 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -724,7 +724,7 @@ config CMD_MEMORY
base - print or set address offset
loop - initialize loop on address range
-config MEM_SEARCH
+config CMD_MEM_SEARCH
bool "ms - Memory search"
help
Memory-search command
diff --git a/cmd/mem.c b/cmd/mem.c
index 575893c18d..190e2b94a7 100644
--- a/cmd/mem.c
+++ b/cmd/mem.c
@@ -53,7 +53,8 @@ static ulong dp_last_length = 0x40;
static ulong mm_last_addr, mm_last_size;
static ulong base_address = 0;
-#ifdef CONFIG_MEM_SEARCH
+#ifdef CONFIG_CMD_MEM_SEARCH
+static ulong dp_last_ms_length;
static u8 search_buf[64];
static uint search_len;
#endif
@@ -367,7 +368,7 @@ static int do_mem_cp(struct cmd_tbl *cmdtp, int flag, int argc,
return 0;
}
-#ifdef CONFIG_MEM_SEARCH
+#ifdef CONFIG_CMD_MEM_SEARCH
static int do_mem_search(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
@@ -377,6 +378,7 @@ static int do_mem_search(struct cmd_tbl *cmdtp, int flag, int argc,
ulong last_pos; /* Offset of last match in 'size' units*/
ulong last_addr; /* Address of last displayed line */
int limit = 10;
+ int used_len;
int count;
int size;
int i;
@@ -384,12 +386,12 @@ static int do_mem_search(struct cmd_tbl *cmdtp, int flag, int argc,
/* We use the last specified parameters, unless new ones are entered */
addr = dp_last_addr;
size = dp_last_size;
- length = dp_last_length;
+ length = dp_last_ms_length;
if (argc < 3)
return CMD_RET_USAGE;
- if ((!flag & CMD_FLAG_REPEAT)) {
+ if (!(flag & CMD_FLAG_REPEAT)) {
/*
* Check for a size specification.
* Defaults to long if no or incorrect specification.
@@ -398,7 +400,8 @@ static int do_mem_search(struct cmd_tbl *cmdtp, int flag, int argc,
if (size < 0 && size != -2 /* string */)
return 1;
- argc--; argv++;
+ argc--;
+ argv++;
while (argc && *argv[0] == '-') {
int ch = argv[0][1];
@@ -408,7 +411,8 @@ static int do_mem_search(struct cmd_tbl *cmdtp, int flag, int argc,
limit = simple_strtoul(argv[0] + 2, NULL, 16);
else
return CMD_RET_USAGE;
- argc--; argv++;
+ argc--;
+ argv++;
}
/* Address is specified since argc > 1 */
@@ -421,7 +425,7 @@ static int do_mem_search(struct cmd_tbl *cmdtp, int flag, int argc,
/* Read the bytes to search for */
end = search_buf + sizeof(search_buf);
for (i = 2, ptr = search_buf; i < argc && ptr < end; i++) {
- if (SUPPORT_64BIT_DATA && size == 8) {
+ if (MEM_SUPPORT_64BIT_DATA && size == 8) {
u64 val = simple_strtoull(argv[i], NULL, 16);
*(u64 *)ptr = val;
@@ -460,7 +464,8 @@ static int do_mem_search(struct cmd_tbl *cmdtp, int flag, int argc,
last_pos = 0;
last_addr = 0;
count = 0;
- for (offset = 0; offset <= bytes - search_len && count < limit;
+ for (offset = 0;
+ offset < bytes && offset <= bytes - search_len && count < limit;
offset += size) {
void *ptr = buf + offset;
@@ -495,9 +500,10 @@ static int do_mem_search(struct cmd_tbl *cmdtp, int flag, int argc,
unmap_sysmem(buf);
- dp_last_addr = addr + offset / size;
+ used_len = offset / size;
+ dp_last_addr = addr + used_len;
dp_last_size = size;
- dp_last_length = length - offset / size;
+ dp_last_ms_length = length < used_len ? 0 : length - used_len;
return count ? 0 : CMD_RET_FAILURE;
}
@@ -1337,13 +1343,13 @@ U_BOOT_CMD(
"[.b, .w, .l" HELP_Q "] addr1 addr2 count"
);
-#ifdef CONFIG_MEM_SEARCH
+#ifdef CONFIG_CMD_MEM_SEARCH
/**************************************************/
U_BOOT_CMD(
ms, 255, 1, do_mem_search,
"memory search",
"[.b, .w, .l" HELP_Q ", .s] [-q | -<n>] address #-of-objects <value>..."
- " -q = quiet, -l<val> = match limit" :
+ " -q = quiet, -l<val> = match limit"
);
#endif