common_util.c 17 KB

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