summaryrefslogtreecommitdiff
path: root/target/device/Atmel/arch-arm/u-boot/2009.01/u-boot-2009.01-007-tools.patch
blob: 8f71ee043ffd91ed894477d5bfc53fb0dbb1d22f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
diff -urN u-boot-2008.10-0rig//tools/Makefile u-boot-2008.10/tools/Makefile
--- u-boot-2008.10-0rig//tools/Makefile	2008-12-31 17:51:29.000000000 +0100
+++ u-boot-2008.10/tools/Makefile	2008-12-31 19:38:15.000000000 +0100
@@ -37,6 +37,11 @@
 #OBJ_FILES	+= mpc86x_clk.o
 #endif
 
+ifeq ($(VENDOR),atmel)
+BINS+= raw-at91$(SFX) sx-at91$(SFX)
+OBJS+= raw-at91.o sx-at91.o
+endif
+
 LIBFDT_OBJ_FILES	= $(obj)fdt.o $(obj)fdt_ro.o $(obj)fdt_rw.o $(obj)fdt_strerror.o $(obj)fdt_wip.o
 
 LOGO_H	= $(OBJTREE)/include/bmp_logo.h
@@ -175,6 +180,14 @@
 		$(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
 		$(STRIP) $@
 
+$(obj)raw-at91$(SFX):	$(obj)raw-at91.o
+		$(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
+		$(STRIP) $@
+
+$(obj)sx-at91$(SFX):	$(obj)sx-at91.o
+		$(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
+		$(STRIP) $@
+
 $(obj)envcrc.o:	$(src)envcrc.c
 		$(CC) -g $(CFLAGS) -c -o $@ $<
 
@@ -223,6 +236,12 @@
 $(obj)fdt_wip.o:	$(obj)fdt_wip.c
 		$(CC) -g $(FIT_CFLAGS) -c -o $@ $<
 
+$(obj)sx-at91.o:		$(src)sx-at91.c
+		$(CC) -g $(CFLAGS) -c -o $@ $<
+
+$(obj)raw-at91.o:	$(src)raw-at91.c
+		$(CC) -g $(CFLAGS) -c -o $@ $<
+
 subdirs:
 ifeq ($(TOOLSUBDIRS),)
 		@:
diff -urN u-boot-2008.10-0rig//tools/raw-at91.c u-boot-2008.10/tools/raw-at91.c
--- u-boot-2008.10-0rig//tools/raw-at91.c	1970-01-01 01:00:00.000000000 +0100
+++ u-boot-2008.10/tools/raw-at91.c	2008-12-31 19:26:23.000000000 +0100
@@ -0,0 +1,225 @@
+/*
+ * xmodem-at91.c
+ *
+ * A simple program using xmodem/1kxmode upload file to at91rm9200 based board.
+ * Created by (C) Copyright 2004
+ * Linhang.Zhang, Jilin University of PR.China, linxing@jlu.edu.cn.
+ *
+ *************************************************************************************
+ *
+ * Modified 01-Feb-2005 (C)Copyright 2005
+ * Marco Cavallini, www.KoanSoftware.com - ITALY, m.cavallini@koansoftware.com
+ * - edited indentations and changed break usage in switch statement.
+ * - added "\r" to printf
+ *
+ * - build with 
+ *   gcc sx-at91.c -o sx-at91
+ *
+ * - Howto use this program with minicom/xminicom and AT91 
+ *   start minicom or xminicom
+ *   edit Options / File transfer protocol, 
+ *   add a name (for example J) like the following example
+ *
+ *   |     Name             Program                 Name U/D FullScr IO-Red. Multi  |
+ *   | A  zmodem     /usr/bin/sz -vv -b              Y    U    N       Y       Y    |
+ *   | B  ymodem     /usr/bin/sb -vv                 Y    U    N       Y       Y    |
+ *   | C  xmodem     /usr/bin/sx -vv                 Y    U    N       Y       N    |
+ *   | D  zmodem     /usr/bin/rz -vv -b -E           N    D    N       Y       Y    |
+ *   | E  ymodem     /usr/bin/rb -vv                 N    D    N       Y       Y    |
+ *   | F  xmodem     /usr/bin/rx -vv                 Y    D    N       Y       N    |
+ *   | G  kermit     /usr/bin/kermit -i -l %l -s     Y    U    Y       N       N    |
+ *   | H  kermit     /usr/bin/kermit -i -l %l -r     N    D    Y       N       N    |
+ *   | I  ascii      /usr/bin/ascii-xfr -dsv         Y    U    N       Y       N    |
+ *   | J  at91       /home/koan/xmodem/xs-at91       Y    U    Y       N       N    |
+ *   | K    -                                                                       |
+ *   | L    -                                                                       |
+ *
+ *   save and use it selecting at91 protocol when you start an Xmodem upload to AT91
+ *
+ *************************************************************************************
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include     <stdio.h>
+#include     <stdlib.h>
+#include     <string.h>
+#include     <unistd.h>
+#include     <sys/types.h>
+#include     <sys/stat.h>
+#include     <fcntl.h>
+#include     <termios.h>
+#include     <errno.h>
+#include     <time.h>
+
+#define	TRUE		1
+#define	FALSE		0
+#define LINESIZE	1024
+
+/*********/
+
+#define SERIAL_DEVICE "/dev/ttyS0"
+#define MYBAUDRATE B115200
+
+/***************SUB PROGRAM*******/
+
+int Initial_SerialPort(void)
+{
+	int fd;
+	struct termios options;
+
+	fd = open( SERIAL_DEVICE , O_RDWR | O_NOCTTY | O_NDELAY );
+	if ( fd == -1 )
+	{ 
+		/*open error!*/
+		perror("Can't open serial port!");
+		return -1;
+	}
+
+	/*Get the current options for the port...*/
+	tcgetattr(fd, &options);
+
+	/*Set the baud rates to BAUDRATE...*/
+	cfsetispeed(&options,MYBAUDRATE);
+	cfsetospeed(&options,MYBAUDRATE);
+	tcsetattr(fd, TCSANOW, &options);
+	if (0 != tcgetattr(fd, &options)) 
+	{
+		perror("SetupSerial 1");
+		return -1;
+	} 
+	
+	/*
+	 * 8bit Data,no partity,1 stop bit...
+	 */
+	options.c_cflag &= ~PARENB;
+	options.c_cflag &= ~CSTOPB;
+	options.c_cflag &= ~CSIZE;
+	options.c_cflag |= CS8;
+	tcflush(fd,TCIFLUSH);
+
+	/***Choosing Raw Input*/
+	options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
+	options.c_oflag &= ~OPOST; 
+
+	/*
+	 * Set the new options for the port...
+	 */
+	if (0 != tcsetattr(fd, TCSANOW, &options))
+	{
+ 		perror("SetupSerial error");
+ 		return -1 ;
+	}
+
+	return fd ;
+}
+
+/******************************/
+void ClearReceiveBuffer(int fd)
+{
+	unsigned char tmp;
+	while ((read(fd,&tmp,1))>0);
+	
+	return;
+}
+unsigned char filebuf[ LINESIZE+2 ];
+unsigned char outbuf[ LINESIZE+2 ];
+FILE *datafile;
+int fd;
+
+static	unsigned int	ChCnt=0;
+static	unsigned int	ChIx;
+unsigned char	GetChar(unsigned char *ch)
+/* 
+ * SUCCESS:	Return TRUE
+ * FAILURE:	Return FALSE
+ */
+{
+  
+  if(ChCnt == 0) {
+    ChCnt = fread( filebuf, sizeof(char), LINESIZE, datafile);
+    ChIx = 0;
+  }
+  if(ChCnt > 0) {
+    *ch = filebuf[ChIx++];
+    ChCnt--;
+    return TRUE;
+  } else {
+    return FALSE;	/* Reached End of File */
+  }
+}
+
+/********************************/
+void	delay()
+{
+}
+
+int main(int argc,char *argv[])
+{
+	char *data_file_name;
+	int	len;
+	unsigned char c;
+	int complete,i,sts;
+
+	printf("raw-at91 started...\r\n");
+	
+	/* open serial port1 */
+	if ( (fd = Initial_SerialPort()) == -1)  
+		return -1 ;
+
+	data_file_name = argv[1];
+
+	if((datafile=fopen(data_file_name,"rb"))==NULL)
+	{
+		perror ("Can't open file!");
+		return -1 ;
+	}
+
+	/*******************************/
+	
+	complete = 0;
+	/*	ClearReceiveBuffer(fd); */
+
+	/* while((read(fd,&ack_id,1))<=0);*/
+	
+	/* printf("%c\r\n",ack_id); */
+	while(!complete)
+	{
+	  for(i=0;i < LINESIZE; i++) {		/* A line more than 1024 characters will have problems...*/
+	    if((sts = GetChar(&outbuf[i]))) {
+	      /* Sts = Success */
+	      if((c = outbuf[i]) == '\n') {	/* Found end of Line - Start Processing*/
+		outbuf[i+1] = '\0';		/* Terminate String*/
+		break;
+	      }
+	    } else {
+	      /* Sts = Failure - End of File */
+	      outbuf[i] = '\n';
+	      outbuf[i+1] = '\0';
+	      complete = 1;
+	    }
+	  }
+	  printf("%s",outbuf);		/* Inform user */
+	  len = strlen((char *)outbuf);
+	  write(fd,outbuf,strlen((char *)outbuf));
+	  for(i = 0; i < 500000000; i++ ) delay();
+	  while((read(fd,&c,1))<=0) putchar(c);
+	  printf("  ");
+	}
+	fclose(datafile);
+	close(fd);
+	return 0;
+}
diff -urN u-boot-2008.10-0rig//tools/sx-at91.c u-boot-2008.10/tools/sx-at91.c
--- u-boot-2008.10-0rig//tools/sx-at91.c	1970-01-01 01:00:00.000000000 +0100
+++ u-boot-2008.10/tools/sx-at91.c	2008-12-31 19:26:23.000000000 +0100
@@ -0,0 +1,300 @@
+/*
+ * xmodem-at91.c
+ *
+ * A simple program using xmodem/1kxmode upload file to at91rm9200 based board.
+ * Created by (C) Copyright 2004
+ * Linhang.Zhang, Jilin University of PR.China, linxing@jlu.edu.cn.
+ *
+ *************************************************************************************
+ *
+ * Modified 01-Feb-2005 (C)Copyright 2005
+ * Marco Cavallini, www.KoanSoftware.com - ITALY, m.cavallini@koansoftware.com
+ * - edited indentations and changed break usage in switch statement.
+ * - added "\r" to printf
+ *
+ * - build with 
+ *   gcc sx-at91.c -o sx-at91
+ *
+ * - Howto use this program with minicom/xminicom and AT91 
+ *   start minicom or xminicom
+ *   edit Options / File transfer protocol, 
+ *   add a name (for example J) like the following example
+ *
+ *   |     Name             Program                 Name U/D FullScr IO-Red. Multi  |
+ *   | A  zmodem     /usr/bin/sz -vv -b              Y    U    N       Y       Y    |
+ *   | B  ymodem     /usr/bin/sb -vv                 Y    U    N       Y       Y    |
+ *   | C  xmodem     /usr/bin/sx -vv                 Y    U    N       Y       N    |
+ *   | D  zmodem     /usr/bin/rz -vv -b -E           N    D    N       Y       Y    |
+ *   | E  ymodem     /usr/bin/rb -vv                 N    D    N       Y       Y    |
+ *   | F  xmodem     /usr/bin/rx -vv                 Y    D    N       Y       N    |
+ *   | G  kermit     /usr/bin/kermit -i -l %l -s     Y    U    Y       N       N    |
+ *   | H  kermit     /usr/bin/kermit -i -l %l -r     N    D    Y       N       N    |
+ *   | I  ascii      /usr/bin/ascii-xfr -dsv         Y    U    N       Y       N    |
+ *   | J  at91       /home/koan/xmodem/xs-at91       Y    U    Y       N       N    |
+ *   | K    -                                                                       |
+ *   | L    -                                                                       |
+ *
+ *   save and use it selecting at91 protocol when you start an Xmodem upload to AT91
+ *
+ *************************************************************************************
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include     <stdio.h>
+#include     <stdlib.h>
+#include     <unistd.h>
+#include     <sys/types.h>
+#include     <sys/stat.h>
+#include     <fcntl.h>
+#include     <termios.h>
+#include     <errno.h>
+#include     <time.h>
+
+/*
+Xmodem Frame form: <SOH><blk #><255-blk #><--128 data bytes--><CRC hi><CRC lo>
+*/
+
+#define XMODEM_SOH 0x01
+#define XMODEM_STX 0x02
+#define XMODEM_EOT 0x04
+#define XMODEM_ACK 0x06
+#define XMODEM_NAK 0x15
+#define XMODEM_CRC_CHR	'C'
+#define XMODEM_CRC_SIZE 2			/* Crc_High Byte + Crc_Low Byte */
+#define XMODEM_FRAME_ID_SIZE 2 /* Frame_Id + 255-Frame_Id */
+#define XMODEM_DATA_SIZE_SOH 128  /* for Xmodem protocol */
+#define XMODEM_DATA_SIZE_STX 1024 /* for 1K xmodem protocol */
+#define USE_1K_XMODEM 0  /* 1 for use 1k_xmodem 0 for xmodem */
+
+#if (USE_1K_XMODEM)
+	#define XMODEM_DATA_SIZE 	XMODEM_DATA_SIZE_STX
+	#define XMODEM_HEAD		XMODEM_STX
+#else
+	#define XMODEM_DATA_SIZE 	XMODEM_DATA_SIZE_SOH
+	#define XMODEM_HEAD 		XMODEM_SOH
+#endif
+/*********/
+
+#define SERIAL_DEVICE "/dev/ttyS0"
+#define MYBAUDRATE B115200
+
+/***************SUB PROGRAM*******/
+unsigned short GetCrc16 ( char *ptr, unsigned short count )
+{
+	unsigned short crc, i;
+
+	crc = 0;
+	while(count--)
+	{
+		crc = crc ^ (int) *ptr++ << 8;
+	
+		for(i = 0; i < 8; i++)
+		{
+			if(crc & 0x8000)
+				crc = crc << 1 ^ 0x1021;
+			else			
+				crc = crc << 1;
+		}
+	}
+
+	return (crc & 0xFFFF);
+}
+
+/*******************************/
+int Initial_SerialPort(void)
+{
+	int fd;
+	struct termios options;
+
+	fd = open( SERIAL_DEVICE , O_RDWR | O_NOCTTY | O_NDELAY );
+	if ( fd == -1 )
+	{ 
+		/*open error!*/
+		perror("Can't open serial port!");
+		return -1;
+	}
+
+	/*Get the current options for the port...*/
+	tcgetattr(fd, &options);
+
+	/*Set the baud rates to BAUDRATE...*/
+	cfsetispeed(&options,MYBAUDRATE);
+	cfsetospeed(&options,MYBAUDRATE);
+	tcsetattr(fd, TCSANOW, &options);
+	if (0 != tcgetattr(fd, &options)) 
+	{
+		perror("SetupSerial 1");
+		return -1;
+	} 
+	
+	/*
+	 * 8bit Data,no partity,1 stop bit...
+	 */
+	options.c_cflag &= ~PARENB;
+	options.c_cflag &= ~CSTOPB;
+	options.c_cflag &= ~CSIZE;
+	options.c_cflag |= CS8;
+	tcflush(fd,TCIFLUSH);
+
+	/***Choosing Raw Input*/
+	options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
+	options.c_oflag &= ~OPOST; 
+
+	/*
+	 * Set the new options for the port...
+	 */
+	if (0 != tcsetattr(fd, TCSANOW, &options))
+	{
+ 		perror("SetupSerial error");
+ 		return -1 ;
+	}
+
+	return fd ;
+}
+
+/******************************/
+void ClearReceiveBuffer(int fd)
+{
+	unsigned char tmp;
+	while ((read(fd,&tmp,1))>0);
+	
+	return;
+}
+
+/********************************/
+int main(int argc,char *argv[])
+{
+	int fd;
+	char *data_file_name;
+	char packet_data[ XMODEM_DATA_SIZE ];
+	char frame_data[ XMODEM_DATA_SIZE + XMODEM_CRC_SIZE + XMODEM_FRAME_ID_SIZE + 1 ];
+	FILE *datafile;
+	int complete,retry_num,pack_counter,read_number,write_number,i;
+	unsigned short crc_value;
+	unsigned char ack_id;
+
+	printf("sx-at91 started...\r\n");
+	
+	/* open serial port1 */
+	if ( (fd = Initial_SerialPort()) == -1)  
+		return -1 ;
+
+	data_file_name = argv[1];
+
+	if((datafile=fopen(data_file_name,"rb"))==NULL)
+	{
+		perror ("Can't open file!");
+		return -1 ;
+	}
+
+	/*******************************/
+	
+	pack_counter = 0;
+	complete = 0;
+	retry_num = 0;
+	ClearReceiveBuffer(fd);
+
+	while((read(fd,&ack_id,1))<=0);
+	
+	printf("%c\r\n",ack_id);
+	ack_id=XMODEM_ACK;
+	while(!complete)
+	{
+		switch(ack_id)
+		{
+		case XMODEM_ACK:
+			retry_num = 0;
+			pack_counter++;
+			read_number = fread( packet_data, sizeof(char), XMODEM_DATA_SIZE, datafile);
+			if(read_number>0)
+			{
+				if(read_number<XMODEM_DATA_SIZE_SOH)
+				{
+			
+					printf("Start filling the last frame!\r\n");
+					for(;read_number<XMODEM_DATA_SIZE;read_number++)
+						packet_data[read_number] = 0x00;
+				}
+				frame_data[0] = XMODEM_HEAD;
+				frame_data[1] = (char)pack_counter;
+				frame_data[2] = (char)(255-frame_data[1]);
+	
+				for(i=0;i<XMODEM_DATA_SIZE;i++)
+					frame_data[i+3]=packet_data[i];
+	
+				crc_value = GetCrc16(packet_data,XMODEM_DATA_SIZE);
+				frame_data[XMODEM_DATA_SIZE_SOH+3]=(unsigned char)(crc_value >> 8);
+				frame_data[XMODEM_DATA_SIZE_SOH+4]=(unsigned char)(crc_value);
+				write_number = write( fd, frame_data, XMODEM_DATA_SIZE_SOH + 5);
+				printf("waiting for ACK,%d,%d,...",pack_counter,write_number);
+				while((read(fd,&ack_id,1))<=0);
+			
+				if(ack_id == XMODEM_ACK)
+					printf("Ok!\r\n");
+				else
+					printf("Error!\r\n");
+			}
+			else
+			{
+				ack_id = XMODEM_EOT;
+				complete = 1;
+				printf("Waiting for complete ACK ...");
+			
+				while(ack_id != XMODEM_ACK)
+				{
+					ack_id = XMODEM_EOT;	
+					write_number=write(fd,&ack_id,1);
+					while((read(fd,&ack_id,1))<=0);
+				}
+				printf("OK\r\n");
+		
+				printf("Sending file complete\r\n");
+			}
+		break;
+
+		case XMODEM_NAK:
+			if( retry_num++ > 10) 
+			{
+				printf("Retry too many times,Quit!\r\n");
+				complete = 1;
+			}
+			else
+			{
+				write_number = write(fd,frame_data,XMODEM_DATA_SIZE + 5);
+				printf("Retry for ACK,%d,%d...",pack_counter,write_number);
+				while((read(fd,&ack_id,1))<=0);
+				
+				if( ack_id == XMODEM_ACK )
+					printf("OK\r\n");
+				else
+					printf("Error!\r\n");
+			}
+		break;
+
+		default:
+			printf("Fatal Error!\r\n");
+			complete = 1;
+		break;
+		}
+
+	}
+
+	fclose(datafile);
+	close(fd);
+
+	return 0;
+}