2002-11-03 00:24:07 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2001
|
|
|
|
* Denis Peter, MPL AG Switzerland, d.peter@mpl.ch
|
|
|
|
*
|
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
|
|
|
#include <video_fb.h>
|
|
|
|
#include "common_util.h"
|
|
|
|
#include <asm/processor.h>
|
2003-03-06 21:55:29 +00:00
|
|
|
#include <asm/byteorder.h>
|
2002-11-03 00:24:07 +00:00
|
|
|
#include <i2c.h>
|
|
|
|
#include <devices.h>
|
|
|
|
#include <pci.h>
|
2003-12-07 18:32:37 +00:00
|
|
|
#include <malloc.h>
|
|
|
|
#include <bzlib.h>
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2003-05-23 11:38:58 +00:00
|
|
|
#ifdef CONFIG_PIP405
|
|
|
|
#include "../pip405/pip405.h"
|
2007-10-03 13:01:02 +00:00
|
|
|
#include <asm/4xx_pci.h>
|
2003-05-23 11:38:58 +00:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_MIP405
|
|
|
|
#include "../mip405/mip405.h"
|
2007-10-03 13:01:02 +00:00
|
|
|
#include <asm/4xx_pci.h>
|
2003-05-23 11:38:58 +00:00
|
|
|
#endif
|
2006-03-31 16:32:53 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2004-01-02 16:05:07 +00:00
|
|
|
#if defined(CONFIG_PATI)
|
|
|
|
#define FIRM_START 0xFFF00000
|
|
|
|
#endif
|
2003-05-23 11:38:58 +00:00
|
|
|
|
2004-09-08 22:03:11 +00:00
|
|
|
extern int gunzip(void *, int, uchar *, unsigned long *);
|
2003-12-07 18:32:37 +00:00
|
|
|
extern int mem_test(ulong start, ulong ramsize, int quiet);
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2003-12-07 18:32:37 +00:00
|
|
|
#define I2C_BACKUP_ADDR 0x7C00 /* 0x200 bytes for backup */
|
2008-10-16 13:01:15 +00:00
|
|
|
#define IMAGE_SIZE CONFIG_SYS_MONITOR_LEN /* ugly, but it works for now */
|
2002-11-03 00:24:07 +00:00
|
|
|
|
|
|
|
extern flash_info_t flash_info[]; /* info for FLASH chips */
|
|
|
|
|
2004-01-02 14:00:00 +00:00
|
|
|
static int
|
2003-12-07 18:32:37 +00:00
|
|
|
mpl_prg(uchar *src, ulong size)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
2003-12-07 18:32:37 +00:00
|
|
|
ulong start;
|
2002-11-03 00:24:07 +00:00
|
|
|
flash_info_t *info;
|
2003-12-07 18:32:37 +00:00
|
|
|
int i, rc;
|
2004-01-02 16:05:07 +00:00
|
|
|
#if defined(CONFIG_PATI)
|
|
|
|
int start_sect;
|
|
|
|
#endif
|
|
|
|
#if defined(CONFIG_PIP405) || defined(CONFIG_MIP405) || defined(CONFIG_PATI)
|
2003-06-04 15:05:30 +00:00
|
|
|
char *copystr = (char *)src;
|
2003-12-07 18:32:37 +00:00
|
|
|
ulong *magic = (ulong *)src;
|
2003-03-14 20:47:52 +00:00
|
|
|
#endif
|
2002-11-03 00:24:07 +00:00
|
|
|
|
|
|
|
info = &flash_info[0];
|
2003-03-06 21:55:29 +00:00
|
|
|
|
2004-01-02 16:05:07 +00:00
|
|
|
#if defined(CONFIG_PIP405) || defined(CONFIG_MIP405) || defined(CONFIG_PATI)
|
2008-02-29 13:58:34 +00:00
|
|
|
if (uimage_to_cpu (magic[0]) != IH_MAGIC) {
|
2003-12-07 18:32:37 +00:00
|
|
|
puts("Bad Magic number\n");
|
2003-03-06 21:55:29 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2003-06-04 15:05:30 +00:00
|
|
|
/* some more checks before we delete the Flash... */
|
|
|
|
/* Checking the ISO_STRING prevents to program a
|
|
|
|
* wrong Firmware Image into the flash.
|
|
|
|
*/
|
2003-12-07 18:32:37 +00:00
|
|
|
i = 4; /* skip Magic number */
|
|
|
|
while (1) {
|
|
|
|
if (strncmp(©str[i], "MEV-", 4) == 0)
|
2003-06-04 15:05:30 +00:00
|
|
|
break;
|
2003-12-07 18:32:37 +00:00
|
|
|
if (i++ >= 0x100) {
|
|
|
|
puts("Firmware Image for unknown Target\n");
|
2003-06-04 15:05:30 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* we have the ISO STRING, check */
|
2003-12-07 18:32:37 +00:00
|
|
|
if (strncmp(©str[i], CONFIG_ISO_STRING, sizeof(CONFIG_ISO_STRING)-1) != 0) {
|
|
|
|
printf("Wrong Firmware Image: %s\n", ©str[i]);
|
2003-06-04 15:05:30 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2004-01-02 16:05:07 +00:00
|
|
|
#if !defined(CONFIG_PATI)
|
2003-06-04 15:05:30 +00:00
|
|
|
start = 0 - size;
|
2003-12-07 18:32:37 +00:00
|
|
|
for (i = info->sector_count-1; i > 0; i--) {
|
2002-11-03 00:24:07 +00:00
|
|
|
info->protect[i] = 0; /* unprotect this sector */
|
2003-12-07 18:32:37 +00:00
|
|
|
if (start >= info->start[i])
|
|
|
|
break;
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
/* set-up flash location */
|
|
|
|
/* now erase flash */
|
|
|
|
printf("Erasing at %lx (sector %d) (start %lx)\n",
|
|
|
|
start,i,info->start[i]);
|
2003-12-07 18:32:37 +00:00
|
|
|
if ((rc = flash_erase (info, i, info->sector_count-1)) != 0) {
|
|
|
|
puts("ERROR ");
|
|
|
|
flash_perror(rc);
|
|
|
|
return (1);
|
|
|
|
}
|
2003-03-06 21:55:29 +00:00
|
|
|
|
2004-01-02 16:05:07 +00:00
|
|
|
#else /* #if !defined(CONFIG_PATI */
|
|
|
|
start = FIRM_START;
|
|
|
|
start_sect = -1;
|
|
|
|
for (i = 0; i < info->sector_count; i++) {
|
|
|
|
if (start < info->start[i]) {
|
|
|
|
start_sect = i - 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
info->protect[i - 1] = 0; /* unprotect this sector */
|
|
|
|
for (; i < info->sector_count; i++) {
|
|
|
|
if ((start + size) < info->start[i])
|
|
|
|
break;
|
|
|
|
info->protect[i] = 0; /* unprotect this sector */
|
|
|
|
}
|
|
|
|
|
|
|
|
i--;
|
|
|
|
/* set-up flash location */
|
|
|
|
/* now erase flash */
|
|
|
|
printf ("Erasing at %lx to %lx (sector %d to %d) (%lx to %lx)\n",
|
|
|
|
start, start + size, start_sect, i,
|
|
|
|
info->start[start_sect], info->start[i]);
|
|
|
|
if ((rc = flash_erase (info, start_sect, i)) != 0) {
|
|
|
|
puts ("ERROR ");
|
|
|
|
flash_perror (rc);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
#endif /* defined(CONFIG_PATI) */
|
|
|
|
|
2003-03-06 21:55:29 +00:00
|
|
|
#elif defined(CONFIG_VCMA9)
|
|
|
|
start = 0;
|
2003-12-07 18:32:37 +00:00
|
|
|
for (i = 0; i <info->sector_count; i++) {
|
2003-03-06 21:55:29 +00:00
|
|
|
info->protect[i] = 0; /* unprotect this sector */
|
|
|
|
if (size < info->start[i])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* set-up flash location */
|
|
|
|
/* now erase flash */
|
|
|
|
printf("Erasing at %lx (sector %d) (start %lx)\n",
|
|
|
|
start,0,info->start[0]);
|
2003-12-07 18:32:37 +00:00
|
|
|
if ((rc = flash_erase (info, 0, i)) != 0) {
|
|
|
|
puts("ERROR ");
|
|
|
|
flash_perror(rc);
|
|
|
|
return (1);
|
|
|
|
}
|
2003-03-06 21:55:29 +00:00
|
|
|
|
|
|
|
#endif
|
2004-01-02 14:00:00 +00:00
|
|
|
printf("flash erased, programming from 0x%lx 0x%lx Bytes\n",
|
|
|
|
(ulong)src, size);
|
2005-10-13 14:45:02 +00:00
|
|
|
if ((rc = flash_write ((char *)src, start, size)) != 0) {
|
2003-12-07 18:32:37 +00:00
|
|
|
puts("ERROR ");
|
|
|
|
flash_perror(rc);
|
2002-11-03 00:24:07 +00:00
|
|
|
return (1);
|
|
|
|
}
|
2003-12-07 18:32:37 +00:00
|
|
|
puts("OK programming done\n");
|
2002-11-03 00:24:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-02 14:00:00 +00:00
|
|
|
static int
|
2003-12-07 18:32:37 +00:00
|
|
|
mpl_prg_image(uchar *ld_addr)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
2008-01-08 17:14:09 +00:00
|
|
|
unsigned long len;
|
2003-12-07 18:32:37 +00:00
|
|
|
uchar *data;
|
2008-01-08 17:14:09 +00:00
|
|
|
image_header_t *hdr = (image_header_t *)ld_addr;
|
2003-12-07 18:32:37 +00:00
|
|
|
int rc;
|
2004-01-02 14:00:00 +00:00
|
|
|
|
2008-02-04 07:28:09 +00:00
|
|
|
#if defined(CONFIG_FIT)
|
2008-02-29 13:58:34 +00:00
|
|
|
if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) {
|
2008-02-04 07:28:09 +00:00
|
|
|
puts ("Non legacy image format not supported\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-01-08 17:14:09 +00:00
|
|
|
if (!image_check_magic (hdr)) {
|
2003-12-07 18:32:37 +00:00
|
|
|
puts("Bad Magic Number\n");
|
2002-11-03 00:24:07 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2008-02-21 16:27:41 +00:00
|
|
|
image_print_contents (hdr);
|
2008-01-08 17:14:09 +00:00
|
|
|
if (!image_check_os (hdr, IH_OS_U_BOOT)) {
|
2003-12-07 18:32:37 +00:00
|
|
|
puts("No U-Boot Image\n");
|
2002-11-03 00:24:07 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2008-01-08 17:14:09 +00:00
|
|
|
if (!image_check_type (hdr, IH_TYPE_FIRMWARE)) {
|
2003-12-07 18:32:37 +00:00
|
|
|
puts("No Firmware Image\n");
|
2002-11-03 00:24:07 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2008-01-08 17:14:09 +00:00
|
|
|
if (!image_check_hcrc (hdr)) {
|
2003-12-07 18:32:37 +00:00
|
|
|
puts("Bad Header Checksum\n");
|
2002-11-03 00:24:07 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2003-12-07 18:32:37 +00:00
|
|
|
puts("Verifying Checksum ... ");
|
2008-01-08 17:14:09 +00:00
|
|
|
if (!image_check_dcrc (hdr)) {
|
2003-12-07 18:32:37 +00:00
|
|
|
puts("Bad Data CRC\n");
|
2002-11-03 00:24:07 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2003-12-07 18:32:37 +00:00
|
|
|
puts("OK\n");
|
|
|
|
|
2008-01-08 17:14:09 +00:00
|
|
|
data = (uchar *)image_get_data (hdr);
|
|
|
|
len = image_get_data_size (hdr);
|
|
|
|
|
|
|
|
if (image_get_comp (hdr) != IH_COMP_NONE) {
|
2003-12-07 18:32:37 +00:00
|
|
|
uchar *buf;
|
|
|
|
/* reserve space for uncompressed image */
|
|
|
|
if ((buf = malloc(IMAGE_SIZE)) == NULL) {
|
2008-05-20 14:00:29 +00:00
|
|
|
puts("Insufficient space for decompression\n");
|
2002-11-03 00:24:07 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2004-01-02 14:00:00 +00:00
|
|
|
|
2008-01-08 17:14:09 +00:00
|
|
|
switch (image_get_comp (hdr)) {
|
2003-12-07 18:32:37 +00:00
|
|
|
case IH_COMP_GZIP:
|
|
|
|
puts("Uncompressing (GZIP) ... ");
|
2004-09-08 22:03:11 +00:00
|
|
|
rc = gunzip ((void *)(buf), IMAGE_SIZE, data, &len);
|
2003-12-07 18:32:37 +00:00
|
|
|
if (rc != 0) {
|
|
|
|
puts("GUNZIP ERROR\n");
|
|
|
|
free(buf);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
puts("OK\n");
|
|
|
|
break;
|
2004-03-14 22:25:36 +00:00
|
|
|
#ifdef CONFIG_BZIP2
|
2003-12-07 18:32:37 +00:00
|
|
|
case IH_COMP_BZIP2:
|
|
|
|
puts("Uncompressing (BZIP2) ... ");
|
|
|
|
{
|
|
|
|
uint retlen = IMAGE_SIZE;
|
|
|
|
rc = BZ2_bzBuffToBuffDecompress ((char *)(buf), &retlen,
|
|
|
|
(char *)data, len, 0, 0);
|
|
|
|
len = retlen;
|
|
|
|
}
|
|
|
|
if (rc != BZ_OK) {
|
|
|
|
printf ("BUNZIP2 ERROR: %d\n", rc);
|
|
|
|
free(buf);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
puts("OK\n");
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
2008-01-08 17:14:09 +00:00
|
|
|
printf ("Unimplemented compression type %d\n",
|
|
|
|
image_get_comp (hdr));
|
2003-12-07 18:32:37 +00:00
|
|
|
free(buf);
|
|
|
|
return 1;
|
|
|
|
}
|
2004-01-02 14:00:00 +00:00
|
|
|
|
2003-12-07 18:32:37 +00:00
|
|
|
rc = mpl_prg(buf, len);
|
|
|
|
free(buf);
|
|
|
|
} else {
|
|
|
|
rc = mpl_prg(data, len);
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
2004-01-02 14:00:00 +00:00
|
|
|
|
2003-12-07 18:32:37 +00:00
|
|
|
return(rc);
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
2004-01-02 16:05:07 +00:00
|
|
|
#if !defined(CONFIG_PATI)
|
2002-11-03 00:24:07 +00:00
|
|
|
void get_backup_values(backup_t *buf)
|
|
|
|
{
|
2008-10-16 13:01:15 +00:00
|
|
|
i2c_read(CONFIG_SYS_DEF_EEPROM_ADDR, I2C_BACKUP_ADDR,2,(void *)buf,sizeof(backup_t));
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void set_backup_values(int overwrite)
|
|
|
|
{
|
|
|
|
backup_t back;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
get_backup_values(&back);
|
|
|
|
if(!overwrite) {
|
|
|
|
if(strncmp(back.signature,"MPL\0",4)==0) {
|
2003-12-07 18:32:37 +00:00
|
|
|
puts("Not possible to write Backup\n");
|
2002-11-03 00:24:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
memcpy(back.signature,"MPL\0",4);
|
2003-03-06 21:55:29 +00:00
|
|
|
i = getenv_r("serial#",back.serial_name,16);
|
|
|
|
if(i < 0) {
|
2003-12-07 18:32:37 +00:00
|
|
|
puts("Not possible to write Backup\n");
|
2002-11-03 00:24:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
back.serial_name[16]=0;
|
2003-03-06 21:55:29 +00:00
|
|
|
i = getenv_r("ethaddr",back.eth_addr,20);
|
|
|
|
if(i < 0) {
|
2003-12-07 18:32:37 +00:00
|
|
|
puts("Not possible to write Backup\n");
|
2002-11-03 00:24:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
back.eth_addr[20]=0;
|
2008-10-16 13:01:15 +00:00
|
|
|
i2c_write(CONFIG_SYS_DEF_EEPROM_ADDR, I2C_BACKUP_ADDR,2,(void *)&back,sizeof(backup_t));
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void clear_env_values(void)
|
|
|
|
{
|
|
|
|
backup_t back;
|
|
|
|
unsigned char env_crc[4];
|
|
|
|
|
|
|
|
memset(&back,0xff,sizeof(backup_t));
|
|
|
|
memset(env_crc,0x00,4);
|
2008-10-16 13:01:15 +00:00
|
|
|
i2c_write(CONFIG_SYS_DEF_EEPROM_ADDR,I2C_BACKUP_ADDR,2,(void *)&back,sizeof(backup_t));
|
|
|
|
i2c_write(CONFIG_SYS_DEF_EEPROM_ADDR,CONFIG_ENV_OFFSET,2,(void *)env_crc,4);
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check crc of "older" environment
|
|
|
|
*/
|
|
|
|
int check_env_old_size(ulong oldsize)
|
|
|
|
{
|
|
|
|
ulong crc, len, new;
|
|
|
|
unsigned off;
|
|
|
|
uchar buf[64];
|
|
|
|
|
|
|
|
/* read old CRC */
|
2008-10-16 13:01:15 +00:00
|
|
|
eeprom_read (CONFIG_SYS_DEF_EEPROM_ADDR,
|
2008-09-10 20:48:06 +00:00
|
|
|
CONFIG_ENV_OFFSET,
|
2002-11-03 00:24:07 +00:00
|
|
|
(uchar *)&crc, sizeof(ulong));
|
|
|
|
|
|
|
|
new = 0;
|
|
|
|
len = oldsize;
|
|
|
|
off = sizeof(long);
|
|
|
|
len = oldsize-off;
|
|
|
|
while (len > 0) {
|
|
|
|
int n = (len > sizeof(buf)) ? sizeof(buf) : len;
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
eeprom_read (CONFIG_SYS_DEF_EEPROM_ADDR, CONFIG_ENV_OFFSET+off, buf, n);
|
2002-11-03 00:24:07 +00:00
|
|
|
new = crc32 (new, buf, n);
|
|
|
|
len -= n;
|
|
|
|
off += n;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (crc == new);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ulong oldsizes[] = {
|
|
|
|
0x200,
|
|
|
|
0x800,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
void copy_old_env(ulong size)
|
|
|
|
{
|
|
|
|
uchar name_buf[64];
|
|
|
|
uchar value_buf[0x800];
|
|
|
|
uchar c;
|
|
|
|
ulong len;
|
|
|
|
unsigned off;
|
|
|
|
uchar *name, *value;
|
|
|
|
|
2008-07-14 13:19:07 +00:00
|
|
|
name = &name_buf[0];
|
|
|
|
value = &value_buf[0];
|
2002-11-03 00:24:07 +00:00
|
|
|
len=size;
|
|
|
|
off = sizeof(long);
|
|
|
|
while (len > off) {
|
2008-10-16 13:01:15 +00:00
|
|
|
eeprom_read (CONFIG_SYS_DEF_EEPROM_ADDR, CONFIG_ENV_OFFSET+off, &c, 1);
|
2002-11-03 00:24:07 +00:00
|
|
|
if(c != '=') {
|
|
|
|
*name++=c;
|
|
|
|
off++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*name++='\0';
|
|
|
|
off++;
|
|
|
|
do {
|
2008-10-16 13:01:15 +00:00
|
|
|
eeprom_read (CONFIG_SYS_DEF_EEPROM_ADDR, CONFIG_ENV_OFFSET+off, &c, 1);
|
2002-11-03 00:24:07 +00:00
|
|
|
*value++=c;
|
|
|
|
off++;
|
|
|
|
if(c == '\0')
|
|
|
|
break;
|
|
|
|
} while(len > off);
|
2008-07-14 13:19:07 +00:00
|
|
|
name = &name_buf[0];
|
|
|
|
value = &value_buf[0];
|
2005-10-13 14:45:02 +00:00
|
|
|
if(strncmp((char *)name,"baudrate",8)!=0) {
|
|
|
|
setenv((char *)name,(char *)value);
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void check_env(void)
|
|
|
|
{
|
2005-10-13 14:45:02 +00:00
|
|
|
char *s;
|
2002-11-03 00:24:07 +00:00
|
|
|
int i=0;
|
|
|
|
char buf[32];
|
|
|
|
backup_t back;
|
|
|
|
|
|
|
|
s=getenv("serial#");
|
|
|
|
if(!s) {
|
|
|
|
while(oldsizes[i]) {
|
|
|
|
if(check_env_old_size(oldsizes[i]))
|
|
|
|
break;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if(!oldsizes[i]) {
|
|
|
|
/* no old environment has been found */
|
|
|
|
get_backup_values (&back);
|
|
|
|
if (strncmp (back.signature, "MPL\0", 4) == 0) {
|
|
|
|
sprintf (buf, "%s", back.serial_name);
|
|
|
|
setenv ("serial#", buf);
|
|
|
|
sprintf (buf, "%s", back.eth_addr);
|
|
|
|
setenv ("ethaddr", buf);
|
|
|
|
printf ("INFO: serial# and ethaddr recovered, use saveenv\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
copy_old_env(oldsizes[i]);
|
2003-12-07 18:32:37 +00:00
|
|
|
puts("INFO: old environment ajusted, use saveenv\n");
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* check if back up is set */
|
|
|
|
get_backup_values(&back);
|
|
|
|
if(strncmp(back.signature,"MPL\0",4)!=0) {
|
|
|
|
set_backup_values(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern device_t *stdio_devices[];
|
|
|
|
extern char *stdio_names[];
|
|
|
|
|
|
|
|
void show_stdio_dev(void)
|
|
|
|
{
|
2003-03-06 13:39:27 +00:00
|
|
|
/* Print information */
|
2003-12-07 18:32:37 +00:00
|
|
|
puts("In: ");
|
2002-11-03 00:24:07 +00:00
|
|
|
if (stdio_devices[stdin] == NULL) {
|
2003-12-07 18:32:37 +00:00
|
|
|
puts("No input devices available!\n");
|
2002-11-03 00:24:07 +00:00
|
|
|
} else {
|
|
|
|
printf ("%s\n", stdio_devices[stdin]->name);
|
|
|
|
}
|
|
|
|
|
2003-12-07 18:32:37 +00:00
|
|
|
puts("Out: ");
|
2002-11-03 00:24:07 +00:00
|
|
|
if (stdio_devices[stdout] == NULL) {
|
2003-12-07 18:32:37 +00:00
|
|
|
puts("No output devices available!\n");
|
2002-11-03 00:24:07 +00:00
|
|
|
} else {
|
|
|
|
printf ("%s\n", stdio_devices[stdout]->name);
|
|
|
|
}
|
|
|
|
|
2003-12-07 18:32:37 +00:00
|
|
|
puts("Err: ");
|
2002-11-03 00:24:07 +00:00
|
|
|
if (stdio_devices[stderr] == NULL) {
|
2003-12-07 18:32:37 +00:00
|
|
|
puts("No error devices available!\n");
|
2002-11-03 00:24:07 +00:00
|
|
|
} else {
|
|
|
|
printf ("%s\n", stdio_devices[stderr]->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-02 16:05:07 +00:00
|
|
|
#endif /* #if !defined(CONFIG_PATI) */
|
2002-11-03 00:24:07 +00:00
|
|
|
|
|
|
|
int do_mplcommon(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
|
|
|
|
{
|
2008-05-20 14:00:29 +00:00
|
|
|
ulong size,src,ld_addr;
|
2002-11-03 00:24:07 +00:00
|
|
|
int result;
|
2004-01-02 16:05:07 +00:00
|
|
|
#if !defined(CONFIG_PATI)
|
2002-11-03 00:24:07 +00:00
|
|
|
backup_t back;
|
|
|
|
src = MULTI_PURPOSE_SOCKET_ADDR;
|
|
|
|
size = IMAGE_SIZE;
|
2004-01-02 16:05:07 +00:00
|
|
|
#endif
|
2002-11-03 00:24:07 +00:00
|
|
|
|
|
|
|
if (strcmp(argv[1], "flash") == 0)
|
|
|
|
{
|
2007-07-09 23:38:39 +00:00
|
|
|
#if defined(CONFIG_CMD_FDC)
|
2002-11-03 00:24:07 +00:00
|
|
|
if (strcmp(argv[2], "floppy") == 0) {
|
2008-05-20 14:00:29 +00:00
|
|
|
char *local_args[3];
|
2002-11-03 00:24:07 +00:00
|
|
|
extern int do_fdcboot (cmd_tbl_t *, int, int, char *[]);
|
2003-12-07 18:32:37 +00:00
|
|
|
puts("\nupdating bootloader image from floppy\n");
|
2002-11-03 00:24:07 +00:00
|
|
|
local_args[0] = argv[0];
|
2008-05-20 14:00:29 +00:00
|
|
|
if(argc==4) {
|
2002-11-03 00:24:07 +00:00
|
|
|
local_args[1] = argv[3];
|
|
|
|
local_args[2] = NULL;
|
|
|
|
ld_addr=simple_strtoul(argv[3], NULL, 16);
|
|
|
|
result=do_fdcboot(cmdtp, 0, 2, local_args);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
local_args[1] = NULL;
|
2008-10-16 13:01:15 +00:00
|
|
|
ld_addr=CONFIG_SYS_LOAD_ADDR;
|
2002-11-03 00:24:07 +00:00
|
|
|
result=do_fdcboot(cmdtp, 0, 1, local_args);
|
|
|
|
}
|
2004-01-02 14:00:00 +00:00
|
|
|
result=mpl_prg_image((uchar *)ld_addr);
|
2002-11-03 00:24:07 +00:00
|
|
|
return result;
|
|
|
|
}
|
2007-07-09 23:38:39 +00:00
|
|
|
#endif
|
2002-11-03 00:24:07 +00:00
|
|
|
if (strcmp(argv[2], "mem") == 0) {
|
2008-05-20 14:00:29 +00:00
|
|
|
if(argc==4) {
|
2002-11-03 00:24:07 +00:00
|
|
|
ld_addr=simple_strtoul(argv[3], NULL, 16);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ld_addr=load_addr;
|
|
|
|
}
|
|
|
|
printf ("\nupdating bootloader image from memory at %lX\n",ld_addr);
|
2003-12-07 18:32:37 +00:00
|
|
|
result=mpl_prg_image((uchar *)ld_addr);
|
2002-11-03 00:24:07 +00:00
|
|
|
return result;
|
|
|
|
}
|
2004-01-02 16:05:07 +00:00
|
|
|
#if !defined(CONFIG_PATI)
|
2002-11-03 00:24:07 +00:00
|
|
|
if (strcmp(argv[2], "mps") == 0) {
|
2003-12-07 18:32:37 +00:00
|
|
|
puts("\nupdating bootloader image from MPS\n");
|
|
|
|
result=mpl_prg((uchar *)src,size);
|
2002-11-03 00:24:07 +00:00
|
|
|
return result;
|
|
|
|
}
|
2004-01-02 16:05:07 +00:00
|
|
|
#endif /* #if !defined(CONFIG_PATI) */
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
if (strcmp(argv[1], "mem") == 0)
|
|
|
|
{
|
|
|
|
result=0;
|
|
|
|
if(argc==3)
|
|
|
|
{
|
|
|
|
result = (int)simple_strtol(argv[2], NULL, 16);
|
|
|
|
}
|
|
|
|
src=(unsigned long)&result;
|
2008-10-16 13:01:15 +00:00
|
|
|
src-=CONFIG_SYS_MEMTEST_START;
|
2002-11-03 00:24:07 +00:00
|
|
|
src-=(100*1024); /* - 100k */
|
|
|
|
src&=0xfff00000;
|
|
|
|
size=0;
|
|
|
|
do {
|
2008-05-20 14:00:29 +00:00
|
|
|
size++;
|
2002-11-03 00:24:07 +00:00
|
|
|
printf("\n\nPass %ld\n",size);
|
2008-10-16 13:01:15 +00:00
|
|
|
mem_test(CONFIG_SYS_MEMTEST_START,src,1);
|
2002-11-03 00:24:07 +00:00
|
|
|
if(ctrlc())
|
|
|
|
break;
|
|
|
|
if(result>0)
|
|
|
|
result--;
|
|
|
|
|
|
|
|
}while(result);
|
|
|
|
return 0;
|
|
|
|
}
|
2004-01-02 16:05:07 +00:00
|
|
|
#if !defined(CONFIG_PATI)
|
2002-11-03 00:24:07 +00:00
|
|
|
if (strcmp(argv[1], "clearenvvalues") == 0)
|
|
|
|
{
|
2008-05-20 14:00:29 +00:00
|
|
|
if (strcmp(argv[2], "yes") == 0)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
|
|
|
clear_env_values();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (strcmp(argv[1], "getback") == 0) {
|
|
|
|
get_backup_values(&back);
|
|
|
|
back.signature[3]=0;
|
|
|
|
back.serial_name[16]=0;
|
|
|
|
back.eth_addr[20]=0;
|
|
|
|
printf("GetBackUp: signature: %s\n",back.signature);
|
|
|
|
printf(" serial#: %s\n",back.serial_name);
|
|
|
|
printf(" ethaddr: %s\n",back.eth_addr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (strcmp(argv[1], "setback") == 0) {
|
|
|
|
set_backup_values(1);
|
|
|
|
return 0;
|
|
|
|
}
|
2004-01-02 16:05:07 +00:00
|
|
|
#endif
|
2009-01-28 00:03:10 +00:00
|
|
|
cmd_usage(cmdtp);
|
2002-11-03 00:24:07 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-09 23:38:39 +00:00
|
|
|
#if defined(CONFIG_CMD_DOC)
|
2002-11-03 00:24:07 +00:00
|
|
|
void doc_init (void)
|
|
|
|
{
|
|
|
|
doc_probe(MULTI_PURPOSE_SOCKET_ADDR);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_VIDEO
|
|
|
|
/******************************************************
|
|
|
|
* Routines to display the Board information
|
|
|
|
* to the screen (since the VGA will be initialized as last,
|
|
|
|
* we must resend the infos)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_CONSOLE_EXTRA_INFO
|
|
|
|
extern GraphicDevice ctfb;
|
2003-09-10 22:30:53 +00:00
|
|
|
extern int get_boot_mode(void);
|
2002-11-03 00:24:07 +00:00
|
|
|
|
|
|
|
void video_get_info_str (int line_number, char *info)
|
|
|
|
{
|
|
|
|
/* init video info strings for graphic console */
|
2007-10-21 06:12:41 +00:00
|
|
|
PPC4xx_SYS_INFO sys_info;
|
2002-11-03 00:24:07 +00:00
|
|
|
char rev;
|
2003-05-23 11:38:58 +00:00
|
|
|
int i,boot;
|
2002-11-03 00:24:07 +00:00
|
|
|
unsigned long pvr;
|
|
|
|
char buf[64];
|
2008-10-19 00:35:49 +00:00
|
|
|
char buf1[32], buf2[32], buf3[32], buf4[32];
|
2003-05-23 11:38:58 +00:00
|
|
|
char cpustr[16];
|
2005-10-13 14:45:02 +00:00
|
|
|
char *s, *e, bc;
|
2002-11-03 00:24:07 +00:00
|
|
|
switch (line_number)
|
|
|
|
{
|
|
|
|
case 2:
|
|
|
|
/* CPU and board infos */
|
|
|
|
pvr=get_pvr();
|
|
|
|
get_sys_info (&sys_info);
|
|
|
|
switch (pvr) {
|
|
|
|
case PVR_405GP_RB: rev='B'; break;
|
|
|
|
case PVR_405GP_RC: rev='C'; break;
|
|
|
|
case PVR_405GP_RD: rev='D'; break;
|
|
|
|
case PVR_405GP_RE: rev='E'; break;
|
2003-05-23 11:38:58 +00:00
|
|
|
case PVR_405GPR_RB: rev='B'; break;
|
2002-11-03 00:24:07 +00:00
|
|
|
default: rev='?'; break;
|
|
|
|
}
|
2003-05-23 11:38:58 +00:00
|
|
|
if(pvr==PVR_405GPR_RB)
|
|
|
|
sprintf(cpustr,"PPC405GPr %c",rev);
|
|
|
|
else
|
|
|
|
sprintf(cpustr,"PPC405GP %c",rev);
|
2002-11-03 00:24:07 +00:00
|
|
|
/* Board info */
|
|
|
|
i=0;
|
|
|
|
s=getenv ("serial#");
|
|
|
|
#ifdef CONFIG_PIP405
|
|
|
|
if (!s || strncmp (s, "PIP405", 6)) {
|
|
|
|
sprintf(buf,"### No HW ID - assuming PIP405");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_MIP405
|
|
|
|
if (!s || strncmp (s, "MIP405", 6)) {
|
|
|
|
sprintf(buf,"### No HW ID - assuming MIP405");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else {
|
|
|
|
for (e = s; *e; ++e) {
|
|
|
|
if (*e == ' ')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (; s < e; ++s) {
|
|
|
|
if (*s == '_') {
|
|
|
|
++s;
|
|
|
|
break;
|
|
|
|
}
|
2008-07-14 13:19:07 +00:00
|
|
|
buf[i++] = *s;
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
sprintf(&buf[i]," SN ");
|
|
|
|
i+=4;
|
|
|
|
for (; s < e; ++s) {
|
2008-07-14 13:19:07 +00:00
|
|
|
buf[i++] = *s;
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
buf[i++]=0;
|
|
|
|
}
|
2008-10-19 00:35:49 +00:00
|
|
|
sprintf (info," %s %s %s MHz (%s/%s/%s MHz)",
|
2003-05-23 11:38:58 +00:00
|
|
|
buf, cpustr,
|
2008-10-19 00:35:49 +00:00
|
|
|
strmhz (buf1, gd->cpu_clk),
|
|
|
|
strmhz (buf2, sys_info.freqPLB),
|
|
|
|
strmhz (buf3, sys_info.freqPLB / sys_info.pllOpbDiv),
|
|
|
|
strmhz (buf4, sys_info.freqPLB / sys_info.pllExtBusDiv));
|
2002-11-03 00:24:07 +00:00
|
|
|
return;
|
|
|
|
case 3:
|
|
|
|
/* Memory Info */
|
2003-05-23 11:38:58 +00:00
|
|
|
boot = get_boot_mode();
|
2002-11-03 00:24:07 +00:00
|
|
|
bc = in8 (CONFIG_PORT_ADDR);
|
|
|
|
sprintf(info, " %luMB RAM, %luMB Flash Cfg 0x%02X %s %s",
|
|
|
|
gd->bd->bi_memsize / 0x100000,
|
|
|
|
gd->bd->bi_flashsize / 0x100000,
|
|
|
|
bc,
|
2003-05-23 11:38:58 +00:00
|
|
|
(boot & BOOT_MPS) ? "MPS boot" : "Flash boot",
|
2002-11-03 00:24:07 +00:00
|
|
|
ctfb.modeIdent);
|
|
|
|
return;
|
|
|
|
case 1:
|
|
|
|
sprintf (buf, "%s",CONFIG_IDENT_STRING);
|
|
|
|
sprintf (info, " %s", &buf[1]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* no more info lines */
|
|
|
|
*info = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_CONSOLE_EXTRA_INFO */
|
|
|
|
|
|
|
|
#endif /* CONFIG_VIDEO */
|