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