First try at generating grub-emu from modules

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-02-07 02:07:35 +01:00
parent 009ec74317
commit 909301af11
23 changed files with 209 additions and 106 deletions

View file

@ -84,7 +84,7 @@ TARGET_ASFLAGS = @TARGET_ASFLAGS@
TARGET_MODULE_FORMAT = @TARGET_MODULE_FORMAT@
TARGET_APPLE_CC = @TARGET_APPLE_CC@
OBJCONV = @OBJCONV@
TARGET_CPPFLAGS = @TARGET_CPPFLAGS@ -nostdinc -isystem $(shell $(TARGET_CC) -print-file-name=include) -I$(srcdir)/include -I$(builddir) -I$(builddir)/include \
TARGET_CPPFLAGS = @TARGET_CPPFLAGS@ -I$(srcdir)/include -I$(builddir) -I$(builddir)/include \
-Wall -W
TARGET_LDFLAGS = @TARGET_LDFLAGS@
TARGET_IMG_LDSCRIPT = @TARGET_IMG_LDSCRIPT@

View file

@ -22,7 +22,6 @@
#include <grub/time.h>
#include <grub/types.h>
#include <grub/misc.h>
#include <grub/machine/time.h>
#include <grub/extcmd.h>
static const struct grub_arg_option options[] =

View file

@ -1,94 +1,85 @@
# -*- makefile -*-
COMMON_LDFLAGS += -nostdlib
COMMON_CFLAGS += -DGRUB_UTIL=1
# Used by various components. These rules need to precede them.
script/lexer.c_DEPENDENCIES = grub_script.tab.h
sbin_UTILITIES += grub-emu
#sbin_UTILITIES += grub-emu
util/grub-emu.c_DEPENDENCIES = grub_emu_init.h
grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \
commands/configfile.c commands/echo.c commands/help.c \
commands/handler.c commands/ls.c commands/test.c \
commands/search.c commands/blocklist.c commands/hexdump.c \
lib/hexdump.c commands/halt.c commands/reboot.c \
lib/envblk.c commands/loadenv.c \
commands/gptsync.c commands/probe.c commands/xnu_uuid.c \
commands/password.c commands/keystatus.c \
disk/host.c disk/loopback.c disk/scsi.c \
fs/fshelp.c \
\
io/gzio.c \
kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c \
pkglib_MODULES += main.mod
main_mod_SOURCES = kern/device.c kern/disk.c kern/dl.c kern/env.c \
kern/err.c kern/list.c kern/handler.c \
kern/command.c kern/corecmd.c commands/extcmd.c kern/file.c \
kern/command.c kern/corecmd.c kern/file.c \
kern/fs.c commands/boot.c kern/main.c kern/misc.c kern/parser.c \
kern/partition.c kern/reader.c kern/term.c \
kern/rescue_reader.c kern/rescue_parser.c \
lib/arg.c normal/cmdline.c normal/datetime.c normal/misc.c \
normal/handler.c normal/auth.c normal/autofs.c \
normal/completion.c normal/main.c normal/color.c \
normal/menu.c normal/menu_entry.c normal/menu_viewer.c \
normal/menu_text.c \
script/main.c script/execute.c script/function.c \
script/lexer.c script/script.c grub_script.tab.c \
partmap/amiga.c partmap/apple.c partmap/msdos.c partmap/sun.c \
partmap/acorn.c partmap/gpt.c \
\
fs/affs.c fs/cpio.c fs/fat.c fs/ext2.c fs/hfs.c \
fs/hfsplus.c fs/iso9660.c fs/udf.c fs/jfs.c fs/minix.c \
fs/ntfs.c fs/ntfscomp.c fs/reiserfs.c fs/sfs.c \
fs/ufs.c fs/ufs2.c fs/xfs.c fs/afs.c fs/afs_be.c \
fs/befs.c fs/befs_be.c fs/tar.c \
\
util/console.c util/hostfs.c util/grub-emu.c util/misc.c \
util/console.c util/grub-emu.c util/misc.c \
util/hostdisk.c util/getroot.c \
\
disk/raid.c disk/raid5_recover.c disk/raid6_recover.c \
disk/mdraid_linux.c disk/dmraid_nvidia.c disk/lvm.c \
commands/parttool.c parttool/msdospart.c \
grub_emu_init.c gnulib/progname.c
main_mod_CFLAGS = $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1
main_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For hostfs.mod.
pkglib_MODULES += hostfs.mod
hostfs_mod_SOURCES = util/hostfs.c
hostfs_mod_CFLAGS = $(COMMON_CFLAGS)
hostfs_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For host.mod.
pkglib_MODULES += host.mod
host_mod_SOURCES = disk/host.c
host_mod_CFLAGS = $(COMMON_CFLAGS)
host_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For reboot.mod.
pkglib_MODULES += reboot.mod
reboot_mod_SOURCES = commands/reboot.c
reboot_mod_CFLAGS = $(COMMON_CFLAGS)
reboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For halt.mod.
pkglib_MODULES += halt.mod
halt_mod_SOURCES = commands/halt.c
halt_mod_CFLAGS = $(COMMON_CFLAGS)
halt_mod_LDFLAGS = $(COMMON_LDFLAGS)
ifeq ($(target_cpu), i386)
grub_emu_SOURCES += commands/i386/cpuid.c
pkglib_MODULES += cpuid.mod
cpuid_mod_SOURCES = commands/i386/cpuid.c
cpuid_mod_CFLAGS = $(COMMON_CFLAGS)
cpuid_mod_LDFLAGS = $(COMMON_LDFLAGS)
endif
grub_emu_LDFLAGS = $(LIBCURSES)
ifeq ($(enable_grub_emu_usb), yes)
grub_emu_SOURCES += disk/usbms.c util/usb.c bus/usb/usb.c \
pkglib_MODULES += usb.mod
usb_mod_SOURCES = disk/usbms.c util/usb.c bus/usb/usb.c \
commands/usbtest.c
grub_emu_LDFLAGS += $(LIBCURSES) $(LIBUSB)
cpuid_mod_CFLAGS = $(COMMON_CFLAGS)
usb_mod_LDFLAGS = $(COMMON_LDFLAGS) $(LIBUSB)
endif
ifeq ($(enable_grub_emu_pci), yes)
grub_emu_SOURCES += util/pci.c commands/lspci.c
grub_emu_LDFLAGS += $(LIBPCIACCESS)
pkglib_MODULES += pci.mod
pci_mod_SOURCES = util/pci.c commands/lspci.c
pci_mod_LDFLAGS = $(LIBPCIACCESS)
endif
grub_emu_init.lst: geninit.sh $(filter-out grub_emu_init.c,$(grub_emu_SOURCES))
rm -f $@; grep GRUB_MOD_INIT $(filter %.c,$^) /dev/null > $@
DISTCLEANFILES += grub_emu_init.lst
grub_emu_init.h: grub_emu_init.lst $(filter-out grub_emu_init.c,$(grub_emu_SOURCES)) geninitheader.sh
rm -f $@; sh $(srcdir)/geninitheader.sh $< > $@
grub_emu_init.h: genemuinitheader.sh
rm -f $@; echo $(pkglib_MODULES) |sh $(srcdir)/genemuinitheader.sh > $@
DISTCLEANFILES += grub_emu_init.h
grub_emu_init.c: grub_emu_init.lst $(filter-out grub_emu_init.c,$(grub_emu_SOURCES)) geninit.sh grub_emu_init.h
rm -f $@; sh $(srcdir)/geninit.sh $< $(filter %.c,$^) > $@
grub_emu_init.c: genemuinit.sh
rm -f $@; echo $(pkglib_MODULES) |sed 's,elf.mod,,;s,extcmd.mod,,;s,main.mod,,;s,gzio.mod,,;s,fshelp.mod,,;s,bufio.mod,,;s,setjmp.mod,,;'|sh $(srcdir)/genemuinit.sh > $@
DISTCLEANFILES += grub_emu_init.c
include $(srcdir)/conf/common.mk
# FIXME: this could be shared with common.rmk
# For grub-mkfont.
ifeq ($(enable_grub_mkfont), yes)
bin_UTILITIES += grub-mkfont
grub_mkfont_SOURCES = gnulib/progname.c util/grub-mkfont.c util/misc.c
grub_mkfont_CFLAGS = $(freetype_cflags)
grub_mkfont_LDFLAGS = $(freetype_libs)
endif
grub_script.tab.c grub_script.tab.h: script/parser.y
$(YACC) -d -p grub_script_yy -b grub_script $(srcdir)/script/parser.y
DISTCLEANFILES += grub_script.tab.c grub_script.tab.h
grub-emu: $(pkglib_MODULES)
$(CC) -o $@ $(pkglib_MODULES) $(grub_emu_LDFLAGS) $(LDFLAGS) $(grub_emu_SOURCES)

View file

@ -74,6 +74,7 @@ fi
if test -z "$target_alias"; then
case "$target_cpu"-"$platform" in
x86_64-efi) ;;
x86_64-emu) ;;
x86_64-*) target_cpu=i386 ;;
powerpc64-ieee1275) target_cpu=powerpc ;;
esac

View file

@ -241,7 +241,7 @@ static struct grub_disk_dev grub_loopback_dev =
static grub_extcmd_t cmd;
GRUB_MOD_INIT(loop)
GRUB_MOD_INIT(loopback)
{
cmd = grub_register_extcmd ("loopback", grub_cmd_loopback,
GRUB_COMMAND_FLAG_BOTH,
@ -250,7 +250,7 @@ GRUB_MOD_INIT(loop)
grub_disk_dev_register (&grub_loopback_dev);
}
GRUB_MOD_FINI(loop)
GRUB_MOD_FINI(loopback)
{
grub_unregister_extcmd (cmd);
grub_disk_dev_unregister (&grub_loopback_dev);

View file

@ -56,7 +56,7 @@ lsfonts_command (grub_command_t cmd __attribute__ ((unused)),
static grub_command_t cmd_loadfont, cmd_lsfonts;
GRUB_MOD_INIT(font_manager)
GRUB_MOD_INIT(font)
{
grub_font_loader_init ();
@ -69,7 +69,7 @@ GRUB_MOD_INIT(font_manager)
0, "List the loaded fonts.");
}
GRUB_MOD_FINI(font_manager)
GRUB_MOD_FINI(font)
{
/* TODO: Determine way to free allocated resources.
Warning: possible pointer references could be in use. */

68
genemuinit.sh Normal file
View file

@ -0,0 +1,68 @@
#! /bin/sh
#
# Copyright (C) 2002,2005,2007 Free Software Foundation, Inc.
#
# This gensymlist.sh is free software; the author
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
lst="$1"
shift
cat <<EOF
/* This file is automatically generated by geninit.sh. DO NOT EDIT! */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2005,2007 Free Software Foundation, Inc.
*
* GRUB 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 3 of the License, or
* (at your option) any later version.
*
* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include "grub_emu_init.h"
EOF
cat <<EOF
void
grub_init_all (void)
{
EOF
read mods
for line in $mods; do
echo "grub_${line}_init ();" | sed 's,\.mod,,g;'
done
cat <<EOF
}
EOF
cat <<EOF
void
grub_fini_all (void)
{
EOF
for line in $mods; do
echo "grub_${line}_fini ();" | sed 's,\.mod,,g;'
done
cat <<EOF
}
EOF

48
genemuinitheader.sh Normal file
View file

@ -0,0 +1,48 @@
#! /bin/sh
#
# Copyright (C) 2005,2007 Free Software Foundation, Inc.
#
# This gensymlist.sh is free software; the author
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
lst="$1"
shift
cat <<EOF
/* This file is automatically generated by gensymlist.sh. DO NOT EDIT! */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2005,2007 Free Software Foundation, Inc.
*
* GRUB 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 3 of the License, or
* (at your option) any later version.
*
* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
EOF
cat <<EOF
void grub_init_all (void);
void grub_fini_all (void);
EOF
read mods
for line in $mods; do
echo "void grub_${line}_init (void);" | sed 's,\.mod,,g;'
echo "void grub_${line}_fini (void);" | sed 's,\.mod,,g;'
done

View file

@ -19,17 +19,17 @@
#ifndef GRUB_I18N_H
#define GRUB_I18N_H 1
#ifdef GRUB_UTIL
//#ifdef GRUB_UTIL
# include <locale.h>
# include <libintl.h>
# define _(str) gettext(str)
#else
//# define _(str) gettext(str)
//#else
# define _(str) grub_gettext(str)
const char *EXPORT_FUNC(grub_gettext_dummy) (const char *s);
extern const char *(*EXPORT_VAR(grub_gettext)) (const char *s);
#endif
//#endif
#define N_(str) str

View file

@ -195,12 +195,12 @@ static struct grub_partition_map grub_acorn_partition_map =
.get_name = acorn_partition_map_get_name
};
GRUB_MOD_INIT(acorn_partition_map)
GRUB_MOD_INIT(part_acorn)
{
grub_partition_map_register (&grub_acorn_partition_map);
}
GRUB_MOD_FINI(acorn_partition_map)
GRUB_MOD_FINI(part_acorn)
{
grub_partition_map_unregister (&grub_acorn_partition_map);
}

View file

@ -204,12 +204,12 @@ static struct grub_partition_map grub_amiga_partition_map =
.get_name = amiga_partition_map_get_name
};
GRUB_MOD_INIT(amiga_partition_map)
GRUB_MOD_INIT(part_amiga)
{
grub_partition_map_register (&grub_amiga_partition_map);
}
GRUB_MOD_FINI(amiga_partition_map)
GRUB_MOD_FINI(part_amiga)
{
grub_partition_map_unregister (&grub_amiga_partition_map);
}

View file

@ -247,12 +247,12 @@ static struct grub_partition_map grub_apple_partition_map =
.get_name = apple_partition_map_get_name
};
GRUB_MOD_INIT(apple_partition_map)
GRUB_MOD_INIT(part_apple)
{
grub_partition_map_register (&grub_apple_partition_map);
}
GRUB_MOD_FINI(apple_partition_map)
GRUB_MOD_FINI(part_apple)
{
grub_partition_map_unregister (&grub_apple_partition_map);
}

View file

@ -182,12 +182,12 @@ static struct grub_partition_map grub_gpt_partition_map =
.get_name = gpt_partition_map_get_name
};
GRUB_MOD_INIT(gpt_partition_map)
GRUB_MOD_INIT(part_gpt)
{
grub_partition_map_register (&grub_gpt_partition_map);
}
GRUB_MOD_FINI(gpt_partition_map)
GRUB_MOD_FINI(part_gpt)
{
grub_partition_map_unregister (&grub_gpt_partition_map);
}

View file

@ -327,12 +327,12 @@ static struct grub_partition_map grub_msdos_partition_map =
.get_name = pc_partition_map_get_name
};
GRUB_MOD_INIT(pc_partition_map)
GRUB_MOD_INIT(part_msdos)
{
grub_partition_map_register (&grub_msdos_partition_map);
}
GRUB_MOD_FINI(pc_partition_map)
GRUB_MOD_FINI(part_msdos)
{
grub_partition_map_unregister (&grub_msdos_partition_map);
}

View file

@ -202,12 +202,12 @@ static struct grub_partition_map grub_sun_partition_map =
.get_name = sun_partition_map_get_name
};
GRUB_MOD_INIT(sun_partition_map)
GRUB_MOD_INIT(part_sun)
{
grub_partition_map_register (&grub_sun_partition_map);
}
GRUB_MOD_FINI(sun_partition_map)
GRUB_MOD_FINI(part_sun)
{
grub_partition_map_unregister (&grub_sun_partition_map);
}

View file

@ -138,7 +138,7 @@ static grub_err_t grub_pcpart_type (const grub_device_t dev,
return GRUB_ERR_NONE;
}
GRUB_MOD_INIT (pcpart)
GRUB_MOD_INIT (msdospart)
{
activate_table_handle = grub_parttool_register ("part_msdos",
grub_pcpart_boot,
@ -148,7 +148,7 @@ GRUB_MOD_INIT (pcpart)
grub_pcpart_typeargs);
}
GRUB_MOD_FINI(pcpart)
GRUB_MOD_FINI(msdospart)
{
grub_parttool_unregister (activate_table_handle);
grub_parttool_unregister (type_table_handle);

View file

@ -251,7 +251,7 @@ static int NESTED_FUNC_ATTR video_hook (grub_video_adapter_t p __attribute__ ((u
}
static grub_err_t
grub_gfxterm_init (void)
grub_gfxterm_term_init (void)
{
char *font_name;
char *modevar;
@ -312,7 +312,7 @@ grub_gfxterm_init (void)
}
static grub_err_t
grub_gfxterm_fini (void)
grub_gfxterm_term_fini (void)
{
if (bitmap)
{
@ -932,8 +932,8 @@ grub_gfxterm_background_image_cmd (grub_command_t cmd __attribute__ ((unused)),
static struct grub_term_output grub_video_term =
{
.name = "gfxterm",
.init = grub_gfxterm_init,
.fini = grub_gfxterm_fini,
.init = grub_gfxterm_term_init,
.fini = grub_gfxterm_term_fini,
.putchar = grub_gfxterm_putchar,
.getcharwidth = grub_gfxterm_getcharwidth,
.getwh = grub_virtual_screen_getwh,
@ -951,7 +951,7 @@ static struct grub_term_output grub_video_term =
static grub_command_t cmd;
GRUB_MOD_INIT(term_gfxterm)
GRUB_MOD_INIT(gfxterm)
{
grub_term_register_output ("gfxterm", &grub_video_term);
cmd = grub_register_command ("background_image",
@ -959,7 +959,7 @@ GRUB_MOD_INIT(term_gfxterm)
0, "Load background image for active terminal");
}
GRUB_MOD_FINI(term_gfxterm)
GRUB_MOD_FINI(gfxterm)
{
grub_unregister_command (cmd);
grub_term_unregister_output (&grub_video_term);

View file

@ -51,7 +51,7 @@ static char *prefix = NULL;
grub_addr_t
grub_arch_modules_addr (void)
{
return NULL;
return 0;
}
grub_err_t
@ -106,10 +106,6 @@ grub_machine_fini (void)
grub_console_fini ();
}
void
read_command_list (void)
{
}
static struct option options[] =

View file

@ -243,11 +243,11 @@ void *grub_video_bitmap_get_data (struct grub_video_bitmap *bitmap)
}
/* Initialize bitmap module. */
GRUB_MOD_INIT(video_bitmap)
GRUB_MOD_INIT(bitmap)
{
}
/* Finalize bitmap module. */
GRUB_MOD_FINI(video_bitmap)
GRUB_MOD_FINI(bitmap)
{
}

View file

@ -725,7 +725,7 @@ static struct grub_video_bitmap_reader jpeg_reader = {
.next = 0
};
GRUB_MOD_INIT (video_reader_jpeg)
GRUB_MOD_INIT (jpeg)
{
grub_video_bitmap_reader_register (&jpg_reader);
grub_video_bitmap_reader_register (&jpeg_reader);
@ -736,7 +736,7 @@ GRUB_MOD_INIT (video_reader_jpeg)
#endif
}
GRUB_MOD_FINI (video_reader_jpeg)
GRUB_MOD_FINI (jpeg)
{
#if defined(JPEG_DEBUG)
grub_unregister_command ("jpegtest");

View file

@ -890,7 +890,7 @@ static struct grub_video_bitmap_reader png_reader = {
.next = 0
};
GRUB_MOD_INIT (video_reader_png)
GRUB_MOD_INIT (png)
{
grub_video_bitmap_reader_register (&png_reader);
#if defined(PNG_DEBUG)
@ -900,7 +900,7 @@ GRUB_MOD_INIT (video_reader_png)
#endif
}
GRUB_MOD_FINI (video_reader_png)
GRUB_MOD_FINI (png)
{
#if defined(PNG_DEBUG)
grub_unregister_command ("pngtest");

View file

@ -476,7 +476,7 @@ static struct grub_video_bitmap_reader tga_reader = {
.next = 0
};
GRUB_MOD_INIT(video_reader_tga)
GRUB_MOD_INIT(tga)
{
grub_video_bitmap_reader_register (&tga_reader);
#if defined(TGA_DEBUG)
@ -485,7 +485,7 @@ GRUB_MOD_INIT(video_reader_tga)
#endif
}
GRUB_MOD_FINI(video_reader_tga)
GRUB_MOD_FINI(tga)
{
#if defined(TGA_DEBUG)
grub_unregister_command ("tgatest");

View file

@ -713,11 +713,11 @@ grub_video_set_mode (const char *modestring,
}
/* Initialize Video API module. */
GRUB_MOD_INIT(video_video)
GRUB_MOD_INIT(video)
{
}
/* Finalize Video API module. */
GRUB_MOD_FINI(video_video)
GRUB_MOD_FINI(video)
{
}