From e38e55a26cb9b2dbe541c5ebb434cbe21ed391a2 Mon Sep 17 00:00:00 2001 From: Ray Morris Date: Mon, 28 Apr 2025 17:27:07 -0500 Subject: [PATCH] dmesg: log init messages to RAM until serial init --- src/main/common/log.c | 17 +++++++++++++++++ src/main/fc/cli.c | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/main/common/log.c b/src/main/common/log.c index 49eb5a8b98..7c8ecac4d4 100644 --- a/src/main/common/log.c +++ b/src/main/common/log.c @@ -61,6 +61,11 @@ PG_RESET_TEMPLATE(logConfig_t, logConfig, .topics = SETTING_LOG_TOPICS_DEFAULT ); +#if defined(DMESG_SIZE) +char dmesg_buffer[DMESG_SIZE]; +char *dmesg_head = dmesg_buffer; +#endif + void logInit(void) { const serialPortConfig_t *portConfig = findSerialPortConfig(FUNCTION_LOG); @@ -135,6 +140,18 @@ static void logPrint(const char *buf, size_t size) } else if (mspLogPort) { mspSerialPushPort(MSP_DEBUGMSG, (uint8_t*)buf, size, mspLogPort, MSP_V2_NATIVE); } + +#ifdef DMESG_SIZE + if ( (dmesg_head + size + 2) < (dmesg_buffer + DMESG_SIZE) ) { + for (unsigned int ii = 0; ii < size; ii++) { + *dmesg_head = buf[ii]; + dmesg_head++; + } + dmesg_head[0] = '\r'; + dmesg_head[1] = '\n'; + dmesg_head = dmesg_head + 2; + } +#endif } static size_t logFormatPrefix(char *buf, const timeMs_t timeMs) diff --git a/src/main/fc/cli.c b/src/main/fc/cli.c index 39305d77f3..572d3ba32a 100644 --- a/src/main/fc/cli.c +++ b/src/main/fc/cli.c @@ -130,6 +130,11 @@ bool cliMode = false; extern timeDelta_t cycleTime; // FIXME dependency on mw.c extern uint8_t detectedSensors[SENSOR_INDEX_COUNT]; +#ifdef DMESG_SIZE +extern char dmesg_buffer[DMESG_SIZE]; +extern char *dmesg_head; +#endif + static serialPort_t *cliPort; static bufWriter_t *cliWriter; @@ -4798,6 +4803,16 @@ static void cliUbloxPrintSatelites(char *arg) } #endif +#ifdef DMESG_SIZE +static void printDmesg(char *cmdline __attribute__((unused))) { + int size = dmesg_head - dmesg_buffer; + cliPrintLinef("log size written: %i", size); + for (int ii = 0; ii < size; ii++) { + cliWrite(dmesg_buffer[ii]); + } +} +#endif + static void cliHelp(char *cmdline); // should be sorted a..z for bsearch() @@ -4829,6 +4844,9 @@ const clicmd_t cmdTable[] = { CLI_COMMAND_DEF("dfu", "DFU mode on reboot", NULL, cliDfu), CLI_COMMAND_DEF("diff", "list configuration changes from default", "[master|battery_profile|control_profile|mixer_profile|rates|all] {showdefaults}", cliDiff), +#ifdef DMESG_SIZE + CLI_COMMAND_DEF("dmesg", "init log (DMESG_SIZE)", NULL, printDmesg), +#endif CLI_COMMAND_DEF("dump", "dump configuration", "[master|battery_profile|control_profile|mixer_profile|rates|all] {showdefaults}", cliDump), #ifdef USE_RX_ELERES