annotate loadtools/romload.c @ 681:0815661d6e3e

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