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");
200 unsigned int num_sectors;
201 int b0_sectors = 0, b1_sectors = 0;
203 int b1_size = 0x2000;
205 switch (
bank->size) {
226 LOG_ERROR(
"BUG: unknown bank->size encountered");
230 num_sectors = b0_sectors + b1_sectors;
232 bank->num_sectors = num_sectors;
234 str9xpec_info->
sector_bits = malloc(
sizeof(uint32_t) * num_sectors);
238 for (i = 0; i < b0_sectors; i++) {
240 bank->sectors[num_sectors].size = 0x10000;
242 bank->sectors[num_sectors].is_erased = -1;
243 bank->sectors[num_sectors].is_protected = 1;
247 for (i = 0; i < b1_sectors; i++) {
249 bank->sectors[num_sectors].size = b1_size;
251 bank->sectors[num_sectors].is_erased = -1;
252 bank->sectors[num_sectors].is_protected = 1;
253 str9xpec_info->
sector_bits[num_sectors++] = i + 32;
272 bank->driver_priv = str9xpec_info;
287 free(
bank->driver_priv);
317 LOG_DEBUG(
"blank check: first_bank: %u, last_bank: %u", first, last);
319 for (
unsigned int i = first; i <= last; i++)
342 for (
unsigned int i = first; i <= last; i++) {
344 bank->sectors[i].is_erased = 0;
346 bank->sectors[i].is_erased = 1;
366 for (
unsigned int i = 0; i <
bank->num_sectors; i++) {
368 bank->sectors[i].is_protected = 1;
370 bank->sectors[i].is_protected = 0;
398 LOG_DEBUG(
"erase: first_bank: %u, last_bank: %u", first, last);
403 for (
unsigned int i = 0; i < 64; i++)
405 }
else if (last == 0xFE)
408 for (
unsigned int i = first; i <= last; i++)
457 str9xpec_info =
bank->driver_priv;
495 unsigned int first,
unsigned int last)
506 LOG_DEBUG(
"protect: first_bank: %u, last_bank: %u", first, last);
517 for (
unsigned int i = first; i <= last; i++) {
557 uint32_t dwords_remaining = (
count / 8);
558 uint32_t bytes_remaining = (
count & 0x00000007);
559 uint32_t bytes_written = 0;
561 uint32_t check_address =
offset;
565 unsigned int first_sector = 0;
566 unsigned int last_sector = 0;
568 tap = str9xpec_info->
tap;
581 for (
unsigned int i = 0; i <
bank->num_sectors; i++) {
582 uint32_t sec_start =
bank->sectors[i].offset;
583 uint32_t sec_end = sec_start +
bank->sectors[i].size;
586 if ((check_address >= sec_start) && (check_address < sec_end)) {
591 check_address = sec_end;
604 LOG_DEBUG(
"first_sector: %i, last_sector: %i", first_sector, last_sector);
610 for (
unsigned int i = first_sector; i <= last_sector; i++) {
613 dwords_remaining = dwords_remaining < (
bank->sectors[i].size/8)
614 ? dwords_remaining : (
bank->sectors[i].size/8);
616 while (dwords_remaining > 0) {
653 if (bytes_remaining) {
654 uint8_t last_dword[8] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
657 memcpy(last_dword,
buffer+bytes_written, bytes_remaining);
719 str9xpec_info =
bank->driver_priv;
720 tap = str9xpec_info->
tap;
760 str9xpec_info =
bank->driver_priv;
807 str9xpec_info =
bank->driver_priv;
875 "INFO: a reset or power cycle is required "
876 "for the new settings to take effect.");
893 str9xpec_info =
bank->driver_priv;
895 if (strcmp(
CMD_ARGV[1],
"bank1") == 0)
915 str9xpec_info =
bank->driver_priv;
917 if (strcmp(
CMD_ARGV[1],
"2.7v") == 0)
937 str9xpec_info =
bank->driver_priv;
939 if (strcmp(
CMD_ARGV[1],
"vdd_vddq") == 0)
959 str9xpec_info =
bank->driver_priv;
961 if (strcmp(
CMD_ARGV[1],
"vdd_vddq") == 0)
1007 "INFO: a reset or power cycle is required "
1008 "for the new settings to take effect.");
1028 str9xpec_info =
bank->driver_priv;
1031 tap0 = str9xpec_info->
tap;
1075 str9xpec_info =
bank->driver_priv;
1076 tap = str9xpec_info->
tap;
1095 .
name =
"enable_turbo",
1097 .handler = str9xpec_handle_flash_enable_turbo_command,
1099 .help =
"enable str9xpec turbo mode",
1102 .name =
"disable_turbo",
1104 .handler = str9xpec_handle_flash_disable_turbo_command,
1106 .help =
"disable str9xpec turbo mode",
1109 .name =
"options_cmap",
1110 .usage =
"<bank> <bank0 | bank1>",
1111 .handler = str9xpec_handle_flash_options_cmap_command,
1113 .help =
"configure str9xpec boot sector",
1116 .name =
"options_lvdthd",
1117 .usage =
"<bank> <2.4v | 2.7v>",
1118 .handler = str9xpec_handle_flash_options_lvdthd_command,
1120 .help =
"configure str9xpec lvd threshold",
1123 .name =
"options_lvdsel",
1124 .usage =
"<bank> <vdd | vdd_vddq>",
1125 .handler = str9xpec_handle_flash_options_lvdsel_command,
1127 .help =
"configure str9xpec lvd selection",
1130 .name =
"options_lvdwarn",
1131 .usage =
"<bank> <vdd | vdd_vddq>",
1132 .handler = str9xpec_handle_flash_options_lvdwarn_command,
1134 .help =
"configure str9xpec lvd warning",
1137 .name =
"options_read",
1139 .handler = str9xpec_handle_flash_options_read_command,
1141 .help =
"read str9xpec options",
1144 .name =
"options_write",
1146 .handler = str9xpec_handle_flash_options_write_command,
1148 .help =
"write str9xpec options",
1153 .handler = str9xpec_handle_flash_lock_command,
1155 .help =
"lock str9xpec device",
1160 .handler = str9xpec_handle_flash_unlock_command,
1162 .help =
"unlock str9xpec device",
1167 .handler = str9xpec_handle_part_id_command,
1169 .help =
"print part id of str9xpec flash bank",
1178 .help =
"str9xpec flash command group",
1188 .flash_bank_command = str9xpec_flash_bank_command,
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned int first, unsigned int 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 int first, unsigned int 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.
uint64_t buffer
Pointer to data buffer to send over SPI.
#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.
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_dr_scan(struct jtag_tap *active, int in_num_fields, const struct scan_field *in_fields, enum tap_state state)
Generate a DR SCAN using the fields passed to the function.
void jtag_add_sleep(uint32_t us)
struct jtag_tap * jtag_tap_by_position(unsigned int n)
void jtag_add_ir_scan(struct jtag_tap *active, struct scan_field *in_fields, enum tap_state state)
Generate an IR SCAN with a list of scan fields with one entry for each enabled TAP.
tap_state
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)
#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 int str9xpec_set_instr(struct jtag_tap *tap, uint32_t new_instr, enum tap_state end_state)
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
unsigned int ir_length
size of instruction register
unsigned int abs_chain_position
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.
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.
unsigned int num_bits
The number of bits this field specifies.
#define ERROR_TARGET_INVALID
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.