8000 Shell commands and modules added during link time by kasjer · Pull Request #3424 · apache/mynewt-core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Shell commands and modules added during link time #3424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

kasjer
Copy link
Contributor
@kasjer kasjer commented Jun 1, 2025

Shell commands registration

So far shell commands could be added with shell_cmd_register() and modules (set of commands) could be added with shell_register()

This approach requires function call usually added in package initialization function.
Registering commands requires some RAM two tables:

static struct shell_module shell_modules[MYNEWT_VAL(SHELL_MAX_MODULES)];
static struct shell_cmd compat_commands[MYNEWT_VAL(SHELL_MAX_COMPAT_COMMANDS) + 1];

Number of modules that can be registered is defined by two mynewt values SHELL_MAX_MODULES and SHELL_MAX_COMPAT_COMMANDS.
When code tries to add more commands or modules system will crash with assert(0).

Link time table for commands registration

Now when link time table can be used shell commands and modules can be added to be available in shell.
Commands can be added with macro MAKE_SHELL_CMD() and modules can be added using SHELL_MODULE_WITH_TABLE().
Both register commands and modules does not use RAM and do not need function calls.

For backward compatibility shell_cmd_register() and shell_register() can still be used.
To minimize memory usage syscfg values SHELL_MAX_MODULES and SHELL_MAX_COMPAT_COMMANDS can be set to 0.

Benefits of new shell commands registration

  • Memory usage is reduced both RAM and flash
  • commands are in alphabetical order (they were displayed in order they were registered)
  • Targets don't need to specify maximum number of command and modules so adding some package will not result in unexpected assert(0) that instruct you to increase limits.

Scope of this PR

  • Macros for module and commands creation
  • Rework of shell command handling to use link time tables
  • Update of many packages (not all yet) to use new way of making shell commands

Comparison of size for target that with many commands

Code without this changes

objsize
   text	   data	    bss	    dec	    hex	filename
 121368	   1744	  30572	 153684	  25854	bin/targets/blackpill411ce-slinky/app/@apache-mynewt-core/apps/slinky/slinky.elf

Same application after change are applied:

objsize
   text	   data	    bss	    dec	    hex	filename
 120844	   1496	  29988	 152328	  25308	bin/targets/blackpill411ce-slinky/app/@apache-mynewt-core/apps/slinky/slinky.elf

@github-actions github-actions bot added USB All USB work should have this label STM STM32 related size/xl labels Jun 1, 2025
This adds macros that help with link time generated
tables.

Signed-off-by: Jerzy Kasenberg <jerzy@apache.org>
@kasjer kasjer force-pushed the kasjer/shell-static-command-registration branch from 10590d6 to 9bc2d89 Compare June 2, 2025 07:01
kasjer added 2 commits June 2, 2025 09:08
Shell commands and modules used to be registered at
run time by packages. This required code and RAM space.
Both shell modules and commands required RAM of some fixed
size (specified in syscfg). When more commands or shell
modules were registered assertion failed at run time.

Now it's possibly to create shell commands that will be
'registered' at link time and will not require RAM
nor explicit function call.
This should eliminate problem of registering to
many modules or commands.

Signed-off-by: Jerzy Kasenberg <jerzy@apache.org>
Shell commands are now registered at link time
instead of compile time to compat module commands.

Signed-off-by: Jerzy Kasenberg <jerzy@apache.org>
@kasjer kasjer force-pushed the kasjer/shell-static-command-registration branch from 9bc2d89 to 18c4367 Compare June 2, 2025 07:08
Module prompt is not linked statically.
No need for runtime registering.

Signed-off-by: Jerzy Kasenberg <jerzy@apache.org>
@kasjer kasjer force-pushed the kasjer/shell-static-command-registration branch from 18c4367 to 3ded33b Compare June 2, 2025 07:35
kasjer added 14 commits June 5, 2025 19:59
Now fs cli commands are register at link time to
reduce memory footprint.
No change in functionality.

Signed-off-by: Jerzy Kasenberg <jerzy@apache.org>
Now stat cli commands are register at link time to
reduce memory footprint.
No change in functionality.

Signed-off-by: Jerzy Kasenberg <jerzy@apache.org>
Now flash_test commands are register at link time to
reduce memory footprint.
No change in functionality.

Signed-off-by: Jerzy Kasenberg <jerzy@apache.org>
Now coremark shell commands are register at link time to
reduce memory footprint.
No change in functionality.

Signed-off-by: Jerzy Kasenberg <jerzy@apache.org>
Now log shell commands are register at link time to
reduce memory footprint.
No change in functionality.

Remove unfinished code depending on non-existing
flag LOG_FCB_SLOT1.

Signed-off-by: Jerzy Kasenberg <jerzy@apache.org>
Now crash shell commands are register at link time to
reduce memory footprint.
No change in functionality.

Signed-off-by: Jerzy Kasenberg <jerzy@apache.org>
Now config shell command is register at link time to
reduce memory footprint.
No change in functionality.

Signed-off-by: Jerzy Kasenberg <jerzy@apache.org>
Now imgr shell command is register at link time to
reduce memory footprint.
No change in functionality.

Signed-off-by: Jerzy Kasenberg <jerzy@apache.org>
Now usb shell module is register at link time to
reduce memory footprint.
No change in functionality.

Signed-off-by: Jerzy Kasenberg <jerzy@apache.org>
Now flashstress shell command is register at link time to
reduce memory footprint.
No change in functionality.

Signed-off-by: Jerzy Kasenberg <jerzy@apache.org>
Now fault shell command is register at link time to
reduce memory footprint.
No change in functionality.

Signed-off-by: Jerzy Kasenberg <jerzy@apache.org>
Now i2c_scan shell command is register at link time to
reduce memory footprint.
No change in functionality.

Signed-off-by: Jerzy Kasenberg <jerzy@apache.org>
Now mcu shell module is register at link time to
reduce memory footprint.
No change in functionality.

Signed-off-by: Jerzy Kasenberg <jerzy@apache.org>
Now mcu shell module is register at link time to
reduce memory footprint.
No change in functionality.

Signed-off-by: Jerzy Kasenberg <jerzy@apache.org>
@kasjer kasjer force-pushed the kasjer/shell-static-command-registration branch from 3ded33b to 8396589 Compare June 5, 2025 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/xl STM STM32 related USB All USB work should have this label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0