field.tap = tap;
field.num_bits = tap->ir_length;
- field.out_value = calloc(CEIL(field.num_bits, 8), 1);
+ field.out_value = calloc(DIV_ROUND_UP(field.num_bits, 8), 1);
buf_set_u32(field.out_value, 0, field.num_bits, new_instr);
field.in_value = NULL;
struct arm7_9_common *arm7_9 = NULL;
struct arm_jtag *jtag_info = NULL;
- if (argc < 6)
+ if (CMD_ARGC < 6)
{
LOG_WARNING("incomplete flash_bank str9x configuration");
return ERROR_FLASH_BANK_INVALID;
return ERROR_FLASH_OPERATION_FAILED;
}
- buffer = calloc(CEIL(64, 8), 1);
+ buffer = calloc(DIV_ROUND_UP(64, 8), 1);
LOG_DEBUG("blank check: first_bank: %i, last_bank: %i", first, last);
return ISC_STATUS_ERROR;
}
- buffer = calloc(CEIL(64, 8), 1);
+ buffer = calloc(DIV_ROUND_UP(64, 8), 1);
LOG_DEBUG("erase: first_bank: %i, last_bank: %i", first, last);
LOG_DEBUG("first_sector: %i, last_sector: %i", first_sector, last_sector);
- scanbuf = calloc(CEIL(64, 8), 1);
+ scanbuf = calloc(DIV_ROUND_UP(64, 8), 1);
LOG_DEBUG("ISC_PROGRAM");
uint32_t idcode;
struct str9xpec_flash_controller *str9xpec_info = NULL;
- if (argc < 1)
+ if (CMD_ARGC < 1)
return ERROR_COMMAND_SYNTAX_ERROR;
struct flash_bank *bank;
- int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank);
+ int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
if (ERROR_OK != retval)
return retval;
str9xpec_info = bank->driver_priv;
tap = str9xpec_info->tap;
- buffer = calloc(CEIL(32, 8), 1);
+ buffer = calloc(DIV_ROUND_UP(32, 8), 1);
str9xpec_set_instr(tap, ISC_IDCODE, TAP_IRPAUSE);
idcode = buf_get_u32(buffer, 0, 32);
- command_print(cmd_ctx, "str9xpec part id: 0x%8.8" PRIx32 "", idcode);
+ command_print(CMD_CTX, "str9xpec part id: 0x%8.8" PRIx32 "", idcode);
free(buffer);
uint8_t status;
struct str9xpec_flash_controller *str9xpec_info = NULL;
- if (argc < 1)
+ if (CMD_ARGC < 1)
{
- command_print(cmd_ctx, "str9xpec options_read <bank>");
+ command_print(CMD_CTX, "str9xpec options_read <bank>");
return ERROR_OK;
}
struct flash_bank *bank;
- int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank);
+ int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
if (ERROR_OK != retval)
return retval;
/* boot bank */
if (buf_get_u32(str9xpec_info->options, STR9XPEC_OPT_CSMAPBIT, 1))
- command_print(cmd_ctx, "CS Map: bank1");
+ command_print(CMD_CTX, "CS Map: bank1");
else
- command_print(cmd_ctx, "CS Map: bank0");
+ command_print(CMD_CTX, "CS Map: bank0");
/* OTP lock */
if (buf_get_u32(str9xpec_info->options, STR9XPEC_OPT_OTPBIT, 1))
- command_print(cmd_ctx, "OTP Lock: OTP Locked");
+ command_print(CMD_CTX, "OTP Lock: OTP Locked");
else
- command_print(cmd_ctx, "OTP Lock: OTP Unlocked");
+ command_print(CMD_CTX, "OTP Lock: OTP Unlocked");
/* LVD Threshold */
if (buf_get_u32(str9xpec_info->options, STR9XPEC_OPT_LVDTHRESBIT, 1))
- command_print(cmd_ctx, "LVD Threshold: 2.7v");
+ command_print(CMD_CTX, "LVD Threshold: 2.7v");
else
- command_print(cmd_ctx, "LVD Threshold: 2.4v");
+ command_print(CMD_CTX, "LVD Threshold: 2.4v");
/* LVD reset warning */
if (buf_get_u32(str9xpec_info->options, STR9XPEC_OPT_LVDWARNBIT, 1))
- command_print(cmd_ctx, "LVD Reset Warning: VDD or VDDQ Inputs");
+ command_print(CMD_CTX, "LVD Reset Warning: VDD or VDDQ Inputs");
else
- command_print(cmd_ctx, "LVD Reset Warning: VDD Input Only");
+ command_print(CMD_CTX, "LVD Reset Warning: VDD Input Only");
/* LVD reset select */
if (buf_get_u32(str9xpec_info->options, STR9XPEC_OPT_LVDSELBIT, 1))
- command_print(cmd_ctx, "LVD Reset Selection: VDD or VDDQ Inputs");
+ command_print(CMD_CTX, "LVD Reset Selection: VDD or VDDQ Inputs");
else
- command_print(cmd_ctx, "LVD Reset Selection: VDD Input Only");
+ command_print(CMD_CTX, "LVD Reset Selection: VDD Input Only");
return ERROR_OK;
}
{
uint8_t status;
- if (argc < 1)
+ if (CMD_ARGC < 1)
{
- command_print(cmd_ctx, "str9xpec options_write <bank>");
+ command_print(CMD_CTX, "str9xpec options_write <bank>");
return ERROR_OK;
}
struct flash_bank *bank;
- int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank);
+ int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
if (ERROR_OK != retval)
return retval;
{
struct str9xpec_flash_controller *str9xpec_info = NULL;
- if (argc < 2)
+ if (CMD_ARGC < 2)
{
- command_print(cmd_ctx, "str9xpec options_cmap <bank> <bank0 | bank1>");
+ command_print(CMD_CTX, "str9xpec options_cmap <bank> <bank0 | bank1>");
return ERROR_OK;
}
struct flash_bank *bank;
- int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank);
+ int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
if (ERROR_OK != retval)
return retval;
str9xpec_info = bank->driver_priv;
- if (strcmp(args[1], "bank1") == 0)
+ if (strcmp(CMD_ARGV[1], "bank1") == 0)
{
buf_set_u32(str9xpec_info->options, STR9XPEC_OPT_CSMAPBIT, 1, 1);
}
{
struct str9xpec_flash_controller *str9xpec_info = NULL;
- if (argc < 2)
+ if (CMD_ARGC < 2)
{
- command_print(cmd_ctx, "str9xpec options_lvdthd <bank> <2.4v | 2.7v>");
+ command_print(CMD_CTX, "str9xpec options_lvdthd <bank> <2.4v | 2.7v>");
return ERROR_OK;
}
struct flash_bank *bank;
- int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank);
+ int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
if (ERROR_OK != retval)
return retval;
str9xpec_info = bank->driver_priv;
- if (strcmp(args[1], "2.7v") == 0)
+ if (strcmp(CMD_ARGV[1], "2.7v") == 0)
{
buf_set_u32(str9xpec_info->options, STR9XPEC_OPT_LVDTHRESBIT, 1, 1);
}
{
struct str9xpec_flash_controller *str9xpec_info = NULL;
- if (argc < 2)
+ if (CMD_ARGC < 2)
{
- command_print(cmd_ctx, "str9xpec options_lvdsel <bank> <vdd | vdd_vddq>");
+ command_print(CMD_CTX, "str9xpec options_lvdsel <bank> <vdd | vdd_vddq>");
return ERROR_OK;
}
struct flash_bank *bank;
- int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank);
+ int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
if (ERROR_OK != retval)
return retval;
str9xpec_info = bank->driver_priv;
- if (strcmp(args[1], "vdd_vddq") == 0)
+ if (strcmp(CMD_ARGV[1], "vdd_vddq") == 0)
{
buf_set_u32(str9xpec_info->options, STR9XPEC_OPT_LVDSELBIT, 1, 1);
}
{
struct str9xpec_flash_controller *str9xpec_info = NULL;
- if (argc < 2)
+ if (CMD_ARGC < 2)
{
- command_print(cmd_ctx, "str9xpec options_lvdwarn <bank> <vdd | vdd_vddq>");
+ command_print(CMD_CTX, "str9xpec options_lvdwarn <bank> <vdd | vdd_vddq>");
return ERROR_OK;
}
struct flash_bank *bank;
- int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank);
+ int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
if (ERROR_OK != retval)
return retval;
str9xpec_info = bank->driver_priv;
- if (strcmp(args[1], "vdd_vddq") == 0)
+ if (strcmp(CMD_ARGV[1], "vdd_vddq") == 0)
{
buf_set_u32(str9xpec_info->options, STR9XPEC_OPT_LVDWARNBIT, 1, 1);
}
{
uint8_t status;
- if (argc < 1)
+ if (CMD_ARGC < 1)
{
- command_print(cmd_ctx, "str9xpec lock <bank>");
+ command_print(CMD_CTX, "str9xpec lock <bank>");
return ERROR_OK;
}
struct flash_bank *bank;
- int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank);
+ int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
if (ERROR_OK != retval)
return retval;
{
uint8_t status;
- if (argc < 1)
+ if (CMD_ARGC < 1)
{
- command_print(cmd_ctx, "str9xpec unlock <bank>");
+ command_print(CMD_CTX, "str9xpec unlock <bank>");
return ERROR_OK;
}
struct flash_bank *bank;
- int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank);
+ int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
if (ERROR_OK != retval)
return retval;
struct jtag_tap *tap2;
struct str9xpec_flash_controller *str9xpec_info = NULL;
- if (argc < 1)
+ if (CMD_ARGC < 1)
{
- command_print(cmd_ctx, "str9xpec enable_turbo <bank>");
+ command_print(CMD_CTX, "str9xpec enable_turbo <bank>");
return ERROR_OK;
}
struct flash_bank *bank;
- int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank);
+ int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
if (ERROR_OK != retval)
return retval;
if (tap1 == NULL)
{
/* things are *WRONG* */
- command_print(cmd_ctx,"**STR9FLASH** (tap1) invalid chain?");
+ command_print(CMD_CTX,"**STR9FLASH** (tap1) invalid chain?");
return ERROR_OK;
}
tap2 = tap1->next_tap;
if (tap2 == NULL)
{
/* things are *WRONG* */
- command_print(cmd_ctx,"**STR9FLASH** (tap2) invalid chain?");
+ command_print(CMD_CTX,"**STR9FLASH** (tap2) invalid chain?");
return ERROR_OK;
}
struct jtag_tap *tap;
struct str9xpec_flash_controller *str9xpec_info = NULL;
- if (argc < 1)
+ if (CMD_ARGC < 1)
{
- command_print(cmd_ctx, "str9xpec disable_turbo <bank>");
+ command_print(CMD_CTX, "str9xpec disable_turbo <bank>");
return ERROR_OK;
}
struct flash_bank *bank;
- int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank);
+ int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
if (ERROR_OK != retval)
return retval;
return ERROR_OK;
}
-static int str9xpec_register_commands(struct command_context_s *cmd_ctx)
-{
- command_t *str9xpec_cmd = register_command(cmd_ctx, NULL, "str9xpec",
- NULL, COMMAND_ANY, "str9xpec flash specific commands");
-
- register_command(cmd_ctx, str9xpec_cmd, "enable_turbo",
- str9xpec_handle_flash_enable_turbo_command,
- COMMAND_EXEC, "enable str9xpec turbo mode");
- register_command(cmd_ctx, str9xpec_cmd, "disable_turbo",
- str9xpec_handle_flash_disable_turbo_command,
- COMMAND_EXEC, "disable str9xpec turbo mode");
- register_command(cmd_ctx, str9xpec_cmd, "options_cmap",
- str9xpec_handle_flash_options_cmap_command,
- COMMAND_EXEC, "configure str9xpec boot sector");
- register_command(cmd_ctx, str9xpec_cmd, "options_lvdthd",
- str9xpec_handle_flash_options_lvdthd_command,
- COMMAND_EXEC, "configure str9xpec lvd threshold");
- register_command(cmd_ctx, str9xpec_cmd, "options_lvdsel",
- str9xpec_handle_flash_options_lvdsel_command,
- COMMAND_EXEC, "configure str9xpec lvd selection");
- register_command(cmd_ctx, str9xpec_cmd, "options_lvdwarn",
- str9xpec_handle_flash_options_lvdwarn_command,
- COMMAND_EXEC, "configure str9xpec lvd warning");
- register_command(cmd_ctx, str9xpec_cmd, "options_read",
- str9xpec_handle_flash_options_read_command,
- COMMAND_EXEC, "read str9xpec options");
- register_command(cmd_ctx, str9xpec_cmd, "options_write",
- str9xpec_handle_flash_options_write_command,
- COMMAND_EXEC, "write str9xpec options");
- register_command(cmd_ctx, str9xpec_cmd, "lock",
- str9xpec_handle_flash_lock_command,
- COMMAND_EXEC, "lock str9xpec device");
- register_command(cmd_ctx, str9xpec_cmd, "unlock",
- str9xpec_handle_flash_unlock_command,
- COMMAND_EXEC, "unlock str9xpec device");
- register_command(cmd_ctx, str9xpec_cmd, "part_id",
- str9xpec_handle_part_id_command,
- COMMAND_EXEC, "print part id of str9xpec flash bank <num>");
-
- return ERROR_OK;
-}
+static const struct command_registration str9xpec_config_command_handlers[] = {
+ {
+ .name = "enable_turbo",
+ .handler = str9xpec_handle_flash_enable_turbo_command,
+ .mode = COMMAND_EXEC,
+ .help = "enable str9xpec turbo mode",
+ },
+ {
+ .name = "disable_turbo",
+ .handler = str9xpec_handle_flash_disable_turbo_command,
+ .mode = COMMAND_EXEC,
+ .help = "disable str9xpec turbo mode",
+ },
+ {
+ .name = "options_cmap",
+ .handler = str9xpec_handle_flash_options_cmap_command,
+ .mode = COMMAND_EXEC,
+ .help = "configure str9xpec boot sector",
+ },
+ {
+ .name = "options_lvdthd",
+ .handler = str9xpec_handle_flash_options_lvdthd_command,
+ .mode = COMMAND_EXEC,
+ .help = "configure str9xpec lvd threshold",
+ },
+ {
+ .name = "options_lvdsel",
+ .handler = str9xpec_handle_flash_options_lvdsel_command,
+ .mode = COMMAND_EXEC,
+ .help = "configure str9xpec lvd selection",
+ },
+ {
+ .name = "options_lvdwarn",
+ .handler = str9xpec_handle_flash_options_lvdwarn_command,
+ .mode = COMMAND_EXEC,
+ .help = "configure str9xpec lvd warning",
+ },
+ {
+ .name = "options_read",
+ .handler = str9xpec_handle_flash_options_read_command,
+ .mode = COMMAND_EXEC,
+ .help = "read str9xpec options",
+ },
+ {
+ .name = "options_write",
+ .handler = str9xpec_handle_flash_options_write_command,
+ .mode = COMMAND_EXEC,
+ .help = "write str9xpec options",
+ },
+ {
+ .name = "lock",
+ .handler = str9xpec_handle_flash_lock_command,
+ .mode = COMMAND_EXEC,
+ .help = "lock str9xpec device",
+ },
+ {
+ .name = "unlock",
+ .handler = str9xpec_handle_flash_unlock_command,
+ .mode = COMMAND_EXEC,
+ .help = "unlock str9xpec device",
+ },
+ {
+ .name = "part_id",
+ .handler = str9xpec_handle_part_id_command,
+ .mode = COMMAND_EXEC,
+ .help = "print part id of str9xpec flash bank <num>",
+ },
+ COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration str9xpec_command_handlers[] = {
+ {
+ .name = "str9xpec",
+ .mode = COMMAND_ANY,
+ .help = "str9xpec flash command group",
+ .chain = str9xpec_config_command_handlers,
+ },
+ COMMAND_REGISTRATION_DONE
+};
struct flash_driver str9xpec_flash = {
.name = "str9xpec",
- .register_commands = &str9xpec_register_commands,
+ .commands = str9xpec_command_handlers,
.flash_bank_command = &str9xpec_flash_bank_command,
.erase = &str9xpec_erase,
.protect = &str9xpec_protect,