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