blob: 5bcb0f2b567cd4526116d6c3fdd31482eb18155b [file] [log] [blame]
Mike Frysinger8fb69662008-02-04 19:26:57 -05001/*
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 Frysinger8fb69662008-02-04 19:26:57 -050010#include <command.h>
Tom Rini5c1444f2024-04-27 08:10:59 -060011#include <vsprintf.h>
Mike Frysinger8fb69662008-02-04 19:26:57 -050012
Mike Frysinger8fb69662008-02-04 19:26:57 -050013static char *start_addr, *last_addr;
14
Simon Glassed38aef2020-05-10 11:40:03 -060015int do_strings(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Mike Frysinger8fb69662008-02-04 19:26:57 -050016{
Wolfgang Denk3b683112010-07-17 01:06:04 +020017 if (argc == 1)
Simon Glassa06dfc72011-12-10 08:44:01 +000018 return CMD_RET_USAGE;
Mike Frysinger8fb69662008-02-04 19:26:57 -050019
20 if ((flag & CMD_FLAG_REPEAT) == 0) {
Simon Glass3ff49ec2021-07-24 09:03:29 -060021 start_addr = (char *)hextoul(argv[1], NULL);
Mike Frysinger8fb69662008-02-04 19:26:57 -050022 if (argc > 2)
Simon Glass3ff49ec2021-07-24 09:03:29 -060023 last_addr = (char *)hextoul(argv[2], NULL);
Mike Frysinger8fb69662008-02-04 19:26:57 -050024 else
25 last_addr = (char *)-1;
26 }
27
28 char *addr = start_addr;
29 do {
Mike Frysinger12d61ad2008-11-04 16:03:46 -050030 puts(addr);
31 puts("\n");
Mike Frysinger8fb69662008-02-04 19:26:57 -050032 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 Meulenbroeks7675a092010-07-31 15:01:53 +020041U_BOOT_CMD(
42 strings, 3, 1, do_strings,
Peter Tyserdfb72b82009-01-27 18:03:12 -060043 "display strings",
Mike Frysinger8fb69662008-02-04 19:26:57 -050044 "<addr> [byte count]\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +020045 " - display strings at <addr> for at least [byte count] or first double NUL"
46);