target: target_flash type cleanup

This commit is contained in:
Rafael Silva 2022-08-19 17:56:41 +01:00 committed by Rachel Mant
parent 31adb2f94d
commit 21922676f9
28 changed files with 218 additions and 258 deletions

View File

@ -478,10 +478,10 @@ found_targets:
uint32_t lowest_flash_start = 0xffffffff;
uint32_t lowest_flash_size = 0;
int n_flash = 0;
for (struct target_flash *f = t->flash; f; f = f->next)
for (target_flash_s *f = t->flash; f; f = f->next)
n_flash++;
for (int n = n_flash; n >= 0; n --) {
struct target_flash *f = t->flash;
for (int n = n_flash; n >= 0; n--) {
target_flash_s *f = t->flash;
for (int i = 1; f; f = f->next, i++)
if (i == n) {
DEBUG_INFO("Flash Start: 0x%08" PRIx32 " length = 0x%" PRIx32

View File

@ -34,10 +34,8 @@
extern const struct command_s stm32f1_cmd_list[]; // Reuse stm32f1 stuff
static int ch32f1_flash_erase(struct target_flash *f,
target_addr addr, size_t len);
static int ch32f1_flash_write(struct target_flash *f,
target_addr dest, const void *src, size_t len);
static int ch32f1_flash_erase(target_flash_s *f, target_addr addr, size_t len);
static int ch32f1_flash_write(target_flash_s *f, target_addr dest, const void *src, size_t len);
// these are common with stm32f1/gd32f1/...
#define FPEC_BASE 0x40022000
@ -73,8 +71,8 @@ static int ch32f1_flash_write(struct target_flash *f,
*/
static void ch32f1_add_flash(target *t, uint32_t addr, size_t length, size_t erasesize)
{
struct target_flash *f = calloc(1, sizeof(*f));
if (!f) { /* calloc failed: heap exhaustion */
target_flash_s *f = calloc(1, sizeof(*f));
if (!f) { /* calloc failed: heap exhaustion */
DEBUG_WARN("calloc: failed in %s\n", __func__);
return;
}
@ -84,7 +82,7 @@ static void ch32f1_add_flash(target *t, uint32_t addr, size_t length, size_t era
f->blocksize = erasesize;
f->erase = ch32f1_flash_erase;
f->write = ch32f1_flash_write;
f->buf_size = erasesize;
f->writesize = erasesize;
f->erased = 0xff;
target_add_flash(t, f);
}
@ -202,7 +200,7 @@ bool ch32f1_probe(target *t)
\fn ch32f1_flash_erase
\brief fast erase of CH32
*/
int ch32f1_flash_erase(struct target_flash *f, target_addr addr, size_t len)
int ch32f1_flash_erase(target_flash_s *f, target_addr addr, size_t len)
{
volatile uint32_t sr, magic;
target *t = f->t;
@ -299,8 +297,7 @@ static int ch32f1_buffer_clear(target *t)
/**
*/
static int ch32f1_flash_write(struct target_flash *f,
target_addr dest, const void *src, size_t len)
static int ch32f1_flash_write(target_flash_s *f, target_addr dest, const void *src, size_t len)
{
volatile uint32_t sr, magic;
target *t = f->t;

View File

@ -45,8 +45,8 @@
#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, target_addr addr, size_t len);
static int efm32_flash_write(struct target_flash *f, target_addr dest, const void *src, size_t len);
static int efm32_flash_erase(target_flash_s *f, target_addr addr, size_t len);
static int efm32_flash_write(target_flash_s *f, target_addr dest, const void *src, size_t len);
static bool efm32_mass_erase(target *t);
static const uint16_t efm32_flash_write_stub[] = {
@ -496,7 +496,7 @@ static efm32_v2_di_miscchip_t efm32_v2_read_miscchip(target *t, uint8_t di_versi
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));
target_flash_s *f = calloc(1, sizeof(*f));
if (!f) { /* calloc failed: heap exhaustion */
DEBUG_WARN("calloc: failed in %s\n", __func__);
return;
@ -507,7 +507,7 @@ static void efm32_add_flash(target *t, target_addr addr, size_t length, size_t p
f->blocksize = page_size;
f->erase = efm32_flash_erase;
f->write = efm32_flash_write;
f->buf_size = page_size;
f->writesize = page_size;
target_add_flash(t, f);
}
@ -595,7 +595,7 @@ bool efm32_probe(target *t)
}
/* Erase flash row by row */
static int efm32_flash_erase(struct target_flash *f, target_addr addr, size_t len)
static int efm32_flash_erase(target_flash_s *f, target_addr addr, size_t len)
{
target *t = f->t;
@ -636,7 +636,7 @@ static int efm32_flash_erase(struct target_flash *f, target_addr addr, size_t le
}
/* Write flash page by page */
static int efm32_flash_write(struct target_flash *f, target_addr dest, const void *src, size_t len)
static int efm32_flash_write(target_flash_s *f, target_addr dest, const void *src, size_t len)
{
(void)len;

View File

@ -111,12 +111,12 @@ static bool kinetis_cmd_unsafe(target *t, int argc, char **argv)
return true;
}
static int kinetis_flash_cmd_erase(struct target_flash *f, target_addr addr, size_t len);
static int kinetis_flash_cmd_write(struct target_flash *f, target_addr dest, const void *src, size_t len);
static int kinetis_flash_done(struct target_flash *f);
static int kinetis_flash_cmd_erase(target_flash_s *f, target_addr addr, size_t len);
static int kinetis_flash_cmd_write(target_flash_s *f, target_addr dest, const void *src, size_t len);
static int kinetis_flash_done(target_flash_s *f);
struct kinetis_flash {
struct target_flash f;
target_flash_s f;
uint8_t write_len;
};
@ -124,7 +124,7 @@ static void kinetis_add_flash(
target *const t, const uint32_t addr, const size_t length, const size_t erasesize, const size_t write_len)
{
struct kinetis_flash *kf = calloc(1, sizeof(*kf));
struct target_flash *f;
target_flash_s *f;
if (!kf) { /* calloc failed: heap exhaustion */
DEBUG_WARN("calloc: failed in %s\n", __func__);
@ -432,7 +432,7 @@ static bool kinetis_fccob_cmd(target *t, uint8_t cmd, uint32_t addr, const uint3
return true;
}
static int kinetis_flash_cmd_erase(struct target_flash *const f, target_addr addr, size_t len)
static int kinetis_flash_cmd_erase(target_flash_s *const f, target_addr addr, size_t len)
{
while (len) {
if (kinetis_fccob_cmd(f->t, FTFx_CMD_ERASE_SECTOR, addr, NULL, 0)) {
@ -449,7 +449,7 @@ static int kinetis_flash_cmd_erase(struct target_flash *const f, target_addr add
return 0;
}
static int kinetis_flash_cmd_write(struct target_flash *f, target_addr dest, const void *src, size_t len)
static int kinetis_flash_cmd_write(target_flash_s *f, target_addr dest, const void *src, size_t len)
{
struct kinetis_flash *const kf = (struct kinetis_flash *)f;
@ -479,7 +479,7 @@ static int kinetis_flash_cmd_write(struct target_flash *f, target_addr dest, con
return 0;
}
static int kinetis_flash_done(struct target_flash *const f)
static int kinetis_flash_done(target_flash_s *const f)
{
struct kinetis_flash *const kf = (struct kinetis_flash *)f;

View File

@ -60,8 +60,8 @@
#define LMI_FLASH_FMC_COMT (1 << 3)
#define LMI_FLASH_FMC_WRKEY 0xA4420000
static int lmi_flash_erase(struct target_flash *f, target_addr addr, size_t len);
static int lmi_flash_write(struct target_flash *f, target_addr dest, const void *src, size_t len);
static int lmi_flash_erase(target_flash_s *f, target_addr addr, size_t len);
static int lmi_flash_write(target_flash_s *f, target_addr dest, const void *src, size_t len);
static bool lmi_mass_erase(target *t);
static const char lmi_driver_str[] = "TI Stellaris/Tiva";
@ -72,7 +72,7 @@ static const uint16_t lmi_flash_write_stub[] = {
static void lmi_add_flash(target *t, size_t length)
{
struct target_flash *f = calloc(1, sizeof(*f));
target_flash_s *f = calloc(1, sizeof(*f));
if (!f) { /* calloc failed: heap exhaustion */
DEBUG_WARN("calloc: failed in %s\n", __func__);
return;
@ -156,7 +156,7 @@ bool lmi_probe(target *const t)
}
}
static int lmi_flash_erase(struct target_flash *f, target_addr addr, const size_t len)
static int lmi_flash_erase(target_flash_s *f, target_addr addr, const size_t len)
{
target *t = f->t;
target_check_error(t);
@ -181,7 +181,7 @@ static int lmi_flash_erase(struct target_flash *f, target_addr addr, const size_
return 0;
}
static int lmi_flash_write(struct target_flash *f, target_addr dest, const void *src, size_t len)
static int lmi_flash_write(target_flash_s *f, target_addr dest, const void *src, size_t len)
{
target *t = f->t;
target_check_error(t);

View File

@ -64,7 +64,7 @@ static void lpc11xx_add_flash(target *t, const uint32_t addr, const size_t len,
{
struct lpc_flash *lf = lpc_add_flash(t, addr, len);
lf->f.blocksize = erase_block_len;
lf->f.buf_size = IAP_PGM_CHUNKSIZE;
lf->f.writesize = IAP_PGM_CHUNKSIZE;
lf->f.write = lpc_flash_write_magic_vect;
lf->iap_entry = iap_entry;
lf->iap_ram = IAP_RAM_BASE;

View File

@ -59,7 +59,7 @@ static void lpc15xx_add_flash(target *t, uint32_t addr, size_t len, size_t erase
{
struct lpc_flash *lf = lpc_add_flash(t, addr, len);
lf->f.blocksize = erasesize;
lf->f.buf_size = IAP_PGM_CHUNKSIZE;
lf->f.writesize = IAP_PGM_CHUNKSIZE;
lf->f.write = lpc_flash_write_magic_vect;
lf->iap_entry = IAP_ENTRYPOINT;
lf->iap_ram = IAP_RAM_BASE;

View File

@ -52,7 +52,7 @@ static void lpc17xx_add_flash(target *t, uint32_t addr, size_t len, size_t erase
struct lpc_flash *lf = lpc_add_flash(t, addr, len);
lf->f.blocksize = erasesize;
lf->base_sector = base_sector;
lf->f.buf_size = IAP_PGM_CHUNKSIZE;
lf->f.writesize = IAP_PGM_CHUNKSIZE;
lf->f.write = lpc_flash_write_magic_vect;
lf->iap_entry = IAP_ENTRYPOINT;
lf->iap_ram = IAP_RAM_BASE;

View File

@ -48,7 +48,7 @@
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, target_addr addr, size_t len);
static int lpc43xx_flash_erase(target_flash_s *f, target_addr addr, size_t len);
static bool lpc43xx_mass_erase(target *t);
static void lpc43xx_set_internal_clock(target *t);
static void lpc43xx_wdt_set_period(target *t);
@ -60,14 +60,13 @@ const struct command_s lpc43xx_cmd_list[] = {
{NULL, NULL, NULL}
};
static void lpc43xx_add_flash(target *t, uint32_t iap_entry,
uint8_t bank, uint8_t base_sector,
uint32_t addr, size_t len, size_t erasesize)
static void lpc43xx_add_flash(
target *t, uint32_t iap_entry, uint8_t bank, uint8_t base_sector, uint32_t addr, size_t len, size_t erasesize)
{
struct lpc_flash *lf = lpc_add_flash(t, addr, len);
lf->f.erase = lpc43xx_flash_erase;
lf->f.blocksize = erasesize;
lf->f.buf_size = IAP_PGM_CHUNKSIZE;
lf->f.writesize = IAP_PGM_CHUNKSIZE;
lf->bank = bank;
lf->base_sector = base_sector;
lf->iap_entry = iap_entry;
@ -187,7 +186,7 @@ static int lpc43xx_flash_init(target *t)
return 0;
}
static int lpc43xx_flash_erase(struct target_flash *f, target_addr addr, size_t len)
static int lpc43xx_flash_erase(target_flash_s *f, target_addr addr, size_t len)
{
if (lpc43xx_flash_init(f->t))
return -1;

View File

@ -54,7 +54,7 @@ static bool lpc546xx_cmd_write_sector(target *t, int argc, const char *argv[]);
static void lpc546xx_reset_attach(target *t);
static int lpc546xx_flash_init(target *t);
static int lpc546xx_flash_erase(struct target_flash *f, target_addr addr, size_t len);
static int lpc546xx_flash_erase(target_flash_s *f, target_addr addr, size_t len);
static bool lpc546xx_mass_erase(target *t);
static void lpc546xx_wdt_set_period(target *t);
static void lpc546xx_wdt_pet(target *t);
@ -73,9 +73,8 @@ const struct command_s lpc546xx_cmd_list[] = {
{ NULL, NULL, NULL }
};
static void lpc546xx_add_flash(target *t, uint32_t iap_entry,
uint8_t base_sector, uint32_t addr,
size_t len, size_t erasesize)
static void lpc546xx_add_flash(
target *t, uint32_t iap_entry, uint8_t base_sector, uint32_t addr, size_t len, size_t erasesize)
{
struct lpc_flash *lf = lpc_add_flash(t, addr, len);
lf->f.erase = lpc546xx_flash_erase;
@ -85,7 +84,7 @@ static void lpc546xx_add_flash(target *t, uint32_t iap_entry,
lf->f.write = lpc_flash_write_magic_vect;
lf->f.blocksize = erasesize;
lf->f.buf_size = IAP_PGM_CHUNKSIZE;
lf->f.writesize = IAP_PGM_CHUNKSIZE;
lf->bank = 0;
lf->base_sector = base_sector;
lf->iap_entry = iap_entry;
@ -292,7 +291,7 @@ static int lpc546xx_flash_init(target *t)
return 0;
}
static int lpc546xx_flash_erase(struct target_flash *tf, target_addr addr, size_t len)
static int lpc546xx_flash_erase(target_flash_s *tf, target_addr addr, size_t len)
{
if (lpc546xx_flash_init(tf->t))
return -1;

View File

@ -70,13 +70,12 @@ char *iap_error[] = {
"Page is invalid",
};
static int lpc_flash_write(struct target_flash *tf,
target_addr dest, const void *src, size_t len);
static int lpc_flash_write(target_flash_s *tf, target_addr dest, const void *src, size_t len);
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;
target_flash_s *f;
if (!lf) { /* calloc failed: heap exhaustion */
DEBUG_WARN("calloc: failed in %s\n", __func__);
@ -183,7 +182,7 @@ enum iap_status lpc_iap_call(struct lpc_flash *f, void *result, enum iap_cmd cmd
#define LPX80X_SECTOR_SIZE 0x400
#define LPX80X_PAGE_SIZE 0x40
int lpc_flash_erase(struct target_flash *tf, target_addr addr, size_t len)
int lpc_flash_erase(target_flash_s *tf, target_addr addr, size_t len)
{
struct lpc_flash *f = (struct lpc_flash *)tf;
const uint32_t start = lpc_sector_for_addr(f, addr);
@ -221,8 +220,7 @@ int lpc_flash_erase(struct target_flash *tf, target_addr addr, size_t len)
return 0;
}
static int lpc_flash_write(struct target_flash *tf,
target_addr dest, const void *src, size_t len)
static int lpc_flash_write(target_flash_s *tf, target_addr dest, const void *src, size_t len)
{
struct lpc_flash *f = (struct lpc_flash *)tf;
/* prepare... */
@ -259,8 +257,7 @@ static int lpc_flash_write(struct target_flash *tf,
return 0;
}
int lpc_flash_write_magic_vect(struct target_flash *f,
target_addr dest, const void *src, size_t len)
int lpc_flash_write_magic_vect(target_flash_s *f, target_addr dest, const void *src, size_t len)
{
if (dest == 0) {
/* Fill in the magic vector to allow booting the flash */

View File

@ -69,7 +69,7 @@ enum iap_status {
#define CPU_CLK_KHZ 12000
struct lpc_flash {
struct target_flash f;
target_flash_s f;
uint8_t base_sector;
uint8_t bank;
uint8_t reserved_pages;
@ -82,8 +82,7 @@ struct lpc_flash {
struct lpc_flash *lpc_add_flash(target *t, target_addr addr, size_t length);
enum iap_status lpc_iap_call(struct lpc_flash *f, void *result, enum iap_cmd cmd, ...);
int lpc_flash_erase(struct target_flash *f, target_addr addr, size_t len);
int lpc_flash_write_magic_vect(struct target_flash *f,
target_addr dest, const void *src, size_t len);
int lpc_flash_erase(target_flash_s *f, target_addr addr, size_t len);
int lpc_flash_write_magic_vect(target_flash_s *f, target_addr dest, const void *src, size_t len);
#endif /* TARGET_LPC_COMMON_H */

View File

@ -99,23 +99,21 @@
#define WDT_A_HOLD 0x5A88u /* Clears and halts the watchdog */
/* Support variables to call code in ROM */
struct msp432_flash
{
struct target_flash f;
struct msp432_flash {
target_flash_s f;
target_addr flash_protect_register; /* Address of the WEPROT register*/
target_addr FlashCtl_eraseSector; /* Erase flash sector routine in ROM*/
target_addr FlashCtl_programMemory; /* Flash programming routine in ROM */
};
/* Flash operations */
static bool msp432_sector_erase(struct target_flash *f, target_addr addr);
static int msp432_flash_erase(struct target_flash *f, target_addr addr, size_t len);
static int msp432_flash_write(struct target_flash *f, target_addr dest,
const void *src, size_t len);
static bool msp432_sector_erase(target_flash_s *f, target_addr addr);
static int msp432_flash_erase(target_flash_s *f, target_addr addr, size_t len);
static int msp432_flash_write(target_flash_s *f, target_addr dest, const void *src, size_t len);
/* Utility functions */
/* Find the the target flash that conatins a specific address */
static struct target_flash *get_target_flash(target *t, target_addr addr);
static target_flash_s *get_target_flash(target *t, target_addr addr);
/* Call a subroutine in the MSP432 ROM (or anywhere else...)*/
static void msp432_call_ROM(target *t, uint32_t address, uint32_t regs[]);
@ -148,8 +146,8 @@ const struct command_s msp432_cmd_list[] = {
static void msp432_add_flash(target *t, uint32_t addr, size_t length, target_addr prot_reg)
{
struct msp432_flash *mf = calloc(1, sizeof(*mf));
struct target_flash *f;
if (!mf) { /* calloc failed: heap exhaustion */
target_flash_s *f;
if (!mf) { /* calloc failed: heap exhaustion */
DEBUG_WARN("calloc: failed in %s\n", __func__);
return;
}
@ -160,16 +158,13 @@ static void msp432_add_flash(target *t, uint32_t addr, size_t length, target_add
f->blocksize = SECTOR_SIZE;
f->erase = msp432_flash_erase;
f->write = msp432_flash_write;
f->buf_size = SRAM_WRITE_BUF_SIZE;
f->writesize = SRAM_WRITE_BUF_SIZE;
f->erased = 0xff;
target_add_flash(t, f);
/* Initialize ROM call pointers. Silicon rev B is not supported */
uint32_t flashctltable =
target_mem_read32(t, ROM_APITABLE + OFS_FLASHCTLTABLE);
mf->FlashCtl_eraseSector =
target_mem_read32(t, flashctltable + OFS_FlashCtl_eraseSector);
mf->FlashCtl_programMemory =
target_mem_read32(t, flashctltable + OFS_FlashCtl_programMemory);
uint32_t flashctltable = target_mem_read32(t, ROM_APITABLE + OFS_FLASHCTLTABLE);
mf->FlashCtl_eraseSector = target_mem_read32(t, flashctltable + OFS_FlashCtl_eraseSector);
mf->FlashCtl_programMemory = target_mem_read32(t, flashctltable + OFS_FlashCtl_programMemory);
mf->flash_protect_register = prot_reg;
}
@ -232,7 +227,7 @@ bool msp432_probe(target *t)
/* Flash operations */
/* Erase a single sector at addr calling the ROM routine*/
static bool msp432_sector_erase(struct target_flash *f, target_addr addr)
static bool msp432_sector_erase(target_flash_s *f, target_addr addr)
{
target *t = f->t;
struct msp432_flash *mf = (struct msp432_flash *)f;
@ -262,7 +257,7 @@ static bool msp432_sector_erase(struct target_flash *f, target_addr addr)
}
/* Erase from addr for len bytes */
static int msp432_flash_erase(struct target_flash *f, target_addr addr, size_t len)
static int msp432_flash_erase(target_flash_s *f, target_addr addr, size_t len)
{
int ret = 0;
while (len) {
@ -280,8 +275,7 @@ static int msp432_flash_erase(struct target_flash *f, target_addr addr, size_t l
}
/* Program flash */
static int msp432_flash_write(struct target_flash *f, target_addr dest,
const void *src, size_t len)
static int msp432_flash_write(target_flash_s *f, target_addr dest, const void *src, size_t len)
{
struct msp432_flash *mf = (struct msp432_flash *)f;
target *t = f->t;
@ -326,7 +320,7 @@ static bool msp432_cmd_erase_main(target *t, int argc, const char **argv)
DEBUG_INFO("Bank Size: 0x%08"PRIX32"\n", banksize);
/* Erase first bank */
struct target_flash *f = get_target_flash(t, MAIN_FLASH_BASE);
target_flash_s *f = get_target_flash(t, MAIN_FLASH_BASE);
bool ret = msp432_flash_erase(f, MAIN_FLASH_BASE, banksize);
/* Erase second bank */
@ -344,7 +338,7 @@ static bool msp432_cmd_sector_erase(target *t, int argc, const char **argv)
uint32_t addr = strtoul(argv[1], NULL, 0);
/* Find the flash structure (for the rigth protect register) */
struct target_flash *f = get_target_flash(t, addr);
target_flash_s *f = get_target_flash(t, addr);
if (f)
return msp432_sector_erase(f, addr);
@ -353,9 +347,9 @@ static bool msp432_cmd_sector_erase(target *t, int argc, const char **argv)
}
/* Returns flash bank containing addr, or NULL if not found */
static struct target_flash *get_target_flash(target *t, target_addr addr)
static target_flash_s *get_target_flash(target *t, target_addr addr)
{
struct target_flash *f = t->flash;
target_flash_s *f = t->flash;
while (f) {
if ((f->start <= addr) && (addr < f->start + f->length))
break;

View File

@ -27,9 +27,8 @@
#include "cortexm.h"
#include "adiv5.h"
static int nrf51_flash_erase(struct target_flash *f, target_addr addr, size_t len);
static int nrf51_flash_write(struct target_flash *f,
target_addr dest, const void *src, size_t len);
static int nrf51_flash_erase(target_flash_s *f, target_addr addr, size_t len);
static int nrf51_flash_write(target_flash_s *f, target_addr dest, const void *src, size_t len);
static bool nrf51_mass_erase(target *t);
static bool nrf51_cmd_erase_uicr(target *t, int argc, const char **argv);
@ -104,7 +103,7 @@ const struct command_s nrf51_read_cmd_list[] = {
static void nrf51_add_flash(target *t,
uint32_t addr, size_t length, size_t erasesize)
{
struct target_flash *f = calloc(1, sizeof(*f));
target_flash_s *f = calloc(1, sizeof(*f));
if (!f) { /* calloc failed: heap exhaustion */
DEBUG_WARN("calloc: failed in %s\n", __func__);
return;
@ -160,7 +159,7 @@ bool nrf51_probe(target *t)
return true;
}
static int nrf51_flash_erase(struct target_flash *f, target_addr addr, size_t len)
static int nrf51_flash_erase(target_flash_s *f, target_addr addr, size_t len)
{
target *t = f->t;
/* Enable erase */
@ -204,8 +203,7 @@ static int nrf51_flash_erase(struct target_flash *f, target_addr addr, size_t le
return 0;
}
static int nrf51_flash_write(struct target_flash *f,
target_addr dest, const void *src, size_t len)
static int nrf51_flash_write(target_flash_s *f, target_addr dest, const void *src, size_t len)
{
target *t = f->t;

View File

@ -116,10 +116,9 @@ static const uint8_t cmdLen[] = {
/* Flash routines */
static bool ke04_command(target *t, uint8_t cmd, uint32_t addr, const uint8_t data[8]);
static int ke04_flash_erase(struct target_flash *f, target_addr addr, size_t len);
static int ke04_flash_write(struct target_flash *f,
target_addr dest, const void *src, size_t len);
static int ke04_flash_done(struct target_flash *f);
static int ke04_flash_erase(target_flash_s *f, target_addr addr, size_t len);
static int ke04_flash_write(target_flash_s *f, target_addr dest, const void *src, size_t len);
static int ke04_flash_done(target_flash_s *f);
static bool ke04_mass_erase(target *t);
/* Target specific commands */
@ -138,7 +137,7 @@ static bool ke04_cmd_sector_erase(target *t, int argc, char **argv)
tc_printf(t, "usage: monitor sector_erase <addr>\n");
char *eos;
struct target_flash *f = t->flash;
target_flash_s *f = t->flash;
uint32_t addr = strtoul(argv[1], &eos, 0);
/* check that addr is a valid number and inside the flash range */
@ -224,8 +223,8 @@ bool ke04_probe(target *t)
target_add_ram(t, RAM_BASE_ADDR, ramsize); /* Higher RAM */
/* Add flash, all KE04 have same write and erase size */
struct target_flash *f = calloc(1, sizeof(*f));
if (!f) { /* calloc failed: heap exhaustion */
target_flash_s *f = calloc(1, sizeof(*f));
if (!f) { /* calloc failed: heap exhaustion */
DEBUG_WARN("calloc: failed in %s\n", __func__);
return false;
}
@ -323,7 +322,7 @@ static bool ke04_command(target *t, uint8_t cmd, uint32_t addr, const uint8_t da
return true;
}
static int ke04_flash_erase(struct target_flash *f, target_addr addr, size_t len)
static int ke04_flash_erase(target_flash_s *f, target_addr addr, size_t len)
{
while (len) {
if (ke04_command(f->t, CMD_ERASE_FLASH_SECTOR, addr, NULL)) {
@ -337,8 +336,7 @@ static int ke04_flash_erase(struct target_flash *f, target_addr addr, size_t len
return 0;
}
static int ke04_flash_write(struct target_flash *f,
target_addr dest, const void *src, size_t len)
static int ke04_flash_write(target_flash_s *f, target_addr dest, const void *src, size_t len)
{
/* Ensure we don't write something horrible over the security byte */
target *t = f->t;
@ -361,7 +359,7 @@ static int ke04_flash_write(struct target_flash *f,
return 0;
}
static int ke04_flash_done(struct target_flash *f)
static int ke04_flash_done(target_flash_s *f)
{
target *t = f->t;
if (t->unsafe_enabled)

View File

@ -193,7 +193,7 @@ static void rp_add_flash(target *t)
f->blocksize = spi_parameters.sector_size;
f->erase = rp_flash_erase;
f->write = rp_flash_write;
f->buf_size = 2048; /* Max buffer size used otherwise */
f->writesize = 2048; /* Max buffer size used otherwise */
f->erased = 0xffU;
target_add_flash(t, f);

View File

@ -28,10 +28,9 @@
#include "target.h"
#include "target_internal.h"
static int sam_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 sam_flash_write(struct target_flash *f, target_addr dest,
const void *src, size_t len);
static int sam_flash_erase(target_flash_s *f, target_addr addr, size_t len);
static int sam3_flash_erase(target_flash_s *f, target_addr addr, size_t len);
static int sam_flash_write(target_flash_s *f, target_addr dest, const void *src, size_t len);
static int sam_gpnvm_get(target *t, uint32_t base, uint32_t *gpnvm);
@ -173,7 +172,7 @@ enum sam_driver {
};
struct sam_flash {
struct target_flash f;
target_flash_s f;
uint32_t eefc_base;
uint8_t write_cmd;
};
@ -192,11 +191,10 @@ struct sam_priv_s {
char sam_variant_string[16];
};
static void sam3_add_flash(target *t,
uint32_t eefc_base, uint32_t addr, size_t length)
static void sam3_add_flash(target *t, uint32_t eefc_base, uint32_t addr, size_t length)
{
struct sam_flash *sf = calloc(1, sizeof(*sf));
struct target_flash *f;
target_flash_s *f;
if (!sf) { /* calloc failed: heap exhaustion */
DEBUG_WARN("calloc: failed in %s\n", __func__);
@ -209,17 +207,16 @@ static void sam3_add_flash(target *t,
f->blocksize = SAM_SMALL_PAGE_SIZE;
f->erase = sam3_flash_erase;
f->write = sam_flash_write;
f->buf_size = SAM_SMALL_PAGE_SIZE;
f->writesize = SAM_SMALL_PAGE_SIZE;
sf->eefc_base = eefc_base;
sf->write_cmd = EEFC_FCR_FCMD_EWP;
target_add_flash(t, f);
}
static void sam_add_flash(target *t,
uint32_t eefc_base, uint32_t addr, size_t length)
static void sam_add_flash(target *t, uint32_t eefc_base, uint32_t addr, size_t length)
{
struct sam_flash *sf = calloc(1, sizeof(*sf));
struct target_flash *f;
target_flash_s *f;
if (!sf) { /* calloc failed: heap exhaustion */
DEBUG_WARN("calloc: failed in %s\n", __func__);
@ -232,7 +229,7 @@ static void sam_add_flash(target *t,
f->blocksize = SAM_LARGE_PAGE_SIZE * 8;
f->erase = sam_flash_erase;
f->write = sam_flash_write;
f->buf_size = SAM_LARGE_PAGE_SIZE;
f->writesize = SAM_LARGE_PAGE_SIZE;
sf->eefc_base = eefc_base;
sf->write_cmd = EEFC_FCR_FCMD_WP;
target_add_flash(t, f);
@ -538,7 +535,7 @@ static enum sam_driver sam_driver(target *t)
return DRIVER_SAMX7X;
}
static int sam_flash_erase(struct target_flash *f, target_addr addr, size_t len)
static int sam_flash_erase(target_flash_s *f, target_addr addr, size_t len)
{
target *t = f->t;
uint32_t base = ((struct sam_flash *)f)->eefc_base;
@ -564,7 +561,7 @@ static int sam_flash_erase(struct target_flash *f, target_addr addr, size_t len)
return 0;
}
static int sam3_flash_erase(struct target_flash *f, target_addr addr, size_t len)
static int sam3_flash_erase(target_flash_s *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.
@ -573,13 +570,12 @@ static int sam3_flash_erase(struct target_flash *f, target_addr addr, size_t len
return 0;
}
static int sam_flash_write(struct target_flash *f, target_addr dest,
const void *src, size_t len)
static int sam_flash_write(target_flash_s *f, target_addr dest, const void *src, size_t len)
{
target *t = f->t;
struct sam_flash *sf = (struct sam_flash *)f;
uint32_t base = sf->eefc_base;
unsigned chunk = (dest - f->start) / f->buf_size;
unsigned chunk = (dest - f->start) / f->writesize;
target_mem_write(t, dest, src, len);
if(sam_flash_cmd(t, base, sf->write_cmd, chunk))

View File

@ -103,9 +103,8 @@
#define FLASHCALW_FGPFRLO (FLASHCALW_BASE + 0x18)
static void sam4l_extended_reset(target *t);
static int sam4l_flash_erase(struct target_flash *f, target_addr addr, size_t len);
static int sam4l_flash_write_buf(struct target_flash *f, target_addr dest,
const void *src, size_t len);
static int sam4l_flash_erase(target_flash_s *f, target_addr addr, size_t len);
static int sam4l_flash_write_buf(target_flash_s *f, target_addr dest, const void *src, size_t len);
/* why Atmel couldn't make it sequential ... */
static const size_t __ram_size[16] = {
@ -168,8 +167,8 @@ static const size_t __nvp_size[16] = {
*/
static void sam4l_add_flash(target *t, uint32_t addr, size_t length)
{
struct target_flash *f = calloc(1, sizeof(struct target_flash));
if (!f) { /* calloc failed: heap exhaustion */
target_flash_s *f = calloc(1, sizeof(target_flash_s));
if (!f) { /* calloc failed: heap exhaustion */
DEBUG_WARN("calloc: failed in %s\n", __func__);
return;
}
@ -179,7 +178,7 @@ static void sam4l_add_flash(target *t, uint32_t addr, size_t length)
f->blocksize = SAM4L_PAGE_SIZE;
f->erase = sam4l_flash_erase;
f->write = sam4l_flash_write_buf;
f->buf_size = SAM4L_PAGE_SIZE;
f->writesize = SAM4L_PAGE_SIZE;
f->erased = 0xff;
/* add it into the target structures flash chain */
target_add_flash(t, f);
@ -330,8 +329,7 @@ sam4l_flash_command(target *t, uint32_t page, uint32_t cmd)
* Write data from 'src' into flash using the algorithim provided by
* Atmel in their data sheet.
*/
static int
sam4l_flash_write_buf(struct target_flash *f, target_addr addr, const void *src, size_t len)
static int sam4l_flash_write_buf(target_flash_s *f, target_addr addr, const void *src, size_t len)
{
target *t = f->t;
uint32_t *src_data = (uint32_t *)src;
@ -379,8 +377,7 @@ sam4l_flash_write_buf(struct target_flash *f, target_addr addr, const void *src,
/*
* Erase flash across the addresses specified by addr and len
*/
static int
sam4l_flash_erase(struct target_flash *f, target_addr addr, size_t len)
static int sam4l_flash_erase(target_flash_s *f, target_addr addr, size_t len)
{
target *t = f->t;
uint16_t page;

View File

@ -39,8 +39,8 @@
#include "target_internal.h"
#include "cortexm.h"
static int samd_flash_erase(struct target_flash *f, target_addr addr, size_t len);
static int samd_flash_write(struct target_flash *f, target_addr dest, const void *src, size_t len);
static int samd_flash_erase(target_flash_s *f, target_addr addr, size_t len);
static int samd_flash_write(target_flash_s *f, target_addr dest, const void *src, size_t len);
bool samd_mass_erase(target *t);
static bool samd_cmd_lock_flash(target *t, int argc, const char **argv);
@ -445,8 +445,8 @@ struct samd_descr samd_parse_device_id(uint32_t did)
static void samd_add_flash(target *t, uint32_t addr, size_t length)
{
struct target_flash *f = calloc(1, sizeof(*f));
if (!f) { /* calloc failed: heap exhaustion */
target_flash_s *f = calloc(1, sizeof(*f));
if (!f) { /* calloc failed: heap exhaustion */
DEBUG_WARN("calloc: failed in %s\n", __func__);
return;
}
@ -456,7 +456,7 @@ static void samd_add_flash(target *t, uint32_t addr, size_t length)
f->blocksize = SAMD_ROW_SIZE;
f->erase = samd_flash_erase;
f->write = samd_flash_write;
f->buf_size = SAMD_PAGE_SIZE;
f->writesize = SAMD_PAGE_SIZE;
target_add_flash(t, f);
}
@ -579,7 +579,7 @@ static void samd_unlock_current_address(target *t)
/*
* Erase flash row by row
*/
static int samd_flash_erase(struct target_flash *f, target_addr addr, size_t len)
static int samd_flash_erase(target_flash_s *f, target_addr addr, size_t len)
{
target *t = f->t;
while (len) {
@ -614,7 +614,7 @@ static int samd_flash_erase(struct target_flash *f, target_addr addr, size_t len
/*
* Write flash page by page
*/
static int samd_flash_write(struct target_flash *f,
static int samd_flash_write(target_flash_s *f,
target_addr dest, const void *src, size_t len)
{
target *t = f->t;

View File

@ -38,10 +38,8 @@
#include "target_internal.h"
#include "cortexm.h"
static int samx5x_flash_erase(struct target_flash *t, target_addr addr,
size_t len);
static int samx5x_flash_write(struct target_flash *f,
target_addr dest, const void *src, size_t len);
static int samx5x_flash_erase(target_flash_s *f, target_addr addr, size_t len);
static int samx5x_flash_write(target_flash_s *f, target_addr dest, const void *src, size_t len);
static bool samx5x_cmd_lock_flash(target *t, int argc, const char **argv);
static bool samx5x_cmd_unlock_flash(target *t, int argc, const char **argv);
static bool samx5x_cmd_unlock_bootprot(target *t, int argc, const char **argv);
@ -317,11 +315,10 @@ struct samx5x_descr samx5x_parse_device_id(uint32_t did)
return samd;
}
static void samx5x_add_flash(target *t, uint32_t addr, size_t length,
size_t erase_block_size, size_t write_page_size)
static void samx5x_add_flash(target *t, uint32_t addr, size_t length, size_t erase_block_size, size_t write_page_size)
{
struct target_flash *f = calloc(1, sizeof(*f));
if (!f) { /* calloc failed: heap exhaustion */
target_flash_s *f = calloc(1, sizeof(*f));
if (!f) { /* calloc failed: heap exhaustion */
DEBUG_INFO("calloc: failed in %s\n", __func__);
return;
}
@ -331,7 +328,7 @@ static void samx5x_add_flash(target *t, uint32_t addr, size_t length,
f->blocksize = erase_block_size;
f->erase = samx5x_flash_erase;
f->write = samx5x_flash_write;
f->buf_size = write_page_size;
f->writesize = write_page_size;
target_add_flash(t, f);
}
@ -499,8 +496,7 @@ static int samx5x_check_nvm_error(target *t)
/**
* Erase flash block by block
*/
static int samx5x_flash_erase(struct target_flash *f, target_addr addr,
size_t len)
static int samx5x_flash_erase(target_flash_s *f, target_addr addr, size_t len)
{
target *t = f->t;
uint16_t errs = samx5x_read_nvm_error(t);
@ -566,8 +562,7 @@ static int samx5x_flash_erase(struct target_flash *f, target_addr addr,
/**
* Write flash page by page
*/
static int samx5x_flash_write(struct target_flash *f,
target_addr dest, const void *src, size_t len)
static int samx5x_flash_write(target_flash_s *f, target_addr dest, const void *src, size_t len)
{
target *t = f->t;
bool error = false;

View File

@ -46,8 +46,8 @@ const struct command_s stm32f1_cmd_list[] = {
{NULL, NULL, NULL}
};
static int stm32f1_flash_erase(struct target_flash *f, target_addr addr, size_t len);
static int stm32f1_flash_write(struct target_flash *f, target_addr dest, const void *src, size_t len);
static int stm32f1_flash_erase(target_flash_s *f, target_addr addr, size_t len);
static int stm32f1_flash_write(target_flash_s *f, target_addr dest, const void *src, size_t len);
static bool stm32f1_mass_erase(target *t);
/* Flash Program ad Erase Controller Register Map */
@ -96,7 +96,7 @@ static bool stm32f1_mass_erase(target *t);
static void stm32f1_add_flash(target *t, uint32_t addr, size_t length, size_t erasesize)
{
struct target_flash *f = calloc(1, sizeof(*f));
target_flash_s *f = calloc(1, sizeof(*f));
if (!f) { /* calloc failed: heap exhaustion */
DEBUG_WARN("calloc: failed in %s\n", __func__);
return;
@ -107,7 +107,7 @@ static void stm32f1_add_flash(target *t, uint32_t addr, size_t length, size_t er
f->blocksize = erasesize;
f->erase = stm32f1_flash_erase;
f->write = stm32f1_flash_write;
f->buf_size = erasesize;
f->writesize = erasesize;
f->erased = 0xff;
target_add_flash(t, f);
}
@ -357,7 +357,7 @@ static int stm32f1_flash_unlock(target *t, uint32_t bank_offset)
return 0;
}
static int stm32f1_flash_erase(struct target_flash *f, target_addr addr, size_t len)
static int stm32f1_flash_erase(target_flash_s *f, target_addr addr, size_t len)
{
target *t = f->t;
target_addr end = addr + len - 1;
@ -418,7 +418,7 @@ static int stm32f1_flash_erase(struct target_flash *f, target_addr addr, size_t
return 0;
}
static int stm32f1_flash_write(struct target_flash *f, target_addr dest, const void *src, size_t len)
static int stm32f1_flash_write(target_flash_s *f, target_addr dest, const void *src, size_t len)
{
target *t = f->t;
uint32_t sr;

View File

@ -47,8 +47,8 @@ const struct command_s stm32f4_cmd_list[] = {
};
static bool stm32f4_attach(target *t);
static int stm32f4_flash_erase(struct target_flash *f, target_addr addr, size_t len);
static int stm32f4_flash_write(struct target_flash *f, target_addr dest, const void *src, size_t len);
static int stm32f4_flash_erase(target_flash_s *f, target_addr addr, size_t len);
static int stm32f4_flash_write(target_flash_s *f, target_addr dest, const void *src, size_t len);
static bool stm32f4_mass_erase(target *t);
/* Flash Program and Erase Controller Register Map */
@ -110,7 +110,7 @@ static bool stm32f4_mass_erase(target *t);
#define DBGMCU_CR_DBG_STANDBY (0x1U << 2U)
struct stm32f4_flash {
struct target_flash f;
target_flash_s f;
enum align psize;
uint8_t base_sector;
uint8_t bank_split;
@ -137,25 +137,24 @@ enum IDS_STM32F247 {
ID_STM32F413 = 0x463
};
static void stm32f4_add_flash(target *t,
uint32_t addr, size_t length, size_t blocksize,
unsigned int base_sector, int split)
static void stm32f4_add_flash(
target *t, uint32_t addr, size_t length, size_t blocksize, unsigned int base_sector, int split)
{
if (length == 0)
return;
struct stm32f4_flash *sf = calloc(1, sizeof(*sf));
if (!sf) { /* calloc failed: heap exhaustion */
if (!sf) { /* calloc failed: heap exhaustion */
DEBUG_WARN("calloc: failed in %s\n", __func__);
return;
}
struct target_flash *f = &sf->f;
target_flash_s *f = &sf->f;
f->start = addr;
f->length = length;
f->blocksize = blocksize;
f->erase = stm32f4_flash_erase;
f->write = stm32f4_flash_write;
f->buf_size = 1024;
f->writesize = 1024;
f->erased = 0xff;
sf->base_sector = base_sector;
sf->bank_split = split;
@ -391,8 +390,7 @@ static void stm32f4_flash_unlock(target *t)
}
}
static int stm32f4_flash_erase(struct target_flash *f, target_addr addr,
size_t len)
static int stm32f4_flash_erase(target_flash_s *f, target_addr addr, size_t len)
{
target *t = f->t;
struct stm32f4_flash *sf = (struct stm32f4_flash *)f;
@ -402,7 +400,7 @@ static int stm32f4_flash_erase(struct target_flash *f, target_addr addr,
stm32f4_flash_unlock(t);
enum align psize = ALIGN_WORD;
for (struct target_flash *currf = t->flash; currf; currf = currf->next) {
for (target_flash_s *currf = t->flash; currf; currf = currf->next) {
if (currf->write == stm32f4_flash_write) {
psize = ((struct stm32f4_flash *)currf)->psize;
}
@ -439,8 +437,7 @@ static int stm32f4_flash_erase(struct target_flash *f, target_addr addr,
return 0;
}
static int stm32f4_flash_write(struct target_flash *f,
target_addr dest, const void *src, size_t len)
static int stm32f4_flash_write(target_flash_s *f, target_addr dest, const void *src, size_t len)
{
/* Translate ITCM addresses to AXIM */
if ((dest >= ITCM_BASE) && (dest < AXIM_BASE)) {
@ -707,7 +704,7 @@ static bool stm32f4_cmd_psize(target *t, int argc, char *argv[])
{
if (argc == 1) {
enum align psize = ALIGN_WORD;
for (struct target_flash *f = t->flash; f; f = f->next) {
for (target_flash_s *f = t->flash; f; f = f->next) {
if (f->write == stm32f4_flash_write) {
psize = ((struct stm32f4_flash *)f)->psize;
}
@ -730,7 +727,7 @@ static bool stm32f4_cmd_psize(target *t, int argc, char *argv[])
tc_printf(t, "usage: monitor psize (x8|x16|x32|x32)\n");
return false;
}
for (struct target_flash *f = t->flash; f; f = f->next) {
for (target_flash_s *f = t->flash; f; f = f->next) {
if (f->write == stm32f4_flash_write) {
((struct stm32f4_flash *)f)->psize = psize;
}

View File

@ -189,7 +189,7 @@ static void stm32g0_add_flash(target *t, uint32_t addr, size_t length, size_t bl
f->blocksize = blocksize;
f->erase = stm32g0_flash_erase;
f->write = stm32g0_flash_write;
f->buf_size = blocksize;
f->writesize = blocksize;
f->erased = 0xffU;
target_add_flash(t, f);
}

View File

@ -52,9 +52,8 @@ const struct command_s stm32h7_cmd_list[] = {
{NULL, NULL, NULL}
};
static int stm32h7_flash_erase(struct target_flash *f, target_addr addr, size_t len);
static int stm32h7_flash_write(struct target_flash *f, target_addr dest, const void *src, size_t len);
static int stm32h7_flash_erase(target_flash_s *f, target_addr addr, size_t len);
static int stm32h7_flash_write(target_flash_s *f, target_addr dest, const void *src, size_t len);
static bool stm32h7_mass_erase(target *t);
static const char stm32h7_driver_str[] = "STM32H7";
@ -152,7 +151,7 @@ enum ID_STM32H7 {
};
struct stm32h7_flash {
struct target_flash f;
target_flash_s f;
enum align psize;
uint32_t regbase;
};
@ -164,18 +163,18 @@ struct stm32h7_priv_s {
static void stm32h7_add_flash(target *t, uint32_t addr, size_t length, size_t blocksize)
{
struct stm32h7_flash *sf = calloc(1, sizeof(*sf));
if (!sf) { /* calloc failed: heap exhaustion */
if (!sf) { /* calloc failed: heap exhaustion */
DEBUG_WARN("calloc: failed in %s\n", __func__);
return;
}
struct target_flash *f = &sf->f;
target_flash_s *f = &sf->f;
f->start = addr;
f->length = length;
f->blocksize = blocksize;
f->erase = stm32h7_flash_erase;
f->write = stm32h7_flash_write;
f->buf_size = 2048;
f->writesize = 2048;
f->erased = 0xff;
sf->regbase = FPEC1_BASE;
if (addr >= BANK2_START)
@ -268,7 +267,7 @@ static bool stm32h7_flash_unlock(target *t, const uint32_t addr)
return !(target_mem_read32(t, regbase + FLASH_CR) & FLASH_CR_LOCK);
}
static int stm32h7_flash_erase(struct target_flash *f, target_addr addr, size_t len)
static int stm32h7_flash_erase(target_flash_s *f, target_addr addr, size_t len)
{
target *t = f->t;
struct stm32h7_flash *sf = (struct stm32h7_flash *)f;
@ -308,7 +307,7 @@ static int stm32h7_flash_erase(struct target_flash *f, target_addr addr, size_t
return 0;
}
static int stm32h7_flash_write(struct target_flash *f, target_addr dest, const void *src, size_t len)
static int stm32h7_flash_write(target_flash_s *f, target_addr dest, const void *src, size_t len)
{
target *t = f->t;
struct stm32h7_flash *sf = (struct stm32h7_flash *)f;
@ -376,7 +375,7 @@ static bool stm32h7_check_bank(target *const t, const uint32_t reg_base)
static bool stm32h7_mass_erase(target *t)
{
enum align psize = ALIGN_DWORD;
for (struct target_flash *flash = t->flash; flash; flash = flash->next) {
for (target_flash_s *flash = t->flash; flash; flash = flash->next) {
if (flash->write == stm32h7_flash_write)
psize = ((struct stm32h7_flash *)flash)->psize;
}
@ -469,7 +468,7 @@ static bool stm32h7_cmd_psize(target *t, int argc, char *argv[])
(void)argv;
if (argc == 1) {
enum align psize = ALIGN_DWORD;
for (struct target_flash *f = t->flash; f; f = f->next) {
for (target_flash_s *f = t->flash; f; f = f->next) {
if (f->write == stm32h7_flash_write) {
psize = ((struct stm32h7_flash *)f)->psize;
}
@ -492,7 +491,7 @@ static bool stm32h7_cmd_psize(target *t, int argc, char *argv[])
tc_printf(t, "usage: monitor psize (x8|x16|x32|x64)\n");
return false;
}
for (struct target_flash *f = t->flash; f; f = f->next) {
for (target_flash_s *f = t->flash; f; f = f->next) {
if (f->write == stm32h7_flash_write) {
((struct stm32h7_flash *)f)->psize = psize;
}

View File

@ -143,11 +143,11 @@
#define STM32L1_NVM_OPTR_BOR_LEV_M (0xf)
#define STM32L1_NVM_OPTR_SPRMOD (1 << 8)
static int stm32lx_nvm_prog_erase(struct target_flash *f, target_addr addr, size_t len);
static int stm32lx_nvm_prog_write(struct target_flash *f, target_addr destination, const void *src, size_t size);
static int stm32lx_nvm_prog_erase(target_flash_s *f, target_addr addr, size_t len);
static int stm32lx_nvm_prog_write(target_flash_s *f, target_addr destination, const void *src, size_t size);
static int stm32lx_nvm_data_erase(struct target_flash *f, target_addr addr, size_t len);
static int stm32lx_nvm_data_write(struct target_flash *f, target_addr destination, const void *source, size_t size);
static int stm32lx_nvm_data_erase(target_flash_s *f, target_addr addr, size_t len);
static int stm32lx_nvm_data_write(target_flash_s *f, target_addr destination, const void *source, size_t size);
static bool stm32lx_cmd_option(target *t, int argc, char **argv);
static bool stm32lx_cmd_eeprom(target *t, int argc, char **argv);
@ -220,7 +220,7 @@ static uint32_t stm32lx_nvm_option_size(target *t)
static void stm32l_add_flash(target *t, uint32_t addr, size_t length, size_t erasesize)
{
struct target_flash *f = calloc(1, sizeof(*f));
target_flash_s *f = calloc(1, sizeof(*f));
if (!f) { /* calloc failed: heap exhaustion */
DEBUG_WARN("calloc: failed in %s\n", __func__);
return;
@ -231,13 +231,13 @@ static void stm32l_add_flash(target *t, uint32_t addr, size_t length, size_t era
f->blocksize = erasesize;
f->erase = stm32lx_nvm_prog_erase;
f->write = stm32lx_nvm_prog_write;
f->buf_size = erasesize / 2;
f->writesize = erasesize / 2;
target_add_flash(t, f);
}
static void stm32l_add_eeprom(target *t, uint32_t addr, size_t length)
{
struct target_flash *f = calloc(1, sizeof(*f));
target_flash_s *f = calloc(1, sizeof(*f));
if (!f) { /* calloc failed: heap exhaustion */
DEBUG_WARN("calloc: failed in %s\n", __func__);
return;
@ -325,7 +325,7 @@ static bool stm32lx_nvm_opt_unlock(target *t, uint32_t nvm)
interface. This is slower than stubbed versions(see NOTES). The
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, target_addr addr, size_t len)
static int stm32lx_nvm_prog_erase(target_flash_s *f, 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, target_addr addr, size
/** Write to program flash using operations through the debug
interface. */
static int stm32lx_nvm_prog_write(struct target_flash *f, target_addr dest, const void *src, size_t size)
static int stm32lx_nvm_prog_write(target_flash_s *f, target_addr dest, const void *src, size_t size)
{
target *t = f->t;
const uint32_t nvm = stm32lx_nvm_phys(t);
@ -408,7 +408,7 @@ static int stm32lx_nvm_prog_write(struct target_flash *f, target_addr dest, cons
interface . The flash is erased for all pages from addr to
addr+len, inclusive, on a word boundary. NVM register file
address chosen from target. */
static int stm32lx_nvm_data_erase(struct target_flash *f, target_addr addr, size_t len)
static int stm32lx_nvm_data_erase(target_flash_s *f, target_addr addr, size_t len)
{
target *t = f->t;
const size_t page_size = f->blocksize;
@ -458,7 +458,7 @@ static int stm32lx_nvm_data_erase(struct target_flash *f, target_addr addr, size
NVM register file address chosen from target. Unaligned
destination writes are supported (though unaligned sources are
not). */
static int stm32lx_nvm_data_write(struct target_flash *f, target_addr destination, const void *src, size_t size)
static int stm32lx_nvm_data_write(target_flash_s *f, target_addr destination, const void *src, size_t size)
{
target *t = f->t;
const uint32_t nvm = stm32lx_nvm_phys(t);

View File

@ -53,8 +53,8 @@ const struct command_s stm32l4_cmd_list[] = {
{NULL, NULL, NULL}
};
static int stm32l4_flash_erase(struct target_flash *f, target_addr addr, size_t len);
static int stm32l4_flash_write(struct target_flash *f, target_addr dest, const void *src, size_t len);
static int stm32l4_flash_erase(target_flash_s *f, target_addr addr, size_t len);
static int stm32l4_flash_write(target_flash_s *f, target_addr dest, const void *src, size_t len);
static bool stm32l4_mass_erase(target *t);
/* Flash Program ad Erase Controller Register Map */
@ -128,7 +128,7 @@ enum {
#define L5_FLASH_SIZE_REG 0x0bfa05e0
struct stm32l4_flash {
struct target_flash f;
target_flash_s f;
uint32_t bank1_start;
};
@ -367,18 +367,18 @@ static void stm32l4_flash_write32(target *t, enum stm32l4_flash_regs reg, uint32
static void stm32l4_add_flash(target *t, uint32_t addr, size_t length, size_t blocksize, uint32_t bank1_start)
{
struct stm32l4_flash *sf = calloc(1, sizeof(*sf));
if (!sf) { /* calloc failed: heap exhaustion */
if (!sf) { /* calloc failed: heap exhaustion */
DEBUG_WARN("calloc: failed in %s\n", __func__);
return;
}
struct target_flash *f = &sf->f;
target_flash_s *f = &sf->f;
f->start = addr;
f->length = length;
f->blocksize = blocksize;
f->erase = stm32l4_flash_erase;
f->write = stm32l4_flash_write;
f->buf_size = 2048;
f->writesize = 2048;
f->erased = 0xff;
sf->bank1_start = bank1_start;
target_add_flash(t, f);
@ -569,7 +569,7 @@ static void stm32l4_flash_unlock(target *t)
}
}
static int stm32l4_flash_erase(struct target_flash *f, target_addr addr, size_t len)
static int stm32l4_flash_erase(target_flash_s *f, target_addr addr, size_t len)
{
target *t = f->t;
stm32l4_flash_unlock(t);
@ -614,7 +614,7 @@ static int stm32l4_flash_erase(struct target_flash *f, target_addr addr, size_t
return 0;
}
static int stm32l4_flash_write(struct target_flash *f, target_addr dest, const void *src, size_t len)
static int stm32l4_flash_write(target_flash_s *f, target_addr dest, const void *src, size_t len)
{
target *t = f->t;
stm32l4_flash_write32(t, FLASH_CR, FLASH_CR_PG);

View File

@ -29,8 +29,8 @@ target *target_list = NULL;
#define STDOUT_READ_BUF_SIZE 64
static int target_flash_write_buffered(struct target_flash *f, target_addr dest, const void *src, size_t len);
static int target_flash_done_buffered(struct target_flash *f);
static int target_flash_write_buffered(target_flash_s *f, target_addr dest, const void *src, size_t len);
static int target_flash_done_buffered(target_flash_s *f);
static bool target_cmd_mass_erase(target *t, int argc, const char **argv);
static bool target_cmd_range_erase(target *t, int argc, const char **argv);
@ -210,10 +210,10 @@ void target_add_ram(target *t, target_addr start, uint32_t len)
t->ram = ram;
}
void target_add_flash(target *t, struct target_flash *f)
void target_add_flash(target *t, target_flash_s *f)
{
if (f->buf_size == 0)
f->buf_size = MIN(f->blocksize, 0x400);
if (f->writesize == 0)
f->writesize = f->blocksize;
f->t = t;
f->next = t->flash;
t->flash = f;
@ -226,7 +226,7 @@ static ssize_t map_ram(char *buf, size_t len, struct target_ram *ram)
ram->start, (uint32_t)ram->length);
}
static ssize_t map_flash(char *buf, size_t len, struct target_flash *f)
static ssize_t map_flash(char *buf, size_t len, target_flash_s *f)
{
int i = 0;
i += snprintf(&buf[i], len - i, "<memory type=\"flash\" start=\"0x%08"PRIx32
@ -246,7 +246,7 @@ bool target_mem_map(target *t, char *tmp, size_t len)
for (struct target_ram *r = t->ram; r; r = r->next)
i += map_ram(&tmp[i], len - i, r);
/* Map each defined Flash */
for (struct target_flash *f = t->flash; f; f = f->next)
for (target_flash_s *f = t->flash; f; f = f->next)
i += map_flash(&tmp[i], len - i, f);
i += snprintf(&tmp[i], len - i, "</memory-map>");
@ -255,9 +255,9 @@ bool target_mem_map(target *t, char *tmp, size_t len)
return true;
}
struct target_flash *target_flash_for_addr(target *t, uint32_t addr)
target_flash_s *target_flash_for_addr(target *t, uint32_t addr)
{
for (struct target_flash *f = t->flash; f; f = f->next)
for (target_flash_s *f = t->flash; f; f = f->next)
if ((f->start <= addr) &&
(addr < (f->start + f->length)))
return f;
@ -268,7 +268,7 @@ int target_flash_erase(target *t, target_addr addr, size_t len)
{
int ret = 0;
while (len) {
struct target_flash *f = target_flash_for_addr(t, addr);
target_flash_s *f = target_flash_for_addr(t, addr);
if (!f) {
DEBUG_WARN("Erase stopped at 0x%06" PRIx32 "\n", addr);
return ret;
@ -286,7 +286,7 @@ int target_flash_write(target *t, target_addr dest, const void *src, size_t len)
{
int ret = 0;
while (len) {
struct target_flash *f = target_flash_for_addr(t, dest);
target_flash_s *f = target_flash_for_addr(t, dest);
if (!f)
return 1;
size_t tmptarget = MIN(dest + len, f->start + f->length);
@ -306,7 +306,7 @@ int target_flash_write(target *t, target_addr dest, const void *src, size_t len)
int target_flash_done(target *t)
{
for (struct target_flash *f = t->flash; f; f = f->next) {
for (target_flash_s *f = t->flash; f; f = f->next) {
int tmp = target_flash_done_buffered(f);
if (tmp)
return tmp;
@ -319,34 +319,33 @@ int target_flash_done(target *t)
return 0;
}
int target_flash_write_buffered(struct target_flash *f, target_addr dest, const void *src, size_t len)
int target_flash_write_buffered(target_flash_s *f, target_addr dest, const void *src, size_t len)
{
int ret = 0;
if (f->buf == NULL) {
/* Allocate flash sector buffer */
f->buf = malloc(f->buf_size);
if (!f->buf) { /* malloc failed: heap exhaustion */
f->buf = malloc(f->writesize);
if (!f->buf) { /* malloc failed: heap exhaustion */
DEBUG_WARN("malloc: failed in %s\n", __func__);
return 1;
}
f->buf_addr = -1;
}
while (len) {
uint32_t offset = dest % f->buf_size;
uint32_t offset = dest % f->writesize;
uint32_t base = dest - offset;
if (base != f->buf_addr) {
if (f->buf_addr != (uint32_t)-1) {
/* Write sector to flash if valid */
ret |= f->write(f, f->buf_addr,
f->buf, f->buf_size);
ret |= f->write(f, f->buf_addr, f->buf, f->writesize);
}
/* Setup buffer for a new sector */
f->buf_addr = base;
memset(f->buf, f->erased, f->buf_size);
memset(f->buf, f->erased, f->writesize);
}
/* Copy chunk into sector buffer */
size_t sectlen = MIN(f->buf_size - offset, len);
size_t sectlen = MIN(f->writesize - offset, len);
memcpy(f->buf + offset, src, sectlen);
dest += sectlen;
src += sectlen;
@ -355,12 +354,12 @@ int target_flash_write_buffered(struct target_flash *f, target_addr dest, const
return ret;
}
int target_flash_done_buffered(struct target_flash *f)
int target_flash_done_buffered(target_flash_s *f)
{
int ret = 0;
if ((f->buf != NULL) &&(f->buf_addr != (uint32_t)-1)) {
if ((f->buf != NULL) && (f->buf_addr != (uint32_t)-1)) {
/* Write sector to flash if valid */
ret = f->write(f, f->buf_addr, f->buf, f->buf_size);
ret = f->write(f, f->buf_addr, f->buf, f->writesize);
f->buf_addr = -1;
free(f->buf);
f->buf = NULL;
@ -554,7 +553,7 @@ static bool target_cmd_range_erase(target *const t, const int argc, const char *
}
const uint32_t addr = strtoul(argv[1], NULL, 0);
const uint32_t length = strtoul(argv[2], NULL, 0);
struct target_flash *flash = target_flash_for_addr(t, addr);
target_flash_s *flash = target_flash_for_addr(t, addr);
if (flash == NULL) {
gdb_out("Requested address is outside the valid range for this target");

View File

@ -34,24 +34,25 @@ struct target_ram {
typedef struct target_flash target_flash_s;
typedef int (*flash_prepare_func)(target_flash_s *f);
typedef int (*flash_erase_func)(target_flash_s *f, target_addr addr, size_t len);
typedef int (*flash_write_func)(target_flash_s *f, target_addr dest,
const void *src, size_t len);
typedef int (*flash_write_func)(target_flash_s *f, target_addr dest, const void *src, size_t len);
typedef int (*flash_done_func)(target_flash_s *f);
struct target_flash {
target_addr start;
size_t length;
size_t blocksize;
flash_erase_func erase;
flash_write_func write;
flash_done_func done;
target *t;
uint8_t erased;
size_t buf_size;
struct target_flash *next;
target_addr buf_addr;
void *buf;
target *t; /* Target this flash is attached to */
target_addr start; /* start address of flash */
size_t length; /* flash length */
size_t blocksize; /* erase block size */
size_t writesize; /* write operation size, must be <= blocksize */
uint8_t erased; /* byte erased state */
flash_prepare_func prepare; /* prepare for flash operations */
flash_erase_func erase; /* erase a range of flash */
flash_write_func write; /* write to flash */
flash_done_func done; /* finish flash operations */
void *buf; /* buffer for flash operations */
target_addr buf_addr; /* address of block this buffer is for */
target_flash_s *next; /* next flash in list */
};
typedef bool (*cmd_handler)(target *t, int argc, const char **argv);
@ -88,10 +89,8 @@ struct target_s {
bool (*check_error)(target *t);
/* Memory access functions */
void (*mem_read)(target *t, void *dest, target_addr src,
size_t len);
void (*mem_write)(target *t, target_addr dest,
const void *src, size_t len);
void (*mem_read)(target *t, void *dest, target_addr src, size_t len);
void (*mem_write)(target *t, target_addr dest, const void *src, size_t len);
/* Register access functions */
size_t regs_size;
@ -109,8 +108,8 @@ struct target_s {
void (*halt_resume)(target *t, bool step);
/* Break-/watchpoint functions */
int (*breakwatch_set)(target *t, struct breakwatch*);
int (*breakwatch_clear)(target *t, struct breakwatch*);
int (*breakwatch_set)(target *t, struct breakwatch *);
int (*breakwatch_clear)(target *t, struct breakwatch *);
struct breakwatch *bw_list;
/* Recovery functions */
@ -126,7 +125,7 @@ struct target_s {
};
struct target_ram *ram;
struct target_flash *flash;
target_flash_s *flash;
/* Other stuff */
const char *driver;
@ -158,9 +157,9 @@ void target_flash_map_free(target *t);
void target_mem_map_free(target *t);
void target_add_commands(target *t, const struct command_s *cmds, const char *name);
void target_add_ram(target *t, target_addr start, uint32_t len);
void target_add_flash(target *t, struct target_flash *f);
void target_add_flash(target *t, target_flash_s *f);
struct target_flash *target_flash_for_addr(target *t, uint32_t addr);
target_flash_s *target_flash_for_addr(target *t, uint32_t addr);
/* Convenience function for MMIO access */
uint32_t target_mem_read32(target *t, uint32_t addr);
@ -175,15 +174,12 @@ bool target_check_error(target *t);
void tc_printf(target *t, const char *fmt, ...);
/* Interface to host system calls */
int tc_open(target *, target_addr path, size_t plen,
enum target_open_flags flags, mode_t mode);
int tc_open(target *, target_addr path, size_t plen, enum target_open_flags flags, mode_t mode);
int tc_close(target *t, int fd);
int tc_read(target *t, int fd, target_addr buf, unsigned int count);
int tc_write(target *t, int fd, target_addr buf, unsigned int count);
long tc_lseek(target *t, int fd, long offset,
enum target_seek_flag flag);
int tc_rename(target *t, target_addr oldpath, size_t oldlen,
target_addr newpath, size_t newlen);
long tc_lseek(target *t, int fd, long offset, enum target_seek_flag flag);
int tc_rename(target *t, target_addr oldpath, size_t oldlen, target_addr newpath, size_t newlen);
int tc_unlink(target *t, target_addr path, size_t plen);
int tc_stat(target *t, target_addr path, size_t plen, target_addr buf);
int tc_fstat(target *t, int fd, target_addr buf);