Add function to add simple flash driver to target.
Clean up ram/flash/memory map on target destruction.
This commit is contained in:
parent
0fc635b3f8
commit
691d21989a
|
@ -121,14 +121,18 @@ struct target_ram {
|
||||||
struct target_ram *next;
|
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,
|
||||||
|
const void *src, size_t len);
|
||||||
|
typedef int (*flash_done_func)(struct target_flash *f);
|
||||||
struct target_flash {
|
struct target_flash {
|
||||||
uint32_t start;
|
uint32_t start;
|
||||||
uint32_t length;
|
uint32_t length;
|
||||||
uint32_t blocksize;
|
uint32_t blocksize;
|
||||||
int (*erase)(struct target_flash *f, uint32_t addr, size_t len);
|
flash_erase_func erase;
|
||||||
int (*write)(struct target_flash *f, uint32_t dest,
|
flash_write_func write;
|
||||||
const uint8_t *src, size_t len);
|
flash_done_func done;
|
||||||
int (*done)(struct target_flash *t);
|
|
||||||
target *t;
|
target *t;
|
||||||
struct target_flash *next;
|
struct target_flash *next;
|
||||||
};
|
};
|
||||||
|
@ -175,6 +179,7 @@ struct target_s {
|
||||||
|
|
||||||
/* Target memory map */
|
/* Target memory map */
|
||||||
const char *xml_mem_map;
|
const char *xml_mem_map;
|
||||||
|
char *dyn_mem_map;
|
||||||
struct target_ram *ram;
|
struct target_ram *ram;
|
||||||
struct target_flash *flash;
|
struct target_flash *flash;
|
||||||
|
|
||||||
|
|
20
src/target.c
20
src/target.c
|
@ -48,6 +48,18 @@ void target_list_free(void)
|
||||||
free(target_list->commands);
|
free(target_list->commands);
|
||||||
target_list->commands = tc;
|
target_list->commands = tc;
|
||||||
}
|
}
|
||||||
|
if (target_list->dyn_mem_map)
|
||||||
|
free(target_list->dyn_mem_map);
|
||||||
|
while (target_list->ram) {
|
||||||
|
void * next = target_list->ram->next;
|
||||||
|
free(target_list->ram);
|
||||||
|
target_list->ram = next;
|
||||||
|
}
|
||||||
|
while (target_list->flash) {
|
||||||
|
void * next = target_list->flash->next;
|
||||||
|
free(target_list->flash);
|
||||||
|
target_list->flash = next;
|
||||||
|
}
|
||||||
free(target_list);
|
free(target_list);
|
||||||
target_list = t;
|
target_list = t;
|
||||||
}
|
}
|
||||||
|
@ -117,9 +129,13 @@ static ssize_t map_flash(char *buf, size_t len, struct target_flash *f)
|
||||||
|
|
||||||
const char *target_mem_map(target *t)
|
const char *target_mem_map(target *t)
|
||||||
{
|
{
|
||||||
|
/* Deprecated static const memory map */
|
||||||
if (t->xml_mem_map)
|
if (t->xml_mem_map)
|
||||||
return t->xml_mem_map;
|
return t->xml_mem_map;
|
||||||
|
|
||||||
|
if (t->dyn_mem_map)
|
||||||
|
return t->dyn_mem_map;
|
||||||
|
|
||||||
/* FIXME size buffer */
|
/* FIXME size buffer */
|
||||||
size_t len = 1024;
|
size_t len = 1024;
|
||||||
char *tmp = malloc(len);
|
char *tmp = malloc(len);
|
||||||
|
@ -133,8 +149,8 @@ const char *target_mem_map(target *t)
|
||||||
i += map_flash(&tmp[i], len - i, f);
|
i += map_flash(&tmp[i], len - i, f);
|
||||||
i += snprintf(&tmp[i], len - i, "</memory-map>");
|
i += snprintf(&tmp[i], len - i, "</memory-map>");
|
||||||
|
|
||||||
t->xml_mem_map = tmp;
|
t->dyn_mem_map = tmp;
|
||||||
|
|
||||||
return t->xml_mem_map;
|
return t->dyn_mem_map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue