123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365 |
-
-
-
-
- #include "etherboot.h"
- #include "dev.h"
- #include "nic.h"
- #include "disk.h"
- #include "timer.h"
- #include "cpu.h"
- #include "console.h"
- #include <gpxe/init.h>
- #include "image.h"
- #include <stdarg.h>
-
- #include <gpxe/device.h>
- #include <gpxe/heap.h>
- #include <gpxe/netdevice.h>
-
- #ifdef CONFIG_FILO
- #include <lib.h>
- #endif
-
-
- extern char _bss[], _ebss[];
-
- jmp_buf restart_etherboot;
- int url_port;
-
- char as_main_program = 1;
-
- #if 0
-
- static inline unsigned long ask_boot(unsigned *index)
- {
- unsigned long order = DEFAULT_BOOT_ORDER;
- *index = DEFAULT_BOOT_INDEX;
- #ifdef LINUXBIOS
- order = get_boot_order(order, index);
- #endif
- #if defined(ASK_BOOT)
- #if ASK_BOOT >= 0
- while(1) {
- int c = 0;
- printf(ASK_PROMPT);
- #if ASK_BOOT > 0
- {
- unsigned long time;
- for ( time = currticks() + ASK_BOOT*TICKS_PER_SEC;
- !c && !iskey(); ) {
- if (currticks() > time) c = ANS_DEFAULT;
- }
- }
- #endif
- if ( !c ) c = getchar();
- if ((c >= 'a') && (c <= 'z')) c &= 0x5F;
- if ((c >= ' ') && (c <= '~')) putchar(c);
- putchar('\n');
-
- switch(c) {
- default:
-
- continue;
- case ANS_QUIT:
- order = BOOT_NOTHING;
- *index = 0;
- break;
- case ANS_DEFAULT:
-
- break;
- case ANS_NETWORK:
- order = (BOOT_NIC << (0*BOOT_BITS)) |
- (BOOT_NOTHING << (1*BOOT_BITS));
- *index = 0;
- break;
- case ANS_DISK:
- order = (BOOT_DISK << (0*BOOT_BITS)) |
- (BOOT_NOTHING << (1*BOOT_BITS));
- *index = 0;
- break;
- case ANS_FLOPPY:
- order = (BOOT_FLOPPY << (0*BOOT_BITS)) |
- (BOOT_NOTHING << (1*BOOT_BITS));
- *index = 0;
- break;
- }
- break;
- }
- putchar('\n');
- #endif
- #endif
- return order;
- }
-
- static inline void try_floppy_first(void)
- {
- #if (TRY_FLOPPY_FIRST > 0)
- int i;
- printf("Trying floppy");
- disk_init();
- for (i = TRY_FLOPPY_FIRST; i-- > 0; ) {
- putchar('.');
- if (pcbios_disk_read(0, 0, 0, 0, ((char *)FLOPPY_BOOT_LOCATION)) != 0x8000) {
- printf("using floppy\n");
- exit(0);
- }
- }
- printf("no floppy\n");
- #endif
- }
-
- static struct class_operations {
- struct dev *dev;
- int (*probe)(struct dev *dev);
- int (*load_configuration)(struct dev *dev);
- int (*load)(struct dev *dev);
- }
- operations[] = {
- { &nic.dev, eth_probe, eth_load_configuration, eth_load },
- { &disk.dev, disk_probe, disk_load_configuration, disk_load },
- { &disk.dev, disk_probe, disk_load_configuration, disk_load },
- };
-
- #endif
-
-
-
- static int main_loop(int state);
- static int exit_ok;
- static int exit_status;
- static int initialized;
-
-
-
- int main ( void ) {
- struct net_device *netdev;
-
-
- init_heap();
- call_init_fns ();
- probe_devices();
-
- netdev = next_netdev ();
- if ( netdev ) {
- test_aoeboot ( netdev );
- } else {
- printf ( "No network device found\n" );
- }
-
- printf ( "Press any key to exit\n" );
- getchar();
-
- remove_devices();
- call_exit_fns ();
-
- return exit_status;
- }
-
- #if 0
-
- void exit(int status)
- {
- while(!exit_ok)
- ;
- exit_status = status;
- longjmp(restart_etherboot, 255);
- }
-
-
-
- static int main_loop(int state)
- {
-
-
- static unsigned long order;
- static unsigned boot_index;
- static struct dev * dev = 0;
- static struct class_operations *ops;
- static int type;
- static int i;
-
- if (!initialized) {
- initialized = 1;
- if (dev && (state >= 1) && (state <= 2)) {
- dev->how_probe = PROBE_AWAKE;
- dev->how_probe = ops->probe(dev);
- if (dev->how_probe == PROBE_FAILED) {
- state = -1;
- }
- if (state == 1) {
-
- decode_rfc1533(bootp_data.bootp_reply.bp_vend, 0,
- #ifdef NO_DHCP_SUPPORT
- BOOTP_VENDOR_LEN + MAX_BOOTP_EXTLEN,
- #else
- DHCP_OPT_LEN + MAX_BOOTP_EXTLEN,
- #endif
- 1);
- }
- }
- }
- switch(state) {
- case 0:
- {
- static int firsttime = 1;
-
- if (firsttime) {
- cleanup();
- firsttime = 0;
- }
- #ifdef EXIT_IF_NO_OFFER
- else {
- cleanup();
- exit(0);
- }
- #endif
- i = -1;
- state = 4;
- dev = 0;
-
-
- order = ask_boot(&boot_index);
- try_floppy_first();
- break;
- }
- case 4:
- cleanup();
- call_reset_fns();
-
- if (!dev) {
- int boot;
- int failsafe;
-
-
- i++;
- boot = (order >> (i * BOOT_BITS)) & BOOT_MASK;
- type = boot & BOOT_TYPE_MASK;
- failsafe = (boot & BOOT_FAILSAFE) != 0;
- if (i >= MAX_BOOT_ENTRIES) {
- type = BOOT_NOTHING;
- }
- if ((i == 0) && (type == BOOT_NOTHING)) {
-
- exit(0);
- }
- if (type >= BOOT_NOTHING) {
- interruptible_sleep(2);
- state = 0;
- break;
- }
- ops = &operations[type];
- dev = ops->dev;
- dev->how_probe = PROBE_FIRST;
- dev->type = type;
- dev->failsafe = failsafe;
- dev->type_index = 0;
- } else {
-
- dev->how_probe = PROBE_NEXT;
- }
- state = 3;
- break;
- case 3:
- state = -1;
-
-
-
- dev->how_probe = ops->probe(dev);
- if (dev->how_probe == PROBE_FAILED) {
- dev = 0;
- state = 4;
- } else if (boot_index && (i == 0) && (boot_index != (unsigned)dev->type_index)) {
- printf("Wrong index\n");
- state = 4;
- }
- else {
- state = 2;
- }
- break;
- case 2:
- state = -1;
- if (ops->load_configuration(dev) >= 0) {
- state = 1;
- }
- break;
- case 1:
-
- ops->load(dev);
- state = -1;
- break;
- case 256:
- state = 0;
- break;
- case -3:
- i = MAX_BOOT_ENTRIES;
- type = BOOT_NOTHING;
-
- default:
- printf("<abort>\n");
- state = 4;
-
- if ((type >= BOOT_NOTHING) || (i >= MAX_BOOT_ENTRIES)) {
- state = 0;
- }
- break;
- }
- return state;
- }
-
-
- #endif
-
-
-
- #if 0
-
- static const struct proto protos[] = {
- { "x-tftm", url_tftm },
- { "x-slam", url_slam },
- { "nfs", nfs },
- { "file", url_file },
- { "tftp", tftp },
- { "http", http },
- };
- #endif
-
-
-
- void cleanup(void)
- {
-
- disable ( &dev );
- initialized = 0;
- }
-
|