Zephyr Project API  3.4.0
A Scalable Open Source RTOS
coredump.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Intel Corporation.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_DEBUG_COREDUMP_H_
8#define ZEPHYR_INCLUDE_DEBUG_COREDUMP_H_
9
10#include <stddef.h>
11#include <stdint.h>
12#include <sys/types.h>
13
14/* Query ID */
16 /*
17 * Returns error code from backend.
18 */
20
21 /*
22 * Check if there is a stored coredump from backend.
23 *
24 * Returns 1 if there is a stored coredump.
25 * 0 if none.
26 * -ENOTSUP if this query is not supported.
27 * Otherwise, error code from backend.
28 */
30
31 /*
32 * Returns coredump raw size from backend.
33 * 0 if none.
34 * -ENOTSUP if this query is not supported.
35 * Otherwise, error code from backend.
36 */
38
40};
41
42/* Command ID */
44 /*
45 * Clear error code from backend.
46 *
47 * Returns 0 if successful, failed otherwise.
48 */
50
51 /*
52 * Verify that the stored coredump is valid.
53 *
54 * Returns 1 if valid.
55 * 0 if not valid or no stored coredump.
56 * -ENOTSUP if this command is not supported.
57 * Otherwise, error code from backend.
58 */
60
61 /*
62 * Erase the stored coredump.
63 *
64 * Returns 0 if successful.
65 * -ENOTSUP if this command is not supported.
66 * Otherwise, error code from backend.
67 */
69
70 /*
71 * Copy the raw stored coredump.
72 *
73 * Returns copied size if successful
74 * 0 if stored coredump is not found
75 * -ENOTSUP if this command is not supported.
76 * Otherwise, error code from backend.
77 */
79
80 /*
81 * Invalidate the stored coredump. This is faster than
82 * erasing the whole partition.
83 *
84 * Returns 0 if successful.
85 * -ENOTSUP if this command is not supported.
86 * Otherwise, error code from backend.
87 */
89
91};
92
93/* Coredump copy command argument definition */
95 /* Copy offset */
97
98 /* Copy destination buffer */
100
101 /* Copy length */
102 size_t length;
103};
104
105#ifdef CONFIG_DEBUG_COREDUMP
106
107#include <zephyr/toolchain.h>
108#include <zephyr/arch/cpu.h>
109#include <zephyr/sys/byteorder.h>
110
111#define COREDUMP_HDR_VER 1
112
113#define COREDUMP_ARCH_HDR_ID 'A'
114
115#define COREDUMP_MEM_HDR_ID 'M'
116#define COREDUMP_MEM_HDR_VER 1
117
118/* Target code */
119enum coredump_tgt_code {
120 COREDUMP_TGT_UNKNOWN = 0,
121 COREDUMP_TGT_X86,
122 COREDUMP_TGT_X86_64,
123 COREDUMP_TGT_ARM_CORTEX_M,
124 COREDUMP_TGT_RISC_V,
125 COREDUMP_TGT_XTENSA,
126};
127
128/* Coredump header */
129struct coredump_hdr_t {
130 /* 'Z', 'E' */
131 char id[2];
132
133 /* Header version */
134 uint16_t hdr_version;
135
136 /* Target code */
137 uint16_t tgt_code;
138
139 /* Pointer size in Log2 */
140 uint8_t ptr_size_bits;
141
143
144 /* Coredump Reason given */
145 unsigned int reason;
146} __packed;
147
148/* Architecture-specific block header */
149struct coredump_arch_hdr_t {
150 /* COREDUMP_ARCH_HDR_ID */
151 char id;
152
153 /* Header version */
154 uint16_t hdr_version;
155
156 /* Number of bytes in this block (excluding header) */
157 uint16_t num_bytes;
158} __packed;
159
160/* Memory block header */
161struct coredump_mem_hdr_t {
162 /* COREDUMP_MEM_HDR_ID */
163 char id;
164
165 /* Header version */
166 uint16_t hdr_version;
167
168 /* Address of start of memory region */
169 uintptr_t start;
170
171 /* Address of end of memory region */
172 uintptr_t end;
173} __packed;
174
175typedef void (*coredump_backend_start_t)(void);
176typedef void (*coredump_backend_end_t)(void);
177typedef void (*coredump_backend_buffer_output_t)(uint8_t *buf, size_t buflen);
178typedef int (*coredump_backend_query_t)(enum coredump_query_id query_id,
179 void *arg);
180typedef int (*coredump_backend_cmd_t)(enum coredump_cmd_id cmd_id,
181 void *arg);
182
183struct coredump_backend_api {
184 /* Signal to backend of the start of coredump. */
185 coredump_backend_start_t start;
186
187 /* Signal to backend of the end of coredump. */
188 coredump_backend_end_t end;
189
190 /* Raw buffer output */
191 coredump_backend_buffer_output_t buffer_output;
192
193 /* Perform query on backend */
194 coredump_backend_query_t query;
195
196 /* Perform command on backend */
197 coredump_backend_cmd_t cmd;
198};
199
200void coredump(unsigned int reason, const z_arch_esf_t *esf,
201 struct k_thread *thread);
202void coredump_memory_dump(uintptr_t start_addr, uintptr_t end_addr);
203void coredump_buffer_output(uint8_t *buf, size_t buflen);
204
205int coredump_query(enum coredump_query_id query_id, void *arg);
206int coredump_cmd(enum coredump_cmd_id cmd_id, void *arg);
207
208#else
209
210void coredump(unsigned int reason, const z_arch_esf_t *esf,
211 struct k_thread *thread)
212{
213}
214
215void coredump_memory_dump(uintptr_t start_addr, uintptr_t end_addr)
216{
217}
218
219void coredump_buffer_output(uint8_t *buf, size_t buflen)
220{
221}
222
223int coredump_query(enum coredump_query_id query_id, void *arg)
224{
225 return -ENOTSUP;
226}
227
228int coredump_cmd(enum coredump_cmd_id query_id, void *arg)
229{
230 return -ENOTSUP;
231}
232
233#endif /* CONFIG_DEBUG_COREDUMP */
234
303#endif /* ZEPHYR_INCLUDE_DEBUG_COREDUMP_H_ */
static struct k_thread thread[2]
Definition: atomic.c:26
coredump_query_id
Definition: coredump.h:15
@ COREDUMP_QUERY_HAS_STORED_DUMP
Definition: coredump.h:29
@ COREDUMP_QUERY_GET_STORED_DUMP_SIZE
Definition: coredump.h:37
@ COREDUMP_QUERY_MAX
Definition: coredump.h:39
@ COREDUMP_QUERY_GET_ERROR
Definition: coredump.h:19
coredump_cmd_id
Definition: coredump.h:43
@ COREDUMP_CMD_COPY_STORED_DUMP
Definition: coredump.h:78
@ COREDUMP_CMD_MAX
Definition: coredump.h:90
@ COREDUMP_CMD_INVALIDATE_STORED_DUMP
Definition: coredump.h:88
@ COREDUMP_CMD_ERASE_STORED_DUMP
Definition: coredump.h:68
@ COREDUMP_CMD_VERIFY_STORED_DUMP
Definition: coredump.h:59
@ COREDUMP_CMD_CLEAR_ERROR
Definition: coredump.h:49
void coredump_buffer_output(uint8_t *buf, size_t buflen)
Output the buffer via coredump.
Definition: coredump.h:219
void coredump_memory_dump(uintptr_t start_addr, uintptr_t end_addr)
Dump memory region.
Definition: coredump.h:215
int coredump_cmd(enum coredump_cmd_id query_id, void *arg)
Perform command on coredump subsystem.
Definition: coredump.h:228
void coredump(unsigned int reason, const z_arch_esf_t *esf, struct k_thread *thread)
Perform coredump.
Definition: coredump.h:210
int coredump_query(enum coredump_query_id query_id, void *arg)
Perform query on coredump subsystem.
Definition: coredump.h:223
static void cmd(uint32_t command)
Execute a display list command by co-processor engine.
Definition: ft8xx_reference_api.h:153
#define ENOTSUP
Definition: errno.h:115
__INTPTR_TYPE__ off_t
Definition: types.h:36
static ZTEST_DMEM int flag
Definition: main.c:26
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINTPTR_TYPE__ uintptr_t
Definition: stdint.h:105
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
Definition: coredump.h:94
off_t offset
Definition: coredump.h:96
uint8_t * buffer
Definition: coredump.h:99
size_t length
Definition: coredump.h:102
Definition: thread.h:245
Byte order helpers.
Macros to abstract toolchain specific capabilities.