2004-09-12 Tomas Ebenlendr <ebik@ucw.cz>
Added normal mode command `chainloader' as module chain.mod, which depends on normal.mod and _chain.mod. * conf/i386-pc.rmk (pkgdata_MODULES): Add `chain.mod'. (chain_mod_SOURCES, chain_mod_CFLAGS): Variables added. * include/grub/i386/pc/loader.h (grub_rescue_cmd_chainloader): Deleted prototype. * loader/i386/pc/chainloader.c (grub_rescue_cmd_chainloader): All but arguments parsing moved to ... (grub_chainloader_cmd): ... here. New function. * include/grub/i386/pc/chainloader.h: New file. * loader/i386/pc/chainloader_normal.c: Likewise.
This commit is contained in:
parent
2c1f4ce368
commit
8ddad8453b
7 changed files with 176 additions and 22 deletions
15
ChangeLog
15
ChangeLog
|
@ -1,3 +1,18 @@
|
|||
2004-09-12 Tomas Ebenlendr <ebik@ucw.cz>
|
||||
|
||||
Added normal mode command `chainloader' as module chain.mod, which
|
||||
depends on normal.mod and _chain.mod.
|
||||
|
||||
* conf/i386-pc.rmk (pkgdata_MODULES): Add `chain.mod'.
|
||||
(chain_mod_SOURCES, chain_mod_CFLAGS): Variables added.
|
||||
* include/grub/i386/pc/loader.h (grub_rescue_cmd_chainloader):
|
||||
Deleted prototype.
|
||||
* loader/i386/pc/chainloader.c (grub_rescue_cmd_chainloader): All
|
||||
but arguments parsing moved to ...
|
||||
(grub_chainloader_cmd): ... here. New function.
|
||||
* include/grub/i386/pc/chainloader.h: New file.
|
||||
* loader/i386/pc/chainloader_normal.c: Likewise.
|
||||
|
||||
2004-09-11 Marco Gerards <metgerards@student.han.nl>
|
||||
|
||||
* conf/i386-pc.rmk (kernel_img_SOURCES): Added kern/fshelp.c.
|
||||
|
|
|
@ -788,7 +788,7 @@ genmoddep-util_genmoddep.d: util/genmoddep.c
|
|||
# Modules.
|
||||
pkgdata_MODULES = _chain.mod _linux.mod fat.mod ufs.mod ext2.mod minix.mod \
|
||||
hfs.mod jfs.mod normal.mod hello.mod vga.mod font.mod _multiboot.mod ls.mod \
|
||||
boot.mod cmp.mod cat.mod terminal.mod fshelp.mod
|
||||
boot.mod cmp.mod cat.mod terminal.mod fshelp.mod chain.mod
|
||||
|
||||
# For _chain.mod.
|
||||
_chain_mod_SOURCES = loader/i386/pc/chainloader.c
|
||||
|
@ -829,6 +829,45 @@ _chain_mod-loader_i386_pc_chainloader.d: loader/i386/pc/chainloader.c
|
|||
|
||||
_chain_mod_CFLAGS = $(COMMON_CFLAGS)
|
||||
|
||||
# For chain.mod.
|
||||
chain_mod_SOURCES = loader/i386/pc/chainloader_normal.c
|
||||
CLEANFILES += chain.mod mod-chain.o mod-chain.c pre-chain.o chain_mod-loader_i386_pc_chainloader_normal.o def-chain.lst und-chain.lst
|
||||
MOSTLYCLEANFILES += chain_mod-loader_i386_pc_chainloader_normal.d
|
||||
DEFSYMFILES += def-chain.lst
|
||||
UNDSYMFILES += und-chain.lst
|
||||
|
||||
chain.mod: pre-chain.o mod-chain.o
|
||||
-rm -f $@
|
||||
$(LD) -r -o $@ $^
|
||||
$(STRIP) --strip-unneeded -K grub_mod_init -K grub_mod_fini -R .note -R .comment $@
|
||||
|
||||
pre-chain.o: chain_mod-loader_i386_pc_chainloader_normal.o
|
||||
-rm -f $@
|
||||
$(LD) -r -o $@ $^
|
||||
|
||||
mod-chain.o: mod-chain.c
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) $(chain_mod_CFLAGS) -c -o $@ $<
|
||||
|
||||
mod-chain.c: moddep.lst genmodsrc.sh
|
||||
sh $(srcdir)/genmodsrc.sh 'chain' $< > $@ || (rm -f $@; exit 1)
|
||||
|
||||
def-chain.lst: pre-chain.o
|
||||
$(NM) -g --defined-only -P -p $< | sed 's/^\([^ ]*\).*/\1 chain/' > $@
|
||||
|
||||
und-chain.lst: pre-chain.o
|
||||
echo 'chain' > $@
|
||||
$(NM) -u -P -p $< | cut -f1 -d' ' >> $@
|
||||
|
||||
chain_mod-loader_i386_pc_chainloader_normal.o: loader/i386/pc/chainloader_normal.c
|
||||
$(CC) -Iloader/i386/pc -I$(srcdir)/loader/i386/pc $(CPPFLAGS) $(CFLAGS) $(chain_mod_CFLAGS) -c -o $@ $<
|
||||
|
||||
chain_mod-loader_i386_pc_chainloader_normal.d: loader/i386/pc/chainloader_normal.c
|
||||
set -e; $(CC) -Iloader/i386/pc -I$(srcdir)/loader/i386/pc $(CPPFLAGS) $(CFLAGS) $(chain_mod_CFLAGS) -M $< | sed 's,chainloader_normal\.o[ :]*,chain_mod-loader_i386_pc_chainloader_normal.o $@ : ,g' > $@; [ -s $@ ] || rm -f $@
|
||||
|
||||
-include chain_mod-loader_i386_pc_chainloader_normal.d
|
||||
|
||||
chain_mod_CFLAGS = $(COMMON_CFLAGS)
|
||||
|
||||
# For fshelp.mod.
|
||||
fshelp_mod_SOURCES = fs/fshelp.c
|
||||
CLEANFILES += fshelp.mod mod-fshelp.o mod-fshelp.c pre-fshelp.o fshelp_mod-fs_fshelp.o def-fshelp.lst und-fshelp.lst
|
||||
|
|
|
@ -80,12 +80,16 @@ genmoddep_SOURCES = util/genmoddep.c
|
|||
# Modules.
|
||||
pkgdata_MODULES = _chain.mod _linux.mod fat.mod ufs.mod ext2.mod minix.mod \
|
||||
hfs.mod jfs.mod normal.mod hello.mod vga.mod font.mod _multiboot.mod ls.mod \
|
||||
boot.mod cmp.mod cat.mod terminal.mod fshelp.mod
|
||||
boot.mod cmp.mod cat.mod terminal.mod fshelp.mod chain.mod
|
||||
|
||||
# For _chain.mod.
|
||||
_chain_mod_SOURCES = loader/i386/pc/chainloader.c
|
||||
_chain_mod_CFLAGS = $(COMMON_CFLAGS)
|
||||
|
||||
# For chain.mod.
|
||||
chain_mod_SOURCES = loader/i386/pc/chainloader_normal.c
|
||||
chain_mod_CFLAGS = $(COMMON_CFLAGS)
|
||||
|
||||
# For fshelp.mod.
|
||||
fshelp_mod_SOURCES = fs/fshelp.c
|
||||
fshelp_mod_CFLAGS = $(COMMON_CFLAGS)
|
||||
|
|
34
include/grub/i386/pc/chainloader.h
Normal file
34
include/grub/i386/pc/chainloader.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef GRUB_CHAINLOADER_MACHINE_HEADER
|
||||
#define GRUB_CHAINLOADER_MACHINE_HEADER 1
|
||||
|
||||
#include <grub/dl.h>
|
||||
|
||||
/* Common function for normal and rescue mode commands. */
|
||||
typedef enum
|
||||
{
|
||||
GRUB_CHAINLOADER_FORCE = 0x1
|
||||
} grub_chainloader_flags_t;
|
||||
|
||||
void EXPORT_FUNC(grub_chainloader_cmd) (const char * file,
|
||||
grub_chainloader_flags_t flags);
|
||||
|
||||
#endif /* GRUB_CHAINLOADER_MACHINE_HEADER */
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2002,2003 Free Software Foundation, Inc.
|
||||
* Copyright (C) 2002,2003,2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -41,7 +41,6 @@ void EXPORT_FUNC(grub_multiboot_real_boot) (grub_addr_t entry,
|
|||
|
||||
/* It is necessary to export these functions, because normal mode commands
|
||||
reuse rescue mode commands. */
|
||||
void grub_rescue_cmd_chainloader (int argc, char *argv[]);
|
||||
void grub_rescue_cmd_linux (int argc, char *argv[]);
|
||||
void grub_rescue_cmd_initrd (int argc, char *argv[]);
|
||||
void grub_rescue_cmd_multiboot (int argc, char *argv[]);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* chainloader.c - boot another boot loader */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
* Copyright (C) 2002,2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include <grub/loader.h>
|
||||
#include <grub/machine/loader.h>
|
||||
#include <grub/machine/chainloader.h>
|
||||
#include <grub/file.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/device.h>
|
||||
|
@ -82,28 +83,14 @@ grub_chainloader_unload (void)
|
|||
}
|
||||
|
||||
void
|
||||
grub_rescue_cmd_chainloader (int argc, char *argv[])
|
||||
grub_chainloader_cmd (const char *filename, grub_chainloader_flags_t flags)
|
||||
{
|
||||
grub_file_t file = 0;
|
||||
grub_uint16_t signature;
|
||||
int force = 0;
|
||||
|
||||
grub_dl_ref (my_mod);
|
||||
|
||||
if (argc > 0 && grub_strcmp (argv[0], "--force") == 0)
|
||||
{
|
||||
force = 1;
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
if (argc == 0)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
file = grub_file_open (argv[0]);
|
||||
file = grub_file_open (filename);
|
||||
if (! file)
|
||||
goto fail;
|
||||
|
||||
|
@ -119,7 +106,8 @@ grub_rescue_cmd_chainloader (int argc, char *argv[])
|
|||
|
||||
/* Check the signature. */
|
||||
signature = *((grub_uint16_t *) (0x7C00 + GRUB_DISK_SECTOR_SIZE - 2));
|
||||
if (signature != grub_le_to_cpu16 (0xaa55) && ! force)
|
||||
if (signature != grub_le_to_cpu16 (0xaa55)
|
||||
&& ! (flags & GRUB_CHAINLOADER_FORCE))
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_OS, "invalid signature");
|
||||
goto fail;
|
||||
|
@ -137,6 +125,24 @@ grub_rescue_cmd_chainloader (int argc, char *argv[])
|
|||
grub_dl_unref (my_mod);
|
||||
}
|
||||
|
||||
static void
|
||||
grub_rescue_cmd_chainloader (int argc, char *argv[])
|
||||
{
|
||||
grub_chainloader_flags_t flags = 0;
|
||||
|
||||
if (argc > 0 && grub_strcmp (argv[0], "--force") == 0)
|
||||
{
|
||||
flags |= GRUB_CHAINLOADER_FORCE;
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
if (argc == 0)
|
||||
grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified");
|
||||
else
|
||||
grub_chainloader_cmd (argv[0], flags);
|
||||
}
|
||||
|
||||
static const char loader_name[] = "chainloader";
|
||||
|
||||
GRUB_MOD_INIT
|
||||
|
|
57
loader/i386/pc/chainloader_normal.c
Normal file
57
loader/i386/pc/chainloader_normal.c
Normal file
|
@ -0,0 +1,57 @@
|
|||
/* chainloader_normal.c - boot another boot loader */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <grub/machine/chainloader.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/normal.h>
|
||||
#include <grub/dl.h>
|
||||
|
||||
static const struct grub_arg_option options[] =
|
||||
{
|
||||
{"force", 'f', 0, "Skip bootsector magic number test.", 0, 0},
|
||||
{0, 0, 0, 0, 0, 0}
|
||||
};
|
||||
|
||||
static grub_err_t
|
||||
chainloader_command (struct grub_arg_list *state,
|
||||
int argc, char **args)
|
||||
{
|
||||
grub_chainloader_flags_t flags = state[0].set ? GRUB_CHAINLOADER_FORCE : 0;
|
||||
|
||||
if (argc == 0)
|
||||
grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified");
|
||||
else
|
||||
grub_chainloader_cmd (args[0], flags);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
GRUB_MOD_INIT
|
||||
{
|
||||
(void) mod; /* To stop warning. */
|
||||
grub_register_command ("chainloader", chainloader_command,
|
||||
GRUB_COMMAND_FLAG_BOTH,
|
||||
"chainloader [options] FILE",
|
||||
"Prepare to boot another boot loader", options);
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI
|
||||
{
|
||||
grub_unregister_command ("chainloader");
|
||||
}
|
Loading…
Reference in a new issue