blob: 793684d0e29417bcb791832e2d19a1474f8ca380 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
2 * (C) Copyright 2001
3 * Denis Peter, MPL AG Switzerland, d.peter@mpl.ch
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 *
23 */
24
25#include <common.h>
26#include <command.h>
27#include <video_fb.h>
28#include "common_util.h"
29#include <asm/processor.h>
wdenk1cb8e982003-03-06 21:55:29 +000030#include <asm/byteorder.h>
wdenkc6097192002-11-03 00:24:07 +000031#include <i2c.h>
32#include <devices.h>
33#include <pci.h>
wdenka2663ea2003-12-07 18:32:37 +000034#include <malloc.h>
35#include <bzlib.h>
wdenkc6097192002-11-03 00:24:07 +000036
wdenk33149b82003-05-23 11:38:58 +000037#ifdef CONFIG_PIP405
38#include "../pip405/pip405.h"
39#include <405gp_pci.h>
40#endif
41#ifdef CONFIG_MIP405
42#include "../mip405/mip405.h"
43#include <405gp_pci.h>
44#endif
wdenkb6e4c402004-01-02 16:05:07 +000045#if defined(CONFIG_PATI)
46#define FIRM_START 0xFFF00000
47#endif
wdenk33149b82003-05-23 11:38:58 +000048
wdenka2663ea2003-12-07 18:32:37 +000049extern int gunzip(void *, int, uchar *, int *);
50extern int mem_test(ulong start, ulong ramsize, int quiet);
wdenkc6097192002-11-03 00:24:07 +000051
wdenka2663ea2003-12-07 18:32:37 +000052#define I2C_BACKUP_ADDR 0x7C00 /* 0x200 bytes for backup */
53#define IMAGE_SIZE CFG_MONITOR_LEN /* ugly, but it works for now */
wdenkc6097192002-11-03 00:24:07 +000054
55extern flash_info_t flash_info[]; /* info for FLASH chips */
56
wdenk1cb8e982003-03-06 21:55:29 +000057static image_header_t header;
wdenkc6097192002-11-03 00:24:07 +000058
59
wdenkd4ca31c2004-01-02 14:00:00 +000060static int
wdenka2663ea2003-12-07 18:32:37 +000061mpl_prg(uchar *src, ulong size)
wdenkc6097192002-11-03 00:24:07 +000062{
wdenka2663ea2003-12-07 18:32:37 +000063 ulong start;
wdenkc6097192002-11-03 00:24:07 +000064 flash_info_t *info;
wdenka2663ea2003-12-07 18:32:37 +000065 int i, rc;
wdenkb6e4c402004-01-02 16:05:07 +000066#if defined(CONFIG_PATI)
67 int start_sect;
68#endif
69#if defined(CONFIG_PIP405) || defined(CONFIG_MIP405) || defined(CONFIG_PATI)
wdenkf3e0de62003-06-04 15:05:30 +000070 char *copystr = (char *)src;
wdenka2663ea2003-12-07 18:32:37 +000071 ulong *magic = (ulong *)src;
wdenk06d01db2003-03-14 20:47:52 +000072#endif
wdenkc6097192002-11-03 00:24:07 +000073
74 info = &flash_info[0];
wdenk1cb8e982003-03-06 21:55:29 +000075
wdenkb6e4c402004-01-02 16:05:07 +000076#if defined(CONFIG_PIP405) || defined(CONFIG_MIP405) || defined(CONFIG_PATI)
wdenka2663ea2003-12-07 18:32:37 +000077 if (ntohl(magic[0]) != IH_MAGIC) {
78 puts("Bad Magic number\n");
wdenk1cb8e982003-03-06 21:55:29 +000079 return -1;
80 }
wdenkf3e0de62003-06-04 15:05:30 +000081 /* some more checks before we delete the Flash... */
82 /* Checking the ISO_STRING prevents to program a
83 * wrong Firmware Image into the flash.
84 */
wdenka2663ea2003-12-07 18:32:37 +000085 i = 4; /* skip Magic number */
86 while (1) {
87 if (strncmp(&copystr[i], "MEV-", 4) == 0)
wdenkf3e0de62003-06-04 15:05:30 +000088 break;
wdenka2663ea2003-12-07 18:32:37 +000089 if (i++ >= 0x100) {
90 puts("Firmware Image for unknown Target\n");
wdenkf3e0de62003-06-04 15:05:30 +000091 return -1;
92 }
93 }
94 /* we have the ISO STRING, check */
wdenka2663ea2003-12-07 18:32:37 +000095 if (strncmp(&copystr[i], CONFIG_ISO_STRING, sizeof(CONFIG_ISO_STRING)-1) != 0) {
96 printf("Wrong Firmware Image: %s\n", &copystr[i]);
wdenkf3e0de62003-06-04 15:05:30 +000097 return -1;
98 }
wdenkb6e4c402004-01-02 16:05:07 +000099#if !defined(CONFIG_PATI)
wdenkf3e0de62003-06-04 15:05:30 +0000100 start = 0 - size;
wdenka2663ea2003-12-07 18:32:37 +0000101 for (i = info->sector_count-1; i > 0; i--) {
wdenkc6097192002-11-03 00:24:07 +0000102 info->protect[i] = 0; /* unprotect this sector */
wdenka2663ea2003-12-07 18:32:37 +0000103 if (start >= info->start[i])
104 break;
wdenkc6097192002-11-03 00:24:07 +0000105 }
106 /* set-up flash location */
107 /* now erase flash */
wdenkc6097192002-11-03 00:24:07 +0000108 printf("Erasing at %lx (sector %d) (start %lx)\n",
109 start,i,info->start[i]);
wdenka2663ea2003-12-07 18:32:37 +0000110 if ((rc = flash_erase (info, i, info->sector_count-1)) != 0) {
111 puts("ERROR ");
112 flash_perror(rc);
113 return (1);
114 }
wdenk1cb8e982003-03-06 21:55:29 +0000115
wdenkb6e4c402004-01-02 16:05:07 +0000116#else /* #if !defined(CONFIG_PATI */
117 start = FIRM_START;
118 start_sect = -1;
119 for (i = 0; i < info->sector_count; i++) {
120 if (start < info->start[i]) {
121 start_sect = i - 1;
122 break;
123 }
124 }
125
126 info->protect[i - 1] = 0; /* unprotect this sector */
127 for (; i < info->sector_count; i++) {
128 if ((start + size) < info->start[i])
129 break;
130 info->protect[i] = 0; /* unprotect this sector */
131 }
132
133 i--;
134 /* set-up flash location */
135 /* now erase flash */
136 printf ("Erasing at %lx to %lx (sector %d to %d) (%lx to %lx)\n",
137 start, start + size, start_sect, i,
138 info->start[start_sect], info->start[i]);
139 if ((rc = flash_erase (info, start_sect, i)) != 0) {
140 puts ("ERROR ");
141 flash_perror (rc);
142 return (1);
143 }
144#endif /* defined(CONFIG_PATI) */
145
wdenk1cb8e982003-03-06 21:55:29 +0000146#elif defined(CONFIG_VCMA9)
147 start = 0;
wdenka2663ea2003-12-07 18:32:37 +0000148 for (i = 0; i <info->sector_count; i++) {
wdenk1cb8e982003-03-06 21:55:29 +0000149 info->protect[i] = 0; /* unprotect this sector */
150 if (size < info->start[i])
151 break;
152 }
153 /* set-up flash location */
154 /* now erase flash */
155 printf("Erasing at %lx (sector %d) (start %lx)\n",
156 start,0,info->start[0]);
wdenka2663ea2003-12-07 18:32:37 +0000157 if ((rc = flash_erase (info, 0, i)) != 0) {
158 puts("ERROR ");
159 flash_perror(rc);
160 return (1);
161 }
wdenk1cb8e982003-03-06 21:55:29 +0000162
163#endif
wdenkd4ca31c2004-01-02 14:00:00 +0000164 printf("flash erased, programming from 0x%lx 0x%lx Bytes\n",
165 (ulong)src, size);
wdenka2663ea2003-12-07 18:32:37 +0000166 if ((rc = flash_write (src, start, size)) != 0) {
167 puts("ERROR ");
168 flash_perror(rc);
wdenkc6097192002-11-03 00:24:07 +0000169 return (1);
170 }
wdenka2663ea2003-12-07 18:32:37 +0000171 puts("OK programming done\n");
wdenkc6097192002-11-03 00:24:07 +0000172 return 0;
173}
174
175
wdenkd4ca31c2004-01-02 14:00:00 +0000176static int
wdenka2663ea2003-12-07 18:32:37 +0000177mpl_prg_image(uchar *ld_addr)
wdenkc6097192002-11-03 00:24:07 +0000178{
wdenka2663ea2003-12-07 18:32:37 +0000179 unsigned long len, checksum;
180 uchar *data;
181 image_header_t *hdr = &header;
182 int rc;
wdenkd4ca31c2004-01-02 14:00:00 +0000183
wdenkc6097192002-11-03 00:24:07 +0000184 /* Copy header so we can blank CRC field for re-calculation */
185 memcpy (&header, (char *)ld_addr, sizeof(image_header_t));
wdenk1cb8e982003-03-06 21:55:29 +0000186 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
wdenka2663ea2003-12-07 18:32:37 +0000187 puts("Bad Magic Number\n");
wdenkc6097192002-11-03 00:24:07 +0000188 return 1;
189 }
190 print_image_hdr(hdr);
191 if (hdr->ih_os != IH_OS_U_BOOT) {
wdenka2663ea2003-12-07 18:32:37 +0000192 puts("No U-Boot Image\n");
wdenkc6097192002-11-03 00:24:07 +0000193 return 1;
194 }
195 if (hdr->ih_type != IH_TYPE_FIRMWARE) {
wdenka2663ea2003-12-07 18:32:37 +0000196 puts("No Firmware Image\n");
wdenkc6097192002-11-03 00:24:07 +0000197 return 1;
198 }
wdenka2663ea2003-12-07 18:32:37 +0000199 data = (uchar *)&header;
wdenkc6097192002-11-03 00:24:07 +0000200 len = sizeof(image_header_t);
wdenk1cb8e982003-03-06 21:55:29 +0000201 checksum = ntohl(hdr->ih_hcrc);
wdenkc6097192002-11-03 00:24:07 +0000202 hdr->ih_hcrc = 0;
203 if (crc32 (0, (char *)data, len) != checksum) {
wdenka2663ea2003-12-07 18:32:37 +0000204 puts("Bad Header Checksum\n");
wdenkc6097192002-11-03 00:24:07 +0000205 return 1;
206 }
207 data = ld_addr + sizeof(image_header_t);
wdenk1cb8e982003-03-06 21:55:29 +0000208 len = ntohl(hdr->ih_size);
wdenka2663ea2003-12-07 18:32:37 +0000209 puts("Verifying Checksum ... ");
wdenk1cb8e982003-03-06 21:55:29 +0000210 if (crc32 (0, (char *)data, len) != ntohl(hdr->ih_dcrc)) {
wdenka2663ea2003-12-07 18:32:37 +0000211 puts("Bad Data CRC\n");
wdenkc6097192002-11-03 00:24:07 +0000212 return 1;
213 }
wdenka2663ea2003-12-07 18:32:37 +0000214 puts("OK\n");
215
216 if (hdr->ih_comp != IH_COMP_NONE) {
217 uchar *buf;
218 /* reserve space for uncompressed image */
219 if ((buf = malloc(IMAGE_SIZE)) == NULL) {
220 puts("Insufficient space for decompression\n");
wdenkc6097192002-11-03 00:24:07 +0000221 return 1;
222 }
wdenkd4ca31c2004-01-02 14:00:00 +0000223
wdenka2663ea2003-12-07 18:32:37 +0000224 switch (hdr->ih_comp) {
225 case IH_COMP_GZIP:
226 puts("Uncompressing (GZIP) ... ");
227 rc = gunzip ((void *)(buf), IMAGE_SIZE, data, (int *)&len);
228 if (rc != 0) {
229 puts("GUNZIP ERROR\n");
230 free(buf);
231 return 1;
232 }
233 puts("OK\n");
234 break;
wdenk42dfe7a2004-03-14 22:25:36 +0000235#ifdef CONFIG_BZIP2
wdenka2663ea2003-12-07 18:32:37 +0000236 case IH_COMP_BZIP2:
237 puts("Uncompressing (BZIP2) ... ");
238 {
239 uint retlen = IMAGE_SIZE;
240 rc = BZ2_bzBuffToBuffDecompress ((char *)(buf), &retlen,
241 (char *)data, len, 0, 0);
242 len = retlen;
243 }
244 if (rc != BZ_OK) {
245 printf ("BUNZIP2 ERROR: %d\n", rc);
246 free(buf);
247 return 1;
248 }
249 puts("OK\n");
250 break;
251#endif
252 default:
253 printf ("Unimplemented compression type %d\n", hdr->ih_comp);
254 free(buf);
255 return 1;
256 }
wdenkd4ca31c2004-01-02 14:00:00 +0000257
wdenka2663ea2003-12-07 18:32:37 +0000258 rc = mpl_prg(buf, len);
259 free(buf);
260 } else {
261 rc = mpl_prg(data, len);
wdenkc6097192002-11-03 00:24:07 +0000262 }
wdenkd4ca31c2004-01-02 14:00:00 +0000263
wdenka2663ea2003-12-07 18:32:37 +0000264 return(rc);
wdenkc6097192002-11-03 00:24:07 +0000265}
266
wdenkb6e4c402004-01-02 16:05:07 +0000267#if !defined(CONFIG_PATI)
wdenkc6097192002-11-03 00:24:07 +0000268void get_backup_values(backup_t *buf)
269{
270 i2c_read(CFG_DEF_EEPROM_ADDR, I2C_BACKUP_ADDR,2,(void *)buf,sizeof(backup_t));
271}
272
273void set_backup_values(int overwrite)
274{
275 backup_t back;
276 int i;
277
278 get_backup_values(&back);
279 if(!overwrite) {
280 if(strncmp(back.signature,"MPL\0",4)==0) {
wdenka2663ea2003-12-07 18:32:37 +0000281 puts("Not possible to write Backup\n");
wdenkc6097192002-11-03 00:24:07 +0000282 return;
283 }
284 }
285 memcpy(back.signature,"MPL\0",4);
wdenk1cb8e982003-03-06 21:55:29 +0000286 i = getenv_r("serial#",back.serial_name,16);
287 if(i < 0) {
wdenka2663ea2003-12-07 18:32:37 +0000288 puts("Not possible to write Backup\n");
wdenkc6097192002-11-03 00:24:07 +0000289 return;
290 }
291 back.serial_name[16]=0;
wdenk1cb8e982003-03-06 21:55:29 +0000292 i = getenv_r("ethaddr",back.eth_addr,20);
293 if(i < 0) {
wdenka2663ea2003-12-07 18:32:37 +0000294 puts("Not possible to write Backup\n");
wdenkc6097192002-11-03 00:24:07 +0000295 return;
296 }
297 back.eth_addr[20]=0;
298 i2c_write(CFG_DEF_EEPROM_ADDR, I2C_BACKUP_ADDR,2,(void *)&back,sizeof(backup_t));
299}
300
301void clear_env_values(void)
302{
303 backup_t back;
304 unsigned char env_crc[4];
305
306 memset(&back,0xff,sizeof(backup_t));
307 memset(env_crc,0x00,4);
308 i2c_write(CFG_DEF_EEPROM_ADDR,I2C_BACKUP_ADDR,2,(void *)&back,sizeof(backup_t));
309 i2c_write(CFG_DEF_EEPROM_ADDR,CFG_ENV_OFFSET,2,(void *)env_crc,4);
310}
311
312/*
313 * check crc of "older" environment
314 */
315int check_env_old_size(ulong oldsize)
316{
317 ulong crc, len, new;
318 unsigned off;
319 uchar buf[64];
320
321 /* read old CRC */
322 eeprom_read (CFG_DEF_EEPROM_ADDR,
323 CFG_ENV_OFFSET,
324 (uchar *)&crc, sizeof(ulong));
325
326 new = 0;
327 len = oldsize;
328 off = sizeof(long);
329 len = oldsize-off;
330 while (len > 0) {
331 int n = (len > sizeof(buf)) ? sizeof(buf) : len;
332
333 eeprom_read (CFG_DEF_EEPROM_ADDR, CFG_ENV_OFFSET+off, buf, n);
334 new = crc32 (new, buf, n);
335 len -= n;
336 off += n;
337 }
338
339 return (crc == new);
340}
341
342static ulong oldsizes[] = {
343 0x200,
344 0x800,
345 0
346};
347
348void copy_old_env(ulong size)
349{
350 uchar name_buf[64];
351 uchar value_buf[0x800];
352 uchar c;
353 ulong len;
354 unsigned off;
355 uchar *name, *value;
356
357 name=&name_buf[0];
358 value=&value_buf[0];
359 len=size;
360 off = sizeof(long);
361 while (len > off) {
362 eeprom_read (CFG_DEF_EEPROM_ADDR, CFG_ENV_OFFSET+off, &c, 1);
363 if(c != '=') {
364 *name++=c;
365 off++;
366 }
367 else {
368 *name++='\0';
369 off++;
370 do {
371 eeprom_read (CFG_DEF_EEPROM_ADDR, CFG_ENV_OFFSET+off, &c, 1);
372 *value++=c;
373 off++;
374 if(c == '\0')
375 break;
376 } while(len > off);
377 name=&name_buf[0];
378 value=&value_buf[0];
379 if(strncmp(name,"baudrate",8)!=0) {
380 setenv(name,value);
381 }
382
383 }
384 }
385}
386
387
388void check_env(void)
389{
390 unsigned char *s;
391 int i=0;
392 char buf[32];
393 backup_t back;
394
395 s=getenv("serial#");
396 if(!s) {
397 while(oldsizes[i]) {
398 if(check_env_old_size(oldsizes[i]))
399 break;
400 i++;
401 }
402 if(!oldsizes[i]) {
403 /* no old environment has been found */
404 get_backup_values (&back);
405 if (strncmp (back.signature, "MPL\0", 4) == 0) {
406 sprintf (buf, "%s", back.serial_name);
407 setenv ("serial#", buf);
408 sprintf (buf, "%s", back.eth_addr);
409 setenv ("ethaddr", buf);
410 printf ("INFO: serial# and ethaddr recovered, use saveenv\n");
411 return;
412 }
413 }
414 else {
415 copy_old_env(oldsizes[i]);
wdenka2663ea2003-12-07 18:32:37 +0000416 puts("INFO: old environment ajusted, use saveenv\n");
wdenkc6097192002-11-03 00:24:07 +0000417 }
418 }
419 else {
420 /* check if back up is set */
421 get_backup_values(&back);
422 if(strncmp(back.signature,"MPL\0",4)!=0) {
423 set_backup_values(0);
424 }
425 }
426}
427
428
wdenkc6097192002-11-03 00:24:07 +0000429extern device_t *stdio_devices[];
430extern char *stdio_names[];
431
432void show_stdio_dev(void)
433{
wdenk47cd00f2003-03-06 13:39:27 +0000434 /* Print information */
wdenka2663ea2003-12-07 18:32:37 +0000435 puts("In: ");
wdenkc6097192002-11-03 00:24:07 +0000436 if (stdio_devices[stdin] == NULL) {
wdenka2663ea2003-12-07 18:32:37 +0000437 puts("No input devices available!\n");
wdenkc6097192002-11-03 00:24:07 +0000438 } else {
439 printf ("%s\n", stdio_devices[stdin]->name);
440 }
441
wdenka2663ea2003-12-07 18:32:37 +0000442 puts("Out: ");
wdenkc6097192002-11-03 00:24:07 +0000443 if (stdio_devices[stdout] == NULL) {
wdenka2663ea2003-12-07 18:32:37 +0000444 puts("No output devices available!\n");
wdenkc6097192002-11-03 00:24:07 +0000445 } else {
446 printf ("%s\n", stdio_devices[stdout]->name);
447 }
448
wdenka2663ea2003-12-07 18:32:37 +0000449 puts("Err: ");
wdenkc6097192002-11-03 00:24:07 +0000450 if (stdio_devices[stderr] == NULL) {
wdenka2663ea2003-12-07 18:32:37 +0000451 puts("No error devices available!\n");
wdenkc6097192002-11-03 00:24:07 +0000452 } else {
453 printf ("%s\n", stdio_devices[stderr]->name);
454 }
455}
456
wdenkb6e4c402004-01-02 16:05:07 +0000457#endif /* #if !defined(CONFIG_PATI) */
wdenkc6097192002-11-03 00:24:07 +0000458
459int do_mplcommon(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
460{
461 ulong size,src,ld_addr;
462 int result;
wdenkb6e4c402004-01-02 16:05:07 +0000463#if !defined(CONFIG_PATI)
wdenkc6097192002-11-03 00:24:07 +0000464 backup_t back;
wdenkc6097192002-11-03 00:24:07 +0000465 src = MULTI_PURPOSE_SOCKET_ADDR;
466 size = IMAGE_SIZE;
wdenkb6e4c402004-01-02 16:05:07 +0000467#endif
wdenkc6097192002-11-03 00:24:07 +0000468
469 if (strcmp(argv[1], "flash") == 0)
470 {
wdenkc6097192002-11-03 00:24:07 +0000471#if (CONFIG_COMMANDS & CFG_CMD_FDC)
472 if (strcmp(argv[2], "floppy") == 0) {
473 char *local_args[3];
474 extern int do_fdcboot (cmd_tbl_t *, int, int, char *[]);
wdenka2663ea2003-12-07 18:32:37 +0000475 puts("\nupdating bootloader image from floppy\n");
wdenkc6097192002-11-03 00:24:07 +0000476 local_args[0] = argv[0];
477 if(argc==4) {
478 local_args[1] = argv[3];
479 local_args[2] = NULL;
480 ld_addr=simple_strtoul(argv[3], NULL, 16);
481 result=do_fdcboot(cmdtp, 0, 2, local_args);
482 }
483 else {
484 local_args[1] = NULL;
485 ld_addr=CFG_LOAD_ADDR;
486 result=do_fdcboot(cmdtp, 0, 1, local_args);
487 }
wdenkd4ca31c2004-01-02 14:00:00 +0000488 result=mpl_prg_image((uchar *)ld_addr);
wdenkc6097192002-11-03 00:24:07 +0000489 return result;
490 }
491#endif /* (CONFIG_COMMANDS & CFG_CMD_FDC) */
492 if (strcmp(argv[2], "mem") == 0) {
493 if(argc==4) {
494 ld_addr=simple_strtoul(argv[3], NULL, 16);
495 }
496 else {
497 ld_addr=load_addr;
498 }
499 printf ("\nupdating bootloader image from memory at %lX\n",ld_addr);
wdenka2663ea2003-12-07 18:32:37 +0000500 result=mpl_prg_image((uchar *)ld_addr);
wdenkc6097192002-11-03 00:24:07 +0000501 return result;
502 }
wdenkb6e4c402004-01-02 16:05:07 +0000503#if !defined(CONFIG_PATI)
wdenkc6097192002-11-03 00:24:07 +0000504 if (strcmp(argv[2], "mps") == 0) {
wdenka2663ea2003-12-07 18:32:37 +0000505 puts("\nupdating bootloader image from MPS\n");
506 result=mpl_prg((uchar *)src,size);
wdenkc6097192002-11-03 00:24:07 +0000507 return result;
508 }
wdenkb6e4c402004-01-02 16:05:07 +0000509#endif /* #if !defined(CONFIG_PATI) */
wdenkc6097192002-11-03 00:24:07 +0000510 }
511 if (strcmp(argv[1], "mem") == 0)
512 {
513 result=0;
514 if(argc==3)
515 {
516 result = (int)simple_strtol(argv[2], NULL, 16);
517 }
518 src=(unsigned long)&result;
519 src-=CFG_MEMTEST_START;
520 src-=(100*1024); /* - 100k */
521 src&=0xfff00000;
522 size=0;
523 do {
524 size++;
525 printf("\n\nPass %ld\n",size);
526 mem_test(CFG_MEMTEST_START,src,1);
527 if(ctrlc())
528 break;
529 if(result>0)
530 result--;
531
532 }while(result);
533 return 0;
534 }
wdenkb6e4c402004-01-02 16:05:07 +0000535#if !defined(CONFIG_PATI)
wdenkc6097192002-11-03 00:24:07 +0000536 if (strcmp(argv[1], "clearenvvalues") == 0)
537 {
538 if (strcmp(argv[2], "yes") == 0)
539 {
540 clear_env_values();
541 return 0;
542 }
543 }
544 if (strcmp(argv[1], "getback") == 0) {
545 get_backup_values(&back);
546 back.signature[3]=0;
547 back.serial_name[16]=0;
548 back.eth_addr[20]=0;
549 printf("GetBackUp: signature: %s\n",back.signature);
550 printf(" serial#: %s\n",back.serial_name);
551 printf(" ethaddr: %s\n",back.eth_addr);
552 return 0;
553 }
554 if (strcmp(argv[1], "setback") == 0) {
555 set_backup_values(1);
556 return 0;
557 }
wdenkb6e4c402004-01-02 16:05:07 +0000558#endif
wdenkc6097192002-11-03 00:24:07 +0000559 printf("Usage:\n%s\n", cmdtp->usage);
560 return 1;
561}
562
563
564#if (CONFIG_COMMANDS & CFG_CMD_DOC)
565extern void doc_probe(ulong physadr);
566void doc_init (void)
567{
568 doc_probe(MULTI_PURPOSE_SOCKET_ADDR);
569}
570#endif
571
572
573#ifdef CONFIG_VIDEO
574/******************************************************
575 * Routines to display the Board information
576 * to the screen (since the VGA will be initialized as last,
577 * we must resend the infos)
578 */
579
580#ifdef CONFIG_CONSOLE_EXTRA_INFO
581extern GraphicDevice ctfb;
wdenk7205e402003-09-10 22:30:53 +0000582extern int get_boot_mode(void);
wdenkc6097192002-11-03 00:24:07 +0000583
584void video_get_info_str (int line_number, char *info)
585{
586 /* init video info strings for graphic console */
587 DECLARE_GLOBAL_DATA_PTR;
588 PPC405_SYS_INFO sys_info;
589 char rev;
wdenk33149b82003-05-23 11:38:58 +0000590 int i,boot;
wdenkc6097192002-11-03 00:24:07 +0000591 unsigned long pvr;
592 char buf[64];
593 char tmp[16];
wdenk33149b82003-05-23 11:38:58 +0000594 char cpustr[16];
595 unsigned char *s, *e, bc;
wdenkc6097192002-11-03 00:24:07 +0000596 switch (line_number)
597 {
598 case 2:
599 /* CPU and board infos */
600 pvr=get_pvr();
601 get_sys_info (&sys_info);
602 switch (pvr) {
603 case PVR_405GP_RB: rev='B'; break;
604 case PVR_405GP_RC: rev='C'; break;
605 case PVR_405GP_RD: rev='D'; break;
606 case PVR_405GP_RE: rev='E'; break;
wdenk33149b82003-05-23 11:38:58 +0000607 case PVR_405GPR_RB: rev='B'; break;
wdenkc6097192002-11-03 00:24:07 +0000608 default: rev='?'; break;
609 }
wdenk33149b82003-05-23 11:38:58 +0000610 if(pvr==PVR_405GPR_RB)
611 sprintf(cpustr,"PPC405GPr %c",rev);
612 else
613 sprintf(cpustr,"PPC405GP %c",rev);
wdenkc6097192002-11-03 00:24:07 +0000614 /* Board info */
615 i=0;
616 s=getenv ("serial#");
617#ifdef CONFIG_PIP405
618 if (!s || strncmp (s, "PIP405", 6)) {
619 sprintf(buf,"### No HW ID - assuming PIP405");
620 }
621#endif
622#ifdef CONFIG_MIP405
623 if (!s || strncmp (s, "MIP405", 6)) {
624 sprintf(buf,"### No HW ID - assuming MIP405");
625 }
626#endif
627 else {
628 for (e = s; *e; ++e) {
629 if (*e == ' ')
630 break;
631 }
632 for (; s < e; ++s) {
633 if (*s == '_') {
634 ++s;
635 break;
636 }
637 buf[i++]=*s;
638 }
639 sprintf(&buf[i]," SN ");
640 i+=4;
641 for (; s < e; ++s) {
642 buf[i++]=*s;
643 }
644 buf[i++]=0;
645 }
wdenk33149b82003-05-23 11:38:58 +0000646 sprintf (info," %s %s %s MHz (%lu/%lu/%lu MHz)",
647 buf, cpustr,
wdenkc6097192002-11-03 00:24:07 +0000648 strmhz (tmp, gd->cpu_clk), sys_info.freqPLB / 1000000,
649 sys_info.freqPLB / sys_info.pllOpbDiv / 1000000,
650 sys_info.freqPLB / sys_info.pllExtBusDiv / 1000000);
651 return;
652 case 3:
653 /* Memory Info */
wdenk33149b82003-05-23 11:38:58 +0000654 boot = get_boot_mode();
wdenkc6097192002-11-03 00:24:07 +0000655 bc = in8 (CONFIG_PORT_ADDR);
656 sprintf(info, " %luMB RAM, %luMB Flash Cfg 0x%02X %s %s",
657 gd->bd->bi_memsize / 0x100000,
658 gd->bd->bi_flashsize / 0x100000,
659 bc,
wdenk33149b82003-05-23 11:38:58 +0000660 (boot & BOOT_MPS) ? "MPS boot" : "Flash boot",
wdenkc6097192002-11-03 00:24:07 +0000661 ctfb.modeIdent);
662 return;
663 case 1:
664 sprintf (buf, "%s",CONFIG_IDENT_STRING);
665 sprintf (info, " %s", &buf[1]);
666 return;
667 }
668 /* no more info lines */
669 *info = 0;
670 return;
671}
672#endif /* CONFIG_CONSOLE_EXTRA_INFO */
673
674#endif /* CONFIG_VIDEO */