L1.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. /*
  2. * (C) Copyright 2000
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  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. #include <common.h>
  24. #include <asm/processor.h>
  25. #include <asm/ppc4xx-i2c.h>
  26. #include <command.h>
  27. #include <rtc.h>
  28. #include <post.h>
  29. #include <net.h>
  30. #include <malloc.h>
  31. #define L1_MEMSIZE (32*1024*1024)
  32. /* the std. DHCP stufff */
  33. #define DHCP_ROUTER 3
  34. #define DHCP_NETMASK 1
  35. #define DHCP_BOOTFILE 67
  36. #define DHCP_ROOTPATH 17
  37. #define DHCP_HOSTNAME 12
  38. /* some extras used by CRAY
  39. *
  40. * on the server this looks like:
  41. *
  42. * option L1-initrd-image code 224 = string;
  43. * option L1-initrd-image "/opt/craysv2/craymcu/l1/flash/initrd.image"
  44. */
  45. #define DHCP_L1_INITRD 224
  46. /* new, [better?] way via official vendor-extensions, defining an option
  47. * space.
  48. * on the server this looks like:
  49. *
  50. * option space CRAYL1;
  51. * option CRAYL1.initrd code 3 = string;
  52. * ..etc...
  53. */
  54. #define DHCP_VENDOR_SPECX 43
  55. #define DHCP_VX_INITRD 3
  56. #define DHCP_VX_BOOTCMD 4
  57. #define DHCP_VX_BOOTARGS 5
  58. #define DHCP_VX_ROOTDEV 6
  59. #define DHCP_VX_FROMFLASH 7
  60. #define DHCP_VX_BOOTSCRIPT 8
  61. #define DHCP_VX_RCFILE 9
  62. #define DHCP_VX_MAGIC 10
  63. /* Things DHCP server can tellme about. If there's no flash address, then
  64. * they dont participate in 'update' to flash, and we force their values
  65. * back to '0' every boot to be sure to get them fresh from DHCP. Yes, I
  66. * know this is a pain...
  67. *
  68. * If I get no bootfile, boot from flash. If rootpath, use that. If no
  69. * rootpath use initrd in flash.
  70. */
  71. typedef struct dhcp_item_s {
  72. u8 dhcp_option;
  73. u8 dhcp_vendor_option;
  74. char *dhcpvalue;
  75. char *envname;
  76. } dhcp_item_t;
  77. static dhcp_item_t Things[] = {
  78. {DHCP_ROUTER, 0, NULL, "gateway"},
  79. {DHCP_NETMASK, 0, NULL, "netmask"},
  80. {DHCP_BOOTFILE, 0, NULL, "bootfile"},
  81. {DHCP_ROOTPATH, 0, NULL, "rootpath"},
  82. {DHCP_HOSTNAME, 0, NULL, "hostname"},
  83. {DHCP_L1_INITRD, 0, NULL, "initrd"},
  84. /* and the other way.. */
  85. {DHCP_VENDOR_SPECX, DHCP_VX_INITRD, NULL, "initrd"},
  86. {DHCP_VENDOR_SPECX, DHCP_VX_BOOTCMD, NULL, "bootcmd"},
  87. {DHCP_VENDOR_SPECX, DHCP_VX_FROMFLASH, NULL, "fromflash"},
  88. {DHCP_VENDOR_SPECX, DHCP_VX_BOOTSCRIPT, NULL, "bootscript"},
  89. {DHCP_VENDOR_SPECX, DHCP_VX_RCFILE, NULL, "rcfile"},
  90. {DHCP_VENDOR_SPECX, DHCP_VX_BOOTARGS, NULL, "xbootargs"},
  91. {DHCP_VENDOR_SPECX, DHCP_VX_ROOTDEV, NULL, NULL},
  92. {DHCP_VENDOR_SPECX, DHCP_VX_MAGIC, NULL, NULL}
  93. };
  94. #define N_THINGS ((sizeof(Things))/(sizeof(dhcp_item_t)))
  95. extern char bootscript[];
  96. /* Here is the boot logic as HUSH script. Overridden by any TFP provided
  97. * bootscript file.
  98. */
  99. static void init_sdram (void);
  100. /* ------------------------------------------------------------------------- */
  101. int board_early_init_f (void)
  102. {
  103. /* Running from ROM: global data is still READONLY */
  104. init_sdram ();
  105. mtdcr (UIC0SR, 0xFFFFFFFF); /* clear all ints */
  106. mtdcr (UIC0ER, 0x00000000); /* disable all ints */
  107. mtdcr (UIC0CR, 0x00000020); /* set all but FPGA SMI to be non-critical */
  108. mtdcr (UIC0PR, 0xFFFFFFE0); /* set int polarities */
  109. mtdcr (UIC0TR, 0x10000000); /* set int trigger levels */
  110. mtdcr (UIC0VCR, 0x00000001); /* set vect base=0,INT0 highest priority */
  111. mtdcr (UIC0SR, 0xFFFFFFFF); /* clear all ints */
  112. return 0;
  113. }
  114. /* ------------------------------------------------------------------------- */
  115. int checkboard (void)
  116. {
  117. return (0);
  118. }
  119. /* ------------------------------------------------------------------------- */
  120. /* ------------------------------------------------------------------------- */
  121. int misc_init_r (void)
  122. {
  123. char *s, *e;
  124. image_header_t *hdr;
  125. time_t timestamp;
  126. struct rtc_time tm;
  127. char bootcmd[32];
  128. hdr = (image_header_t *) (CONFIG_SYS_MONITOR_BASE - image_get_header_size ());
  129. #if defined(CONFIG_FIT)
  130. if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) {
  131. puts ("Non legacy image format not supported\n");
  132. return -1;
  133. }
  134. #endif
  135. timestamp = (time_t)image_get_time (hdr);
  136. to_tm (timestamp, &tm);
  137. printf ("Welcome to U-Boot on Cray L1. Compiled %4d-%02d-%02d %2d:%02d:%02d (UTC)\n", tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  138. #define FACTORY_SETTINGS 0xFFFC0000
  139. if ((s = getenv ("ethaddr")) == NULL) {
  140. e = (char *) (FACTORY_SETTINGS);
  141. if (*(e + 0) != '0'
  142. || *(e + 1) != '0'
  143. || *(e + 2) != ':'
  144. || *(e + 3) != '4' || *(e + 4) != '0' || *(e + 17) != '\0') {
  145. printf ("No valid MAC address in flash location 0x3C0000!\n");
  146. } else {
  147. printf ("Factory MAC: %s\n", e);
  148. setenv ("ethaddr", e);
  149. }
  150. }
  151. sprintf (bootcmd,"source %X",(unsigned)bootscript);
  152. setenv ("bootcmd", bootcmd);
  153. return (0);
  154. }
  155. /* ------------------------------------------------------------------------- */
  156. /* stubs so we can print dates w/o any nvram RTC.*/
  157. int rtc_get (struct rtc_time *tmp)
  158. {
  159. return 0;
  160. }
  161. int rtc_set (struct rtc_time *tmp)
  162. {
  163. return 0;
  164. }
  165. void rtc_reset (void)
  166. {
  167. return;
  168. }
  169. /* ------------------------------------------------------------------------- */
  170. /* Do sdram bank init in C so I can read it..no console to print to yet!
  171. */
  172. static void init_sdram (void)
  173. {
  174. unsigned long tmp;
  175. /* write SDRAM bank 0 register */
  176. mtdcr (SDRAM0_CFGADDR, SDRAM0_B0CR);
  177. mtdcr (SDRAM0_CFGDATA, 0x00062001);
  178. /* Set the SDRAM Timing reg, SDTR1 and the refresh timer reg, RTR. */
  179. /* To set the appropriate timings, we need to know the SDRAM speed. */
  180. /* We can use the PLB speed since the SDRAM speed is the same as */
  181. /* the PLB speed. The PLB speed is the FBK divider times the */
  182. /* 405GP reference clock, which on the L1 is 25MHz. */
  183. /* Thus, if FBK div is 2, SDRAM is 50MHz; if FBK div is 3, SDRAM is */
  184. /* 150MHz; if FBK is 3, SDRAM is 150MHz. */
  185. /* divisor = ((mfdcr(strap)>> 28) & 0x3); */
  186. /* write SDRAM timing for 100MHz. */
  187. mtdcr (SDRAM0_CFGADDR, SDRAM0_TR);
  188. mtdcr (SDRAM0_CFGDATA, 0x0086400D);
  189. /* write SDRAM refresh interval register */
  190. mtdcr (SDRAM0_CFGADDR, SDRAM0_RTR);
  191. mtdcr (SDRAM0_CFGDATA, 0x05F00000);
  192. udelay (200);
  193. /* sdram controller.*/
  194. mtdcr (SDRAM0_CFGADDR, SDRAM0_CFG);
  195. mtdcr (SDRAM0_CFGDATA, 0x90800000);
  196. udelay (200);
  197. /* initially, disable ECC on all banks */
  198. udelay (200);
  199. mtdcr (SDRAM0_CFGADDR, SDRAM0_ECCCFG);
  200. tmp = mfdcr (SDRAM0_CFGDATA);
  201. tmp &= 0xff0fffff;
  202. mtdcr (SDRAM0_CFGADDR, SDRAM0_ECCCFG);
  203. mtdcr (SDRAM0_CFGDATA, tmp);
  204. return;
  205. }
  206. extern int memory_post_test (int flags);
  207. int testdram (void)
  208. {
  209. unsigned long tmp;
  210. uint *pstart = (uint *) 0x00000000;
  211. uint *pend = (uint *) L1_MEMSIZE;
  212. uint *p;
  213. if (getenv_f("booted",NULL,0) <= 0)
  214. {
  215. printf ("testdram..");
  216. /*AA*/
  217. for (p = pstart; p < pend; p++)
  218. *p = 0xaaaaaaaa;
  219. for (p = pstart; p < pend; p++) {
  220. if (*p != 0xaaaaaaaa) {
  221. printf ("SDRAM test fails at: %08x, was %08x expected %08x\n",
  222. (uint) p, *p, 0xaaaaaaaa);
  223. return 1;
  224. }
  225. }
  226. /*55*/
  227. for (p = pstart; p < pend; p++)
  228. *p = 0x55555555;
  229. for (p = pstart; p < pend; p++) {
  230. if (*p != 0x55555555) {
  231. printf ("SDRAM test fails at: %08x, was %08x expected %08x\n",
  232. (uint) p, *p, 0x55555555);
  233. return 1;
  234. }
  235. }
  236. /*addr*/
  237. for (p = pstart; p < pend; p++)
  238. *p = (unsigned)p;
  239. for (p = pstart; p < pend; p++) {
  240. if (*p != (unsigned)p) {
  241. printf ("SDRAM test fails at: %08x, was %08x expected %08x\n",
  242. (uint) p, *p, (uint)p);
  243. return 1;
  244. }
  245. }
  246. printf ("Success. ");
  247. }
  248. printf ("Enable ECC..");
  249. mtdcr (SDRAM0_CFGADDR, SDRAM0_CFG);
  250. tmp = (mfdcr (SDRAM0_CFGDATA) & ~0xFFE00000) | 0x90800000;
  251. mtdcr (SDRAM0_CFGADDR, SDRAM0_CFG);
  252. mtdcr (SDRAM0_CFGDATA, tmp);
  253. udelay (600);
  254. for (p = (unsigned long) 0; ((unsigned long) p < L1_MEMSIZE); *p++ = 0L)
  255. ;
  256. udelay (400);
  257. mtdcr (SDRAM0_CFGADDR, SDRAM0_ECCCFG);
  258. tmp = mfdcr (SDRAM0_CFGDATA);
  259. tmp |= 0x00800000;
  260. mtdcr (SDRAM0_CFGDATA, tmp);
  261. udelay (400);
  262. printf ("enabled.\n");
  263. return (0);
  264. }
  265. /* ------------------------------------------------------------------------- */
  266. static u8 *dhcp_env_update (u8 thing, u8 * pop)
  267. {
  268. u8 i, oplen;
  269. oplen = *(pop + 1);
  270. if ((Things[thing].dhcpvalue = malloc (oplen)) == NULL) {
  271. printf ("Whoops! failed to malloc space for DHCP thing %s\n",
  272. Things[thing].envname);
  273. return NULL;
  274. }
  275. for (i = 0; (i < oplen); i++)
  276. if ((*(Things[thing].dhcpvalue + i) = *(pop + 2 + i)) == ' ')
  277. break;
  278. *(Things[thing].dhcpvalue + i) = '\0';
  279. /* set env. */
  280. if (Things[thing].envname)
  281. {
  282. setenv (Things[thing].envname, Things[thing].dhcpvalue);
  283. }
  284. return ((u8 *)(Things[thing].dhcpvalue));
  285. }
  286. /* ------------------------------------------------------------------------- */
  287. u8 *dhcp_vendorex_prep (u8 * e)
  288. {
  289. u8 thing;
  290. /* ask for the things I want. */
  291. *e++ = 55; /* Parameter Request List */
  292. *e++ = N_THINGS;
  293. for (thing = 0; thing < N_THINGS; thing++)
  294. *e++ = Things[thing].dhcp_option;
  295. *e++ = 255;
  296. return e;
  297. }
  298. /* ------------------------------------------------------------------------- */
  299. /* .. return NULL means it wasnt mine, non-null means I got it..*/
  300. u8 *dhcp_vendorex_proc (u8 * pop)
  301. {
  302. u8 oplen, *sub_op, sub_oplen, *retval;
  303. u8 thing = 0;
  304. retval = NULL;
  305. oplen = *(pop + 1);
  306. /* if pop is vender spec indicator, there are sub-options. */
  307. if (*pop == DHCP_VENDOR_SPECX) {
  308. for (sub_op = pop + 2;
  309. oplen && (sub_oplen = *(sub_op + 1));
  310. oplen -= sub_oplen, sub_op += (sub_oplen + 2)) {
  311. for (thing = 0; thing < N_THINGS; thing++) {
  312. if (*sub_op == Things[thing].dhcp_vendor_option) {
  313. if (!(retval = dhcp_env_update (thing, sub_op))) {
  314. return NULL;
  315. }
  316. }
  317. }
  318. }
  319. } else {
  320. for (thing = 0; thing < N_THINGS; thing++) {
  321. if (*pop == Things[thing].dhcp_option)
  322. if (!(retval = dhcp_env_update (thing, pop)))
  323. return NULL;
  324. }
  325. }
  326. return (pop);
  327. }