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
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions fs/fs/pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ pkg.deps.FS_CLI:

pkg.deps.FS_MGMT:
- "@apache-mynewt-mcumgr/cmd/fs/port/mynewt"

pkg.whole_archive: true
84 changes: 27 additions & 57 deletions fs/fs/src/fs_cli.c
10000
Original file line number Diff line number Diff line change
Expand Up @@ -29,51 +29,24 @@

#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)
fs_ls_file(struct streamer *streamer, const char *name, struct fs_file *file)
{
uint32_t len;

len = 0;
fs_filelen(file, &len);
console_printf("\t%6lu %s\n", (unsigned long)len, name);
streamer_printf(streamer, "\t%6lu %s\n", (unsigned long)len, name);
}

static void
fs_ls_dir(const char *name)
fs_ls_dir(struct streamer *streamer, const char *name)
{
console_printf("\t%6s %s\n", "dir", name);
streamer_printf(streamer, "\t%6s %s\n", "dir", name);
}

static int
fs_ls_cmd(int argc, char **argv)
fs_ls_cmd(const struct shell_cmd *cmd, int argc, char **argv, struct streamer *streamer)
{
int rc, file_cnt = 0;
char *path;
Expand All @@ -92,13 +65,13 @@ fs_ls_cmd(int argc, char **argv)
path = argv[1];
break;
default:
console_printf("ls <path>\n");
streamer_printf(streamer, "ls <path>\n");
return 1;
}

rc = fs_open(path, FS_ACCESS_READ, &file);
if (rc == 0) {
fs_ls_file(path, file);
fs_ls_file(streamer, path, file);
fs_close(file);
file_cnt = 1;
goto done;
Expand All @@ -124,24 +97,24 @@ fs_ls_cmd(int argc, char **argv)
}
rc = fs_open(name, FS_ACCESS_READ, &file);
if (rc == 0) {
fs_ls_file(name, file);
fs_ls_file(streamer, name, file);
fs_close(file);
} else {
fs_ls_dir(name);
fs_ls_dir(streamer, name);
}
file_cnt++;
} while (1);
fs_closedir(dir);
goto done;
}
console_printf("Error listing %s - %d\n", path, rc);
streamer_printf(streamer, "Error listing %s - %d\n", path, rc);
done:
console_printf("%d files\n", file_cnt);
streamer_printf(streamer, "%d files\n", file_cnt);
return 0;
}

static int
fs_rm_cmd(int argc, char **argv)
fs_rm_cmd(const struct shell_cmd *cmd, int argc, char **argv, struct streamer *streamer)
{
int i;
int rc;
Expand All @@ -156,22 +129,22 @@ fs_rm_cmd(int argc, char **argv)
}

static int
fs_mkdir_cmd(int argc, char **argv)
fs_mkdir_cmd(const struct shell_cmd *cmd, int argc, char **argv, struct streamer *streamer)
{
int i;
int rc;

for (i = 1; i < argc; i++) {
rc = fs_mkdir(argv[1]);
if (rc) {
console_printf("Error creating %s - %d\n", argv[i], rc);
streamer_printf(streamer, "Error creating %s - %d\n", argv[i], rc);
}
}
return 0;
}

static int
fs_mv_cmd(int argc, char **argv)
fs_mv_cmd(const struct shell_cmd *cmd, int argc, char **argv, struct streamer *streamer)
{
int rc;

Expand All @@ -182,51 +155,48 @@ fs_mv_cmd(int argc, char **argv)
rc = fs_rename(argv[1], argv[2]);
out:
if (rc) {
console_printf("Error moving - %d\n", rc);
streamer_printf(streamer, "Error moving - %d\n", rc);
}
return 0;
}

static int
fs_cat_cmd(int argc, char **argv)
fs_cat_cmd(const struct shell_cmd *cmd, int argc, char **argv, struct streamer *streamer)
{
int rc;
struct fs_file *file;
char buf[32];
uint32_t len;

if (argc != 2) {
console_printf("cat <filename>\n");
streamer_printf(streamer, "cat <filename>\n");
return -1;
}

rc = fs_open(argv[1], FS_ACCESS_READ, &file);
if (rc != FS_EOK) {
console_printf("Error opening %s - %d\n", argv[1], rc);
streamer_printf(streamer, "Error opening %s - %d\n", argv[1], rc);
return -1;
}

do {
rc = fs_read(file, sizeof(buf), buf, &len);
if (rc != FS_EOK) {
console_printf("\nError reading %s - %d\n", argv[1], rc);
streamer_printf(streamer, "\nError reading %s - %d\n", argv[1], rc);
break;
}
console_write(buf, len);
streamer_write(streamer, buf, len);
} while (len > 0);

fs_close(file);

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) */
11 changes: 0 additions & 11 deletions fs/fs/src/fs_mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down
3 changes: 0 additions & 3 deletions fs/fs/src/fs_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions hw/mcu/stm/stm32f1xx/mcu_cli/pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ pkg.deps:
pkg.req_apis:
- console

pkg.init:
mcu_cli_init: 'MYNEWT_VAL(MCU_CLI_SYSINIT_STAGE)'
pkg.whole_archive: true
9 changes: 1 addition & 8 deletions hw/mcu/stm/stm32f1xx/mcu_cli/src/mcu_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,6 @@ static const struct shell_cmd_help mcu_cli_info_help = {

static const struct shell_cmd mcu_cli_commands[] = {
SHELL_CMD_EXT("info", mcu_cli_info_cmd, &mcu_cli_info_help),
{ },
};

int
mcu_cli_init(void)
{
shell_register("mcu", mcu_cli_commands);

return 0;
}
SHELL_MODULE_WITH_TABLE(mcu, mcu_cli_commands)
4 changes: 0 additions & 4 deletions hw/mcu/stm/st 2851 m32f1xx/mcu_cli/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,3 @@
#

syscfg.defs:
MCU_CLI_SYSINIT_STAGE:
description: >
Sysinit stage for mcu cli.
value: 501
3 changes: 1 addition & 2 deletions hw/mcu/stm/stm32f4xx/mcu_cli/pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,4 @@ pkg.deps:
pkg.req_apis:
- console

pkg.init:
mcu_cli_init: 'MYNEWT_VAL(MCU_CLI_SYSINIT_STAGE)'
pkg.whole_archive: true
9 changes: 1 addition & 8 deletions hw/mcu/stm/stm32f4xx/mcu_cli/src/mcu_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,13 +424,6 @@ static const struct shell_cmd_help mcu_cli_info_help = {

static const struct shell_cmd mcu_cli_commands[] = {
SHELL_CMD_EXT("info", mcu_cli_info_cmd, &mcu_cli_info_help),
{ },
};

int
mcu_cli_init(void)
{
shell_register("mcu", mcu_cli_commands);

return 0;
}
SHELL_MODULE_WITH_TABLE(mcu, mcu_cli_commands)
4 changes: 0 additions & 4 deletions hw/mcu/stm/stm32f4xx/mcu_cli/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,3 @@
#

syscfg.defs:
MCU_CLI_SYSINIT_STAGE:
description: >
Sysinit stage for mcu cli.
value: 501
3 changes: 1 addition & 2 deletions hw/usb/tinyusb/shell/pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@ pkg.deps:
- "@apache-mynewt-core/kernel/os"
- "@apache-mynewt-core/hw/usb/tinyusb"

pkg.init:
tinyusb_cli_init: 'MYNEWT_VAL(SHELL_SYSINIT_STAGE) + 1'
pkg.whole_archive: true
9 changes: 1 addition & 8 deletions hw/usb/tinyusb/shell/src/tinyusb_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ usb_cli_stop_cmd(const struct shell_cmd *cmd, int argc, char **argv,
static const struct shell_cmd usb_cli_commands[] = {
SHELL_CMD_EXT("start", usb_cli_start_cmd, NULL),
SHELL_CMD_EXT("stop", usb_cli_stop_cmd, NULL),
{ },
};

int
tinyusb_cli_init(void)
{
shell_register("usb", usb_cli_commands);

return 0;
}
SHELL_MODULE_WITH_TABLE(usb, usb_cli_commands)
Loading
Loading
0