3 * Denis Peter, MPL AG Switzerland, d.peter@mpl.ch
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
28 #include "common_util.h"
29 #include <asm/processor.h>
30 #include <asm/byteorder.h>
37 #include "../pip405/pip405.h"
38 #include <asm/4xx_pci.h>
41 #include "../mip405/mip405.h"
42 #include <asm/4xx_pci.h>
45 DECLARE_GLOBAL_DATA_PTR
;
47 #if defined(CONFIG_PATI)
48 #define FIRM_START 0xFFF00000
51 extern int mem_test(ulong start
, ulong ramsize
, int quiet
);
53 #define I2C_BACKUP_ADDR 0x7C00 /* 0x200 bytes for backup */
54 #define IMAGE_SIZE CONFIG_SYS_MONITOR_LEN /* ugly, but it works for now */
56 extern flash_info_t flash_info
[]; /* info for FLASH chips */
59 mpl_prg(uchar
*src
, ulong size
)
64 #if defined(CONFIG_PATI)
67 #if defined(CONFIG_PIP405) || defined(CONFIG_MIP405) || defined(CONFIG_PATI)
68 char *copystr
= (char *)src
;
69 ulong
*magic
= (ulong
*)src
;
72 info
= &flash_info
[0];
74 #if defined(CONFIG_PIP405) || defined(CONFIG_MIP405) || defined(CONFIG_PATI)
75 if (uimage_to_cpu (magic
[0]) != IH_MAGIC
) {
76 puts("Bad Magic number\n");
79 /* some more checks before we delete the Flash... */
80 /* Checking the ISO_STRING prevents to program a
81 * wrong Firmware Image into the flash.
83 i
= 4; /* skip Magic number */
85 if (strncmp(©str
[i
], "MEV-", 4) == 0)
88 puts("Firmware Image for unknown Target\n");
92 /* we have the ISO STRING, check */
93 if (strncmp(©str
[i
], CONFIG_ISO_STRING
, sizeof(CONFIG_ISO_STRING
)-1) != 0) {
94 printf("Wrong Firmware Image: %s\n", ©str
[i
]);
97 #if !defined(CONFIG_PATI)
99 for (i
= info
->sector_count
-1; i
> 0; i
--) {
100 info
->protect
[i
] = 0; /* unprotect this sector */
101 if (start
>= info
->start
[i
])
104 /* set-up flash location */
105 /* now erase flash */
106 printf("Erasing at %lx (sector %d) (start %lx)\n",
107 start
,i
,info
->start
[i
]);
108 if ((rc
= flash_erase (info
, i
, info
->sector_count
-1)) != 0) {
114 #else /* #if !defined(CONFIG_PATI */
117 for (i
= 0; i
< info
->sector_count
; i
++) {
118 if (start
< info
->start
[i
]) {
124 info
->protect
[i
- 1] = 0; /* unprotect this sector */
125 for (; i
< info
->sector_count
; i
++) {
126 if ((start
+ size
) < info
->start
[i
])
128 info
->protect
[i
] = 0; /* unprotect this sector */
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) {
142 #endif /* defined(CONFIG_PATI) */
144 #elif defined(CONFIG_VCMA9)
146 for (i
= 0; i
<info
->sector_count
; i
++) {
147 info
->protect
[i
] = 0; /* unprotect this sector */
148 if (size
< info
->start
[i
])
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]);
155 if ((rc
= flash_erase (info
, 0, i
)) != 0) {
162 printf("flash erased, programming from 0x%lx 0x%lx Bytes\n",
164 if ((rc
= flash_write ((char *)src
, start
, size
)) != 0) {
169 puts("OK programming done\n");
175 mpl_prg_image(uchar
*ld_addr
)
179 image_header_t
*hdr
= (image_header_t
*)ld_addr
;
182 #if defined(CONFIG_FIT)
183 if (genimg_get_format ((void *)hdr
) != IMAGE_FORMAT_LEGACY
) {
184 puts ("Non legacy image format not supported\n");
189 if (!image_check_magic (hdr
)) {
190 puts("Bad Magic Number\n");
193 image_print_contents (hdr
);
194 if (!image_check_os (hdr
, IH_OS_U_BOOT
)) {
195 puts("No U-Boot Image\n");
198 if (!image_check_type (hdr
, IH_TYPE_FIRMWARE
)) {
199 puts("No Firmware Image\n");
202 if (!image_check_hcrc (hdr
)) {
203 puts("Bad Header Checksum\n");
206 puts("Verifying Checksum ... ");
207 if (!image_check_dcrc (hdr
)) {
208 puts("Bad Data CRC\n");
213 data
= (uchar
*)image_get_data (hdr
);
214 len
= image_get_data_size (hdr
);
216 if (image_get_comp (hdr
) != IH_COMP_NONE
) {
218 /* reserve space for uncompressed image */
219 if ((buf
= malloc(IMAGE_SIZE
)) == NULL
) {
220 puts("Insufficient space for decompression\n");
224 switch (image_get_comp (hdr
)) {
226 puts("Uncompressing (GZIP) ... ");
227 rc
= gunzip ((void *)(buf
), IMAGE_SIZE
, data
, &len
);
229 puts("GUNZIP ERROR\n");
237 puts("Uncompressing (BZIP2) ... ");
239 uint retlen
= IMAGE_SIZE
;
240 rc
= BZ2_bzBuffToBuffDecompress ((char *)(buf
), &retlen
,
241 (char *)data
, len
, 0, 0);
245 printf ("BUNZIP2 ERROR: %d\n", rc
);
253 printf ("Unimplemented compression type %d\n",
254 image_get_comp (hdr
));
259 rc
= mpl_prg(buf
, len
);
262 rc
= mpl_prg(data
, len
);
268 #if !defined(CONFIG_PATI)
269 void get_backup_values(backup_t
*buf
)
271 i2c_read(CONFIG_SYS_DEF_EEPROM_ADDR
, I2C_BACKUP_ADDR
,2,(void *)buf
,sizeof(backup_t
));
274 void set_backup_values(int overwrite
)
279 get_backup_values(&back
);
281 if(strncmp(back
.signature
,"MPL\0",4)==0) {
282 puts("Not possible to write Backup\n");
286 memcpy(back
.signature
,"MPL\0",4);
287 i
= getenv_r("serial#",back
.serial_name
,16);
289 puts("Not possible to write Backup\n");
292 back
.serial_name
[16]=0;
293 i
= getenv_r("ethaddr",back
.eth_addr
,20);
295 puts("Not possible to write Backup\n");
299 i2c_write(CONFIG_SYS_DEF_EEPROM_ADDR
, I2C_BACKUP_ADDR
,2,(void *)&back
,sizeof(backup_t
));
302 void clear_env_values(void)
305 unsigned char env_crc
[4];
307 memset(&back
,0xff,sizeof(backup_t
));
308 memset(env_crc
,0x00,4);
309 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);
314 * check crc of "older" environment
316 int check_env_old_size(ulong oldsize
)
323 eeprom_read (CONFIG_SYS_DEF_EEPROM_ADDR
,
325 (uchar
*)&crc
, sizeof(ulong
));
332 int n
= (len
> sizeof(buf
)) ? sizeof(buf
) : len
;
334 eeprom_read (CONFIG_SYS_DEF_EEPROM_ADDR
, CONFIG_ENV_OFFSET
+off
, buf
, n
);
335 new = crc32 (new, buf
, n
);
343 static ulong oldsizes
[] = {
349 void copy_old_env(ulong size
)
352 uchar value_buf
[0x800];
359 value
= &value_buf
[0];
363 eeprom_read (CONFIG_SYS_DEF_EEPROM_ADDR
, CONFIG_ENV_OFFSET
+off
, &c
, 1);
372 eeprom_read (CONFIG_SYS_DEF_EEPROM_ADDR
, CONFIG_ENV_OFFSET
+off
, &c
, 1);
379 value
= &value_buf
[0];
380 if(strncmp((char *)name
,"baudrate",8)!=0) {
381 setenv((char *)name
,(char *)value
);
399 if(check_env_old_size(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");
416 copy_old_env(oldsizes
[i
]);
417 puts("INFO: old environment ajusted, use saveenv\n");
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);
429 #endif /* #if !defined(CONFIG_PATI) */
431 int do_mplcommon(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
433 ulong size
,src
,ld_addr
;
435 #if !defined(CONFIG_PATI)
437 src
= MULTI_PURPOSE_SOCKET_ADDR
;
441 if (strcmp(argv
[1], "flash") == 0)
443 #if defined(CONFIG_CMD_FDC)
444 if (strcmp(argv
[2], "floppy") == 0) {
446 extern int do_fdcboot (cmd_tbl_t
*, int, int, char *[]);
447 puts("\nupdating bootloader image from floppy\n");
448 local_args
[0] = argv
[0];
450 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
);
456 local_args
[1] = NULL
;
457 ld_addr
=CONFIG_SYS_LOAD_ADDR
;
458 result
=do_fdcboot(cmdtp
, 0, 1, local_args
);
460 result
=mpl_prg_image((uchar
*)ld_addr
);
464 if (strcmp(argv
[2], "mem") == 0) {
466 ld_addr
=simple_strtoul(argv
[3], NULL
, 16);
471 printf ("\nupdating bootloader image from memory at %lX\n",ld_addr
);
472 result
=mpl_prg_image((uchar
*)ld_addr
);
475 #if !defined(CONFIG_PATI)
476 if (strcmp(argv
[2], "mps") == 0) {
477 puts("\nupdating bootloader image from MPS\n");
478 result
=mpl_prg((uchar
*)src
,size
);
481 #endif /* #if !defined(CONFIG_PATI) */
483 if (strcmp(argv
[1], "mem") == 0)
488 result
= (int)simple_strtol(argv
[2], NULL
, 16);
490 src
=(unsigned long)&result
;
491 src
-=CONFIG_SYS_MEMTEST_START
;
492 src
-=(100*1024); /* - 100k */
497 printf("\n\nPass %ld\n",size
);
498 mem_test(CONFIG_SYS_MEMTEST_START
,src
,1);
507 #if !defined(CONFIG_PATI)
508 if (strcmp(argv
[1], "clearenvvalues") == 0)
510 if (strcmp(argv
[2], "yes") == 0)
516 if (strcmp(argv
[1], "getback") == 0) {
517 get_backup_values(&back
);
519 back
.serial_name
[16]=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
);
526 if (strcmp(argv
[1], "setback") == 0) {
527 set_backup_values(1);
536 #if defined(CONFIG_CMD_DOC)
539 doc_probe(MULTI_PURPOSE_SOCKET_ADDR
);
545 /******************************************************
546 * Routines to display the Board information
547 * to the screen (since the VGA will be initialized as last,
548 * we must resend the infos)
551 #ifdef CONFIG_CONSOLE_EXTRA_INFO
552 extern GraphicDevice ctfb
;
553 extern int get_boot_mode(void);
555 void video_get_info_str (int line_number
, char *info
)
557 /* init video info strings for graphic console */
558 PPC4xx_SYS_INFO sys_info
;
563 char buf1
[32], buf2
[32], buf3
[32], buf4
[32];
569 /* CPU and board infos */
571 get_sys_info (&sys_info
);
573 case PVR_405GP_RB
: rev
='B'; break;
574 case PVR_405GP_RC
: rev
='C'; break;
575 case PVR_405GP_RD
: rev
='D'; break;
576 case PVR_405GP_RE
: rev
='E'; break;
577 case PVR_405GPR_RB
: rev
='B'; break;
578 default: rev
='?'; break;
580 if(pvr
==PVR_405GPR_RB
)
581 sprintf(cpustr
,"PPC405GPr %c",rev
);
583 sprintf(cpustr
,"PPC405GP %c",rev
);
586 s
=getenv ("serial#");
588 if (!s
|| strncmp (s
, "PIP405", 6)) {
589 sprintf(buf
,"### No HW ID - assuming PIP405");
593 if (!s
|| strncmp (s
, "MIP405", 6)) {
594 sprintf(buf
,"### No HW ID - assuming MIP405");
598 for (e
= s
; *e
; ++e
) {
609 sprintf(&buf
[i
]," SN ");
616 sprintf (info
," %s %s %s MHz (%s/%s/%s MHz)",
618 strmhz (buf1
, gd
->cpu_clk
),
619 strmhz (buf2
, sys_info
.freqPLB
),
620 strmhz (buf3
, sys_info
.freqPLB
/ sys_info
.pllOpbDiv
),
621 strmhz (buf4
, sys_info
.freqPLB
/ sys_info
.pllExtBusDiv
));
625 boot
= get_boot_mode();
626 bc
= in8 (CONFIG_PORT_ADDR
);
627 sprintf(info
, " %luMB RAM, %luMB Flash Cfg 0x%02X %s %s",
628 gd
->bd
->bi_memsize
/ 0x100000,
629 gd
->bd
->bi_flashsize
/ 0x100000,
631 (boot
& BOOT_MPS
) ? "MPS boot" : "Flash boot",
635 sprintf (buf
, "%s",CONFIG_IDENT_STRING
);
636 sprintf (info
, " %s", &buf
[1]);
639 /* no more info lines */
643 #endif /* CONFIG_CONSOLE_EXTRA_INFO */
645 #endif /* CONFIG_VIDEO */