common_util.c 17 KB

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