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