FreeCalypso > hg > freecalypso-sw
comparison loadtools/chainload.c @ 42:5da0cbee2b89
fc-xram tool written, compiles, now needs to be debugged
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Mon, 17 Jun 2013 07:18:04 +0000 |
parents | |
children | 5ca0ad4003a0 |
comparison
equal
deleted
inserted
replaced
41:1c50add5e202 | 42:5da0cbee2b89 |
---|---|
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 static void | |
16 make_ml_arg(rec, buf) | |
17 u_char *rec; | |
18 char *buf; | |
19 { | |
20 register int i, len; | |
21 register char *s; | |
22 | |
23 len = rec[0] + 1; | |
24 s = buf; | |
25 for (i = 0; i < len; i++) { | |
26 sprintf(s, "%02X", rec[i]); | |
27 s += 2; | |
28 } | |
29 *s = '\0'; | |
30 } | |
31 | |
32 perform_chain_load() | |
33 { | |
34 int resp; | |
35 unsigned long rec_count; | |
36 char *argv[3], srecarg[516]; | |
37 | |
38 if (open_srec_file(&xramimage) < 0) | |
39 exit(1); | |
40 argv[0] = "ML"; | |
41 argv[1] = srecarg; | |
42 argv[2] = 0; | |
43 for (rec_count = 0; ; ) { | |
44 if (read_s_record(&xramimage) < 0) | |
45 exit(1); | |
46 switch (xramimage.record_type) { | |
47 case '0': | |
48 if (xramimage.lineno == 1) | |
49 continue; | |
50 fprintf(stderr, | |
51 "%s: S0 record found in line %d (expected in line 1 only)\n", | |
52 xramimage.filename, xramimage.lineno); | |
53 exit(1); | |
54 case '3': | |
55 case '7': | |
56 if (s3s7_get_addr_data(&xramimage) < 0) | |
57 exit(1); | |
58 break; | |
59 default: | |
60 fprintf(stderr, | |
61 "%s line %d: S%c record type not supported\n", | |
62 xramimage.filename, xramimage.lineno, | |
63 xramimage.record_type); | |
64 exit(1); | |
65 } | |
66 if (xramimage.record_type == '7') | |
67 break; | |
68 /* must be S3 */ | |
69 if (xramimage.datalen < 1) { | |
70 fprintf(stderr, | |
71 "%s line %d: S3 record has zero data length\n", | |
72 xramimage.filename, xramimage.lineno); | |
73 exit(1); | |
74 } | |
75 make_ml_arg(xramimage.record, srecarg); | |
76 tpinterf_make_cmd(argv); | |
77 if (tpinterf_send_cmd()) | |
78 exit(1); | |
79 if (tpinterf_pass_output(1)) | |
80 exit(1); | |
81 putchar('.'); | |
82 fflush(stdout); | |
83 rec_count++; | |
84 } | |
85 /* got S7 */ | |
86 fclose(xramimage.openfile); | |
87 if (!rec_count) { | |
88 fprintf(stderr, | |
89 "%s line %d: S7 without any preceding S3 data records\n", | |
90 xramimage.filename, xramimage.lineno); | |
91 exit(1); | |
92 } | |
93 sprintf(srecarg, "%lX", (u_long) xramimage.addr); | |
94 argv[0] = "jump"; | |
95 tpinterf_make_cmd(argv); | |
96 if (tpinterf_send_cmd()) | |
97 exit(1); | |
98 printf("Sent \"%s %s\": XRAM image should now be running!\n", | |
99 argv[0], argv[1]); | |
100 return(0); | |
101 } |