Mike Frysinger | 8fb6966 | 2008-02-04 19:26:57 -0500 | [diff] [blame] | 1 | /* |
| 2 | * cmd_strings.c - just like `strings` command |
| 3 | * |
| 4 | * Copyright (c) 2008 Analog Devices Inc. |
| 5 | * |
| 6 | * Licensed under the GPL-2 or later. |
| 7 | */ |
| 8 | |
| 9 | #include <config.h> |
Mike Frysinger | 8fb6966 | 2008-02-04 19:26:57 -0500 | [diff] [blame] | 10 | #include <command.h> |
Tom Rini | 5c1444f | 2024-04-27 08:10:59 -0600 | [diff] [blame] | 11 | #include <vsprintf.h> |
Mike Frysinger | 8fb6966 | 2008-02-04 19:26:57 -0500 | [diff] [blame] | 12 | |
Mike Frysinger | 8fb6966 | 2008-02-04 19:26:57 -0500 | [diff] [blame] | 13 | static char *start_addr, *last_addr; |
| 14 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 15 | int do_strings(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Mike Frysinger | 8fb6966 | 2008-02-04 19:26:57 -0500 | [diff] [blame] | 16 | { |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 17 | if (argc == 1) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 18 | return CMD_RET_USAGE; |
Mike Frysinger | 8fb6966 | 2008-02-04 19:26:57 -0500 | [diff] [blame] | 19 | |
| 20 | if ((flag & CMD_FLAG_REPEAT) == 0) { |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 21 | start_addr = (char *)hextoul(argv[1], NULL); |
Mike Frysinger | 8fb6966 | 2008-02-04 19:26:57 -0500 | [diff] [blame] | 22 | if (argc > 2) |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 23 | last_addr = (char *)hextoul(argv[2], NULL); |
Mike Frysinger | 8fb6966 | 2008-02-04 19:26:57 -0500 | [diff] [blame] | 24 | else |
| 25 | last_addr = (char *)-1; |
| 26 | } |
| 27 | |
| 28 | char *addr = start_addr; |
| 29 | do { |
Mike Frysinger | 12d61ad | 2008-11-04 16:03:46 -0500 | [diff] [blame] | 30 | puts(addr); |
| 31 | puts("\n"); |
Mike Frysinger | 8fb6966 | 2008-02-04 19:26:57 -0500 | [diff] [blame] | 32 | addr += strlen(addr) + 1; |
| 33 | } while (addr[0] && addr < last_addr); |
| 34 | |
| 35 | last_addr = addr + (last_addr - start_addr); |
| 36 | start_addr = addr; |
| 37 | |
| 38 | return 0; |
| 39 | } |
| 40 | |
Frans Meulenbroeks | 7675a09 | 2010-07-31 15:01:53 +0200 | [diff] [blame] | 41 | U_BOOT_CMD( |
| 42 | strings, 3, 1, do_strings, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 43 | "display strings", |
Mike Frysinger | 8fb6966 | 2008-02-04 19:26:57 -0500 | [diff] [blame] | 44 | "<addr> [byte count]\n" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 45 | " - display strings at <addr> for at least [byte count] or first double NUL" |
| 46 | ); |