L1.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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 <4xx_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 (uicsr, 0xFFFFFFFF); /* clear all ints */
  106. mtdcr (uicer, 0x00000000); /* disable all ints */
  107. mtdcr (uiccr, 0x00000020); /* set all but FPGA SMI to be non-critical */
  108. mtdcr (uicpr, 0xFFFFFFE0); /* set int polarities */
  109. mtdcr (uictr, 0x10000000); /* set int trigger levels */
  110. mtdcr (uicvcr, 0x00000001); /* set vect base=0,INT0 highest priority */
  111. mtdcr (uicsr, 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 *) (CFG_MONITOR_BASE - image_get_header_size ());
  129. timestamp = (time_t)image_get_time (hdr);
  130. to_tm (timestamp, &tm);
  131. 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);
  132. #define FACTORY_SETTINGS 0xFFFC0000
  133. if ((s = getenv ("ethaddr")) == NULL) {
  134. e = (char *) (FACTORY_SETTINGS);
  135. if (*(e + 0) != '0'
  136. || *(e + 1) != '0'
  137. || *(e + 2) != ':'
  138. || *(e + 3) != '4' || *(e + 4) != '0' || *(e + 17) != '\0') {
  139. printf ("No valid MAC address in flash location 0x3C0000!\n");
  140. } else {
  141. printf ("Factory MAC: %s\n", e);
  142. setenv ("ethaddr", e);
  143. }
  144. }
  145. sprintf (bootcmd,"autoscript %X",(unsigned)bootscript);
  146. setenv ("bootcmd", bootcmd);
  147. return (0);
  148. }
  149. /* ------------------------------------------------------------------------- */
  150. long int initdram (int board_type)
  151. {
  152. return (L1_MEMSIZE);
  153. }
  154. /* ------------------------------------------------------------------------- */
  155. /* stubs so we can print dates w/o any nvram RTC.*/
  156. void rtc_get (struct rtc_time *tmp)
  157. {
  158. return;
  159. }
  160. void rtc_set (struct rtc_time *tmp)
  161. {
  162. return;
  163. }
  164. void rtc_reset (void)
  165. {
  166. return;
  167. }
  168. /* ------------------------------------------------------------------------- */
  169. /* Do sdram bank init in C so I can read it..no console to print to yet!
  170. */
  171. static void init_sdram (void)
  172. {
  173. unsigned long tmp;
  174. /* write SDRAM bank 0 register */
  175. mtdcr (memcfga, mem_mb0cf);
  176. mtdcr (memcfgd, 0x00062001);
  177. /* Set the SDRAM Timing reg, SDTR1 and the refresh timer reg, RTR. */
  178. /* To set the appropriate timings, we need to know the SDRAM speed. */
  179. /* We can use the PLB speed since the SDRAM speed is the same as */
  180. /* the PLB speed. The PLB speed is the FBK divider times the */
  181. /* 405GP reference clock, which on the L1 is 25Mhz. */
  182. /* Thus, if FBK div is 2, SDRAM is 50Mhz; if FBK div is 3, SDRAM is */
  183. /* 150Mhz; if FBK is 3, SDRAM is 150Mhz. */
  184. /* divisor = ((mfdcr(strap)>> 28) & 0x3); */
  185. /* write SDRAM timing for 100Mhz. */
  186. mtdcr (memcfga, mem_sdtr1);
  187. mtdcr (memcfgd, 0x0086400D);
  188. /* write SDRAM refresh interval register */
  189. mtdcr (memcfga, mem_rtr);
  190. mtdcr (memcfgd, 0x05F00000);
  191. udelay (200);
  192. /* sdram controller.*/
  193. mtdcr (memcfga, mem_mcopt1);
  194. mtdcr (memcfgd, 0x90800000);
  195. udelay (200);
  196. /* initially, disable ECC on all banks */
  197. udelay (200);
  198. mtdcr (memcfga, mem_ecccf);
  199. tmp = mfdcr (memcfgd);
  200. tmp &= 0xff0fffff;
  201. mtdcr (memcfga, mem_ecccf);
  202. mtdcr (memcfgd, tmp);
  203. return;
  204. }
  205. extern int memory_post_test (int flags);
  206. int testdram (void)
  207. {
  208. unsigned long tmp;
  209. uint *pstart = (uint *) 0x00000000;
  210. uint *pend = (uint *) L1_MEMSIZE;
  211. uint *p;
  212. if (getenv_r("booted",NULL,0) <= 0)
  213. {
  214. printf ("testdram..");
  215. /*AA*/
  216. for (p = pstart; p < pend; p++)
  217. *p = 0xaaaaaaaa;
  218. for (p = pstart; p < pend; p++) {
  219. if (*p != 0xaaaaaaaa) {
  220. printf ("SDRAM test fails at: %08x, was %08x expected %08x\n",
  221. (uint) p, *p, 0xaaaaaaaa);
  222. return 1;
  223. }
  224. }
  225. /*55*/
  226. for (p = pstart; p < pend; p++)
  227. *p = 0x55555555;
  228. for (p = pstart; p < pend; p++) {
  229. if (*p != 0x55555555) {
  230. printf ("SDRAM test fails at: %08x, was %08x expected %08x\n",
  231. (uint) p, *p, 0x55555555);
  232. return 1;
  233. }
  234. }
  235. /*addr*/
  236. for (p = pstart; p < pend; p++)
  237. *p = (unsigned)p;
  238. for (p = pstart; p < pend; p++) {
  239. if (*p != (unsigned)p) {
  240. printf ("SDRAM test fails at: %08x, was %08x expected %08x\n",
  241. (uint) p, *p, (uint)p);
  242. return 1;
  243. }
  244. }
  245. printf ("Success. ");
  246. }
  247. printf ("Enable ECC..");
  248. mtdcr (memcfga, mem_mcopt1);
  249. tmp = (mfdcr (memcfgd) & ~0xFFE00000) | 0x90800000;
  250. mtdcr (memcfga, mem_mcopt1);
  251. mtdcr (memcfgd, tmp);
  252. udelay (600);
  253. for (p = (unsigned long) 0; ((unsigned long) p < L1_MEMSIZE); *p++ = 0L)
  254. ;
  255. udelay (400);
  256. mtdcr (memcfga, mem_ecccf);
  257. tmp = mfdcr (memcfgd);
  258. tmp |= 0x00800000;
  259. mtdcr (memcfgd, tmp);
  260. udelay (400);
  261. printf ("enabled.\n");
  262. return (0);
  263. }
  264. /* ------------------------------------------------------------------------- */
  265. static u8 *dhcp_env_update (u8 thing, u8 * pop)
  266. {
  267. u8 i, oplen;
  268. oplen = *(pop + 1);
  269. if ((Things[thing].dhcpvalue = malloc (oplen)) == NULL) {
  270. printf ("Whoops! failed to malloc space for DHCP thing %s\n",
  271. Things[thing].envname);
  272. return NULL;
  273. }
  274. for (i = 0; (i < oplen); i++)
  275. if ((*(Things[thing].dhcpvalue + i) = *(pop + 2 + i)) == ' ')
  276. break;
  277. *(Things[thing].dhcpvalue + i) = '\0';
  278. /* set env. */
  279. if (Things[thing].envname)
  280. {
  281. setenv (Things[thing].envname, Things[thing].dhcpvalue);
  282. }
  283. return ((u8 *)(Things[thing].dhcpvalue));
  284. }
  285. /* ------------------------------------------------------------------------- */
  286. u8 *dhcp_vendorex_prep (u8 * e)
  287. {
  288. u8 thing;
  289. /* ask for the things I want. */
  290. *e++ = 55; /* Parameter Request List */
  291. *e++ = N_THINGS;
  292. for (thing = 0; thing < N_THINGS; thing++)
  293. *e++ = Things[thing].dhcp_option;
  294. *e++ = 255;
  295. return e;
  296. }
  297. /* ------------------------------------------------------------------------- */
  298. /* .. return NULL means it wasnt mine, non-null means I got it..*/
  299. u8 *dhcp_vendorex_proc (u8 * pop)
  300. {
  301. u8 oplen, *sub_op, sub_oplen, *retval;
  302. u8 thing = 0;
  303. retval = NULL;
  304. oplen = *(pop + 1);
  305. /* if pop is vender spec indicator, there are sub-options. */
  306. if (*pop == DHCP_VENDOR_SPECX) {
  307. for (sub_op = pop + 2;
  308. oplen && (sub_oplen = *(sub_op + 1));
  309. oplen -= sub_oplen, sub_op += (sub_oplen + 2)) {
  310. for (thing = 0; thing < N_THINGS; thing++) {
  311. if (*sub_op == Things[thing].dhcp_vendor_option) {
  312. if (!(retval = dhcp_env_update (thing, sub_op))) {
  313. return NULL;
  314. }
  315. }
  316. }
  317. }
  318. } else {
  319. for (thing = 0; thing < N_THINGS; thing++) {
  320. if (*pop == Things[thing].dhcp_option)
  321. if (!(retval = dhcp_env_update (thing, pop)))
  322. return NULL;
  323. }
  324. }
  325. return (pop);
  326. }