This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git

commit 0923948d8069130c7f4ee279e58fbc548babf48e
Author: wangjianyu3 <[email protected]>
AuthorDate: Wed Aug 19 10:31:57 2026 +0800

    system/nxinit: fix event-board timing
    
    Move the boot event orchestration into a preset config buffer so the
    "init" and (optional) "netinit"/"finalinit" events are triggered as a
    serialized chain rather than queued back-to-back in main(). This fixes
    the timing between preset event initialization and board initialization.
    
    Adapted for the community tree: BOARDIOC_INIT has been removed upstream
    (replaced by CONFIG_BOARD_LATE_INITIALIZE), so no board_init/board_finalinit
    builtins are added and no 
boardctl(BOARDIOC_INIT)/boardctl(BOARDIOC_FINALINIT)
    calls are reintroduced; board device init is now performed by the kernel
    before init starts.
    
    netinit is not a boardctl call, so it is kept in the serialized event
    chain like the original: add a "netinit" builtin that calls
    netinit_bringup(), driven by "on init -> trigger netinit -> on netinit",
    instead of calling netinit_bringup() directly in main(). finalinit
    remains a pure event for user-defined services to hook.
    
    Assisted-by: GitHubCopilot:claude-opus-4.8
    Signed-off-by: wangjianyu3 <[email protected]>
---
 system/nxinit/builtin.c | 18 ++++++++++++++++++
 system/nxinit/init.c    | 14 --------------
 system/nxinit/parser.c  | 23 +++++++++++++++++++++++
 3 files changed, 41 insertions(+), 14 deletions(-)

diff --git a/system/nxinit/builtin.c b/system/nxinit/builtin.c
index 8ebeb4c02..f0097d90c 100644
--- a/system/nxinit/builtin.c
+++ b/system/nxinit/builtin.c
@@ -33,6 +33,8 @@
 #include <sys/param.h>
 #include <sys/wait.h>
 
+#include <netutils/netinit.h>
+
 #include "builtin.h"
 #include "init.h"
 #include "property.h"
@@ -81,6 +83,10 @@ static int cmd_boot(FAR struct action_manager_s *am,
 static int cmd_start_cpu(FAR struct action_manager_s *am,
                          int argc, FAR char **argv);
 #endif
+#ifdef CONFIG_NETUTILS_NETINIT
+static int cmd_netinit(FAR struct action_manager_s *am,
+                       int argc, FAR char **argv);
+#endif
 
 /****************************************************************************
  * Private Data
@@ -93,6 +99,9 @@ static const struct cmd_map_s g_builtin[] =
 #endif
 #ifdef CONFIG_BOARDCTL_START_CPU
   {"start_cpu", 1, 3, cmd_start_cpu},
+#endif
+#ifdef CONFIG_NETUTILS_NETINIT
+  {"netinit", 1, 1, cmd_netinit},
 #endif
   {"class_start", 2, 2, cmd_class_start},
   {"class_stop", 2, 2, cmd_class_stop},
@@ -152,6 +161,15 @@ static int cmd_start_cpu(FAR struct action_manager_s *am,
 }
 #endif
 
+#ifdef CONFIG_NETUTILS_NETINIT
+static int cmd_netinit(FAR struct action_manager_s *am,
+                       int argc, FAR char **argv)
+{
+  UNUSED(am);
+  return netinit_bringup();
+}
+#endif
+
 static int cmd_class_start(FAR struct action_manager_s *am,
                            int argc, FAR char **argv)
 {
diff --git a/system/nxinit/init.c b/system/nxinit/init.c
index e4b62f3d6..2c2bcb166 100644
--- a/system/nxinit/init.c
+++ b/system/nxinit/init.c
@@ -29,11 +29,8 @@
 #include <errno.h>
 #include <poll.h>
 #include <sys/param.h>
-#include <sys/boardctl.h>
 #include <sys/wait.h>
 
-#include <netutils/netinit.h>
-
 #include "action.h"
 #include "builtin.h"
 #include "init.h"
@@ -190,17 +187,6 @@ int main(int argc, FAR char *argv[])
 
   init_action_add_event(&am, "boot");
 
-  init_action_add_event(&am, "init");
-
-#ifdef CONFIG_NETUTILS_NETINIT
-  netinit_bringup();
-  init_action_add_event(&am, "netinit");
-#endif
-
-#ifdef CONFIG_SYSTEM_NXINIT_FINALINIT
-  init_action_add_event(&am, "finalinit");
-#endif
-
   for (; ; )
     {
       int t1 = init_service_refresh(&sm);
diff --git a/system/nxinit/parser.c b/system/nxinit/parser.c
index 49193487f..ced92a2d8 100644
--- a/system/nxinit/parser.c
+++ b/system/nxinit/parser.c
@@ -331,11 +331,34 @@ out:
 
 int init_parse_configs(FAR const struct parser_s *parser)
 {
+  static const char preset[] =
+    "on boot\n"
+    "   trigger init\n"
+#if defined(CONFIG_NETUTILS_NETINIT) || defined(CONFIG_SYSTEM_NXINIT_FINALINIT)
+    "on init\n"
+#ifdef CONFIG_NETUTILS_NETINIT
+    "   trigger netinit\n"
+#endif
+#ifdef CONFIG_SYSTEM_NXINIT_FINALINIT
+    "   trigger finalinit\n"
+#endif
+#endif
+#ifdef CONFIG_NETUTILS_NETINIT
+    "on netinit\n"
+    "   netinit\n"
+#endif
+    ;
   FAR const char *path = CONFIG_SYSTEM_NXINIT_RC_FILE_PATH;
   FAR const char *ext;
   char file[PATH_MAX];
   int ret;
 
+  ret = init_parse_config_buffer(parser, preset, sizeof(preset));
+  if (ret < 0)
+    {
+      return ret;
+    }
+
   ret = init_parse_config_file(parser, path);
   if (ret < 0)
     {

Reply via email to