24 #define RSL10_FLASH_ADDRESS_MAIN 0x00100000
25 #define RSL10_FLASH_ADDRESS_NVR1 0x00080000
26 #define RSL10_FLASH_ADDRESS_NVR2 0x00080800
27 #define RSL10_FLASH_ADDRESS_NVR3 0x00081000
28 #define RSL10_FLASH_ADDRESS_NVR4 0x00081800
29 #define RSL10_FLASH_ADDRESS_LOCK_INFO_SETTING 0x00081040
31 #define RSL10_REG_ID 0x1FFFFFFC
33 #define RSL10_FLASH_REG_MAIN_WRITE_UNLOCK 0x40000504
34 #define RSL10_FLASH_REG_MAIN_CTRL 0x40000508
35 #define RSL10_FLASH_REG_IF_STATUS 0x40000538
36 #define RSL10_FLASH_REG_NVR_WRITE_UNLOCK 0x40000548
37 #define RSL10_FLASH_REG_NVR_CTRL 0x4000054C
39 #define RSL10_FLASH_REG_DEBUG_UNLOCK_KEY1 0x400000F0
40 #define RSL10_FLASH_REG_DEBUG_UNLOCK_KEY2 0x400000F4
41 #define RSL10_FLASH_REG_DEBUG_UNLOCK_KEY3 0x400000F8
42 #define RSL10_FLASH_REG_DEBUG_UNLOCK_KEY4 0x400000FC
44 #define RSL10_NVR3_USER_KEY_OFFSET 0x40
46 #define RSL10_ID 0x09010106
47 #define RSL10_FLASH_KEY_MAIN 0xDBC8264E
48 #define RSL10_FLASH_KEY_NVR 0x71B371F5
49 #define RSL10_KEY_DEBUG_LOCK 0x4C6F634B
51 #define RSL10_FLASH_REG_MAIN_CTRL_LOW_W_ENABLE BIT(0)
52 #define RSL10_FLASH_REG_MAIN_CTRL_MIDDLE_W_ENABLE BIT(1)
53 #define RSL10_FLASH_REG_MAIN_CTRL_HIGH_W_ENABLE BIT(2)
55 #define RSL10_FLASH_REG_NVR_CTRL_NVR1_W_ENABLE BIT(1)
56 #define RSL10_FLASH_REG_NVR_CTRL_NVR2_W_ENABLE BIT(2)
57 #define RSL10_FLASH_REG_NVR_CTRL_NVR3_W_ENABLE BIT(3)
59 #define RSL10_FLASH_REG_STATUS_LOW_W_UNLOCKED BIT(0)
60 #define RSL10_FLASH_REG_STATUS_MIDDLE_W_UNLOCKED BIT(1)
61 #define RSL10_FLASH_REG_STATUS_HIGH_W_UNLOCKED BIT(2)
62 #define RSL10_FLASH_REG_STATUS_NVR1_W_UNLOCKED BIT(4)
63 #define RSL10_FLASH_REG_STATUS_NVR2_W_UNLOCKED BIT(5)
64 #define RSL10_FLASH_REG_STATUS_NVR3_W_UNLOCKED BIT(6)
66 #define RSL10_ROM_CMD_WRITE_WORD_PAIR 0x3C
67 #define RSL10_ROM_CMD_WRITE_BUFFER 0x40
68 #define RSL10_ROM_CMD_ERASE_SECTOR 0x44
69 #define RSL10_ROM_CMD_ERASE_ALL 0x48
71 #define FLASH_SECTOR_SIZE 0x2000
73 #define RSL10_ROM_CMD_WRITE_BUFFER_MAX_SIZE FLASH_SECTOR_SIZE
75 #define ALGO_STACK_POINTER_ADDR 0x20002000
83 #include "../../../contrib/loaders/flash/rsl10/rom_launcher.inc"
133 struct rsl10_bank *nbank =
bank->driver_priv;
135 return nbank->probed;
147 struct rsl10_bank *nbank =
bank->driver_priv;
158 struct rsl10_bank *nbank =
bank->driver_priv;
170 for (
unsigned int i = 0; i <
bank->num_prot_blocks; i++)
171 bank->prot_blocks[i].is_protected = (
status & (1 << i)) ? 0 : 1;
175 switch (
bank->base) {
208 for (
unsigned int i = first; i <= last; i++) {
224 switch (
bank->base) {
268 LOG_ERROR(
"This is not supported (RSL10) device, use other flash driver!!!");
276 struct rsl10_bank *nbank =
bank->driver_priv;
283 unsigned int bank_id;
284 unsigned int num_prot_blocks = 0;
285 switch (
bank->base) {
303 uint32_t flash_page_size = 2048;
305 bank->write_start_alignment = 8;
306 bank->write_end_alignment = 8;
308 bank->num_sectors =
bank->size / flash_page_size;
318 free(
bank->prot_blocks);
321 if (num_prot_blocks > 0) {
322 bank->num_prot_blocks = num_prot_blocks;
324 if (!
bank->prot_blocks)
371 goto free_reg_params;
380 goto free_reg_params;
382 int algo_ret =
buf_get_u32(reg_params[0].value, 0, 32);
389 for (
unsigned int i = 0; i <
ARRAY_SIZE(reg_params); i++)
405 LOG_DEBUG(
"Writing 0x%" PRIx32
" to flash address=0x%" PRIx32
" bytes=0x%" PRIx32, data,
address, bytes);
407 LOG_DEBUG(
"Writing buffer to flash address=0x%" PRIx32
" bytes=0x%" PRIx32,
address, bytes);
444 uint32_t sent_bytes = 0;
445 uint32_t write_address = 0;
446 uint32_t bytes_to_send = 0;
447 uint32_t remaining_bytes = 0;
451 goto free_everything;
453 while (sent_bytes < bytes) {
454 remaining_bytes = bytes - sent_bytes;
455 bytes_to_send = remaining_bytes >= buffer_size ? buffer_size : remaining_bytes;
459 goto free_everything;
461 write_address = address + sent_bytes;
464 "write_address: 0x%" PRIx32
", words: 0x%" PRIx32
", source: 0x%" PRIx64
", cmd: 0x%" PRIx32, write_address,
467 buf_set_u32(reg_params[0].value, 0, 32, write_address);
468 buf_set_u32(reg_params[1].value, 0, 32, bytes_to_send / 4);
477 goto free_everything;
479 int algo_ret =
buf_get_u32(reg_params[0].value, 0, 32);
483 goto free_everything;
486 sent_bytes += bytes_to_send;
492 for (
unsigned int i = 0; i <
ARRAY_SIZE(reg_params); i++)
528 goto free_reg_params;
537 goto free_reg_params;
539 int algo_ret =
buf_get_u32(reg_params[0].value, 0, 32);
546 for (
unsigned int i = 0; i <
ARRAY_SIZE(reg_params); i++)
567 LOG_INFO(
"erase bank: %x, %x", first, last);
575 for (
unsigned int i = first; i <= last; i++) {
586 struct rsl10_bank *nbank =
bank->driver_priv;
623 struct rsl10_bank *nbank =
NULL;
626 switch (
bank->base) {
640 chip = calloc(1,
sizeof(*chip));
647 switch (
bank->base) {
649 nbank = &chip->
bank[0];
652 nbank = &chip->
bank[1];
655 nbank = &chip->
bank[2];
658 nbank = &chip->
bank[3];
661 nbank = &chip->
bank[4];
668 nbank->probed =
false;
669 bank->driver_priv = nbank;
688 uint32_t user_key[4];
694 uint8_t write_buffer[6 * 4];
698 memset(&write_buffer[5 * 4],
bank->default_padded_value, 4);
711 CMD,
"****** WARNING ******\n"
712 "rsl10 device has been successfully prepared to lock.\n"
713 "Debug port is locked after restart.\n"
714 "Unlock with 'rsl10_unlock key0 key1 key2 key3'\n"
715 "****** ....... ******\n"
732 uint32_t user_key[4];
738 uint8_t write_buffer1[4 * 4];
752 LOG_INFO(
"mem read: 0x%08" PRIx32, key);
768 uint8_t write_buffer2[4 * 2];
771 memset(&write_buffer2[4],
bank->default_padded_value, 4);
799 .handler = rsl10_lock_command,
801 .help =
"Lock rsl10 debug, with passed keys",
802 .usage =
"key1 key2 key3 key4",
806 .handler = rsl10_unlock_command,
808 .help =
"Unlock rsl10 debug, with passed keys",
809 .usage =
"key1 key2 key3 key4",
812 .name =
"mass_erase",
813 .handler = rsl10_mass_erase_command,
815 .help =
"Mass erase all unprotected flash areas",
825 .help =
"rsl10 flash command group",
835 .flash_bank_command = rsl10_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 mem_ap_read_atomic_u32(struct adiv5_ap *ap, target_addr_t address, uint32_t *value)
Synchronous read of a word from memory or a system register.
struct adiv5_ap * dap_get_ap(struct adiv5_dap *dap, uint64_t ap_num)
int dap_put_ap(struct adiv5_ap *ap)
int mem_ap_write_buf(struct adiv5_ap *ap, const uint8_t *buffer, uint32_t size, uint32_t count, target_addr_t address)
This defines formats and data structures used to talk to ADIv5 entities.
#define ARMV7M_COMMON_MAGIC
Support functions to access arbitrary bits in a byte array.
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.
static int test_bit(unsigned int nr, const volatile unsigned long *addr)
test_bit - Determine whether a bit is set
void command_print(struct command_invocation *cmd, const char *format,...)
int command_run_line(struct command_context *context, char *line)
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
#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 CMD_CTX
Use this macro to access the context of the command being handled, rather than accessing the variable...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
static struct cortex_m_common * target_to_cm(struct target *target)
#define ERROR_FLASH_SECTOR_NOT_ERASED
#define ERROR_FLASH_OPERATION_FAILED
struct flash_sector * alloc_block_array(uint32_t offset, uint32_t size, unsigned int num_blocks)
Allocate and fill an array of sectors or protection blocks.
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.
int get_flash_bank_by_addr(struct target *target, target_addr_t addr, bool check, struct flash_bank **result_bank)
Returns the flash bank located at a specified address.
struct flash_bank * flash_bank_list(void)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
static uint32_t bit(uint32_t value, unsigned int b)
#define RSL10_ROM_CMD_ERASE_SECTOR
#define RSL10_FLASH_ADDRESS_NVR2
static void rsl10_free_driver_priv(struct flash_bank *bank)
static int rsl10_protect_check(struct flash_bank *bank)
static int rsl10_auto_probe(struct flash_bank *bank)
#define RSL10_FLASH_ADDRESS_NVR4
#define RSL10_FLASH_REG_STATUS_NVR2_W_UNLOCKED
#define RSL10_FLASH_KEY_NVR
#define RSL10_FLASH_REG_NVR_WRITE_UNLOCK
const struct flash_driver rsl10_flash
static const struct command_registration rsl10_command_handlers[]
FLASH_BANK_COMMAND_HANDLER(rsl10_flash_bank_command)
static const uint8_t rsl10_rom_launcher_code[]
static int rsl10_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
#define RSL10_ROM_CMD_WRITE_BUFFER_MAX_SIZE
#define RSL10_FLASH_REG_NVR_CTRL
#define RSL10_FLASH_ADDRESS_MAIN
static const char *const rsl10_error_list[]
#define ALGO_STACK_POINTER_ADDR
static int rsl10_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
static int rsl10_probe(struct flash_bank *bank)
#define RSL10_ROM_CMD_WRITE_BUFFER
static int rsl10_ll_flash_write(struct rsl10_info *chip, uint32_t address, const uint8_t *buffer, uint32_t bytes)
#define RSL10_FLASH_REG_STATUS_NVR1_W_UNLOCKED
static const struct command_registration rsl10_exec_command_handlers[]
#define RSL10_FLASH_ADDRESS_LOCK_INFO_SETTING
#define RSL10_KEY_DEBUG_LOCK
#define RSL10_FLASH_KEY_MAIN
#define RSL10_NVR3_USER_KEY_OFFSET
#define RSL10_FLASH_REG_MAIN_CTRL
static const char * rsl10_error(enum rsl10_flash_status x)
static bool rsl10_bank_is_probed(const struct flash_bank *bank)
static int rsl10_get_probed_chip_if_halted(struct flash_bank *bank, struct rsl10_info **chip)
#define RSL10_FLASH_REG_NVR_CTRL_NVR1_W_ENABLE
@ RSL10_FLASH_ERR_INACCESSIBLE
@ RSL10_FLASH_ERR_WRITE_NOT_ENABLED
@ RSL10_FLASH_MAX_ERR_CODES
@ RSL10_FLASH_ERR_BAD_LENGTH
@ RSL10_FLASH_ERR_PROG_FAILED
@ RSL10_FLASH_ERR_BAD_ADDRESS
@ RSL10_FLASH_ERR_GENERAL_FAILURE
@ RSL10_FLASH_ERR_COPIER_BUSY
@ RSL10_FLASH_ERR_ERASE_FAILED
static int rsl10_mass_erase(struct target *target)
#define RSL10_FLASH_REG_NVR_CTRL_NVR2_W_ENABLE
#define RSL10_FLASH_REG_IF_STATUS
static int rsl10_ll_flash_erase(struct rsl10_info *chip, uint32_t address)
#define RSL10_FLASH_ADDRESS_NVR3
#define RSL10_FLASH_ADDRESS_NVR1
static struct rsl10_info * rsl10_get_chip(struct target *target)
#define RSL10_FLASH_REG_MAIN_WRITE_UNLOCK
COMMAND_HANDLER(rsl10_lock_command)
#define RSL10_FLASH_REG_DEBUG_UNLOCK_KEY1
static int rsl10_check_device(struct flash_bank *bank)
static int rsl10_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
#define RSL10_ROM_CMD_ERASE_ALL
#define RSL10_FLASH_REG_NVR_CTRL_NVR3_W_ENABLE
#define RSL10_FLASH_REG_STATUS_NVR3_W_UNLOCKED
This represents an ARM Debug Interface (v5) Access Port (AP).
struct adiv5_dap * dap
DAP this AP belongs to.
This represents an ARM Debug Interface (v5) Debug Access Port (DAP).
struct adiv5_dap * dap
For targets conforming to ARM Debug Interface v5, this handle references the Debug Access Port (DAP) ...
unsigned int common_magic
struct armv7m_common armv7m
Provides details of a flash bank, available either on-chip or through a major interface.
const struct flash_driver * driver
Driver for this bank.
void * driver_priv
Private driver storage pointer.
struct flash_bank * next
The next flash bank on this chip.
struct target * target
Target to which this bank belongs.
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...
struct rsl10_info::rsl10_bank bank[5]
unsigned int flash_size_kb
uint32_t working_area_size
void target_buffer_set_u32(struct target *target, uint8_t *buffer, uint32_t value)
int target_write_buffer(struct target *target, target_addr_t address, uint32_t size, const uint8_t *buffer)
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, unsigned int timeout_ms, void *arch_info)
Downloads a target-specific native code algorithm to the target, and executes it.
uint32_t target_get_working_area_avail(struct target *target)
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_read_u32(struct target *target, target_addr_t address, uint32_t *value)
struct target * get_current_target(struct command_context *cmd_ctx)
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_INVALID
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.