L1.c 10 KB

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