diff options
author | Solomon Peachy <pizza@shaftnet.org> | 2020-07-15 19:40:55 -0400 |
---|---|---|
committer | Solomon Peachy <pizza@shaftnet.org> | 2020-07-24 21:20:13 +0000 |
commit | 092c340a2062fa98b7387fc5fd63578ddae7d0b6 (patch) | |
tree | 98ec96946eeb2ae709cb0528cc6998e21bb9b290 /flash/uart_boot/uart_boot.c | |
parent | 17f7cc92c258bc456a27c3e7c5a19c9409851879 (diff) | |
download | rockbox-092c340a2062fa98b7387fc5fd63578ddae7d0b6.tar.gz rockbox-092c340a2062fa98b7387fc5fd63578ddae7d0b6.zip |
[1/4] Remove SH support and all archos targets
This removes all code specific to SH targets
Change-Id: I7980523785d2596e65c06430f4638eec74a06061
Diffstat (limited to 'flash/uart_boot/uart_boot.c')
-rw-r--r-- | flash/uart_boot/uart_boot.c | 370 |
1 files changed, 0 insertions, 370 deletions
diff --git a/flash/uart_boot/uart_boot.c b/flash/uart_boot/uart_boot.c deleted file mode 100644 index 06750fdbe2..0000000000 --- a/flash/uart_boot/uart_boot.c +++ /dev/null | |||
@@ -1,370 +0,0 @@ | |||
1 | // uart_boot.cpp : Defines the entry point for the console application. | ||
2 | // | ||
3 | |||
4 | #include <stdio.h> | ||
5 | #include <stdlib.h> | ||
6 | #include <string.h> | ||
7 | #include "scalar_types.h" // (U)INT8/16/32 | ||
8 | #include "Uart.h" // platform abstraction for UART | ||
9 | #include "client.h" // client functions | ||
10 | #include "flash.h" // flash high level functions | ||
11 | |||
12 | // command line configuration: what shall we do? | ||
13 | static struct | ||
14 | { | ||
15 | char* szPort; // COM port to use | ||
16 | bool bRecorder; // it's a recorder | ||
17 | bool bArchos; // use the Archos monitor to load, instead of UART boot | ||
18 | bool bSpindown; // spindown the harddisk | ||
19 | bool bReadID; // read manufacturer+device ID | ||
20 | char* szFlashfile; // file to be programmed | ||
21 | char* szDumpfile; // file to dump into | ||
22 | char* szExecfile; // file with the executable | ||
23 | bool bTest; // debug action | ||
24 | bool bHold; // hold power (for FMs & V2s) | ||
25 | bool bBlink; // blink red LED | ||
26 | bool bNoDownload; | ||
27 | } gCmd; | ||
28 | |||
29 | |||
30 | |||
31 | int ProcessCmdLine(int argc, char* argv[]) | ||
32 | { | ||
33 | argc--; // exclude our name | ||
34 | argv++; | ||
35 | |||
36 | memset(&gCmd, 0, sizeof(gCmd)); | ||
37 | |||
38 | if (argc == 0) | ||
39 | { | ||
40 | printf("Usage: uart_boot [-option {filename}]\n"); | ||
41 | printf(" uses activated UART boot mod, box has to be fresh started\n"); | ||
42 | printf("The order of the options does not matter, one letter is sufficient.\n"); | ||
43 | printf("Possible options are (in the order of later processing):\n"); | ||
44 | printf("-port <name of COM port to use>\n"); | ||
45 | printf("-recorder (this is a recorder/FM, default is player if not specified)\n"); | ||
46 | printf("-archos (use Archos bootloader, this one needs powerup while program waits)\n"); | ||
47 | printf("-nodownload (no MiniMon download, it's already active)\n"); | ||
48 | printf("-hold (hold the power, useful for FMs and V2s, so you can release ON)\n"); | ||
49 | printf("-spindown (spindown the harddisk, else it stays on by default)\n"); | ||
50 | printf("-id (read manufacturer and device ID of flash, no checks)\n"); | ||
51 | printf("-flash <filename of binary to program into flash>\n"); | ||
52 | printf("-dump <filename to write flash content to>\n"); | ||
53 | printf("-exec <filename of executable for 0x09000000:0x09000200>\n"); | ||
54 | printf("-test (some test action currently under development, don't use!)\n"); | ||
55 | printf("-blink (blink red LED forever, meant as diagnostics)\n"); | ||
56 | printf("\n"); | ||
57 | printf("Examples:\n"); | ||
58 | printf("uart_boot -r -p COM1 -s -f flashfile.bin -d dumpfile.bin\n"); | ||
59 | printf(" recorder on COM1, spindown HD, program and dump (for e.g. offline verify)\n"); | ||
60 | printf("uart_boot -r -p COM2 -e rockbox.bin\n"); | ||
61 | printf(" recorder on COM2, load Rockbox from file and start it\n"); | ||
62 | exit (0); | ||
63 | } | ||
64 | |||
65 | |||
66 | while (argc) | ||
67 | { | ||
68 | if (!strncmp("-port", *argv, 2)) | ||
69 | { | ||
70 | gCmd.szPort = *++argv; | ||
71 | if (--argc <= 0 || **argv == '-') | ||
72 | { | ||
73 | printf("No argument given for option %s, aborting.\n", argv[-1]); | ||
74 | exit (-2); | ||
75 | } | ||
76 | } | ||
77 | else if (!strncmp("-recorder", *argv, 2)) | ||
78 | { | ||
79 | gCmd.bRecorder = true; | ||
80 | } | ||
81 | else if (!strncmp("-archos", *argv, 2)) | ||
82 | { | ||
83 | gCmd.bArchos = true; | ||
84 | } | ||
85 | else if (!strncmp("-nodownload", *argv, 2)) | ||
86 | { | ||
87 | gCmd.bNoDownload = true; | ||
88 | } | ||
89 | else if (!strncmp("-spindown", *argv, 2)) | ||
90 | { | ||
91 | gCmd.bSpindown = true; | ||
92 | } | ||
93 | else if (!strncmp("-id", *argv, 2)) | ||
94 | { | ||
95 | gCmd.bReadID = true; | ||
96 | } | ||
97 | else if (!strncmp("-flash", *argv, 2)) | ||
98 | { | ||
99 | gCmd.szFlashfile = *++argv; | ||
100 | if (--argc <= 0 || **argv == '-') | ||
101 | { | ||
102 | printf("No argument given for option %s, aborting.\n", argv[-1]); | ||
103 | exit (-2); | ||
104 | } | ||
105 | } | ||
106 | else if (!strncmp("-dump", *argv, 2)) | ||
107 | { | ||
108 | gCmd.szDumpfile = *++argv; | ||
109 | if (--argc <= 0 || **argv == '-') | ||
110 | { | ||
111 | printf("No argument given for option %s, aborting.\n", argv[-1]); | ||
112 | exit (-3); | ||
113 | } | ||
114 | } | ||
115 | else if (!strncmp("-exec", *argv, 2)) | ||
116 | { | ||
117 | gCmd.szExecfile = *++argv; | ||
118 | if (--argc <= 0 || **argv == '-') | ||
119 | { | ||
120 | printf("No argument given for option %s, aborting.\n", argv[-1]); | ||
121 | exit (-4); | ||
122 | } | ||
123 | } | ||
124 | else if (!strncmp("-test", *argv, 2)) | ||
125 | { | ||
126 | gCmd.bTest = true; | ||
127 | } | ||
128 | else if (!strncmp("-hold", *argv, 2)) | ||
129 | { | ||
130 | gCmd.bHold = true; | ||
131 | } | ||
132 | else if (!strncmp("-blink", *argv, 2)) | ||
133 | { | ||
134 | gCmd.bBlink = true; | ||
135 | } | ||
136 | else | ||
137 | { | ||
138 | printf("Unknown option %s, aborting. Use 'uart_boot' without options for help.\n", *argv); | ||
139 | exit(-1); | ||
140 | } | ||
141 | |||
142 | argv++; | ||
143 | argc--; | ||
144 | } | ||
145 | |||
146 | return 0; | ||
147 | } | ||
148 | |||
149 | |||
150 | int main(int argc, char* argv[]) | ||
151 | { | ||
152 | tUartHandle serial_handle; | ||
153 | UINT16 reg; | ||
154 | FILE* pFile; | ||
155 | size_t size; | ||
156 | static UINT8 abFirmware[256*1024]; // blocksize | ||
157 | memset(abFirmware, 0xFF, sizeof(abFirmware)); | ||
158 | |||
159 | ProcessCmdLine(argc, argv); // what to do | ||
160 | |||
161 | if (!gCmd.szPort) | ||
162 | { | ||
163 | printf("No serial port given, use 'uart_boot' without parameters for options.\n"); | ||
164 | exit(-1); | ||
165 | } | ||
166 | |||
167 | serial_handle = UartOpen(gCmd.szPort); // opening serial port | ||
168 | if (serial_handle == NULL) | ||
169 | { | ||
170 | printf("Cannot open port %s\n", gCmd.szPort); | ||
171 | return -1; | ||
172 | } | ||
173 | |||
174 | if (gCmd.bNoDownload) | ||
175 | { // just set our speed | ||
176 | int baudrate = gCmd.bRecorder ? 115200 : 14400; | ||
177 | if (!gCmd.bRecorder && gCmd.bTest) | ||
178 | { // experimental Player speedup to 38400 baud | ||
179 | baudrate = 38400; | ||
180 | } | ||
181 | |||
182 | if (!UartConfig(serial_handle, baudrate, eNOPARITY, eONESTOPBIT, 8)) | ||
183 | { | ||
184 | printf("Error setting up COM params\n"); | ||
185 | exit(1); | ||
186 | } | ||
187 | } | ||
188 | else | ||
189 | { // download the monitor program | ||
190 | if (gCmd.bArchos) | ||
191 | { | ||
192 | printf("Waiting for box startup to download monitor..."); | ||
193 | DownloadArchosMonitor(serial_handle, "minimon_archos.bin"); // load the monitor image | ||
194 | printf("\b\b\b done.\n"); | ||
195 | } | ||
196 | else | ||
197 | { | ||
198 | printf("Downloading monitor..."); | ||
199 | DownloadMonitor(serial_handle, gCmd.bRecorder, "minimon.bin"); // load the monitor image | ||
200 | // From now on, we can talk to the box. | ||
201 | printf("\b\b\b done.\n"); | ||
202 | |||
203 | if (gCmd.bRecorder) | ||
204 | { // we can be faster | ||
205 | SetTargetBaudrate(serial_handle, 11059200, 115200); // set to 115200 | ||
206 | } | ||
207 | else if (gCmd.bTest) // experimental Player speedup to 38400 baud | ||
208 | { | ||
209 | SetTargetBaudrate(serial_handle, 12000000, 38400); // set to 38400 | ||
210 | } | ||
211 | } | ||
212 | } | ||
213 | |||
214 | |||
215 | // do the action | ||
216 | if (gCmd.bHold) | ||
217 | { | ||
218 | // hold power for FM | ||
219 | reg = ReadHalfword(serial_handle, 0x05FFFFC2); // PBDR | ||
220 | reg |= 0x0020; // set PB5 to keep power | ||
221 | WriteHalfword(serial_handle, 0x05FFFFC2, reg); | ||
222 | |||
223 | reg = ReadHalfword(serial_handle, 0x05FFFFC6); // PBIOR | ||
224 | reg |= 0x0020; // make PB5 an output | ||
225 | WriteHalfword(serial_handle, 0x05FFFFC6, reg); | ||
226 | printf("Power hold, you can release ON button now.\n"); | ||
227 | } | ||
228 | |||
229 | |||
230 | if (gCmd.bSpindown) | ||
231 | { | ||
232 | // power down the disk | ||
233 | if (gCmd.bRecorder) | ||
234 | { // Recorder (V1+V2) and FM have disk power control on PA5 | ||
235 | reg = ReadHalfword(serial_handle, 0x05FFFFCA); // PACR2 | ||
236 | reg &= ~0x0400; // clear bit 10: GPIO | ||
237 | WriteHalfword(serial_handle, 0x05FFFFCA, reg); | ||
238 | |||
239 | reg = ReadHalfword(serial_handle, 0x05FFFFC4); // PAIOR | ||
240 | reg |= 0x0020; // set bit 5: output | ||
241 | WriteHalfword(serial_handle, 0x05FFFFC4, reg); | ||
242 | |||
243 | reg = ReadHalfword(serial_handle, 0x05FFFFC0); // PADR | ||
244 | reg &= ~0x0020; // clear PA5 to power down | ||
245 | WriteHalfword(serial_handle, 0x05FFFFC0, reg); | ||
246 | } | ||
247 | else | ||
248 | { // new Players have disk power control on PB4 | ||
249 | reg = ReadHalfword(serial_handle, 0x05FFFFC6); // PBIOR | ||
250 | reg |= 0x0010; // set bit 4: output | ||
251 | WriteHalfword(serial_handle, 0x05FFFFC6, reg); | ||
252 | |||
253 | reg = ReadHalfword(serial_handle, 0x05FFFFC2); // PBDR | ||
254 | reg &= ~0x0010; // clear PB4 to power down | ||
255 | WriteHalfword(serial_handle, 0x05FFFFC2, reg); | ||
256 | } | ||
257 | printf("Harddisk powered down.\n"); | ||
258 | } | ||
259 | |||
260 | |||
261 | if (gCmd.bReadID) | ||
262 | { | ||
263 | UINT8 bMan, bID; | ||
264 | ReadID(serial_handle, 0x02000000, &bMan, &bID); | ||
265 | printf("Manufacturer ID = 0x%02X, Device ID = 0x%02X\n", bMan, bID); | ||
266 | } | ||
267 | |||
268 | |||
269 | if (gCmd.szFlashfile) | ||
270 | { | ||
271 | // flash a firmware file | ||
272 | printf("Flashing file %s...", gCmd.szFlashfile); | ||
273 | pFile = fopen(gCmd.szFlashfile, "rb"); | ||
274 | if (pFile == NULL) | ||
275 | { | ||
276 | printf("\nFlash file %s not found, exiting.\n", gCmd.szFlashfile); | ||
277 | return -2; | ||
278 | } | ||
279 | size = fread(abFirmware, 1, sizeof(abFirmware), pFile); | ||
280 | fclose (pFile); | ||
281 | |||
282 | EraseChip(serial_handle, 0x02000000); | ||
283 | FlashByteMultiple(serial_handle, 0x02000000, size, abFirmware); | ||
284 | printf("\b\b\b done.\n"); | ||
285 | } | ||
286 | |||
287 | |||
288 | if (gCmd.szDumpfile) | ||
289 | { | ||
290 | // dump the flash content | ||
291 | printf("Writing flash dump into file %s...", gCmd.szDumpfile); | ||
292 | ReadByteMultiple(serial_handle, 0x02000000, sizeof(abFirmware), abFirmware); | ||
293 | pFile = fopen(gCmd.szDumpfile, "wb"); | ||
294 | if (pFile == NULL) | ||
295 | { | ||
296 | printf("\nDump file %s cannot be opened, exiting.\n", gCmd.szDumpfile); | ||
297 | return -3; | ||
298 | } | ||
299 | fwrite(abFirmware, 1, sizeof(abFirmware), pFile); | ||
300 | fclose (pFile); | ||
301 | printf("\b\b\b done.\n"); | ||
302 | } | ||
303 | |||
304 | |||
305 | if (gCmd.szExecfile) | ||
306 | { | ||
307 | UINT32 size; | ||
308 | |||
309 | printf("Downloading program..."); | ||
310 | |||
311 | // init the DRAM controller like the flash boot does | ||
312 | reg = ReadHalfword(serial_handle, 0x05FFFFCA); // PACR2 | ||
313 | reg &= 0xFFFB; // PA1 config: /RAS | ||
314 | reg |= 0x0008; | ||
315 | WriteHalfword(serial_handle, 0x05FFFFCA, reg); // PACR2 | ||
316 | reg = 0xAFFF; // CS1, CS3 config: /CASH. /CASL | ||
317 | WriteHalfword(serial_handle, 0x05FFFFEE, reg); // CASCR | ||
318 | reg = ReadHalfword(serial_handle, 0x05FFFFA0); // BCR | ||
319 | reg |= 0x8000; // DRAM enable, default bus | ||
320 | WriteHalfword(serial_handle, 0x05FFFFA0, reg); // BCR | ||
321 | reg = ReadHalfword(serial_handle, 0x05FFFFA2); // WCR1 | ||
322 | reg &= 0xFDFD; // 1-cycle CAS | ||
323 | WriteHalfword(serial_handle, 0x05FFFFA2, reg); // WCR1 | ||
324 | reg = 0x0E00; // CAS 35%, multiplexed, 10 bit row addr. | ||
325 | WriteHalfword(serial_handle, 0x05FFFFA8, reg); // DCR | ||
326 | reg = 0x5AB0; // refresh, 4 cycle waitstate | ||
327 | WriteHalfword(serial_handle, 0x05FFFFAC, reg); // RCR | ||
328 | reg = 0x9605; // refresh constant | ||
329 | WriteHalfword(serial_handle, 0x05FFFFB2, reg); // RTCOR | ||
330 | reg = 0xA518; // phi/32 | ||
331 | WriteHalfword(serial_handle, 0x05FFFFAE, reg); // RTCSR | ||
332 | |||
333 | |||
334 | // download Rockbox/gdb | ||
335 | pFile = fopen(gCmd.szExecfile, "rb"); | ||
336 | if (pFile == NULL) | ||
337 | { | ||
338 | printf("\nExecutable file %s cannot be opened, exiting.\n", gCmd.szExecfile); | ||
339 | return -3; | ||
340 | } | ||
341 | |||
342 | size = fread(abFirmware, 1, sizeof(abFirmware), pFile); | ||
343 | WriteByteMultiple(serial_handle, 0x09000000, size, abFirmware); | ||
344 | fclose (pFile); | ||
345 | printf("\b\b\b done.\n"); | ||
346 | |||
347 | // start rockbox/gdb | ||
348 | printf("Starting program..."); | ||
349 | Execute(serial_handle, 0x09000200, false); | ||
350 | printf("\b\b\b done.\n"); | ||
351 | } | ||
352 | |||
353 | |||
354 | if (gCmd.bBlink) | ||
355 | { | ||
356 | // blinking LED | ||
357 | UINT8 byte; | ||
358 | printf("Flashing red LED forever... (stop with Ctrl-C)\n"); | ||
359 | byte = ReadByte(serial_handle, 0x05FFFFC3); | ||
360 | while (1) | ||
361 | { | ||
362 | byte ^= 0x40; | ||
363 | WriteByte(serial_handle, 0x05FFFFC3, byte); | ||
364 | Sleep(200); | ||
365 | } | ||
366 | } | ||
367 | |||
368 | return 0; | ||
369 | } | ||
370 | |||