From 837b45c5bef77041be83e2b9048bcbf0285e392e Mon Sep 17 00:00:00 2001 From: wangjianyu3 Date: Thu, 14 Aug 2025 21:45:53 +0800 Subject: [PATCH 1/7] system/nxinit: Add NuttX Init MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This component (abbreviated as "NxInit") is specifically developed for NuttX and intended for system initialization. While we have adopted the Android Init Language among various syntax options, this is a brand-new implementation—it is not a port or variant of Android Init. Refer to the implementation of Android Init Language, consists of five broad classes of statements: Actions, Commands, Services, Options, and Imports. Actions support two types of triggers: event and action. Action triggers also support runtime triggering. Services support lifecycle management, including automatic restart (at specified intervals), and starting/stopping individually or by class. Import supports files or directories, and we may add a static method in the future. The following are some differences: 1. The Android Init Language treats lines starting with `#` as comments, while we use a preprocessor to handle comments. 2. For action commands, we can omit "exec" and directly execute built-in apps or nsh builtins. 3. Regarding the property service, users can either adapt it by self or directly use the preset NVS-based properties. 4. Only part of standard action commands and service options are implemented currlently. To enable system/nxinit: ```diff -CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INIT_ENTRYPOINT="init_main" +CONFIG_SYSTEM_NXINIT=y ``` For format and additional details, refer to: https://android.googlesource.com/platform/system/core/+/ master/init/README.md Signed-off-by: wangjianyu3 --- system/nxinit/CMakeLists.txt | 39 +++ system/nxinit/Kconfig | 118 +++++++ system/nxinit/Make.defs | 25 ++ system/nxinit/Makefile | 39 +++ system/nxinit/action.c | 320 ++++++++++++++++++ system/nxinit/action.h | 85 +++++ system/nxinit/builtin.c | 184 +++++++++++ system/nxinit/builtin.h | 38 +++ system/nxinit/import.c | 60 ++++ system/nxinit/import.h | 38 +++ system/nxinit/init.c | 252 ++++++++++++++ system/nxinit/init.h | 91 +++++ system/nxinit/parser.c | 288 ++++++++++++++++ system/nxinit/parser.h | 60 ++++ system/nxinit/service.c | 622 +++++++++++++++++++++++++++++++++++ system/nxinit/service.h | 138 ++++++++ 16 files changed, 2397 insertions(+) create mode 100644 system/nxinit/CMakeLists.txt create mode 100644 system/nxinit/Kconfig create mode 100644 system/nxinit/Make.defs create mode 100644 system/nxinit/Makefile create mode 100644 system/nxinit/action.c create mode 100644 system/nxinit/action.h create mode 100644 system/nxinit/builtin.c create mode 100644 system/nxinit/builtin.h create mode 100644 system/nxinit/import.c create mode 100644 system/nxinit/import.h create mode 100644 system/nxinit/init.c create mode 100644 system/nxinit/init.h create mode 100644 system/nxinit/parser.c create mode 100644 system/nxinit/parser.h create mode 100644 system/nxinit/service.c create mode 100644 system/nxinit/service.h diff --git a/system/nxinit/CMakeLists.txt b/system/nxinit/CMakeLists.txt new file mode 100644 index 00000000000..5aef892e9fc --- /dev/null +++ b/system/nxinit/CMakeLists.txt @@ -0,0 +1,39 @@ +# ############################################################################## +# apps/system/nxinit/CMakeLists.txt +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more contributor +# license agreements. See the NOTICE file distributed with this work for +# additional information regarding copyright ownership. The ASF licenses this +# file to you under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# +# ############################################################################## + +if(CONFIG_SYSTEM_NXINIT) + + set(CSRCS init.c action.c builtin.c import.c parser.c service.c) + + nuttx_add_application( + MODULE + ${CONFIG_SYSTEM_NXINIT} + NAME + ${CONFIG_SYSTEM_NXINIT_PROGNAME} + STACKSIZE + ${CONFIG_SYSTEM_NXINIT_STACKSIZE} + PRIORITY + ${CONFIG_SYSTEM_NXINIT_PRIORITY} + SRCS + ${CSRCS}) + +endif() diff --git a/system/nxinit/Kconfig b/system/nxinit/Kconfig new file mode 100644 index 00000000000..8b1bb6b221d --- /dev/null +++ b/system/nxinit/Kconfig @@ -0,0 +1,118 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config SYSTEM_NXINIT + tristate "NuttX Init" + default n + depends on LIBC_EXECFUNCS + depends on SCHED_CHILD_STATUS + ---help--- + Enable NxInit(NuttX Init) component for system initialization. + The script of NxInit(init.rc) is compatible with the Android Init Language syntax. + +if SYSTEM_NXINIT + +# +# Basic +# + +config SYSTEM_NXINIT_PRIORITY + int "Thread priority" + default 100 + +config SYSTEM_NXINIT_STACKSIZE + int "Stack size" + default DEFAULT_TASK_STACKSIZE + +config SYSTEM_NXINIT_PROGNAME + string "Program name" + default "init" + +# +# RC +# + +config SYSTEM_NXINIT_RC_LINE_MAX + int "Max line length of RC file" + default 128 + ---help--- + Maximum line length of RC file. + More details: https://android.googlesource.com/platform/system/core/+/master/init/README.md + +# +# Action +# + +config SYSTEM_NXINIT_ACTION_CMD_ARGS_MAX + int "Max number of command arguments" + default 8 + ---help--- + Maximum number of command arguments. + Form: + ``` + on + + + + ... + ``` + +config SYSTEM_NXINIT_ACTION_MANAGER_EVENT_MAX + int "Max number of action manager events" + default 32 + ---help--- + Maximum number of action manager events. + ``` + struct action_manager_s + { + ... + FAR char *events[CONFIG_SYSTEM_NXINIT_ACTION_MANAGER_EVENT_MAX]; + ... + }; + ``` + +# +# Service +# + +config SYSTEM_NXINIT_SERVICE_ARGS_MAX + int "Max number of service arguments" + default 8 + range 3 64 + ---help--- + Maximum number of service arguments, + including "name", "pathname" and key word "service"(at least 3). Form: + ``` + service [ ]* +