L1.c 10 KB

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