From 1bb94397a5b9f4b16b26f650f2604f2e32c63976 Mon Sep 17 00:00:00 2001 From: okuji Date: Tue, 8 Feb 2000 21:20:46 +0000 Subject: [PATCH] fix a fat32 bug and some netboot bugs. --- ChangeLog | 34 ++++++++++++++++++- netboot/config.c | 15 ++++++-- netboot/etherboot.h | 4 +-- netboot/fsys_tftp.c | 2 +- netboot/main.c | 83 +++++++++++++++++++++++++++++---------------- stage2/builtins.c | 2 +- stage2/disk_io.c | 6 ++-- stage2/fsys_fat.c | 6 ++-- 8 files changed, 110 insertions(+), 42 deletions(-) diff --git a/ChangeLog b/ChangeLog index a44d1b798..e10813126 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,35 @@ +2000-02-09 OKUJI Yoshinori + + From Jochen Hoenicke: + * stage2/fsys_fat.c (fat_create_blocklist): The previous change + is reversed. Set FIRST_FAT_ENTRY to a unsigned long value in + FAT_BUF + (NEW_MAPBLOCK - MAPBLOCK) instead of a unsigned short + value. Mask FIRST_FAT_ENTRY with 0xFFF if FAT_SIZE is equal to + 3, whether the bit 0 of LAST_FAT_ENTRY is set or not. + + * netboot/config.c (eth_probe): If PROBED is set to non-zero, + return 1 without probing ethernet cards. Clear NETWORK_READY. If + *T->ETH_PROBE return sucessfully, set PROBED to 1. + * netboot/main.c (rarp): Call eth_probe and return zero if + fails. Clear NETWORK_READY at first, and set NETWORK_READY to 1 + if RETRY is less than MAX_ARP_RETRIES. If IP_ABORT is non-zero, + return zero instead of one. + (bootp): Call eth_probe and return zero if fails. Clear + NETWORK_READY at first, and set NETWORK_READY to 1 if + await_reply returns successfully. + (bootp) [T509HACK]: If FLAG is non-zero, skip calling + await_reply. Don't call await_reply here any more. + (bootp) [!NO_DHCP_SUPPORT]: If any ack packet is not reached + within MAX_BOOTP_RETRIES times, return zero. If DHCP_REPLY isn't + DHCPOFFER, set NETWORK_READY to one and return one. + * netboot/etherboot.h (NO_DHCP_SUPPORT): Undefined. + + * stage2/builtins.c (print_root_device): Use the macro + NETWORK_DRIVE instead of 0x20. + * stage2/disk_io.c [!STAGE1_5] (sane_partition): Likewise. + (real_open_partition) [!STAGE1_5]: Likewise. + (set_device) [!STAGE1_5]: Likewise. + 2000-02-08 OKUJI Yoshinori * grub/asmstub.c (biosdisk) [__linux__]: Use _llseek when @@ -163,7 +195,7 @@ 2000-02-07 OKUJI Yoshinori * stage2/asm.S: Undo the previous changes. Is - binutils-2.9.5.0.25 too strict to break the compatibility? + binutils-2.9.5.0.25 too strict to retain the compatibility? Reported by Kalle Olavi Niemitalo . 2000-02-03 OKUJI Yoshinori diff --git a/netboot/config.c b/netboot/config.c index 700ffddaa..6663d3253 100644 --- a/netboot/config.c +++ b/netboot/config.c @@ -28,7 +28,7 @@ struct pci_device; /* for the probe prototype */ #undef INCLUDE_PCI -#if defined(INCLUDE_NEPCI) || defined(INCLUDE_EEPRO100) || defined(INCLUDE_LANCEPCI) || defined(INCLUDE_EPIC100) || defined(INCLUDE_TULIP) || defined(INCLUDE_NTULIP) || defined(INCLUDE_3C90X) || defined(INCLUDE_RTL8139) || defined(INCLUDE_VIA_RHINE) +#if defined(INCLUDE_NEPCI) || defined(INCLUDE_EEPRO100) || defined(INCLUDE_LANCEPCI) || defined(INCLUDE_EPIC100) || defined(INCLUDE_TULIP) || defined(INCLUDE_NTULIP) || defined(INCLUDE_3C90X) || defined(INCLUDE_RTL8139) || defined(INCLUDE_VIA_RHINE) || defined(INCLUDE_3C59X) /* || others later */ #if defined(ETHERBOOT32) /* only for 32 bit machines */ #define INCLUDE_PCI @@ -425,7 +425,15 @@ int eth_probe(void) { struct pci_device *p; struct dispatch_table *t; + static int probed = 0; + /* If already probed, don't try to probe it any longer. */ + if (probed) + return 1; + + /* Clear the ready flag. */ + network_ready = 0; + p = 0; #ifdef INCLUDE_PCI /* In GRUB, the ROM info is initialized here. */ @@ -448,7 +456,10 @@ int eth_probe(void) { printf("[%s]", t->nic_name); if ((*t->eth_probe)(&nic, t->probe_ioaddrs, p)) - return (1); + { + probed = 1; + return (1); + } } return (0); } diff --git a/netboot/etherboot.h b/netboot/etherboot.h index 91a7a5ffa..4c3c4b8c1 100644 --- a/netboot/etherboot.h +++ b/netboot/etherboot.h @@ -9,10 +9,10 @@ Author: Martin Renters /* Include GRUB-specific macros and prototypes here. */ #include -/* FIXME: For now, disable the DHCP support. Perhaps I should segregate +/* FIXME: For now, enable the DHCP support. Perhaps I should segregate the DHCP support from the BOOTP support, and permit both to co-exist. */ -#define NO_DHCP_SUPPORT 1 +#undef NO_DHCP_SUPPORT #include "osdep.h" diff --git a/netboot/fsys_tftp.c b/netboot/fsys_tftp.c index b5b3fb871..b1c84291c 100644 --- a/netboot/fsys_tftp.c +++ b/netboot/fsys_tftp.c @@ -63,7 +63,7 @@ buf_fill (int abort) if (! block && retry++ < MAX_TFTP_RETRIES) { /* Maybe initial request was lost. */ - rfc951_sleep(retry); + rfc951_sleep (retry); if (! udp_transmit (arptable[ARP_SERVER].ipaddr.s_addr, ++isocket, TFTP, len, (char *) &tp)) return 0; diff --git a/netboot/main.c b/netboot/main.c index c78d2daad..03ea6196b 100644 --- a/netboot/main.c +++ b/netboot/main.c @@ -35,8 +35,12 @@ Author: Martin Renters #include struct arptable_t arptable[MAX_ARP]; + +/* Set if the user pushes the ESC key. */ int ip_abort = 0; +/* Set if an ethernet card is probed and IP addresses are set. */ int network_ready = 0; + struct rom_info rom; static int vendorext_isvalid; @@ -398,6 +402,13 @@ rarp (void) /* arp and rarp requests share the same packet structure. */ struct arprequest rarpreq; + /* Make sure that an ethernet is probed. */ + if (! eth_probe ()) + return 0; + + /* Clear the ready flag. */ + network_ready = 0; + memset (&rarpreq, 0, sizeof (rarpreq)); rarpreq.hwtype = htons (1); @@ -420,11 +431,14 @@ rarp (void) break; if (ip_abort) - return 1; + return 0; } if (retry < MAX_ARP_RETRIES) - return 1; + { + network_ready = 1; + return 1; + } return 0; } @@ -446,6 +460,14 @@ bootp (void) flag = 1; #endif + + /* Make sure that an ethernet is probed. */ + if (! eth_probe ()) + return 0; + + /* Clear the ready flag. */ + network_ready = 0; + grub_memset (&bp, 0, sizeof (struct bootp_t)); bp.bp_op = BOOTP_REQUEST; bp.bp_htype = 1; @@ -487,27 +509,19 @@ bootp (void) if (flag) { flag--; + continue; } - else - { - if (await_reply (AWAIT_BOOTP, 0, NULL, 0)) - return 1; - - if (ip_abort) - return 0; - - rfc951_sleep (++retry); - } -#else /* ! T509HACK */ +#endif /* T509HACK */ -# ifdef NO_DHCP_SUPPORT - if (await_reply (AWAIT_BOOTP, 0, NULL, 0)) -# else +#ifdef NO_DHCP_SUPPORT + if (await_reply (AWAIT_BOOTP, 0, NULL, 0)) + { + network_ready = 1; + return 1; + } +#else /* ! NO_DHCP_SUPPORT */ if (await_reply (AWAIT_BOOTP, 0, NULL, 0)) { - if (ip_abort) - return 0; - if (dhcp_reply == DHCPOFFER) { dhcp_reply = 0; @@ -526,27 +540,36 @@ bootp (void) dhcp_reply = 0; if (await_reply (AWAIT_BOOTP, 0, NULL, 0)) if (dhcp_reply == DHCPACK) - return 1; + { + network_ready = 1; + return 1; + } if (ip_abort) return 0; rfc951_sleep (++retry1); } + + /* Timeout. */ + return 0; } else -# endif /* ! NO_DHCP_SUPPORT */ - return 1; -# ifndef NO_DHCP_SUPPORT + { + network_ready = 1; + return 1; + } } - rfc951_sleep (++retry); - -# endif /* ! NO_DHCP_SUPPORT */ -#endif /* ! T509HACK */ +#endif /* ! NO_DHCP_SUPPORT */ + if (ip_abort) + return 0; + + rfc951_sleep (++retry); bp.bp_secs = htons ((currticks () - starttime) / 20); } - + + /* Timeout. */ return 0; } @@ -892,7 +915,9 @@ decode_rfc1533 (unsigned char *p, int block, int len, int eof) } extdata = extend = end; - + + /* Perhaps we can eliminate this because we doesn't require so + much information, but I leave this alone. */ if (block == 0 && extpath != NULL) { char fname[64]; diff --git a/stage2/builtins.c b/stage2/builtins.c index e419e7a63..a98609e00 100644 --- a/stage2/builtins.c +++ b/stage2/builtins.c @@ -1957,7 +1957,7 @@ static struct builtin builtin_read = static void print_root_device (void) { - if (saved_drive == 0x20) + if (saved_drive == NETWORK_DRIVE) { /* Network drive. */ grub_printf (" (nd):"); diff --git a/stage2/disk_io.c b/stage2/disk_io.c index 4b0441954..9343642a1 100644 --- a/stage2/disk_io.c +++ b/stage2/disk_io.c @@ -247,7 +247,7 @@ static int sane_partition (void) { /* network drive */ - if (current_drive == 0x20) + if (current_drive == NETWORK_DRIVE) return 1; if (!(current_partition & 0xFF000000uL) @@ -464,7 +464,7 @@ real_open_partition (int flags) #ifndef STAGE1_5 /* network drive */ - if (current_drive == 0x20) + if (current_drive == NETWORK_DRIVE) return 1; if (! sane_partition ()) @@ -739,7 +739,7 @@ set_device (char *device) errnum = ERR_NUMBER_PARSING; if (ch == 'n') - current_drive = 0x20; + current_drive = NETWORK_DRIVE; else { safe_parse_maxint (&device, (int *) ¤t_drive); diff --git a/stage2/fsys_fat.c b/stage2/fsys_fat.c index d3cfb3a7e..50c8a3b88 100644 --- a/stage2/fsys_fat.c +++ b/stage2/fsys_fat.c @@ -124,14 +124,14 @@ fat_create_blocklist (int first_fat_entry) } first_fat_entry - = *((unsigned short *) (FAT_BUF + (new_mapblock - mapblock))); + = *((unsigned long *) (FAT_BUF + (new_mapblock - mapblock))); if (fat_size == 3) { if (last_fat_entry & 1) first_fat_entry >>= 4; - else - first_fat_entry &= 0xFFF; + + first_fat_entry &= 0xFFF; } else if (fat_size == 4) first_fat_entry &= 0xFFFF;