20 #define BLUENRG2_JTAG_REG (flash_priv_data_2.jtag_idcode_reg)
21 #define BLUENRGLP_JTAG_REG (flash_priv_data_lp.jtag_idcode_reg)
23 #define DIE_ID_REG(bluenrgx_info) (bluenrgx_info->flash_ptr->die_id_reg)
24 #define JTAG_IDCODE_REG(bluenrgx_info) (bluenrgx_info->flash_ptr->jtag_idcode_reg)
25 #define FLASH_PAGE_SIZE(bluenrgx_info) (bluenrgx_info->flash_ptr->flash_page_size)
27 #define FLASH_SIZE_REG_MASK (0xFFFF)
41 .jtag_idcode_reg = 0x40900028,
42 .flash_base = 0x10040000,
43 .flash_regs_base = 0x40100000,
44 .flash_page_size = 2048,
45 .jtag_idcode = 0x00000000,
46 .part_name =
"BLUENRG-1",
51 .jtag_idcode_reg = 0x40900028,
52 .flash_base = 0x10040000,
53 .flash_regs_base = 0x40100000,
54 .flash_page_size = 2048,
55 .jtag_idcode = 0x0200A041,
56 .part_name =
"BLUENRG-2",
61 .jtag_idcode_reg = 0x40000004,
62 .flash_base = 0x10040000,
63 .flash_regs_base = 0x40001000,
64 .flash_page_size = 2048,
65 .jtag_idcode = 0x0201E041,
66 .part_name =
"BLUENRG-LP",
71 .jtag_idcode_reg = 0x40000004,
72 .flash_base = 0x10040000,
73 .flash_regs_base = 0x40001000,
74 .flash_page_size = 2048,
75 .jtag_idcode = 0x02028041,
76 .part_name =
"BLUENRG-LPS",
96 bluenrgx_info = calloc(1,
sizeof(*bluenrgx_info));
100 LOG_ERROR(
"failed to allocate bank structure");
104 bank->write_start_alignment = 16;
105 bank->write_end_alignment = 16;
107 bank->driver_priv = bluenrgx_info;
109 bluenrgx_info->
probed =
false;
138 unsigned int num_sectors = (last - first + 1);
144 if (!bluenrgx_info->
probed)
159 address =
bank->base;
176 for (
unsigned int i = 0; i < 100; i++) {
185 LOG_ERROR(
"Mass erase command failed (timeout)");
192 for (
unsigned int i = first; i <= last; i++) {
194 LOG_DEBUG(
"address = %08" PRIx32
", index = %u", address, i);
212 for (
unsigned int j = 0; j < 100; j++) {
221 LOG_ERROR(
"Erase command failed (timeout)");
237 uint32_t buffer_size = 16384 + 8;
250 static const uint8_t bluenrgx_flash_write_code[] = {
251 #include "../../../contrib/loaders/flash/bluenrg-x/bluenrg-x_write.inc"
255 if (!bluenrgx_info->
probed)
259 LOG_ERROR(
"Requested write past beyond of flash size: (offset+count) = %" PRIu32
", size=%" PRIu32,
272 LOG_WARNING(
"no working area available, can't do block memory writes");
277 sizeof(bluenrgx_flash_write_code),
278 bluenrgx_flash_write_code);
284 LOG_WARNING(
"no large enough working area available");
290 &write_algorithm_stack) !=
ERROR_OK) {
291 LOG_DEBUG(
"no working area for target algorithm stack");
331 LOG_DEBUG(
"address = %08" PRIx32, address);
349 LOG_ERROR(
"error executing bluenrg-x flash write algorithm");
351 uint32_t error =
buf_get_u32(reg_params[0].value, 0, 32);
354 LOG_ERROR(
"flash write failed = %08" PRIx32, error);
361 if ((rp < source->address+8) || (rp > (
source->address +
source->size))) {
362 LOG_ERROR(
"flash write failed = %08" PRIx32, rp);
384 uint32_t idcode, size_info,
die_id;
420 for (
unsigned int i = 0; i <
bank->num_sectors; i++) {
423 bank->sectors[i].is_erased = -1;
424 bank->sectors[i].is_protected = 0;
427 bluenrgx_info->
probed =
true;
437 if (bluenrgx_info->
probed)
447 int mask_number, cut_number;
449 if (!bluenrgx_info->
probed) {
457 mask_number = (bluenrgx_info->
die_id >> 4) & 0xF;
458 cut_number = bluenrgx_info->
die_id & 0xF;
467 .flash_bank_command = bluenrgx_flash_bank_command,
474 .protect_check =
NULL,
void init_reg_param(struct reg_param *param, char *reg_name, uint32_t size, enum param_direction direction)
void destroy_mem_param(struct mem_param *param)
void destroy_reg_param(struct reg_param *param)
void init_mem_param(struct mem_param *param, uint32_t address, uint32_t size, enum param_direction direction)
#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 const struct flash_ctrl_priv_data * flash_ctrl[]
static const struct flash_ctrl_priv_data flash_priv_data_lp
#define DIE_ID_REG(bluenrgx_info)
#define FLASH_PAGE_SIZE(bluenrgx_info)
static uint32_t bluenrgx_get_flash_reg(struct flash_bank *bank, uint32_t reg_offset)
const struct flash_driver bluenrgx_flash
#define BLUENRG2_JTAG_REG
static const struct flash_ctrl_priv_data flash_priv_data_2
static int bluenrgx_write_flash_reg(struct flash_bank *bank, uint32_t reg_offset, uint32_t value)
static int bluenrgx_probe(struct flash_bank *bank)
static int bluenrgx_get_info(struct flash_bank *bank, struct command_invocation *cmd)
static int bluenrgx_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
FLASH_BANK_COMMAND_HANDLER(bluenrgx_flash_bank_command)
#define FLASH_SIZE_REG_MASK
static int bluenrgx_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
static const struct flash_ctrl_priv_data flash_priv_data_lps
static int bluenrgx_read_flash_reg(struct flash_bank *bank, uint32_t reg_offset, uint32_t *value)
#define BLUENRGLP_JTAG_REG
static int bluenrgx_auto_probe(struct flash_bank *bank)
static const struct flash_ctrl_priv_data flash_priv_data_1
#define FLASH_INT_CMDDONE
#define FLASH_CMD_ERASE_PAGE
#define FLASH_REG_COMMAND
#define FLASH_REG_ADDRESS
#define FLASH_CMD_MASSERASE
void command_print_sameline(struct command_invocation *cmd, const char *format,...)
#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...
static int mass_erase(struct target *target, uint16_t *hfm_ustat)
Executes the FM mass erase command.
#define ERROR_FLASH_BANK_NOT_PROBED
#define ERROR_FLASH_OPERATION_FAILED
#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.
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_DEBUG(expr ...)
unsigned int common_magic
const struct flash_ctrl_priv_data * flash_ptr
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_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_flash_async_algorithm(struct target *target, const uint8_t *buffer, uint32_t count, int block_size, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_params, uint32_t buffer_start, uint32_t buffer_size, uint32_t entry_point, uint32_t exit_point, void *arch_info)
Streams data to a circular buffer on target intended for consumption by code running asynchronously o...
int target_read_u32(struct target *target, target_addr_t address, uint32_t *value)
#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.