Commit graph

1195 commits

Author SHA1 Message Date
Abhishek Mishra
fc14d02ae0 nshlib,fsutils: add Kconfig deps for NSH console login with PBKDF2
Require a cryptodev backend for FSUTILS_PASSWD and tie NSH console/telnet
login to ROMFS passwd generation when ETC_ROMFS is enabled.

Fixes #19573

Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
2026-07-31 10:20:23 +08:00
Abhishek Mishra
92c3b6446d nsh: show real, effective, and saved IDs in id command
Use getresuid() and getresgid() for Linux-style id output with name
resolution and a groups= list based on the effective GID.

Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
2026-07-31 01:14:30 +08:00
Junbo Zheng
fabafbc361 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>
2026-07-27 09:38:34 -03:00
Junbo Zheng
101b713be6 nshlib: add du command support
Add a du command to NSH that recursively summarizes the size of each
path argument in 1K-blocks, or human-readable form with -h.

Supports -s (summary only), -a (all files), -d N (max-depth), and -h,
matching GNU du semantics.

Testing:

Built and ran on sim:nsh with:
```bash
  cmake -B out/nuttx_sim_nsh -S nuttx -DBOARD_CONFIG=sim:nsh -GNinja
  ninja -C out/nuttx_sim_nsh
  ./out/nuttx_sim_nsh/nuttx

  nsh> du
  397449  /data/test/elf
  71993   /data/test/coredump
  5       /data/test/log2
  3251    /data/test/log1
  472700  /data/test

  nsh> du -h
  388.1M  /data/test/elf
  70.3M   /data/test/coredump
  4.1K    /data/test/log2
  3.1M    /data/test/log1
  461.6M  /data/test
```

Host Ubuntu22.04 du on the same directory:
```bash
  $ du
  397456  ./elf
  72000   ./coredump
  8       ./log2
  3252    ./log1
  472720  .

  $ du -h
  389M  ./elf
  71M   ./coredump
  8.0K  ./log2
  3.2M  ./log1
  462M  .
```

Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
2026-07-26 07:39:39 -03:00
Alan C. Assis
48eb95998b readline: Make prompt-caching available
readline cached the current prompt only when TAB completion was enabled,
even though line-editing redraws also depend on that cached prompt.
With TAB completion disabled, full-line redraws erased the prompt and
repainted only the command buffer. Make the prompt cache available
whenever line editing is enabled.

Signed-off-by: Alan C. Assis <acassis@gmail.com>
2026-07-24 14:12:38 -03:00
Alan C. Assis
51bfd48e78 system/readline: Add support for line movements and editing
This commit adds support to nsh> command line editing. This is one
of the most missing feature of the NuttShell. If you typed a long
command line and make a mistake you need to press Backspace and
remove everything until reach that typo. Only the basic editing
feature is enabled by default (left/right keys movement, Home/End
to move to the beginning or ending of the command line).

More advanced features are available when CONFIG_READLINE_EDIT_EMACS
is selected. It enables the Emacs-style control keys (Ctrl+A/B/D/E/F/K/U/W)
that allow more flexible line editing.

Other more advanced feature is enabled when CONFIG_READLINE_CMD_HISTORY
and CONFIG_READLINE_EDIT_EMACS_REVERSE_SEARCH are enabled. It allows the
user to press Ctrl+R to do reverse search in the command line history.

Signed-off-by: Alan C. Assis <acassis@gmail.com>
Assisted-by: Claude Code
2026-07-24 14:12:38 -03:00
Abhishek Mishra
c02683e282 !nshlib: Remove fixed login; require FSUTILS_PASSWD
Report password policy failures clearly from useradd and passwd when a
password does not meet complexity requirements.

Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
2026-07-22 17:21:22 +08:00
Abhishek Mishra
608f13fd4b !fsutils/passwd: Replace TEA with PBKDF2-HMAC-SHA256
Migrate passwd encrypt/verify to PBKDF2 modular crypt format using
kernel cryptodev (CRYPTO_PBKDF2_HMAC_SHA256 via /dev/crypto).  Add
passwd_pbkdf2 wrapper, base64url helpers, complexity validation, and
pbkdf2_test for RFC 6070 vector coverage.  FSUTILS_PASSWD selects
CRYPTO, ALLOW_BSD_COMPONENTS, and CRYPTO_CRYPTODEV so existing sim
defconfigs keep building.  Change NSH_LOGIN_USERNAME default to root and
remove fixed-login password defaults.

BREAKING CHANGE: TEA-encoded /etc/passwd entries no longer verify.
Regenerate each entry after upgrading.  Pair with the nuttx host mkpasswd
changes in apache/nuttx#19209.  Boards must enable the appropriate
software or hardware crypto backend for PBKDF2 at runtime.  When
CONFIG_NSH_LOGIN_FIXED=y, set CONFIG_NSH_LOGIN_PASSWORD in the board
defconfig or menuconfig; there is no default password.

Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
2026-07-22 17:21:22 +08:00
Jorge Guzman
62b7e95530 nshlib: top: add Linux-like summary and flicker-free refresh
Print a summary header before the task list in the style of the
Linux top command: uptime, task counts (total/running/sleeping),
CPU busy/idle and memory usage, all gathered via sysinfo().

Refresh the screen in place (cursor home + erase-line per row +
erase-below) instead of clearing the whole screen every cycle,
which removes the flicker.

Poll stdin during the update interval and exit on 'q', ESC or
Ctrl-C. Previously the only exit path was the SIGINT handler,
which requires both CONFIG_ENABLE_ALL_SIGNALS (handler) and
CONFIG_TTY_SIGINT (serial console converts Ctrl-C into SIGINT,
default n); on configurations missing either option top could
not be terminated at all.

Tested on linum-stm32h753bi:nsh.

Signed-off-by: Jorge Guzman <jorge.gzm@gmail.com>
2026-07-12 10:00:40 +08:00
orbisai0security
d071a0b585 fix: V-001 security vulnerability
Automated security fix generated by OrbisAI Security

Signed-off-by: OrbisAI Security <mediratta01.pally@gmail.com>
2026-07-10 13:01:42 +08:00
Alan Carvalho de Assis
caa7d7faa5 apps/nsh: Don't disable error by default
NSH error shouldn't be disabled by default, even when in SMALL
Memory because it will make difficult to discover why things are
not working. It should be disabled manually by experienced dev.

Signed-off-by: Alan C. Assis <acassis@gmail.com>
2026-07-06 09:13:02 -03:00
hanzhijian
9b51035300 nshlib/nsh_fscmds: Fix potential NULL pointer dereferences
Fix two potential NULL pointer dereferences in nsh_fscmds.c:

1. fdinfo_callback: asprintf() failure left filepath potentially
   NULL, which was then passed to nsh_catfile(). Add early return
   on asprintf failure.

2. cmd_cat: malloc(BUFSIZ) for stdin reading was used without
   checking the return value. Add NULL check with -ENOMEM return.

Also fix a typo in error message: 'nsh_catfaile' -> 'nsh_catfile'.

Signed-off-by: hanzhijian <hanzhijian@zepp.com>
2026-06-30 10:05:08 -03:00
hanzhijian
f57aa7b4cf nshlib/nsh_fscmds: Display modification time in ls -l output
Fixes #17063

Add modification time display to ls -l long format output.
The timestamp is shown as 'YYYY-MM-DD HH:MM' between the permission
string and the file size, following the ISO long-iso format.

Files with st_mtime == 0 (e.g., procfs, tmpfs pseudo-entries) skip
the timestamp display to avoid showing a meaningless epoch time.

Signed-off-by: hanzhijian <hanzhijian@zepp.com>
2026-06-30 10:03:03 -03:00
Xiang Xiao
4c560ef0a2 apps: Replace O_RDOK with O_RDONLY after alias removal
The O_RDOK/O_WROK aliases have been removed from fcntl.h.  Replace
all remaining O_RDOK usage with O_RDONLY in the apps repository.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2026-06-28 13:00:52 +02:00
Alan Carvalho de Assis
ae718ba47f nsh/echo: Fix echo previous behavior, single write with '\n'
This commit fixes the previous behavior where an echo with a
single string and its default new line is send as single write().

This issue came from:  https://github.com/apache/nuttx-apps/pull/1559

Signed-off-by: Alan C. Assis <acassis@gmail.com>
2026-06-27 13:44:14 +02:00
Felipe Moura
fee2ddbf54 netutils/dropbear: add Dropbear SSH server port for NuttX
Integrated SSH daemon authenticating against FSUTILS_PASSWD, with an
ECDSA P-256 host key and an NSH session over a PTY per connection. Built
from the upstream Dropbear tarball (pinned commit) and patched for
NuttX, using Dropbear's bundled libtomcrypt for all crypto. setsid()
(apache/nuttx#19184) and link() now come from NuttX, not local stubs.

Signed-off-by: Felipe Moura <moura.fmo@gmail.com>
2026-06-27 08:42:00 -03:00
Abhishek Mishra
75ee4d9090 nshlib: Add su, id, and whoami identity commands
Add NSH commands for switching effective credentials and inspecting
session identity. Update login and prompt to reflect effective user.

Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
2026-06-20 15:38:45 -03:00
wangjianyu3
ed063a0981 nshlib: fix infinite loop on broken stdout in nsh_catfile
When stdout is broken (e.g. PTY master closed), nsh_catfile could spin
forever: write() fails, error logging generates syslog output to
/dev/log, next read() picks it up, write() fails again, ad infinitum.

Two fixes:
- nsh_console: drop the _err() in nsh_consolewrite entirely.  The risk
  is errno-agnostic (EPIPE / EIO / ENOSPC / ...): any failure logged
  here can be re-injected by the syslog backend when OUTFD is bound to
  /dev/log.  Callers already see the failure via the negative return
  value and errno, so on-failure logging at this layer is redundant.
- nsh_fsutils: jump straight from the inner write-failure path to a
  single errout: cleanup label instead of using a two-level break +
  flag check, so a failed write cannot fall through to another read().

Assisted-by: GitHubCopilot:claude-4.7-opus
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2026-05-26 16:06:28 -03:00
Nightt
c44f9a0556 apps: Fix unchecked strdup()/asprintf() as requested in #1727
Add missing failure handling for direct strdup() and asprintf() calls where the allocated result is consumed locally before any NULL/error check.

This keeps the scope to the functions named in #1727 and avoids changing pass-through return sites where callers already receive NULL on allocation failure.

Signed-off-by: Nightt <87569709+nightt5879@users.noreply.github.com>
2026-05-23 16:30:52 -04:00
Nightt
5c703f5603 nshlib/testing: Fix open() arguments.
Pass explicit open flags for the NSH script redirect file so the mode argument is used as file creation permissions.

Add the missing mode argument to AIO ostest open() calls that create the test file.

Signed-off-by: Nightt <87569709+nightt5879@users.noreply.github.com>
2026-05-22 13:39:04 +08:00
Xiang Xiao
f9f59bd0f8 !apps: drop redundant casts on tv_sec/tv_nsec and fix printf formats
Now that time_t is unconditionally 64-bit (signed int64_t) and the
struct timespec fields tv_sec / tv_nsec are wide enough on their own,
the explicit (uint64_t)/(int64_t)/(int) casts that used to guard the
multiplications and subtractions in *_us / *_ms / *_ns helpers are no
longer needed.  Drop them to keep the timekeeping math readable.

In the same spirit, this commit also normalises the printf-style format
specifiers and casts used to print tv_sec / tv_nsec / tv_usec values.
The prior code was a mix of "%d"/"%u"/"%ld"/"%lu"/"%lld" with matching
(int)/(unsigned long)/(long long) casts; some formats truncated time_t
on 32-bit hosts, others mismatched signedness or width.  Replace all
such cases with the portable POSIX-recommended forms:

  - tv_sec  (time_t,       signed, impl-defined width) -> %jd  + (intmax_t)
  - tv_nsec (long,         signed)                     -> %ld  (no cast)
  - tv_usec (suseconds_t / long)                       -> %ld  (no cast)

Also drop two stale `(FAR const time_t *)&ts.tv_sec` casts that are
unnecessary now that ts.tv_sec is plain time_t.

Arithmetic-cleanup files (existing scope):

  - benchmarks/cyclictest/cyclictest.c:        timediff_us()
  - benchmarks/sd_bench/sd_bench_main.c:       get_time_delta_us()
  - examples/oneshot/oneshot_main.c:           maxus computation
  - examples/watchdog/watchdog_main.c:         current_time_ms (x2)
  - industry/nxmodbus/nxmb_internal.h:         nxmb_util_clock_ms()
  - netutils/ntpclient/ntpclient.c:            timespec2ntp()
  - netutils/ptpd/ptpd.c:                      ptp_adjtime()
  - system/dd/dd_main.c:                       elapsed accounting
  - testing/drivers/drivertest/drivertest_posix_timer.c:
                                               get_timestamp()
  - testing/drivers/sd_stress/sd_stress_main.c:get_time_delta()
  - testing/sched/getprime/getprime_main.c:    elapsed accounting
  - testing/sched/pthread_mutex_perf/pthread_mutex_perf.c:
                                               timespec_avg()

Printf-format-fix files (new in this revision):

  - examples/adjtime/adjtime_main.c
  - examples/charger/charger_main.c
  - examples/netpkt/netpkt_ethercat.c
  - fsutils/mkfatfs/mkfatfs.c
  - graphics/tiff/tiff_initialize.c
  - netutils/ptpd/ptpd.c
  - nshlib/nsh_timcmds.c
  - system/coredump/coredump.c
  - system/ptpd/ptpd_main.c
  - testing/drivers/drivertest/drivertest_oneshot.c
  - testing/mm/kasantest/kasantest.c
  - testing/ostest/semtimed.c
  - testing/sched/pthread_mutex_perf/pthread_mutex_perf.c
  - testing/sched/timerjitter/timerjitter.c
  - testing/testsuites/kernel/time/cases/clock_test_clock01.c
  - testing/testsuites/kernel/time/cases/clock_test_smoke.c

No behavioural change.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2026-05-22 13:38:25 +08:00
Abhishek Mishra
ecfc1b5b61 nshlib: add chmod and chown builtins
Add minimal chmod/chown support to NSH using the
existing libc/VFS syscall interfaces.

Supported forms:

  - chmod <octal-mode> <path>
  - chown <uid>[:gid] <path>

The chown implementation supports the numeric
ownership forms already handled by the underlying
NuttX chown() implementation, including unchanged
uid/gid semantics via omitted fields.

Only numeric permission modes and numeric uid/gid
forms are supported in this initial implementation.

This adds interactive filesystem permission and
ownership management support to NSH and aligns the
shell more closely with standard POSIX environments.

Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
2026-05-19 09:56:24 +08:00
Matteo Golin
5b0cae9ab0 !apps: Simplify NuttX initialization
BREAKING: In an effort to simplify board initialization logic for NuttX,
NSH will no longer support architecture initialization. This will happen
during boot via the BOARD_LATE_INITIALIZE option. The boardctl command
BOARDIOC_INIT is also no longer available from user-space.

Quick fix:
Any application relying on BOARDIOC_INIT should now enable
BOARD_LATE_INITIALIZE to have initialization performed by the kernel in
advance of the application running. If control over initialization is
still necessary, BOARDIOC_FINALINIT should be implemented and used.
Boards relying on NSH for initialization should also enable
BOARD_LATE_INITIALIZE instead.

Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
2026-05-06 13:27:05 +08:00
Michal Lenc
8e9f5a8d3a nshlib/nsh_timcmds.c: fix incorrect time set during summer time
Value zero in tm_isdst means daylight saving time (or summer
time) is not in effect. This is obviously not true for half of the year
in most timezones and keeping it at zero leads to incorrect time
being set. This commit sets tm_isdst to -1, which means the information
is not available and it should be handled according to timezone rules.

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
2026-04-17 11:11:53 -03:00
Piyush Patle
9d849adfab include/debug.h: Use <nuttx/debug.h> in apps
Replace app-side includes of <debug.h> with <nuttx/debug.h> to use the
header from the NuttX tree explicitly after the header move.

Signed-off-by: Piyush Patle <piyushpatle228@gmail.com>
2026-04-11 10:39:27 -03:00
zhanghongyu
d48b45000d netlib_xarp: remove redundant cast
removes redundant type casts in ARP-related network library functions.
The casts from req.arp_dev (already a char array) to (FAR char *)
are unnecessary and can be safely removed.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-02-04 01:52:49 +08:00
zhaoxingyu1
d9d434d97e mtdconfig: lomtdconfig device change to depends on !MTD_CONFIG_NONE
Because  MTD_CONFIG configuration item in drivers/mtd/Kconfig
has changed.

Signed-off-by: zhaoxingyu1 <zhaoxingyu1@xiaomi.com>
2026-02-02 11:01:19 +08:00
fangpeina
35f3690a4c nshlib: Add stderr redirection support
This commit implements stderr redirection in HSN, support
Bash-like syntax for redirecting standard error output.
Support both foreground and background commands.

example:
- nsh> ls noexists 2> err.log
- nsh> ls noexists 2> err.log &
- nsh> ls noexists 2>> err.log
- nsh> sh < /dev/ttyS0 > /dev/ttyS0 2> /dev/ttyS1 &
- nsh> sh < /dev/ttyS0 > /dev/ttyS0 2>&1 &

Signed-off-by: fangpeina <fangpeina@xiaomi.com>
2026-01-27 03:14:00 +08:00
guohao15
197401975a mtdconfig: support ram_mtdconfig device && lomtdconfig device
For nvs test in qemu

Signed-off-by: guohao15 <guohao15@xiaomi.com>
2026-01-23 10:07:11 +08:00
zhenwei fang
72fe4e21e1 nsh: fix nsh redirect fd double close
avoid double-close of redirection fds

Signed-off-by: zhenwei fang <fangzhenwei@bytedance.com>
2026-01-21 14:42:50 -03:00
wangchengdong
d9afe2db8c signals: fix build and runtime issues when signals all isabled
Fix build and runtime issues when signals all disabled.

Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
2026-01-19 22:55:19 +08:00
wangchengdong
60d814efa2 sched/signal: Add support to disable partial or all signals
Fix dependency issue when signals are partially or fully enabled

Co-authored-by: guoshichao <guoshichao@xiaomi.com>
Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
2026-01-15 15:48:54 +08:00
Zhe Weng
10eae1dc6b vconfig: Support setting default PCP when creating VLAN
Now we allow setting a default PCP when creating VLAN like:
`vconfig add iface-name vlan-id [pcp]`
e.g.
`vconfig add eth0 10` will create eth0.10 with VID=10 and no PCP(0)
`vconfig add eth0 10 3` will create eth0.10 with VID=10 and PCP=3

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2026-01-08 22:51:19 +08:00
Zhe Weng
ae7c168bf6 nshlib: Add vconfig command
Add vconfig command

Signed-off-by: gaohedong <gaohedong@xiaomi.com>
2026-01-08 22:51:19 +08:00
mazhuang
9c4103d496 nsh_syscmds/rpmsg: add rpmsg test command support
User can use rpmsg test /dev/rpmsg/<cpuname> to test the rpmsg
channel

Signed-off-by: mazhuang <mazhuang@xiaomi.com>
2026-01-08 22:50:11 +08:00
dongjiuzhu1
c90b64ed8b nshlib/ls_handler: eliminate floating-point operations for human-readable sizes
Replace floating-point arithmetic with fixed-point integer math to avoid
linking soft-float library (~2-3KB Flash) when displaying human-readable
file sizes (ls -lh command).

Changes:
- Use integer division and modulo to calculate size components
- Calculate decimal part: (remainder * 10) / unit for one decimal place
- Refactor duplicated code: consolidate GB/MB/KB logic into single path
- Remove CONFIG_HAVE_FLOAT dependency

This eliminates calls to __aeabi_f2d, __aeabi_fmul, __aeabi_i2f and other
ARM EABI floating-point helpers, reducing Flash footprint for systems
compiled with -mfloat-abi=soft.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-12-31 16:32:27 -03:00
gaohedong
74c71145da net/ethernet: ARP can be configured on interface
ARP can be configured on interface

Signed-off-by: gaohedong <gaohedong@xiaomi.com>
2025-12-25 12:25:02 +08:00
zhengyu16
cfff7f5a22 nshlib: add -f for umount
adds support for the -f (force) option to the NSH umount command

Signed-off-by: zhengyu16 <zhengyu16@xiaomi.com>
2025-12-10 12:16:49 +08:00
yangsong8
f82e6c2229 nsh: return EOF when nread is 0
If enable CONFIG NSH_CLE. When sh reads data and detects that nread is 0,
return EOF and exit.

Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
2025-12-10 11:24:14 +08:00
yangsong8
2bc4bdadee apps/nsh: fix switchboot command spelling error
modify swtichboot -> switchboot

Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
2025-12-10 11:24:14 +08:00
Jukka Laitinen
c3247ecc6c nshlib/nsh_fscmds.c: Allocate a PATH_MAX sized buffer for unlink_recursive
This fixes heap corruption when deleting a folder containing other folders
or files. The issue appeared at commit 131d50ae9d, which removed the
stack-based temporary buffer.

unlink_recursive requires that the path is provided in PATH_MAX sized
buffer. It concatenates sub-folder or file names to the same buffer.

nsh_getfullpath just allocates a buffer using strdup, so there is no room
for concatenating more data to it.

To keep the stack usage smaller, instead of reverting the breaking commit,
allocate the temporary buffer with lib_get_pathbuffer instead.

Signed-off-by: Jukka Laitinen <jukka.laitinen@tii.ae>
2025-11-26 10:27:47 -05:00
Michal Lenc
761f25c857 nshlib/nsh_proccmds.c: fix description for TID and switch order
ID previously marked as PID was in fact TID. PID was hidden under
GROUP column. This fixes the description. The order of TID, PPID, PID
is also changed to more logical TID, PID, PPID.

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
2025-11-07 10:32:42 +08:00
wangjianyu3
bc73779144 nshlib/nsh_parse: Fix "e" flag not take effect
The NSH exits when a command exits with a non-zero status, even if the "e" flag is not set.
This error does not exist in NSH scripts.

Without this patch:

  nsh> sh -c "set -e; mkdir /test; echo $?"
  nsh: /test: mkdir failed: 17
  nsh> sh -c "set +e; mkdir /test; echo $?"
  nsh: /test: mkdir failed: 17
  nsh> rm /test
  nsh> sh -c "set +e; mkdir /test; echo $?"
  0

With this patch:

  nsh> sh -c "set -e; mkdir /test; echo $?"
  nsh: /test: mkdir failed: 17
  nsh> sh -c "set +e; mkdir /test; echo $?"
  nsh: /test: mkdir failed: 17
  1
  nsh> rm /test
  nsh> sh -c "set +e; mkdir /test; echo $?"
  0

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2025-09-18 02:15:49 +08:00
wangjianyu3
10cab6bf6d nshlib/nsh_syscmds: Fix resetcause and rpmsg_help typos
nshlib/nsh_syscmds.c:111: unkown ==> unknown
nshlib/nsh_syscmds.c:651: acknowlege ==> acknowledge

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2025-09-17 10:07:24 +02:00
wangjianyu3
09f0f89e3a nshlib/reset_cause: Fix format warning for flag
Fix format string not appropriate warning for cause.flag.

nsh_syscmds.c: In function 'cmd_reset_cause':
nsh_syscmds.c:513:24: error: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'uint32_t' {aka 'unsigned int'} [-Werror=format=]
  513 |       nsh_output(vtbl, "%s(%lu)\n",
      |                        ^~~~~~~~~~~
  514 |              g_resetcause[cause.cause], cause.flag);
      |                                         ~~~~~~~~~~
      |                                              |
      |                                              uint32_t {aka unsigned int}

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2025-09-17 10:07:24 +02:00
wangchengdong
93060aa59d nshlib/nsh_builtin.c : Add support to run builtin dirrectly as command
Add a new config: NSH_BUILTIN_AS_COMMAND.
  Provide a new implementation for nsh_builtin
  when CONFIG_NSH_BUILTIN_APPS_AS_COMMAND is enabled.

Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
2025-09-11 20:00:20 +08:00
wangjianyu3
8d2a7e32a5 nshlib: Add ppid support for command ps
Add parent process ID support for command ps,
get from "/proc/<PID>/group/status:Parent".

For example

  nsh> sh
  nsh> ps
    PID  PPID GROUP CPU PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK            STACK COMMAND
  ... ...
      3     0     3 --- 100 RR       Task      - Waiting  Signal    0000000000000000 0008136 nsh_main
  ... ...
      9     3     9   0 100 RR       Task      - Running            0000000000000000 0004064 sh

  nsh> sleep 100 &
  sh [10:100]
  nsh> ps
    PID  PPID GROUP CPU PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK            STACK COMMAND
  ... ...
      3     0     3 --- 100 RR       Task      - Waiting  Signal    0000000000000000 0008136 nsh_main
  ... ...
      9     3     9   0 100 RR       Task      - Running            0000000000000000 0004064 sh
     10     9    10 --- 100 RR       Task      - Waiting  Signal    0000000000000000 0004040 sh -c sleep

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2025-08-03 22:56:32 +08:00
wangjianyu3
c3e628c45a nshlib/md5: Support reading from standard input
Sometimes users may want to calculate the MD5 of part of a file(e.g. check
partition contents for debug after flashing, size of which may be greater
than image). This can be done with the "dd" command and pipes, the "md5"
command just needs to support reading from standard input. For example:
`dd if=/dev/virtblk0 bs=512 count=1 | md5`.

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2025-07-02 10:59:40 -03:00
dongjiuzhu1
fb6b3ddfd9 nsh/script: remove double close for output fd
the output fd had been closed in nsh_closeifnotclosed, so
remove double close.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-05-14 15:03:35 +08:00
dongjiuzhu1
5585c9d347 nshlib/dd: remove nsh dd cmd
using system/dd to instead nsh dd cmd
remove related to config, file.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-04-20 00:41:18 +08:00