boot: zephyr: Capture lost early and late log events#2637
boot: zephyr: Capture lost early and late log events#2637de-nordic merged 1 commit intomcu-tools:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates MCUboot’s Zephyr port logging behavior to reduce lost deferred logs and to avoid unnecessarily disabling logging when serial recovery is active and the log transport is not UART.
Changes:
- Start the custom deferred log processing thread immediately (
K_NO_WAIT) rather than after the polling interval delay. - Wake the log processing thread during shutdown via
k_wakeup()to drain logs without waiting for the next sleep interval. - Make
ZEPHYR_BOOT_LOG_STOP()conditional onCONFIG_LOG_BACKEND_UART(no-op for non-UART backends).
Comments suppressed due to low confidence (1)
boot/zephyr/main.c:486
zephyr_boot_log_stop()intends to wait for the logging thread to exit, butboot_log_semis defined with an initial count of 1, so the firstk_sem_take(..., K_FOREVER)will typically return immediately and not wait forboot_log_thread_func()tok_sem_give(). To make this a real join/drain, initialize the semaphore to 0 (or take it before starting the thread) sozephyr_boot_log_stop()blocks until the thread signals completion.
* This can be reworked using a thread_join() API once a such will be
* available in zephyr.
* see https://github.com/zephyrproject-rtos/zephyr/issues/21500
*/
(void)k_sem_take(&boot_log_sem, K_FOREVER);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
216d289 to
27c8c25
Compare
I updated this based on the Copilot feedback. Can someone double check this to confirm it's corrected behavior? It sounds correct to me... |
27c8c25 to
7f90296
Compare
7f90296 to
865e762
Compare
nordicjm
left a comment
There was a problem hiding this comment.
Fix is ok but title is wrong, change to boot: zephyr: Fix deferred logging before jumping to app or similar
|
by title, I mean git commit title, that needs updating |
The deferred logging thread starts after a polling-interval delay and stops without waking, leaving a window where final log messages are lost before MCUboot jumps to the application. Start the logging thread with K_NO_WAIT so messages are processed immediately. Wake the thread in zephyr_boot_log_stop() so it drains the buffer without waiting for the next polling interval. Signed-off-by: Jay Beavers <jay@tolttechnologies.com>
865e762 to
0be74f9
Compare
Problem
When using SWO deferred logging, I noticed lost early and late log messages in my swoviewer.
Summary
boot_log_seminitial count from 1 to 0 sozephyr_boot_log_stop()actually blocks until the logging thread finishes draining — previously the semaphore was already signaled at init, sok_sem_takereturned immediately without waitingK_NO_WAITinstead of a polling-interval delay so log messages are processed immediatelyzephyr_boot_log_stop()viak_wakeup()so it drains the buffer without waiting for the next polling intervalTest plan