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