Skip to content

Commit 769c4f2

Browse files
Appana Durga Kedareswara raofabiobaltieri
authored andcommitted
samples: debug: coredump_udp_demos: add shell-triggered UDP coredump demo
Add demo_shell under samples/subsys/debug/coredump_udp_demos/. The sample boots with a Zephyr shell on UART; the user runs coredump_crash to trigger a deliberate null-pointer dereference. The DEBUG_COREDUMP_BACKEND_LOGGING_UDP backend captures the resulting coredump and transmits it as framed UDP datagrams to the configured peer. A custom k_sys_fatal_error_handler() halts after the dump to prevent reboots that would truncate in-flight datagrams. prj.conf enables dual-stack networking with 192.0.2.x placeholders; the boards/versalnet_apu.conf overlay supplies lab-local 10.10.70.x addresses for Versal Net APU testing on tenzing2 hardware. Signed-off-by: Appana Durga Kedareswara rao <appana.durga.kedareswara.rao@amd.com>
1 parent 810c3c8 commit 769c4f2

6 files changed

Lines changed: 139 additions & 0 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(coredump_udp_demo_shell)
7+
8+
target_sources(app PRIVATE src/main.c)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
.. zephyr:code-sample:: coredump-udp-demo-shell
2+
:name: UDP coredump via shell
3+
4+
Fault from the Zephyr shell; the coredump is mirrored as UART ``#CD:`` hex and framed UDP.
5+
6+
.. SPDX-License-Identifier: Apache-2.0
7+
8+
Overview
9+
========
10+
11+
Zephyr shell stays running on the serial console. Run **``coredump_crash``**
12+
to fault the board; with **``CONFIG_DEBUG_COREDUMP_BACKEND_LOGGING_UDP``**
13+
the coredump byte stream is mirrored as ``#CD:`` hex on the UART and sent
14+
as framed UDP to **``CONFIG_DEBUG_COREDUMP_LOGGING_UDP_HOST``** (syntax is
15+
whatever ``net_ipaddr_parse()`` accepts, e.g. ``192.0.2.2``, ``192.0.2.2:17777``,
16+
``[2001:db8::1]:17777``; port defaults to **17777** when omitted).
17+
18+
Board overlay **``boards/versalnet_apu.conf``** sets lab-style static IPv4;
19+
adjust for your bench. Networking and UDP coredump options live in
20+
**``prj.conf``** (defaults use ``192.0.2.x`` before the overlay applies).
21+
22+
See :ref:`coredump` and :zephyr_file:`subsys/debug/coredump/coredump_backend_logging_udp.c`.
23+
24+
Build
25+
=====
26+
27+
.. zephyr-app-commands::
28+
:zephyr-app: samples/subsys/debug/coredump_udp_demos/demo_shell
29+
:board: versalnet_apu
30+
:goals: build
31+
:compact:
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
CONFIG_NET_CONFIG_MY_IPV4_ADDR="10.10.70.1"
4+
CONFIG_NET_CONFIG_PEER_IPV4_ADDR="10.10.70.101"
5+
CONFIG_DEBUG_COREDUMP_LOGGING_UDP_HOST="10.10.70.101"
6+
CONFIG_COMPILER_WARNINGS_AS_ERRORS=n
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
CONFIG_SHELL=y
4+
CONFIG_SHELL_STACK_SIZE=8192
5+
CONFIG_SHELL_BACKEND_SERIAL=y
6+
CONFIG_SHELL_REMOTE=n
7+
8+
# Network stack + logging/UDP coredump backend (defaults 192.0.2.x).
9+
CONFIG_MAIN_STACK_SIZE=4096
10+
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096
11+
12+
CONFIG_NETWORKING=y
13+
CONFIG_NET_IPV4=y
14+
CONFIG_NET_IPV6=y
15+
CONFIG_NET_UDP=y
16+
CONFIG_NET_TCP=n
17+
CONFIG_NET_SOCKETS=y
18+
CONFIG_NET_CONNECTION_MANAGER=y
19+
# zsock_socket()+zsock_bind() in the L4_CONNECTED callback need more mgmt stack
20+
CONFIG_NET_MGMT_EVENT_STACK_SIZE=2048
21+
22+
CONFIG_ENTROPY_GENERATOR=y
23+
CONFIG_TEST_RANDOM_GENERATOR=y
24+
25+
CONFIG_LOG=y
26+
CONFIG_PRINTK=y
27+
28+
CONFIG_NET_PKT_RX_COUNT=16
29+
CONFIG_NET_PKT_TX_COUNT=16
30+
CONFIG_NET_BUF_RX_COUNT=64
31+
CONFIG_NET_BUF_TX_COUNT=64
32+
CONFIG_NET_CONTEXT_NET_PKT_POOL=y
33+
34+
CONFIG_NET_CONFIG_SETTINGS=y
35+
CONFIG_NET_CONFIG_NEED_IPV4=y
36+
CONFIG_NET_CONFIG_AUTO_INIT=y
37+
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1"
38+
CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.2"
39+
40+
CONFIG_DEBUG_COREDUMP_LOGGING_UDP_HOST="192.0.2.2"
41+
42+
CONFIG_DEBUG_COREDUMP=y
43+
CONFIG_DEBUG_COREDUMP_BACKEND_LOGGING_UDP=y
44+
CONFIG_DEBUG_COREDUMP_MEMORY_DUMP_MIN=y
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
sample:
3+
name: UDP coredump via shell
4+
tests:
5+
sample.debug.coredump_udp_demo_shell:
6+
build_only: true
7+
platform_allow: versalnet_apu
8+
tags: debug coredump
9+
extra_configs:
10+
- CONFIG_NET_NAMESPACE_COMPAT_MODE=n
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2026 Advanced Micro Devices, Inc.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Demo: stay running; user types shell command to trigger fault (good for repeatable UDP runs).
7+
*/
8+
9+
#include <zephyr/kernel.h>
10+
#include <zephyr/shell/shell.h>
11+
#include <zephyr/sys/printk.h>
12+
#include <zephyr/debug/coredump.h>
13+
14+
void k_sys_fatal_error_handler(unsigned int reason, const struct arch_esf *pEsf)
15+
{
16+
ARG_UNUSED(pEsf);
17+
18+
printk("%s is expected; reason = %u; halting ...\n", __func__, reason);
19+
k_fatal_halt(reason);
20+
}
21+
22+
static int cmd_coredump_crash(const struct shell *sh, size_t argc, char **argv)
23+
{
24+
ARG_UNUSED(argc);
25+
ARG_UNUSED(argv);
26+
27+
shell_print(sh, "Triggering null deref for coredump (UDP + UART)...");
28+
uint32_t *p = NULL;
29+
30+
*p = 0;
31+
return 0;
32+
}
33+
34+
SHELL_CMD_REGISTER(coredump_crash, NULL, "Trigger coredump via fault", cmd_coredump_crash);
35+
36+
int main(void)
37+
{
38+
printk("demo_shell: %s — open shell, run: coredump_crash\n", CONFIG_BOARD);
39+
return 0;
40+
}

0 commit comments

Comments
 (0)