25 #define FLASH_CR0       0x00000000 
   26 #define FLASH_CR1       0x00000004 
   27 #define FLASH_DR0       0x00000008 
   28 #define FLASH_DR1       0x0000000C 
   29 #define FLASH_AR        0x00000010 
   30 #define FLASH_ER        0x00000014 
   31 #define FLASH_NVWPAR    0x0000DFB0 
   32 #define FLASH_NVAPR0    0x0000DFB8 
   33 #define FLASH_NVAPR1    0x0000DFBC 
   37 #define FLASH_WMS       0x80000000 
   38 #define FLASH_SUSP      0x40000000 
   39 #define FLASH_WPG       0x20000000 
   40 #define FLASH_DWPG      0x10000000 
   41 #define FLASH_SER       0x08000000 
   42 #define FLASH_SPR       0x01000000 
   43 #define FLASH_BER       0x04000000 
   44 #define FLASH_MER       0x02000000 
   45 #define FLASH_LOCK      0x00000010 
   46 #define FLASH_BSYA1     0x00000004 
   47 #define FLASH_BSYA0     0x00000002 
   51 #define FLASH_B1S       0x02000000 
   52 #define FLASH_B0S       0x01000000 
   53 #define FLASH_B1F1      0x00020000 
   54 #define FLASH_B1F0      0x00010000 
   55 #define FLASH_B0F7      0x00000080 
   56 #define FLASH_B0F6      0x00000040 
   57 #define FLASH_B0F5      0x00000020 
   58 #define FLASH_B0F4      0x00000010 
   59 #define FLASH_B0F3      0x00000008 
   60 #define FLASH_B0F2      0x00000004 
   61 #define FLASH_B0F1      0x00000002 
   62 #define FLASH_B0F0      0x00000001 
   66 #define FLASH_WPF       0x00000100 
   67 #define FLASH_RESER     0x00000080 
   68 #define FLASH_SEQER     0x00000040 
   69 #define FLASH_10ER      0x00000008 
   70 #define FLASH_PGER      0x00000004 
   71 #define FLASH_ERER      0x00000002 
   72 #define FLASH_ERR       0x00000001 
  104     {0x00000000, 0x02000, 0x01},
 
  105     {0x00002000, 0x02000, 0x02},
 
  106     {0x00004000, 0x02000, 0x04},
 
  107     {0x00006000, 0x02000, 0x08},
 
  108     {0x00008000, 0x08000, 0x10},
 
  109     {0x00010000, 0x10000, 0x20},
 
  110     {0x00020000, 0x10000, 0x40},
 
  111     {0x00030000, 0x10000, 0x80}
 
  115     {0x00000000, 0x02000, 0x10000},
 
  116     {0x00002000, 0x02000, 0x20000}
 
  130     unsigned int num_sectors;
 
  131     int b0_sectors = 0, b1_sectors = 0;
 
  133     switch (
bank->size) {
 
  147             LOG_ERROR(
"BUG: unknown bank->size encountered");
 
  151     num_sectors = b0_sectors + b1_sectors;
 
  153     bank->num_sectors = num_sectors;
 
  155     str7x_info->
sector_bits = malloc(
sizeof(uint32_t) * num_sectors);
 
  159     for (i = 0; i < b0_sectors; i++) {
 
  162         bank->sectors[num_sectors].is_erased = -1;
 
  166         bank->sectors[num_sectors].is_protected = 0;
 
  170     for (i = 0; i < b1_sectors; i++) {
 
  173         bank->sectors[num_sectors].is_erased = -1;
 
  177         bank->sectors[num_sectors].is_protected = 0;
 
  194     bank->driver_priv = str7x_info;
 
  200     if (strcmp(
CMD_ARGV[6], 
"STR71x") == 0)
 
  202     else if (strcmp(
CMD_ARGV[6], 
"STR73x") == 0) {
 
  205     } 
else if (strcmp(
CMD_ARGV[6], 
"STR75x") == 0) {
 
  236     for (i = 0 ; i < 10000; i++) {
 
  242         if ((retval & str7x_info->
busy_bits) == 0)
 
  247     LOG_ERROR(
"Timed out waiting for str7x flash");
 
  255     uint32_t flash_flags;
 
  263         LOG_ERROR(
"str7x hw write protection set");
 
  267         LOG_ERROR(
"str7x suspended program erase not resumed");
 
  271         LOG_ERROR(
"str7x trying to set bit to 1 when it is already 0");
 
  285             LOG_ERROR(
"str7x write operation failed / bad setup");
 
  298     uint32_t flash_flags;
 
  310     for (
unsigned int i = 0; i < 
bank->num_sectors; i++) {
 
  312             bank->sectors[i].is_protected = 0;
 
  314             bank->sectors[i].is_protected = 1;
 
  327     uint32_t sectors = 0;
 
  335     for (
unsigned int i = first; i <= last; i++)
 
  338     LOG_DEBUG(
"sectors: 0x%" PRIx32 
"", sectors);
 
  377     uint32_t protect_blocks;
 
  384     protect_blocks = 0xFFFFFFFF;
 
  387         for (
unsigned int i = first; i <= last; i++)
 
  407     cmd = protect_blocks;
 
  433     uint32_t buffer_size = 32768;
 
  443     static const uint32_t str7x_flash_write_code[] = {
 
  475     uint8_t code[
sizeof(str7x_flash_write_code)];
 
  477             str7x_flash_write_code);
 
  483         if (buffer_size <= 256) {
 
  488             LOG_WARNING(
"no large enough working area available, can't do block memory writes");
 
  505         uint32_t thisrun_count = (
count > (buffer_size / 8)) ? (buffer_size / 8) : 
count;
 
  512         buf_set_u32(reg_params[3].value, 0, 32, thisrun_count);
 
  517                 write_algorithm->
address + (
sizeof(str7x_flash_write_code) - 4),
 
  522         if (
buf_get_u32(reg_params[4].value, 0, 32) != 0x00) {
 
  527         buffer += thisrun_count * 8;
 
  528         address += thisrun_count * 8;
 
  529         count -= thisrun_count;
 
  549     uint32_t dwords_remaining = (
count / 8);
 
  550     uint32_t bytes_remaining = (
count & 0x00000007);
 
  552     uint32_t bytes_written = 0;
 
  555     uint32_t check_address = 
offset;
 
  567     for (
unsigned int i = 0; i < 
bank->num_sectors; i++) {
 
  568         uint32_t sec_start = 
bank->sectors[i].offset;
 
  569         uint32_t sec_end = sec_start + 
bank->sectors[i].size;
 
  572         if ((check_address >= sec_start) && (check_address < sec_end)) {
 
  577                 check_address = sec_end;
 
  588     if (dwords_remaining > 0) {
 
  595                 LOG_WARNING(
"couldn't use block writes, falling back to single memory accesses");
 
  600             buffer += dwords_remaining * 8;
 
  601             address += dwords_remaining * 8;
 
  602             dwords_remaining = 0;
 
  606     while (dwords_remaining > 0) {
 
  616                 4, 1, 
buffer + bytes_written);
 
  621                 4, 1, 
buffer + bytes_written);
 
  641     if (bytes_remaining) {
 
  642         uint8_t last_dword[8] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
 
  645         memcpy(last_dword, 
buffer+bytes_written, bytes_remaining);
 
  660                 4, 1, last_dword + 4);
 
  698             "clearing the protection is only temporary and may not be reflected in the current " 
  709     uint16_t protection_level = 0;
 
  710     uint16_t protection_regs;
 
  720     str7x_info = 
bank->driver_priv;
 
  734         protection_level = 1;
 
  737     protection_regs = ~(
reg >> 16);
 
  739     while (((protection_regs) != 0) && (protection_level < 16)) {
 
  740         protection_regs >>= 1;
 
  744     if (protection_level == 0) {
 
  756                 ~(1 << (15 + protection_level)));
 
  766         .
name = 
"disable_jtag",
 
  768         .handler = str7x_handle_disable_jtag_command,
 
  770         .help = 
"disable jtag access",
 
  779         .help = 
"str7x flash command group",
 
  789     .flash_bank_command = str7x_flash_bank_command,
 
void init_reg_param(struct reg_param *param, char *reg_name, uint32_t size, enum param_direction direction)
 
void destroy_reg_param(struct reg_param *param)
 
Holds the interface to ARM cores.
 
Support functions to access arbitrary bits in a byte array.
 
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_sameline(struct command_invocation *cmd, const char *format,...)
 
#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_BANK_INVALID
 
#define ERROR_FLASH_DST_BREAKS_ALIGNMENT
 
#define ERROR_FLASH_DST_OUT_OF_BANK
 
int default_flash_blank_check(struct flash_bank *bank)
Provides default erased-bank check handling.
 
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.
 
void alive_sleep(uint64_t ms)
 
#define LOG_WARNING(expr ...)
 
#define LOG_ERROR(expr ...)
 
#define LOG_DEBUG(expr ...)
 
@ STR7X_SECTOR_NOT_PREPARED
 
@ STR7X_DST_ADDR_NOT_MAPPED
 
@ STR7X_SRC_ADDR_NOT_MAPPED
 
static const struct command_registration str7x_exec_command_handlers[]
 
static int str7x_build_block_list(struct flash_bank *bank)
 
static int str7x_protect_check(struct flash_bank *bank)
 
static const struct str7x_mem_layout mem_layout_str7bank0[]
 
static int str7x_probe(struct flash_bank *bank)
 
static const struct str7x_mem_layout mem_layout_str7bank1[]
 
static int str7x_get_flash_adr(struct flash_bank *bank, uint32_t reg)
 
static int str7x_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
 
static int str7x_result(struct flash_bank *bank)
 
static const struct command_registration str7x_command_handlers[]
 
static int str7x_write_block(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
 
static int get_str7x_info(struct flash_bank *bank, struct command_invocation *cmd)
 
static int str7x_waitbusy(struct flash_bank *bank)
 
COMMAND_HANDLER(str7x_handle_disable_jtag_command)
 
static int str7x_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
 
static int str7x_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
 
const struct flash_driver str7x_flash
 
FLASH_BANK_COMMAND_HANDLER(str7x_flash_bank_command)
 
unsigned int common_magic
 
enum arm_state core_state
 
When run_command is called, a new instance will be created on the stack, filled with the proper value...
 
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.
 
int target_write_buffer(struct target *target, target_addr_t address, uint32_t size, const uint8_t *buffer)
 
int target_write_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Write count items of size bytes to the memory of target at the address given.
 
int target_write_u32(struct target *target, target_addr_t address, uint32_t value)
 
int target_free_working_area(struct target *target, struct working_area *area)
Free a working area.
 
int target_run_algorithm(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_param, target_addr_t entry_point, target_addr_t exit_point, int timeout_ms, void *arch_info)
Downloads a target-specific native code algorithm to the target, and executes it.
 
int target_alloc_working_area_try(struct target *target, uint32_t size, struct working_area **area)
 
int target_read_u32(struct target *target, target_addr_t address, uint32_t *value)
 
void target_buffer_set_u32_array(struct target *target, uint8_t *buffer, uint32_t count, const uint32_t *srcbuf)
 
#define ERROR_TARGET_NOT_HALTED
 
#define ERROR_TARGET_RESOURCE_NOT_AVAILABLE
 
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.