flash: nor: rewrite command 'flash list' as COMMAND_HANDLER

The mixed use of jim commands and OpenOCD commands is error prone
due to handling of errors through JIM_xx and ERROR_yy.

Rewrite the jim command 'flash list' as OpenOCD command.
While there:
- format in a human readable way the output dictionary list, while
  preserving the structure of its TCL data;
- add the mandatory 'usage' field.

Change-Id: I1ee69870d3ab3c1cfc46cd2b8ec03de6b2300bd6
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7486
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Tested-by: jenkins
This commit is contained in:
Antonio Borneo 2022-12-18 16:09:02 +01:00
parent d05c686671
commit 80fc9fabc6
1 changed files with 18 additions and 30 deletions

View File

@ -1324,40 +1324,27 @@ COMMAND_HANDLER(handle_flash_banks_command)
return ERROR_OK; return ERROR_OK;
} }
static int jim_flash_list(Jim_Interp *interp, int argc, Jim_Obj * const *argv) COMMAND_HANDLER(handle_flash_list)
{ {
if (argc != 1) { if (CMD_ARGC != 0)
Jim_WrongNumArgs(interp, 1, argv, return ERROR_COMMAND_SYNTAX_ERROR;
"no arguments to 'flash list' command");
return JIM_ERR;
}
Jim_Obj *list = Jim_NewListObj(interp, NULL, 0);
for (struct flash_bank *p = flash_bank_list(); p; p = p->next) { for (struct flash_bank *p = flash_bank_list(); p; p = p->next) {
Jim_Obj *elem = Jim_NewListObj(interp, NULL, 0); command_print(CMD,
"{\n"
Jim_ListAppendElement(interp, elem, Jim_NewStringObj(interp, "name", -1)); " name %s\n"
Jim_ListAppendElement(interp, elem, Jim_NewStringObj(interp, p->name, -1)); " driver %s\n"
Jim_ListAppendElement(interp, elem, Jim_NewStringObj(interp, "driver", -1)); " base " TARGET_ADDR_FMT "\n"
Jim_ListAppendElement(interp, elem, Jim_NewStringObj(interp, p->driver->name, -1)); " size 0x%" PRIx32 "\n"
Jim_ListAppendElement(interp, elem, Jim_NewStringObj(interp, "base", -1)); " bus_width %u\n"
Jim_ListAppendElement(interp, elem, Jim_NewIntObj(interp, p->base)); " chip_width %u\n"
Jim_ListAppendElement(interp, elem, Jim_NewStringObj(interp, "size", -1)); " target %s\n"
Jim_ListAppendElement(interp, elem, Jim_NewIntObj(interp, p->size)); "}",
Jim_ListAppendElement(interp, elem, Jim_NewStringObj(interp, "bus_width", -1)); p->name, p->driver->name, p->base, p->size, p->bus_width, p->chip_width,
Jim_ListAppendElement(interp, elem, Jim_NewIntObj(interp, p->bus_width)); target_name(p->target));
Jim_ListAppendElement(interp, elem, Jim_NewStringObj(interp, "chip_width", -1));
Jim_ListAppendElement(interp, elem, Jim_NewIntObj(interp, p->chip_width));
Jim_ListAppendElement(interp, elem, Jim_NewStringObj(interp, "target", -1));
Jim_ListAppendElement(interp, elem, Jim_NewStringObj(interp, target_name(p->target), -1));
Jim_ListAppendElement(interp, list, elem);
} }
Jim_SetResult(interp, list); return ERROR_OK;
return JIM_OK;
} }
COMMAND_HANDLER(handle_flash_init_command) COMMAND_HANDLER(handle_flash_init_command)
@ -1404,8 +1391,9 @@ static const struct command_registration flash_config_command_handlers[] = {
{ {
.name = "list", .name = "list",
.mode = COMMAND_ANY, .mode = COMMAND_ANY,
.jim_handler = jim_flash_list, .handler = handle_flash_list,
.help = "Returns a list of details about the flash banks.", .help = "Returns a list of details about the flash banks.",
.usage = "",
}, },
COMMAND_REGISTRATION_DONE COMMAND_REGISTRATION_DONE
}; };