Renamed target_flash_write_words to target_flash_write.

Buffer from GDB may not be aligned or integer number of words.
Corrected alignment in in STM32F1 driver.
This commit is contained in:
Gareth McMullin 2012-06-18 20:53:06 +12:00
parent bc7e7d2112
commit 6089a66dce
6 changed files with 36 additions and 33 deletions

View File

@ -426,7 +426,7 @@ handle_v_packet(char *packet, int plen)
/* Write Flash Memory */
len = plen - bin;
DEBUG("Flash Write %08lX %08lX\n", addr, len);
if(cur_target && target_flash_write_words(cur_target, addr, (void*)packet + bin, len) == 0)
if(cur_target && target_flash_write(cur_target, addr, (void*)packet + bin, len) == 0)
gdb_putpacketz("OK");
else
gdb_putpacketz("EFF");

View File

@ -103,8 +103,8 @@
#define target_flash_erase(target, addr, len) \
(target)->flash_erase((target), (addr), (len))
#define target_flash_write_words(target, dest, src, len) \
(target)->flash_write_words((target), (dest), (src), (len))
#define target_flash_write(target, dest, src, len) \
(target)->flash_write((target), (dest), (src), (len))
#define TARGET_LIST_FREE() { \
@ -165,8 +165,8 @@ typedef struct target_s {
/* Flash memory access functions */
const char *xml_mem_map;
int (*flash_erase)(struct target_s *target, uint32_t addr, int len);
int (*flash_write_words)(struct target_s *target, uint32_t dest,
const uint32_t *src, int len);
int (*flash_write)(struct target_s *target, uint32_t dest,
const uint8_t *src, int len);
const char *driver;

View File

@ -35,8 +35,8 @@
#include "target.h"
static int lmi_flash_erase(struct target_s *target, uint32_t addr, int len);
static int lmi_flash_write_words(struct target_s *target, uint32_t dest,
const uint32_t *src, int len);
static int lmi_flash_write(struct target_s *target, uint32_t dest,
const uint8_t *src, int len);
static const char lmi_driver_str[] = "LuminaryMicro Stellaris";
@ -96,7 +96,7 @@ int lmi_probe(struct target_s *target)
target->driver = lmi_driver_str;
target->xml_mem_map = lmi_xml_memory_map;
target->flash_erase = lmi_flash_erase;
target->flash_write_words = lmi_flash_write_words;
target->flash_write = lmi_flash_write;
return 0;
}
@ -131,8 +131,8 @@ int lmi_flash_erase(struct target_s *target, uint32_t addr, int len)
return 0;
}
int lmi_flash_write_words(struct target_s *target, uint32_t dest,
const uint32_t *src, int len)
int lmi_flash_write(struct target_s *target, uint32_t dest,
const uint8_t *src, int len)
{
uint32_t data[(len>>2)+2];
data[0] = dest;

View File

@ -47,7 +47,7 @@ static struct flash_program flash_pgm;
static void lpc11x_iap_call(struct target_s *target, struct flash_param *param, unsigned param_len);
static int lpc11xx_flash_prepare(struct target_s *target, uint32_t addr, int len);
static int lpc11xx_flash_erase(struct target_s *target, uint32_t addr, int len);
static int lpc11xx_flash_write_words(struct target_s *target, uint32_t dest, const uint32_t *src,
static int lpc11xx_flash_write(struct target_s *target, uint32_t dest, const uint8_t *src,
int len);
/*
@ -100,7 +100,7 @@ lpc11xx_probe(struct target_s *target)
target->driver = "lpc11xx";
target->xml_mem_map = lpc11xx_xml_memory_map;
target->flash_erase = lpc11xx_flash_erase;
target->flash_write_words = lpc11xx_flash_write_words;
target->flash_write = lpc11xx_flash_write;
return 0;
@ -185,9 +185,8 @@ lpc11xx_flash_erase(struct target_s *target, uint32_t addr, int len)
}
static int
lpc11xx_flash_write_words(struct target_s *target, uint32_t dest, const uint32_t *src, int len)
lpc11xx_flash_write(struct target_s *target, uint32_t dest, const uint8_t *src, int len)
{
const uint8_t *s = (const uint8_t *)src;
unsigned first_chunk = dest / IAP_PGM_CHUNKSIZE;
unsigned last_chunk = (dest + len - 1) / IAP_PGM_CHUNKSIZE;
unsigned chunk_offset = dest % IAP_PGM_CHUNKSIZE;
@ -206,11 +205,11 @@ lpc11xx_flash_write_words(struct target_s *target, uint32_t dest, const uint32_t
int copylen = IAP_PGM_CHUNKSIZE - chunk_offset;
if (copylen > len)
copylen = len;
memcpy(&flash_pgm.data[chunk_offset], s, copylen);
memcpy(&flash_pgm.data[chunk_offset], src, copylen);
/* update to suit */
len -= copylen;
s += copylen;
src += copylen;
chunk_offset = 0;
/* if we are programming the vectors, calculate the magic number */
@ -226,9 +225,9 @@ lpc11xx_flash_write_words(struct target_s *target, uint32_t dest, const uint32_t
} else {
/* interior chunk, must be aligned and full-sized */
memcpy(flash_pgm.data, s, IAP_PGM_CHUNKSIZE);
memcpy(flash_pgm.data, src, IAP_PGM_CHUNKSIZE);
len -= IAP_PGM_CHUNKSIZE;
s += IAP_PGM_CHUNKSIZE;
src += IAP_PGM_CHUNKSIZE;
}
/* prepare... */

View File

@ -40,8 +40,8 @@ static int stm32md_flash_erase(struct target_s *target, uint32_t addr, int len);
static int stm32hd_flash_erase(struct target_s *target, uint32_t addr, int len);
static int stm32f1_flash_erase(struct target_s *target, uint32_t addr, int len,
uint32_t pagesize);
static int stm32f1_flash_write_words(struct target_s *target, uint32_t dest,
const uint32_t *src, int len);
static int stm32f1_flash_write(struct target_s *target, uint32_t dest,
const uint8_t *src, int len);
static const char stm32f1_driver_str[] = "STM32, Medium density.";
static const char stm32hd_driver_str[] = "STM32, High density.";
@ -136,7 +136,7 @@ int stm32f1_probe(struct target_s *target)
target->driver = stm32f1_driver_str;
target->xml_mem_map = stm32f1_xml_memory_map;
target->flash_erase = stm32md_flash_erase;
target->flash_write_words = stm32f1_flash_write_words;
target->flash_write = stm32f1_flash_write;
return 0;
case 0x414: /* High density */
case 0x418: /* Connectivity Line */
@ -144,7 +144,7 @@ int stm32f1_probe(struct target_s *target)
target->driver = stm32hd_driver_str;
target->xml_mem_map = stm32hd_xml_memory_map;
target->flash_erase = stm32hd_flash_erase;
target->flash_write_words = stm32f1_flash_write_words;
target->flash_write = stm32f1_flash_write;
return 0;
default:
return -1;
@ -197,16 +197,20 @@ static int stm32md_flash_erase(struct target_s *target, uint32_t addr, int len)
return stm32f1_flash_erase(target, addr, len, 0x400);
}
static int stm32f1_flash_write_words(struct target_s *target, uint32_t dest,
const uint32_t *src, int len)
static int stm32f1_flash_write(struct target_s *target, uint32_t dest,
const uint8_t *src, int len)
{
ADIv5_AP_t *ap = adiv5_target_ap(target);
uint32_t data[(len>>2)+2];
uint32_t offset = dest % 4;
uint32_t words = (offset + len + 3) / 4;
uint32_t data[2 + words];
/* Construct data buffer used by stub */
data[0] = dest & 0xFFFFFFFE;
data[1] = len & 0xFFFFFFFE;
memcpy(&data[2], src, len);
data[0] = dest - offset;
data[1] = words * 4; /* length must always be a multiple of 4 */
data[2] = 0xFFFFFFFF; /* pad partial words with all 1s to avoid */
data[words + 1] = 0xFFFFFFFF; /* damaging overlapping areas */
memcpy((uint8_t *)&data[2] + offset, src, len);
/* Write stub and data to target ram and set PC */
target_mem_write_words(target, 0x20000000, (void*)stm32f1_flash_write_stub, 0x2C);

View File

@ -38,8 +38,8 @@
#include "target.h"
static int stm32f4_flash_erase(struct target_s *target, uint32_t addr, int len);
static int stm32f4_flash_write_words(struct target_s *target, uint32_t dest, const uint32_t *src,
int len);
static int stm32f4_flash_write(struct target_s *target, uint32_t dest,
const uint8_t *src, int len);
static const char stm32f4_driver_str[] = "STM32F4xx";
@ -143,7 +143,7 @@ int stm32f4_probe(struct target_s *target)
target->driver = stm32f4_driver_str;
target->xml_mem_map = stm32f4_xml_memory_map;
target->flash_erase = stm32f4_flash_erase;
target->flash_write_words = stm32f4_flash_write_words;
target->flash_write = stm32f4_flash_write;
return 0;
}
return -1;
@ -198,8 +198,8 @@ static int stm32f4_flash_erase(struct target_s *target, uint32_t addr, int len)
return 0;
}
static int stm32f4_flash_write_words(struct target_s *target, uint32_t dest,
const uint32_t *src, int len)
static int stm32f4_flash_write(struct target_s *target, uint32_t dest,
const uint8_t *src, int len)
{
struct target_ap_s *t = (void *)target;
uint32_t offset = dest % 4;