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> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 32 | #include <pci.h> |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 33 | #include <malloc.h> |
| 34 | #include <bzlib.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 35 | |
wdenk | 7d07641 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 36 | #ifdef CONFIG_PIP405 |
| 37 | #include "../pip405/pip405.h" |
Stefan Roese | ca8725f | 2007-10-03 15:01:02 +0200 | [diff] [blame] | 38 | #include <asm/4xx_pci.h> |
wdenk | 7d07641 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 39 | #endif |
| 40 | #ifdef CONFIG_MIP405 |
| 41 | #include "../mip405/mip405.h" |
Stefan Roese | ca8725f | 2007-10-03 15:01:02 +0200 | [diff] [blame] | 42 | #include <asm/4xx_pci.h> |
wdenk | 7d07641 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 43 | #endif |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 44 | |
| 45 | DECLARE_GLOBAL_DATA_PTR; |
| 46 | |
wdenk | bc01dd5 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 47 | #if defined(CONFIG_PATI) |
| 48 | #define FIRM_START 0xFFF00000 |
| 49 | #endif |
wdenk | 7d07641 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 50 | |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 51 | extern int mem_test(ulong start, ulong ramsize, int quiet); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 52 | |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 53 | #define I2C_BACKUP_ADDR 0x7C00 /* 0x200 bytes for backup */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 54 | #define IMAGE_SIZE CONFIG_SYS_MONITOR_LEN /* ugly, but it works for now */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 55 | |
David Müller | b4a931e | 2011-12-22 13:38:19 +0100 | [diff] [blame^] | 56 | #if defined(CONFIG_PIP405) || defined(CONFIG_MIP405) |
| 57 | /*----------------------------------------------------------------------- |
| 58 | * On PIP/MIP405 we have 3 (4) possible boot mode |
| 59 | * |
| 60 | * - Boot from Flash (Flash CS = CS0, MPS CS = CS1) |
| 61 | * - Boot from MPS (Flash CS = CS1, MPS CS = CS0) |
| 62 | * - Boot from PCI with Flash map (Flash CS = CS0, MPS CS = CS1) |
| 63 | * - Boot from PCI with MPS map (Flash CS = CS1, MPS CS = CS0) |
| 64 | * The flash init is the first board specific routine which is called |
| 65 | * after code relocation (running from SDRAM) |
| 66 | * The first thing we do is to map the Flash CS to the Flash area and |
| 67 | * the MPS CS to the MPS area. Since the flash size is unknown at this |
| 68 | * point, we use the max flash size and the lowest flash address as base. |
| 69 | * |
| 70 | * After flash detection we adjust the size of the CS area accordingly. |
| 71 | * update_flash_size() will fix in wrong values in the flash_info structure, |
| 72 | * misc_init_r() will fix the values in the board info structure |
| 73 | */ |
| 74 | int get_boot_mode(void) |
| 75 | { |
| 76 | unsigned long pbcr; |
| 77 | int res = 0; |
| 78 | pbcr = mfdcr(CPC0_PSR); |
| 79 | if ((pbcr & PSR_ROM_WIDTH_MASK) == 0) |
| 80 | /* boot via MPS or MPS mapping */ |
| 81 | res = BOOT_MPS; |
| 82 | if (pbcr & PSR_ROM_LOC) |
| 83 | /* boot via PCI.. */ |
| 84 | res |= BOOT_PCI; |
| 85 | return res; |
| 86 | } |
| 87 | |
| 88 | /* Map the flash high (in boot area) |
| 89 | This code can only be executed from SDRAM (after relocation). |
| 90 | */ |
| 91 | void setup_cs_reloc(void) |
| 92 | { |
| 93 | int mode; |
| 94 | /* |
| 95 | * since we are relocated, we can set-up the CS finaly |
| 96 | * but first of all, switch off PCI mapping (in case it |
| 97 | * was a PCI boot) |
| 98 | */ |
| 99 | out32r(PMM0MA, 0L); |
| 100 | /* get boot mode */ |
| 101 | mode = get_boot_mode(); |
| 102 | /* |
| 103 | * we map the flash high in every case |
| 104 | * first find out to which CS the flash is attached to |
| 105 | */ |
| 106 | if (mode & BOOT_MPS) { |
| 107 | /* map flash high on CS1 and MPS on CS0 */ |
| 108 | mtdcr(EBC0_CFGADDR, PB0AP); |
| 109 | mtdcr(EBC0_CFGDATA, MPS_AP); |
| 110 | mtdcr(EBC0_CFGADDR, PB0CR); |
| 111 | mtdcr(EBC0_CFGDATA, MPS_CR); |
| 112 | /* |
| 113 | * we use the default values (max values) for the flash |
| 114 | * because its real size is not yet known |
| 115 | */ |
| 116 | mtdcr(EBC0_CFGADDR, PB1AP); |
| 117 | mtdcr(EBC0_CFGDATA, FLASH_AP); |
| 118 | mtdcr(EBC0_CFGADDR, PB1CR); |
| 119 | mtdcr(EBC0_CFGDATA, FLASH_CR_B); |
| 120 | } else { |
| 121 | /* map flash high on CS0 and MPS on CS1 */ |
| 122 | mtdcr(EBC0_CFGADDR, PB1AP); |
| 123 | mtdcr(EBC0_CFGDATA, MPS_AP); |
| 124 | mtdcr(EBC0_CFGADDR, PB1CR); |
| 125 | mtdcr(EBC0_CFGDATA, MPS_CR); |
| 126 | /* |
| 127 | * we use the default values (max values) for the flash |
| 128 | * because its real size is not yet known |
| 129 | */ |
| 130 | mtdcr(EBC0_CFGADDR, PB0AP); |
| 131 | mtdcr(EBC0_CFGDATA, FLASH_AP); |
| 132 | mtdcr(EBC0_CFGADDR, PB0CR); |
| 133 | mtdcr(EBC0_CFGDATA, FLASH_CR_B); |
| 134 | } |
| 135 | } |
| 136 | #endif /* #if defined(CONFIG_PIP405) || defined(CONFIG_MIP405) */ |
| 137 | |
| 138 | #ifdef CONFIG_SYS_UPDATE_FLASH_SIZE |
| 139 | /* adjust flash start and protection info */ |
| 140 | int update_flash_size(int flash_size) |
| 141 | { |
| 142 | int i = 0, mode; |
| 143 | flash_info_t *info = &flash_info[0]; |
| 144 | unsigned long flashcr; |
| 145 | unsigned long flash_base = (0 - flash_size) & 0xFFF00000; |
| 146 | |
| 147 | if (flash_size > 128*1024*1024) { |
| 148 | printf("\n ### ERROR, wrong flash size: %X, reset board ###\n", |
| 149 | flash_size); |
| 150 | hang(); |
| 151 | } |
| 152 | |
| 153 | if ((flash_size >> 20) != 0) |
| 154 | i = __ilog2(flash_size >> 20); |
| 155 | |
| 156 | /* set up flash CS according to the size */ |
| 157 | mode = get_boot_mode(); |
| 158 | if (mode & BOOT_MPS) { |
| 159 | /* flash is on CS1 */ |
| 160 | mtdcr(EBC0_CFGADDR, PB1CR); |
| 161 | flashcr = mfdcr(EBC0_CFGDATA); |
| 162 | /* we map the flash high in every case */ |
| 163 | flashcr &= 0x0001FFFF; /* mask out address bits */ |
| 164 | flashcr |= flash_base; /* start addr */ |
| 165 | flashcr |= (i << 17); /* size addr */ |
| 166 | mtdcr(EBC0_CFGADDR, PB1CR); |
| 167 | mtdcr(EBC0_CFGDATA, flashcr); |
| 168 | } else { |
| 169 | /* flash is on CS0 */ |
| 170 | mtdcr(EBC0_CFGADDR, PB0CR); |
| 171 | flashcr = mfdcr(EBC0_CFGDATA); |
| 172 | /* we map the flash high in every case */ |
| 173 | flashcr &= 0x0001FFFF; /* mask out address bits */ |
| 174 | flashcr |= flash_base; /* start addr */ |
| 175 | flashcr |= (i << 17); /* size addr */ |
| 176 | mtdcr(EBC0_CFGADDR, PB0CR); |
| 177 | mtdcr(EBC0_CFGDATA, flashcr); |
| 178 | } |
| 179 | |
| 180 | for (i = 0; i < info->sector_count; i++) |
| 181 | /* adjust sector start address */ |
| 182 | info->start[i] = flash_base + |
| 183 | (info->start[i] - CONFIG_SYS_FLASH_BASE); |
| 184 | |
| 185 | /* unprotect all sectors */ |
| 186 | flash_protect(FLAG_PROTECT_CLEAR, |
| 187 | info->start[0], |
| 188 | 0xFFFFFFFF, |
| 189 | info); |
| 190 | flash_protect_default(); |
| 191 | /* protect reset vector too*/ |
| 192 | flash_protect(FLAG_PROTECT_SET, |
| 193 | info->start[info->sector_count-1], |
| 194 | 0xFFFFFFFF, |
| 195 | info); |
| 196 | |
| 197 | return 0; |
| 198 | } |
| 199 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 200 | |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 201 | static int |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 202 | mpl_prg(uchar *src, ulong size) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 203 | { |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 204 | ulong start; |
David Müller | b4a931e | 2011-12-22 13:38:19 +0100 | [diff] [blame^] | 205 | flash_info_t *info = &flash_info[0]; |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 206 | int i, rc; |
wdenk | bc01dd5 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 207 | #if defined(CONFIG_PATI) |
| 208 | int start_sect; |
| 209 | #endif |
| 210 | #if defined(CONFIG_PIP405) || defined(CONFIG_MIP405) || defined(CONFIG_PATI) |
wdenk | e39c284 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 211 | char *copystr = (char *)src; |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 212 | ulong *magic = (ulong *)src; |
wdenk | 6b58f33 | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 213 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 214 | |
wdenk | bc01dd5 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 215 | #if defined(CONFIG_PIP405) || defined(CONFIG_MIP405) || defined(CONFIG_PATI) |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 216 | if (uimage_to_cpu (magic[0]) != IH_MAGIC) { |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 217 | puts("Bad Magic number\n"); |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 218 | return -1; |
| 219 | } |
wdenk | e39c284 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 220 | /* some more checks before we delete the Flash... */ |
| 221 | /* Checking the ISO_STRING prevents to program a |
| 222 | * wrong Firmware Image into the flash. |
| 223 | */ |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 224 | i = 4; /* skip Magic number */ |
| 225 | while (1) { |
| 226 | if (strncmp(©str[i], "MEV-", 4) == 0) |
wdenk | e39c284 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 227 | break; |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 228 | if (i++ >= 0x100) { |
| 229 | puts("Firmware Image for unknown Target\n"); |
wdenk | e39c284 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 230 | return -1; |
| 231 | } |
| 232 | } |
| 233 | /* we have the ISO STRING, check */ |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 234 | if (strncmp(©str[i], CONFIG_ISO_STRING, sizeof(CONFIG_ISO_STRING)-1) != 0) { |
| 235 | printf("Wrong Firmware Image: %s\n", ©str[i]); |
wdenk | e39c284 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 236 | return -1; |
| 237 | } |
wdenk | bc01dd5 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 238 | #if !defined(CONFIG_PATI) |
wdenk | e39c284 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 239 | start = 0 - size; |
David Müller | b4a931e | 2011-12-22 13:38:19 +0100 | [diff] [blame^] | 240 | |
| 241 | /* unprotect sectors used by u-boot */ |
| 242 | flash_protect(FLAG_PROTECT_CLEAR, |
| 243 | start, |
| 244 | 0xFFFFFFFF, |
| 245 | info); |
| 246 | |
| 247 | /* search start sector */ |
| 248 | for (i = info->sector_count-1; i > 0; i--) |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 249 | if (start >= info->start[i]) |
| 250 | break; |
David Müller | b4a931e | 2011-12-22 13:38:19 +0100 | [diff] [blame^] | 251 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 252 | /* now erase flash */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 253 | printf("Erasing at %lx (sector %d) (start %lx)\n", |
| 254 | start,i,info->start[i]); |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 255 | if ((rc = flash_erase (info, i, info->sector_count-1)) != 0) { |
| 256 | puts("ERROR "); |
| 257 | flash_perror(rc); |
| 258 | return (1); |
| 259 | } |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 260 | |
wdenk | bc01dd5 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 261 | #else /* #if !defined(CONFIG_PATI */ |
| 262 | start = FIRM_START; |
| 263 | start_sect = -1; |
David Müller | b4a931e | 2011-12-22 13:38:19 +0100 | [diff] [blame^] | 264 | |
| 265 | /* search start sector */ |
| 266 | for (i = info->sector_count-1; i > 0; i--) |
| 267 | if (start >= info->start[i]) |
wdenk | bc01dd5 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 268 | break; |
David Müller | b4a931e | 2011-12-22 13:38:19 +0100 | [diff] [blame^] | 269 | |
| 270 | start_sect = i; |
wdenk | bc01dd5 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 271 | |
David Müller | b4a931e | 2011-12-22 13:38:19 +0100 | [diff] [blame^] | 272 | for (i = info->sector_count-1; i > 0; i--) |
| 273 | if ((start + size) >= info->start[i]) |
wdenk | bc01dd5 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 274 | break; |
David Müller | b4a931e | 2011-12-22 13:38:19 +0100 | [diff] [blame^] | 275 | |
| 276 | /* unprotect sectors used by u-boot */ |
| 277 | flash_protect(FLAG_PROTECT_CLEAR, |
| 278 | start, |
| 279 | start + size, |
| 280 | info); |
wdenk | bc01dd5 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 281 | |
wdenk | bc01dd5 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 282 | /* now erase flash */ |
| 283 | printf ("Erasing at %lx to %lx (sector %d to %d) (%lx to %lx)\n", |
| 284 | start, start + size, start_sect, i, |
| 285 | info->start[start_sect], info->start[i]); |
| 286 | if ((rc = flash_erase (info, start_sect, i)) != 0) { |
| 287 | puts ("ERROR "); |
| 288 | flash_perror (rc); |
| 289 | return (1); |
| 290 | } |
| 291 | #endif /* defined(CONFIG_PATI) */ |
| 292 | |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 293 | #elif defined(CONFIG_VCMA9) |
| 294 | start = 0; |
David Müller | b4a931e | 2011-12-22 13:38:19 +0100 | [diff] [blame^] | 295 | |
| 296 | /* search end sector */ |
| 297 | for (i = 0; i < info->sector_count; i++) |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 298 | if (size < info->start[i]) |
| 299 | break; |
David Müller | b4a931e | 2011-12-22 13:38:19 +0100 | [diff] [blame^] | 300 | |
| 301 | flash_protect(FLAG_PROTECT_CLEAR, |
| 302 | start, |
| 303 | size, |
| 304 | info); |
| 305 | |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 306 | /* now erase flash */ |
| 307 | printf("Erasing at %lx (sector %d) (start %lx)\n", |
| 308 | start,0,info->start[0]); |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 309 | if ((rc = flash_erase (info, 0, i)) != 0) { |
| 310 | puts("ERROR "); |
| 311 | flash_perror(rc); |
| 312 | return (1); |
| 313 | } |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 314 | |
| 315 | #endif |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 316 | printf("flash erased, programming from 0x%lx 0x%lx Bytes\n", |
| 317 | (ulong)src, size); |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 318 | if ((rc = flash_write ((char *)src, start, size)) != 0) { |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 319 | puts("ERROR "); |
| 320 | flash_perror(rc); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 321 | return (1); |
| 322 | } |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 323 | puts("OK programming done\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 324 | return 0; |
| 325 | } |
| 326 | |
| 327 | |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 328 | static int |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 329 | mpl_prg_image(uchar *ld_addr) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 330 | { |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 331 | unsigned long len; |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 332 | uchar *data; |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 333 | image_header_t *hdr = (image_header_t *)ld_addr; |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 334 | int rc; |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 335 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 336 | #if defined(CONFIG_FIT) |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 337 | if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 338 | puts ("Non legacy image format not supported\n"); |
| 339 | return -1; |
| 340 | } |
| 341 | #endif |
| 342 | |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 343 | if (!image_check_magic (hdr)) { |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 344 | puts("Bad Magic Number\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 345 | return 1; |
| 346 | } |
Marian Balakowicz | a1cc147 | 2008-02-21 17:27:41 +0100 | [diff] [blame] | 347 | image_print_contents (hdr); |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 348 | if (!image_check_os (hdr, IH_OS_U_BOOT)) { |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 349 | puts("No U-Boot Image\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 350 | return 1; |
| 351 | } |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 352 | if (!image_check_type (hdr, IH_TYPE_FIRMWARE)) { |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 353 | puts("No Firmware Image\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 354 | return 1; |
| 355 | } |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 356 | if (!image_check_hcrc (hdr)) { |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 357 | puts("Bad Header Checksum\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 358 | return 1; |
| 359 | } |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 360 | puts("Verifying Checksum ... "); |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 361 | if (!image_check_dcrc (hdr)) { |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 362 | puts("Bad Data CRC\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 363 | return 1; |
| 364 | } |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 365 | puts("OK\n"); |
| 366 | |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 367 | data = (uchar *)image_get_data (hdr); |
| 368 | len = image_get_data_size (hdr); |
| 369 | |
| 370 | if (image_get_comp (hdr) != IH_COMP_NONE) { |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 371 | uchar *buf; |
| 372 | /* reserve space for uncompressed image */ |
| 373 | if ((buf = malloc(IMAGE_SIZE)) == NULL) { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 374 | puts("Insufficient space for decompression\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 375 | return 1; |
| 376 | } |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 377 | |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 378 | switch (image_get_comp (hdr)) { |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 379 | case IH_COMP_GZIP: |
| 380 | puts("Uncompressing (GZIP) ... "); |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 381 | rc = gunzip ((void *)(buf), IMAGE_SIZE, data, &len); |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 382 | if (rc != 0) { |
| 383 | puts("GUNZIP ERROR\n"); |
| 384 | free(buf); |
| 385 | return 1; |
| 386 | } |
| 387 | puts("OK\n"); |
| 388 | break; |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 389 | #ifdef CONFIG_BZIP2 |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 390 | case IH_COMP_BZIP2: |
| 391 | puts("Uncompressing (BZIP2) ... "); |
| 392 | { |
| 393 | uint retlen = IMAGE_SIZE; |
| 394 | rc = BZ2_bzBuffToBuffDecompress ((char *)(buf), &retlen, |
| 395 | (char *)data, len, 0, 0); |
| 396 | len = retlen; |
| 397 | } |
| 398 | if (rc != BZ_OK) { |
| 399 | printf ("BUNZIP2 ERROR: %d\n", rc); |
| 400 | free(buf); |
| 401 | return 1; |
| 402 | } |
| 403 | puts("OK\n"); |
| 404 | break; |
| 405 | #endif |
| 406 | default: |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 407 | printf ("Unimplemented compression type %d\n", |
| 408 | image_get_comp (hdr)); |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 409 | free(buf); |
| 410 | return 1; |
| 411 | } |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 412 | |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 413 | rc = mpl_prg(buf, len); |
| 414 | free(buf); |
| 415 | } else { |
| 416 | rc = mpl_prg(data, len); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 417 | } |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 418 | |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 419 | return(rc); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 420 | } |
| 421 | |
wdenk | bc01dd5 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 422 | #if !defined(CONFIG_PATI) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 423 | void get_backup_values(backup_t *buf) |
| 424 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 425 | i2c_read(CONFIG_SYS_DEF_EEPROM_ADDR, I2C_BACKUP_ADDR,2,(void *)buf,sizeof(backup_t)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | void set_backup_values(int overwrite) |
| 429 | { |
| 430 | backup_t back; |
| 431 | int i; |
| 432 | |
| 433 | get_backup_values(&back); |
| 434 | if(!overwrite) { |
| 435 | if(strncmp(back.signature,"MPL\0",4)==0) { |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 436 | puts("Not possible to write Backup\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 437 | return; |
| 438 | } |
| 439 | } |
| 440 | memcpy(back.signature,"MPL\0",4); |
Wolfgang Denk | 76af278 | 2010-07-24 21:55:43 +0200 | [diff] [blame] | 441 | i = getenv_f("serial#",back.serial_name,16); |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 442 | if(i < 0) { |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 443 | puts("Not possible to write Backup\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 444 | return; |
| 445 | } |
| 446 | back.serial_name[16]=0; |
Wolfgang Denk | 76af278 | 2010-07-24 21:55:43 +0200 | [diff] [blame] | 447 | i = getenv_f("ethaddr",back.eth_addr,20); |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 448 | if(i < 0) { |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 449 | puts("Not possible to write Backup\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 450 | return; |
| 451 | } |
| 452 | back.eth_addr[20]=0; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 453 | i2c_write(CONFIG_SYS_DEF_EEPROM_ADDR, I2C_BACKUP_ADDR,2,(void *)&back,sizeof(backup_t)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | void clear_env_values(void) |
| 457 | { |
| 458 | backup_t back; |
| 459 | unsigned char env_crc[4]; |
| 460 | |
| 461 | memset(&back,0xff,sizeof(backup_t)); |
| 462 | memset(env_crc,0x00,4); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 463 | i2c_write(CONFIG_SYS_DEF_EEPROM_ADDR,I2C_BACKUP_ADDR,2,(void *)&back,sizeof(backup_t)); |
| 464 | i2c_write(CONFIG_SYS_DEF_EEPROM_ADDR,CONFIG_ENV_OFFSET,2,(void *)env_crc,4); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | /* |
| 468 | * check crc of "older" environment |
| 469 | */ |
| 470 | int check_env_old_size(ulong oldsize) |
| 471 | { |
| 472 | ulong crc, len, new; |
| 473 | unsigned off; |
| 474 | uchar buf[64]; |
| 475 | |
| 476 | /* read old CRC */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 477 | eeprom_read (CONFIG_SYS_DEF_EEPROM_ADDR, |
Jean-Christophe PLAGNIOL-VILLARD | 7e1cda6 | 2008-09-10 22:48:06 +0200 | [diff] [blame] | 478 | CONFIG_ENV_OFFSET, |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 479 | (uchar *)&crc, sizeof(ulong)); |
| 480 | |
| 481 | new = 0; |
| 482 | len = oldsize; |
| 483 | off = sizeof(long); |
| 484 | len = oldsize-off; |
| 485 | while (len > 0) { |
| 486 | int n = (len > sizeof(buf)) ? sizeof(buf) : len; |
| 487 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 488 | eeprom_read (CONFIG_SYS_DEF_EEPROM_ADDR, CONFIG_ENV_OFFSET+off, buf, n); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 489 | new = crc32 (new, buf, n); |
| 490 | len -= n; |
| 491 | off += n; |
| 492 | } |
| 493 | |
| 494 | return (crc == new); |
| 495 | } |
| 496 | |
| 497 | static ulong oldsizes[] = { |
| 498 | 0x200, |
| 499 | 0x800, |
| 500 | 0 |
| 501 | }; |
| 502 | |
| 503 | void copy_old_env(ulong size) |
| 504 | { |
| 505 | uchar name_buf[64]; |
| 506 | uchar value_buf[0x800]; |
| 507 | uchar c; |
| 508 | ulong len; |
| 509 | unsigned off; |
| 510 | uchar *name, *value; |
| 511 | |
Wolfgang Denk | dc770c7 | 2008-07-14 15:19:07 +0200 | [diff] [blame] | 512 | name = &name_buf[0]; |
| 513 | value = &value_buf[0]; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 514 | len=size; |
| 515 | off = sizeof(long); |
| 516 | while (len > off) { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 517 | eeprom_read (CONFIG_SYS_DEF_EEPROM_ADDR, CONFIG_ENV_OFFSET+off, &c, 1); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 518 | if(c != '=') { |
| 519 | *name++=c; |
| 520 | off++; |
| 521 | } |
| 522 | else { |
| 523 | *name++='\0'; |
| 524 | off++; |
| 525 | do { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 526 | eeprom_read (CONFIG_SYS_DEF_EEPROM_ADDR, CONFIG_ENV_OFFSET+off, &c, 1); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 527 | *value++=c; |
| 528 | off++; |
| 529 | if(c == '\0') |
| 530 | break; |
| 531 | } while(len > off); |
Wolfgang Denk | dc770c7 | 2008-07-14 15:19:07 +0200 | [diff] [blame] | 532 | name = &name_buf[0]; |
| 533 | value = &value_buf[0]; |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 534 | if(strncmp((char *)name,"baudrate",8)!=0) { |
| 535 | setenv((char *)name,(char *)value); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | } |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | |
| 543 | void check_env(void) |
| 544 | { |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 545 | char *s; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 546 | int i=0; |
| 547 | char buf[32]; |
| 548 | backup_t back; |
| 549 | |
| 550 | s=getenv("serial#"); |
| 551 | if(!s) { |
| 552 | while(oldsizes[i]) { |
| 553 | if(check_env_old_size(oldsizes[i])) |
| 554 | break; |
| 555 | i++; |
| 556 | } |
| 557 | if(!oldsizes[i]) { |
| 558 | /* no old environment has been found */ |
| 559 | get_backup_values (&back); |
| 560 | if (strncmp (back.signature, "MPL\0", 4) == 0) { |
| 561 | sprintf (buf, "%s", back.serial_name); |
| 562 | setenv ("serial#", buf); |
| 563 | sprintf (buf, "%s", back.eth_addr); |
| 564 | setenv ("ethaddr", buf); |
| 565 | printf ("INFO: serial# and ethaddr recovered, use saveenv\n"); |
| 566 | return; |
| 567 | } |
| 568 | } |
| 569 | else { |
| 570 | copy_old_env(oldsizes[i]); |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 571 | puts("INFO: old environment ajusted, use saveenv\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 572 | } |
| 573 | } |
| 574 | else { |
| 575 | /* check if back up is set */ |
| 576 | get_backup_values(&back); |
| 577 | if(strncmp(back.signature,"MPL\0",4)!=0) { |
| 578 | set_backup_values(0); |
| 579 | } |
| 580 | } |
| 581 | } |
| 582 | |
wdenk | bc01dd5 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 583 | #endif /* #if !defined(CONFIG_PATI) */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 584 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 585 | int do_mplcommon(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 586 | { |
Peter Tyser | e9b1b49 | 2010-10-05 23:48:47 -0500 | [diff] [blame] | 587 | ulong ld_addr; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 588 | int result; |
wdenk | bc01dd5 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 589 | #if !defined(CONFIG_PATI) |
Peter Tyser | e9b1b49 | 2010-10-05 23:48:47 -0500 | [diff] [blame] | 590 | ulong size = IMAGE_SIZE; |
| 591 | ulong src = MULTI_PURPOSE_SOCKET_ADDR; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 592 | backup_t back; |
wdenk | bc01dd5 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 593 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 594 | |
| 595 | if (strcmp(argv[1], "flash") == 0) |
| 596 | { |
Jon Loeliger | 145318c | 2007-07-09 18:38:39 -0500 | [diff] [blame] | 597 | #if defined(CONFIG_CMD_FDC) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 598 | if (strcmp(argv[2], "floppy") == 0) { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 599 | char *local_args[3]; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 600 | extern int do_fdcboot (cmd_tbl_t *, int, int, char *[]); |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 601 | puts("\nupdating bootloader image from floppy\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 602 | local_args[0] = argv[0]; |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 603 | if(argc==4) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 604 | local_args[1] = argv[3]; |
| 605 | local_args[2] = NULL; |
| 606 | ld_addr=simple_strtoul(argv[3], NULL, 16); |
| 607 | result=do_fdcboot(cmdtp, 0, 2, local_args); |
| 608 | } |
| 609 | else { |
| 610 | local_args[1] = NULL; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 611 | ld_addr=CONFIG_SYS_LOAD_ADDR; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 612 | result=do_fdcboot(cmdtp, 0, 1, local_args); |
| 613 | } |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 614 | result=mpl_prg_image((uchar *)ld_addr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 615 | return result; |
| 616 | } |
Jon Loeliger | 145318c | 2007-07-09 18:38:39 -0500 | [diff] [blame] | 617 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 618 | if (strcmp(argv[2], "mem") == 0) { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 619 | if(argc==4) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 620 | ld_addr=simple_strtoul(argv[3], NULL, 16); |
| 621 | } |
| 622 | else { |
| 623 | ld_addr=load_addr; |
| 624 | } |
| 625 | printf ("\nupdating bootloader image from memory at %lX\n",ld_addr); |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 626 | result=mpl_prg_image((uchar *)ld_addr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 627 | return result; |
| 628 | } |
wdenk | bc01dd5 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 629 | #if !defined(CONFIG_PATI) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 630 | if (strcmp(argv[2], "mps") == 0) { |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 631 | puts("\nupdating bootloader image from MPS\n"); |
| 632 | result=mpl_prg((uchar *)src,size); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 633 | return result; |
| 634 | } |
wdenk | bc01dd5 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 635 | #endif /* #if !defined(CONFIG_PATI) */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 636 | } |
wdenk | bc01dd5 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 637 | #if !defined(CONFIG_PATI) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 638 | if (strcmp(argv[1], "clearenvvalues") == 0) |
| 639 | { |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 640 | if (strcmp(argv[2], "yes") == 0) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 641 | { |
| 642 | clear_env_values(); |
| 643 | return 0; |
| 644 | } |
| 645 | } |
| 646 | if (strcmp(argv[1], "getback") == 0) { |
| 647 | get_backup_values(&back); |
| 648 | back.signature[3]=0; |
| 649 | back.serial_name[16]=0; |
| 650 | back.eth_addr[20]=0; |
| 651 | printf("GetBackUp: signature: %s\n",back.signature); |
| 652 | printf(" serial#: %s\n",back.serial_name); |
| 653 | printf(" ethaddr: %s\n",back.eth_addr); |
| 654 | return 0; |
| 655 | } |
| 656 | if (strcmp(argv[1], "setback") == 0) { |
| 657 | set_backup_values(1); |
| 658 | return 0; |
| 659 | } |
wdenk | bc01dd5 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 660 | #endif |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 661 | return cmd_usage(cmdtp); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | |
Jon Loeliger | 145318c | 2007-07-09 18:38:39 -0500 | [diff] [blame] | 665 | #if defined(CONFIG_CMD_DOC) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 666 | void doc_init (void) |
| 667 | { |
| 668 | doc_probe(MULTI_PURPOSE_SOCKET_ADDR); |
| 669 | } |
| 670 | #endif |
| 671 | |
| 672 | |
| 673 | #ifdef CONFIG_VIDEO |
| 674 | /****************************************************** |
| 675 | * Routines to display the Board information |
| 676 | * to the screen (since the VGA will be initialized as last, |
| 677 | * we must resend the infos) |
| 678 | */ |
| 679 | |
| 680 | #ifdef CONFIG_CONSOLE_EXTRA_INFO |
| 681 | extern GraphicDevice ctfb; |
wdenk | 2c9b05d | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 682 | extern int get_boot_mode(void); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 683 | |
| 684 | void video_get_info_str (int line_number, char *info) |
| 685 | { |
| 686 | /* init video info strings for graphic console */ |
Stefan Roese | edd73f2 | 2007-10-21 08:12:41 +0200 | [diff] [blame] | 687 | PPC4xx_SYS_INFO sys_info; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 688 | char rev; |
wdenk | 7d07641 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 689 | int i,boot; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 690 | unsigned long pvr; |
| 691 | char buf[64]; |
Wolfgang Denk | 2059104 | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 692 | char buf1[32], buf2[32], buf3[32], buf4[32]; |
wdenk | 7d07641 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 693 | char cpustr[16]; |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 694 | char *s, *e, bc; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 695 | switch (line_number) |
| 696 | { |
| 697 | case 2: |
| 698 | /* CPU and board infos */ |
| 699 | pvr=get_pvr(); |
| 700 | get_sys_info (&sys_info); |
| 701 | switch (pvr) { |
| 702 | case PVR_405GP_RB: rev='B'; break; |
| 703 | case PVR_405GP_RC: rev='C'; break; |
| 704 | case PVR_405GP_RD: rev='D'; break; |
| 705 | case PVR_405GP_RE: rev='E'; break; |
wdenk | 7d07641 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 706 | case PVR_405GPR_RB: rev='B'; break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 707 | default: rev='?'; break; |
| 708 | } |
wdenk | 7d07641 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 709 | if(pvr==PVR_405GPR_RB) |
| 710 | sprintf(cpustr,"PPC405GPr %c",rev); |
| 711 | else |
| 712 | sprintf(cpustr,"PPC405GP %c",rev); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 713 | /* Board info */ |
| 714 | i=0; |
| 715 | s=getenv ("serial#"); |
| 716 | #ifdef CONFIG_PIP405 |
| 717 | if (!s || strncmp (s, "PIP405", 6)) { |
| 718 | sprintf(buf,"### No HW ID - assuming PIP405"); |
| 719 | } |
| 720 | #endif |
| 721 | #ifdef CONFIG_MIP405 |
| 722 | if (!s || strncmp (s, "MIP405", 6)) { |
| 723 | sprintf(buf,"### No HW ID - assuming MIP405"); |
| 724 | } |
| 725 | #endif |
| 726 | else { |
| 727 | for (e = s; *e; ++e) { |
| 728 | if (*e == ' ') |
| 729 | break; |
| 730 | } |
| 731 | for (; s < e; ++s) { |
| 732 | if (*s == '_') { |
| 733 | ++s; |
| 734 | break; |
| 735 | } |
Wolfgang Denk | dc770c7 | 2008-07-14 15:19:07 +0200 | [diff] [blame] | 736 | buf[i++] = *s; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 737 | } |
| 738 | sprintf(&buf[i]," SN "); |
| 739 | i+=4; |
| 740 | for (; s < e; ++s) { |
Wolfgang Denk | dc770c7 | 2008-07-14 15:19:07 +0200 | [diff] [blame] | 741 | buf[i++] = *s; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 742 | } |
| 743 | buf[i++]=0; |
| 744 | } |
Wolfgang Denk | 2059104 | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 745 | sprintf (info," %s %s %s MHz (%s/%s/%s MHz)", |
wdenk | 7d07641 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 746 | buf, cpustr, |
Wolfgang Denk | 2059104 | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 747 | strmhz (buf1, gd->cpu_clk), |
| 748 | strmhz (buf2, sys_info.freqPLB), |
| 749 | strmhz (buf3, sys_info.freqPLB / sys_info.pllOpbDiv), |
| 750 | strmhz (buf4, sys_info.freqPLB / sys_info.pllExtBusDiv)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 751 | return; |
| 752 | case 3: |
| 753 | /* Memory Info */ |
wdenk | 7d07641 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 754 | boot = get_boot_mode(); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 755 | bc = in8 (CONFIG_PORT_ADDR); |
| 756 | sprintf(info, " %luMB RAM, %luMB Flash Cfg 0x%02X %s %s", |
| 757 | gd->bd->bi_memsize / 0x100000, |
| 758 | gd->bd->bi_flashsize / 0x100000, |
| 759 | bc, |
wdenk | 7d07641 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 760 | (boot & BOOT_MPS) ? "MPS boot" : "Flash boot", |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 761 | ctfb.modeIdent); |
| 762 | return; |
| 763 | case 1: |
| 764 | sprintf (buf, "%s",CONFIG_IDENT_STRING); |
| 765 | sprintf (info, " %s", &buf[1]); |
| 766 | return; |
| 767 | } |
| 768 | /* no more info lines */ |
| 769 | *info = 0; |
| 770 | return; |
| 771 | } |
| 772 | #endif /* CONFIG_CONSOLE_EXTRA_INFO */ |
| 773 | |
| 774 | #endif /* CONFIG_VIDEO */ |