wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
| 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> |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 30 | #include <asm/byteorder.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 31 | #include <i2c.h> |
| 32 | #include <devices.h> |
| 33 | #include <pci.h> |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 34 | #include <malloc.h> |
| 35 | #include <bzlib.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 36 | |
wdenk | 7d07641 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 37 | #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 |
| 45 | |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 46 | extern int gunzip(void *, int, uchar *, int *); |
| 47 | extern int mem_test(ulong start, ulong ramsize, int quiet); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 48 | |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 49 | #define I2C_BACKUP_ADDR 0x7C00 /* 0x200 bytes for backup */ |
| 50 | #define IMAGE_SIZE CFG_MONITOR_LEN /* ugly, but it works for now */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 51 | |
| 52 | extern flash_info_t flash_info[]; /* info for FLASH chips */ |
| 53 | |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 54 | static image_header_t header; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 55 | |
| 56 | |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame^] | 57 | static int |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 58 | mpl_prg(uchar *src, ulong size) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 59 | { |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 60 | ulong start; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 61 | flash_info_t *info; |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 62 | int i, rc; |
wdenk | 6b58f33 | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 63 | #if defined(CONFIG_PIP405) || defined(CONFIG_MIP405) |
wdenk | e39c284 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 64 | char *copystr = (char *)src; |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 65 | ulong *magic = (ulong *)src; |
wdenk | 6b58f33 | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 66 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 67 | |
| 68 | info = &flash_info[0]; |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 69 | |
| 70 | #if defined(CONFIG_PIP405) || defined(CONFIG_MIP405) |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 71 | if (ntohl(magic[0]) != IH_MAGIC) { |
| 72 | puts("Bad Magic number\n"); |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 73 | return -1; |
| 74 | } |
wdenk | e39c284 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 75 | /* some more checks before we delete the Flash... */ |
| 76 | /* Checking the ISO_STRING prevents to program a |
| 77 | * wrong Firmware Image into the flash. |
| 78 | */ |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 79 | i = 4; /* skip Magic number */ |
| 80 | while (1) { |
| 81 | if (strncmp(©str[i], "MEV-", 4) == 0) |
wdenk | e39c284 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 82 | break; |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 83 | if (i++ >= 0x100) { |
| 84 | puts("Firmware Image for unknown Target\n"); |
wdenk | e39c284 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 85 | return -1; |
| 86 | } |
| 87 | } |
| 88 | /* we have the ISO STRING, check */ |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 89 | if (strncmp(©str[i], CONFIG_ISO_STRING, sizeof(CONFIG_ISO_STRING)-1) != 0) { |
| 90 | printf("Wrong Firmware Image: %s\n", ©str[i]); |
wdenk | e39c284 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 91 | return -1; |
| 92 | } |
| 93 | start = 0 - size; |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 94 | for (i = info->sector_count-1; i > 0; i--) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 95 | info->protect[i] = 0; /* unprotect this sector */ |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 96 | if (start >= info->start[i]) |
| 97 | break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 98 | } |
| 99 | /* set-up flash location */ |
| 100 | /* now erase flash */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 101 | printf("Erasing at %lx (sector %d) (start %lx)\n", |
| 102 | start,i,info->start[i]); |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 103 | if ((rc = flash_erase (info, i, info->sector_count-1)) != 0) { |
| 104 | puts("ERROR "); |
| 105 | flash_perror(rc); |
| 106 | return (1); |
| 107 | } |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 108 | |
| 109 | #elif defined(CONFIG_VCMA9) |
| 110 | start = 0; |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 111 | for (i = 0; i <info->sector_count; i++) { |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 112 | info->protect[i] = 0; /* unprotect this sector */ |
| 113 | if (size < info->start[i]) |
| 114 | break; |
| 115 | } |
| 116 | /* set-up flash location */ |
| 117 | /* now erase flash */ |
| 118 | printf("Erasing at %lx (sector %d) (start %lx)\n", |
| 119 | start,0,info->start[0]); |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 120 | if ((rc = flash_erase (info, 0, i)) != 0) { |
| 121 | puts("ERROR "); |
| 122 | flash_perror(rc); |
| 123 | return (1); |
| 124 | } |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 125 | |
| 126 | #endif |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame^] | 127 | printf("flash erased, programming from 0x%lx 0x%lx Bytes\n", |
| 128 | (ulong)src, size); |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 129 | if ((rc = flash_write (src, start, size)) != 0) { |
| 130 | puts("ERROR "); |
| 131 | flash_perror(rc); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 132 | return (1); |
| 133 | } |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 134 | puts("OK programming done\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame^] | 139 | static int |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 140 | mpl_prg_image(uchar *ld_addr) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 141 | { |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 142 | unsigned long len, checksum; |
| 143 | uchar *data; |
| 144 | image_header_t *hdr = &header; |
| 145 | int rc; |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame^] | 146 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 147 | /* Copy header so we can blank CRC field for re-calculation */ |
| 148 | memcpy (&header, (char *)ld_addr, sizeof(image_header_t)); |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 149 | if (ntohl(hdr->ih_magic) != IH_MAGIC) { |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 150 | puts("Bad Magic Number\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 151 | return 1; |
| 152 | } |
| 153 | print_image_hdr(hdr); |
| 154 | if (hdr->ih_os != IH_OS_U_BOOT) { |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 155 | puts("No U-Boot Image\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 156 | return 1; |
| 157 | } |
| 158 | if (hdr->ih_type != IH_TYPE_FIRMWARE) { |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 159 | puts("No Firmware Image\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 160 | return 1; |
| 161 | } |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 162 | data = (uchar *)&header; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 163 | len = sizeof(image_header_t); |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 164 | checksum = ntohl(hdr->ih_hcrc); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 165 | hdr->ih_hcrc = 0; |
| 166 | if (crc32 (0, (char *)data, len) != checksum) { |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 167 | puts("Bad Header Checksum\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 168 | return 1; |
| 169 | } |
| 170 | data = ld_addr + sizeof(image_header_t); |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 171 | len = ntohl(hdr->ih_size); |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 172 | puts("Verifying Checksum ... "); |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 173 | if (crc32 (0, (char *)data, len) != ntohl(hdr->ih_dcrc)) { |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 174 | puts("Bad Data CRC\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 175 | return 1; |
| 176 | } |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 177 | puts("OK\n"); |
| 178 | |
| 179 | if (hdr->ih_comp != IH_COMP_NONE) { |
| 180 | uchar *buf; |
| 181 | /* reserve space for uncompressed image */ |
| 182 | if ((buf = malloc(IMAGE_SIZE)) == NULL) { |
| 183 | puts("Insufficient space for decompression\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 184 | return 1; |
| 185 | } |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame^] | 186 | |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 187 | switch (hdr->ih_comp) { |
| 188 | case IH_COMP_GZIP: |
| 189 | puts("Uncompressing (GZIP) ... "); |
| 190 | rc = gunzip ((void *)(buf), IMAGE_SIZE, data, (int *)&len); |
| 191 | if (rc != 0) { |
| 192 | puts("GUNZIP ERROR\n"); |
| 193 | free(buf); |
| 194 | return 1; |
| 195 | } |
| 196 | puts("OK\n"); |
| 197 | break; |
| 198 | #if CONFIG_BZIP2 |
| 199 | case IH_COMP_BZIP2: |
| 200 | puts("Uncompressing (BZIP2) ... "); |
| 201 | { |
| 202 | uint retlen = IMAGE_SIZE; |
| 203 | rc = BZ2_bzBuffToBuffDecompress ((char *)(buf), &retlen, |
| 204 | (char *)data, len, 0, 0); |
| 205 | len = retlen; |
| 206 | } |
| 207 | if (rc != BZ_OK) { |
| 208 | printf ("BUNZIP2 ERROR: %d\n", rc); |
| 209 | free(buf); |
| 210 | return 1; |
| 211 | } |
| 212 | puts("OK\n"); |
| 213 | break; |
| 214 | #endif |
| 215 | default: |
| 216 | printf ("Unimplemented compression type %d\n", hdr->ih_comp); |
| 217 | free(buf); |
| 218 | return 1; |
| 219 | } |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame^] | 220 | |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 221 | rc = mpl_prg(buf, len); |
| 222 | free(buf); |
| 223 | } else { |
| 224 | rc = mpl_prg(data, len); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 225 | } |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame^] | 226 | |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 227 | return(rc); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | |
| 231 | void get_backup_values(backup_t *buf) |
| 232 | { |
| 233 | i2c_read(CFG_DEF_EEPROM_ADDR, I2C_BACKUP_ADDR,2,(void *)buf,sizeof(backup_t)); |
| 234 | } |
| 235 | |
| 236 | void set_backup_values(int overwrite) |
| 237 | { |
| 238 | backup_t back; |
| 239 | int i; |
| 240 | |
| 241 | get_backup_values(&back); |
| 242 | if(!overwrite) { |
| 243 | if(strncmp(back.signature,"MPL\0",4)==0) { |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 244 | puts("Not possible to write Backup\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 245 | return; |
| 246 | } |
| 247 | } |
| 248 | memcpy(back.signature,"MPL\0",4); |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 249 | i = getenv_r("serial#",back.serial_name,16); |
| 250 | if(i < 0) { |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 251 | puts("Not possible to write Backup\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 252 | return; |
| 253 | } |
| 254 | back.serial_name[16]=0; |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 255 | i = getenv_r("ethaddr",back.eth_addr,20); |
| 256 | if(i < 0) { |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 257 | puts("Not possible to write Backup\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 258 | return; |
| 259 | } |
| 260 | back.eth_addr[20]=0; |
| 261 | i2c_write(CFG_DEF_EEPROM_ADDR, I2C_BACKUP_ADDR,2,(void *)&back,sizeof(backup_t)); |
| 262 | } |
| 263 | |
| 264 | void clear_env_values(void) |
| 265 | { |
| 266 | backup_t back; |
| 267 | unsigned char env_crc[4]; |
| 268 | |
| 269 | memset(&back,0xff,sizeof(backup_t)); |
| 270 | memset(env_crc,0x00,4); |
| 271 | i2c_write(CFG_DEF_EEPROM_ADDR,I2C_BACKUP_ADDR,2,(void *)&back,sizeof(backup_t)); |
| 272 | i2c_write(CFG_DEF_EEPROM_ADDR,CFG_ENV_OFFSET,2,(void *)env_crc,4); |
| 273 | } |
| 274 | |
| 275 | /* |
| 276 | * check crc of "older" environment |
| 277 | */ |
| 278 | int check_env_old_size(ulong oldsize) |
| 279 | { |
| 280 | ulong crc, len, new; |
| 281 | unsigned off; |
| 282 | uchar buf[64]; |
| 283 | |
| 284 | /* read old CRC */ |
| 285 | eeprom_read (CFG_DEF_EEPROM_ADDR, |
| 286 | CFG_ENV_OFFSET, |
| 287 | (uchar *)&crc, sizeof(ulong)); |
| 288 | |
| 289 | new = 0; |
| 290 | len = oldsize; |
| 291 | off = sizeof(long); |
| 292 | len = oldsize-off; |
| 293 | while (len > 0) { |
| 294 | int n = (len > sizeof(buf)) ? sizeof(buf) : len; |
| 295 | |
| 296 | eeprom_read (CFG_DEF_EEPROM_ADDR, CFG_ENV_OFFSET+off, buf, n); |
| 297 | new = crc32 (new, buf, n); |
| 298 | len -= n; |
| 299 | off += n; |
| 300 | } |
| 301 | |
| 302 | return (crc == new); |
| 303 | } |
| 304 | |
| 305 | static ulong oldsizes[] = { |
| 306 | 0x200, |
| 307 | 0x800, |
| 308 | 0 |
| 309 | }; |
| 310 | |
| 311 | void copy_old_env(ulong size) |
| 312 | { |
| 313 | uchar name_buf[64]; |
| 314 | uchar value_buf[0x800]; |
| 315 | uchar c; |
| 316 | ulong len; |
| 317 | unsigned off; |
| 318 | uchar *name, *value; |
| 319 | |
| 320 | name=&name_buf[0]; |
| 321 | value=&value_buf[0]; |
| 322 | len=size; |
| 323 | off = sizeof(long); |
| 324 | while (len > off) { |
| 325 | eeprom_read (CFG_DEF_EEPROM_ADDR, CFG_ENV_OFFSET+off, &c, 1); |
| 326 | if(c != '=') { |
| 327 | *name++=c; |
| 328 | off++; |
| 329 | } |
| 330 | else { |
| 331 | *name++='\0'; |
| 332 | off++; |
| 333 | do { |
| 334 | eeprom_read (CFG_DEF_EEPROM_ADDR, CFG_ENV_OFFSET+off, &c, 1); |
| 335 | *value++=c; |
| 336 | off++; |
| 337 | if(c == '\0') |
| 338 | break; |
| 339 | } while(len > off); |
| 340 | name=&name_buf[0]; |
| 341 | value=&value_buf[0]; |
| 342 | if(strncmp(name,"baudrate",8)!=0) { |
| 343 | setenv(name,value); |
| 344 | } |
| 345 | |
| 346 | } |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | |
| 351 | void check_env(void) |
| 352 | { |
| 353 | unsigned char *s; |
| 354 | int i=0; |
| 355 | char buf[32]; |
| 356 | backup_t back; |
| 357 | |
| 358 | s=getenv("serial#"); |
| 359 | if(!s) { |
| 360 | while(oldsizes[i]) { |
| 361 | if(check_env_old_size(oldsizes[i])) |
| 362 | break; |
| 363 | i++; |
| 364 | } |
| 365 | if(!oldsizes[i]) { |
| 366 | /* no old environment has been found */ |
| 367 | get_backup_values (&back); |
| 368 | if (strncmp (back.signature, "MPL\0", 4) == 0) { |
| 369 | sprintf (buf, "%s", back.serial_name); |
| 370 | setenv ("serial#", buf); |
| 371 | sprintf (buf, "%s", back.eth_addr); |
| 372 | setenv ("ethaddr", buf); |
| 373 | printf ("INFO: serial# and ethaddr recovered, use saveenv\n"); |
| 374 | return; |
| 375 | } |
| 376 | } |
| 377 | else { |
| 378 | copy_old_env(oldsizes[i]); |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 379 | puts("INFO: old environment ajusted, use saveenv\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 380 | } |
| 381 | } |
| 382 | else { |
| 383 | /* check if back up is set */ |
| 384 | get_backup_values(&back); |
| 385 | if(strncmp(back.signature,"MPL\0",4)!=0) { |
| 386 | set_backup_values(0); |
| 387 | } |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 392 | extern device_t *stdio_devices[]; |
| 393 | extern char *stdio_names[]; |
| 394 | |
| 395 | void show_stdio_dev(void) |
| 396 | { |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 397 | /* Print information */ |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 398 | puts("In: "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 399 | if (stdio_devices[stdin] == NULL) { |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 400 | puts("No input devices available!\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 401 | } else { |
| 402 | printf ("%s\n", stdio_devices[stdin]->name); |
| 403 | } |
| 404 | |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 405 | puts("Out: "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 406 | if (stdio_devices[stdout] == NULL) { |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 407 | puts("No output devices available!\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 408 | } else { |
| 409 | printf ("%s\n", stdio_devices[stdout]->name); |
| 410 | } |
| 411 | |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 412 | puts("Err: "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 413 | if (stdio_devices[stderr] == NULL) { |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 414 | puts("No error devices available!\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 415 | } else { |
| 416 | printf ("%s\n", stdio_devices[stderr]->name); |
| 417 | } |
| 418 | } |
| 419 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 420 | |
| 421 | int do_mplcommon(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 422 | { |
| 423 | ulong size,src,ld_addr; |
| 424 | int result; |
| 425 | backup_t back; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 426 | src = MULTI_PURPOSE_SOCKET_ADDR; |
| 427 | size = IMAGE_SIZE; |
| 428 | |
| 429 | if (strcmp(argv[1], "flash") == 0) |
| 430 | { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 431 | #if (CONFIG_COMMANDS & CFG_CMD_FDC) |
| 432 | if (strcmp(argv[2], "floppy") == 0) { |
| 433 | char *local_args[3]; |
| 434 | extern int do_fdcboot (cmd_tbl_t *, int, int, char *[]); |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 435 | puts("\nupdating bootloader image from floppy\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 436 | local_args[0] = argv[0]; |
| 437 | if(argc==4) { |
| 438 | local_args[1] = argv[3]; |
| 439 | local_args[2] = NULL; |
| 440 | ld_addr=simple_strtoul(argv[3], NULL, 16); |
| 441 | result=do_fdcboot(cmdtp, 0, 2, local_args); |
| 442 | } |
| 443 | else { |
| 444 | local_args[1] = NULL; |
| 445 | ld_addr=CFG_LOAD_ADDR; |
| 446 | result=do_fdcboot(cmdtp, 0, 1, local_args); |
| 447 | } |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame^] | 448 | result=mpl_prg_image((uchar *)ld_addr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 449 | return result; |
| 450 | } |
| 451 | #endif /* (CONFIG_COMMANDS & CFG_CMD_FDC) */ |
| 452 | if (strcmp(argv[2], "mem") == 0) { |
| 453 | if(argc==4) { |
| 454 | ld_addr=simple_strtoul(argv[3], NULL, 16); |
| 455 | } |
| 456 | else { |
| 457 | ld_addr=load_addr; |
| 458 | } |
| 459 | printf ("\nupdating bootloader image from memory at %lX\n",ld_addr); |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 460 | result=mpl_prg_image((uchar *)ld_addr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 461 | return result; |
| 462 | } |
| 463 | if (strcmp(argv[2], "mps") == 0) { |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 464 | puts("\nupdating bootloader image from MPS\n"); |
| 465 | result=mpl_prg((uchar *)src,size); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 466 | return result; |
| 467 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 468 | } |
| 469 | if (strcmp(argv[1], "mem") == 0) |
| 470 | { |
| 471 | result=0; |
| 472 | if(argc==3) |
| 473 | { |
| 474 | result = (int)simple_strtol(argv[2], NULL, 16); |
| 475 | } |
| 476 | src=(unsigned long)&result; |
| 477 | src-=CFG_MEMTEST_START; |
| 478 | src-=(100*1024); /* - 100k */ |
| 479 | src&=0xfff00000; |
| 480 | size=0; |
| 481 | do { |
| 482 | size++; |
| 483 | printf("\n\nPass %ld\n",size); |
| 484 | mem_test(CFG_MEMTEST_START,src,1); |
| 485 | if(ctrlc()) |
| 486 | break; |
| 487 | if(result>0) |
| 488 | result--; |
| 489 | |
| 490 | }while(result); |
| 491 | return 0; |
| 492 | } |
| 493 | if (strcmp(argv[1], "clearenvvalues") == 0) |
| 494 | { |
| 495 | if (strcmp(argv[2], "yes") == 0) |
| 496 | { |
| 497 | clear_env_values(); |
| 498 | return 0; |
| 499 | } |
| 500 | } |
| 501 | if (strcmp(argv[1], "getback") == 0) { |
| 502 | get_backup_values(&back); |
| 503 | back.signature[3]=0; |
| 504 | back.serial_name[16]=0; |
| 505 | back.eth_addr[20]=0; |
| 506 | printf("GetBackUp: signature: %s\n",back.signature); |
| 507 | printf(" serial#: %s\n",back.serial_name); |
| 508 | printf(" ethaddr: %s\n",back.eth_addr); |
| 509 | return 0; |
| 510 | } |
| 511 | if (strcmp(argv[1], "setback") == 0) { |
| 512 | set_backup_values(1); |
| 513 | return 0; |
| 514 | } |
| 515 | printf("Usage:\n%s\n", cmdtp->usage); |
| 516 | return 1; |
| 517 | } |
| 518 | |
| 519 | |
| 520 | #if (CONFIG_COMMANDS & CFG_CMD_DOC) |
| 521 | extern void doc_probe(ulong physadr); |
| 522 | void doc_init (void) |
| 523 | { |
| 524 | doc_probe(MULTI_PURPOSE_SOCKET_ADDR); |
| 525 | } |
| 526 | #endif |
| 527 | |
| 528 | |
| 529 | #ifdef CONFIG_VIDEO |
| 530 | /****************************************************** |
| 531 | * Routines to display the Board information |
| 532 | * to the screen (since the VGA will be initialized as last, |
| 533 | * we must resend the infos) |
| 534 | */ |
| 535 | |
| 536 | #ifdef CONFIG_CONSOLE_EXTRA_INFO |
| 537 | extern GraphicDevice ctfb; |
wdenk | 2c9b05d | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 538 | extern int get_boot_mode(void); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 539 | |
| 540 | void video_get_info_str (int line_number, char *info) |
| 541 | { |
| 542 | /* init video info strings for graphic console */ |
| 543 | DECLARE_GLOBAL_DATA_PTR; |
| 544 | PPC405_SYS_INFO sys_info; |
| 545 | char rev; |
wdenk | 7d07641 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 546 | int i,boot; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 547 | unsigned long pvr; |
| 548 | char buf[64]; |
| 549 | char tmp[16]; |
wdenk | 7d07641 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 550 | char cpustr[16]; |
| 551 | unsigned char *s, *e, bc; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 552 | switch (line_number) |
| 553 | { |
| 554 | case 2: |
| 555 | /* CPU and board infos */ |
| 556 | pvr=get_pvr(); |
| 557 | get_sys_info (&sys_info); |
| 558 | switch (pvr) { |
| 559 | case PVR_405GP_RB: rev='B'; break; |
| 560 | case PVR_405GP_RC: rev='C'; break; |
| 561 | case PVR_405GP_RD: rev='D'; break; |
| 562 | case PVR_405GP_RE: rev='E'; break; |
wdenk | 7d07641 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 563 | case PVR_405GPR_RB: rev='B'; break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 564 | default: rev='?'; break; |
| 565 | } |
wdenk | 7d07641 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 566 | if(pvr==PVR_405GPR_RB) |
| 567 | sprintf(cpustr,"PPC405GPr %c",rev); |
| 568 | else |
| 569 | sprintf(cpustr,"PPC405GP %c",rev); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 570 | /* Board info */ |
| 571 | i=0; |
| 572 | s=getenv ("serial#"); |
| 573 | #ifdef CONFIG_PIP405 |
| 574 | if (!s || strncmp (s, "PIP405", 6)) { |
| 575 | sprintf(buf,"### No HW ID - assuming PIP405"); |
| 576 | } |
| 577 | #endif |
| 578 | #ifdef CONFIG_MIP405 |
| 579 | if (!s || strncmp (s, "MIP405", 6)) { |
| 580 | sprintf(buf,"### No HW ID - assuming MIP405"); |
| 581 | } |
| 582 | #endif |
| 583 | else { |
| 584 | for (e = s; *e; ++e) { |
| 585 | if (*e == ' ') |
| 586 | break; |
| 587 | } |
| 588 | for (; s < e; ++s) { |
| 589 | if (*s == '_') { |
| 590 | ++s; |
| 591 | break; |
| 592 | } |
| 593 | buf[i++]=*s; |
| 594 | } |
| 595 | sprintf(&buf[i]," SN "); |
| 596 | i+=4; |
| 597 | for (; s < e; ++s) { |
| 598 | buf[i++]=*s; |
| 599 | } |
| 600 | buf[i++]=0; |
| 601 | } |
wdenk | 7d07641 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 602 | sprintf (info," %s %s %s MHz (%lu/%lu/%lu MHz)", |
| 603 | buf, cpustr, |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 604 | strmhz (tmp, gd->cpu_clk), sys_info.freqPLB / 1000000, |
| 605 | sys_info.freqPLB / sys_info.pllOpbDiv / 1000000, |
| 606 | sys_info.freqPLB / sys_info.pllExtBusDiv / 1000000); |
| 607 | return; |
| 608 | case 3: |
| 609 | /* Memory Info */ |
wdenk | 7d07641 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 610 | boot = get_boot_mode(); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 611 | bc = in8 (CONFIG_PORT_ADDR); |
| 612 | sprintf(info, " %luMB RAM, %luMB Flash Cfg 0x%02X %s %s", |
| 613 | gd->bd->bi_memsize / 0x100000, |
| 614 | gd->bd->bi_flashsize / 0x100000, |
| 615 | bc, |
wdenk | 7d07641 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 616 | (boot & BOOT_MPS) ? "MPS boot" : "Flash boot", |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 617 | ctfb.modeIdent); |
| 618 | return; |
| 619 | case 1: |
| 620 | sprintf (buf, "%s",CONFIG_IDENT_STRING); |
| 621 | sprintf (info, " %s", &buf[1]); |
| 622 | return; |
| 623 | } |
| 624 | /* no more info lines */ |
| 625 | *info = 0; |
| 626 | return; |
| 627 | } |
| 628 | #endif /* CONFIG_CONSOLE_EXTRA_INFO */ |
| 629 | |
| 630 | #endif /* CONFIG_VIDEO */ |