shell: Convert to using iterable sections
Convert handling of shell_root_cmds, shell_subcmds, and shell_dynamic_subcmds to use iterable section macros. Signed-off-by: Kumar Gala <kumar.gala@intel.com>
This commit is contained in:
parent
17ca780674
commit
6b5139c4bb
4 changed files with 51 additions and 58 deletions
|
|
@ -173,6 +173,12 @@ zephyr_linker_section_configure(SECTION log_const INPUT ".log_const_*" KEEP SORT
|
|||
|
||||
zephyr_iterable_section(NAME shell KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4)
|
||||
|
||||
zephyr_iterable_section(NAME shell_root_cmds KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4)
|
||||
|
||||
zephyr_iterable_section(NAME shell_subcmds KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4)
|
||||
|
||||
zephyr_iterable_section(NAME shell_dynamic_subcmds KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4)
|
||||
|
||||
zephyr_linker_section(NAME shell_root_cmds KVMA RAM_REGION GROUP RODATA_REGION NOINPUT ${XIP_ALIGN_WITH_INPUT})
|
||||
zephyr_linker_section_configure(SECTION shell_root_cmds INPUT ".shell_root_cmd_*" KEEP SORT NAME)
|
||||
|
||||
|
|
|
|||
|
|
@ -33,26 +33,11 @@
|
|||
|
||||
ITERABLE_SECTION_ROM(shell, 4)
|
||||
|
||||
SECTION_DATA_PROLOGUE(shell_root_cmds_sections,,)
|
||||
{
|
||||
__shell_root_cmds_start = .;
|
||||
KEEP(*(SORT(.shell_root_cmd_*)));
|
||||
__shell_root_cmds_end = .;
|
||||
} GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
|
||||
ITERABLE_SECTION_ROM(shell_root_cmds, 4)
|
||||
|
||||
SECTION_DATA_PROLOGUE(shell_subcmds_sections,,)
|
||||
{
|
||||
__shell_subcmds_start = .;
|
||||
KEEP(*(SORT(.shell_subcmd_*)));
|
||||
__shell_subcmds_end = .;
|
||||
} GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
|
||||
ITERABLE_SECTION_ROM(shell_subcmds, 4)
|
||||
|
||||
SECTION_DATA_PROLOGUE(shell_dynamic_subcmds_sections,,)
|
||||
{
|
||||
__shell_dynamic_subcmds_start = .;
|
||||
KEEP(*(SORT(.shell_dynamic_subcmd_*)));
|
||||
__shell_dynamic_subcmds_end = .;
|
||||
} GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
|
||||
ITERABLE_SECTION_ROM(shell_dynamic_subcmds, 4)
|
||||
|
||||
SECTION_DATA_PROLOGUE(font_entry_sections,,)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -196,10 +196,10 @@ struct shell_static_entry {
|
|||
mandatory, optional) \
|
||||
static const struct shell_static_entry UTIL_CAT(_shell_, syntax) = \
|
||||
SHELL_CMD_ARG(syntax, subcmd, help, handler, mandatory, optional); \
|
||||
static const union shell_cmd_entry UTIL_CAT(shell_cmd_, syntax) \
|
||||
__attribute__ ((section("." \
|
||||
STRINGIFY(UTIL_CAT(shell_root_cmd_, syntax))))) \
|
||||
__attribute__((used)) = { \
|
||||
static const TYPE_SECTION_ITERABLE(union shell_cmd_entry, \
|
||||
UTIL_CAT(shell_cmd_, syntax), shell_root_cmds, \
|
||||
UTIL_CAT(shell_cmd_, syntax) \
|
||||
) = { \
|
||||
.entry = &UTIL_CAT(_shell_, syntax) \
|
||||
}
|
||||
|
||||
|
|
@ -294,7 +294,12 @@ struct shell_static_entry {
|
|||
|
||||
#define Z_SHELL_UNDERSCORE(x) _##x
|
||||
#define Z_SHELL_SUBCMD_NAME(...) \
|
||||
UTIL_CAT(shell_subcmd, MACRO_MAP_CAT(Z_SHELL_UNDERSCORE, __VA_ARGS__))
|
||||
UTIL_CAT(shell_subcmds, MACRO_MAP_CAT(Z_SHELL_UNDERSCORE, __VA_ARGS__))
|
||||
#define Z_SHELL_SUBCMD_SECTION_TAG(...) MACRO_MAP_CAT(Z_SHELL_UNDERSCORE, __VA_ARGS__)
|
||||
#define Z_SHELL_SUBCMD_SET_SECTION_TAG(x) \
|
||||
Z_SHELL_SUBCMD_SECTION_TAG(NUM_VA_ARGS_LESS_1 x, __DEBRACKET x)
|
||||
#define Z_SHELL_SUBCMD_ADD_SECTION_TAG(x, y) \
|
||||
Z_SHELL_SUBCMD_SECTION_TAG(NUM_VA_ARGS_LESS_1 x, __DEBRACKET x, y)
|
||||
|
||||
/** @brief Create set of subcommands.
|
||||
*
|
||||
|
|
@ -307,12 +312,11 @@ struct shell_static_entry {
|
|||
* @param[in] _parent Set of comma separated parent commands in parenthesis, e.g.
|
||||
* (foo_cmd) if subcommands are for the root command "foo_cmd".
|
||||
*/
|
||||
#define SHELL_SUBCMD_SET_CREATE(_name, _parent) \
|
||||
static const struct shell_static_entry _name \
|
||||
__attribute__ ((section("." \
|
||||
STRINGIFY(Z_SHELL_SUBCMD_NAME(NUM_VA_ARGS_LESS_1 _parent, \
|
||||
__DEBRACKET _parent))))) \
|
||||
__attribute__((used))
|
||||
|
||||
#define SHELL_SUBCMD_SET_CREATE(_name, _parent) \
|
||||
static const TYPE_SECTION_ITERABLE(struct shell_static_entry, _name, shell_subcmds, \
|
||||
Z_SHELL_SUBCMD_SET_SECTION_TAG(_parent))
|
||||
|
||||
|
||||
/** @brief Conditionally add command to the set of subcommands.
|
||||
*
|
||||
|
|
@ -336,12 +340,10 @@ struct shell_static_entry {
|
|||
#define SHELL_SUBCMD_COND_ADD(_flag, _parent, _syntax, _subcmd, _help, _handler, \
|
||||
_mand, _opt) \
|
||||
COND_CODE_1(_flag, \
|
||||
(static const struct shell_static_entry \
|
||||
Z_SHELL_SUBCMD_NAME(__DEBRACKET _parent, _syntax)\
|
||||
__attribute__ ((section("." \
|
||||
STRINGIFY(Z_SHELL_SUBCMD_NAME(NUM_VA_ARGS_LESS_1 _parent, \
|
||||
__DEBRACKET _parent, _syntax))))) \
|
||||
__attribute__((used)) = \
|
||||
(static const TYPE_SECTION_ITERABLE(struct shell_static_entry, \
|
||||
Z_SHELL_SUBCMD_NAME(__DEBRACKET _parent, _syntax), \
|
||||
shell_subcmds, \
|
||||
Z_SHELL_SUBCMD_ADD_SECTION_TAG(_parent, _syntax)) = \
|
||||
SHELL_EXPR_CMD_ARG(1, _syntax, _subcmd, _help, \
|
||||
_handler, _mand, _opt)\
|
||||
), \
|
||||
|
|
@ -380,10 +382,9 @@ struct shell_static_entry {
|
|||
* @param[in] get Pointer to the function returning dynamic commands array
|
||||
*/
|
||||
#define SHELL_DYNAMIC_CMD_CREATE(name, get) \
|
||||
static const union shell_cmd_entry name \
|
||||
__attribute__ ((section("." \
|
||||
STRINGIFY(UTIL_CAT(shell_dynamic_subcmd_, syntax))))) \
|
||||
__attribute__((used)) = { \
|
||||
static const TYPE_SECTION_ITERABLE(union shell_cmd_entry, name, \
|
||||
shell_dynamic_subcmds, name) = \
|
||||
{ \
|
||||
.dynamic_get = get \
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,29 +9,28 @@
|
|||
#include "shell_utils.h"
|
||||
#include "shell_wildcard.h"
|
||||
|
||||
extern const union shell_cmd_entry __shell_root_cmds_start[];
|
||||
extern const union shell_cmd_entry __shell_root_cmds_end[];
|
||||
TYPE_SECTION_START_EXTERN(union shell_cmd_entry, shell_dynamic_subcmds);
|
||||
TYPE_SECTION_END_EXTERN(union shell_cmd_entry, shell_dynamic_subcmds);
|
||||
|
||||
extern const union shell_cmd_entry __shell_dynamic_subcmds_start[];
|
||||
extern const union shell_cmd_entry __shell_dynamic_subcmds_end[];
|
||||
|
||||
extern const union shell_cmd_entry __shell_subcmds_start[];
|
||||
extern const union shell_cmd_entry __shell_subcmds_end[];
|
||||
TYPE_SECTION_START_EXTERN(union shell_cmd_entry, shell_subcmds);
|
||||
TYPE_SECTION_END_EXTERN(union shell_cmd_entry, shell_subcmds);
|
||||
|
||||
/* Macro creates empty entry at the bottom of the memory section with subcommands
|
||||
* it is used to detect end of subcommand set that is located before this marker.
|
||||
*/
|
||||
#define Z_SHELL_SUBCMD_END_MARKER_CREATE() \
|
||||
static const struct shell_static_entry z_shell_subcmd_end_marker\
|
||||
__attribute__ ((section("." \
|
||||
STRINGIFY(Z_SHELL_SUBCMD_NAME(999))))) \
|
||||
__attribute__((used))
|
||||
static const TYPE_SECTION_ITERABLE(struct shell_static_entry, \
|
||||
z_shell_subcmd_end_marker, shell_subcmds, Z_SHELL_UNDERSCORE(999))
|
||||
|
||||
Z_SHELL_SUBCMD_END_MARKER_CREATE();
|
||||
|
||||
static inline const union shell_cmd_entry *shell_root_cmd_get(uint32_t id)
|
||||
{
|
||||
return &__shell_root_cmds_start[id];
|
||||
const union shell_cmd_entry *cmd;
|
||||
|
||||
TYPE_SECTION_GET(union shell_cmd_entry, shell_root_cmds, id, &cmd);
|
||||
|
||||
return cmd;
|
||||
}
|
||||
|
||||
/* Determine if entry is a dynamic command by checking if address is within
|
||||
|
|
@ -39,8 +38,8 @@ static inline const union shell_cmd_entry *shell_root_cmd_get(uint32_t id)
|
|||
*/
|
||||
static inline bool is_dynamic_cmd(const union shell_cmd_entry *entry)
|
||||
{
|
||||
return (entry >= __shell_dynamic_subcmds_start) &&
|
||||
(entry < __shell_dynamic_subcmds_end);
|
||||
return (entry >= TYPE_SECTION_START(shell_dynamic_subcmds)) &&
|
||||
(entry < TYPE_SECTION_END(shell_dynamic_subcmds));
|
||||
}
|
||||
|
||||
/* Determine if entry is a section command by checking if address is within
|
||||
|
|
@ -48,8 +47,8 @@ static inline bool is_dynamic_cmd(const union shell_cmd_entry *entry)
|
|||
*/
|
||||
static inline bool is_section_cmd(const union shell_cmd_entry *entry)
|
||||
{
|
||||
return (entry >= __shell_subcmds_start) &&
|
||||
(entry < __shell_subcmds_end);
|
||||
return (entry >= TYPE_SECTION_START(shell_subcmds)) &&
|
||||
(entry < TYPE_SECTION_END(shell_subcmds));
|
||||
}
|
||||
|
||||
/* Calculates relative line number of given position in buffer */
|
||||
|
|
@ -259,9 +258,11 @@ void z_shell_pattern_remove(char *buff, uint16_t *buff_len, const char *pattern)
|
|||
|
||||
static inline uint32_t shell_root_cmd_count(void)
|
||||
{
|
||||
return ((uint8_t *)__shell_root_cmds_end -
|
||||
(uint8_t *)__shell_root_cmds_start)/
|
||||
sizeof(union shell_cmd_entry);
|
||||
size_t len;
|
||||
|
||||
TYPE_SECTION_COUNT(union shell_cmd_entry, shell_root_cmds, &len);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
/* Function returning pointer to parent command matching requested syntax. */
|
||||
|
|
|
|||
Loading…
Reference in a new issue