FreeCalypso > hg > freecalypso-tools
annotate target-utils/loadagent/binload.c @ 700:db9a8e88e63f
target-utils lunadrv program written, compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 07 May 2020 02:19:51 +0000 |
parents | 3229940734e5 |
children |
rev | line source |
---|---|
648
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * Here we are going to implement our new binary protocol for RAM loading |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * for a faster version of fc-xram. |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include "types.h" |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 void |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 cmd_binary_memload() |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 { |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 int state, recptr, extlen, datalen; |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 u8 record[256], cksum; |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 u32 addr; |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 u16 rec_count; |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 int c, i; |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 rec_count = 0; |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 for (state = 0; ; ) { |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 switch (state) { |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 case 0: |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 c = serial_in_timeout(3000000); /* 1.8 s */ |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 if (c < 0 || c == 0x04) |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 return; |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 if (c == 0x05) { |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 serial_out(0x06); /* ACK */ |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 serial_out(rec_count >> 8); |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 serial_out(rec_count); |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 continue; |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 } |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 if (c >= 6) { |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 record[0] = c; |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 extlen = c + 1; |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 datalen = c - 5; |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 recptr = 1; |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 state = 1; |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 continue; |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 } |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 serial_out(0x15); /* NAK */ |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 state = 2; |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 continue; |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 case 1: |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 c = serial_in_timeout(1000000); /* 0.6 s */ |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 if (c < 0) { |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 serial_out(0x15); /* NAK */ |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 state = 2; |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 continue; |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 } |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 record[recptr++] = c; |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 if (recptr < extlen) |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 continue; |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 /* verify checksum */ |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 cksum = 0; |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 for (i = 0; i < extlen; i++) |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 cksum += record[i]; |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 if (cksum != 0xFF) { |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 serial_out(0x15); /* NAK */ |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 state = 2; |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 continue; |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 } |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 addr = ((u32)record[1] << 24) | |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 ((u32)record[2] << 16) | |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 ((u32)record[3] << 8) | |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 (u32)record[4]; |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 memcpy(addr, record + 5, datalen); |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 rec_count++; |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 state = 0; |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 continue; |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 default: |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 c = serial_in_timeout(10000000); /* 6.15 s */ |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 if (c < 0) |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 return; |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 serial_out_if_empty(0x15); /* NAK */ |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 continue; |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 } |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 } |
3229940734e5
loadagent: binary memload command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 } |