FreeCalypso > hg > freecalypso-tools
comparison loadtools/chainload.c @ 0:e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 11 Jun 2016 00:13:35 +0000 |
parents | |
children | 88962b111edc |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e7502631a0f9 |
---|---|
1 /* | |
2 * This module implements the chain-loading of XRAM images via loadagent. | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <stdint.h> | |
7 #include <stdio.h> | |
8 #include <stdlib.h> | |
9 #include <string.h> | |
10 #include <strings.h> | |
11 #include "srecreader.h" | |
12 | |
13 struct srecreader xramimage; | |
14 | |
15 extern struct baudrate *current_baud_rate; | |
16 extern struct baudrate *xram_run_baudrate; | |
17 | |
18 static void | |
19 make_ml_arg(rec, buf) | |
20 u_char *rec; | |
21 char *buf; | |
22 { | |
23 register int i, len; | |
24 register char *s; | |
25 | |
26 len = rec[0] + 1; | |
27 s = buf; | |
28 for (i = 0; i < len; i++) { | |
29 sprintf(s, "%02X", rec[i]); | |
30 s += 2; | |
31 } | |
32 *s = '\0'; | |
33 } | |
34 | |
35 perform_chain_load() | |
36 { | |
37 int resp; | |
38 unsigned long rec_count; | |
39 char *argv[3], srecarg[516]; | |
40 | |
41 if (open_srec_file(&xramimage) < 0) | |
42 exit(1); | |
43 argv[0] = "ML"; | |
44 argv[1] = srecarg; | |
45 argv[2] = 0; | |
46 for (rec_count = 0; ; ) { | |
47 if (read_s_record(&xramimage) < 0) | |
48 exit(1); | |
49 switch (xramimage.record_type) { | |
50 case '0': | |
51 if (xramimage.lineno == 1) | |
52 continue; | |
53 fprintf(stderr, | |
54 "%s: S0 record found in line %d (expected in line 1 only)\n", | |
55 xramimage.filename, xramimage.lineno); | |
56 exit(1); | |
57 case '3': | |
58 case '7': | |
59 if (s3s7_get_addr_data(&xramimage) < 0) | |
60 exit(1); | |
61 break; | |
62 default: | |
63 fprintf(stderr, | |
64 "%s line %d: S%c record type not supported\n", | |
65 xramimage.filename, xramimage.lineno, | |
66 xramimage.record_type); | |
67 exit(1); | |
68 } | |
69 if (xramimage.record_type == '7') | |
70 break; | |
71 /* must be S3 */ | |
72 if (xramimage.datalen < 1) { | |
73 fprintf(stderr, | |
74 "%s line %d: S3 record has zero data length\n", | |
75 xramimage.filename, xramimage.lineno); | |
76 exit(1); | |
77 } | |
78 if (!rec_count) | |
79 printf("Each \'.\' is 100 S-records\n"); | |
80 make_ml_arg(xramimage.record, srecarg); | |
81 tpinterf_make_cmd(argv); | |
82 if (tpinterf_send_cmd()) | |
83 exit(1); | |
84 if (tpinterf_pass_output(1)) | |
85 exit(1); | |
86 rec_count++; | |
87 if (rec_count % 100 == 0) { | |
88 putchar('.'); | |
89 fflush(stdout); | |
90 } | |
91 } | |
92 /* got S7 */ | |
93 fclose(xramimage.openfile); | |
94 if (!rec_count) { | |
95 fprintf(stderr, | |
96 "%s line %d: S7 without any preceding S3 data records\n", | |
97 xramimage.filename, xramimage.lineno); | |
98 exit(1); | |
99 } | |
100 if (xram_run_baudrate != current_baud_rate) { | |
101 resp = loadagent_switch_baud(xram_run_baudrate); | |
102 if (resp) | |
103 exit(1); | |
104 } | |
105 printf("Sending jump command\n"); | |
106 sprintf(srecarg, "%lX", (u_long) xramimage.addr); | |
107 argv[0] = "jump"; | |
108 tpinterf_make_cmd(argv); | |
109 if (tpinterf_send_cmd()) | |
110 exit(1); | |
111 printf("Sent \"%s %s\": XRAM image should now be running!\n", | |
112 argv[0], argv[1]); | |
113 return(0); | |
114 } |