Commit Graph

155 Commits

Author SHA1 Message Date
Michal Lenc
f81a094283 nshlib: add support for pkill command
This command looks through the currently running processes and kills
the those that match the selection criteria. This way system can send
signal to processes by name and without knowing the IDs.

Example (kill application hello):
	pkill -15 hello

The command can be turned off by NSH_DISABLE_PKILL option and depends
on FS_PROCFS.

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
2024-09-23 08:40:54 +08:00
wangjianyu3
aaf4e9d480 nshlib: Support "-f" option for command "rm"
In below two cases "rm" command with "-f" option will return 0:
  a. Bad arguments
  b. File not exists

Following "rm" of GNU coreutils 8.32

GNU coreutils
  $ rm --version
  rm (GNU coreutils) 8.32
  Copyright (C) 2020 Free Software Foundation, Inc.
  License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
  This is free software: you are free to change and redistribute it.
  There is NO WARRANTY, to the extent permitted by law.

  Written by Paul Rubin, David MacKenzie, Richard M. Stallman,
  and Jim Meyering.

  $ rm /FILE_NOT_EXISTS
  rm: cannot remove '/FILE_NOT_EXISTS': No such file or directory
  $ echo $?
  1

  $ rm -f
  $ echo $?
  0

  $ rm -f /FILE_NOT_EXISTS
  $ echo $?
  0

Without this patch
  nsh> rm
  nsh: rm: missing required argument(s)

  nsh> rm /FILE_NOT_EXISTS
  nsh: rm: unlink failed: 2
  nsh> echo $?
  1

With this patch
  nsh> rm -f
  nsh> echo $?
  0

  nsh> rm -f /FILE_NOT_EXISTS
  nsh> echo $?
  0

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2024-09-19 03:45:37 +08:00
chao an
8ad39537dd nshlib: move g_builtin_prompt from data to rodata
1. move g_builtin_prompt from data to rodata
2. add g_ prefix to some global variables

Signed-off-by: chao an <anchao@lixiang.com>
2024-09-05 09:49:44 +08: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
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
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
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
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
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
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
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
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
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
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
yinshengkai
105fd2aac5 nsh: fix a buffer overflow in help
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-08-09 18:22:09 +08:00
chenrun1
415168dde6 nshlib: Add fdinfo to get information about the process associated fd
Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2023-07-16 16:39:11 +08:00
Junbo Zheng
9de5a2550e nshlib: add -h option for ls command
config: ./tools/configure.sh sim:nsh
CONFIG_LIBC_FLOATINGPOINT=y
```
nsh> ls -l /dev
/dev:
 crw-rw-rw-       0 console
 crw-rw-rw-       0 gpio0
 crw-rw-rw-       0 gpio1
 crw-rw-rw-       0 gpio2
 crw-rw-rw-       0 gpio3
 crw-rw-rw-       0 loop
 crw-rw-rw-       0 null
 crw-rw-rw-       0 oneshot
 brw-rw-rw- 1048576 ram0
 brw-rw-rw-    1024 ram1
 brw-rw-rw-  524288 ram2
 crw-rw-rw-       0 zero
nsh> ls /lh /dev
nsh: ls: too many arguments
nsh> ls -lh /dev
/dev:
 crw-rw-rw-       0 console
 crw-rw-rw-       0 gpio0
 crw-rw-rw-       0 gpio1
 crw-rw-rw-       0 gpio2
 crw-rw-rw-       0 gpio3
 crw-rw-rw-       0 loop
 crw-rw-rw-       0 null
 crw-rw-rw-       0 oneshot
 brw-rw-rw-    1.0M ram0
 brw-rw-rw-    1.0K ram1
 brw-rw-rw-  512.0K ram2
 crw-rw-rw-       0 zero
```

config: ./tools/configure.sh ../vendor/sim/boards/miwear/configs/miwear -j16
```
nsh> ls -l /resource/misc/media
/resource/misc/media:
 -rwxrwxr-x  384044 AlexaTimer.wav
 -rwxrwxr-x   57001 AlexaReminder.mp3
 -rwxrwxr-x  384132 AlexaAlarm.wav
 -rw-rw-r--   20733 Clank.mp3
 -rw-rw-r--   45183 NotificationXylophone.mp3
 -rw-rw-r--   27420 Robot.mp3
 -rw-rw-r--   21986 FadeIn.mp3
 -rw-rw-r--   42049 Flute.mp3
 -rw-rw-r--  362748 Latona-15s.mp3
 drwxrwxr-x    4096 .
 -rw-rw-r--   47198 alarm_volume_adjust.mp3
 -rw-rw-r--   95338 Expect.mp3
 drwxrwxr-x    4096 ..
 -rw-rw-r--  409435 Sunrise.mp3
 -rw-rw-r--   55841 Fresh.mp3
 -rw-rw-r--   36685 Bells-1s.mp3
 -rw-rw-r--    4432 camera_click.mp3
 -rw-rw-r--  469621 MiRemix.mp3
nsh>
nsh> ls -lh /resource/misc/media
/resource/misc/media:
 -rwxrwxr-x  375.0K AlexaTimer.wav
 -rwxrwxr-x   55.7K AlexaReminder.mp3
 -rwxrwxr-x  375.1K AlexaAlarm.wav
 -rw-rw-r--   20.2K Clank.mp3
 -rw-rw-r--   44.1K NotificationXylophone.mp3
 -rw-rw-r--   26.8K Robot.mp3
 -rw-rw-r--   21.5K FadeIn.mp3
 -rw-rw-r--   41.1K Flute.mp3
 -rw-rw-r--  354.2K Latona-15s.mp3
 drwxrwxr-x    4.0K .
 -rw-rw-r--   46.1K alarm_volume_adjust.mp3
 -rw-rw-r--   93.1K Expect.mp3
 drwxrwxr-x    4.0K ..
 -rw-rw-r--  399.8K Sunrise.mp3
 -rw-rw-r--   54.5K Fresh.mp3
 -rw-rw-r--   35.8K Bells-1s.mp3
 -rw-rw-r--    4.3K camera_click.mp3
 -rw-rw-r--  458.6K MiRemix.mp3
```

Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
2023-07-05 16:25:27 +08:00
chao an
e4cf94b509 nshlib/command: exclude usage to reduce data size
Test on sim/nsh (CONFIG_NSH_DISABLE_HELP=y):

   text	   data	    bss	    dec	    hex	filename
 393746	  26824	   4000	 424570	  67a7a	nuttx     /* before */
 391858	  26440	   4000	 422298	  6719a	nuttx     /* after */
  -1888    -384

Signed-off-by: chao an <anchao@xiaomi.com>
2023-06-10 02:20:49 +08:00
Xiang Xiao
e81227f99d Indent the define statement by two spaces
follow the code style convention

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-05-22 11:57:40 +02:00
anjiahao
e68d5ffb98 support memdump can dump by seq number
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-05-21 00:08:48 +08:00
wangchen
cb292d0608 nshlib/netcmds:modify the description of setting MTU
modify the description of setting MTU

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2023-05-10 19:56:04 +08:00
Xiang Xiao
bebae28bdd nsh: Fix the typo error cmd_swtichboot -> cmd_switchboot
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-05-03 17:40:49 +03:00
wangchen
c2f75330f7 nshlib/netcmds:support to set MTU
Usage:ifconfig interfacename mtu ***

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2023-04-27 18:02:23 +08:00
Xiang Xiao
1d3e6510e6 nshlib: Add switchboot command
switchboot <image path>

Switch to the updated or specified boot system. This command depends on
hardware support CONFIG_BOARDCTL_SWITCH_BOOT. `<image path>` point to a
partion or file which contain the firmware to boot.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-04-07 13:44:49 +03:00
Xiang Xiao
49418d6de5 nshlib: Align the command table
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-04-04 13:53:28 +03:00
Xiang Xiao
4f7dd7be7c nshlib: Add boot command
boot [<image path> [<header size>]]

Boot a new firmware image. This command depends on hardware support
CONFIG_BOARDCTL_BOOT_IMAGE. <image path> may point to a partion or file
which contain the firmware to boot. The optional, numeric argument
<header size> may be useful for skipping metadata information preprended
to the firmware image.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-04-04 13:53:28 +03:00
Ville Juven
f9dfb51001 nsh/nshlib: Add alias support for nsh
This adds support for string aliases into nsh. There are some nuances that
are not handled correctly yet:

- Reserved words can be overloaded, which is a clear POSIX violation
2023-03-23 22:10:19 +02:00
Huang Qi
dbf7d34a2a nsh: Fix a potential buffer overflow in cmd help
Follow https://github.com/apache/nuttx-apps/pull/1621, fix issue of builtin command list.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2023-03-09 01:42:38 +08:00
Huang Qi
12d31075eb nsh: Fix a buffer overflow in help
Introduced by https://github.com/apache/nuttx-apps/pull/1610,
internal line buffer should have more bytes for tab before newline and '\0'.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2023-03-05 11:18:59 +02:00
Huang Qi
e957e1633c nsh: Improve performance of help by line buffer
This change reduce the usage of `printf`,
which will improve both CPU usage and IO performance.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2023-03-03 17:41:39 +09:00
Xiang Xiao
359f66ad37 nshlib: Remove the remaining CONFIG_FILE_STREAM dependence
continue the change from https://github.com/apache/nuttx-apps/pull/1559

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-02-24 17:38:19 +08:00
Oreh
f63a3cac0e Add NSH lomtd command (creates MTD loop device) 2023-02-19 19:55:52 +08:00
Zhe Weng
93b4dc2692 ifconfig: Support ifconfig interface and update arg limit
From comment in cmd_ifconfig, it seems that we support `ifconfig [interface]`, but actually not considering the interface param now. After this commit, we only print the information of interface specified in param, just like linux.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-02-01 11:12:24 +08:00
zhanghongyu
df3121213e cmd_arp: add device input for arp interface
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2022-12-14 21:19:37 +08:00
anjiahao
14465b85c4 cmd_dd:support dd can do verify
After writing the file, compare the contents of the two files again

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2022-11-14 20:40:43 +08:00
Xiang Xiao
36a0c924f7 netutils: Support telnetd in the kernel mode
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Signed-off-by: chao an <anchao@xiaomi.com>
2022-11-07 15:24:08 +09:00
Junbo Zheng
79e770b0c6 apps/nshlib: add the missing FAR macro for all source files
Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
2022-09-22 14:22:13 +08:00
Junbo Zheng
06f39d10f1 apps/nshlib: add uptime command support
run uptime command on sim:
nsh>
nsh>
nsh> uptime
19:35:01 up  1:40, load average: 0.00, 0.00, 0.00
nsh>
nsh>
nsh> uptime -s
2022-09-16 17:54:26
nsh>
nsh>
nsh> uptime -p
up 1 hour, 40 minutes
nsh>
nsh>
nsh> uptime -h
Usage:
uptime [options]
Options:
-p, show uptime in pretty format
-h, display this help and exit
-s, system up since
nsh>
nsh>
nsh> uptime -abc
uptime: invalid option -- -abc
Usage:
uptime [options]
Options:
-p, show uptime in pretty format
-h, display this help and exit
-s, system up since
nsh>
nsh>
nsh> date
Fri, Sep 16 19:35:18 2022
nsh>
nsh>

Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
2022-09-21 16:37:34 +02:00
Junbo Zheng
732450d42a apps/nshlib: correct commands with alphabet order in kconfig
Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
2022-09-16 15:59:30 +08:00
Fotis Panagiotopoulos
1c7839c28c Fixed compiler warnings. 2022-08-30 12:10:49 +08:00
Fotis Panagiotopoulos
0cdb2cfa48 Fixed compiler warnings. 2022-08-23 01:39:59 +08:00
ligd
a109a6e58b rptun_ping: add sleep param to rptun_ping
Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-07-30 03:15:01 +08:00
Jiuzhu Dong
45615a8d9d nshlib/dmesg: update config about enable dmesg
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-07-25 08:27:48 +02:00
zhuyanlin
a5a4c561fb pmconfig: add mulit domain support
pmconfig [domain]
pmconfig relax/stay state [domain]

Signed-off-by: zhuyanlin <zhuyanlin1@xiaomi.com>
2022-04-28 00:36:36 +08:00
YAMAMOTO Takashi
c7fcffd09a nshlib/nsh_fscmds.c: Make losetup command take optional sector size 2022-04-11 22:19:19 +08:00
Jiuzhu Dong
63f28099e3 nsh/timedatectl: add timedatectl to get/set TZ
follow https://man7.org/linux/man-pages/man1/timedatectl.1.html

nsh> timedatectl
      TimeZone: CST, 28800
    Local time: Sat, Apr 02 05:59:43 2022 CST
Universal time: Fri, Apr 01 21:59:43 2022 GMT
      RTC time: Sun, Apr 01 21:59:42 2022

Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-04-07 02:52:11 +08:00
ligd
470174260c rptun: update rptun cmd usage
Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-04-01 17:36:51 +08:00
ligd
f5d2c64556 rptun: add rptun ping support
Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-04-01 17:36:51 +08:00