cmd_strings.c 1013 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. #ifdef CONFIG_CFG_STRINGS
  12. static char *start_addr, *last_addr;
  13. int do_strings(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  14. {
  15. if (argc == 1) {
  16. printf("Usage:\n%s\n", cmdtp->usage);
  17. return 1;
  18. }
  19. if ((flag & CMD_FLAG_REPEAT) == 0) {
  20. start_addr = (char *)simple_strtoul(argv[1], NULL, 16);
  21. if (argc > 2)
  22. last_addr = (char *)simple_strtoul(argv[2], NULL, 16);
  23. else
  24. last_addr = (char *)-1;
  25. }
  26. char *addr = start_addr;
  27. do {
  28. printf("%s\n", addr);
  29. addr += strlen(addr) + 1;
  30. } while (addr[0] && addr < last_addr);
  31. last_addr = addr + (last_addr - start_addr);
  32. start_addr = addr;
  33. return 0;
  34. }
  35. U_BOOT_CMD(strings, 3, 1, do_strings,
  36. "strings - display strings\n",
  37. "<addr> [byte count]\n"
  38. " - display strings at <addr> for at least [byte count] or first double NUL\n");
  39. #endif