Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. /**************************************************************************
  2. Etherboot - Network Bootstrap Program
  3. Literature dealing with the network protocols:
  4. ARP - RFC826
  5. RARP - RFC903
  6. UDP - RFC768
  7. BOOTP - RFC951, RFC2132 (vendor extensions)
  8. DHCP - RFC2131, RFC2132 (options)
  9. TFTP - RFC1350, RFC2347 (options), RFC2348 (blocksize), RFC2349 (tsize)
  10. RPC - RFC1831, RFC1832 (XDR), RFC1833 (rpcbind/portmapper)
  11. NFS - RFC1094, RFC1813 (v3, useful for clarifications, not implemented)
  12. IGMP - RFC1112
  13. **************************************************************************/
  14. /* #define MDEBUG */
  15. #include "etherboot.h"
  16. #include "dev.h"
  17. #include "nic.h"
  18. #include "disk.h"
  19. #include "timer.h"
  20. #include "cpu.h"
  21. #include "cmdline.h"
  22. #include "console.h"
  23. #include <gpxe/init.h>
  24. #include "image.h"
  25. #include <stdarg.h>
  26. #include <gpxe/device.h>
  27. #include <gpxe/heap.h>
  28. #include <gpxe/netdevice.h>
  29. /* Linker symbols */
  30. extern char _bss[], _ebss[];
  31. jmp_buf restart_etherboot;
  32. int url_port;
  33. char as_main_program = 1;
  34. #if 0
  35. static inline unsigned long ask_boot(unsigned *index)
  36. {
  37. unsigned long order = DEFAULT_BOOT_ORDER;
  38. *index = DEFAULT_BOOT_INDEX;
  39. #ifdef LINUXBIOS
  40. order = get_boot_order(order, index);
  41. #endif
  42. #if defined(ASK_BOOT)
  43. #if ASK_BOOT >= 0
  44. while(1) {
  45. int c = 0;
  46. printf(ASK_PROMPT);
  47. #if ASK_BOOT > 0
  48. {
  49. unsigned long time;
  50. for ( time = currticks() + ASK_BOOT*TICKS_PER_SEC;
  51. !c && !iskey(); ) {
  52. if (currticks() > time) c = ANS_DEFAULT;
  53. }
  54. }
  55. #endif /* ASK_BOOT > 0 */
  56. if ( !c ) c = getchar();
  57. if ((c >= 'a') && (c <= 'z')) c &= 0x5F;
  58. if ((c >= ' ') && (c <= '~')) putchar(c);
  59. putchar('\n');
  60. switch(c) {
  61. default:
  62. /* Nothing useful try again */
  63. continue;
  64. case ANS_QUIT:
  65. order = BOOT_NOTHING;
  66. *index = 0;
  67. break;
  68. case ANS_DEFAULT:
  69. /* Preserve the default boot order */
  70. break;
  71. case ANS_NETWORK:
  72. order = (BOOT_NIC << (0*BOOT_BITS)) |
  73. (BOOT_NOTHING << (1*BOOT_BITS));
  74. *index = 0;
  75. break;
  76. case ANS_DISK:
  77. order = (BOOT_DISK << (0*BOOT_BITS)) |
  78. (BOOT_NOTHING << (1*BOOT_BITS));
  79. *index = 0;
  80. break;
  81. case ANS_FLOPPY:
  82. order = (BOOT_FLOPPY << (0*BOOT_BITS)) |
  83. (BOOT_NOTHING << (1*BOOT_BITS));
  84. *index = 0;
  85. break;
  86. }
  87. break;
  88. }
  89. putchar('\n');
  90. #endif /* ASK_BOOT >= 0 */
  91. #endif /* defined(ASK_BOOT) */
  92. return order;
  93. }
  94. static inline void try_floppy_first(void)
  95. {
  96. #if (TRY_FLOPPY_FIRST > 0)
  97. int i;
  98. printf("Trying floppy");
  99. disk_init();
  100. for (i = TRY_FLOPPY_FIRST; i-- > 0; ) {
  101. putchar('.');
  102. if (pcbios_disk_read(0, 0, 0, 0, ((char *)FLOPPY_BOOT_LOCATION)) != 0x8000) {
  103. printf("using floppy\n");
  104. exit(0);
  105. }
  106. }
  107. printf("no floppy\n");
  108. #endif /* TRY_FLOPPY_FIRST */
  109. }
  110. static struct class_operations {
  111. struct dev *dev;
  112. int (*probe)(struct dev *dev);
  113. int (*load_configuration)(struct dev *dev);
  114. int (*load)(struct dev *dev);
  115. }
  116. operations[] = {
  117. { &nic.dev, eth_probe, eth_load_configuration, eth_load },
  118. { &disk.dev, disk_probe, disk_load_configuration, disk_load },
  119. { &disk.dev, disk_probe, disk_load_configuration, disk_load },
  120. };
  121. #endif
  122. static int main_loop(int state);
  123. static int exit_ok;
  124. static int exit_status;
  125. static int initialized;
  126. /**************************************************************************
  127. MAIN - Kick off routine
  128. **************************************************************************/
  129. int main ( void ) {
  130. struct net_device *netdev;
  131. /* Call all registered initialisation functions */
  132. init_heap();
  133. call_init_fns ();
  134. probe_devices();
  135. netdev = next_netdev ();
  136. if ( netdev ) {
  137. test_dhcp ( netdev );
  138. //cmdl_start();
  139. } else {
  140. printf ( "No network device found\n" );
  141. }
  142. printf ( "Press any key to exit\n" );
  143. getchar();
  144. remove_devices();
  145. call_exit_fns ();
  146. return exit_status;
  147. }
  148. #if 0
  149. void exit(int status)
  150. {
  151. while(!exit_ok)
  152. ;
  153. exit_status = status;
  154. longjmp(restart_etherboot, 255);
  155. }
  156. static int main_loop(int state)
  157. {
  158. /* Splitting main into 2 pieces makes the semantics of
  159. * which variables are preserved across a longjmp clean
  160. * and predictable.
  161. */
  162. static unsigned long order;
  163. static unsigned boot_index;
  164. static struct dev * dev = 0;
  165. static struct class_operations *ops;
  166. static int type;
  167. static int i;
  168. if (!initialized) {
  169. initialized = 1;
  170. if (dev && (state >= 1) && (state <= 2)) {
  171. dev->how_probe = PROBE_AWAKE;
  172. dev->how_probe = ops->probe(dev);
  173. if (dev->how_probe == PROBE_FAILED) {
  174. state = -1;
  175. }
  176. if (state == 1) {
  177. /* The bootp reply might have been changed, re-parse. */
  178. decode_rfc1533(bootp_data.bootp_reply.bp_vend, 0,
  179. #ifdef NO_DHCP_SUPPORT
  180. BOOTP_VENDOR_LEN + MAX_BOOTP_EXTLEN,
  181. #else
  182. DHCP_OPT_LEN + MAX_BOOTP_EXTLEN,
  183. #endif /* NO_DHCP_SUPPORT */
  184. 1);
  185. }
  186. }
  187. }
  188. switch(state) {
  189. case 0:
  190. {
  191. static int firsttime = 1;
  192. /* First time through */
  193. if (firsttime) {
  194. cleanup();
  195. firsttime = 0;
  196. }
  197. #ifdef EXIT_IF_NO_OFFER
  198. else {
  199. cleanup();
  200. exit(0);
  201. }
  202. #endif
  203. i = -1;
  204. state = 4;
  205. dev = 0;
  206. /* We just called setjmp ... */
  207. order = ask_boot(&boot_index);
  208. try_floppy_first();
  209. break;
  210. }
  211. case 4:
  212. cleanup();
  213. call_reset_fns();
  214. /* Find a dev entry to probe with */
  215. if (!dev) {
  216. int boot;
  217. int failsafe;
  218. /* Advance to the next device type */
  219. i++;
  220. boot = (order >> (i * BOOT_BITS)) & BOOT_MASK;
  221. type = boot & BOOT_TYPE_MASK;
  222. failsafe = (boot & BOOT_FAILSAFE) != 0;
  223. if (i >= MAX_BOOT_ENTRIES) {
  224. type = BOOT_NOTHING;
  225. }
  226. if ((i == 0) && (type == BOOT_NOTHING)) {
  227. /* Return to caller */
  228. exit(0);
  229. }
  230. if (type >= BOOT_NOTHING) {
  231. interruptible_sleep(2);
  232. state = 0;
  233. break;
  234. }
  235. ops = &operations[type];
  236. dev = ops->dev;
  237. dev->how_probe = PROBE_FIRST;
  238. dev->type = type;
  239. dev->failsafe = failsafe;
  240. dev->type_index = 0;
  241. } else {
  242. /* Advance to the next device of the same type */
  243. dev->how_probe = PROBE_NEXT;
  244. }
  245. state = 3;
  246. break;
  247. case 3:
  248. state = -1;
  249. /* Removed the following line because it was causing
  250. * heap.o to be dragged in unnecessarily. It's also
  251. * slightly puzzling: by resetting heap_base, doesn't
  252. * this mean that we permanently leak memory?
  253. */
  254. /* heap_base = allot(0); */
  255. dev->how_probe = ops->probe(dev);
  256. if (dev->how_probe == PROBE_FAILED) {
  257. dev = 0;
  258. state = 4;
  259. } else if (boot_index && (i == 0) && (boot_index != (unsigned)dev->type_index)) {
  260. printf("Wrong index\n");
  261. state = 4;
  262. }
  263. else {
  264. state = 2;
  265. }
  266. break;
  267. case 2:
  268. state = -1;
  269. if (ops->load_configuration(dev) >= 0) {
  270. state = 1;
  271. }
  272. break;
  273. case 1:
  274. /* Any return from load is a failure */
  275. ops->load(dev);
  276. state = -1;
  277. break;
  278. case 256:
  279. state = 0;
  280. break;
  281. case -3:
  282. i = MAX_BOOT_ENTRIES;
  283. type = BOOT_NOTHING;
  284. /* fall through */
  285. default:
  286. printf("<abort>\n");
  287. state = 4;
  288. /* At the end goto state 0 */
  289. if ((type >= BOOT_NOTHING) || (i >= MAX_BOOT_ENTRIES)) {
  290. state = 0;
  291. }
  292. break;
  293. }
  294. return state;
  295. }
  296. #endif
  297. /**************************************************************************
  298. LOADKERNEL - Try to load kernel image
  299. **************************************************************************/
  300. #if 0
  301. /* To be split out into individual files */
  302. static const struct proto protos[] = {
  303. { "x-tftm", url_tftm },
  304. { "x-slam", url_slam },
  305. { "nfs", nfs },
  306. { "file", url_file },
  307. { "tftp", tftp },
  308. { "http", http },
  309. };
  310. #endif
  311. /**************************************************************************
  312. CLEANUP - shut down networking and console so that the OS may be called
  313. **************************************************************************/
  314. void cleanup(void)
  315. {
  316. /* Stop receiving packets */
  317. disable ( &dev );
  318. initialized = 0;
  319. }
  320. /*
  321. * Local variables:
  322. * c-basic-offset: 8
  323. * End:
  324. */