Skip to content

toybox: new feature, boards configuration, documentation, other updates. - #19818

Open
acassis wants to merge 7 commits into
apache:masterfrom
acassis:toybox
Open

toybox: new feature, boards configuration, documentation, other updates.#19818
acassis wants to merge 7 commits into
apache:masterfrom
acassis:toybox

Conversation

@acassis

@acassis acassis commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Toybox is the tool box used on Android by default. Adding it to NuttX allows to have more advanced features from Linux, even better support for shell scripts.

Depends-on: apache/nuttx-apps#3722

Impact

User could use a shell more similar to Linux and even use real shell scripts from Linux

Testing

$ ./nuttx 

Toybox 0.8.14-nuttx for NuttX -- 'help' lists commands, 'exit' leaves the prompt.

toybox> help
[ base64 basename cal cat chgrp chmod chown cksum clear cmp comm cp
cpio cut date dd df diff dirname dos2unix du echo egrep env expand
expr fallocate false fgrep file find fmt free fsync getopt grep groups
gunzip gzip head help hostname id kill killall ln logname ls md5sum
mkdir mkfifo mktemp mv nice nl nohup nproc od paste pgrep pidof pkill
printenv printf prlimit ps pwd readlink realpath renice rev rm rmdir
sed seq setsid sha1sum sha224sum sha256sum sha384sum sha512sum sleep
sort split stat strings sync tac tail tar tee test time timeout touch
tr true truncate ulimit uname uniq unix2dos unlink uptime usleep uudecode
uuencode uuidgen wc which whoami xargs xxd yes zcat 

toybox> uname -a
NuttX  0.0.0 6c5a59b1-dirty Aug 12 2026 14:38:48 sim Toybox

toybox> ls /dev
console  gpio1  gpio3  null     ram0  rtc0
gpio0    gpio2  loop   oneshot  ram1  zero
toybox> 

@github-actions github-actions Bot added Area: Documentation Improvements or additions to documentation Size: M The size of the change in this PR is medium Board: arm Board: simulator labels Aug 12, 2026
@github-actions

github-actions Bot commented Aug 12, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

arduino-mega2560

  • flash: .text -84 B (-0.1%, 67,538 B / 262,144 B, total: 26% used)

esp32-devkitc

  • ROM: .flash.text +20 B (+0.0%, 124,416 B / 4,194,272 B, total: 3% used)
  • irom0_0_seg: .flash.text +20 B (+0.0%, 88,620 B / 3,342,304 B, total: 3% used)

hifive1-revb

  • flash: .text +8 B (+0.0%, 83,380 B / 4,194,304 B, total: 2% used)

qemu-armv8a

  • Code: .text.inode_nextname +20 B (+0.0%, 316,740 B)

qemu-intel64

  • Code: .text +14 B (+0.0%, 8,657,198 B)

rx65n-rsk2mb

  • ROM: .text +16 B (+0.0%, 87,312 B / 2,097,152 B, total: 4% used)

s698pm-dkit

  • Code: .text +80 B (+0.0%, 364,016 B)

stm32-nucleo-f103rb

  • flash: .text +8 B (+0.0%, 34,024 B / 131,072 B, total: 26% used)
    No memory changes detected for:
  • mirtoo

padlen = sizeof(void *) - (addr % sizeof(void *)) never returns 0, even
when addr is already pointer-aligned -- it returns a full alignment unit
instead. Since callers size buflen for zero padding, the subsequent
"buflen < padlen + reqdlen" check then always fails, so getgrgid()/
getgrnam() and their _r variants always return ERANGE.

Found via `id` on sim:toybox, which resolves gid 0 to "root" through
this path.

Signed-off-by: Alan C. Assis <acassis@gmail.com>
Assisted-by: Claude Sonnet 5 <noreply@anthropic.com>
wait4() is BSD/Linux-standard (used by toybox's "time" applet) but NuttX
only had waitpid()+getrusage() separately. Add it to libs/libc/unistd/
built on top of those two existing primitives, so it needs no syscall
plumbing of its own and works unmodified across flat/protected/kernel
build separation. Prototype added to include/sys/wait.h.

Signed-off-by: Alan C. Assis <acassis@gmail.com>
Assisted-by: Claude Sonnet 5 <noreply@anthropic.com>
inode_nextname() already skipped a '.' segment mid-path (e.g. "./foo"),
but only checked for a '/' right after it -- a path ending in a bare
'.' (e.g. "/foo/.", or "." itself once AT_FDCWD resolution prepends
$PWD) fell through and was looked up as a literal child named ".",
which no real node is ever named, failing with ENOENT.

This broke every "operate on the current directory" idiom relative
paths rely on: bare `ls`, `stat .`, `cd .`, etc., all failed outright
even though the equivalent absolute path worked fine. Found while
testing the Toybox port's interactive REPL, but this is generic VFS
path resolution, not Toybox-specific.

Signed-off-by: Alan C. Assis <acassis@gmail.com>
Assisted-by: Claude Sonnet 5 <noreply@anthropic.com>
CONFIG_SYSTEM_TOYBOX=y with CONFIG_INIT_ENTRYPOINT="toybox_main":
Toybox as the system's shell instead of NSH. No NSH config is present
-- Toybox has no dependency on it in either direction (see
apps/system/toybox/Kconfig's SYSTEM_TOYBOX_BUILTIN_BRIDGE).

Signed-off-by: Alan C. Assis <acassis@gmail.com>
Assisted-by: Claude Sonnet 5 <noreply@anthropic.com>
Same shape as boards/sim/sim/sim/configs/toybox: CONFIG_SYSTEM_TOYBOX=y
with CONFIG_INIT_ENTRYPOINT="toybox_main", built on top of the existing
stm32f4discovery:nsh defconfig's board/console setup.

Needs several options nsh's defconfig doesn't, since Toybox's library
code references more of NuttX's libc unconditionally than NSH does:
CONFIG_ALLOW_MIT_COMPONENTS (gates CONFIG_LIBC_REGEX -- grep/sed/etc),
CONFIG_ARCH_SETJMP_H (sigjmp_buf; the REPL's rebound trap uses
sigsetjmp/siglongjmp), CONFIG_LIBC_EXECFUNCS, CONFIG_LIBC_LOCALE,
CONFIG_LIBC_LOCALTIME, CONFIG_PIPES, CONFIG_PSEUDOFS_SOFTLINKS,
CONFIG_FS_NOTIFY (tail -f), CONFIG_SCHED_HAVE_PARENT (waitpid()).

Signed-off-by: Alan C. Assis <acassis@gmail.com>
Assisted-by: Claude Sonnet 5 <noreply@anthropic.com>
Basic usage/configuration reference for the toybox application, plus
known limitations: ps lists no processes (it expects Linux's
/proc/<pid>/stat, which NuttX's procfs doesn't provide), and grep -r
is unreliable against procfs.

Signed-off-by: Alan C. Assis <acassis@gmail.com>
Assisted-by: Claude Sonnet 5 <noreply@anthropic.com>
tzset() is unconditionally defined in libs/libc/time/lib_localtime.c,
but its prototype in <time.h> is gated behind CONFIG_LIBC_LOCALTIME --
without it, Toybox's own tzset() calls (lib/xwrap.c, toys/posix/date.c)
compile as implicit declarations instead. The stm32f4discovery:toybox
defconfig already carries this option (see its own commit message);
sim:toybox's was simply missing it.

Signed-off-by: Alan C. Assis <acassis@gmail.com>
Assisted-by: Claude Sonnet 5 <noreply@anthropic.com>
@acassis acassis changed the title Toybox boards/sim, boards/stm32f4discovery: Add support to toybox Aug 12, 2026
@acassis
acassis requested review from cederom and linguini1 August 12, 2026 18:15
@cederom cederom changed the title boards/sim, boards/stm32f4discovery: Add support to toybox toybox: new feature, boards configuration, documentation, other updates. Aug 12, 2026

@cederom cederom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @acassis amazing feature and great work!! :-)

Comment thread boards/sim/sim/sim/configs/toybox/defconfig
@cederom

cederom commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

msys2 build failed :-(

@acassis

acassis commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

msys2 build failed :-(

It is the internal CI issue to download some artifacts

@github-actions

Copy link
Copy Markdown

🔗 Cross-repo PR dependencies

The read-only Build run reported the following dependent PR(s) and fetched head SHA(s):

CI run: https://github.com/apache/nuttx/actions/runs/31637144938

@cederom

cederom commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

will restarting ci help in this case @acassis ? :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Documentation Improvements or additions to documentation Board: arm Board: simulator Size: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants