commit d10d305103c1d62e01e8832c2da26ad74defc9ea
parent 1ce128d22448271b6d991006b58e7348beb21bb2
Author: Brian Swetland <swetland@frotz.net>
Date: Sun, 14 Jun 2015 21:27:00 -0700
debugger: use builtin agents if they exist, arch selects agent
- agents are now included in the debugger binary
- agents are now selected with the arch command
Diffstat:
1 file changed, 36 insertions(+), 2 deletions(-)
diff --git a/tools/debugger-commands.c b/tools/debugger-commands.c
@@ -456,6 +456,8 @@ int do_help(int argc, param *argv) {
return 0;
}
+void *get_builtin_file(const char *fn, size_t *sz);
+
void *load_file(const char *fn, size_t *_sz) {
int fd;
off_t sz;
@@ -475,6 +477,35 @@ fail:
return NULL;
}
+void *load_agent(const char *arch, size_t *_sz) {
+ void *data;
+ size_t sz;
+ char name[256];
+ if (arch == NULL) return NULL;
+ snprintf(name, 256, "agent-%s.bin", arch);
+ if ((data = get_builtin_file(name, &sz))) {
+ void *copy = malloc(sz + 4);
+ if (copy == NULL) return NULL;
+ memcpy(copy, data, sz);
+ *_sz = sz;
+ return copy;
+ }
+ snprintf(name, sizeof(name), "out/agent-%s.bin", arch);
+ return load_file(name, _sz);
+}
+
+static char *agent_arch = NULL;
+
+int do_setarch(int argc, param *argv) {
+ char *x;
+ if (argc != 1) return -1;
+ if((x = strdup(argv[0].s))) {
+ free(agent_arch);
+ agent_arch = x;
+ }
+ return 0;
+}
+
int invoke(u32 agent, u32 func, u32 r0, u32 r1, u32 r2, u32 r3) {
swdp_core_write(0, r0);
swdp_core_write(1, r1);
@@ -509,8 +540,10 @@ int run_flash_agent(u32 flashaddr, void *data, size_t data_sz) {
flash_agent *agent = NULL;
size_t agent_sz;
- if ((agent = load_file("out/agent-lpc15xx.bin", &agent_sz)) == NULL) {
- xprintf("error: cannot load flash agent\n");
+ if ((agent = load_agent(agent_arch, &agent_sz)) == NULL) {
+ xprintf("error: cannot load flash agent for architecture '%s'\n",
+ agent_arch ? agent_arch : "unknown");
+ xprintf("error: set architecture with: arch <name>\n");
goto fail;
}
// sanity check
@@ -661,6 +694,7 @@ struct debugger_command debugger_commands[] = {
{ "echo", "", do_echo, "echo command line" },
{ "bootloader", "", do_bootloader, "reboot into bootloader" },
{ "setclock", "", do_setclock, "set clock rate (khz)" },
+ { "arch", "", do_setarch, "set architecture for flash agent" },
{ "text", "", do_text, "dump text" },
{ "help", "", do_help, "help" },
{ 0, 0, 0, 0 },