strings.c 927 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. #include <config.h>
  9. #include <common.h>
  10. #include <command.h>
  11. static char *start_addr, *last_addr;
  12. int do_strings(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
  13. {
  14. if (argc == 1)
  15. return CMD_RET_USAGE;
  16. if ((flag & CMD_FLAG_REPEAT) == 0) {
  17. start_addr = (char *)hextoul(argv[1], NULL);
  18. if (argc > 2)
  19. last_addr = (char *)hextoul(argv[2], NULL);
  20. else
  21. last_addr = (char *)-1;
  22. }
  23. char *addr = start_addr;
  24. do {
  25. puts(addr);
  26. puts("\n");
  27. addr += strlen(addr) + 1;
  28. } while (addr[0] && addr < last_addr);
  29. last_addr = addr + (last_addr - start_addr);
  30. start_addr = addr;
  31. return 0;
  32. }
  33. U_BOOT_CMD(
  34. strings, 3, 1, do_strings,
  35. "display strings",
  36. "<addr> [byte count]\n"
  37. " - display strings at <addr> for at least [byte count] or first double NUL"
  38. );