Skip to content

system/nxinit: add rptun/unlink builtins and service fallback option - #3761

Open
JianyuWang0623 wants to merge 3 commits into
apache:masterfrom
JianyuWang0623:nxinit-rptun-unlink-fallback
Open

system/nxinit: add rptun/unlink builtins and service fallback option#3761
JianyuWang0623 wants to merge 3 commits into
apache:masterfrom
JianyuWang0623:nxinit-rptun-unlink-fallback

Conversation

@JianyuWang0623

@JianyuWang0623 JianyuWang0623 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Summary

  1. rptun / unlink builtin commands. Some products drive early bring-up
    entirely from init.rc rather than NSH, so the NSH rptun command is
    not available there. Add rptun as an init builtin (guarded by
    CONFIG_RPTUN) supporting start/stop, plus a generic unlink
    builtin (always available) for removing device nodes, e.g.:

    rptun stop /dev/rptun/proc
    unlink /dev/rptun/proc
    rptun start /dev/rptun/proc
    

    RPTUNIOC_START returns the pid of the rptun kernel thread in async
    mode (CONFIG_RPTUN_START_SYNC unset). That thread is a detached
    kthread, never a child of init, so returning a positive value would
    make the action engine waitpid() on it and block the whole action
    queue (and on init / console would never run). A successful start is
    normalized to 0.

  2. fallback service option. Add an SVC_FALLBACK flag and a
    fallback service option — the semantic opposite of override — to
    resolve same-name service conflicts. override makes the new
    definition replace the old; fallback makes the definition marked
    fallback yield to the other one, so a board-level init.rc can provide
    a default service that is silently dropped when another init.rc
    defines a service with the same name (and vice versa). If neither flag
    is set, duplicate service names still produce -EEXIST as before.

Impact

  • Only touches system/nxinit/{builtin.c,service.c,service.h}. No change
    to existing builtins/options; new behavior is opt-in via the new
    rptun/unlink commands and the fallback option.
  • rptun builtin is compiled only when CONFIG_RPTUN is enabled;
    unlink and fallback are always available.
  • No new Kconfig symbols.

Testing

Built and verified locally with the sim target (host gcc). nxstyle
clean on all three touched files.

fallback verified at runtime on sim + nxinit with an init.rc that
declares two services named console (A/B against the same config
without the flag):

# without "fallback":
Error Redefined service 'console'          # parse fails (-EEXIST)

# with "fallback" on the second definition:
nsh> ps
  TID  PID PPID ... COMMAND
    4    4    0 ... init_main               # nxinit is init
    5    5    4 ... sh                       # the non-fallback console starts;
                                             # the fallback one is silently ignored, no error

unlink is always compiled in and rptun compiles under CONFIG_RPTUN;
both build cleanly. The sim target has no rptun device, so the rptun
runtime path is not exercised here — the concurrency fix (normalizing a
successful async RPTUNIOC_START to 0 so the action engine does not
waitpid() on the detached rptun kthread) is a targeted one-line change
verified by build + code review.

cc @wyr-7

BL uses init framework (not NSH), so the NSH rptun command is not
available. Add rptun as an init builtin command that supports
start and stop subcommands. Also add a generic unlink builtin
command for removing device nodes.

Usage in init.bl.rc:
  rptun stop /dev/rptun/corecs
  unlink /dev/rptun/corecs
  rptun start /dev/rptun/corecs

- rptun start/stop: open device, ioctl(RPTUNIOC_START/STOP), close
- unlink: generic command to unlink any file/device node

Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
@JianyuWang0623
JianyuWang0623 force-pushed the nxinit-rptun-unlink-fallback branch 2 times, most recently from 3daf3bf to b2288ea Compare August 28, 2026 13:24
RPTUNIOC_START returns the (positive) pid of the rptun kernel thread
in async mode (CONFIG_RPTUN_START_SYNC unset). The action engine
treats any positive builtin return value as the pid of a spawned
child and waitpid()s on it (action.c: "if (ret > 0) pid_running =
ret"). The rptun thread is a detached kthread, never a child of init,
so that wait blocks the whole action queue forever and "on init" /
console never run. Normalize a successful start to 0.

Assisted-by: OpenCode:claude-sonnet-5
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
The preset kvdb service defined in parser.c conflicts with user-defined
kvdb service in board-level init.rc, causing:

  Error redefined service 'kvdb'

Add SVC_FALLBACK flag and fallback service option. When a service
is marked as fallback, it will be silently ignored if another
service with the same name already exists. This is the semantic
opposite of override:

- override: new definition replaces old
- fallback: new definition yields to old
- old has fallback + new arrives: old yields to new

If neither flag is set, duplicate service names still produce
EEXIST error as before.

Mark the preset kvdb service as fallback so that board-specific
init.rc can freely define its own kvdb service without conflict.

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
@JianyuWang0623
JianyuWang0623 force-pushed the nxinit-rptun-unlink-fallback branch from b2288ea to 7e1e173 Compare August 28, 2026 13:29
@JianyuWang0623

Copy link
Copy Markdown
Contributor Author

Note: The Assisted-by trailer appears only in commits that were originally authored with the help of AI coding tools. Some commits in this series (e.g., the rptun/unlink builtin and the fallback service option) were originally created on our internal Gerrit at an earlier date, before AI-assisted workflows were adopted, so they do not carry the Assisted-by tag. The commit message content is otherwise preserved as-is from the original internal commits.

@JianyuWang0623
JianyuWang0623 marked this pull request as ready for review August 28, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants