diff --git a/Documentation/debugging/tasktraceuser.rst b/Documentation/debugging/tasktraceuser.rst index 06dd8b1351f..6756366fc59 100644 --- a/Documentation/debugging/tasktraceuser.rst +++ b/Documentation/debugging/tasktraceuser.rst @@ -357,3 +357,41 @@ If no command parameters are specified, display the current filter settings as t 11 15 +System Startup and Board Initialization Trace +============================================= + +NuttX has trace points during system startup and board initialization. + +These trace points include: +- System startup phases (e.g., BOOT, TASKLISTS, MEMORY, HARDWARE, OSREADY, IDLELOOP) +- Entry and exit of board_early_initialize() and board_late_initialize() +- System RESET and PANIC events + +This information helps analyze the boot process and locate issues related to board initialization or early system failures. + +How to capture startup and board initialization trace +----------------------------------------------------- +1. **Ensure trace-related kernel configs are enabled** (see configuration section above). +2. **Boot the system normally**; the trace driver will automatically record these early trace points. +3. After boot, export the trace data with: + +.. code-block:: + + nsh> trace dump boot_trace.txt + +4. Open boot_trace.txt in Trace Compass. You will see the timeline of each phase, board early/late init boundaries, and RESET/PANIC events. + +Common trace events during the startup +-------------------------------------- +- ``sched_trace_mark("BOOT")`` : Entering BOOT phase +- ``sched_trace_mark("TASKLISTS")`` : Initializing task lists +- ``sched_trace_mark("MEMORY")`` : Memory manager available +- ``sched_trace_mark("HARDWARE")`` : Hardware resources initialized +- ``sched_trace_mark("OSREADY")`` : Multitasking ready +- ``sched_trace_mark("IDLELOOP")`` : Entering idle loop +- ``boards_trace_begin/end()`` : Entry/exit of board_early_initialize/board_late_initialize +- ``sched_trace_mark("RESET")`` : System reset +- ``sched_trace_mark("PANIC")`` : System panic + +**Tip:** If you need to analyze boot or board initialization issues, always export and review the boot phase trace data first. This can help you quickly locate the problematic stage. + diff --git a/boards/boardctl.c b/boards/boardctl.c index d61a5515509..d5c4a0d69dd 100644 --- a/boards/boardctl.c +++ b/boards/boardctl.c @@ -36,10 +36,12 @@ #include #include #include +#include #include #include #include #include +#include #ifdef CONFIG_NX # include @@ -412,6 +414,8 @@ int boardctl(unsigned int cmd, uintptr_t arg) case BOARDIOC_RESET: { + g_nx_initstate = OSINIT_RESET; + sched_trace_mark("RESET"); reboot_notifier_call_chain(SYS_RESTART, (FAR void *)arg); up_flush_dcache_all(); ret = board_reset((int)arg); diff --git a/include/nuttx/init.h b/include/nuttx/init.h index f54a4f9dce3..bcc9a24c2f0 100644 --- a/include/nuttx/init.h +++ b/include/nuttx/init.h @@ -73,7 +73,8 @@ enum nx_initstate_e OSINIT_OSREADY = 5, /* The OS is fully initialized and multi-tasking is * active. */ OSINIT_IDLELOOP = 6, /* The OS enter idle loop. */ - OSINIT_PANIC = 7 /* Fatal error happened. */ + OSINIT_RESET = 7, /* The OS is in resetting process. */ + OSINIT_PANIC = 8 /* Fatal error happened. */ }; /**************************************************************************** diff --git a/sched/init/nx_bringup.c b/sched/init/nx_bringup.c index 5ba9806df91..0f5ea706c05 100644 --- a/sched/init/nx_bringup.c +++ b/sched/init/nx_bringup.c @@ -318,7 +318,9 @@ static inline void nx_start_application(void) * configured. */ + boards_trace_begin(); board_late_initialize(); + boards_trace_end(); #endif #ifdef CONFIG_COREDUMP diff --git a/sched/init/nx_start.c b/sched/init/nx_start.c index ef04b1fbf95..b6a44f432cb 100644 --- a/sched/init/nx_start.c +++ b/sched/init/nx_start.c @@ -508,6 +508,7 @@ void nx_start(void) /* Boot up is complete */ g_nx_initstate = OSINIT_BOOT; + sched_trace_mark("BOOT"); /* Initialize task list table *********************************************/ @@ -520,6 +521,7 @@ void nx_start(void) /* Task lists are initialized */ g_nx_initstate = OSINIT_TASKLISTS; + sched_trace_mark("TASKLISTS"); /* Initialize RTOS Data ***************************************************/ @@ -613,6 +615,7 @@ void nx_start(void) /* The memory manager is available */ g_nx_initstate = OSINIT_MEMORY; + sched_trace_mark("MEMORY"); /* Initialize tasking data structures */ @@ -682,12 +685,15 @@ void nx_start(void) * that cannot wait until board_late_initialize. */ + boards_trace_begin(); board_early_initialize(); + boards_trace_end(); #endif /* Hardware resources are now available */ g_nx_initstate = OSINIT_HARDWARE; + sched_trace_mark("HARDWARE"); /* Setup for Multi-Tasking ************************************************/ @@ -734,6 +740,7 @@ void nx_start(void) /* The OS is fully initialized and we are beginning multi-tasking */ g_nx_initstate = OSINIT_OSREADY; + sched_trace_mark("OSREADY"); /* Create initial tasks and bring-up the system */ @@ -742,6 +749,7 @@ void nx_start(void) /* Enter to idleloop */ g_nx_initstate = OSINIT_IDLELOOP; + sched_trace_mark("IDLELOOP"); /* Let other threads have access to the memory manager */ diff --git a/sched/misc/assert.c b/sched/misc/assert.c index 8da7a1a9953..015e32603c9 100644 --- a/sched/misc/assert.c +++ b/sched/misc/assert.c @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -860,6 +861,7 @@ void _assert(FAR const char *filename, int linenum, /* Fatal error, enter panic state. */ g_nx_initstate = OSINIT_PANIC; + sched_trace_mark("PANIC"); /* Disable KASAN to avoid false positive */