Mike Frysinger | 30942b1 | 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> |
| 10 | #include <common.h> |
| 11 | #include <command.h> |
| 12 | |
Mike Frysinger | 30942b1 | 2008-02-04 19:26:57 -0500 | [diff] [blame] | 13 | static char *start_addr, *last_addr; |
| 14 | |
| 15 | int do_strings(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 16 | { |
| 17 | if (argc == 1) { |
Peter Tyser | 62c3ae7 | 2009-01-27 18:03:10 -0600 | [diff] [blame] | 18 | cmd_usage(cmdtp); |
Mike Frysinger | 30942b1 | 2008-02-04 19:26:57 -0500 | [diff] [blame] | 19 | return 1; |
| 20 | } |
| 21 | |
| 22 | if ((flag & CMD_FLAG_REPEAT) == 0) { |
| 23 | start_addr = (char *)simple_strtoul(argv[1], NULL, 16); |
| 24 | if (argc > 2) |
| 25 | last_addr = (char *)simple_strtoul(argv[2], NULL, 16); |
| 26 | else |
| 27 | last_addr = (char *)-1; |
| 28 | } |
| 29 | |
| 30 | char *addr = start_addr; |
| 31 | do { |
Mike Frysinger | 774ce72 | 2008-11-04 16:03:46 -0500 | [diff] [blame] | 32 | puts(addr); |
| 33 | puts("\n"); |
Mike Frysinger | 30942b1 | 2008-02-04 19:26:57 -0500 | [diff] [blame] | 34 | addr += strlen(addr) + 1; |
| 35 | } while (addr[0] && addr < last_addr); |
| 36 | |
| 37 | last_addr = addr + (last_addr - start_addr); |
| 38 | start_addr = addr; |
| 39 | |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | U_BOOT_CMD(strings, 3, 1, do_strings, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 44 | "display strings", |
Mike Frysinger | 30942b1 | 2008-02-04 19:26:57 -0500 | [diff] [blame] | 45 | "<addr> [byte count]\n" |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 46 | " - display strings at <addr> for at least [byte count] or first double NUL" |
| 47 | ); |