blob: b4343d81dedea6d44ae9847751d478f339dd68ec [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>
wdenkc6097192002-11-03 00:24:07 +000032#include <pci.h>
wdenka2663ea2003-12-07 18:32:37 +000033#include <malloc.h>
34#include <bzlib.h>
wdenkc6097192002-11-03 00:24:07 +000035
wdenk33149b82003-05-23 11:38:58 +000036#ifdef CONFIG_PIP405
37#include "../pip405/pip405.h"
Stefan Roese3048bcb2007-10-03 15:01:02 +020038#include <asm/4xx_pci.h>
wdenk33149b82003-05-23 11:38:58 +000039#endif
40#ifdef CONFIG_MIP405
41#include "../mip405/mip405.h"
Stefan Roese3048bcb2007-10-03 15:01:02 +020042#include <asm/4xx_pci.h>
wdenk33149b82003-05-23 11:38:58 +000043#endif
Wolfgang Denkd87080b2006-03-31 18:32:53 +020044
45DECLARE_GLOBAL_DATA_PTR;
46
wdenkb6e4c402004-01-02 16:05:07 +000047#if defined(CONFIG_PATI)
48#define FIRM_START 0xFFF00000
49#endif
wdenk33149b82003-05-23 11:38:58 +000050
wdenka2663ea2003-12-07 18:32:37 +000051extern int mem_test(ulong start, ulong ramsize, int quiet);
wdenkc6097192002-11-03 00:24:07 +000052
wdenka2663ea2003-12-07 18:32:37 +000053#define I2C_BACKUP_ADDR 0x7C00 /* 0x200 bytes for backup */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020054#define IMAGE_SIZE CONFIG_SYS_MONITOR_LEN /* ugly, but it works for now */
wdenkc6097192002-11-03 00:24:07 +000055
56extern flash_info_t flash_info[]; /* info for FLASH chips */
57
wdenkd4ca31c2004-01-02 14:00:00 +000058static int
wdenka2663ea2003-12-07 18:32:37 +000059mpl_prg(uchar *src, ulong size)
wdenkc6097192002-11-03 00:24:07 +000060{
wdenka2663ea2003-12-07 18:32:37 +000061 ulong start;
wdenkc6097192002-11-03 00:24:07 +000062 flash_info_t *info;
wdenka2663ea2003-12-07 18:32:37 +000063 int i, rc;
wdenkb6e4c402004-01-02 16:05:07 +000064#if defined(CONFIG_PATI)
65 int start_sect;
66#endif
67#if defined(CONFIG_PIP405) || defined(CONFIG_MIP405) || defined(CONFIG_PATI)
wdenkf3e0de62003-06-04 15:05:30 +000068 char *copystr = (char *)src;
wdenka2663ea2003-12-07 18:32:37 +000069 ulong *magic = (ulong *)src;
wdenk06d01db2003-03-14 20:47:52 +000070#endif
wdenkc6097192002-11-03 00:24:07 +000071
72 info = &flash_info[0];
wdenk1cb8e982003-03-06 21:55:29 +000073
wdenkb6e4c402004-01-02 16:05:07 +000074#if defined(CONFIG_PIP405) || defined(CONFIG_MIP405) || defined(CONFIG_PATI)
Marian Balakowicz9a4daad2008-02-29 14:58:34 +010075 if (uimage_to_cpu (magic[0]) != IH_MAGIC) {
wdenka2663ea2003-12-07 18:32:37 +000076 puts("Bad Magic number\n");
wdenk1cb8e982003-03-06 21:55:29 +000077 return -1;
78 }
wdenkf3e0de62003-06-04 15:05:30 +000079 /* some more checks before we delete the Flash... */
80 /* Checking the ISO_STRING prevents to program a
81 * wrong Firmware Image into the flash.
82 */
wdenka2663ea2003-12-07 18:32:37 +000083 i = 4; /* skip Magic number */
84 while (1) {
85 if (strncmp(&copystr[i], "MEV-", 4) == 0)
wdenkf3e0de62003-06-04 15:05:30 +000086 break;
wdenka2663ea2003-12-07 18:32:37 +000087 if (i++ >= 0x100) {
88 puts("Firmware Image for unknown Target\n");
wdenkf3e0de62003-06-04 15:05:30 +000089 return -1;
90 }
91 }
92 /* we have the ISO STRING, check */
wdenka2663ea2003-12-07 18:32:37 +000093 if (strncmp(&copystr[i], CONFIG_ISO_STRING, sizeof(CONFIG_ISO_STRING)-1) != 0) {
94 printf("Wrong Firmware Image: %s\n", &copystr[i]);
wdenkf3e0de62003-06-04 15:05:30 +000095 return -1;
96 }
wdenkb6e4c402004-01-02 16:05:07 +000097#if !defined(CONFIG_PATI)
wdenkf3e0de62003-06-04 15:05:30 +000098 start = 0 - size;
wdenka2663ea2003-12-07 18:32:37 +000099 for (i = info->sector_count-1; i > 0; i--) {
wdenkc6097192002-11-03 00:24:07 +0000100 info->protect[i] = 0; /* unprotect this sector */
wdenka2663ea2003-12-07 18:32:37 +0000101 if (start >= info->start[i])
102 break;
wdenkc6097192002-11-03 00:24:07 +0000103 }
104 /* set-up flash location */
105 /* now erase flash */
wdenkc6097192002-11-03 00:24:07 +0000106 printf("Erasing at %lx (sector %d) (start %lx)\n",
107 start,i,info->start[i]);
wdenka2663ea2003-12-07 18:32:37 +0000108 if ((rc = flash_erase (info, i, info->sector_count-1)) != 0) {
109 puts("ERROR ");
110 flash_perror(rc);
111 return (1);
112 }
wdenk1cb8e982003-03-06 21:55:29 +0000113
wdenkb6e4c402004-01-02 16:05:07 +0000114#else /* #if !defined(CONFIG_PATI */
115 start = FIRM_START;
116 start_sect = -1;
117 for (i = 0; i < info->sector_count; i++) {
118 if (start < info->start[i]) {
119 start_sect = i - 1;
120 break;
121 }
122 }
123
124 info->protect[i - 1] = 0; /* unprotect this sector */
125 for (; i < info->sector_count; i++) {
126 if ((start + size) < info->start[i])
127 break;
128 info->protect[i] = 0; /* unprotect this sector */
129 }
130
131 i--;
132 /* set-up flash location */
133 /* now erase flash */
134 printf ("Erasing at %lx to %lx (sector %d to %d) (%lx to %lx)\n",
135 start, start + size, start_sect, i,
136 info->start[start_sect], info->start[i]);
137 if ((rc = flash_erase (info, start_sect, i)) != 0) {
138 puts ("ERROR ");
139 flash_perror (rc);
140 return (1);
141 }
142#endif /* defined(CONFIG_PATI) */
143
wdenk1cb8e982003-03-06 21:55:29 +0000144#elif defined(CONFIG_VCMA9)
145 start = 0;
wdenka2663ea2003-12-07 18:32:37 +0000146 for (i = 0; i <info->sector_count; i++) {
wdenk1cb8e982003-03-06 21:55:29 +0000147 info->protect[i] = 0; /* unprotect this sector */
148 if (size < info->start[i])
149 break;
150 }
151 /* set-up flash location */
152 /* now erase flash */
153 printf("Erasing at %lx (sector %d) (start %lx)\n",
154 start,0,info->start[0]);
wdenka2663ea2003-12-07 18:32:37 +0000155 if ((rc = flash_erase (info, 0, i)) != 0) {
156 puts("ERROR ");
157 flash_perror(rc);
158 return (1);
159 }
wdenk1cb8e982003-03-06 21:55:29 +0000160
161#endif
wdenkd4ca31c2004-01-02 14:00:00 +0000162 printf("flash erased, programming from 0x%lx 0x%lx Bytes\n",
163 (ulong)src, size);
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200164 if ((rc = flash_write ((char *)src, start, size)) != 0) {
wdenka2663ea2003-12-07 18:32:37 +0000165 puts("ERROR ");
166 flash_perror(rc);
wdenkc6097192002-11-03 00:24:07 +0000167 return (1);
168 }
wdenka2663ea2003-12-07 18:32:37 +0000169 puts("OK programming done\n");
wdenkc6097192002-11-03 00:24:07 +0000170 return 0;
171}
172
173
wdenkd4ca31c2004-01-02 14:00:00 +0000174static int
wdenka2663ea2003-12-07 18:32:37 +0000175mpl_prg_image(uchar *ld_addr)
wdenkc6097192002-11-03 00:24:07 +0000176{
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100177 unsigned long len;
wdenka2663ea2003-12-07 18:32:37 +0000178 uchar *data;
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100179 image_header_t *hdr = (image_header_t *)ld_addr;
wdenka2663ea2003-12-07 18:32:37 +0000180 int rc;
wdenkd4ca31c2004-01-02 14:00:00 +0000181
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100182#if defined(CONFIG_FIT)
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100183 if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100184 puts ("Non legacy image format not supported\n");
185 return -1;
186 }
187#endif
188
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100189 if (!image_check_magic (hdr)) {
wdenka2663ea2003-12-07 18:32:37 +0000190 puts("Bad Magic Number\n");
wdenkc6097192002-11-03 00:24:07 +0000191 return 1;
192 }
Marian Balakowicz2242f532008-02-21 17:27:41 +0100193 image_print_contents (hdr);
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100194 if (!image_check_os (hdr, IH_OS_U_BOOT)) {
wdenka2663ea2003-12-07 18:32:37 +0000195 puts("No U-Boot Image\n");
wdenkc6097192002-11-03 00:24:07 +0000196 return 1;
197 }
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100198 if (!image_check_type (hdr, IH_TYPE_FIRMWARE)) {
wdenka2663ea2003-12-07 18:32:37 +0000199 puts("No Firmware Image\n");
wdenkc6097192002-11-03 00:24:07 +0000200 return 1;
201 }
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100202 if (!image_check_hcrc (hdr)) {
wdenka2663ea2003-12-07 18:32:37 +0000203 puts("Bad Header Checksum\n");
wdenkc6097192002-11-03 00:24:07 +0000204 return 1;
205 }
wdenka2663ea2003-12-07 18:32:37 +0000206 puts("Verifying Checksum ... ");
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100207 if (!image_check_dcrc (hdr)) {
wdenka2663ea2003-12-07 18:32:37 +0000208 puts("Bad Data CRC\n");
wdenkc6097192002-11-03 00:24:07 +0000209 return 1;
210 }
wdenka2663ea2003-12-07 18:32:37 +0000211 puts("OK\n");
212
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100213 data = (uchar *)image_get_data (hdr);
214 len = image_get_data_size (hdr);
215
216 if (image_get_comp (hdr) != IH_COMP_NONE) {
wdenka2663ea2003-12-07 18:32:37 +0000217 uchar *buf;
218 /* reserve space for uncompressed image */
219 if ((buf = malloc(IMAGE_SIZE)) == NULL) {
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200220 puts("Insufficient space for decompression\n");
wdenkc6097192002-11-03 00:24:07 +0000221 return 1;
222 }
wdenkd4ca31c2004-01-02 14:00:00 +0000223
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100224 switch (image_get_comp (hdr)) {
wdenka2663ea2003-12-07 18:32:37 +0000225 case IH_COMP_GZIP:
226 puts("Uncompressing (GZIP) ... ");
wdenkeedcd072004-09-08 22:03:11 +0000227 rc = gunzip ((void *)(buf), IMAGE_SIZE, data, &len);
wdenka2663ea2003-12-07 18:32:37 +0000228 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:
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100253 printf ("Unimplemented compression type %d\n",
254 image_get_comp (hdr));
wdenka2663ea2003-12-07 18:32:37 +0000255 free(buf);
256 return 1;
257 }
wdenkd4ca31c2004-01-02 14:00:00 +0000258
wdenka2663ea2003-12-07 18:32:37 +0000259 rc = mpl_prg(buf, len);
260 free(buf);
261 } else {
262 rc = mpl_prg(data, len);
wdenkc6097192002-11-03 00:24:07 +0000263 }
wdenkd4ca31c2004-01-02 14:00:00 +0000264
wdenka2663ea2003-12-07 18:32:37 +0000265 return(rc);
wdenkc6097192002-11-03 00:24:07 +0000266}
267
wdenkb6e4c402004-01-02 16:05:07 +0000268#if !defined(CONFIG_PATI)
wdenkc6097192002-11-03 00:24:07 +0000269void get_backup_values(backup_t *buf)
270{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200271 i2c_read(CONFIG_SYS_DEF_EEPROM_ADDR, I2C_BACKUP_ADDR,2,(void *)buf,sizeof(backup_t));
wdenkc6097192002-11-03 00:24:07 +0000272}
273
274void set_backup_values(int overwrite)
275{
276 backup_t back;
277 int i;
278
279 get_backup_values(&back);
280 if(!overwrite) {
281 if(strncmp(back.signature,"MPL\0",4)==0) {
wdenka2663ea2003-12-07 18:32:37 +0000282 puts("Not possible to write Backup\n");
wdenkc6097192002-11-03 00:24:07 +0000283 return;
284 }
285 }
286 memcpy(back.signature,"MPL\0",4);
wdenk1cb8e982003-03-06 21:55:29 +0000287 i = getenv_r("serial#",back.serial_name,16);
288 if(i < 0) {
wdenka2663ea2003-12-07 18:32:37 +0000289 puts("Not possible to write Backup\n");
wdenkc6097192002-11-03 00:24:07 +0000290 return;
291 }
292 back.serial_name[16]=0;
wdenk1cb8e982003-03-06 21:55:29 +0000293 i = getenv_r("ethaddr",back.eth_addr,20);
294 if(i < 0) {
wdenka2663ea2003-12-07 18:32:37 +0000295 puts("Not possible to write Backup\n");
wdenkc6097192002-11-03 00:24:07 +0000296 return;
297 }
298 back.eth_addr[20]=0;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200299 i2c_write(CONFIG_SYS_DEF_EEPROM_ADDR, I2C_BACKUP_ADDR,2,(void *)&back,sizeof(backup_t));
wdenkc6097192002-11-03 00:24:07 +0000300}
301
302void clear_env_values(void)
303{
304 backup_t back;
305 unsigned char env_crc[4];
306
307 memset(&back,0xff,sizeof(backup_t));
308 memset(env_crc,0x00,4);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200309 i2c_write(CONFIG_SYS_DEF_EEPROM_ADDR,I2C_BACKUP_ADDR,2,(void *)&back,sizeof(backup_t));
310 i2c_write(CONFIG_SYS_DEF_EEPROM_ADDR,CONFIG_ENV_OFFSET,2,(void *)env_crc,4);
wdenkc6097192002-11-03 00:24:07 +0000311}
312
313/*
314 * check crc of "older" environment
315 */
316int check_env_old_size(ulong oldsize)
317{
318 ulong crc, len, new;
319 unsigned off;
320 uchar buf[64];
321
322 /* read old CRC */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200323 eeprom_read (CONFIG_SYS_DEF_EEPROM_ADDR,
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200324 CONFIG_ENV_OFFSET,
wdenkc6097192002-11-03 00:24:07 +0000325 (uchar *)&crc, sizeof(ulong));
326
327 new = 0;
328 len = oldsize;
329 off = sizeof(long);
330 len = oldsize-off;
331 while (len > 0) {
332 int n = (len > sizeof(buf)) ? sizeof(buf) : len;
333
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200334 eeprom_read (CONFIG_SYS_DEF_EEPROM_ADDR, CONFIG_ENV_OFFSET+off, buf, n);
wdenkc6097192002-11-03 00:24:07 +0000335 new = crc32 (new, buf, n);
336 len -= n;
337 off += n;
338 }
339
340 return (crc == new);
341}
342
343static ulong oldsizes[] = {
344 0x200,
345 0x800,
346 0
347};
348
349void copy_old_env(ulong size)
350{
351 uchar name_buf[64];
352 uchar value_buf[0x800];
353 uchar c;
354 ulong len;
355 unsigned off;
356 uchar *name, *value;
357
Wolfgang Denkd0ff51b2008-07-14 15:19:07 +0200358 name = &name_buf[0];
359 value = &value_buf[0];
wdenkc6097192002-11-03 00:24:07 +0000360 len=size;
361 off = sizeof(long);
362 while (len > off) {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200363 eeprom_read (CONFIG_SYS_DEF_EEPROM_ADDR, CONFIG_ENV_OFFSET+off, &c, 1);
wdenkc6097192002-11-03 00:24:07 +0000364 if(c != '=') {
365 *name++=c;
366 off++;
367 }
368 else {
369 *name++='\0';
370 off++;
371 do {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200372 eeprom_read (CONFIG_SYS_DEF_EEPROM_ADDR, CONFIG_ENV_OFFSET+off, &c, 1);
wdenkc6097192002-11-03 00:24:07 +0000373 *value++=c;
374 off++;
375 if(c == '\0')
376 break;
377 } while(len > off);
Wolfgang Denkd0ff51b2008-07-14 15:19:07 +0200378 name = &name_buf[0];
379 value = &value_buf[0];
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200380 if(strncmp((char *)name,"baudrate",8)!=0) {
381 setenv((char *)name,(char *)value);
wdenkc6097192002-11-03 00:24:07 +0000382 }
383
384 }
385 }
386}
387
388
389void check_env(void)
390{
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200391 char *s;
wdenkc6097192002-11-03 00:24:07 +0000392 int i=0;
393 char buf[32];
394 backup_t back;
395
396 s=getenv("serial#");
397 if(!s) {
398 while(oldsizes[i]) {
399 if(check_env_old_size(oldsizes[i]))
400 break;
401 i++;
402 }
403 if(!oldsizes[i]) {
404 /* no old environment has been found */
405 get_backup_values (&back);
406 if (strncmp (back.signature, "MPL\0", 4) == 0) {
407 sprintf (buf, "%s", back.serial_name);
408 setenv ("serial#", buf);
409 sprintf (buf, "%s", back.eth_addr);
410 setenv ("ethaddr", buf);
411 printf ("INFO: serial# and ethaddr recovered, use saveenv\n");
412 return;
413 }
414 }
415 else {
416 copy_old_env(oldsizes[i]);
wdenka2663ea2003-12-07 18:32:37 +0000417 puts("INFO: old environment ajusted, use saveenv\n");
wdenkc6097192002-11-03 00:24:07 +0000418 }
419 }
420 else {
421 /* check if back up is set */
422 get_backup_values(&back);
423 if(strncmp(back.signature,"MPL\0",4)!=0) {
424 set_backup_values(0);
425 }
426 }
427}
428
wdenkb6e4c402004-01-02 16:05:07 +0000429#endif /* #if !defined(CONFIG_PATI) */
wdenkc6097192002-11-03 00:24:07 +0000430
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200431int do_mplcommon(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenkc6097192002-11-03 00:24:07 +0000432{
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200433 ulong size,src,ld_addr;
wdenkc6097192002-11-03 00:24:07 +0000434 int result;
wdenkb6e4c402004-01-02 16:05:07 +0000435#if !defined(CONFIG_PATI)
wdenkc6097192002-11-03 00:24:07 +0000436 backup_t back;
wdenkc6097192002-11-03 00:24:07 +0000437 src = MULTI_PURPOSE_SOCKET_ADDR;
438 size = IMAGE_SIZE;
wdenkb6e4c402004-01-02 16:05:07 +0000439#endif
wdenkc6097192002-11-03 00:24:07 +0000440
441 if (strcmp(argv[1], "flash") == 0)
442 {
Jon Loeliger3fe00102007-07-09 18:38:39 -0500443#if defined(CONFIG_CMD_FDC)
wdenkc6097192002-11-03 00:24:07 +0000444 if (strcmp(argv[2], "floppy") == 0) {
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200445 char *local_args[3];
wdenkc6097192002-11-03 00:24:07 +0000446 extern int do_fdcboot (cmd_tbl_t *, int, int, char *[]);
wdenka2663ea2003-12-07 18:32:37 +0000447 puts("\nupdating bootloader image from floppy\n");
wdenkc6097192002-11-03 00:24:07 +0000448 local_args[0] = argv[0];
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200449 if(argc==4) {
wdenkc6097192002-11-03 00:24:07 +0000450 local_args[1] = argv[3];
451 local_args[2] = NULL;
452 ld_addr=simple_strtoul(argv[3], NULL, 16);
453 result=do_fdcboot(cmdtp, 0, 2, local_args);
454 }
455 else {
456 local_args[1] = NULL;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200457 ld_addr=CONFIG_SYS_LOAD_ADDR;
wdenkc6097192002-11-03 00:24:07 +0000458 result=do_fdcboot(cmdtp, 0, 1, local_args);
459 }
wdenkd4ca31c2004-01-02 14:00:00 +0000460 result=mpl_prg_image((uchar *)ld_addr);
wdenkc6097192002-11-03 00:24:07 +0000461 return result;
462 }
Jon Loeliger3fe00102007-07-09 18:38:39 -0500463#endif
wdenkc6097192002-11-03 00:24:07 +0000464 if (strcmp(argv[2], "mem") == 0) {
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200465 if(argc==4) {
wdenkc6097192002-11-03 00:24:07 +0000466 ld_addr=simple_strtoul(argv[3], NULL, 16);
467 }
468 else {
469 ld_addr=load_addr;
470 }
471 printf ("\nupdating bootloader image from memory at %lX\n",ld_addr);
wdenka2663ea2003-12-07 18:32:37 +0000472 result=mpl_prg_image((uchar *)ld_addr);
wdenkc6097192002-11-03 00:24:07 +0000473 return result;
474 }
wdenkb6e4c402004-01-02 16:05:07 +0000475#if !defined(CONFIG_PATI)
wdenkc6097192002-11-03 00:24:07 +0000476 if (strcmp(argv[2], "mps") == 0) {
wdenka2663ea2003-12-07 18:32:37 +0000477 puts("\nupdating bootloader image from MPS\n");
478 result=mpl_prg((uchar *)src,size);
wdenkc6097192002-11-03 00:24:07 +0000479 return result;
480 }
wdenkb6e4c402004-01-02 16:05:07 +0000481#endif /* #if !defined(CONFIG_PATI) */
wdenkc6097192002-11-03 00:24:07 +0000482 }
483 if (strcmp(argv[1], "mem") == 0)
484 {
485 result=0;
486 if(argc==3)
487 {
488 result = (int)simple_strtol(argv[2], NULL, 16);
489 }
490 src=(unsigned long)&result;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200491 src-=CONFIG_SYS_MEMTEST_START;
wdenkc6097192002-11-03 00:24:07 +0000492 src-=(100*1024); /* - 100k */
493 src&=0xfff00000;
494 size=0;
495 do {
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200496 size++;
wdenkc6097192002-11-03 00:24:07 +0000497 printf("\n\nPass %ld\n",size);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200498 mem_test(CONFIG_SYS_MEMTEST_START,src,1);
wdenkc6097192002-11-03 00:24:07 +0000499 if(ctrlc())
500 break;
501 if(result>0)
502 result--;
503
504 }while(result);
505 return 0;
506 }
wdenkb6e4c402004-01-02 16:05:07 +0000507#if !defined(CONFIG_PATI)
wdenkc6097192002-11-03 00:24:07 +0000508 if (strcmp(argv[1], "clearenvvalues") == 0)
509 {
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200510 if (strcmp(argv[2], "yes") == 0)
wdenkc6097192002-11-03 00:24:07 +0000511 {
512 clear_env_values();
513 return 0;
514 }
515 }
516 if (strcmp(argv[1], "getback") == 0) {
517 get_backup_values(&back);
518 back.signature[3]=0;
519 back.serial_name[16]=0;
520 back.eth_addr[20]=0;
521 printf("GetBackUp: signature: %s\n",back.signature);
522 printf(" serial#: %s\n",back.serial_name);
523 printf(" ethaddr: %s\n",back.eth_addr);
524 return 0;
525 }
526 if (strcmp(argv[1], "setback") == 0) {
527 set_backup_values(1);
528 return 0;
529 }
wdenkb6e4c402004-01-02 16:05:07 +0000530#endif
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200531 return cmd_usage(cmdtp);
wdenkc6097192002-11-03 00:24:07 +0000532}
533
534
Jon Loeliger3fe00102007-07-09 18:38:39 -0500535#if defined(CONFIG_CMD_DOC)
wdenkc6097192002-11-03 00:24:07 +0000536void doc_init (void)
537{
538 doc_probe(MULTI_PURPOSE_SOCKET_ADDR);
539}
540#endif
541
542
543#ifdef CONFIG_VIDEO
544/******************************************************
545 * Routines to display the Board information
546 * to the screen (since the VGA will be initialized as last,
547 * we must resend the infos)
548 */
549
550#ifdef CONFIG_CONSOLE_EXTRA_INFO
551extern GraphicDevice ctfb;
wdenk7205e402003-09-10 22:30:53 +0000552extern int get_boot_mode(void);
wdenkc6097192002-11-03 00:24:07 +0000553
554void video_get_info_str (int line_number, char *info)
555{
556 /* init video info strings for graphic console */
Stefan Roese087dfdb2007-10-21 08:12:41 +0200557 PPC4xx_SYS_INFO sys_info;
wdenkc6097192002-11-03 00:24:07 +0000558 char rev;
wdenk33149b82003-05-23 11:38:58 +0000559 int i,boot;
wdenkc6097192002-11-03 00:24:07 +0000560 unsigned long pvr;
561 char buf[64];
Wolfgang Denk08ef89e2008-10-19 02:35:49 +0200562 char buf1[32], buf2[32], buf3[32], buf4[32];
wdenk33149b82003-05-23 11:38:58 +0000563 char cpustr[16];
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200564 char *s, *e, bc;
wdenkc6097192002-11-03 00:24:07 +0000565 switch (line_number)
566 {
567 case 2:
568 /* CPU and board infos */
569 pvr=get_pvr();
570 get_sys_info (&sys_info);
571 switch (pvr) {
572 case PVR_405GP_RB: rev='B'; break;
573 case PVR_405GP_RC: rev='C'; break;
574 case PVR_405GP_RD: rev='D'; break;
575 case PVR_405GP_RE: rev='E'; break;
wdenk33149b82003-05-23 11:38:58 +0000576 case PVR_405GPR_RB: rev='B'; break;
wdenkc6097192002-11-03 00:24:07 +0000577 default: rev='?'; break;
578 }
wdenk33149b82003-05-23 11:38:58 +0000579 if(pvr==PVR_405GPR_RB)
580 sprintf(cpustr,"PPC405GPr %c",rev);
581 else
582 sprintf(cpustr,"PPC405GP %c",rev);
wdenkc6097192002-11-03 00:24:07 +0000583 /* Board info */
584 i=0;
585 s=getenv ("serial#");
586#ifdef CONFIG_PIP405
587 if (!s || strncmp (s, "PIP405", 6)) {
588 sprintf(buf,"### No HW ID - assuming PIP405");
589 }
590#endif
591#ifdef CONFIG_MIP405
592 if (!s || strncmp (s, "MIP405", 6)) {
593 sprintf(buf,"### No HW ID - assuming MIP405");
594 }
595#endif
596 else {
597 for (e = s; *e; ++e) {
598 if (*e == ' ')
599 break;
600 }
601 for (; s < e; ++s) {
602 if (*s == '_') {
603 ++s;
604 break;
605 }
Wolfgang Denkd0ff51b2008-07-14 15:19:07 +0200606 buf[i++] = *s;
wdenkc6097192002-11-03 00:24:07 +0000607 }
608 sprintf(&buf[i]," SN ");
609 i+=4;
610 for (; s < e; ++s) {
Wolfgang Denkd0ff51b2008-07-14 15:19:07 +0200611 buf[i++] = *s;
wdenkc6097192002-11-03 00:24:07 +0000612 }
613 buf[i++]=0;
614 }
Wolfgang Denk08ef89e2008-10-19 02:35:49 +0200615 sprintf (info," %s %s %s MHz (%s/%s/%s MHz)",
wdenk33149b82003-05-23 11:38:58 +0000616 buf, cpustr,
Wolfgang Denk08ef89e2008-10-19 02:35:49 +0200617 strmhz (buf1, gd->cpu_clk),
618 strmhz (buf2, sys_info.freqPLB),
619 strmhz (buf3, sys_info.freqPLB / sys_info.pllOpbDiv),
620 strmhz (buf4, sys_info.freqPLB / sys_info.pllExtBusDiv));
wdenkc6097192002-11-03 00:24:07 +0000621 return;
622 case 3:
623 /* Memory Info */
wdenk33149b82003-05-23 11:38:58 +0000624 boot = get_boot_mode();
wdenkc6097192002-11-03 00:24:07 +0000625 bc = in8 (CONFIG_PORT_ADDR);
626 sprintf(info, " %luMB RAM, %luMB Flash Cfg 0x%02X %s %s",
627 gd->bd->bi_memsize / 0x100000,
628 gd->bd->bi_flashsize / 0x100000,
629 bc,
wdenk33149b82003-05-23 11:38:58 +0000630 (boot & BOOT_MPS) ? "MPS boot" : "Flash boot",
wdenkc6097192002-11-03 00:24:07 +0000631 ctfb.modeIdent);
632 return;
633 case 1:
634 sprintf (buf, "%s",CONFIG_IDENT_STRING);
635 sprintf (info, " %s", &buf[1]);
636 return;
637 }
638 /* no more info lines */
639 *info = 0;
640 return;
641}
642#endif /* CONFIG_CONSOLE_EXTRA_INFO */
643
644#endif /* CONFIG_VIDEO */