#include "arm7_9_common.h"
-static int str9xpec_erase_area(struct flash_bank_s *bank, int first, int last);
-static int str9xpec_set_address(struct flash_bank_s *bank, uint8_t sector);
-static int str9xpec_write_options(struct flash_bank_s *bank);
+static int str9xpec_erase_area(struct flash_bank *bank, int first, int last);
+static int str9xpec_set_address(struct flash_bank *bank, uint8_t sector);
+static int str9xpec_write_options(struct flash_bank *bank);
int str9xpec_set_instr(struct jtag_tap *tap, uint32_t new_instr, tap_state_t end_state)
{
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;
return status;
}
-static int str9xpec_isc_enable(struct flash_bank_s *bank)
+static int str9xpec_isc_enable(struct flash_bank *bank)
{
uint8_t status;
struct jtag_tap *tap;
return ERROR_OK;
}
-static int str9xpec_isc_disable(struct flash_bank_s *bank)
+static int str9xpec_isc_disable(struct flash_bank *bank)
{
uint8_t status;
struct jtag_tap *tap;
return ERROR_OK;
}
-static int str9xpec_read_config(struct flash_bank_s *bank)
+static int str9xpec_read_config(struct flash_bank *bank)
{
struct scan_field field;
uint8_t status;
return status;
}
-static int str9xpec_build_block_list(struct flash_bank_s *bank)
+static int str9xpec_build_block_list(struct flash_bank *bank)
{
struct str9xpec_flash_controller *str9xpec_info = bank->driver_priv;
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_OK;
}
-static int str9xpec_blank_check(struct flash_bank_s *bank, int first, int last)
+static int str9xpec_blank_check(struct flash_bank *bank, int first, int last)
{
struct scan_field field;
uint8_t status;
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 ERROR_OK;
}
-static int str9xpec_protect_check(struct flash_bank_s *bank)
+static int str9xpec_protect_check(struct flash_bank *bank)
{
uint8_t status;
int i;
return ERROR_OK;
}
-static int str9xpec_erase_area(struct flash_bank_s *bank, int first, int last)
+static int str9xpec_erase_area(struct flash_bank *bank, int first, int last)
{
struct scan_field field;
uint8_t status;
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);
return status;
}
-static int str9xpec_erase(struct flash_bank_s *bank, int first, int last)
+static int str9xpec_erase(struct flash_bank *bank, int first, int last)
{
int status;
return ERROR_OK;
}
-static int str9xpec_lock_device(struct flash_bank_s *bank)
+static int str9xpec_lock_device(struct flash_bank *bank)
{
struct scan_field field;
uint8_t status;
return status;
}
-static int str9xpec_unlock_device(struct flash_bank_s *bank)
+static int str9xpec_unlock_device(struct flash_bank *bank)
{
uint8_t status;
return status;
}
-static int str9xpec_protect(struct flash_bank_s *bank, int set, int first, int last)
+static int str9xpec_protect(struct flash_bank *bank, int set, int first, int last)
{
uint8_t status;
int i;
return ERROR_OK;
}
-static int str9xpec_set_address(struct flash_bank_s *bank, uint8_t sector)
+static int str9xpec_set_address(struct flash_bank *bank, uint8_t sector)
{
struct jtag_tap *tap;
struct scan_field field;
return ERROR_OK;
}
-static int str9xpec_write(struct flash_bank_s *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
+static int str9xpec_write(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
{
struct str9xpec_flash_controller *str9xpec_info = bank->driver_priv;
uint32_t dwords_remaining = (count / 8);
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");
return ERROR_OK;
}
-static int str9xpec_probe(struct flash_bank_s *bank)
+static int str9xpec_probe(struct flash_bank *bank)
{
return ERROR_OK;
}
uint32_t idcode;
struct str9xpec_flash_controller *str9xpec_info = NULL;
- if (argc < 1)
+ if (CMD_ARGC < 1)
return ERROR_COMMAND_SYNTAX_ERROR;
- flash_bank_t *bank;
- int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank);
+ struct flash_bank *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);
return ERROR_OK;
}
-static int str9xpec_erase_check(struct flash_bank_s *bank)
+static int str9xpec_erase_check(struct flash_bank *bank)
{
return str9xpec_blank_check(bank, 0, bank->num_sectors - 1);
}
-static int str9xpec_info(struct flash_bank_s *bank, char *buf, int buf_size)
+static int str9xpec_info(struct flash_bank *bank, char *buf, int buf_size)
{
snprintf(buf, buf_size, "str9xpec flash driver info");
return ERROR_OK;
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;
}
- flash_bank_t *bank;
- int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank);
+ struct flash_bank *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;
}
-static int str9xpec_write_options(struct flash_bank_s *bank)
+static int str9xpec_write_options(struct flash_bank *bank)
{
struct scan_field field;
uint8_t status;
{
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;
}
- flash_bank_t *bank;
- int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank);
+ struct flash_bank *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;
}
- flash_bank_t *bank;
- int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank);
+ struct flash_bank *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;
}
- flash_bank_t *bank;
- int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank);
+ struct flash_bank *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;
}
- flash_bank_t *bank;
- int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank);
+ struct flash_bank *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;
}
- flash_bank_t *bank;
- int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank);
+ struct flash_bank *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;
}
- flash_bank_t *bank;
- int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank);
+ struct flash_bank *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;
}
- flash_bank_t *bank;
- int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank);
+ struct flash_bank *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;
}
- flash_bank_t *bank;
- int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank);
+ struct flash_bank *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;
}
- flash_bank_t *bank;
- int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank);
+ struct flash_bank *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)
+static int str9xpec_register_commands(struct command_context *cmd_ctx)
{
- command_t *str9xpec_cmd = register_command(cmd_ctx, NULL, "str9xpec",
+ struct command *str9xpec_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "str9xpec",
NULL, COMMAND_ANY, "str9xpec flash specific commands");
- register_command(cmd_ctx, str9xpec_cmd, "enable_turbo",
+ COMMAND_REGISTER(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",
+ COMMAND_REGISTER(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",
+ COMMAND_REGISTER(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",
+ COMMAND_REGISTER(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",
+ COMMAND_REGISTER(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",
+ COMMAND_REGISTER(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",
+ COMMAND_REGISTER(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",
+ COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "options_write",
str9xpec_handle_flash_options_write_command,
COMMAND_EXEC, "write str9xpec options");
- register_command(cmd_ctx, str9xpec_cmd, "lock",
+ COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "lock",
str9xpec_handle_flash_lock_command,
COMMAND_EXEC, "lock str9xpec device");
- register_command(cmd_ctx, str9xpec_cmd, "unlock",
+ COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "unlock",
str9xpec_handle_flash_unlock_command,
COMMAND_EXEC, "unlock str9xpec device");
- register_command(cmd_ctx, str9xpec_cmd, "part_id",
+ COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "part_id",
str9xpec_handle_part_id_command,
COMMAND_EXEC, "print part id of str9xpec flash bank <num>");