From 276ccd04e7b95bb4111036c339c7ae37da7b9f9a Mon Sep 17 00:00:00 2001 From: Yong Cong Sin Date: Fri, 23 Aug 2024 16:51:31 +0800 Subject: [PATCH] shell: devmem: minor optimizations - Use `SHELL_CMD_ARG_REGISTER` for the main cmd to state the required number of arguments, this helps to remove the runtime check from the command, and also print the help message to the terminal when the argument count is unexpected. - Some changes to the help text that hopefully makes the mandatory and optional arguments more obvious to the user Signed-off-by: Yong Cong Sin Signed-off-by: Yong Cong Sin --- subsys/shell/modules/devmem_service.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/subsys/shell/modules/devmem_service.c b/subsys/shell/modules/devmem_service.c index 8b649e8093b..e1ebaee7ef3 100644 --- a/subsys/shell/modules/devmem_service.c +++ b/subsys/shell/modules/devmem_service.c @@ -315,10 +315,6 @@ static int cmd_devmem(const struct shell *sh, size_t argc, char **argv) uint32_t value = 0; uint8_t width; - if (argc < 2 || argc > 4) { - return -EINVAL; - } - phys_addr = strtoul(argv[1], NULL, 16); #if defined(CONFIG_MMU) || defined(CONFIG_PCIE) @@ -365,11 +361,11 @@ SHELL_STATIC_SUBCMD_SET_CREATE(sub_devmem, cmd_load, 2, 1), SHELL_SUBCMD_SET_END); -SHELL_CMD_REGISTER(devmem, &sub_devmem, +SHELL_CMD_ARG_REGISTER(devmem, &sub_devmem, "Read/write physical memory\n" "Usage:\n" "Read memory at address with optional width:\n" - "devmem address [width]\n" + "devmem
[]\n" "Write memory at address with mandatory width and value:\n" - "devmem address ", - cmd_devmem); + "devmem
", + cmd_devmem, 2, 2);