Add functions for dynamically generating the XML memory map.
This commit is contained in:
parent
482070c91b
commit
0fc635b3f8
@ -112,12 +112,27 @@ target *target_attach(target *t, target_destroy_callback destroy_cb);
|
|||||||
#define target_regs_size(target) \
|
#define target_regs_size(target) \
|
||||||
((target)->regs_size)
|
((target)->regs_size)
|
||||||
|
|
||||||
#define target_mem_map(target) \
|
|
||||||
((target)->xml_mem_map ? (target)->xml_mem_map : "")
|
|
||||||
|
|
||||||
#define target_tdesc(target) \
|
#define target_tdesc(target) \
|
||||||
((target)->tdesc ? (target)->tdesc : "")
|
((target)->tdesc ? (target)->tdesc : "")
|
||||||
|
|
||||||
|
struct target_ram {
|
||||||
|
uint32_t start;
|
||||||
|
uint32_t length;
|
||||||
|
struct target_ram *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct target_flash {
|
||||||
|
uint32_t start;
|
||||||
|
uint32_t length;
|
||||||
|
uint32_t blocksize;
|
||||||
|
int (*erase)(struct target_flash *f, uint32_t addr, size_t len);
|
||||||
|
int (*write)(struct target_flash *f, uint32_t dest,
|
||||||
|
const uint8_t *src, size_t len);
|
||||||
|
int (*done)(struct target_flash *t);
|
||||||
|
target *t;
|
||||||
|
struct target_flash *next;
|
||||||
|
};
|
||||||
|
|
||||||
struct target_s {
|
struct target_s {
|
||||||
/* Notify controlling debugger if target is lost */
|
/* Notify controlling debugger if target is lost */
|
||||||
target_destroy_callback destroy_callback;
|
target_destroy_callback destroy_callback;
|
||||||
@ -158,8 +173,12 @@ struct target_s {
|
|||||||
unsigned target_options;
|
unsigned target_options;
|
||||||
uint32_t idcode;
|
uint32_t idcode;
|
||||||
|
|
||||||
/* Flash memory access functions */
|
/* Target memory map */
|
||||||
const char *xml_mem_map;
|
const char *xml_mem_map;
|
||||||
|
struct target_ram *ram;
|
||||||
|
struct target_flash *flash;
|
||||||
|
|
||||||
|
/* DEPRECATED: Flash memory access functions */
|
||||||
int (*flash_erase)(target *t, uint32_t addr, size_t len);
|
int (*flash_erase)(target *t, uint32_t addr, size_t len);
|
||||||
int (*flash_write)(target *t, uint32_t dest,
|
int (*flash_write)(target *t, uint32_t dest,
|
||||||
const uint8_t *src, size_t len);
|
const uint8_t *src, size_t len);
|
||||||
@ -190,6 +209,9 @@ extern bool connect_assert_srst;
|
|||||||
target *target_new(unsigned size);
|
target *target_new(unsigned size);
|
||||||
void target_list_free(void);
|
void target_list_free(void);
|
||||||
void target_add_commands(target *t, const struct command_s *cmds, const char *name);
|
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_flash(target *t, struct target_flash *f);
|
||||||
|
const char *target_mem_map(target *t);
|
||||||
|
|
||||||
static inline uint32_t target_mem_read32(target *t, uint32_t addr)
|
static inline uint32_t target_mem_read32(target *t, uint32_t addr)
|
||||||
{
|
{
|
||||||
|
@ -150,6 +150,7 @@
|
|||||||
/* Use newlib provided integer only stdio functions */
|
/* Use newlib provided integer only stdio functions */
|
||||||
#define sscanf siscanf
|
#define sscanf siscanf
|
||||||
#define sprintf siprintf
|
#define sprintf siprintf
|
||||||
|
#define snprintf sniprintf
|
||||||
#define vasprintf vasiprintf
|
#define vasprintf vasiprintf
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
58
src/target.c
58
src/target.c
@ -80,3 +80,61 @@ target *target_attach(target *t, target_destroy_callback destroy_cb)
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void target_add_ram(target *t, uint32_t start, uint32_t len)
|
||||||
|
{
|
||||||
|
struct target_ram *ram = malloc(sizeof(*ram));
|
||||||
|
ram->start = start;
|
||||||
|
ram->length = len;
|
||||||
|
ram->next = t->ram;
|
||||||
|
t->ram = ram;
|
||||||
|
}
|
||||||
|
|
||||||
|
void target_add_flash(target *t, struct target_flash *f)
|
||||||
|
{
|
||||||
|
f->t = t;
|
||||||
|
f->next = t->flash;
|
||||||
|
t->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"\"/>",
|
||||||
|
ram->start, ram->length);
|
||||||
|
}
|
||||||
|
|
||||||
|
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"\">",
|
||||||
|
f->start, f->length);
|
||||||
|
i += snprintf(&buf[i], len - i, "<property name=\"blocksize\">0x%08"PRIx32
|
||||||
|
"</property></memory>",
|
||||||
|
f->blocksize);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *target_mem_map(target *t)
|
||||||
|
{
|
||||||
|
if (t->xml_mem_map)
|
||||||
|
return t->xml_mem_map;
|
||||||
|
|
||||||
|
/* FIXME size buffer */
|
||||||
|
size_t len = 1024;
|
||||||
|
char *tmp = malloc(len);
|
||||||
|
size_t i = 0;
|
||||||
|
i = snprintf(&tmp[i], len - i, "<memory-map>");
|
||||||
|
/* Map each defined RAM */
|
||||||
|
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)
|
||||||
|
i += map_flash(&tmp[i], len - i, f);
|
||||||
|
i += snprintf(&tmp[i], len - i, "</memory-map>");
|
||||||
|
|
||||||
|
t->xml_mem_map = tmp;
|
||||||
|
|
||||||
|
return t->xml_mem_map;
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user