230-cmd-add-pstore-check.patch 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. --- a/cmd/pstore.c
  2. +++ b/cmd/pstore.c
  3. @@ -208,6 +208,58 @@ static int pstore_set(struct cmd_tbl *cm
  4. }
  5. /**
  6. + * pstore_check() - Check for pstore records
  7. + * @cmdtp: Command data struct pointer
  8. + * @flag: Command flag
  9. + * @argc: Command-line argument count
  10. + * @argv: Array of command-line arguments
  11. + *
  12. + * Return: 0 if there are records in pstore, 1 otherwise
  13. + */
  14. +static int pstore_check(struct cmd_tbl *cmdtp, int flag, int argc,
  15. + char * const argv[])
  16. +{
  17. + phys_addr_t ptr;
  18. + char *buffer;
  19. + u32 size;
  20. + int header_len = 0;
  21. + bool compressed;
  22. +
  23. + if (pstore_length == 0) {
  24. + printf("Please set PStore configuration\n");
  25. + return CMD_RET_USAGE;
  26. + }
  27. +
  28. + if (buffer_size == 0)
  29. + pstore_init_buffer_size();
  30. +
  31. + buffer = malloc_cache_aligned(buffer_size);
  32. +
  33. + ptr = pstore_addr;
  34. + phys_addr_t ptr_end = ptr + pstore_length - pstore_pmsg_size
  35. + - pstore_ftrace_size - pstore_console_size;
  36. +
  37. + while (ptr < ptr_end) {
  38. + size = pstore_get_buffer(PERSISTENT_RAM_SIG, ptr,
  39. + pstore_record_size, buffer);
  40. + ptr += pstore_record_size;
  41. +
  42. + if (size == 0)
  43. + continue;
  44. +
  45. + header_len = pstore_read_kmsg_hdr(buffer, &compressed);
  46. + if (header_len == 0)
  47. + continue;
  48. +
  49. + free(buffer);
  50. + return 0;
  51. + }
  52. +
  53. + free(buffer);
  54. + return 1;
  55. +}
  56. +
  57. +/**
  58. * pstore_print_buffer() - Print buffer
  59. * @type: buffer type
  60. * @buffer: buffer to print
  61. @@ -459,6 +511,7 @@ static int pstore_save(struct cmd_tbl *c
  62. static struct cmd_tbl cmd_pstore_sub[] = {
  63. U_BOOT_CMD_MKENT(set, 8, 0, pstore_set, "", ""),
  64. + U_BOOT_CMD_MKENT(check, 1, 0, pstore_check, "", ""),
  65. U_BOOT_CMD_MKENT(display, 3, 0, pstore_display, "", ""),
  66. U_BOOT_CMD_MKENT(save, 4, 0, pstore_save, "", ""),
  67. };
  68. @@ -566,6 +619,8 @@ U_BOOT_CMD(pstore, 10, 0, do_pstore,
  69. " 'pmsg-size' is the size of the user space logs record.\n"
  70. " 'ecc-size' enables/disables ECC support and specifies ECC buffer size in\n"
  71. " bytes (0 disables it, 1 is a special value, means 16 bytes ECC).\n"
  72. + "pstore check\n"
  73. + "- Returns true if there are records in pstore.\n"
  74. "pstore display [record-type] [nb]\n"
  75. "- Display existing records in pstore reserved memory. A 'record-type' can\n"
  76. " be given to only display records of this kind. 'record-type' can be one\n"