X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=ao-tools%2Fao-load%2Fao-load.c;fp=ao-tools%2Fao-load%2Fao-load.c;h=1b729d393a7bba5f7f3942f4768b3bee480e946c;hp=5accefc88e3f14995273df0aafcdda8aed57c7e7;hb=d007bccf6cb36d24a9c7c48de7d80759ac6f2e37;hpb=57d83f51377fb58018f422e42d74f29b86a821d2 diff --git a/ao-tools/ao-load/ao-load.c b/ao-tools/ao-load/ao-load.c index 5accefc8..1b729d39 100644 --- a/ao-tools/ao-load/ao-load.c +++ b/ao-tools/ao-load/ao-load.c @@ -29,17 +29,18 @@ struct sym { unsigned addr; char *name; + int required; } ao_symbols[] = { - { 0, "_ao_serial_number" }, + { 0, "_ao_serial_number", 1 }, #define AO_SERIAL_NUMBER (ao_symbols[0].addr) - { 0, "_ao_usb_descriptors" }, + { 0, "_ao_usb_descriptors", 0 }, #define AO_USB_DESCRIPTORS (ao_symbols[1].addr) - { 0, "_ao_radio_cal" }, + { 0, "_ao_radio_cal", 1 }, #define AO_RADIO_CAL (ao_symbols[2].addr) }; -#define NUM_SERIAL_SYMBOLS 2 #define NUM_SYMBOLS 3 +#define NUM_REQUIRED_SYMBOLS 2 static int find_symbols(FILE *map) @@ -51,7 +52,7 @@ find_symbols(FILE *map) char *colon; unsigned long a; int s; - int found = 0; + int required = 0; while (fgets(line, sizeof(line), map) != NULL) { line[sizeof(line)-1] = '\0'; @@ -70,11 +71,12 @@ find_symbols(FILE *map) for (s = 0; s < NUM_SYMBOLS; s++) if (!strcmp(ao_symbols[s].name, name)) { ao_symbols[s].addr = (unsigned) a; - ++found; + if (ao_symbols[s].required) + ++required; break; } } - return found >= NUM_SERIAL_SYMBOLS; + return required >= NUM_REQUIRED_SYMBOLS; } static int @@ -125,7 +127,6 @@ main (int argc, char **argv) char serial_int[2]; unsigned int s; int i; - unsigned usb_descriptors; int string_num; char *tty = NULL; char *device = NULL; @@ -207,35 +208,38 @@ main (int argc, char **argv) exit(1); } - usb_descriptors = AO_USB_DESCRIPTORS - image->address; - string_num = 0; - while (image->data[usb_descriptors] != 0 && usb_descriptors < image->length) { - if (image->data[usb_descriptors+1] == AO_USB_DESC_STRING) { - ++string_num; - if (string_num == 4) - break; + if (AO_USB_DESCRIPTORS) { + unsigned usb_descriptors; + usb_descriptors = AO_USB_DESCRIPTORS - image->address; + string_num = 0; + while (image->data[usb_descriptors] != 0 && usb_descriptors < image->length) { + if (image->data[usb_descriptors+1] == AO_USB_DESC_STRING) { + ++string_num; + if (string_num == 4) + break; + } + usb_descriptors += image->data[usb_descriptors]; + } + if (usb_descriptors >= image->length || image->data[usb_descriptors] == 0 ) { + fprintf(stderr, "Cannot rewrite serial string at %04x\n", AO_USB_DESCRIPTORS); + exit(1); } - usb_descriptors += image->data[usb_descriptors]; - } - if (usb_descriptors >= image->length || image->data[usb_descriptors] == 0 ) { - fprintf(stderr, "Cannot rewrite serial string at %04x\n", AO_USB_DESCRIPTORS); - exit(1); - } - serial_ucs2_len = image->data[usb_descriptors] - 2; - serial_ucs2 = malloc(serial_ucs2_len); - if (!serial_ucs2) { - fprintf(stderr, "Malloc(%d) failed\n", serial_ucs2_len); - exit(1); - } - s = serial; - for (i = serial_ucs2_len / 2; i; i--) { - serial_ucs2[i * 2 - 1] = 0; - serial_ucs2[i * 2 - 2] = (s % 10) + '0'; - s /= 10; + serial_ucs2_len = image->data[usb_descriptors] - 2; + serial_ucs2 = malloc(serial_ucs2_len); + if (!serial_ucs2) { + fprintf(stderr, "Malloc(%d) failed\n", serial_ucs2_len); + exit(1); + } + s = serial; + for (i = serial_ucs2_len / 2; i; i--) { + serial_ucs2[i * 2 - 1] = 0; + serial_ucs2[i * 2 - 2] = (s % 10) + '0'; + s /= 10; + } + if (!rewrite(image, usb_descriptors + 2 + image->address, serial_ucs2, serial_ucs2_len)) + usage(argv[0]); } - if (!rewrite(image, usb_descriptors + 2 + image->address, serial_ucs2, serial_ucs2_len)) - usage(argv[0]); if (cal) { cal_int[0] = cal & 0xff;