1a0f9c559fd1f6152ba4d42a124d8f10942aad30
[openwrt/svn-archive/archive.git] / target / linux / at91-2.6 / image / romboot / patches / 004-code-cleanup.patch
1 diff -urN romboot.old/com.cpp romboot/com.cpp
2 --- romboot.old/com.cpp 2004-07-04 21:37:05.000000000 +0200
3 +++ romboot/com.cpp 2007-04-04 04:30:12.000000000 +0200
4 @@ -27,7 +27,7 @@
5 //*-----------------------------------------------------------------------------
6 void AT91F_ClrScr(void)
7 {
8 - puts(CLRSCREEN);
9 + putstr(CLRSCREEN);
10 }
11
12
13 @@ -47,12 +47,12 @@
14
15 if (*(--p) == '\t') { /* will retype the whole line */
16 while (*colp > plen) {
17 - puts(erase_seq);
18 + putstr(erase_seq);
19 (*colp)--;
20 }
21 for (s=buffer; s<p; ++s) {
22 if (*s == '\t') {
23 - puts(tab_seq+((*colp) & 07));
24 + putstr(tab_seq+((*colp) & 07));
25 *colp += 8 - ((*colp) & 07);
26 } else {
27 ++(*colp);
28 @@ -60,7 +60,7 @@
29 }
30 }
31 } else {
32 - puts(erase_seq);
33 + putstr(erase_seq);
34 (*colp)--;
35 }
36 (*np)--;
37 @@ -85,7 +85,7 @@
38
39 /* print prompt */
40 if(prompt)
41 - puts(prompt);
42 + putstr(prompt);
43 col = plen;
44
45 for (;;)
46 @@ -97,7 +97,7 @@
47 case '\r': /* Enter */
48 case '\n':
49 *p = '\0';
50 - puts ("\r\n");
51 + putstr ("\r\n");
52 return (p - console_buffer);
53
54 case 0x03: /* ^C - break */
55 @@ -107,7 +107,7 @@
56 case 0x15: /* ^U - erase line */
57 while (col > plen)
58 {
59 - puts(erase_seq);
60 + putstr(erase_seq);
61 --col;
62 }
63 p = console_buffer;
64 @@ -152,7 +152,7 @@
65 void AT91F_WaitKeyPressed(void)
66 {
67 int c;
68 - puts("Hit a Key!");
69 + putstr("Hit a Key!");
70 c = getc();
71 }
72
73 diff -urN romboot.old/main.cpp romboot/main.cpp
74 --- romboot.old/main.cpp 2007-04-03 12:12:33.000000000 +0200
75 +++ romboot/main.cpp 2007-04-04 05:56:39.000000000 +0200
76 @@ -382,8 +382,10 @@
77
78 AT91F_MCI_ReadBlockSwab(&MCI_Device, block*Max_Read_DataBlock_Length, (unsigned int *)bufpos, Max_Read_DataBlock_Length);
79
80 - if (p->magic != TRX_MAGIC)
81 + if (p->magic != TRX_MAGIC) {
82 + printf("Invalid Image 0x%08x\n\r");
83 return FALSE;
84 + }
85
86 printf("Read SD-Card\n\r");
87 AT91C_BASE_PIOC->PIO_CODR = AT91C_PIO_PC7 | AT91C_PIO_PC15 | AT91C_PIO_PC8 | AT91C_PIO_PC14;
88 @@ -438,9 +440,6 @@
89 int NbPage;
90 int mci_present;
91
92 - stdin = fopen(0, at91_dbgu_getc);
93 - stdout = fopen(at91_dbgu_putc, 0);
94 -
95 pAT91 = AT91C_ROM_BOOT_ADDRESS;
96
97 // Tempo Initialisation
98 @@ -472,16 +471,18 @@
99
100 #ifdef PRODTEST
101 if (mci_present) {
102 - Program_From_MCI();
103 - AT91F_StartUboot(0, (void *)0);
104 + if (Program_From_MCI())
105 + AT91F_StartUboot(0, (void *)0);
106 }
107 #endif
108
109 // start tempo to start Uboot in a delay of 1 sec if no key pressed
110 svcUbootTempo.Start(&svcUbootTempo, 1000, 0, AT91F_StartUboot, (void *)0);
111
112 +#ifndef PRODTEST
113 printf("press key\n\r");
114 getc();
115 +#endif
116
117 // stop tempo
118 svcUbootTempo.Stop(&svcUbootTempo);
119 @@ -601,3 +602,10 @@
120 AT91F_WaitKeyPressed();
121 }
122 }
123 +
124 +
125 +int puts(const char *str)
126 +{
127 + putstr(str);
128 + return 0;
129 +}
130 diff -urN romboot.old/stdio.cpp romboot/stdio.cpp
131 --- romboot.old/stdio.cpp 2004-07-04 22:36:10.000000000 +0200
132 +++ romboot/stdio.cpp 2007-04-04 04:29:25.000000000 +0200
133 @@ -1,117 +1,32 @@
134 #include "stdio.h"
135
136 extern int at91_dbgu_putc(int ch);
137 +extern int at91_dbgu_getc();
138
139 -FILE *stdout = (FILE *)0;
140 -FILE *stdin = (FILE *)0;
141 -
142 -FILE __filedesc[FILEDESCS];
143 -
144 -FILE *fopen(int (*put)(int), int (*get)())
145 -{
146 - static int init = 1;
147 -
148 - if(init != 0)
149 - {
150 - for(int i = 0; i < FILEDESCS; i++)
151 - {
152 - __filedesc[i].active = false;
153 - __filedesc[i].put = 0;
154 - __filedesc[i].get = 0;
155 - }
156 -
157 - init = 0;
158 - }
159 -
160 - for(int i = 0; i < FILEDESCS; i++)
161 - {
162 - if(!__filedesc[i].active)
163 - {
164 - __filedesc[i].put = put;
165 - __filedesc[i].get = get;
166 -
167 - __filedesc[i].active = true;
168 -
169 - return &__filedesc[i];
170 - }
171 - }
172 -
173 - return (FILE *)0;
174 -}
175 -
176 -int fclose(FILE *fp)
177 +int putstr(const char *str)
178 {
179 - for(int i = 0; i < FILEDESCS; i++)
180 - if(&__filedesc[i] == fp || fp->active)
181 - {
182 - fp->active = false;
183 -
184 - fp->put = 0;
185 - fp->get = 0;
186 -
187 - return 0;
188 - }
189 -
190 - return -1;
191 -}
192 -
193 -int fputs(const char *str, FILE *fp)
194 -{
195 - if(fp == (FILE *)0)
196 - return -1;
197 -
198 - if(fp->put == (void *)0)
199 - return -1;
200 -
201 - while(*str != 0)
202 - {
203 - fp->put(*str);
204 - str++;
205 - }
206 + while (*str != 0)
207 + {
208 + putc(*str);
209 + str++;
210 + }
211 return 0;
212 }
213
214 -int fputc(int c, FILE *fp)
215 -{
216 - if(fp == (FILE *)0)
217 - return -1;
218 -
219 - if(fp->put == (void *)0)
220 - return -1;
221 -
222 - return fp->put(c);
223 -}
224 -
225 -int fgetc(FILE *fp)
226 -{
227 - if(fp == (FILE *)0)
228 - return -1;
229 -
230 - if(fp->get == (void *)0)
231 - return -1;
232 -
233 - return fp->get();
234 -}
235 -
236 -
237 -int puts(const char *str)
238 +int putchar(int c)
239 {
240 - return fputs(str, stdout);
241 + return putc(c);
242 }
243
244 int putc(int c)
245 {
246 - return fputc(c, stdout);
247 -}
248 -
249 -int putchar(int c)
250 -{
251 - return fputc(c, stdout);
252 + at91_dbgu_putc(c);
253 + return 0;
254 }
255
256 int getc()
257 {
258 - return fgetc(stdin);
259 + return at91_dbgu_getc();
260 }
261
262 int strlen(const char *str)
263 @@ -139,7 +54,7 @@
264 __res; \
265 })
266
267 -int number(FILE *fp, int num, int base, int size, int precision, int type)
268 +int number(int num, int base, int size, int precision, int type)
269 {
270 char c, sign, tmp[66];
271 const char *digits="0123456789abcdef";
272 @@ -173,28 +88,28 @@
273
274 if(!(type&(ZEROPAD+LEFT)))
275 while(size-->0)
276 - fputc(' ', fp);
277 + putc(' ');
278
279 if(sign)
280 - fputc(sign, fp);
281 + putc(sign);
282
283 if (!(type & LEFT))
284 while (size-- > 0)
285 - fputc(c, fp);
286 + putc(c);
287
288 while (i < precision--)
289 - fputc('0', fp);
290 + putc('0');
291
292 while (i-- > 0)
293 - fputc(tmp[i], fp);
294 + putc(tmp[i]);
295
296 while (size-- > 0)
297 - fputc(' ', fp);;
298 + putc(' ');;
299
300 return 1;
301 }
302
303 -int vfprintf(FILE *fp, const char *fmt, va_list va)
304 +int vprintf(const char *fmt, va_list va)
305 {
306 char *s;
307
308 @@ -231,33 +146,33 @@
309 case 's' :
310 s = va_arg(va, char *);
311 if(!s)
312 - fputs("<NULL>", fp);
313 + putstr("<NULL>");
314 else
315 - fputs(s, fp);
316 + putstr(s);
317 done = true;
318 break;
319 case 'c' :
320 - fputc(va_arg(va, int), fp);
321 + putc(va_arg(va, int));
322 done = true;
323 break;
324 case 'd' :
325 - number(fp, va_arg(va, int), 10, 0, precision, type);
326 + number(va_arg(va, int), 10, 0, precision, type);
327 done = true;
328 break;
329 case 'x' :
330 - number(fp, va_arg(va, int), 16, 0, precision, type);
331 + number(va_arg(va, int), 16, 0, precision, type);
332 done = true;
333 break;
334 case 'X' :
335 - number(fp, va_arg(va, int), 16, 0, precision, type | LARGE);
336 + number(va_arg(va, int), 16, 0, precision, type | LARGE);
337 done = true;
338 break;
339 case '%' :
340 - fputc(*fmt, fp);
341 + putc(*fmt);
342 done = true;
343 default:
344 - fputc('%', fp);
345 - fputc(*fmt, fp);
346 + putc('%');
347 + putc(*fmt);
348 done = true;
349 break;
350 }
351 @@ -265,7 +180,7 @@
352 while(!done);
353 }
354 else
355 - fputc(*fmt, fp);
356 + putc(*fmt);
357
358 fmt++;
359 }
360 @@ -274,25 +189,13 @@
361 return 0;
362 }
363
364 -int fprintf(FILE *fp, const char *fmt, ...)
365 -{
366 - va_list ap;
367 - int i;
368 -
369 - va_start(ap, fmt);
370 - i = fprintf(fp, fmt, ap);
371 - va_end(ap);
372 -
373 - return i;
374 -}
375 -
376 int printf(const char *fmt, ...)
377 {
378 va_list ap;
379 int i;
380
381 va_start(ap, fmt);
382 - i = vfprintf(stdout, fmt, ap);
383 + i = vprintf(fmt, ap);
384 va_end(ap);
385
386 return i;
387 diff -urN romboot.old/stdio.h romboot/stdio.h
388 --- romboot.old/stdio.h 2004-07-04 22:04:27.000000000 +0200
389 +++ romboot/stdio.h 2007-04-04 04:29:48.000000000 +0200
390 @@ -1,31 +1,12 @@
391 #include <stdarg.h>
392
393 -struct FILE
394 -{
395 - bool active;
396 - int (*put)(int); /* function to write one char to device */
397 - int (*get)(); /* function to read one char from device */
398 -};
399 -
400 -#define FILEDESCS 8
401 -
402 -FILE *fopen(int (*put)(int), int (*get)());
403 -int fclose(FILE *fp);
404 -
405 -int puts(const char *str);
406 +int putstr(const char *str);
407 int putc(int c);
408 int putchar(int c);
409 int getc();
410
411 -int fputs(const char *str, FILE *fp);
412 -int fputc(int c, FILE *fp);
413 -int fgetc(FILE *fp);
414 int strlen(const char *str);
415
416 -int fprintf(FILE *fp, const char *fmt, ...);
417 -int vfprintf(FILE *fp, const char *fmt, va_list ap);
418 +int vprintf(const char *fmt, va_list ap);
419
420 int printf(const char *fmt, ...);
421 -
422 -extern FILE *stdout;
423 -extern FILE *stdin;