L1.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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 <rtc.h>
  30. #include <net.h>
  31. #include <malloc.h>
  32. #define L1_MEMSIZE (32*1024*1024)
  33. /* the std. DHCP stufff */
  34. #define DHCP_ROUTER 3
  35. #define DHCP_NETMASK 1
  36. #define DHCP_BOOTFILE 67
  37. #define DHCP_ROOTPATH 17
  38. #define DHCP_HOSTNAME 12
  39. /* some extras used by CRAY
  40. *
  41. * on the server this looks like:
  42. *
  43. * option L1-initrd-image code 224 = string;
  44. * option L1-initrd-image "/opt/craysv2/craymcu/l1/flash/initrd.image"
  45. */
  46. #define DHCP_L1_INITRD 224
  47. /* new, [better?] way via official vendor-extensions, defining an option
  48. * space.
  49. * on the server this looks like:
  50. *
  51. * option space U-Boot;
  52. * option U-Boot.initrd code 3 = string;
  53. * option U-Boot.bootcmd code 4 = string;
  54. * option U-Boot.bootflags code 5 = string;
  55. * option U-Boot.rootdev code 6 = string;
  56. */
  57. #define DHCP_VENDOR_SPECX 43
  58. #define DHCP_VX_INITRD 3
  59. #define DHCP_VX_BOOTCMD 4
  60. #define DHCP_VX_BOOTFLAGS 5
  61. #define DHCP_VX_ROOTDEV 6
  62. /* Things DHCP server can tellme about. If there's no flash address, then
  63. * they dont participate in 'update' to flash, and we force their values
  64. * back to '0' every boot to be sure to get them fresh from DHCP. Yes, I
  65. * know this is a pain...
  66. *
  67. * If I get no bootfile, boot from flash. If rootpath, use that. If no
  68. * rootpath use initrd in flash.
  69. */
  70. typedef struct dhcp_item_s {
  71. u8 dhcp_option;
  72. u8 dhcp_vendor_option;
  73. char *dhcpvalue;
  74. char *envname;
  75. } dhcp_item_t;
  76. static dhcp_item_t Things[] = {
  77. {DHCP_ROUTER, 0, NULL, "gateway"},
  78. {DHCP_NETMASK, 0, NULL, "netmask"},
  79. {DHCP_BOOTFILE, 0, NULL, "bootfile"},
  80. {DHCP_ROOTPATH, 0, NULL, "rootpath"},
  81. {DHCP_HOSTNAME, 0, NULL, "hostname"},
  82. {DHCP_L1_INITRD, 0, NULL, "initrd"},
  83. /* and the other way.. */
  84. {DHCP_VENDOR_SPECX, DHCP_VX_INITRD, NULL, "initrd"},
  85. {DHCP_VENDOR_SPECX, DHCP_VX_BOOTCMD, NULL, "bootcmd"},
  86. {DHCP_VENDOR_SPECX, DHCP_VX_BOOTFLAGS, NULL, NULL},
  87. {DHCP_VENDOR_SPECX, DHCP_VX_ROOTDEV, NULL, NULL},
  88. };
  89. #define N_THINGS ((sizeof(Things))/(sizeof(dhcp_item_t)))
  90. static void init_ecc_sdram (void);
  91. /* ------------------------------------------------------------------------- */
  92. int board_pre_init (void)
  93. {
  94. init_ecc_sdram ();
  95. mtdcr (uicsr, 0xFFFFFFFF); /* clear all ints */
  96. mtdcr (uicer, 0x00000000); /* disable all ints */
  97. mtdcr (uiccr, 0x00000020); /* set all but FPGA SMI to be non-critical */
  98. mtdcr (uicpr, 0xFFFFFFE0); /* set int polarities */
  99. mtdcr (uictr, 0x10000000); /* set int trigger levels */
  100. mtdcr (uicvcr, 0x00000001); /* set vect base=0,INT0 highest priority */
  101. mtdcr (uicsr, 0xFFFFFFFF); /* clear all ints */
  102. return 0;
  103. }
  104. /* ------------------------------------------------------------------------- */
  105. int checkboard (void)
  106. {
  107. return (0);
  108. }
  109. /* ------------------------------------------------------------------------- */
  110. int misc_init_r (void)
  111. {
  112. unsigned char *s, *e;
  113. image_header_t *hdr;
  114. time_t timestamp;
  115. struct rtc_time tm;
  116. hdr = (image_header_t *) (CFG_MONITOR_BASE - sizeof (image_header_t));
  117. timestamp = (time_t) hdr->ih_time;
  118. to_tm (timestamp, &tm);
  119. 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);
  120. #define FACTORY_SETTINGS 0xFFFC0000
  121. if ((s = getenv ("ethaddr")) == NULL) {
  122. e = (unsigned char *) (FACTORY_SETTINGS);
  123. if (*(e + 0) != '0'
  124. || *(e + 1) != '0'
  125. || *(e + 2) != ':'
  126. || *(e + 3) != '4' || *(e + 4) != '0' || *(e + 17) != '\0') {
  127. printf ("No valid MAC address in flash location 0x3C0000!\n");
  128. } else {
  129. printf ("Factory MAC: %s\n", e);
  130. setenv ("ethaddr", e);
  131. }
  132. }
  133. return (0);
  134. }
  135. /* ------------------------------------------------------------------------- */
  136. long int initdram (int board_type)
  137. {
  138. return (L1_MEMSIZE);
  139. }
  140. /* ------------------------------------------------------------------------- */
  141. /* stubs so we can print dates w/o any nvram RTC.*/
  142. void rtc_get (struct rtc_time *tmp)
  143. {
  144. return;
  145. }
  146. void rtc_set (struct rtc_time *tmp)
  147. {
  148. return;
  149. }
  150. void rtc_reset (void)
  151. {
  152. return;
  153. }
  154. /* ------------------------------------------------------------------------- */
  155. /* Do sdram bank init in C so I can read it..
  156. */
  157. static void init_ecc_sdram (void)
  158. {
  159. unsigned long tmp, *p;
  160. /* write SDRAM bank 0 register */
  161. mtdcr (memcfga, mem_mb0cf);
  162. mtdcr (memcfgd, 0x00062001);
  163. /* Set the SDRAM Timing reg, SDTR1 and the refresh timer reg, RTR. */
  164. /* To set the appropriate timings, we need to know the SDRAM speed. */
  165. /* We can use the PLB speed since the SDRAM speed is the same as */
  166. /* the PLB speed. The PLB speed is the FBK divider times the */
  167. /* 405GP reference clock, which on the L1 is 25Mhz. */
  168. /* Thus, if FBK div is 2, SDRAM is 50Mhz; if FBK div is 3, SDRAM is */
  169. /* 150Mhz; if FBK is 3, SDRAM is 150Mhz. */
  170. /* divisor = ((mfdcr(strap)>> 28) & 0x3); */
  171. /* write SDRAM timing for 100Mhz. */
  172. mtdcr (memcfga, mem_sdtr1);
  173. mtdcr (memcfgd, 0x0086400D);
  174. /* write SDRAM refresh interval register */
  175. mtdcr (memcfga, mem_rtr);
  176. mtdcr (memcfgd, 0x05F00000);
  177. udelay (200);
  178. /* sdram controller.*/
  179. mtdcr (memcfga, mem_mcopt1);
  180. mtdcr (memcfgd, 0x90800000);
  181. udelay (200);
  182. /* disable ECC on all banks */
  183. mtdcr (memcfga, mem_ecccf);
  184. tmp = mfdcr (memcfgd);
  185. tmp &= 0xff0fffff;
  186. mtdcr (memcfga, mem_ecccf);
  187. mtdcr (memcfgd, tmp);
  188. /* set up SDRAM Controller with ECC enabled */
  189. mtdcr (memcfga, mem_mcopt1);
  190. tmp = (mfdcr (memcfgd) & ~0xFFE00000) | 0x90800000;
  191. mtdcr (memcfga, mem_mcopt1);
  192. mtdcr (memcfgd, tmp);
  193. udelay (600);
  194. /* fill all the memory */
  195. for (p = (unsigned long) 0; ((unsigned long) p < L1_MEMSIZE);
  196. *p++ = 0L);
  197. udelay (400);
  198. mtdcr (memcfga, mem_ecccf);
  199. tmp = mfdcr (memcfgd);
  200. /* enable ECC on bank 0 */
  201. tmp |= 0x00800000;
  202. mtdcr (memcfgd, tmp);
  203. udelay (400);
  204. return;
  205. }
  206. /* ------------------------------------------------------------------------- */
  207. static u8 *dhcp_env_update (u8 thing, u8 * pop)
  208. {
  209. u8 i, oplen;
  210. oplen = *(pop + 1);
  211. if ((Things[thing].dhcpvalue = malloc (oplen)) == NULL) {
  212. printf ("Whoops! failed to malloc space for DHCP thing %s\n",
  213. Things[thing].envname);
  214. return NULL;
  215. }
  216. for (i = 0; (i < oplen); i++)
  217. if ((*(Things[thing].dhcpvalue + i) = *(pop + 2 + i)) == ' ')
  218. break;
  219. *(Things[thing].dhcpvalue + i) = '\0';
  220. /* set env. */
  221. if (Things[thing].envname)
  222. setenv (Things[thing].envname, Things[thing].dhcpvalue);
  223. return (Things[thing].dhcpvalue);
  224. }
  225. /* ------------------------------------------------------------------------- */
  226. u8 *dhcp_vendorex_prep (u8 * e)
  227. {
  228. u8 thing;
  229. /* ask for the things I want. */
  230. *e++ = 55; /* Parameter Request List */
  231. *e++ = N_THINGS;
  232. for (thing = 0; thing < N_THINGS; thing++)
  233. *e++ = Things[thing].dhcp_option;
  234. *e++ = 255;
  235. return e;
  236. }
  237. /* ------------------------------------------------------------------------- */
  238. /* .. return NULL means it wasnt mine, non-null means I got it..*/
  239. u8 *dhcp_vendorex_proc (u8 * pop)
  240. {
  241. u8 oplen, *sub_op, sub_oplen, *retval;
  242. u8 thing = 0;
  243. retval = NULL;
  244. oplen = *(pop + 1);
  245. /* if pop is vender spec indicator, there are sub-options. */
  246. if (*pop == DHCP_VENDOR_SPECX) {
  247. for (sub_op = pop + 2;
  248. oplen && (sub_oplen = *(sub_op + 1));
  249. oplen -= sub_oplen, sub_op += (sub_oplen + 2)) {
  250. for (thing = 0; thing < N_THINGS; thing++) {
  251. if (*sub_op == Things[thing].dhcp_vendor_option) {
  252. if (!(retval = dhcp_env_update (thing, sub_op))) {
  253. return NULL;
  254. }
  255. }
  256. }
  257. }
  258. } else {
  259. for (thing = 0; thing < N_THINGS; thing++) {
  260. if (*pop == Things[thing].dhcp_option)
  261. if (!(retval = dhcp_env_update (thing, pop)))
  262. return NULL;
  263. }
  264. }
  265. return (thing >= N_THINGS ? NULL : pop);
  266. }