Skip to content

Commit ea9866d

Browse files
jackrosenthalcarlescufi
authored andcommitted
shell: add an option for minimal default configuration
The default shell configuration has heavy flash and memory requirements, requiring project maintainers to set many configuration options to "n" to keep flash and memory requirements within reason. This adds a new configuration option, CONFIG_SHELL_MINIMAL, which will disable flash and memory heavy options by default, and allow project maintainers to select/imply only the options they want. On a quick test from an ARM board I'm working on, enabling this option cut flash space requirements by ~8 KB, and memory requirements by ~1 KB. Signed-off-by: Jack Rosenthal <[email protected]>
1 parent c2a777c commit ea9866d

20 files changed

+49
-303
lines changed

doc/reference/shell/index.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ interaction is required. This module is a Unix-like shell with these features:
3232
* Support for meta keys.
3333
* Kconfig configuration to optimize memory usage.
3434

35-
Some of these features have a significant impact on RAM and flash usage,
36-
but many can be disabled when not needed. A configuration that should
37-
produce the minimum useful feature set is in
38-
:zephyr_file:`samples/subsys/shell/shell_module/prj_minimal.conf`.
35+
.. note::
36+
Some of these features have a significant impact on RAM and flash usage,
37+
but many can be disabled when not needed. To default to options which
38+
favor reduced RAM and flash requirements instead of features, you should
39+
enable :option:`CONFIG_SHELL_MINIMAL` and selectively enable just the
40+
features you want.
3941

4042
The module can be connected to any transport for command input and output.
4143
At this point, the following transport layers are implemented:

drivers/sensor/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ config SENSOR_SHELL
2424
bool "Enable sensor shell"
2525
depends on SHELL
2626
select CBPRINTF_FP_SUPPORT
27-
default y
27+
default y if !SHELL_MINIMAL
2828
help
2929
This shell provides access to basic sensor data.
3030

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,12 @@
11
CONFIG_PRINTK=y
22
CONFIG_SHELL=y
3-
CONFIG_KERNEL_SHELL=n
3+
CONFIG_SHELL_MINIMAL=y
4+
CONFIG_SHELL_STACK_SIZE=1024
45
CONFIG_SHELL_BACKEND_SERIAL=y
56
CONFIG_OBJECT_TRACING=y
67
CONFIG_THREAD_MONITOR=y
78
CONFIG_INIT_STACKS=y
89
CONFIG_BOOT_BANNER=n
910
CONFIG_THREAD_NAME=y
1011
CONFIG_LOG=n
11-
CONFIG_SHELL_HISTORY=n
12-
CONFIG_SHELL_STACK_SIZE=1024
13-
CONFIG_SHELL_CMD_BUFF_SIZE=128
14-
CONFIG_SHELL_WILDCARD=n
15-
CONFIG_SHELL_DYNAMIC_CMDS=n
16-
CONFIG_SHELL_VT100_COLORS=n
17-
CONFIG_SHELL_HELP_ON_WRONG_ARGUMENT_COUNT=n
18-
CONFIG_SHELL_STATS=n
19-
CONFIG_SHELL_CMDS=n
20-
CONFIG_SHELL_HELP=n
21-
CONFIG_SHELL_TAB=n
22-
CONFIG_SHELL_METAKEYS=n
23-
CONFIG_SHELL_LOG_BACKEND=n
24-
CONFIG_KERNEL_SHELL=n
25-
CONFIG_DEVICE_SHELL=n
26-
CONFIG_DATE_SHELL=n
2712
CONFIG_CBPRINTF_NANO=y
28-
CONFIG_SENSOR_SHELL=n

samples/subsys/shell/shell_module/prj_minimal_rtt.conf

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,16 @@
11
CONFIG_PRINTK=y
22
CONFIG_SHELL=y
3-
CONFIG_KERNEL_SHELL=n
3+
CONFIG_SHELL_MINIMAL=y
4+
CONFIG_SHELL_STACK_SIZE=1024
45
CONFIG_SHELL_BACKEND_SERIAL=n
56
CONFIG_OBJECT_TRACING=y
67
CONFIG_THREAD_MONITOR=y
78
CONFIG_INIT_STACKS=y
89
CONFIG_BOOT_BANNER=n
910
CONFIG_THREAD_NAME=y
1011
CONFIG_LOG=n
11-
CONFIG_SHELL_HISTORY=n
12-
CONFIG_SHELL_STACK_SIZE=1024
13-
CONFIG_SHELL_CMD_BUFF_SIZE=128
14-
CONFIG_SHELL_WILDCARD=n
15-
CONFIG_SHELL_DYNAMIC_CMDS=n
16-
CONFIG_SHELL_VT100_COLORS=n
17-
CONFIG_SHELL_HELP_ON_WRONG_ARGUMENT_COUNT=n
18-
CONFIG_SHELL_STATS=n
19-
CONFIG_SHELL_CMDS=n
2012
CONFIG_CONSOLE=y
21-
22-
CONFIG_SHELL_HELP=n
23-
CONFIG_SHELL_TAB=n
24-
CONFIG_SHELL_METAKEYS=n
25-
CONFIG_SHELL_LOG_BACKEND=n
26-
CONFIG_KERNEL_SHELL=n
27-
CONFIG_DEVICE_SHELL=n
28-
CONFIG_DATE_SHELL=n
2913
CONFIG_CBPRINTF_NANO=y
30-
CONFIG_SENSOR_SHELL=n
3114

3215
#enable RTT shell
3316
CONFIG_USE_SEGGER_RTT=y

subsys/shell/Kconfig

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ module-str = Shell
1717
source "subsys/logging/Kconfig.template.log_config"
1818
source "subsys/shell/Kconfig.backends"
1919

20+
config SHELL_MINIMAL
21+
bool "Default config to reduce flash and memory requirements"
22+
help
23+
This is a meta-configuration option to significantly reduce the flash
24+
and memory requirements of the shell. Enabling it will choose Kconfig
25+
defaults which favor reduced flash or memory requirements over extra
26+
features.
27+
2028
config SHELL_STACK_SIZE
2129
int "Shell thread stack size"
2230
default 2520 if OPENTHREAD_SHELL
@@ -35,6 +43,7 @@ config SHELL_BACKSPACE_MODE_DELETE
3543

3644
config SHELL_CMD_BUFF_SIZE
3745
int "Shell command buffer size"
46+
default 128 if SHELL_MINIMAL
3847
default 256
3948
help
4049
Maximum command size in bytes. One byte is reserved for the string
@@ -67,7 +76,7 @@ config SHELL_ARGC_MAX
6776

6877
config SHELL_TAB
6978
bool "Enable the Tab button support in shell"
70-
default y
79+
default y if !SHELL_MINIMAL
7180
help
7281
Enable using the Tab button in the shell. The button
7382
can be used for prompting commands, or for autocompletion.
@@ -76,15 +85,15 @@ config SHELL_TAB
7685
config SHELL_TAB_AUTOCOMPLETION
7786
bool "Enable commands autocompletion with the Tab button"
7887
depends on SHELL_TAB
79-
default y
88+
default y if !SHELL_MINIMAL
8089
help
8190
Enable commands and subcommands autocompletion with the Tab
8291
key. This function can be deactivated to save some flash.
8392

8493
config SHELL_WILDCARD
8594
bool "Enable wildcard support in shell"
8695
select FNMATCH
87-
default y
96+
default y if !SHELL_MINIMAL
8897
help
8998
Enables using wildcards: * and ? in the shell.
9099

@@ -96,58 +105,59 @@ config SHELL_ECHO_STATUS
96105

97106
config SHELL_VT100_COLORS
98107
bool "Enable colors in shell"
99-
default y
108+
default y if !SHELL_MINIMAL
100109
help
101110
If enabled VT100 colors are used in shell (e.g. print errors in red).
102111

103112
config SHELL_METAKEYS
104113
bool "Enable metakeys"
105-
default y
114+
default y if !SHELL_MINIMAL
106115
help
107116
Enables shell meta keys: Ctrl+a, Ctrl+b, Ctrl+c, Ctrl+d, Ctrl+e,
108117
Ctrl+f, Ctrl+k, Ctrl+l, Ctrl+u, Ctrl+w, Alt+b, Alt+f
109118
Meta keys will not be active when shell echo is set to off.
110119

111120
config SHELL_HELP
112121
bool "Enable help message"
113-
default y
122+
default y if !SHELL_MINIMAL
114123
help
115124
Enables formatting help message when requested with '-h' or '--help'.
116125

117126
config SHELL_HELP_ON_WRONG_ARGUMENT_COUNT
118127
bool "Enable printing help on wrong argument count"
119128
depends on SHELL_HELP
120-
default y
129+
default y if !SHELL_MINIMAL
121130

122131
config SHELL_HISTORY
123132
bool "Enable history in shell"
124-
default y
133+
default y if !SHELL_MINIMAL
125134
select RING_BUFFER
126135
help
127136
Enable commands history. History can be accessed using up and down
128137
arrows or Ctrl+n and Ctrl+p meta keys.
129138

130139
config SHELL_HISTORY_BUFFER
131140
int "History buffer in bytes"
141+
default 128 if SHELL_MINIMAL
132142
default 512
133143
depends on SHELL_HISTORY
134144
help
135145
Number of bytes dedicated for storing executed commands.
136146

137147
config SHELL_STATS
138148
bool "Enable shell statistics"
139-
default y
149+
default y if !SHELL_MINIMAL
140150

141151
config SHELL_CMDS
142152
bool "Enable built-in commands"
143-
default y
153+
default y if !SHELL_MINIMAL
144154
help
145155
Enable built-in commands like 'clear', 'history', etc.
146156

147157
config SHELL_CMDS_RESIZE
148158
bool "Enable resize command"
149159
depends on SHELL_CMDS
150-
default y
160+
default y if !SHELL_MINIMAL
151161
help
152162
By default shell assumes width of a terminal screen set to 80
153163
characters. Each time terminal screen width is changed resize command

subsys/shell/modules/Kconfig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
config KERNEL_SHELL
77
bool "Enable kernel shell"
8-
default y
8+
default y if !SHELL_MINIMAL
99
imply INIT_STACKS
1010
imply THREAD_MONITOR
1111
imply THREAD_NAME
@@ -16,13 +16,13 @@ config KERNEL_SHELL
1616

1717
config DEVICE_SHELL
1818
bool "Enable device shell"
19-
default y
19+
default y if !SHELL_MINIMAL
2020
help
2121
This shell provides access to basic device data.
2222

2323
config DATE_SHELL
2424
bool "Enable date shell"
2525
depends on POSIX_CLOCK
26-
default y
26+
default y if !SHELL_MINIMAL
2727
help
2828
This shell provides access to date and time based on Unix time.

tests/subsys/shell/shell/shell_min.conf

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,18 @@ CONFIG_ZTEST=y
22
CONFIG_TEST_LOGGING_DEFAULTS=n
33

44
CONFIG_SHELL=y
5+
CONFIG_SHELL_MINIMAL=y
56
CONFIG_SHELL_BACKEND_DUMMY=y
67
CONFIG_SHELL_BACKEND_SERIAL=n
78
CONFIG_THREAD_NAME=y
89
CONFIG_SHELL_STACK_SIZE=2048
9-
CONFIG_SHELL_CMD_BUFF_SIZE=128
1010

1111
#using CBPRINTF_NANO decreases signigicantly Flash usage.
1212
CONFIG_CBPRINTF_NANO=y
1313

1414
CONFIG_LOG=n
15-
#Shell features:
16-
CONFIG_SHELL_LOG_BACKEND=n
17-
CONFIG_SHELL_TAB=n
18-
CONFIG_SHELL_TAB_AUTOCOMPLETION=n
19-
CONFIG_SHELL_HELP=n
20-
CONFIG_SHELL_HELP_ON_WRONG_ARGUMENT_COUNT=n
21-
CONFIG_SHELL_HISTORY=n
22-
CONFIG_SHELL_CMDS=n
23-
CONFIG_SHELL_CMDS_RESIZE=n
24-
CONFIG_SHELL_CMDS_SELECT=n
25-
CONFIG_SHELL_WILDCARD=n
26-
CONFIG_SHELL_METAKEYS=n
27-
CONFIG_SHELL_VT100_COLORS=n
2815

29-
CONFIG_KERNEL_SHELL=n
3016
CONFIG_OBJECT_TRACING=n
3117
CONFIG_THREAD_MONITOR=n
3218
CONFIG_INIT_STACKS=y
3319
CONFIG_BOOT_BANNER=n
34-
CONFIG_SHELL_STATS=n
35-
CONFIG_KERNEL_SHELL=n
36-
CONFIG_DEVICE_SHELL=n
37-
CONFIG_DATE_SHELL=n
38-
CONFIG_SENSOR_SHELL=n

tests/subsys/shell/shell/shell_min_cmds.conf

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,20 @@ CONFIG_ZTEST=y
22
CONFIG_TEST_LOGGING_DEFAULTS=n
33

44
CONFIG_SHELL=y
5+
CONFIG_SHELL_MINIMAL=y
56
CONFIG_SHELL_BACKEND_DUMMY=y
67
CONFIG_SHELL_BACKEND_SERIAL=n
78
CONFIG_THREAD_NAME=y
89
CONFIG_SHELL_STACK_SIZE=2048
9-
CONFIG_SHELL_CMD_BUFF_SIZE=128
1010

1111
#using CBPRINTF_NANO decreases signigicantly Flash usage.
1212
CONFIG_CBPRINTF_NANO=y
1313

1414
CONFIG_LOG=n
1515
#Shell features:
16-
CONFIG_SHELL_LOG_BACKEND=n
17-
CONFIG_SHELL_TAB=n
18-
CONFIG_SHELL_TAB_AUTOCOMPLETION=n
19-
CONFIG_SHELL_HELP=n
20-
CONFIG_SHELL_HELP_ON_WRONG_ARGUMENT_COUNT=n
21-
CONFIG_SHELL_HISTORY=n
2216
CONFIG_SHELL_CMDS=y
23-
CONFIG_SHELL_CMDS_RESIZE=n
24-
CONFIG_SHELL_CMDS_SELECT=n
25-
CONFIG_SHELL_WILDCARD=n
26-
CONFIG_SHELL_METAKEYS=n
27-
CONFIG_SHELL_VT100_COLORS=n
2817

29-
CONFIG_KERNEL_SHELL=n
3018
CONFIG_OBJECT_TRACING=n
3119
CONFIG_THREAD_MONITOR=n
3220
CONFIG_INIT_STACKS=y
3321
CONFIG_BOOT_BANNER=n
34-
CONFIG_SHELL_STATS=n
35-
CONFIG_KERNEL_SHELL=n
36-
CONFIG_DEVICE_SHELL=n
37-
CONFIG_DATE_SHELL=n
38-
CONFIG_SENSOR_SHELL=n

tests/subsys/shell/shell/shell_min_cmds_all.conf

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,22 @@ CONFIG_ZTEST=y
22
CONFIG_TEST_LOGGING_DEFAULTS=n
33

44
CONFIG_SHELL=y
5+
CONFIG_SHELL_MINIMAL=y
56
CONFIG_SHELL_BACKEND_DUMMY=y
67
CONFIG_SHELL_BACKEND_SERIAL=n
78
CONFIG_THREAD_NAME=y
89
CONFIG_SHELL_STACK_SIZE=2048
9-
CONFIG_SHELL_CMD_BUFF_SIZE=128
1010

1111
#using CBPRINTF_NANO decreases signigicantly Flash usage.
1212
CONFIG_CBPRINTF_NANO=y
1313

1414
CONFIG_LOG=n
1515
#Shell features:
16-
CONFIG_SHELL_LOG_BACKEND=n
17-
CONFIG_SHELL_TAB=n
18-
CONFIG_SHELL_TAB_AUTOCOMPLETION=n
19-
CONFIG_SHELL_HELP=n
20-
CONFIG_SHELL_HELP_ON_WRONG_ARGUMENT_COUNT=n
21-
CONFIG_SHELL_HISTORY=n
2216
CONFIG_SHELL_CMDS=y
2317
CONFIG_SHELL_CMDS_RESIZE=y
2418
CONFIG_SHELL_CMDS_SELECT=y
25-
CONFIG_SHELL_WILDCARD=n
26-
CONFIG_SHELL_METAKEYS=n
27-
CONFIG_SHELL_VT100_COLORS=n
2819

29-
CONFIG_KERNEL_SHELL=n
3020
CONFIG_OBJECT_TRACING=n
3121
CONFIG_THREAD_MONITOR=n
3222
CONFIG_INIT_STACKS=y
3323
CONFIG_BOOT_BANNER=n
34-
CONFIG_SHELL_STATS=n
35-
CONFIG_KERNEL_SHELL=n
36-
CONFIG_DEVICE_SHELL=n
37-
CONFIG_DATE_SHELL=n
38-
CONFIG_SENSOR_SHELL=n

tests/subsys/shell/shell/shell_min_cmds_resize.conf

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,21 @@ CONFIG_ZTEST=y
22
CONFIG_TEST_LOGGING_DEFAULTS=n
33

44
CONFIG_SHELL=y
5+
CONFIG_SHELL_MINIMAL=y
56
CONFIG_SHELL_BACKEND_DUMMY=y
67
CONFIG_SHELL_BACKEND_SERIAL=n
78
CONFIG_THREAD_NAME=y
89
CONFIG_SHELL_STACK_SIZE=2048
9-
CONFIG_SHELL_CMD_BUFF_SIZE=128
1010

1111
#using CBPRINTF_NANO decreases signigicantly Flash usage.
1212
CONFIG_CBPRINTF_NANO=y
1313

1414
CONFIG_LOG=n
1515
#Shell features:
16-
CONFIG_SHELL_LOG_BACKEND=n
17-
CONFIG_SHELL_TAB=n
18-
CONFIG_SHELL_TAB_AUTOCOMPLETION=n
19-
CONFIG_SHELL_HELP=n
20-
CONFIG_SHELL_HELP_ON_WRONG_ARGUMENT_COUNT=n
21-
CONFIG_SHELL_HISTORY=n
2216
CONFIG_SHELL_CMDS=y
2317
CONFIG_SHELL_CMDS_RESIZE=y
24-
CONFIG_SHELL_CMDS_SELECT=n
25-
CONFIG_SHELL_WILDCARD=n
26-
CONFIG_SHELL_METAKEYS=n
27-
CONFIG_SHELL_VT100_COLORS=n
2818

29-
CONFIG_KERNEL_SHELL=n
3019
CONFIG_OBJECT_TRACING=n
3120
CONFIG_THREAD_MONITOR=n
3221
CONFIG_INIT_STACKS=y
3322
CONFIG_BOOT_BANNER=n
34-
CONFIG_SHELL_STATS=n
35-
CONFIG_KERNEL_SHELL=n
36-
CONFIG_DEVICE_SHELL=n
37-
CONFIG_DATE_SHELL=n
38-
CONFIG_SENSOR_SHELL=n

0 commit comments

Comments
 (0)