From 3942472e34e38a3591d63d1870dfd466c73fc964 Mon Sep 17 00:00:00 2001 From: Jakub Klimek Date: Wed, 27 Aug 2025 16:30:45 +0200 Subject: [PATCH 1/2] stm32l4-multi: introduce libcoredumpsrv Save target memory by including libcoredumpsrv in stm32l4-multi instead of standalone executable. JIRA: RTOS-1054 --- multi/stm32l4-multi/Makefile | 8 ++- multi/stm32l4-multi/config.h | 5 ++ multi/stm32l4-multi/coredumpsrv.c | 90 +++++++++++++++++++++++++++++ multi/stm32l4-multi/stm32l4-multi.c | 9 +++ 4 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 multi/stm32l4-multi/coredumpsrv.c diff --git a/multi/stm32l4-multi/Makefile b/multi/stm32l4-multi/Makefile index b20b6fc38..fe23afb5b 100644 --- a/multi/stm32l4-multi/Makefile +++ b/multi/stm32l4-multi/Makefile @@ -8,7 +8,7 @@ LOCAL_PATH := $(call my-dir) NAME := stm32l4-multi -LOCAL_SRCS = fs.c gpio.c i2c.c posixsrv.c rng.c rtc.c spi.c stm32l4-multi.c tty.c uart.c +LOCAL_SRCS = fs.c gpio.c i2c.c posixsrv.c rng.c rtc.c spi.c stm32l4-multi.c tty.c uart.c coredumpsrv.c ifeq ($(TARGET_SUBFAMILY),stm32l4x6) LOCAL_CFLAGS += -DMULTIDRV_STACKSZ=640 LOCAL_SRCS += adc_l4.c exti_l4.c flash.c rcc_l4.c @@ -21,4 +21,10 @@ LOCAL_HEADERS := stm32l4-multi.h DEP_LIBS := libstm32l4-multi libtty libklog LIBS := libdummyfs libklog libposixsrv +ifeq ($(COREDUMP_DISABLE),1) + LOCAL_CFLAGS += -DBUILTIN_COREDUMPSRV=0 +else + LIBS += libcoredumpsrv +endif + include $(binary.mk) diff --git a/multi/stm32l4-multi/config.h b/multi/stm32l4-multi/config.h index d1ab1569d..6bea72f59 100644 --- a/multi/stm32l4-multi/config.h +++ b/multi/stm32l4-multi/config.h @@ -488,5 +488,10 @@ #define BUILTIN_POSIXSRV 0 #endif +/* libcoredumpsrv */ +#ifndef BUILTIN_COREDUMPSRV +#define BUILTIN_COREDUMPSRV 1 +#endif + #endif diff --git a/multi/stm32l4-multi/coredumpsrv.c b/multi/stm32l4-multi/coredumpsrv.c new file mode 100644 index 000000000..9c9eddb47 --- /dev/null +++ b/multi/stm32l4-multi/coredumpsrv.c @@ -0,0 +1,90 @@ +/* + * Phoenix-RTOS + * + * STM32L4 builtin coredump server (libcoredumpsrv) + * + * Copyright 2025 Phoenix Systems + * Author: Jakub Klimek + * + * This file is part of Phoenix-RTOS. + * + * %LICENSE% + */ + +#include "config.h" + +#if BUILTIN_COREDUMPSRV + +#include +#include + +#ifndef COREDUMPSRV_PRIO +#define COREDUMPSRV_PRIO 4 +#endif + +#ifndef COREDUMP_MAX_THREADS +#define COREDUMP_MAX_THREADS 4 +#endif + +#ifndef COREDUMP_MAX_STACK_SIZE +#define COREDUMP_MAX_STACK_SIZE 0 +#endif + +#ifndef COREDUMP_MEM_SCOPE +#define COREDUMP_MEM_SCOPE COREDUMP_MEM_ALL_STACKS +#endif + +#ifndef COREDUMP_FP_CONTEXT +#define COREDUMP_FP_CONTEXT 0 +#endif + +#ifndef COREDUMP_MAX_MEM_CHUNK +#define COREDUMP_MAX_MEM_CHUNK 0 +#endif + +#ifndef COREDUMP_PRINT +#define COREDUMP_PRINT 1 +#endif + +#ifndef COREDUMP_PRINT_SLEEP +#define COREDUMP_PRINT_SLEEP 10 * 1000 /* 10ms */ +#endif + +#ifndef COREDUMP_SAVEPATH +#define COREDUMP_SAVEPATH "/coredumps" +#endif + +#ifndef COREDUMP_MAX_FILES +#define COREDUMP_MAX_FILES 0 +#endif + + +static struct { + char stack[_PAGE_SIZE]; + coredump_opts_t opts; +} coredumpsrv_common; + + +static void coredumpsrv_thr(void *arg) +{ + coredumpsrv_common.opts = (coredump_opts_t) { + .maxThreads = COREDUMP_MAX_THREADS, + .maxStackSize = COREDUMP_MAX_STACK_SIZE, + .memScope = COREDUMP_MEM_SCOPE, + .fpContext = COREDUMP_FP_CONTEXT, + .maxMemChunk = COREDUMP_MAX_MEM_CHUNK, + .print = COREDUMP_PRINT, + .printSleep = COREDUMP_PRINT_SLEEP, + .savepath = COREDUMP_SAVEPATH, + .maxFiles = COREDUMP_MAX_FILES, + }; + coredump_serverthr(&coredumpsrv_common.opts); +} + + +int coredumpsrv_start(void) +{ + return beginthread(coredumpsrv_thr, COREDUMPSRV_PRIO, coredumpsrv_common.stack, sizeof(coredumpsrv_common.stack), NULL); +} + +#endif diff --git a/multi/stm32l4-multi/stm32l4-multi.c b/multi/stm32l4-multi/stm32l4-multi.c index d8cf81613..8bbfbb41b 100644 --- a/multi/stm32l4-multi/stm32l4-multi.c +++ b/multi/stm32l4-multi/stm32l4-multi.c @@ -355,6 +355,11 @@ extern int posixsrv_start(void); #endif +#if BUILTIN_COREDUMPSRV +extern int coredumpsrv_start(void); +#endif + + int main(void) { int i; @@ -394,6 +399,10 @@ int main(void) pwm_init(); #endif +#if BUILTIN_COREDUMPSRV + coredumpsrv_start(); +#endif + /* Do this after klog init to keep shell from overtaking klog */ #if CONSOLE_IS_TTY From 38bf08d748f8a70e9153599a7ffbb7cdb915179e Mon Sep 17 00:00:00 2001 From: Jakub Klimek Date: Wed, 27 Aug 2025 16:30:45 +0200 Subject: [PATCH 2/2] imxrt-multi: introduce libcoredumpsrv Save target memory by including libcoredumpsrv in imxrt-multi instead of standalone executable. JIRA: RTOS-1054 --- multi/imxrt-multi/Makefile | 10 +++- multi/imxrt-multi/config.h | 5 ++ multi/imxrt-multi/coredumpsrv.c | 90 +++++++++++++++++++++++++++++++++ multi/imxrt-multi/imxrt-multi.c | 9 ++++ 4 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 multi/imxrt-multi/coredumpsrv.c diff --git a/multi/imxrt-multi/Makefile b/multi/imxrt-multi/Makefile index 3348c2997..fb336ff58 100644 --- a/multi/imxrt-multi/Makefile +++ b/multi/imxrt-multi/Makefile @@ -8,7 +8,7 @@ NAME := imxrt-multi LOCAL_PATH := $(call my-dir) -LOCAL_SRCS = imxrt-multi.c common.c uart.c gpio.c spi.c i2c.c fs.c posixsrv.c pct2075.c rtt.c +LOCAL_SRCS = imxrt-multi.c common.c uart.c gpio.c spi.c i2c.c fs.c posixsrv.c pct2075.c rtt.c coredumpsrv.c ifneq ($(TARGET_SUBFAMILY), imxrt117x) LOCAL_SRCS += trng.c else @@ -18,7 +18,13 @@ DEP_LIBS := libtty libklog libpseudodev i2c-common librtt LIBS := libdummyfs libklog libpseudodev libposixsrv LOCAL_HEADERS := imxrt-multi.h -# FIXME: adapt code to array-bounds checker +# FIXME: adapt code to array-bounds checker LOCAL_CFLAGS := -Wno-array-bounds +ifeq ($(COREDUMP_DISABLE),1) + LOCAL_CFLAGS += -DBUILTIN_COREDUMPSRV=0 +else + LIBS += libcoredumpsrv +endif + include $(binary.mk) diff --git a/multi/imxrt-multi/config.h b/multi/imxrt-multi/config.h index b07bfc46d..66cec2708 100644 --- a/multi/imxrt-multi/config.h +++ b/multi/imxrt-multi/config.h @@ -1436,6 +1436,11 @@ #error "BUILTIN_POSIXSRV must have a value of 0, 1, or be undefined" #endif +/* libcoredumpsrv */ +#ifndef BUILTIN_COREDUMPSRV +#define BUILTIN_COREDUMPSRV 1 +#endif + /* Pseudodev */ diff --git a/multi/imxrt-multi/coredumpsrv.c b/multi/imxrt-multi/coredumpsrv.c new file mode 100644 index 000000000..6d9d04bd7 --- /dev/null +++ b/multi/imxrt-multi/coredumpsrv.c @@ -0,0 +1,90 @@ +/* + * Phoenix-RTOS + * + * i.MX RT builtin coredump server (libcoredumpsrv) + * + * Copyright 2025 Phoenix Systems + * Author: Jakub Klimek + * + * This file is part of Phoenix-RTOS. + * + * %LICENSE% + */ + +#include "config.h" + +#if BUILTIN_COREDUMPSRV + +#include +#include + +#ifndef COREDUMPSRV_PRIO +#define COREDUMPSRV_PRIO 4 +#endif + +#ifndef COREDUMP_MAX_THREADS +#define COREDUMP_MAX_THREADS 4 +#endif + +#ifndef COREDUMP_MAX_STACK_SIZE +#define COREDUMP_MAX_STACK_SIZE 0 +#endif + +#ifndef COREDUMP_MEM_SCOPE +#define COREDUMP_MEM_SCOPE COREDUMP_MEM_ALL_STACKS +#endif + +#ifndef COREDUMP_FP_CONTEXT +#define COREDUMP_FP_CONTEXT 0 +#endif + +#ifndef COREDUMP_MAX_MEM_CHUNK +#define COREDUMP_MAX_MEM_CHUNK 0 +#endif + +#ifndef COREDUMP_PRINT +#define COREDUMP_PRINT 1 +#endif + +#ifndef COREDUMP_PRINT_SLEEP +#define COREDUMP_PRINT_SLEEP 10 * 1000 /* 10ms */ +#endif + +#ifndef COREDUMP_SAVEPATH +#define COREDUMP_SAVEPATH "/coredumps" +#endif + +#ifndef COREDUMP_MAX_FILES +#define COREDUMP_MAX_FILES 0 +#endif + + +static struct { + char stack[_PAGE_SIZE]; + coredump_opts_t opts; +} coredumpsrv_common; + + +static void coredumpsrv_thr(void *arg) +{ + coredumpsrv_common.opts = (coredump_opts_t) { + .maxThreads = COREDUMP_MAX_THREADS, + .maxStackSize = COREDUMP_MAX_STACK_SIZE, + .memScope = COREDUMP_MEM_SCOPE, + .fpContext = COREDUMP_FP_CONTEXT, + .maxMemChunk = COREDUMP_MAX_MEM_CHUNK, + .print = COREDUMP_PRINT, + .printSleep = COREDUMP_PRINT_SLEEP, + .savepath = COREDUMP_SAVEPATH, + .maxFiles = COREDUMP_MAX_FILES, + }; + coredump_serverthr(&coredumpsrv_common.opts); +} + + +int coredumpsrv_start(void) +{ + return beginthread(coredumpsrv_thr, COREDUMPSRV_PRIO, coredumpsrv_common.stack, sizeof(coredumpsrv_common.stack), NULL); +} + +#endif diff --git a/multi/imxrt-multi/imxrt-multi.c b/multi/imxrt-multi/imxrt-multi.c index 531bdeaf7..23deb6bd4 100644 --- a/multi/imxrt-multi/imxrt-multi.c +++ b/multi/imxrt-multi/imxrt-multi.c @@ -571,6 +571,11 @@ extern int posixsrv_start(void); #endif +#if BUILTIN_COREDUMPSRV +extern int coredumpsrv_start(void); +#endif + + int main(void) { int i; @@ -620,6 +625,10 @@ int main(void) posixsrv_start(); #endif +#if BUILTIN_COREDUMPSRV + coredumpsrv_start(); +#endif + #if PSEUDODEV pseudo_init(); #endif