summaryrefslogtreecommitdiff
path: root/flash/uart_boot
diff options
context:
space:
mode:
Diffstat (limited to 'flash/uart_boot')
-rw-r--r--flash/uart_boot/Makefile19
-rw-r--r--flash/uart_boot/README8
-rw-r--r--flash/uart_boot/client.c737
-rw-r--r--flash/uart_boot/client.h22
-rw-r--r--flash/uart_boot/flash.c78
-rw-r--r--flash/uart_boot/flash.h10
-rw-r--r--flash/uart_boot/minimon.h24
-rw-r--r--flash/uart_boot/scalar_types.h45
-rw-r--r--flash/uart_boot/uart.h57
-rw-r--r--flash/uart_boot/uart_boot.c370
-rw-r--r--flash/uart_boot/uart_boot.dsp130
-rw-r--r--flash/uart_boot/uart_win.c139
12 files changed, 0 insertions, 1639 deletions
diff --git a/flash/uart_boot/Makefile b/flash/uart_boot/Makefile
deleted file mode 100644
index 04db068c07..0000000000
--- a/flash/uart_boot/Makefile
+++ /dev/null
@@ -1,19 +0,0 @@
1# __________ __ ___.
2# Open \______ \ ____ ____ | | _\_ |__ _______ ___
3# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
4# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
5# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
6# \/ \/ \/ \/ \/
7# $Id$
8#
9# This Makefile currently works for cygwin only!
10
11
12CFLAGS := -O -W -Wall -mno-cygwin
13
14uart_boot: uart_boot.c client.c flash.c uart_win.c
15 $(CC) $(CFLAGS) $+ -o $@
16
17clean:
18 -rm -f uart_boot.exe
19
diff --git a/flash/uart_boot/README b/flash/uart_boot/README
deleted file mode 100644
index af2b5ae87d..0000000000
--- a/flash/uart_boot/README
+++ /dev/null
@@ -1,8 +0,0 @@
1(c) 2003 by Jörg Hohensohn
2
3This is the client side for MiniMon, a command line program that communicates with it.
4It can be used to reflash a box from ground up, load a program like gdb stub or Rockbox,
5and other diagnostics.
6
7Current implementation is for Windows, but with a different UART implementation
8it should work for other platforms (Linux) as well.
diff --git a/flash/uart_boot/client.c b/flash/uart_boot/client.c
deleted file mode 100644
index 71749a2c55..0000000000
--- a/flash/uart_boot/client.c
+++ /dev/null
@@ -1,737 +0,0 @@
1// client.cpp : functions for monitor download and communication.
2//
3
4#include <stdio.h>
5#include <stdlib.h>
6#include "scalar_types.h" // (U)INT8/16/32
7#include "Uart.h" // platform abstraction for UART
8#include "minimon.h" // protocol of my little monitor
9
10// do the baudrate configuration for the Player
11int ConfigFirstlevelPlayer (tUartHandle serial_handle)
12{
13 UINT32 result_nbr;
14
15 if(!UartConfig(serial_handle, 4800, eMARKPARITY, eTWOSTOPBITS, 8))
16 {
17 UINT32 dwErr = GET_LAST_ERR();
18 printf("Error %lu setting up COM params for baudrate byte\n", dwErr);
19 exit(1);
20 }
21
22 // this will read as 0x19 when viewed with 2300 baud like the player does
23 result_nbr = UartWrite(serial_handle, (UINT8*)"\x86\xC0", 2);
24 if (result_nbr != 2)
25 {
26 UINT32 dwErr = GET_LAST_ERR();
27 printf("Error %lu setting up COM params for baudrate byte\n", dwErr);
28 }
29
30 SLEEP(100); // wait for the chars to be sent, is there a better way?
31
32 // the read 0x19 means 14423 baud with 12 MHz
33 if(!UartConfig(serial_handle, 14400, eNOPARITY, eONESTOPBIT, 8))
34 {
35 printf("Error setting up COM params for 1st level loader\n");
36 exit(1);
37 }
38
39 return 0;
40}
41
42
43// do the baudrate configuration for the Recoder/FM
44int ConfigFirstlevelRecorder (tUartHandle serial_handle)
45{
46 UINT32 result_nbr;
47
48 if(!UartConfig(serial_handle, 4800, eNOPARITY, eTWOSTOPBITS, 8))
49 {
50 UINT32 dwErr = GET_LAST_ERR();
51 printf("Error %lu setting up COM params for baudrate byte\n", dwErr);
52 exit(1);
53 }
54
55 // this will read as 0x08 when viewed with 2120 baud like the recorder does
56 result_nbr = UartWrite(serial_handle, (UINT8*)"\x00\x00", 2);
57 if(result_nbr != 2)
58 {
59 printf("Error transmitting baudrate byte\n");
60 exit(1);
61 }
62
63 SLEEP(100); // wait for the chars to be sent, is there a better way?
64
65 // the read 0x08 means 38400 baud with 11.0592 MHz
66 if(!UartConfig(serial_handle, 38400, eNOPARITY, eONESTOPBIT, 8))
67 {
68 UINT32 dwErr = GET_LAST_ERR();
69 printf("Error %lu setting up COM params for 1st level loader\n", dwErr);
70 exit(1);
71 }
72
73 return 0;
74}
75
76
77// transfer a byte for the monitor download, with or without acknowledge
78int DownloadByte(tUartHandle serial_handle, unsigned char byte, bool bAck)
79{
80 unsigned char received;
81
82 while (1)
83 {
84 UartWrite(serial_handle, &byte, 1);
85 if (bAck)
86 {
87 UartRead(serial_handle, &received, 1);
88 if (received == byte)
89 {
90 UartWrite(serial_handle, (UINT8*)"\x01", 1); // ack success
91 break; // exit the loop
92 }
93 else
94 {
95 printf("Error transmitting monitor byte 0x%02X, got 0x%0X\n", byte, received);
96 UartWrite(serial_handle, (UINT8*)"\x00", 1); // ack fail, try again
97 }
98 }
99 else
100 break; // no loop
101 }
102 return 1;
103}
104
105
106// download our little monitor, the box must have been just freshly switched on for this to work
107int DownloadMonitor(tUartHandle serial_handle, bool bRecorder, char* szFilename)
108{
109 FILE* pFile;
110 size_t filesize;
111 UINT8 byte;
112 unsigned i;
113
114 // hard-coded parameters
115 bool bAck = true; // configure if acknowledged download (without useful for remote pin boot)
116 UINT32 TargetLoad = 0x0FFFF000; // target load address
117
118 pFile = fopen(szFilename, "rb");
119 if (pFile == NULL)
120 {
121 printf("\nMonitor file %s not found, exiting\n", szFilename);
122 exit(1);
123 }
124
125 // determine file size
126 fseek(pFile, 0, SEEK_END);
127 filesize = ftell(pFile);
128 fseek(pFile, 0, SEEK_SET);
129
130 // This is _really_ tricky! The box expects a BRR value in a nonstandard baudrate,
131 // which a PC can't generate. I'm using a higher one with some wild settings
132 // to generate a pulse series that:
133 // 1) looks like a stable byte when sampled with the nonstandard baudrate
134 // 2) gives a BRR value to the box which results in a baudrate the PC can also use
135 if (bRecorder)
136 {
137 ConfigFirstlevelRecorder(serial_handle);
138 }
139 else
140 {
141 ConfigFirstlevelPlayer(serial_handle);
142 }
143
144 UartWrite(serial_handle, bAck ? (UINT8*)"\x01" : (UINT8*)"\x00", 1); // ACK mode
145
146 // transmit the size, little endian
147 DownloadByte(serial_handle, (UINT8)( filesize & 0xFF), bAck);
148 DownloadByte(serial_handle, (UINT8)((filesize>>8) & 0xFF), bAck);
149 DownloadByte(serial_handle, (UINT8)((filesize>>16) & 0xFF), bAck);
150 DownloadByte(serial_handle, (UINT8)((filesize>>24) & 0xFF), bAck);
151
152 // transmit the load address, little endian
153 DownloadByte(serial_handle, (UINT8)( TargetLoad & 0xFF), bAck);
154 DownloadByte(serial_handle, (UINT8)((TargetLoad>>8) & 0xFF), bAck);
155 DownloadByte(serial_handle, (UINT8)((TargetLoad>>16) & 0xFF), bAck);
156 DownloadByte(serial_handle, (UINT8)((TargetLoad>>24) & 0xFF), bAck);
157
158 // transmit the command byte
159 DownloadByte(serial_handle, 0xFF, bAck); // 0xFF means execute the transferred image
160
161 // transmit the image
162 for (i=0; i<filesize; i++)
163 {
164 fread(&byte, 1, 1, pFile);
165 DownloadByte(serial_handle, byte, bAck);
166 }
167
168 fclose (pFile);
169
170 // now the image should have been started, red LED off
171
172 return 0;
173}
174
175
176// wait for a fixed string to be received (no foolproof algorithm,
177// may overlook if the searched string contains repeatitions)
178int WaitForString(tUartHandle serial_handle, char* pszWait)
179{
180 int i = 0;
181 unsigned char received;
182
183 while(pszWait[i] != '\0')
184 {
185 UartRead(serial_handle, &received, 1);
186
187 printf("%c", received); // debug
188
189 if (received == pszWait[i])
190 i++; // continue
191 else
192 i=0; // mismatch, start over
193 }
194 return 0;
195}
196
197
198// send a sting and check the echo
199int SendWithEcho(tUartHandle serial_handle, char* pszSend)
200{
201 int i = 0;
202 unsigned char received;
203
204 while(pszSend[i] != '\0')
205 {
206 UartWrite(serial_handle, (unsigned char*)(pszSend + i), 1); // send char
207 do
208 {
209 UartRead(serial_handle, &received, 1); // receive echo
210 printf("%c", received); // debug
211 }
212 while (received != pszSend[i]); // should normally be equal
213 i++; // next char
214 }
215 return 0;
216}
217
218
219// rarely used variant: download our monitor using the built-in Archos monitor
220int DownloadArchosMonitor(tUartHandle serial_handle, char* szFilename)
221{
222 FILE* pFile;
223 size_t filesize;
224 UINT8 byte;
225 UINT16 checksum = 0;
226 unsigned i;
227
228 // the onboard monitor uses 115200 baud
229 if(!UartConfig(serial_handle, 115200, eNOPARITY, eONESTOPBIT, 8))
230 {
231 UINT32 dwErr = GET_LAST_ERR();
232 printf("Error %lu setting up COM params for baudrate %d\n", dwErr, 115200);
233 exit(1);
234 }
235
236 // wait for receiving "#SERIAL#"
237 WaitForString(serial_handle, "#SERIAL#");
238
239 // send magic "SRL" command to get interactive mode
240 SendWithEcho(serial_handle, "SRL\r");
241
242 // wait for menu completion: "ROOT>" at the end
243 WaitForString(serial_handle, "ROOT>");
244
245 // send upload command "UP"
246 SendWithEcho(serial_handle, "UP\r");
247
248 pFile = fopen(szFilename, "rb");
249 if (pFile == NULL)
250 {
251 printf("\nMonitor file %s not found, exiting\n", szFilename);
252 exit(1);
253 }
254
255 // determine file size
256 fseek(pFile, 0, SEEK_END);
257 filesize = ftell(pFile);
258 fseek(pFile, 0, SEEK_SET);
259
260 // calculate checksum
261 for (i=0; i<filesize; i++)
262 {
263 fread(&byte, 1, 1, pFile);
264 checksum += byte;
265 }
266 fseek(pFile, 0, SEEK_SET);
267
268 // send header
269
270 // size as 32 bit little endian
271 byte = (UINT8)( filesize & 0xFF);
272 UartWrite(serial_handle, &byte, 1);
273 byte = (UINT8)((filesize>>8) & 0xFF);
274 UartWrite(serial_handle, &byte, 1);
275 byte = (UINT8)((filesize>>16) & 0xFF);
276 UartWrite(serial_handle, &byte, 1);
277 byte = (UINT8)((filesize>>24) & 0xFF);
278 UartWrite(serial_handle, &byte, 1);
279
280 // checksum as 16 bit little endian
281 byte = (UINT8)( checksum & 0xFF);
282 UartWrite(serial_handle, &byte, 1);
283 byte = (UINT8)((checksum>>8) & 0xFF);
284 UartWrite(serial_handle, &byte, 1);
285
286 UartWrite(serial_handle, (unsigned char*)"\x00", 1); // kind (3 means flash)
287 UartWrite(serial_handle, (unsigned char*)"\x00", 1); // ignored byte
288
289 // wait for monitor to accept data
290 WaitForString(serial_handle, "#OKCTRL#");
291
292 // transmit the image
293 for (i=0; i<filesize; i++)
294 {
295 fread(&byte, 1, 1, pFile);
296 UartWrite(serial_handle, &byte, 1); // payload
297 }
298 fclose (pFile);
299
300 UartWrite(serial_handle, (unsigned char*)"\x00", 1); // ignored byte
301
302 // wait for menu completion: "ROOT>" at the end
303 WaitForString(serial_handle, "ROOT>");
304
305 // send start program command "SPRO"
306 SendWithEcho(serial_handle, "SPRO\r");
307
308 SLEEP(100); // wait a little while for startup
309
310 return 0;
311}
312
313
314/********** Target functions using the Monitor Protocol **********/
315
316// read a byte using the target monitor
317UINT8 ReadByte(tUartHandle serial_handle, UINT32 addr)
318{
319 UINT8 send;
320 UINT8 received;
321
322 // send the address command
323 send = ADDRESS;
324 UartWrite(serial_handle, &send, 1);
325
326 // transmit the address, big endian
327 send = (UINT8)((addr>>24) & 0xFF);
328 UartWrite(serial_handle, &send, 1);
329 send = (UINT8)((addr>>16) & 0xFF);
330 UartWrite(serial_handle, &send, 1);
331 send = (UINT8)((addr>>8) & 0xFF);
332 UartWrite(serial_handle, &send, 1);
333 send = (UINT8)(addr & 0xFF);
334 UartWrite(serial_handle, &send, 1);
335
336 UartRead(serial_handle, &received, 1); // response
337 if (received != ADDRESS)
338 {
339 printf("Protocol error!\n");
340 return 1;
341 }
342
343 // send the read command
344 send = BYTE_READ;
345 UartWrite(serial_handle, &send, 1);
346
347 UartRead(serial_handle, &received, 1); // response
348
349 return received;
350}
351
352
353// write a byte using the target monitor
354int WriteByte(tUartHandle serial_handle, UINT32 addr, UINT8 byte)
355{
356 UINT8 send;
357 UINT8 received;
358
359 // send the address command
360 send = ADDRESS;
361 UartWrite(serial_handle, &send, 1);
362
363 // transmit the address, big endian
364 send = (UINT8)((addr>>24) & 0xFF);
365 UartWrite(serial_handle, &send, 1);
366 send = (UINT8)((addr>>16) & 0xFF);
367 UartWrite(serial_handle, &send, 1);
368 send = (UINT8)((addr>>8) & 0xFF);
369 UartWrite(serial_handle, &send, 1);
370 send = (UINT8)(addr & 0xFF);
371 UartWrite(serial_handle, &send, 1);
372
373 UartRead(serial_handle, &received, 1); // response
374 if (received != ADDRESS)
375 {
376 printf("Protocol error, receiced 0x%02X!\n", received);
377 return 1;
378 }
379
380 // send the write command
381 send = BYTE_WRITE;
382 UartWrite(serial_handle, &send, 1);
383
384 // transmit the data
385 UartWrite(serial_handle, &byte, 1);
386
387 UartRead(serial_handle, &received, 1); // response
388
389 if (received != BYTE_WRITE)
390 {
391 printf("Protocol error!\n");
392 return 1;
393 }
394
395 return 0;
396}
397
398
399// read many bytes using the target monitor
400int ReadByteMultiple(tUartHandle serial_handle, UINT32 addr, UINT32 size, UINT8* pBuffer)
401{
402 UINT8 send, received;
403
404 // send the address command
405 send = ADDRESS;
406 UartWrite(serial_handle, &send, 1);
407
408 // transmit the address, big endian
409 send = (UINT8)((addr>>24) & 0xFF);
410 UartWrite(serial_handle, &send, 1);
411 send = (UINT8)((addr>>16) & 0xFF);
412 UartWrite(serial_handle, &send, 1);
413 send = (UINT8)((addr>>8) & 0xFF);
414 UartWrite(serial_handle, &send, 1);
415 send = (UINT8)(addr & 0xFF);
416 UartWrite(serial_handle, &send, 1);
417
418 UartRead(serial_handle, &received, 1); // response
419 if (received != ADDRESS)
420 {
421 printf("Protocol error!\n");
422 return 1;
423 }
424
425 while (size)
426 {
427 if (size >= 16)
428 { // we can use a "burst" command
429 send = BYTE_READ16;
430 UartWrite(serial_handle, &send, 1); // send the read command
431 UartRead(serial_handle, pBuffer, 16); // data response
432 pBuffer += 16;
433 size -= 16;
434 }
435 else
436 { // use single byte command
437 send = BYTE_READ;
438 UartWrite(serial_handle, &send, 1); // send the read command
439 UartRead(serial_handle, pBuffer++, 1); // data response
440 size--;
441 }
442 }
443
444 return 0;
445}
446
447
448// write many bytes using the target monitor
449int WriteByteMultiple(tUartHandle serial_handle, UINT32 addr, UINT32 size, UINT8* pBuffer)
450{
451 UINT8 send, received;
452
453 // send the address command
454 send = ADDRESS;
455 UartWrite(serial_handle, &send, 1);
456
457 // transmit the address, big endian
458 send = (UINT8)((addr>>24) & 0xFF);
459 UartWrite(serial_handle, &send, 1);
460 send = (UINT8)((addr>>16) & 0xFF);
461 UartWrite(serial_handle, &send, 1);
462 send = (UINT8)((addr>>8) & 0xFF);
463 UartWrite(serial_handle, &send, 1);
464 send = (UINT8)(addr & 0xFF);
465 UartWrite(serial_handle, &send, 1);
466
467 UartRead(serial_handle, &received, 1); // response
468 if (received != ADDRESS)
469 {
470 printf("Protocol error!\n");
471 return 1;
472 }
473
474 while (size)
475 {
476 if (size >= 16)
477 { // we can use a "burst" command
478 send = BYTE_WRITE16;
479 UartWrite(serial_handle, &send, 1); // send the write command
480 UartWrite(serial_handle, pBuffer, 16); // transmit the data
481 UartRead(serial_handle, &received, 1); // response
482 if (received != BYTE_WRITE16)
483 {
484 printf("Protocol error!\n");
485 return 1;
486 }
487 pBuffer += 16;
488 size -= 16;
489 }
490 else
491 { // use single byte command
492 send = BYTE_WRITE;
493 UartWrite(serial_handle, &send, 1); // send the write command
494 UartWrite(serial_handle, pBuffer++, 1); // transmit the data
495 UartRead(serial_handle, &received, 1); // response
496 if (received != BYTE_WRITE)
497 {
498 printf("Protocol error!\n");
499 return 1;
500 }
501 size--;
502 }
503 }
504
505 return 0;
506}
507
508
509// write many bytes using the target monitor
510int FlashByteMultiple(tUartHandle serial_handle, UINT32 addr, UINT32 size, UINT8* pBuffer)
511{
512 UINT8 send, received;
513
514 // send the address command
515 send = ADDRESS;
516 UartWrite(serial_handle, &send, 1);
517
518 // transmit the address, big endian
519 send = (UINT8)((addr>>24) & 0xFF);
520 UartWrite(serial_handle, &send, 1);
521 send = (UINT8)((addr>>16) & 0xFF);
522 UartWrite(serial_handle, &send, 1);
523 send = (UINT8)((addr>>8) & 0xFF);
524 UartWrite(serial_handle, &send, 1);
525 send = (UINT8)(addr & 0xFF);
526 UartWrite(serial_handle, &send, 1);
527
528 UartRead(serial_handle, &received, 1); // response
529 if (received != ADDRESS)
530 {
531 printf("Protocol error!\n");
532 return 1;
533 }
534
535 while (size)
536 {
537 if (size >= 16)
538 { // we can use a "burst" command
539 send = BYTE_FLASH16;
540 UartWrite(serial_handle, &send, 1); // send the write command
541 UartWrite(serial_handle, pBuffer, 16); // transmit the data
542 UartRead(serial_handle, &received, 1); // response
543 if (received != BYTE_FLASH16)
544 {
545 printf("Protocol error!\n");
546 return 1;
547 }
548 pBuffer += 16;
549 size -= 16;
550 }
551 else
552 { // use single byte command
553 send = BYTE_FLASH;
554 UartWrite(serial_handle, &send, 1); // send the write command
555 UartWrite(serial_handle, pBuffer++, 1); // transmit the data
556 UartRead(serial_handle, &received, 1); // response
557 if (received != BYTE_FLASH)
558 {
559 printf("Protocol error!\n");
560 return 1;
561 }
562 size--;
563 }
564 }
565
566 return 0;
567}
568
569
570// read a 16bit halfword using the target monitor
571UINT16 ReadHalfword(tUartHandle serial_handle, UINT32 addr)
572{
573 UINT8 send;
574 UINT8 received;
575 UINT16 halfword;
576
577 // send the address command
578 send = ADDRESS;
579 UartWrite(serial_handle, &send, 1);
580
581 // transmit the address, big endian
582 send = (UINT8)((addr>>24) & 0xFF);
583 UartWrite(serial_handle, &send, 1);
584 send = (UINT8)((addr>>16) & 0xFF);
585 UartWrite(serial_handle, &send, 1);
586 send = (UINT8)((addr>>8) & 0xFF);
587 UartWrite(serial_handle, &send, 1);
588 send = (UINT8)(addr & 0xFF);
589 UartWrite(serial_handle, &send, 1);
590
591 UartRead(serial_handle, &received, 1); // response
592 if (received != ADDRESS)
593 {
594 printf("Protocol error!\n");
595 return 1;
596 }
597
598 // send the read command
599 send = HALFWORD_READ;
600 UartWrite(serial_handle, &send, 1);
601
602 UartRead(serial_handle, &received, 1); // response
603 halfword = received << 8; // highbyte
604 UartRead(serial_handle, &received, 1);
605 halfword |= received; // lowbyte
606
607 return halfword;
608}
609
610
611// write a 16bit halfword using the target monitor
612int WriteHalfword(tUartHandle serial_handle, UINT32 addr, UINT16 halfword)
613{
614 UINT8 send;
615 UINT8 received;
616
617 // send the address command
618 send = ADDRESS;
619 UartWrite(serial_handle, &send, 1);
620
621 // transmit the address, big endian
622 send = (UINT8)((addr>>24) & 0xFF);
623 UartWrite(serial_handle, &send, 1);
624 send = (UINT8)((addr>>16) & 0xFF);
625 UartWrite(serial_handle, &send, 1);
626 send = (UINT8)((addr>>8) & 0xFF);
627 UartWrite(serial_handle, &send, 1);
628 send = (UINT8)(addr & 0xFF);
629 UartWrite(serial_handle, &send, 1);
630
631 UartRead(serial_handle, &received, 1); // response
632 if (received != ADDRESS)
633 {
634 printf("Protocol error!\n");
635 return 1;
636 }
637
638 // send the write command
639 send = HALFWORD_WRITE;
640 UartWrite(serial_handle, &send, 1);
641
642 // transmit the data
643 send = halfword >> 8; // highbyte
644 UartWrite(serial_handle, &send, 1);
645 send = halfword & 0xFF; // lowbyte
646 UartWrite(serial_handle, &send, 1);
647
648 UartRead(serial_handle, &received, 1); // response
649
650 if (received != HALFWORD_WRITE)
651 {
652 printf("Protocol error!\n");
653 return 1;
654 }
655
656 return 0;
657}
658
659
660// change baudrate using target monitor
661int SetTargetBaudrate(tUartHandle serial_handle, long lClock, long lBaudrate)
662{
663 UINT8 send;
664 UINT8 received;
665 UINT8 brr;
666 long lBRR;
667
668 lBRR = lClock / lBaudrate;
669 lBRR = ((lBRR + 16) / 32) - 1; // with rounding
670 brr = (UINT8)lBRR;
671
672 // send the command
673 send = BAUDRATE;
674 UartWrite(serial_handle, &send, 1);
675 UartWrite(serial_handle, &brr, 1); // send the BRR value
676 UartRead(serial_handle, &received, 1); // response ack
677
678 if (received != BAUDRATE)
679 { // bad situation, now we're unclear about the baudrate of the target
680 printf("Protocol error!\n");
681 return 1;
682 }
683
684 SLEEP(100); // give it some time to settle
685
686 // change our baudrate, too
687 UartConfig(serial_handle, lBaudrate, eNOPARITY, eONESTOPBIT, 8);
688
689 return 0;
690}
691
692
693// call a subroutine using the target monitor
694int Execute(tUartHandle serial_handle, UINT32 addr, bool bReturns)
695{
696 UINT8 send;
697 UINT8 received;
698
699 // send the address command
700 send = ADDRESS;
701 UartWrite(serial_handle, &send, 1);
702
703 // transmit the address, big endian
704 send = (UINT8)((addr>>24) & 0xFF);
705 UartWrite(serial_handle, &send, 1);
706 send = (UINT8)((addr>>16) & 0xFF);
707 UartWrite(serial_handle, &send, 1);
708 send = (UINT8)((addr>>8) & 0xFF);
709 UartWrite(serial_handle, &send, 1);
710 send = (UINT8)(addr & 0xFF);
711 UartWrite(serial_handle, &send, 1);
712
713 UartRead(serial_handle, &received, 1); // response
714 if (received != ADDRESS)
715 {
716 printf("Protocol error!\n");
717 return 1;
718 }
719
720 // send the execute command
721 send = EXECUTE;
722 UartWrite(serial_handle, &send, 1);
723 if (bReturns)
724 { // we expect the call to return control to minimon
725 UartRead(serial_handle, &received, 1); // response
726
727 if (received != EXECUTE)
728 {
729 printf("Protocol error!\n");
730 return 1;
731 }
732 }
733
734 return 0;
735}
736
737
diff --git a/flash/uart_boot/client.h b/flash/uart_boot/client.h
deleted file mode 100644
index a5df8c35d6..0000000000
--- a/flash/uart_boot/client.h
+++ /dev/null
@@ -1,22 +0,0 @@
1#ifndef _CLIENT_H
2#define _CLIENT_H
3
4
5// setup function for monitor download
6int DownloadMonitor(tUartHandle serial_handle, bool bRecorder, char* szFilename);
7int DownloadArchosMonitor(tUartHandle serial_handle, char* szFilename);
8
9// target functions using the Monitor Protocol
10UINT8 ReadByte(tUartHandle serial_handle, UINT32 addr);
11int WriteByte(tUartHandle serial_handle, UINT32 addr, UINT8 byte);
12int ReadByteMultiple(tUartHandle serial_handle, UINT32 addr, UINT32 size, UINT8* pBuffer);
13int WriteByteMultiple(tUartHandle serial_handle, UINT32 addr, UINT32 size, UINT8* pBuffer);
14int FlashByteMultiple(tUartHandle serial_handle, UINT32 addr, UINT32 size, UINT8* pBuffer);
15UINT16 ReadHalfword(tUartHandle serial_handle, UINT32 addr);
16int WriteHalfword(tUartHandle serial_handle, UINT32 addr, UINT16 halfword);
17int SetTargetBaudrate(tUartHandle serial_handle, long lClock, long lBaudrate);
18int Execute(tUartHandle serial_handle, UINT32 addr, bool bReturns);
19
20
21#endif
22
diff --git a/flash/uart_boot/flash.c b/flash/uart_boot/flash.c
deleted file mode 100644
index 854de20454..0000000000
--- a/flash/uart_boot/flash.c
+++ /dev/null
@@ -1,78 +0,0 @@
1// flash.cpp : higher-level functions for flashing the chip
2//
3
4#include "scalar_types.h" // (U)INT8/16/32
5#include "Uart.h" // platform abstraction for UART
6#include "client.h" // client functions
7
8
9// read the manufacturer and device ID
10int ReadID(tUartHandle serial_handle, UINT32 base, UINT8* pManufacturerID, UINT8* pDeviceID)
11{
12 base &= 0xFFF80000; // round down to 512k align, to make shure
13
14 WriteByte(serial_handle, base + 0x5555, 0xAA); // enter command mode
15 WriteByte(serial_handle, base + 0x2AAA, 0x55);
16 WriteByte(serial_handle, base + 0x5555, 0x90); // ID command
17 SLEEP(20); // Atmel wants 20ms pause here
18
19 *pManufacturerID = ReadByte(serial_handle, base + 0);
20 *pDeviceID = ReadByte(serial_handle, base + 1);
21
22 WriteByte(serial_handle, base + 0, 0xF0); // reset flash (back to normal read mode)
23 SLEEP(20); // Atmel wants 20ms pause here
24
25 return 0;
26}
27
28
29// erase the sector which contains the given address
30int EraseSector(tUartHandle serial_handle, UINT32 address)
31{
32 UINT32 base = address & 0xFFF80000; // round down to 512k align
33
34 WriteByte(serial_handle, base + 0x5555, 0xAA); // enter command mode
35 WriteByte(serial_handle, base + 0x2AAA, 0x55);
36 WriteByte(serial_handle, base + 0x5555, 0x80); // eraze command
37 WriteByte(serial_handle, base + 0x5555, 0xAA); // enter command mode
38 WriteByte(serial_handle, base + 0x2AAA, 0x55);
39 WriteByte(serial_handle, address, 0x30); // eraze the sector
40 SLEEP(25); // sector eraze time: 25ms
41
42 return 0;
43}
44
45
46// erase the whole flash
47int EraseChip(tUartHandle serial_handle, UINT32 base)
48{
49 base &= 0xFFF80000; // round down to 512k align, to make shure
50
51 WriteByte(serial_handle, base + 0x5555, 0xAA); // enter command mode
52 WriteByte(serial_handle, base + 0x2AAA, 0x55);
53 WriteByte(serial_handle, base + 0x5555, 0x80); // eraze command
54 WriteByte(serial_handle, base + 0x5555, 0xAA); // enter command mode
55 WriteByte(serial_handle, base + 0x2AAA, 0x55);
56 WriteByte(serial_handle, base + 0x5555, 0x10); // chip eraze command
57 SLEEP(100); // chip eraze time: 100ms
58
59 return 0;
60}
61
62
63// program a bunch of bytes "by hand"
64int ProgramBytes(tUartHandle serial_handle, UINT32 address, UINT8* pData, UINT32 size)
65{
66 UINT32 base = address & 0xFFF80000; // round down to 512k align
67
68 while (size--)
69 {
70 WriteByte(serial_handle, base + 0x5555, 0xAA); // enter command mode
71 WriteByte(serial_handle, base + 0x2AAA, 0x55);
72 WriteByte(serial_handle, base + 0x5555, 0xA0); // byte program command
73 WriteByte(serial_handle, address++, *pData++);
74 // UART protocol is slow enough such that I don't have to wait 20us here
75 }
76 return 0;
77}
78
diff --git a/flash/uart_boot/flash.h b/flash/uart_boot/flash.h
deleted file mode 100644
index 9c69ad46a5..0000000000
--- a/flash/uart_boot/flash.h
+++ /dev/null
@@ -1,10 +0,0 @@
1#ifndef _FLASH_H
2#define _FLASH_H
3
4int ReadID(tUartHandle serial_handle, UINT32 base, UINT8* pManufacturerID, UINT8* pDeviceID);
5int EraseSector(tUartHandle serial_handle, UINT32 address);
6int EraseChip(tUartHandle serial_handle, UINT32 base);
7int ProgramBytes(tUartHandle serial_handle, UINT32 address, UINT8* pData, UINT32 size);
8
9#endif
10
diff --git a/flash/uart_boot/minimon.h b/flash/uart_boot/minimon.h
deleted file mode 100644
index 69a03b1f4d..0000000000
--- a/flash/uart_boot/minimon.h
+++ /dev/null
@@ -1,24 +0,0 @@
1#ifndef _MINIMON_H
2#define _MINIMON_H
3
4
5// Commands
6// all multibyte values (address, halfwords) are passed as big endian
7// (most significant of the bytes first)
8
9// set the address (all read/write commands will auto-increment it)
10#define BAUDRATE 0x00 // followed by BRR value; response: command byte
11#define ADDRESS 0x01 // followed by 4 bytes address; response: command byte
12#define BYTE_READ 0x02 // response: 1 byte content
13#define BYTE_WRITE 0x03 // followed by 1 byte content; response: command byte
14#define BYTE_READ16 0x04 // response: 16 bytes content
15#define BYTE_WRITE16 0x05 // followed by 16 bytes; response: command byte
16#define BYTE_FLASH 0x06 // followed by 1 byte content; response: command byte
17#define BYTE_FLASH16 0x07 // followed by 16 bytes; response: command byte
18#define HALFWORD_READ 0x08 // response: 2 byte content
19#define HALFWORD_WRITE 0x09 // followed by 2 byte content; response: command byte
20#define EXECUTE 0x0A // response: command byte if call returns
21
22
23#endif // _MINIMON_H
24
diff --git a/flash/uart_boot/scalar_types.h b/flash/uart_boot/scalar_types.h
deleted file mode 100644
index f3ac1d86eb..0000000000
--- a/flash/uart_boot/scalar_types.h
+++ /dev/null
@@ -1,45 +0,0 @@
1// this is meant to resolve platform dependency
2
3#ifndef _SCALAR_TYPES_H
4#define _SCALAR_TYPES_H
5
6
7#ifdef WIN32
8#include <windows.h>
9#define SLEEP Sleep
10#define GET_LAST_ERR GetLastError
11#endif
12// ToDo: add stuff for Linux
13
14
15
16#ifndef UINT8
17#define UINT8 unsigned char
18#endif
19
20#ifndef UINT16
21#define UINT16 unsigned short
22#endif
23
24#ifndef UINT32
25#define UINT32 unsigned long
26#endif
27
28#ifndef bool
29#define bool int
30#endif
31
32#ifndef true
33#define true 1
34#endif
35
36#ifndef false
37#define false 0
38#endif
39
40
41
42
43
44#endif
45
diff --git a/flash/uart_boot/uart.h b/flash/uart_boot/uart.h
deleted file mode 100644
index a0c10d1a0f..0000000000
--- a/flash/uart_boot/uart.h
+++ /dev/null
@@ -1,57 +0,0 @@
1// A general definition for the required UART functionality.
2// This will be used to gain platform abstraction.
3
4#ifndef _UART_H
5#define _UART_H
6
7// data types
8
9typedef void* tUartHandle;
10#define INVALID_UART_HANDLE (tUartHandle)-1
11
12typedef enum
13{
14 eNOPARITY,
15 eODDPARITY,
16 eEVENPARITY,
17 eMARKPARITY,
18 eSPACEPARITY,
19} tParity;
20
21typedef enum
22{
23 eONESTOPBIT,
24 eONE5STOPBITS,
25 eTWOSTOPBITS,
26} tStopBits;
27
28
29// prototypes
30
31tUartHandle UartOpen( // returns NULL on error
32 char* szPortName); // COMx for windows
33
34bool UartConfig( // returns true on success, false on error
35 tUartHandle handle, // the handle returned from UartOpen()
36 long lBaudRate, // must be one of the "standard" baudrates
37 tParity nParity, // what kind of parity
38 tStopBits nStopBits, // how many stop bits
39 int nByteSize); // size of the "payload", can be 5 to 8
40
41long UartWrite( // returns how much data was actually transmitted
42 tUartHandle handle, // the handle returned from UartOpen()
43 unsigned char* pData, // pointer to the data to be transmitted
44 long lSize); // how many bytes
45
46long UartRead( // returns how much data was actually received
47 tUartHandle handle, // the handle returned from UartOpen()
48 unsigned char* pBuffer, // pointer to the destination
49 long lSize); // how many bytes to read (pBuffer must have enough room)
50
51
52void UartClose(tUartHandle handle);
53
54
55
56#endif // _UART_H
57
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?
13static 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
31int 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
150int 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
diff --git a/flash/uart_boot/uart_boot.dsp b/flash/uart_boot/uart_boot.dsp
deleted file mode 100644
index 4d94c72530..0000000000
--- a/flash/uart_boot/uart_boot.dsp
+++ /dev/null
@@ -1,130 +0,0 @@
1# Microsoft Developer Studio Project File - Name="uart_boot" - Package Owner=<4>
2# Microsoft Developer Studio Generated Build File, Format Version 6.00
3# ** DO NOT EDIT **
4
5# TARGTYPE "Win32 (x86) Console Application" 0x0103
6
7CFG=uart_boot - Win32 Debug
8!MESSAGE This is not a valid makefile. To build this project using NMAKE,
9!MESSAGE use the Export Makefile command and run
10!MESSAGE
11!MESSAGE NMAKE /f "uart_boot.mak".
12!MESSAGE
13!MESSAGE You can specify a configuration when running NMAKE
14!MESSAGE by defining the macro CFG on the command line. For example:
15!MESSAGE
16!MESSAGE NMAKE /f "uart_boot.mak" CFG="uart_boot - Win32 Debug"
17!MESSAGE
18!MESSAGE Possible choices for configuration are:
19!MESSAGE
20!MESSAGE "uart_boot - Win32 Release" (based on "Win32 (x86) Console Application")
21!MESSAGE "uart_boot - Win32 Debug" (based on "Win32 (x86) Console Application")
22!MESSAGE
23
24# Begin Project
25# PROP AllowPerConfigDependencies 0
26# PROP Scc_ProjName ""
27# PROP Scc_LocalPath ""
28CPP=cl.exe
29RSC=rc.exe
30
31!IF "$(CFG)" == "uart_boot - Win32 Release"
32
33# PROP BASE Use_MFC 0
34# PROP BASE Use_Debug_Libraries 0
35# PROP BASE Output_Dir "Release"
36# PROP BASE Intermediate_Dir "Release"
37# PROP BASE Target_Dir ""
38# PROP Use_MFC 0
39# PROP Use_Debug_Libraries 0
40# PROP Output_Dir "Release"
41# PROP Intermediate_Dir "Release"
42# PROP Target_Dir ""
43# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /c
44# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FR /FD /c
45# SUBTRACT CPP /YX /Yc /Yu
46# ADD BASE RSC /l 0x407 /d "NDEBUG"
47# ADD RSC /l 0x407 /d "NDEBUG"
48BSC32=bscmake.exe
49# ADD BASE BSC32 /nologo
50# ADD BSC32 /nologo
51LINK32=link.exe
52# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
53# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
54
55!ELSEIF "$(CFG)" == "uart_boot - Win32 Debug"
56
57# PROP BASE Use_MFC 0
58# PROP BASE Use_Debug_Libraries 1
59# PROP BASE Output_Dir "Debug"
60# PROP BASE Intermediate_Dir "Debug"
61# PROP BASE Target_Dir ""
62# PROP Use_MFC 0
63# PROP Use_Debug_Libraries 1
64# PROP Output_Dir "Debug"
65# PROP Intermediate_Dir "Debug"
66# PROP Target_Dir ""
67# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /GZ /c
68# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /FD /GZ /c
69# SUBTRACT CPP /YX /Yc /Yu
70# ADD BASE RSC /l 0x407 /d "_DEBUG"
71# ADD RSC /l 0x407 /d "_DEBUG"
72BSC32=bscmake.exe
73# ADD BASE BSC32 /nologo
74# ADD BSC32 /nologo
75LINK32=link.exe
76# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
77# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
78
79!ENDIF
80
81# Begin Target
82
83# Name "uart_boot - Win32 Release"
84# Name "uart_boot - Win32 Debug"
85# Begin Group "Source Files"
86
87# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
88# Begin Source File
89
90SOURCE=.\client.c
91# End Source File
92# Begin Source File
93
94SOURCE=.\flash.c
95# End Source File
96# Begin Source File
97
98SOURCE=.\uart_boot.c
99# End Source File
100# Begin Source File
101
102SOURCE=.\uart_win.c
103# End Source File
104# End Group
105# Begin Group "Header Files"
106
107# PROP Default_Filter "h;hpp;hxx;hm;inl"
108# Begin Source File
109
110SOURCE=.\client.h
111# End Source File
112# Begin Source File
113
114SOURCE=.\flash.h
115# End Source File
116# Begin Source File
117
118SOURCE=.\minimon.h
119# End Source File
120# Begin Source File
121
122SOURCE=.\scalar_types.h
123# End Source File
124# Begin Source File
125
126SOURCE=.\uart.h
127# End Source File
128# End Group
129# End Target
130# End Project
diff --git a/flash/uart_boot/uart_win.c b/flash/uart_boot/uart_win.c
deleted file mode 100644
index 6e82e9580c..0000000000
--- a/flash/uart_boot/uart_win.c
+++ /dev/null
@@ -1,139 +0,0 @@
1// UART wrapper implementation for the Win32 platform
2// make a new version of this file for different systems, e.g. Linux
3
4#include <windows.h>
5#include "scalar_types.h" // (U)INT8/16/32
6#include "Uart.h"
7
8// COMx for windows, returns NULL on error
9tUartHandle UartOpen(char* szPortName)
10{
11 HANDLE serial_handle;
12 DCB dcb;
13 COMMTIMEOUTS cto = { 0, 0, 0, 0, 0 };
14
15 memset(&dcb,0,sizeof(dcb));
16
17 /* -------------------------------------------------------------------- */
18 // set DCB to configure the serial port
19 dcb.DCBlength = sizeof(dcb);
20
21 dcb.fOutxCtsFlow = 0;
22 dcb.fOutxDsrFlow = 0;
23 dcb.fDtrControl = DTR_CONTROL_ENABLE; // enable for power
24 dcb.fDsrSensitivity = 0;
25 dcb.fRtsControl = RTS_CONTROL_ENABLE; // enable for power
26 dcb.fOutX = 0;
27 dcb.fInX = 0;
28
29 /* ----------------- misc parameters ----- */
30 dcb.fErrorChar = 0;
31 dcb.fBinary = 1;
32 dcb.fNull = 0;
33 dcb.fAbortOnError = 0;
34 dcb.wReserved = 0;
35 dcb.XonLim = 2;
36 dcb.XoffLim = 4;
37 dcb.XonChar = 0x13;
38 dcb.XoffChar = 0x19;
39 dcb.EvtChar = 0;
40
41 /* ----------------- defaults ----- */
42 dcb.BaudRate = 4800;
43 dcb.Parity = NOPARITY;
44 dcb.fParity = 0;
45 dcb.StopBits = ONESTOPBIT;
46 dcb.ByteSize = 8;
47
48
49 /* -------------------------------------------------------------------- */
50 // opening serial port
51 serial_handle = CreateFile(szPortName, GENERIC_READ | GENERIC_WRITE,
52 0, NULL, OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH, NULL);
53
54 if (serial_handle == INVALID_HANDLE_VALUE)
55 {
56 //printf("Cannot open port \n");
57 return NULL;
58 }
59
60 SetCommMask(serial_handle, 0);
61 SetCommTimeouts(serial_handle, &cto);
62
63 if(!SetCommState(serial_handle, &dcb))
64 {
65 //printf("Error setting up COM params\n");
66 CloseHandle(serial_handle);
67 return NULL;
68 }
69
70 return serial_handle;
71}
72
73// returns true on success, false on error
74bool UartConfig(tUartHandle handle, long lBaudRate, tParity nParity, tStopBits nStopBits, int nByteSize)
75{
76 DCB dcb;
77
78 if (!GetCommState (handle, &dcb))
79 {
80 return false;
81 }
82
83 dcb.BaudRate = lBaudRate;
84 dcb.Parity = nParity;
85 dcb.StopBits = nStopBits;
86 dcb.ByteSize = nByteSize;
87
88 if(!SetCommState(handle, &dcb))
89 {
90 //DWORD dwErr = GetLastError();
91 //printf("Error %d setting up COM params for baudrate byte\n", dwErr);
92 return false;
93 }
94
95 return true;
96}
97
98// returns how much data was actually transmitted
99long UartWrite(tUartHandle handle, unsigned char* pData, long lSize)
100{
101 BOOL success;
102 DWORD result_nbr;
103
104 success = WriteFile(handle, pData, lSize, &result_nbr, NULL);
105
106 if(!success)
107 {
108 return 0;
109 }
110
111 return result_nbr;
112}
113
114// returns how much data was actually received
115long UartRead(tUartHandle handle, unsigned char* pBuffer, long lSize)
116{
117 BOOL success;
118 DWORD read_nbr;
119
120 success = ReadFile(handle, pBuffer, lSize, &read_nbr, NULL);
121 if(!success)
122 {
123 return 0;
124 }
125
126 return read_nbr;
127}
128
129
130void UartClose(tUartHandle handle)
131{
132 if (handle != NULL)
133 {
134 CloseHandle(handle);
135 }
136
137 return;
138}
139