Toybox is the toolbox used on Android by default. Adding it to NuttX
allows to have more advanced features from Linux, even better support
for shell scripts.
Signed-off-by: Alan C. Assis <acassis@gmail.com>
Assisted-by: Claude Sonnet 5 <noreply@anthropic.com>
The `on <event>` action re-executed on every property poll because the
event pending flag was sticky: event_callback returned the same non-zero
pending value whether the event had just changed or had stayed satisfied
from an earlier change. init_action_foreach_event could not distinguish
an edge from a steady state and re-enqueued the action each round
(board_netinit ran 262 times per boot).
Introduce a three-state result (EVENT_STATE_UNSATISFIED / SATISFIED /
TRIGGERED). event_callback now returns TRIGGERED only on the edge where
pending flips false -> true. foreach folds per-event states into a
product clamped to TRIGGERED, enqueuing the action only when every event
is satisfied AND at least one fired this round.
Assisted-by: GitHubCopilot:claude-4.8-opus
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
Action triggered on any event before this fix (e.g. both opposite actions in
init.rc below triggered when event "boot" triggered).
init.rc
on boot && property:sys.boot.reason=bootloader
echo "On boot, the reason is BL."
on boot && property:sys.boot.reason!=bootloader
echo "On boot, the reason is not BL."
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
init.rc
on boot && property:sys.boot.reason!=bootloader
echo "On boot, the reason is not BL."
Before fixing
init_main: action 0x40436120
init_main: sys.boot.reason!=bootloader
init_main: argv[0] 'echo'
init_main: argv[1] 'On boot, the reason is not BL.'
After fixing
init_main: action 0x40436120
init_main: sys.boot.reason!=bootloader
+ init_main: default==boot
init_main: argv[0] 'echo'
init_main: argv[1] 'On boot, the reason is not BL.'
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
Previously only supported event trigger, now added support for
action triggers (property setting).
Steps to enable action triggers:
- Define all init_property_*() interfaces declared in this file.
- Data structures or functions that will likely be used:
- struct action_trigger_s
- init_action_for_every()
Example
```
on boot
setprop key_test
setprop key_test value_test /* property changed and matched */
trigger event_test
on event_test && property:key_test=value_test
echo "on event_test, property changed!"
on property:key_test=value_test
echo "property changed!"
```
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
Add the property backend and a setprop builtin so that setting a
property can feed action triggers. property_simple.c provides a minimal
init_property_*() implementation whose init_property_set() forwards the
key/value pair to init_action_trigger_event(), and init.c wires the
property poller into the init poll loop.
Signed-off-by: fangpeina <fangpeina@xiaomi.com>
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
nsh_consolemain always passes NSH_LOGIN_LOCAL, so treating any
non-NONE session as a login rewrote nsh> to nsh# whenever
SCHED_USER_IDENTITY was enabled. NTFC boot detection then timed
out on sim/citest and qemu-rv/citest.
Keep CONFIG_NSH_PROMPT_STRING until a successful console or telnet
login (or su).
Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
When NSH_PROMPT_STRING_ROOT/USER are empty, keep NSH_PROMPT_STRING at
boot (for example, "nsh> ") so CI/NTFC boot detection still works.
After login, su, or telnet login, replace the last '>' with '#' (euid 0)
or '$' (non-zero euid) and ensure a trailing space. Refresh readline
after console/telnet login when line editing is enabled.
Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
This commit adds a system utily 'stty' to NuttX, providing a standard
Unix-like interface for configuring terminal (TTY) device settings.
The command allows runtime configuration of termios attributes for
serial ports and other character devices.
Usage examples:
# Set raw mode on ttyS0 (for binary communication)
nsh> stty -F /dev/ttyS0 raw -echo
# Set console mode for interactive terminal
nsh> stty -F /dev/ttyS0 cooked
# Display current settings
nsh> stty -F /dev/ttyS0
# Configure stdin (if it's a TTY)
nsh> stty echo icanon
# Set baudrate (if driver support)
nsh> stty -F /dev/ttyS1 speed 115200
Signed-off-by: fangpeina <fangpeina@xiaomi.com>
ostest's "vfork" test was never testing vfork(). It has the child write a
global and the parent observe the write -- the defining property of *sharing*,
not of vfork(), whose defining property is that the parent is suspended and
whose contract forbids the child to write anything at all. It passed because
NuttX implemented fork() and vfork() as the same sharing primitive, which
apache/nuttx#19562 separates.
vfork.c is rewritten to test what vfork() promises. The child does only what
POSIX permits -- it calls _exit(42) and nothing else, not even exit(), which
would run atexit handlers and flush stdio in the parent's address space. Since
the child may not write memory and the parent cannot run while the child lives,
the observable is the child's exit status: had the parent not been suspended,
it would have reached waitpid() while the child was still alive. Where child
status is not retained -- ostest_main() sets SA_NOCLDWAIT for the whole run,
deliberately -- ECHILD is accepted as equally good evidence, since it says the
child was already gone when the parent asked.
fork.c is new and tests POSIX fork(): the child's writes to .data, .bss and
the heap are invisible to the parent and vice versa, a pointer to a stack local
taken before the fork names the same object in both, and the child does
everything a vfork() child may not -- calls malloc() and printf(), and returns
from the function that called fork().
Both run at the top of user_main(). They exercise the lowest-level machinery
in the suite -- address environments, stack setup, the architecture's register
context -- so a fault in one takes the process down instead of reporting a
failure. Learning that in seconds rather than after everything else has passed
matters when a port is being brought up.
Each test gates on the one primitive it tests, ARCH_HAVE_VFORK and
ARCH_HAVE_FORK respectively. There is no compatibility layer and no mapping
between symbols. vfork.c no longer requires SCHED_WAITPID: the suspension is
in the kernel primitive now, so the test's core assertion holds without it and
only the status check is conditional.
The simulator is the one exception. It selects ARCH_HAVE_VFORK, but ostest
takes the sim down as soon as the test runs there, so the call keeps the
!ARCH_SIM guard that apps ee7642793 put on the old test in 2024. The old gate
hid this: ARCH_HAVE_FORK is not set on the sim, so the test was not built
there at all.
The other in-tree callers are audited for which primitive they actually meant:
* interpreters/python's _posixsubprocess and netutils/libwebsockets'
LWS_HAVE_WORKING_VFORK want the fork-then-exec path -- ARCH_HAVE_VFORK.
* python's os.fork() and libwebsockets' LWS_HAVE_FORK mean real fork() and stay
on ARCH_HAVE_FORK, so they become *absent* rather than silently wrong.
* testing/fs/fdsantest's vfork case follows ARCH_HAVE_VFORK.
interpreters/bas is deliberately left alone. Its SHELL and EDIT statements
reach for vfork() under an ARCH_HAVE_FORK guard and want the same treatment,
but checkpatch.sh checks the whole of any file a patch touches and
bas_statement.c produces 1681 pre-existing findings against master, so a
one-line change there fails CI on its own. The consequence is small:
EXAMPLES_BAS_SHELL is EXPERIMENTAL and already depends on ARCH_HAVE_FORK, so it
becomes unselectable rather than misbehaving.
Assisted-by: Claude Code:claude-opus-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
_err() is a kernel-internal debug macro from <debug.h>; it resolves to
the kernel-only _err symbol, which an application cannot reference. In a
flat build the example therefore fails to link:
apa102_main.c: undefined reference to `_err'
(observed on xtensa/esp32s3). Report the failure with fprintf(stderr),
which is what the open() error path a few lines above already does.
Signed-off-by: Ricard Rosson <ricard@groundbits.com>
Assisted-by: Claude Opus 5 (Claude Code)
This example drives the APA102 LED-strip character driver: it opens
/dev/leddrv0 and writes an array of struct apa102_ledstrip_s from
<nuttx/leds/apa102.h>, which is provided by drivers/leds/apa102.c
(CONFIG_LEDS_APA102). CONFIG_LCD_APA102 selects an unrelated driver,
drivers/lcd/apa102.c, which drives an APA102 matrix as a framebuffer LCD
and registers no /dev/leddrvN node at all.
The wrong dependency makes the example unusable either way: with the LED
strip driver enabled the example cannot be selected in menuconfig, and
with CONFIG_LCD_APA102 the dependency is met but the driver the example
needs is absent, so it fails at open().
Signed-off-by: Ricard Rosson <ricard@groundbits.com>
Assisted-by: Claude Opus 5 (Claude Code)
Previously "ifconfig eth0 up" fell through to the host-IP parsing
branch, where inet_addr("up") returns INADDR_NONE, so the address was
silently set to 255.255.255.255 and the interface was never brought
up. Users had to run the separate "ifup"/"ifdown" commands.
Recognize the "up" and "down" tokens explicitly and apply them once
the rest of the configuration is in place, so up/down is just another
keyword in the argument list as it is in Linux ifconfig.
A bare "ifconfig <iface> up|down" needs no special case: the preceding
patch made the address, netmask, gateway, DNS and DHCP blocks check
whether they were asked for, so the command falls through them without
touching anything.
The up/down handling calls netlib_ifup()/netlib_ifdown() from netlib, so
it stays available regardless of CONFIG_NSH_DISABLE_IFUPDOWN (which only
strips the standalone ifup/ifdown commands).
Assisted-by: GitHubCopilot:claude-opus-5
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
cmd_ifconfig() returns early for argc <= 2, so by the time the argument
loop is reached argc > 2 always holds. Remove the dead condition and
unindent the loop.
No functional change.
Assisted-by: GitHubCopilot:claude-opus-5
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
cmd_ifconfig() pushed every setting to the device on each invocation,
whether or not the command line carried it, and stopped parsing as soon
as it saw "mtu". So a command meant to touch one thing quietly rewrote
the rest of the interface configuration:
ifconfig eth0 hw 00:11:22:33:44:55 # clears the address, netmask,
# gateway and resolver, and kicks
# off a DHCP request
ifconfig eth0 mtu 1500 # same, plus the default route
ifconfig eth0 mtu 1500 dns 8.8.8.8 # dns silently ignored
In detail:
- the address was written unconditionally. For IPv6 that read the
uninitialized addr6 off the stack and pushed whatever it held into
the device; for IPv4 it forced 0.0.0.0.
- the netmask fell back to a hard-coded 255.255.255.0, or to
ffff:ffff:ffff:ffff:: for IPv6.
- the IPv4 gateway was always written, unlike the IPv6 one, so it fell
back to INADDR_ANY.
- the resolver fell back to that gateway, i.e. to 0.0.0.0.
- the DHCP client was started whenever gip was left at zero instead of
when "dhcp" was asked for, and gip only becomes non-zero when an
address or a gateway is parsed.
- the "mtu" branch returned as soon as netlib_set_mtu() succeeded, so
every argument behind it was dropped.
Write each setting only when the user provided it, or when an address
is being assigned and the setting belongs to it. Keeping the address
case is deliberate: a freshly assigned address still needs a mask and
a route, so dropping the derived netmask and "x.x.x.1" gateway there
would be a regression of its own. DHCP now triggers on the "dhcp"
keyword, which is the only way to request it. And with nothing left
to clobber, the "mtu" branch no longer has to bail out early.
This is how ifconfig behaves elsewhere: Linux net-tools walks the
argument vector in a single loop where every keyword handler ends in
"continue" and none of them returns, so each keyword is an independent,
idempotent operation applied in the order it was written.
As a side effect mip is now only read along the paths that assign it,
since the IPv4 gateway fallback only derives an address from mip when
gip came from hostip.
Assisted-by: GitHubCopilot:claude-opus-5
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
test_strcpy(), test_strncpy() and test_stpcpy() applied the same offset
to the source and to the destination, so both pointers always shared the
same word congruence. Architecture optimized copy routines take a
different code path when the two offsets differ: a byte prologue to
align the destination, then either a byte fallback or a shift-merge loop
that recombines two source words per store. None of that was reached by
the test.
Vary the source and destination offsets independently over 0..7 in those
three tests, so both the equal congruence (aligned word copy) and the
unequal congruence (shift-merge) paths are covered, and report both
offsets on failure so a regression points at the offending combination.
Also drop the ARCH_TOOLCHAIN_GNU dependency from TESTING_ARCH_LIBC. The
test only uses standard C string functions and perf_gettime(), with no
GNU specific construct, so it builds with non GNU toolchains such as
TASKING as well.
Impact: test only, selected by CONFIG_TESTING_ARCH_LIBC (default n).
Dropping the ARCH_TOOLCHAIN_GNU dependency only widens the set of
toolchains that may select the test, no existing configuration changes.
Testing: built and ran sim:nsh on Linux x86_64 (Ubuntu 24.04,
gcc 13.3.0) with CONFIG_TESTING_ARCH_LIBC=y. strcpy, strncpy and
stpcpy report PASSED for all 64 offset combinations, and
"arch_libc_test Passed".
Assisted-by: Claude:claude-opus-5
Signed-off-by: zhangyuan29 <zhangyuan29@xiaomi.com>
The adjacent overlap case in test_memmove() placed the source at a fixed
g_buf1 + align + 64 and the destination one size further, so the
destination tail reached align + 64 + 2 * size. g_buf1 is only
TEST_BUF_SIZE + MAX_ALIGN (528) bytes, so the larger swept sizes ran off
the end: align=0 with size=255 writes up to offset 573, that is 46 bytes
past the object. AddressSanitizer aborted arch_libctest with a
global-buffer-overflow.
Start the adjacent layout at g_buf1 + align instead. The tail then
reaches align + 2 * size, which is at most 7 + 2 * 257 = 521 and stays
inside g_buf1 for every alignment and boundary size that is swept, while
still keeping source and destination exactly adjacent.
Impact: test only, selected by CONFIG_TESTING_ARCH_LIBC (default n).
Testing: built and ran sim:nsh on Linux x86_64 (Ubuntu 24.04,
gcc 13.3.0) with CONFIG_TESTING_ARCH_LIBC=y. memmove reports PASSED
with no sanitizer report, and "arch_libc_test Passed".
Assisted-by: Claude:claude-opus-5
Signed-off-by: dengwenqi <dengwenqi@xiaomi.com>
Add test_strchrnul() and speed_strchrnul(), selected by the new
CONFIG_TESTING_ARCH_LIBC_STRCHRNUL option, covering the hit, miss and
NUL cases.
Sweep alignment 0..7 and the boundary sizes {0, 1, 7, 8, 9, 15, 16, 17,
31, 32, 33, 63, 64, 65, 127, 128, 129, 255, 256, 257} in the scan
function tests (memcmp, memchr, strlen, strcmp, strchr, strncmp,
strnlen, strrchr) and in memmove. Those sizes sit on the 8 and 16 byte
chunk edges and on the sub-word tails, so vectorized (NEON/MVE) and
word-at-a-time implementations are stressed exactly at their alignment
and size boundaries instead of only at "nice" lengths. memmove is
additionally exercised across four overlap layouts: forward, backward,
contained and adjacent.
Impact: test only, selected by CONFIG_TESTING_ARCH_LIBC (default n).
Testing: built and ran qemu-armv7a:nsh (Cortex-A7, generic C
implementation) and sim:nsh on Linux x86_64 (Ubuntu 24.04, gcc 13.3.0)
with CONFIG_TESTING_ARCH_LIBC=y. All 16 enabled functions report
PASSED and "arch_libc_test Passed". These tests pass against the
generic C routines, which establishes the correctness baseline before
architecture optimized assembly is introduced.
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
The arch_libc test only covered strcpy, so the architecture optimized
implementations of the remaining string and memory routines were never
exercised by the test suite.
Extend the test to also cover memcpy, memmove, memset, memcmp, memchr,
strlen, strcmp, strchr, strncmp, strnlen, strncpy, stpcpy, strcat and
strrchr:
* Every function gets a correctness test that sweeps the buffer
alignment and the transfer size and compares the result against the
expected value.
* Every function gets a speed test that reports the average cycle count
measured with perf_gettime().
* Every individual test is selected by its own
CONFIG_TESTING_ARCH_LIBC_<FUNC> option (default y), so a target can
drop the ones it does not need.
Impact: test only. Nothing is built unless CONFIG_TESTING_ARCH_LIBC
(default n) is selected, so no existing board configuration changes.
Testing: built and ran sim:nsh on Linux x86_64 (Ubuntu 24.04,
gcc 13.3.0) with CONFIG_TESTING_ARCH_LIBC=y. All 15 enabled functions
report PASSED and "arch_libc_test Passed".
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This companion change updates the nuttx-apps CMake build to use
NuttX’s NUTTX_DIR and NUTTX_BINARY_DIR instead of CMAKE_SOURCE_DIR
and CMAKE_BINARY_DIR, which incorrectly refer to the outermost project
when NuttX is embedded via add_subdirectory(). Since apps/ is itself
included from NuttX’s top-level CMakeLists.txt, these variables were
effectively being used as references to NuttX’s root and inherited
the same bug fixed in the matching NuttX change for #19697. All
self-referencing uses are replaced while intentionally preserving
standalone projects and unrelated custom variables or hardcoded paths.
The change affects only the CMake build system, preserves normal
standalone behavior, and was tested with sim:nsh both standalone and
embedded, with apps such as hello and ostest successfully built and
available in NSH.
Fixes#19697.
Assisted-by: Claude:claude-sonnet-5
Signed-off-by: Alan Carvalho de Assis <acassis@gmail.com>
The link line for applications in a kernel build is libmm, libc and the
proxies. libnx is never named, though the export has been shipping it
all along. So every application built on NX or NXFONTS fails to link,
the nx examples and fbcon alike, with undefined references to the font
and geometry routines.
Name it, ahead of libc since it calls into it, and only when CONFIG_NX
is set so that configurations without graphics are unaffected.
Tested on an EIC7700 EVB in a kernel build: with this, an application
built on NXFONTS links and runs; without it the same application fails
at link time.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Justin Hammond <justin@dynam.ac>
fbcon asked the registry of built-in applications for the stack size and
priority to spawn its shell with. A kernel build has no such registry:
its programs are ELF files in a filesystem, which is exactly what the
posix_spawn() below already handles, PATH search and all. The lookup
therefore fails to compile there.
Ask the registry only where there is one, and take the numbers from this
example's own configuration otherwise.
Tested on an EIC7700 EVB in a kernel build: fbcon renders its console on
a 1080p HDMI framebuffer and spawns a shell whose prompt appears on the
monitor.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Justin Hammond <justin@dynam.ac>
The terminal spawned "nsh" by a name compiled in, which finds nothing
on a system that installs NSH under another name, as a kernel build
does when NSH is the system's init: the program is /system/bin/init
and no "nsh" exists at all. The terminal came up,
took keystrokes, and had no shell behind it.
The name is now configurable and still defaults to "nsh", so a bare
name is looked up on PATH as before and a path is taken as given.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Justin Hammond <justin@dynam.ac>
A bare `boot` (no argument, argc == 1) passes argv[1] == NULL.
nsh_getfullpath(NULL) returns strdup(g_home) == "/" instead of NULL,
which turned the default-boot path (NULL -> board default image)
into "/". board_boot_image("/") then failed with -EINVAL (-22),
preventing the board from booting.
Guard the nsh_getfullpath() call so NULL passes through unchanged,
restoring the original default-boot behavior while still resolving
relative paths when an argument is given.
This fixes the regression introduced by the relative-path support
```
commit fabafbc361 (origin/master, origin/HEAD)
Author: Junbo Zheng <zhengjunbo1@xiaomi.com>
Date: Fri Jul 24 23:47:44 2026 +0800
nshlib: add relative image path support in boot command
cmd_boot passed the image path straight to boardctl(), which resolves
it in a context that does not inherit the NSH shell cwd, so relative
paths failed and only absolute paths worked. Use nsh_getfullpath() to
resolve relative paths against the cwd before calling boardctl().
Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
```
Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
Both the demo and the test asserted that each running instance of a module
gets its own copy of a library named in DT_NEEDED: two instances adding
their own seed each saw a total of seed*3.
That was true of the loader that walked DT_NEEDED itself. The loader now
hands the work to dlopen(), which returns the object already in the module
registry rather than loading a second copy of it, so there is one library
and one set of its globals, shared by every module that names it. The
module's own data stays private per instance, because exec() loads the
module afresh each time.
What an instance can still assert on its own is that every add it made
landed in the library, so that is what it checks; the totals interleave and
the final one counts both. The test additionally checks the consequences:
the library is pinned once rather than once per instance, and its
destructor runs once, at the last close, holding what both instances built
up.
USER_FAIL_PRIVATE becomes USER_FAIL_SHARED rather than gaining a
companion. The bit is a private protocol between cxxuser.cpp, which sets
it, and testing/fs/xipfs, which reads it; nothing else names it, and the
property it used to report no longer exists.
Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
The two helper scripts this Makefile names gained a file extension when
tools/fdpic came into the nuttx tree: checkpatch rejects an executable file
that is not .sh, .py or .bat.
Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
Forward the packets received by a LoRa concentrator to a LoRaWAN network
server with the Semtech UDP protocol version 2, and turn the downlink
requests of the server into transmissions. The server may be given as a name
and is resolved with getaddrinfo(). No floating point is used anywhere.
The same program provides the "lora" command, which mirrors the AT command
set of the vendor gateway firmwares, plus tx, which sends a single packet and
so brings a gateway up against any LoRa receiver without a network server.
Nothing here names a chip: the types and the commands are the device
independent gateway ones of the nuttx repository,
nuttx/wireless/lpwan/lora_gw.h. The application depends on LPWAN_LORA_GW,
the symbol such a driver selects, so until one is merged nothing here is
compiled.
Assisted-by: Claude Code 4.8
Signed-off-by: Jorge Guzman <jorge.gzm@gmail.com>
Allow pull requests targeting master to declare same- and
cross-repository dependencies. Parse declarations with a tested Python
helper, apply exact dependency commits before the existing build matrix,
and rerun heavy CI only when an edited description changes the dependency
state.
Keep fork builds read-only and use a trusted workflow_run to validate
artifacts and post per-build dependency results. Keep the apps workflow
consistent with the implementation already merged in apache/nuttx.
Assisted-by: Kiro:gpt-5.6-sol
Signed-off-by: zhangning21 <zhangning21@xiaomi.com>
The CMake build passed no STACKSIZE, so kernel-mode ELF loading fell
back to CONFIG_ELF_STACKSIZE, which may exceed the initial user heap.
Use CONFIG_DEFAULT_TASK_STACKSIZE as the Makefile does.
Signed-off-by: raiden00pl <raiden00@railab.me>
Assisted-by: Claude Code
Verify that a mutex remains reusable after its last waiter times out
and that ownership is transferred when another waiter remains queued.
Signed-off-by: Martin Krasula <mkrasula@elektroline.cz>