- }
-
- if (AO_USB_DESCRIPTORS) {
- unsigned usb_descriptors;
- usb_descriptors = AO_USB_DESCRIPTORS - load->addr;
- string_num = 0;
-
- while (load->buf[usb_descriptors] != 0 && usb_descriptors < load->len) {
- if (load->buf[usb_descriptors+1] == AO_USB_DESC_STRING) {
- ++string_num;
- if (string_num == 4)
- break;
- }
- usb_descriptors += load->buf[usb_descriptors];
- }
- if (usb_descriptors >= load->len || load->buf[usb_descriptors] == 0 ) {
- fprintf(stderr, "Cannot rewrite serial string at %08x\n", AO_USB_DESCRIPTORS);
- done(sl, 1);
- }
-
- serial_ucs2_len = load->buf[usb_descriptors] - 2;
- serial_ucs2 = malloc(serial_ucs2_len);
- if (!serial_ucs2) {
- fprintf(stderr, "Malloc(%d) failed\n", serial_ucs2_len);
- done(sl, 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(load, usb_descriptors + 2 + load->addr, serial_ucs2, serial_ucs2_len)) {
- fprintf (stderr, "Cannot rewrite USB descriptor at %08x\n", AO_USB_DESCRIPTORS);
- done(sl, 1);
- }
- }
-
- if (cal && AO_RADIO_CAL) {
- cal_int[0] = cal & 0xff;
- cal_int[1] = (cal >> 8) & 0xff;
- cal_int[2] = (cal >> 16) & 0xff;
- cal_int[3] = (cal >> 24) & 0xff;
-
- if (!rewrite(load, AO_RADIO_CAL, cal_int, sizeof (cal_int))) {
- fprintf(stderr, "Cannot rewrite radio calibration at %08x\n", AO_RADIO_CAL);
- exit(1);
- }
- }