esp_core_dump.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef ESP_CORE_DUMP_H_
  14. #define ESP_CORE_DUMP_H_
  15. #include <stddef.h>
  16. #include "esp_err.h"
  17. #include "esp_private/panic_internal.h"
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. /**************************************************************************************/
  22. /******************************** EXCEPTION MODE API **********************************/
  23. /**************************************************************************************/
  24. /**
  25. * @brief Initializes core dump module internal data.
  26. *
  27. * @note Should be called at system startup.
  28. */
  29. void esp_core_dump_init(void);
  30. /**
  31. * @brief Saves core dump to flash.
  32. *
  33. * The structure of data stored in flash is as follows:
  34. *
  35. * | TOTAL_LEN | VERSION | TASKS_NUM | TCB_SIZE |
  36. * | TCB_ADDR_1 | STACK_TOP_1 | STACK_END_1 | TCB_1 | STACK_1 |
  37. * . . . .
  38. * . . . .
  39. * | TCB_ADDR_N | STACK_TOP_N | STACK_END_N | TCB_N | STACK_N |
  40. * | CHECKSUM |
  41. *
  42. * Core dump in flash consists of header and data for every task in the system at the moment of crash.
  43. * For flash data integrity, a checksum is used at the end of core the dump data.
  44. * The structure of core dump data is described below in details.
  45. * 1) Core dump starts with header:
  46. * 1.1) TOTAL_LEN is total length of core dump data in flash including the checksum. Size is 4 bytes.
  47. * 1.2) VERSION field keeps 4 byte version of core dump.
  48. * 1.2) TASKS_NUM is the number of tasks for which data are stored. Size is 4 bytes.
  49. * 1.3) TCB_SIZE is the size of task's TCB structure. Size is 4 bytes.
  50. * 2) Core dump header is followed by the data for every task in the system.
  51. * Task data are started with task header:
  52. * 2.1) TCB_ADDR is the address of TCB in memory. Size is 4 bytes.
  53. * 2.2) STACK_TOP is the top of task's stack (address of the topmost stack item). Size is 4 bytes.
  54. * 2.2) STACK_END is the end of task's stack (address from which task's stack starts). Size is 4 bytes.
  55. * 3) Task header is followed by TCB data. Size is TCB_SIZE bytes.
  56. * 4) Task's stack is placed after TCB data. Size is (STACK_END - STACK_TOP) bytes.
  57. * 5) The checksum is placed at the end of the data.
  58. */
  59. void esp_core_dump_to_flash(panic_info_t *info);
  60. /**
  61. * @brief Print base64-encoded core dump to UART.
  62. *
  63. * The structure of core dump data is the same as for data stored in flash (@see esp_core_dump_to_flash) with some notes:
  64. * 1) The checksum is not present in core dump printed to UART.
  65. * 2) Since checksum is omitted TOTAL_LEN does not include its size.
  66. * 3) Printed base64 data are surrounded with special messages to help user recognize the start and end of actual data.
  67. */
  68. void esp_core_dump_to_uart(panic_info_t *info);
  69. /**************************************************************************************/
  70. /*********************************** USER MODE API ************************************/
  71. /**************************************************************************************/
  72. /**
  73. * @brief Check integrity of coredump data in flash.
  74. * This function reads the coredump data while calculating their checksum. If it
  75. * doesn't match the checksum written on flash, it means data are corrupted,
  76. * an error will be returned. Else, ESP_OK is returned.
  77. *
  78. * @return `ESP_OK` if core dump is present and valid, `ESP_ERR_NOT_FOUND` if no core dump
  79. * is stored in the partition, `ESP_ERR_INVALID_SIZE` or `ESP_ERR_INVALID_CRC`
  80. * if the core dump is corrupted, other errors when unable to access flash, in that
  81. * case please refer to \see esp_err_t
  82. */
  83. esp_err_t esp_core_dump_image_check(void);
  84. /**
  85. * @brief Retrieves address and size of coredump data in flash.
  86. * This function is always available, even when core dump is disabled in menuconfig.
  87. *
  88. * @param out_addr pointer to store image address in flash.
  89. * @param out_size pointer to store image size in flash (including checksum). In bytes.
  90. *
  91. * @return ESP_OK on success, otherwise \see esp_err_t
  92. */
  93. esp_err_t esp_core_dump_image_get(size_t* out_addr, size_t *out_size);
  94. /**
  95. * @brief Erases coredump data in flash. esp_core_dump_image_get() will then return
  96. * ESP_ERR_NOT_FOUND. Can be used after a coredump has been transmitted successfully.
  97. * This function is always available, even when core dump is disabled in menuconfig.
  98. *
  99. * @return ESP_OK on success, otherwise \see esp_err_t
  100. */
  101. esp_err_t esp_core_dump_image_erase(void);
  102. #ifdef __cplusplus
  103. }
  104. #endif
  105. #endif