Commit Graph

1077 Commits

Author SHA1 Message Date
Marco Casaroli
0797ee2312 fix(nsh_parse): handle env variables correctly
The PR #2469 broke handling of environment variables because an
error in the if/else if control flow.

This fixes it.
2024-08-10 11:08:18 -03:00
Marco Casaroli
e46347ec1b nsh_fileapp: handle input redirection 2024-08-08 19:19:18 -03:00
Marco Casaroli
8fba726a7d feat(nsh_cat): allow cat to read from stdin
Now, if we run cat without arguments, it will just read from stdin.

It can be used with redirect like `cat < infile > outfile`.
2024-08-08 19:19:18 -03:00
Marco Casaroli
4104019e1c feat(nsh): add console read
This allows programs such as `cat` to read from the console (that could be redirected).
2024-08-08 19:19:18 -03:00
Marco Casaroli
96100b30f2 feat(nsh): input (stdin) redirection
This adds support for `<` to redirect input on nsh commands.
2024-08-08 19:19:18 -03:00
chenrun1
ffcee721ce nshlib/ddcmd:Fixed NSH_CMDOPT_DD_STATS output format warning in 64-bit environment
In file included from nsh_ddcmd.c:44:
nsh_ddcmd.c: In function 'cmd_dd':
nsh_ddcmd.c:456:20: error: format '%llu' expects argument of type 'long long unsigned int', but argument 3 has type 'uint64_t' {aka 'long unsigned int'} [-Werror=format=]
  456 |   nsh_output(vtbl, "%llu bytes copied, %u usec, ",
      |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  457 |              total, (unsigned int)elapsed);
      |              ~~~~~
      |              |
      |              uint64_t {aka long unsigned int}
nsh_console.h:55:49: note: in definition of macro 'nsh_output'
   55 | #  define nsh_output(v, ...)   (v)->output(v, ##__VA_ARGS__)
      |                                                 ^~~~~~~~~~~
nsh_ddcmd.c:456:24: note: format string is defined here
  456 |   nsh_output(vtbl, "%llu bytes copied, %u usec, ",
      |                     ~~~^
      |                        |
      |                        long long unsigned int
      |                     %lu
cc1: all warnings being treated as errors

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-08-07 15:04:39 +08:00
chenrun1
f126adb5fc nshlib/fscmds:Fix write overflow during cp -r process
Summary:
      do
        {
          nbyteswritten = write(wrfd, iobuffer, nbytesread);
          if (nbyteswritten >= 0)

The write return type is ssize_t, which is different in size from the originally declared type, so the unified type is ssize_t

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-08-06 19:30:12 -03:00
Denis Ryndine
a15403958d nsh_dd: fix lseek return check.
- As was merged in commit 1852731df8 on
   dd_main.c: lseek returns -1 on error.

   Should be consistent in nsh_ddcmd.c and nsh_main.c.
2024-08-01 09:52:03 +08:00
buxiasen
b9a7353a43 add include to handle when PM_NDOMAINS from pm.h
Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-05-18 22:08:14 +08:00
Alan Carvalho de Assis
b4ec000dec apps/nsh_commands: Use quit to poweroff
Currently new users when try to run NuttX using the SIM
get stuck into simulator, because they have no idea that
poweroff command is used to leave it. Let use KISS approach
and use quit as an alias to poweroff command.

Signed-off-by: Alan C. Assis <acassis@gmail.com>
2024-04-13 15:17:50 +08:00
Alan Carvalho de Assis
8d14f4eaac apps/nshlib: Never disable HELP and ? 2024-04-06 13:34:56 +08:00
chao an
20c90d5b43 nshlib/irqaff: add irq affinity command
add support for set an IRQ affinity to CPUs by software

qemu-armv7a/bmp: switch uart irq to different CPUs

nsh> ps
  PID GROUP PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK           STACK   USED  FILLED COMMAND
    0     0   0 FIFO     Kthread   - Ready              0000000000000000 004080 000536  13.1%  CPU0 IDLE
    1     1 192 RR       Kthread   - Waiting  Semaphore 0000000000000000 004032 000296   7.3%  hpwork 0x4013f51c 0x4013f530
    2     2 100 RR       Task      - Running            0000000000000000 004056 001168  28.7%  nsh_main
nsh> irqaff 33 0x2
nsh> ps
  PID GROUP PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK           STACK   USED  FILLED COMMAND
    0     0   0 FIFO     Kthread   - Ready              0000000000000000 004080 000736  18.0%  CPU1 IDLE
    1     1 192 RR       Kthread   - Waiting  Semaphore 0000000000000000 004032 000296   7.3%  hpwork 0x4013f544 0x4013f558
    2     2 100 RR       Task      - Running            0000000000000000 004056 001288  31.7%  nsh_main
nsh> irqaff 33 0x4
nsh> ps
  PID GROUP PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK           STACK   USED  FILLED COMMAND
    0     0   0 FIFO     Kthread   - Ready              0000000000000000 004080 000736  18.0%  CPU2 IDLE
    1     1 192 RR       Kthread   - Waiting  Semaphore 0000000000000000 004032 000296   7.3%  hpwork 0x4013f56c 0x4013f580
    2     2 100 RR       Task      - Running            0000000000000000 004056 001168  28.7%  nsh_main
nsh> irqaff 33 0x8
nsh> ps
  PID GROUP PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK           STACK   USED  FILLED COMMAND
    0     0   0 FIFO     Kthread   - Ready              0000000000000000 004080 000736  18.0%  CPU3 IDLE
    1     1 192 RR       Kthread   - Waiting  Semaphore 0000000000000000 004032 000296   7.3%  hpwork 0x4013f594 0x4013f5a8
    2     2 100 RR       Task      - Running            0000000000000000 004056 001168  28.7%  nsh_main

Signed-off-by: chao an <anchao@lixiang.com>
2024-03-29 16:16:07 +08:00
chenrun1
bac8aab243 cmd_cp:Skip mkdir when mkdir is not available
The behavior of mkdir is used during the cp -r process, and the mkdir behavior is skipped when mkdir is unavailable (this may cause unpredictable behavior of cp -r)

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-02-25 21:59:57 -08:00
chenrun1
e8470f7d0e cp:support -r recursive copies
The cp command supports recursive copying. Use "cp -r" to copy a folder.

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-02-25 21:59:57 -08:00
chenrun1
bd1cc85ad4 dd:support "seek"
Now the dd command can use the "seek" parameter to adjust how many bytes need to be skipped before being written to the target.

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-02-25 06:36:43 -08:00
Yanfeng Liu
31908b3128 nshlib/prompt: extend NSH prompt string management
Currently NSH prompt is defined at build time, thus improper for AMP cases
where the same NSH binary is used on different nodes as the same NSH prompt
shows on all nodes.

This patch attempts to support runtime prompt string population from ordered
sources:
  - the environment variable defined by NSH_PROMPT_ENV plus suffix
  - the NSH_PROMPT_STRING
  - the HOSTNAME plus suffix
The suffix is defined by NSH_PROMPT_SUFFIX so that to clearly separate the
command inputs.

Changes in `nshlib/`

- Kconfig:       add configs NSH_PROMPT_MAX/ENV/SUFFIX etc
- nsh.h:         adjust g_nshprompt defs, add nsh_update_prompt
- nsh_parse.c    relocate g_nshpromt to nsh_prompt.c
- nsh_init.c     revise to use nsh_update_prompt once
- nsh_session.c  revise to use methods in nsh_prompt.c
- Makefile       add nsh_prompt.c
- CMakeLists.txt add nsh_prompt.c

New additions in `nshlib/`

- nsh_prompt.c   prompt related data structures and methods.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2024-02-25 00:55:47 -08:00
Yanfeng Liu
3dd35cb549 nshlib/syscmds: guard help mesg for rpmsg ping
This patch guards help message for ping sub-command so that it only
shows when the sub-command is enabled.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2024-02-21 05:31:45 -08:00
wangyongrong
25e8c1c9c4 cmd rptun: Strip rpmsg ioctl and rptun ioctl.
cmd_rptun handles RPTUNIOC_START, RPTUNIOC_STOP, RPTUNIOC_RESET,
cmd_rpmsg handles the public ioctl commands part.

Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
2024-02-19 05:59:34 -08:00
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