Commit graph

9296 commits

Author SHA1 Message Date
wangjianyu3
c8ffe2a5e1 system/nxinit: add CONFIG_SYSTEM_NXINIT_STDOUT for printf-based log output
Syslog may be output via services such as DFX. When debugging the init
component (e.g., service startup failures, including DFX-related
exceptions), syslog may not be output properly.

Add a debug Kconfig option SYSTEM_NXINIT_STDOUT that redirects all init
log macros (init_debug/info/warn/err) to printf instead of syslog.
This is useful for early boot debugging when syslog is not yet
available or serial console shows no output.

Introduce init_log_output() macro as the common log backend, selected
at compile time between printf (with appended newline) and syslog.

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2026-09-15 09:17:06 -03:00
Junbo Zheng
2968b2c587 monkey: add missing blank lines after declarations
The nxstyle check on CI flagged three spots in monkey_main.c where a
declaration block runs directly into the following statement. Insert a
blank line after the declarations at each location; no logic change.

Fixes the Check job failure on PR #3784:
https://github.com/apache/nuttx-apps/actions/runs/34935981535/job/104273851956?pr=3784

Before:
```
graphics/input/monkey/monkey_main.c:223:2: error: Missing blank line after declarations
graphics/input/monkey/monkey_main.c:363:2: error: Missing blank line after declarations
graphics/input/monkey/monkey_main.c:526:6: error: Missing blank line after declarations
```

After:
```
nxstyle monkey_main.c -> exit 0
```

Assisted-by: Claude Code (GLM-5.3) <claude@anthropic.com>
Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
2026-09-15 09:16:23 -03:00
Junbo Zheng
6e79ea2d85 monkey: block SIGTERM and consume it in sigtimedwait() for a clean exit
Block SIGTERM at startup and add it to the sigtimedwait() set in
monkey_wait(): a blocked signal is never swallowed by the handler, it
either wakes the in-progress wait or stays pending on the task until
the next sigtimedwait() returns it immediately, so the exit through
the regular monkey_delete() cleanup path is deterministic. Because
the kernel keeps the signal mask and pending queue per task, sibling
monkey instances (e.g. multiple instances started for different
input devices) each stop independently, and no shared state is
involved.

Also add a signal_handler() that logs the received signal and
register it for SIGTSTP/SIGCONT/SIGTERM, so these signals never fall
back to their default actions and stay consumable by sigtimedwait()
/ sigwaitinfo().

Before:
kill -15 <pid> terminates the task via the default SIGTERM action
with no cleanup: no "monkey_delete: OK" is ever printed.

After:
kill -15 <pid> exits within one loop iteration (<= one event period,
100-500ms by default) via monkey_delete(), independently for each
running instance, and restarting monkey works.

Testing:

Built and verified on the NuttX simulator (host: Ubuntu 22.04):

  cmake -B build -DBOARD_CONFIG=sim:nsh -GNinja
  # enable in build/.config:
  #   CONFIG_INPUT=y
  #   CONFIG_GRAPHICS_INPUT_MONKEY=y
  #   CONFIG_NSH_MAXARGUMENTS=16
  ninja -C build olddefconfig && ninja -C build
  ./build/nuttx

Run in the nsh prompt (uinput injection mode):

  nsh> monkey -t 0x11 -p 100-300 -s 454x454 &   (uinput touch)
  nsh> monkey -t 0x12 -p 100-300 -s 454x454 -b 0 &  (uinput button)
  nsh> ps
  nsh> kill -15 <pid>

ps with both instances running (each monkey task shows "Waiting
Signal" with SIGMASK 0x8000, i.e. SIGTERM blocked while sitting in
sigtimedwait):

  TID   PID  PPID PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK            STACK COMMAND
    0     0     0   0 FIFO     Kthread   - Ready              0000000000000000 0069584 Idle_Task
    1     0     0 224 FIFO     Kthread   - Waiting  Semaphore 0000000000000000 0067456 sim_loop_wq 0x71204b2003f0 0x71204b200478
    2     0     0 224 FIFO     Kthread   - Waiting  Semaphore 0000000000000000 0067464 hpwork 0x40188860 0x401888e8
    4     4     0 100 FIFO     Task      - Waiting  Semaphore 0000000000000000 0067496 init_main
    9     9     4 100 FIFO     Task      - Running            0000000000000000 0067504 sh
   10    10     9 110 FIFO     Task      - Waiting  Signal    0000000000008000 0069472 monkey -t 0x11 -p 100-300 -s 454x454
   11    11     9 110 FIFO     Task      - Waiting  Signal    0000000000008000 0069448 monkey -t 0x12 -p 100-300 -s 454x454 -b 0

After "kill -15 10" (touch instance exits, button instance
unaffected):

  nsh> kill -15 10
  [monkey] monkey_wait: Recv sig: SIGTERM
  [monkey] monkey_delete: OK
  nsh> ps
  TID   PID  PPID PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK            STACK COMMAND
    0     0     0   0 FIFO     Kthread   - Ready              0000000000000000 0069584 Idle_Task
    1     0     0 224 FIFO     Kthread   - Waiting  Semaphore 0000000000000000 0067456 sim_loop_wq 0x71204b2003f0 0x71204b200478
    2     0     0 224 FIFO     Kthread   - Waiting  Semaphore 0000000000000000 0067464 hpwork 0x40188860 0x401888e8
    4     4     0 100 FIFO     Task      - Waiting  Semaphore 0000000000000000 0067496 init_main
    9     9     4 100 FIFO     Task      - Running            0000000000000000 0067504 sh
   11    11     9 110 FIFO     Task      - Waiting  Signal    0000000000008000 0069448 monkey -t 0x12 -p 100-300 -s 454x454 -b 0

After "kill -15 11" (second instance exits the same way, no monkey
task left):

  nsh> kill -15 11
  [monkey] monkey_wait: Recv sig: SIGTERM
  [monkey] monkey_delete: OK
  nsh> ps
  TID   PID  PPID PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK            STACK COMMAND
    0     0     0   0 FIFO     Kthread   - Ready              0000000000000000 0069584 Idle_Task
    1     0     0 224 FIFO     Kthread   - Waiting  Semaphore 0000000000000000 0067456 sim_loop_wq 0x71204b2003f0 0x71204b200478
    2     0     0 224 FIFO     Kthread   - Waiting  Semaphore 0000000000000000 0067464 hpwork 0x40188860 0x401888e8
    4     4     0 100 FIFO     Task      - Waiting  Semaphore 0000000000000000 0067496 init_main
    9     9     4 100 FIFO     Task      - Running            0000000000000000 0067504 sh

A new instance started after both kills (PID 12) runs normally and
is again stopped cleanly by kill -15.

Note: on the simulator the uinput devices register as /dev/utouch
and /dev/ubutton, while monkey opens /dev/input0 and /dev/buttons;
the run above used a local (uncommitted) path patch to work around
this. On a board where the device paths match, no patch is needed.

Assisted-by: Claude Code (glm-5.3) <claude@anthropic.com>
Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
2026-09-15 09:16:23 -03:00
lljwork2021
6284bdc50e system/xrcedds: add eProsima Micro XRCE-DDS
Add a lightweight Micro XRCE-DDS Client integration with UDP transport support and a publisher example.

Signed-off-by: lljwork2021 <lljwork2021@163.com>
2026-09-15 09:14:39 -03:00
Daniel P. Carvalho
9fdf62935b netutils/ptpd: add diagnostic logging for RX and Delay_Resp checks
Add ptpinfo()/ptpwarn() calls, gated by the existing
CONFIG_DEBUG_PTP_INFO/_WARN symbols (zero cost when disabled), at
points that previously failed silently: an unrecognized L2 protocol,
a domain mismatch, and a Delay_Resp rejected by the source/requester
identity check. These were essential to diagnosing the drift and
Delay_Req bugs fixed in the two preceding commits on real hardware,
and are kept for future maintainers debugging this path.

Assisted-by: Claude:claude-sonnet-5
Assisted-by: Gemini:gemini-3.8-flash-medium
Signed-off-by: Daniel P. Carvalho <danieloak@gmail.com>
2026-09-15 09:09:00 -03:00
Daniel P. Carvalho
32411a54ae netutils/ptpd: fix Delay_Req transmission over AF_PACKET
1. On AF_PACKET SOCK_RAW sockets in NuttX, msg_name must be NULL because
   the destination MAC address is already contained in the Ethernet header.
   Previously, passing sockaddr_in caused sendmsg() to fail immediately
   with -EAFNOSUPPORT, completely blocking transmission of Delay_Req.
2. Correct PTP primary multicast MAC address to 01:1b:19:00:00:00
   (IEEE 1588 Annex F) and ensure ether_type is in network byte order.
3. Initialize delayreq_interval to 1 second default and guard against 0.
4. Set logmessageinterval to 0x7f (IEEE 1588-2008 Table 23 sentinel for
   Delay_Req) instead of inheriting 0 from the announce header template.
5. Update PTP version to 0x12 (2.1, minorVersionPTP=1) to match the
   value used by mature implementations such as linuxptp.

Assisted-by: Claude:claude-sonnet-5
Assisted-by: Gemini:gemini-3.8-flash-medium
Signed-off-by: Daniel P. Carvalho <danieloak@gmail.com>
2026-09-15 09:09:00 -03:00
Daniel P. Carvalho
d9cb21d909 netutils/ptpd: fix drift divergence and post-jump bootstrap
1. Post-jump drift bootstrap: on the first Sync packet following a step
   jump, do not compute frequency drift against a synthesized zero delta,
   which previously caused the entire residual phase offset (~ms) to be
   mistaken for frequency drift (~million ppb) and immediately absorbed.
2. Drift rate formula: normalize the adjustment contribution by the actual
   measurement interval instead of the adjtime slew period, and compute
   natural delta rate as (delta - last_delta + last_adjtime) / interval.
3. Remove broken last_delta > delta comparison that prevented offsets from
   converging and applied inverted corrections on negative overshoots.
4. Correct ptp_adjtime() invocation to always pass adjustment_ns for
   CLOCK_REALTIME slewing rather than dropping drift compensation when
   delta exceeds threshold. Clamp adjustment_ns to the hardware slew limit
   so last_adjtime_ns accurately mirrors the true slew applied.
5. Enable Delay_Req in E2E mode once clock is tracking (not jumping) and
   allow software timestamping latency in ptp_process_delay_resp().
6. Propagate initialization return code from ptpd_start() and avoid
   unconditional failure print in do_ptpd_start().

Assisted-by: Claude:claude-sonnet-5
Assisted-by: Gemini:gemini-3.8-flash-medium
Signed-off-by: Daniel P. Carvalho <danieloak@gmail.com>
2026-09-15 09:09:00 -03:00
Daniel P. Carvalho
071074247b netutils/ptpd: fix BMCA compilation typos and define ETHERTYPE_PTP
- Fix typo state->conifg -> state->config in BMCA announce check.
- Fix typo state->n_identity -> state->own_identity in BMCA announce check.
- Define ETHERTYPE_PTP as 0x88f7 for IEEE 802.3 Layer 2 transport.

Assisted-by: Claude:claude-sonnet-5
Assisted-by: Gemini:gemini-3.8-flash-medium
Signed-off-by: Daniel P. Carvalho <danieloak@gmail.com>
2026-09-15 09:09:00 -03:00
Daniel P. Carvalho
72cf59b647 examples/comp: add comparator example tool
Add a dedicated NSH tool for testing and interacting with analog
comparator devices (/dev/comp*). Supports reading comparator output
state, enabling/disabling via IOCTL, and performing an automated voltage
ramp sweep using a DAC device when available.

Assisted-by: Gemini:gemini-2.5-pro
Signed-off-by: Daniel P. Carvalho <danieloak@gmail.com>
2026-09-15 16:09:24 +08:00
likun17
d1b15db361 system/uorb: add resistance, conductivity, energy and charge topics.
Declare and define the uORB metadata for the resistance, conductivity,
energy and charge types, and register them in g_sensor_list[] so that
orb_get_meta() and uorb_listener can resolve them by name.

Signed-off-by: likun17 <likun17@xiaomi.com>
2026-09-14 23:56:06 +08:00
likun17
b93c947608 system/uorb: add voltage, current and power topics
Declare and define the uORB metadata for the voltage, current and power
types, and register them in g_sensor_list[] so that orb_get_meta() and
uorb_listener can resolve them by name.

Signed-off-by: likun17 <likun17@xiaomi.com>
2026-09-14 23:56:06 +08:00
likun17
00d9af873d system/uorb: add missing metadata for velocity and ambient_temp
SENSOR_TYPE_VELOCITY and SENSOR_TYPE_AMBIENT_TEMPERATURE have an
entry in the kernel g_sensor_meta[] table but no ORB_DECLARE/ORB_DEFINE
in user space, so ORB_ID() fails to link, callers must fall back to
orb_open() by name and lose the o_size check, and uorb_listener cannot
monitor them.
Add the missing metadata and register both in g_sensor_list[];
ambient_temp reuses struct sensor_temp the same way sensor_light_uncal
already reuses struct sensor_light.

Signed-off-by: likun17 <likun17@xiaomi.com>
2026-09-14 23:56:06 +08:00
Junbo Zheng
8404450fb8 CMakeLists: fix missing '$' in dummy.c existence guard
The guard tested the literal string "{NUTTX_APPS_BINDIR}/dummy.c"
instead of the expanded path, so dummy.c was re-touched after each
reconfigure, invalidating its object. Add the missing '$' so the
guard checks the intended path.

Assisted-by: Claude Code (glm-5.3) <claude@anthropic.com>
Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
2026-09-13 11:21:09 +08:00
Junbo Zheng
61e0ea0824 cmake: fix missing '$' in wamrmod dir existence guard
The guard tested the literal string "{WAMR_MODULE_DIR}" instead of
the expanded path, so it never short-circuited and
file(MAKE_DIRECTORY) ran on every configure. Add the missing '$' so
the guard checks the intended path.

Assisted-by: Claude Code (glm-5.3) <claude@anthropic.com>
Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
2026-09-13 11:21:09 +08:00
Junbo Zheng
7a8ce88ed4 cmake: fix missing '$' in luamod dir existence guard
The guard tested the literal string "{LUAMOD_DIR}" instead of the
expanded path, so it never short-circuited and file(MAKE_DIRECTORY)
ran on every configure. Add the missing '$' so the guard checks the
intended path.

Assisted-by: Claude Code (glm-5.3) <claude@anthropic.com>
Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
2026-09-13 11:21:09 +08:00
wangjianyu3
bc0ed23a5d system/nxinit: add a per-service "console" option
Services started by nxinit (e.g. "sh") do not open a console device on
their own, unlike nsh_main, which explicitly does so via
nsh_consolemain()/nsh_waitusbready() for USB gadget consoles
(CDC-ACM/PL2303). When such a board switches its top-level init from
nsh_main to nxinit, no code path ever registers/connects the USB
console gadget, and a service that just execs a plain "sh" inherits
whatever (invalid, for a USB gadget console not yet opened at the time
the idle task file descriptors are set up) stdio nxinit itself has.

Add a "console [<device>]" service option: a service declared with it
gets the given device (CONFIG_SYSTEM_NXINIT_CONSOLE_DEV, "/dev/console"
by default, if no device is given) opened and dup'd onto its stdin,
stdout and stderr via posix_spawn_file_actions before it is spawned.
This does not depend on nsh being enabled at all.

For a USB gadget console, the device does not exist until the gadget
is actually registered; boards using one are expected to bring it up
themselves before any service using "console" is started (e.g. via an
"exec -- sercon" action in their init.rc, since apps/system/cdcacm
already implements exactly that registration step and does not depend
on nxinit or nsh either).

console_file_actions() runs after the previous commit's time_started
update, so a failure to build the console's file actions is covered by
the same up to date timestamp - no separate clock_gettime() call is
needed on this failure path.

Covered by a new unit test, test_nxinit_service_console_option, that
exercises the option with and without an explicit device, and confirms
services without the option are left untouched.

Assisted-by: Kiro:claude-sonnet-5
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2026-09-10 23:12:06 +08:00
wangjianyu3
a90c12b6da system/nxinit: retry a service whose spawn failed
init_service_refresh() ignored the return value of init_service_start().
If spawning a restarting service failed for any reason (e.g.
posix_spawnp() itself failing), the service stayed SVC_RESTARTING
forever with nothing left to re-arm its retry timer: this function's
return value drives the poll timeout in the caller's event loop
(main()), and a failed spawn does not fork a child, so there is no
SIGCHLD either to wake it up some other way. If this service happens
to be the only pending timer, the poll blocks indefinitely and the
service is never attempted again.

Check the return value and, on failure, feed the service restart
period into the poll timeout computed by this function, the same way
a successfully started/still-restarting service already does.

Also move the CLOCK_MONOTONIC read that updates a service's
time_started from after a successful spawn to before the spawn is
even attempted, so that time_started stays current on a failed spawn
too - otherwise, once woken up (by the fix above or by an unrelated
event), a repeatedly failing service would look permanently overdue
(elapsed time computed against a stale timestamp) and get retried
immediately regardless of its restart_period.

Assisted-by: Kiro:claude-sonnet-5
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2026-09-10 23:12:06 +08:00
wangjianyu3
3b86850d27 system/nxinit: fix missing blank line after declaration in service.c
nxstyle flags a missing blank line between the declaration of "s" and
the first statement in option_reboot_on_failure(); pre-existing,
unrelated to any behavioral change here.

Assisted-by: Kiro:claude-sonnet-5
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2026-09-10 23:12:06 +08:00
Megha Rajput
3c0fdc1ff6 testing/nettest: add checksum zero-length regression test
Add a CMocka regression test for zero-length checksum fragments.
The test verifies that an empty IOB between fragments does not affect
the checksum calculation or pending odd-byte state.

Assisted by: GitHub Copilot

Signed-off-by: Megha Rajput <i.meghar.2408@gmail.com>
2026-09-10 23:11:37 +08:00
Abhishek Mishra
a81fe2f4d9 mlearning/tflite-micro: enable Makefile hello-world and usable tflm
Build tflm_hello from Makefile, allocate tensors in tflm, keep syslog
strings without debug, and honor CONFIG_DARKNET_YOLO_VER.

Assisted-by: Cursor:Grok-4.6
Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
2026-09-10 09:48:24 +02:00
Junbo Zheng
46b8774f7f system/grep: Add grep command with regex support
Add a standalone grep application under apps/system/grep/. It uses the
NuttX libc regex library (regcomp/regexec) to support -i, -n, -v, -r,
-H and -h options plus stdin input and recursive directory search.

SYSTEM_GREP depends on LIBC_REGEX, so the regex library must be enabled
first -- CONFIG_SYSTEM_GREP only becomes selectable once LIBC_REGEX is
turned on.

Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
2026-09-09 10:34:10 +08:00
raiden00pl
5a7ab4200d examples/s2opc: add OPC UA server example
Add a small high-level S2OPC server with an anonymous SecurityPolicy None
endpoint and a generated C address space.

Assisted-by: OpenAI Codex:gpt-5
Signed-off-by: raiden00pl <raiden00@railab.me>
2026-09-07 15:01:21 -03:00
raiden00pl
35133b6a63 netutils/s2opc: add NuttX platform integration
Add Make and CMake packaging for the S2OPC 1.7.3 toolkit.

Assisted-by: OpenAI Codex:gpt-5
Signed-off-by: raiden00pl <raiden00@railab.me>
2026-09-07 15:01:21 -03:00
Ansh Rai
0ae2c5391c mlearning/tflite-micro: Register DEPTHWISE_CONV_2D in tflm_tool resolver.
MicroMutableOpResolver<8> only registered 8 ops, missing
DEPTHWISE_CONV_2D, required by any depthwise-separable CNN
(MobileNet-style, DS-CNN keyword-spotting models). The kernel
already exists upstream (Register_DEPTHWISE_CONV_2D_INT8() in
tensorflow/lite/micro/kernels/depthwise_conv.h); this wires it
into the resolver and bumps the template size to <9>.

Verified with micro_speech_quantized.tflite on sim:tflm.
Before: Didn't find op for builtin opcode 'DEPTHWISE_CONV_2D'.
After: RESHAPE/DEPTHWISE_CONV_2D/FULLY_CONNECTED/SOFTMAX all execute.

Signed-off-by: Ansh Rai <anshrai331@gmail.com>
2026-09-07 14:07:09 +02:00
raiden00pl
dc3cc88758 testing/ostest: use STACKSIZE for the wqueue test worker threads
Size the worker stacks with STACKSIZE like the rest of ostest.

Signed-off-by: raiden00pl <raiden00@railab.me>
2026-09-06 22:39:30 +08:00
Pavel Pisa
6be063a7fc graphics/microwindows: nanoxcalc fix and upstream update to fix warnings
This update introduces the following changes in mw:
- Fixed all idetified -Werror warnings in CI.
- Fixed the issue where the backspace key was not working in QEMU

Signed-off-by: Pavel Pisa <ppisa@pikron.com>
2026-09-06 10:39:44 -03:00
Acfboy
e0fd7c67c1 graphics/microwindiws: Update microwindows commit hash
This update introduces the following changes in mw:
- Fixed some -Werror warnings in CI.
- Fixed the issue where the backspace key was not working in QEMU

Signed-off-by: Acfboy <AcfboyU@outlook.com>
2026-09-04 11:49:29 +02:00
wangjianyu3
00653bb510 .github/workflows/build.yml: bump nuttx-ntfc-testing to release-0.0.2
nuttx-ntfc-testing's release-0.0.1 tag pins ntfc.yaml's citest
requirement to CONFIG_INIT_ENTRYPOINT=nsh_main, so any sim/citest
defconfig that switches to a different init entrypoint (e.g. nxinit's
init_main) fails CI with:

  OSError: Missing kconfig dependency: ['CONFIG_INIT_ENTRYPOINT', 'nsh_main']

Maintainer raiden00pl cut nuttx-ntfc-testing release-0.0.2, which drops
that CONFIG_INIT_ENTRYPOINT requirement from ntfc.yaml, and requested
both nuttx and nuttx-apps workflows be updated to it:
https://github.com/apache/nuttx-ntfc-testing/issues/7#issuecomment-5480486089

Only the `git clone -b release-0.0.1` line is changed; the unrelated
`ntfc==0.0.1` PyPI package pin (build.yml) is untouched.

Assisted-by: opencode-agent/claude-sonnet-5
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2026-09-01 11:24:28 +08:00
guao
c91322216b testing/crypto: add SHA2-224 HMAC test case
Add SHA2-224 HMAC verification to the crypto hmac test using
CRYPTO_SHA2_224_HMAC through the /dev/crypto interface. Uses
standard HMAC test vectors producing a 28-byte digest.

Signed-off-by: guao <guao@xiaomi.com>
2026-08-29 00:12:45 +08:00
guao
6a19675e77 testing/crypto: add chacha20 and chacha20-poly1305 tests
Add test cases for ChaCha20 stream cipher and ChaCha20-Poly1305
AEAD algorithm using the NuttX cryptodev interface. Tests cover
RFC 7539 test vectors including encryption/decryption with various
key/nonce/counter combinations.

Signed-off-by: guao <guao@xiaomi.com>
2026-08-29 00:12:45 +08:00
wangjianyu3
63698738a8 system/nxinit: add cmocka unit tests for parser/action/service
Add a test/ subdirectory (mirroring apps/system/uorb/test/) with
cmocka-based unit tests covering the NxInit logic most prone to
regression:

- init_parse_arguments(): plain/quoted arguments, "--" separator vs.
  "--option" long options (regression coverage for a previously fixed
  bug), argv-capacity truncation (asserting the exact folded contents
  of the last slot, not just its presence).
- init_parse_config_file()/init_parse_config_lines()/
  init_parse_config_buffer(): section routing, blank/whitespace-only
  line skipping, unknown-section rejection, over-length line rejection,
  and a line straddling two read-buffer refills, exercised through both
  the file-based and buffer-based entry points.
- Action event matching: exact match, invert (!=), fnmatch wildcards,
  and AND semantics across multiple events per action.
- Service conflict detection: duplicate service name rejection,
  override replacing an earlier duplicate, and the SERVICE_ARGS_MAX
  boundary built dynamically from CONFIG_SYSTEM_NXINIT_SERVICE_ARGS_MAX
  rather than a hardcoded value.

Test sources compile action.c/parser.c/service.c a second time into a
separate nxinit_unit_test program, gated behind new
CONFIG_SYSTEM_NXINIT_TEST (depends on TESTING_CMOCKA); the default init
program is unaffected. The CMake path builds a dedicated
nxinit_unit_test target (with test/test_nxinit.c placed first in SRCS
so nuttx_add_application() renames its main() correctly); the Make path
appends the test sources into the shared CSRCS list.

Supporting bits required to make the suite exercise the real code:

- init_parse_config_buffer() is declared in parser.h and made
  non-static so the buffer-based boundary test can call it directly,
  alongside the existing init_parse_config_file() entry point.
- CONFIG_SYSTEM_NXINIT_ACTION_EVENTS_MAX default is raised from 1 to 2
  so an action can carry more than one event ("on evA && evB"), which
  the multi-event AND-semantics test exercises; a single event slot
  made that test dead code.
- CONFIG_SYSTEM_NXINIT_TEST_STACKSIZE defaults to 8192: several parser
  test cases build multi-hundred-byte stack buffers on top of cmocka's
  own overhead, and the previous DEFAULT_TASK_STACKSIZE (2048)
  overflowed the test task's stack silently on real hardware (no crash
  dump, no watchdog reset, output just stopped) partway through the
  suite.

Testing:
Built via `make CROSSDEV=riscv-none-elf-` for
esp32p4-pico-wifi-wareshare:nsh (CONFIG_SYSTEM_NXINIT_TEST=y) and ran
nxinit_unit_test on real esp32p4-pico-wifi-wareshare hardware over
UART:

  nsh> nxinit_unit_test
  [==========] nxinit_tests: Running 18 test(s).
  ...
  [==========] nxinit_tests: 18 test(s) run.
  [  PASSED  ] 18 test(s).

nxstyle clean on all touched files.

Assisted-by: GitHubCopilot:claude-sonnet-5
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2026-08-28 09:33:47 -03:00
wangjianyu3
7a1c6aaa7c system/nxinit: fix stack-buffer-overflow in init_parse_config_buffer
init_parse_config_buffer() computed the per-refill copy length as
MIN(len - off, sizeof(tmp)) without subtracting the 'n' leftover bytes
already held at the front of 'tmp' from a previous refill, so
memcpy(&tmp[n], ..., r) could write past the end of tmp[]. The
file-based twin, init_parse_config_file(), already gets this right
(read(fd, &buf[n], sizeof(buf) - n)).

Reproduced locally with an AddressSanitizer host harness feeding the
real 95-byte builtin "preset" rc content through
init_parse_config_buffer() at CONFIG_SYSTEM_NXINIT_RC_LINE_MAX=32/48:
ASan reports a stack-buffer-overflow on the 'tmp' array. Fixed to
MIN(len - off, sizeof(tmp) - n) and reverified clean at
RC_LINE_MAX=32/48/64/128.

The default config never hits this (the builtin preset is 95 bytes and
the default RC_LINE_MAX is 128), but SYSTEM_NXINIT_RC_LINE_MAX had no
lower bound, so lowering it towards 32/48 for a smaller build would
silently corrupt the stack while parsing the preset during boot. Add a
"range 64 4096" bound so the value can no longer be set below the
builtin preset's needs.

Assisted-by: opencode:mimo-v2.5-pro
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2026-08-28 09:33:47 -03:00
wangjianyu3
a31fe191fa system/nxinit: fix missing blank line after declaration in parser.c
init_parse_config_file() declares 'r' inside the read loop with no
blank line before the following 'if (r < 0)' statement, violating the
NuttX coding standard (nxstyle: "Missing blank line after
declarations"). checkpatch.sh runs a whole-file nxstyle check on any
file a commit touches, not diff-only, so this pre-existing issue
surfaced on this PR's CI once parser.c was touched again.

Assisted-by: GitHubCopilot:claude-sonnet-5
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2026-08-28 09:33:47 -03:00
wangjianyu3
5c3f14ae76 system/nxinit: fix truncated line loss in config parser
init_parse_config_lines() had a dead early "continue" for a truly
empty line (buf == "\0") that skipped the memmove() bookkeeping its
sibling whitespace-only-line branch performs. When a real empty line
appeared mid-buffer, subsequent bytes were never shifted to the front
of the working buffer, corrupting the remaining-length tracking and
silently dropping every line after it for that refill chunk.

The whitespace-skip loop right below already handles the empty-string
case correctly (the loop body never executes, so it falls straight
into the "only whitespace" -> memmove -> continue path), so the buggy
early exit is simply redundant and removed.

Assisted-by: GitHubCopilot:claude-sonnet-5
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2026-08-28 09:33:47 -03:00
wangjianyu3
11c1c6bece system/nxinit: add 'set' builtin command for environment variables
Previously, 'set KEY VALUE' in init.rc was not recognized as a builtin
command. It fell through to posix_spawnp(), which ran it in a
temporary child shell. The environment variable was set only in the
child process and lost when it exited, so services started afterward
never inherited it.

Register cmd_set as an init builtin that calls setenv(key, value, 1)
directly in the init process. The command takes exactly 2 arguments
(key and value). All code is guarded by CONFIG_DISABLE_ENVIRON so it
compiles out when environment support is disabled.

Since child processes inherit init's environment, 'set TZ Asia/Shanghai'
in init.rc now correctly propagates to all subsequently started
services.

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2026-08-28 09:30:53 -03:00
wangjianyu3
ec33a924a5 system/nxinit: increase SERVICE_ARGS_MAX default to 16
The previous default of 8 is insufficient for services with many
arguments (e.g. ptpd needs 10 argv slots). When exceeded, argv lacks
a NULL terminator, causing posix_spawnp to read out of bounds.

Increase default to 16 to prevent argument truncation for typical
daemon services.

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2026-08-28 09:30:53 -03:00
zhengyu16
48ddaadad1 nshlib, wamr: fix pre-existing style issues in touched files
Because this PR modifies nsh_fscmds.c and wamr/Kconfig, CI runs
nxstyle and codespell over the whole files and rejects pre-existing
issues that are unrelated to the rename:

  - nsh_fscmds.c: reindent misaligned switch/case blocks in cmd_dmesg,
    cmd_losetup, cmd_losmart, cmd_lomtd, cmd_mkdir, cmd_mkfatfs and
    cmd_mkrd to the standard NuttX layout.
  - wamr/Kconfig: fix two spelling typos flagged by codespell
    ("expections" -> "exceptions", "Configuable" -> "Configurable").

Style/whitespace and spelling only; no functional change.

Signed-off-by: zhengyu16 <zhengyu16@xiaomi.com>
2026-08-27 13:31:34 +08:00
zhengyu16
9cda1fbb60 fs: rename PSEUDOFS_SOFTLINKS to FS_LINKS
The link support is no longer limited to the pseudo file system and now
covers both soft (symbolic) links and hard links across the VFS.  Update
all references to the renamed configuration option PSEUDOFS_SOFTLINKS,
which has been renamed to FS_LINKS in the NuttX kernel, so that nshlib,
the interpreters, adb, tlpi and the test suites keep building.

This must be merged together with the corresponding NuttX change that
performs the actual kernel-side rename.

Signed-off-by: zhengyu16 <zhengyu16@xiaomi.com>
2026-08-27 13:31:34 +08:00
Pavel Pisa
94012303da netutils/libshvc: implement headers export and update shv-libs4c
The uLUt and libshvc declare headers intended for make export
by EXPORTED_INCLUDES mechanism implemented during 2026
Micowindows GSoC. The shv-libs4c has been updated as well
to support newer pyshv versions and that way firmware updates
when shv-nxboot-updater is used through pyshv based shvflasher.py
and related GUI.

For pyshv see https://github.com/silicon-heaven/pyshv

New commits from shv-libs4c project

  https://github.com/silicon-heaven/shv-libs4c

- shv_com_common: shv_unpack_discard and shv_unpack_skip

   required to skip additional parameters and query requests
   introduced introduced by newer silicon-heaven protocol
   and pyshv. Incorrect skipping was a bug even against
   previous protocol version but did not present itself because
   older pyshv did not send additional requests which need
   to be ignored.

- shv_file_node: small, but crucial unpack change

  Ignore any other messages than PARAM in file node's write unpack
  function. Other different states should be handled, too.

- shv_file_node: fix the CRC unpack method too

  Any other messages than PARAM are ignored.

- shv_com: add a method to close a connection only

- shv_dotdevice_node.c: close the conn with the other side when resetted

- shv_com.h: use array designators for error strings

- libshvtree: move shv_con_errno_strs to the C file to not waste space
  by copies

- shvtree/shv_clayer_posix: provide alternative socketpair notification
  support

  This allows to use shv-libs4c and related pysimCoder support
  on RTEMS system which does not provide functional pipe
  directive/system call but BSD networking supported local/UNIX
  socket pair is fully supported.

Signed-off-by: Pavel Pisa <ppisa@pikron.com>
2026-08-27 02:04:21 +08:00
wangjianyu3
82eb73da76 system/nxinit: fix unkown -> unknown typo in resetcause[]
codespell flagged this in PR #3751 CI:
  system/nxinit/init.c:119: unkown ==> unknown
  system/nxinit/init.c:130: unkown ==> unknown

Both entries were introduced by the resetcause-for-triggers commit and
are unrelated to the earlier nxstyle regression already discussed on
the PR.

Assisted-by: GitHubCopilot:claude-sonnet-5
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2026-08-26 10:00:02 -03:00
wangjianyu3
c91fe7bf01 system/nxinit: Add missing "assert" entry to resetflag
Add the missing mapping entries in the resetflag[] array to prevent
potential NULL pointer dereference when accessing reset.flag.

The resetflag array uses designated initializers and must have entries
for all BOARDIOC_SOFTRESETCAUSE_* values to avoid array holes.

Reported by: xuchuntian@xiaomi.com
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2026-08-26 10:00:02 -03:00
wangjianyu3
ee32ebda06 system/nxinit: Add subreason for sys.boot.reason
init.rc

  on init && property:sys.boot.reason=watchdog,4
     ...

  on init && property:sys.boot.reason=bootloader|recovery|thermal
     ...

Test

  cause->cause = BOARDIOC_RESETCAUSE_CPU_RWDT;
  cause->flag  = 4
  init_main: setprop key:sys.boot.reason value:watchdog,4

  cause->cause = BOARDIOC_RESETCAUSE_CPU_SOFT;
  cause->flag  = BOARDIOC_SOFTRESETCAUSE_ENTER_BOOTLOADER;
  init_main: setprop key:sys.boot.reason value:bootloader

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2026-08-26 10:00:02 -03:00
wangjianyu3
fd35a05249 system/nxinit: Add resetcause for triggers
Add built-in property sys.boot.reason, which allows action triggers to be
executed on specific reset cause.

For example:
  ```
  on property:sys.boot.reason=cpu_soft_reset(bootloader)
      echo "bootloader mode ..."
      start fastboot
  ```

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2026-08-26 10:00:02 -03:00
fangpeina
4cb0068732 system/nxinit: support compound command execution
Example in init.rc:
  echo "start" && hello && echo "done"
  ls /missing || echo "not found"
  echo "A" && echo "B" || echo "fallback"

Signed-off-by: fangpeina <fangpeina@xiaomi.com>
2026-08-26 10:00:02 -03:00
Filipe Cavalcanti
19bab7621d examples/lvglterm: fix wrong dependency on PSEUDOTERM
Changes PSEUDOTERM dependency from 'select' to 'depends on' which was
missing from the initial pull request.

Signed-off-by: Filipe Cavalcanti <filipe.cavalcanti@espressif.com>
2026-08-26 10:28:21 +08:00
Filipe Cavalcanti
2b92bedaee examples/lvglterm: replace PIPES with PSEUDOTERM
The lvglterm terminal now runs the shell on a pseudo-terminal instead of three
plain pipes.

Signed-off-by: Filipe Cavalcanti <filipe.cavalcanti@espressif.com>
2026-08-25 12:21:12 +08:00
raiden00pl
d570175cc9 interpreters/python: use NuttX readline for TTY input
CPython's default TTY reader bypasses NuttX editing and control-key handling.

Signed-off-by: raiden00pl <raiden00@railab.me>
Assisted-by: Claude Code
2026-08-24 22:15:31 +08:00
raiden00pl
9545e12054 system/readline: add caller-selectable control handling
Let CPython handle Ctrl-D and signals without changing existing NSH behavior.

Signed-off-by: raiden00pl <raiden00@railab.me>
Assisted-by: Claude Code
2026-08-24 22:15:31 +08:00
wangjianyu3
0923948d80 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 <wangjianyu3@xiaomi.com>
2026-08-24 20:11:14 +08:00
jingfei
6d178011d5 system/nxinit: Add start_cpu support for action
Add support for starting a cpu's software.
Depends on `BOARDCTL_START_CPU`.

Signed-off-by: jingfei <jingfei@xiaomi.com>
2026-08-24 20:11:14 +08:00