common_util.c 18 KB

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