From d468ccce62e4d48fc726ef9f883159f2ca3baa47 Mon Sep 17 00:00:00 2001 From: Alessandro Gatti Date: Sun, 30 Nov 2025 11:05:57 +0100 Subject: [PATCH] extmod/modopenamp: Rework trace buffer setup procedure. This commit reworks the setup procedure for the OpenAMP trace buffer, used by the libmetal framework to provide cross-core logging data if needed. Before these changes, the buffer was provided by MicroPython, as a fixed size 128 bytes chunk that was accidentally put into the .rodata section, making it not usable for its intended purpose. Now, a buffer placed in .bss with a default size of 128 bytes is provided by MicroPython unless chosen otherwise. A user-chosen buffer pointer can be provided to MicroPython using the MICROPY_PY_OPENAMP_TRACE_BUF preprocessor definition. If what MicroPython provides by default is fine, the buffer size can be overridden with a new value for the MICROPY_PY_OPENAMP_TRACE_BUF_LEN preprocessor definition instead. Signed-off-by: Alessandro Gatti --- extmod/modopenamp.c | 9 +++++---- extmod/modopenamp.h | 6 ++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/extmod/modopenamp.c b/extmod/modopenamp.c index 7d5841c400..b5e813495b 100644 --- a/extmod/modopenamp.c +++ b/extmod/modopenamp.c @@ -80,11 +80,12 @@ #define VRING_BUFF_ADDR (METAL_SHM_ADDR + 0x2000) #define VRING_BUFF_SIZE (METAL_SHM_SIZE - 0x2000) -#if MICROPY_PY_OPENAMP_HOST -static const char openamp_trace_buf[128]; +#if MICROPY_PY_OPENAMP_HOST && MICROPY_PY_OPENAMP_TRACE_BUF_ENABLE +#ifndef MICROPY_PY_OPENAMP_TRACE_BUF +static char openamp_trace_buf[MICROPY_PY_OPENAMP_TRACE_BUF_LEN]; #define MICROPY_PY_OPENAMP_TRACE_BUF ((uint32_t)openamp_trace_buf) -#define MICROPY_PY_OPENAMP_TRACE_BUF_LEN sizeof(MICROPY_PY_OPENAMP_TRACE_BUF) -#endif // MICROPY_PY_OPENAMP_HOST +#endif // MICROPY_PY_OPENAMP_TRACE_BUF +#endif // MICROPY_PY_OPENAMP_HOST && MICROPY_PY_OPENAMP_TRACE_BUF_ENABLE #endif // MICROPY_PY_OPENAMP_RSC_TABLE_ENABLE diff --git a/extmod/modopenamp.h b/extmod/modopenamp.h index 8f677788f9..463399507b 100644 --- a/extmod/modopenamp.h +++ b/extmod/modopenamp.h @@ -47,6 +47,12 @@ #define MICROPY_PY_OPENAMP_TRACE_BUF_ENABLE (1) #endif +// Set the default trace buffer size, making it 128 bytes long unless +// marked otherwise. +#ifndef MICROPY_PY_OPENAMP_TRACE_BUF_LEN +#define MICROPY_PY_OPENAMP_TRACE_BUF_LEN (128) +#endif + // For ports that don't define a custom image store, this enables a generic // VFS-based image store that supports loading elf files from storage. #ifndef MICROPY_PY_OPENAMP_REMOTEPROC_STORE_ENABLE