target: Use target_addr for flash routines.

This commit is contained in:
Gareth McMullin 2016-07-04 10:55:26 +12:00
parent aeaca988c3
commit 82cb6c8e83
15 changed files with 72 additions and 72 deletions

View File

@ -44,9 +44,9 @@
#define SRAM_BASE 0x20000000
#define STUB_BUFFER_BASE ALIGN(SRAM_BASE + sizeof(efm32_flash_write_stub), 4)
static int efm32_flash_erase(struct target_flash *t, uint32_t addr, size_t len);
static int efm32_flash_erase(struct target_flash *t, target_addr addr, size_t len);
static int efm32_flash_write(struct target_flash *f,
uint32_t dest, const void *src, size_t len);
target_addr dest, const void *src, size_t len);
static const uint16_t efm32_flash_write_stub[] = {
#include "flashstub/efm32.stub"
@ -230,7 +230,7 @@ uint16_t efm32_read_radio_part_number(target *t)
static void efm32_add_flash(target *t, uint32_t addr, size_t length,
static void efm32_add_flash(target *t, target_addr addr, size_t length,
size_t page_size)
{
struct target_flash *f = calloc(1, sizeof(*f));
@ -344,7 +344,7 @@ bool efm32_probe(target *t)
/**
* Erase flash row by row
*/
static int efm32_flash_erase(struct target_flash *f, uint32_t addr, size_t len)
static int efm32_flash_erase(struct target_flash *f, target_addr addr, size_t len)
{
target *t = f->t;
@ -376,7 +376,7 @@ static int efm32_flash_erase(struct target_flash *f, uint32_t addr, size_t len)
* Write flash page by page
*/
static int efm32_flash_write(struct target_flash *f,
uint32_t dest, const void *src, size_t len)
target_addr dest, const void *src, size_t len)
{
(void)len;
target *t = f->t;

View File

@ -61,9 +61,9 @@
#define KL_GEN_PAGESIZE 0x400
static int kl_gen_flash_erase(struct target_flash *f, uint32_t addr, size_t len);
static int kl_gen_flash_erase(struct target_flash *f, target_addr addr, size_t len);
static int kl_gen_flash_write(struct target_flash *f,
uint32_t dest, const void *src, size_t len);
target_addr dest, const void *src, size_t len);
static void kl_gen_add_flash(target *t,
uint32_t addr, size_t length, size_t erasesize)
@ -159,7 +159,7 @@ kl_gen_command(target *t, uint8_t cmd, uint32_t addr, const uint8_t data[8])
return true;
}
static int kl_gen_flash_erase(struct target_flash *f, uint32_t addr, size_t len)
static int kl_gen_flash_erase(struct target_flash *f, target_addr addr, size_t len)
{
while (len) {
if (kl_gen_command(f->t, FTFA_CMD_ERASE_SECTOR, addr, NULL)) {
@ -173,7 +173,7 @@ static int kl_gen_flash_erase(struct target_flash *f, uint32_t addr, size_t len)
}
static int kl_gen_flash_write(struct target_flash *f,
uint32_t dest, const void *src, size_t len)
target_addr dest, const void *src, size_t len)
{
while (len) {
if (kl_gen_command(f->t, FTFA_CMD_PROGRAM_LONGWORD, dest, src)) {

View File

@ -47,9 +47,9 @@
#define LMI_FLASH_FMC_COMT (1 << 3)
#define LMI_FLASH_FMC_WRKEY 0xA4420000
static int lmi_flash_erase(struct target_flash *f, uint32_t addr, size_t len);
static int lmi_flash_erase(struct target_flash *f, target_addr addr, size_t len);
static int lmi_flash_write(struct target_flash *f,
uint32_t dest, const void *src, size_t len);
target_addr dest, const void *src, size_t len);
static const char lmi_driver_str[] = "TI Stellaris/Tiva";
@ -89,7 +89,7 @@ bool lmi_probe(target *t)
return false;
}
int lmi_flash_erase(struct target_flash *f, uint32_t addr, size_t len)
int lmi_flash_erase(struct target_flash *f, target_addr addr, size_t len)
{
target *t = f->t;
while(len) {
@ -106,7 +106,7 @@ int lmi_flash_erase(struct target_flash *f, uint32_t addr, size_t len)
}
int lmi_flash_write(struct target_flash *f,
uint32_t dest, const void *src, size_t len)
target_addr dest, const void *src, size_t len)
{
target *t = f->t;

View File

@ -50,7 +50,7 @@ static bool lpc43xx_cmd_erase(target *t, int argc, const char *argv[]);
static bool lpc43xx_cmd_reset(target *t, int argc, const char *argv[]);
static bool lpc43xx_cmd_mkboot(target *t, int argc, const char *argv[]);
static int lpc43xx_flash_init(target *t);
static int lpc43xx_flash_erase(struct target_flash *f, uint32_t addr, size_t len);
static int lpc43xx_flash_erase(struct target_flash *f, target_addr addr, size_t len);
static void lpc43xx_set_internal_clock(target *t);
static void lpc43xx_wdt_set_period(target *t);
static void lpc43xx_wdt_pet(target *t);
@ -194,7 +194,7 @@ static int lpc43xx_flash_init(target *t)
return 0;
}
static int lpc43xx_flash_erase(struct target_flash *f, uint32_t addr, size_t len)
static int lpc43xx_flash_erase(struct target_flash *f, target_addr addr, size_t len)
{
if (lpc43xx_flash_init(f->t))
return -1;

View File

@ -33,7 +33,7 @@ struct flash_param {
} __attribute__((aligned(4)));
struct lpc_flash *lpc_add_flash(target *t, uint32_t addr, size_t length)
struct lpc_flash *lpc_add_flash(target *t, target_addr addr, size_t length)
{
struct lpc_flash *lf = calloc(1, sizeof(*lf));
struct target_flash *f = &lf->f;
@ -94,7 +94,7 @@ static uint8_t lpc_sector_for_addr(struct lpc_flash *f, uint32_t addr)
return f->base_sector + (addr - f->f.start) / f->f.blocksize;
}
int lpc_flash_erase(struct target_flash *tf, uint32_t addr, size_t len)
int lpc_flash_erase(struct target_flash *tf, target_addr addr, size_t len)
{
struct lpc_flash *f = (struct lpc_flash *)tf;
uint32_t start = lpc_sector_for_addr(f, addr);
@ -115,7 +115,7 @@ int lpc_flash_erase(struct target_flash *tf, uint32_t addr, size_t len)
}
int lpc_flash_write(struct target_flash *tf,
uint32_t dest, const void *src, size_t len)
target_addr dest, const void *src, size_t len)
{
struct lpc_flash *f = (struct lpc_flash *)tf;
/* prepare... */
@ -135,7 +135,7 @@ int lpc_flash_write(struct target_flash *tf,
}
int lpc_flash_write_magic_vect(struct target_flash *f,
uint32_t dest, const void *src, size_t len)
target_addr dest, const void *src, size_t len)
{
if (dest == 0) {
/* Fill in the magic vector to allow booting the flash */

View File

@ -58,13 +58,13 @@ struct lpc_flash {
uint32_t iap_msp;
};
struct lpc_flash *lpc_add_flash(target *t, uint32_t addr, size_t length);
struct lpc_flash *lpc_add_flash(target *t, target_addr addr, size_t length);
enum iap_status lpc_iap_call(struct lpc_flash *f, enum iap_cmd cmd, ...);
int lpc_flash_erase(struct target_flash *f, uint32_t addr, size_t len);
int lpc_flash_erase(struct target_flash *f, target_addr addr, size_t len);
int lpc_flash_write(struct target_flash *f,
uint32_t dest, const void *src, size_t len);
target_addr dest, const void *src, size_t len);
int lpc_flash_write_magic_vect(struct target_flash *f,
uint32_t dest, const void *src, size_t len);
target_addr dest, const void *src, size_t len);
#endif

View File

@ -26,9 +26,9 @@
#include "target_internal.h"
#include "cortexm.h"
static int nrf51_flash_erase(struct target_flash *f, uint32_t addr, size_t len);
static int nrf51_flash_erase(struct target_flash *f, target_addr addr, size_t len);
static int nrf51_flash_write(struct target_flash *f,
uint32_t dest, const void *src, size_t len);
target_addr dest, const void *src, size_t len);
static bool nrf51_cmd_erase_all(target *t);
static bool nrf51_cmd_read_hwid(target *t);
@ -172,7 +172,7 @@ bool nrf51_probe(target *t)
return false;
}
static int nrf51_flash_erase(struct target_flash *f, uint32_t addr, size_t len)
static int nrf51_flash_erase(struct target_flash *f, target_addr addr, size_t len)
{
target *t = f->t;
/* Enable erase */
@ -214,7 +214,7 @@ static int nrf51_flash_erase(struct target_flash *f, uint32_t addr, size_t len)
}
static int nrf51_flash_write(struct target_flash *f,
uint32_t dest, const void *src, size_t len)
target_addr dest, const void *src, size_t len)
{
target *t = f->t;
uint32_t data[2 + len/4];

View File

@ -28,9 +28,9 @@
#include "target.h"
#include "target_internal.h"
static int sam4_flash_erase(struct target_flash *f, uint32_t addr, size_t len);
static int sam3_flash_erase(struct target_flash *f, uint32_t addr, size_t len);
static int sam3x_flash_write(struct target_flash *f, uint32_t dest,
static int sam4_flash_erase(struct target_flash *f, target_addr addr, size_t len);
static int sam3_flash_erase(struct target_flash *f, target_addr addr, size_t len);
static int sam3x_flash_write(struct target_flash *f, target_addr dest,
const void *src, size_t len);
static bool sam3x_cmd_gpnvm_get(target *t);
@ -281,7 +281,7 @@ static uint32_t sam3x_flash_base(target *t)
return SAM3N_EEFC_BASE;
}
static int sam4_flash_erase(struct target_flash *f, uint32_t addr, size_t len)
static int sam4_flash_erase(struct target_flash *f, target_addr addr, size_t len)
{
target *t = f->t;
uint32_t base = ((struct sam_flash *)f)->eefc_base;
@ -304,7 +304,7 @@ static int sam4_flash_erase(struct target_flash *f, uint32_t addr, size_t len)
return 0;
}
static int sam3_flash_erase(struct target_flash *f, uint32_t addr, size_t len)
static int sam3_flash_erase(struct target_flash *f, target_addr addr, size_t len)
{
/* The SAM3X/SAM3N don't really have a page erase function.
* We do nothing here and use Erase/Write page in flash_write.
@ -313,7 +313,7 @@ static int sam3_flash_erase(struct target_flash *f, uint32_t addr, size_t len)
return 0;
}
static int sam3x_flash_write(struct target_flash *f, uint32_t dest,
static int sam3x_flash_write(struct target_flash *f, target_addr dest,
const void *src, size_t len)
{
target *t = f->t;

View File

@ -37,9 +37,9 @@
#include "target_internal.h"
#include "cortexm.h"
static int samd_flash_erase(struct target_flash *t, uint32_t addr, size_t len);
static int samd_flash_erase(struct target_flash *t, target_addr addr, size_t len);
static int samd_flash_write(struct target_flash *f,
uint32_t dest, const void *src, size_t len);
target_addr dest, const void *src, size_t len);
static bool samd_cmd_erase_all(target *t);
static bool samd_cmd_lock_flash(target *t);
@ -457,7 +457,7 @@ static void samd_unlock_current_address(target *t)
/**
* Erase flash row by row
*/
static int samd_flash_erase(struct target_flash *f, uint32_t addr, size_t len)
static int samd_flash_erase(struct target_flash *f, target_addr addr, size_t len)
{
target *t = f->t;
while (len) {
@ -490,7 +490,7 @@ static int samd_flash_erase(struct target_flash *f, uint32_t addr, size_t len)
* Write flash page by page
*/
static int samd_flash_write(struct target_flash *f,
uint32_t dest, const void *src, size_t len)
target_addr dest, const void *src, size_t len)
{
target *t = f->t;

View File

@ -45,9 +45,9 @@ const struct command_s stm32f1_cmd_list[] = {
static int stm32f1_flash_erase(struct target_flash *f,
uint32_t addr, size_t len);
target_addr addr, size_t len);
static int stm32f1_flash_write(struct target_flash *f,
uint32_t dest, const void *src, size_t len);
target_addr dest, const void *src, size_t len);
/* Flash Program ad Erase Controller Register Map */
#define FPEC_BASE 0x40022000
@ -179,7 +179,7 @@ static void stm32f1_flash_unlock(target *t)
}
static int stm32f1_flash_erase(struct target_flash *f,
uint32_t addr, size_t len)
target_addr addr, size_t len)
{
target *t = f->t;
uint16_t sr;
@ -212,7 +212,7 @@ static int stm32f1_flash_erase(struct target_flash *f,
}
static int stm32f1_flash_write(struct target_flash *f,
uint32_t dest, const void *src, size_t len)
target_addr dest, const void *src, size_t len)
{
target *t = f->t;
/* Write stub and data to target ram and set PC */

View File

@ -45,9 +45,9 @@ const struct command_s stm32f4_cmd_list[] = {
};
static int stm32f4_flash_erase(struct target_flash *f, uint32_t addr, size_t len);
static int stm32f4_flash_erase(struct target_flash *f, target_addr addr, size_t len);
static int stm32f4_flash_write(struct target_flash *f,
uint32_t dest, const void *src, size_t len);
target_addr dest, const void *src, size_t len);
static const char stm32f4_driver_str[] = "STM32F4xx";
static const char stm32f7_driver_str[] = "STM32F7xx";
@ -219,7 +219,7 @@ static void stm32f4_flash_unlock(target *t)
}
}
static int stm32f4_flash_erase(struct target_flash *f, uint32_t addr, size_t len)
static int stm32f4_flash_erase(struct target_flash *f, target_addr addr, size_t len)
{
target *t = f->t;
uint16_t sr;
@ -254,7 +254,7 @@ static int stm32f4_flash_erase(struct target_flash *f, uint32_t addr, size_t len
}
static int stm32f4_flash_write(struct target_flash *f,
uint32_t dest, const void *src, size_t len)
target_addr dest, const void *src, size_t len)
{
/* Write buffer to target ram call stub */
target_mem_write(f->t, SRAM_BASE, stm32f4_flash_write_stub,

View File

@ -142,16 +142,16 @@
#define STM32L1_NVM_OPTR_SPRMOD (1<<8)
static int stm32lx_nvm_prog_erase(struct target_flash* f,
uint32_t addr, size_t len);
target_addr addr, size_t len);
static int stm32lx_nvm_prog_write(struct target_flash* f,
uint32_t destination,
target_addr destination,
const void* src,
size_t size);
static int stm32lx_nvm_data_erase(struct target_flash* f,
uint32_t addr, size_t len);
target_addr addr, size_t len);
static int stm32lx_nvm_data_write(struct target_flash* f,
uint32_t destination,
target_addr destination,
const void* source,
size_t size);
@ -322,7 +322,7 @@ static bool stm32lx_nvm_opt_unlock(target *t, uint32_t nvm)
flash array is erased for all pages from addr to addr+len
inclusive. NVM register file address chosen from target. */
static int stm32lx_nvm_prog_erase(struct target_flash* f,
uint32_t addr, size_t len)
target_addr addr, size_t len)
{
target *t = f->t;
const size_t page_size = f->blocksize;
@ -372,7 +372,7 @@ static int stm32lx_nvm_prog_erase(struct target_flash* f,
/** Write to program flash using operations through the debug
interface. */
static int stm32lx_nvm_prog_write(struct target_flash *f,
uint32_t dest,
target_addr dest,
const void* src,
size_t size)
{
@ -415,7 +415,7 @@ static int stm32lx_nvm_prog_write(struct target_flash *f,
addr+len, inclusive, on a word boundary. NVM register file
address chosen from target. */
static int stm32lx_nvm_data_erase(struct target_flash *f,
uint32_t addr, size_t len)
target_addr addr, size_t len)
{
target *t = f->t;
const size_t page_size = f->blocksize;
@ -467,7 +467,7 @@ static int stm32lx_nvm_data_erase(struct target_flash *f,
destination writes are supported (though unaligned sources are
not). */
static int stm32lx_nvm_data_write(struct target_flash *f,
uint32_t destination,
target_addr destination,
const void* src,
size_t size)
{

View File

@ -49,9 +49,9 @@ const struct command_s stm32l4_cmd_list[] = {
};
static int stm32l4_flash_erase(struct target_flash *f, uint32_t addr, size_t len);
static int stm32l4_flash_erase(struct target_flash *f, target_addr addr, size_t len);
static int stm32l4_flash_write(struct target_flash *f,
uint32_t dest, const void *src, size_t len);
target_addr dest, const void *src, size_t len);
static const char stm32l4_driver_str[] = "STM32L4xx";
@ -171,7 +171,7 @@ static void stm32l4_flash_unlock(target *t)
}
}
static int stm32l4_flash_erase(struct target_flash *f, uint32_t addr, size_t len)
static int stm32l4_flash_erase(struct target_flash *f, target_addr addr, size_t len)
{
target *t = f->t;
uint16_t sr;
@ -212,7 +212,7 @@ static int stm32l4_flash_erase(struct target_flash *f, uint32_t addr, size_t len
}
static int stm32l4_flash_write(struct target_flash *f,
uint32_t dest, const void *src, size_t len)
target_addr dest, const void *src, size_t len)
{
/* Write buffer to target ram call stub */
target_mem_write(f->t, SRAM_BASE, stm32l4_flash_write_stub,

View File

@ -116,7 +116,7 @@ target *target_attach(target *t, struct target_controller *tc)
return t;
}
void target_add_ram(target *t, uint32_t start, uint32_t len)
void target_add_ram(target *t, target_addr start, uint32_t len)
{
struct target_ram *ram = malloc(sizeof(*ram));
ram->start = start;
@ -135,7 +135,7 @@ void target_add_flash(target *t, struct target_flash *f)
static ssize_t map_ram(char *buf, size_t len, struct target_ram *ram)
{
return snprintf(buf, len, "<memory type=\"ram\" start=\"0x%08"PRIx32
"\" length=\"0x%08"PRIx32"\"/>",
"\" length=\"0x%08zx\"/>",
ram->start, ram->length);
}
@ -143,9 +143,9 @@ static ssize_t map_flash(char *buf, size_t len, struct target_flash *f)
{
int i = 0;
i += snprintf(&buf[i], len - i, "<memory type=\"flash\" start=\"0x%08"PRIx32
"\" length=\"0x%08"PRIx32"\">",
"\" length=\"0x%08zx\">",
f->start, f->length);
i += snprintf(&buf[i], len - i, "<property name=\"blocksize\">0x%08"PRIx32
i += snprintf(&buf[i], len - i, "<property name=\"blocksize\">0x%08zx"
"</property></memory>",
f->blocksize);
return i;
@ -231,7 +231,7 @@ int target_flash_done(target *t)
}
int target_flash_write_buffered(struct target_flash *f,
uint32_t dest, const void *src, size_t len)
target_addr dest, const void *src, size_t len)
{
int ret = 0;

View File

@ -25,20 +25,20 @@ extern target *target_list;
target *target_new(void);
struct target_ram {
uint32_t start;
uint32_t length;
target_addr start;
size_t length;
struct target_ram *next;
};
struct target_flash;
typedef int (*flash_erase_func)(struct target_flash *f, uint32_t addr, size_t len);
typedef int (*flash_write_func)(struct target_flash *f, uint32_t dest,
typedef int (*flash_erase_func)(struct target_flash *f, target_addr addr, size_t len);
typedef int (*flash_write_func)(struct target_flash *f, target_addr dest,
const void *src, size_t len);
typedef int (*flash_done_func)(struct target_flash *f);
struct target_flash {
uint32_t start;
uint32_t length;
uint32_t blocksize;
target_addr start;
size_t length;
size_t blocksize;
flash_erase_func erase;
flash_write_func write;
flash_done_func done;
@ -50,7 +50,7 @@ struct target_flash {
/* For buffered flash */
size_t buf_size;
flash_write_func write_buf;
uint32_t buf_addr;
target_addr buf_addr;
void *buf;
};
@ -124,10 +124,10 @@ struct target_s {
};
void target_add_commands(target *t, const struct command_s *cmds, const char *name);
void target_add_ram(target *t, uint32_t start, uint32_t len);
void target_add_ram(target *t, target_addr start, uint32_t len);
void target_add_flash(target *t, struct target_flash *f);
int target_flash_write_buffered(struct target_flash *f,
uint32_t dest, const void *src, size_t len);
target_addr dest, const void *src, size_t len);
int target_flash_done_buffered(struct target_flash *f);
/* Convenience function for MMIO access */