add some new commands to the stage2 for the network support.

This commit is contained in:
okuji 2000-02-09 21:14:33 +00:00
parent 1bb94397a5
commit 899a275d55
10 changed files with 138 additions and 79 deletions

View file

@ -1,3 +1,24 @@
2000-02-10 OKUJI Yoshinori <okuji@gnu.org>
* stage2/Makefile.am [NETBOOT_SUPPORT] (STAGE2_COMPILE): Added
-I$(top_srcdir)/netboot and -DSUPPORT_NETBOOT=1.
* stage2/builtins.c (bootp_func): New function.
(dhcp_func): Likewise.
(rarp_func): Likewise.
(builtin_bootp): New variable.
(builtin_dhcp): Likewise.
(builtin_rarp): Likewise.
(builtin_table): Added pointers to BUILTIN_BOOTP, BUILTIN_DHCP
and BUILTIN_RARP.
* docs/user-ref.texi (General Commands): Added descriptions
about "bootp", "dhcp" and "rarp".
* netboot/main.c (bootp) [!NO_DHCP_SUPPORT]: Added casts to
suppress gcc warnings.
(decode_rfc1533) [!NO_DHCP_SUPPORT]: Likewise.
* netboot/3c90x.c: Include the local "pci.h" instead of
<linux/pci.h> even if __FreeBSD__ is undefined.
2000-02-09 OKUJI Yoshinori <okuji@gnu.org>
From Jochen Hoenicke:

2
NEWS
View file

@ -38,6 +38,8 @@ New in 0.5.94:
you are sure that your BIOS does support LBA mode but GRUB doesn't
work in LBA mode, recompile GRUB with this option specified. You can
check if GRUB accesses a drive in LBA mode by the command "geometry".
* New commands "bootp", "dhcp" and "rarp" can be used to initialize a
network device and get IP addresses from a network.
New in 0.5.93 - 1999-10-30:
* ELF format of FreeBSD kernel is supported.

75
TODO
View file

@ -35,81 +35,6 @@ Priorities:
partition, so that it won't be accidentally erased or modified by
the kernel.
* Complete the netboot support. !!!
This is the proposed interface between the netboot module and the core
system:
- The module contains a header like this:
struct netboot_module_header
{
/* The same as the Multiboot header, but has a different magic. */
struct multiboot_header mb_header;
/* The version number to avoid incompatibilities. */
unsigned short compat_version;
/* The identifier. */
unsigned short identifier;
/* some pointers to callback functions. */
unsigned long init_func;
unsigned long fini_func;
unsigned long open_func;
unsinged long read_func;
unsinged long seek_func;
unsinged long close_func;
/* The address of the message buffer. The module should not print
anything on the screen directly. */
unsinged long msg_addr;
/* The maximum size of the message buffer (perhaps should be less
than 80*24, because of the screen size). */
unsinged long msg_size;
}
- When the core system loads the module, check for the header
structure and store the image in the specified memory address (in
the ELF header or in MB_HEADER). If successful, call INIT_FUNC.
- INIT_FUNC should initialize the module and return the required
memory space. The prototype is:
grub_error_t init_func (const struct multiboot_info *mbi,
unsigned long *mem_start,
unsigned long *mem_end);
If the module does not need any extra memory space, then set
*MEM_START to _START and *MEM_END to _END. MBI->CMDLINE has the
command-line argument specified (probably netmask=... or something).
FIXME: Should the module return most of the information dynamically
from INIT_FUNC, instead of the module header?
- When the core system unloads the module, call FINI_FUNC to restore
the resources cleanly.
- The prototype of FINI_FUNC is:
grub_error_t fini_func (const struct multiboot_info *mbi);
- The rest of the callback functions are equivalent to the filesystem
callbacks. Their prototypes are:
grub_error_t open_func (const struct multiboot_info *mbi,
const char *filename);
grub_error_t read_func (const struct multiboot_info *mbi,
char *buffer, int len);
grub_error_t seek_func (const struct multiboot_info *mbi,
int offset);
grub_error_t close_func (const struct multiboot_info *mbi);
FIXME: How to add decompression support?
- The core system will print the string MSG_ADDR after each call is
finished.
- Each callback function will be run in the exactly same condition as
when a Multiboot kernel starts up, and it MUST restore the condition
before it returns (i.e. PIC or IDT).
* Add automatic configuration support.
* Add bunzip2 support.

View file

@ -398,6 +398,7 @@ if test "x$enable_via_rhine" = xyes; then
NETBOOT_DRIVERS="$NETBOOT_DRIVERS via_rhine.o"
fi
dnl Check if the netboot support is turned on.
AM_CONDITIONAL(NETBOOT_SUPPORT, test "x$NET_CFLAGS" != x)
if test "x$NET_CFLAGS" != x; then
FSYS_CFLAGS="$FSYS_CFLAGS -DFSYS_TFTP=1"

View file

@ -498,6 +498,10 @@ the line, starting with the first non-space character.
Commands usable both in the menu and in the command line.
@deffn Command bootp
Initialize a network device via the @dfn{BOOTP} protocol.
@end deffn
@deffn Command color normal [highlight]
Change the menu colors. The color @var{normal} is used for most
lines in the menu, and the color @var{highlight} is used to highlight the
@ -592,12 +596,21 @@ This command can be used only in the grub shell (@pxref{Invoking the
grub shell}).
@end deffn
@deffn Command dhcp
Initialize a network device via the @dfn{DHCP} protocol. At the moment,
this command is just an alias for @command{bootp}.
@end deffn
@deffn Command hide partition
Hide @var{partition} by setting the @dfn{hidden} bit in its partition
type code. This is useful only for DOS or Windows when multiple primary
partitions exist in one disk.
@end deffn
@deffn Command rarp
Initialize a network device via the @dfn{RARP} protocol.
@end deffn
@deffn Command setkey to_key from_key
Change the keyboard map. The key @var{from_key} is mapped to the key
@var{to_key}. Note that this command @emph{does not} exchange the

View file

@ -36,9 +36,12 @@
#include "etherboot.h"
#include "nic.h"
#include "pci.h"
#if 0
#ifndef __FreeBSD__
#include <linux/pci.h>
#endif
#endif
#define TIME_OUT 60000
#define XCVR_MAGIC (0x5A00)

View file

@ -531,8 +531,10 @@ bootp (void)
grub_memmove (bp.bp_vend + sizeof rfc1533_cookie
+ sizeof dhcprequest,
rfc1533_end, sizeof rfc1533_end);
grub_memmove (bp.bp_vend + 9, &dhcp_server, sizeof (in_addr));
grub_memmove (bp.bp_vend + 15, &dhcp_addr, sizeof (in_addr));
grub_memmove (bp.bp_vend + 9, (char *) &dhcp_server,
sizeof (in_addr));
grub_memmove (bp.bp_vend + 15, (char *) &dhcp_addr,
sizeof (in_addr));
for (retry1 = 0; retry1 < MAX_BOOTP_RETRIES;)
{
udp_transmit (IP_BROADCAST, 0, BOOTP_SERVER,
@ -861,7 +863,7 @@ decode_rfc1533 (unsigned char *p, int block, int len, int eof)
}
else if (c == RFC2132_SRV_ID)
{
grub_memmove (&dhcp_server, p + 2, sizeof (in_addr));
grub_memmove ((char *) &dhcp_server, p + 2, sizeof (in_addr));
}
#endif /* ! NO_DHCP_SUPPORT */

View file

@ -32,7 +32,12 @@ MOSTLYCLEANFILES = $(noinst_PROGRAMS)
PRE_STAGE2_LINK = -nostdlib -Wl,-N -Wl,-Ttext -Wl,8200
START_LINK = -nostdlib -Wl,-N -Wl,-Ttext -Wl,8000
if NETBOOT_SUPPORT
STAGE2_COMPILE = $(STAGE2_CFLAGS) -fno-builtin -nostdinc \
-I$(top_srcdir)/netboot -DSUPPORT_NETBOOT=1
else
STAGE2_COMPILE = $(STAGE2_CFLAGS) -fno-builtin -nostdinc
endif
STAGE1_5_LINK = -nostdlib -Wl,-N -Wl,-Ttext -Wl,2000
STAGE1_5_COMPILE = $(STAGE2_COMPILE) -DNO_DECOMPRESSION=1 -DSTAGE1_5=1

View file

@ -121,7 +121,9 @@ MOSTLYCLEANFILES = $(noinst_PROGRAMS)
PRE_STAGE2_LINK = -nostdlib -Wl,-N -Wl,-Ttext -Wl,8200
START_LINK = -nostdlib -Wl,-N -Wl,-Ttext -Wl,8000
STAGE2_COMPILE = $(STAGE2_CFLAGS) -fno-builtin -nostdinc
@NETBOOT_SUPPORT_TRUE@STAGE2_COMPILE = @NETBOOT_SUPPORT_TRUE@$(STAGE2_CFLAGS) -fno-builtin -nostdinc \
@NETBOOT_SUPPORT_TRUE@ -I$(top_srcdir)/netboot -DSUPPORT_NETBOOT=1
@NETBOOT_SUPPORT_FALSE@STAGE2_COMPILE = @NETBOOT_SUPPORT_FALSE@$(STAGE2_CFLAGS) -fno-builtin -nostdinc
STAGE1_5_LINK = -nostdlib -Wl,-N -Wl,-Ttext -Wl,2000
STAGE1_5_COMPILE = $(STAGE2_COMPILE) -DNO_DECOMPRESSION=1 -DSTAGE1_5=1

View file

@ -22,6 +22,10 @@
#include <shared.h>
#include <filesys.h>
#ifdef SUPPORT_NETBOOT
# include <etherboot.h>
#endif
#ifndef GRUB_UTIL
# include "apic.h"
# include "smp-imps.h"
@ -239,6 +243,37 @@ static struct builtin builtin_boot =
};
/* bootp */
static int
bootp_func (char *arg, int flags)
{
#ifdef SUPPORT_NETBOOT
if (! bootp ())
{
if (errnum == ERR_NONE)
errnum = ERR_DEV_VALUES;
return 1;
}
return 0;
#else
errnum = ERR_UNRECOGNIZED;
return 1;
#endif
}
static struct builtin builtin_bootp =
{
"bootp",
bootp_func,
BUILTIN_CMDLINE | BUILTIN_MENU,
"bootp",
"Initialize a network device via BOOTP."
};
/* cat */
static int
cat_func (char *arg, int flags)
{
@ -582,6 +617,24 @@ static struct builtin builtin_device =
" can be used only in the grub shell."
};
/* dhcp */
static int
dhcp_func (char *arg, int flags)
{
/* For now, this is an alias for bootp. */
return bootp_func (arg, flags);
}
static struct builtin builtin_dhcp =
{
"dhcp",
dhcp_func,
BUILTIN_CMDLINE | BUILTIN_MENU,
"dhcp",
"Initialize a network device via DHCP."
};
/* displaymem */
static int
@ -1928,6 +1981,35 @@ static struct builtin builtin_quit =
"Exit from the GRUB shell."
};
static int
rarp_func (char *arg, int flags)
{
#ifdef SUPPORT_NETBOOT
if (! rarp ())
{
if (errnum == ERR_NONE)
errnum = ERR_DEV_VALUES;
return 1;
}
return 0;
#else
errnum = ERR_UNRECOGNIZED;
return 1;
#endif
}
static struct builtin builtin_rarp =
{
"rarp",
rarp_func,
BUILTIN_CMDLINE | BUILTIN_MENU,
"rarp",
"Initialize a network device via RARP."
};
static int
read_func (char *arg, int flags)
@ -2718,6 +2800,7 @@ struct builtin *builtin_table[] =
{
&builtin_blocklist,
&builtin_boot,
&builtin_bootp,
&builtin_cat,
&builtin_chainloader,
&builtin_color,
@ -2725,6 +2808,7 @@ struct builtin *builtin_table[] =
&builtin_debug,
&builtin_default,
&builtin_device,
&builtin_dhcp,
&builtin_displaymem,
&builtin_embed,
&builtin_fallback,
@ -2745,6 +2829,7 @@ struct builtin *builtin_table[] =
&builtin_password,
&builtin_pause,
&builtin_quit,
&builtin_rarp,
&builtin_read,
&builtin_root,
&builtin_rootnoverify,