20 #define ISC_IDCODE 0xFE
21 #define ISC_MFG_READ 0x4C
22 #define ISC_CONFIGURATION 0x07
23 #define ISC_ENABLE 0x0C
24 #define ISC_DISABLE 0x0F
26 #define ISC_ADDRESS_SHIFT 0x11
27 #define ISC_CLR_STATUS 0x13
28 #define ISC_PROGRAM 0x20
29 #define ISC_PROGRAM_SECURITY 0x22
30 #define ISC_PROGRAM_UC 0x23
31 #define ISC_ERASE 0x30
33 #define ISC_BLANK_CHECK 0x60
37 #define ISC_STATUS_SECURITY 0x40
38 #define ISC_STATUS_INT_ERROR 0x30
39 #define ISC_STATUS_MODE 0x08
40 #define ISC_STATUS_BUSY 0x04
41 #define ISC_STATUS_ERROR 0x03
45 #define STR9XPEC_OPT_CSMAPBIT 48
46 #define STR9XPEC_OPT_LVDTHRESBIT 49
47 #define STR9XPEC_OPT_LVDSELBIT 50
48 #define STR9XPEC_OPT_LVDWARNBIT 51
49 #define STR9XPEC_OPT_OTPBIT 63
112 LOG_INFO(
"Device Security Bit Set");
203 unsigned int num_sectors;
204 int b0_sectors = 0, b1_sectors = 0;
206 int b1_size = 0x2000;
208 switch (
bank->size) {
229 LOG_ERROR(
"BUG: unknown bank->size encountered");
233 num_sectors = b0_sectors + b1_sectors;
235 bank->num_sectors = num_sectors;
237 str9xpec_info->
sector_bits = malloc(
sizeof(uint32_t) * num_sectors);
241 for (i = 0; i < b0_sectors; i++) {
243 bank->sectors[num_sectors].size = 0x10000;
245 bank->sectors[num_sectors].is_erased = -1;
246 bank->sectors[num_sectors].is_protected = 1;
250 for (i = 0; i < b1_sectors; i++) {
252 bank->sectors[num_sectors].size = b1_size;
254 bank->sectors[num_sectors].is_erased = -1;
255 bank->sectors[num_sectors].is_protected = 1;
256 str9xpec_info->
sector_bits[num_sectors++] = i + 32;
275 bank->driver_priv = str9xpec_info;
316 LOG_DEBUG(
"blank check: first_bank: %u, last_bank: %u", first, last);
318 for (
unsigned int i = first; i <= last; i++)
341 for (
unsigned int i = first; i <= last; i++) {
343 bank->sectors[i].is_erased = 0;
345 bank->sectors[i].is_erased = 1;
365 for (
unsigned int i = 0; i <
bank->num_sectors; i++) {
367 bank->sectors[i].is_protected = 1;
369 bank->sectors[i].is_protected = 0;
397 LOG_DEBUG(
"erase: first_bank: %u, last_bank: %u", first, last);
402 for (
unsigned int i = 0; i < 64; i++)
404 }
else if (last == 0xFE)
407 for (
unsigned int i = first; i <= last; i++)
456 str9xpec_info =
bank->driver_priv;
498 unsigned int first,
unsigned int last)
509 LOG_DEBUG(
"protect: first_bank: %u, last_bank: %u", first, last);
520 for (
unsigned int i = first; i <= last; i++) {
560 uint32_t dwords_remaining = (
count / 8);
561 uint32_t bytes_remaining = (
count & 0x00000007);
562 uint32_t bytes_written = 0;
564 uint32_t check_address =
offset;
568 unsigned int first_sector = 0;
569 unsigned int last_sector = 0;
571 tap = str9xpec_info->
tap;
584 for (
unsigned int i = 0; i <
bank->num_sectors; i++) {
585 uint32_t sec_start =
bank->sectors[i].offset;
586 uint32_t sec_end = sec_start +
bank->sectors[i].size;
589 if ((check_address >= sec_start) && (check_address < sec_end)) {
594 check_address = sec_end;
607 LOG_DEBUG(
"first_sector: %i, last_sector: %i", first_sector, last_sector);
613 for (
unsigned int i = first_sector; i <= last_sector; i++) {
616 dwords_remaining = dwords_remaining < (
bank->sectors[i].size/8)
617 ? dwords_remaining : (
bank->sectors[i].size/8);
619 while (dwords_remaining > 0) {
656 if (bytes_remaining) {
657 uint8_t last_dword[8] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
660 memcpy(last_dword,
buffer+bytes_written, bytes_remaining);
722 str9xpec_info =
bank->driver_priv;
723 tap = str9xpec_info->
tap;
763 str9xpec_info =
bank->driver_priv;
810 str9xpec_info =
bank->driver_priv;
878 "INFO: a reset or power cycle is required "
879 "for the new settings to take effect.");
896 str9xpec_info =
bank->driver_priv;
898 if (strcmp(
CMD_ARGV[1],
"bank1") == 0)
918 str9xpec_info =
bank->driver_priv;
920 if (strcmp(
CMD_ARGV[1],
"2.7v") == 0)
940 str9xpec_info =
bank->driver_priv;
942 if (strcmp(
CMD_ARGV[1],
"vdd_vddq") == 0)
962 str9xpec_info =
bank->driver_priv;
964 if (strcmp(
CMD_ARGV[1],
"vdd_vddq") == 0)
1010 "INFO: a reset or power cycle is required "
1011 "for the new settings to take effect.");
1031 str9xpec_info =
bank->driver_priv;
1034 tap0 = str9xpec_info->
tap;
1078 str9xpec_info =
bank->driver_priv;
1079 tap = str9xpec_info->
tap;
1098 .
name =
"enable_turbo",
1100 .handler = str9xpec_handle_flash_enable_turbo_command,
1102 .help =
"enable str9xpec turbo mode",
1105 .name =
"disable_turbo",
1107 .handler = str9xpec_handle_flash_disable_turbo_command,
1109 .help =
"disable str9xpec turbo mode",
1112 .name =
"options_cmap",
1113 .usage =
"<bank> <bank0 | bank1>",
1114 .handler = str9xpec_handle_flash_options_cmap_command,
1116 .help =
"configure str9xpec boot sector",
1119 .name =
"options_lvdthd",
1120 .usage =
"<bank> <2.4v | 2.7v>",
1121 .handler = str9xpec_handle_flash_options_lvdthd_command,
1123 .help =
"configure str9xpec lvd threshold",
1126 .name =
"options_lvdsel",
1127 .usage =
"<bank> <vdd | vdd_vddq>",
1128 .handler = str9xpec_handle_flash_options_lvdsel_command,
1130 .help =
"configure str9xpec lvd selection",
1133 .name =
"options_lvdwarn",
1134 .usage =
"<bank> <vdd | vdd_vddq>",
1135 .handler = str9xpec_handle_flash_options_lvdwarn_command,
1137 .help =
"configure str9xpec lvd warning",
1140 .name =
"options_read",
1142 .handler = str9xpec_handle_flash_options_read_command,
1144 .help =
"read str9xpec options",
1147 .name =
"options_write",
1149 .handler = str9xpec_handle_flash_options_write_command,
1151 .help =
"write str9xpec options",
1156 .handler = str9xpec_handle_flash_lock_command,
1158 .help =
"lock str9xpec device",
1163 .handler = str9xpec_handle_flash_unlock_command,
1165 .help =
"unlock str9xpec device",
1170 .handler = str9xpec_handle_part_id_command,
1172 .help =
"print part id of str9xpec flash bank",
1181 .help =
"str9xpec flash command group",
1191 .flash_bank_command = str9xpec_flash_bank_command,
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned first, unsigned num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
static void buf_set_u32(uint8_t *_buffer, unsigned first, unsigned num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
void command_print(struct command_invocation *cmd, const char *format,...)
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
#define CALL_COMMAND_HANDLER(name, extra ...)
Use this to macro to call a command helper (or a nested handler).
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
#define ERROR_COMMAND_SYNTAX_ERROR
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
#define ERROR_FLASH_OPERATION_FAILED
#define ERROR_FLASH_DST_BREAKS_ALIGNMENT
#define ERROR_FLASH_DST_OUT_OF_BANK
int default_flash_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
Provides default read implementation for flash memory.
void default_flash_free_driver_priv(struct flash_bank *bank)
Deallocates bank->driver_priv.
int jtag_execute_queue(void)
For software FIFO implementations, the queued commands can be executed during this call or earlier.
struct jtag_tap * jtag_tap_by_position(unsigned n)
void jtag_add_tlr(void)
Run a TAP_RESET reset where the end state is TAP_RESET, regardless of the start state.
void jtag_add_sleep(uint32_t us)
void jtag_add_ir_scan(struct jtag_tap *active, struct scan_field *in_fields, tap_state_t state)
Generate an IR SCAN with a list of scan fields with one entry for each enabled TAP.
void jtag_add_dr_scan(struct jtag_tap *active, int in_num_fields, const struct scan_field *in_fields, tap_state_t state)
Generate a DR SCAN using the fields passed to the function.
enum tap_state tap_state_t
Defines JTAG Test Access Port states.
void alive_sleep(uint64_t ms)
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
static int str9xpec_unlock_device(struct flash_bank *bank)
static int str9xpec_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
static int str9xpec_protect_check(struct flash_bank *bank)
static int str9xpec_set_instr(struct jtag_tap *tap, uint32_t new_instr, tap_state_t end_state)
#define STR9XPEC_OPT_LVDWARNBIT
#define ISC_PROGRAM_SECURITY
static int str9xpec_build_block_list(struct flash_bank *bank)
static int str9xpec_erase_check(struct flash_bank *bank)
static const struct command_registration str9xpec_command_handlers[]
const struct flash_driver str9xpec_flash
static int str9xpec_blank_check(struct flash_bank *bank, unsigned int first, unsigned int last)
#define ISC_CONFIGURATION
static int str9xpec_erase_area(struct flash_bank *bank, unsigned int first, unsigned int last)
COMMAND_HANDLER(str9xpec_handle_part_id_command)
static const struct command_registration str9xpec_config_command_handlers[]
#define STR9XPEC_OPT_CSMAPBIT
#define STR9XPEC_OPT_OTPBIT
static int str9xpec_isc_disable(struct flash_bank *bank)
static int str9xpec_isc_enable(struct flash_bank *bank)
#define STR9XPEC_OPT_LVDSELBIT
@ STR9XPEC_INVALID_COMMAND
static int str9xpec_read_config(struct flash_bank *bank)
static int str9xpec_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
static int str9xpec_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
#define STR9XPEC_OPT_LVDTHRESBIT
#define ISC_STATUS_SECURITY
FLASH_BANK_COMMAND_HANDLER(str9xpec_flash_bank_command)
static int str9xpec_lock_device(struct flash_bank *bank)
static uint8_t str9xpec_isc_status(struct jtag_tap *tap)
#define ISC_ADDRESS_SHIFT
static int str9xpec_set_address(struct flash_bank *bank, uint8_t sector)
static int str9xpec_probe(struct flash_bank *bank)
static int str9xpec_write_options(struct flash_bank *bank)
Structure for items that are common between both ARM7 and ARM9 targets.
struct arm_jtag jtag_info
JTAG information for target.
Represents a generic ARM core, with standard application registers.
Provides details of a flash bank, available either on-chip or through a major interface.
Provides the implementation-independent structure that defines all of the callbacks required by OpenO...
const char * name
Gives a human-readable name of this flash driver, This field is used to select and initialize the dri...
Describes the geometry and status of a single flash sector within a flash bank.
uint8_t * cur_instr
current instruction
int ir_length
size of instruction register
bool enabled
Is this TAP currently enabled?
struct jtag_tap * next_tap
uint32_t idcode
device identification code
This structure defines a single scan field in the scan.
int num_bits
The number of bits this field specifies.
uint8_t * in_value
A pointer to a 32-bit memory location for data scanned out.
const uint8_t * out_value
A pointer to value to be scanned into the device.
#define ERROR_TARGET_INVALID
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.