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