X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=ao-tools%2Fao-stmload%2Fao-stmload.c;h=a11d93de68974c1c0e417f8f69c44cd412536e00;hp=b9bf4392bc6e55f8b72c2ec758968e153b7009c7;hb=14204e3d147ad99cc249ad8de254809180fe5c38;hpb=c9ba2d17b979410acfa41f9954674757f7f321fc diff --git a/ao-tools/ao-stmload/ao-stmload.c b/ao-tools/ao-stmload/ao-stmload.c index b9bf4392..a11d93de 100644 --- a/ao-tools/ao-stmload/ao-stmload.c +++ b/ao-tools/ao-stmload/ao-stmload.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "stlink-common.h" #include "ao-elf.h" #include "ccdbg.h" @@ -34,21 +35,21 @@ #define AO_USB_DESC_STRING 3 -struct sym ao_symbols[] = { +struct ao_sym ao_symbols[] = { - { 0, 0x08002100, "ao_romconfig_version", 1 }, + { 0, AO_BOOT_APPLICATION_BASE + 0x100, "ao_romconfig_version", 1 }, #define AO_ROMCONFIG_VERSION (ao_symbols[0].addr) - { 0, 0x08002102, "ao_romconfig_check", 1 }, + { 0, AO_BOOT_APPLICATION_BASE + 0x102, "ao_romconfig_check", 1 }, #define AO_ROMCONFIG_CHECK (ao_symbols[1].addr) - { 0, 0x08002104, "ao_serial_number", 1 }, + { 0, AO_BOOT_APPLICATION_BASE + 0x104, "ao_serial_number", 1 }, #define AO_SERIAL_NUMBER (ao_symbols[2].addr) - { 0, 0x08002108, "ao_radio_cal", 0 }, + { 0, AO_BOOT_APPLICATION_BASE + 0x108, "ao_radio_cal", 0 }, #define AO_RADIO_CAL (ao_symbols[3].addr) - { 0, 0x0800210c, "ao_usb_descriptors", 0 }, + { 0, AO_BOOT_APPLICATION_BASE + 0x10c, "ao_usb_descriptors", 0 }, #define AO_USB_DESCRIPTORS (ao_symbols[4].addr) }; @@ -62,7 +63,7 @@ int ao_num_required_symbols = NUM_REQUIRED_SYMBOLS; * Edit the to-be-written memory block */ static int -rewrite(struct hex_image *load, unsigned address, uint8_t *data, int length) +rewrite(struct ao_hex_image *load, unsigned address, uint8_t *data, int length) { int i; @@ -86,7 +87,7 @@ rewrite(struct hex_image *load, unsigned address, uint8_t *data, int length) static uint16_t get_uint16_cc(struct cc_usb *cc, uint32_t addr) { - struct hex_image *hex = ao_self_read(cc, addr, 2); + struct ao_hex_image *hex = ao_self_read(cc, addr, 2); uint16_t v; uint8_t *data; @@ -101,7 +102,7 @@ get_uint16_cc(struct cc_usb *cc, uint32_t addr) static uint32_t get_uint32_cc(struct cc_usb *cc, uint32_t addr) { - struct hex_image *hex = ao_self_read(cc, addr, 4); + struct ao_hex_image *hex = ao_self_read(cc, addr, 4); uint32_t v; uint8_t *data; @@ -218,18 +219,43 @@ check_flashed(stlink_t *sl, struct cc_usb *cc) return 1; } +/* + * Find the symbols needed to correctly load the program + */ + +static bool +find_symbols(struct ao_sym *file_symbols, int num_file_symbols, + struct ao_sym *symbols, int num_symbols) +{ + int f, s; + + for (f = 0; f < num_file_symbols; f++) { + for (s = 0; s < num_symbols; s++) { + if (strcmp(symbols[s].name, file_symbols[f].name) == 0) { + symbols[s].addr = file_symbols[f].addr; + symbols[s].found = true; + } + } + } + for (s = 0; s < num_symbols; s++) + if (!symbols[s].found && symbols[s].required) + return false; + return true; +} + static const struct option options[] = { { .name = "stlink", .has_arg = 0, .val = 'S' }, { .name = "tty", .has_arg = 1, .val = 'T' }, { .name = "device", .has_arg = 1, .val = 'D' }, { .name = "cal", .has_arg = 1, .val = 'c' }, { .name = "serial", .has_arg = 1, .val = 's' }, + { .name = "verbose", .has_arg = 0, .val = 'v' }, { 0, 0, 0, 0}, }; static void usage(char *program) { - fprintf(stderr, "usage: %s [--stlink] [--device=] [-tty=] [--cal=] [--serial=] file.{elf,ihx}\n", program); + fprintf(stderr, "usage: %s [--stlink] [--verbose] [--device=] [-tty=] [--cal=] [--serial=] file.{elf,ihx}\n", program); exit(1); } @@ -280,14 +306,17 @@ main (int argc, char **argv) int c; stlink_t *sl = NULL; int was_flashed = 0; - struct hex_image *load; + struct ao_hex_image *load; int tries; struct cc_usb *cc = NULL; int use_stlink = 0; char *tty = NULL; int success; + int verbose = 0; + struct ao_sym *file_symbols; + int num_file_symbols; - while ((c = getopt_long(argc, argv, "T:D:c:s:S", options, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "T:D:c:s:Sv", options, NULL)) != -1) { switch (c) { case 'T': tty = optarg; @@ -308,26 +337,34 @@ main (int argc, char **argv) case 'S': use_stlink = 1; break; + case 'v': + verbose++; + break; default: usage(argv[0]); break; } } + ao_self_verbose = verbose; + + if (verbose > 1) + ccdbg_add_debug(CC_DEBUG_BITBANG); + filename = argv[optind]; if (filename == NULL) usage(argv[0]); if (ends_with (filename, ".elf")) { - load = ao_load_elf(filename); + load = ao_load_elf(filename, &file_symbols, &num_file_symbols); } else if (ends_with (filename, ".ihx")) { - int i; - load = ccdbg_hex_load(filename); - for (i = 0; i < ao_num_symbols; i++) - ao_symbols[i].addr = ao_symbols[i].default_addr; + load = ao_hex_load(filename, &file_symbols, &num_file_symbols); } else usage(argv[0]); + if (!find_symbols(file_symbols, num_file_symbols, ao_symbols, ao_num_symbols)) + fprintf(stderr, "Cannot find required symbols\n"); + if (use_stlink) { /* Connect to the programming dongle */ @@ -403,7 +440,7 @@ main (int argc, char **argv) if (is_loader) break; printf ("rebooting to loader\n"); - cc_usb_printf(cc, "L\n"); + cc_usb_printf(cc, "X\n"); cc_usb_close(cc); sleep(1); cc = NULL; @@ -412,11 +449,12 @@ main (int argc, char **argv) fprintf(stderr, "Cannot switch to boot loader\n"); exit(1); } +#if 0 { uint8_t check[256]; int i = 0; - ao_self_block_read(cc, 0x08002000, check); + ao_self_block_read(cc, AO_BOOT_APPLICATION_BASE, check); for (;;) { uint8_t block[256]; putchar ('.'); @@ -425,14 +463,15 @@ main (int argc, char **argv) i = 0; } fflush(stdout); - ao_self_block_write(cc, 0x08002000, block); - ao_self_block_read(cc, 0x08002000, block); - if (memcmp(block, check, 256/me ta) != 0) { + ao_self_block_write(cc, AO_BOOT_APPLICATION_BASE, block); + ao_self_block_read(cc, AO_BOOT_APPLICATION_BASE, block); + if (memcmp(block, check, 256) != 0) { fprintf (stderr, "read differed\n"); exit(1); } } } +#endif } /* Go fetch existing config values