Commit 16b6b5e7 authored by Mathias K's avatar Mathias K Committed by Øyvind Harboe
Browse files

Change return value on error.



On wrong parameters a error is signalized to the calling function.

Change-Id: I484443fdb39938e20382edc9246d5ec546a5c960
Signed-off-by: default avatarMathias K <kesmtp@freenet.de>
Signed-off-by: default avatarØyvind Harboe <oyvind.harboe@zylin.com>
Reviewed-on: http://openocd.zylin.com/282


Tested-by: jenkins
Reviewed-by: default avatarØyvind Harboe <oyvindharboe@gmail.com>
parent 42cb62cf
......@@ -130,8 +130,7 @@ FLASH_BANK_COMMAND_HANDLER(stm32x_flash_bank_command)
if (CMD_ARGC < 6)
{
LOG_WARNING("incomplete flash_bank stm32x configuration");
return ERROR_FLASH_BANK_INVALID;
return ERROR_COMMAND_SYNTAX_ERROR;
}
stm32x_info = malloc(sizeof(struct stm32x_flash_bank));
......@@ -1329,8 +1328,7 @@ COMMAND_HANDLER(stm32x_handle_lock_command)
if (CMD_ARGC < 1)
{
command_print(CMD_CTX, "stm32x lock <bank>");
return ERROR_OK;
return ERROR_COMMAND_SYNTAX_ERROR;
}
struct flash_bank *bank;
......@@ -1378,8 +1376,7 @@ COMMAND_HANDLER(stm32x_handle_unlock_command)
if (CMD_ARGC < 1)
{
command_print(CMD_CTX, "stm32x unlock <bank>");
return ERROR_OK;
return ERROR_COMMAND_SYNTAX_ERROR;
}
struct flash_bank *bank;
......@@ -1426,8 +1423,7 @@ COMMAND_HANDLER(stm32x_handle_options_read_command)
if (CMD_ARGC < 1)
{
command_print(CMD_CTX, "stm32x options_read <bank>");
return ERROR_OK;
return ERROR_COMMAND_SYNTAX_ERROR;
}
struct flash_bank *bank;
......@@ -1496,9 +1492,7 @@ COMMAND_HANDLER(stm32x_handle_options_write_command)
if (CMD_ARGC < 4)
{
command_print(CMD_CTX, "stm32x options_write <bank> <SWWDG | HWWDG> "
"<RSTSTNDBY | NORSTSTNDBY> <RSTSTOP | NORSTSTOP> <BOOT0 | BOOT1>");
return ERROR_OK;
return ERROR_COMMAND_SYNTAX_ERROR;
}
struct flash_bank *bank;
......@@ -1631,8 +1625,7 @@ COMMAND_HANDLER(stm32x_handle_mass_erase_command)
if (CMD_ARGC < 1)
{
command_print(CMD_CTX, "stm32x mass_erase <bank>");
return ERROR_OK;
return ERROR_COMMAND_SYNTAX_ERROR;
}
struct flash_bank *bank;
......
......@@ -165,8 +165,7 @@ FLASH_BANK_COMMAND_HANDLER(stm32x_flash_bank_command)
if (CMD_ARGC < 6)
{
LOG_WARNING("incomplete flash_bank stm32x configuration");
return ERROR_FLASH_BANK_INVALID;
return ERROR_COMMAND_SYNTAX_ERROR;
}
stm32x_info = malloc(sizeof(struct stm32x_flash_bank));
......
......@@ -130,8 +130,7 @@ FLASH_BANK_COMMAND_HANDLER(stm32lx_flash_bank_command)
struct stm32lx_flash_bank *stm32lx_info;
if (CMD_ARGC < 6)
{
LOG_ERROR("incomplete flash_bank stm32lx configuration");
return ERROR_FLASH_BANK_INVALID;
return ERROR_COMMAND_SYNTAX_ERROR;
}
// Create the bank structure
......
......@@ -206,8 +206,7 @@ FLASH_BANK_COMMAND_HANDLER(stmsmi_flash_bank_command)
if (CMD_ARGC < 6)
{
LOG_WARNING("incomplete flash_bank stmsmi configuration");
return ERROR_FLASH_BANK_INVALID;
return ERROR_COMMAND_SYNTAX_ERROR;
}
stmsmi_info = malloc(sizeof(struct stmsmi_flash_bank));
......
......@@ -208,8 +208,7 @@ FLASH_BANK_COMMAND_HANDLER(str7x_flash_bank_command)
if (CMD_ARGC < 7)
{
LOG_WARNING("incomplete flash_bank str7x configuration");
return ERROR_FLASH_BANK_INVALID;
return ERROR_COMMAND_SYNTAX_ERROR;
}
str7x_info = malloc(sizeof(struct str7x_flash_bank));
......@@ -786,8 +785,7 @@ COMMAND_HANDLER(str7x_handle_disable_jtag_command)
if (CMD_ARGC < 1)
{
command_print(CMD_CTX, "str7x disable_jtag <bank>");
return ERROR_OK;
return ERROR_COMMAND_SYNTAX_ERROR;
}
struct flash_bank *bank;
......@@ -849,6 +847,7 @@ COMMAND_HANDLER(str7x_handle_disable_jtag_command)
static const struct command_registration str7x_exec_command_handlers[] = {
{
.name = "disable_jtag",
.usage = "<bank>",
.handler = str7x_handle_disable_jtag_command,
.mode = COMMAND_EXEC,
.help = "disable jtag access",
......
......@@ -158,8 +158,7 @@ FLASH_BANK_COMMAND_HANDLER(str9x_flash_bank_command)
if (CMD_ARGC < 6)
{
LOG_WARNING("incomplete flash_bank str9x configuration");
return ERROR_FLASH_BANK_INVALID;
return ERROR_COMMAND_SYNTAX_ERROR;
}
str9x_info = malloc(sizeof(struct str9x_flash_bank));
......
......@@ -292,8 +292,7 @@ FLASH_BANK_COMMAND_HANDLER(str9xpec_flash_bank_command)
if (CMD_ARGC < 6)
{
LOG_WARNING("incomplete flash_bank str9x configuration");
return ERROR_FLASH_BANK_INVALID;
return ERROR_COMMAND_SYNTAX_ERROR;
}
str9xpec_info = malloc(sizeof(struct str9xpec_flash_controller));
......@@ -825,8 +824,7 @@ COMMAND_HANDLER(str9xpec_handle_flash_options_read_command)
if (CMD_ARGC < 1)
{
command_print(CMD_CTX, "str9xpec options_read <bank>");
return ERROR_OK;
return ERROR_COMMAND_SYNTAX_ERROR;
}
struct flash_bank *bank;
......@@ -939,8 +937,7 @@ COMMAND_HANDLER(str9xpec_handle_flash_options_write_command)
if (CMD_ARGC < 1)
{
command_print(CMD_CTX, "str9xpec options_write <bank>");
return ERROR_OK;
return ERROR_COMMAND_SYNTAX_ERROR;
}
struct flash_bank *bank;
......@@ -966,8 +963,7 @@ COMMAND_HANDLER(str9xpec_handle_flash_options_cmap_command)
if (CMD_ARGC < 2)
{
command_print(CMD_CTX, "str9xpec options_cmap <bank> <bank0 | bank1>");
return ERROR_OK;
return ERROR_COMMAND_SYNTAX_ERROR;
}
struct flash_bank *bank;
......@@ -995,8 +991,7 @@ COMMAND_HANDLER(str9xpec_handle_flash_options_lvdthd_command)
if (CMD_ARGC < 2)
{
command_print(CMD_CTX, "str9xpec options_lvdthd <bank> <2.4v | 2.7v>");
return ERROR_OK;
return ERROR_COMMAND_SYNTAX_ERROR;
}
struct flash_bank *bank;
......@@ -1024,8 +1019,7 @@ COMMAND_HANDLER(str9xpec_handle_flash_options_lvdsel_command)
if (CMD_ARGC < 2)
{
command_print(CMD_CTX, "str9xpec options_lvdsel <bank> <vdd | vdd_vddq>");
return ERROR_OK;
return ERROR_COMMAND_SYNTAX_ERROR;
}
struct flash_bank *bank;
......@@ -1053,8 +1047,7 @@ COMMAND_HANDLER(str9xpec_handle_flash_options_lvdwarn_command)
if (CMD_ARGC < 2)
{
command_print(CMD_CTX, "str9xpec options_lvdwarn <bank> <vdd | vdd_vddq>");
return ERROR_OK;
return ERROR_COMMAND_SYNTAX_ERROR;
}
struct flash_bank *bank;
......@@ -1082,8 +1075,7 @@ COMMAND_HANDLER(str9xpec_handle_flash_lock_command)
if (CMD_ARGC < 1)
{
command_print(CMD_CTX, "str9xpec lock <bank>");
return ERROR_OK;
return ERROR_COMMAND_SYNTAX_ERROR;
}
struct flash_bank *bank;
......@@ -1105,8 +1097,7 @@ COMMAND_HANDLER(str9xpec_handle_flash_unlock_command)
if (CMD_ARGC < 1)
{
command_print(CMD_CTX, "str9xpec unlock <bank>");
return ERROR_OK;
return ERROR_COMMAND_SYNTAX_ERROR;
}
struct flash_bank *bank;
......@@ -1135,8 +1126,7 @@ COMMAND_HANDLER(str9xpec_handle_flash_enable_turbo_command)
if (CMD_ARGC < 1)
{
command_print(CMD_CTX, "str9xpec enable_turbo <bank>");
return ERROR_OK;
return ERROR_COMMAND_SYNTAX_ERROR;
}
struct flash_bank *bank;
......@@ -1182,8 +1172,7 @@ COMMAND_HANDLER(str9xpec_handle_flash_disable_turbo_command)
if (CMD_ARGC < 1)
{
command_print(CMD_CTX, "str9xpec disable_turbo <bank>");
return ERROR_OK;
return ERROR_COMMAND_SYNTAX_ERROR;
}
struct flash_bank *bank;
......@@ -1213,60 +1202,70 @@ COMMAND_HANDLER(str9xpec_handle_flash_disable_turbo_command)
static const struct command_registration str9xpec_config_command_handlers[] = {
{
.name = "enable_turbo",
.usage = "<bank>",
.handler = str9xpec_handle_flash_enable_turbo_command,
.mode = COMMAND_EXEC,
.help = "enable str9xpec turbo mode",
},
{
.name = "disable_turbo",
.usage = "<bank>",
.handler = str9xpec_handle_flash_disable_turbo_command,
.mode = COMMAND_EXEC,
.help = "disable str9xpec turbo mode",
},
{
.name = "options_cmap",
.usage = "<bank> <bank0 | bank1>",
.handler = str9xpec_handle_flash_options_cmap_command,
.mode = COMMAND_EXEC,
.help = "configure str9xpec boot sector",
},
{
.name = "options_lvdthd",
.usage = "<bank> <2.4v | 2.7v>",
.handler = str9xpec_handle_flash_options_lvdthd_command,
.mode = COMMAND_EXEC,
.help = "configure str9xpec lvd threshold",
},
{
.name = "options_lvdsel",
.usage = "<bank> <vdd | vdd_vddq>",
.handler = str9xpec_handle_flash_options_lvdsel_command,
.mode = COMMAND_EXEC,
.help = "configure str9xpec lvd selection",
},
{
.name = "options_lvdwarn",
.usage = "<bank> <vdd | vdd_vddq>",
.handler = str9xpec_handle_flash_options_lvdwarn_command,
.mode = COMMAND_EXEC,
.help = "configure str9xpec lvd warning",
},
{
.name = "options_read",
.usage = "<bank>",
.handler = str9xpec_handle_flash_options_read_command,
.mode = COMMAND_EXEC,
.help = "read str9xpec options",
},
{
.name = "options_write",
.usage = "<bank>",
.handler = str9xpec_handle_flash_options_write_command,
.mode = COMMAND_EXEC,
.help = "write str9xpec options",
},
{
.name = "lock",
.usage = "<bank>",
.handler = str9xpec_handle_flash_lock_command,
.mode = COMMAND_EXEC,
.help = "lock str9xpec device",
},
{
.name = "unlock",
.usage = "<bank>",
.handler = str9xpec_handle_flash_unlock_command,
.mode = COMMAND_EXEC,
.help = "unlock str9xpec device",
......
......@@ -313,7 +313,6 @@ COMMAND_HANDLER(tms470_handle_flash_keyset_command)
{
if (CMD_ARGC > 4)
{
command_print(CMD_CTX, "tms470 flash_keyset <key0> <key1> <key2> <key3>");
return ERROR_COMMAND_SYNTAX_ERROR;
}
else if (CMD_ARGC == 4)
......@@ -377,7 +376,6 @@ COMMAND_HANDLER(tms470_handle_osc_megahertz_command)
{
if (CMD_ARGC > 1)
{
command_print(CMD_CTX, "tms470 osc_megahertz <MHz>");
return ERROR_COMMAND_SYNTAX_ERROR;
}
else if (CMD_ARGC == 1)
......@@ -406,7 +404,6 @@ COMMAND_HANDLER(tms470_handle_plldis_command)
{
if (CMD_ARGC > 1)
{
command_print(CMD_CTX, "tms470 plldis <0 | 1>");
return ERROR_COMMAND_SYNTAX_ERROR;
}
else if (CMD_ARGC == 1)
......@@ -840,18 +837,21 @@ static int tms470_erase_sector(struct flash_bank *bank, int sector)
static const struct command_registration tms470_any_command_handlers[] = {
{
.name = "flash_keyset",
.usage = "<key0> <key1> <key2> <key3>",
.handler = tms470_handle_flash_keyset_command,
.mode = COMMAND_ANY,
.help = "tms470 flash_keyset <key0> <key1> <key2> <key3>",
},
{
.name = "osc_megahertz",
.usage = "<MHz>",
.handler = tms470_handle_osc_megahertz_command,
.mode = COMMAND_ANY,
.help = "tms470 osc_megahertz <MHz>",
},
{
.name = "plldis",
.usage = "<0 | 1>",
.handler = tms470_handle_plldis_command,
.mode = COMMAND_ANY,
.help = "tms470 plldis <0/1>",
......
......@@ -55,8 +55,7 @@ FLASH_BANK_COMMAND_HANDLER(virtual_flash_bank_command)
{
if (CMD_ARGC < 7)
{
LOG_WARNING("incomplete flash_bank virtual configuration");
return ERROR_FLASH_OPERATION_FAILED;
return ERROR_COMMAND_SYNTAX_ERROR;
}
/* get the master flash bank */
......
......@@ -26,7 +26,6 @@ COMMAND_HANDLER(handle_foo_command)
{
if (CMD_ARGC < 1 || CMD_ARGC > 2)
{
LOG_ERROR("%s: incorrect number of arguments", CMD_NAME);
return ERROR_COMMAND_SYNTAX_ERROR;
}
......@@ -82,7 +81,6 @@ static COMMAND_HELPER(handle_hello_args, const char **sep, const char **name)
{
if (CMD_ARGC > 1)
{
LOG_ERROR("%s: too many arguments", CMD_NAME);
return ERROR_COMMAND_SYNTAX_ERROR;
}
if (1 == CMD_ARGC)
......
......@@ -117,7 +117,6 @@ COMMAND_HANDLER(handle_cat_command)
{
if (CMD_ARGC != 1)
{
command_print(CMD_CTX, "cat <filename>");
return ERROR_COMMAND_SYNTAX_ERROR;
}
......@@ -143,7 +142,6 @@ COMMAND_HANDLER(handle_trunc_command)
{
if (CMD_ARGC != 1)
{
command_print(CMD_CTX, "trunc <filename>");
return ERROR_COMMAND_SYNTAX_ERROR;
}
......@@ -162,7 +160,6 @@ COMMAND_HANDLER(handle_meminfo_command)
if (CMD_ARGC != 0)
{
command_print(CMD_CTX, "meminfo");
return ERROR_COMMAND_SYNTAX_ERROR;
}
......@@ -184,8 +181,6 @@ COMMAND_HANDLER(handle_append_command)
{
if (CMD_ARGC < 1)
{
command_print(CMD_CTX,
"append <filename> [<string1>, [<string2>, ...]]");
return ERROR_COMMAND_SYNTAX_ERROR;
}
......@@ -644,7 +639,7 @@ static const struct command_registration ioutil_command_handlers[] = {
.handler = handle_append_command,
.mode = COMMAND_ANY,
.help = "append a variable number of strings to a file",
.usage= "file_name [string ...]",
.usage = "file_name [<string1>, [<string2>, ...]]",
},
{
.name = "meminfo",
......
......@@ -175,7 +175,7 @@ static int at91rm9200_speed(int speed)
COMMAND_HANDLER(at91rm9200_handle_device_command)
{
if (CMD_ARGC == 0)
return ERROR_OK;
return ERROR_COMMAND_SYNTAX_ERROR;
/* only if the device name wasn't overwritten by cmdline */
if (at91rm9200_device == 0)
......
......@@ -280,8 +280,7 @@ COMMAND_HANDLER(buspirate_handle_adc_command)
COMMAND_HANDLER(buspirate_handle_vreg_command)
{
if (CMD_ARGC < 1) {
LOG_ERROR("usage: buspirate_vreg <1|0>");
return ERROR_OK;
return ERROR_COMMAND_SYNTAX_ERROR;
}
if (atoi(CMD_ARGV[0]) == 1)
......@@ -298,8 +297,7 @@ COMMAND_HANDLER(buspirate_handle_vreg_command)
COMMAND_HANDLER(buspirate_handle_pullup_command)
{
if (CMD_ARGC < 1) {
LOG_ERROR("usage: buspirate_pullup <1|0>");
return ERROR_OK;
return ERROR_COMMAND_SYNTAX_ERROR;
}
if (atoi(CMD_ARGV[0]) == 1)
......@@ -316,8 +314,7 @@ COMMAND_HANDLER(buspirate_handle_pullup_command)
COMMAND_HANDLER(buspirate_handle_led_command)
{
if (CMD_ARGC < 1) {
LOG_ERROR("usage: buspirate_led <1|0>");
return ERROR_OK;
return ERROR_COMMAND_SYNTAX_ERROR;
}
if (atoi(CMD_ARGV[0]) == 1) {
......@@ -339,8 +336,7 @@ COMMAND_HANDLER(buspirate_handle_led_command)
COMMAND_HANDLER(buspirate_handle_mode_command)
{
if (CMD_ARGC < 1) {
LOG_ERROR("usage: buspirate_mode <normal|open-drain>");
return ERROR_OK;
return ERROR_COMMAND_SYNTAX_ERROR;
}
if (CMD_ARGV[0][0] == 'n')
......@@ -357,8 +353,7 @@ COMMAND_HANDLER(buspirate_handle_mode_command)
COMMAND_HANDLER(buspirate_handle_speed_command)
{
if (CMD_ARGC < 1) {
LOG_ERROR("usage: buspirate_speed <normal|fast>");
return ERROR_OK;
return ERROR_COMMAND_SYNTAX_ERROR;
}
if (CMD_ARGV[0][0] == 'n')
......@@ -375,8 +370,7 @@ COMMAND_HANDLER(buspirate_handle_speed_command)
COMMAND_HANDLER(buspirate_handle_port_command)
{
if (CMD_ARGC < 1) {
LOG_ERROR("usage: buspirate_port /dev/ttyUSB0");
return ERROR_OK;
return ERROR_COMMAND_SYNTAX_ERROR;
}
if (buspirate_port == NULL)
......@@ -395,36 +389,42 @@ static const struct command_registration buspirate_command_handlers[] = {
},
{
.name = "buspirate_vreg",
.usage = "<1|0>",
.handler = &buspirate_handle_vreg_command,
.mode = COMMAND_CONFIG,
.help = "changes the state of voltage regulators",
},
{
.name = "buspirate_pullup",
.usage = "<1|0>",
.handler = &buspirate_handle_pullup_command,
.mode = COMMAND_CONFIG,
.help = "changes the state of pullup",
},
{
.name = "buspirate_led",
.usage = "<1|0>",
.handler = &buspirate_handle_led_command,
.mode = COMMAND_EXEC,
.help = "changes the state of led",
},
{
.name = "buspirate_speed",
.usage = "<normal|fast>",
.handler = &buspirate_handle_speed_command,
.mode = COMMAND_CONFIG,
.help = "speed of the interface",
},
{
.name = "buspirate_mode",
.usage = "<normal|open-drain>",
.handler = &buspirate_handle_mode_command,
.mode = COMMAND_CONFIG,
.help = "pin mode of the interface",
},
{
.name = "buspirate_port",
.usage = "/dev/ttyUSB0",
.handler = &buspirate_handle_port_command,
.mode = COMMAND_CONFIG,
.help = "name of the serial port to open",
......
......@@ -3431,7 +3431,7 @@ COMMAND_HANDLER(ft2232_handle_serial_command)
}
else
{
LOG_ERROR("expected exactly one argument to ft2232_serial <serial-number>");
return ERROR_COMMAND_SYNTAX_ERROR;
}
return ERROR_OK;
......@@ -3440,8 +3440,7 @@ COMMAND_HANDLER(ft2232_handle_serial_command)
COMMAND_HANDLER(ft2232_handle_layout_command)
{
if (CMD_ARGC != 1) {
LOG_ERROR("Need exactly one argument to ft2232_layout");
return ERROR_FAIL;
return ERROR_COMMAND_SYNTAX_ERROR;
}
if (layout) {
......@@ -3504,7 +3503,7 @@ COMMAND_HANDLER(ft2232_handle_latency_command)
}
else
{
LOG_ERROR("expected exactly one argument to ft2232_latency <ms>");
return ERROR_COMMAND_SYNTAX_ERROR;
}
return ERROR_OK;
......
......@@ -449,8 +449,7 @@ COMMAND_HANDLER(parport_handle_write_on_exit_command)
{
if (CMD_ARGC != 1)
{
command_print(CMD_CTX, "usage: parport_write_on_exit <on | off>");
return ERROR_OK;
return ERROR_COMMAND_SYNTAX_ERROR;
}
COMMAND_PARSE_ON_OFF(CMD_ARGV[0], parport_exit);
......
......@@ -740,7 +740,7 @@ COMMAND_HANDLER(presto_handle_serial_command)
}
else
{
LOG_ERROR("expected exactly one argument to presto_serial <serial-number>");
return ERROR_COMMAND_SYNTAX_ERROR;
}
return ERROR_OK;
......
......@@ -2320,10 +2320,9 @@ COMMAND_HANDLER(ulink_download_firmware_handler)
{
int ret;
if (CMD_ARGC != 1) {
LOG_ERROR("Need exactly one argument to ulink_download_firmware");
return ERROR_FAIL;
}
if (CMD_ARGC != 1)
return ERROR_COMMAND_SYNTAX_ERROR;
LOG_INFO("Downloading ULINK firmware image %s", CMD_ARGV[0]);
......
......@@ -472,9 +472,7 @@ static void vsllink_reset(int trst, int srst)
COMMAND_HANDLER(vsllink_handle_usb_vid_command)
{
if (CMD_ARGC != 1) {
LOG_ERROR("parameter error, "
"should be one parameter for VID");
return ERROR_OK;
return ERROR_COMMAND_SYNTAX_ERROR;
}
COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0],
......@@ -485,9 +483,7 @@ COMMAND_HANDLER(vsllink_handle_usb_vid_command)
COMMAND_HANDLER(vsllink_handle_usb_pid_command)
{
if (CMD_ARGC != 1) {
LOG_ERROR("parameter error, "
"should be one parameter for PID");
return ERROR_OK;
return ERROR_COMMAND_SYNTAX_ERROR;
}
COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0],
versaloon_interface.usb_setting.pid);
......@@ -497,9 +493,7 @@ COMMAND_HANDLER(vsllink_handle_usb_pid_command)
COMMAND_HANDLER(vsllink_handle_usb_bulkin_command)
{
if (CMD_ARGC != 1) {
LOG_ERROR("parameter error, "
"should be one parameter for BULKIN endpoint");
return ERROR_OK;
return ERROR_COMMAND_SYNTAX_ERROR;
}
COMMAND_PARSE_NUMBER(u8, CMD_ARGV[0],
......@@ -513,9 +507,7 @@ COMMAND_HANDLER(vsllink_handle_usb_bulkin_command)
COMMAND_HANDLER(vsllink_handle_usb_bulkout_command)
{
if (CMD_ARGC != 1) {
LOG_ERROR("parameter error, "
"should be one parameter for BULKOUT endpoint");
return ERROR_OK;