24 #define FLASH_BBSR 0x54000000
25 #define FLASH_NBBSR 0x54000004
26 #define FLASH_BBADR 0x5400000C
27 #define FLASH_NBBADR 0x54000010
28 #define FLASH_CR 0x54000018
29 #define FLASH_SR 0x5400001C
30 #define FLASH_BCE5ADDR 0x54000020
60 unsigned int num_sectors;
61 int b0_sectors = 0, b1_sectors = 0;
66 str9x_info->
bank1 = 0;
87 str9x_info->
bank1 = 1;
92 str9x_info->
bank1 = 1;
97 LOG_ERROR(
"BUG: unknown bank->size encountered");
101 num_sectors = b0_sectors + b1_sectors;
103 bank->num_sectors = num_sectors;
105 str9x_info->
sector_bits = malloc(
sizeof(uint32_t) * num_sectors);
109 for (i = 0; i < b0_sectors; i++) {
111 bank->sectors[num_sectors].size = 0x10000;
113 bank->sectors[num_sectors].is_erased = -1;
114 bank->sectors[num_sectors].is_protected = 1;
118 for (i = 0; i < b1_sectors; i++) {
120 bank->sectors[num_sectors].size = str9x_info->
variant == 0 ? 0x2000 : 0x4000;
122 bank->sectors[num_sectors].is_erased = -1;
123 bank->sectors[num_sectors].is_protected = 1;
127 str9x_info->
sector_bits[num_sectors++] = (1 << (i + 8));
143 bank->driver_priv = str9x_info;
158 uint16_t hstatus = 0;
168 if (str9x_info->
bank1) {
202 for (
unsigned int i = 0; i <
bank->num_sectors; i++) {
204 bank->sectors[i].is_protected = 1;
206 bank->sectors[i].is_protected = 0;
227 if ((first == 0) && (last == (
bank->num_sectors - 1))) {
231 total_timeout = 1000 *
bank->num_sectors;
235 total_timeout = 1000;
239 assert(total_timeout > 0);
241 for (
unsigned int i = first; i <= last; i++) {
243 adr =
bank->base +
bank->sectors[i].offset;
267 if (
timeout == total_timeout) {
288 if (erase_cmd == 0x80)
307 for (
unsigned int i = first; i <= last; i++) {
310 adr =
bank->base +
bank->sectors[i].offset;
335 uint32_t buffer_size = 32768;
345 static const uint32_t str9x_flash_write_code[] = {
373 LOG_WARNING(
"no working area available, can't do block memory writes");
377 uint8_t code[
sizeof(str9x_flash_write_code)];
379 str9x_flash_write_code);
385 if (buffer_size <= 256) {
390 LOG_WARNING(
"no large enough working area available, can't do block memory writes");
405 uint32_t thisrun_count = (
count > (buffer_size / 2)) ? (buffer_size / 2) :
count;
411 buf_set_u32(reg_params[2].value, 0, 32, thisrun_count);
415 0, 10000, &arm_algo);
417 LOG_ERROR(
"error executing str9x flash write algorithm");
422 if (
buf_get_u32(reg_params[3].value, 0, 32) != 0x80) {
427 buffer += thisrun_count * 2;
428 address += thisrun_count * 2;
429 count -= thisrun_count;
447 uint32_t words_remaining = (
count / 2);
448 uint32_t bytes_remaining = (
count & 0x00000001);
450 uint32_t bytes_written = 0;
453 uint32_t check_address =
offset;
466 for (
unsigned int i = 0; i <
bank->num_sectors; i++) {
467 uint32_t sec_start =
bank->sectors[i].offset;
468 uint32_t sec_end = sec_start +
bank->sectors[i].size;
471 if ((check_address >= sec_start) && (check_address < sec_end)) {
476 check_address = sec_end;
484 if (words_remaining > 0) {
491 LOG_WARNING(
"couldn't use block writes, falling back to single memory accesses");
497 buffer += words_remaining * 2;
498 address += words_remaining * 2;
503 while (words_remaining > 0) {
504 bank_adr = address & ~0x03;
539 if (bytes_remaining) {
540 uint8_t last_halfword[2] = {0xff, 0xff};
543 memcpy(last_halfword,
buffer+bytes_written, bytes_remaining);
545 bank_adr = address & ~0x03;
603 uint32_t bbsr, nbbsr, bbadr, nbbadr;
632 .
name =
"flash_config",
633 .handler = str9x_handle_flash_config_command,
635 .help =
"Configure str9x flash controller, prior to "
636 "programming the flash.",
637 .usage =
"bank_id BBSR NBBSR BBADR NBBADR",
646 .help =
"str9x flash command group",
656 .flash_bank_command = str9x_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)
int arm966e_write_cp15(struct target *target, int reg_addr, uint32_t value)
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.
#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_PARSE_NUMBER(type, in, out)
parses the string in into out as a type, or prints a command error and passes the error code to the c...
#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_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 ...)
static const struct command_registration str9x_command_handlers[]
const struct flash_driver str9x_flash
FLASH_BANK_COMMAND_HANDLER(str9x_flash_bank_command)
static int str9x_write_block(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
@ STR9X_DST_ADDR_NOT_MAPPED
@ STR9X_SECTOR_NOT_PREPARED
@ STR9X_SRC_ADDR_NOT_MAPPED
static const struct command_registration str9x_config_command_handlers[]
static int str9x_probe(struct flash_bank *bank)
static int str9x_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
static int str9x_build_block_list(struct flash_bank *bank)
static int str9x_protect_check(struct flash_bank *bank)
static int str9x_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
static int str9x_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
COMMAND_HANDLER(str9x_handle_flash_config_command)
static uint32_t bank1start
unsigned int common_magic
enum arm_state core_state
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_u16(struct target *target, target_addr_t address, uint16_t value)
int target_read_u8(struct target *target, target_addr_t address, uint8_t *value)
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_alloc_working_area(struct target *target, uint32_t size, struct working_area **area)
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_u16(struct target *target, target_addr_t address, uint16_t *value)
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.