FreeCalypso > hg > freecalypso-tools
annotate loadtools/romload.c @ 649:141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 02 Mar 2020 02:45:35 +0000 |
parents | 3172e3111ab7 |
children | 46d7ed4ee634 |
rev | line source |
---|---|
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements the communication protocol for pushing our |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * IRAM-loadable code to the Calypso ROM bootloader. |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <sys/ioctl.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <sys/time.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <sys/errno.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdint.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdio.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <stdlib.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <strings.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <termios.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include <unistd.h> |
250
8c011177adb9
loadtools reworked to use factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
16 #include "../libserial/baudrate.h" |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #include "srecreader.h" |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 extern int errno; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 extern char *target_ttydev; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 extern int target_fd; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 extern struct baudrate baud_rate_table[]; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 extern struct baudrate *find_baudrate_by_name(); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 struct srecreader iramimage; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 struct baudrate *romload_baud_rate = baud_rate_table; /* 1st entry default */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 static int beacon_interval = 13; /* in milliseconds */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 static u_char beacon_cmd[2] = {'<', 'i'}; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 static u_char param_cmd[11] = {'<', 'p', |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 0x00, /* baud rate select code (115200) */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 0x00, /* DPLL setup: leave it off like on power-up, */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 /* OsmocomBB does the same thing */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 0x00, 0x04, /* chip select timing (WS) settings */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 /* our setting matches both OsmocomBB */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 /* and what the ROM runs with */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 /* before receiving this command */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 0x22, /* FFFF:F900 register config, low byte */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 /* OsmocomBB sends 0x00 here, but I've chosen */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 /* 0x22 to match the setting of this register */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 /* used by the boot ROM before this command. */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 0x00, 0x01, 0xD4, 0xC0 /* UART timeout */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 /* I've chosen the same value as what the */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 /* boot ROM runs with before getting this cmd */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 }; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 |
636
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
50 static u_char write_cmd[1024] = {'<', 'w', 0x01, 0x01}; |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
51 static u_char cksum_cmd[3] = {'<', 'c'}; |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
52 static u_char branch_cmd[6] = {'<', 'b'}; |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
53 |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
54 static uint32_t write_cmd_endaddr; |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
55 static unsigned write_cmd_datalen; |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
56 static unsigned write_block_count; |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
57 static uint16_t image_cksum; |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
58 |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
59 #define MAX_WRITE_LEN 0x3F6 |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 #define INTERMEDIATE_TIMEOUT 500 /* ms to wait for responses */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 #define SERIAL_FLUSH_DELAY 200 /* also in ms */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 /* |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 * The following function should be called by command line option |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 * parsers upon encountering the -i option. |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 set_beacon_interval(arg) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 char *arg; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 int i; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 i = atoi(arg); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 if (i < 2 || i > 500) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 fprintf(stderr, "invalid -i argument specified\n"); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 exit(1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 beacon_interval = i; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 /* |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 * The following function should be called by command line option |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 * parsers upon encountering the -b option. |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 set_romload_baudrate(arg) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 char *arg; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 struct baudrate *br; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 br = find_baudrate_by_name(arg); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 if (!br) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 exit(1); /* error msg already printed */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 if (br->bootrom_code < 0) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 fprintf(stderr, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 "baud rate of %s is not supported by the Calypso boot ROM\n", |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 br->name); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 exit(1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 romload_baud_rate = br; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 /* |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 * The following functions alter some of the parameters sent to the |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 * boot ROM in the <p command. |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 set_romload_pll_conf(byte) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 param_cmd[3] = byte; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 set_romload_rhea_cntl(byte) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 param_cmd[6] = byte; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 static int |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 expect_response(timeout) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 char buf[2]; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 fd_set fds; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 struct timeval tv; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 int pass, cc; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 for (pass = 0; pass < 2; ) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 FD_ZERO(&fds); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 FD_SET(target_fd, &fds); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 tv.tv_sec = 0; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 tv.tv_usec = timeout * 1000; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 cc = select(target_fd+1, &fds, NULL, NULL, &tv); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 if (cc < 0) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 if (errno == EINTR) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 continue; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 perror("select"); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 exit(1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 if (cc < 1) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 return(-1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 cc = read(target_fd, buf + pass, 2 - pass); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 if (cc <= 0) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 perror("read after successful select"); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 exit(1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 if (pass == 0 && buf[0] != '>') |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 continue; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 pass += cc; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 return(buf[1]); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 static |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 send_beacons() |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 printf("Sending beacons to %s\n", target_ttydev); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 do |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 write(target_fd, beacon_cmd, sizeof beacon_cmd); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 while (expect_response(beacon_interval) != 'i'); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 return 0; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 |
633
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
160 static int |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
161 expect_add_response(buf, expect_bytes, timeout) |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
162 u_char *buf; |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
163 { |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
164 fd_set fds; |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
165 struct timeval tv; |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
166 int pass, cc; |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
167 |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
168 for (pass = 0; pass < expect_bytes; ) { |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
169 FD_ZERO(&fds); |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
170 FD_SET(target_fd, &fds); |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
171 tv.tv_sec = 0; |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
172 tv.tv_usec = timeout * 1000; |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
173 cc = select(target_fd+1, &fds, NULL, NULL, &tv); |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
174 if (cc < 0) { |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
175 if (errno == EINTR) |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
176 continue; |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
177 perror("select"); |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
178 exit(1); |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
179 } |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
180 if (cc < 1) |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
181 return(-1); |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
182 cc = read(target_fd, buf + pass, expect_bytes - pass); |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
183 if (cc <= 0) { |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
184 perror("read after successful select"); |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
185 exit(1); |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
186 } |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
187 pass += cc; |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
188 } |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
189 return(0); |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
190 } |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
191 |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 static uint32_t |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 compute_block_cksum() |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 uint32_t sum; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 int i, llen; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 |
636
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
198 sum = write_cmd_datalen + 5; |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
199 llen = write_cmd_datalen + 4; |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 for (i = 0; i < llen; i++) |
636
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
201 sum += write_cmd[i+6]; |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 return sum; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 |
636
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
205 static void |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
206 send_write_cmd() |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
207 { |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
208 int resp; |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
209 |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
210 write_cmd[4] = write_cmd_datalen >> 8; |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
211 write_cmd[5] = write_cmd_datalen & 0xFF; |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
212 write(target_fd, write_cmd, write_cmd_datalen + 10); |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
213 /* update our checksum accumulator */ |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
214 image_cksum += ~compute_block_cksum() & 0xFF; |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
215 /* collect response */ |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
216 resp = expect_response(INTERMEDIATE_TIMEOUT); |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
217 if (resp != 'w') { |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
218 fprintf(stderr, "Block #%lu: ", write_block_count); |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
219 if (resp < 0) |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
220 fprintf(stderr, "No response to <w command\n"); |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
221 else if (isprint(resp)) |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
222 fprintf(stderr, |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
223 "Got >%c in response to <w command; expected >w\n", |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
224 resp); |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
225 else |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
226 fprintf(stderr, |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
227 "Got > %02X in response to <w command; expected >w\n", |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
228 resp); |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
229 exit(1); |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
230 } |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
231 putchar('.'); |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
232 fflush(stdout); |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
233 write_block_count++; |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
234 } |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
235 |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
236 perform_romload() |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
237 { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
238 int resp; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
239 unsigned long rec_count; |
633
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
240 u_char addresp[2]; |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
241 static int zero = 0; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
242 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
243 if (open_srec_file(&iramimage) < 0) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
244 exit(1); |
250
8c011177adb9
loadtools reworked to use factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
245 set_fixed_baudrate("19200"); |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
246 ioctl(target_fd, FIONBIO, &zero); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
247 send_beacons(); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
248 printf("Got beacon response, attempting download\n"); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
249 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
250 usleep(SERIAL_FLUSH_DELAY * 1000); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
251 tcflush(target_fd, TCIFLUSH); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
252 param_cmd[2] = romload_baud_rate->bootrom_code; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
253 write(target_fd, param_cmd, sizeof param_cmd); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
254 resp = expect_response(INTERMEDIATE_TIMEOUT); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
255 if (resp != 'p') { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
256 if (resp < 0) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
257 fprintf(stderr, "No response to <p command\n"); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
258 else if (isprint(resp)) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
259 fprintf(stderr, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
260 "Got >%c in response to <p command; expected >p\n", |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
261 resp); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
262 else |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
263 fprintf(stderr, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
264 "Got > %02X in response to <p command; expected >p\n", |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
265 resp); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
266 exit(1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
267 } |
633
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
268 resp = expect_add_response(addresp, 2, INTERMEDIATE_TIMEOUT); |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
269 if (resp < 0 || addresp[0] != 0x00 || addresp[1] != 0x04) { |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
270 fprintf(stderr, |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
271 "error: extra bytes after >p not received as expected\n"); |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
272 exit(1); |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
273 } |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
274 printf("<p command successful, switching to %s baud\n", |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
275 romload_baud_rate->name); |
250
8c011177adb9
loadtools reworked to use factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
276 set_serial_baudrate(romload_baud_rate); |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
277 usleep(SERIAL_FLUSH_DELAY * 1000); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
278 tcflush(target_fd, TCIFLUSH); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
279 |
636
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
280 write_cmd_datalen = 0; |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
281 write_block_count = 0; |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
282 image_cksum = 0; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
283 for (rec_count = 0; ; ) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
284 if (read_s_record(&iramimage) < 0) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
285 exit(1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
286 switch (iramimage.record_type) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
287 case '0': |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
288 if (iramimage.lineno == 1) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
289 continue; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
290 fprintf(stderr, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
291 "%s: S0 record found in line %d (expected in line 1 only)\n", |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
292 iramimage.filename, iramimage.lineno); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
293 exit(1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
294 case '3': |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
295 case '7': |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
296 if (s3s7_get_addr_data(&iramimage) < 0) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
297 exit(1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
298 break; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
299 default: |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
300 fprintf(stderr, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
301 "%s line %d: S%c record type not supported\n", |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
302 iramimage.filename, iramimage.lineno, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
303 iramimage.record_type); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
304 exit(1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
305 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
306 if (iramimage.record_type == '7') |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
307 break; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
308 /* must be S3 */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
309 if (iramimage.datalen < 1) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
310 fprintf(stderr, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
311 "%s line %d: S3 record has zero data length\n", |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
312 iramimage.filename, iramimage.lineno); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
313 exit(1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
314 } |
636
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
315 /* get to work */ |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
316 if (!rec_count) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
317 printf("Sending image payload\n"); |
636
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
318 if (write_cmd_datalen && |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
319 (iramimage.addr != write_cmd_endaddr || |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
320 write_cmd_datalen + iramimage.datalen > MAX_WRITE_LEN)) { |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
321 send_write_cmd(); |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
322 write_cmd_datalen = 0; |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
323 } |
636
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
324 if (!write_cmd_datalen) { |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
325 bcopy(iramimage.record + 1, write_cmd + 6, 4); |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
326 write_cmd_endaddr = iramimage.addr; |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
327 } |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
328 bcopy(iramimage.record + 5, write_cmd + 10 + write_cmd_datalen, |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
329 iramimage.datalen); |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
330 write_cmd_endaddr += iramimage.datalen; |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
331 write_cmd_datalen += iramimage.datalen; |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
332 rec_count++; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
333 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
334 /* got S7 */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
335 fclose(iramimage.openfile); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
336 if (!rec_count) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
337 fprintf(stderr, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
338 "%s line %d: S7 without any preceding S3 data records\n", |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
339 iramimage.filename, iramimage.lineno); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
340 exit(1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
341 } |
636
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
342 send_write_cmd(); /* last block */ |
3172e3111ab7
loadtools/romload.c: implemented grouping of S-records into bigger blocks
Mychaela Falconia <falcon@freecalypso.org>
parents:
633
diff
changeset
|
343 putchar('\n'); /* end line of dots */ |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
344 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
345 /* send <c */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
346 printf("Sending checksum\n"); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
347 cksum_cmd[2] = ~image_cksum & 0xFF; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
348 write(target_fd, cksum_cmd, sizeof cksum_cmd); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
349 resp = expect_response(INTERMEDIATE_TIMEOUT); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
350 if (resp != 'c') { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
351 if (resp < 0) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
352 fprintf(stderr, "No response to <c command\n"); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
353 else if (isprint(resp)) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
354 fprintf(stderr, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
355 "Got >%c in response to <c command; expected >c\n", |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
356 resp); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
357 else |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
358 fprintf(stderr, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
359 "Got > %02X in response to <c command; expected >c\n", |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
360 resp); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
361 exit(1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
362 } |
633
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
363 resp = expect_add_response(addresp, 1, INTERMEDIATE_TIMEOUT); |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
364 if (resp < 0) { |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
365 fprintf(stderr, |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
366 "error: extra byte after >c not received as expected\n"); |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
367 exit(1); |
4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
Mychaela Falconia <falcon@freecalypso.org>
parents:
574
diff
changeset
|
368 } |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
369 printf("<c command successful, sending <b\n"); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
370 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
371 bcopy(iramimage.record + 1, branch_cmd + 2, 4); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
372 write(target_fd, branch_cmd, sizeof branch_cmd); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
373 resp = expect_response(INTERMEDIATE_TIMEOUT); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
374 if (resp != 'b') { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
375 if (resp < 0) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
376 fprintf(stderr, "No response to <b command\n"); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
377 else if (isprint(resp)) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
378 fprintf(stderr, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
379 "Got >%c in response to <b command; expected >b\n", |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
380 resp); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
381 else |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
382 fprintf(stderr, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
383 "Got > %02X in response to <b command; expected >b\n", |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
384 resp); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
385 exit(1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
386 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
387 printf("<b command successful: downloaded image should now be running!\n"); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
388 return(0); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
389 } |