From 909301af11e312a64fba7929bbb53f48b9460615 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 7 Feb 2010 02:07:35 +0100 Subject: [PATCH] First try at generating grub-emu from modules --- Makefile.in | 2 +- commands/sleep.c | 1 - conf/any-emu.rmk | 113 ++++++++++++++++++++----------------------- configure.ac | 1 + disk/loopback.c | 4 +- font/font_cmd.c | 4 +- genemuinit.sh | 68 ++++++++++++++++++++++++++ genemuinitheader.sh | 48 ++++++++++++++++++ include/grub/i18n.h | 8 +-- partmap/acorn.c | 4 +- partmap/amiga.c | 4 +- partmap/apple.c | 4 +- partmap/gpt.c | 4 +- partmap/msdos.c | 4 +- partmap/sun.c | 4 +- parttool/msdospart.c | 4 +- term/gfxterm.c | 12 ++--- util/grub-emu.c | 6 +-- video/bitmap.c | 4 +- video/readers/jpeg.c | 4 +- video/readers/png.c | 4 +- video/readers/tga.c | 4 +- video/video.c | 4 +- 23 files changed, 209 insertions(+), 106 deletions(-) create mode 100644 genemuinit.sh create mode 100644 genemuinitheader.sh diff --git a/Makefile.in b/Makefile.in index 46b380cd5..faf13a134 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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@ diff --git a/commands/sleep.c b/commands/sleep.c index 9207b60a7..cb208c96f 100644 --- a/commands/sleep.c +++ b/commands/sleep.c @@ -22,7 +22,6 @@ #include #include #include -#include #include static const struct grub_arg_option options[] = diff --git a/conf/any-emu.rmk b/conf/any-emu.rmk index fb97de0a0..310076345 100644 --- a/conf/any-emu.rmk +++ b/conf/any-emu.rmk @@ -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) diff --git a/configure.ac b/configure.ac index 6560d3e31..098e4524e 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/disk/loopback.c b/disk/loopback.c index 29805182e..a8bc25d8c 100644 --- a/disk/loopback.c +++ b/disk/loopback.c @@ -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); diff --git a/font/font_cmd.c b/font/font_cmd.c index 0402b8d77..b3eeb4dca 100644 --- a/font/font_cmd.c +++ b/font/font_cmd.c @@ -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. */ diff --git a/genemuinit.sh b/genemuinit.sh new file mode 100644 index 000000000..e40a683af --- /dev/null +++ b/genemuinit.sh @@ -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 <. + */ + +#include "grub_emu_init.h" + +EOF + +cat <. + */ + +EOF + +cat < # include -# 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 diff --git a/partmap/acorn.c b/partmap/acorn.c index e005975c0..ed8738755 100644 --- a/partmap/acorn.c +++ b/partmap/acorn.c @@ -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); } diff --git a/partmap/amiga.c b/partmap/amiga.c index dce9f4f1f..f769d4048 100644 --- a/partmap/amiga.c +++ b/partmap/amiga.c @@ -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); } diff --git a/partmap/apple.c b/partmap/apple.c index 4dea55a32..6208ebcea 100644 --- a/partmap/apple.c +++ b/partmap/apple.c @@ -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); } diff --git a/partmap/gpt.c b/partmap/gpt.c index 4a4957437..46f3f0a37 100644 --- a/partmap/gpt.c +++ b/partmap/gpt.c @@ -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); } diff --git a/partmap/msdos.c b/partmap/msdos.c index 6ba7fb927..bae7ced9b 100644 --- a/partmap/msdos.c +++ b/partmap/msdos.c @@ -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); } diff --git a/partmap/sun.c b/partmap/sun.c index e816ec17a..39cd29969 100644 --- a/partmap/sun.c +++ b/partmap/sun.c @@ -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); } diff --git a/parttool/msdospart.c b/parttool/msdospart.c index dbb25bc52..6ce48a977 100644 --- a/parttool/msdospart.c +++ b/parttool/msdospart.c @@ -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); diff --git a/term/gfxterm.c b/term/gfxterm.c index f161499e6..5c94a6b9a 100644 --- a/term/gfxterm.c +++ b/term/gfxterm.c @@ -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); diff --git a/util/grub-emu.c b/util/grub-emu.c index e65c8585e..b3117ab53 100644 --- a/util/grub-emu.c +++ b/util/grub-emu.c @@ -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[] = diff --git a/video/bitmap.c b/video/bitmap.c index 7b135a5dc..02ded85c6 100644 --- a/video/bitmap.c +++ b/video/bitmap.c @@ -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) { } diff --git a/video/readers/jpeg.c b/video/readers/jpeg.c index 460a52872..8b7398c39 100644 --- a/video/readers/jpeg.c +++ b/video/readers/jpeg.c @@ -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"); diff --git a/video/readers/png.c b/video/readers/png.c index c2008aeb2..7acce2145 100644 --- a/video/readers/png.c +++ b/video/readers/png.c @@ -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"); diff --git a/video/readers/tga.c b/video/readers/tga.c index d0ca2770f..5f0a7f890 100644 --- a/video/readers/tga.c +++ b/video/readers/tga.c @@ -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"); diff --git a/video/video.c b/video/video.c index c1d66bdd0..5dcca7c7e 100644 --- a/video/video.c +++ b/video/video.c @@ -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) { }