FreeCalypso > hg > freecalypso-tools
view loadtools/chainload.c @ 651:6bb41b4d39ed
fc-xram number of records per batch made baudrate-dependent
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 02 Mar 2020 03:39:46 +0000 |
parents | bf840c984113 |
children | 9f5a3e9e6294 |
line wrap: on
line source
/* * This module implements the chain-loading of XRAM images via loadagent. */ #include <sys/types.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <strings.h> #include <time.h> #include "../libserial/baudrate.h" #include "srecreader.h" extern int target_fd; struct srecreader xramimage; extern struct baudrate *current_baud_rate; extern struct baudrate *xram_run_baudrate; extern int xram_jtag_mode; perform_chain_load() { int resp, reclen; unsigned long rec_count; char *argv[3], jumparg[10]; u_char scratch[3], expect_conf[3]; time_t start_time, finish_time; unsigned duration, mm, ss; if (open_srec_file(&xramimage) < 0) exit(1); /* enter binary RAM download mode */ argv[0] = "BINML"; argv[1] = 0; tpinterf_make_cmd(argv); if (tpinterf_send_cmd()) exit(1); /* read and send S-record image */ expect_conf[0] = 0x06; for (rec_count = 0; ; ) { if (read_s_record(&xramimage) < 0) exit(1); switch (xramimage.record_type) { case '0': if (xramimage.lineno == 1) continue; fprintf(stderr, "%s: S0 record found in line %d (expected in line 1 only)\n", xramimage.filename, xramimage.lineno); exit(1); case '3': case '7': if (s3s7_get_addr_data(&xramimage) < 0) exit(1); break; default: fprintf(stderr, "%s line %d: S%c record type not supported\n", xramimage.filename, xramimage.lineno, xramimage.record_type); exit(1); } if (xramimage.record_type == '7') break; /* must be S3 */ if (xramimage.datalen < 1) { fprintf(stderr, "%s line %d: S3 record has zero data length\n", xramimage.filename, xramimage.lineno); exit(1); } if (!rec_count) { printf("Each \'.\' is %d S-records\n", current_baud_rate->xram_records); time(&start_time); } reclen = xramimage.datalen + 6; if (write(target_fd, xramimage.record, reclen) != reclen) { perror("binary write to target"); exit(1); } rec_count++; if (rec_count % current_baud_rate->xram_records == 0) { scratch[0] = 0x05; /* ENQ */ write(target_fd, scratch, 1); if (collect_binblock_from_target(scratch, 3, 1)) exit(1); expect_conf[1] = rec_count >> 8; expect_conf[2] = rec_count; if (bcmp(scratch, expect_conf, 3)) { fprintf(stderr, "error: expected sync mismatch\n"); exit(1); } putchar('.'); fflush(stdout); } } /* got S7 */ fclose(xramimage.openfile); if (!rec_count) { fprintf(stderr, "%s line %d: S7 without any preceding S3 data records\n", xramimage.filename, xramimage.lineno); exit(1); } putchar('\n'); /* newline after the dots */ scratch[0] = 0x04; /* EOT */ write(target_fd, scratch, 1); if (collect_binblock_from_target(scratch, 1, 1)) exit(1); time(&finish_time); if (scratch[0] != '=') { fprintf(stderr, "error: \'=\' not received as expected\n"); exit(1); } duration = finish_time - start_time; mm = duration / 60; ss = duration - mm * 60; printf("XRAM image transferred in %um%us\n", mm, ss); if (xram_run_baudrate != current_baud_rate) { resp = loadagent_switch_baud(xram_run_baudrate); if (resp) exit(1); } if (xram_jtag_mode) { printf( "Leaving target in loadagent for JTAG; image start address is 0x%08lX\n", (u_long) xramimage.addr); exit(0); } printf("Sending jump command\n"); sprintf(jumparg, "%lX", (u_long) xramimage.addr); argv[0] = "jump"; argv[1] = jumparg; argv[2] = 0; tpinterf_make_cmd(argv); if (tpinterf_send_cmd()) exit(1); printf("Sent \"%s %s\": XRAM image should now be running!\n", argv[0], argv[1]); return(0); }