blob: 31636b30ee511d5dd042bef3110ed5f101316df9 [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 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenkc6097192002-11-03 00:24:07 +00006 */
7
8#include <common.h>
9#include <command.h>
10#include <video_fb.h>
11#include "common_util.h"
12#include <asm/processor.h>
wdenk1fe2c702003-03-06 21:55:29 +000013#include <asm/byteorder.h>
wdenkc6097192002-11-03 00:24:07 +000014#include <i2c.h>
wdenkc6097192002-11-03 00:24:07 +000015#include <pci.h>
wdenk4ea537d2003-12-07 18:32:37 +000016#include <malloc.h>
17#include <bzlib.h>
Simon Glass88ecb9b2016-10-17 20:12:54 -060018#include <video.h>
wdenkc6097192002-11-03 00:24:07 +000019
wdenk7d076412003-05-23 11:38:58 +000020#ifdef CONFIG_PIP405
21#include "../pip405/pip405.h"
Stefan Roeseca8725f2007-10-03 15:01:02 +020022#include <asm/4xx_pci.h>
wdenk7d076412003-05-23 11:38:58 +000023#endif
Tom Rini45ae6732016-09-19 21:55:34 -040024#if defined(CONFIG_TARGET_MIP405) || defined(CONFIG_TARGET_MIP405T)
wdenk7d076412003-05-23 11:38:58 +000025#include "../mip405/mip405.h"
Stefan Roeseca8725f2007-10-03 15:01:02 +020026#include <asm/4xx_pci.h>
wdenk7d076412003-05-23 11:38:58 +000027#endif
Wolfgang Denk6405a152006-03-31 18:32:53 +020028
29DECLARE_GLOBAL_DATA_PTR;
30
wdenk4ea537d2003-12-07 18:32:37 +000031extern int mem_test(ulong start, ulong ramsize, int quiet);
wdenkc6097192002-11-03 00:24:07 +000032
wdenk4ea537d2003-12-07 18:32:37 +000033#define I2C_BACKUP_ADDR 0x7C00 /* 0x200 bytes for backup */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020034#define IMAGE_SIZE CONFIG_SYS_MONITOR_LEN /* ugly, but it works for now */
wdenkc6097192002-11-03 00:24:07 +000035
Tom Rini45ae6732016-09-19 21:55:34 -040036#if defined(CONFIG_PIP405) || defined(CONFIG_TARGET_MIP405) \
37 || defined(CONFIG_TARGET_MIP405T)
David Müllerb4a931e2011-12-22 13:38:19 +010038/*-----------------------------------------------------------------------
39 * On PIP/MIP405 we have 3 (4) possible boot mode
40 *
41 * - Boot from Flash (Flash CS = CS0, MPS CS = CS1)
42 * - Boot from MPS (Flash CS = CS1, MPS CS = CS0)
43 * - Boot from PCI with Flash map (Flash CS = CS0, MPS CS = CS1)
44 * - Boot from PCI with MPS map (Flash CS = CS1, MPS CS = CS0)
45 * The flash init is the first board specific routine which is called
46 * after code relocation (running from SDRAM)
47 * The first thing we do is to map the Flash CS to the Flash area and
48 * the MPS CS to the MPS area. Since the flash size is unknown at this
49 * point, we use the max flash size and the lowest flash address as base.
50 *
51 * After flash detection we adjust the size of the CS area accordingly.
52 * update_flash_size() will fix in wrong values in the flash_info structure,
53 * misc_init_r() will fix the values in the board info structure
54 */
55int get_boot_mode(void)
56{
57 unsigned long pbcr;
58 int res = 0;
59 pbcr = mfdcr(CPC0_PSR);
60 if ((pbcr & PSR_ROM_WIDTH_MASK) == 0)
61 /* boot via MPS or MPS mapping */
62 res = BOOT_MPS;
63 if (pbcr & PSR_ROM_LOC)
64 /* boot via PCI.. */
65 res |= BOOT_PCI;
66 return res;
67}
68
69/* Map the flash high (in boot area)
70 This code can only be executed from SDRAM (after relocation).
71*/
72void setup_cs_reloc(void)
73{
74 int mode;
75 /*
76 * since we are relocated, we can set-up the CS finaly
77 * but first of all, switch off PCI mapping (in case it
78 * was a PCI boot)
79 */
80 out32r(PMM0MA, 0L);
81 /* get boot mode */
82 mode = get_boot_mode();
83 /*
84 * we map the flash high in every case
85 * first find out to which CS the flash is attached to
86 */
87 if (mode & BOOT_MPS) {
88 /* map flash high on CS1 and MPS on CS0 */
89 mtdcr(EBC0_CFGADDR, PB0AP);
90 mtdcr(EBC0_CFGDATA, MPS_AP);
91 mtdcr(EBC0_CFGADDR, PB0CR);
92 mtdcr(EBC0_CFGDATA, MPS_CR);
93 /*
94 * we use the default values (max values) for the flash
95 * because its real size is not yet known
96 */
97 mtdcr(EBC0_CFGADDR, PB1AP);
98 mtdcr(EBC0_CFGDATA, FLASH_AP);
99 mtdcr(EBC0_CFGADDR, PB1CR);
100 mtdcr(EBC0_CFGDATA, FLASH_CR_B);
101 } else {
102 /* map flash high on CS0 and MPS on CS1 */
103 mtdcr(EBC0_CFGADDR, PB1AP);
104 mtdcr(EBC0_CFGDATA, MPS_AP);
105 mtdcr(EBC0_CFGADDR, PB1CR);
106 mtdcr(EBC0_CFGDATA, MPS_CR);
107 /*
108 * we use the default values (max values) for the flash
109 * because its real size is not yet known
110 */
111 mtdcr(EBC0_CFGADDR, PB0AP);
112 mtdcr(EBC0_CFGDATA, FLASH_AP);
113 mtdcr(EBC0_CFGADDR, PB0CR);
114 mtdcr(EBC0_CFGDATA, FLASH_CR_B);
115 }
116}
Tom Rini45ae6732016-09-19 21:55:34 -0400117#endif /* #if defined(CONFIG_PIP405) || defined(CONFIG_TARGET_MIP405) */
David Müllerb4a931e2011-12-22 13:38:19 +0100118
119#ifdef CONFIG_SYS_UPDATE_FLASH_SIZE
120/* adjust flash start and protection info */
121int update_flash_size(int flash_size)
122{
123 int i = 0, mode;
124 flash_info_t *info = &flash_info[0];
125 unsigned long flashcr;
126 unsigned long flash_base = (0 - flash_size) & 0xFFF00000;
127
128 if (flash_size > 128*1024*1024) {
129 printf("\n ### ERROR, wrong flash size: %X, reset board ###\n",
130 flash_size);
131 hang();
132 }
133
134 if ((flash_size >> 20) != 0)
135 i = __ilog2(flash_size >> 20);
136
137 /* set up flash CS according to the size */
138 mode = get_boot_mode();
139 if (mode & BOOT_MPS) {
140 /* flash is on CS1 */
141 mtdcr(EBC0_CFGADDR, PB1CR);
142 flashcr = mfdcr(EBC0_CFGDATA);
143 /* we map the flash high in every case */
144 flashcr &= 0x0001FFFF; /* mask out address bits */
145 flashcr |= flash_base; /* start addr */
146 flashcr |= (i << 17); /* size addr */
147 mtdcr(EBC0_CFGADDR, PB1CR);
148 mtdcr(EBC0_CFGDATA, flashcr);
149 } else {
150 /* flash is on CS0 */
151 mtdcr(EBC0_CFGADDR, PB0CR);
152 flashcr = mfdcr(EBC0_CFGDATA);
153 /* we map the flash high in every case */
154 flashcr &= 0x0001FFFF; /* mask out address bits */
155 flashcr |= flash_base; /* start addr */
156 flashcr |= (i << 17); /* size addr */
157 mtdcr(EBC0_CFGADDR, PB0CR);
158 mtdcr(EBC0_CFGDATA, flashcr);
159 }
160
161 for (i = 0; i < info->sector_count; i++)
162 /* adjust sector start address */
163 info->start[i] = flash_base +
164 (info->start[i] - CONFIG_SYS_FLASH_BASE);
165
166 /* unprotect all sectors */
167 flash_protect(FLAG_PROTECT_CLEAR,
168 info->start[0],
169 0xFFFFFFFF,
170 info);
171 flash_protect_default();
172 /* protect reset vector too*/
173 flash_protect(FLAG_PROTECT_SET,
174 info->start[info->sector_count-1],
175 0xFFFFFFFF,
176 info);
177
178 return 0;
179}
180#endif
wdenkc6097192002-11-03 00:24:07 +0000181
wdenk1ebf41e2004-01-02 14:00:00 +0000182static int
wdenk4ea537d2003-12-07 18:32:37 +0000183mpl_prg(uchar *src, ulong size)
wdenkc6097192002-11-03 00:24:07 +0000184{
wdenk4ea537d2003-12-07 18:32:37 +0000185 ulong start;
David Müllerb4a931e2011-12-22 13:38:19 +0100186 flash_info_t *info = &flash_info[0];
wdenk4ea537d2003-12-07 18:32:37 +0000187 int i, rc;
Heiko Schocherd4def9b2017-06-07 17:33:11 +0200188#if defined(CONFIG_PIP405) || defined(CONFIG_TARGET_MIP405) || \
189 defined(CONFIG_TARGET_MIP405T)
wdenke39c2842003-06-04 15:05:30 +0000190 char *copystr = (char *)src;
wdenk4ea537d2003-12-07 18:32:37 +0000191 ulong *magic = (ulong *)src;
wdenkc6097192002-11-03 00:24:07 +0000192
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100193 if (uimage_to_cpu (magic[0]) != IH_MAGIC) {
wdenk4ea537d2003-12-07 18:32:37 +0000194 puts("Bad Magic number\n");
wdenk1fe2c702003-03-06 21:55:29 +0000195 return -1;
196 }
wdenke39c2842003-06-04 15:05:30 +0000197 /* some more checks before we delete the Flash... */
198 /* Checking the ISO_STRING prevents to program a
199 * wrong Firmware Image into the flash.
200 */
wdenk4ea537d2003-12-07 18:32:37 +0000201 i = 4; /* skip Magic number */
202 while (1) {
203 if (strncmp(&copystr[i], "MEV-", 4) == 0)
wdenke39c2842003-06-04 15:05:30 +0000204 break;
wdenk4ea537d2003-12-07 18:32:37 +0000205 if (i++ >= 0x100) {
206 puts("Firmware Image for unknown Target\n");
wdenke39c2842003-06-04 15:05:30 +0000207 return -1;
208 }
209 }
210 /* we have the ISO STRING, check */
wdenk4ea537d2003-12-07 18:32:37 +0000211 if (strncmp(&copystr[i], CONFIG_ISO_STRING, sizeof(CONFIG_ISO_STRING)-1) != 0) {
212 printf("Wrong Firmware Image: %s\n", &copystr[i]);
wdenke39c2842003-06-04 15:05:30 +0000213 return -1;
214 }
215 start = 0 - size;
David Müllerb4a931e2011-12-22 13:38:19 +0100216
217 /* unprotect sectors used by u-boot */
218 flash_protect(FLAG_PROTECT_CLEAR,
219 start,
220 0xFFFFFFFF,
221 info);
222
223 /* search start sector */
224 for (i = info->sector_count-1; i > 0; i--)
wdenk4ea537d2003-12-07 18:32:37 +0000225 if (start >= info->start[i])
226 break;
David Müllerb4a931e2011-12-22 13:38:19 +0100227
wdenkc6097192002-11-03 00:24:07 +0000228 /* now erase flash */
wdenkc6097192002-11-03 00:24:07 +0000229 printf("Erasing at %lx (sector %d) (start %lx)\n",
230 start,i,info->start[i]);
wdenk4ea537d2003-12-07 18:32:37 +0000231 if ((rc = flash_erase (info, i, info->sector_count-1)) != 0) {
232 puts("ERROR ");
233 flash_perror(rc);
234 return (1);
235 }
wdenk1fe2c702003-03-06 21:55:29 +0000236#endif
wdenk1ebf41e2004-01-02 14:00:00 +0000237 printf("flash erased, programming from 0x%lx 0x%lx Bytes\n",
238 (ulong)src, size);
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200239 if ((rc = flash_write ((char *)src, start, size)) != 0) {
wdenk4ea537d2003-12-07 18:32:37 +0000240 puts("ERROR ");
241 flash_perror(rc);
wdenkc6097192002-11-03 00:24:07 +0000242 return (1);
243 }
wdenk4ea537d2003-12-07 18:32:37 +0000244 puts("OK programming done\n");
wdenkc6097192002-11-03 00:24:07 +0000245 return 0;
246}
247
248
wdenk1ebf41e2004-01-02 14:00:00 +0000249static int
wdenk4ea537d2003-12-07 18:32:37 +0000250mpl_prg_image(uchar *ld_addr)
wdenkc6097192002-11-03 00:24:07 +0000251{
Marian Balakowicz41d71ed2008-01-08 18:14:09 +0100252 unsigned long len;
wdenk4ea537d2003-12-07 18:32:37 +0000253 uchar *data;
Marian Balakowicz41d71ed2008-01-08 18:14:09 +0100254 image_header_t *hdr = (image_header_t *)ld_addr;
wdenk4ea537d2003-12-07 18:32:37 +0000255 int rc;
wdenk1ebf41e2004-01-02 14:00:00 +0000256
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100257#if defined(CONFIG_FIT)
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100258 if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) {
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100259 puts ("Non legacy image format not supported\n");
260 return -1;
261 }
262#endif
263
Marian Balakowicz41d71ed2008-01-08 18:14:09 +0100264 if (!image_check_magic (hdr)) {
wdenk4ea537d2003-12-07 18:32:37 +0000265 puts("Bad Magic Number\n");
wdenkc6097192002-11-03 00:24:07 +0000266 return 1;
267 }
Marian Balakowicza1cc1472008-02-21 17:27:41 +0100268 image_print_contents (hdr);
Marian Balakowicz41d71ed2008-01-08 18:14:09 +0100269 if (!image_check_os (hdr, IH_OS_U_BOOT)) {
wdenk4ea537d2003-12-07 18:32:37 +0000270 puts("No U-Boot Image\n");
wdenkc6097192002-11-03 00:24:07 +0000271 return 1;
272 }
Marian Balakowicz41d71ed2008-01-08 18:14:09 +0100273 if (!image_check_type (hdr, IH_TYPE_FIRMWARE)) {
wdenk4ea537d2003-12-07 18:32:37 +0000274 puts("No Firmware Image\n");
wdenkc6097192002-11-03 00:24:07 +0000275 return 1;
276 }
Marian Balakowicz41d71ed2008-01-08 18:14:09 +0100277 if (!image_check_hcrc (hdr)) {
wdenk4ea537d2003-12-07 18:32:37 +0000278 puts("Bad Header Checksum\n");
wdenkc6097192002-11-03 00:24:07 +0000279 return 1;
280 }
wdenk4ea537d2003-12-07 18:32:37 +0000281 puts("Verifying Checksum ... ");
Marian Balakowicz41d71ed2008-01-08 18:14:09 +0100282 if (!image_check_dcrc (hdr)) {
wdenk4ea537d2003-12-07 18:32:37 +0000283 puts("Bad Data CRC\n");
wdenkc6097192002-11-03 00:24:07 +0000284 return 1;
285 }
wdenk4ea537d2003-12-07 18:32:37 +0000286 puts("OK\n");
287
Marian Balakowicz41d71ed2008-01-08 18:14:09 +0100288 data = (uchar *)image_get_data (hdr);
289 len = image_get_data_size (hdr);
290
291 if (image_get_comp (hdr) != IH_COMP_NONE) {
wdenk4ea537d2003-12-07 18:32:37 +0000292 uchar *buf;
293 /* reserve space for uncompressed image */
294 if ((buf = malloc(IMAGE_SIZE)) == NULL) {
Wolfgang Denka1be4762008-05-20 16:00:29 +0200295 puts("Insufficient space for decompression\n");
wdenkc6097192002-11-03 00:24:07 +0000296 return 1;
297 }
wdenk1ebf41e2004-01-02 14:00:00 +0000298
Marian Balakowicz41d71ed2008-01-08 18:14:09 +0100299 switch (image_get_comp (hdr)) {
wdenk4ea537d2003-12-07 18:32:37 +0000300 case IH_COMP_GZIP:
301 puts("Uncompressing (GZIP) ... ");
wdenka0ebde52004-09-08 22:03:11 +0000302 rc = gunzip ((void *)(buf), IMAGE_SIZE, data, &len);
wdenk4ea537d2003-12-07 18:32:37 +0000303 if (rc != 0) {
304 puts("GUNZIP ERROR\n");
305 free(buf);
306 return 1;
307 }
308 puts("OK\n");
309 break;
wdenkc35ba4e2004-03-14 22:25:36 +0000310#ifdef CONFIG_BZIP2
wdenk4ea537d2003-12-07 18:32:37 +0000311 case IH_COMP_BZIP2:
312 puts("Uncompressing (BZIP2) ... ");
313 {
314 uint retlen = IMAGE_SIZE;
315 rc = BZ2_bzBuffToBuffDecompress ((char *)(buf), &retlen,
316 (char *)data, len, 0, 0);
317 len = retlen;
318 }
319 if (rc != BZ_OK) {
320 printf ("BUNZIP2 ERROR: %d\n", rc);
321 free(buf);
322 return 1;
323 }
324 puts("OK\n");
325 break;
326#endif
327 default:
Marian Balakowicz41d71ed2008-01-08 18:14:09 +0100328 printf ("Unimplemented compression type %d\n",
329 image_get_comp (hdr));
wdenk4ea537d2003-12-07 18:32:37 +0000330 free(buf);
331 return 1;
332 }
wdenk1ebf41e2004-01-02 14:00:00 +0000333
wdenk4ea537d2003-12-07 18:32:37 +0000334 rc = mpl_prg(buf, len);
335 free(buf);
336 } else {
337 rc = mpl_prg(data, len);
wdenkc6097192002-11-03 00:24:07 +0000338 }
wdenk1ebf41e2004-01-02 14:00:00 +0000339
wdenk4ea537d2003-12-07 18:32:37 +0000340 return(rc);
wdenkc6097192002-11-03 00:24:07 +0000341}
342
wdenkc6097192002-11-03 00:24:07 +0000343void get_backup_values(backup_t *buf)
344{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200345 i2c_read(CONFIG_SYS_DEF_EEPROM_ADDR, I2C_BACKUP_ADDR,2,(void *)buf,sizeof(backup_t));
wdenkc6097192002-11-03 00:24:07 +0000346}
347
348void set_backup_values(int overwrite)
349{
350 backup_t back;
351 int i;
352
353 get_backup_values(&back);
354 if(!overwrite) {
355 if(strncmp(back.signature,"MPL\0",4)==0) {
wdenk4ea537d2003-12-07 18:32:37 +0000356 puts("Not possible to write Backup\n");
wdenkc6097192002-11-03 00:24:07 +0000357 return;
358 }
359 }
360 memcpy(back.signature,"MPL\0",4);
Wolfgang Denk76af2782010-07-24 21:55:43 +0200361 i = getenv_f("serial#",back.serial_name,16);
wdenk1fe2c702003-03-06 21:55:29 +0000362 if(i < 0) {
wdenk4ea537d2003-12-07 18:32:37 +0000363 puts("Not possible to write Backup\n");
wdenkc6097192002-11-03 00:24:07 +0000364 return;
365 }
366 back.serial_name[16]=0;
Wolfgang Denk76af2782010-07-24 21:55:43 +0200367 i = getenv_f("ethaddr",back.eth_addr,20);
wdenk1fe2c702003-03-06 21:55:29 +0000368 if(i < 0) {
wdenk4ea537d2003-12-07 18:32:37 +0000369 puts("Not possible to write Backup\n");
wdenkc6097192002-11-03 00:24:07 +0000370 return;
371 }
372 back.eth_addr[20]=0;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200373 i2c_write(CONFIG_SYS_DEF_EEPROM_ADDR, I2C_BACKUP_ADDR,2,(void *)&back,sizeof(backup_t));
wdenkc6097192002-11-03 00:24:07 +0000374}
375
376void clear_env_values(void)
377{
378 backup_t back;
379 unsigned char env_crc[4];
380
381 memset(&back,0xff,sizeof(backup_t));
382 memset(env_crc,0x00,4);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200383 i2c_write(CONFIG_SYS_DEF_EEPROM_ADDR,I2C_BACKUP_ADDR,2,(void *)&back,sizeof(backup_t));
384 i2c_write(CONFIG_SYS_DEF_EEPROM_ADDR,CONFIG_ENV_OFFSET,2,(void *)env_crc,4);
wdenkc6097192002-11-03 00:24:07 +0000385}
386
387/*
388 * check crc of "older" environment
389 */
390int check_env_old_size(ulong oldsize)
391{
392 ulong crc, len, new;
393 unsigned off;
394 uchar buf[64];
395
396 /* read old CRC */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200397 eeprom_read (CONFIG_SYS_DEF_EEPROM_ADDR,
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200398 CONFIG_ENV_OFFSET,
wdenkc6097192002-11-03 00:24:07 +0000399 (uchar *)&crc, sizeof(ulong));
400
401 new = 0;
402 len = oldsize;
403 off = sizeof(long);
404 len = oldsize-off;
405 while (len > 0) {
406 int n = (len > sizeof(buf)) ? sizeof(buf) : len;
407
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200408 eeprom_read (CONFIG_SYS_DEF_EEPROM_ADDR, CONFIG_ENV_OFFSET+off, buf, n);
wdenkc6097192002-11-03 00:24:07 +0000409 new = crc32 (new, buf, n);
410 len -= n;
411 off += n;
412 }
413
414 return (crc == new);
415}
416
417static ulong oldsizes[] = {
418 0x200,
419 0x800,
420 0
421};
422
423void copy_old_env(ulong size)
424{
425 uchar name_buf[64];
426 uchar value_buf[0x800];
427 uchar c;
428 ulong len;
429 unsigned off;
430 uchar *name, *value;
431
Wolfgang Denkdc770c72008-07-14 15:19:07 +0200432 name = &name_buf[0];
433 value = &value_buf[0];
wdenkc6097192002-11-03 00:24:07 +0000434 len=size;
435 off = sizeof(long);
436 while (len > off) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200437 eeprom_read (CONFIG_SYS_DEF_EEPROM_ADDR, CONFIG_ENV_OFFSET+off, &c, 1);
wdenkc6097192002-11-03 00:24:07 +0000438 if(c != '=') {
439 *name++=c;
440 off++;
441 }
442 else {
443 *name++='\0';
444 off++;
445 do {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200446 eeprom_read (CONFIG_SYS_DEF_EEPROM_ADDR, CONFIG_ENV_OFFSET+off, &c, 1);
wdenkc6097192002-11-03 00:24:07 +0000447 *value++=c;
448 off++;
449 if(c == '\0')
450 break;
451 } while(len > off);
Wolfgang Denkdc770c72008-07-14 15:19:07 +0200452 name = &name_buf[0];
453 value = &value_buf[0];
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200454 if(strncmp((char *)name,"baudrate",8)!=0) {
455 setenv((char *)name,(char *)value);
wdenkc6097192002-11-03 00:24:07 +0000456 }
457
458 }
459 }
460}
461
462
463void check_env(void)
464{
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200465 char *s;
wdenkc6097192002-11-03 00:24:07 +0000466 int i=0;
467 char buf[32];
468 backup_t back;
469
470 s=getenv("serial#");
471 if(!s) {
472 while(oldsizes[i]) {
473 if(check_env_old_size(oldsizes[i]))
474 break;
475 i++;
476 }
477 if(!oldsizes[i]) {
478 /* no old environment has been found */
479 get_backup_values (&back);
480 if (strncmp (back.signature, "MPL\0", 4) == 0) {
481 sprintf (buf, "%s", back.serial_name);
482 setenv ("serial#", buf);
483 sprintf (buf, "%s", back.eth_addr);
484 setenv ("ethaddr", buf);
485 printf ("INFO: serial# and ethaddr recovered, use saveenv\n");
486 return;
487 }
488 }
489 else {
490 copy_old_env(oldsizes[i]);
wdenk4ea537d2003-12-07 18:32:37 +0000491 puts("INFO: old environment ajusted, use saveenv\n");
wdenkc6097192002-11-03 00:24:07 +0000492 }
493 }
494 else {
495 /* check if back up is set */
496 get_backup_values(&back);
497 if(strncmp(back.signature,"MPL\0",4)!=0) {
498 set_backup_values(0);
499 }
500 }
501}
502
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200503int do_mplcommon(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenkc6097192002-11-03 00:24:07 +0000504{
Peter Tysere9b1b492010-10-05 23:48:47 -0500505 ulong ld_addr;
wdenkc6097192002-11-03 00:24:07 +0000506 int result;
Peter Tysere9b1b492010-10-05 23:48:47 -0500507 ulong size = IMAGE_SIZE;
508 ulong src = MULTI_PURPOSE_SOCKET_ADDR;
wdenkc6097192002-11-03 00:24:07 +0000509 backup_t back;
wdenkc6097192002-11-03 00:24:07 +0000510
511 if (strcmp(argv[1], "flash") == 0)
512 {
Jon Loeliger145318c2007-07-09 18:38:39 -0500513#if defined(CONFIG_CMD_FDC)
wdenkc6097192002-11-03 00:24:07 +0000514 if (strcmp(argv[2], "floppy") == 0) {
Wolfgang Denka1be4762008-05-20 16:00:29 +0200515 char *local_args[3];
wdenkc6097192002-11-03 00:24:07 +0000516 extern int do_fdcboot (cmd_tbl_t *, int, int, char *[]);
wdenk4ea537d2003-12-07 18:32:37 +0000517 puts("\nupdating bootloader image from floppy\n");
wdenkc6097192002-11-03 00:24:07 +0000518 local_args[0] = argv[0];
Wolfgang Denka1be4762008-05-20 16:00:29 +0200519 if(argc==4) {
wdenkc6097192002-11-03 00:24:07 +0000520 local_args[1] = argv[3];
521 local_args[2] = NULL;
522 ld_addr=simple_strtoul(argv[3], NULL, 16);
523 result=do_fdcboot(cmdtp, 0, 2, local_args);
524 }
525 else {
526 local_args[1] = NULL;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200527 ld_addr=CONFIG_SYS_LOAD_ADDR;
wdenkc6097192002-11-03 00:24:07 +0000528 result=do_fdcboot(cmdtp, 0, 1, local_args);
529 }
wdenk1ebf41e2004-01-02 14:00:00 +0000530 result=mpl_prg_image((uchar *)ld_addr);
wdenkc6097192002-11-03 00:24:07 +0000531 return result;
532 }
Jon Loeliger145318c2007-07-09 18:38:39 -0500533#endif
wdenkc6097192002-11-03 00:24:07 +0000534 if (strcmp(argv[2], "mem") == 0) {
Wolfgang Denka1be4762008-05-20 16:00:29 +0200535 if(argc==4) {
wdenkc6097192002-11-03 00:24:07 +0000536 ld_addr=simple_strtoul(argv[3], NULL, 16);
537 }
538 else {
539 ld_addr=load_addr;
540 }
541 printf ("\nupdating bootloader image from memory at %lX\n",ld_addr);
wdenk4ea537d2003-12-07 18:32:37 +0000542 result=mpl_prg_image((uchar *)ld_addr);
wdenkc6097192002-11-03 00:24:07 +0000543 return result;
544 }
545 if (strcmp(argv[2], "mps") == 0) {
wdenk4ea537d2003-12-07 18:32:37 +0000546 puts("\nupdating bootloader image from MPS\n");
547 result=mpl_prg((uchar *)src,size);
wdenkc6097192002-11-03 00:24:07 +0000548 return result;
549 }
wdenkc6097192002-11-03 00:24:07 +0000550 }
wdenkc6097192002-11-03 00:24:07 +0000551 if (strcmp(argv[1], "clearenvvalues") == 0)
552 {
Wolfgang Denka1be4762008-05-20 16:00:29 +0200553 if (strcmp(argv[2], "yes") == 0)
wdenkc6097192002-11-03 00:24:07 +0000554 {
555 clear_env_values();
556 return 0;
557 }
558 }
559 if (strcmp(argv[1], "getback") == 0) {
560 get_backup_values(&back);
561 back.signature[3]=0;
562 back.serial_name[16]=0;
563 back.eth_addr[20]=0;
564 printf("GetBackUp: signature: %s\n",back.signature);
565 printf(" serial#: %s\n",back.serial_name);
566 printf(" ethaddr: %s\n",back.eth_addr);
567 return 0;
568 }
569 if (strcmp(argv[1], "setback") == 0) {
570 set_backup_values(1);
571 return 0;
572 }
Wolfgang Denk3b683112010-07-17 01:06:04 +0200573 return cmd_usage(cmdtp);
wdenkc6097192002-11-03 00:24:07 +0000574}
575
wdenkc6097192002-11-03 00:24:07 +0000576#ifdef CONFIG_VIDEO
577/******************************************************
578 * Routines to display the Board information
579 * to the screen (since the VGA will be initialized as last,
580 * we must resend the infos)
581 */
582
583#ifdef CONFIG_CONSOLE_EXTRA_INFO
584extern GraphicDevice ctfb;
wdenk2c9b05d2003-09-10 22:30:53 +0000585extern int get_boot_mode(void);
wdenkc6097192002-11-03 00:24:07 +0000586
587void video_get_info_str (int line_number, char *info)
588{
589 /* init video info strings for graphic console */
Stefan Roeseedd73f22007-10-21 08:12:41 +0200590 PPC4xx_SYS_INFO sys_info;
wdenkc6097192002-11-03 00:24:07 +0000591 char rev;
wdenk7d076412003-05-23 11:38:58 +0000592 int i,boot;
wdenkc6097192002-11-03 00:24:07 +0000593 unsigned long pvr;
594 char buf[64];
Wolfgang Denk20591042008-10-19 02:35:49 +0200595 char buf1[32], buf2[32], buf3[32], buf4[32];
wdenk7d076412003-05-23 11:38:58 +0000596 char cpustr[16];
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200597 char *s, *e, bc;
wdenkc6097192002-11-03 00:24:07 +0000598 switch (line_number)
599 {
600 case 2:
601 /* CPU and board infos */
602 pvr=get_pvr();
603 get_sys_info (&sys_info);
604 switch (pvr) {
605 case PVR_405GP_RB: rev='B'; break;
606 case PVR_405GP_RC: rev='C'; break;
607 case PVR_405GP_RD: rev='D'; break;
608 case PVR_405GP_RE: rev='E'; break;
wdenk7d076412003-05-23 11:38:58 +0000609 case PVR_405GPR_RB: rev='B'; break;
wdenkc6097192002-11-03 00:24:07 +0000610 default: rev='?'; break;
611 }
wdenk7d076412003-05-23 11:38:58 +0000612 if(pvr==PVR_405GPR_RB)
613 sprintf(cpustr,"PPC405GPr %c",rev);
614 else
615 sprintf(cpustr,"PPC405GP %c",rev);
wdenkc6097192002-11-03 00:24:07 +0000616 /* Board info */
617 i=0;
618 s=getenv ("serial#");
619#ifdef CONFIG_PIP405
620 if (!s || strncmp (s, "PIP405", 6)) {
Ben Whitten34fd6c92015-12-30 13:05:58 +0000621 strcpy(buf,"### No HW ID - assuming PIP405");
wdenkc6097192002-11-03 00:24:07 +0000622 }
623#endif
Tom Rini45ae6732016-09-19 21:55:34 -0400624#if defined(CONFIG_TARGET_MIP405) || defined(CONFIG_TARGET_MIP405T)
wdenkc6097192002-11-03 00:24:07 +0000625 if (!s || strncmp (s, "MIP405", 6)) {
Ben Whitten34fd6c92015-12-30 13:05:58 +0000626 strcpy(buf,"### No HW ID - assuming MIP405");
wdenkc6097192002-11-03 00:24:07 +0000627 }
628#endif
629 else {
630 for (e = s; *e; ++e) {
631 if (*e == ' ')
632 break;
633 }
634 for (; s < e; ++s) {
635 if (*s == '_') {
636 ++s;
637 break;
638 }
Wolfgang Denkdc770c72008-07-14 15:19:07 +0200639 buf[i++] = *s;
wdenkc6097192002-11-03 00:24:07 +0000640 }
Ben Whitten34fd6c92015-12-30 13:05:58 +0000641 strcpy(&buf[i]," SN ");
wdenkc6097192002-11-03 00:24:07 +0000642 i+=4;
643 for (; s < e; ++s) {
Wolfgang Denkdc770c72008-07-14 15:19:07 +0200644 buf[i++] = *s;
wdenkc6097192002-11-03 00:24:07 +0000645 }
646 buf[i++]=0;
647 }
Wolfgang Denk20591042008-10-19 02:35:49 +0200648 sprintf (info," %s %s %s MHz (%s/%s/%s MHz)",
wdenk7d076412003-05-23 11:38:58 +0000649 buf, cpustr,
Wolfgang Denk20591042008-10-19 02:35:49 +0200650 strmhz (buf1, gd->cpu_clk),
651 strmhz (buf2, sys_info.freqPLB),
652 strmhz (buf3, sys_info.freqPLB / sys_info.pllOpbDiv),
653 strmhz (buf4, sys_info.freqPLB / sys_info.pllExtBusDiv));
wdenkc6097192002-11-03 00:24:07 +0000654 return;
655 case 3:
656 /* Memory Info */
wdenk7d076412003-05-23 11:38:58 +0000657 boot = get_boot_mode();
wdenkc6097192002-11-03 00:24:07 +0000658 bc = in8 (CONFIG_PORT_ADDR);
659 sprintf(info, " %luMB RAM, %luMB Flash Cfg 0x%02X %s %s",
660 gd->bd->bi_memsize / 0x100000,
661 gd->bd->bi_flashsize / 0x100000,
662 bc,
wdenk7d076412003-05-23 11:38:58 +0000663 (boot & BOOT_MPS) ? "MPS boot" : "Flash boot",
wdenkc6097192002-11-03 00:24:07 +0000664 ctfb.modeIdent);
665 return;
666 case 1:
Ben Whitten34fd6c92015-12-30 13:05:58 +0000667 strcpy(buf, CONFIG_IDENT_STRING);
wdenkc6097192002-11-03 00:24:07 +0000668 sprintf (info, " %s", &buf[1]);
669 return;
670 }
671 /* no more info lines */
672 *info = 0;
673 return;
674}
675#endif /* CONFIG_CONSOLE_EXTRA_INFO */
676
677#endif /* CONFIG_VIDEO */