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 <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
This commit is contained in:
Yong Cong Sin 2024-08-23 16:51:31 +08:00 committed by Carles Cufí
commit 276ccd04e7

View file

@ -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 <address> [<width>]\n"
"Write memory at address with mandatory width and value:\n"
"devmem address <width> <value>",
cmd_devmem);
"devmem <address> <width> <value>",
cmd_devmem, 2, 2);