boards: Simplify NuttX initialization#18408
boards: Simplify NuttX initialization#18408linguini1 wants to merge 18 commits intoapache:masterfrom
Conversation
|
Notes for reviewers on the initial draft:
|
|
@linguini1 this is a great initiative. |
Hi @fdcavalcanti, if you're talking about making the changes, I think all ESP boards should be included in this patch already (xtensa/risc-v). They were actually quite easy since the board_late_init and board_app_init logic were pretty much identical. If you're talking about how to test, the process would be to configure the build system for one of the modified ESP32 configurations (i.e. nsh) and just boot into NuttX, check that things look okay and run Hope I understood correctly, thanks for your help! |
f30db82 to
31a4ad2
Compare
|
This PR is now ready! I just finished removing the remaining references to board_app_initialize everywhere, so aside from unintended bugs, everything is in place. What needs to happen now is some pretty extensive testing (right now I have only done a few QEMU/sim boards) to make sure there were no human errors/unintended consequences :)
I think that would be good! I must admit though, I am not the most familiar with the boot process. This PR only modifies a very small subset of it. TLDR: Note: users can still control init from userspace in extreme cases by making their own implementation of BOARDIOC_FINALINIT.
What kind of naming are you thinking of? I don't really want to play around with too many changes since that will delay this PR and could introduce more margin of error. Right now all I've done is strictly replace all |
|
The only thing that puzzles me about this change is how the "init thread" aligns with safety standards. This mechanism creates a thread that is later destroyed, which isn't entirely desirable for safety critical applications. But on the other hand, "init thread" is part of the system initialization process, and during the initialization phase, dynamic memory allocation is tolerated, but I'm not sure about deallocation. The goal here is that in the event of a board initialization failure, the system is in a known safe state. |
|
The initial thread is never destroyed: Prior to going into multi-tasking mode, it does single-thread system bringup. Then when the operating system is initialized and threading is start, it gets renamed the IDLE loop. It just jumps into the IDLE loop with the lowest possible priority. When nothing else is running, the IDLE thread runs. This is for the life of the system.
Greg
…________________________________
From: Mateusz Szafoni ***@***.***>
Sent: Friday, February 20, 2026 12:17 AM
To: apache/nuttx ***@***.***>
Cc: patacongo ***@***.***>; Review requested ***@***.***>
Subject: Re: [apache/nuttx] boards: Simplify NuttX initialization (PR #18408)
[https://avatars.githubusercontent.com/u/6563055?s=20&v=4]raiden00pl left a comment (apache/nuttx#18408)<#18408 (comment)>
The only thing that puzzles me about this change is how the "init thread" aligns with safety standards. This mechanism creates a thread that is later destroyed, which isn't entirely desirable for safety critical applications. But on the other hand, "init thread" is part of the system initialization process, and during the initialization phase, dynamic memory allocation and deallocation is tolerated. The goal here is that in the event of a board initialization failure, the system is in a known safe state.
So, I think it still fits within the acceptable use of dynamic memory for safety critical apps, but not sure. Ultimately, there's always BOARDIOC_FINALINIT option, which allows users to get rid of the "init thread" and perform initialization in "main", just like old BOARDIOC_INIT.
—
Reply to this email directly, view it on GitHub<#18408 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ABFUG6SSZNLV5ZRQJYZG3QD4M27LHAVCNFSM6AAAAACVUO2FE6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTSMZSGM2DMMZQGE>.
You are receiving this because your review was requested.Message ID: ***@***.***>
|
|
hi @patacongo :) I think Lines 749 to 771 in 34f5238 Board late init ( Lines 409 to 417 in 34f5238 and finally some resources are freed:
|
|
Hi, |
|
Nx_bringup() just starts some threads and returns. It does not exit. See "Bring Up the System"; it is just a sequence of function calls and still exists after the bring-up is complete. When it returns, it just falls through and becomes the IDLE loop. Nothing starts the IDLE loop, See "Enter to idleloop". The IDLE was just created from nothing at power-up, what was the initialization thread is simple called the IDLE loop after that point.
Maybe things have changed. Can you show me where the initialization thread exits? It shouldn't. Can you show where the IDLE thread is created. It should already exist.
Greg
…________________________________
From: Mateusz Szafoni ***@***.***>
Sent: Friday, February 20, 2026 5:17 AM
To: apache/nuttx ***@***.***>
Cc: patacongo ***@***.***>; Mention ***@***.***>
Subject: Re: [apache/nuttx] boards: Simplify NuttX initialization (PR #18408)
[https://avatars.githubusercontent.com/u/6563055?s=20&v=4]raiden00pl left a comment (apache/nuttx#18408)<#18408 (comment)>
hi @patacongo<https://github.com/patacongo> :)
I think nx_start() became IDLE thread:
https://github.com/apache/nuttx/blob/34f52384d870a8ded11e611441c615992f7d57cf/sched/init/nx_start.c#L749-L771
Board late init (CONFIG_BOARD_LATE_INITIALIZE=y) just exit after work is done:
https://github.com/apache/nuttx/blob/34f52384d870a8ded11e611441c615992f7d57cf/sched/init/nx_bringup.c#L409-L417
and finally some resources are freed:
image.png (view on web)<https://github.com/user-attachments/assets/604538db-d59f-46f8-9389-9e5a0d2df28e>
—
Reply to this email directly, view it on GitHub<#18408 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ABFUG6R3NEBHW2ILYZLLYN34M4CP7AVCNFSM6AAAAACVUO2FE6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTSMZUGQ4DEMZRGE>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Thank you for testing! |
That's a good point. I wonder if it would be worth making board_late_initialize synchronous instead of a thread? |
That's the point. It creates "AppBringUp" that runs
@linguini1 board initialization must be performed in the "thread context", not "init context". More advanced drivers require kernel features that are not available in the "init context" |
BREAKING: In an effort to simplify NuttX initialization, NSH_ARCHINIT is removed. board_app_initialize is also removed. BOARD_LATE_INITIALIZE now performs all board initialization logic, and is by default enabled. All references to these symbols are removed. BOARDIOC_INIT remains, but will result in -ENOTTY when called. It is to be removed in a later commit. Quick fix: Boards relying on NSH_ARCHINIT should now enable CONFIG_BOARD_LATE_INITIALIZE instead. If the application needs fine-grained control over board initialization from userspace, the logic performed by BOARDIOC_INIT may be copied to the board_finalinitialize function and used instead via BOARDIOC_FINALINIT. All board_app_initialize logic provided by NuttX is now moved to board_late_initialize, and the same should be done for out-of-tree boards. Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
Logic provided by board_app_initialize is replaced by board_late_initialize. Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
Logic provided by board_app_initialize is removed due to the removal of BOARDIOC_INIT boardctl command. Logic inside board_late_initialize is to be used and is identical. Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
Replaced board_app_initialize logic with board_late_initialize. Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
Replaced board_app_initialize logic with board_late_initialize. Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
Replaced board_app_initialize logic with board_late_initialize. Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
Replaced board_app_initialize logic with board_late_initialize. Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
Replaced board_app_initialize logic with board_late_initialize. Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
Replaced board_app_initialize logic with board_late_initialize. Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
Replaced board_app_initialize logic with board_late_initialize. Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
Replaced board_app_initialize logic with board_late_initialize. Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
Replaced board_app_initialize logic with board_late_initialize. Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
Replaced board_app_initialize logic with board_late_initialize. Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
Replaced board_app_initialize logic with board_late_initialize. Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
Replaced board_app_initialize logic with board_late_initialize. Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
Replaced board_app_initialize logic with board_late_initialize. Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
Replaced board_app_initialize logic with board_late_initialize. Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
Replaced board_app_initialize logic with board_late_initialize. Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
31a4ad2 to
735ed55
Compare
|
To try and get the CI at least to verify the PR (since it's quite an undertaking to do manually), I have put back |

Summary
BREAKING CHANGE
This change simplifies the NuttX initialization logic by:
board_app_initialize did so any defconfigs relying on NSH_ARCHINIT will not
break.
This is related to #11321.
Twin PR in NuttX apps should be merged at the same time: apache/nuttx-apps#3405
Impact
Almost every single board/configuration in the NuttX source tree, since many
relied on NSH for initialization.
This is a breaking change that removes the user's ability to use BOARDIOC_INIT
as well. Users are provided with quick-fixes in the commit messages for how to
fix any breakages. BOARDIOC_FINALINIT should be used instead for applications
that truly require full control over the initialization process. For every other
application, BOARD_LATE_INITIALIZE should be enabled to have the NuttX kernel
perform initialization before launching into the app.
Testing
I will be testing on the platforms available to me (simulators and whatever
hardware I own). Testing from community members with hardware across the
architectures affected would be greatly appreciated. If you do want to help with
testing, please provide logs in the PR comments for the affected defconfigs you
tested.
Testing of applications can be seen in the twin PR: apache/nuttx-apps#3405
OS Test logs
sim:nsh: sim-nsh.txtqemu-armv8a:nsh: qemu-armv8a-nsh.txtqemu-armv7a:nsh: qemu-armv7a-nsh.txtrv-virt:nsh: rv-virt-nsh.txt