aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGareth McMullin2015-03-24 20:45:05 -0700
committerGareth McMullin2015-04-03 21:18:16 -0700
commit691d21989a6957be728635fe8b56720c21758a3f (patch)
treee063a0010fe6c809b9667eaaf190f025c346fdd0
parent0fc635b3f8a961d09a7ac784d7846c785a3345dc (diff)
Add function to add simple flash driver to target.
Clean up ram/flash/memory map on target destruction.
-rw-r--r--src/include/target.h13
-rw-r--r--src/target.c20
2 files changed, 27 insertions, 6 deletions
diff --git a/src/include/target.h b/src/include/target.h
index 5a9a94a..7085ff2 100644
--- a/src/include/target.h
+++ b/src/include/target.h
@@ -121,14 +121,18 @@ struct target_ram {
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 {
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);
+ flash_erase_func erase;
+ flash_write_func write;
+ flash_done_func done;
target *t;
struct target_flash *next;
};
@@ -175,6 +179,7 @@ struct target_s {
/* Target memory map */
const char *xml_mem_map;
+ char *dyn_mem_map;
struct target_ram *ram;
struct target_flash *flash;
diff --git a/src/target.c b/src/target.c
index 4e10e72..86d88ed 100644
--- a/src/target.c
+++ b/src/target.c
@@ -48,6 +48,18 @@ void target_list_free(void)
free(target_list->commands);
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);
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)
{
+ /* Deprecated static const memory map */
if (t->xml_mem_map)
return t->xml_mem_map;
+ if (t->dyn_mem_map)
+ return t->dyn_mem_map;
+
/* FIXME size buffer */
size_t len = 1024;
char *tmp = malloc(len);
@@ -133,8 +149,8 @@ const char *target_mem_map(target *t)
i += map_flash(&tmp[i], len - i, f);
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;
}