This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit a562d649c61499c4e337f4693bc9642fe1cfb31f
Author: Jerzy Kasenberg <[email protected]>
AuthorDate: Sat May 31 18:48:07 2025 +0200

    fs/fs_cli: Register commands statically
    
    Now fs cli commands are register at link time to
    reduce memory footprint.
    No change in functionality.
    
    Signed-off-by: Jerzy Kasenberg <[email protected]>
---
 fs/fs/pkg.yml        |  2 ++
 fs/fs/src/fs_cli.c   | 42 ++++++------------------------------------
 fs/fs/src/fs_mount.c | 11 -----------
 fs/fs/src/fs_priv.h  |  3 ---
 4 files changed, 8 insertions(+), 50 deletions(-)

diff --git a/fs/fs/pkg.yml b/fs/fs/pkg.yml
index d08fd18de..10c68746e 100644
--- a/fs/fs/pkg.yml
+++ b/fs/fs/pkg.yml
@@ -34,3 +34,5 @@ pkg.deps.FS_CLI:
 
 pkg.deps.FS_MGMT:
     - "@apache-mynewt-mcumgr/cmd/fs_mgmt/port/mynewt"
+
+pkg.whole_archive: true
diff --git a/fs/fs/src/fs_cli.c b/fs/fs/src/fs_cli.c
index 257586093..9fa932a22 100644
--- a/fs/fs/src/fs_cli.c
+++ b/fs/fs/src/fs_cli.c
@@ -29,33 +29,6 @@
 
 #include "fs/fs.h"
 
-static int fs_ls_cmd(int argc, char **argv);
-static int fs_rm_cmd(int argc, char **argv);
-static int fs_mkdir_cmd(int argc, char **argv);
-static int fs_mv_cmd(int argc, char **argv);
-static int fs_cat_cmd(int argc, char **argv);
-
-static struct shell_cmd fs_ls_struct = {
-    .sc_cmd = "ls",
-    .sc_cmd_func = fs_ls_cmd
-};
-static struct shell_cmd fs_rm_struct = {
-    .sc_cmd = "rm",
-    .sc_cmd_func = fs_rm_cmd
-};
-static struct shell_cmd fs_mkdir_struct = {
-    .sc_cmd = "mkdir",
-    .sc_cmd_func = fs_mkdir_cmd
-};
-static struct shell_cmd fs_mv_struct = {
-    .sc_cmd = "mv",
-    .sc_cmd_func = fs_mv_cmd
-};
-static struct shell_cmd fs_cat_struct = {
-    .sc_cmd = "cat",
-    .sc_cmd_func = fs_cat_cmd
-};
-
 static void
 fs_ls_file(const char *name, struct fs_file *file)
 {
@@ -220,13 +193,10 @@ fs_cat_cmd(int argc, char **argv)
     return 0;
 }
 
-void
-fs_cli_init(void)
-{
-    shell_cmd_register(&fs_ls_struct);
-    shell_cmd_register(&fs_rm_struct);
-    shell_cmd_register(&fs_mkdir_struct);
-    shell_cmd_register(&fs_mv_struct);
-    shell_cmd_register(&fs_cat_struct);
-}
+MAKE_SHELL_CMD(ls, fs_ls_cmd, NULL)
+MAKE_SHELL_CMD(rm, fs_rm_cmd, NULL)
+MAKE_SHELL_CMD(mkdir, fs_mkdir_cmd, NULL)
+MAKE_SHELL_CMD(mv, fs_mv_cmd, NULL)
+MAKE_SHELL_CMD(cat, fs_cat_cmd, NULL)
+
 #endif /* MYNEWT_VAL(FS_CLI) */
diff --git a/fs/fs/src/fs_mount.c b/fs/fs/src/fs_mount.c
index 5319aed7b..c687cf47c 100644
--- a/fs/fs/src/fs_mount.c
+++ b/fs/fs/src/fs_mount.c
@@ -28,10 +28,6 @@
 
 static SLIST_HEAD(, fs_ops) root_fops = SLIST_HEAD_INITIALIZER();
 
-#if MYNEWT_VAL(FS_CLI)
-static uint8_t g_cli_initialized;
-#endif
-
 #if MYNEWT_VAL(FS_MGMT)
 static uint8_t g_mgmt_initialized;
 #endif
@@ -49,13 +45,6 @@ fs_register(struct fs_ops *fops)
 
     SLIST_INSERT_HEAD(&root_fops, fops, sc_next);
 
-#if MYNEWT_VAL(FS_CLI)
-    if (!g_cli_initialized) {
-        fs_cli_init();
-        g_cli_initialized = 1;
-    }
-#endif
-
 #if MYNEWT_VAL(FS_MGMT)
     if (!g_mgmt_initialized) {
         fs_mgmt_register_group();
diff --git a/fs/fs/src/fs_priv.h b/fs/fs/src/fs_priv.h
index 0e6345db5..d5138c938 100644
--- a/fs/fs/src/fs_priv.h
+++ b/fs/fs/src/fs_priv.h
@@ -29,9 +29,6 @@ struct fs_ops;
 struct fs_ops *fs_ops_for(const char *fs_name);
 struct fs_ops *safe_fs_ops_for(const char *fs_name);
 
-#if MYNEWT_VAL(FS_CLI)
-void fs_cli_init(void);
-#endif
 
 #ifdef __cplusplus
 }

Reply via email to