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