Commit Graph

1059 Commits

Author SHA1 Message Date
chao an
05ffbabca7 nsh/uname: improve compatibility for non-GNU compilers
The alloca() function is machine- and compiler-dependent.  For certain
applications, its use can improve efficiency compared to the use of
malloc(3) plus free(3).  In certain cases, it can also simplify memory
deallocation in applications that use longjmp(3) or siglongjmp(3).
Otherwise, its use is discouraged.

Signed-off-by: chao an <anchao@lixiang.com>
2024-02-19 03:49:22 -08:00
Ville Juven
0f31a8d98e nsh_fscmds.c: Fix CONFIG_FS_SHM -> CONFIG_FS_SHMFS
The define macro was wrong
2024-01-31 08:52:05 -08:00
chao an
0968264ac0 nshlib: fix build break if CONFIG_CPP_HAVE_VARARGS if undefined
ctc E272: ["nsh_ddcmd.c" 197/7] undeclared identifier "vtbl"

Signed-off-by: chao an <anchao@lixiang.com>
2024-01-30 20:44:05 -08:00
wangyongrong
32f269a079 nsh_syscmds: update rptun_ping to rpmsg_ping, add cmd_rpmsg.
To support rpmsg ioctl, add cmd_rpmsg function, and update rptun ping to rpmsg ping.
depends on apache/nuttx#11618

Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
2024-01-30 20:42:49 -08:00
yangjian11
09122debe9 nsh_timcmds: display date using set format
Reference: https://www.geeksforgeeks.org/date-command-linux-examples/?ref=gcse#9-list-of-format-specifiers-used-with-date-command

Signed-off-by: yangjian11 <yangjian11@xiaomi.com>
2024-01-26 19:13:25 -08:00
Michal Lenc
61d1f37f5f nsh_timcmds: show RTC time in timedatectl command only if CONFIG_RTC_DRIVER is set
NuttX build fails otherwise as required structures are not included.

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
2024-01-26 09:45:03 -08:00
Junbo Zheng
c699b05f74 nshlib: add expr command support
It is a mini version for the `expr` command, which implements the features of addition, subtraction, multiplication, division and mod.

Reference: https://www.geeksforgeeks.org/expr-command-in-linux-with-examples/

bl2>
bl2> expr 1 + 2
3
bl2> expr
Usage: expr <operand1> <operator> <operand2>
bl2> expr 5 - 2
3
bl2> set hello 10
bl2> expr $hello - 2
8
bl2> expr 8 a 9
Unknown operator
bl2> expr 20 / 5
4
bl2> expr 10 % 4
2
bl2> expr 10 / 0
operand2 invalid
bl2>
bl2> expr mi + 100
invalid parameter
bl2> expr 100 + mi
invalid parameter
bl2> expr 100 + 0
100

Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
2024-01-25 18:12:28 -08:00
Yanfeng Liu
596328ccca nshcmd/rptun: align help mesg with impl
the ping subcommand is guarded with RPTUN_PING in its handler.
its help mesg should have same guard to avoid confusing user.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2024-01-25 18:11:39 -08:00
wangyongrong
7047fa5bde nsh syscmds: add CONFIG_RPTUN_PING when use rptun_ping
Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
2024-01-13 02:15:55 -08:00
fangxinyong
385f707382 nshlib: move etc romfs mount from nsh to nuttx
This commit corresponds to apache/nuttx#11498 in nuttx.

Move etc romfs mount to sched/init for compatibility with kernel/protected mode.

changes:
- move etc romfs mount from nsh to Nuttx, but keep the script to parse and execute.
- move and rename the related CONFIG, move customized nsh_romfsimg.h to etc_romfs.c
  in boards, and no need declaration for romfs_img/romfs_img_len.

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2024-01-09 21:25:19 -08:00
Bowen Wang
2a08d17ed6 nsh_mmcmds: support "memdump -h/help" to show usage and sequence number
Compare with "cat /proc/memdump", use "memdump -h/help" is more
convenient.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-01-06 04:34:27 -08:00
Bowen Wang
3d4442207d nsh_ddcmd: print errno instead the return value when dd failed
Print the errno gives more information to debug the dd failed
problem.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-01-06 04:34:07 -08:00
wangyongrong
51762a8958 nsh cmd rptun: add rptun ping useage description
Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
2024-01-06 04:33:48 -08:00
Zhe Weng
4c0bd143eb nshlib/ifconfig: Let "dns" option depends on CONFIG_NETDB_DNSCLIENT
"dns" option of `ifconfig` can work just with `CONFIG_NETDB_DNSCLIENT`,
no need to depend on `CONFIG_NETINIT_DNS` or `CONFIG_NETINIT_DHCPC`.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-12-30 01:40:05 -08:00
yuanyongjian
dcfb4d0662 nshlib:dmesg add '-c|-C' opt
Signed-off-by: yuanyongjian <yuanyongjian@xiaomi.com>
2023-12-14 20:14:25 -08:00
Zhe Weng
b7c5bdbdc9 nshlib/ifconfig: Add error print for inet_pton fail
> ifconfig wlan0 inet6 add fb
nsh: ifconfig: argument invalid

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-12-12 22:17:05 -08:00
Zhe Weng
9abc82c792 nshlib/ifconfig: Generate default IPv4 gateway with netmask
Generate default gateway using configured netmask instead of fixed
255.255.255.0, which may be more flexible under certain situations.
e.g. A subnet like 10.0.23.16/28 may not contain the .1 address.

Before:

ifconfig eth0 10.0.23.22 netmask 255.255.255.252 => DRaddr:10.0.23.1
ifconfig eth0 10.0.23.22 netmask 255.255.255.240 => DRaddr:10.0.23.1
ifconfig eth0 10.0.23.22 netmask 255.255.255.0   => DRaddr:10.0.23.1
ifconfig eth0 10.0.23.22 netmask 255.255.0.0     => DRaddr:10.0.23.1

ifconfig eth0 10.0.23.22 => Mask:255.255.255.0      DRaddr:10.0.23.1

After:

ifconfig eth0 10.0.23.22 netmask 255.255.255.252 => DRaddr:10.0.23.21
ifconfig eth0 10.0.23.22 netmask 255.255.255.240 => DRaddr:10.0.23.17
ifconfig eth0 10.0.23.22 netmask 255.255.255.0   => DRaddr:10.0.23.1
ifconfig eth0 10.0.23.22 netmask 255.255.0.0     => DRaddr:10.0.0.1

ifconfig eth0 10.0.23.22 => Mask:255.255.255.0      DRaddr:10.0.23.1

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-12-07 07:16:43 -08:00
Zhe Weng
fb72849089 nshlib/ifconfig: Set network mask before setting gateway
Switch the order of setting network mask and gateway, re-order only, no
logic change.

In IPv6 cases, we may set `addr6` and prefix length together to an
interface, but the gateway logic may change the value in `addr6`, and
result in wrong address set to the interface.

The order doesn't change behavior in network stack, so we just need to
make sure the value is correct.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-12-07 07:16:43 -08:00
Zhe Weng
56ef320d6f nshlib/ifconfig: Add support for add/del a single IPv6 address
Note: We're using similar error codes as Linux:
```
linux> sudo ifconfig eth0 inet6 add fc00::2/64
linux> sudo ifconfig eth0 inet6 del fc00::2/112
SIOCDIFADDR: Cannot assign requested address
linux> sudo ifconfig eth0 inet6 del fc00::3/64
SIOCDIFADDR: Cannot assign requested address
linux> sudo ifconfig eth0 inet6 add fc00::2/64
SIOCSIFADDR: File exists

nuttx> ifconfig eth0 inet6 add fc00::2/64
nuttx> ifconfig eth0 inet6 del fc00::2/112
Failed to manage IPv6 address: Cannot assign requested address
nuttx> ifconfig eth0 inet6 del fc00::3/112
Failed to manage IPv6 address: Cannot assign requested address
nuttx> ifconfig eth0 inet6 add fc00::2/64
Failed to manage IPv6 address: File exists
```

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-11-08 00:20:19 +08:00
yinshengkai
647db6393d nsh: rename CONFIG_SCHED_CPULOAD to CONFIG_SCHED_CPULOAD_NONE
Explicitly select dependencies to avoid automatically selecting inappropriate configurations.

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-11-01 09:23:07 +08:00
raiden00pl
b8c35f667e remove nshlib/README.md which is already in Documentation/applications/nsh 2023-10-30 20:33:41 +08:00
Ville Juven
3ff49e86f5 nshlib/nsh_fileapps.c: Remove sched_lock() from nsh_fileapp()
Locking the scheduler prior to calling posix_spawn() might lock the
scheduler for a relatively long time, if the file to be loaded is large.

posix_spawn() loads the process into memory, possibly linking it as well
if the binary format is linkable (elf). This can take tens / hundreds of
milliseconds, which basically destroys the OS's real time performance.

Missing the death-of-child signal is a very trivial penalty considering
the alternative.
2023-10-26 00:24:58 +08:00
Junbo Zheng
c0da2b2a0e nshlib: correct ls -l command output format
Since the output format will be messed up with a size of GB.

before
```
ap> ls -l
/dev:
 brw-rw-rw-       0       0314572800 app
 dr--r--r--       0       0       0 audio/
 crw-rw-rw-       0       0       0 buttons
 crw-rw-rw-       0       0       0 console
 brw-rw-rw-       0       0104857600 coredump
 crw-rw-rw-       0       0       0 crypto
 brw-rw-rw-       0       02214592512 data
```

after
```
ap> ls -l
/dev:
 brw-rw-rw-       0       0   314572800 app
 dr--r--r--       0       0           0 audio/
 crw-rw-rw-       0       0           0 buttons
 crw-rw-rw-       0       0           0 console
 brw-rw-rw-       0       0   104857600 coredump
 crw-rw-rw-       0       0           0 crypto
 brw-rw-rw-       0       0  2214592512 data
```

Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
2023-10-26 00:24:40 +08:00
Xiang Xiao
fe7f217497 nshlib: losetup/lomtd change "-s <sectsize>" to "-b <sectsize>"
to follow host tool usage:
https://github.com/util-linux/util-linux/blob/master/sys-utils/losetup.c#L473

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-10-16 13:14:48 -04:00
Xiang Xiao
9e31a26edc Fix nsh_altconsole.c:152:41: error: implicit declaration of function 'strlen'
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-09-26 00:31:09 +08:00
Ville Juven
e9f4e87786 nsh_alias.c: unalias -a command does not work correctly
getopt returns the argument if it is found, so testing against != ERROR is
wrong.
2023-09-25 21:05:37 +08:00
dulibo1
049aaa4c96 pmconfig: check domain if invaild return error avoid to crash
Signed-off-by: dulibo1 <dulibo1@xiaomi.com>
2023-09-22 09:16:54 +08:00
0528Mike
a46a661b34 Update nshlib/nsh_codeccmd.c
Co-authored-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-09-21 10:48:29 +08:00
wangmingrong
2459476b65 nshlib: Implementation of modifying command md5
Simplify the "cmd_codecs_proc" md5 related framework and modify the implementation of the command md5:

Signed-off-by: wangmingrong <wangmingrong@xiaomi.com>
2023-09-21 10:48:29 +08:00
Daniel Appiagyei
b37e84b05f c++ compatibility: rename usages of reserved c++ keywords 'this' and 'public' 2023-09-16 19:45:52 +08:00
wangmingrong
5e59b0b384 nshlib: Fix static scanning errors
Signed-off-by: wangmingrong <wangmingrong@xiaomi.com>
2023-09-08 18:49:31 +08:00
Xiang Xiao
6aa05b5855 Replace strlen with sizeof for kconfig string
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-09-02 16:26:51 +03:00
anjiahao
8d7497f7fb memdump:fix bug with space does not parse correctly
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-08-29 23:14:06 +08:00
Niklas Hauser
78a6d07a90 nshlib/nsh_consolemain: detect null pointer
Returning with an error from nsh_consolemain prevents dereferencing a
NULL pointer later in the code.
2023-08-29 03:11:28 +08:00
wangmingrong
7981278021 apps/nshlib: Add the pidof command and API nsh_getpid
Add the API "nsh_getpid" in "nsh_fsutils. c" and the nsh command pidof. Temporarily support two parameters, - s, and process name

Signed-off-by: wangmingrong <wangmingrong@xiaomi.com>
2023-08-29 02:58:45 +08:00
wanggang26
75c8580238 nshlib: fix a typo
painc to panic

Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2023-08-28 17:33:15 +03:00
Ville Juven
94d477b3df nshlib/nsh_console.h: Add nsh_none, where any empty output can be forwarded
Add nsh_none to consume all empty traces from nsh.

For the variadic argument case need to add a (inline) function to eat
away the __VA_ARGS__ list, there is no good / portable way to do this by
pre-processor macros, but a function will eat the variadic list whatever
its size is.
2023-08-25 17:18:35 +08:00
Ville Juven
1668c3e97d Revert "nshlib/nsh_timcmds.c: Suppress warning about unused variable (errfmt)"
This reverts commit 4ca9b518fa9923c1af9c120eafbac59359874e13.
2023-08-25 17:18:35 +08:00
Ville Juven
b65b577ad3 nshlib/nsh_timcmds.c: Suppress warning about unused variable (errfmt)
Fixes following warning:

CC:  grp/lib_getgrbufr.c nsh_timcmds.c: In function 'cmd_date':
nsh_timcmds.c:370:19: warning: variable 'errfmt' set but not used [-Wunused-but-set-variable]
  370 |   FAR const char *errfmt;
      |
2023-08-23 00:17:25 +08:00
raiden00pl
2b58cc6578 rptun/ping: fix invalid use of nsh_error after 31421db6f 2023-08-21 18:47:01 +03:00
raiden00pl
31421db6fa rptun/ping: print invalid arguments error 2023-08-20 22:58:07 +08:00
Xiang Xiao
b586ab839d nshlib: Don't select LIBC_NETDB automatically
since nshlib always call netdb API inside #ifdef CONFIG_LIBC_NETDB

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-08-12 15:58:11 +03:00
anjiahao
79e481d093 resetcause:show reset string not number
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-08-10 13:51:43 +08:00
yinshengkai
105fd2aac5 nsh: fix a buffer overflow in help
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-08-09 18:22:09 +08:00
fangxinyong
2234c3a2e6 nshlib: support list numeric user and group IDs
Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2023-08-09 15:06:09 +08:00
Zhe Weng
396ab2e931 nsh/alias: Fix compiler warning
Got use-after-free warning under GCC 12 with `-O3` option, and I found
that `nsh_strcat` may realloc `ptr`, then `cmdline` may point to invalid
memory.

Let `cmdline` point to the reallocated `ptr` may solve the problem.
Tested by `alias ll='ls -l'` and `ll /` on sim.

GCC output:

CC:  binfmt_unloadmodule.c In function 'nsh_aliasexpand',
    inlined from 'nsh_argument' at nsh_parse.c:1879:20:
nsh_parse.c:1196:23: error: pointer 'ptr' used after 'realloc' [-Werror=use-after-free]
 1196 |               ptr     = cmdline + len;
      |               ~~~~~~~~^~~~~~~~~~~~~~~
In function 'nsh_strcat',
    inlined from 'nsh_aliasexpand' at nsh_parse.c:1190:21,
    inlined from 'nsh_argument' at nsh_parse.c:1879:20:
nsh_parse.c:1100:27: note: call to 'realloc' here
 1100 |   argument  = (FAR char *)realloc(s1, allocsize);
      |                           ^~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-08-01 08:13:23 -07:00
wanggang26
cb684097b8 nshlib: add print negative number support for echo command
Fix issue that "echo -1" will give "argument invalid" error

Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2023-07-31 07:58:41 -07:00
wanggang26
f585d74b8c nshlib: refine dd verify printing format
before:
infile sector 0
7f454c46010101000000000000000000
02002800010000007d13001834000000
8cbd2a00000400053400200004002800

now:
infile sector 0:
0000: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 .ELF............
0010: 02 00 28 00 01 00 00 00 7d 13 00 18 34 00 00 00 ..(.....}...4...
0020: 8c bd 2a 00 00 04 00 05 34 00 20 00 04 00 28 00 ..*.....4. ...(.

Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2023-07-30 22:21:34 -07:00
wanggang26
9621aca73c nshlib: add negative number logical judgement support for test and [ command
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2023-07-30 22:20:02 -07:00
wangjianyu3
fc8c425cc0 Fix dependents of nsh_foreach_direntry
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2023-07-28 21:51:50 -07:00