Resync with trunk

This commit is contained in:
Robert Millan 2010-01-18 15:02:21 +00:00
commit e68d3b243f
706 changed files with 157184 additions and 45875 deletions

65
.bzrignore Normal file
View File

@ -0,0 +1,65 @@
00_header
10_*
30_os-prober
40_custom
aclocal.m4
autom4te.cache
build_env.mk
.bzrignore
config.cache
config.guess
config.h
config.h.in
config.log
config.status
config.sub
configure
conf/*.mk
conf/gcry.rmk
*.d
DISTLIST
docs/*.info
docs/stamp-vti
docs/version.texi
*.elf
*.exec
genkernsyms.sh
gensymlist.sh
grub-dumpbios
grub-editenv
grub-emu
grub_emu_init.c
grub_emu_init.h
grub-fstest
grub_fstest_init.c
grub_fstest_init.h
grub-install
grub-mk*
grub-pbkdf2
grub-pe2elf
grub-probe
grub_probe_init.c
grub_probe_init.h
grub_script.tab.c
grub_script.tab.h
grub-setup
grub_setup_init.c
grub_setup_init.h
*.img
include/grub/cpu
include/grub/machine
install-sh
lib/libgcrypt-grub
*.lst
Makefile
*.mod
mod-*.c
missing
*.pf2
po/*.mo
po/grub.pot
stamp-h
stamp-h1
stamp-h.in
symlist.c
update-grub_lib

View File

@ -1,36 +0,0 @@
*.d
*.exec
*.img
*.lst
*.mod
00_header
10_hurd
10_linux
Makefile
autom4te.cache
config.cache
config.h
config.log
config.status
genkernsyms.sh
gensymlist.sh
grub-install
grub-mkdevicemap
grub-mkimage
grub-mkrescue
grub-probe
grub-setup
grub_probe_init.c
grub_probe_init.h
grub_script.tab.c
grub_script.tab.h
grub_setup_init.c
grub_setup_init.h
kernel.elf
kernel_elf_symlist.c
mod-*.c
stamp-h
stamp-h1
symlist.c
update-grub
update-grub_lib

14898
ChangeLog

File diff suppressed because it is too large Load Diff

340
DISTLIST
View File

@ -1,340 +0,0 @@
AUTHORS
COPYING
ChangeLog
DISTLIST
INSTALL
NEWS
README
THANKS
TODO
Makefile.in
aclocal.m4
autogen.sh
config.guess
config.h.in
config.sub
configure
configure.ac
gencmdlist.sh
gendistlist.sh
genfslist.sh
geninitheader.sh
geninit.sh
genkernsyms.sh.in
genmk.rb
genmoddep.awk
genmodsrc.sh
gensymlist.sh.in
install-sh
mkinstalldirs
stamp-h.in
boot/i386/pc/boot.S
boot/i386/pc/diskboot.S
boot/i386/pc/lnxboot.S
boot/i386/pc/pxeboot.S
commands/boot.c
commands/blocklist.c
commands/cat.c
commands/cmp.c
commands/configfile.c
commands/echo.c
commands/help.c
commands/hexdump.c
commands/ls.c
commands/search.c
commands/terminal.c
commands/test.c
commands/videotest.c
commands/i386/cpuid.c
commands/i386/pc/halt.c
commands/i386/pc/play.c
commands/i386/pc/reboot.c
commands/i386/pc/vbeinfo.c
commands/i386/pc/vbetest.c
commands/ieee1275/halt.c
commands/ieee1275/reboot.c
commands/ieee1275/suspend.c
conf/common.mk
conf/common.rmk
conf/i386-efi.mk
conf/i386-efi.rmk
conf/i386-linuxbios.rmk
conf/i386-linuxbios.mk
conf/i386-pc.mk
conf/i386-pc.rmk
conf/powerpc-ieee1275.mk
conf/powerpc-ieee1275.rmk
conf/sparc64-ieee1275.mk
conf/sparc64-ieee1275.rmk
disk/ata.c
disk/host.c
disk/loopback.c
disk/lvm.c
disk/raid.c
disk/efi/efidisk.c
disk/i386/pc/biosdisk.c
disk/ieee1275/ofdisk.c
font/manager.c
fs/affs.c
fs/cpio.c
fs/ext2.c
fs/fat.c
fs/fshelp.c
fs/hfs.c
fs/hfsplus.c
fs/iso9660.c
fs/jfs.c
fs/minix.c
fs/ntfs.c
fs/ntfscomp.c
fs/reiserfs.c
fs/sfs.c
fs/ufs.c
fs/xfs.c
hello/hello.c
include/multiboot.h
include/multiboot2.h
include/grub/acorn_filecore.h
include/grub/arg.h
include/grub/bitmap.h
include/grub/boot.h
include/grub/cache.h
include/grub/device.h
include/grub/disk.h
include/grub/dl.h
include/grub/elf.h
include/grub/elfload.h
include/grub/env.h
include/grub/err.h
include/grub/file.h
include/grub/font.h
include/grub/fs.h
include/grub/fshelp.h
include/grub/gzio.h
include/grub/hexdump.h
include/grub/hfs.h
include/grub/kernel.h
include/grub/loader.h
include/grub/lvm.h
include/grub/misc.h
include/grub/mm.h
include/grub/multiboot.h
include/grub/multiboot_loader.h
include/grub/multiboot2.h
include/grub/net.h
include/grub/normal.h
include/grub/ntfs.h
include/grub/parser.h
include/grub/partition.h
include/grub/pc_partition.h
include/grub/raid.h
include/grub/rescue.h
include/grub/script.h
include/grub/setjmp.h
include/grub/symbol.h
include/grub/term.h
include/grub/terminfo.h
include/grub/tparm.h
include/grub/types.h
include/grub/video.h
include/grub/efi/api.h
include/grub/efi/chainloader.h
include/grub/efi/console.h
include/grub/efi/console_control.h
include/grub/efi/disk.h
include/grub/efi/efi.h
include/grub/efi/pe32.h
include/grub/efi/time.h
include/grub/i386/linux.h
include/grub/i386/loader.h
include/grub/i386/setjmp.h
include/grub/i386/time.h
include/grub/i386/types.h
include/grub/i386/efi/kernel.h
include/grub/i386/efi/loader.h
include/grub/i386/efi/time.h
include/grub/i386/ieee1275/loader.h
include/grub/i386/ieee1275/machine.h
include/grub/i386/ieee1275/memory.h
include/grub/i386/ieee1275/serial.h
include/grub/i386/io.h
include/grub/i386/linuxbios/boot.h
include/grub/i386/linuxbios/console.h
include/grub/i386/linuxbios/init.h
include/grub/i386/linuxbios/kernel.h
include/grub/i386/linuxbios/loader.h
include/grub/i386/linuxbios/memory.h
include/grub/i386/linuxbios/serial.h
include/grub/i386/linuxbios/time.h
include/grub/i386/pc/biosdisk.h
include/grub/i386/pc/boot.h
include/grub/i386/pc/chainloader.h
include/grub/i386/pc/console.h
include/grub/i386/pc/init.h
include/grub/i386/pc/kernel.h
include/grub/i386/pc/loader.h
include/grub/i386/pc/machine.h
include/grub/i386/pc/memory.h
include/grub/i386/pc/serial.h
include/grub/i386/pc/time.h
include/grub/i386/pc/vbe.h
include/grub/i386/pc/vbeblit.h
include/grub/i386/pc/vbefill.h
include/grub/i386/pc/vbeutil.h
include/grub/i386/pc/vga.h
include/grub/ieee1275/ieee1275.h
include/grub/ieee1275/ofdisk.h
include/grub/powerpc/libgcc.h
include/grub/powerpc/setjmp.h
include/grub/powerpc/time.h
include/grub/powerpc/types.h
include/grub/powerpc/ieee1275/biosdisk.h
include/grub/powerpc/ieee1275/console.h
include/grub/powerpc/ieee1275/ieee1275.h
include/grub/powerpc/ieee1275/kernel.h
include/grub/powerpc/ieee1275/loader.h
include/grub/powerpc/ieee1275/time.h
include/grub/powerpc/ieee1275/util/biosdisk.h
include/grub/sparc64/setjmp.h
include/grub/sparc64/time.h
include/grub/sparc64/types.h
include/grub/sparc64/ieee1275/console.h
include/grub/sparc64/ieee1275/ieee1275.h
include/grub/sparc64/ieee1275/kernel.h
include/grub/sparc64/ieee1275/time.h
include/grub/time.h
include/grub/util/biosdisk.h
include/grub/util/getroot.h
include/grub/util/lvm.h
include/grub/util/misc.h
include/grub/util/raid.h
include/grub/util/resolve.h
io/gzio.c
kern/device.c
kern/disk.c
kern/dl.c
kern/elf.c
kern/env.c
kern/err.c
kern/file.c
kern/fs.c
kern/loader.c
kern/main.c
kern/misc.c
kern/mm.c
kern/parser.c
kern/partition.c
kern/rescue.c
kern/term.c
kern/efi/init.c
kern/efi/efi.c
kern/efi/mm.c
kern/i386/dl.c
kern/i386/efi/init.c
kern/i386/efi/startup.S
kern/i386/loader.S
kern/i386/linuxbios/init.c
kern/i386/linuxbios/startup.S
kern/i386/linuxbios/table.c
term/i386/pc/at_keyboard.c
kern/i386/pc/init.c
kern/i386/pc/lzo1x.S
kern/i386/pc/startup.S
term/i386/pc/vga_text.c
kern/i386/realmode.S
kern/ieee1275/ieee1275.c
kern/powerpc/cache.S
kern/powerpc/dl.c
kern/powerpc/ieee1275/cmain.c
kern/powerpc/ieee1275/crt0.S
kern/powerpc/ieee1275/init.c
kern/powerpc/ieee1275/openfw.c
kern/sparc64/cache.S
kern/sparc64/dl.c
kern/sparc64/ieee1275/init.c
kern/sparc64/ieee1275/openfw.c
loader/multiboot_loader.c
loader/multiboot_loader_normal.c
loader/multiboot2.c
loader/efi/chainloader.c
loader/efi/chainloader_normal.c
loader/i386/efi/linux.c
loader/i386/efi/linux_normal.c
loader/i386/pc/chainloader.c
loader/i386/pc/chainloader_normal.c
loader/i386/pc/linux.c
loader/i386/pc/linux_normal.c
loader/i386/pc/multiboot.c
loader/i386/pc/multiboot_normal.c
loader/i386/pc/multiboot2.c
loader/powerpc/ieee1275/linux.c
loader/powerpc/ieee1275/linux_normal.c
loader/powerpc/ieee1275/multiboot2.c
normal/arg.c
normal/color.c
normal/cmdline.c
normal/command.c
normal/completion.c
normal/execute.c
normal/function.c
normal/lexer.c
normal/main.c
normal/menu.c
normal/menu_entry.c
normal/misc.c
normal/parser.y
normal/script.c
normal/i386/setjmp.S
normal/powerpc/setjmp.S
partmap/acorn.c
partmap/amiga.c
partmap/apple.c
partmap/gpt.c
partmap/pc.c
partmap/sun.c
term/terminfo.c
term/tparm.c
term/gfxterm.c
term/efi/console.c
term/i386/pc/console.c
term/i386/pc/serial.c
term/i386/pc/vesafb.c
term/i386/pc/vga.c
term/ieee1275/ofconsole.c
util/biosdisk.c
util/console.c
util/getroot.c
util/grub-emu.c
util/grub-mkdevicemap.c
util/grub-probe.c
util/hostfs.c
util/lvm.c
util/misc.c
util/raid.c
util/resolve.c
util/unifont2pff.rb
util/update-grub.in
util/update-grub_lib.in
util/grub.d/00_header.in
util/grub.d/10_hurd.in
util/grub.d/10_linux.in
util/grub.d/README
util/elf/grub-mkimage.c
util/i386/efi/grub-install.in
util/i386/efi/grub-mkimage.c
util/i386/get_disk_name.c
util/i386/pc/grub-install.in
util/i386/pc/grub-mkimage.c
util/i386/pc/grub-setup.c
util/i386/pc/misc.c
util/i386/pc/grub-mkrescue.in
util/ieee1275/get_disk_name.c
util/powerpc/ieee1275/grub-install.in
util/powerpc/ieee1275/misc.c
video/bitmap.c
video/video.c
video/i386/pc/vbe.c
video/i386/pc/vbeblit.c
video/i386/pc/vbefill.c
video/readers/tga.c
video/i386/pc/vbeutil.c

23
INSTALL
View File

@ -11,17 +11,19 @@ GRUB depends on some software packages installed into your system. If
you don't have any of them, please obtain and install them before you don't have any of them, please obtain and install them before
configuring the GRUB. configuring the GRUB.
* GCC 2.95 or later * GCC 4.1.3 or later
* GNU Make * GNU Make
* GNU Bison * GNU Bison 2.3 or later
* GNU binutils 2.9.1.0.23 or later * GNU binutils 2.9.1.0.23 or later
* Other standard GNU/Unix tools * Other standard GNU/Unix tools
* LZO 1.02 or later
If you'd like to develop GRUB, these below are also required. If you use a development snapshot or want to hack on GRUB you may
need the following.
* Ruby 1.6 or later * Ruby 1.6 or later
* Autoconf 2.53 or later * Python 2.5.2 or later
* Autoconf 2.60 or later
* Automake 1.10.1 or later
Configuring the GRUB Configuring the GRUB
==================== ====================
@ -52,11 +54,12 @@ Building the GRUB
The simplest way to compile this package is: The simplest way to compile this package is:
1. `cd' to the directory containing the package's source code and 1. `cd' to the directory containing the package's source code. If
type `./configure' to configure the package for your system. If you don't use a release tarball you have to type `./autogen.sh'.
you're using `csh' on an old version of System V, you might need Type `./configure' to configure the package for your system.
to type `sh ./configure' instead to prevent `csh' from trying to If you're using `csh' on an old version of System V, you might
execute `configure' itself. need to type `sh ./configure' instead to prevent `csh' from trying
to execute `configure' itself.
Running `configure' takes awhile. While running, it prints some Running `configure' takes awhile. While running, it prints some
messages telling which features it is checking for. messages telling which features it is checking for.

View File

@ -1,6 +1,6 @@
# -*- makefile -*- # -*- makefile -*-
# #
# Copyright (C) 1994,1995,1996,1997,1998,1999,2000,2001,2002,2004,2005,2006,2007 Free Software Foundation, Inc. # Copyright (C) 1994,1995,1996,1997,1998,1999,2000,2001,2002,2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
# #
# This Makefile.in is free software; the author # This Makefile.in is free software; the author
# gives unlimited permission to copy and/or distribute it, # gives unlimited permission to copy and/or distribute it,
@ -20,6 +20,7 @@ SHELL = /bin/sh
transform = @program_transform_name@ transform = @program_transform_name@
srcdir = @srcdir@ srcdir = @srcdir@
builddir = @builddir@
top_srcdir = @top_srcdir@ top_srcdir = @top_srcdir@
VPATH = @srcdir@ VPATH = @srcdir@
prefix = @prefix@ prefix = @prefix@
@ -40,12 +41,28 @@ includedir = @includedir@
pkgdatadir = $(datadir)/`echo @PACKAGE_TARNAME@ | sed '$(transform)'` pkgdatadir = $(datadir)/`echo @PACKAGE_TARNAME@ | sed '$(transform)'`
pkglibdir = $(libdir)/`echo @PACKAGE_TARNAME@/$(target_cpu)-$(platform) | sed '$(transform)'` pkglibdir = $(libdir)/`echo @PACKAGE_TARNAME@/$(target_cpu)-$(platform) | sed '$(transform)'`
# Internationalization library.
LIBINTL = @LIBINTL@
XGETTEXT = @XGETTEXT@
MSGMERGE = @MSGMERGE@
MSGFMT = @MSGFMT@
LINGUAS = $(shell for i in $(srcdir)/po/*.po ; do \
if test -e $$i ; then echo $$i ; fi ; \
done | sed -e "s,.*/po/\(.*\)\.po$$,\1,")
PACKAGE = @PACKAGE@
PACKAGE_NAME = @PACKAGE_NAME@ PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_VERSION = @PACKAGE_VERSION@ PACKAGE_VERSION = @PACKAGE_VERSION@
PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
host_os = @host_os@
host_kernel = @host_kernel@
host_cpu = @host_cpu@
target_cpu = @target_cpu@ target_cpu = @target_cpu@
platform = @platform@ platform = @platform@
@ -54,68 +71,113 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@ INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
MKDIR_P = @MKDIR_P@
mkinstalldirs = $(srcdir)/mkinstalldirs mkinstalldirs = $(srcdir)/mkinstalldirs
LIBS = @LIBS@ $(LIBINTL)
CC = @CC@ CC = @CC@
CFLAGS = @CFLAGS@ CFLAGS = @CFLAGS@
LDFLAGS = @LDFLAGS@ ASFLAGS = @ASFLAGS@
CPPFLAGS = @CPPFLAGS@ -I. -Iinclude -I$(srcdir)/include -Wall -W \ LDFLAGS = @LDFLAGS@ $(LIBS)
-DGRUB_LIBDIR=\"$(pkglibdir)\" CPPFLAGS = @CPPFLAGS@ -I$(builddir) -I$(builddir)/include -I$(srcdir)/gnulib -I$(srcdir)/include -Wall -W \
-DGRUB_LIBDIR=\"$(pkglibdir)\" -DLOCALEDIR=\"$(localedir)\"
TARGET_CC = @TARGET_CC@ TARGET_CC = @TARGET_CC@
TARGET_CFLAGS = @TARGET_CFLAGS@ TARGET_CFLAGS = @TARGET_CFLAGS@
TARGET_CPPFLAGS = @TARGET_CPPFLAGS@ -I. -Iinclude -I$(srcdir)/include \ 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 \
-Wall -W -Wall -W
TARGET_LDFLAGS = @TARGET_LDFLAGS@ TARGET_LDFLAGS = @TARGET_LDFLAGS@
STRIP_FLAGS=--strip-unneeded -K grub_mod_init -K grub_mod_fini -R .note -R .comment TARGET_IMG_LDSCRIPT = @TARGET_IMG_LDSCRIPT@
TARGET_IMG_LDFLAGS = @TARGET_IMG_LDFLAGS@
TARGET_IMG_CFLAGS = @TARGET_IMG_CFLAGS@
TARGET_OBJ2ELF = @TARGET_OBJ2ELF@
STRIP_FLAGS = --strip-unneeded -K grub_mod_init -K grub_mod_fini -K _grub_mod_init -K _grub_mod_fini -R .note -R .comment
EXEEXT = @EXEEXT@
OBJCOPY = @OBJCOPY@ OBJCOPY = @OBJCOPY@
STRIP = @STRIP@ STRIP = @STRIP@
NM = @NM@ NM = @NM@
RUBY = @RUBY@ RUBY = @RUBY@
MAKEINFO = @MAKEINFO@
ifeq (, $(MAKEINFO))
MAKEINFO = true
endif
HELP2MAN = @HELP2MAN@
ifeq (, $(HELP2MAN))
HELP2MAN = true
else
HELP2MAN := LANG=C $(HELP2MAN) --no-info --source=FSF
endif
AWK = @AWK@ AWK = @AWK@
LIBCURSES = @LIBCURSES@ LIBCURSES = @LIBCURSES@
LIBLZO = @LIBLZO@ LIBUSB = @LIBUSB@
LIBPCIACCESS = @LIBPCIACCESS@
YACC = @YACC@ YACC = @YACC@
UNIFONT_HEX = @UNIFONT_HEX@ FONT_SOURCE = @FONT_SOURCE@
# Options. # Options.
enable_grub_emu = @enable_grub_emu@ enable_grub_emu_usb = @enable_grub_emu_usb@
enable_grub_emu_pci = @enable_grub_emu_pci@
enable_grub_fstest = @enable_grub_fstest@
enable_grub_pe2elf = @enable_grub_pe2elf@
enable_grub_mkfont = @enable_grub_mkfont@
freetype_cflags = @freetype_cflags@
freetype_libs = @freetype_libs@
enable_efiemu = @enable_efiemu@
### General variables. ### General variables.
RMKFILES = $(wildcard $(srcdir)/conf/*.rmk) RMKFILES = $(wildcard conf/*.rmk)
MKFILES = $(patsubst %.rmk,%.mk,$(RMKFILES)) MKFILES = $(patsubst %.rmk,%.mk,$(RMKFILES))
PKGLIB = $(pkglib_IMAGES) $(pkglib_MODULES) $(pkglib_PROGRAMS) \ PKGLIB = $(pkglib_IMAGES) $(pkglib_MODULES) $(pkglib_PROGRAMS) \
$(pkglib_DATA) $(lib_DATA) $(pkglib_DATA) $(pkglib_BUILDDIR)
PKGDATA = $(pkgdata_DATA) PKGDATA = $(pkgdata_DATA)
PROGRAMS = $(bin_UTILITIES) $(sbin_UTILITIES) PROGRAMS = $(bin_UTILITIES) $(sbin_UTILITIES)
SCRIPTS = $(bin_SCRIPTS) $(sbin_SCRIPTS) $(update-grub_SCRIPTS) SCRIPTS = $(bin_SCRIPTS) $(sbin_SCRIPTS) $(grub-mkconfig_SCRIPTS) \
$(lib_SCRIPTS)
INFOS = $(info_INFOS)
CLEANFILES = CLEANFILES =
MOSTLYCLEANFILES = MOSTLYCLEANFILES =
DISTCLEANFILES = config.status config.cache config.log config.h \ DISTCLEANFILES = config.status config.cache config.log config.h \
Makefile stamp-h include/grub/cpu include/grub/machine \ Makefile stamp-h include/grub/cpu include/grub/machine \
gensymlist.sh genkernsyms.sh gensymlist.sh genkernsyms.sh build_env.mk \
MAINTAINER_CLEANFILES = $(srcdir)/configure $(MKFILES) docs/grub.info docs/version.texi docs/stamp-vti
MAINTAINER_CLEANFILES = $(srcdir)/configure $(addprefix $(srcdir)/,$(MKFILES)) \
$(srcdir)/DISTLIST $(srcdir)/config.h.in $(srcdir)/stamp-h.in $(INFOS)
# The default target. # The default target.
all: all-local all: all-local
### Include an arch-specific Makefile. ### Include an arch-specific Makefile.
$(MKFILES): %.mk: %.rmk genmk.rb $(addprefix $(srcdir)/,$(MKFILES)): %.mk: %.rmk genmk.rb
if test "x$(RUBY)" = x; then \ if test "x$(RUBY)" = x; then \
touch $@; \ touch $@; \
else \ else \
$(RUBY) $(srcdir)/genmk.rb < $< > $@; \ $(RUBY) $(srcdir)/genmk.rb < $< > $@; \
fi fi
ifeq ($(platform), emu)
include $(srcdir)/conf/any-emu.mk
else
include $(srcdir)/conf/$(target_cpu)-$(platform).mk include $(srcdir)/conf/$(target_cpu)-$(platform).mk
# For tests.
include $(srcdir)/conf/tests.mk
# For external modules.
-include $(wildcard $(GRUB_CONTRIB)/*/conf/common.mk)
endif
### General targets. ### General targets.
CLEANFILES += $(pkglib_DATA) $(pkgdata_DATA) CLEANFILES += $(pkglib_DATA) $(pkgdata_DATA) po/*.mo
pkglib_DATA += moddep.lst command.lst fs.lst pkglib_DATA += moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst video.lst crypto.lst terminal.lst
moddep.lst: $(DEFSYMFILES) $(UNDSYMFILES) genmoddep.awk moddep.lst: $(DEFSYMFILES) $(UNDSYMFILES) genmoddep.awk
cat $(DEFSYMFILES) /dev/null \ cat $(DEFSYMFILES) /dev/null \
| $(AWK) -f $(srcdir)/genmoddep.awk $(UNDSYMFILES) > $@ \ | $(AWK) -f $(srcdir)/genmoddep.awk $(UNDSYMFILES) > $@ \
@ -127,75 +189,168 @@ command.lst: $(COMMANDFILES)
fs.lst: $(FSFILES) fs.lst: $(FSFILES)
cat $^ /dev/null | sort > $@ cat $^ /dev/null | sort > $@
ifeq (, $(UNIFONT_HEX)) partmap.lst: $(PARTMAPFILES)
else cat $^ /dev/null | sort > $@
pkgdata_DATA += unicode.pff ascii.pff
unicode.pff: $(UNIFONT_HEX)
ruby $(srcdir)/util/unifont2pff.rb $(UNIFONT_HEX) > $@
ascii.pff: $(UNIFONT_HEX) handler.lst: $(HANDLERFILES)
ruby $(srcdir)/util/unifont2pff.rb 0-127 $(UNIFONT_HEX) > $@ cat $^ /dev/null | sort > $@
terminal.lst: $(TERMINALFILES)
cat $^ /dev/null | sort > $@
parttool.lst: $(PARTTOOLFILES)
cat $^ /dev/null | sort | uniq > $@
video.lst: $(VIDEOFILES)
cat $^ /dev/null | sort | uniq > $@
crypto.lst: lib/libgcrypt-grub/cipher/crypto.lst
cp $^ $@
ifneq (true, $(MAKEINFO))
info_INFOS += docs/grub.info
endif endif
all-local: $(PROGRAMS) $(PKGLIB) $(PKGDATA) $(SCRIPTS) $(MKFILES) MOSTLYCLEANFILES += vti.tmp
MAINTAINER_CLEANFILES += docs/stamp-vti docs/version.texi
docs/version.texi: docs/stamp-vti
docs/stamp-vti: docs/grub.texi configure.ac
$(MKDIR_P) docs
(set `$(SHELL) $(srcdir)/docs/mdate-sh $<`; \
echo "@set UPDATED $$1 $$2 $$3"; \
echo "@set UPDATED-MONTH $$2 $$3"; \
echo "@set EDITION $(PACKAGE_VERSION)"; \
echo "@set VERSION $(PACKAGE_VERSION)") > vti.tmp
@cmp -s vti.tmp $(builddir)/docs/version.texi \
|| (echo "Updating $(builddir)/docs/version.texi"; \
cp vti.tmp $(builddir)/docs/version.texi)
-@rm -f vti.tmp
@cp $(builddir)/docs/version.texi $@
# Use --force until such time as the documentation is cleaned up.
docs/grub.info: docs/grub.texi docs/version.texi docs/fdl.texi
$(MKDIR_P) docs
-$(MAKEINFO) -P $(builddir)/docs --no-split --force $< -o $@
ifeq (, $(FONT_SOURCE))
else
ifeq ($(enable_grub_mkfont),yes)
pkgdata_DATA += unicode.pf2 ascii.pf2
# Arrows and lines are needed to draw the menu, so we always include them
UNICODE_ARROWS=0x2190-0x2193
UNICODE_LINES=0x2501-0x251B
unicode.pf2: $(FONT_SOURCE) grub-mkfont
$(builddir)/grub-mkfont -o $@ $(FONT_SOURCE)
ascii.pf2: $(FONT_SOURCE) grub-mkfont
$(builddir)/grub-mkfont -o $@ $(FONT_SOURCE) -r 0x0-0x7f,$(UNICODE_ARROWS),$(UNICODE_LINES)
endif
endif
# Used for building modules externally
pkglib_BUILDDIR += build_env.mk
build_env.mk: Makefile
(\
echo "TARGET_CC=$(TARGET_CC)" ; \
echo "TARGET_CFLAGS=$(TARGET_CFLAGS)" ; \
echo "TARGET_ASFLAGS=$(TARGET_ASFLAGS)" ; \
echo "TARGET_CPPFLAGS=$(TARGET_CPPFLAGS) -I$(pkglibdir) -I$(includedir)" ; \
echo "STRIP=$(STRIP)" ; \
echo "OBJCONV=$(OBJCONV)" ; \
echo "TARGET_MODULE_FORMAT=$(TARGET_MODULE_FORMAT)" ; \
echo "TARGET_APPLE_CC=$(TARGET_APPLE_CC)" ; \
echo "COMMON_ASFLAGS=$(COMMON_ASFLAGS)" ; \
echo "COMMON_CFLAGS=$(COMMON_CFLAGS)" ; \
echo "COMMON_LDFLAGS=$(COMMON_LDFLAGS)"\
) > $@
pkglib_BUILDDIR += config.h grub_script.tab.h
all-local: $(PROGRAMS) $(PKGLIB) $(PKGDATA) $(SCRIPTS) $(INFOS) $(MKFILES) $(foreach lang, $(LINGUAS), po/$(lang).mo)
install: install-local install: install-local
install-local: all install-local: all
$(mkinstalldirs) $(DESTDIR)$(pkglibdir) $(SHELL) $(mkinstalldirs) $(DESTDIR)$(pkglibdir)
rm -f $(DESTDIR)$(pkglibdir)/*
@list='$(PKGLIB)'; \ @list='$(PKGLIB)'; \
for file in $$list; do \ for file in $$list; do \
if test -f "$$file"; then dir=; else dir="$(srcdir)/"; fi; \ if test -f "$$file"; then dir=; else dir="$(srcdir)/"; fi; \
dest="`echo $$file | sed 's,.*/,,'`"; \ dest="`echo $$file | sed 's,.*/,,'`"; \
$(INSTALL_DATA) $$dir$$file $(DESTDIR)$(pkglibdir)/$$dest; \ $(INSTALL_DATA) $$dir$$file $(DESTDIR)$(pkglibdir)/$$dest; \
done done
$(mkinstalldirs) $(DESTDIR)$(pkgdatadir) $(SHELL) $(mkinstalldirs) $(DESTDIR)$(pkgdatadir)
@list='$(PKGDATA)'; \ @list='$(PKGDATA)'; \
for file in $$list; do \ for file in $$list; do \
if test -f "$$file"; then dir=; else dir="$(srcdir)/"; fi; \ if test -f "$$file"; then dir=; else dir="$(srcdir)/"; fi; \
dest="`echo $$file | sed 's,.*/,,'`"; \ dest="`echo $$file | sed 's,.*/,,'`"; \
$(INSTALL_DATA) $$dir$$file $(DESTDIR)$(pkgdatadir)/$$dest; \ $(INSTALL_DATA) $$dir$$file $(DESTDIR)$(pkgdatadir)/$$dest; \
done done
$(mkinstalldirs) $(DESTDIR)$(bindir) $(SHELL) $(mkinstalldirs) $(DESTDIR)$(bindir) $(DESTDIR)$(mandir)/man1
@list='$(bin_UTILITIES)'; for file in $$list; do \ @list='$(bin_UTILITIES)'; for file in $$list; do \
if test -f "$$file"; then dir=; else dir="$(srcdir)/"; fi; \ if test -f "$$file"; then dir=; else dir="$(srcdir)/"; fi; \
dest="`echo $$file | sed 's,.*/,,' | sed '$(transform)'`"; \ dest="`echo $$file | sed 's,.*/,,' | sed '$(transform)'`"; \
$(INSTALL_PROGRAM) $$dir$$file $(DESTDIR)$(bindir)/$$dest; \ $(INSTALL_PROGRAM) $$dir$$file $(DESTDIR)$(bindir)/$$dest; \
$(HELP2MAN) --section=1 -o $(DESTDIR)$(mandir)/man1/$$dest.1 $(builddir)/$$file; \
done done
$(mkinstalldirs) $(DESTDIR)$(sbindir) $(SHELL) $(mkinstalldirs) $(DESTDIR)$(sbindir) $(DESTDIR)$(mandir)/man8
@list='$(sbin_UTILITIES)'; for file in $$list; do \ @list='$(sbin_UTILITIES)'; for file in $$list; do \
if test -f "$$file"; then dir=; else dir="$(srcdir)/"; fi; \ if test -f "$$file"; then dir=; else dir="$(srcdir)/"; fi; \
dest="`echo $$file | sed 's,.*/,,' | sed '$(transform)'`"; \ dest="`echo $$file | sed 's,.*/,,' | sed '$(transform)'`"; \
$(INSTALL_PROGRAM) $$dir$$file $(DESTDIR)$(sbindir)/$$dest; \ $(INSTALL_PROGRAM) $$dir$$file $(DESTDIR)$(sbindir)/$$dest; \
$(HELP2MAN) --section=8 -o $(DESTDIR)$(mandir)/man8/$$dest.8 $(builddir)/$$file; \
done done
@list='$(bin_SCRIPTS)'; for file in $$list; do \ @list='$(bin_SCRIPTS)'; for file in $$list; do \
if test -f "$$file"; then dir=; else dir="$(srcdir)/"; fi; \ if test -f "$$file"; then dir=; else dir="$(srcdir)/"; fi; \
dest="`echo $$file | sed 's,.*/,,' | sed '$(transform)'`"; \ dest="`echo $$file | sed 's,.*/,,' | sed '$(transform)'`"; \
$(INSTALL_SCRIPT) $$dir$$file $(DESTDIR)$(bindir)/$$dest; \ $(INSTALL_SCRIPT) $$dir$$file $(DESTDIR)$(bindir)/$$dest; \
$(HELP2MAN) --section=1 -o $(DESTDIR)$(mandir)/man1/$$dest.1 $(builddir)/$$file; \
done done
@list='$(sbin_SCRIPTS)'; for file in $$list; do \ @list='$(sbin_SCRIPTS)'; for file in $$list; do \
if test -f "$$file"; then dir=; else dir="$(srcdir)/"; fi; \ if test -f "$$file"; then dir=; else dir="$(srcdir)/"; fi; \
dest="`echo $$file | sed 's,.*/,,' | sed '$(transform)'`"; \ dest="`echo $$file | sed 's,.*/,,' | sed '$(transform)'`"; \
$(INSTALL_SCRIPT) $$dir$$file $(DESTDIR)$(sbindir)/$$dest; \ $(INSTALL_SCRIPT) $$dir$$file $(DESTDIR)$(sbindir)/$$dest; \
$(HELP2MAN) --section=8 -o $(DESTDIR)$(mandir)/man8/$$dest.8 $(builddir)/$$file; \
done done
$(mkinstalldirs) $(DESTDIR)$(sysconfdir)/grub.d $(SHELL) $(mkinstalldirs) $(DESTDIR)$(sysconfdir)/grub.d
@list='$(update-grub_SCRIPTS)'; for file in $$list; do \ @list='$(grub-mkconfig_SCRIPTS)'; for file in $$list; do \
if test -f "$$file"; then dir=; else dir="$(srcdir)/"; fi; \ if test -f "$$file"; then dir=; else dir="$(srcdir)/"; fi; \
dest="`echo $$file | sed 's,.*/,,' | sed '$(transform)'`"; \ dest="`echo $$file | sed 's,.*/,,' | sed '$(transform)'`"; \
$(INSTALL_SCRIPT) $$dir$$file $(DESTDIR)$(sysconfdir)/grub.d/$$dest; \ $(INSTALL_SCRIPT) $$dir$$file $(DESTDIR)$(sysconfdir)/grub.d/$$dest; \
done done
@list='$(update-grub_DATA)'; for file in $$list; do \ @list='$(grub-mkconfig_DATA)'; for file in $$list; do \
if test -f "$$file"; then dir=; else dir="$(srcdir)/"; fi; \ if test -f "$$file"; then dir=; else dir="$(srcdir)/"; fi; \
dest="`echo $$file | sed 's,.*/,,' | sed '$(transform)'`"; \ dest="`echo $$file | sed 's,.*/,,' | sed '$(transform)'`"; \
$(INSTALL_DATA) $$dir$$file $(DESTDIR)$(sysconfdir)/grub.d/$$dest; \ $(INSTALL_DATA) $$dir$$file $(DESTDIR)$(sysconfdir)/grub.d/$$dest; \
done done
$(mkinstalldirs) $(DESTDIR)$(libdir)/grub $(SHELL) $(mkinstalldirs) $(DESTDIR)$(libdir)/grub
@list='$(lib_DATA)'; \ @list='$(lib_SCRIPTS)'; \
for file in $$list; do \ for file in $$list; do \
if test -f "$$file"; then dir=; else dir="$(srcdir)/"; fi; \ if test -f "$$file"; then dir=; else dir="$(srcdir)/"; fi; \
dest="`echo $$file | sed 's,.*/,,'`"; \ dest="`echo $$file | sed 's,.*/,,'`"; \
$(INSTALL_DATA) $$dir$$file $(DESTDIR)$(libdir)/grub/$$dest; \ $(INSTALL_DATA) $$dir$$file $(DESTDIR)$(libdir)/grub/$$dest; \
done done
@langs='$(LINGUAS)'; \
for lang in $$langs; do \
$(SHELL) $(mkinstalldirs) $(DESTDIR)/$(datadir)/locale/$$lang/LC_MESSAGES; \
file="po/$$lang.mo"; \
if test -f "$$file"; then dir=; else dir="$(srcdir)/"; fi; \
$(INSTALL_DATA) $$dir$$file $(DESTDIR)/$(datadir)/locale/$$lang/LC_MESSAGES/$(PACKAGE).mo; \
done
$(SHELL) $(mkinstalldirs) $(DESTDIR)$(infodir)
@list='$(info_INFOS)'; \
for file in $$list; do \
if test -f "$$file"; then dir=; else dir="$(srcdir)/"; fi; \
dest="`echo $$file | sed 's,.*/,,'`"; \
$(INSTALL_DATA) $$dir$$file $(DESTDIR)$(infodir); \
if (install-info --version && \
install-info --version 2>&1 | sed 1q | grep -i -v debian) >/dev/null 2>&1; then \
install-info --info-dir="$(DESTDIR)$(infodir)" "$(DESTDIR)$(infodir)/$$dest" || :; \
fi; \
done
install-strip: install-strip:
$(MAKE) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" install $(MAKE) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" install
@ -214,20 +369,41 @@ uninstall:
@list='$(bin_UTILITIES) $(bin_SCRIPTS)'; for file in $$list; do \ @list='$(bin_UTILITIES) $(bin_SCRIPTS)'; for file in $$list; do \
dest="`echo $$file | sed 's,.*/,,' | sed '$(transform)'`"; \ dest="`echo $$file | sed 's,.*/,,' | sed '$(transform)'`"; \
rm -f $(DESTDIR)$(bindir)/$$dest; \ rm -f $(DESTDIR)$(bindir)/$$dest; \
rm -f $(DESTDIR)$(mandir)/man1/$$dest.1; \
done done
@list='$(sbin_UTILITIES) $(sbin_SCRIPTS)'; for file in $$list; do \ @list='$(sbin_UTILITIES) $(sbin_SCRIPTS)'; for file in $$list; do \
dest="`echo $$file | sed 's,.*/,,' | sed '$(transform)'`"; \ dest="`echo $$file | sed 's,.*/,,' | sed '$(transform)'`"; \
rm -f $(DESTDIR)$(sbindir)/$$dest; \ rm -f $(DESTDIR)$(sbindir)/$$dest; \
rm -f $(DESTDIR)$(mandir)/man8/$$dest.8; \
done done
@list='$(update-grub_SCRIPTS) $(update-grub_DATA)'; for file in $$list; do \ @list='$(grub-mkconfig_SCRIPTS) $(grub-mkconfig_DATA)'; for file in $$list; do \
dest="`echo $$file | sed 's,.*/,,' | sed '$(transform)'`"; \ dest="`echo $$file | sed 's,.*/,,' | sed '$(transform)'`"; \
rm -f $(DESTDIR)$(sysconfdir)/grub.d/$$dest; \ rm -f $(DESTDIR)$(sysconfdir)/grub.d/$$dest; \
done done
@list='$(lib_SCRIPTS)'; \
for file in $$list; do \
dest="`echo $$file | sed 's,.*/,,'`"; \
echo rm -f $(DESTDIR)$(libdir)/$$dest; \
rm -f $(DESTDIR)$(libdir)/grub/$$dest; \
done
@list='$(info_INFOS)'; \
for file in $$list; do \
dest="`echo $$file | sed 's,.*/,,'`"; \
if (install-info --version && \
install-info --version 2>&1 | sed 1q | grep -i -v debian) >/dev/null 2>&1; then \
if install-info --info-dir="$(DESTDIR)$(infodir)" --remove "$(DESTDIR)$(infodir)/$$dest"; then \
:; \
else \
test ! -f "$(DESTDIR)$(infodir)/$$dest" || exit 1; \
fi; \
fi; \
rm -f $(DESTDIR)$(infodir)/$$dest; \
done
clean: clean: $(CLEAN_IMAGE_TARGETS) $(CLEAN_MODULE_TARGETS) $(CLEAN_UTILITY_TARGETS)
-test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
mostlyclean: clean mostlyclean: clean $(MOSTLYCLEAN_IMAGE_TARGETS) $(MOSTLYCLEAN_MODULE_TARGETS) $(MOSTLYCLEAN_UTILITY_TARGETS)
-test -z "$(MOSTLYCLEANFILES)" || rm -f $(MOSTLYCLEANFILES) -test -z "$(MOSTLYCLEANFILES)" || rm -f $(MOSTLYCLEANFILES)
distclean: mostlyclean distclean: mostlyclean
@ -244,15 +420,15 @@ dvi:
distdir=$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) distdir=$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)
DISTLIST: gendistlist.sh DISTLIST: gendistlist.sh
sh $(srcdir)/gendistlist.sh > $(srcdir)/DISTLIST $(SHELL) $(srcdir)/gendistlist.sh > $(srcdir)/DISTLIST
distdir: DISTLIST distdir: DISTLIST
-chmod -R a+w $(distdir) >/dev/null 2>&1; rm -rf $(distdir) -chmod -R a+w $(distdir) >/dev/null 2>&1; rm -rf $(distdir)
$(mkinstalldirs) $(distdir) $(SHELL) $(mkinstalldirs) $(distdir)
for i in `cat $(srcdir)/DISTLIST`; do \ for i in `cat $(srcdir)/DISTLIST`; do \
dir=`echo "$$i" | sed 's:/[^/]*$$::'`; \ dir=`echo "$$i" | sed 's:/[^/]*$$::'`; \
if test -d $(srcdir)/$$dir; then \ if test -d $(srcdir)/$$dir; then \
$(mkinstalldirs) $(distdir)/$$dir; \ $(SHELL) $(mkinstalldirs) $(distdir)/$$dir; \
fi; \ fi; \
cp -p $(srcdir)/$$i $(distdir)/$$i || exit 1; \ cp -p $(srcdir)/$$i $(distdir)/$$i || exit 1; \
done done
@ -274,7 +450,7 @@ distcheck: dist
chmod a-w $(distdir) chmod a-w $(distdir)
dc_instdir=`CDPATH=: && cd $(distdir)/=inst && pwd` \ dc_instdir=`CDPATH=: && cd $(distdir)/=inst && pwd` \
&& cd $(distdir)/=build \ && cd $(distdir)/=build \
&& ../configure --srcdir=.. --prefix=$$dc_instdir \ && $(SHELL) ../configure --srcdir=.. --prefix=$$dc_instdir \
&& $(MAKE) all dvi check install && $(MAKE) uninstall \ && $(MAKE) all dvi check install && $(MAKE) uninstall \
&& (test `find $$dc_instdir -type f -print | wc -l` -le 1 \ && (test `find $$dc_instdir -type f -print | wc -l` -le 1 \
|| (echo "Error: files left after uninstall" 1>&2; \ || (echo "Error: files left after uninstall" 1>&2; \
@ -288,12 +464,34 @@ distcheck: dist
@echo "$(distdir).tar.gz is ready for distribution" | \ @echo "$(distdir).tar.gz is ready for distribution" | \
sed 'h;s/./=/g;p;x;p;x' sed 'h;s/./=/g;p;x;p;x'
check: check: all $(UNIT_TESTS) $(FUNCTIONAL_TESTS) $(SCRIPTED_TESTS)
@list="$(UNIT_TESTS)"; \
for file in $$list; do \
$(builddir)/$$file; \
done
@list="$(FUNCTIONAL_TESTS)"; \
for file in $$list; do \
mod=`basename $$file .mod`; \
echo "insmod functional_test; insmod $$mod; functional_test" \
| $(builddir)/grub-shell; \
done
@list="$(SCRIPTED_TESTS)"; \
for file in $$list; do \
echo "$$file:"; \
if $(builddir)/$$file; then \
echo "$$file: PASS"; \
else \
echo "$$file: FAIL"; \
fi; \
done
.SUFFIX: .SUFFIX:
.SUFFIX: .c .o .S .d .SUFFIX: .c .o .S .d
# Regenerate configure and Makefile automatically. # Regenerate configure and Makefile automatically.
$(srcdir)/aclocal.m4: configure.ac acinclude.m4
cd $(srcdir) && aclocal
$(srcdir)/configure: configure.ac aclocal.m4 $(srcdir)/configure: configure.ac aclocal.m4
cd $(srcdir) && autoconf cd $(srcdir) && autoconf
@ -304,19 +502,30 @@ $(srcdir)/stamp-h.in: configure.ac aclocal.m4
config.h: stamp-h config.h: stamp-h
stamp-h: config.h.in config.status stamp-h: config.h.in config.status
./config.status $(SHELL) ./config.status
Makefile: Makefile.in config.status Makefile: Makefile.in config.status
./config.status $(SHELL) ./config.status
config.status: configure config.status: configure
./config.status --recheck $(SHELL) ./config.status --recheck
gensymlist.sh: gensymlist.sh.in config.status gensymlist.sh: gensymlist.sh.in config.status
./config.status $(SHELL) ./config.status
genkernsyms.sh: genkernsyms.sh.in config.status genkernsyms.sh: genkernsyms.sh.in config.status
./config.status $(SHELL) ./config.status
$(srcdir)/po/$(PACKAGE).pot: po/POTFILES po/POTFILES-shell
cd $(srcdir) && $(XGETTEXT) -ctranslate --from-code=utf-8 -o $@ -f $< --keyword=_ --keyword=N_
cd $(srcdir) && $(XGETTEXT) -ctranslate --from-code=utf-8 -o $@ -f po/POTFILES-shell -j --language=Shell
$(foreach lang, $(LINGUAS), $(srcdir)/po/$(lang).po): po/$(PACKAGE).pot
$(MSGMERGE) -U $@ $^
po/%.mo: po/%.po
$(MKDIR_P) $$(dirname $@)
$(MSGFMT) -c --statistics -o $@ $^
.PHONY: all install install-strip uninstall clean mostlyclean distclean .PHONY: all install install-strip uninstall clean mostlyclean distclean
.PHONY: maintainer-clean info dvi dist check .PHONY: maintainer-clean info dvi dist check

77
NEWS
View File

@ -1,4 +1,79 @@
New in 1.96: New in 1.98:
* Add grub-probe support for GNU/Hurd.
* Add support for gettext.
New in 1.97:
* Add support for loading XNU (MacOS X kernel).
* ACPI override support.
* Integrated gptsync.
* Password protection support.
* Partition manipulation tool.
* Add `keystatus' command.
* Unicode fonts are now used by default.
* Add `hdparm' command.
* Add support for getting the current date and time from CMOS as variables.
* Add `drivemap' command.
* Add support for RAID levels 4,6 and 10.
* update-grub is replaced by grub-mkconfig.
* When booting from PXE, PXE can be used to load files.
* High resolution timer support.
* Image loaders now support IO buffering.
* Add `crc' command.
* Add Cygwin support.
* Add x86_64 EFI support.
* Use LZMA compression instead of LZO.
* Support for saving the environment from and loading the environment
from a file.
* Allow the UUID to be used as device name.
* The `search' command can use UUIDs now.
* Add support for IEEE 1275 on i386.
* Create partmap.lst and use it to automatically load partition map
modules.
* grub-mkconfig supports os-prober to add operating systems to the
boot menu.
* The ATA driver supports devices bigger than 2 TiB.
* Add support for the UDF, AFS and EXT4 filesystems.
* The ISO9660 filesystem supports the Joliet extension
* Add support for loading kernels of FreeBSD, NetBSD and OpenBSD.
* Add new command `sleep'.
* Support for direct access to AT keyboards.
* New utility `grub-fstest'.
New in 1.96 - 2008-02-03:
* The license term is changed to GNU General Public License Version 3. * The license term is changed to GNU General Public License Version 3.

3
THANKS
View File

@ -8,6 +8,7 @@ generally assist in the GRUB 2 maintainership process:
Andrey Shuvikov <mr_hyro@yahoo.com> Andrey Shuvikov <mr_hyro@yahoo.com>
Bibo Mao <bibo.mao@intel.com> Bibo Mao <bibo.mao@intel.com>
David Miller <davem@davemloft.net>
Guillem Jover <guillem@hadrons.org> Guillem Jover <guillem@hadrons.org>
Harley D. Eades III <hde@foobar-qux.org> Harley D. Eades III <hde@foobar-qux.org>
Hitoshi Ozeki <h-ozeki@ck2.so-net.ne.jp> Hitoshi Ozeki <h-ozeki@ck2.so-net.ne.jp>
@ -30,7 +31,7 @@ Vincent Guffens <guffens@inma.ucl.ac.be>
Vincent Pelletier <subdino2004@yahoo.fr> Vincent Pelletier <subdino2004@yahoo.fr>
Vladimir Serbinenko <phcoder@gmail.com> Vladimir Serbinenko <phcoder@gmail.com>
Also, we thank the projects GNU Automake and LZO. Some code Also, we thank the projects GNU Automake and LZMA. Some code
was stolen from them. was stolen from them.
This project was supported by Information-technology Promotion Agency, This project was supported by Information-technology Promotion Agency,

View File

@ -1,3 +1,37 @@
dnl Redefine AC_LANG_PROGRAM with a "-Wstrict-prototypes -Werror"-friendly
dnl version. Patch submitted to bug-autoconf in 2009-09-16.
m4_define([AC_LANG_PROGRAM(C)],
[$1
int
main (void)
{
dnl Do *not* indent the following line: there may be CPP directives.
dnl Don't move the `;' right after for the same reason.
$2
;
return 0;
}])
dnl Check whether target compiler is working
AC_DEFUN(grub_PROG_TARGET_CC,
[AC_MSG_CHECKING([whether target compiler is working])
AC_CACHE_VAL(grub_cv_prog_target_cc,
[AC_LINK_IFELSE([AC_LANG_PROGRAM([[
asm (".globl start; start: nop");
int main (void);
]], [[]])],
[grub_cv_prog_target_cc=yes],
[grub_cv_prog_target_cc=no])
])
AC_MSG_RESULT([$grub_cv_prog_target_cc])
if test "x$grub_cv_prog_target_cc" = xno; then
AC_MSG_ERROR([cannot compile for the target])
fi
])
dnl grub_ASM_USCORE checks if C symbols get an underscore after dnl grub_ASM_USCORE checks if C symbols get an underscore after
dnl compiling to assembler. dnl compiling to assembler.
dnl Written by Pavel Roskin. Based on grub_ASM_EXT_C written by dnl Written by Pavel Roskin. Based on grub_ASM_EXT_C written by
@ -7,6 +41,7 @@ AC_DEFUN(grub_ASM_USCORE,
AC_MSG_CHECKING([if C symbols get an underscore after compilation]) AC_MSG_CHECKING([if C symbols get an underscore after compilation])
AC_CACHE_VAL(grub_cv_asm_uscore, AC_CACHE_VAL(grub_cv_asm_uscore,
[cat > conftest.c <<\EOF [cat > conftest.c <<\EOF
int func (int *);
int int
func (int *list) func (int *list)
{ {
@ -44,6 +79,7 @@ AC_DEFUN(grub_PROG_OBJCOPY_ABSOLUTE,
[AC_MSG_CHECKING([whether ${OBJCOPY} works for absolute addresses]) [AC_MSG_CHECKING([whether ${OBJCOPY} works for absolute addresses])
AC_CACHE_VAL(grub_cv_prog_objcopy_absolute, AC_CACHE_VAL(grub_cv_prog_objcopy_absolute,
[cat > conftest.c <<\EOF [cat > conftest.c <<\EOF
void cmain (void);
void void
cmain (void) cmain (void)
{ {
@ -56,12 +92,12 @@ else
AC_MSG_ERROR([${CC-cc} cannot compile C source code]) AC_MSG_ERROR([${CC-cc} cannot compile C source code])
fi fi
grub_cv_prog_objcopy_absolute=yes grub_cv_prog_objcopy_absolute=yes
for link_addr in 2000 8000 7C00; do for link_addr in 0x2000 0x8000 0x7C00; do
if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} ${LDFLAGS} -nostdlib -Wl,-N -Wl,-Ttext -Wl,$link_addr conftest.o -o conftest.exec]); then : if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -nostdlib ${TARGET_IMG_LDFLAGS_AC} -Wl,-Ttext -Wl,$link_addr conftest.o -o conftest.exec]); then :
else else
AC_MSG_ERROR([${CC-cc} cannot link at address $link_addr]) AC_MSG_ERROR([${CC-cc} cannot link at address $link_addr])
fi fi
if AC_TRY_COMMAND([${OBJCOPY-objcopy} -O binary conftest.exec conftest]); then : if AC_TRY_COMMAND([${OBJCOPY-objcopy} --only-section=.text -O binary conftest.exec conftest]); then :
else else
AC_MSG_ERROR([${OBJCOPY-objcopy} cannot create binary files]) AC_MSG_ERROR([${OBJCOPY-objcopy} cannot create binary files])
fi fi
@ -81,6 +117,26 @@ fi
]) ])
dnl Supply --build-id=none to ld if building modules.
dnl This suppresses warnings from ld on some systems
AC_DEFUN(grub_PROG_LD_BUILD_ID_NONE,
[AC_MSG_CHECKING([whether linker accepts --build-id=none])
AC_CACHE_VAL(grub_cv_prog_ld_build_id_none,
[save_LDFLAGS="$LDFLAGS"
LDFLAGS="$LDFLAGS -Wl,--build-id=none"
AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
[grub_cv_prog_ld_build_id_none=yes],
[grub_cv_prog_ld_build_id_none=no])
LDFLAGS="$save_LDFLAGS"
])
AC_MSG_RESULT([$grub_cv_prog_ld_build_id_none])
if test "x$grub_cv_prog_ld_build_id_none" = xyes; then
TARGET_LDFLAGS="$TARGET_LDFLAGS -Wl,--build-id=none"
fi
])
dnl Mass confusion! dnl Mass confusion!
dnl Older versions of GAS interpret `.code16' to mean ``generate 32-bit dnl Older versions of GAS interpret `.code16' to mean ``generate 32-bit
dnl instructions, but implicitly insert addr32 and data32 bytes so dnl instructions, but implicitly insert addr32 and data32 bytes so
@ -120,6 +176,36 @@ rm -f conftest*])
AC_MSG_RESULT([$grub_cv_i386_asm_addr32])]) AC_MSG_RESULT([$grub_cv_i386_asm_addr32])])
dnl check if our compiler is apple cc
dnl because it requires numerous workarounds
AC_DEFUN(grub_apple_cc,
[AC_REQUIRE([AC_PROG_CC])
AC_MSG_CHECKING([whether our compiler is apple cc])
AC_CACHE_VAL(grub_cv_apple_cc,
[if $CC -v 2>&1 | grep "Apple Inc." > /dev/null; then
grub_cv_apple_cc=yes
else
grub_cv_apple_cc=no
fi
])
AC_MSG_RESULT([$grub_cv_apple_cc])])
dnl check if our target compiler is apple cc
dnl because it requires numerous workarounds
AC_DEFUN(grub_apple_target_cc,
[AC_REQUIRE([AC_PROG_CC])
AC_MSG_CHECKING([whether our target compiler is apple cc])
AC_CACHE_VAL(grub_cv_apple_target_cc,
[if $CC -v 2>&1 | grep "Apple Inc." > /dev/null; then
grub_cv_apple_target_cc=yes
else
grub_cv_apple_target_cc=no
fi
])
AC_MSG_RESULT([$grub_cv_apple_target_cc])])
dnl Later versions of GAS requires that addr32 and data32 prefixes dnl Later versions of GAS requires that addr32 and data32 prefixes
dnl appear in the same lines as the instructions they modify, while dnl appear in the same lines as the instructions they modify, while
@ -166,7 +252,7 @@ AC_MSG_CHECKING(dnl
[whether an absolute indirect call/jump must not be prefixed with an asterisk]) [whether an absolute indirect call/jump must not be prefixed with an asterisk])
AC_CACHE_VAL(grub_cv_i386_asm_absolute_without_asterisk, AC_CACHE_VAL(grub_cv_i386_asm_absolute_without_asterisk,
[cat > conftest.s <<\EOF [cat > conftest.s <<\EOF
lcall *(offset) lcall *(offset)
offset: offset:
.long 0 .long 0
.word 0 .word 0
@ -188,62 +274,34 @@ fi
AC_MSG_RESULT([$grub_cv_i386_asm_absolute_without_asterisk])]) AC_MSG_RESULT([$grub_cv_i386_asm_absolute_without_asterisk])])
dnl Check what symbol is defined as a start symbol.
dnl Written by Yoshinori K. Okuji.
AC_DEFUN(grub_CHECK_START_SYMBOL,
[AC_REQUIRE([AC_PROG_CC])
AC_MSG_CHECKING([if start is defined by the compiler])
AC_CACHE_VAL(grub_cv_check_start_symbol,
[AC_TRY_LINK([], [asm ("incl start")],
grub_cv_check_start_symbol=yes,
grub_cv_check_start_symbol=no)])
AC_MSG_RESULT([$grub_cv_check_start_symbol])
AC_MSG_CHECKING([if _start is defined by the compiler])
AC_CACHE_VAL(grub_cv_check_uscore_start_symbol,
[AC_TRY_LINK([], [asm ("incl _start")],
grub_cv_check_uscore_start_symbol=yes,
grub_cv_check_uscore_start_symbol=no)])
AC_MSG_RESULT([$grub_cv_check_uscore_start_symbol])
AH_TEMPLATE([START_SYMBOL], [Define it to either start or _start])
if test "x$grub_cv_check_start_symbol" = xyes; then
AC_DEFINE([START_SYMBOL], [start])
elif test "x$grub_cv_check_uscore_start_symbol" = xyes; then
AC_DEFINE([START_SYMBOL], [_start])
else
AC_MSG_ERROR([neither start nor _start is defined])
fi
])
dnl Check what symbol is defined as a bss start symbol. dnl Check what symbol is defined as a bss start symbol.
dnl Written by Michael Hohmoth and Yoshinori K. Okuji. dnl Written by Michael Hohmoth and Yoshinori K. Okuji.
AC_DEFUN(grub_CHECK_BSS_START_SYMBOL, AC_DEFUN(grub_CHECK_BSS_START_SYMBOL,
[AC_REQUIRE([AC_PROG_CC]) [AC_REQUIRE([AC_PROG_CC])
AC_MSG_CHECKING([if __bss_start is defined by the compiler]) AC_MSG_CHECKING([if __bss_start is defined by the compiler])
AC_CACHE_VAL(grub_cv_check_uscore_uscore_bss_start_symbol, AC_CACHE_VAL(grub_cv_check_uscore_uscore_bss_start_symbol,
[AC_TRY_LINK([], [asm ("incl __bss_start")], [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
grub_cv_check_uscore_uscore_bss_start_symbol=yes, [[asm ("incl __bss_start")]])],
grub_cv_check_uscore_uscore_bss_start_symbol=no)]) [grub_cv_check_uscore_uscore_bss_start_symbol=yes],
[grub_cv_check_uscore_uscore_bss_start_symbol=no])])
AC_MSG_RESULT([$grub_cv_check_uscore_uscore_bss_start_symbol]) AC_MSG_RESULT([$grub_cv_check_uscore_uscore_bss_start_symbol])
AC_MSG_CHECKING([if edata is defined by the compiler]) AC_MSG_CHECKING([if edata is defined by the compiler])
AC_CACHE_VAL(grub_cv_check_edata_symbol, AC_CACHE_VAL(grub_cv_check_edata_symbol,
[AC_TRY_LINK([], [asm ("incl edata")], [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
grub_cv_check_edata_symbol=yes, [[asm ("incl edata")]])],
grub_cv_check_edata_symbol=no)]) [grub_cv_check_edata_symbol=yes],
[grub_cv_check_edata_symbol=no])])
AC_MSG_RESULT([$grub_cv_check_edata_symbol]) AC_MSG_RESULT([$grub_cv_check_edata_symbol])
AC_MSG_CHECKING([if _edata is defined by the compiler]) AC_MSG_CHECKING([if _edata is defined by the compiler])
AC_CACHE_VAL(grub_cv_check_uscore_edata_symbol, AC_CACHE_VAL(grub_cv_check_uscore_edata_symbol,
[AC_TRY_LINK([], [asm ("incl _edata")], [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
grub_cv_check_uscore_edata_symbol=yes, [[asm ("incl _edata")]])],
grub_cv_check_uscore_edata_symbol=no)]) [grub_cv_check_uscore_edata_symbol=yes],
[grub_cv_check_uscore_edata_symbol=no])])
AC_MSG_RESULT([$grub_cv_check_uscore_edata_symbol]) AC_MSG_RESULT([$grub_cv_check_uscore_edata_symbol])
@ -266,17 +324,19 @@ AC_DEFUN(grub_CHECK_END_SYMBOL,
[AC_REQUIRE([AC_PROG_CC]) [AC_REQUIRE([AC_PROG_CC])
AC_MSG_CHECKING([if end is defined by the compiler]) AC_MSG_CHECKING([if end is defined by the compiler])
AC_CACHE_VAL(grub_cv_check_end_symbol, AC_CACHE_VAL(grub_cv_check_end_symbol,
[AC_TRY_LINK([], [asm ("incl end")], [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
grub_cv_check_end_symbol=yes, [[asm ("incl end")]])],
grub_cv_check_end_symbol=no)]) [grub_cv_check_end_symbol=yes],
[grub_cv_check_end_symbol=no])])
AC_MSG_RESULT([$grub_cv_check_end_symbol]) AC_MSG_RESULT([$grub_cv_check_end_symbol])
AC_MSG_CHECKING([if _end is defined by the compiler]) AC_MSG_CHECKING([if _end is defined by the compiler])
AC_CACHE_VAL(grub_cv_check_uscore_end_symbol, AC_CACHE_VAL(grub_cv_check_uscore_end_symbol,
[AC_TRY_LINK([], [asm ("incl _end")], [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
grub_cv_check_uscore_end_symbol=yes, [[asm ("incl _end")]])],
grub_cv_check_uscore_end_symbol=no)]) [grub_cv_check_uscore_end_symbol=yes],
[grub_cv_check_uscore_end_symbol=no])])
AC_MSG_RESULT([$grub_cv_check_uscore_end_symbol]) AC_MSG_RESULT([$grub_cv_check_uscore_end_symbol])
@ -291,58 +351,32 @@ else
fi fi
]) ])
dnl Check if the C compiler has a bug while using nested functions when dnl Check if the C compiler generates calls to `__enable_execute_stack()'.
dnl mregparm is used on the i386. Some gcc versions do not pass the third AC_DEFUN(grub_CHECK_ENABLE_EXECUTE_STACK,[
dnl parameter correctly to the nested function. AC_MSG_CHECKING([whether `$CC' generates calls to `__enable_execute_stack()'])
dnl Written by Marco Gerards. AC_LANG_CONFTEST([[
AC_DEFUN(grub_I386_CHECK_REGPARM_BUG, void f (int (*p) (void));
[AC_REQUIRE([AC_PROG_CC]) void g (int i)
AC_MSG_CHECKING([if GCC has the regparm=3 bug])
AC_CACHE_VAL(grub_cv_i386_check_nested_functions,
[AC_RUN_IFELSE([AC_LANG_SOURCE(
[[
static int
test (int *n)
{ {
return *n == -1; int nestedfunc (void) { return i; }
f (nestedfunc);
} }
]])
static int if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -S conftest.c]) && test -s conftest.s; then
testfunc (int __attribute__ ((__regparm__ (3))) (*hook) (int a, int b, int *c)) true
{
int a = 0;
int b = 0;
int c = -1;
return hook (a, b, &c);
}
int
main (void)
{
int __attribute__ ((__regparm__ (3))) nestedfunc (int a, int b, int *c)
{
return a == b && test (c);
}
return testfunc (nestedfunc) ? 0 : 1;
}
]])],
[grub_cv_i386_check_nested_functions=no],
[grub_cv_i386_check_nested_functions=yes])])
AC_MSG_RESULT([$grub_cv_i386_check_nested_functions])
if test "x$grub_cv_i386_check_nested_functions" = xyes; then
AC_DEFINE([NESTED_FUNC_ATTR],
[__attribute__ ((__regparm__ (2)))],
[Catch gcc bug])
else else
dnl Unfortunately, the above test does not detect a bug in gcc-4.0. AC_MSG_ERROR([${CC-cc} failed to produce assembly code])
dnl So use regparm 2 until a better test is found.
AC_DEFINE([NESTED_FUNC_ATTR],
[__attribute__ ((__regparm__ (2)))],
[Catch gcc bug])
fi fi
if grep __enable_execute_stack conftest.s >/dev/null 2>&1; then
AC_DEFINE([NEED_ENABLE_EXECUTE_STACK], 1,
[Define to 1 if GCC generates calls to __enable_execute_stack()])
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no])
fi
rm -f conftest*
]) ])
dnl Check if the C compiler supports `-fstack-protector'. dnl Check if the C compiler supports `-fstack-protector'.
AC_DEFUN(grub_CHECK_STACK_PROTECTOR,[ AC_DEFUN(grub_CHECK_STACK_PROTECTOR,[
@ -362,3 +396,65 @@ else
AC_MSG_RESULT([no]) AC_MSG_RESULT([no])
[fi] [fi]
]) ])
dnl Check if the C compiler supports `-mstack-arg-probe' (Cygwin).
AC_DEFUN(grub_CHECK_STACK_ARG_PROBE,[
[# Smashing stack arg probe.
sap_possible=yes]
AC_MSG_CHECKING([whether `$CC' accepts `-mstack-arg-probe'])
AC_LANG_CONFTEST([[void foo (void) { volatile char a[8]; a[3]; }]])
[if eval "$ac_compile -S -mstack-arg-probe -o conftest.s" 2> /dev/null; then]
AC_MSG_RESULT([yes])
[# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
rm -f conftest.s
else
sap_possible=no]
AC_MSG_RESULT([no])
[fi]
])
dnl Check if ln can handle directories properly (mingw).
AC_DEFUN(grub_CHECK_LINK_DIR,[
AC_MSG_CHECKING([whether ln can handle directories properly])
[mkdir testdir 2>/dev/null
case $srcdir in
[\\/$]* | ?:[\\/]* ) reldir=$srcdir/include/grub/util ;;
*) reldir=../$srcdir/include/grub/util ;;
esac
if ln -s $reldir testdir/util 2>/dev/null ; then]
AC_MSG_RESULT([yes])
[link_dir=yes
else
link_dir=no]
AC_MSG_RESULT([no])
[fi
rm -rf testdir]
])
dnl Check if the C compiler supports `-fPIE'.
AC_DEFUN(grub_CHECK_PIE,[
[# Position independent executable.
pie_possible=yes]
AC_MSG_CHECKING([whether `$CC' has `-fPIE' as default])
# Is this a reliable test case?
AC_LANG_CONFTEST([[
#ifdef __PIE__
int main() {
return 0;
}
#else
#error NO __PIE__ DEFINED
#endif
]])
[# `$CC -c -o ...' might not be portable. But, oh, well... Is calling
# `ac_compile' like this correct, after all?
if eval "$ac_compile -S -o conftest.s" 2> /dev/null; then]
AC_MSG_RESULT([yes])
[# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
rm -f conftest.s
else
pie_possible=no]
AC_MSG_RESULT([no])
[fi]
])

16
autogen.sh Normal file → Executable file
View File

@ -2,10 +2,22 @@
set -e set -e
aclocal
autoconf autoconf
autoheader autoheader
for rmk in conf/*.rmk; do
ruby genmk.rb < $rmk > `echo $rmk | sed 's/\.rmk$/.mk/'` # FIXME: automake doesn't like that there's no Makefile.am
automake -a -c -f || true
echo timestamp > stamp-h.in
python util/import_gcry.py lib/libgcrypt/ .
for rmk in conf/*.rmk ${GRUB_CONTRIB}/*/conf/*.rmk; do
if test -e $rmk ; then
ruby genmk.rb < $rmk > `echo $rmk | sed 's/\.rmk$/.mk/'`
fi
done done
sh gendistlist.sh > DISTLIST
exit 0 exit 0

View File

@ -1,7 +1,7 @@
/* -*-Asm-*- */ /* -*-Asm-*- */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2005,2006,2007 Free Software Foundation, Inc. * Copyright (C) 1999,2000,2001,2002,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
* *
* GRUB is free software: you can redistribute it and/or modify * GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -17,24 +17,17 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <grub/symbol.h>
#include <grub/boot.h> #include <grub/boot.h>
#include <grub/machine/boot.h> #include <grub/machine/boot.h>
/* /*
* defines for the code go here * defines for the code go here
*/ */
/* Absolute addresses
This makes the assembler generate the address without support
from the linker. (ELF can't relocate 16-bit addresses!) */
#define ABS(x) (x-_start+0x7c00)
/* Print message string */ /* Print message string */
#define MSG(x) movw $ABS(x), %si; call message #define MSG(x) movw $x, %si; call LOCAL(message)
/* XXX: binutils-2.9.1.0.x doesn't produce a short opcode for this. */
#define MOV_MEM_TO_AL(x) .byte 0xa0; .word x
.file "boot.S" .file "boot.S"
.text .text
@ -43,7 +36,9 @@
in real mode. */ in real mode. */
.code16 .code16
.globl _start; _start: .globl _start, start;
_start:
start:
/* /*
* _start is loaded at 0x7c00 and is jumped to with CS:IP 0:0x7c00 * _start is loaded at 0x7c00 and is jumped to with CS:IP 0:0x7c00
*/ */
@ -53,7 +48,7 @@
* parameter block. * parameter block.
*/ */
jmp after_BPB jmp LOCAL(after_BPB)
nop /* do I care about this ??? */ nop /* do I care about this ??? */
/* /*
@ -62,12 +57,13 @@
* this area. * this area.
*/ */
. = _start + GRUB_BOOT_MACHINE_BPB_START
. = _start + 4 . = _start + 4
/* scratch space */ /* scratch space */
mode: mode:
.byte 0 .byte 0
disk_address_packet: disk_address_packet:
sectors: sectors:
.long 0 .long 0
heads: heads:
@ -88,19 +84,19 @@ cylinder_start:
* End of BIOS parameter block. * End of BIOS parameter block.
*/ */
boot_version:
.byte GRUB_BOOT_VERSION_MAJOR, GRUB_BOOT_VERSION_MINOR
kernel_address: kernel_address:
.word GRUB_BOOT_MACHINE_KERNEL_ADDR .word GRUB_BOOT_MACHINE_KERNEL_ADDR
kernel_segment:
.word GRUB_BOOT_MACHINE_KERNEL_SEG . = _start + GRUB_BOOT_MACHINE_KERNEL_SECTOR
kernel_sector: kernel_sector:
.long 1, 0 .long 1, 0
boot_drive:
. = _start + GRUB_BOOT_MACHINE_BOOT_DRIVE
boot_drive:
.byte 0xff /* the disk to load kernel from */ .byte 0xff /* the disk to load kernel from */
/* 0xff means use the boot drive */ /* 0xff means use the boot drive */
after_BPB: LOCAL(after_BPB):
/* general setup */ /* general setup */
cli /* we're not safe here! */ cli /* we're not safe here! */
@ -113,20 +109,21 @@ after_BPB:
* possible boot drive. If GRUB is installed into a floppy, * possible boot drive. If GRUB is installed into a floppy,
* this does nothing (only jump). * this does nothing (only jump).
*/ */
. = _start + GRUB_BOOT_MACHINE_DRIVE_CHECK
boot_drive_check: boot_drive_check:
jmp 1f /* grub-setup may overwrite this jump */ jmp 1f /* grub-setup may overwrite this jump */
testb $0x80, %dl testb $0x80, %dl
jnz 1f jnz 1f
movb $0x80, %dl movb $0x80, %dl
1: 1:
/* /*
* ljmp to the next instruction because some bogus BIOSes * ljmp to the next instruction because some bogus BIOSes
* jump to 07C0:0000 instead of 0000:7C00. * jump to 07C0:0000 instead of 0000:7C00.
*/ */
ljmp $0, $ABS(real_start) ljmp $0, $real_start
real_start: real_start:
/* set up %ds and %ss as offset from 0 */ /* set up %ds and %ss as offset from 0 */
xorw %ax, %ax xorw %ax, %ax
@ -141,7 +138,7 @@ real_start:
/* /*
* Check if we have a forced disk reference here * Check if we have a forced disk reference here
*/ */
MOV_MEM_TO_AL(ABS(boot_drive)) /* movb ABS(boot_drive), %al */ movb boot_drive, %al
cmpb $0xff, %al cmpb $0xff, %al
je 1f je 1f
movb %al, %dl movb %al, %dl
@ -153,18 +150,18 @@ real_start:
MSG(notification_string) MSG(notification_string)
/* set %si to the disk address packet */ /* set %si to the disk address packet */
movw $ABS(disk_address_packet), %si movw $disk_address_packet, %si
/* do not probe LBA if the drive is a floppy */ /* do not probe LBA if the drive is a floppy */
testb $GRUB_BOOT_MACHINE_BIOS_HD_FLAG, %dl testb $GRUB_BOOT_MACHINE_BIOS_HD_FLAG, %dl
jz chs_mode jz LOCAL(chs_mode)
/* check if LBA is supported */ /* check if LBA is supported */
movb $0x41, %ah movb $0x41, %ah
movw $0x55aa, %bx movw $0x55aa, %bx
int $0x13 int $0x13
/* /*
* %dl may have been clobbered by INT 13, AH=41H. * %dl may have been clobbered by INT 13, AH=41H.
* This happens, for example, with AST BIOS 1.04. * This happens, for example, with AST BIOS 1.04.
*/ */
@ -172,21 +169,21 @@ real_start:
pushw %dx pushw %dx
/* use CHS if fails */ /* use CHS if fails */
jc chs_mode jc LOCAL(chs_mode)
cmpw $0xaa55, %bx cmpw $0xaa55, %bx
jne chs_mode jne LOCAL(chs_mode)
andw $1, %cx andw $1, %cx
jz chs_mode jz LOCAL(chs_mode)
lba_mode: lba_mode:
xorw %ax, %ax xorw %ax, %ax
movw %ax, 4(%si) movw %ax, 4(%si)
incw %ax incw %ax
/* set the mode to non-zero */ /* set the mode to non-zero */
movb %al, -1(%si) movb %al, -1(%si)
/* the blocks */ /* the blocks */
movw %ax, 2(%si) movw %ax, 2(%si)
@ -194,9 +191,9 @@ lba_mode:
movw $0x0010, (%si) movw $0x0010, (%si)
/* the absolute address */ /* the absolute address */
movl ABS(kernel_sector), %ebx movl kernel_sector, %ebx
movl %ebx, 8(%si) movl %ebx, 8(%si)
movl ABS(kernel_sector + 4), %ebx movl kernel_sector + 4, %ebx
movl %ebx, 12(%si) movl %ebx, 12(%si)
/* the segment of buffer address */ /* the segment of buffer address */
@ -215,34 +212,34 @@ lba_mode:
int $0x13 int $0x13
/* LBA read is not supported, so fallback to CHS. */ /* LBA read is not supported, so fallback to CHS. */
jc chs_mode jc LOCAL(chs_mode)
movw $GRUB_BOOT_MACHINE_BUFFER_SEG, %bx movw $GRUB_BOOT_MACHINE_BUFFER_SEG, %bx
jmp copy_buffer jmp LOCAL(copy_buffer)
chs_mode: LOCAL(chs_mode):
/* /*
* Determine the hard disk geometry from the BIOS! * Determine the hard disk geometry from the BIOS!
* We do this first, so that LS-120 IDE floppies work correctly. * We do this first, so that LS-120 IDE floppies work correctly.
*/ */
movb $8, %ah movb $8, %ah
int $0x13 int $0x13
jnc final_init jnc LOCAL(final_init)
/* /*
* The call failed, so maybe use the floppy probe instead. * The call failed, so maybe use the floppy probe instead.
*/ */
testb $GRUB_BOOT_MACHINE_BIOS_HD_FLAG, %dl testb $GRUB_BOOT_MACHINE_BIOS_HD_FLAG, %dl
jz floppy_probe jz LOCAL(floppy_probe)
/* Nope, we definitely have a hard disk, and we're screwed. */ /* Nope, we definitely have a hard disk, and we're screwed. */
jmp hd_probe_error jmp LOCAL(hd_probe_error)
final_init: LOCAL(final_init):
/* set the mode to zero */ /* set the mode to zero */
movzbl %dh, %eax movzbl %dh, %eax
movb %ah, -1(%si) movb %ah, -1(%si)
/* save number of heads */ /* save number of heads */
incw %ax incw %ax
movl %eax, 4(%si) movl %eax, 4(%si)
@ -264,12 +261,13 @@ final_init:
setup_sectors: setup_sectors:
/* load logical sector start (top half) */ /* load logical sector start (top half) */
movl ABS(kernel_sector + 4), %eax movl kernel_sector + 4, %eax
orl %eax, %eax orl %eax, %eax
jnz geometry_error jnz LOCAL(geometry_error)
/* load logical sector start (bottom half) */ /* load logical sector start (bottom half) */
movl ABS(kernel_sector), %eax movl kernel_sector, %eax
/* zero %edx */ /* zero %edx */
xorl %edx, %edx xorl %edx, %edx
@ -285,7 +283,7 @@ setup_sectors:
/* do we need too many cylinders? */ /* do we need too many cylinders? */
cmpw 8(%si), %ax cmpw 8(%si), %ax
jge geometry_error jge LOCAL(geometry_error)
/* normalize sector start (1-based) */ /* normalize sector start (1-based) */
incb %cl incb %cl
@ -327,27 +325,26 @@ setup_sectors:
movw $0x0201, %ax /* function 2 */ movw $0x0201, %ax /* function 2 */
int $0x13 int $0x13
jc read_error jc LOCAL(read_error)
movw %es, %bx movw %es, %bx
copy_buffer:
movw ABS(kernel_segment), %es
LOCAL(copy_buffer):
/* /*
* We need to save %cx and %si because the startup code in * We need to save %cx and %si because the startup code in
* kernel uses them without initializing them. * kernel uses them without initializing them.
*/ */
pusha pusha
pushw %ds pushw %ds
movw $0x100, %cx movw $0x100, %cx
movw %bx, %ds movw %bx, %ds
xorw %si, %si xorw %si, %si
xorw %di, %di movw $GRUB_BOOT_MACHINE_KERNEL_ADDR, %di
movw %si, %es
cld cld
rep rep
movsw movsw
@ -362,36 +359,37 @@ copy_buffer:
/* /*
* BIOS Geometry translation error (past the end of the disk geometry!). * BIOS Geometry translation error (past the end of the disk geometry!).
*/ */
geometry_error: LOCAL(geometry_error):
MSG(geometry_error_string) MSG(geometry_error_string)
jmp general_error jmp LOCAL(general_error)
/* /*
* Disk probe failure. * Disk probe failure.
*/ */
hd_probe_error: LOCAL(hd_probe_error):
MSG(hd_probe_error_string) MSG(hd_probe_error_string)
jmp general_error jmp LOCAL(general_error)
/* /*
* Read error on the disk. * Read error on the disk.
*/ */
read_error: LOCAL(read_error):
MSG(read_error_string) MSG(read_error_string)
general_error: LOCAL(general_error):
MSG(general_error_string) MSG(general_error_string)
/* go here when you need to stop the machine hard after an error condition */ /* go here when you need to stop the machine hard after an error condition */
/* tell the BIOS a boot failure, which may result in no effect */ /* tell the BIOS a boot failure, which may result in no effect */
int $0x18 int $0x18
stop: jmp stop LOCAL(stop):
jmp LOCAL(stop)
notification_string: .string "GRUB " notification_string: .asciz "GRUB "
geometry_error_string: .string "Geom" geometry_error_string: .asciz "Geom"
hd_probe_error_string: .string "Hard Disk" hd_probe_error_string: .asciz "Hard Disk"
read_error_string: .string "Read" read_error_string: .asciz "Read"
general_error_string: .string " Error" general_error_string: .asciz " Error\r\n"
/* /*
* message: write the string pointed to by %si * message: write the string pointed to by %si
@ -408,7 +406,7 @@ general_error_string: .string " Error"
movw $0x0001, %bx movw $0x0001, %bx
movb $0xe, %ah movb $0xe, %ah
int $0x10 /* display a byte */ int $0x10 /* display a byte */
message: LOCAL(message):
lodsb lodsb
cmpb $0, %al cmpb $0, %al
jne 1b /* if not end of string, jmp to display */ jne 1b /* if not end of string, jmp to display */
@ -420,7 +418,7 @@ message:
*/ */
. = _start + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC . = _start + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC
nt_magic: nt_magic:
.long 0 .long 0
.word 0 .word 0
@ -430,20 +428,20 @@ nt_magic:
* sneaky, huh? * sneaky, huh?
*/ */
part_start:
. = _start + GRUB_BOOT_MACHINE_PART_START . = _start + GRUB_BOOT_MACHINE_PART_START
part_start:
probe_values: probe_values:
.byte 36, 18, 15, 9, 0 .byte 36, 18, 15, 9, 0
floppy_probe: LOCAL(floppy_probe):
/* /*
* Perform floppy probe. * Perform floppy probe.
*/ */
movw $ABS(probe_values-1), %si movw $probe_values - 1, %si
probe_loop: LOCAL(probe_loop):
/* reset floppy controller INT 13h AH=0 */ /* reset floppy controller INT 13h AH=0 */
xorw %ax, %ax xorw %ax, %ax
int $0x13 int $0x13
@ -459,9 +457,10 @@ probe_loop:
* Floppy disk probe failure. * Floppy disk probe failure.
*/ */
MSG(fd_probe_error_string) MSG(fd_probe_error_string)
jmp general_error jmp LOCAL(general_error)
fd_probe_error_string: .string "Floppy" /* "Floppy" */
fd_probe_error_string: .asciz "Floppy"
1: 1:
/* perform read */ /* perform read */
@ -471,14 +470,14 @@ fd_probe_error_string: .string "Floppy"
movb $0, %dh movb $0, %dh
int $0x13 int $0x13
/* if error, jump to "probe_loop" */ /* if error, jump to "LOCAL(probe_loop)" */
jc probe_loop jc LOCAL(probe_loop)
/* %cl is already the correct value! */ /* %cl is already the correct value! */
movb $1, %dh movb $1, %dh
movb $79, %ch movb $79, %ch
jmp final_init jmp LOCAL(final_init)
. = _start + GRUB_BOOT_MACHINE_PART_END . = _start + GRUB_BOOT_MACHINE_PART_END

173
boot/i386/pc/cdboot.S Normal file
View File

@ -0,0 +1,173 @@
/* -*-Asm-*- */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008,2009 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/symbol.h>
#include <grub/boot.h>
#include <grub/machine/boot.h>
#include <grub/machine/kernel.h>
#include <multiboot.h>
.file "cdboot.S"
#define CODE_ADDR 0x6000
#define DATA_ADDR ((GRUB_BOOT_MACHINE_KERNEL_ADDR) + 0x200)
#define CDSEC_SHIFT 11
#define CDBLK_LENG 16
.text
.code16
.globl start, _start
start:
_start:
call LOCAL(next)
LOCAL(next):
jmp 1f
. = start + 8
bi_pvd:
.long 0 /* LBA of primary volume descriptor. */
bi_file:
.long 0 /* LBA of boot file. */
bi_length:
.long 0 /* Length of boot file. */
bi_csum:
.long 0 /* Checksum of boot file */
bi_reserved:
.space (10*4) /* Reserved */
1:
popw %bx
/* Boot from CDROM. */
xorw %ax, %ax
movw %ax, %ss
movw $(CODE_ADDR), %sp
movw %ax, %ds
movw %ax, %es
movw $(0x7C00 + err_noboot_msg - start), %si
movl %cs: bi_length - LOCAL(next)(%bx), %ecx
orl %ecx, %ecx
jz LOCAL(fail)
addl $((1 << CDSEC_SHIFT) - 1), %ecx
shrl $CDSEC_SHIFT, %ecx
movl %cs: bi_file - LOCAL(next)(%bx), %esi
call LOCAL(read_cdrom)
ljmp $(DATA_ADDR >> 4), $0
/*
* Parameters:
* esi: start sector
* ecx: number of sectors
*/
LOCAL(read_cdrom):
xorl %eax, %eax
/* Number of blocks to read. */
pushw $CDBLK_LENG
/* Block number. */
pushl %eax
pushl %esi
/* Buffer address. */
pushw $((DATA_ADDR - 0x400)>> 4)
pushl %eax
pushw $0x10
xorl %edi, %edi
movw %sp, %si
1:
movw 0x10(%si), %di
cmpl %ecx, %edi
jbe 2f
movl %ecx, %edi
2:
mov %di, 2(%si)
pushl %ecx
movb $0x42, %ah
int $0x13
jnc 3f
movb $0x42, %ah /* Try again. */
int $0x13
jnc 3f
2:
shrw $1, %di /* Reduce transfer size. */
jz LOCAL(cdrom_fail)
movw %di, 0x10(%si)
movw %di, 2(%si)
movb $0x42, %ah
int $0x13
jc 2b
3:
movw %di, %ax
shlw $(CDSEC_SHIFT - 4), %ax
addw %ax, 6(%si)
addl %edi, 8(%si)
popl %ecx
subl %edi, %ecx
jnz 1b
addw $0x12, %sp
ret
LOCAL(cdrom_fail):
movw $(0x7C00 + err_cdfail_msg - start), %si
LOCAL(fail):
movb $0x0e, %ah
xorw %bx, %bx
1:
lodsb (%si), %al
int $0x10
cmpb $0, %al
jne 1b
1: jmp 1b
err_noboot_msg:
.ascii "no boot info\0"
err_cdfail_msg:
.ascii "cdrom read fails\0"
. = start + 0x1FF
.byte 0

View File

@ -1,6 +1,6 @@
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2006,2007 Free Software Foundation, Inc. * Copyright (C) 1999,2000,2001,2002,2006,2007,2009,2010 Free Software Foundation, Inc.
* *
* GRUB is free software: you can redistribute it and/or modify * GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -16,19 +16,14 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <grub/symbol.h>
#include <grub/machine/boot.h> #include <grub/machine/boot.h>
/* /*
* defines for the code go here * defines for the code go here
*/ */
/* Absolute addresses #define MSG(x) movw $x, %si; call LOCAL(message)
This makes the assembler generate the address without support
from the linker. (ELF can't relocate 16-bit addresses!) */
#define ABS(x) (x-_start+GRUB_BOOT_MACHINE_KERNEL_ADDR)
/* Print message string */
#define MSG(x) movw $ABS(x), %si; call message
.file "diskboot.S" .file "diskboot.S"
@ -40,18 +35,18 @@
.globl start, _start .globl start, _start
start: start:
_start: _start:
/* /*
* _start is loaded at 0x2000 and is jumped to with * _start is loaded at 0x2000 and is jumped to with
* CS:IP 0:0x2000 in kernel. * CS:IP 0:0x2000 in kernel.
*/ */
/* /*
* we continue to use the stack for boot.img and assume that * we continue to use the stack for boot.img and assume that
* some registers are set to correct values. See boot.S * some registers are set to correct values. See boot.S
* for more information. * for more information.
*/ */
/* save drive reference first thing! */ /* save drive reference first thing! */
pushw %dx pushw %dx
@ -59,30 +54,29 @@ _start:
pushw %si pushw %si
MSG(notification_string) MSG(notification_string)
popw %si popw %si
/* this sets up for the first run through "bootloop" */ /* this sets up for the first run through "bootloop" */
movw $ABS(firstlist - GRUB_BOOT_MACHINE_LIST_SIZE), %di movw $(firstlist - GRUB_BOOT_MACHINE_LIST_SIZE), %di
/* save the sector number of the second sector in %ebp */ /* save the sector number of the second sector in %ebp */
movl (%di), %ebp movl (%di), %ebp
/* this is the loop for reading the rest of the kernel in */ /* this is the loop for reading the rest of the kernel in */
bootloop: LOCAL(bootloop):
/* check the number of sectors to read */ /* check the number of sectors to read */
cmpw $0, 8(%di) cmpw $0, 8(%di)
/* if zero, go to the start function */ /* if zero, go to the start function */
je bootit je LOCAL(bootit)
setup_sectors: LOCAL(setup_sectors):
/* check if we use LBA or CHS */ /* check if we use LBA or CHS */
cmpb $0, -1(%si) cmpb $0, -1(%si)
/* jump to chs_mode if zero */ /* use CHS if zero, LBA otherwise */
je chs_mode je LOCAL(chs_mode)
lba_mode:
/* load logical sector start */ /* load logical sector start */
movl (%di), %ebx movl (%di), %ebx
movl 4(%di), %ecx movl 4(%di), %ecx
@ -100,7 +94,7 @@ lba_mode:
/* if less than, set to total */ /* if less than, set to total */
movw 8(%di), %ax movw 8(%di), %ax
1: 1:
/* subtract from total */ /* subtract from total */
subw %ax, 8(%di) subw %ax, 8(%di)
@ -141,16 +135,16 @@ lba_mode:
movb $0x42, %ah movb $0x42, %ah
int $0x13 int $0x13
jc read_error jc LOCAL(read_error)
movw $GRUB_BOOT_MACHINE_BUFFER_SEG, %bx movw $GRUB_BOOT_MACHINE_BUFFER_SEG, %bx
jmp copy_buffer jmp LOCAL(copy_buffer)
chs_mode: LOCAL(chs_mode):
/* load logical sector start (top half) */ /* load logical sector start (top half) */
movl 4(%di), %eax movl 4(%di), %eax
orl %eax, %eax orl %eax, %eax
jnz geometry_error jnz LOCAL(geometry_error)
/* load logical sector start (bottom half) */ /* load logical sector start (bottom half) */
movl (%di), %eax movl (%di), %eax
@ -175,7 +169,7 @@ chs_mode:
/* do we need too many cylinders? */ /* do we need too many cylinders? */
cmpw 8(%si), %ax cmpw 8(%si), %ax
jge geometry_error jge LOCAL(geometry_error)
/* determine the maximum sector length of this read */ /* determine the maximum sector length of this read */
movw (%si), %ax /* get number of sectors per track/head */ movw (%si), %ax /* get number of sectors per track/head */
@ -193,7 +187,7 @@ chs_mode:
/* if less than, set to total */ /* if less than, set to total */
movw 8(%di), %ax movw 8(%di), %ax
2: 2:
/* subtract from total */ /* subtract from total */
subw %ax, 8(%di) subw %ax, 8(%di)
@ -245,12 +239,12 @@ chs_mode:
movb $0x2, %ah /* function 2 */ movb $0x2, %ah /* function 2 */
int $0x13 int $0x13
jc read_error jc LOCAL(read_error)
/* save source segment */ /* save source segment */
movw %es, %bx movw %es, %bx
copy_buffer: LOCAL(copy_buffer):
/* load addresses for copy from disk buffer to destination */ /* load addresses for copy from disk buffer to destination */
movw 10(%di), %es /* load destination segment */ movw 10(%di), %es /* load destination segment */
@ -282,7 +276,7 @@ copy_buffer:
rep /* sets a repeat */ rep /* sets a repeat */
movsw /* this runs the actual copy */ movsw /* this runs the actual copy */
/* restore addressing regs and print a dot with correct DS /* restore addressing regs and print a dot with correct DS
(MSG modifies SI, which is saved, and unused AX and BX) */ (MSG modifies SI, which is saved, and unused AX and BX) */
popw %ds popw %ds
MSG(notification_step) MSG(notification_step)
@ -290,17 +284,17 @@ copy_buffer:
/* check if finished with this dataset */ /* check if finished with this dataset */
cmpw $0, 8(%di) cmpw $0, 8(%di)
jne setup_sectors jne LOCAL(setup_sectors)
/* update position to load from */ /* update position to load from */
subw $GRUB_BOOT_MACHINE_LIST_SIZE, %di subw $GRUB_BOOT_MACHINE_LIST_SIZE, %di
/* jump to bootloop */ /* jump to bootloop */
jmp bootloop jmp LOCAL(bootloop)
/* END OF MAIN LOOP */ /* END OF MAIN LOOP */
bootit: LOCAL(bootit):
/* print a newline */ /* print a newline */
MSG(notification_done) MSG(notification_done)
popw %dx /* this makes sure %dl is our "boot" drive */ popw %dx /* this makes sure %dl is our "boot" drive */
@ -310,30 +304,30 @@ bootit:
/* /*
* BIOS Geometry translation error (past the end of the disk geometry!). * BIOS Geometry translation error (past the end of the disk geometry!).
*/ */
geometry_error: LOCAL(geometry_error):
MSG(geometry_error_string) MSG(geometry_error_string)
jmp general_error jmp LOCAL(general_error)
/* /*
* Read error on the disk. * Read error on the disk.
*/ */
read_error: LOCAL(read_error):
MSG(read_error_string) MSG(read_error_string)
general_error: LOCAL(general_error):
MSG(general_error_string) MSG(general_error_string)
/* go here when you need to stop the machine hard after an error condition */ /* go here when you need to stop the machine hard after an error condition */
stop: jmp stop LOCAL(stop): jmp LOCAL(stop)
notification_string: .string "Loading kernel" notification_string: .asciz "loading"
notification_step: .string "." notification_step: .asciz "."
notification_done: .string "\r\n" notification_done: .asciz "\r\n"
geometry_error_string: .string "Geom" geometry_error_string: .asciz "Geom"
read_error_string: .string "Read" read_error_string: .asciz "Read"
general_error_string: .string " Error" general_error_string: .asciz " Error"
/* /*
* message: write the string pointed to by %si * message: write the string pointed to by %si
@ -352,12 +346,11 @@ general_error_string: .string " Error"
int $0x10 /* display a byte */ int $0x10 /* display a byte */
incw %si incw %si
message: LOCAL(message):
movb (%si), %al movb (%si), %al
cmpb $0, %al cmpb $0, %al
jne 1b /* if not end of string, jmp to display */ jne 1b /* if not end of string, jmp to display */
ret ret
lastlist:
/* /*
* This area is an empty space between the main body of code below which * This area is an empty space between the main body of code below which
@ -370,18 +363,18 @@ lastlist:
.word 0 .word 0
. = _start + 0x200 - GRUB_BOOT_MACHINE_LIST_SIZE . = _start + 0x200 - GRUB_BOOT_MACHINE_LIST_SIZE
/* fill the first data listing with the default */ /* fill the first data listing with the default */
blocklist_default_start: blocklist_default_start:
/* this is the sector start parameter, in logical sectors from /* this is the sector start parameter, in logical sectors from
the start of the disk, sector 0 */ the start of the disk, sector 0 */
.long 2, 0 .long 2, 0
blocklist_default_len: blocklist_default_len:
/* this is the number of sectors to read the command "install" /* this is the number of sectors to read. grub-mkimage
will fill this up */ will fill this up */
.word 0 .word 0
blocklist_default_seg: blocklist_default_seg:
/* this is the segment of the starting address to load the data into */ /* this is the segment of the starting address to load the data into */
.word (GRUB_BOOT_MACHINE_KERNEL_SEG + 0x20) .word (GRUB_BOOT_MACHINE_KERNEL_SEG + 0x20)
firstlist: /* this label has to be after the list data!!! */ firstlist: /* this label has to be after the list data!!! */

View File

@ -1,7 +1,7 @@
/* -*-Asm-*- */ /* -*-Asm-*- */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2005,2006,2007 Free Software Foundation, Inc. * Copyright (C) 2007,2008,2009 Free Software Foundation, Inc.
* *
* GRUB is free software: you can redistribute it and/or modify * GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -17,14 +17,17 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <config.h>
#include <grub/symbol.h>
#include <grub/boot.h> #include <grub/boot.h>
#include <grub/machine/boot.h> #include <grub/machine/boot.h>
#include <grub/machine/kernel.h> #include <grub/machine/kernel.h>
#include <multiboot.h>
.file "lnxboot.S" .file "lnxboot.S"
#define CODE_ADDR 0x6000 #define CODE_ADDR 0x6000
#define CODE_LENG (code_end - start) #define CODE_SECTORS 1
#define DATA_ADDR ((GRUB_BOOT_MACHINE_KERNEL_ADDR) + 0x200) #define DATA_ADDR ((GRUB_BOOT_MACHINE_KERNEL_ADDR) + 0x200)
#define BLCK_LENG 0x4000 #define BLCK_LENG 0x4000
@ -36,28 +39,13 @@
.globl start, _start .globl start, _start
data_start: data_start:
pushw %cs xorl %ebp, %ebp
popw %ds jmp LOCAL(linux_next)
xorl %eax, %eax
xorl %ebx, %ebx
call data_next
data_next:
popw %bx
movw %cs, %ax
shll $4, %eax
leal 0x200 + data_start - data_next(%ebx,%eax), %eax
movzbl setup_sects - data_next(%bx), %ecx
shll $9, %ecx
addl %ecx, %eax
movl %eax, code32_start - data_next(%bx)
jmp linux_next
. = data_start + 0x1F1 . = data_start + 0x1F1
setup_sects: setup_sects:
.byte (CODE_LENG >> 9) .byte CODE_SECTORS
root_flags: root_flags:
.word 0 .word 0
syssize: syssize:
@ -76,29 +64,29 @@ boot_flag:
start: start:
_start: _start:
jmp linux_code jmp LOCAL(linux_init)
.ascii "HdrS" // Header signature .ascii "HdrS" /* Header signature. */
.word 0x0203 // Header version number .word 0x0203 /* Header version number. */
realmode_swtch: realmode_swtch:
.word 0, 0 // default_switch, SETUPSEG .word 0, 0 /* default_switch, SETUPSEG. */
start_sys_seg: start_sys_seg:
.word 0x1000 // obsolete .word 0x1000 /* Obsolete. */
version_ptr: version_ptr:
.word 0 // version string ptr .word 0 /* Version string ptr. */
type_of_loader: type_of_loader:
.byte 0 // Filled in by boot loader .byte 0 /* Filled in by boot loader. */
loadflags: loadflags:
.byte 1 // Please load high .byte 1 /* Please load high. */
setup_move_size: setup_move_size:
.word 0 // Unused .word 0 /* Unused. */
code32_start: code32_start:
.long 0x100000 // 32-bit start address .long 0x100000 /* 32-bit start address. */
ramdisk_image: ramdisk_image:
.long 0 // Loaded ramdisk image address .long 0 /* Loaded ramdisk image address. */
ramdisk_size: ramdisk_size:
.long 0 // Size of loaded ramdisk .long 0 /* Size of loaded ramdisk. */
bootsect_kludge: bootsect_kludge:
.word 0, 0 .word 0, 0
heap_end_ptr: heap_end_ptr:
@ -106,51 +94,51 @@ heap_end_ptr:
pad1: pad1:
.word 0 .word 0
cmd_line_ptr: cmd_line_ptr:
.long 0 // Command line .long 0 /* Command line. */
ramdisk_max: ramdisk_max:
.long 0xffffffff // Highest allowed ramdisk address .long 0xffffffff /* Highest allowed ramdisk address. */
gdt: gdt:
.long 0, 0, 0, 0 // Must be zero .long 0, 0, 0, 0 /* Must be zero. */
.word 0xffff // 64 K segment size .word 0xffff /* 64 K segment size. */
gdt_src1: gdt_src1:
.byte 0, 0 ,0 // Low 24 bits of source addy .byte 0, 0 ,0 /* Low 24 bits of source address. */
.byte 0x93 // Access rights .byte 0x93 /* Access rights. */
.byte 0 // Extended access rights .byte 0 /* Extended access rights. */
gdt_src2: gdt_src2:
.byte 0 // High 8 bits of source addy .byte 0 /* High 8 bits of source address. */
.word 0xffff // 64 K segment size .word 0xffff /* 64 K segment size. */
gdt_dst1: gdt_dst1:
.byte 0, 0, 0 // Low 24 bits of target addy .byte 0, 0, 0 /* Low 24 bits of target address. */
.byte 0x93 // Access rights .byte 0x93 /* Access rights. */
.byte 0 // Extended access rights .byte 0 /* Extended access rights. */
gdt_dst2: gdt_dst2:
.byte 0 // High 8 bits of source addy .byte 0 /* High 8 bits of source address. */
.long 0, 0, 0, 0 // More space for the BIOS .long 0, 0, 0, 0 /* More space for the BIOS. */
reg_edx: reg_edx:
.byte 0x80,0,0xFF,0xFF .byte 0x80, 0, 0xFF, 0xFF
data_leng: data_leng:
.long 0 .long 0
linux_code: LOCAL(linux_init):
movw %cs:(reg_edx - start), %dx movw %cs:(reg_edx - start), %dx
movl %cs:(code32_start - start), %ebp
linux_next: LOCAL(linux_next):
call normalize call LOCAL(normalize)
normalize: LOCAL(normalize):
popw %bx popw %bx
subw $(normalize - start), %bx subw $(LOCAL(normalize) - start), %bx
shrw $4, %bx shrw $4, %bx
movw %cs, %ax movw %cs, %ax
addw %bx, %ax addw %bx, %ax
pushw %ax pushw %ax
pushw $(real_code - start) pushw $(real_code - start)
lret // jump to real_code lret /* Jump to real_code. */
real_code: real_code:
subw $0x20, %ax subw $0x20, %ax
@ -158,16 +146,13 @@ real_code:
movw (setup_sects - data_start), %cx movw (setup_sects - data_start), %cx
shlw $7, %cx shlw $7, %cx
// Setup stack /* Setup stack. */
xorw %si, %si xorw %si, %si
movw %si, %ss movw %si, %ss
movw $(CODE_ADDR), %sp movw $(CODE_ADDR), %sp
pushl %esi /* Move itself to 0:CODE_ADDR. */
pushl %edi
// Move itself to 0:CODE_ADDR
cld cld
movw %cs, %ax movw %cs, %ax
@ -178,47 +163,61 @@ real_code:
rep rep
movsl movsl
ljmp $(CODE_ADDR >> 4), $(real_code_2 - start) ljmp $(CODE_ADDR >> 4), $(real_code_2 - start)
real_code_2: real_code_2:
xchgl %ebp, %esi
orl %esi, %esi
jnz 1f
movw %ds, %si
shll $4, %esi
addl %ebp, %esi
1:
pushw %es pushw %es
popw %ds popw %ds
movl (ramdisk_image - start), %esi
or %esi, %esi
jnz 1f
movl (code32_start - start), %esi
1:
movl $0x200, %ecx movl $0x200, %ecx
addl %ecx, %esi addl %ecx, %esi
movl $DATA_ADDR, %edi movl $DATA_ADDR, %edi
call move_memory call LOCAL(move_memory)
movsbl %dh, %eax /* Check for multiboot signature. */
movl %eax, %ss:(DATA_ADDR + GRUB_KERNEL_MACHINE_INSTALL_DOS_PART) cmpl $MULTIBOOT_HEADER_MAGIC, %ss:(DATA_ADDR + GRUB_KERNEL_MACHINE_DATA_END)
jz 1f
movsbl (reg_edx + 2 - start), %eax movl (ramdisk_image - start), %esi
movl %eax, %ss:(DATA_ADDR + GRUB_KERNEL_MACHINE_INSTALL_BSD_PART) movl (ramdisk_size - start), %ecx
movl $(DATA_ADDR - 0x200), %edi
jmp 2f
1:
movl %ss:(DATA_ADDR + GRUB_KERNEL_MACHINE_COMPRESSED_SIZE), %ecx movl %ss:(DATA_ADDR + GRUB_KERNEL_MACHINE_COMPRESSED_SIZE), %ecx
addl $(GRUB_KERNEL_MACHINE_RAW_SIZE - 0x200), %ecx addl $(GRUB_KERNEL_MACHINE_RAW_SIZE - 0x200), %ecx
call move_memory 2:
call LOCAL(move_memory)
popl %edi movsbl %dh, %eax
popl %esi movl %eax, %ss:(DATA_ADDR + GRUB_KERNEL_MACHINE_INSTALL_DOS_PART)
movsbl (reg_edx + 2 - start), %eax
movl %eax, %ss:(DATA_ADDR + GRUB_KERNEL_MACHINE_INSTALL_BSD_PART)
movb $0xFF, %dh
ljmp $(DATA_ADDR >> 4), $0 ljmp $(DATA_ADDR >> 4), $0
// Parameters: /*
// esi: source address * Parameters:
// edi: target address * esi: source address
// ecx: number of bytes * edi: target address
move_memory: * ecx: number of bytes
*/
LOCAL(move_memory):
incl %ecx incl %ecx
andb $0xFE, %cl andb $0xFE, %cl
pushw %dx pushw %dx
@ -257,12 +256,12 @@ move_memory:
jnc 2f jnc 2f
movw $(err_int15_msg - start), %si movw $(err_int15_msg - start), %si
jmp fail jmp LOCAL(fail)
2: 2:
leal (%esi, %eax), %esi addl %eax, %esi
leal (%edi, %eax), %edi addl %eax, %edi
subl %eax, %ecx subl %eax, %ecx
jnz 1b jnz 1b
@ -270,9 +269,12 @@ move_memory:
popw %dx popw %dx
ret ret
// Parameters: /*
// si: message * Parameters:
fail: * si: message
*/
LOCAL(fail):
movb $0x0e, %ah movb $0x0e, %ah
xorw %bx, %bx xorw %bx, %bx
1: 1:
@ -285,8 +287,4 @@ fail:
err_int15_msg: err_int15_msg:
.ascii "move memory fails\0" .ascii "move memory fails\0"
. = (. & (~0x1FF)) + 0x1FF . = _start + CODE_SECTORS * 512
.byte 0
code_end:

View File

@ -1,6 +1,6 @@
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2000,2005,2007 Free Software Foundation, Inc. * Copyright (C) 2000,2005,2007,2008,2009 Free Software Foundation, Inc.
* *
* GRUB is free software: you can redistribute it and/or modify * GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -21,9 +21,14 @@
/* Start with the prehistoric environment... */ /* Start with the prehistoric environment... */
.code16 .code16
/* Let's go */ /* Let's go */
.globl _start; _start: .globl start, _start;
_start:
start:
/* Use drive number 0x7F for PXE */
movb $0x7F, %dl
/* Jump to the real world */ /* Jump to the real world */
ljmp $0, $0x8200 ljmp $0, $0x8200

67
boot/i386/qemu/boot.S Normal file
View File

@ -0,0 +1,67 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2005,2006,2007,2008,2009 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 <config.h>
#include <grub/symbol.h>
#include <grub/machine/memory.h>
#include <grub/machine/boot.h>
#include <grub/machine/kernel.h>
.text
.code16
.globl _start
_start:
/* Disable interrupts. */
cli
jmp 1f
. = _start + GRUB_BOOT_MACHINE_CORE_ENTRY_ADDR
VARIABLE(grub_core_entry_addr)
.long 0
1:
/* Process VGA rom. */
call $0xc000, $0x3
/* Set up %ds, %ss, and %es. */
xorw %ax, %ax
movw %ax, %ds
movw %ax, %ss
movw %ax, %es
/* Set up the real mode stack. */
movl $GRUB_MEMORY_MACHINE_REAL_STACK, %esp
/* Transition to protected mode. We use pushl to force generation
of a flat return address. */
pushl $1f
DATA32 jmp real_to_prot
.code32
1:
movl grub_core_entry_addr, %edx
jmp *%edx
#include "../../../kern/i386/realmode.S"
/* Intel, in its infinite wisdom, decided to put the i8086 entry point
*right here* and this is why we need this kludge. */
. = GRUB_BOOT_MACHINE_SIZE - 16
jmp _start
. = GRUB_BOOT_MACHINE_SIZE

View File

@ -0,0 +1,196 @@
/* -*-Asm-*- */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 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/boot.h>
#include <grub/machine/boot.h>
.text
.align 4
.globl _start
_start:
/* OF CIF entry point arrives in %o4 */
pic_base:
call boot_continue
mov %o4, CIF_REG
. = _start + GRUB_BOOT_MACHINE_VER_MAJ
boot_version: .byte GRUB_BOOT_VERSION_MAJOR, GRUB_BOOT_VERSION_MINOR
/* The offsets to these locations are defined by the
* GRUB_BOOT_MACHINE_foo macros in include/grub/sparc/ieee1275/boot.h,
* and grub-setup uses this to patch these next three values as needed.
*
* The boot_path will be the OF device path of the partition where the
* rest of the GRUB kernel image resides. kernel_sector will be set to
* the location of the first block of the GRUB kernel, and
* kernel_address is the location where we should load that first block.
*
* After loading in that block we will execute it by jumping to the
* load address plus the size of the prepended A.OUT header (32 bytes).
*/
boot_path:
. = _start + GRUB_BOOT_MACHINE_KERNEL_SECTOR
kernel_sector: .xword 2
kernel_address: .word GRUB_BOOT_MACHINE_KERNEL_ADDR
prom_finddev_name: .asciz "finddevice"
prom_chosen_path: .asciz "/chosen"
prom_getprop_name: .asciz "getprop"
prom_stdout_name: .asciz "stdout"
prom_write_name: .asciz "write"
prom_bootpath_name: .asciz "bootpath"
prom_open_name: .asciz "open"
prom_seek_name: .asciz "seek"
prom_read_name: .asciz "read"
prom_exit_name: .asciz "exit"
grub_name: .asciz "GRUB "
#define GRUB_NAME_LEN 5
.align 4
prom_open_error:
GET_ABS(prom_open_name, %o2)
call console_write
mov 4, %o3
/* fallthru */
prom_error:
GET_ABS(prom_exit_name, %o0)
/* fallthru */
/* %o0: OF call name
* %o1: input arg 1
*/
prom_call_1_1:
mov 1, %g1
ba prom_call
mov 1, %o5
/* %o2: message string
* %o3: message length
*/
console_write:
GET_ABS(prom_write_name, %o0)
mov STDOUT_NODE_REG, %o1
/* fallthru */
/* %o0: OF call name
* %o1: input arg 1
* %o2: input arg 2
* %o3: input arg 3
*/
prom_call_3_1:
mov 3, %g1
mov 1, %o5
/* fallthru */
/* %o0: OF call name
* %g1: num inputs
* %o5: num outputs
* %o1-%o4: inputs
*/
prom_call:
stx %o0, [%l1 + 0x00]
stx %g1, [%l1 + 0x08]
stx %o5, [%l1 + 0x10]
stx %o1, [%l1 + 0x18]
stx %o2, [%l1 + 0x20]
stx %o3, [%l1 + 0x28]
stx %o4, [%l1 + 0x30]
jmpl CIF_REG, %g0
mov %l1, %o0
boot_continue:
mov %o7, PIC_REG /* PIC base */
sethi %hi(SCRATCH_PAD), %l1 /* OF argument slots */
/* Find the /chosen node so we can fetch the stdout handle,
* and thus perform console output.
*
* chosen_node = prom_finddevice("/chosen")
*/
GET_ABS(prom_finddev_name, %o0)
GET_ABS(prom_chosen_path, %o1)
call prom_call_1_1
clr %o2
ldx [%l1 + 0x20], CHOSEN_NODE_REG
brz CHOSEN_NODE_REG, prom_error
/* getprop(chosen_node, "stdout", &buffer, buffer_size) */
GET_ABS(prom_getprop_name, %o0)
mov 4, %g1
mov 1, %o5
mov CHOSEN_NODE_REG, %o1
GET_ABS(prom_stdout_name, %o2)
add %l1, 256, %o3
mov 1024, %o4
call prom_call
stx %g1, [%l1 + 256]
lduw [%l1 + 256], STDOUT_NODE_REG
brz,pn STDOUT_NODE_REG, prom_error
/* write(stdout_node, "GRUB ", strlen("GRUB ")) */
GET_ABS(grub_name, %o2)
call console_write
mov GRUB_NAME_LEN, %o3
/* Open up the boot_path, and use that handle to read the
* first block of the GRUB kernel image.
*
* bootdev_handle = open(boot_path)
*/
GET_ABS(prom_open_name, %o0)
GET_ABS(boot_path, %o1)
call prom_call_1_1
clr %o2
ldx [%l1 + 0x20], BOOTDEV_REG
brz,pn BOOTDEV_REG, prom_open_error
/* Since we have 64-bit cells, the high cell of the seek offset
* is zero and the low cell is the entire value.
*
* seek(bootdev, 0, *kernel_sector << 9)
*/
GET_ABS(prom_seek_name, %o0)
mov BOOTDEV_REG, %o1
clr %o2
LDX_ABS(kernel_sector, 0x00, %o3)
call prom_call_3_1
sllx %o3, 9, %o3
/* read(bootdev, *kernel_address, 512) */
GET_ABS(prom_read_name, %o0)
mov BOOTDEV_REG, %o1
LDUW_ABS(kernel_address, 0x00, %o2)
call prom_call_3_1
mov 512, %o3
LDUW_ABS(kernel_address, 0x00, %o2)
jmpl %o2, %o7
nop
1: ba,a 1b
. = _start + GRUB_BOOT_MACHINE_CODE_END
/* the last 4 bytes in the sector 0 contain the signature */
.word GRUB_BOOT_MACHINE_SIGNATURE

View File

@ -0,0 +1,145 @@
/* -*-Asm-*- */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 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/boot.h>
#include <grub/machine/boot.h>
.text
.align 4
.globl _start
_start:
/* First stage boot block jumps to us here. */
pic_base:
call after_info_block
mov %o7, PIC_REG
prom_write_name: .asciz "write"
prom_seek_name: .asciz "seek"
prom_read_name: .asciz "read"
prom_close_name: .asciz "close"
notification_string: .asciz "Loading kernel"
#define NOTIFICATION_STRING_LEN 14
notification_step: .asciz "."
#define NOTIFICATION_STEP_LEN 1
notification_done: .asciz "\r\n"
#define NOTIFICATION_DONE_LEN 2
.align 4
/* %o2: message string
* %o3: message length
*/
console_write:
GET_ABS(prom_write_name, %o0)
mov STDOUT_NODE_REG, %o1
/* fallthru */
/* %o0: OF call name
* %o1: input arg 1
* %o2: input arg 2
* %o3: input arg 3
*/
prom_call_3_1:
mov 3, %g1
mov 1, %o5
/* fallthru */
/* %o0: OF call name
* %g1: num inputs
* %o5: num outputs
* %o1-%o4: inputs
*/
prom_call:
stx %o0, [%l1 + 0x00]
stx %g1, [%l1 + 0x08]
stx %o5, [%l1 + 0x10]
stx %o1, [%l1 + 0x18]
stx %o2, [%l1 + 0x20]
stx %o3, [%l1 + 0x28]
stx %o4, [%l1 + 0x30]
jmpl CIF_REG, %g0
mov %l1, %o0
after_info_block:
sethi %hi(SCRATCH_PAD), %l1 /* OF argument slots */
GET_ABS(notification_string, %o2)
call console_write
mov NOTIFICATION_STRING_LEN, %o3
GET_ABS(firstlist - GRUB_BOOT_MACHINE_LIST_SIZE, %l2)
set GRUB_BOOT_MACHINE_IMAGE_ADDRESS, %l3
bootloop:
lduw [%l2 + 0x08], %o0
brz %o0, bootit
lduw [%l2 + 0x00], %o3
sllx %o3, 32, %o3
lduw [%l2 + 0x04], %o4
or %o3, %o4, %o3
GET_ABS(prom_seek_name, %o0)
mov BOOTDEV_REG, %o1
clr %o2
call prom_call_3_1
sllx %o3, 9, %o3
GET_ABS(prom_read_name, %o0)
mov BOOTDEV_REG, %o1
lduw [%l2 + 0x08], %o3
sllx %o3, 9, %o3
mov %l3, %o2
call prom_call_3_1
add %l3, %o3, %l3
GET_ABS(notification_step, %o2)
call console_write
mov NOTIFICATION_STEP_LEN, %o3
ba bootloop
sub %l2, GRUB_BOOT_MACHINE_LIST_SIZE, %l2
bootit:
GET_ABS(prom_close_name, %o0)
mov 1, %g1
mov 0, %o5
call prom_call
mov BOOTDEV_REG, %o1
GET_ABS(notification_done, %o2)
call console_write
mov NOTIFICATION_DONE_LEN, %o3
sethi %hi(GRUB_BOOT_MACHINE_IMAGE_ADDRESS), %o2
jmpl %o2 + %lo(GRUB_BOOT_MACHINE_IMAGE_ADDRESS), %o7
mov CIF_REG, %o0
1: ba,a 1b
lastlist:
.word 0
.word 0
. = _start + (0x200 - GRUB_BOOT_MACHINE_LIST_SIZE)
blocklist_default_start:
.word 0
.word 2
blocklist_default_len:
.word 0
firstlist:

65
bus/pci.c Normal file
View File

@ -0,0 +1,65 @@
/* pci.c - Generic PCI interfaces. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2007,2009 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/dl.h>
#include <grub/pci.h>
grub_pci_address_t
grub_pci_make_address (grub_pci_device_t dev, int reg)
{
return (1 << 31) | (dev.bus << 16) | (dev.device << 11)
| (dev.function << 8) | (reg << 2);
}
void
grub_pci_iterate (grub_pci_iteratefunc_t hook)
{
grub_pci_device_t dev;
grub_pci_address_t addr;
grub_pci_id_t id;
grub_uint32_t hdr;
for (dev.bus = 0; dev.bus < 256; dev.bus++)
{
for (dev.device = 0; dev.device < 32; dev.device++)
{
for (dev.function = 0; dev.function < 8; dev.function++)
{
addr = grub_pci_make_address (dev, 0);
id = grub_pci_read (addr);
/* Check if there is a device present. */
if (id >> 16 == 0xFFFF)
continue;
if (hook (dev, id))
return;
/* Probe only func = 0 if the device if not multifunction */
if (dev.function == 0)
{
addr = grub_pci_make_address (dev, 3);
hdr = grub_pci_read (addr);
if (!(hdr & 0x800000))
break;
}
}
}
}
}

611
bus/usb/ohci.c Normal file
View File

@ -0,0 +1,611 @@
/* ohci.c - OHCI Support. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008 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/dl.h>
#include <grub/mm.h>
#include <grub/usb.h>
#include <grub/usbtrans.h>
#include <grub/misc.h>
#include <grub/pci.h>
#include <grub/cpu/pci.h>
#include <grub/i386/io.h>
#include <grub/time.h>
struct grub_ohci_hcca
{
/* Pointers to Interrupt Endpoint Descriptors. Not used by
GRUB. */
grub_uint32_t inttable[32];
/* Current frame number. */
grub_uint16_t framenumber;
grub_uint16_t pad;
/* List of completed TDs. */
grub_uint32_t donehead;
grub_uint8_t reserved[116];
} __attribute__((packed));
/* OHCI Endpoint Descriptor. */
struct grub_ohci_ed
{
grub_uint32_t target;
grub_uint32_t td_tail;
grub_uint32_t td_head;
grub_uint32_t next_ed;
} __attribute__((packed));
struct grub_ohci_td
{
/* Information used to construct the TOKEN packet. */
grub_uint32_t token;
grub_uint32_t buffer;
grub_uint32_t next_td;
grub_uint32_t buffer_end;
} __attribute__((packed));
typedef struct grub_ohci_td *grub_ohci_td_t;
typedef struct grub_ohci_ed *grub_ohci_ed_t;
struct grub_ohci
{
volatile grub_uint32_t *iobase;
volatile struct grub_ohci_hcca *hcca;
struct grub_ohci *next;
};
static struct grub_ohci *ohci;
typedef enum
{
GRUB_OHCI_REG_REVISION = 0x00,
GRUB_OHCI_REG_CONTROL,
GRUB_OHCI_REG_CMDSTATUS,
GRUB_OHCI_REG_INTSTATUS,
GRUB_OHCI_REG_INTENA,
GRUB_OHCI_REG_INTDIS,
GRUB_OHCI_REG_HCCA,
GRUB_OHCI_REG_PERIODIC,
GRUB_OHCI_REG_CONTROLHEAD,
GRUB_OHCI_REG_CONTROLCURR,
GRUB_OHCI_REG_BULKHEAD,
GRUB_OHCI_REG_BULKCURR,
GRUB_OHCI_REG_DONEHEAD,
GRUB_OHCI_REG_FRAME_INTERVAL,
GRUB_OHCI_REG_RHUBA = 18,
GRUB_OHCI_REG_RHUBPORT = 21
} grub_ohci_reg_t;
static grub_uint32_t
grub_ohci_readreg32 (struct grub_ohci *o, grub_ohci_reg_t reg)
{
return grub_le_to_cpu32 (*(o->iobase + reg));
}
static void
grub_ohci_writereg32 (struct grub_ohci *o,
grub_ohci_reg_t reg, grub_uint32_t val)
{
*(o->iobase + reg) = grub_cpu_to_le32 (val);
}
/* Iterate over all PCI devices. Determine if a device is an OHCI
controller. If this is the case, initialize it. */
static int NESTED_FUNC_ATTR
grub_ohci_pci_iter (grub_pci_device_t dev,
grub_pci_id_t pciid __attribute__((unused)))
{
grub_uint32_t class_code;
grub_uint32_t class;
grub_uint32_t subclass;
grub_uint32_t interf;
grub_uint32_t base;
grub_pci_address_t addr;
struct grub_ohci *o;
grub_uint32_t revision;
grub_uint32_t frame_interval;
addr = grub_pci_make_address (dev, 2);
class_code = grub_pci_read (addr) >> 8;
interf = class_code & 0xFF;
subclass = (class_code >> 8) & 0xFF;
class = class_code >> 16;
/* If this is not an OHCI controller, just return. */
if (class != 0x0c || subclass != 0x03 || interf != 0x10)
return 0;
/* Determine IO base address. */
addr = grub_pci_make_address (dev, 4);
base = grub_pci_read (addr);
#if 0
/* Stop if there is no IO space base address defined. */
if (! (base & 1))
return 0;
#endif
/* Allocate memory for the controller and register it. */
o = grub_malloc (sizeof (*o));
if (! o)
return 1;
o->iobase = (grub_uint32_t *) base;
/* Reserve memory for the HCCA. */
o->hcca = (struct grub_ohci_hcca *) grub_memalign (256, 256);
grub_dprintf ("ohci", "class=0x%02x 0x%02x interface 0x%02x base=%p\n",
class, subclass, interf, o->iobase);
/* Check if the OHCI revision is actually 1.0 as supported. */
revision = grub_ohci_readreg32 (o, GRUB_OHCI_REG_REVISION);
grub_dprintf ("ohci", "OHCI revision=0x%02x\n", revision & 0xFF);
if ((revision & 0xFF) != 0x10)
goto fail;
/* Backup the frame interval register. */
frame_interval = grub_ohci_readreg32 (o, GRUB_OHCI_REG_FRAME_INTERVAL);
/* Suspend the OHCI by issuing a reset. */
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CMDSTATUS, 1); /* XXX: Magic. */
grub_millisleep (1);
grub_dprintf ("ohci", "OHCI reset\n");
/* Restore the frame interval register. */
grub_ohci_writereg32 (o, GRUB_OHCI_REG_FRAME_INTERVAL, frame_interval);
/* Setup the HCCA. */
grub_ohci_writereg32 (o, GRUB_OHCI_REG_HCCA, (grub_uint32_t) o->hcca);
grub_dprintf ("ohci", "OHCI HCCA\n");
/* Enable the OHCI. */
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CONTROL,
(2 << 6));
grub_dprintf ("ohci", "OHCI enable: 0x%02x\n",
(grub_ohci_readreg32 (o, GRUB_OHCI_REG_CONTROL) >> 6) & 3);
/* Link to ohci now that initialisation is successful. */
o->next = ohci;
ohci = o;
return 0;
fail:
if (o)
grub_free ((void *) o->hcca);
grub_free (o);
return 1;
}
static void
grub_ohci_inithw (void)
{
grub_pci_iterate (grub_ohci_pci_iter);
}
static int
grub_ohci_iterate (int (*hook) (grub_usb_controller_t dev))
{
struct grub_ohci *o;
struct grub_usb_controller dev;
for (o = ohci; o; o = o->next)
{
dev.data = o;
if (hook (&dev))
return 1;
}
return 0;
}
static void
grub_ohci_transaction (grub_ohci_td_t td,
grub_transfer_type_t type, unsigned int toggle,
grub_size_t size, char *data)
{
grub_uint32_t token;
grub_uint32_t buffer;
grub_uint32_t buffer_end;
grub_dprintf ("ohci", "OHCI transaction td=%p type=%d, toggle=%d, size=%d\n",
td, type, toggle, size);
switch (type)
{
case GRUB_USB_TRANSFER_TYPE_SETUP:
token = 0 << 19;
break;
case GRUB_USB_TRANSFER_TYPE_IN:
token = 2 << 19;
break;
case GRUB_USB_TRANSFER_TYPE_OUT:
token = 1 << 19;
break;
default:
token = 0;
break;
}
/* Generate no interrupts. */
token |= 7 << 21;
/* Set the token. */
token |= toggle << 24;
token |= 1 << 25;
buffer = (grub_uint32_t) data;
buffer_end = buffer + size - 1;
td->token = grub_cpu_to_le32 (token);
td->buffer = grub_cpu_to_le32 (buffer);
td->next_td = 0;
td->buffer_end = grub_cpu_to_le32 (buffer_end);
}
static grub_usb_err_t
grub_ohci_transfer (grub_usb_controller_t dev,
grub_usb_transfer_t transfer)
{
struct grub_ohci *o = (struct grub_ohci *) dev->data;
grub_ohci_ed_t ed;
grub_ohci_td_t td_list;
grub_uint32_t target;
grub_uint32_t td_tail;
grub_uint32_t td_head;
grub_uint32_t status;
grub_uint32_t control;
grub_usb_err_t err;
int i;
/* Allocate an Endpoint Descriptor. */
ed = grub_memalign (16, sizeof (*ed));
if (! ed)
return GRUB_USB_ERR_INTERNAL;
td_list = grub_memalign (16, sizeof (*td_list) * (transfer->transcnt + 1));
if (! td_list)
{
grub_free ((void *) ed);
return GRUB_USB_ERR_INTERNAL;
}
grub_dprintf ("ohci", "alloc=%p\n", td_list);
/* Setup all Transfer Descriptors. */
for (i = 0; i < transfer->transcnt; i++)
{
grub_usb_transaction_t tr = &transfer->transactions[i];
grub_ohci_transaction (&td_list[i], tr->pid, tr->toggle,
tr->size, tr->data);
td_list[i].next_td = grub_cpu_to_le32 (&td_list[i + 1]);
}
/* Setup the Endpoint Descriptor. */
/* Set the device address. */
target = transfer->devaddr;
/* Set the endpoint. */
target |= transfer->endpoint << 7;
/* Set the device speed. */
target |= (transfer->dev->speed == GRUB_USB_SPEED_LOW) << 13;
/* Set the maximum packet size. */
target |= transfer->max << 16;
td_head = (grub_uint32_t) td_list;
td_tail = (grub_uint32_t) &td_list[transfer->transcnt];
ed->target = grub_cpu_to_le32 (target);
ed->td_head = grub_cpu_to_le32 (td_head);
ed->td_tail = grub_cpu_to_le32 (td_tail);
ed->next_ed = grub_cpu_to_le32 (0);
grub_dprintf ("ohci", "program OHCI\n");
/* Program the OHCI to actually transfer. */
switch (transfer->type)
{
case GRUB_USB_TRANSACTION_TYPE_BULK:
{
grub_dprintf ("ohci", "add to bulk list\n");
status = grub_ohci_readreg32 (o, GRUB_OHCI_REG_CMDSTATUS);
control = grub_ohci_readreg32 (o, GRUB_OHCI_REG_CONTROL);
/* Disable the Control and Bulk lists. */
control &= ~(3 << 4);
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CONTROL, control);
/* Clear BulkListFilled. */
status &= ~(1 << 2);
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CMDSTATUS, status);
grub_ohci_writereg32 (o, GRUB_OHCI_REG_BULKHEAD, (grub_uint32_t) ed);
/* Enable the Bulk list. */
control |= 1 << 5;
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CONTROL, control);
/* Set BulkListFilled. */
status |= 1 << 2;
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CMDSTATUS, status);
break;
}
case GRUB_USB_TRANSACTION_TYPE_CONTROL:
{
grub_dprintf ("ohci", "add to control list\n");
status = grub_ohci_readreg32 (o, GRUB_OHCI_REG_CMDSTATUS);
control = grub_ohci_readreg32 (o, GRUB_OHCI_REG_CONTROL);
/* Disable the Control and Bulk lists. */
control &= ~(3 << 4);
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CONTROL, control);
/* Clear ControlListFilled. */
status &= ~(1 << 1);
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CMDSTATUS, status);
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CONTROLHEAD,
(grub_uint32_t) ed);
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CONTROLHEAD+1,
(grub_uint32_t) ed);
/* Enable the Control list. */
control |= 1 << 4;
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CONTROL, control);
/* Set ControlListFilled. */
status |= 1 << 1;
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CMDSTATUS, status);
break;
}
}
grub_dprintf ("ohci", "wait for completion\n");
grub_dprintf ("ohci", "control=0x%02x status=0x%02x\n",
grub_ohci_readreg32 (o, GRUB_OHCI_REG_CONTROL),
grub_ohci_readreg32 (o, GRUB_OHCI_REG_CMDSTATUS));
/* Wait until the transfer is completed or STALLs. */
while ((ed->td_head & ~0xf) != (ed->td_tail & ~0xf))
{
grub_cpu_idle ();
grub_dprintf ("ohci", "head=0x%02x tail=0x%02x\n", ed->td_head, ed->td_tail);
/* Detected a STALL. */
if (ed->td_head & 1)
break;
}
grub_dprintf ("ohci", "complete\n");
/* if (ed->td_head & 1) */
/* err = GRUB_USB_ERR_STALL; */
/* else if (ed->td */
if (ed->td_head & 1)
{
grub_uint8_t errcode;
grub_ohci_td_t tderr;
tderr = (grub_ohci_td_t) grub_ohci_readreg32 (o,
GRUB_OHCI_REG_DONEHEAD);
errcode = tderr->token >> 28;
switch (errcode)
{
case 0:
/* XXX: Should not happen! */
grub_error (GRUB_ERR_IO, "OHCI without reporting the reason");
err = GRUB_USB_ERR_INTERNAL;
break;
case 1:
/* XXX: CRC error. */
err = GRUB_USB_ERR_TIMEOUT;
break;
case 2:
err = GRUB_USB_ERR_BITSTUFF;
break;
case 3:
/* XXX: Data Toggle error. */
err = GRUB_USB_ERR_DATA;
break;
case 4:
err = GRUB_USB_ERR_STALL;
break;
case 5:
/* XXX: Not responding. */
err = GRUB_USB_ERR_TIMEOUT;
break;
case 6:
/* XXX: PID Check bits failed. */
err = GRUB_USB_ERR_BABBLE;
break;
case 7:
/* XXX: PID unexpected failed. */
err = GRUB_USB_ERR_BABBLE;
break;
case 8:
/* XXX: Data overrun error. */
err = GRUB_USB_ERR_DATA;
break;
case 9:
/* XXX: Data underrun error. */
err = GRUB_USB_ERR_DATA;
break;
case 10:
/* XXX: Reserved. */
err = GRUB_USB_ERR_NAK;
break;
case 11:
/* XXX: Reserved. */
err = GRUB_USB_ERR_NAK;
break;
case 12:
/* XXX: Buffer overrun. */
err = GRUB_USB_ERR_DATA;
break;
case 13:
/* XXX: Buffer underrun. */
err = GRUB_USB_ERR_DATA;
break;
default:
err = GRUB_USB_ERR_NAK;
break;
}
}
else
err = GRUB_USB_ERR_NONE;
/* Disable the Control and Bulk lists. */
control = grub_ohci_readreg32 (o, GRUB_OHCI_REG_CONTROL);
control &= ~(3 << 4);
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CONTROL, control);
/* Clear BulkListFilled and ControlListFilled. */
status = grub_ohci_readreg32 (o, GRUB_OHCI_REG_CMDSTATUS);
status &= ~((1 << 2) | (1 << 3));
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CMDSTATUS, status);
/* XXX */
grub_free (td_list);
grub_free (ed);
return err;
}
static grub_err_t
grub_ohci_portstatus (grub_usb_controller_t dev,
unsigned int port, unsigned int enable)
{
struct grub_ohci *o = (struct grub_ohci *) dev->data;
grub_uint32_t status;
/* Reset the port. */
status = grub_ohci_readreg32 (o, GRUB_OHCI_REG_RHUBPORT + port);
status |= (1 << 4); /* XXX: Magic. */
grub_ohci_writereg32 (o, GRUB_OHCI_REG_RHUBPORT + port, status);
grub_millisleep (100);
/* End the reset signaling. */
status = grub_ohci_readreg32 (o, GRUB_OHCI_REG_RHUBPORT + port);
status |= (1 << 20); /* XXX: Magic. */
grub_ohci_writereg32 (o, GRUB_OHCI_REG_RHUBPORT + port, status);
grub_millisleep (10);
/* Enable the port. */
status = grub_ohci_readreg32 (o, GRUB_OHCI_REG_RHUBPORT + port);
status |= (enable << 1); /* XXX: Magic. */
grub_ohci_writereg32 (o, GRUB_OHCI_REG_RHUBPORT + port, status);
status = grub_ohci_readreg32 (o, GRUB_OHCI_REG_RHUBPORT + port);
grub_dprintf ("ohci", "portstatus=0x%02x\n", status);
return GRUB_ERR_NONE;
}
static grub_usb_speed_t
grub_ohci_detect_dev (grub_usb_controller_t dev, int port)
{
struct grub_ohci *o = (struct grub_ohci *) dev->data;
grub_uint32_t status;
status = grub_ohci_readreg32 (o, GRUB_OHCI_REG_RHUBPORT + port);
grub_dprintf ("ohci", "detect_dev status=0x%02x\n", status);
if (! (status & 1))
return GRUB_USB_SPEED_NONE;
else if (status & (1 << 9))
return GRUB_USB_SPEED_LOW;
else
return GRUB_USB_SPEED_FULL;
}
static int
grub_ohci_hubports (grub_usb_controller_t dev)
{
struct grub_ohci *o = (struct grub_ohci *) dev->data;
grub_uint32_t portinfo;
portinfo = grub_ohci_readreg32 (o, GRUB_OHCI_REG_RHUBA);
grub_dprintf ("ohci", "root hub ports=%d\n", portinfo & 0xFF);
/* The root hub has exactly two ports. */
return portinfo & 0xFF;
}
static struct grub_usb_controller_dev usb_controller =
{
.name = "ohci",
.iterate = grub_ohci_iterate,
.transfer = grub_ohci_transfer,
.hubports = grub_ohci_hubports,
.portstatus = grub_ohci_portstatus,
.detect_dev = grub_ohci_detect_dev
};
GRUB_MOD_INIT(ohci)
{
grub_ohci_inithw ();
grub_usb_controller_dev_register (&usb_controller);
}
GRUB_MOD_FINI(ohci)
{
grub_usb_controller_dev_unregister (&usb_controller);
}

689
bus/usb/uhci.c Normal file
View File

@ -0,0 +1,689 @@
/* uhci.c - UHCI Support. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008 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/dl.h>
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/usb.h>
#include <grub/usbtrans.h>
#include <grub/pci.h>
#include <grub/i386/io.h>
#include <grub/time.h>
#define GRUB_UHCI_IOMASK (0x7FF << 5)
typedef enum
{
GRUB_UHCI_REG_USBCMD = 0x00,
GRUB_UHCI_REG_FLBASEADD = 0x08,
GRUB_UHCI_REG_PORTSC1 = 0x10,
GRUB_UHCI_REG_PORTSC2 = 0x12
} grub_uhci_reg_t;
#define GRUB_UHCI_LINK_TERMINATE 1
#define GRUB_UHCI_LINK_QUEUE_HEAD 2
/* UHCI Queue Head. */
struct grub_uhci_qh
{
/* Queue head link pointer which points to the next queue head. */
grub_uint32_t linkptr;
/* Queue element link pointer which points to the first data object
within the queue. */
grub_uint32_t elinkptr;
/* Queue heads are aligned on 16 bytes, pad so a queue head is 16
bytes so we can store many in a 4K page. */
grub_uint8_t pad[8];
} __attribute__ ((packed));
/* UHCI Transfer Descriptor. */
struct grub_uhci_td
{
/* Pointer to the next TD in the list. */
grub_uint32_t linkptr;
/* Control and status bits. */
grub_uint32_t ctrl_status;
/* All information required to transfer the Token packet. */
grub_uint32_t token;
/* A pointer to the data buffer, UHCI requires this pointer to be 32
bits. */
grub_uint32_t buffer;
/* Another linkptr that is not overwritten by the Host Controller.
This is GRUB specific. */
grub_uint32_t linkptr2;
/* 3 additional 32 bits words reserved for the Host Controller Driver. */
grub_uint32_t data[3];
} __attribute__ ((packed));
typedef volatile struct grub_uhci_td *grub_uhci_td_t;
typedef volatile struct grub_uhci_qh *grub_uhci_qh_t;
struct grub_uhci
{
int iobase;
grub_uint32_t *framelist;
/* 256 Queue Heads. */
grub_uhci_qh_t qh;
/* 256 Transfer Descriptors. */
grub_uhci_td_t td;
/* Free Transfer Descriptors. */
grub_uhci_td_t tdfree;
struct grub_uhci *next;
};
static struct grub_uhci *uhci;
static grub_uint16_t
grub_uhci_readreg16 (struct grub_uhci *u, grub_uhci_reg_t reg)
{
return grub_inw (u->iobase + reg);
}
#if 0
static grub_uint32_t
grub_uhci_readreg32 (struct grub_uhci *u, grub_uhci_reg_t reg)
{
return grub_inl (u->iobase + reg);
}
#endif
static void
grub_uhci_writereg16 (struct grub_uhci *u,
grub_uhci_reg_t reg, grub_uint16_t val)
{
grub_outw (val, u->iobase + reg);
}
static void
grub_uhci_writereg32 (struct grub_uhci *u,
grub_uhci_reg_t reg, grub_uint32_t val)
{
grub_outl (val, u->iobase + reg);
}
static grub_err_t
grub_uhci_portstatus (grub_usb_controller_t dev,
unsigned int port, unsigned int enable);
/* Iterate over all PCI devices. Determine if a device is an UHCI
controller. If this is the case, initialize it. */
static int NESTED_FUNC_ATTR
grub_uhci_pci_iter (grub_pci_device_t dev,
grub_pci_id_t pciid __attribute__((unused)))
{
grub_uint32_t class_code;
grub_uint32_t class;
grub_uint32_t subclass;
grub_uint32_t interf;
grub_uint32_t base;
grub_uint32_t fp;
grub_pci_address_t addr;
struct grub_uhci *u;
int i;
addr = grub_pci_make_address (dev, 2);
class_code = grub_pci_read (addr) >> 8;
interf = class_code & 0xFF;
subclass = (class_code >> 8) & 0xFF;
class = class_code >> 16;
/* If this is not an UHCI controller, just return. */
if (class != 0x0c || subclass != 0x03 || interf != 0x00)
return 0;
/* Determine IO base address. */
addr = grub_pci_make_address (dev, 8);
base = grub_pci_read (addr);
/* Stop if there is no IO space base address defined. */
if (! (base & 1))
return 0;
/* Allocate memory for the controller and register it. */
u = grub_zalloc (sizeof (*u));
if (! u)
return 1;
u->iobase = base & GRUB_UHCI_IOMASK;
grub_dprintf ("uhci", "class=0x%02x 0x%02x interface 0x%02x base=0x%x\n",
class, subclass, interf, u->iobase);
/* Reserve a page for the frame list. */
u->framelist = grub_memalign (4096, 4096);
if (! u->framelist)
goto fail;
/* The framelist pointer of UHCI is only 32 bits, make sure this
code works on on 64 bits architectures. */
#if GRUB_CPU_SIZEOF_VOID_P == 8
if ((grub_uint64_t) u->framelist >> 32)
{
grub_error (GRUB_ERR_OUT_OF_MEMORY,
"allocated frame list memory not <4GB");
goto fail;
}
#endif
/* The QH pointer of UHCI is only 32 bits, make sure this
code works on on 64 bits architectures. */
u->qh = (grub_uhci_qh_t) grub_memalign (4096, 4096);
if (! u->qh)
goto fail;
#if GRUB_CPU_SIZEOF_VOID_P == 8
if ((grub_uint64_t) u->qh >> 32)
{
grub_error (GRUB_ERR_OUT_OF_MEMORY, "allocated QH memory not <4GB");
goto fail;
}
#endif
/* The TD pointer of UHCI is only 32 bits, make sure this
code works on on 64 bits architectures. */
u->td = (grub_uhci_td_t) grub_memalign (4096, 4096*2);
if (! u->td)
goto fail;
#if GRUB_CPU_SIZEOF_VOID_P == 8
if ((grub_uint64_t) u->td >> 32)
{
grub_error (GRUB_ERR_OUT_OF_MEMORY, "allocated TD memory not <4GB");
goto fail;
}
#endif
/* Link all Transfer Descriptors in a list of available Transfer
Descriptors. */
for (i = 0; i < 256; i++)
u->td[i].linkptr = (grub_uint32_t) &u->td[i + 1];
u->td[255 - 1].linkptr = 0;
u->tdfree = u->td;
/* Make sure UHCI is disabled! */
grub_uhci_writereg16 (u, GRUB_UHCI_REG_USBCMD, 0);
/* Setup the frame list pointers. Since no isochronous transfers
are and will be supported, they all point to the (same!) queue
head. */
fp = (grub_uint32_t) u->qh & (~15);
/* Mark this as a queue head. */
fp |= 2;
for (i = 0; i < 1024; i++)
u->framelist[i] = fp;
/* Program the framelist address into the UHCI controller. */
grub_uhci_writereg32 (u, GRUB_UHCI_REG_FLBASEADD,
(grub_uint32_t) u->framelist);
/* Make the Queue Heads point to each other. */
for (i = 0; i < 256; i++)
{
/* Point to the next QH. */
u->qh[i].linkptr = (grub_uint32_t) (&u->qh[i + 1]) & (~15);
/* This is a QH. */
u->qh[i].linkptr |= GRUB_UHCI_LINK_QUEUE_HEAD;
/* For the moment, do not point to a Transfer Descriptor. These
are set at transfer time, so just terminate it. */
u->qh[i].elinkptr = 1;
}
/* The last Queue Head should terminate. 256 are too many QHs so
just use 50. */
u->qh[50 - 1].linkptr = 1;
/* Enable UHCI again. */
grub_uhci_writereg16 (u, GRUB_UHCI_REG_USBCMD, 1 | (1 << 7));
/* UHCI is initialized and ready for transfers. */
grub_dprintf ("uhci", "UHCI initialized\n");
#if 0
{
int i;
for (i = 0; i < 10; i++)
{
grub_uint16_t frnum;
frnum = grub_uhci_readreg16 (u, 6);
grub_dprintf ("uhci", "Framenum=%d\n", frnum);
grub_millisleep (100);
}
}
#endif
/* Link to uhci now that initialisation is successful. */
u->next = uhci;
uhci = u;
return 0;
fail:
if (u)
{
grub_free ((void *) u->qh);
grub_free (u->framelist);
}
grub_free (u);
return 1;
}
static void
grub_uhci_inithw (void)
{
grub_pci_iterate (grub_uhci_pci_iter);
}
static grub_uhci_td_t
grub_alloc_td (struct grub_uhci *u)
{
grub_uhci_td_t ret;
/* Check if there is a Transfer Descriptor available. */
if (! u->tdfree)
return NULL;
ret = u->tdfree;
u->tdfree = (grub_uhci_td_t) u->tdfree->linkptr;
return ret;
}
static void
grub_free_td (struct grub_uhci *u, grub_uhci_td_t td)
{
td->linkptr = (grub_uint32_t) u->tdfree;
u->tdfree = td;
}
static void
grub_free_queue (struct grub_uhci *u, grub_uhci_td_t td)
{
/* Free the TDs in this queue. */
while (td)
{
grub_uhci_td_t tdprev;
/* Unlink the queue. */
tdprev = td;
td = (grub_uhci_td_t) td->linkptr2;
/* Free the TD. */
grub_free_td (u, tdprev);
}
}
static grub_uhci_qh_t
grub_alloc_qh (struct grub_uhci *u,
grub_transaction_type_t tr __attribute__((unused)))
{
int i;
grub_uhci_qh_t qh;
/* Look for a Queue Head for this transfer. Skip the first QH if
this is a Interrupt Transfer. */
#if 0
if (tr == GRUB_USB_TRANSACTION_TYPE_INTERRUPT)
i = 0;
else
#endif
i = 1;
for (; i < 255; i++)
{
if (u->qh[i].elinkptr & 1)
break;
}
qh = &u->qh[i];
if (! (qh->elinkptr & 1))
{
grub_error (GRUB_ERR_OUT_OF_MEMORY,
"no free queue heads available");
return NULL;
}
return qh;
}
static grub_uhci_td_t
grub_uhci_transaction (struct grub_uhci *u, unsigned int endp,
grub_transfer_type_t type, unsigned int addr,
unsigned int toggle, grub_size_t size,
char *data)
{
grub_uhci_td_t td;
static const unsigned int tf[] = { 0x69, 0xE1, 0x2D };
/* XXX: Check if data is <4GB. If it isn't, just copy stuff around.
This is only relevant for 64 bits architectures. */
/* Grab a free Transfer Descriptor and initialize it. */
td = grub_alloc_td (u);
if (! td)
{
grub_error (GRUB_ERR_OUT_OF_MEMORY,
"no transfer descriptors available for UHCI transfer");
return 0;
}
grub_dprintf ("uhci",
"transaction: endp=%d, type=%d, addr=%d, toggle=%d, size=%d data=%p td=%p\n",
endp, type, addr, toggle, size, data, td);
/* Don't point to any TD, just terminate. */
td->linkptr = 1;
/* Active! Only retry a transfer 3 times. */
td->ctrl_status = (1 << 23) | (3 << 27);
/* If zero bytes are transmitted, size is 0x7FF. Otherwise size is
size-1. */
if (size == 0)
size = 0x7FF;
else
size = size - 1;
/* Setup whatever is required for the token packet. */
td->token = ((size << 21) | (toggle << 19) | (endp << 15)
| (addr << 8) | tf[type]);
td->buffer = (grub_uint32_t) data;
return td;
}
static grub_usb_err_t
grub_uhci_transfer (grub_usb_controller_t dev,
grub_usb_transfer_t transfer)
{
struct grub_uhci *u = (struct grub_uhci *) dev->data;
grub_uhci_qh_t qh;
grub_uhci_td_t td;
grub_uhci_td_t td_first = NULL;
grub_uhci_td_t td_prev = NULL;
grub_usb_err_t err = GRUB_USB_ERR_NONE;
int i;
grub_uint64_t endtime;
/* Allocate a queue head for the transfer queue. */
qh = grub_alloc_qh (u, GRUB_USB_TRANSACTION_TYPE_CONTROL);
if (! qh)
return grub_errno;
for (i = 0; i < transfer->transcnt; i++)
{
grub_usb_transaction_t tr = &transfer->transactions[i];
td = grub_uhci_transaction (u, transfer->endpoint, tr->pid,
transfer->devaddr, tr->toggle,
tr->size, tr->data);
if (! td)
{
/* Terminate and free. */
td_prev->linkptr2 = 0;
td_prev->linkptr = 1;
if (td_first)
grub_free_queue (u, td_first);
return GRUB_USB_ERR_INTERNAL;
}
if (! td_first)
td_first = td;
else
{
td_prev->linkptr2 = (grub_uint32_t) td;
td_prev->linkptr = (grub_uint32_t) td;
td_prev->linkptr |= 4;
}
td_prev = td;
}
td_prev->linkptr2 = 0;
td_prev->linkptr = 1;
grub_dprintf ("uhci", "setup transaction %d\n", transfer->type);
/* Link it into the queue and terminate. Now the transaction can
take place. */
qh->elinkptr = (grub_uint32_t) td_first;
grub_dprintf ("uhci", "initiate transaction\n");
/* Wait until either the transaction completed or an error
occurred. */
endtime = grub_get_time_ms () + 1000;
for (;;)
{
grub_uhci_td_t errtd;
errtd = (grub_uhci_td_t) (qh->elinkptr & ~0x0f);
grub_dprintf ("uhci", ">t status=0x%02x data=0x%02x td=%p\n",
errtd->ctrl_status, errtd->buffer & (~15), errtd);
/* Check if the transaction completed. */
if (qh->elinkptr & 1)
break;
grub_dprintf ("uhci", "t status=0x%02x\n", errtd->ctrl_status);
/* Check if the TD is not longer active. */
if (! (errtd->ctrl_status & (1 << 23)))
{
grub_dprintf ("uhci", ">>t status=0x%02x\n", errtd->ctrl_status);
/* Check if the endpoint is stalled. */
if (errtd->ctrl_status & (1 << 22))
err = GRUB_USB_ERR_STALL;
/* Check if an error related to the data buffer occurred. */
if (errtd->ctrl_status & (1 << 21))
err = GRUB_USB_ERR_DATA;
/* Check if a babble error occurred. */
if (errtd->ctrl_status & (1 << 20))
err = GRUB_USB_ERR_BABBLE;
/* Check if a NAK occurred. */
if (errtd->ctrl_status & (1 << 19))
err = GRUB_USB_ERR_NAK;
/* Check if a timeout occurred. */
if (errtd->ctrl_status & (1 << 18))
err = GRUB_USB_ERR_TIMEOUT;
/* Check if a bitstuff error occurred. */
if (errtd->ctrl_status & (1 << 17))
err = GRUB_USB_ERR_BITSTUFF;
if (err)
goto fail;
/* Fall through, no errors occurred, so the QH might be
updated. */
grub_dprintf ("uhci", "transaction fallthrough\n");
}
if (grub_get_time_ms () > endtime)
{
err = GRUB_USB_ERR_STALL;
grub_dprintf ("uhci", "transaction timed out\n");
goto fail;
}
grub_cpu_idle ();
}
grub_dprintf ("uhci", "transaction complete\n");
fail:
grub_dprintf ("uhci", "transaction failed\n");
/* Place the QH back in the free list and deallocate the associated
TDs. */
qh->elinkptr = 1;
grub_free_queue (u, td_first);
return err;
}
static int
grub_uhci_iterate (int (*hook) (grub_usb_controller_t dev))
{
struct grub_uhci *u;
struct grub_usb_controller dev;
for (u = uhci; u; u = u->next)
{
dev.data = u;
if (hook (&dev))
return 1;
}
return 0;
}
static grub_err_t
grub_uhci_portstatus (grub_usb_controller_t dev,
unsigned int port, unsigned int enable)
{
struct grub_uhci *u = (struct grub_uhci *) dev->data;
int reg;
unsigned int status;
grub_uint64_t endtime;
grub_dprintf ("uhci", "enable=%d port=%d\n", enable, port);
if (port == 0)
reg = GRUB_UHCI_REG_PORTSC1;
else if (port == 1)
reg = GRUB_UHCI_REG_PORTSC2;
else
return grub_error (GRUB_ERR_OUT_OF_RANGE,
"UHCI Root Hub port does not exist");
status = grub_uhci_readreg16 (u, reg);
grub_dprintf ("uhci", "detect=0x%02x\n", status);
/* Reset the port. */
grub_uhci_writereg16 (u, reg, enable << 9);
/* Wait for the reset to complete. XXX: How long exactly? */
grub_millisleep (10);
status = grub_uhci_readreg16 (u, reg);
grub_uhci_writereg16 (u, reg, status & ~(1 << 9));
grub_dprintf ("uhci", "reset completed\n");
grub_millisleep (10);
/* Enable the port. */
grub_uhci_writereg16 (u, reg, enable << 2);
grub_millisleep (10);
grub_dprintf ("uhci", "waiting for the port to be enabled\n");
endtime = grub_get_time_ms () + 1000;
while (! (grub_uhci_readreg16 (u, reg) & (1 << 2)))
if (grub_get_time_ms () > endtime)
return grub_error (GRUB_ERR_IO, "UHCI Timed out");
status = grub_uhci_readreg16 (u, reg);
grub_dprintf ("uhci", ">3detect=0x%02x\n", status);
return GRUB_ERR_NONE;
}
static grub_usb_speed_t
grub_uhci_detect_dev (grub_usb_controller_t dev, int port)
{
struct grub_uhci *u = (struct grub_uhci *) dev->data;
int reg;
unsigned int status;
if (port == 0)
reg = GRUB_UHCI_REG_PORTSC1;
else if (port == 1)
reg = GRUB_UHCI_REG_PORTSC2;
else
return grub_error (GRUB_ERR_OUT_OF_RANGE,
"UHCI Root Hub port does not exist");
status = grub_uhci_readreg16 (u, reg);
grub_dprintf ("uhci", "detect=0x%02x port=%d\n", status, port);
if (! (status & 1))
return GRUB_USB_SPEED_NONE;
else if (status & (1 << 8))
return GRUB_USB_SPEED_LOW;
else
return GRUB_USB_SPEED_FULL;
}
static int
grub_uhci_hubports (grub_usb_controller_t dev __attribute__((unused)))
{
/* The root hub has exactly two ports. */
return 2;
}
static struct grub_usb_controller_dev usb_controller =
{
.name = "uhci",
.iterate = grub_uhci_iterate,
.transfer = grub_uhci_transfer,
.hubports = grub_uhci_hubports,
.portstatus = grub_uhci_portstatus,
.detect_dev = grub_uhci_detect_dev
};
GRUB_MOD_INIT(uhci)
{
grub_uhci_inithw ();
grub_usb_controller_dev_register (&usb_controller);
grub_dprintf ("uhci", "registered\n");
}
GRUB_MOD_FINI(uhci)
{
struct grub_uhci *u;
/* Disable all UHCI controllers. */
for (u = uhci; u; u = u->next)
grub_uhci_writereg16 (u, GRUB_UHCI_REG_USBCMD, 0);
/* Unregister the controller. */
grub_usb_controller_dev_unregister (&usb_controller);
}

227
bus/usb/usb.c Normal file
View File

@ -0,0 +1,227 @@
/* usb.c - Generic USB interfaces. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008 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/dl.h>
#include <grub/mm.h>
#include <grub/usb.h>
#include <grub/misc.h>
static grub_usb_controller_dev_t grub_usb_list;
void
grub_usb_controller_dev_register (grub_usb_controller_dev_t usb)
{
auto int iterate_hook (grub_usb_controller_t dev);
/* Iterate over all controllers found by the driver. */
int iterate_hook (grub_usb_controller_t dev)
{
dev->dev = usb;
/* Enable the ports of the USB Root Hub. */
grub_usb_root_hub (dev);
return 0;
}
usb->next = grub_usb_list;
grub_usb_list = usb;
if (usb->iterate)
usb->iterate (iterate_hook);
}
void
grub_usb_controller_dev_unregister (grub_usb_controller_dev_t usb)
{
grub_usb_controller_dev_t *p, q;
for (p = &grub_usb_list, q = *p; q; p = &(q->next), q = q->next)
if (q == usb)
{
*p = q->next;
break;
}
}
#if 0
int
grub_usb_controller_iterate (int (*hook) (grub_usb_controller_t dev))
{
grub_usb_controller_dev_t p;
auto int iterate_hook (grub_usb_controller_t dev);
int iterate_hook (grub_usb_controller_t dev)
{
dev->dev = p;
if (hook (dev))
return 1;
return 0;
}
/* Iterate over all controller drivers. */
for (p = grub_usb_list; p; p = p->next)
{
/* Iterate over the busses of the controllers. XXX: Actually, a
hub driver should do this. */
if (p->iterate (iterate_hook))
return 1;
}
return 0;
}
#endif
grub_usb_err_t
grub_usb_clear_halt (grub_usb_device_t dev, int endpoint)
{
dev->toggle[endpoint] = 0;
return grub_usb_control_msg (dev, (GRUB_USB_REQTYPE_OUT
| GRUB_USB_REQTYPE_STANDARD
| GRUB_USB_REQTYPE_TARGET_ENDP),
GRUB_USB_REQ_CLEAR_FEATURE,
GRUB_USB_FEATURE_ENDP_HALT,
endpoint, 0, 0);
}
grub_usb_err_t
grub_usb_set_configuration (grub_usb_device_t dev, int configuration)
{
int i;
for (i = 0; i < 16; i++)
dev->toggle[i] = 0;
return grub_usb_control_msg (dev, (GRUB_USB_REQTYPE_OUT
| GRUB_USB_REQTYPE_STANDARD
| GRUB_USB_REQTYPE_TARGET_DEV),
GRUB_USB_REQ_SET_CONFIGURATION, configuration,
0, 0, NULL);
}
grub_usb_err_t
grub_usb_get_descriptor (grub_usb_device_t dev,
grub_uint8_t type, grub_uint8_t index,
grub_size_t size, char *data)
{
return grub_usb_control_msg (dev, (GRUB_USB_REQTYPE_IN
| GRUB_USB_REQTYPE_STANDARD
| GRUB_USB_REQTYPE_TARGET_DEV),
GRUB_USB_REQ_GET_DESCRIPTOR,
(type << 8) | index,
0, size, data);
}
struct grub_usb_desc_endp *
grub_usb_get_endpdescriptor (grub_usb_device_t usbdev, int addr)
{
int i;
for (i = 0; i < usbdev->config[0].descconf->numif; i++)
{
struct grub_usb_desc_if *interf;
int j;
interf = usbdev->config[0].interf[i].descif;
for (j = 0; j < interf->endpointcnt; j++)
{
struct grub_usb_desc_endp *endp;
endp = &usbdev->config[0].interf[i].descendp[j];
if (endp->endp_addr == addr)
return endp;
}
}
return NULL;
}
grub_usb_err_t
grub_usb_device_initialize (grub_usb_device_t dev)
{
struct grub_usb_desc_device *descdev;
struct grub_usb_desc_config config;
grub_usb_err_t err;
int i;
err = grub_usb_get_descriptor (dev, GRUB_USB_DESCRIPTOR_DEVICE,
0, sizeof (struct grub_usb_desc_device),
(char *) &dev->descdev);
if (err)
return err;
descdev = &dev->descdev;
for (i = 0; i < 8; i++)
dev->config[i].descconf = NULL;
for (i = 0; i < descdev->configcnt; i++)
{
int pos;
int currif;
char *data;
/* First just read the first 4 bytes of the configuration
descriptor, after that it is known how many bytes really have
to be read. */
err = grub_usb_get_descriptor (dev, GRUB_USB_DESCRIPTOR_CONFIG, i, 4,
(char *) &config);
data = grub_malloc (config.totallen);
if (! data)
{
err = GRUB_USB_ERR_INTERNAL;
goto fail;
}
dev->config[i].descconf = (struct grub_usb_desc_config *) data;
err = grub_usb_get_descriptor (dev, GRUB_USB_DESCRIPTOR_CONFIG, i,
config.totallen, data);
if (err)
goto fail;
/* Skip the configuration descriptor. */
pos = sizeof (struct grub_usb_desc_config);
/* Read all interfaces. */
for (currif = 0; currif < dev->config[i].descconf->numif; currif++)
{
dev->config[i].interf[currif].descif
= (struct grub_usb_desc_if *) &data[pos];
pos += sizeof (struct grub_usb_desc_if);
/* Point to the first endpoint. */
dev->config[i].interf[currif].descendp
= (struct grub_usb_desc_endp *) &data[pos];
pos += (sizeof (struct grub_usb_desc_endp)
* dev->config[i].interf[currif].descif->endpointcnt);
}
}
return GRUB_USB_ERR_NONE;
fail:
for (i = 0; i < 8; i++)
grub_free (dev->config[i].descconf);
return err;
}

192
bus/usb/usbhub.c Normal file
View File

@ -0,0 +1,192 @@
/* usb.c - USB Hub Support. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008 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/dl.h>
#include <grub/mm.h>
#include <grub/usb.h>
#include <grub/misc.h>
/* USB Supports 127 devices, with device 0 as special case. */
static struct grub_usb_device *grub_usb_devs[128];
/* Add a device that currently has device number 0 and resides on
CONTROLLER, the Hub reported that the device speed is SPEED. */
static grub_usb_device_t
grub_usb_hub_add_dev (grub_usb_controller_t controller, grub_usb_speed_t speed)
{
grub_usb_device_t dev;
int i;
dev = grub_zalloc (sizeof (struct grub_usb_device));
if (! dev)
return NULL;
dev->controller = *controller;
dev->speed = speed;
grub_usb_device_initialize (dev);
/* Assign a new address to the device. */
for (i = 1; i < 128; i++)
{
if (! grub_usb_devs[i])
break;
}
if (i == 128)
{
grub_error (GRUB_ERR_IO, "can't assign address to USB device");
return NULL;
}
grub_usb_control_msg (dev,
(GRUB_USB_REQTYPE_OUT
| GRUB_USB_REQTYPE_STANDARD
| GRUB_USB_REQTYPE_TARGET_DEV),
GRUB_USB_REQ_SET_ADDRESS,
i, 0, 0, NULL);
dev->addr = i;
dev->initialized = 1;
grub_usb_devs[i] = dev;
return dev;
}
static grub_err_t
grub_usb_add_hub (grub_usb_device_t dev)
{
struct grub_usb_usb_hubdesc hubdesc;
grub_err_t err;
int i;
grub_usb_control_msg (dev, (GRUB_USB_REQTYPE_IN
| GRUB_USB_REQTYPE_CLASS
| GRUB_USB_REQTYPE_TARGET_DEV),
GRUB_USB_REQ_GET_DESCRIPTOR,
(GRUB_USB_DESCRIPTOR_HUB << 8) | 0,
0, sizeof (hubdesc), (char *) &hubdesc);
/* Iterate over the Hub ports. */
for (i = 1; i <= hubdesc.portcnt; i++)
{
grub_uint32_t status;
/* Get the port status. */
err = grub_usb_control_msg (dev, (GRUB_USB_REQTYPE_IN
| GRUB_USB_REQTYPE_CLASS
| GRUB_USB_REQTYPE_TARGET_OTHER),
GRUB_USB_REQ_HUB_GET_PORT_STATUS,
0, i, sizeof (status), (char *) &status);
/* Just ignore the device if the Hub does not report the
status. */
if (err)
continue;
/* If connected, reset and enable the port. */
if (status & GRUB_USB_HUB_STATUS_CONNECTED)
{
grub_usb_speed_t speed;
/* Determine the device speed. */
if (status & GRUB_USB_HUB_STATUS_LOWSPEED)
speed = GRUB_USB_SPEED_LOW;
else
{
if (status & GRUB_USB_HUB_STATUS_HIGHSPEED)
speed = GRUB_USB_SPEED_HIGH;
else
speed = GRUB_USB_SPEED_FULL;
}
/* A device is actually connected to this port, not enable
the port. XXX: Why 0x03? According to some docs it
should be 0x0. Check the specification! */
err = grub_usb_control_msg (dev, (GRUB_USB_REQTYPE_OUT
| GRUB_USB_REQTYPE_CLASS
| GRUB_USB_REQTYPE_TARGET_OTHER),
0x3, 0x4, i, 0, 0);
/* If the Hub does not cooperate for this port, just skip
the port. */
if (err)
continue;
/* Add the device and assign a device address to it. */
grub_usb_hub_add_dev (&dev->controller, speed);
}
}
return GRUB_ERR_NONE;
}
grub_usb_err_t
grub_usb_root_hub (grub_usb_controller_t controller)
{
grub_err_t err;
int ports;
int i;
/* Query the number of ports the root Hub has. */
ports = controller->dev->hubports (controller);
for (i = 0; i < ports; i++)
{
grub_usb_speed_t speed = controller->dev->detect_dev (controller, i);
if (speed != GRUB_USB_SPEED_NONE)
{
grub_usb_device_t dev;
/* Enable the port. */
err = controller->dev->portstatus (controller, i, 1);
if (err)
continue;
/* Enable the port and create a device. */
dev = grub_usb_hub_add_dev (controller, speed);
if (! dev)
continue;
/* If the device is a Hub, scan it for more devices. */
if (dev->descdev.class == 0x09)
grub_usb_add_hub (dev);
}
}
return GRUB_USB_ERR_NONE;
}
int
grub_usb_iterate (int (*hook) (grub_usb_device_t dev))
{
int i;
for (i = 0; i < 128; i++)
{
if (grub_usb_devs[i])
{
if (hook (grub_usb_devs[i]))
return 1;
}
}
return 0;
}

212
bus/usb/usbtrans.c Normal file
View File

@ -0,0 +1,212 @@
/* usbtrans.c - USB Transfers and Transactions. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008 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/dl.h>
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/usb.h>
#include <grub/usbtrans.h>
grub_usb_err_t
grub_usb_control_msg (grub_usb_device_t dev,
grub_uint8_t reqtype,
grub_uint8_t request,
grub_uint16_t value,
grub_uint16_t index,
grub_size_t size, char *data)
{
int i;
grub_usb_transfer_t transfer;
int datablocks;
struct grub_usb_packet_setup setupdata;
grub_usb_err_t err;
unsigned int max;
grub_dprintf ("usb",
"control: reqtype=0x%02x req=0x%02x val=0x%02x idx=0x%02x size=%d\n",
reqtype, request, value, index, size);
/* Create a transfer. */
transfer = grub_malloc (sizeof (struct grub_usb_transfer));
if (! transfer)
return grub_errno;
/* Determine the maximum packet size. */
if (dev->initialized)
max = dev->descdev.maxsize0;
else
max = 64;
datablocks = (size + max - 1) / max;
/* XXX: Discriminate between different types of control
messages. */
transfer->transcnt = datablocks + 2;
transfer->size = size; /* XXX ? */
transfer->endpoint = 0;
transfer->devaddr = dev->addr;
transfer->type = GRUB_USB_TRANSACTION_TYPE_CONTROL;
transfer->max = max;
transfer->dev = dev;
/* Allocate an array of transfer data structures. */
transfer->transactions = grub_malloc (transfer->transcnt
* sizeof (struct grub_usb_transfer));
if (! transfer->transactions)
{
grub_free (transfer);
return grub_errno;
}
/* Build a Setup packet. XXX: Endianness. */
setupdata.reqtype = reqtype;
setupdata.request = request;
setupdata.value = value;
setupdata.index = index;
setupdata.length = size;
transfer->transactions[0].size = sizeof (setupdata);
transfer->transactions[0].pid = GRUB_USB_TRANSFER_TYPE_SETUP;
transfer->transactions[0].data = (char *) &setupdata;
transfer->transactions[0].toggle = 0;
/* Now the data... XXX: Is this the right way to transfer control
transfers? */
for (i = 0; i < datablocks; i++)
{
grub_usb_transaction_t tr = &transfer->transactions[i + 1];
tr->size = (size > max) ? max : size;
/* Use the right most bit as the data toggle. Simple and
effective. */
tr->toggle = !(i & 1);
if (reqtype & 128)
tr->pid = GRUB_USB_TRANSFER_TYPE_IN;
else
tr->pid = GRUB_USB_TRANSFER_TYPE_OUT;
tr->data = &data[i * max];
size -= max;
}
/* End with an empty OUT transaction. */
transfer->transactions[datablocks + 1].size = 0;
transfer->transactions[datablocks + 1].data = NULL;
if (reqtype & 128)
transfer->transactions[datablocks + 1].pid = GRUB_USB_TRANSFER_TYPE_OUT;
else
transfer->transactions[datablocks + 1].pid = GRUB_USB_TRANSFER_TYPE_IN;
transfer->transactions[datablocks + 1].toggle = 1;
err = dev->controller.dev->transfer (&dev->controller, transfer);
grub_free (transfer->transactions);
grub_free (transfer);
return err;
}
static grub_usb_err_t
grub_usb_bulk_readwrite (grub_usb_device_t dev,
int endpoint, grub_size_t size, char *data,
grub_transfer_type_t type)
{
int i;
grub_usb_transfer_t transfer;
int datablocks;
unsigned int max;
grub_usb_err_t err;
int toggle = dev->toggle[endpoint];
/* Use the maximum packet size given in the endpoint descriptor. */
if (dev->initialized)
{
struct grub_usb_desc_endp *endpdesc;
endpdesc = grub_usb_get_endpdescriptor (dev, 0);
if (endpdesc)
max = endpdesc->maxpacket;
else
max = 64;
}
else
max = 64;
/* Create a transfer. */
transfer = grub_malloc (sizeof (struct grub_usb_transfer));
if (! transfer)
return grub_errno;
datablocks = ((size + max - 1) / max);
transfer->transcnt = datablocks;
transfer->size = size - 1;
transfer->endpoint = endpoint;
transfer->devaddr = dev->addr;
transfer->type = GRUB_USB_TRANSACTION_TYPE_BULK;
transfer->max = max;
transfer->dev = dev;
/* Allocate an array of transfer data structures. */
transfer->transactions = grub_malloc (transfer->transcnt
* sizeof (struct grub_usb_transfer));
if (! transfer->transactions)
{
grub_free (transfer);
return grub_errno;
}
/* Set up all transfers. */
for (i = 0; i < datablocks; i++)
{
grub_usb_transaction_t tr = &transfer->transactions[i];
tr->size = (size > max) ? max : size;
/* XXX: Use the right most bit as the data toggle. Simple and
effective. */
tr->toggle = toggle;
toggle = toggle ? 0 : 1;
tr->pid = type;
tr->data = &data[i * max];
size -= tr->size;
}
err = dev->controller.dev->transfer (&dev->controller, transfer);
grub_dprintf ("usb", "toggle=%d\n", toggle);
dev->toggle[endpoint] = toggle;
grub_free (transfer->transactions);
grub_free (transfer);
return err;
}
grub_usb_err_t
grub_usb_bulk_write (grub_usb_device_t dev,
int endpoint, grub_size_t size, char *data)
{
return grub_usb_bulk_readwrite (dev, endpoint, size, data,
GRUB_USB_TRANSFER_TYPE_OUT);
}
grub_usb_err_t
grub_usb_bulk_read (grub_usb_device_t dev,
int endpoint, grub_size_t size, char *data)
{
return grub_usb_bulk_readwrite (dev, endpoint, size, data,
GRUB_USB_TRANSFER_TYPE_IN);
}

774
commands/acpi.c Normal file
View File

@ -0,0 +1,774 @@
/* acpi.c - modify acpi tables. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 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/dl.h>
#include <grub/extcmd.h>
#include <grub/file.h>
#include <grub/disk.h>
#include <grub/term.h>
#include <grub/misc.h>
#include <grub/gzio.h>
#include <grub/acpi.h>
#include <grub/mm.h>
#include <grub/machine/memory.h>
#include <grub/memory.h>
#include <grub/i18n.h>
#ifdef GRUB_MACHINE_EFI
#include <grub/efi/efi.h>
#include <grub/efi/api.h>
#endif
static const struct grub_arg_option options[] = {
{"exclude", 'x', 0,
N_("Don't load host tables specified by comma-separated list."),
0, ARG_TYPE_STRING},
{"load-only", 'n', 0,
N_("Load only tables specified by comma-separated list."), 0, ARG_TYPE_STRING},
{"v1", '1', 0, N_("Expose v1 tables."), 0, ARG_TYPE_NONE},
{"v2", '2', 0, N_("Expose v2 and v3 tables."), 0, ARG_TYPE_NONE},
{"oemid", 'o', 0, N_("Set OEMID of RSDP, XSDT and RSDT."), 0, ARG_TYPE_STRING},
{"oemtable", 't', 0,
N_("Set OEMTABLE ID of RSDP, XSDT and RSDT."), 0, ARG_TYPE_STRING},
{"oemtablerev", 'r', 0,
N_("Set OEMTABLE revision of RSDP, XSDT and RSDT."), 0, ARG_TYPE_INT},
{"oemtablecreator", 'c', 0,
N_("Set creator field of RSDP, XSDT and RSDT."), 0, ARG_TYPE_STRING},
{"oemtablecreatorrev", 'd', 0,
N_("Set creator revision of RSDP, XSDT and RSDT."), 0, ARG_TYPE_INT},
{"no-ebda", 'e', 0, N_("Don't update EBDA. May fix failures or hangs on some."
" BIOSes but makes it ineffective with OS not receiving RSDP from GRUB."),
0, ARG_TYPE_NONE},
{0, 0, 0, 0, 0, 0}
};
/* Simple checksum by summing all bytes. Used by ACPI and SMBIOS. */
grub_uint8_t
grub_byte_checksum (void *base, grub_size_t size)
{
grub_uint8_t *ptr;
grub_uint8_t ret = 0;
for (ptr = (grub_uint8_t *) base; ptr < ((grub_uint8_t *) base) + size;
ptr++)
ret += *ptr;
return ret;
}
/* rev1 is 1 if ACPIv1 is to be generated, 0 otherwise.
rev2 contains the revision of ACPIv2+ to generate or 0 if none. */
static int rev1, rev2;
/* OEMID of RSDP, RSDT and XSDT. */
static char root_oemid[6];
/* OEMTABLE of the same tables. */
static char root_oemtable[8];
/* OEMREVISION of the same tables. */
static grub_uint32_t root_oemrev;
/* CreatorID of the same tables. */
static char root_creator_id[4];
/* CreatorRevision of the same tables. */
static grub_uint32_t root_creator_rev;
static struct grub_acpi_rsdp_v10 *rsdpv1_new = 0;
static struct grub_acpi_rsdp_v20 *rsdpv2_new = 0;
static char *playground = 0, *playground_ptr = 0;
static int playground_size = 0;
/* Linked list of ACPI tables. */
struct efiemu_acpi_table
{
void *addr;
grub_size_t size;
struct efiemu_acpi_table *next;
};
static struct efiemu_acpi_table *acpi_tables = 0;
/* DSDT isn't in RSDT. So treat it specially. */
static void *table_dsdt = 0;
/* Pointer to recreated RSDT. */
static void *rsdt_addr = 0;
/* Allocation handles for different tables. */
static grub_size_t dsdt_size = 0;
/* Address of original FACS. */
static grub_uint32_t facs_addr = 0;
struct grub_acpi_rsdp_v20 *
grub_acpi_get_rsdpv2 (void)
{
if (rsdpv2_new)
return rsdpv2_new;
if (rsdpv1_new)
return 0;
return grub_machine_acpi_get_rsdpv2 ();
}
struct grub_acpi_rsdp_v10 *
grub_acpi_get_rsdpv1 (void)
{
if (rsdpv1_new)
return rsdpv1_new;
if (rsdpv2_new)
return 0;
return grub_machine_acpi_get_rsdpv1 ();
}
static inline int
iszero (grub_uint8_t *reg, int size)
{
int i;
for (i = 0; i < size; i++)
if (reg[i])
return 0;
return 1;
}
grub_err_t
grub_acpi_create_ebda (void)
{
int ebda_kb_len;
int ebda_len;
int mmapregion = 0;
grub_uint8_t *ebda, *v1inebda = 0, *v2inebda = 0;
grub_uint64_t highestlow = 0;
grub_uint8_t *targetebda, *target;
struct grub_acpi_rsdp_v10 *v1;
struct grub_acpi_rsdp_v20 *v2;
auto int NESTED_FUNC_ATTR find_hook (grub_uint64_t, grub_uint64_t,
grub_uint32_t);
int NESTED_FUNC_ATTR find_hook (grub_uint64_t start, grub_uint64_t size,
grub_uint32_t type)
{
grub_uint64_t end = start + size;
if (type != GRUB_MACHINE_MEMORY_AVAILABLE)
return 0;
if (end > 0x100000)
end = 0x100000;
if (end > start + ebda_len
&& highestlow < ((end - ebda_len) & (~0xf)) )
highestlow = (end - ebda_len) & (~0xf);
return 0;
}
ebda = (grub_uint8_t *) UINT_TO_PTR ((*((grub_uint16_t *)0x40e)) << 4);
ebda_kb_len = *(grub_uint16_t *) ebda;
if (! ebda || ebda_kb_len > 16)
ebda_kb_len = 0;
ebda_len = (ebda_kb_len + 1) << 10;
/* FIXME: use low-memory mm allocation once it's available. */
grub_mmap_iterate (find_hook);
targetebda = (grub_uint8_t *) UINT_TO_PTR (highestlow);
grub_dprintf ("acpi", "creating ebda @%llx\n",
(unsigned long long) highestlow);
if (! highestlow)
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"couldn't find space for the new EBDA");
mmapregion = grub_mmap_register (PTR_TO_UINT64 (targetebda), ebda_len,
GRUB_MACHINE_MEMORY_RESERVED);
if (! mmapregion)
return grub_errno;
/* XXX: EBDA is unstandardized, so this implementation is heuristical. */
if (ebda_kb_len)
grub_memcpy (targetebda, ebda, 0x400);
else
grub_memset (targetebda, 0, 0x400);
*((grub_uint16_t *) targetebda) = ebda_kb_len + 1;
target = targetebda;
v1 = grub_acpi_get_rsdpv1 ();
v2 = grub_acpi_get_rsdpv2 ();
if (v2 && v2->length > 40)
v2 = 0;
/* First try to replace already existing rsdp. */
if (v2)
{
grub_dprintf ("acpi", "Scanning EBDA for old rsdpv2\n");
for (; target < targetebda + 0x400 - v2->length; target += 0x10)
if (grub_memcmp (target, "RSD PTR ", 8) == 0
&& grub_byte_checksum (target,
sizeof (struct grub_acpi_rsdp_v10)) == 0
&& ((struct grub_acpi_rsdp_v10 *) target)->revision != 0
&& ((struct grub_acpi_rsdp_v20 *) target)->length <= v2->length)
{
grub_memcpy (target, v2, v2->length);
grub_dprintf ("acpi", "Copying rsdpv2 to %p\n", target);
v2inebda = target;
target += v2->length;
target = (grub_uint8_t *) ((((long) target - 1) | 0xf) + 1);
v2 = 0;
break;
}
}
if (v1)
{
grub_dprintf ("acpi", "Scanning EBDA for old rsdpv1\n");
for (; target < targetebda + 0x400 - sizeof (struct grub_acpi_rsdp_v10);
target += 0x10)
if (grub_memcmp (target, "RSD PTR ", 8) == 0
&& grub_byte_checksum (target,
sizeof (struct grub_acpi_rsdp_v10)) == 0)
{
grub_memcpy (target, v1, sizeof (struct grub_acpi_rsdp_v10));
grub_dprintf ("acpi", "Copying rsdpv1 to %p\n", target);
v1inebda = target;
target += sizeof (struct grub_acpi_rsdp_v10);
target = (grub_uint8_t *) ((((long) target - 1) | 0xf) + 1);
v1 = 0;
break;
}
}
target = targetebda + 0x100;
/* Try contiguous zeros. */
if (v2)
{
grub_dprintf ("acpi", "Scanning EBDA for block of zeros\n");
for (; target < targetebda + 0x400 - v2->length; target += 0x10)
if (iszero (target, v2->length))
{
grub_dprintf ("acpi", "Copying rsdpv2 to %p\n", target);
grub_memcpy (target, v2, v2->length);
v2inebda = target;
target += v2->length;
target = (grub_uint8_t *) ((((long) target - 1) | 0xf) + 1);
v2 = 0;
break;
}
}
if (v1)
{
grub_dprintf ("acpi", "Scanning EBDA for block of zeros\n");
for (; target < targetebda + 0x400 - sizeof (struct grub_acpi_rsdp_v10);
target += 0x10)
if (iszero (target, sizeof (struct grub_acpi_rsdp_v10)))
{
grub_dprintf ("acpi", "Copying rsdpv1 to %p\n", target);
grub_memcpy (target, v1, sizeof (struct grub_acpi_rsdp_v10));
v1inebda = target;
target += sizeof (struct grub_acpi_rsdp_v10);
target = (grub_uint8_t *) ((((long) target - 1) | 0xf) + 1);
v1 = 0;
break;
}
}
if (v1 || v2)
{
grub_mmap_unregister (mmapregion);
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"couldn't find suitable spot in EBDA");
}
/* Remove any other RSDT. */
for (target = targetebda;
target < targetebda + 0x400 - sizeof (struct grub_acpi_rsdp_v10);
target += 0x10)
if (grub_memcmp (target, "RSD PTR ", 8) == 0
&& grub_byte_checksum (target,
sizeof (struct grub_acpi_rsdp_v10)) == 0
&& target != v1inebda && target != v2inebda)
*target = 0;
grub_dprintf ("acpi", "Switching EBDA\n");
(*((grub_uint16_t *) 0x40e)) = ((long)targetebda) >> 4;
grub_dprintf ("acpi", "EBDA switched\n");
return GRUB_ERR_NONE;
}
/* Create tables common to ACPIv1 and ACPIv2+ */
static void
setup_common_tables (void)
{
struct efiemu_acpi_table *cur;
struct grub_acpi_table_header *rsdt;
grub_uint32_t *rsdt_entry;
int numoftables;
/* Treat DSDT. */
grub_memcpy (playground_ptr, table_dsdt, dsdt_size);
grub_free (table_dsdt);
table_dsdt = playground_ptr;
playground_ptr += dsdt_size;
/* Treat other tables. */
for (cur = acpi_tables; cur; cur = cur->next)
{
struct grub_acpi_fadt *fadt;
grub_memcpy (playground_ptr, cur->addr, cur->size);
grub_free (cur->addr);
cur->addr = playground_ptr;
playground_ptr += cur->size;
/* If it's FADT correct DSDT and FACS addresses. */
fadt = (struct grub_acpi_fadt *) cur->addr;
if (grub_memcmp (fadt->hdr.signature, "FACP", 4) == 0)
{
fadt->dsdt_addr = PTR_TO_UINT32 (table_dsdt);
fadt->facs_addr = facs_addr;
/* Does a revision 2 exist at all? */
if (fadt->hdr.revision >= 3)
{
fadt->dsdt_xaddr = PTR_TO_UINT64 (table_dsdt);
fadt->facs_xaddr = facs_addr;
}
/* Recompute checksum. */
fadt->hdr.checksum = 0;
fadt->hdr.checksum = 1 + ~grub_byte_checksum (fadt, fadt->hdr.length);
}
}
/* Fill RSDT entries. */
numoftables = 0;
for (cur = acpi_tables; cur; cur = cur->next)
numoftables++;
rsdt_addr = rsdt = (struct grub_acpi_table_header *) playground_ptr;
playground_ptr += sizeof (struct grub_acpi_table_header) + 4 * numoftables;
rsdt_entry = (grub_uint32_t *)(rsdt + 1);
/* Fill RSDT header. */
grub_memcpy (&(rsdt->signature), "RSDT", 4);
rsdt->length = sizeof (struct grub_acpi_table_header) + 4 * numoftables;
rsdt->revision = 1;
grub_memcpy (&(rsdt->oemid), root_oemid, 6);
grub_memcpy (&(rsdt->oemtable), root_oemtable, 4);
rsdt->oemrev = root_oemrev;
grub_memcpy (&(rsdt->creator_id), root_creator_id, 6);
rsdt->creator_rev = root_creator_rev;
for (cur = acpi_tables; cur; cur = cur->next)
*(rsdt_entry++) = PTR_TO_UINT32 (cur->addr);
/* Recompute checksum. */
rsdt->checksum = 0;
rsdt->checksum = 1 + ~grub_byte_checksum (rsdt, rsdt->length);
}
/* Regenerate ACPIv1 RSDP */
static void
setv1table (void)
{
/* Create RSDP. */
rsdpv1_new = (struct grub_acpi_rsdp_v10 *) playground_ptr;
playground_ptr += sizeof (struct grub_acpi_rsdp_v10);
grub_memcpy (&(rsdpv1_new->signature), "RSD PTR ", 8);
grub_memcpy (&(rsdpv1_new->oemid), root_oemid, sizeof (rsdpv1_new->oemid));
rsdpv1_new->revision = 0;
rsdpv1_new->rsdt_addr = PTR_TO_UINT32 (rsdt_addr);
rsdpv1_new->checksum = 0;
rsdpv1_new->checksum = 1 + ~grub_byte_checksum (rsdpv1_new,
sizeof (*rsdpv1_new));
grub_dprintf ("acpi", "Generated ACPIv1 tables\n");
}
static void
setv2table (void)
{
struct grub_acpi_table_header *xsdt;
struct efiemu_acpi_table *cur;
grub_uint64_t *xsdt_entry;
int numoftables;
numoftables = 0;
for (cur = acpi_tables; cur; cur = cur->next)
numoftables++;
/* Create XSDT. */
xsdt = (struct grub_acpi_table_header *) playground_ptr;
playground_ptr += sizeof (struct grub_acpi_table_header) + 8 * numoftables;
xsdt_entry = (grub_uint64_t *)(xsdt + 1);
for (cur = acpi_tables; cur; cur = cur->next)
*(xsdt_entry++) = PTR_TO_UINT64 (cur->addr);
grub_memcpy (&(xsdt->signature), "XSDT", 4);
xsdt->length = sizeof (struct grub_acpi_table_header) + 8 * numoftables;
xsdt->revision = 1;
grub_memcpy (&(xsdt->oemid), root_oemid, sizeof (xsdt->oemid));
grub_memcpy (&(xsdt->oemtable), root_oemtable, sizeof (xsdt->oemtable));
xsdt->oemrev = root_oemrev;
grub_memcpy (&(xsdt->creator_id), root_creator_id, sizeof (xsdt->creator_id));
xsdt->creator_rev = root_creator_rev;
xsdt->checksum = 0;
xsdt->checksum = 1 + ~grub_byte_checksum (xsdt, xsdt->length);
/* Create RSDPv2. */
rsdpv2_new = (struct grub_acpi_rsdp_v20 *) playground_ptr;
playground_ptr += sizeof (struct grub_acpi_rsdp_v20);
grub_memcpy (&(rsdpv2_new->rsdpv1.signature), "RSD PTR ",
sizeof (rsdpv2_new->rsdpv1.signature));
grub_memcpy (&(rsdpv2_new->rsdpv1.oemid), root_oemid,
sizeof (rsdpv2_new->rsdpv1.oemid));
rsdpv2_new->rsdpv1.revision = rev2;
rsdpv2_new->rsdpv1.rsdt_addr = PTR_TO_UINT32 (rsdt_addr);
rsdpv2_new->rsdpv1.checksum = 0;
rsdpv2_new->rsdpv1.checksum = 1 + ~grub_byte_checksum
(&(rsdpv2_new->rsdpv1), sizeof (rsdpv2_new->rsdpv1));
rsdpv2_new->length = sizeof (*rsdpv2_new);
rsdpv2_new->xsdt_addr = PTR_TO_UINT64 (xsdt);
rsdpv2_new->checksum = 0;
rsdpv2_new->checksum = 1 + ~grub_byte_checksum (rsdpv2_new,
rsdpv2_new->length);
grub_dprintf ("acpi", "Generated ACPIv2 tables\n");
}
static void
free_tables (void)
{
struct efiemu_acpi_table *cur, *t;
if (table_dsdt)
grub_free (table_dsdt);
for (cur = acpi_tables; cur;)
{
t = cur;
grub_free (cur->addr);
cur = cur->next;
grub_free (t);
}
acpi_tables = 0;
table_dsdt = 0;
}
static grub_err_t
grub_cmd_acpi (struct grub_extcmd *cmd,
int argc, char **args)
{
struct grub_arg_list *state = cmd->state;
struct grub_acpi_rsdp_v10 *rsdp;
struct efiemu_acpi_table *cur, *t;
grub_err_t err;
int i, mmapregion;
int numoftables;
/* Default values if no RSDP is found. */
rev1 = 1;
rev2 = 3;
facs_addr = 0;
playground = playground_ptr = 0;
playground_size = 0;
rsdp = (struct grub_acpi_rsdp_v10 *) grub_machine_acpi_get_rsdpv2 ();
if (! rsdp)
rsdp = grub_machine_acpi_get_rsdpv1 ();
if (rsdp)
{
grub_uint32_t *entry_ptr;
char *exclude = 0;
char *load_only = 0;
char *ptr;
/* RSDT consists of header and an array of 32-bit pointers. */
struct grub_acpi_table_header *rsdt;
exclude = state[0].set ? grub_strdup (state[0].arg) : 0;
if (exclude)
{
for (ptr = exclude; *ptr; ptr++)
*ptr = grub_tolower (*ptr);
}
load_only = state[1].set ? grub_strdup (state[1].arg) : 0;
if (load_only)
{
for (ptr = load_only; *ptr; ptr++)
*ptr = grub_tolower (*ptr);
}
/* Set revision variables to replicate the same version as host. */
rev1 = ! rsdp->revision;
rev2 = rsdp->revision;
rsdt = (struct grub_acpi_table_header *) UINT_TO_PTR (rsdp->rsdt_addr);
/* Load host tables. */
for (entry_ptr = (grub_uint32_t *) (rsdt + 1);
entry_ptr < (grub_uint32_t *) (((grub_uint8_t *) rsdt)
+ rsdt->length);
entry_ptr++)
{
char signature[5];
struct efiemu_acpi_table *table;
struct grub_acpi_table_header *curtable
= (struct grub_acpi_table_header *) UINT_TO_PTR (*entry_ptr);
signature[4] = 0;
for (i = 0; i < 4;i++)
signature[i] = grub_tolower (curtable->signature[i]);
/* If it's FADT it contains addresses of DSDT and FACS. */
if (grub_strcmp (signature, "facp") == 0)
{
struct grub_acpi_table_header *dsdt;
struct grub_acpi_fadt *fadt = (struct grub_acpi_fadt *) curtable;
/* Set root header variables to the same values
as FACP by default. */
grub_memcpy (&root_oemid, &(fadt->hdr.oemid),
sizeof (root_oemid));
grub_memcpy (&root_oemtable, &(fadt->hdr.oemtable),
sizeof (root_oemtable));
root_oemrev = fadt->hdr.oemrev;
grub_memcpy (&root_creator_id, &(fadt->hdr.creator_id),
sizeof (root_creator_id));
root_creator_rev = fadt->hdr.creator_rev;
/* Load DSDT if not excluded. */
dsdt = (struct grub_acpi_table_header *)
UINT_TO_PTR (fadt->dsdt_addr);
if (dsdt && (! exclude || ! grub_strword (exclude, "dsdt"))
&& (! load_only || grub_strword (load_only, "dsdt"))
&& dsdt->length >= sizeof (*dsdt))
{
dsdt_size = dsdt->length;
table_dsdt = grub_malloc (dsdt->length);
if (! table_dsdt)
{
free_tables ();
grub_free (exclude);
grub_free (load_only);
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"couldn't allocate table");
}
grub_memcpy (table_dsdt, dsdt, dsdt->length);
}
/* Save FACS address. FACS shouldn't be overridden. */
facs_addr = fadt->facs_addr;
}
/* Skip excluded tables. */
if (exclude && grub_strword (exclude, signature))
continue;
if (load_only && ! grub_strword (load_only, signature))
continue;
/* Sanity check. */
if (curtable->length < sizeof (*curtable))
continue;
table = (struct efiemu_acpi_table *) grub_malloc
(sizeof (struct efiemu_acpi_table));
if (! table)
{
free_tables ();
grub_free (exclude);
grub_free (load_only);
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"couldn't allocate table structure");
}
table->size = curtable->length;
table->addr = grub_malloc (table->size);
playground_size += table->size;
if (! table->addr)
{
free_tables ();
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"couldn't allocate table");
}
table->next = acpi_tables;
acpi_tables = table;
grub_memcpy (table->addr, curtable, table->size);
}
grub_free (exclude);
grub_free (load_only);
}
/* Does user specify versions to generate? */
if (state[2].set || state[3].set)
{
rev1 = state[2].set;
if (state[3].set)
rev2 = rev2 ? : 2;
else
rev2 = 0;
}
/* Does user override root header information? */
if (state[4].set)
grub_strncpy (root_oemid, state[4].arg, sizeof (root_oemid));
if (state[5].set)
grub_strncpy (root_oemtable, state[5].arg, sizeof (root_oemtable));
if (state[6].set)
root_oemrev = grub_strtoul (state[6].arg, 0, 0);
if (state[7].set)
grub_strncpy (root_creator_id, state[7].arg, sizeof (root_creator_id));
if (state[8].set)
root_creator_rev = grub_strtoul (state[8].arg, 0, 0);
/* Load user tables */
for (i = 0; i < argc; i++)
{
grub_file_t file;
grub_size_t size;
char *buf;
file = grub_gzfile_open (args[i], 1);
if (! file)
{
free_tables ();
return grub_error (GRUB_ERR_BAD_OS, "couldn't open file %s", args[i]);
}
size = grub_file_size (file);
if (size < sizeof (struct grub_acpi_table_header))
{
grub_file_close (file);
free_tables ();
return grub_error (GRUB_ERR_BAD_OS, "file %s is too small", args[i]);
}
buf = (char *) grub_malloc (size);
if (! buf)
{
grub_file_close (file);
free_tables ();
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"couldn't read file %s", args[i]);
}
if (grub_file_read (file, buf, size) != (int) size)
{
grub_file_close (file);
free_tables ();
return grub_error (GRUB_ERR_BAD_OS, "couldn't read file %s", args[i]);
}
grub_file_close (file);
if (grub_memcmp (((struct grub_acpi_table_header *) buf)->signature,
"DSDT", 4) == 0)
{
grub_free (table_dsdt);
table_dsdt = buf;
dsdt_size = size;
}
else
{
struct efiemu_acpi_table *table;
table = (struct efiemu_acpi_table *) grub_malloc
(sizeof (struct efiemu_acpi_table));
if (! table)
{
free_tables ();
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"couldn't allocate table structure");
}
table->size = size;
table->addr = buf;
playground_size += table->size;
table->next = acpi_tables;
acpi_tables = table;
}
}
numoftables = 0;
for (cur = acpi_tables; cur; cur = cur->next)
numoftables++;
/* DSDT. */
playground_size += dsdt_size;
/* RSDT. */
playground_size += sizeof (struct grub_acpi_table_header) + 4 * numoftables;
/* RSDPv1. */
playground_size += sizeof (struct grub_acpi_rsdp_v10);
/* XSDT. */
playground_size += sizeof (struct grub_acpi_table_header) + 8 * numoftables;
/* RSDPv2. */
playground_size += sizeof (struct grub_acpi_rsdp_v20);
playground = playground_ptr
= grub_mmap_malign_and_register (1, playground_size, &mmapregion,
GRUB_MACHINE_MEMORY_ACPI, 0);
if (! playground)
{
free_tables ();
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"couldn't allocate space for ACPI tables");
}
setup_common_tables ();
/* Request space for RSDPv1. */
if (rev1)
setv1table ();
/* Request space for RSDPv2+ and XSDT. */
if (rev2)
setv2table ();
for (cur = acpi_tables; cur;)
{
t = cur;
cur = cur->next;
grub_free (t);
}
acpi_tables = 0;
if (! state[9].set && (err = grub_acpi_create_ebda ()))
{
rsdpv1_new = 0;
rsdpv2_new = 0;
grub_mmap_free_and_unregister (mmapregion);
return err;
}
#ifdef GRUB_MACHINE_EFI
{
struct grub_efi_guid acpi = GRUB_EFI_ACPI_TABLE_GUID;
struct grub_efi_guid acpi20 = GRUB_EFI_ACPI_20_TABLE_GUID;
grub_efi_system_table->boot_services->install_configuration_table
(&acpi20, grub_acpi_get_rsdpv2 ());
grub_efi_system_table->boot_services->install_configuration_table
(&acpi, grub_acpi_get_rsdpv1 ());
}
#endif
return GRUB_ERR_NONE;
}
static grub_extcmd_t cmd;
GRUB_MOD_INIT(acpi)
{
cmd = grub_register_extcmd ("acpi", grub_cmd_acpi,
GRUB_COMMAND_FLAG_BOTH,
N_("[-1|-2] [--exclude=TABLE1,TABLE2|"
"--load-only=table1,table2] FILE1"
" [FILE2] [...]"),
N_("Load host ACPI tables and tables "
"specified by arguments."),
options);
}
GRUB_MOD_FINI(acpi)
{
grub_unregister_extcmd (cmd);
}

View File

@ -17,17 +17,17 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <grub/normal.h>
#include <grub/dl.h> #include <grub/dl.h>
#include <grub/arg.h>
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/file.h> #include <grub/file.h>
#include <grub/mm.h> #include <grub/mm.h>
#include <grub/disk.h> #include <grub/disk.h>
#include <grub/partition.h> #include <grub/partition.h>
#include <grub/command.h>
#include <grub/i18n.h>
static grub_err_t static grub_err_t
grub_cmd_blocklist (struct grub_arg_list *state __attribute__ ((unused)), grub_cmd_blocklist (grub_command_t cmd __attribute__ ((unused)),
int argc, char **args) int argc, char **args)
{ {
grub_file_t file; grub_file_t file;
@ -40,7 +40,7 @@ grub_cmd_blocklist (struct grub_arg_list *state __attribute__ ((unused)),
unsigned length); unsigned length);
auto void NESTED_FUNC_ATTR print_blocklist (grub_disk_addr_t sector, unsigned num, auto void NESTED_FUNC_ATTR print_blocklist (grub_disk_addr_t sector, unsigned num,
unsigned offset, unsigned length); unsigned offset, unsigned length);
void NESTED_FUNC_ATTR read_blocklist (grub_disk_addr_t sector, unsigned offset, void NESTED_FUNC_ATTR read_blocklist (grub_disk_addr_t sector, unsigned offset,
unsigned length) unsigned length)
{ {
@ -52,7 +52,7 @@ grub_cmd_blocklist (struct grub_arg_list *state __attribute__ ((unused)),
num_sectors++; num_sectors++;
return; return;
} }
print_blocklist (start_sector, num_sectors, 0, 0); print_blocklist (start_sector, num_sectors, 0, 0);
num_sectors = 0; num_sectors = 0;
} }
@ -65,20 +65,20 @@ grub_cmd_blocklist (struct grub_arg_list *state __attribute__ ((unused)),
else else
print_blocklist (sector, 0, offset, length); print_blocklist (sector, 0, offset, length);
} }
void NESTED_FUNC_ATTR print_blocklist (grub_disk_addr_t sector, unsigned num, void NESTED_FUNC_ATTR print_blocklist (grub_disk_addr_t sector, unsigned num,
unsigned offset, unsigned length) unsigned offset, unsigned length)
{ {
if (num_entries++) if (num_entries++)
grub_printf (","); grub_printf (",");
grub_printf ("%llu", sector - part_start); grub_printf ("%llu", (unsigned long long) (sector - part_start));
if (num > 0) if (num > 0)
grub_printf ("+%u", num); grub_printf ("+%u", num);
if (offset != 0 || length != 0) if (offset != 0 || length != 0)
grub_printf ("[%u-%u]", offset, offset + length); grub_printf ("[%u-%u]", offset, offset + length);
} }
if (argc < 1) if (argc < 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified"); return grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified");
@ -88,11 +88,11 @@ grub_cmd_blocklist (struct grub_arg_list *state __attribute__ ((unused)),
if (! file->device->disk) if (! file->device->disk)
return grub_error (GRUB_ERR_BAD_DEVICE, return grub_error (GRUB_ERR_BAD_DEVICE,
"this command is available only for disk devices."); "this command is available only for disk devices");
if (file->device->disk->partition) if (file->device->disk->partition)
part_start = grub_partition_get_start (file->device->disk->partition); part_start = grub_partition_get_start (file->device->disk->partition);
file->read_hook = read_blocklist; file->read_hook = read_blocklist;
while (grub_file_read (file, buf, sizeof (buf)) > 0) while (grub_file_read (file, buf, sizeof (buf)) > 0)
@ -100,23 +100,21 @@ grub_cmd_blocklist (struct grub_arg_list *state __attribute__ ((unused)),
if (num_sectors > 0) if (num_sectors > 0)
print_blocklist (start_sector, num_sectors, 0, 0); print_blocklist (start_sector, num_sectors, 0, 0);
grub_file_close (file); grub_file_close (file);
return grub_errno; return grub_errno;
} }
static grub_command_t cmd;
GRUB_MOD_INIT(blocklist) GRUB_MOD_INIT(blocklist)
{ {
(void) mod; /* To stop warning. */ cmd = grub_register_command ("blocklist", grub_cmd_blocklist,
grub_register_command ("blocklist", grub_cmd_blocklist, N_("FILE"), N_("Print a block list."));
GRUB_COMMAND_FLAG_BOTH,
"blocklist FILE",
"Print a block list.", 0);
} }
GRUB_MOD_FINI(blocklist) GRUB_MOD_FINI(blocklist)
{ {
grub_unregister_command ("blocklist"); grub_unregister_command (cmd);
} }

View File

@ -1,7 +1,7 @@
/* boot.c - command to boot an operating system */ /* boot.c - command to boot an operating system */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2003,2005,2007 Free Software Foundation, Inc. * Copyright (C) 2002,2003,2004,2005,2007,2009 Free Software Foundation, Inc.
* *
* GRUB is free software: you can redistribute it and/or modify * GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -19,32 +19,178 @@
#include <grub/normal.h> #include <grub/normal.h>
#include <grub/dl.h> #include <grub/dl.h>
#include <grub/arg.h>
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/loader.h> #include <grub/loader.h>
#include <grub/kernel.h>
#include <grub/mm.h>
#include <grub/i18n.h>
static grub_err_t static grub_err_t (*grub_loader_boot_func) (void);
grub_cmd_boot (struct grub_arg_list *state __attribute__ ((unused)), static grub_err_t (*grub_loader_unload_func) (void);
int argc, char **args __attribute__ ((unused))) static int grub_loader_noreturn;
struct grub_preboot_t
{ {
if (argc) grub_err_t (*preboot_func) (int);
return grub_error (GRUB_ERR_BAD_ARGUMENT, "too many arguments"); grub_err_t (*preboot_rest_func) (void);
grub_loader_preboot_hook_prio_t prio;
grub_loader_boot (); struct grub_preboot_t *next;
struct grub_preboot_t *prev;
return 0; };
static int grub_loader_loaded;
static struct grub_preboot_t *preboots_head = 0,
*preboots_tail = 0;
int
grub_loader_is_loaded (void)
{
return grub_loader_loaded;
}
/* Register a preboot hook. */
void *
grub_loader_register_preboot_hook (grub_err_t (*preboot_func) (int noreturn),
grub_err_t (*preboot_rest_func) (void),
grub_loader_preboot_hook_prio_t prio)
{
struct grub_preboot_t *cur, *new_preboot;
if (! preboot_func && ! preboot_rest_func)
return 0;
new_preboot = (struct grub_preboot_t *)
grub_malloc (sizeof (struct grub_preboot_t));
if (! new_preboot)
{
grub_error (GRUB_ERR_OUT_OF_MEMORY, "hook not added");
return 0;
}
new_preboot->preboot_func = preboot_func;
new_preboot->preboot_rest_func = preboot_rest_func;
new_preboot->prio = prio;
for (cur = preboots_head; cur && cur->prio > prio; cur = cur->next);
if (cur)
{
new_preboot->next = cur;
new_preboot->prev = cur->prev;
cur->prev = new_preboot;
}
else
{
new_preboot->next = 0;
new_preboot->prev = preboots_tail;
preboots_tail = new_preboot;
}
if (new_preboot->prev)
new_preboot->prev->next = new_preboot;
else
preboots_head = new_preboot;
return new_preboot;
}
void
grub_loader_unregister_preboot_hook (void *hnd)
{
struct grub_preboot_t *preb = hnd;
if (preb->next)
preb->next->prev = preb->prev;
else
preboots_tail = preb->prev;
if (preb->prev)
preb->prev->next = preb->next;
else
preboots_head = preb->next;
grub_free (preb);
}
void
grub_loader_set (grub_err_t (*boot) (void),
grub_err_t (*unload) (void),
int noreturn)
{
if (grub_loader_loaded && grub_loader_unload_func)
grub_loader_unload_func ();
grub_loader_boot_func = boot;
grub_loader_unload_func = unload;
grub_loader_noreturn = noreturn;
grub_loader_loaded = 1;
}
void
grub_loader_unset(void)
{
if (grub_loader_loaded && grub_loader_unload_func)
grub_loader_unload_func ();
grub_loader_boot_func = 0;
grub_loader_unload_func = 0;
grub_loader_loaded = 0;
}
grub_err_t
grub_loader_boot (void)
{
grub_err_t err = GRUB_ERR_NONE;
struct grub_preboot_t *cur;
if (! grub_loader_loaded)
return grub_error (GRUB_ERR_NO_KERNEL, "no loaded kernel");
if (grub_loader_noreturn)
grub_machine_fini ();
for (cur = preboots_head; cur; cur = cur->next)
{
err = cur->preboot_func (grub_loader_noreturn);
if (err)
{
for (cur = cur->prev; cur; cur = cur->prev)
cur->preboot_rest_func ();
return err;
}
}
err = (grub_loader_boot_func) ();
for (cur = preboots_tail; cur; cur = cur->prev)
if (! err)
err = cur->preboot_rest_func ();
else
cur->preboot_rest_func ();
return err;
}
/* boot */
static grub_err_t
grub_cmd_boot (struct grub_command *cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)),
char *argv[] __attribute__ ((unused)))
{
return grub_loader_boot ();
} }
static grub_command_t cmd_boot;
GRUB_MOD_INIT(boot) GRUB_MOD_INIT(boot)
{ {
(void) mod; /* To stop warning. */ cmd_boot =
grub_register_command ("boot", grub_cmd_boot, GRUB_COMMAND_FLAG_BOTH, grub_register_command ("boot", grub_cmd_boot,
"boot", "Boot an operating system.", 0); 0, N_("Boot an operating system."));
} }
GRUB_MOD_FINI(boot) GRUB_MOD_FINI(boot)
{ {
grub_unregister_command ("boot"); grub_unregister_command (cmd_boot);
} }

View File

@ -1,7 +1,7 @@
/* cat.c - command to show the contents of a file */ /* cat.c - command to show the contents of a file */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2003,2005,2007 Free Software Foundation, Inc. * Copyright (C) 2003,2005,2007,2008 Free Software Foundation, Inc.
* *
* GRUB is free software: you can redistribute it and/or modify * GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -17,23 +17,24 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <grub/normal.h>
#include <grub/dl.h> #include <grub/dl.h>
#include <grub/arg.h>
#include <grub/file.h> #include <grub/file.h>
#include <grub/disk.h> #include <grub/disk.h>
#include <grub/term.h> #include <grub/term.h>
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/gzio.h> #include <grub/gzio.h>
#include <grub/command.h>
#include <grub/i18n.h>
static grub_err_t static grub_err_t
grub_cmd_cat (struct grub_arg_list *state __attribute__ ((unused)), grub_cmd_cat (grub_command_t cmd __attribute__ ((unused)),
int argc, char **args) int argc, char **args)
{ {
grub_file_t file; grub_file_t file;
char buf[GRUB_DISK_SECTOR_SIZE]; char buf[GRUB_DISK_SECTOR_SIZE];
grub_ssize_t size; grub_ssize_t size;
int key = 0;
if (argc != 1) if (argc != 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required"); return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required");
@ -41,16 +42,17 @@ grub_cmd_cat (struct grub_arg_list *state __attribute__ ((unused)),
file = grub_gzfile_open (args[0], 1); file = grub_gzfile_open (args[0], 1);
if (! file) if (! file)
return 0; return 0;
while ((size = grub_file_read (file, buf, sizeof (buf))) > 0) while ((size = grub_file_read (file, buf, sizeof (buf))) > 0
&& key != GRUB_TERM_ESC)
{ {
int i; int i;
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
{ {
unsigned char c = buf[i]; unsigned char c = buf[i];
if (grub_isprint (c) || grub_isspace (c)) if ((grub_isprint (c) || grub_isspace (c)) && c != '\r')
grub_putchar (c); grub_putchar (c);
else else
{ {
@ -59,24 +61,28 @@ grub_cmd_cat (struct grub_arg_list *state __attribute__ ((unused)),
grub_setcolorstate (GRUB_TERM_COLOR_STANDARD); grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
} }
} }
while (grub_checkkey () >= 0 &&
(key = GRUB_TERM_ASCII_CHAR (grub_getkey ())) != GRUB_TERM_ESC)
;
} }
grub_putchar ('\n'); grub_putchar ('\n');
grub_refresh (); grub_refresh ();
grub_file_close (file); grub_file_close (file);
return 0; return 0;
} }
static grub_command_t cmd;
GRUB_MOD_INIT(cat) GRUB_MOD_INIT(cat)
{ {
(void) mod; /* To stop warning. */ cmd = grub_register_command_p1 ("cat", grub_cmd_cat,
grub_register_command ("cat", grub_cmd_cat, GRUB_COMMAND_FLAG_BOTH, N_("FILE"), N_("Show the contents of a file."));
"cat FILE", "Show the contents of a file.", 0);
} }
GRUB_MOD_FINI(cat) GRUB_MOD_FINI(cat)
{ {
grub_unregister_command ("cat"); grub_unregister_command (cmd);
} }

View File

@ -1,7 +1,7 @@
/* cmd.c - command to cmp an operating system */ /* cmd.c - command to cmp an operating system */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2003,2005,2006,2007 Free Software Foundation, Inc. * Copyright (C) 2003,2005,2006,2007,2009 Free Software Foundation, Inc.
* *
* GRUB is free software: you can redistribute it and/or modify * GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -17,18 +17,18 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <grub/normal.h>
#include <grub/dl.h> #include <grub/dl.h>
#include <grub/arg.h>
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/file.h> #include <grub/file.h>
#include <grub/mm.h> #include <grub/mm.h>
#include <grub/gzio.h> #include <grub/gzio.h>
#include <grub/command.h>
#include <grub/i18n.h>
#define BUFFER_SIZE 512 #define BUFFER_SIZE 512
static grub_err_t static grub_err_t
grub_cmd_cmp (struct grub_arg_list *state __attribute__ ((unused)), grub_cmd_cmp (grub_command_t cmd __attribute__ ((unused)),
int argc, char **args) int argc, char **args)
{ {
grub_ssize_t rd1, rd2; grub_ssize_t rd1, rd2;
@ -41,7 +41,7 @@ grub_cmd_cmp (struct grub_arg_list *state __attribute__ ((unused)),
if (argc != 2) if (argc != 2)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "two arguments required"); return grub_error (GRUB_ERR_BAD_ARGUMENT, "two arguments required");
grub_printf ("Compare `%s' and `%s':\n", args[0], grub_printf ("Compare file `%s' with `%s':\n", args[0],
args[1]); args[1]);
file1 = grub_gzfile_open (args[0], 1); file1 = grub_gzfile_open (args[0], 1);
@ -50,23 +50,23 @@ grub_cmd_cmp (struct grub_arg_list *state __attribute__ ((unused)),
goto cleanup; goto cleanup;
if (grub_file_size (file1) != grub_file_size (file2)) if (grub_file_size (file1) != grub_file_size (file2))
grub_printf ("Differ in size: %llu [%s], %llu [%s]\n", grub_printf ("Files differ in size: %llu [%s], %llu [%s]\n",
grub_file_size (file1), args[0], (unsigned long long) grub_file_size (file1), args[0],
grub_file_size (file2), args[1]); (unsigned long long) grub_file_size (file2), args[1]);
else else
{ {
pos = 0; pos = 0;
buf1 = grub_malloc (BUFFER_SIZE); buf1 = grub_malloc (BUFFER_SIZE);
buf2 = grub_malloc (BUFFER_SIZE); buf2 = grub_malloc (BUFFER_SIZE);
if (! buf1 || ! buf2) if (! buf1 || ! buf2)
goto cleanup; goto cleanup;
do do
{ {
int i; int i;
rd1 = grub_file_read (file1, buf1, BUFFER_SIZE); rd1 = grub_file_read (file1, buf1, BUFFER_SIZE);
rd2 = grub_file_read (file2, buf2, BUFFER_SIZE); rd2 = grub_file_read (file2, buf2, BUFFER_SIZE);
@ -77,22 +77,22 @@ grub_cmd_cmp (struct grub_arg_list *state __attribute__ ((unused)),
{ {
if (buf1[i] != buf2[i]) if (buf1[i] != buf2[i])
{ {
grub_printf ("Differ at the offset %llu: 0x%x [%s], 0x%x [%s]\n", grub_printf ("Files differ at the offset %llu: 0x%x [%s], 0x%x [%s]\n",
i + pos, buf1[i], args[0], (unsigned long long) (i + pos), buf1[i], args[0],
buf2[i], args[1]); buf2[i], args[1]);
goto cleanup; goto cleanup;
} }
} }
pos += BUFFER_SIZE; pos += BUFFER_SIZE;
} }
while (rd2); while (rd2);
grub_printf ("The files are identical.\n"); grub_printf ("The files are identical.\n");
} }
cleanup: cleanup:
if (buf1) if (buf1)
grub_free (buf1); grub_free (buf1);
if (buf2) if (buf2)
@ -105,15 +105,15 @@ cleanup:
return grub_errno; return grub_errno;
} }
static grub_command_t cmd;
GRUB_MOD_INIT(cmp) GRUB_MOD_INIT(cmp)
{ {
(void) mod; /* To stop warning. */ cmd = grub_register_command ("cmp", grub_cmd_cmp,
grub_register_command ("cmp", grub_cmd_cmp, GRUB_COMMAND_FLAG_BOTH, N_("FILE1 FILE2"), N_("Compare two files."));
"cmp FILE1 FILE2", "Compare two files.", 0);
} }
GRUB_MOD_FINI(cmp) GRUB_MOD_FINI(cmp)
{ {
grub_unregister_command ("cmp"); grub_unregister_command (cmd);
} }

View File

@ -1,7 +1,7 @@
/* configfile.c - command to manually load config file */ /* configfile.c - command to manually load config file */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2005,2006,2007 Free Software Foundation, Inc. * Copyright (C) 2005,2006,2007,2009 Free Software Foundation, Inc.
* *
* GRUB is free software: you can redistribute it and/or modify * GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -17,62 +17,59 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <grub/normal.h>
#include <grub/dl.h> #include <grub/dl.h>
#include <grub/arg.h>
#include <grub/term.h> #include <grub/term.h>
#include <grub/misc.h>
#include <grub/env.h> #include <grub/env.h>
#include <grub/normal.h>
#include <grub/command.h>
#include <grub/i18n.h>
static grub_err_t static grub_err_t
grub_cmd_configfile (struct grub_arg_list *state __attribute__ ((unused)), grub_cmd_source (grub_command_t cmd, int argc, char **args)
int argc, char **args)
{ {
int new_env;
if (argc != 1) if (argc != 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required"); return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required");
grub_cls (); new_env = (cmd->name[0] == 'c');
grub_env_context_open ();
grub_normal_execute (args[0], 1); if (new_env)
grub_env_context_close (); {
grub_cls ();
return 0; grub_env_context_open (1);
} }
static grub_err_t grub_normal_execute (args[0], 1, ! new_env);
grub_cmd_source (struct grub_arg_list *state __attribute__ ((unused)),
int argc, char **args) if (new_env)
grub_env_context_close ();
{
if (argc != 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required");
grub_normal_execute (args[0], 1);
return 0; return 0;
} }
static grub_command_t cmd_configfile, cmd_source, cmd_dot;
GRUB_MOD_INIT(configfile) GRUB_MOD_INIT(configfile)
{ {
(void) mod; /* To stop warning. */ cmd_configfile =
grub_register_command ("configfile", grub_cmd_configfile, grub_register_command ("configfile", grub_cmd_source,
GRUB_COMMAND_FLAG_BOTH, "configfile FILE", N_("FILE"), N_("Load another config file."));
"Load another config file.", 0); cmd_source =
grub_register_command ("source", grub_cmd_source, grub_register_command ("source", grub_cmd_source,
GRUB_COMMAND_FLAG_BOTH, "source FILE", N_("FILE"),
"Load another config file without changing context.", N_("Load another config file without changing context.")
0); );
grub_register_command (".", grub_cmd_source, cmd_dot =
GRUB_COMMAND_FLAG_BOTH, ". FILE", grub_register_command (".", grub_cmd_source,
"Load another config file without changing context.", N_("FILE"),
0); N_("Load another config file without changing context.")
);
} }
GRUB_MOD_FINI(configfile) GRUB_MOD_FINI(configfile)
{ {
grub_unregister_command ("configfile"); grub_unregister_command (cmd_configfile);
grub_unregister_command ("source"); grub_unregister_command (cmd_source);
grub_unregister_command ("."); grub_unregister_command (cmd_dot);
} }

71
commands/crc.c Normal file
View File

@ -0,0 +1,71 @@
/* crc.c - command to calculate the crc32 checksum of a file */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008,2010 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/dl.h>
#include <grub/disk.h>
#include <grub/file.h>
#include <grub/misc.h>
#include <grub/lib/crc.h>
#include <grub/command.h>
#include <grub/i18n.h>
static grub_err_t
grub_cmd_crc (grub_command_t cmd __attribute__ ((unused)),
int argc, char **args)
{
grub_file_t file;
char buf[GRUB_DISK_SECTOR_SIZE];
grub_ssize_t size;
grub_uint32_t crc;
if (argc != 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required");
file = grub_file_open (args[0]);
if (! file)
return 0;
crc = 0;
while ((size = grub_file_read (file, buf, sizeof (buf))) > 0)
crc = grub_getcrc32 (crc, buf, size);
if (grub_errno)
goto fail;
grub_printf ("%08x\n", crc);
fail:
grub_file_close (file);
return 0;
}
static grub_command_t cmd;
GRUB_MOD_INIT(crc)
{
cmd = grub_register_command ("crc", grub_cmd_crc,
N_("FILE"),
N_("Calculate the crc32 checksum of a file."));
}
GRUB_MOD_FINI(crc)
{
grub_unregister_command (cmd);
}

146
commands/date.c Normal file
View File

@ -0,0 +1,146 @@
/* date.c - command to display/set current datetime. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008 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/dl.h>
#include <grub/err.h>
#include <grub/misc.h>
#include <grub/datetime.h>
#include <grub/command.h>
#include <grub/i18n.h>
#define GRUB_DATETIME_SET_YEAR 1
#define GRUB_DATETIME_SET_MONTH 2
#define GRUB_DATETIME_SET_DAY 4
#define GRUB_DATETIME_SET_HOUR 8
#define GRUB_DATETIME_SET_MINUTE 16
#define GRUB_DATETIME_SET_SECOND 32
static grub_err_t
grub_cmd_date (grub_command_t cmd __attribute__ ((unused)),
int argc, char **args)
{
struct grub_datetime datetime;
int limit[6][2] = {{1980, 2079}, {1, 12}, {1, 31}, {0, 23}, {0, 59}, {0, 59}};
int value[6], mask;
if (argc == 0)
{
if (grub_get_datetime (&datetime))
return grub_errno;
grub_printf ("%d-%02d-%02d %02d:%02d:%02d %s\n",
datetime.year, datetime.month, datetime.day,
datetime.hour, datetime.minute, datetime.second,
grub_get_weekday_name (&datetime));
return 0;
}
grub_memset (&value, 0, sizeof (value));
mask = 0;
for (; argc; argc--, args++)
{
char *p, c;
int m1, ofs, n, cur_mask;
p = args[0];
m1 = grub_strtoul (p, &p, 10);
c = *p;
if (c == '-')
ofs = 0;
else if (c == ':')
ofs = 3;
else
goto fail;
value[ofs] = m1;
cur_mask = (1 << ofs);
mask &= ~(cur_mask * (1 + 2 + 4));
for (n = 1; (n < 3) && (*p); n++)
{
if (*p != c)
goto fail;
value[ofs + n] = grub_strtoul (p + 1, &p, 10);
cur_mask |= (1 << (ofs + n));
}
if (*p)
goto fail;
if ((ofs == 0) && (n == 2))
{
value[ofs + 2] = value[ofs + 1];
value[ofs + 1] = value[ofs];
ofs++;
cur_mask <<= 1;
}
for (; n; n--, ofs++)
if ((value [ofs] < limit[ofs][0]) ||
(value [ofs] > limit[ofs][1]))
goto fail;
mask |= cur_mask;
}
if (grub_get_datetime (&datetime))
return grub_errno;
if (mask & GRUB_DATETIME_SET_YEAR)
datetime.year = value[0];
if (mask & GRUB_DATETIME_SET_MONTH)
datetime.month = value[1];
if (mask & GRUB_DATETIME_SET_DAY)
datetime.day = value[2];
if (mask & GRUB_DATETIME_SET_HOUR)
datetime.hour = value[3];
if (mask & GRUB_DATETIME_SET_MINUTE)
datetime.minute = value[4];
if (mask & GRUB_DATETIME_SET_SECOND)
datetime.second = value[5];
return grub_set_datetime (&datetime);
fail:
return grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid datetime");
}
static grub_command_t cmd;
GRUB_MOD_INIT(date)
{
cmd =
grub_register_command ("date", grub_cmd_date,
N_("[[year-]month-day] [hour:minute[:second]]"),
N_("Command to display/set current datetime."));
}
GRUB_MOD_FINI(date)
{
grub_unregister_command (cmd);
}

View File

@ -17,22 +17,22 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <grub/normal.h>
#include <grub/dl.h> #include <grub/dl.h>
#include <grub/arg.h>
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/extcmd.h>
#include <grub/i18n.h>
static const struct grub_arg_option options[] = static const struct grub_arg_option options[] =
{ {
{0, 'n', 0, "do not output the trailing newline", 0, 0}, {0, 'n', 0, N_("Do not output the trailing newline."), 0, 0},
{0, 'e', 0, "enable interpretation of backslash escapes", 0, 0}, {0, 'e', 0, N_("Enable interpretation of backslash escapes."), 0, 0},
{0, 0, 0, 0, 0, 0} {0, 0, 0, 0, 0, 0}
}; };
static grub_err_t static grub_err_t
grub_cmd_echo (struct grub_arg_list *state, int argc, char **args) grub_cmd_echo (grub_extcmd_t cmd, int argc, char **args)
{ {
struct grub_arg_list *state = cmd->state;
int newline = 1; int newline = 1;
int i; int i;
@ -91,7 +91,7 @@ grub_cmd_echo (struct grub_arg_list *state, int argc, char **args)
arg++; arg++;
continue; continue;
} }
/* This was not an escaped character, or escaping is not /* This was not an escaped character, or escaping is not
enabled. */ enabled. */
grub_printf ("%c", *arg); grub_printf ("%c", *arg);
@ -109,16 +109,16 @@ grub_cmd_echo (struct grub_arg_list *state, int argc, char **args)
return 0; return 0;
} }
static grub_extcmd_t cmd;
GRUB_MOD_INIT(echo) GRUB_MOD_INIT(echo)
{ {
(void) mod; /* To stop warning. */ cmd = grub_register_extcmd ("echo", grub_cmd_echo, GRUB_COMMAND_FLAG_BOTH,
grub_register_command ("echo", grub_cmd_echo, GRUB_COMMAND_FLAG_BOTH, N_("[-e|-n] STRING"), N_("Display a line of text."),
"echo [-e|-n] FILE", "Display a line of text.", options);
options);
} }
GRUB_MOD_FINI(echo) GRUB_MOD_FINI(echo)
{ {
grub_unregister_command ("echo"); grub_unregister_extcmd (cmd);
} }

View File

@ -1,7 +1,7 @@
/* acpi.c - Display acpi tables. */ /* acpi.c - get acpi tables. */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2008 Free Software Foundation, Inc. * Copyright (C) 2009 Free Software Foundation, Inc.
* *
* GRUB is free software: you can redistribute it and/or modify * GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -16,175 +16,44 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <grub/types.h>
#include <grub/mm.h> #include <grub/acpi.h>
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/normal.h> #include <grub/efi/efi.h>
#include <grub/efi/api.h>
static grub_uint32_t read16 (grub_uint8_t *p) struct grub_acpi_rsdp_v10 *
grub_machine_acpi_get_rsdpv1 (void)
{ {
return grub_le_to_cpu16 (*(grub_uint16_t *)p); unsigned i;
} static grub_efi_guid_t acpi_guid = GRUB_EFI_ACPI_TABLE_GUID;
static grub_uint32_t read32 (grub_uint8_t *p) for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
{
return grub_le_to_cpu32 (*(grub_uint32_t *)p);
}
static grub_uint64_t read64 (grub_uint8_t *p)
{
return grub_le_to_cpu64 (*(grub_uint64_t *)p);
}
static void
disp_acpi_table (grub_uint8_t *t)
{
int i;
grub_printf ("%c%c%c%c %4dB rev=%d OEM=", t[0], t[1], t[2], t[3],
read32 (t + 4), t[8]);
for (i = 0; i < 6; i++)
grub_printf ("%c", t[10 + i]);
grub_printf (" ");
for (i = 0; i < 8; i++)
grub_printf ("%c", t[16 + i]);
grub_printf (" V=%08lx ", read32 (t + 24));
for (i = 0; i < 4; i++)
grub_printf ("%c", t[28 + i]);
grub_printf (" %08lx\n", read32 (t + 32));
}
static void
disp_acpi_apic_table (grub_uint8_t *t)
{
grub_uint8_t *d;
grub_uint32_t len;
grub_uint32_t flags;
disp_acpi_table (t);
grub_printf ("Local APIC=%08lx Flags=%08lx\n",
read32 (t + 36), read32 (t + 40));
len = read32 (t + 4);
len -= 44;
d = t + 44;
while (len > 0)
{ {
grub_uint32_t l = d[1]; grub_efi_guid_t *guid =
grub_printf (" type=%x l=%d ", d[0], l); &grub_efi_system_table->configuration_table[i].vendor_guid;
switch (d[0]) if (! grub_memcmp (guid, &acpi_guid, sizeof (grub_efi_guid_t)))
{ return (struct grub_acpi_rsdp_v10 *)
case 2: grub_efi_system_table->configuration_table[i].vendor_table;
grub_printf ("Int Override bus=%x src=%x GSI=%08x Flags=%04x",
d[2], d[3], read32 (d + 4), read16 (d + 8));
break;
case 6:
grub_printf ("IOSAPIC Id=%02x GSI=%08x Addr=%016llx",
d[2], read32 (d + 4), read64 (d + 8));
break;
case 7:
flags = read32 (d + 8);
grub_printf ("LSAPIC ProcId=%02x ID=%02x EID=%02x Flags=%x",
d[2], d[3], d[4], flags);
if (flags & 1)
grub_printf (" Enabled");
else
grub_printf (" Disabled");
if (l >= 17)
grub_printf ("\n"
" UID val=%08x, Str=%s", read32 (d + 12), d + 16);
break;
case 8:
grub_printf ("Platform INT flags=%04x type=%02x (",
read16 (d + 2), d[4]);
if (d[4] <= 3)
{
static const char * const platint_type[4] =
{"Nul", "PMI", "INIT", "CPEI"};
grub_printf ("%s", platint_type[d[4]]);
}
else
grub_printf ("??");
grub_printf (") ID=%02x EID=%02x\n", d[5], d[6]);
grub_printf (" IOSAPIC Vec=%02x GSI=%08x source flags=%08x",
d[7], read32 (d + 8), read32 (d + 12));
break;
default:
grub_printf (" ??");
}
grub_printf ("\n");
d += l;
len -= l;
} }
return 0;
} }
static void struct grub_acpi_rsdp_v20 *
disp_acpi_xsdt_table (grub_uint8_t *t) grub_machine_acpi_get_rsdpv2 (void)
{ {
grub_uint32_t len; unsigned i;
grub_uint8_t *desc; static grub_efi_guid_t acpi20_guid = GRUB_EFI_ACPI_20_TABLE_GUID;
disp_acpi_table (t); for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
len = read32 (t + 4) - 36;
desc = t + 36;
while (len > 0)
{ {
t = read64 (desc); grub_efi_guid_t *guid =
&grub_efi_system_table->configuration_table[i].vendor_guid;
if (t[0] == 'A' && t[1] == 'P' && t[2] == 'I' && t[3] == 'C')
disp_acpi_apic_table (t); if (! grub_memcmp (guid, &acpi20_guid, sizeof (grub_efi_guid_t)))
else return (struct grub_acpi_rsdp_v20 *)
disp_acpi_table (t); grub_efi_system_table->configuration_table[i].vendor_table;
desc += 8;
len -= 8;
}
}
static void
disp_acpi_rsdt_table (grub_uint8_t *t)
{
grub_uint32_t len;
grub_uint8_t *desc;
disp_acpi_table (t);
len = read32 (t + 4) - 36;
desc = t + 36;
while (len > 0)
{
t = read32 (desc);
if (t != NULL)
disp_acpi_table (t);
desc += 4;
len -= 4;
}
}
void
disp_acpi_rsdp_table (grub_uint8_t *rsdp)
{
grub_uint8_t *t = rsdp;
int i;
grub_uint8_t *xsdt;
grub_printf ("RSDP signature:");
for (i = 0; i < 8; i++)
grub_printf ("%c", t[i]);
grub_printf (" chksum:%02x, OEM-ID: ", t[8]);
for (i = 0; i < 6; i++)
grub_printf ("%c", t[9 + i]);
grub_printf (" rev=%d\n", t[15]);
grub_printf ("RSDT=%08lx", read32 (t + 16));
if (t[15] == 2)
{
xsdt = read64 (t + 24);
grub_printf (" len=%d XSDT=%016llx\n", read32 (t + 20), xsdt);
grub_printf ("\n");
disp_acpi_xsdt_table (xsdt);
}
else
{
grub_printf ("\n");
disp_acpi_rsdt_table (read32 (t + 16));
} }
return 0;
} }

190
commands/efi/acpi2.c Normal file
View File

@ -0,0 +1,190 @@
/* acpi.c - Display acpi tables. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008 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/types.h>
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/normal.h>
static grub_uint32_t read16 (grub_uint8_t *p)
{
return grub_le_to_cpu16 (*(grub_uint16_t *)p);
}
static grub_uint32_t read32 (grub_uint8_t *p)
{
return grub_le_to_cpu32 (*(grub_uint32_t *)p);
}
static grub_uint64_t read64 (grub_uint8_t *p)
{
return grub_le_to_cpu64 (*(grub_uint64_t *)p);
}
static void
disp_acpi_table (grub_uint8_t *t)
{
int i;
grub_printf ("%c%c%c%c %4dB rev=%d OEM=", t[0], t[1], t[2], t[3],
read32 (t + 4), t[8]);
for (i = 0; i < 6; i++)
grub_printf ("%c", t[10 + i]);
grub_printf (" ");
for (i = 0; i < 8; i++)
grub_printf ("%c", t[16 + i]);
grub_printf (" V=%08lx ", read32 (t + 24));
for (i = 0; i < 4; i++)
grub_printf ("%c", t[28 + i]);
grub_printf (" %08lx\n", read32 (t + 32));
}
static void
disp_acpi_apic_table (grub_uint8_t *t)
{
grub_uint8_t *d;
grub_uint32_t len;
grub_uint32_t flags;
disp_acpi_table (t);
grub_printf ("Local APIC=%08lx Flags=%08lx\n",
read32 (t + 36), read32 (t + 40));
len = read32 (t + 4);
len -= 44;
d = t + 44;
while (len > 0)
{
grub_uint32_t l = d[1];
grub_printf (" type=%x l=%d ", d[0], l);
switch (d[0])
{
case 2:
grub_printf ("Int Override bus=%x src=%x GSI=%08x Flags=%04x",
d[2], d[3], read32 (d + 4), read16 (d + 8));
break;
case 6:
grub_printf ("IOSAPIC Id=%02x GSI=%08x Addr=%016llx",
d[2], read32 (d + 4), read64 (d + 8));
break;
case 7:
flags = read32 (d + 8);
grub_printf ("LSAPIC ProcId=%02x ID=%02x EID=%02x Flags=%x",
d[2], d[3], d[4], flags);
if (flags & 1)
grub_printf (" Enabled");
else
grub_printf (" Disabled");
if (l >= 17)
grub_printf ("\n"
" UID val=%08x, Str=%s", read32 (d + 12), d + 16);
break;
case 8:
grub_printf ("Platform INT flags=%04x type=%02x (",
read16 (d + 2), d[4]);
if (d[4] <= 3)
{
static const char * const platint_type[4] =
{"Nul", "PMI", "INIT", "CPEI"};
grub_printf ("%s", platint_type[d[4]]);
}
else
grub_printf ("??");
grub_printf (") ID=%02x EID=%02x\n", d[5], d[6]);
grub_printf (" IOSAPIC Vec=%02x GSI=%08x source flags=%08x",
d[7], read32 (d + 8), read32 (d + 12));
break;
default:
grub_printf (" ??");
}
grub_printf ("\n");
d += l;
len -= l;
}
}
static void
disp_acpi_xsdt_table (grub_uint8_t *t)
{
grub_uint32_t len;
grub_uint8_t *desc;
disp_acpi_table (t);
len = read32 (t + 4) - 36;
desc = t + 36;
while (len > 0)
{
t = read64 (desc);
if (t[0] == 'A' && t[1] == 'P' && t[2] == 'I' && t[3] == 'C')
disp_acpi_apic_table (t);
else
disp_acpi_table (t);
desc += 8;
len -= 8;
}
}
static void
disp_acpi_rsdt_table (grub_uint8_t *t)
{
grub_uint32_t len;
grub_uint8_t *desc;
disp_acpi_table (t);
len = read32 (t + 4) - 36;
desc = t + 36;
while (len > 0)
{
t = read32 (desc);
if (t != NULL)
disp_acpi_table (t);
desc += 4;
len -= 4;
}
}
void
disp_acpi_rsdp_table (grub_uint8_t *rsdp)
{
grub_uint8_t *t = rsdp;
int i;
grub_uint8_t *xsdt;
grub_printf ("RSDP signature:");
for (i = 0; i < 8; i++)
grub_printf ("%c", t[i]);
grub_printf (" chksum:%02x, OEM-ID: ", t[8]);
for (i = 0; i < 6; i++)
grub_printf ("%c", t[9 + i]);
grub_printf (" rev=%d\n", t[15]);
grub_printf ("RSDT=%08lx", read32 (t + 16));
if (t[15] == 2)
{
xsdt = read64 (t + 24);
grub_printf (" len=%d XSDT=%016llx\n", read32 (t + 20), xsdt);
grub_printf ("\n");
disp_acpi_xsdt_table (xsdt);
}
else
{
grub_printf ("\n");
disp_acpi_rsdt_table (read32 (t + 16));
}
}

110
commands/efi/fixvideo.c Normal file
View File

@ -0,0 +1,110 @@
/* fixvideo.c - fix video problem in efi */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 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/dl.h>
#include <grub/misc.h>
#include <grub/file.h>
#include <grub/pci.h>
#include <grub/command.h>
#include <grub/i18n.h>
static struct grub_video_patch
{
const char *name;
grub_uint32_t pci_id;
grub_uint32_t mmio_bar;
grub_uint32_t mmio_reg;
grub_uint32_t mmio_old;
} video_patches[] =
{
{"Intel 945GM", 0x27a28086, 0, 0x71184, 0x1000000}, /* DSPBBASE */
{"Intel 965GM", 0x2a028086, 0, 0x7119C, 0x1000000}, /* DSPBSURF */
{0, 0, 0, 0, 0}
};
static int NESTED_FUNC_ATTR
scan_card (grub_pci_device_t dev, grub_pci_id_t pciid)
{
grub_pci_address_t addr;
addr = grub_pci_make_address (dev, 2);
if (grub_pci_read_byte (addr + 3) == 0x3)
{
struct grub_video_patch *p = video_patches;
while (p->name)
{
if (p->pci_id == pciid)
{
grub_target_addr_t base;
grub_printf ("Found graphic card: %s\n", p->name);
addr += 8 + p->mmio_bar * 4;
base = grub_pci_read (addr);
if ((! base) || (base & GRUB_PCI_ADDR_SPACE_IO) ||
(base & GRUB_PCI_ADDR_MEM_PREFETCH))
grub_printf ("Invalid MMIO bar %d\n", p->mmio_bar);
else
{
base &= GRUB_PCI_ADDR_MEM_MASK;
base += p->mmio_reg;
if (*((volatile grub_uint32_t *) base) != p->mmio_old)
grub_printf ("Old value don't match\n");
else
{
*((volatile grub_uint32_t *) base) = 0;
if (*((volatile grub_uint32_t *) base))
grub_printf ("Set MMIO fails\n");
}
}
return 1;
}
p++;
}
grub_printf ("Unknown graphic card: %x\n", pciid);
}
return 0;
}
static grub_err_t
grub_cmd_fixvideo (grub_command_t cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)),
char *argv[] __attribute__ ((unused)))
{
grub_pci_iterate (scan_card);
return 0;
}
static grub_command_t cmd_fixvideo;
GRUB_MOD_INIT(fixvideo)
{
cmd_fixvideo = grub_register_command ("fix_video", grub_cmd_fixvideo,
0, N_("Fix video problem."));
}
GRUB_MOD_FINI(fixvideo)
{
grub_unregister_command (cmd_fixvideo);
}

216
commands/efi/loadbios.c Normal file
View File

@ -0,0 +1,216 @@
/* loadbios.c - command to load a bios dump */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 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/dl.h>
#include <grub/misc.h>
#include <grub/file.h>
#include <grub/efi/efi.h>
#include <grub/pci.h>
#include <grub/command.h>
#include <grub/i18n.h>
static grub_efi_guid_t acpi_guid = GRUB_EFI_ACPI_TABLE_GUID;
static grub_efi_guid_t acpi2_guid = GRUB_EFI_ACPI_20_TABLE_GUID;
static grub_efi_guid_t smbios_guid = GRUB_EFI_SMBIOS_TABLE_GUID;
#define EBDA_SEG_ADDR 0x40e
#define LOW_MEM_ADDR 0x413
#define FAKE_EBDA_SEG 0x9fc0
#define BLANK_MEM 0xffffffff
#define VBIOS_ADDR 0xc0000
#define SBIOS_ADDR 0xf0000
static int
enable_rom_area (void)
{
grub_pci_address_t addr;
grub_uint32_t *rom_ptr;
grub_pci_device_t dev = { .bus = 0, .device = 0, .function = 0};
rom_ptr = (grub_uint32_t *) VBIOS_ADDR;
if (*rom_ptr != BLANK_MEM)
{
grub_printf ("ROM image is present.\n");
return 0;
}
addr = grub_pci_make_address (dev, 36);
grub_pci_write_byte (addr++, 0x30);
grub_pci_write_byte (addr++, 0x33);
grub_pci_write_byte (addr++, 0x33);
grub_pci_write_byte (addr++, 0x33);
grub_pci_write_byte (addr++, 0x33);
grub_pci_write_byte (addr++, 0x33);
grub_pci_write_byte (addr++, 0x33);
grub_pci_write_byte (addr, 0);
*rom_ptr = 0;
if (*rom_ptr != 0)
{
grub_printf ("Can\'t enable ROM area.\n");
return 0;
}
return 1;
}
static void
lock_rom_area (void)
{
grub_pci_address_t addr;
grub_pci_device_t dev = { .bus = 0, .device = 0, .function = 0};
addr = grub_pci_make_address (dev, 36);
grub_pci_write_byte (addr++, 0x10);
grub_pci_write_byte (addr++, 0x11);
grub_pci_write_byte (addr++, 0x11);
grub_pci_write_byte (addr++, 0x11);
grub_pci_write_byte (addr, 0x11);
}
static void
fake_bios_data (int use_rom)
{
unsigned i;
void *acpi, *smbios;
grub_uint16_t *ebda_seg_ptr, *low_mem_ptr;
ebda_seg_ptr = (grub_uint16_t *) EBDA_SEG_ADDR;
low_mem_ptr = (grub_uint16_t *) LOW_MEM_ADDR;
if ((*ebda_seg_ptr) || (*low_mem_ptr))
return;
acpi = 0;
smbios = 0;
for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
{
grub_efi_guid_t *guid =
&grub_efi_system_table->configuration_table[i].vendor_guid;
if (! grub_memcmp (guid, &acpi2_guid, sizeof (grub_efi_guid_t)))
{
acpi = grub_efi_system_table->configuration_table[i].vendor_table;
grub_dprintf ("efi", "ACPI2: %p\n", acpi);
}
else if (! grub_memcmp (guid, &acpi_guid, sizeof (grub_efi_guid_t)))
{
void *t;
t = grub_efi_system_table->configuration_table[i].vendor_table;
if (! acpi)
acpi = t;
grub_dprintf ("efi", "ACPI: %p\n", t);
}
else if (! grub_memcmp (guid, &smbios_guid, sizeof (grub_efi_guid_t)))
{
smbios = grub_efi_system_table->configuration_table[i].vendor_table;
grub_dprintf ("efi", "SMBIOS: %p\n", smbios);
}
}
*ebda_seg_ptr = FAKE_EBDA_SEG;
*low_mem_ptr = (FAKE_EBDA_SEG >> 6);
*((grub_uint16_t *) (FAKE_EBDA_SEG << 4)) = 640 - *low_mem_ptr;
if (acpi)
grub_memcpy ((char *) ((FAKE_EBDA_SEG << 4) + 16), acpi, 1024 - 16);
if ((use_rom) && (smbios))
grub_memcpy ((char *) SBIOS_ADDR, (char *) smbios + 16, 16);
}
static grub_err_t
grub_cmd_fakebios (struct grub_command *cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)),
char *argv[] __attribute__ ((unused)))
{
if (enable_rom_area ())
{
fake_bios_data (1);
lock_rom_area ();
}
else
fake_bios_data (0);
return 0;
}
static grub_err_t
grub_cmd_loadbios (grub_command_t cmd __attribute__ ((unused)),
int argc, char *argv[])
{
grub_file_t file;
int size;
if (argc == 0)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no ROM image specified");
if (argc > 1)
{
file = grub_file_open (argv[1]);
if (! file)
return grub_errno;
if (file->size != 4)
grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid int10 dump size");
else
grub_file_read (file, (void *) 0x40, 4);
grub_file_close (file);
if (grub_errno)
return grub_errno;
}
file = grub_file_open (argv[0]);
if (! file)
return grub_errno;
size = file->size;
if ((size < 0x10000) || (size > 0x40000))
grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid bios dump size");
else if (enable_rom_area ())
{
grub_file_read (file, (void *) VBIOS_ADDR, size);
fake_bios_data (size <= 0x40000);
lock_rom_area ();
}
grub_file_close (file);
return grub_errno;
}
static grub_command_t cmd_fakebios, cmd_loadbios;
GRUB_MOD_INIT(loadbios)
{
cmd_fakebios = grub_register_command ("fakebios", grub_cmd_fakebios,
0, N_("Fake BIOS."));
cmd_loadbios = grub_register_command ("loadbios", grub_cmd_loadbios,
"BIOS_DUMP [INT10_DUMP]",
N_("Load BIOS dump."));
}
GRUB_MOD_FINI(loadbios)
{
grub_unregister_command (cmd_fakebios);
grub_unregister_command (cmd_loadbios);
}

96
commands/extcmd.c Normal file
View File

@ -0,0 +1,96 @@
/* extcmd.c - support extended command */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 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/mm.h>
#include <grub/list.h>
#include <grub/misc.h>
#include <grub/extcmd.h>
static grub_err_t
grub_extcmd_dispatcher (struct grub_command *cmd,
int argc, char **args)
{
int new_argc;
char **new_args;
struct grub_arg_option *parser;
struct grub_arg_list *state;
int maxargs = 0;
grub_err_t ret;
grub_extcmd_t ext;
ext = cmd->data;
parser = (struct grub_arg_option *) ext->options;
while (parser && (parser++)->doc)
maxargs++;
/* Set up the option state. */
state = grub_zalloc (sizeof (struct grub_arg_list) * maxargs);
if (grub_arg_parse (ext, argc, args, state, &new_args, &new_argc))
{
ext->state = state;
ret = (ext->func) (ext, new_argc, new_args);
grub_free (new_args);
}
else
ret = grub_errno;
grub_free (state);
return ret;
}
grub_extcmd_t
grub_register_extcmd (const char *name, grub_extcmd_func_t func,
unsigned flags, const char *summary,
const char *description,
const struct grub_arg_option *parser)
{
grub_extcmd_t ext;
grub_command_t cmd;
ext = (grub_extcmd_t) grub_malloc (sizeof (*ext));
if (! ext)
return 0;
cmd = grub_register_command_prio (name, grub_extcmd_dispatcher,
summary, description, 1);
if (! cmd)
{
grub_free (ext);
return 0;
}
cmd->flags = (flags | GRUB_COMMAND_FLAG_EXTCMD);
cmd->data = ext;
ext->cmd = cmd;
ext->func = func;
ext->options = parser;
ext->data = 0;
return ext;
}
void
grub_unregister_extcmd (grub_extcmd_t ext)
{
grub_unregister_command (ext->cmd);
grub_free (ext);
}

256
commands/gptsync.c Normal file
View File

@ -0,0 +1,256 @@
/* gptsync.c - fill the mbr based on gpt entries */
/* XXX: I don't know what to do if sector size isn't 512 bytes */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 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/command.h>
#include <grub/dl.h>
#include <grub/device.h>
#include <grub/disk.h>
#include <grub/msdos_partition.h>
#include <grub/partition.h>
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/fs.h>
#include <grub/i18n.h>
/* Convert a LBA address to a CHS address in the INT 13 format. */
/* Taken from grub1. */
/* XXX: use hardcoded geometry of C = 1024, H = 255, S = 63.
Is it a problem?
*/
static void
lba_to_chs (int lba, grub_uint8_t *cl, grub_uint8_t *ch,
grub_uint8_t *dh)
{
int cylinder, head, sector;
int sectors = 63, heads = 255, cylinders = 1024;
sector = lba % sectors + 1;
head = (lba / sectors) % heads;
cylinder = lba / (sectors * heads);
if (cylinder >= cylinders)
{
*cl = *ch = *dh = 0xff;
return;
}
*cl = sector | ((cylinder & 0x300) >> 2);
*ch = cylinder & 0xFF;
*dh = head;
}
static grub_err_t
grub_cmd_gptsync (grub_command_t cmd __attribute__ ((unused)),
int argc, char **args)
{
grub_device_t dev;
struct grub_msdos_partition_mbr mbr;
struct grub_partition *partition;
grub_disk_addr_t first_sector;
int numactive = 0;
if (argc < 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required");
if (argc > 4)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "only 3 partitions can be "
"in hybrid MBR");
if (args[0][0] == '(' && args[0][grub_strlen (args[0]) - 1] == ')')
{
args[0][grub_strlen (args[0]) - 1] = 0;
dev = grub_device_open (args[0] + 1);
args[0][grub_strlen (args[0])] = ')';
}
else
dev = grub_device_open (args[0]);
if (! dev)
return grub_errno;
if (! dev->disk)
{
grub_device_close (dev);
return grub_error (GRUB_ERR_BAD_ARGUMENT, "not a disk");
}
/* Read the protective MBR. */
if (grub_disk_read (dev->disk, 0, 0, sizeof (mbr), &mbr))
{
grub_device_close (dev);
return grub_errno;
}
/* Check if it is valid. */
if (mbr.signature != grub_cpu_to_le16 (GRUB_PC_PARTITION_SIGNATURE))
{
grub_device_close (dev);
return grub_error (GRUB_ERR_BAD_PART_TABLE, "no signature");
}
/* Make sure the MBR is a protective MBR and not a normal MBR. */
if (mbr.entries[0].type != GRUB_PC_PARTITION_TYPE_GPT_DISK)
{
grub_device_close (dev);
return grub_error (GRUB_ERR_BAD_PART_TABLE, "no GPT partition map found");
}
int i;
first_sector = dev->disk->total_sectors;
for (i = 1; i < argc; i++)
{
char *separator, csep = 0;
grub_uint8_t type;
separator = grub_strchr (args[i], '+');
if (! separator)
separator = grub_strchr (args[i], '-');
if (separator)
{
csep = *separator;
*separator = 0;
}
partition = grub_partition_probe (dev->disk, args[i]);
if (separator)
*separator = csep;
if (! partition)
{
grub_device_close (dev);
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no such partition");
}
if (partition->start + partition->len > 0xffffffff)
{
grub_device_close (dev);
return grub_error (GRUB_ERR_OUT_OF_RANGE,
"only partitions resding in the first 2TB "
"can be presen in hybrid MBR");
}
if (first_sector > partition->start)
first_sector = partition->start;
if (separator && *(separator + 1))
type = grub_strtoul (separator + 1, 0, 0);
else
{
grub_fs_t fs = 0;
dev->disk->partition = partition;
fs = grub_fs_probe (dev);
/* Unknown filesystem isn't fatal. */
if (grub_errno == GRUB_ERR_UNKNOWN_FS)
{
fs = 0;
grub_errno = GRUB_ERR_NONE;
}
if (fs && grub_strcmp (fs->name, "ntfs") == 0)
type = GRUB_PC_PARTITION_TYPE_NTFS;
else if (fs && grub_strcmp (fs->name, "fat") == 0)
/* FIXME: detect FAT16. */
type = GRUB_PC_PARTITION_TYPE_FAT32_LBA;
else if (fs && (grub_strcmp (fs->name, "hfsplus") == 0
|| grub_strcmp (fs->name, "hfs") == 0))
type = GRUB_PC_PARTITION_TYPE_HFS;
else
/* FIXME: detect more types. */
type = GRUB_PC_PARTITION_TYPE_EXT2FS;
dev->disk->partition = 0;
}
mbr.entries[i].flag = (csep == '+') ? 0x80 : 0;
if (csep == '+')
{
numactive++;
if (numactive == 2)
{
grub_device_close (dev);
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"only one partition can be active");
}
}
mbr.entries[i].type = type;
mbr.entries[i].start = grub_cpu_to_le32 (partition->start);
lba_to_chs (partition->start,
&(mbr.entries[i].start_sector),
&(mbr.entries[i].start_cylinder),
&(mbr.entries[i].start_head));
lba_to_chs (partition->start + partition->len - 1,
&(mbr.entries[i].end_sector),
&(mbr.entries[i].end_cylinder),
&(mbr.entries[i].end_head));
mbr.entries[i].length = grub_cpu_to_le32 (partition->len);
grub_free (partition);
}
for (; i < 4; i++)
grub_memset (&(mbr.entries[i]), 0, sizeof (mbr.entries[i]));
/* The protective partition. */
if (first_sector > 0xffffffff)
first_sector = 0xffffffff;
else
first_sector--;
mbr.entries[0].flag = 0;
mbr.entries[0].type = GRUB_PC_PARTITION_TYPE_GPT_DISK;
mbr.entries[0].start = grub_cpu_to_le32 (1);
lba_to_chs (1,
&(mbr.entries[0].start_sector),
&(mbr.entries[0].start_cylinder),
&(mbr.entries[0].start_head));
lba_to_chs (first_sector,
&(mbr.entries[0].end_sector),
&(mbr.entries[0].end_cylinder),
&(mbr.entries[0].end_head));
mbr.entries[0].length = grub_cpu_to_le32 (first_sector);
mbr.signature = grub_cpu_to_le16 (GRUB_PC_PARTITION_SIGNATURE);
if (grub_disk_write (dev->disk, 0, 0, sizeof (mbr), &mbr))
{
grub_device_close (dev);
return grub_errno;
}
grub_printf ("New MBR is written to '%s'\n", args[0]);
return GRUB_ERR_NONE;
}
static grub_command_t cmd;
GRUB_MOD_INIT(gptsync)
{
(void) mod; /* To stop warning. */
cmd = grub_register_command ("gptsync", grub_cmd_gptsync,
N_("DEVICE [PARTITION[+/-[TYPE]]] ..."),
N_("Fill hybrid MBR of GPT drive DEVICE. "
"specified partitions will be a part "
"of hybrid mbr. Up to 3 partitions are "
"allowed. TYPE is an MBR type. "
"+ means that partition is active. "
"Only one partition can be active."));
}
GRUB_MOD_FINI(gptsync)
{
grub_unregister_command (cmd);
}

View File

@ -1,7 +1,7 @@
/* halt.c - command to halt the computer. */ /* halt.c - command to halt the computer. */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2005,2007 Free Software Foundation, Inc. * Copyright (C) 2005,2007,2008 Free Software Foundation, Inc.
* *
* GRUB is free software: you can redistribute it and/or modify * GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -17,13 +17,13 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <grub/normal.h>
#include <grub/dl.h> #include <grub/dl.h>
#include <grub/command.h>
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/machine/kernel.h> #include <grub/i18n.h>
static grub_err_t static grub_err_t
grub_cmd_halt (struct grub_arg_list *state __attribute__ ((unused)), grub_cmd_halt (grub_command_t cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)), int argc __attribute__ ((unused)),
char **args __attribute__ ((unused))) char **args __attribute__ ((unused)))
{ {
@ -31,16 +31,16 @@ grub_cmd_halt (struct grub_arg_list *state __attribute__ ((unused)),
return 0; return 0;
} }
static grub_command_t cmd;
GRUB_MOD_INIT(ieee1275_halt) GRUB_MOD_INIT(halt)
{ {
(void)mod; /* To stop warning. */ cmd = grub_register_command ("halt", grub_cmd_halt,
grub_register_command ("halt", grub_cmd_halt, GRUB_COMMAND_FLAG_BOTH, 0, N_("Halts the computer. This command does"
"halt", "halts the computer. This command does not" " not work on all firmware implementations."));
" work on all firmware.", 0);
} }
GRUB_MOD_FINI(ieee1275_halt) GRUB_MOD_FINI(halt)
{ {
grub_unregister_command ("halt"); grub_unregister_command (cmd);
} }

101
commands/handler.c Normal file
View File

@ -0,0 +1,101 @@
/* handler.c - commands to list or select handlers */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 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/dl.h>
#include <grub/err.h>
#include <grub/misc.h>
#include <grub/term.h>
#include <grub/handler.h>
#include <grub/command.h>
#include <grub/i18n.h>
static grub_err_t
grub_cmd_handler (struct grub_command *cmd __attribute__ ((unused)),
int argc, char **args)
{
void *curr_item = 0;
grub_handler_class_t head;
auto int list_item (grub_named_list_t item);
int list_item (grub_named_list_t item)
{
if (item == curr_item)
grub_putchar ('*');
grub_printf ("%s\n", item->name);
return 0;
}
head = grub_handler_class_list;
if (argc == 0)
{
grub_list_iterate (GRUB_AS_LIST (head), (grub_list_hook_t) list_item);
}
else
{
char *class_name;
grub_handler_class_t class;
class_name = args[0];
argc--;
args++;
class = grub_named_list_find (GRUB_AS_NAMED_LIST (head), class_name);
if (! class)
return grub_error (GRUB_ERR_FILE_NOT_FOUND, "class not found");
if (argc == 0)
{
curr_item = class->cur_handler;
grub_list_iterate (GRUB_AS_LIST (class->handler_list),
(grub_list_hook_t) list_item);
}
else
{
grub_handler_t handler;
handler =
grub_named_list_find (GRUB_AS_NAMED_LIST (class->handler_list),
args[0]);
if (! handler)
return grub_error (GRUB_ERR_FILE_NOT_FOUND, "handler not found");
grub_handler_set_current (class, handler);
}
}
return 0;
}
static grub_command_t cmd_handler;
GRUB_MOD_INIT(handler)
{
cmd_handler =
grub_register_command ("handler", grub_cmd_handler,
N_("[class [handler]]"),
N_("List or select a handler."));
}
GRUB_MOD_FINI(handler)
{
grub_unregister_command (cmd_handler);
}

278
commands/hashsum.c Normal file
View File

@ -0,0 +1,278 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 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/dl.h>
#include <grub/extcmd.h>
#include <grub/file.h>
#include <grub/disk.h>
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/crypto.h>
#include <grub/normal.h>
static const struct grub_arg_option options[] = {
{"hash", 'h', 0, "Specify hash to use.", "HASH", ARG_TYPE_STRING},
{"check", 'c', 0, "Check hash list file.", "FILE", ARG_TYPE_STRING},
{"prefix", 'p', 0, "Base directory for hash list.", "DIRECTORY",
ARG_TYPE_STRING},
{"keep-going", 'k', 0, "Don't stop after first error.", 0, 0},
{0, 0, 0, 0, 0, 0}
};
struct { const char *name; const char *hashname; } aliases[] =
{
{"sha256sum", "sha256"},
{"sha512sum", "sha512"},
{"md5sum", "md5"},
};
static inline int
hextoval (char c)
{
if (c >= '0' && c <= '9')
return c - '0';
if (c >= 'a' && c <= 'f')
return c - 'a' + 10;
if (c >= 'A' && c <= 'F')
return c - 'A' + 10;
return -1;
}
static grub_err_t
hash_file (grub_file_t file, const gcry_md_spec_t *hash, void *result)
{
grub_uint8_t context[hash->contextsize];
char *readbuf[4096];
grub_memset (context, 0, sizeof (context));
hash->init (context);
while (1)
{
grub_ssize_t r;
r = grub_file_read (file, readbuf, sizeof (readbuf));
if (r < 0)
return grub_errno;
if (r == 0)
break;
hash->write (context, readbuf, r);
}
hash->final (context);
grub_memcpy (result, hash->read (context), hash->mdlen);
return GRUB_ERR_NONE;
}
static grub_err_t
check_list (const gcry_md_spec_t *hash, const char *hashfilename,
const char *prefix, int keep)
{
grub_file_t hashlist, file;
char *buf = NULL;
grub_uint8_t expected[hash->mdlen];
grub_uint8_t actual[hash->mdlen];
grub_err_t err;
unsigned i;
unsigned unread = 0, mismatch = 0;
hashlist = grub_file_open (hashfilename);
if (!hashlist)
return grub_errno;
while (grub_free (buf), (buf = grub_file_getline (hashlist)))
{
const char *p = buf;
for (i = 0; i < hash->mdlen; i++)
{
int high, low;
high = hextoval (*p++);
low = hextoval (*p++);
if (high < 0 || low < 0)
return grub_error (GRUB_ERR_BAD_FILE_TYPE, "invalid hash list");
expected[i] = (high << 4) | low;
}
if (*p++ != ' ' || *p++ != ' ')
return grub_error (GRUB_ERR_BAD_FILE_TYPE, "invalid hash list");
if (prefix)
{
char *filename;
filename = grub_malloc (grub_strlen (prefix)
+ grub_strlen (p) + 2);
if (!filename)
return grub_errno;
grub_sprintf (filename, "%s/%s", prefix, p);
file = grub_file_open (filename);
grub_free (filename);
}
else
file = grub_file_open (p);
if (!file)
{
grub_file_close (hashlist);
grub_free (buf);
return grub_errno;
}
err = hash_file (file, hash, actual);
grub_file_close (file);
if (err)
{
grub_printf ("%s: READ ERROR\n", p);
if (!keep)
{
grub_file_close (hashlist);
grub_free (buf);
return err;
}
grub_print_error ();
grub_errno = GRUB_ERR_NONE;
unread++;
continue;
}
if (grub_crypto_memcmp (expected, actual, hash->mdlen) != 0)
{
grub_printf ("%s: HASH MISMATCH\n", p);
if (!keep)
{
grub_file_close (hashlist);
grub_free (buf);
return grub_error (GRUB_ERR_TEST_FAILURE,
"hash of '%s' mismatches", p);
}
mismatch++;
continue;
}
grub_printf ("%s: OK\n", p);
}
if (mismatch || unread)
return grub_error (GRUB_ERR_TEST_FAILURE,
"%d files couldn't be read and hash "
"of %d files mismatches", unread, mismatch);
return GRUB_ERR_NONE;
}
static grub_err_t
grub_cmd_hashsum (struct grub_extcmd *cmd,
int argc, char **args)
{
struct grub_arg_list *state = cmd->state;
const char *hashname = NULL;
const char *prefix = NULL;
const gcry_md_spec_t *hash;
unsigned i;
int keep = state[3].set;
unsigned unread = 0;
for (i = 0; i < ARRAY_SIZE (aliases); i++)
if (grub_strcmp (cmd->cmd->name, aliases[i].name) == 0)
hashname = aliases[i].hashname;
if (state[0].set)
hashname = state[0].arg;
if (!hashname)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no hash specified");
hash = grub_crypto_lookup_md_by_name (hashname);
if (!hash)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown hash");
if (state[2].set)
prefix = state[2].arg;
if (state[1].set)
{
if (argc != 0)
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"--check is incompatible with file list");
return check_list (hash, state[1].arg, prefix, keep);
}
for (i = 0; i < (unsigned) argc; i++)
{
grub_uint8_t result[hash->mdlen];
grub_file_t file;
grub_err_t err;
unsigned j;
file = grub_file_open (args[i]);
if (!file)
{
if (!keep)
return grub_errno;
grub_print_error ();
grub_errno = GRUB_ERR_NONE;
unread++;
continue;
}
err = hash_file (file, hash, result);
grub_file_close (file);
if (err)
{
if (!keep)
return err;
grub_print_error ();
grub_errno = GRUB_ERR_NONE;
unread++;
continue;
}
for (j = 0; j < hash->mdlen; j++)
grub_printf ("%02x", result[j]);
grub_printf (" %s\n", args[i]);
}
if (unread)
return grub_error (GRUB_ERR_TEST_FAILURE, "%d files couldn't be read.",
unread);
return GRUB_ERR_NONE;
}
static grub_extcmd_t cmd, cmd_md5, cmd_sha256, cmd_sha512;
GRUB_MOD_INIT(hashsum)
{
cmd = grub_register_extcmd ("hashsum", grub_cmd_hashsum,
GRUB_COMMAND_FLAG_BOTH,
"hashsum -h HASH [-c FILE [-p PREFIX]] "
"[FILE1 [FILE2 ...]]",
"Compute or check hash checksum.",
options);
cmd_md5 = grub_register_extcmd ("md5sum", grub_cmd_hashsum,
GRUB_COMMAND_FLAG_BOTH,
"md5sum [-c FILE [-p PREFIX]] "
"[FILE1 [FILE2 ...]]",
"Compute or check hash checksum.",
options);
cmd_sha256 = grub_register_extcmd ("sha256sum", grub_cmd_hashsum,
GRUB_COMMAND_FLAG_BOTH,
"sha256sum [-c FILE [-p PREFIX]] "
"[FILE1 [FILE2 ...]]",
"Compute or check hash checksum.",
options);
cmd_sha512 = grub_register_extcmd ("sha512sum", grub_cmd_hashsum,
GRUB_COMMAND_FLAG_BOTH,
"sha512sum [-c FILE [-p PREFIX]] "
"[FILE1 [FILE2 ...]]",
"Compute or check hash checksum.",
options);
}
GRUB_MOD_FINI(hashsum)
{
grub_unregister_extcmd (cmd);
grub_unregister_extcmd (cmd_md5);
grub_unregister_extcmd (cmd_sha256);
grub_unregister_extcmd (cmd_sha512);
}

421
commands/hdparm.c Normal file
View File

@ -0,0 +1,421 @@
/* hdparm.c - command to get/set ATA disk parameters. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 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/ata.h>
#include <grub/disk.h>
#include <grub/dl.h>
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/lib/hexdump.h>
#include <grub/extcmd.h>
#include <grub/i18n.h>
static const struct grub_arg_option options[] = {
{"apm", 'B', 0, N_("Set Advanced Power Management\n"
"(1=low, ..., 254=high, 255=off)."),
0, ARG_TYPE_INT},
{"power", 'C', 0, N_("Check power mode."), 0, ARG_TYPE_NONE},
{"security-freeze", 'F', 0, N_("Freeze ATA security settings until reset."),
0, ARG_TYPE_NONE},
{"health", 'H', 0, N_("Check SMART health status."), 0, ARG_TYPE_NONE},
{"aam", 'M', 0, N_("Set Automatic Acoustic Management\n"
"(0=off, 128=quiet, ..., 254=fast)."),
0, ARG_TYPE_INT},
{"standby-timeout", 'S', 0, N_("Set standby timeout\n"
"(0=off, 1=5s, 2=10s, ..., 240=20m, 241=30m, ...)."),
0, ARG_TYPE_INT},
{"standby", 'y', 0, N_("Set drive to standby mode."), 0, ARG_TYPE_NONE},
{"sleep", 'Y', 0, N_("Set drive to sleep mode."), 0, ARG_TYPE_NONE},
{"identify", 'i', 0, N_("Print drive identity and settings."),
0, ARG_TYPE_NONE},
{"dumpid", 'I', 0, N_("Dump contents of ATA IDENTIFY sector."),
0, ARG_TYPE_NONE},
{"smart", -1, 0, N_("Disable/enable SMART (0/1)."), 0, ARG_TYPE_INT},
{"quiet", 'q', 0, N_("Do not print messages."), 0, ARG_TYPE_NONE},
{0, 0, 0, 0, 0, 0}
};
enum grub_ata_smart_commands
{
GRUB_ATA_FEAT_SMART_ENABLE = 0xd8,
GRUB_ATA_FEAT_SMART_DISABLE = 0xd9,
GRUB_ATA_FEAT_SMART_STATUS = 0xda,
};
static int quiet = 0;
static grub_err_t
grub_hdparm_do_ata_cmd (grub_disk_t disk, grub_uint8_t cmd,
grub_uint8_t features, grub_uint8_t sectors,
void * buffer, int size)
{
struct grub_disk_ata_pass_through_parms apt;
grub_memset (&apt, 0, sizeof (apt));
apt.taskfile[GRUB_ATA_REG_CMD] = cmd;
apt.taskfile[GRUB_ATA_REG_FEATURES] = features;
apt.taskfile[GRUB_ATA_REG_SECTORS] = sectors;
apt.buffer = buffer;
apt.size = size;
if (grub_disk_ata_pass_through (disk, &apt))
return grub_errno;
return GRUB_ERR_NONE;
}
static int
grub_hdparm_do_check_powermode_cmd (grub_disk_t disk)
{
struct grub_disk_ata_pass_through_parms apt;
grub_memset (&apt, 0, sizeof (apt));
apt.taskfile[GRUB_ATA_REG_CMD] = GRUB_ATA_CMD_CHECK_POWER_MODE;
if (grub_disk_ata_pass_through (disk, &apt))
return -1;
return apt.taskfile[GRUB_ATA_REG_SECTORS];
}
static int
grub_hdparm_do_smart_cmd (grub_disk_t disk, grub_uint8_t features)
{
struct grub_disk_ata_pass_through_parms apt;
grub_memset (&apt, 0, sizeof (apt));
apt.taskfile[GRUB_ATA_REG_CMD] = GRUB_ATA_CMD_SMART;
apt.taskfile[GRUB_ATA_REG_FEATURES] = features;
apt.taskfile[GRUB_ATA_REG_LBAMID] = 0x4f;
apt.taskfile[GRUB_ATA_REG_LBAHIGH] = 0xc2;
if (grub_disk_ata_pass_through (disk, &apt))
return -1;
if (features == GRUB_ATA_FEAT_SMART_STATUS)
{
if ( apt.taskfile[GRUB_ATA_REG_LBAMID] == 0x4f
&& apt.taskfile[GRUB_ATA_REG_LBAHIGH] == 0xc2)
return 0; /* Good SMART status. */
else if ( apt.taskfile[GRUB_ATA_REG_LBAMID] == 0xf4
&& apt.taskfile[GRUB_ATA_REG_LBAHIGH] == 0x2c)
return 1; /* Bad SMART status. */
else
return -1;
}
return 0;
}
static grub_err_t
grub_hdparm_simple_cmd (const char * msg,
grub_disk_t disk, grub_uint8_t cmd)
{
if (! quiet && msg)
grub_printf ("%s", msg);
grub_err_t err = grub_hdparm_do_ata_cmd (disk, cmd, 0, 0, NULL, 0);
if (! quiet && msg)
grub_printf ("%s\n", ! err ? "" : ": not supported");
return err;
}
static grub_err_t
grub_hdparm_set_val_cmd (const char * msg, int val,
grub_disk_t disk, grub_uint8_t cmd,
grub_uint8_t features, grub_uint8_t sectors)
{
if (! quiet && msg && *msg)
{
if (val >= 0)
grub_printf ("Set %s to %d", msg, val);
else
grub_printf ("Disable %s", msg);
}
grub_err_t err = grub_hdparm_do_ata_cmd (disk, cmd, features, sectors,
NULL, 0);
if (! quiet && msg)
grub_printf ("%s\n", ! err ? "" : ": not supported");
return err;
}
static const char *
le16_to_char (char *dest, const grub_uint16_t * src16, unsigned bytes)
{
grub_uint16_t * dest16 = (grub_uint16_t *) dest;
unsigned i;
for (i = 0; i < bytes / 2; i++)
dest16[i] = grub_be_to_cpu16 (src16[i]);
return dest;
}
static void
grub_hdparm_print_identify (const char * idbuf)
{
const grub_uint16_t * idw = (const grub_uint16_t *) idbuf;
/* Print identity strings. */
char tmp[40];
grub_printf ("Model: \"%.40s\"\n", le16_to_char (tmp, &idw[27], 40));
grub_printf ("Firmware: \"%.8s\"\n", le16_to_char (tmp, &idw[23], 8));
grub_printf ("Serial: \"%.20s\"\n", le16_to_char (tmp, &idw[10], 20));
/* Print AAM, APM and SMART settings. */
grub_uint16_t features1 = grub_le_to_cpu16 (idw[82]);
grub_uint16_t features2 = grub_le_to_cpu16 (idw[83]);
grub_uint16_t enabled1 = grub_le_to_cpu16 (idw[85]);
grub_uint16_t enabled2 = grub_le_to_cpu16 (idw[86]);
grub_printf ("Automatic Acoustic Management: ");
if (features2 & 0x0200)
{
if (enabled2 & 0x0200)
{
grub_uint16_t aam = grub_le_to_cpu16 (idw[94]);
grub_printf ("%u (128=quiet, ..., 254=fast, recommended=%u)\n",
aam & 0xff, (aam >> 8) & 0xff);
}
else
grub_printf ("disabled\n");
}
else
grub_printf ("not supported\n");
grub_printf ("Advanced Power Management: ");
if (features2 & 0x0008)
{
if (enabled2 & 0x0008)
grub_printf ("%u (1=low, ..., 254=high)\n",
grub_le_to_cpu16 (idw[91]) & 0xff);
else
grub_printf ("disabled\n");
}
else
grub_printf ("not supported\n");
grub_printf ("SMART Feature Set: ");
if (features1 & 0x0001)
grub_printf ("%sabled\n", (enabled1 & 0x0001 ? "en" : "dis"));
else
grub_printf ("not supported\n");
/* Print security settings. */
grub_uint16_t security = grub_le_to_cpu16 (idw[128]);
grub_printf ("ATA Security: ");
if (security & 0x0001)
grub_printf ("%s, %s, %s, %s\n",
(security & 0x0002 ? "ENABLED" : "disabled"),
(security & 0x0004 ? "**LOCKED**" : "not locked"),
(security & 0x0008 ? "frozen" : "NOT FROZEN"),
(security & 0x0010 ? "COUNT EXPIRED" : "count not expired"));
else
grub_printf ("not supported\n");
}
static void
grub_hdparm_print_standby_tout (int timeout)
{
if (timeout == 0)
grub_printf ("off");
else if (timeout <= 252 || timeout == 255)
{
int h = 0, m = 0 , s = 0;
if (timeout == 255)
{
m = 21;
s = 15;
}
else if (timeout == 252)
m = 21;
else if (timeout <= 240)
{
s = timeout * 5;
m = s / 60;
s %= 60;
}
else
{
m = (timeout - 240) * 30;
h = m / 60;
m %= 60;
}
grub_printf ("%02d:%02d:%02d", h, m, s);
}
else
grub_printf ("invalid or vendor-specific");
}
static int get_int_arg (const struct grub_arg_list *state)
{
return (state->set ? (int)grub_strtoul (state->arg, 0, 0) : -1);
}
static grub_err_t
grub_cmd_hdparm (grub_extcmd_t cmd, int argc, char **args) // state????
{
struct grub_arg_list *state = cmd->state;
/* Check command line. */
if (argc != 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "missing device name argument");
grub_size_t len = grub_strlen (args[0]);
if (! (args[0][0] == '(' && args[0][len - 1] == ')'))
return grub_error (GRUB_ERR_BAD_ARGUMENT, "argument is not a device name");
args[0][len - 1] = 0;
if (! grub_disk_ata_pass_through)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "ATA pass through not available");
int i = 0;
int apm = get_int_arg (&state[i++]);
int power = state[i++].set;
int sec_freeze = state[i++].set;
int health = state[i++].set;
int aam = get_int_arg (&state[i++]);
int standby_tout = get_int_arg (&state[i++]);
int standby_now = state[i++].set;
int sleep_now = state[i++].set;
int ident = state[i++].set;
int dumpid = state[i++].set;
int enable_smart = get_int_arg (&state[i++]);
quiet = state[i++].set;
/* Open disk. */
grub_disk_t disk = grub_disk_open (&args[0][1]);
if (! disk)
return grub_errno;
if (disk->partition)
{
grub_disk_close (disk);
return grub_error (GRUB_ERR_BAD_ARGUMENT, "partition not allowed");
}
/* Change settings. */
if (aam >= 0)
grub_hdparm_set_val_cmd ("Automatic Acoustic Management", (aam ? aam : -1),
disk, GRUB_ATA_CMD_SET_FEATURES, (aam ? 0x42 : 0xc2), aam);
if (apm >= 0)
grub_hdparm_set_val_cmd ("Advanced Power Management",
(apm != 255 ? apm : -1), disk, GRUB_ATA_CMD_SET_FEATURES,
(apm != 255 ? 0x05 : 0x85), (apm != 255 ? apm : 0));
if (standby_tout >= 0)
{
if (! quiet)
{
grub_printf ("Set standby timeout to %d (", standby_tout);
grub_hdparm_print_standby_tout (standby_tout);
grub_printf (")");
}
/* The IDLE cmd sets disk to idle mode and configures standby timer. */
grub_hdparm_set_val_cmd ("", -1, disk, GRUB_ATA_CMD_IDLE, 0, standby_tout);
}
if (enable_smart >= 0)
{
if (! quiet)
grub_printf ("%sable SMART operations", (enable_smart ? "En" : "Dis"));
int err = grub_hdparm_do_smart_cmd (disk, (enable_smart ?
GRUB_ATA_FEAT_SMART_ENABLE : GRUB_ATA_FEAT_SMART_DISABLE));
if (! quiet)
grub_printf ("%s\n", err ? ": not supported" : "");
}
if (sec_freeze)
grub_hdparm_simple_cmd ("Freeze security settings", disk,
GRUB_ATA_CMD_SECURITY_FREEZE_LOCK);
/* Print/dump IDENTIFY. */
if (ident || dumpid)
{
char buf[GRUB_DISK_SECTOR_SIZE];
if (grub_hdparm_do_ata_cmd (disk, GRUB_ATA_CMD_IDENTIFY_DEVICE,
0, 0, buf, sizeof (buf)))
grub_printf ("Cannot read ATA IDENTIFY data\n");
else
{
if (ident)
grub_hdparm_print_identify (buf);
if (dumpid)
hexdump (0, buf, sizeof (buf));
}
}
/* Check power mode. */
if (power)
{
grub_printf ("Disk power mode is: ");
int mode = grub_hdparm_do_check_powermode_cmd (disk);
if (mode < 0)
grub_printf ("unknown\n");
else
grub_printf ("%s (0x%02x)\n",
(mode == 0xff ? "active/idle" :
mode == 0x80 ? "idle" :
mode == 0x00 ? "standby" : "unknown"), mode);
}
/* Check health. */
int status = 0;
if (health)
{
if (! quiet)
grub_printf ("SMART status is: ");
int err = grub_hdparm_do_smart_cmd (disk, GRUB_ATA_FEAT_SMART_STATUS);
if (! quiet)
grub_printf ("%s\n", (err < 0 ? "unknown" :
err == 0 ? "OK" : "*BAD*"));
status = (err > 0);
}
/* Change power mode. */
if (standby_now)
grub_hdparm_simple_cmd ("Set disk to standby mode", disk,
GRUB_ATA_CMD_STANDBY_IMMEDIATE);
if (sleep_now)
grub_hdparm_simple_cmd ("Set disk to sleep mode", disk,
GRUB_ATA_CMD_SLEEP);
grub_disk_close (disk);
grub_errno = GRUB_ERR_NONE;
return status;
}
static grub_extcmd_t cmd;
GRUB_MOD_INIT(hdparm)
{
cmd = grub_register_extcmd ("hdparm", grub_cmd_hdparm,
GRUB_COMMAND_FLAG_BOTH,
N_("[OPTIONS] DISK"),
N_("Get/set ATA disk parameters."), options);
}
GRUB_MOD_FINI(hdparm)
{
grub_unregister_extcmd (cmd);
}

View File

@ -1,7 +1,7 @@
/* help.c - command to show a help text. */ /* help.c - command to show a help text. */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2005,2007 Free Software Foundation, Inc. * Copyright (C) 2005,2007,2008,2009 Free Software Foundation, Inc.
* *
* GRUB is free software: you can redistribute it and/or modify * GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -17,90 +17,129 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <grub/normal.h>
#include <grub/dl.h> #include <grub/dl.h>
#include <grub/arg.h>
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/term.h>
/* XXX: This has to be changed into a function so the screen can be #include <grub/extcmd.h>
optimally used. */ #include <grub/i18n.h>
#define TERM_WIDTH 80 #include <grub/mm.h>
#include <grub/normal.h>
#include <grub/charset.h>
static grub_err_t static grub_err_t
grub_cmd_help (struct grub_arg_list *state __attribute__ ((unused)), int argc, grub_cmd_help (grub_extcmd_t ext __attribute__ ((unused)), int argc,
char **args) char **args)
{ {
int cnt = 0; int cnt = 0;
char *currarg; char *currarg;
auto int print_command_info (grub_command_t cmd); auto int print_command_info (grub_command_t cmd);
auto int print_command_help (grub_command_t cmd); auto int print_command_help (grub_command_t cmd);
int print_command_info (grub_command_t cmd) int print_command_info (grub_command_t cmd)
{ {
if (grub_command_find (cmd->name)) if ((cmd->prio & GRUB_PRIO_LIST_FLAG_ACTIVE) &&
(cmd->flags & GRUB_COMMAND_FLAG_CMDLINE))
{ {
if (cmd->flags & GRUB_COMMAND_FLAG_CMDLINE) struct grub_term_output *term;
{ const char *summary_translated = _(cmd->summary);
char description[TERM_WIDTH / 2]; char *command_help;
int desclen = grub_strlen (cmd->summary); grub_uint32_t *unicode_command_help;
grub_uint32_t *unicode_last_position;
/* Make a string with a length of TERM_WIDTH / 2 - 1 filled
with the description followed by spaces. */ command_help = grub_malloc (grub_strlen (cmd->name) +
grub_memset (description, ' ', TERM_WIDTH / 2 - 1); sizeof (" ") - 1 +
description[TERM_WIDTH / 2 - 1] = '\0'; grub_strlen (summary_translated));
grub_memcpy (description, cmd->summary,
(desclen < TERM_WIDTH / 2 - 1 grub_sprintf(command_help, "%s %s", cmd->name, summary_translated);
? desclen : TERM_WIDTH / 2 - 1));
grub_utf8_to_ucs4_alloc (command_help, &unicode_command_help,
grub_printf ("%s%s", description, (cnt++) % 2 ? "\n" : " "); &unicode_last_position);
}
FOR_ACTIVE_TERM_OUTPUTS(term)
{
unsigned stringwidth;
grub_uint32_t *unicode_last_screen_position;
unicode_last_screen_position = unicode_command_help;
stringwidth = 0;
while (unicode_last_screen_position < unicode_last_position &&
stringwidth < ((grub_term_width (term) / 2) - 2))
{
stringwidth
+= grub_term_getcharwidth (term,
*unicode_last_screen_position);
unicode_last_screen_position++;
}
grub_print_ucs4 (unicode_command_help,
unicode_last_screen_position, term);
if (!(cnt % 2))
grub_print_spaces (term, grub_term_width (term) / 2
- stringwidth);
}
if (cnt % 2)
grub_printf ("\n");
cnt++;
grub_free (command_help);
grub_free (unicode_command_help);
} }
return 0; return 0;
} }
int print_command_help (grub_command_t cmd) int print_command_help (grub_command_t cmd)
{ {
if (grub_command_find (cmd->name)) if (cmd->prio & GRUB_PRIO_LIST_FLAG_ACTIVE)
{ {
if (! grub_strncmp (cmd->name, currarg, grub_strlen (currarg))) if (! grub_strncmp (cmd->name, currarg, grub_strlen (currarg)))
{ {
if (cnt++ > 0) if (cnt++ > 0)
grub_printf ("\n\n"); grub_printf ("\n\n");
grub_arg_show_help (cmd); if (cmd->flags & GRUB_COMMAND_FLAG_EXTCMD)
grub_arg_show_help ((grub_extcmd_t) cmd->data);
else
grub_printf ("%s %s %s\n%s\b", _("Usage:"), cmd->name, _(cmd->summary),
_(cmd->description));
} }
} }
return 0; return 0;
} }
if (argc == 0) if (argc == 0)
grub_iterate_commands (print_command_info); {
grub_command_iterate (print_command_info);
if (!(cnt % 2))
grub_printf ("\n");
}
else else
{ {
int i; int i;
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
{ {
currarg = args[i]; currarg = args[i];
grub_iterate_commands (print_command_help); grub_command_iterate (print_command_help);
} }
} }
return 0; return 0;
} }
static grub_extcmd_t cmd;
GRUB_MOD_INIT(help) GRUB_MOD_INIT(help)
{ {
(void)mod; /* To stop warning. */ cmd = grub_register_extcmd ("help", grub_cmd_help,
grub_register_command ("help", grub_cmd_help, GRUB_COMMAND_FLAG_CMDLINE, GRUB_COMMAND_FLAG_CMDLINE,
"help [PATTERN ...]", "Show a help message.", 0); N_("[PATTERN ...]"),
N_("Show a help message."), 0);
} }
GRUB_MOD_FINI(help) GRUB_MOD_FINI(help)
{ {
grub_unregister_command ("help"); grub_unregister_extcmd (cmd);
} }

View File

@ -1,7 +1,7 @@
/* hexdump.c - command to dump the contents of a file or memory */ /* hexdump.c - command to dump the contents of a file or memory */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2007 Free Software Foundation, Inc. * Copyright (C) 2007,2008,2009 Free Software Foundation, Inc.
* *
* GRUB is free software: you can redistribute it and/or modify * GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -17,91 +17,80 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <grub/normal.h>
#include <grub/dl.h> #include <grub/dl.h>
#include <grub/arg.h>
#include <grub/file.h> #include <grub/file.h>
#include <grub/disk.h> #include <grub/disk.h>
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/gzio.h> #include <grub/gzio.h>
#include <grub/hexdump.h> #include <grub/lib/hexdump.h>
#include <grub/extcmd.h>
#include <grub/i18n.h>
static const struct grub_arg_option options[] = { static const struct grub_arg_option options[] = {
{"skip", 's', 0, "skip offset bytes from the beginning of file.", 0, {"skip", 's', 0, N_("Skip offset bytes from the beginning of file."), 0,
ARG_TYPE_INT}, ARG_TYPE_INT},
{"length", 'n', 0, "read only length bytes", 0, ARG_TYPE_INT}, {"length", 'n', 0, N_("Read only LENGTH bytes."), 0, ARG_TYPE_INT},
{0, 0, 0, 0, 0, 0} {0, 0, 0, 0, 0, 0}
}; };
void
hexdump (unsigned long bse, char *buf, int len)
{
int pos;
char line[80];
while (len > 0)
{
int cnt, i;
pos = grub_sprintf (line, "%08lx ", bse);
cnt = 16;
if (cnt > len)
cnt = len;
for (i = 0; i < cnt; i++)
{
pos += grub_sprintf (&line[pos], "%02x ", (unsigned char) buf[i]);
if ((i & 7) == 7)
line[pos++] = ' ';
}
for (; i < 16; i++)
{
pos += grub_sprintf (&line[pos], " ");
if ((i & 7) == 7)
line[pos++] = ' ';
}
line[pos++] = '|';
for (i = 0; i < cnt; i++)
line[pos++] = ((buf[i] >= 32) && (buf[i] < 127)) ? buf[i] : '.';
line[pos++] = '|';
line[pos] = 0;
grub_printf ("%s\n", line);
bse += 16;
buf += 16;
len -= cnt;
}
}
static grub_err_t static grub_err_t
grub_cmd_hexdump (struct grub_arg_list *state, int argc, char **args) grub_cmd_hexdump (grub_extcmd_t cmd, int argc, char **args)
{ {
grub_file_t file; struct grub_arg_list *state = cmd->state;
char buf[GRUB_DISK_SECTOR_SIZE]; char buf[GRUB_DISK_SECTOR_SIZE * 4];
grub_ssize_t size, length; grub_ssize_t size, length;
unsigned long skip; grub_disk_addr_t skip;
int is_file; int namelen;
if (argc != 1) if (argc != 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required"); return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required");
skip = (state[0].set) ? grub_strtoul (state[0].arg, 0, 0) : 0; namelen = grub_strlen (args[0]);
length = (state[1].set) ? grub_strtoul (state[1].arg, 0, 0) : 0; skip = (state[0].set) ? grub_strtoull (state[0].arg, 0, 0) : 0;
length = (state[1].set) ? grub_strtoul (state[1].arg, 0, 0) : 256;
is_file = (grub_strcmp (args[0], "(mem)")); if (!grub_strcmp (args[0], "(mem)"))
if ((!is_file) && (!length)) hexdump (skip, (char *) (grub_addr_t) skip, length);
length = 256; else if ((args[0][0] == '(') && (args[0][namelen - 1] == ')'))
if (is_file)
{ {
grub_disk_t disk;
grub_disk_addr_t sector;
grub_size_t ofs;
args[0][namelen - 1] = 0;
disk = grub_disk_open (&args[0][1]);
if (! disk)
return 0;
sector = (skip >> (GRUB_DISK_SECTOR_BITS + 2)) * 4;
ofs = skip & (GRUB_DISK_SECTOR_SIZE * 4 - 1);
while (length)
{
grub_size_t len;
len = length;
if (len > sizeof (buf))
len = sizeof (buf);
if (grub_disk_read (disk, sector, ofs, len, buf))
break;
hexdump (skip, buf, len);
ofs = 0;
skip += len;
length -= len;
sector += 4;
}
grub_disk_close (disk);
}
else
{
grub_file_t file;
file = grub_gzfile_open (args[0], 1); file = grub_gzfile_open (args[0], 1);
if (!file) if (! file)
return 0; return 0;
file->offset = skip; file->offset = skip;
@ -123,22 +112,22 @@ grub_cmd_hexdump (struct grub_arg_list *state, int argc, char **args)
grub_file_close (file); grub_file_close (file);
} }
else
hexdump (skip, (char *) skip, length);
return 0; return 0;
} }
static grub_extcmd_t cmd;
GRUB_MOD_INIT (hexdump) GRUB_MOD_INIT (hexdump)
{ {
(void) mod; /* To stop warning. */ cmd = grub_register_extcmd ("hexdump", grub_cmd_hexdump,
grub_register_command ("hexdump", grub_cmd_hexdump, GRUB_COMMAND_FLAG_BOTH, GRUB_COMMAND_FLAG_BOTH,
"hexdump [ -s offset ] [-n length] { FILE | (mem) }", N_("[OPTIONS] FILE_OR_DEVICE"),
"Dump the contents of a file or memory.", options); N_("Dump the contents of a file or memory."),
options);
} }
GRUB_MOD_FINI (hexdump) GRUB_MOD_FINI (hexdump)
{ {
grub_unregister_command ("hexdump"); grub_unregister_extcmd (cmd);
} }

View File

@ -1,7 +1,7 @@
/* cpuid.c - test for CPU features */ /* cpuid.c - test for CPU features */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2006, 2007 Free Software Foundation, Inc. * Copyright (C) 2006, 2007, 2009 Free Software Foundation, Inc.
* Based on gcc/gcc/config/i386/driver-i386.c * Based on gcc/gcc/config/i386/driver-i386.c
* *
* GRUB is free software: you can redistribute it and/or modify * GRUB is free software: you can redistribute it and/or modify
@ -18,41 +18,46 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <grub/normal.h>
#include <grub/dl.h> #include <grub/dl.h>
#include <grub/arg.h>
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/mm.h> #include <grub/mm.h>
#include <grub/env.h> #include <grub/env.h>
#include <grub/command.h>
#include <grub/extcmd.h>
#include <grub/i386/cpuid.h>
#include <grub/i18n.h>
#define cpuid(num,a,b,c,d) \ #define cpuid(num,a,b,c,d) \
asm volatile ("xchgl %%ebx, %1; cpuid; xchgl %%ebx, %1" \ asm volatile ("xchgl %%ebx, %1; cpuid; xchgl %%ebx, %1" \
: "=a" (a), "=r" (b), "=c" (c), "=d" (d) \ : "=a" (a), "=r" (b), "=c" (c), "=d" (d) \
: "0" (num)) : "0" (num))
#define bit_LM (1 << 29)
unsigned char has_longmode = 0;
static const struct grub_arg_option options[] = static const struct grub_arg_option options[] =
{ {
{"long-mode", 'l', 0, "check for long mode flag (default)", 0, 0}, {"long-mode", 'l', 0, N_("Check for long mode flag (default)."), 0, 0},
{0, 0, 0, 0, 0, 0} {0, 0, 0, 0, 0, 0}
}; };
#define bit_LM (1 << 29)
unsigned char grub_cpuid_has_longmode = 0;
static grub_err_t static grub_err_t
grub_cmd_cpuid (struct grub_arg_list *state __attribute__ ((unused)), grub_cmd_cpuid (grub_extcmd_t cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)), int argc __attribute__ ((unused)),
char **args __attribute__ ((unused))) char **args __attribute__ ((unused)))
{ {
return !has_longmode; return grub_cpuid_has_longmode ? GRUB_ERR_NONE
: grub_error (GRUB_ERR_TEST_FAILURE, "false");
} }
static grub_extcmd_t cmd;
GRUB_MOD_INIT(cpuid) GRUB_MOD_INIT(cpuid)
{ {
#ifdef __x86_64__ #ifdef __x86_64__
/* grub-emu */ /* grub-emu */
has_longmode = 1; grub_cpuid_has_longmode = 1;
#else #else
unsigned int eax, ebx, ecx, edx; unsigned int eax, ebx, ecx, edx;
unsigned int max_level; unsigned int max_level;
@ -79,15 +84,15 @@ GRUB_MOD_INIT(cpuid)
goto done; goto done;
cpuid (0x80000001, eax, ebx, ecx, edx); cpuid (0x80000001, eax, ebx, ecx, edx);
has_longmode = !!(edx & bit_LM); grub_cpuid_has_longmode = !!(edx & bit_LM);
done: done:
#endif #endif
grub_register_command ("cpuid", grub_cmd_cpuid, GRUB_COMMAND_FLAG_CMDLINE, cmd = grub_register_extcmd ("cpuid", grub_cmd_cpuid, GRUB_COMMAND_FLAG_BOTH,
"cpuid", "Check for CPU features", options); "[-l]", N_("Check for CPU features."), options);
} }
GRUB_MOD_FINI(cpuid) GRUB_MOD_FINI(cpuid)
{ {
grub_unregister_command ("cpuid"); grub_unregister_extcmd (cmd);
} }

81
commands/i386/pc/acpi.c Normal file
View File

@ -0,0 +1,81 @@
/* acpi.c - get acpi tables. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 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/acpi.h>
#include <grub/misc.h>
struct grub_acpi_rsdp_v10 *
grub_machine_acpi_get_rsdpv1 (void)
{
int ebda_len;
grub_uint8_t *ebda, *ptr;
grub_dprintf ("acpi", "Looking for RSDP. Scanning EBDA\n");
ebda = (grub_uint8_t *) ((* ((grub_uint16_t *) 0x40e)) << 4);
ebda_len = * (grub_uint16_t *) ebda;
if (! ebda_len)
return 0;
for (ptr = ebda; ptr < ebda + 0x400; ptr += 16)
if (grub_memcmp (ptr, "RSD PTR ", 8) == 0
&& grub_byte_checksum (ptr, sizeof (struct grub_acpi_rsdp_v10)) == 0
&& ((struct grub_acpi_rsdp_v10 *) ptr)->revision == 0)
return (struct grub_acpi_rsdp_v10 *) ptr;
grub_dprintf ("acpi", "Looking for RSDP. Scanning BIOS\n");
for (ptr = (grub_uint8_t *) 0xe0000; ptr < (grub_uint8_t *) 0x100000;
ptr += 16)
if (grub_memcmp (ptr, "RSD PTR ", 8) == 0
&& grub_byte_checksum (ptr, sizeof (struct grub_acpi_rsdp_v10)) == 0
&& ((struct grub_acpi_rsdp_v10 *) ptr)->revision == 0)
return (struct grub_acpi_rsdp_v10 *) ptr;
return 0;
}
struct grub_acpi_rsdp_v20 *
grub_machine_acpi_get_rsdpv2 (void)
{
int ebda_len;
grub_uint8_t *ebda, *ptr;
grub_dprintf ("acpi", "Looking for RSDP. Scanning EBDA\n");
ebda = (grub_uint8_t *) ((* ((grub_uint16_t *) 0x40e)) << 4);
ebda_len = * (grub_uint16_t *) ebda;
if (! ebda_len)
return 0;
for (ptr = ebda; ptr < ebda + 0x400; ptr += 16)
if (grub_memcmp (ptr, "RSD PTR ", 8) == 0
&& grub_byte_checksum (ptr, sizeof (struct grub_acpi_rsdp_v10)) == 0
&& ((struct grub_acpi_rsdp_v10 *) ptr)->revision != 0
&& ((struct grub_acpi_rsdp_v20 *) ptr)->length < 1024
&& grub_byte_checksum (ptr, ((struct grub_acpi_rsdp_v20 *) ptr)->length)
== 0)
return (struct grub_acpi_rsdp_v20 *) ptr;
grub_dprintf ("acpi", "Looking for RSDP. Scanning BIOS\n");
for (ptr = (grub_uint8_t *) 0xe0000; ptr < (grub_uint8_t *) 0x100000;
ptr += 16)
if (grub_memcmp (ptr, "RSD PTR ", 8) == 0
&& grub_byte_checksum (ptr, sizeof (struct grub_acpi_rsdp_v10)) == 0
&& ((struct grub_acpi_rsdp_v10 *) ptr)->revision != 0
&& ((struct grub_acpi_rsdp_v20 *) ptr)->length < 1024
&& grub_byte_checksum (ptr, ((struct grub_acpi_rsdp_v20 *) ptr)->length)
== 0)
return (struct grub_acpi_rsdp_v20 *) ptr;
return 0;
}

422
commands/i386/pc/drivemap.c Normal file
View File

@ -0,0 +1,422 @@
/* drivemap.c - command to manage the BIOS drive mappings. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008, 2009 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/extcmd.h>
#include <grub/dl.h>
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/disk.h>
#include <grub/loader.h>
#include <grub/env.h>
#include <grub/machine/memory.h>
#include <grub/machine/biosnum.h>
#include <grub/i18n.h>
/* Real mode IVT slot (seg:off far pointer) for interrupt 0x13. */
static grub_uint32_t *const int13slot = UINT_TO_PTR (4 * 0x13);
/* Remember to update enum opt_idxs accordingly. */
static const struct grub_arg_option options[] = {
{"list", 'l', 0, N_("Show the current mappings."), 0, 0},
{"reset", 'r', 0, N_("Reset all mappings to the default values."), 0, 0},
{"swap", 's', 0, N_("Perform both direct and reverse mappings."), 0, 0},
{0, 0, 0, 0, 0, 0}
};
/* Remember to update options[] accordingly. */
enum opt_idxs
{
OPTIDX_LIST = 0,
OPTIDX_RESET,
OPTIDX_SWAP,
};
/* Realmode far ptr (2 * 16b) to the previous INT13h handler. */
extern grub_uint32_t grub_drivemap_oldhandler;
/* The type "void" is used for imported assembly labels, takes no storage and
serves just to take the address with &label. */
/* The assembly function to replace the old INT13h handler. It does not follow
any C callspecs and returns with IRET. */
extern const void grub_drivemap_handler;
/* Start of the drive mappings area (space reserved at runtime). */
extern const void grub_drivemap_mapstart;
typedef struct drivemap_node
{
struct drivemap_node *next;
grub_uint8_t newdrive;
grub_uint8_t redirto;
} drivemap_node_t;
typedef struct __attribute__ ((packed)) int13map_node
{
grub_uint8_t disknum;
grub_uint8_t mapto;
} int13map_node_t;
#define INT13H_OFFSET(x) \
(((grub_uint8_t *)(x)) - ((grub_uint8_t *)&grub_drivemap_handler))
static drivemap_node_t *map_head;
static void *drivemap_hook;
static int drivemap_mmap;
/* Puts the specified mapping into the table, replacing an existing mapping
for newdrive or adding a new one if required. */
static grub_err_t
drivemap_set (grub_uint8_t newdrive, grub_uint8_t redirto)
{
drivemap_node_t *mapping = 0;
drivemap_node_t *search = map_head;
while (search)
{
if (search->newdrive == newdrive)
{
mapping = search;
break;
}
search = search->next;
}
/* Check for pre-existing mappings to modify before creating a new one. */
if (mapping)
mapping->redirto = redirto;
else
{
mapping = grub_malloc (sizeof (drivemap_node_t));
if (! mapping)
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"cannot allocate map entry, not enough memory");
mapping->newdrive = newdrive;
mapping->redirto = redirto;
mapping->next = map_head;
map_head = mapping;
}
return GRUB_ERR_NONE;
}
/* Removes the mapping for newdrive from the table. If there is no mapping,
then this function behaves like a no-op on the map. */
static void
drivemap_remove (grub_uint8_t newdrive)
{
drivemap_node_t *mapping = 0;
drivemap_node_t *search = map_head;
drivemap_node_t *previous = 0;
while (search)
{
if (search->newdrive == newdrive)
{
mapping = search;
break;
}
previous = search;
search = search->next;
}
if (mapping)
{
if (previous)
previous->next = mapping->next;
else
map_head = mapping->next;
grub_free (mapping);
}
}
/* Given a GRUB-like device name and a convenient location, stores the
related BIOS disk number. Accepts devices like \((f|h)dN\), with
0 <= N < 128. */
static grub_err_t
tryparse_diskstring (const char *str, grub_uint8_t *output)
{
/* Skip opening paren in order to allow both (hd0) and hd0. */
if (*str == '(')
str++;
if ((str[0] == 'f' || str[0] == 'h') && str[1] == 'd')
{
grub_uint8_t bios_num = (str[0] == 'h') ? 0x80 : 0x00;
unsigned long drivenum = grub_strtoul (str + 2, 0, 0);
if (grub_errno == GRUB_ERR_NONE && drivenum < 128)
{
bios_num |= drivenum;
if (output)
*output = bios_num;
return GRUB_ERR_NONE;
}
}
return grub_error (GRUB_ERR_BAD_ARGUMENT, "device format \"%s\" "
"invalid: must be (f|h)dN, with 0 <= N < 128", str);
}
static grub_err_t
list_mappings (void)
{
/* Show: list mappings. */
if (! map_head)
{
grub_printf ("No drives have been remapped\n");
return GRUB_ERR_NONE;
}
grub_printf ("OS disk #num ------> GRUB/BIOS device\n");
drivemap_node_t *curnode = map_head;
while (curnode)
{
grub_printf ("%cD #%-3u (0x%02x) %cd%d\n",
(curnode->newdrive & 0x80) ? 'H' : 'F',
curnode->newdrive & 0x7F, curnode->newdrive,
(curnode->redirto & 0x80) ? 'h' : 'f',
curnode->redirto & 0x7F
);
curnode = curnode->next;
}
return GRUB_ERR_NONE;
}
static grub_err_t
grub_cmd_drivemap (struct grub_extcmd *cmd, int argc, char **args)
{
if (cmd->state[OPTIDX_LIST].set)
{
return list_mappings ();
}
else if (cmd->state[OPTIDX_RESET].set)
{
/* Reset: just delete all mappings, freeing their memory. */
drivemap_node_t *curnode = map_head;
drivemap_node_t *prevnode = 0;
while (curnode)
{
prevnode = curnode;
curnode = curnode->next;
grub_free (prevnode);
}
map_head = 0;
return GRUB_ERR_NONE;
}
else if (!cmd->state[OPTIDX_SWAP].set && argc == 0)
{
/* No arguments */
return list_mappings ();
}
/* Neither flag: put mapping. */
grub_uint8_t mapfrom = 0;
grub_uint8_t mapto = 0xFF;
grub_err_t err;
if (argc != 2)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "two arguments required");
err = tryparse_diskstring (args[0], &mapfrom);
if (err != GRUB_ERR_NONE)
return err;
err = tryparse_diskstring (args[1], &mapto);
if (err != GRUB_ERR_NONE)
return err;
if (mapto == mapfrom)
{
/* Reset to default. */
grub_dprintf ("drivemap", "Removing mapping for %s (%02x)\n",
args[0], mapfrom);
drivemap_remove (mapfrom);
return GRUB_ERR_NONE;
}
/* Set the mapping for the disk (overwrites any existing mapping). */
grub_dprintf ("drivemap", "%s %s (%02x) = %s (%02x)\n",
cmd->state[OPTIDX_SWAP].set ? "Swapping" : "Mapping",
args[1], mapto, args[0], mapfrom);
err = drivemap_set (mapto, mapfrom);
/* If -s, perform the reverse mapping too (only if the first was OK). */
if (cmd->state[OPTIDX_SWAP].set && err == GRUB_ERR_NONE)
err = drivemap_set (mapfrom, mapto);
return err;
}
/* Int13h handler installer - reserves conventional memory for the handler,
copies it over and sets the IVT entry for int13h.
This code rests on the assumption that GRUB does not activate any kind
of memory mapping apart from identity paging, since it accesses
realmode structures by their absolute addresses, like the IVT at 0;
and transforms a pmode pointer into a rmode seg:off far ptr. */
static grub_err_t
install_int13_handler (int noret __attribute__ ((unused)))
{
/* Size of the full int13 handler "bundle", including code and map. */
grub_uint32_t total_size;
/* Base address of the space reserved for the handler bundle. */
grub_uint8_t *handler_base = 0;
/* Address of the map within the deployed bundle. */
int13map_node_t *handler_map;
int i;
int entries = 0;
drivemap_node_t *curentry = map_head;
/* Count entries to prepare a contiguous map block. */
while (curentry)
{
entries++;
curentry = curentry->next;
}
if (entries == 0)
{
/* No need to install the int13h handler. */
grub_dprintf ("drivemap", "No drives marked as remapped, not installing "
"our int13h handler.\n");
return GRUB_ERR_NONE;
}
grub_dprintf ("drivemap", "Installing our int13h handler\n");
/* Save the pointer to the old handler. */
grub_drivemap_oldhandler = *int13slot;
grub_dprintf ("drivemap", "Original int13 handler: %04x:%04x\n",
(grub_drivemap_oldhandler >> 16) & 0x0ffff,
grub_drivemap_oldhandler & 0x0ffff);
/* Find a rmode-segment-aligned zone in conventional memory big
enough to hold the handler and its data. */
total_size = INT13H_OFFSET (&grub_drivemap_mapstart)
+ (entries + 1) * sizeof (int13map_node_t);
grub_dprintf ("drivemap", "Payload is %u bytes long\n", total_size);
handler_base = grub_mmap_malign_and_register (16, total_size,
&drivemap_mmap,
GRUB_MACHINE_MEMORY_RESERVED,
GRUB_MMAP_MALLOC_LOW);
if (! handler_base)
return grub_error (GRUB_ERR_OUT_OF_MEMORY, "couldn't reserve "
"memory for the int13h handler");
/* Copy int13h handler bundle to reserved area. */
grub_dprintf ("drivemap", "Reserved memory at %p, copying handler\n",
handler_base);
grub_memcpy (handler_base, &grub_drivemap_handler,
INT13H_OFFSET (&grub_drivemap_mapstart));
/* Copy the mappings to the reserved area. */
curentry = map_head;
handler_map = (int13map_node_t *) (handler_base +
INT13H_OFFSET (&grub_drivemap_mapstart));
grub_dprintf ("drivemap", "Target map at %p, copying mappings\n", handler_map);
for (i = 0; i < entries; ++i, curentry = curentry->next)
{
handler_map[i].disknum = curentry->newdrive;
handler_map[i].mapto = curentry->redirto;
grub_dprintf ("drivemap", "\t#%d: 0x%02x <- 0x%02x\n", i,
handler_map[i].disknum, handler_map[i].mapto);
}
/* Signal end-of-map. */
handler_map[i].disknum = 0;
handler_map[i].mapto = 0;
grub_dprintf ("drivemap", "\t#%d: 0x00 <- 0x00 (end)\n", i);
/* Install our function as the int13h handler in the IVT. */
*int13slot = ((grub_uint32_t) handler_base) << 12; /* Segment address. */
grub_dprintf ("drivemap", "New int13 handler: %04x:%04x\n",
(*int13slot >> 16) & 0x0ffff, *int13slot & 0x0ffff);
return GRUB_ERR_NONE;
}
static grub_err_t
uninstall_int13_handler (void)
{
if (! grub_drivemap_oldhandler)
return GRUB_ERR_NONE;
*int13slot = grub_drivemap_oldhandler;
grub_mmap_free_and_unregister (drivemap_mmap);
grub_drivemap_oldhandler = 0;
grub_dprintf ("drivemap", "Restored int13 handler: %04x:%04x\n",
(*int13slot >> 16) & 0x0ffff, *int13slot & 0x0ffff);
return GRUB_ERR_NONE;
}
static int
grub_get_root_biosnumber_drivemap (void)
{
char *biosnum;
int ret = -1;
grub_device_t dev;
biosnum = grub_env_get ("biosnum");
if (biosnum)
return grub_strtoul (biosnum, 0, 0);
dev = grub_device_open (0);
if (dev && dev->disk && dev->disk->dev
&& dev->disk->dev->id == GRUB_DISK_DEVICE_BIOSDISK_ID)
{
drivemap_node_t *curnode = map_head;
ret = (int) dev->disk->id;
while (curnode)
{
if (curnode->redirto == ret)
{
ret = curnode->newdrive;
break;
}
curnode = curnode->next;
}
}
if (dev)
grub_device_close (dev);
return ret;
}
static grub_extcmd_t cmd;
static int (*grub_get_root_biosnumber_saved) (void);
GRUB_MOD_INIT (drivemap)
{
grub_get_root_biosnumber_saved = grub_get_root_biosnumber;
grub_get_root_biosnumber = grub_get_root_biosnumber_drivemap;
cmd = grub_register_extcmd ("drivemap", grub_cmd_drivemap,
GRUB_COMMAND_FLAG_BOTH,
"drivemap"
N_("-l | -r | [-s] grubdev osdisk."),
N_("Manage the BIOS drive mappings."),
options);
drivemap_hook =
grub_loader_register_preboot_hook (&install_int13_handler,
&uninstall_int13_handler,
GRUB_LOADER_PREBOOT_HOOK_PRIO_NORMAL);
}
GRUB_MOD_FINI (drivemap)
{
grub_get_root_biosnumber = grub_get_root_biosnumber_saved;
grub_loader_unregister_preboot_hook (drivemap_hook);
drivemap_hook = 0;
grub_unregister_extcmd (cmd);
}

View File

@ -0,0 +1,119 @@
/* drivemap_int13h.S - interrupt handler for the BIOS drive remapper */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008, 2009 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/symbol.h>
#define INT13H_OFFSET(x) ((x) - EXT_C(grub_drivemap_handler))
.code16
/* Copy starts here. When deployed, this code must be segment-aligned. */
/* The replacement int13 handler. Preserve all registers. */
FUNCTION(grub_drivemap_handler)
/* Save %dx for future restore. */
push %dx
/* Push flags. Used to simulate interrupt with original flags. */
pushf
/* Map the drive number (always in DL). */
push %ax
push %bx
#ifdef APPLE_CC
grub_drivemap_mapstart_ofs = INT13H_OFFSET(EXT_C(grub_drivemap_mapstart))
movw $grub_drivemap_mapstart_ofs, %bx
#else
movw $INT13H_OFFSET(EXT_C(grub_drivemap_mapstart)), %bx
#endif
more_remaining:
movw %cs:(%bx), %ax
cmpb %ah, %al
jz not_found /* DRV=DST => map end - drive not remapped, keep DL. */
inc %bx
inc %bx
cmpb %dl, %al
jnz more_remaining /* Not found, but more remaining, loop. */
movb %ah, %dl /* Found - drive remapped, modify DL. */
not_found:
pop %bx
pop %ax
/* If the call isn't ah=0x8 or ah=0x15 we must restore %dx. */
cmpb $0x8, %ah
jz norestore
cmpb $0x15, %ah
jz norestore
/* Restore flags. */
popf
pushf
#ifdef APPLE_CC
grub_drivemap_oldhandler_ofs = INT13H_OFFSET (EXT_C (grub_drivemap_oldhandler))
lcall *%cs:grub_drivemap_oldhandler_ofs
#else
lcall *%cs:INT13H_OFFSET (EXT_C (grub_drivemap_oldhandler))
#endif
push %bp
mov %sp, %bp
tail:
/* Save new flags below %esp so the caller will recieve new flags. */
pushf
pop %dx
mov %dx, 8(%bp)
pop %bp
/* Restore %dx. */
pop %dx
iret
norestore:
/* Restore flags. */
popf
pushf
#ifdef APPLE_CC
lcall *%cs:grub_drivemap_oldhandler_ofs
#else
lcall *%cs:INT13H_OFFSET (EXT_C (grub_drivemap_oldhandler))
#endif
push %bp
mov %sp, %bp
/* Save %dx. So it won't be restored to original value. */
mov %dx, 2(%bp)
jmp tail
/* Far pointer to the old handler. Stored as a CS:IP in the style of real-mode
IVT entries (thus PI:SC in mem). */
VARIABLE(grub_drivemap_oldhandler)
.word 0x0, 0x0
/* This label MUST be at the end of the copied block, since the installer code
reserves additional space for mappings at runtime and copies them over it. */
.align 2
VARIABLE(grub_drivemap_mapstart)

View File

@ -1,7 +1,7 @@
/* halt.c - command to halt the computer. */ /* halt.c - command to halt the computer. */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2005,2007 Free Software Foundation, Inc. * Copyright (C) 2005,2007,2009 Free Software Foundation, Inc.
* *
* GRUB is free software: you can redistribute it and/or modify * GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -17,23 +17,24 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <grub/normal.h>
#include <grub/dl.h> #include <grub/dl.h>
#include <grub/arg.h> #include <grub/misc.h>
#include <grub/machine/init.h> #include <grub/extcmd.h>
#include <grub/i18n.h>
static const struct grub_arg_option options[] = static const struct grub_arg_option options[] =
{ {
{"no-apm", 'n', 0, "do not use APM to halt the computer", 0, 0}, {"no-apm", 'n', 0, N_("Do not use APM to halt the computer."), 0, 0},
{0, 0, 0, 0, 0, 0} {0, 0, 0, 0, 0, 0}
}; };
static grub_err_t static grub_err_t
grub_cmd_halt (struct grub_arg_list *state, grub_cmd_halt (grub_extcmd_t cmd,
int argc __attribute__ ((unused)), int argc __attribute__ ((unused)),
char **args __attribute__ ((unused))) char **args __attribute__ ((unused)))
{ {
struct grub_arg_list *state = cmd->state;
int no_apm = 0; int no_apm = 0;
if (state[0].set) if (state[0].set)
no_apm = 1; no_apm = 1;
@ -41,17 +42,17 @@ grub_cmd_halt (struct grub_arg_list *state,
return 0; return 0;
} }
static grub_extcmd_t cmd;
GRUB_MOD_INIT(halt) GRUB_MOD_INIT(halt)
{ {
(void)mod; /* To stop warning. */ cmd = grub_register_extcmd ("halt", grub_cmd_halt, GRUB_COMMAND_FLAG_BOTH,
grub_register_command ("halt", grub_cmd_halt, GRUB_COMMAND_FLAG_BOTH, "[-n]",
"halt [-n]", N_("Halt the system, if possible using APM."),
"Halt the system, if possible using APM", options); options);
} }
GRUB_MOD_FINI(halt) GRUB_MOD_FINI(halt)
{ {
grub_unregister_command ("halt"); grub_unregister_extcmd (cmd);
} }

View File

@ -1,7 +1,7 @@
/* play.c - command to play a tune */ /* play.c - command to play a tune */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2005,2007 Free Software Foundation, Inc. * Copyright (C) 2005,2007,2009 Free Software Foundation, Inc.
* *
* GRUB is free software: you can redistribute it and/or modify * GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -19,15 +19,15 @@
/* Lots of this file is borrowed from GNU/Hurd generic-speaker driver. */ /* Lots of this file is borrowed from GNU/Hurd generic-speaker driver. */
#include <grub/normal.h>
#include <grub/dl.h> #include <grub/dl.h>
#include <grub/arg.h>
#include <grub/file.h> #include <grub/file.h>
#include <grub/disk.h> #include <grub/disk.h>
#include <grub/term.h> #include <grub/term.h>
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/machine/time.h> #include <grub/machine/time.h>
#include <grub/cpu/io.h> #include <grub/cpu/io.h>
#include <grub/command.h>
#include <grub/i18n.h>
#define BASE_TEMPO 120 #define BASE_TEMPO 120
@ -144,7 +144,7 @@ beep_on (short pitch)
} }
static grub_err_t static grub_err_t
grub_cmd_play (struct grub_arg_list *state __attribute__ ((unused)), grub_cmd_play (grub_command_t cmd __attribute__ ((unused)),
int argc, char **args) int argc, char **args)
{ {
grub_file_t file; grub_file_t file;
@ -159,7 +159,7 @@ grub_cmd_play (struct grub_arg_list *state __attribute__ ((unused)),
if (! file) if (! file)
return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found");
if (grub_file_read (file, (void *) &tempo, sizeof(tempo)) != sizeof(tempo)) if (grub_file_read (file, &tempo, sizeof(tempo)) != sizeof(tempo))
{ {
grub_file_close (file); grub_file_close (file);
return grub_error (GRUB_ERR_FILE_READ_ERROR, return grub_error (GRUB_ERR_FILE_READ_ERROR,
@ -168,11 +168,11 @@ grub_cmd_play (struct grub_arg_list *state __attribute__ ((unused)),
grub_dprintf ("play","tempo = %d\n", tempo); grub_dprintf ("play","tempo = %d\n", tempo);
while (grub_file_read (file, (void *) &buf, while (grub_file_read (file, &buf,
sizeof (struct note)) == sizeof (struct note) sizeof (struct note)) == sizeof (struct note)
&& buf.pitch != T_FINE && grub_checkkey () < 0) && buf.pitch != T_FINE && grub_checkkey () < 0)
{ {
grub_dprintf ("play", "pitch = %d, duration = %d\n", buf.pitch, grub_dprintf ("play", "pitch = %d, duration = %d\n", buf.pitch,
buf.duration); buf.duration);
@ -203,15 +203,15 @@ grub_cmd_play (struct grub_arg_list *state __attribute__ ((unused)),
return 0; return 0;
} }
static grub_command_t cmd;
GRUB_MOD_INIT(play) GRUB_MOD_INIT(play)
{ {
(void)mod; /* To stop warning. */ cmd = grub_register_command ("play", grub_cmd_play,
grub_register_command ("play", grub_cmd_play, GRUB_COMMAND_FLAG_BOTH, N_("FILE"), N_("Play a tune."));
"play FILE", "Play a tune", 0);
} }
GRUB_MOD_FINI(play) GRUB_MOD_FINI(play)
{ {
grub_unregister_command ("play"); grub_unregister_command (cmd);
} }

View File

@ -1,7 +1,7 @@
/* reboot.c - command to reboot the computer. */ /* pxe.c - command to control the pxe driver */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2005,2007 Free Software Foundation, Inc. * Copyright (C) 2008,2009 Free Software Foundation, Inc.
* *
* GRUB is free software: you can redistribute it and/or modify * GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -17,29 +17,36 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <grub/normal.h>
#include <grub/dl.h> #include <grub/dl.h>
#include <grub/err.h>
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/machine/kernel.h> #include <grub/machine/pxe.h>
#include <grub/command.h>
#include <grub/i18n.h>
static grub_err_t static grub_err_t
grub_cmd_reboot (struct grub_arg_list *state __attribute__ ((unused)), grub_cmd_pxe_unload (grub_command_t cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)), int argc __attribute__ ((unused)),
char **args __attribute__ ((unused))) char **args __attribute__ ((unused)))
{ {
grub_reboot (); if (! grub_pxe_pxenv)
return grub_error (GRUB_ERR_FILE_NOT_FOUND, "no pxe environment");
grub_pxe_unload ();
return 0; return 0;
} }
static grub_command_t cmd;
GRUB_MOD_INIT(ieee1275_reboot)
GRUB_MOD_INIT(pxecmd)
{ {
(void)mod; /* To stop warning. */ cmd = grub_register_command ("pxe_unload", grub_cmd_pxe_unload,
grub_register_command ("reboot", grub_cmd_reboot, GRUB_COMMAND_FLAG_BOTH, 0,
"reboot", "Reboot the computer", 0); N_("Unload PXE environment."));
} }
GRUB_MOD_FINI(ieee1275_reboot) GRUB_MOD_FINI(pxecmd)
{ {
grub_unregister_command ("reboot"); grub_unregister_command (cmd);
} }

View File

@ -1,7 +1,7 @@
/* vbeinfo.c - command to list compatible VBE video modes. */ /* vbeinfo.c - command to list compatible VBE video modes. */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2005,2007 Free Software Foundation, Inc. * Copyright (C) 2005,2007,2008,2009 Free Software Foundation, Inc.
* *
* GRUB is free software: you can redistribute it and/or modify * GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -17,14 +17,14 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <grub/normal.h>
#include <grub/dl.h> #include <grub/dl.h>
#include <grub/arg.h>
#include <grub/env.h> #include <grub/env.h>
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/machine/init.h> #include <grub/machine/init.h>
#include <grub/machine/vbe.h> #include <grub/machine/vbe.h>
#include <grub/mm.h> #include <grub/mm.h>
#include <grub/command.h>
#include <grub/i18n.h>
static void * static void *
real2pm (grub_vbe_farptr_t ptr) real2pm (grub_vbe_farptr_t ptr)
@ -34,7 +34,7 @@ real2pm (grub_vbe_farptr_t ptr)
} }
static grub_err_t static grub_err_t
grub_cmd_vbeinfo (struct grub_arg_list *state __attribute__ ((unused)), grub_cmd_vbeinfo (grub_command_t cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)), int argc __attribute__ ((unused)),
char **args __attribute__ ((unused))) char **args __attribute__ ((unused)))
{ {
@ -48,31 +48,43 @@ grub_cmd_vbeinfo (struct grub_arg_list *state __attribute__ ((unused)),
grub_err_t err; grub_err_t err;
char *modevar; char *modevar;
grub_printf ("List of compatible video modes:\n");
err = grub_vbe_probe (&controller_info); err = grub_vbe_probe (&controller_info);
if (err != GRUB_ERR_NONE) if (err != GRUB_ERR_NONE)
return err; return err;
grub_printf ("VBE info: version: %d.%d OEM software rev: %d.%d\n",
controller_info.version >> 8,
controller_info.version & 0xFF,
controller_info.oem_software_rev >> 8,
controller_info.oem_software_rev & 0xFF);
/* The total_memory field is in 64 KiB units. */
grub_printf (" total memory: %d KiB\n",
(controller_info.total_memory << 16) / 1024);
/* Because the information on video modes is stored in a temporary place, /* Because the information on video modes is stored in a temporary place,
it is better to copy it to somewhere safe. */ it is better to copy it to somewhere safe. */
p = video_mode_list = real2pm (controller_info.video_mode_ptr); p = video_mode_list = real2pm (controller_info.video_mode_ptr);
while (*p++ != 0xFFFF) while (*p++ != 0xFFFF)
; ;
video_mode_list_size = (grub_addr_t) p - (grub_addr_t) video_mode_list; video_mode_list_size = (grub_addr_t) p - (grub_addr_t) video_mode_list;
saved_video_mode_list = grub_malloc (video_mode_list_size); saved_video_mode_list = grub_malloc (video_mode_list_size);
if (! saved_video_mode_list) if (! saved_video_mode_list)
return grub_errno; return grub_errno;
grub_memcpy (saved_video_mode_list, video_mode_list, video_mode_list_size); grub_memcpy (saved_video_mode_list, video_mode_list, video_mode_list_size);
grub_printf ("List of compatible video modes:\n");
grub_printf ("Legend: P=Packed pixel, D=Direct color, "
"mask/pos=R/G/B/reserved\n");
/* Walk through all video modes listed. */ /* Walk through all video modes listed. */
for (p = saved_video_mode_list; *p != 0xFFFF; p++) for (p = saved_video_mode_list; *p != 0xFFFF; p++)
{ {
const char *memory_model = 0; const char *memory_model = 0;
grub_uint32_t mode = (grub_uint32_t) *p; grub_uint32_t mode = (grub_uint32_t) *p;
err = grub_vbe_get_video_mode_info (mode, &mode_info_tmp); err = grub_vbe_get_video_mode_info (mode, &mode_info_tmp);
if (err != GRUB_ERR_NONE) if (err != GRUB_ERR_NONE)
{ {
@ -80,33 +92,33 @@ grub_cmd_vbeinfo (struct grub_arg_list *state __attribute__ ((unused)),
continue; continue;
} }
if ((mode_info_tmp.mode_attributes & 0x001) == 0) if ((mode_info_tmp.mode_attributes & GRUB_VBE_MODEATTR_SUPPORTED) == 0)
/* If not available, skip it. */ /* If not available, skip it. */
continue; continue;
if ((mode_info_tmp.mode_attributes & 0x002) == 0) if ((mode_info_tmp.mode_attributes & GRUB_VBE_MODEATTR_RESERVED_1) == 0)
/* Not enough information. */ /* Not enough information. */
continue; continue;
if ((mode_info_tmp.mode_attributes & 0x008) == 0) if ((mode_info_tmp.mode_attributes & GRUB_VBE_MODEATTR_COLOR) == 0)
/* Monochrome is unusable. */ /* Monochrome is unusable. */
continue; continue;
if ((mode_info_tmp.mode_attributes & 0x080) == 0) if ((mode_info_tmp.mode_attributes & GRUB_VBE_MODEATTR_LFB_AVAIL) == 0)
/* We support only linear frame buffer modes. */ /* We support only linear frame buffer modes. */
continue; continue;
if ((mode_info_tmp.mode_attributes & 0x010) == 0) if ((mode_info_tmp.mode_attributes & GRUB_VBE_MODEATTR_GRAPHICS) == 0)
/* We allow only graphical modes. */ /* We allow only graphical modes. */
continue; continue;
switch (mode_info_tmp.memory_model) switch (mode_info_tmp.memory_model)
{ {
case 0x04: case GRUB_VBE_MEMORY_MODEL_PACKED_PIXEL:
memory_model = "Packed Pixel"; memory_model = "Packed";
break; break;
case 0x06: case GRUB_VBE_MEMORY_MODEL_DIRECT_COLOR:
memory_model = "Direct Color"; memory_model = "Direct";
break; break;
default: default:
@ -116,16 +128,29 @@ grub_cmd_vbeinfo (struct grub_arg_list *state __attribute__ ((unused)),
if (! memory_model) if (! memory_model)
continue; continue;
grub_printf ("0x%03x: %d x %d x %d bpp (%s)\n", grub_printf ("0x%03x: %4d x %4d x %2d %s",
mode, mode,
mode_info_tmp.x_resolution, mode_info_tmp.x_resolution,
mode_info_tmp.y_resolution, mode_info_tmp.y_resolution,
mode_info_tmp.bits_per_pixel, mode_info_tmp.bits_per_pixel,
memory_model); memory_model);
/* Show mask and position details for direct color modes. */
if (mode_info_tmp.memory_model == GRUB_VBE_MEMORY_MODEL_DIRECT_COLOR)
grub_printf (", mask: %d/%d/%d/%d pos: %d/%d/%d/%d",
mode_info_tmp.red_mask_size,
mode_info_tmp.green_mask_size,
mode_info_tmp.blue_mask_size,
mode_info_tmp.rsvd_mask_size,
mode_info_tmp.red_field_position,
mode_info_tmp.green_field_position,
mode_info_tmp.blue_field_position,
mode_info_tmp.rsvd_field_position);
grub_printf ("\n");
} }
grub_free (saved_video_mode_list); grub_free (saved_video_mode_list);
/* Check existence of vbe_mode environment variable. */ /* Check existence of vbe_mode environment variable. */
modevar = grub_env_get ("vbe_mode"); modevar = grub_env_get ("vbe_mode");
@ -145,18 +170,16 @@ grub_cmd_vbeinfo (struct grub_arg_list *state __attribute__ ((unused)),
return 0; return 0;
} }
static grub_command_t cmd;
GRUB_MOD_INIT(vbeinfo) GRUB_MOD_INIT(vbeinfo)
{ {
(void) mod; /* To stop warning. */ cmd =
grub_register_command ("vbeinfo", grub_register_command ("vbeinfo", grub_cmd_vbeinfo, 0,
grub_cmd_vbeinfo, N_("List compatible VESA BIOS extension video modes."));
GRUB_COMMAND_FLAG_BOTH,
"vbeinfo",
"List compatible VESA BIOS extension video modes.",
0);
} }
GRUB_MOD_FINI(vbeinfo) GRUB_MOD_FINI(vbeinfo)
{ {
grub_unregister_command ("vbeinfo"); grub_unregister_command (cmd);
} }

View File

@ -19,16 +19,16 @@
#include <grub/normal.h> #include <grub/normal.h>
#include <grub/dl.h> #include <grub/dl.h>
#include <grub/arg.h>
#include <grub/env.h> #include <grub/env.h>
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/term.h> #include <grub/term.h>
#include <grub/machine/init.h> #include <grub/machine/init.h>
#include <grub/machine/vbe.h> #include <grub/machine/vbe.h>
#include <grub/err.h> #include <grub/err.h>
#include <grub/i18n.h>
static grub_err_t static grub_err_t
grub_cmd_vbetest (struct grub_arg_list *state __attribute__ ((unused)), grub_cmd_vbetest (grub_command_t cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)), int argc __attribute__ ((unused)),
char **args __attribute__ ((unused))) char **args __attribute__ ((unused)))
{ {
@ -74,7 +74,7 @@ grub_cmd_vbetest (struct grub_arg_list *state __attribute__ ((unused)),
grub_printf ("Old video mode = %04x\n", old_mode); grub_printf ("Old video mode = %04x\n", old_mode);
else else
grub_errno = GRUB_ERR_NONE; grub_errno = GRUB_ERR_NONE;
/* Check existence of vbe_mode environment variable. */ /* Check existence of vbe_mode environment variable. */
modevar = grub_env_get ("vbe_mode"); modevar = grub_env_get ("vbe_mode");
if (modevar != 0) if (modevar != 0)
@ -91,7 +91,7 @@ grub_cmd_vbetest (struct grub_arg_list *state __attribute__ ((unused)),
err = grub_vbe_get_video_mode_info (use_mode, &mode_info); err = grub_vbe_get_video_mode_info (use_mode, &mode_info);
if (err != GRUB_ERR_NONE) if (err != GRUB_ERR_NONE)
return err; return err;
/* Dump out details about the mode being tested. */ /* Dump out details about the mode being tested. */
grub_printf ("mode: 0x%03x\n", grub_printf ("mode: 0x%03x\n",
use_mode); use_mode);
@ -156,24 +156,23 @@ grub_cmd_vbetest (struct grub_arg_list *state __attribute__ ((unused)),
grub_getkey (); grub_getkey ();
grub_video_restore ();
/* Restore old video mode. */ /* Restore old video mode. */
grub_vbe_set_video_mode (old_mode, 0); grub_vbe_set_video_mode (old_mode, 0);
return grub_errno; return grub_errno;
} }
static grub_command_t cmd;
GRUB_MOD_INIT(vbetest) GRUB_MOD_INIT(vbetest)
{ {
(void) mod; /* To stop warning. */ cmd = grub_register_command ("vbetest", grub_cmd_vbetest,
grub_register_command ("vbetest", 0, N_("Test VESA BIOS Extension 2.0+ support."));
grub_cmd_vbetest,
GRUB_COMMAND_FLAG_BOTH,
"vbetest",
"Test VESA BIOS Extension 2.0+ support",
0);
} }
GRUB_MOD_FINI(vbetest) GRUB_MOD_FINI(vbetest)
{ {
grub_unregister_command ("vbetest"); grub_unregister_command (cmd);
} }

View File

@ -17,14 +17,15 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <grub/normal.h>
#include <grub/dl.h> #include <grub/dl.h>
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/term.h> #include <grub/term.h>
#include <grub/ieee1275/ieee1275.h> #include <grub/ieee1275/ieee1275.h>
#include <grub/command.h>
#include <grub/i18n.h>
static grub_err_t static grub_err_t
grub_cmd_suspend (struct grub_arg_list *state __attribute__ ((unused)), grub_cmd_suspend (grub_command_t cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)), int argc __attribute__ ((unused)),
char **args __attribute__ ((unused))) char **args __attribute__ ((unused)))
{ {
@ -34,15 +35,15 @@ grub_cmd_suspend (struct grub_arg_list *state __attribute__ ((unused)),
return 0; return 0;
} }
static grub_command_t cmd;
GRUB_MOD_INIT(ieee1275_suspend) GRUB_MOD_INIT(ieee1275_suspend)
{ {
(void)mod; /* To stop warning. */ cmd = grub_register_command ("suspend", grub_cmd_suspend,
grub_register_command ("suspend", grub_cmd_suspend, GRUB_COMMAND_FLAG_BOTH, 0, N_("Return to Open Firmware prompt."));
"suspend", "Return to Open Firmware prompt", 0);
} }
GRUB_MOD_FINI(ieee1275_suspend) GRUB_MOD_FINI(ieee1275_suspend)
{ {
grub_unregister_command ("suspend"); grub_unregister_command (cmd);
} }

93
commands/keystatus.c Normal file
View File

@ -0,0 +1,93 @@
/* keystatus.c - Command to check key modifier status. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 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/dl.h>
#include <grub/misc.h>
#include <grub/extcmd.h>
#include <grub/term.h>
#include <grub/i18n.h>
static const struct grub_arg_option options[] =
{
{"shift", 's', 0, N_("Check Shift key."), 0, 0},
{"ctrl", 'c', 0, N_("Check Control key."), 0, 0},
{"alt", 'a', 0, N_("Check Alt key."), 0, 0},
{0, 0, 0, 0, 0, 0}
};
#define grub_cur_term_input grub_term_get_current_input ()
static grub_err_t
grub_cmd_keystatus (grub_extcmd_t cmd,
int argc __attribute__ ((unused)),
char **args __attribute__ ((unused)))
{
struct grub_arg_list *state = cmd->state;
int expect_mods = 0;
int mods;
if (state[0].set)
expect_mods |= GRUB_TERM_STATUS_SHIFT;
if (state[1].set)
expect_mods |= GRUB_TERM_STATUS_CTRL;
if (state[2].set)
expect_mods |= GRUB_TERM_STATUS_ALT;
grub_dprintf ("keystatus", "expect_mods: %d\n", expect_mods);
/* Without arguments, just check whether getkeystatus is supported at
all. */
if (expect_mods == 0)
{
grub_term_input_t term;
int nterms = 0;
FOR_ACTIVE_TERM_INPUTS (term)
if (!term->getkeystatus)
return grub_error (GRUB_ERR_TEST_FAILURE, "false");
else
nterms++;
if (!nterms)
return grub_error (GRUB_ERR_TEST_FAILURE, "false");
return 0;
}
mods = grub_getkeystatus ();
grub_dprintf ("keystatus", "mods: %d\n", mods);
if (mods >= 0 && (mods & expect_mods) != 0)
return 0;
else
return grub_error (GRUB_ERR_TEST_FAILURE, "false");
}
static grub_extcmd_t cmd;
GRUB_MOD_INIT(keystatus)
{
cmd = grub_register_extcmd ("keystatus", grub_cmd_keystatus,
GRUB_COMMAND_FLAG_BOTH,
N_("[--shift] [--ctrl] [--alt]"),
N_("Check key modifier status."),
options);
}
GRUB_MOD_FINI(keystatus)
{
grub_unregister_extcmd (cmd);
}

410
commands/loadenv.c Normal file
View File

@ -0,0 +1,410 @@
/* loadenv.c - command to load/save environment variable. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008,2009 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/dl.h>
#include <grub/mm.h>
#include <grub/file.h>
#include <grub/disk.h>
#include <grub/misc.h>
#include <grub/env.h>
#include <grub/partition.h>
#include <grub/lib/envblk.h>
#include <grub/extcmd.h>
#include <grub/i18n.h>
static const struct grub_arg_option options[] =
{
{"file", 'f', 0, N_("Specify filename."), 0, ARG_TYPE_PATHNAME},
{0, 0, 0, 0, 0, 0}
};
static grub_file_t
open_envblk_file (char *filename)
{
grub_file_t file;
if (! filename)
{
char *prefix;
prefix = grub_env_get ("prefix");
if (prefix)
{
int len;
len = grub_strlen (prefix);
filename = grub_malloc (len + 1 + sizeof (GRUB_ENVBLK_DEFCFG));
if (! filename)
return 0;
grub_strcpy (filename, prefix);
filename[len] = '/';
grub_strcpy (filename + len + 1, GRUB_ENVBLK_DEFCFG);
file = grub_file_open (filename);
grub_free (filename);
return file;
}
else
{
grub_error (GRUB_ERR_FILE_NOT_FOUND, "prefix is not found");
return 0;
}
}
return grub_file_open (filename);
}
static grub_envblk_t
read_envblk_file (grub_file_t file)
{
grub_off_t offset = 0;
char *buf;
grub_size_t size = grub_file_size (file);
grub_envblk_t envblk;
buf = grub_malloc (size);
if (! buf)
return 0;
while (size > 0)
{
grub_ssize_t ret;
ret = grub_file_read (file, buf + offset, size);
if (ret <= 0)
{
if (grub_errno == GRUB_ERR_NONE)
grub_error (GRUB_ERR_FILE_READ_ERROR, "cannot read");
grub_free (buf);
return 0;
}
size -= ret;
offset += ret;
}
envblk = grub_envblk_open (buf, offset);
if (! envblk)
{
grub_free (buf);
grub_error (GRUB_ERR_BAD_FILE_TYPE, "invalid environment block");
return 0;
}
return envblk;
}
static grub_err_t
grub_cmd_load_env (grub_extcmd_t cmd,
int argc __attribute__ ((unused)),
char **args __attribute__ ((unused)))
{
struct grub_arg_list *state = cmd->state;
grub_file_t file;
grub_envblk_t envblk;
auto int set_var (const char *name, const char *value);
int set_var (const char *name, const char *value)
{
grub_env_set (name, value);
return 0;
}
file = open_envblk_file ((state[0].set) ? state[0].arg : 0);
if (! file)
return grub_errno;
envblk = read_envblk_file (file);
if (! envblk)
goto fail;
grub_envblk_iterate (envblk, set_var);
grub_envblk_close (envblk);
fail:
grub_file_close (file);
return grub_errno;
}
static grub_err_t
grub_cmd_list_env (grub_extcmd_t cmd,
int argc __attribute__ ((unused)),
char **args __attribute__ ((unused)))
{
struct grub_arg_list *state = cmd->state;
grub_file_t file;
grub_envblk_t envblk;
/* Print all variables in current context. */
auto int print_var (const char *name, const char *value);
int print_var (const char *name, const char *value)
{
grub_printf ("%s=%s\n", name, value);
return 0;
}
file = open_envblk_file ((state[0].set) ? state[0].arg : 0);
if (! file)
return grub_errno;
envblk = read_envblk_file (file);
if (! envblk)
goto fail;
grub_envblk_iterate (envblk, print_var);
grub_envblk_close (envblk);
fail:
grub_file_close (file);
return grub_errno;
}
/* Used to maintain a variable length of blocklists internally. */
struct blocklist
{
grub_disk_addr_t sector;
unsigned offset;
unsigned length;
struct blocklist *next;
};
static void
free_blocklists (struct blocklist *p)
{
struct blocklist *q;
for (; p; p = q)
{
q = p->next;
grub_free (p);
}
}
static int
check_blocklists (grub_envblk_t envblk, struct blocklist *blocklists,
grub_file_t file)
{
grub_size_t total_length;
grub_size_t index;
grub_disk_t disk;
grub_disk_addr_t part_start;
struct blocklist *p;
char *buf;
/* Sanity checks. */
total_length = 0;
for (p = blocklists; p; p = p->next)
{
struct blocklist *q;
for (q = p->next; q; q = q->next)
{
/* Check if any pair of blocks overlap. */
if (p->sector == q->sector)
{
/* This might be actually valid, but it is unbelievable that
any filesystem makes such a silly allocation. */
grub_error (GRUB_ERR_BAD_FS, "malformed file");
return 0;
}
}
total_length += p->length;
}
if (total_length != grub_file_size (file))
{
/* Maybe sparse, unallocated sectors. No way in GRUB. */
grub_error (GRUB_ERR_BAD_FILE_TYPE, "sparse file not allowed");
return 0;
}
/* One more sanity check. Re-read all sectors by blocklists, and compare
those with the data read via a file. */
disk = file->device->disk;
if (disk->partition)
part_start = grub_partition_get_start (disk->partition);
else
part_start = 0;
buf = grub_envblk_buffer (envblk);
for (p = blocklists, index = 0; p; index += p->length, p = p->next)
{
char blockbuf[GRUB_DISK_SECTOR_SIZE];
if (grub_disk_read (disk, p->sector - part_start,
p->offset, p->length, blockbuf))
return 0;
if (grub_memcmp (buf + index, blockbuf, p->length) != 0)
{
grub_error (GRUB_ERR_FILE_READ_ERROR, "invalid blocklist");
return 0;
}
}
return 1;
}
static int
write_blocklists (grub_envblk_t envblk, struct blocklist *blocklists,
grub_file_t file)
{
char *buf;
grub_disk_t disk;
grub_disk_addr_t part_start;
struct blocklist *p;
grub_size_t index;
buf = grub_envblk_buffer (envblk);
disk = file->device->disk;
if (disk->partition)
part_start = grub_partition_get_start (disk->partition);
else
part_start = 0;
index = 0;
for (p = blocklists; p; index += p->length, p = p->next)
{
if (grub_disk_write (disk, p->sector - part_start,
p->offset, p->length, buf + index))
return 0;
}
return 1;
}
static grub_err_t
grub_cmd_save_env (grub_extcmd_t cmd, int argc, char **args)
{
struct grub_arg_list *state = cmd->state;
grub_file_t file;
grub_envblk_t envblk;
struct blocklist *head = 0;
struct blocklist *tail = 0;
/* Store blocklists in a linked list. */
auto void NESTED_FUNC_ATTR read_hook (grub_disk_addr_t sector,
unsigned offset,
unsigned length);
void NESTED_FUNC_ATTR read_hook (grub_disk_addr_t sector,
unsigned offset, unsigned length)
{
struct blocklist *block;
if (offset + length > GRUB_DISK_SECTOR_SIZE)
/* Seemingly a bug. */
return;
block = grub_malloc (sizeof (*block));
if (! block)
return;
block->sector = sector;
block->offset = offset;
block->length = length;
/* Slightly complicated, because the list should be FIFO. */
block->next = 0;
if (tail)
tail->next = block;
tail = block;
if (! head)
head = block;
}
if (! argc)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no variable is specified");
file = open_envblk_file ((state[0].set) ? state[0].arg : 0);
if (! file)
return grub_errno;
if (! file->device->disk)
{
grub_file_close (file);
return grub_error (GRUB_ERR_BAD_DEVICE, "disk device required");
}
file->read_hook = read_hook;
envblk = read_envblk_file (file);
file->read_hook = 0;
if (! envblk)
goto fail;
if (! check_blocklists (envblk, head, file))
goto fail;
while (argc)
{
char *value;
value = grub_env_get (args[0]);
if (value)
{
if (! grub_envblk_set (envblk, args[0], value))
{
grub_error (GRUB_ERR_BAD_ARGUMENT, "environment block too small");
goto fail;
}
}
argc--;
args++;
}
write_blocklists (envblk, head, file);
fail:
if (envblk)
grub_envblk_close (envblk);
free_blocklists (head);
grub_file_close (file);
return grub_errno;
}
static grub_extcmd_t cmd_load, cmd_list, cmd_save;
GRUB_MOD_INIT(loadenv)
{
cmd_load =
grub_register_extcmd ("load_env", grub_cmd_load_env,
GRUB_COMMAND_FLAG_BOTH,
N_("[-f FILE]"),
N_("Load variables from environment block file."),
options);
cmd_list =
grub_register_extcmd ("list_env", grub_cmd_list_env,
GRUB_COMMAND_FLAG_BOTH,
N_("[-f FILE]"),
N_("List variables from environment block file."),
options);
cmd_save =
grub_register_extcmd ("save_env", grub_cmd_save_env,
GRUB_COMMAND_FLAG_BOTH,
N_("[-f FILE] variable_name [...]"),
N_("Save variables to environment block file."),
options);
}
GRUB_MOD_FINI(loadenv)
{
grub_unregister_extcmd (cmd_load);
grub_unregister_extcmd (cmd_list);
grub_unregister_extcmd (cmd_save);
}

View File

@ -1,7 +1,7 @@
/* ls.c - command to list files and devices */ /* ls.c - command to list files and devices */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2003,2005,2007 Free Software Foundation, Inc. * Copyright (C) 2003,2005,2007,2008,2009 Free Software Foundation, Inc.
* *
* GRUB is free software: you can redistribute it and/or modify * GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -22,19 +22,21 @@
#include <grub/mm.h> #include <grub/mm.h>
#include <grub/err.h> #include <grub/err.h>
#include <grub/dl.h> #include <grub/dl.h>
#include <grub/normal.h>
#include <grub/arg.h>
#include <grub/disk.h> #include <grub/disk.h>
#include <grub/device.h> #include <grub/device.h>
#include <grub/term.h> #include <grub/term.h>
#include <grub/partition.h> #include <grub/partition.h>
#include <grub/file.h> #include <grub/file.h>
#include <grub/normal.h>
#include <grub/extcmd.h>
#include <grub/datetime.h>
#include <grub/i18n.h>
static const struct grub_arg_option options[] = static const struct grub_arg_option options[] =
{ {
{"long", 'l', 0, "show a long list with more detailed information", 0, 0}, {"long", 'l', 0, N_("Show a long list with more detailed information."), 0, 0},
{"human-readable", 'h', 0, "print sizes in a human readable format", 0, 0}, {"human-readable", 'h', 0, N_("Print sizes in a human readable format."), 0, 0},
{"all", 'a', 0, "list all files", 0, 0}, {"all", 'a', 0, N_("List all files."), 0, 0},
{0, 0, 0, 0, 0, 0} {0, 0, 0, 0, 0, 0}
}; };
@ -50,10 +52,10 @@ grub_ls_list_devices (int longlist)
grub_normal_print_device_info (name); grub_normal_print_device_info (name);
else else
grub_printf ("(%s) ", name); grub_printf ("(%s) ", name);
return 0; return 0;
} }
grub_device_iterate (grub_ls_print_devices); grub_device_iterate (grub_ls_print_devices);
grub_putchar ('\n'); grub_putchar ('\n');
grub_refresh (); grub_refresh ();
@ -68,28 +70,32 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
grub_fs_t fs; grub_fs_t fs;
const char *path; const char *path;
grub_device_t dev; grub_device_t dev;
auto int print_files (const char *filename, int dir);
auto int print_files_long (const char *filename, int dir); auto int print_files (const char *filename,
const struct grub_dirhook_info *info);
int print_files (const char *filename, int dir) auto int print_files_long (const char *filename,
const struct grub_dirhook_info *info);
int print_files (const char *filename, const struct grub_dirhook_info *info)
{ {
if (all || filename[0] != '.') if (all || filename[0] != '.')
grub_printf ("%s%s ", filename, dir ? "/" : ""); grub_printf ("%s%s ", filename, info->dir ? "/" : "");
return 0; return 0;
} }
int print_files_long (const char *filename, int dir) int print_files_long (const char *filename,
const struct grub_dirhook_info *info)
{ {
char pathname[grub_strlen (dirname) + grub_strlen (filename) + 1]; char pathname[grub_strlen (dirname) + grub_strlen (filename) + 1];
if ((! all) && (filename[0] == '.')) if ((! all) && (filename[0] == '.'))
return 0; return 0;
if (! dir) if (! info->dir)
{ {
grub_file_t file; grub_file_t file;
if (dirname[grub_strlen (dirname) - 1] == '/') if (dirname[grub_strlen (dirname) - 1] == '/')
grub_sprintf (pathname, "%s%s", dirname, filename); grub_sprintf (pathname, "%s%s", dirname, filename);
else else
@ -105,36 +111,56 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
} }
if (! human) if (! human)
grub_printf ("%-12llu", file->size); grub_printf ("%-12llu", (unsigned long long) file->size);
else else
{ {
float fsize = file->size; grub_uint64_t fsize = file->size * 100ULL;
int fsz = file->size; int fsz = file->size;
int units = 0; int units = 0;
char buf[20]; char buf[20];
while (fsz / 1024) while (fsz / 1024)
{ {
fsize /= 1024; fsize = (fsize + 512) / 1024;
fsz /= 1024; fsz /= 1024;
units++; units++;
} }
if (units) if (units)
{ {
grub_sprintf (buf, "%0.2f%c", fsize, grub_human_sizes[units]); grub_uint32_t whole, fraction;
whole = grub_divmod64 (fsize, 100, &fraction);
grub_sprintf (buf, "%u.%02u%c", whole, fraction,
grub_human_sizes[units]);
grub_printf ("%-12s", buf); grub_printf ("%-12s", buf);
} }
else else
grub_printf ("%-12llu", file->size); grub_printf ("%-12llu", (unsigned long long) file->size);
} }
grub_file_close (file); grub_file_close (file);
} }
else else
grub_printf ("%-12s", "DIR"); grub_printf ("%-12s", "DIR");
grub_printf ("%s%s\n", filename, dir ? "/" : ""); if (info->mtimeset)
{
struct grub_datetime datetime;
grub_unixtime2datetime (info->mtime, &datetime);
if (human)
grub_printf (" %d-%02d-%02d %02d:%02d:%02d %-11s ",
datetime.year, datetime.month, datetime.day,
datetime.hour, datetime.minute,
datetime.second,
grub_get_weekday_name (&datetime));
else
grub_printf (" %04d%02d%02d%02d%02d%02d ",
datetime.year, datetime.month,
datetime.day, datetime.hour,
datetime.minute, datetime.second);
}
grub_printf ("%s%s\n", filename, info->dir ? "/" : "");
return 0; return 0;
} }
@ -150,13 +176,13 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
path = dirname; path = dirname;
else else
path++; path++;
if (! path && ! device_name) if (! path && ! device_name)
{ {
grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid argument"); grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid argument");
goto fail; goto fail;
} }
if (! *path) if (! *path)
{ {
if (grub_errno == GRUB_ERR_UNKNOWN_FS) if (grub_errno == GRUB_ERR_UNKNOWN_FS)
@ -177,47 +203,50 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
/* PATH might be a regular file. */ /* PATH might be a regular file. */
char *p; char *p;
grub_file_t file; grub_file_t file;
struct grub_dirhook_info info;
grub_errno = 0; grub_errno = 0;
file = grub_file_open (dirname); file = grub_file_open (dirname);
if (! file) if (! file)
goto fail; goto fail;
grub_file_close (file); grub_file_close (file);
p = grub_strrchr (dirname, '/') + 1; p = grub_strrchr (dirname, '/') + 1;
dirname = grub_strndup (dirname, p - dirname); dirname = grub_strndup (dirname, p - dirname);
if (! dirname) if (! dirname)
goto fail; goto fail;
all = 1; all = 1;
grub_memset (&info, 0, sizeof (info));
if (longlist) if (longlist)
print_files_long (p, 0); print_files_long (p, &info);
else else
print_files (p, 0); print_files (p, &info);
grub_free (dirname); grub_free (dirname);
} }
if (grub_errno == GRUB_ERR_NONE) if (grub_errno == GRUB_ERR_NONE)
grub_putchar ('\n'); grub_putchar ('\n');
grub_refresh (); grub_refresh ();
} }
fail: fail:
if (dev) if (dev)
grub_device_close (dev); grub_device_close (dev);
grub_free (device_name); grub_free (device_name);
return 0; return 0;
} }
static grub_err_t static grub_err_t
grub_cmd_ls (struct grub_arg_list *state, int argc, char **args) grub_cmd_ls (grub_extcmd_t cmd, int argc, char **args)
{ {
struct grub_arg_list *state = cmd->state;
if (argc == 0) if (argc == 0)
grub_ls_list_devices (state[0].set); grub_ls_list_devices (state[0].set);
else else
@ -227,15 +256,16 @@ grub_cmd_ls (struct grub_arg_list *state, int argc, char **args)
return 0; return 0;
} }
static grub_extcmd_t cmd;
GRUB_MOD_INIT(ls) GRUB_MOD_INIT(ls)
{ {
(void)mod; /* To stop warning. */ cmd = grub_register_extcmd ("ls", grub_cmd_ls, GRUB_COMMAND_FLAG_BOTH,
grub_register_command ("ls", grub_cmd_ls, GRUB_COMMAND_FLAG_BOTH, N_("[-l|-h|-a] [FILE]"),
"ls [-l|-h|-a] [FILE]", N_("List devices and files."), options);
"List devices and files.", options);
} }
GRUB_MOD_FINI(ls) GRUB_MOD_FINI(ls)
{ {
grub_unregister_command ("ls"); grub_unregister_extcmd (cmd);
} }

53
commands/lsmmap.c Normal file
View File

@ -0,0 +1,53 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008 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/machine/memory.h>
#include <grub/dl.h>
#include <grub/misc.h>
#include <grub/command.h>
#include <grub/i18n.h>
static grub_err_t
grub_cmd_lsmmap (grub_command_t cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)), char **args __attribute__ ((unused)))
{
auto int NESTED_FUNC_ATTR hook (grub_uint64_t, grub_uint64_t, grub_uint32_t);
int NESTED_FUNC_ATTR hook (grub_uint64_t addr, grub_uint64_t size, grub_uint32_t type)
{
grub_printf ("base_addr = 0x%llx, length = 0x%llx, type = 0x%x\n",
(long long) addr, (long long) size, type);
return 0;
}
grub_machine_mmap_iterate (hook);
return 0;
}
static grub_command_t cmd;
GRUB_MOD_INIT(lsmmap)
{
cmd = grub_register_command ("lsmmap", grub_cmd_lsmmap,
0, N_("List memory map provided by firmware."));
}
GRUB_MOD_FINI(lsmmap)
{
grub_unregister_command (cmd);
}

228
commands/lspci.c Normal file
View File

@ -0,0 +1,228 @@
/* lspci.c - List PCI devices. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008, 2009 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/pci.h>
#include <grub/dl.h>
#include <grub/misc.h>
#include <grub/extcmd.h>
#include <grub/i18n.h>
struct grub_pci_classname
{
int class;
int subclass;
char *desc;
};
static const struct grub_pci_classname grub_pci_classes[] =
{
{ 0, 0, "" },
{ 1, 0, "SCSI Controller" },
{ 1, 1, "IDE Controller" },
{ 1, 2, "Floppy Controller" },
{ 1, 3, "IPI Controller" },
{ 1, 4, "RAID Controller" },
{ 1, 6, "SATA Controller" },
{ 1, 0x80, "Mass storage Controller" },
{ 2, 0, "Ethernet Controller" },
{ 2, 1, "Token Ring Controller" },
{ 2, 2, "FDDI Controller" },
{ 2, 3, "ATM Controller" },
{ 2, 4, "ISDN Controller" },
{ 2, 0x80, "Network controller" },
{ 3, 0, "VGA Controller" },
{ 3, 1, "XGA Controller" },
{ 3, 2, "3D Controller" },
{ 3, 0x80, "Display Controller" },
{ 4, 0, "Multimedia Video Device" },
{ 4, 1, "Multimedia Audio Device" },
{ 4, 2, "Multimedia Telephony Device" },
{ 4, 0x80, "Multimedia device" },
{ 5, 0, "RAM Controller" },
{ 5, 1, "Flash Memory Controller" },
{ 5, 0x80, "Memory Controller" },
{ 6, 0, "Host Bridge" },
{ 6, 1, "ISA Bridge" },
{ 6, 2, "EISA Bride" },
{ 6, 3, "MCA Bridge" },
{ 6, 4, "PCI-PCI Bridge" },
{ 6, 5, "PCMCIA Bridge" },
{ 6, 6, "NuBus Bridge" },
{ 6, 7, "CardBus Bridge" },
{ 6, 8, "Raceway Bridge" },
{ 6, 0x80, "Unknown Bridge" },
{ 7, 0x80, "Communication controller" },
{ 8, 0x80, "System hardware" },
{ 9, 0, "Keyboard Controller" },
{ 9, 1, "Digitizer" },
{ 9, 2, "Mouse Controller" },
{ 9, 3, "Scanner Controller" },
{ 9, 4, "Gameport Controller" },
{ 9, 0x80, "Unknown Input Device" },
{ 10, 0, "Generic Docking Station" },
{ 10, 0x80, "Unknown Docking Station" },
{ 11, 0, "80386 Processor" },
{ 11, 1, "80486 Processor" },
{ 11, 2, "Pentium Processor" },
{ 11, 0x10, "Alpha Processor" },
{ 11, 0x20, "PowerPC Processor" },
{ 11, 0x30, "MIPS Processor" },
{ 11, 0x40, "Co-Processor" },
{ 11, 0x80, "Unknown Processor" },
{ 12, 3, "USB Controller" },
{ 12, 0x80, "Serial Bus Controller" },
{ 13, 0x80, "Wireless Controller" },
{ 14, 0, "I2O" },
{ 15, 0, "IrDA Controller" },
{ 15, 1, "Consumer IR" },
{ 15, 0x10, "RF-Controller" },
{ 15, 0x80, "Satellite Communication Controller" },
{ 16, 0, "Network Decryption" },
{ 16, 1, "Entertainment Decryption" },
{ 16, 0x80, "Unknown Decryption Controller" },
{ 17, 0, "Digital IO Module" },
{ 17, 0x80, "Unknown Data Input System" },
{ 0, 0, 0 },
};
static const char *
grub_pci_get_class (int class, int subclass)
{
const struct grub_pci_classname *curr = grub_pci_classes;
while (curr->desc)
{
if (curr->class == class && curr->subclass == subclass)
return curr->desc;
curr++;
}
return 0;
}
static const struct grub_arg_option options[] =
{
{"iospace", 'i', 0, "show I/O spaces", 0, 0},
{0, 0, 0, 0, 0, 0}
};
static int iospace;
static int NESTED_FUNC_ATTR
grub_lspci_iter (grub_pci_device_t dev, grub_pci_id_t pciid)
{
grub_uint32_t class;
const char *sclass;
grub_pci_address_t addr;
int reg;
grub_printf ("%02x:%02x.%x %04x:%04x", grub_pci_get_bus (dev),
grub_pci_get_device (dev), grub_pci_get_function (dev),
pciid & 0xFFFF, pciid >> 16);
addr = grub_pci_make_address (dev, 2);
class = grub_pci_read (addr);
/* Lookup the class name, if there isn't a specific one,
retry with 0x80 to get the generic class name. */
sclass = grub_pci_get_class (class >> 24, (class >> 16) & 0xFF);
if (! sclass)
sclass = grub_pci_get_class (class >> 24, 0x80);
if (! sclass)
sclass = "";
grub_printf (" [%04x] %s", (class >> 16) & 0xffff, sclass);
grub_uint8_t pi = (class >> 8) & 0xff;
if (pi)
grub_printf (" [PI %02x]", pi);
grub_printf ("\n");
if (iospace)
{
reg = 4;
while (reg < 10)
{
grub_uint64_t space;
addr = grub_pci_make_address (dev, reg);
space = grub_pci_read (addr);
reg++;
if (space == 0)
continue;
switch (space & GRUB_PCI_ADDR_SPACE_MASK)
{
case GRUB_PCI_ADDR_SPACE_IO:
grub_printf ("\tIO space %d at 0x%llx\n", (reg - 1) - 4,
(unsigned long long)
(space & GRUB_PCI_ADDR_IO_MASK));
break;
case GRUB_PCI_ADDR_SPACE_MEMORY:
if ((space & GRUB_PCI_ADDR_MEM_TYPE_MASK)
== GRUB_PCI_ADDR_MEM_TYPE_64)
{
addr = grub_pci_make_address (dev, reg);
space |= ((grub_uint64_t) grub_pci_read (addr)) << 32;
reg++;
grub_printf ("\t64-bit memory space %d at 0x%016llx [%s]\n",
(reg - 2) - 4, (unsigned long long)
(space & GRUB_PCI_ADDR_MEM_MASK),
space & GRUB_PCI_ADDR_MEM_PREFETCH
? "prefetchable" : "non-prefetchable");
}
else
grub_printf ("\t32-bit memory space %d at 0x%016llx [%s]\n",
(reg - 1) - 4, (unsigned long long)
(space & GRUB_PCI_ADDR_MEM_MASK),
space & GRUB_PCI_ADDR_MEM_PREFETCH
? "prefetchable" : "non-prefetchable");
break;
}
}
}
return 0;
}
static grub_err_t
grub_cmd_lspci (grub_extcmd_t cmd,
int argc __attribute__ ((unused)),
char **args __attribute__ ((unused)))
{
iospace = cmd->state[0].set;
grub_pci_iterate (grub_lspci_iter);
return GRUB_ERR_NONE;
}
static grub_extcmd_t cmd;
GRUB_MOD_INIT(lspci)
{
cmd = grub_register_extcmd ("lspci", grub_cmd_lspci, GRUB_COMMAND_FLAG_BOTH,
"[-i]", N_("List PCI devices."), options);
}
GRUB_MOD_FINI(lspci)
{
grub_unregister_extcmd (cmd);
}

149
commands/memrw.c Normal file
View File

@ -0,0 +1,149 @@
/* memrw.c - command to read / write physical memory */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 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/dl.h>
#include <grub/misc.h>
#include <grub/extcmd.h>
#include <grub/env.h>
#include <grub/i18n.h>
static grub_extcmd_t cmd_read_byte, cmd_read_word, cmd_read_dword;
static grub_command_t cmd_write_byte, cmd_write_word, cmd_write_dword;
static const struct grub_arg_option options[] =
{
{0, 'v', 0, N_("Save read value into variable VARNAME."),
"VARNAME", ARG_TYPE_STRING},
{0, 0, 0, 0, 0, 0}
};
static grub_err_t
grub_cmd_read (grub_extcmd_t cmd, int argc, char **argv)
{
grub_target_addr_t addr;
grub_uint32_t value = 0;
char buf[sizeof ("XXXXXXXX")];
if (argc != 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid number of arguments");
addr = grub_strtoul (argv[0], 0, 0);
switch (cmd->cmd->name[sizeof ("read_") - 1])
{
case 'd':
value = *((volatile grub_uint32_t *) addr);
break;
case 'w':
value = *((volatile grub_uint16_t *) addr);
break;
case 'b':
value = *((volatile grub_uint8_t *) addr);
break;
}
if (cmd->state[0].set)
{
grub_sprintf (buf, "%x", value);
grub_env_set (cmd->state[0].arg, buf);
}
else
grub_printf ("0x%x\n", value);
return 0;
}
static grub_err_t
grub_cmd_write (grub_command_t cmd, int argc, char **argv)
{
grub_target_addr_t addr;
grub_uint32_t value;
grub_uint32_t mask = 0xffffffff;
if (argc != 2 && argc != 3)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid number of arguments");
addr = grub_strtoul (argv[0], 0, 0);
value = grub_strtoul (argv[1], 0, 0);
if (argc == 3)
mask = grub_strtoul (argv[2], 0, 0);
value &= mask;
switch (cmd->name[sizeof ("write_") - 1])
{
case 'd':
if (mask != 0xffffffff)
*((volatile grub_uint32_t *) addr)
= (*((volatile grub_uint32_t *) addr) & ~mask) | value;
else
*((volatile grub_uint32_t *) addr) = value;
break;
case 'w':
if ((mask & 0xffff) != 0xffff)
*((volatile grub_uint16_t *) addr)
= (*((volatile grub_uint16_t *) addr) & ~mask) | value;
else
*((volatile grub_uint16_t *) addr) = value;
break;
case 'b':
if ((mask & 0xff) != 0xff)
*((volatile grub_uint8_t *) addr)
= (*((volatile grub_uint8_t *) addr) & ~mask) | value;
else
*((volatile grub_uint8_t *) addr) = value;
break;
}
return 0;
}
GRUB_MOD_INIT(memrw)
{
cmd_read_byte =
grub_register_extcmd ("read_byte", grub_cmd_read, GRUB_COMMAND_FLAG_BOTH,
N_("ADDR"), N_("Read byte from ADDR."), options);
cmd_read_word =
grub_register_extcmd ("read_word", grub_cmd_read, GRUB_COMMAND_FLAG_BOTH,
N_("ADDR"), N_("Read word from ADDR."), options);
cmd_read_dword =
grub_register_extcmd ("read_dword", grub_cmd_read, GRUB_COMMAND_FLAG_BOTH,
N_("ADDR"), N_("Read dword from ADDR."), options);
cmd_write_byte =
grub_register_command ("write_byte", grub_cmd_write,
N_("ADDR VALUE [MASK]"), N_("Write byte VALUE to ADDR."));
cmd_write_word =
grub_register_command ("write_word", grub_cmd_write,
N_("ADDR VALUE [MASK]"), N_("Write word VALUE to ADDR."));
cmd_write_dword =
grub_register_command ("write_dword", grub_cmd_write,
N_("ADDR VALUE [MASK]"), N_("Write dword VALUE to ADDR."));
}
GRUB_MOD_FINI(memrw)
{
grub_unregister_extcmd (cmd_read_byte);
grub_unregister_extcmd (cmd_read_word);
grub_unregister_extcmd (cmd_read_dword);
grub_unregister_command (cmd_write_byte);
grub_unregister_command (cmd_write_word);
grub_unregister_command (cmd_write_dword);
}

392
commands/minicmd.c Normal file
View File

@ -0,0 +1,392 @@
/* minicmd.c - commands for the rescue mode */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2003,2005,2006,2007,2009 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/dl.h>
#include <grub/mm.h>
#include <grub/err.h>
#include <grub/env.h>
#include <grub/misc.h>
#include <grub/file.h>
#include <grub/disk.h>
#include <grub/term.h>
#include <grub/loader.h>
#include <grub/command.h>
#include <grub/i18n.h>
/* cat FILE */
static grub_err_t
grub_mini_cmd_cat (struct grub_command *cmd __attribute__ ((unused)),
int argc, char *argv[])
{
grub_file_t file;
char buf[GRUB_DISK_SECTOR_SIZE];
grub_ssize_t size;
if (argc < 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified");
file = grub_file_open (argv[0]);
if (! file)
return grub_errno;
while ((size = grub_file_read (file, buf, sizeof (buf))) > 0)
{
int i;
for (i = 0; i < size; i++)
{
unsigned char c = buf[i];
if ((grub_isprint (c) || grub_isspace (c)) && c != '\r')
grub_putchar (c);
else
{
grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT);
grub_printf ("<%x>", (int) c);
grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
}
}
}
grub_putchar ('\n');
grub_refresh ();
grub_file_close (file);
return 0;
}
/* help */
static grub_err_t
grub_mini_cmd_help (struct grub_command *cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)),
char *argv[] __attribute__ ((unused)))
{
grub_command_t p;
for (p = grub_command_list; p; p = p->next)
grub_printf ("%s (%d%c)\t%s\n", p->name,
p->prio & GRUB_PRIO_LIST_PRIO_MASK,
(p->prio & GRUB_PRIO_LIST_FLAG_ACTIVE) ? '+' : '-',
p->description);
return 0;
}
#if 0
static void
grub_rescue_cmd_info (void)
{
extern void grub_disk_cache_get_performance (unsigned long *,
unsigned long *);
unsigned long hits, misses;
grub_disk_cache_get_performance (&hits, &misses);
grub_printf ("Disk cache: hits = %u, misses = %u ", hits, misses);
if (hits + misses)
{
unsigned long ratio = hits * 10000 / (hits + misses);
grub_printf ("(%u.%u%%)\n", ratio / 100, ratio % 100);
}
else
grub_printf ("(N/A)\n");
}
#endif
/* root [DEVICE] */
static grub_err_t
grub_mini_cmd_root (struct grub_command *cmd __attribute__ ((unused)),
int argc, char *argv[])
{
grub_device_t dev;
grub_fs_t fs;
if (argc > 0)
{
char *device_name = grub_file_get_device_name (argv[0]);
if (! device_name)
return grub_errno;
grub_env_set ("root", device_name);
grub_free (device_name);
}
dev = grub_device_open (0);
if (! dev)
return grub_errno;
fs = grub_fs_probe (dev);
if (grub_errno == GRUB_ERR_UNKNOWN_FS)
grub_errno = GRUB_ERR_NONE;
grub_printf ("(%s): Filesystem is %s.\n",
grub_env_get ("root"), fs ? fs->name : "unknown");
grub_device_close (dev);
return 0;
}
#if 0
static void
grub_rescue_cmd_testload (int argc, char *argv[])
{
grub_file_t file;
char *buf;
grub_ssize_t size;
grub_ssize_t pos;
auto void read_func (unsigned long sector, unsigned offset, unsigned len);
void read_func (unsigned long sector __attribute__ ((unused)),
unsigned offset __attribute__ ((unused)),
unsigned len __attribute__ ((unused)))
{
grub_putchar ('.');
grub_refresh ();
}
if (argc < 1)
{
grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified");
return;
}
file = grub_file_open (argv[0]);
if (! file)
return;
size = grub_file_size (file) & ~(GRUB_DISK_SECTOR_SIZE - 1);
if (size == 0)
{
grub_file_close (file);
return;
}
buf = grub_malloc (size);
if (! buf)
goto fail;
grub_printf ("Reading %s sequentially", argv[0]);
file->read_hook = read_func;
if (grub_file_read (file, buf, size) != size)
goto fail;
grub_printf (" Done.\n");
/* Read sequentially again. */
grub_printf ("Reading %s sequentially again", argv[0]);
if (grub_file_seek (file, 0) < 0)
goto fail;
for (pos = 0; pos < size; pos += GRUB_DISK_SECTOR_SIZE)
{
char sector[GRUB_DISK_SECTOR_SIZE];
if (grub_file_read (file, sector, GRUB_DISK_SECTOR_SIZE)
!= GRUB_DISK_SECTOR_SIZE)
goto fail;
if (grub_memcmp (sector, buf + pos, GRUB_DISK_SECTOR_SIZE) != 0)
{
grub_printf ("\nDiffers in %d\n", pos);
goto fail;
}
}
grub_printf (" Done.\n");
/* Read backwards and compare. */
grub_printf ("Reading %s backwards", argv[0]);
pos = size;
while (pos > 0)
{
char sector[GRUB_DISK_SECTOR_SIZE];
pos -= GRUB_DISK_SECTOR_SIZE;
if (grub_file_seek (file, pos) < 0)
goto fail;
if (grub_file_read (file, sector, GRUB_DISK_SECTOR_SIZE)
!= GRUB_DISK_SECTOR_SIZE)
goto fail;
if (grub_memcmp (sector, buf + pos, GRUB_DISK_SECTOR_SIZE) != 0)
{
int i;
grub_printf ("\nDiffers in %d\n", pos);
for (i = 0; i < GRUB_DISK_SECTOR_SIZE; i++)
grub_putchar (buf[pos + i]);
if (i)
grub_refresh ();
goto fail;
}
}
grub_printf (" Done.\n");
fail:
grub_file_close (file);
grub_free (buf);
}
#endif
/* dump ADDRESS [SIZE] */
static grub_err_t
grub_mini_cmd_dump (struct grub_command *cmd __attribute__ ((unused)),
int argc, char *argv[])
{
grub_uint8_t *addr;
grub_size_t size = 4;
if (argc == 0)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no address specified");
addr = (grub_uint8_t *) grub_strtoul (argv[0], 0, 0);
if (grub_errno)
return grub_errno;
if (argc > 1)
size = (grub_size_t) grub_strtoul (argv[1], 0, 0);
while (size--)
{
grub_printf ("%x%x ", *addr >> 4, *addr & 0xf);
addr++;
}
return 0;
}
/* rmmod MODULE */
static grub_err_t
grub_mini_cmd_rmmod (struct grub_command *cmd __attribute__ ((unused)),
int argc, char *argv[])
{
grub_dl_t mod;
if (argc == 0)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no module specified");
mod = grub_dl_get (argv[0]);
if (! mod)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no such module");
if (grub_dl_unref (mod) <= 0)
grub_dl_unload (mod);
return 0;
}
/* lsmod */
static grub_err_t
grub_mini_cmd_lsmod (struct grub_command *cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)),
char *argv[] __attribute__ ((unused)))
{
auto int print_module (grub_dl_t mod);
int print_module (grub_dl_t mod)
{
grub_dl_dep_t dep;
grub_printf ("%s\t%d\t\t", mod->name, mod->ref_count);
for (dep = mod->dep; dep; dep = dep->next)
{
if (dep != mod->dep)
grub_putchar (',');
grub_printf ("%s", dep->mod->name);
}
grub_putchar ('\n');
grub_refresh ();
return 0;
}
grub_printf ("Name\tRef Count\tDependencies\n");
grub_dl_iterate (print_module);
return 0;
}
/* exit */
static grub_err_t
grub_mini_cmd_exit (struct grub_command *cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)),
char *argv[] __attribute__ ((unused)))
{
grub_exit ();
return 0;
}
/* clear */
static grub_err_t
grub_mini_cmd_clear (struct grub_command *cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)),
char *argv[] __attribute__ ((unused)))
{
grub_cls ();
return 0;
}
static grub_command_t cmd_cat, cmd_help, cmd_root;
static grub_command_t cmd_dump, cmd_rmmod, cmd_lsmod, cmd_exit;
static grub_command_t cmd_clear;
GRUB_MOD_INIT(minicmd)
{
cmd_cat =
grub_register_command ("cat", grub_mini_cmd_cat,
N_("FILE"), N_("Show the contents of a file."));
cmd_help =
grub_register_command ("help", grub_mini_cmd_help,
0, N_("Show this message."));
cmd_root =
grub_register_command ("root", grub_mini_cmd_root,
N_("[DEVICE]"), N_("Set the root device."));
cmd_dump =
grub_register_command ("dump", grub_mini_cmd_dump,
N_("ADDR"), N_("Dump memory."));
cmd_rmmod =
grub_register_command ("rmmod", grub_mini_cmd_rmmod,
N_("MODULE"), N_("Remove a module."));
cmd_lsmod =
grub_register_command ("lsmod", grub_mini_cmd_lsmod,
0, N_("Show loaded modules."));
cmd_exit =
grub_register_command ("exit", grub_mini_cmd_exit,
0, N_("Exit from GRUB."));
cmd_clear =
grub_register_command ("clear", grub_mini_cmd_clear,
0, N_("Clear the screen."));
}
GRUB_MOD_FINI(minicmd)
{
grub_unregister_command (cmd_cat);
grub_unregister_command (cmd_help);
grub_unregister_command (cmd_root);
grub_unregister_command (cmd_dump);
grub_unregister_command (cmd_rmmod);
grub_unregister_command (cmd_lsmod);
grub_unregister_command (cmd_exit);
grub_unregister_command (cmd_clear);
}

333
commands/parttool.c Normal file
View File

@ -0,0 +1,333 @@
/* parttool.c - common dispatcher and parser for partition operations */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 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/types.h>
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/err.h>
#include <grub/dl.h>
#include <grub/normal.h>
#include <grub/device.h>
#include <grub/disk.h>
#include <grub/partition.h>
#include <grub/parttool.h>
#include <grub/command.h>
#include <grub/i18n.h>
static struct grub_parttool *parts = 0;
static int curhandle = 0;
static grub_dl_t mymod;
static char helpmsg[] =
"Perform COMMANDS on partition.\n"
"Use \"parttool PARTITION help\" for the list "
"of available commands.";
int
grub_parttool_register(const char *part_name,
const grub_parttool_function_t func,
const struct grub_parttool_argdesc *args)
{
struct grub_parttool *cur;
int nargs = 0;
if (! parts)
grub_dl_ref (mymod);
cur = (struct grub_parttool *) grub_malloc (sizeof (struct grub_parttool));
cur->next = parts;
cur->name = grub_strdup (part_name);
cur->handle = curhandle++;
for (nargs = 0; args[nargs].name != 0; nargs++);
cur->nargs = nargs;
cur->args = (struct grub_parttool_argdesc *)
grub_malloc ((nargs + 1) * sizeof (struct grub_parttool_argdesc));
grub_memcpy (cur->args, args,
(nargs + 1) * sizeof (struct grub_parttool_argdesc));
cur->func = func;
parts = cur;
return cur->handle;
}
void
grub_parttool_unregister (int handle)
{
struct grub_parttool *prev = 0, *cur, *t;
for (cur = parts; cur; )
if (cur->handle == handle)
{
grub_free (cur->args);
grub_free (cur->name);
if (prev)
prev->next = cur->next;
else
parts = cur->next;
t = cur;
cur = cur->next;
grub_free (t);
}
else
{
prev = cur;
cur = cur->next;
}
if (! parts)
grub_dl_unref (mymod);
}
static grub_err_t
grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
int argc, char **args)
{
grub_device_t dev;
struct grub_parttool *cur, *ptool;
int *parsed;
int i, j;
grub_err_t err = GRUB_ERR_NONE;
auto grub_err_t show_help (void);
grub_err_t show_help (void)
{
int found = 0;
for (cur = parts; cur; cur = cur->next)
if (grub_strcmp (dev->disk->partition->partmap->name, cur->name) == 0)
{
struct grub_parttool_argdesc *curarg;
found = 1;
for (curarg = cur->args; curarg->name; curarg++)
{
int spacing = 20;
spacing -= grub_strlen (curarg->name);
grub_printf ("%s", curarg->name);
switch (curarg->type)
{
case GRUB_PARTTOOL_ARG_BOOL:
grub_printf ("+/-");
spacing -= 3;
break;
case GRUB_PARTTOOL_ARG_VAL:
grub_printf ("=VAL");
spacing -= 4;
break;
case GRUB_PARTTOOL_ARG_END:
break;
}
while (spacing-- > 0)
grub_printf (" ");
grub_printf ("%s\n", curarg->desc);
}
}
if (! found)
grub_printf ("Sorry no parttool is available for %s\n",
dev->disk->partition->partmap->name);
return GRUB_ERR_NONE;
}
if (argc < 1)
{
grub_printf ("%s\n", helpmsg);
return grub_error (GRUB_ERR_BAD_ARGUMENT, "too few arguments");
}
if (args[0][0] == '(' && args[0][grub_strlen (args[0]) - 1] == ')')
{
args[0][grub_strlen (args[0]) - 1] = 0;
dev = grub_device_open (args[0] + 1);
args[0][grub_strlen (args[0]) - 1] = ')';
}
else
dev = grub_device_open (args[0]);
if (! dev)
return grub_errno;
if (! dev->disk)
{
grub_device_close (dev);
return grub_error (GRUB_ERR_BAD_ARGUMENT, "not a disk");
}
if (! dev->disk->partition)
{
grub_device_close (dev);
return grub_error (GRUB_ERR_BAD_ARGUMENT, "not a partition");
}
/* Load modules. */
#ifndef GRUB_UTIL
{
const char *prefix;
prefix = grub_env_get ("prefix");
if (prefix)
{
char *filename;
filename = grub_malloc (grub_strlen (prefix) + sizeof ("/parttool.lst"));
if (filename)
{
grub_file_t file;
grub_sprintf (filename, "%s/parttool.lst", prefix);
file = grub_file_open (filename);
if (file)
{
char *buf = 0;
for (;; grub_free(buf))
{
char *p, *name;
buf = grub_file_getline (file);
if (! buf)
break;
name = buf;
if (! grub_isgraph (name[0]))
continue;
p = grub_strchr (name, ':');
if (! p)
continue;
*p = '\0';
while (*++p == ' ')
;
if (! grub_isgraph (*p))
continue;
if (grub_strcmp (name, dev->disk->partition->partmap->name)
!= 0)
continue;
grub_dl_load (p);
}
grub_file_close (file);
}
grub_free (filename);
}
}
/* Ignore errors. */
grub_errno = GRUB_ERR_NONE;
}
#endif
if (argc == 1)
return show_help ();
for (i = 1; i < argc; i++)
if (grub_strcmp (args[i], "help") == 0)
return show_help ();
parsed = (int *) grub_zalloc (argc * sizeof (int));
for (i = 1; i < argc; i++)
if (! parsed[i])
{
struct grub_parttool_argdesc *curarg;
struct grub_parttool_args *pargs;
for (cur = parts; cur; cur = cur->next)
if (grub_strcmp (dev->disk->partition->partmap->name, cur->name) == 0)
{
for (curarg = cur->args; curarg->name; curarg++)
if (grub_strncmp (curarg->name, args[i],
grub_strlen (curarg->name)) == 0
&& ((curarg->type == GRUB_PARTTOOL_ARG_BOOL
&& (args[i][grub_strlen (curarg->name)] == '+'
|| args[i][grub_strlen (curarg->name)] == '-'
|| args[i][grub_strlen (curarg->name)] == 0))
|| (curarg->type == GRUB_PARTTOOL_ARG_VAL
&& args[i][grub_strlen (curarg->name)] == '=')))
break;
if (curarg->name)
break;
}
if (! cur)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "unrecognised argument %s",
args[i]);
ptool = cur;
pargs = (struct grub_parttool_args *)
grub_zalloc (ptool->nargs * sizeof (struct grub_parttool_args));
for (j = i; j < argc; j++)
if (! parsed[j])
{
for (curarg = ptool->args; curarg->name; curarg++)
if (grub_strncmp (curarg->name, args[i],
grub_strlen (curarg->name)) == 0
&& ((curarg->type == GRUB_PARTTOOL_ARG_BOOL
&& (args[j][grub_strlen (curarg->name)] == '+'
|| args[j][grub_strlen (curarg->name)] == '-'
|| args[j][grub_strlen (curarg->name)] == 0))
|| (curarg->type == GRUB_PARTTOOL_ARG_VAL
&& args[j][grub_strlen (curarg->name)] == '=')))
{
parsed[j] = 1;
pargs[curarg - ptool->args].set = 1;
switch (curarg->type)
{
case GRUB_PARTTOOL_ARG_BOOL:
pargs[curarg - ptool->args].bool
= (args[j][grub_strlen (curarg->name)] != '-');
break;
case GRUB_PARTTOOL_ARG_VAL:
pargs[curarg - ptool->args].str
= (args[j] + grub_strlen (curarg->name) + 1);
break;
case GRUB_PARTTOOL_ARG_END:
break;
}
}
}
err = ptool->func (dev, pargs);
grub_free (pargs);
if (err)
break;
}
grub_free (parsed);
grub_device_close (dev);
return err;
}
static grub_command_t cmd;
GRUB_MOD_INIT(parttool)
{
mymod = mod;
cmd = grub_register_command ("parttool", grub_cmd_parttool,
N_("PARTITION COMMANDS"),
helpmsg);
}
GRUB_MOD_FINI(parttool)
{
grub_unregister_command (cmd);
}

86
commands/password.c Normal file
View File

@ -0,0 +1,86 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 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/auth.h>
#include <grub/crypto.h>
#include <grub/list.h>
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/env.h>
#include <grub/normal.h>
#include <grub/dl.h>
#include <grub/i18n.h>
static grub_dl_t my_mod;
static grub_err_t
check_password (const char *user, const char *entered,
void *password)
{
if (grub_crypto_memcmp (entered, password, GRUB_AUTH_MAX_PASSLEN) != 0)
return GRUB_ACCESS_DENIED;
grub_auth_authenticate (user);
return GRUB_ERR_NONE;
}
static grub_err_t
grub_cmd_password (grub_command_t cmd __attribute__ ((unused)),
int argc, char **args)
{
grub_err_t err;
char *pass;
int copylen;
if (argc != 2)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "two arguments expected");
pass = grub_zalloc (GRUB_AUTH_MAX_PASSLEN);
if (!pass)
return grub_errno;
copylen = grub_strlen (args[1]);
if (copylen >= GRUB_AUTH_MAX_PASSLEN)
copylen = GRUB_AUTH_MAX_PASSLEN - 1;
grub_memcpy (pass, args[1], copylen);
err = grub_auth_register_authentication (args[0], check_password, pass);
if (err)
{
grub_free (pass);
return err;
}
grub_dl_ref (my_mod);
return GRUB_ERR_NONE;
}
static grub_command_t cmd;
GRUB_MOD_INIT(password)
{
my_mod = mod;
cmd = grub_register_command ("password", grub_cmd_password,
N_("USER PASSWORD"),
N_("Set user password (plaintext). "
"Unrecommended and insecure."));
}
GRUB_MOD_FINI(password)
{
grub_unregister_command (cmd);
}

196
commands/password_pbkdf2.c Normal file
View File

@ -0,0 +1,196 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 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/auth.h>
#include <grub/crypto.h>
#include <grub/list.h>
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/env.h>
#include <grub/normal.h>
#include <grub/dl.h>
static grub_dl_t my_mod;
struct pbkdf2_password
{
grub_uint8_t *salt;
grub_size_t saltlen;
unsigned int c;
grub_uint8_t *expected;
grub_size_t buflen;
};
static grub_err_t
check_password (const char *user, const char *entered, void *pin)
{
grub_uint8_t *buf;
struct pbkdf2_password *pass = pin;
gcry_err_code_t err;
buf = grub_malloc (pass->buflen);
if (!buf)
return grub_crypto_gcry_error (GPG_ERR_OUT_OF_MEMORY);
err = grub_crypto_pbkdf2 (GRUB_MD_SHA512, (grub_uint8_t *) entered,
grub_strlen (entered),
pass->salt, pass->saltlen, pass->c,
buf, pass->buflen);
if (err)
{
grub_free (buf);
return grub_crypto_gcry_error (err);
}
if (grub_crypto_memcmp (buf, pass->expected, pass->buflen) != 0)
return GRUB_ACCESS_DENIED;
grub_auth_authenticate (user);
return GRUB_ERR_NONE;
}
static inline int
hex2val (char hex)
{
if ('0' <= hex && hex <= '9')
return hex - '0';
if ('a' <= hex && hex <= 'f')
return hex - 'a' + 10;
if ('A' <= hex && hex <= 'F')
return hex - 'A' + 10;
return -1;
}
static grub_err_t
grub_cmd_password (grub_command_t cmd __attribute__ ((unused)),
int argc, char **args)
{
grub_err_t err;
char *ptr, *ptr2;
grub_uint8_t *ptro;
struct pbkdf2_password *pass;
if (argc != 2)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "Two arguments expected.");
if (grub_memcmp (args[1], "grub.pbkdf2.sha512.",
sizeof ("grub.pbkdf2.sha512.") - 1) != 0)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "Incorrect PBKDF2 password.");
ptr = args[1] + sizeof ("grub.pbkdf2.sha512.") - 1;
pass = grub_malloc (sizeof (*pass));
if (!pass)
return grub_errno;
pass->c = grub_strtoul (ptr, &ptr, 0);
if (*ptr != '.')
{
grub_free (pass);
return grub_error (GRUB_ERR_BAD_ARGUMENT, "Incorrect PBKDF2 password.");
}
ptr++;
ptr2 = grub_strchr (ptr, '.');
if (!ptr2 || ((ptr2 - ptr) & 1) || grub_strlen (ptr2 + 1) & 1)
{
grub_free (pass);
return grub_error (GRUB_ERR_BAD_ARGUMENT, "Incorrect PBKDF2 password.");
}
pass->saltlen = (ptr2 - ptr) >> 1;
pass->buflen = grub_strlen (ptr2 + 1) >> 1;
ptro = pass->salt = grub_malloc (pass->saltlen);
if (!ptro)
{
grub_free (pass);
return grub_errno;
}
while (ptr < ptr2)
{
int hex1, hex2;
hex1 = hex2val (*ptr);
ptr++;
hex2 = hex2val (*ptr);
ptr++;
if (hex1 < 0 || hex2 < 0)
{
grub_free (pass->salt);
grub_free (pass);
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"Incorrect PBKDF2 password.");
}
*ptro = (hex1 << 4) | hex2;
ptro++;
}
ptro = pass->expected = grub_malloc (pass->buflen);
if (!ptro)
{
grub_free (pass->salt);
grub_free (pass);
return grub_errno;
}
ptr = ptr2 + 1;
ptr2 += grub_strlen (ptr2);
while (ptr < ptr2)
{
int hex1, hex2;
hex1 = hex2val (*ptr);
ptr++;
hex2 = hex2val (*ptr);
ptr++;
if (hex1 < 0 || hex2 < 0)
{
grub_free (pass->expected);
grub_free (pass->salt);
grub_free (pass);
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"Incorrect PBKDF2 password.");
}
*ptro = (hex1 << 4) | hex2;
ptro++;
}
err = grub_auth_register_authentication (args[0], check_password, pass);
if (err)
{
grub_free (pass);
return err;
}
grub_dl_ref (my_mod);
return GRUB_ERR_NONE;
}
static grub_command_t cmd;
GRUB_MOD_INIT(password_pbkdf2)
{
my_mod = mod;
cmd = grub_register_command ("password_pbkdf2", grub_cmd_password,
"password_pbkdf2 USER PBKDF2_PASSWORD",
"Set user password (PBKDF2). ");
}
GRUB_MOD_FINI(password_pbkdf2)
{
grub_unregister_command (cmd);
}

161
commands/probe.c Normal file
View File

@ -0,0 +1,161 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 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/types.h>
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/err.h>
#include <grub/dl.h>
#include <grub/device.h>
#include <grub/disk.h>
#include <grub/partition.h>
#include <grub/net.h>
#include <grub/fs.h>
#include <grub/file.h>
#include <grub/misc.h>
#include <grub/env.h>
#include <grub/extcmd.h>
#include <grub/i18n.h>
static const struct grub_arg_option options[] =
{
{"set", 's', GRUB_ARG_OPTION_OPTIONAL,
N_("Set a variable to return value."), "VAR", ARG_TYPE_STRING},
{"driver", 'd', 0, N_("Determine driver."), 0, 0},
{"partmap", 'p', 0, N_("Determine partition map type."), 0, 0},
{"fs", 'f', 0, N_("Determine filesystem type."), 0, 0},
{"fs-uuid", 'u', 0, N_("Determine filesystem UUID."), 0, 0},
{"label", 'l', 0, N_("Determine filesystem label."), 0, 0},
{0, 0, 0, 0, 0, 0}
};
static grub_err_t
grub_cmd_probe (grub_extcmd_t cmd, int argc, char **args)
{
struct grub_arg_list *state = cmd->state;
grub_device_t dev;
grub_fs_t fs;
char *ptr;
grub_err_t err;
if (argc < 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required");
ptr = args[0] + grub_strlen (args[0]) - 1;
if (args[0][0] == '(' && *ptr == ')')
{
*ptr = 0;
dev = grub_device_open (args[0] + 1);
*ptr = ')';
}
else
dev = grub_device_open (args[0]);
if (! dev)
return grub_error (GRUB_ERR_BAD_DEVICE, "couldn't open device");
if (state[1].set)
{
const char *val = "none";
if (dev->net)
val = dev->net->dev->name;
if (dev->disk)
val = dev->disk->dev->name;
if (state[0].set)
grub_env_set (state[0].arg, val);
else
grub_printf ("%s", val);
return GRUB_ERR_NONE;
}
if (state[2].set)
{
const char *val = "none";
if (dev->disk && dev->disk->partition)
val = dev->disk->partition->partmap->name;
if (state[0].set)
grub_env_set (state[0].arg, val);
else
grub_printf ("%s", val);
return GRUB_ERR_NONE;
}
fs = grub_fs_probe (dev);
if (! fs)
return grub_error (GRUB_ERR_UNKNOWN_FS, "unrecognised fs");
if (state[3].set)
{
if (state[0].set)
grub_env_set (state[0].arg, fs->name);
else
grub_printf ("%s", fs->name);
return GRUB_ERR_NONE;
}
if (state[4].set)
{
char *uuid;
if (! fs->uuid)
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"uuid for this FS isn't supported yet");
err = fs->uuid (dev, &uuid);
if (err)
return err;
if (! uuid)
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"uuid for this FS isn't supported yet");
if (state[0].set)
grub_env_set (state[0].arg, uuid);
else
grub_printf ("%s", uuid);
grub_free (uuid);
return GRUB_ERR_NONE;
}
if (state[5].set)
{
char *label;
if (! fs->label)
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"label for this FS isn't supported yet");
err = fs->label (dev, &label);
if (err)
return err;
if (! label)
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"uuid for this FS isn't supported yet");
if (state[0].set)
grub_env_set (state[0].arg, label);
else
grub_printf ("%s", label);
grub_free (label);
return GRUB_ERR_NONE;
}
return grub_error (GRUB_ERR_BAD_ARGUMENT, "unrecognised target");
}
static grub_extcmd_t cmd;
GRUB_MOD_INIT (probe)
{
cmd = grub_register_extcmd ("probe", grub_cmd_probe, GRUB_COMMAND_FLAG_BOTH,
N_("[DEVICE]"),
N_("Retrieve device info."), options);
}
GRUB_MOD_FINI (probe)
{
grub_unregister_extcmd (cmd);
}

90
commands/read.c Normal file
View File

@ -0,0 +1,90 @@
/* read.c - Command to read variables from user. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2006,2007,2008 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/dl.h>
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/env.h>
#include <grub/term.h>
#include <grub/types.h>
#include <grub/command.h>
#include <grub/i18n.h>
static char *
grub_getline (void)
{
int i;
char *line;
char *tmp;
char c;
i = 0;
line = grub_malloc (1 + i + sizeof('\0'));
if (! line)
return NULL;
while (1)
{
c = grub_getkey ();
if ((c == '\n') || (c == '\r'))
break;
line[i] = c;
if (grub_isprint (c))
grub_putchar (c);
i++;
tmp = grub_realloc (line, 1 + i + sizeof('\0'));
if (! tmp)
{
grub_free (line);
return NULL;
}
line = tmp;
}
line[i] = '\0';
return line;
}
static grub_err_t
grub_cmd_read (grub_command_t cmd __attribute__ ((unused)), int argc, char **args)
{
char *line = grub_getline ();
if (! line)
return grub_errno;
if (argc > 0)
grub_env_set (args[0], line);
grub_free (line);
return 0;
}
static grub_command_t cmd;
GRUB_MOD_INIT(read)
{
cmd = grub_register_command ("read", grub_cmd_read,
N_("[ENVVAR]"),
N_("Set variable with user input."));
}
GRUB_MOD_FINI(read)
{
grub_unregister_command (cmd);
}

View File

@ -1,7 +1,7 @@
/* reboot.c - command to reboot the computer. */ /* reboot.c - command to reboot the computer. */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2005,2007 Free Software Foundation, Inc. * Copyright (C) 2005,2007,2008 Free Software Foundation, Inc.
* *
* GRUB is free software: you can redistribute it and/or modify * GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -17,31 +17,29 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <grub/normal.h>
#include <grub/dl.h> #include <grub/dl.h>
#include <grub/arg.h> #include <grub/command.h>
#include <grub/machine/init.h> #include <grub/misc.h>
#include <grub/i18n.h>
static grub_err_t static grub_err_t
grub_cmd_reboot (struct grub_arg_list *state __attribute__ ((unused)), grub_cmd_reboot (grub_command_t cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)), int argc __attribute__ ((unused)),
char **args __attribute__ ((unused))) char **args __attribute__ ((unused)))
{ {
grub_reboot (); grub_reboot ();
return 0; return 0;
} }
static grub_command_t cmd;
GRUB_MOD_INIT(reboot) GRUB_MOD_INIT(reboot)
{ {
(void)mod; /* To stop warning. */ cmd = grub_register_command ("reboot", grub_cmd_reboot,
grub_register_command ("reboot", grub_cmd_reboot, GRUB_COMMAND_FLAG_BOTH, 0, N_("Reboot the computer."));
"reboot", "Reboot the computer", 0);
} }
GRUB_MOD_FINI(reboot) GRUB_MOD_FINI(reboot)
{ {
grub_unregister_command ("reboot"); grub_unregister_command (cmd);
} }

View File

@ -1,7 +1,7 @@
/* search.c - search devices based on a file or a filesystem label */ /* search.c - search devices based on a file or a filesystem label */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2005,2007 Free Software Foundation, Inc. * Copyright (C) 2005,2007,2008,2009 Free Software Foundation, Inc.
* *
* GRUB is free software: you can redistribute it and/or modify * GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -22,144 +22,160 @@
#include <grub/mm.h> #include <grub/mm.h>
#include <grub/err.h> #include <grub/err.h>
#include <grub/dl.h> #include <grub/dl.h>
#include <grub/normal.h>
#include <grub/arg.h>
#include <grub/device.h> #include <grub/device.h>
#include <grub/file.h> #include <grub/file.h>
#include <grub/env.h> #include <grub/env.h>
#include <grub/command.h>
#include <grub/search.h>
#include <grub/i18n.h>
static const struct grub_arg_option options[] = void
{ FUNC_NAME (const char *key, const char *var, int no_floppy)
{"file", 'f', 0, "search devices by a file (default)", 0, 0},
{"label", 'l', 0, "search devices by a filesystem label", 0, 0},
{"set", 's', GRUB_ARG_OPTION_OPTIONAL, "set a variable to the first device found", "VAR", ARG_TYPE_STRING},
{0, 0, 0, 0, 0, 0}
};
static void
search_label (const char *key, const char *var)
{ {
int count = 0; int count = 0;
char *buf = NULL;
grub_fs_autoload_hook_t saved_autoload;
auto int iterate_device (const char *name); auto int iterate_device (const char *name);
int iterate_device (const char *name) int iterate_device (const char *name)
{ {
grub_device_t dev; int found = 0;
dev = grub_device_open (name);
if (dev)
{
grub_fs_t fs;
fs = grub_fs_probe (dev);
if (fs && fs->label)
{
char *label;
(fs->label) (dev, &label);
if (grub_errno == GRUB_ERR_NONE && label)
{
if (grub_strcmp (label, key) == 0)
{
/* Found! */
grub_printf (" %s", name);
if (count++ == 0 && var)
grub_env_set (var, name);
}
grub_free (label);
}
}
grub_device_close (dev);
}
grub_errno = GRUB_ERR_NONE; /* Skip floppy drives when requested. */
if (no_floppy &&
name[0] == 'f' && name[1] == 'd' && name[2] >= '0' && name[2] <= '9')
return 0; return 0;
#ifdef DO_SEARCH_FILE
{
grub_size_t len;
char *p;
grub_file_t file;
len = grub_strlen (name) + 2 + grub_strlen (key) + 1;
p = grub_realloc (buf, len);
if (! p)
return 1;
buf = p;
grub_sprintf (buf, "(%s)%s", name, key);
file = grub_file_open (buf);
if (file)
{
found = 1;
grub_file_close (file);
}
}
#else
{
/* SEARCH_FS_UUID or SEARCH_LABEL */
grub_device_t dev;
grub_fs_t fs;
char *quid;
dev = grub_device_open (name);
if (dev)
{
fs = grub_fs_probe (dev);
#ifdef DO_SEARCH_FS_UUID
#define compare_fn grub_strcasecmp
#define read_fn uuid
#else
#define compare_fn grub_strcmp
#define read_fn label
#endif
if (fs && fs->read_fn)
{
fs->read_fn (dev, &quid);
if (grub_errno == GRUB_ERR_NONE && quid)
{
if (compare_fn (quid, key) == 0)
found = 1;
grub_free (quid);
}
}
grub_device_close (dev);
}
}
#endif
if (found)
{
count++;
if (var)
grub_env_set (var, name);
else
grub_printf (" %s", name);
}
grub_errno = GRUB_ERR_NONE;
return (found && var);
}
/* First try without autoloading if we're setting variable. */
if (var)
{
saved_autoload = grub_fs_autoload_hook;
grub_fs_autoload_hook = 0;
grub_device_iterate (iterate_device);
/* Restore autoload hook. */
grub_fs_autoload_hook = saved_autoload;
/* Retry with autoload if nothing found. */
if (grub_errno == GRUB_ERR_NONE && count == 0)
grub_device_iterate (iterate_device);
} }
else
grub_device_iterate (iterate_device); grub_device_iterate (iterate_device);
if (count == 0) grub_free (buf);
if (grub_errno == GRUB_ERR_NONE && count == 0)
grub_error (GRUB_ERR_FILE_NOT_FOUND, "no such device: %s", key); grub_error (GRUB_ERR_FILE_NOT_FOUND, "no such device: %s", key);
} }
static void
search_file (const char *key, const char *var)
{
int count = 0;
char *buf = 0;
auto int iterate_device (const char *name);
int iterate_device (const char *name)
{
grub_size_t len;
char *p;
grub_file_t file;
len = grub_strlen (name) + 2 + grub_strlen (key) + 1;
p = grub_realloc (buf, len);
if (! p)
return 1;
buf = p;
grub_sprintf (buf, "(%s)%s", name, key);
file = grub_file_open (buf);
if (file)
{
/* Found! */
grub_printf (" %s", name);
if (count++ == 0 && var)
grub_env_set (var, name);
grub_file_close (file);
}
grub_errno = GRUB_ERR_NONE;
return 0;
}
grub_device_iterate (iterate_device);
grub_free (buf);
if (grub_errno == GRUB_ERR_NONE && count == 0)
grub_error (GRUB_ERR_FILE_NOT_FOUND, "no such device");
}
static grub_err_t static grub_err_t
grub_cmd_search (struct grub_arg_list *state, int argc, char **args) grub_cmd_do_search (grub_command_t cmd __attribute__ ((unused)), int argc,
char **args)
{ {
const char *var = 0;
if (argc == 0) if (argc == 0)
return grub_error (GRUB_ERR_INVALID_COMMAND, "no argument specified"); return grub_error (GRUB_ERR_BAD_ARGUMENT, "no argument specified");
if (state[2].set) FUNC_NAME (args[0], argc == 1 ? 0 : args[1], 0);
var = state[2].arg ? : "root";
if (state[1].set)
search_label (args[0], var);
else
search_file (args[0], var);
return grub_errno; return grub_errno;
} }
GRUB_MOD_INIT(search) static grub_command_t cmd;
#ifdef DO_SEARCH_FILE
GRUB_MOD_INIT(search_file)
#elif defined (DO_SEARCH_FS_UUID)
GRUB_MOD_INIT(search_fs_uuid)
#else
GRUB_MOD_INIT(search_fs_label)
#endif
{ {
(void) mod; /* To stop warning. */ cmd =
grub_register_command ("search", grub_cmd_search, GRUB_COMMAND_FLAG_BOTH, grub_register_command (COMMAND_NAME, grub_cmd_do_search,
"search [-f|-l|-s] NAME", N_("NAME [VARIABLE]"),
"Search devices by a file or a filesystem label." HELP_MESSAGE);
" If --set is specified, the first device found is"
" set to a variable. If no variable name is"
" specified, \"root\" is used.",
options);
} }
GRUB_MOD_FINI(search) #ifdef DO_SEARCH_FILE
GRUB_MOD_FINI(search_file)
#elif defined (DO_SEARCH_FS_UUID)
GRUB_MOD_FINI(search_fs_uuid)
#else
GRUB_MOD_FINI(search_fs_label)
#endif
{ {
grub_unregister_command ("search"); grub_unregister_command (cmd);
} }

6
commands/search_file.c Normal file
View File

@ -0,0 +1,6 @@
#define DO_SEARCH_FILE 1
#define FUNC_NAME grub_search_fs_file
#define COMMAND_NAME "search.file"
#define SEARCH_TARGET "file"
#define HELP_MESSAGE N_("Search devices by file. If VARIABLE is specified, the first device found is set to a variable.")
#include "search.c"

6
commands/search_label.c Normal file
View File

@ -0,0 +1,6 @@
#define DO_SEARCH_FS_LABEL 1
#define FUNC_NAME grub_search_label
#define COMMAND_NAME "search.fs_label"
#define SEARCH_TARGET "filesystem label"
#define HELP_MESSAGE N_("Search devices by label. If VARIABLE is specified, the first device found is set to a variable.")
#include "search.c"

6
commands/search_uuid.c Normal file
View File

@ -0,0 +1,6 @@
#define DO_SEARCH_FS_UUID 1
#define FUNC_NAME grub_search_fs_uuid
#define COMMAND_NAME "search.fs_uuid"
#define SEARCH_TARGET "filesystem UUID"
#define HELP_MESSAGE N_("Search devices by UUID. If VARIABLE is specified, the first device found is set to a variable.")
#include "search.c"

95
commands/search_wrap.c Normal file
View File

@ -0,0 +1,95 @@
/* search.c - search devices based on a file or a filesystem label */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2005,2007,2008,2009 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/types.h>
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/err.h>
#include <grub/dl.h>
#include <grub/env.h>
#include <grub/extcmd.h>
#include <grub/search.h>
#include <grub/i18n.h>
static const struct grub_arg_option options[] =
{
{"file", 'f', 0, N_("Search devices by a file."), 0, 0},
{"label", 'l', 0, N_("Search devices by a filesystem label."),
0, 0},
{"fs-uuid", 'u', 0, N_("Search devices by a filesystem UUID."),
0, 0},
{"set", 's', GRUB_ARG_OPTION_OPTIONAL,
N_("Set a variable to the first device found."), "VAR", ARG_TYPE_STRING},
{"no-floppy", 'n', 0, N_("Do not probe any floppy drive."), 0, 0},
{0, 0, 0, 0, 0, 0}
};
enum options
{
SEARCH_FILE,
SEARCH_LABEL,
SEARCH_FS_UUID,
SEARCH_SET,
SEARCH_NO_FLOPPY,
};
static grub_err_t
grub_cmd_search (grub_extcmd_t cmd, int argc, char **args)
{
struct grub_arg_list *state = cmd->state;
const char *var = 0;
if (argc == 0)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no argument specified");
if (state[SEARCH_SET].set)
var = state[SEARCH_SET].arg ? state[SEARCH_SET].arg : "root";
if (state[SEARCH_LABEL].set)
grub_search_label (args[0], var, state[SEARCH_NO_FLOPPY].set);
else if (state[SEARCH_FS_UUID].set)
grub_search_fs_uuid (args[0], var, state[SEARCH_NO_FLOPPY].set);
else if (state[SEARCH_FILE].set)
grub_search_fs_file (args[0], var, state[SEARCH_NO_FLOPPY].set);
else
return grub_error (GRUB_ERR_INVALID_COMMAND, "unspecified search type");
return grub_errno;
}
static grub_extcmd_t cmd;
GRUB_MOD_INIT(search)
{
cmd =
grub_register_extcmd ("search", grub_cmd_search,
GRUB_COMMAND_FLAG_BOTH,
N_("search [-f|-l|-u|-s|-n] NAME"),
N_("Search devices by file, filesystem label"
" or filesystem UUID."
" If --set is specified, the first device found is"
" set to a variable. If no variable name is"
" specified, \"root\" is used."),
options);
}
GRUB_MOD_FINI(search)
{
grub_unregister_extcmd (cmd);
}

114
commands/sleep.c Normal file
View File

@ -0,0 +1,114 @@
/* sleep.c - Command to wait a specified number of seconds. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2006,2007,2008 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/dl.h>
#include <grub/term.h>
#include <grub/time.h>
#include <grub/types.h>
#include <grub/misc.h>
#include <grub/machine/time.h>
#include <grub/extcmd.h>
#include <grub/i18n.h>
static const struct grub_arg_option options[] =
{
{"verbose", 'v', 0, N_("Verbose countdown."), 0, 0},
{"interruptible", 'i', 0, N_("Interruptible with ESC."), 0, 0},
{0, 0, 0, 0, 0, 0}
};
static grub_uint16_t *pos;
static void
do_print (int n)
{
grub_term_restore_pos (pos);
/* NOTE: Do not remove the trailing space characters.
They are required to clear the line. */
grub_printf ("%d ", n);
}
/* Based on grub_millisleep() from kern/generic/millisleep.c. */
static int
grub_interruptible_millisleep (grub_uint32_t ms)
{
grub_uint64_t start;
start = grub_get_time_ms ();
while (grub_get_time_ms () - start < ms)
if (grub_checkkey () >= 0 &&
GRUB_TERM_ASCII_CHAR (grub_getkey ()) == GRUB_TERM_ESC)
return 1;
return 0;
}
static grub_err_t
grub_cmd_sleep (grub_extcmd_t cmd, int argc, char **args)
{
struct grub_arg_list *state = cmd->state;
int n;
if (argc != 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "missing operand");
n = grub_strtoul (args[0], 0, 10);
if (n == 0)
{
/* Either `0' or broken input. */
return 0;
}
pos = grub_term_save_pos ();
for (; n; n--)
{
if (state[0].set)
do_print (n);
if (state[1].set)
{
if (grub_interruptible_millisleep (1000))
return 1;
}
else
grub_millisleep (1000);
}
if (state[0].set)
do_print (0);
return 0;
}
static grub_extcmd_t cmd;
GRUB_MOD_INIT(sleep)
{
cmd = grub_register_extcmd ("sleep", grub_cmd_sleep, GRUB_COMMAND_FLAG_BOTH,
N_("NUMBER_OF_SECONDS"),
N_("Wait for a specified number of seconds."),
options);
}
GRUB_MOD_FINI(sleep)
{
grub_unregister_extcmd (cmd);
}

View File

@ -1,7 +1,6 @@
/* terminal.c - command to show and select a terminal */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2003,2005,2007 Free Software Foundation, Inc. * Copyright (C) 2009 Free Software Foundation, Inc.
* *
* GRUB is free software: you can redistribute it and/or modify * GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -17,67 +16,349 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <grub/normal.h> #include <grub/mm.h>
#include <grub/dl.h> #include <grub/dl.h>
#include <grub/arg.h> #include <grub/command.h>
#include <grub/misc.h>
#include <grub/term.h> #include <grub/term.h>
#include <grub/i18n.h>
#include <grub/misc.h>
struct grub_term_autoload *grub_term_input_autoload = NULL;
struct grub_term_autoload *grub_term_output_autoload = NULL;
static grub_err_t static grub_err_t
grub_cmd_terminal (struct grub_arg_list *state __attribute__ ((unused)), grub_cmd_terminal_input (grub_command_t cmd __attribute__ ((unused)),
int argc, char **args) int argc, char **args)
{ {
grub_term_t term = 0; int i;
grub_term_input_t term;
auto int print_terminal (grub_term_t); struct grub_term_autoload *aut;
auto int find_terminal (grub_term_t);
int print_terminal (grub_term_t t)
{
grub_printf (" %s", t->name);
return 0;
}
int find_terminal (grub_term_t t)
{
if (grub_strcmp (t->name, args[0]) == 0)
{
term = t;
return 1;
}
return 0;
}
if (argc == 0) if (argc == 0)
{ {
grub_printf ("Available terminal(s):"); grub_puts_ (N_ ("Active input terminals:"));
grub_term_iterate (print_terminal); FOR_ACTIVE_TERM_INPUTS(term)
grub_putchar ('\n'); grub_printf ("%s ", term->name);
grub_printf ("\n");
grub_printf ("Current terminal: %s\n", grub_term_get_current ()->name); grub_puts_ (N_ ("Available input terminals:"));
FOR_DISABLED_TERM_INPUTS(term)
grub_printf ("%s ", term->name);
/* This is quadratic but we don't expect mode than 30 terminal
modules ever. */
for (aut = grub_term_input_autoload; aut; aut = aut->next)
{
FOR_DISABLED_TERM_INPUTS(term)
if (grub_strcmp (term->name, aut->name) == 0)
break;
if (!term)
FOR_ACTIVE_TERM_INPUTS(term)
if (grub_strcmp (term->name, aut->name) == 0)
break;
if (!term)
grub_printf ("%s ", aut->name);
}
grub_printf ("\n");
return GRUB_ERR_NONE;
} }
else i = 0;
{
grub_term_iterate (find_terminal);
if (! term)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no such terminal");
grub_term_set_current (term); if (grub_strcmp (args[0], "--append") == 0
|| grub_strcmp (args[0], "--remove") == 0)
i++;
if (i == argc)
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_ ("no terminal specified"));
for (; i < argc; i++)
{
int again = 0;
while (1)
{
FOR_DISABLED_TERM_INPUTS(term)
if (grub_strcmp (args[i], term->name) == 0)
break;
if (term == 0)
FOR_ACTIVE_TERM_INPUTS(term)
if (grub_strcmp (args[i], term->name) == 0)
break;
if (term)
break;
if (again)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown terminal '%s'\n",
args[i]);
for (aut = grub_term_input_autoload; aut; aut = aut->next)
if (grub_strcmp (args[i], aut->name) == 0)
{
grub_dl_t mod;
mod = grub_dl_load (aut->modname);
if (mod)
grub_dl_ref (mod);
grub_errno = GRUB_ERR_NONE;
break;
}
if (!aut)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown terminal '%s'\n",
args[i]);
again = 1;
}
} }
if (grub_strcmp (args[0], "--append") == 0)
{
for (i = 1; i < argc; i++)
{
FOR_DISABLED_TERM_INPUTS(term)
if (grub_strcmp (args[i], term->name) == 0)
break;
if (term)
{
grub_list_remove (GRUB_AS_LIST_P (&(grub_term_inputs_disabled)),
GRUB_AS_LIST (term));
if (term->init)
term->init ();
grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs),
GRUB_AS_LIST (term));
}
}
return GRUB_ERR_NONE;
}
if (grub_strcmp (args[0], "--remove") == 0)
{
for (i = 1; i < argc; i++)
{
FOR_ACTIVE_TERM_INPUTS(term)
if (grub_strcmp (args[i], term->name) == 0)
break;
if (term)
{
if (!term->next && term == grub_term_inputs)
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"can't remove the last terminal");
grub_list_remove (GRUB_AS_LIST_P (&(grub_term_inputs)),
GRUB_AS_LIST (term));
if (term->fini)
term->fini ();
grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs_disabled),
GRUB_AS_LIST (term));
}
}
return GRUB_ERR_NONE;
}
for (i = 0; i < argc; i++)
{
FOR_DISABLED_TERM_INPUTS(term)
if (grub_strcmp (args[i], term->name) == 0)
break;
if (term)
{
grub_list_remove (GRUB_AS_LIST_P (&(grub_term_inputs_disabled)),
GRUB_AS_LIST (term));
if (term->init)
term->init ();
grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs),
GRUB_AS_LIST (term));
}
}
FOR_ACTIVE_TERM_INPUTS(term)
{
for (i = 0; i < argc; i++)
if (grub_strcmp (args[i], term->name) == 0)
break;
if (i == argc)
{
if (!term->next && term == grub_term_inputs)
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"can't remove the last terminal");
grub_list_remove (GRUB_AS_LIST_P (&(grub_term_inputs)),
GRUB_AS_LIST (term));
if (term->fini)
term->fini ();
grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs_disabled),
GRUB_AS_LIST (term));
}
}
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
} }
static grub_err_t
grub_cmd_terminal_output (grub_command_t cmd __attribute__ ((unused)),
int argc, char **args)
{
int i;
grub_term_output_t term;
struct grub_term_autoload *aut;
if (argc == 0)
{
grub_puts_ (N_ ("Active output terminals:"));
FOR_ACTIVE_TERM_OUTPUTS(term)
grub_printf ("%s ", term->name);
grub_printf ("\n");
grub_puts_ (N_ ("Available output terminals:"));
FOR_DISABLED_TERM_OUTPUTS(term)
grub_printf ("%s ", term->name);
/* This is quadratic but we don't expect mode than 30 terminal
modules ever. */
for (aut = grub_term_output_autoload; aut; aut = aut->next)
{
FOR_DISABLED_TERM_OUTPUTS(term)
if (grub_strcmp (term->name, aut->name) == 0)
break;
if (!term)
FOR_ACTIVE_TERM_OUTPUTS(term)
if (grub_strcmp (term->name, aut->name) == 0)
break;
if (!term)
grub_printf ("%s ", aut->name);
}
grub_printf ("\n");
return GRUB_ERR_NONE;
}
i = 0;
if (grub_strcmp (args[0], "--append") == 0
|| grub_strcmp (args[0], "--remove") == 0)
i++;
if (i == argc)
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_ ("no terminal specified"));
for (; i < argc; i++)
{
int again = 0;
while (1)
{
FOR_DISABLED_TERM_OUTPUTS(term)
if (grub_strcmp (args[i], term->name) == 0)
break;
if (term == 0)
FOR_ACTIVE_TERM_OUTPUTS(term)
if (grub_strcmp (args[i], term->name) == 0)
break;
if (term)
break;
if (again)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown terminal '%s'\n",
args[i]);
for (aut = grub_term_output_autoload; aut; aut = aut->next)
if (grub_strcmp (args[i], aut->name) == 0)
{
grub_dl_t mod;
mod = grub_dl_load (aut->modname);
if (mod)
grub_dl_ref (mod);
grub_errno = GRUB_ERR_NONE;
break;
}
if (!aut)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown terminal '%s'\n",
args[i]);
again = 1;
}
}
if (grub_strcmp (args[0], "--append") == 0)
{
for (i = 1; i < argc; i++)
{
FOR_DISABLED_TERM_OUTPUTS(term)
if (grub_strcmp (args[i], term->name) == 0)
break;
if (term)
{
grub_list_remove (GRUB_AS_LIST_P (&(grub_term_outputs_disabled)),
GRUB_AS_LIST (term));
if (term->init)
term->init ();
grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs),
GRUB_AS_LIST (term));
}
}
return GRUB_ERR_NONE;
}
if (grub_strcmp (args[0], "--remove") == 0)
{
for (i = 1; i < argc; i++)
{
FOR_ACTIVE_TERM_OUTPUTS(term)
if (grub_strcmp (args[i], term->name) == 0)
break;
if (term)
{
if (!term->next && term == grub_term_outputs)
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"can't remove the last terminal");
grub_list_remove (GRUB_AS_LIST_P (&(grub_term_outputs)),
GRUB_AS_LIST (term));
if (term->fini)
term->fini ();
grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs_disabled),
GRUB_AS_LIST (term));
}
}
return GRUB_ERR_NONE;
}
for (i = 0; i < argc; i++)
{
FOR_DISABLED_TERM_OUTPUTS(term)
if (grub_strcmp (args[i], term->name) == 0)
break;
if (term)
{
grub_list_remove (GRUB_AS_LIST_P (&(grub_term_outputs_disabled)),
GRUB_AS_LIST (term));
if (term->init)
term->init ();
grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs),
GRUB_AS_LIST (term));
}
}
FOR_ACTIVE_TERM_OUTPUTS(term)
{
for (i = 0; i < argc; i++)
if (grub_strcmp (args[i], term->name) == 0)
break;
if (i == argc)
{
if (!term->next && term == grub_term_outputs)
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"can't remove the last terminal");
grub_list_remove (GRUB_AS_LIST_P (&(grub_term_outputs)),
GRUB_AS_LIST (term));
if (term->fini)
term->fini ();
grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs_disabled),
GRUB_AS_LIST (term));
}
}
return GRUB_ERR_NONE;
}
static grub_command_t cmd_terminal_input, cmd_terminal_output;
GRUB_MOD_INIT(terminal) GRUB_MOD_INIT(terminal)
{ {
(void)mod; /* To stop warning. */ cmd_terminal_input =
grub_register_command ("terminal", grub_cmd_terminal, GRUB_COMMAND_FLAG_BOTH, grub_register_command ("terminal_input", grub_cmd_terminal_input,
"terminal [TERM...]", "Select a terminal.", 0); "[--append|--remove] "
"[TERMINAL1] [TERMINAL2] ...",
"List or select an input terminal.");
cmd_terminal_output =
grub_register_command ("terminal_output", grub_cmd_terminal_output,
"[--append|--remove] "
"[TERMINAL1] [TERMINAL2] ...",
"List or select an output terminal.");
} }
GRUB_MOD_FINI(terminal) GRUB_MOD_FINI(terminal)
{ {
grub_unregister_command ("terminal"); grub_unregister_command (cmd_terminal_input);
grub_unregister_command (cmd_terminal_output);
} }

View File

@ -1,7 +1,7 @@
/* test.c -- The test command.. */ /* test.c -- The test command.. */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2005,2007 Free Software Foundation, Inc. * Copyright (C) 2005,2007,2009 Free Software Foundation, Inc.
* *
* GRUB is free software: you can redistribute it and/or modify * GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -17,54 +17,417 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <grub/normal.h>
#include <grub/dl.h> #include <grub/dl.h>
#include <grub/arg.h>
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/mm.h> #include <grub/mm.h>
#include <grub/env.h> #include <grub/env.h>
#include <grub/fs.h>
#include <grub/device.h>
#include <grub/file.h>
#include <grub/command.h>
#include <grub/i18n.h>
static grub_err_t /* A simple implementation for signed numbers. */
grub_cmd_test (struct grub_arg_list *state __attribute__ ((unused)), int argc, static int
char **args) grub_strtosl (char *arg, char **end, int base)
{ {
char *eq; if (arg[0] == '-')
char *eqis; return -grub_strtoul (arg + 1, end, base);
return grub_strtoul (arg, end, base);
/* XXX: No fancy expression evaluation yet. */
if (argc == 0)
return 0;
eq = grub_strdup (args[0]);
eqis = grub_strchr (eq, '=');
if (! eqis)
return 0;
*eqis = '\0';
eqis++;
/* Check an expression in the form `A=B'. */
if (grub_strcmp (eq, eqis))
grub_error (GRUB_ERR_TEST_FAILURE, "false");
grub_free (eq);
return grub_errno;
} }
/* Parse a test expression starting from *argn. */
static int
test_parse (char **args, int *argn, int argc)
{
int ret = 0, discard = 0, invert = 0;
int file_exists;
struct grub_dirhook_info file_info;
auto void update_val (int val);
auto void get_fileinfo (char *pathname);
/* Take care of discarding and inverting. */
void update_val (int val)
{
if (! discard)
ret = invert ? ! val : val;
invert = discard = 0;
}
/* Check if file exists and fetch its information. */
void get_fileinfo (char *path)
{
char *filename, *pathname;
char *device_name;
grub_fs_t fs;
grub_device_t dev;
/* A hook for iterating directories. */
auto int find_file (const char *cur_filename,
const struct grub_dirhook_info *info);
int find_file (const char *cur_filename,
const struct grub_dirhook_info *info)
{
if ((info->case_insensitive ? grub_strcasecmp (cur_filename, filename)
: grub_strcmp (cur_filename, filename)) == 0)
{
file_info = *info;
file_exists = 1;
return 1;
}
return 0;
}
file_exists = 0;
device_name = grub_file_get_device_name (path);
dev = grub_device_open (device_name);
if (! dev)
{
grub_free (device_name);
return;
}
fs = grub_fs_probe (dev);
if (! fs)
{
grub_free (device_name);
grub_device_close (dev);
return;
}
pathname = grub_strchr (path, ')');
if (! pathname)
pathname = path;
else
pathname++;
/* Remove trailing '/'. */
while (*pathname && pathname[grub_strlen (pathname) - 1] == '/')
pathname[grub_strlen (pathname) - 1] = 0;
/* Split into path and filename. */
filename = grub_strrchr (pathname, '/');
if (! filename)
{
path = grub_strdup ("/");
filename = pathname;
}
else
{
filename++;
path = grub_strdup (pathname);
path[filename - pathname] = 0;
}
/* It's the whole device. */
if (! *pathname)
{
file_exists = 1;
grub_memset (&file_info, 0, sizeof (file_info));
/* Root is always a directory. */
file_info.dir = 1;
/* Fetch writing time. */
file_info.mtimeset = 0;
if (fs->mtime)
{
if (! fs->mtime (dev, &file_info.mtime))
file_info.mtimeset = 1;
grub_errno = GRUB_ERR_NONE;
}
}
else
(fs->dir) (dev, path, find_file);
grub_device_close (dev);
grub_free (path);
grub_free (device_name);
}
/* Here we have the real parsing. */
while (*argn < argc)
{
/* First try 3 argument tests. */
if (*argn + 2 < argc)
{
/* String tests. */
if (grub_strcmp (args[*argn + 1], "=") == 0
|| grub_strcmp (args[*argn + 1], "==") == 0)
{
update_val (grub_strcmp (args[*argn], args[*argn + 2]) == 0);
(*argn) += 3;
continue;
}
if (grub_strcmp (args[*argn + 1], "!=") == 0)
{
update_val (grub_strcmp (args[*argn], args[*argn + 2]) != 0);
(*argn) += 3;
continue;
}
/* GRUB extension: lexicographical sorting. */
if (grub_strcmp (args[*argn + 1], "<") == 0)
{
update_val (grub_strcmp (args[*argn], args[*argn + 2]) < 0);
(*argn) += 3;
continue;
}
if (grub_strcmp (args[*argn + 1], "<=") == 0)
{
update_val (grub_strcmp (args[*argn], args[*argn + 2]) <= 0);
(*argn) += 3;
continue;
}
if (grub_strcmp (args[*argn + 1], ">") == 0)
{
update_val (grub_strcmp (args[*argn], args[*argn + 2]) > 0);
(*argn) += 3;
continue;
}
if (grub_strcmp (args[*argn + 1], ">=") == 0)
{
update_val (grub_strcmp (args[*argn], args[*argn + 2]) >= 0);
(*argn) += 3;
continue;
}
/* Number tests. */
if (grub_strcmp (args[*argn + 1], "-eq") == 0)
{
update_val (grub_strtosl (args[*argn], 0, 0)
== grub_strtosl (args[*argn + 2], 0, 0));
(*argn) += 3;
continue;
}
if (grub_strcmp (args[*argn + 1], "-ge") == 0)
{
update_val (grub_strtosl (args[*argn], 0, 0)
>= grub_strtosl (args[*argn + 2], 0, 0));
(*argn) += 3;
continue;
}
if (grub_strcmp (args[*argn + 1], "-gt") == 0)
{
update_val (grub_strtosl (args[*argn], 0, 0)
> grub_strtosl (args[*argn + 2], 0, 0));
(*argn) += 3;
continue;
}
if (grub_strcmp (args[*argn + 1], "-le") == 0)
{
update_val (grub_strtosl (args[*argn], 0, 0)
<= grub_strtosl (args[*argn + 2], 0, 0));
(*argn) += 3;
continue;
}
if (grub_strcmp (args[*argn + 1], "-lt") == 0)
{
update_val (grub_strtosl (args[*argn], 0, 0)
< grub_strtosl (args[*argn + 2], 0, 0));
(*argn) += 3;
continue;
}
if (grub_strcmp (args[*argn + 1], "-ne") == 0)
{
update_val (grub_strtosl (args[*argn], 0, 0)
!= grub_strtosl (args[*argn + 2], 0, 0));
(*argn) += 3;
continue;
}
/* GRUB extension: compare numbers skipping prefixes.
Useful for comparing versions. E.g. vmlinuz-2 -plt vmlinuz-11. */
if (grub_strcmp (args[*argn + 1], "-pgt") == 0
|| grub_strcmp (args[*argn + 1], "-plt") == 0)
{
int i;
/* Skip common prefix. */
for (i = 0; args[*argn][i] == args[*argn + 2][i]
&& args[*argn][i]; i++);
/* Go the digits back. */
i--;
while (grub_isdigit (args[*argn][i]) && i > 0)
i--;
i++;
if (grub_strcmp (args[*argn + 1], "-pgt") == 0)
update_val (grub_strtoul (args[*argn] + i, 0, 0)
> grub_strtoul (args[*argn + 2] + i, 0, 0));
else
update_val (grub_strtoul (args[*argn] + i, 0, 0)
< grub_strtoul (args[*argn + 2] + i, 0, 0));
(*argn) += 3;
continue;
}
/* -nt and -ot tests. GRUB extension: when doing -?t<bias> bias
will be added to the first mtime. */
if (grub_memcmp (args[*argn + 1], "-nt", 3) == 0
|| grub_memcmp (args[*argn + 1], "-ot", 3) == 0)
{
struct grub_dirhook_info file1;
int file1exists;
int bias = 0;
/* Fetch fileinfo. */
get_fileinfo (args[*argn]);
file1 = file_info;
file1exists = file_exists;
get_fileinfo (args[*argn + 2]);
if (args[*argn + 1][3])
bias = grub_strtosl (args[*argn + 1] + 3, 0, 0);
if (grub_memcmp (args[*argn + 1], "-nt", 3) == 0)
update_val ((file1exists && ! file_exists)
|| (file1.mtimeset && file_info.mtimeset
&& file1.mtime + bias > file_info.mtime));
else
update_val ((! file1exists && file_exists)
|| (file1.mtimeset && file_info.mtimeset
&& file1.mtime + bias < file_info.mtime));
(*argn) += 3;
continue;
}
}
/* Two-argument tests. */
if (*argn + 1 < argc)
{
/* File tests. */
if (grub_strcmp (args[*argn], "-d") == 0)
{
get_fileinfo (args[*argn + 1]);
update_val (file_exists && file_info.dir);
(*argn) += 2;
return ret;
}
if (grub_strcmp (args[*argn], "-e") == 0)
{
get_fileinfo (args[*argn + 1]);
update_val (file_exists);
(*argn) += 2;
return ret;
}
if (grub_strcmp (args[*argn], "-f") == 0)
{
get_fileinfo (args[*argn + 1]);
/* FIXME: check for other types. */
update_val (file_exists && ! file_info.dir);
(*argn) += 2;
return ret;
}
if (grub_strcmp (args[*argn], "-s") == 0)
{
grub_file_t file;
file = grub_file_open (args[*argn + 1]);
update_val (file && (grub_file_size (file) != 0));
if (file)
grub_file_close (file);
grub_errno = GRUB_ERR_NONE;
(*argn) += 2;
return ret;
}
/* String tests. */
if (grub_strcmp (args[*argn], "-n") == 0)
{
update_val (args[*argn + 1][0]);
(*argn) += 2;
continue;
}
if (grub_strcmp (args[*argn], "-z") == 0)
{
update_val (! args[*argn + 1][0]);
(*argn) += 2;
continue;
}
}
/* Special modifiers. */
/* End of expression. return to parent. */
if (grub_strcmp (args[*argn], ")") == 0)
{
(*argn)++;
return ret;
}
/* Recursively invoke if parenthesis. */
if (grub_strcmp (args[*argn], "(") == 0)
{
(*argn)++;
update_val (test_parse (args, argn, argc));
continue;
}
if (grub_strcmp (args[*argn], "!") == 0)
{
invert = ! invert;
(*argn)++;
continue;
}
if (grub_strcmp (args[*argn], "-a") == 0)
{
/* If current value is 0 second value is to be discarded. */
discard = ! ret;
(*argn)++;
continue;
}
if (grub_strcmp (args[*argn], "-o") == 0)
{
/* If current value is 1 second value is to be discarded. */
discard = ret;
(*argn)++;
continue;
}
/* No test found. Interpret if as just a string. */
update_val (args[*argn][0]);
(*argn)++;
}
return ret;
}
static grub_err_t
grub_cmd_test (grub_command_t cmd __attribute__ ((unused)),
int argc, char **args)
{
int argn = 0;
if (argc >= 1 && grub_strcmp (args[argc - 1], "]") == 0)
argc--;
return test_parse (args, &argn, argc) ? GRUB_ERR_NONE
: grub_error (GRUB_ERR_TEST_FAILURE, "false");
}
static grub_command_t cmd_1, cmd_2;
GRUB_MOD_INIT(test) GRUB_MOD_INIT(test)
{ {
(void)mod; /* To stop warning. */ cmd_1 = grub_register_command ("[", grub_cmd_test,
grub_register_command ("[", grub_cmd_test, GRUB_COMMAND_FLAG_CMDLINE, N_("EXPRESSION ]"), N_("Evaluate an expression."));
"[ EXPRESSION ]", "Evaluate an expression", 0); cmd_2 = grub_register_command ("test", grub_cmd_test,
grub_register_command ("test", grub_cmd_test, GRUB_COMMAND_FLAG_CMDLINE, N_("EXPRESSION"), N_("Evaluate an expression."));
"test EXPRESSION", "Evaluate an expression", 0);
} }
GRUB_MOD_FINI(test) GRUB_MOD_FINI(test)
{ {
grub_unregister_command ("["); grub_unregister_command (cmd_1);
grub_unregister_command ("test"); grub_unregister_command (cmd_2);
} }

57
commands/true.c Normal file
View File

@ -0,0 +1,57 @@
/* true.c - true and false commands. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 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/dl.h>
#include <grub/command.h>
#include <grub/i18n.h>
static grub_err_t
grub_cmd_true (struct grub_command *cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)),
char *argv[] __attribute__ ((unused)))
{
return 0;
}
static grub_err_t
grub_cmd_false (struct grub_command *cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)),
char *argv[] __attribute__ ((unused)))
{
return grub_error (GRUB_ERR_TEST_FAILURE, "false");
}
static grub_command_t cmd_true, cmd_false;
GRUB_MOD_INIT(true)
{
cmd_true =
grub_register_command ("true", grub_cmd_true,
0, N_("Do nothing, successfully."));
cmd_false =
grub_register_command ("false", grub_cmd_false,
0, N_("Do nothing, unsuccessfully."));
}
GRUB_MOD_FINI(true)
{
grub_unregister_command (cmd_true);
grub_unregister_command (cmd_false);
}

205
commands/usbtest.c Normal file
View File

@ -0,0 +1,205 @@
/* usbtest.c - test module for USB */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008 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/types.h>
#include <grub/misc.h>
#include <grub/charset.h>
#include <grub/mm.h>
#include <grub/err.h>
#include <grub/dl.h>
#include <grub/usb.h>
#include <grub/command.h>
#include <grub/i18n.h>
static const char *usb_classes[] =
{
"",
"Audio",
"Communication Interface",
"HID",
"",
"Physical",
"Image",
"Printer",
"Mass Storage",
"Hub",
"Data Interface",
"Smart Card",
"Content Security",
"Video"
};
static const char *usb_endp_type[] =
{
"Control",
"Isochronous",
"Bulk",
"Interrupt"
};
static const char *usb_devspeed[] =
{
"",
"Low",
"Full",
"High"
};
static grub_usb_err_t
grub_usb_get_string (grub_usb_device_t dev, grub_uint8_t index, int langid,
char **string)
{
struct grub_usb_desc_str descstr;
struct grub_usb_desc_str *descstrp;
grub_usb_err_t err;
/* Only get the length. */
err = grub_usb_control_msg (dev, 1 << 7,
0x06, (3 << 8) | index,
langid, 1, (char *) &descstr);
if (err)
return err;
descstrp = grub_malloc (descstr.length);
if (! descstrp)
return GRUB_USB_ERR_INTERNAL;
err = grub_usb_control_msg (dev, 1 << 7,
0x06, (3 << 8) | index,
langid, descstr.length, (char *) descstrp);
*string = grub_malloc (descstr.length / 2);
if (! *string)
{
grub_free (descstrp);
return GRUB_USB_ERR_INTERNAL;
}
grub_utf16_to_utf8 ((grub_uint8_t *) *string, descstrp->str, descstrp->length / 2 - 1);
(*string)[descstr.length / 2 - 1] = '\0';
grub_free (descstrp);
return GRUB_USB_ERR_NONE;
}
static void
usb_print_str (const char *description, grub_usb_device_t dev, int idx)
{
char *name;
grub_usb_err_t err;
/* XXX: LANGID */
if (! idx)
return;
err = grub_usb_get_string (dev, idx, 0x0409, &name);
if (err)
grub_printf ("Error %d retrieving %s\n", err, description);
else
{
grub_printf ("%s: `%s'\n", description, name);
grub_free (name);
}
}
static int
usb_iterate (grub_usb_device_t dev)
{
struct grub_usb_desc_device *descdev;
int i;
descdev = &dev->descdev;
usb_print_str ("Product", dev, descdev->strprod);
usb_print_str ("Vendor", dev, descdev->strvendor);
usb_print_str ("Serial", dev, descdev->strserial);
if (descdev->class > 0 && descdev->class <= 0x0E)
grub_printf ("Class: (0x%02x) %s, Subclass: 0x%02x, Protocol: 0x%02x\n",
descdev->class, usb_classes[descdev->class],
descdev->subclass, descdev->protocol);
grub_printf ("USB version %d.%d, VendorID: 0x%02x, ProductID: 0x%02x, #conf: %d\n",
descdev->usbrel >> 8, (descdev->usbrel >> 4) & 0x0F,
descdev->vendorid, descdev->prodid, descdev->configcnt);
grub_printf ("%s speed device\n", usb_devspeed[dev->speed]);
for (i = 0; i < descdev->configcnt; i++)
{
struct grub_usb_desc_config *config;
config = dev->config[i].descconf;
usb_print_str ("Configuration:", dev, config->strconfig);
}
for (i = 0; i < dev->config[0].descconf->numif; i++)
{
int j;
struct grub_usb_desc_if *interf;
interf = dev->config[0].interf[i].descif;
grub_printf ("Interface #%d: #Endpoints: %d ",
i, interf->endpointcnt);
if (interf->class > 0 && interf->class <= 0x0E)
grub_printf ("Class: (0x%02x) %s, Subclass: 0x%02x, Protocol: 0x%02x\n",
interf->class, usb_classes[interf->class],
interf->subclass, interf->protocol);
usb_print_str ("Interface", dev, interf->strif);
for (j = 0; j < interf->endpointcnt; j++)
{
struct grub_usb_desc_endp *endp;
endp = &dev->config[0].interf[i].descendp[j];
grub_printf ("Endpoint #%d: %s, max packed size: %d, transfer type: %s, latency: %d\n",
endp->endp_addr & 15,
(endp->endp_addr & 128) ? "IN" : "OUT",
endp->maxpacket, usb_endp_type[endp->attrib & 3],
endp->interval);
}
}
grub_printf("\n");
return 0;
}
static grub_err_t
grub_cmd_usbtest (grub_command_t cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)),
char **args __attribute__ ((unused)))
{
grub_printf ("USB devices:\n\n");
grub_usb_iterate (usb_iterate);
return 0;
}
static grub_command_t cmd;
GRUB_MOD_INIT(usbtest)
{
cmd = grub_register_command ("usb", grub_cmd_usbtest,
0, N_("Test USB support."));
}
GRUB_MOD_FINI(usbtest)
{
grub_unregister_command (cmd);
}

View File

@ -1,6 +1,6 @@
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2006,2007 Free Software Foundation, Inc. * Copyright (C) 2006,2007,2009 Free Software Foundation, Inc.
* *
* GRUB is free software: you can redistribute it and/or modify * GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -16,37 +16,41 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <grub/machine/memory.h>
#include <grub/video.h> #include <grub/video.h>
#include <grub/types.h> #include <grub/types.h>
#include <grub/dl.h> #include <grub/dl.h>
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/normal.h>
#include <grub/arg.h>
#include <grub/mm.h> #include <grub/mm.h>
#include <grub/font.h> #include <grub/font.h>
#include <grub/term.h> #include <grub/term.h>
#include <grub/command.h>
#include <grub/i18n.h>
static grub_err_t static grub_err_t
grub_cmd_videotest (struct grub_arg_list *state __attribute__ ((unused)), grub_cmd_videotest (grub_command_t cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)), int argc __attribute__ ((unused)),
char **args __attribute__ ((unused))) char **args __attribute__ ((unused)))
{ {
if (grub_video_setup (1024, 768, grub_err_t err;
GRUB_VIDEO_MODE_TYPE_INDEX_COLOR) != GRUB_ERR_NONE)
return grub_errno;
grub_getkey ();
grub_video_color_t color; grub_video_color_t color;
unsigned int x; unsigned int x;
unsigned int y; unsigned int y;
unsigned int width; unsigned int width;
unsigned int height; unsigned int height;
int i; int i;
struct grub_font_glyph glyph; grub_font_t sansbig;
grub_font_t sans;
grub_font_t sanssmall;
grub_font_t fixed;
struct grub_font_glyph *glyph;
struct grub_video_render_target *text_layer; struct grub_video_render_target *text_layer;
grub_video_color_t palette[16]; grub_video_color_t palette[16];
const char *str;
int texty;
err = grub_video_set_mode ("auto", GRUB_VIDEO_MODE_TYPE_PURE_TEXT, 0);
if (err)
return err;
grub_video_get_viewport (&x, &y, &width, &height); grub_video_get_viewport (&x, &y, &width, &height);
@ -65,8 +69,15 @@ grub_cmd_videotest (struct grub_arg_list *state __attribute__ ((unused)),
color = grub_video_map_rgb (0, 255, 255); color = grub_video_map_rgb (0, 255, 255);
grub_video_fill_rect (color, 100, 100, 100, 100); grub_video_fill_rect (color, 100, 100, 100, 100);
grub_font_get_glyph ('*', &glyph); sansbig = grub_font_get ("Helvetica Bold 24");
grub_video_blit_glyph (&glyph, color, 200 ,0); sans = grub_font_get ("Helvetica Bold 14");
sanssmall = grub_font_get ("Helvetica 8");
fixed = grub_font_get ("Fixed 20");
if (! sansbig || ! sans || ! sanssmall || ! fixed)
return grub_error (GRUB_ERR_BAD_FONT, "no font loaded");
glyph = grub_font_get_glyph (fixed, '*');
grub_font_draw_glyph (glyph, color, 200 ,0);
grub_video_set_viewport (x + 150, y + 150, grub_video_set_viewport (x + 150, y + 150,
width - 150 * 2, height - 150 * 2); width - 150 * 2, height - 150 * 2);
@ -77,28 +88,80 @@ grub_cmd_videotest (struct grub_arg_list *state __attribute__ ((unused)),
color = grub_video_map_rgb (255, 255, 255); color = grub_video_map_rgb (255, 255, 255);
grub_font_get_glyph ('A', &glyph); texty = 32;
grub_video_blit_glyph (&glyph, color, 16, 16); grub_font_draw_string ("The quick brown fox jumped over the lazy dog.",
grub_font_get_glyph ('B', &glyph); sans, color, 16, texty);
grub_video_blit_glyph (&glyph, color, 16 * 2, 16); texty += grub_font_get_descent (sans) + grub_font_get_leading (sans);
grub_font_get_glyph ('*', &glyph); texty += grub_font_get_ascent (fixed);
grub_font_draw_string ("The quick brown fox jumped over the lazy dog.",
fixed, color, 16, texty);
texty += grub_font_get_descent (fixed) + grub_font_get_leading (fixed);
/* To convert Unicode characters into UTF-8 for this test, the following
command is useful:
echo -ne '\x00\x00\x26\x3A' | iconv -f UTF-32BE -t UTF-8 | od -t x1
This converts the Unicode character U+263A to UTF-8. */
/* Characters used:
Code point Description UTF-8 encoding
----------- ------------------------------ --------------
U+263A unfilled smiley face E2 98 BA
U+00A1 inverted exclamation point C2 A1
U+00A3 British pound currency symbol C2 A3
U+03C4 Greek tau CF 84
U+00E4 lowercase letter a with umlaut C3 A4
U+2124 set 'Z' symbol (integers) E2 84 A4
U+2287 subset symbol E2 8A 87
U+211D set 'R' symbol (real numbers) E2 84 9D */
str =
"Unicode test: happy\xE2\x98\xBA \xC2\xA3 5.00"
" \xC2\xA1\xCF\x84\xC3\xA4u! "
" \xE2\x84\xA4\xE2\x8A\x87\xE2\x84\x9D";
color = grub_video_map_rgb (128, 128, 255);
/* All characters in the string exist in the 'Fixed 20' (10x20) font. */
texty += grub_font_get_ascent(fixed);
grub_font_draw_string (str, fixed, color, 16, texty);
texty += grub_font_get_descent (fixed) + grub_font_get_leading (fixed);
/* Some character don't exist in the Helvetica font, so the font engine
will fall back to using glyphs from another font that does contain them.
TODO The font engine should be smart about selecting a replacement font
and prioritize fonts with similar sizes. */
texty += grub_font_get_ascent(sansbig);
grub_font_draw_string (str, sansbig, color, 16, texty);
texty += grub_font_get_descent (sansbig) + grub_font_get_leading (sansbig);
texty += grub_font_get_ascent(sans);
grub_font_draw_string (str, sans, color, 16, texty);
texty += grub_font_get_descent (sans) + grub_font_get_leading (sans);
texty += grub_font_get_ascent(sanssmall);
grub_font_draw_string (str, sanssmall, color, 16, texty);
texty += (grub_font_get_descent (sanssmall)
+ grub_font_get_leading (sanssmall));
glyph = grub_font_get_glyph (fixed, '*');
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
{ {
color = grub_video_map_color (i); color = grub_video_map_color (i);
palette[i] = color; palette[i] = color;
grub_video_blit_glyph (&glyph, color, 16 + i * 16, 32); grub_font_draw_glyph (glyph, color, 16 + i * 16, 220);
} }
grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY); grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY);
for (i = 0; i < 255; i++) for (i = 0; i < 5; i++)
{ {
color = grub_video_map_rgb (i, 33, 77); color = grub_video_map_rgb (i, 33, 77);
grub_video_fill_rect (color, 0, 0, width, height); grub_video_fill_rect (color, 0, 0, width, height);
grub_video_blit_render_target (text_layer, GRUB_VIDEO_BLIT_BLEND, 0, 0, grub_video_blit_render_target (text_layer, GRUB_VIDEO_BLIT_BLEND, 0, 0,
0, 0, width, height); 0, 0, width, height);
grub_video_swap_buffers ();
} }
grub_getkey (); grub_getkey ();
@ -114,17 +177,15 @@ grub_cmd_videotest (struct grub_arg_list *state __attribute__ ((unused)),
return grub_errno; return grub_errno;
} }
static grub_command_t cmd;
GRUB_MOD_INIT(videotest) GRUB_MOD_INIT(videotest)
{ {
grub_register_command ("videotest", cmd = grub_register_command ("videotest", grub_cmd_videotest,
grub_cmd_videotest, 0, N_("Test video subsystem."));
GRUB_COMMAND_FLAG_BOTH,
"videotest",
"Test video subsystem",
0);
} }
GRUB_MOD_FINI(videotest) GRUB_MOD_FINI(videotest)
{ {
grub_unregister_command ("videotest"); grub_unregister_command (cmd);
} }

100
commands/xnu_uuid.c Normal file
View File

@ -0,0 +1,100 @@
/* xnu_uuid.c - transform 64-bit serial number
to 128-bit uuid suitable for xnu. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1995,1996,1998,1999,2001,2002,
* 2003, 2009 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/types.h>
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/err.h>
#include <grub/dl.h>
#include <grub/device.h>
#include <grub/disk.h>
#include <grub/fs.h>
#include <grub/file.h>
#include <grub/misc.h>
#include <grub/env.h>
#include <grub/command.h>
#include <grub/i18n.h>
#include <grub/crypto.h>
/* This prefix is used by xnu and boot-132 to hash
together with volume serial. */
static grub_uint8_t hash_prefix[16]
= {0xB3, 0xE2, 0x0F, 0x39, 0xF2, 0x92, 0x11, 0xD6,
0x97, 0xA4, 0x00, 0x30, 0x65, 0x43, 0xEC, 0xAC};
static grub_err_t
grub_cmd_xnu_uuid (grub_command_t cmd __attribute__ ((unused)),
int argc, char **args)
{
grub_uint64_t serial;
grub_uint8_t *xnu_uuid;
char uuid_string[sizeof ("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")];
char *ptr;
grub_uint8_t ctx[GRUB_MD_MD5->contextsize];
if (argc < 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "UUID required");
serial = grub_cpu_to_be64 (grub_strtoull (args[0], 0, 16));
GRUB_MD_MD5->init (&ctx);
GRUB_MD_MD5->write (&ctx, hash_prefix, sizeof (hash_prefix));
GRUB_MD_MD5->write (&ctx, &serial, sizeof (serial));
GRUB_MD_MD5->final (&ctx);
xnu_uuid = GRUB_MD_MD5->read (&ctx);
grub_sprintf (uuid_string,
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
(unsigned int) xnu_uuid[0], (unsigned int) xnu_uuid[1],
(unsigned int) xnu_uuid[2], (unsigned int) xnu_uuid[3],
(unsigned int) xnu_uuid[4], (unsigned int) xnu_uuid[5],
(unsigned int) ((xnu_uuid[6] & 0xf) | 0x30),
(unsigned int) xnu_uuid[7],
(unsigned int) ((xnu_uuid[8] & 0x3f) | 0x80),
(unsigned int) xnu_uuid[9],
(unsigned int) xnu_uuid[10], (unsigned int) xnu_uuid[11],
(unsigned int) xnu_uuid[12], (unsigned int) xnu_uuid[13],
(unsigned int) xnu_uuid[14], (unsigned int) xnu_uuid[15]);
for (ptr = uuid_string; *ptr; ptr++)
*ptr = grub_toupper (*ptr);
if (argc == 1)
grub_printf ("%s", uuid_string);
if (argc > 1)
grub_env_set (args[1], uuid_string);
return GRUB_ERR_NONE;
}
static grub_command_t cmd;
GRUB_MOD_INIT (xnu_uuid)
{
cmd = grub_register_command ("xnu_uuid", grub_cmd_xnu_uuid,
N_("GRUBUUID [VARNAME]"),
N_("Transform 64-bit UUID to format "
"suitable for XNU."));
}
GRUB_MOD_FINI (xnu_uuid)
{
grub_unregister_command (cmd);
}

100
conf/any-emu.rmk Normal file
View File

@ -0,0 +1,100 @@
# -*- makefile -*-
# Used by various components. These rules need to precede them.
script/lexer.c_DEPENDENCIES = grub_script.tab.h
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_wrap.c commands/search_file.c \
commands/search_label.c commands/search_uuid.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 \
kern/err.c kern/list.c kern/handler.c \
kern/command.c kern/corecmd.c commands/extcmd.c kern/file.c \
kern/fs.c commands/boot.c kern/main.c kern/misc.c kern/parser.c \
kern/partition.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 lib/crypto.c normal/autofs.c \
normal/completion.c normal/main.c normal/color.c \
normal/menu.c normal/menu_entry.c \
normal/menu_text.c normal/crypto.c normal/term.c \
commands/terminal.c lib/charset.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/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 \
lib/libgcrypt-grub/cipher/md5.c \
grub_emu_init.c gnulib/progname.c
grub_emu_CFLAGS += -Wno-missing-field-initializers -Wno-error -I$(srcdir)/lib/libgcrypt_wrap
ifeq ($(target_cpu), i386)
grub_emu_SOURCES += commands/i386/cpuid.c
endif
grub_emu_LDFLAGS = $(LIBCURSES)
ifeq ($(enable_grub_emu_usb), yes)
grub_emu_SOURCES += disk/usbms.c util/usb.c bus/usb/usb.c \
commands/usbtest.c
grub_emu_LDFLAGS += $(LIBCURSES) $(LIBUSB)
endif
ifeq ($(enable_grub_emu_pci), yes)
grub_emu_SOURCES += util/pci.c commands/lspci.c
grub_emu_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 $< > $@
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,$^) > $@
DISTCLEANFILES += grub_emu_init.c
# 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

File diff suppressed because it is too large Load Diff

View File

@ -1,22 +1,118 @@
# -*- makefile -*- # -*- makefile -*-
sbin_UTILITIES += grub-mkdevicemap
grub_mkdevicemap_SOURCES = gnulib/progname.c util/grub-mkdevicemap.c \
util/deviceiter.c \
util/misc.c
ifeq ($(target_cpu)-$(platform), sparc64-ieee1275)
grub_mkdevicemap_SOURCES += util/ieee1275/ofpath.c util/ieee1275/devicemap.c
else
grub_mkdevicemap_SOURCES += util/devicemap.c
endif
# For grub-mkelfimage.
bin_UTILITIES += grub-mkelfimage
grub_mkelfimage_SOURCES = gnulib/progname.c \
util/elf/grub-mkimage.c util/misc.c \
util/resolve.c
util/elf/grub-mkimage.c_DEPENDENCIES = Makefile
# For grub-probe.
sbin_UTILITIES += grub-probe
util/grub-probe.c_DEPENDENCIES = grub_probe_init.h
grub_probe_SOURCES = gnulib/progname.c util/grub-probe.c \
util/hostdisk.c util/misc.c util/getroot.c \
kern/device.c kern/disk.c kern/err.c kern/misc.c \
kern/parser.c kern/partition.c kern/file.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 \
\
partmap/msdos.c partmap/apple.c partmap/sun.c partmap/gpt.c\
kern/fs.c kern/env.c fs/fshelp.c \
disk/raid.c disk/mdraid_linux.c disk/lvm.c grub_probe_init.c
ifeq ($(enable_grub_fstest), yes)
bin_UTILITIES += grub-fstest
endif
bin_UTILITIES += grub-mkisofs
grub_mkisofs_SOURCES = util/mkisofs/eltorito.c \
util/mkisofs/hash.c util/mkisofs/joliet.c \
util/mkisofs/match.c util/mkisofs/mkisofs.c \
util/mkisofs/multi.c util/mkisofs/name.c \
util/mkisofs/rock.c util/mkisofs/tree.c \
util/mkisofs/write.c \
\
gnulib/fnmatch.c gnulib/getopt1.c gnulib/getopt.c \
gnulib/error.c gnulib/progname.c
grub_mkisofs_CFLAGS = -D_FILE_OFFSET_BITS=64 \
-I$(srcdir)/util/mkisofs/include \
-Wno-all -Werror
# For grub-fstest.
util/grub-fstest.c_DEPENDENCIES = grub_fstest_init.h
grub_fstest_SOURCES = gnulib/progname.c util/grub-fstest.c util/hostfs.c \
util/misc.c \
kern/file.c kern/device.c kern/disk.c kern/err.c kern/misc.c \
disk/host.c disk/loopback.c kern/list.c kern/command.c \
lib/arg.c commands/extcmd.c normal/datetime.c normal/misc.c \
lib/hexdump.c lib/crc.c commands/blocklist.c commands/ls.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 \
\
kern/partition.c partmap/msdos.c partmap/apple.c partmap/sun.c \
partmap/gpt.c \
kern/fs.c kern/env.c fs/fshelp.c disk/raid.c \
disk/raid5_recover.c disk/raid6_recover.c \
disk/mdraid_linux.c disk/dmraid_nvidia.c disk/lvm.c \
grub_fstest_init.c
# 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
# For grub-mkrelpath.
bin_UTILITIES += grub-mkrelpath
grub_mkrelpath_SOURCES = gnulib/progname.c util/grub-mkrelpath.c util/misc.c
# For grub-script-check.
bin_UTILITIES += grub-script-check
util/grub-script-check.c_DEPENDENCIES = grub_script_check_init.h
grub_script_check_SOURCES = gnulib/progname.c util/grub-script-check.c util/misc.c \
script/main.c script/script.c script/function.c script/lexer.c \
kern/handler.c kern/err.c kern/parser.c kern/list.c \
kern/misc.c kern/env.c grub_script_check_init.c grub_script.tab.c
# For the parser. # For the parser.
grub_script.tab.c grub_script.tab.h: normal/parser.y grub_script.tab.c grub_script.tab.h: script/parser.y
$(YACC) -d -p grub_script_yy -b grub_script $(srcdir)/normal/parser.y $(YACC) -d -p grub_script_yy -b grub_script $(srcdir)/script/parser.y
DISTCLEANFILES += grub_script.tab.c grub_script.tab.h DISTCLEANFILES += grub_script.tab.c grub_script.tab.h
# For grub-emu. # For grub-script-check.
grub_emu_init.lst: geninit.sh $(filter-out grub_emu_init.c,$(grub_emu_SOURCES)) grub_script_check_init.lst: geninit.sh $(filter-out grub_script_check_init.c,$(grub_script_check_SOURCES))
rm -f $@; grep GRUB_MOD_INIT $(filter %.c,$^) /dev/null > $@ rm -f $@; grep GRUB_MOD_INIT $(filter %.c,$^) /dev/null > $@
DISTCLEANFILES += grub_emu_init.lst DISTCLEANFILES += grub_script_check_init.lst
grub_emu_init.h: grub_emu_init.lst $(filter-out grub_emu_init.c,$(grub_emu_SOURCES)) geninitheader.sh grub_script_check_init.h: grub_script_check_init.lst $(filter-out grub_script_check_init.c,$(grub_script_check_SOURCES)) geninitheader.sh
rm -f $@; sh $(srcdir)/geninitheader.sh $< > $@ rm -f $@; sh $(srcdir)/geninitheader.sh $< > $@
DISTCLEANFILES += grub_emu_init.h DISTCLEANFILES += grub_script_check_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 grub_script_check_init.c: grub_script_check_init.lst $(filter-out grub_script_check_init.c,$(grub_script_check_SOURCES)) geninit.sh
rm -f $@; sh $(srcdir)/geninit.sh $< $(filter %.c,$^) > $@ rm -f $@; sh $(srcdir)/geninit.sh $< $(filter %.c,$^) > $@
DISTCLEANFILES += grub_emu_init.c DISTCLEANFILES += grub_script_check_init.c
# For grub-probe. # For grub-probe.
grub_probe_init.lst: geninit.sh $(filter-out grub_probe_init.c,$(grub_probe_SOURCES)) grub_probe_init.lst: geninit.sh $(filter-out grub_probe_init.c,$(grub_probe_SOURCES))
@ -44,44 +140,91 @@ grub_setup_init.c: grub_setup_init.lst $(filter-out grub_setup_init.c,$(grub_set
rm -f $@; sh $(srcdir)/geninit.sh $< $(filter %.c,$^) > $@ rm -f $@; sh $(srcdir)/geninit.sh $< $(filter %.c,$^) > $@
DISTCLEANFILES += grub_setup_init.c DISTCLEANFILES += grub_setup_init.c
# For update-grub # For grub-fstest.
update-grub: util/update-grub.in config.status grub_fstest_init.lst: geninit.sh $(filter-out grub_fstest_init.c,$(grub_fstest_SOURCES))
rm -f $@; grep GRUB_MOD_INIT $(filter %.c,$^) /dev/null > $@
DISTCLEANFILES += grub_fstest_init.lst
grub_fstest_init.h: grub_fstest_init.lst $(filter-out grub_fstest_init.c,$(grub_fstest_SOURCES)) geninitheader.sh
rm -f $@; sh $(srcdir)/geninitheader.sh $< > $@
DISTCLEANFILES += grub_fstest_init.h
grub_fstest_init.c: grub_fstest_init.lst $(filter-out grub_fstest_init.c,$(grub_fstest_SOURCES)) geninit.sh grub_fstest_init.h
rm -f $@; sh $(srcdir)/geninit.sh $< $(filter %.c,$^) > $@
DISTCLEANFILES += grub_fstest_init.c
# for grub-editenv
bin_UTILITIES += grub-editenv
grub_editenv_SOURCES = gnulib/progname.c util/grub-editenv.c lib/envblk.c util/misc.c kern/misc.c kern/err.c
CLEANFILES += grub-editenv
# Needed for genmk.rb to work
ifeq (0,1)
bin_UTILITIES += grub-macho2img grub-pe2elf
endif
grub_pe2elf_SOURCES = gnulib/progname.c util/grub-pe2elf.c util/misc.c
CLEANFILES += grub-pe2elf
grub_macho2img_SOURCES = util/grub-macho2img.c
CLEANFILES += grub-macho2img
# For grub-mkconfig
grub-mkconfig: util/grub-mkconfig.in config.status
./config.status --file=$@:$< ./config.status --file=$@:$<
chmod +x $@ chmod +x $@
sbin_SCRIPTS += update-grub sbin_SCRIPTS += grub-mkconfig
CLEANFILES += update-grub CLEANFILES += grub-mkconfig
grub-mkconfig_lib: util/grub-mkconfig_lib.in config.status
./config.status --file=$@:$<
chmod +x $@
lib_SCRIPTS += grub-mkconfig_lib
CLEANFILES += grub-mkconfig_lib
update-grub_lib: util/update-grub_lib.in config.status update-grub_lib: util/update-grub_lib.in config.status
./config.status --file=$@:$< ./config.status --file=$@:$<
chmod +x $@ chmod +x $@
lib_DATA += update-grub_lib lib_SCRIPTS += update-grub_lib
CLEANFILES += update-grub_lib CLEANFILES += update-grub_lib
00_header: util/grub.d/00_header.in config.status grub-gettext_lib: util/grub-gettext_lib.in config.status
./config.status --file=$@:$< ./config.status --file=$@:$<
chmod +x $@ chmod +x $@
update-grub_SCRIPTS += 00_header lib_DATA += grub-gettext_lib
CLEANFILES += 00_header CLEANFILES += grub-gettext_lib
10_linux: util/grub.d/10_linux.in config.status %: util/grub.d/%.in config.status
./config.status --file=$@:$< ./config.status --file=$@:$<
chmod +x $@ chmod +x $@
update-grub_SCRIPTS += 10_linux grub-mkconfig_SCRIPTS = 00_header 30_os-prober 40_custom
CLEANFILES += 10_linux ifneq (, $(host_kernel))
grub-mkconfig_SCRIPTS += 10_$(host_kernel)
endif
10_hurd: util/grub.d/10_hurd.in config.status CLEANFILES += $(grub-mkconfig_SCRIPTS)
grub-mkconfig_DATA += util/grub.d/README
# For grub-set-default.
grub-set-default: util/grub-set-default.in config.status
./config.status --file=$@:$< ./config.status --file=$@:$<
chmod +x $@ chmod +x $@
update-grub_SCRIPTS += 10_hurd sbin_SCRIPTS += grub-set-default
CLEANFILES += 10_hurd CLEANFILES += grub-set-default
update-grub_DATA += util/grub.d/README
# For grub-reboot.
grub-reboot: util/grub-reboot.in config.status
./config.status --file=$@:$<
chmod +x $@
sbin_SCRIPTS += grub-reboot
CLEANFILES += grub-reboot
# Filing systems. # Filing systems.
pkglib_MODULES += fshelp.mod fat.mod ufs.mod ext2.mod ntfs.mod \ pkglib_MODULES += fshelp.mod fat.mod ufs1.mod ufs2.mod ext2.mod ntfs.mod \
ntfscomp.mod minix.mod hfs.mod jfs.mod iso9660.mod xfs.mod \ ntfscomp.mod minix.mod hfs.mod jfs.mod iso9660.mod xfs.mod \
affs.mod sfs.mod hfsplus.mod reiserfs.mod cpio.mod affs.mod sfs.mod hfsplus.mod reiserfs.mod cpio.mod tar.mod \
udf.mod afs.mod afs_be.mod befs.mod befs_be.mod
# For fshelp.mod. # For fshelp.mod.
fshelp_mod_SOURCES = fs/fshelp.c fshelp_mod_SOURCES = fs/fshelp.c
@ -93,10 +236,15 @@ fat_mod_SOURCES = fs/fat.c
fat_mod_CFLAGS = $(COMMON_CFLAGS) fat_mod_CFLAGS = $(COMMON_CFLAGS)
fat_mod_LDFLAGS = $(COMMON_LDFLAGS) fat_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For ufs.mod. # For ufs1.mod.
ufs_mod_SOURCES = fs/ufs.c ufs1_mod_SOURCES = fs/ufs.c
ufs_mod_CFLAGS = $(COMMON_CFLAGS) ufs1_mod_CFLAGS = $(COMMON_CFLAGS)
ufs_mod_LDFLAGS = $(COMMON_LDFLAGS) ufs1_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For ufs2.mod.
ufs2_mod_SOURCES = fs/ufs2.c
ufs2_mod_CFLAGS = $(COMMON_CFLAGS)
ufs2_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For ext2.mod. # For ext2.mod.
ext2_mod_SOURCES = fs/ext2.c ext2_mod_SOURCES = fs/ext2.c
@ -163,73 +311,157 @@ cpio_mod_SOURCES = fs/cpio.c
cpio_mod_CFLAGS = $(COMMON_CFLAGS) cpio_mod_CFLAGS = $(COMMON_CFLAGS)
cpio_mod_LDFLAGS = $(COMMON_LDFLAGS) cpio_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For tar.mod.
tar_mod_SOURCES = fs/tar.c
tar_mod_CFLAGS = $(COMMON_CFLAGS)
tar_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For udf.mod.
udf_mod_SOURCES = fs/udf.c
udf_mod_CFLAGS = $(COMMON_CFLAGS)
udf_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For afs.mod.
afs_mod_SOURCES = fs/afs.c
afs_mod_CFLAGS = $(COMMON_CFLAGS)
afs_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For afs_be.mod.
afs_be_mod_SOURCES = fs/afs_be.c
afs_be_mod_CFLAGS = $(COMMON_CFLAGS)
afs_be_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For befs.mod.
befs_mod_SOURCES = fs/befs.c
befs_mod_CFLAGS = $(COMMON_CFLAGS)
befs_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For befs_be.mod.
befs_be_mod_SOURCES = fs/befs_be.c
befs_be_mod_CFLAGS = $(COMMON_CFLAGS)
befs_be_mod_LDFLAGS = $(COMMON_LDFLAGS)
# Partition maps. # Partition maps.
pkglib_MODULES += amiga.mod apple.mod pc.mod sun.mod acorn.mod gpt.mod
# For amiga.mod pkglib_MODULES += part_amiga.mod
amiga_mod_SOURCES = partmap/amiga.c part_amiga_mod_SOURCES = partmap/amiga.c
amiga_mod_CFLAGS = $(COMMON_CFLAGS) part_amiga_mod_CFLAGS = $(COMMON_CFLAGS)
amiga_mod_LDFLAGS = $(COMMON_LDFLAGS) part_amiga_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For apple.mod pkglib_MODULES += part_apple.mod
apple_mod_SOURCES = partmap/apple.c part_apple_mod_SOURCES = partmap/apple.c
apple_mod_CFLAGS = $(COMMON_CFLAGS) part_apple_mod_CFLAGS = $(COMMON_CFLAGS)
apple_mod_LDFLAGS = $(COMMON_LDFLAGS) part_apple_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For pc.mod pkglib_MODULES += part_msdos.mod
pc_mod_SOURCES = partmap/pc.c part_msdos_mod_SOURCES = partmap/msdos.c
pc_mod_CFLAGS = $(COMMON_CFLAGS) part_msdos_mod_CFLAGS = $(COMMON_CFLAGS)
pc_mod_LDFLAGS = $(COMMON_LDFLAGS) part_msdos_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For sun.mod pkglib_MODULES += part_sun.mod
sun_mod_SOURCES = partmap/sun.c part_sun_mod_SOURCES = partmap/sun.c
sun_mod_CFLAGS = $(COMMON_CFLAGS) part_sun_mod_CFLAGS = $(COMMON_CFLAGS)
sun_mod_LDFLAGS = $(COMMON_LDFLAGS) part_sun_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For acorn.mod pkglib_MODULES += part_acorn.mod
acorn_mod_SOURCES = partmap/acorn.c part_acorn_mod_SOURCES = partmap/acorn.c
acorn_mod_CFLAGS = $(COMMON_CFLAGS) part_acorn_mod_CFLAGS = $(COMMON_CFLAGS)
acorn_mod_LDFLAGS = $(COMMON_LDFLAGS) part_acorn_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For gpt.mod pkglib_MODULES += part_gpt.mod
gpt_mod_SOURCES = partmap/gpt.c part_gpt_mod_SOURCES = partmap/gpt.c
gpt_mod_CFLAGS = $(COMMON_CFLAGS) part_gpt_mod_CFLAGS = $(COMMON_CFLAGS)
gpt_mod_LDFLAGS = $(COMMON_LDFLAGS) part_gpt_mod_LDFLAGS = $(COMMON_LDFLAGS)
# Special disk structures # Special disk structures and generic drivers
pkglib_MODULES += raid.mod lvm.mod pkglib_MODULES += raid.mod raid5rec.mod raid6rec.mod mdraid.mod dm_nv.mod \
lvm.mod scsi.mod
# For raid.mod # For raid.mod
raid_mod_SOURCES = disk/raid.c raid_mod_SOURCES = disk/raid.c
raid_mod_CFLAGS = $(COMMON_CFLAGS) raid_mod_CFLAGS = $(COMMON_CFLAGS)
raid_mod_LDFLAGS = $(COMMON_LDFLAGS) raid_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For raid.mod # For raid5rec.mod
raid5rec_mod_SOURCES = disk/raid5_recover.c
raid5rec_mod_CFLAGS = $(COMMON_CFLAGS)
raid5rec_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For raid6rec.mod
raid6rec_mod_SOURCES = disk/raid6_recover.c
raid6rec_mod_CFLAGS = $(COMMON_CFLAGS)
raid6rec_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For mdraid.mod
mdraid_mod_SOURCES = disk/mdraid_linux.c
mdraid_mod_CFLAGS = $(COMMON_CFLAGS)
mdraid_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For dm_nv.mod
dm_nv_mod_SOURCES = disk/dmraid_nvidia.c
dm_nv_mod_CFLAGS = $(COMMON_CFLAGS)
dm_nv_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For lvm.mod
lvm_mod_SOURCES = disk/lvm.c lvm_mod_SOURCES = disk/lvm.c
lvm_mod_CFLAGS = $(COMMON_CFLAGS) lvm_mod_CFLAGS = $(COMMON_CFLAGS)
lvm_mod_LDFLAGS = $(COMMON_LDFLAGS) lvm_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For scsi.mod
scsi_mod_SOURCES = disk/scsi.c
scsi_mod_CFLAGS = $(COMMON_CFLAGS)
scsi_mod_LDFLAGS = $(COMMON_LDFLAGS)
# Commands. # Commands.
pkglib_MODULES += hello.mod boot.mod terminal.mod ls.mod \ pkglib_MODULES += minicmd.mod extcmd.mod hello.mod handler.mod \
cmp.mod cat.mod help.mod font.mod search.mod \ ls.mod cmp.mod cat.mod help.mod search.mod loopback.mod \
loopback.mod configfile.mod echo.mod \ configfile.mod echo.mod \
terminfo.mod test.mod blocklist.mod hexdump.mod terminfo.mod test.mod blocklist.mod hexdump.mod \
read.mod sleep.mod loadenv.mod crc.mod parttool.mod \
msdospart.mod memrw.mod normal.mod sh.mod \
gptsync.mod true.mod probe.mod password.mod \
keystatus.mod
# For password.mod.
password_mod_SOURCES = commands/password.c
password_mod_CFLAGS = $(COMMON_CFLAGS)
password_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For gptsync.mod.
gptsync_mod_SOURCES = commands/gptsync.c
gptsync_mod_CFLAGS = $(COMMON_CFLAGS)
gptsync_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For minicmd.mod.
minicmd_mod_SOURCES = commands/minicmd.c
minicmd_mod_CFLAGS = $(COMMON_CFLAGS)
minicmd_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For extcmd.mod.
extcmd_mod_SOURCES = commands/extcmd.c lib/arg.c
extcmd_mod_CFLAGS = $(COMMON_CFLAGS)
extcmd_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For hello.mod. # For hello.mod.
hello_mod_SOURCES = hello/hello.c hello_mod_SOURCES = hello/hello.c
hello_mod_CFLAGS = $(COMMON_CFLAGS) hello_mod_CFLAGS = $(COMMON_CFLAGS)
hello_mod_LDFLAGS = $(COMMON_LDFLAGS) hello_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For boot.mod. # For parttool.mod.
boot_mod_SOURCES = commands/boot.c parttool_mod_SOURCES = commands/parttool.c
boot_mod_CFLAGS = $(COMMON_CFLAGS) parttool_mod_CFLAGS = $(COMMON_CFLAGS)
boot_mod_LDFLAGS = $(COMMON_LDFLAGS) parttool_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For terminal.mod. # For msdospart.mod.
terminal_mod_SOURCES = commands/terminal.c msdospart_mod_SOURCES = parttool/msdospart.c
terminal_mod_CFLAGS = $(COMMON_CFLAGS) msdospart_mod_CFLAGS = $(COMMON_CFLAGS)
terminal_mod_LDFLAGS = $(COMMON_LDFLAGS) msdospart_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For handler.mod.
handler_mod_SOURCES = commands/handler.c
handler_mod_CFLAGS = $(COMMON_CFLAGS)
handler_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For ls.mod. # For ls.mod.
ls_mod_SOURCES = commands/ls.c ls_mod_SOURCES = commands/ls.c
@ -256,16 +488,28 @@ help_mod_SOURCES = commands/help.c
help_mod_CFLAGS = $(COMMON_CFLAGS) help_mod_CFLAGS = $(COMMON_CFLAGS)
help_mod_LDFLAGS = $(COMMON_LDFLAGS) help_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For font.mod.
font_mod_SOURCES = font/manager.c
font_mod_CFLAGS = $(COMMON_CFLAGS)
font_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For search.mod. # For search.mod.
search_mod_SOURCES = commands/search.c search_mod_SOURCES = commands/search_wrap.c
search_mod_CFLAGS = $(COMMON_CFLAGS) search_mod_CFLAGS = $(COMMON_CFLAGS)
search_mod_LDFLAGS = $(COMMON_LDFLAGS) search_mod_LDFLAGS = $(COMMON_LDFLAGS)
pkglib_MODULES += search_fs_file.mod search_fs_uuid.mod search_label.mod
# For search.mod.
search_fs_file_mod_SOURCES = commands/search_file.c
search_fs_file_mod_CFLAGS = $(COMMON_CFLAGS)
search_fs_file_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For search.mod.
search_label_mod_SOURCES = commands/search_label.c
search_label_mod_CFLAGS = $(COMMON_CFLAGS)
search_label_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For search.mod.
search_fs_uuid_mod_SOURCES = commands/search_uuid.c
search_fs_uuid_mod_CFLAGS = $(COMMON_CFLAGS)
search_fs_uuid_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For test.mod. # For test.mod.
test_mod_SOURCES = commands/test.c test_mod_SOURCES = commands/test.c
test_mod_CFLAGS = $(COMMON_CFLAGS) test_mod_CFLAGS = $(COMMON_CFLAGS)
@ -292,12 +536,116 @@ blocklist_mod_CFLAGS = $(COMMON_CFLAGS)
blocklist_mod_LDFLAGS = $(COMMON_LDFLAGS) blocklist_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For hexdump.mod. # For hexdump.mod.
hexdump_mod_SOURCES = commands/hexdump.c hexdump_mod_SOURCES = commands/hexdump.c lib/hexdump.c
hexdump_mod_CFLAGS = $(COMMON_CFLAGS) hexdump_mod_CFLAGS = $(COMMON_CFLAGS)
hexdump_mod_LDFLAGS = $(COMMON_LDFLAGS) hexdump_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For read.mod.
read_mod_SOURCES = commands/read.c
read_mod_CFLAGS = $(COMMON_CFLAGS)
read_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For sleep.mod.
sleep_mod_SOURCES = commands/sleep.c
sleep_mod_CFLAGS = $(COMMON_CFLAGS)
sleep_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For loadenv.mod.
loadenv_mod_SOURCES = commands/loadenv.c lib/envblk.c
loadenv_mod_CFLAGS = $(COMMON_CFLAGS)
loadenv_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For crc.mod.
crc_mod_SOURCES = commands/crc.c lib/crc.c
crc_mod_CFLAGS = $(COMMON_CFLAGS)
crc_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For memrw.mod.
memrw_mod_SOURCES = commands/memrw.c
memrw_mod_CFLAGS = $(COMMON_CFLAGS)
memrw_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For true.mod
true_mod_SOURCES = commands/true.c
true_mod_CFLAGS = $(COMMON_CFLAGS)
true_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For probe.mod.
probe_mod_SOURCES = commands/probe.c
probe_mod_CFLAGS = $(COMMON_CFLAGS)
probe_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For keystatus.mod.
keystatus_mod_SOURCES = commands/keystatus.c
keystatus_mod_CFLAGS = $(COMMON_CFLAGS)
keystatus_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For normal.mod.
normal_mod_SOURCES = normal/main.c normal/cmdline.c normal/dyncmd.c \
normal/auth.c normal/autofs.c normal/handler.c \
normal/color.c normal/completion.c normal/datetime.c normal/menu.c \
normal/menu_entry.c normal/menu_text.c \
normal/misc.c normal/crypto.c normal/term.c
normal_mod_CFLAGS = $(COMMON_CFLAGS)
normal_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For sh.mod.
sh_mod_SOURCES = script/main.c script/script.c script/execute.c \
script/function.c script/lexer.c grub_script.tab.c
sh_mod_CFLAGS = $(COMMON_CFLAGS)
sh_mod_LDFLAGS = $(COMMON_LDFLAGS)
# Common Video Subsystem specific modules.
pkglib_MODULES += video.mod videotest.mod bitmap.mod tga.mod jpeg.mod \
png.mod font.mod gfxterm.mod video_fb.mod
# For video.mod.
video_mod_SOURCES = video/video.c
video_mod_CFLAGS = $(COMMON_CFLAGS)
video_mod_LDFLAGS = $(COMMON_LDFLAGS)
video_fb_mod_SOURCES = video/fb/video_fb.c video/fb/fbblit.c \
video/fb/fbfill.c video/fb/fbutil.c
video_fb_mod_CFLAGS = $(COMMON_CFLAGS)
video_fb_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For videotest.mod.
videotest_mod_SOURCES = commands/videotest.c
videotest_mod_CFLAGS = $(COMMON_CFLAGS)
videotest_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For bitmap.mod
bitmap_mod_SOURCES = video/bitmap.c
bitmap_mod_CFLAGS = $(COMMON_CFLAGS)
bitmap_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For tga.mod
tga_mod_SOURCES = video/readers/tga.c
tga_mod_CFLAGS = $(COMMON_CFLAGS)
tga_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For jpeg.mod.
jpeg_mod_SOURCES = video/readers/jpeg.c
jpeg_mod_CFLAGS = $(COMMON_CFLAGS)
jpeg_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For png.mod.
png_mod_SOURCES = video/readers/png.c
png_mod_CFLAGS = $(COMMON_CFLAGS)
png_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For font.mod.
font_mod_SOURCES = font/font_cmd.c font/font.c
font_mod_CFLAGS = $(COMMON_CFLAGS)
font_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For gfxterm.mod.
gfxterm_mod_SOURCES = term/gfxterm.c
gfxterm_mod_CFLAGS = $(COMMON_CFLAGS)
gfxterm_mod_LDFLAGS = $(COMMON_LDFLAGS)
# Misc. # Misc.
pkglib_MODULES += gzio.mod elf.mod pkglib_MODULES += gzio.mod bufio.mod elf.mod
# For elf.mod. # For elf.mod.
elf_mod_SOURCES = kern/elf.c elf_mod_SOURCES = kern/elf.c
@ -309,5 +657,63 @@ gzio_mod_SOURCES = io/gzio.c
gzio_mod_CFLAGS = $(COMMON_CFLAGS) gzio_mod_CFLAGS = $(COMMON_CFLAGS)
gzio_mod_LDFLAGS = $(COMMON_LDFLAGS) gzio_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For bufio.mod.
bufio_mod_SOURCES = io/bufio.c
bufio_mod_CFLAGS = $(COMMON_CFLAGS)
bufio_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For gettext.mod.
pkglib_MODULES += gettext.mod
gettext_mod_SOURCES = gettext/gettext.c
gettext_mod_CFLAGS = $(COMMON_CFLAGS)
gettext_mod_LDFLAGS = $(COMMON_LDFLAGS)
# Misc.
pkglib_MODULES += xnu_uuid.mod
# For elf.mod.
xnu_uuid_mod_SOURCES = commands/xnu_uuid.c
xnu_uuid_mod_CFLAGS = $(COMMON_CFLAGS)
xnu_uuid_mod_LDFLAGS = $(COMMON_LDFLAGS)
pkglib_MODULES += setjmp.mod
setjmp_mod_SOURCES = lib/$(target_cpu)/setjmp.S
setjmp_mod_ASFLAGS = $(COMMON_ASFLAGS)
setjmp_mod_LDFLAGS = $(COMMON_LDFLAGS)
pkglib_MODULES += charset.mod
charset_mod_SOURCES = lib/charset.c
charset_mod_CFLAGS = $(COMMON_CFLAGS)
charset_mod_LDFLAGS = $(COMMON_LDFLAGS)
pkglib_MODULES += terminal.mod
terminal_mod_SOURCES = commands/terminal.c
terminal_mod_CFLAGS = $(COMMON_CFLAGS)
terminal_mod_LDFLAGS = $(COMMON_LDFLAGS)
pkglib_MODULES += crypto.mod
crypto_mod_SOURCES = lib/crypto.c
crypto_mod_CFLAGS = $(COMMON_CFLAGS)
crypto_mod_LDFLAGS = $(COMMON_LDFLAGS)
pkglib_MODULES += hashsum.mod
hashsum_mod_SOURCES = commands/hashsum.c
hashsum_mod_CFLAGS = $(COMMON_CFLAGS)
hashsum_mod_LDFLAGS = $(COMMON_LDFLAGS)
pkglib_MODULES += pbkdf2.mod
pbkdf2_mod_SOURCES = lib/pbkdf2.c
pbkdf2_mod_CFLAGS = $(COMMON_CFLAGS)
pbkdf2_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For password_pbkdf2.mod.
pkglib_MODULES += password_pbkdf2.mod
password_pbkdf2_mod_SOURCES = commands/password_pbkdf2.c
password_pbkdf2_mod_CFLAGS = $(COMMON_CFLAGS)
password_pbkdf2_mod_LDFLAGS = $(COMMON_LDFLAGS)
bin_UTILITIES += grub-mkpasswd-pbkdf2
grub_mkpasswd_pbkdf2_SOURCES = gnulib/progname.c util/grub-mkpasswd-pbkdf2.c lib/crypto.c lib/libgcrypt-grub/cipher/sha512.c lib/pbkdf2.c util/misc.c kern/err.c
grub_mkpasswd_pbkdf2_CFLAGS += -Wno-missing-field-initializers -Wno-error -I$(srcdir)/lib/libgcrypt_wrap -DGRUB_MKPASSWD=1
include $(srcdir)/conf/gcry.mk

196
conf/i386-coreboot.rmk Normal file
View File

@ -0,0 +1,196 @@
# -*- makefile -*-
COMMON_ASFLAGS = -nostdinc -fno-builtin -m32
COMMON_CFLAGS = -fno-builtin -mrtd -mregparm=3 -m32
COMMON_LDFLAGS = -m32 -nostdlib
# Used by various components. These rules need to precede them.
script/lexer.c_DEPENDENCIES = grub_script.tab.h
# Images.
GRUB_KERNEL_MACHINE_LINK_ADDR = 0x8200
ifeq ($(platform), coreboot)
pkglib_PROGRAMS += kernel.img
kernel_img_SOURCES = kern/i386/coreboot/startup.S \
kern/i386/misc.S \
kern/i386/coreboot/init.c \
kern/i386/multiboot_mmap.c \
kern/i386/halt.c \
kern/main.c kern/device.c \
kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \
kern/misc.c kern/mm.c kern/term.c \
kern/rescue_parser.c kern/rescue_reader.c \
kern/time.c kern/list.c kern/handler.c kern/command.c kern/corecmd.c \
kern/$(target_cpu)/dl.c kern/parser.c kern/partition.c \
kern/i386/tsc.c kern/i386/pit.c \
kern/generic/rtc_get_time_ms.c \
kern/generic/millisleep.c \
kern/env.c \
term/i386/pc/vga_text.c term/i386/vga_common.c \
symlist.c
kernel_img_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \
env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \
partition.h msdos_partition.h reader.h symbol.h term.h time.h types.h \
machine/boot.h machine/console.h machine/init.h \
machine/memory.h machine/loader.h list.h handler.h command.h i18n.h
kernel_img_CFLAGS = $(COMMON_CFLAGS)
kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
kernel_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-S,-Ttext,$(GRUB_KERNEL_MACHINE_LINK_ADDR),-Bstatic
endif
ifeq ($(platform), qemu)
GRUB_BOOT_MACHINE_LINK_ADDR = 0xffe00
pkglib_IMAGES += boot.img
boot_img_SOURCES = boot/i386/qemu/boot.S
boot_img_ASFLAGS = $(COMMON_ASFLAGS) -DGRUB_BOOT_MACHINE_LINK_ADDR=$(GRUB_BOOT_MACHINE_LINK_ADDR)
boot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)$(GRUB_BOOT_MACHINE_LINK_ADDR)
boot_img_FORMAT = binary
bin_UTILITIES += grub-mkimage
grub_mkimage_SOURCES = util/i386/pc/grub-mkimage.c util/misc.c \
util/resolve.c gnulib/progname.c
grub_mkimage_CFLAGS = -DGRUB_KERNEL_MACHINE_LINK_ADDR=$(GRUB_KERNEL_MACHINE_LINK_ADDR)
pkglib_IMAGES += kernel.img
kernel_img_SOURCES = kern/i386/qemu/startup.S \
kern/i386/misc.S \
kern/i386/coreboot/init.c \
kern/i386/qemu/mmap.c \
kern/i386/halt.c \
kern/main.c kern/device.c \
kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \
kern/misc.c kern/mm.c kern/term.c \
kern/rescue_parser.c kern/rescue_reader.c \
kern/time.c kern/list.c kern/handler.c kern/command.c kern/corecmd.c \
kern/$(target_cpu)/dl.c kern/parser.c kern/partition.c \
kern/i386/tsc.c kern/i386/pit.c \
kern/generic/rtc_get_time_ms.c \
kern/generic/millisleep.c \
kern/env.c \
term/i386/pc/vga_text.c term/i386/vga_common.c \
symlist.c
kernel_img_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \
env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \
partition.h msdos_partition.h reader.h symbol.h term.h time.h types.h \
machine/boot.h machine/console.h machine/init.h \
machine/memory.h machine/loader.h list.h handler.h command.h i18n.h
kernel_img_CFLAGS = $(COMMON_CFLAGS) -DGRUB_BOOT_MACHINE_LINK_ADDR=$(GRUB_BOOT_MACHINE_LINK_ADDR)
kernel_img_ASFLAGS = $(COMMON_ASFLAGS) -DGRUB_KERNEL_MACHINE_LINK_ADDR=$(GRUB_KERNEL_MACHINE_LINK_ADDR)
kernel_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)$(GRUB_KERNEL_MACHINE_LINK_ADDR)
kernel_img_FORMAT = binary
endif
MOSTLYCLEANFILES += symlist.c kernel_syms.lst
DEFSYMFILES += kernel_syms.lst
symlist.c: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h gensymlist.sh
/bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1)
kernel_syms.lst: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h genkernsyms.sh
/bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1)
sbin_SCRIPTS += grub-install
grub_install_SOURCES = util/grub-install.in
bin_SCRIPTS += grub-mkrescue
grub_mkrescue_SOURCES = util/grub-mkrescue.in
# Modules.
pkglib_MODULES = linux.mod \
aout.mod play.mod serial.mod \
memdisk.mod pci.mod lspci.mod reboot.mod \
halt.mod datetime.mod date.mod datehook.mod \
lsmmap.mod mmap.mod
# For boot.mod.
pkglib_MODULES += boot.mod
boot_mod_SOURCES = commands/boot.c
boot_mod_CFLAGS = $(COMMON_CFLAGS)
boot_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For mmap.mod.
mmap_mod_SOURCES = mmap/mmap.c mmap/i386/uppermem.c mmap/i386/mmap.c
mmap_mod_CFLAGS = $(COMMON_CFLAGS)
mmap_mod_LDFLAGS = $(COMMON_LDFLAGS)
mmap_mod_ASFLAGS = $(COMMON_ASFLAGS)
# For linux.mod.
linux_mod_SOURCES = loader/i386/linux.c
linux_mod_CFLAGS = $(COMMON_CFLAGS)
linux_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For reboot.mod.
reboot_mod_SOURCES = commands/reboot.c
reboot_mod_CFLAGS = $(COMMON_CFLAGS)
reboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For halt.mod.
halt_mod_SOURCES = commands/halt.c
halt_mod_CFLAGS = $(COMMON_CFLAGS)
halt_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For serial.mod.
serial_mod_SOURCES = term/i386/pc/serial.c
serial_mod_CFLAGS = $(COMMON_CFLAGS)
serial_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For aout.mod.
aout_mod_SOURCES = loader/aout.c
aout_mod_CFLAGS = $(COMMON_CFLAGS)
aout_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For bsd.mod
pkglib_MODULES += bsd.mod
bsd_mod_SOURCES = loader/i386/bsd.c loader/i386/bsd32.c loader/i386/bsd64.c loader/i386/bsd_helper.S loader/i386/bsd_trampoline.S
bsd_mod_CFLAGS = $(COMMON_CFLAGS)
bsd_mod_LDFLAGS = $(COMMON_LDFLAGS)
bsd_mod_ASFLAGS = $(COMMON_ASFLAGS)
# For play.mod.
play_mod_SOURCES = commands/i386/pc/play.c
play_mod_CFLAGS = $(COMMON_CFLAGS)
play_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For memdisk.mod.
memdisk_mod_SOURCES = disk/memdisk.c
memdisk_mod_CFLAGS = $(COMMON_CFLAGS)
memdisk_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For pci.mod
pci_mod_SOURCES = bus/pci.c
pci_mod_CFLAGS = $(COMMON_CFLAGS)
pci_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For lspci.mod
lspci_mod_SOURCES = commands/lspci.c
lspci_mod_CFLAGS = $(COMMON_CFLAGS)
lspci_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For datetime.mod
datetime_mod_SOURCES = lib/i386/datetime.c
datetime_mod_CFLAGS = $(COMMON_CFLAGS)
datetime_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For date.mod
date_mod_SOURCES = commands/date.c
date_mod_CFLAGS = $(COMMON_CFLAGS)
date_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For datehook.mod
datehook_mod_SOURCES = hook/datehook.c
datehook_mod_CFLAGS = $(COMMON_CFLAGS)
datehook_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For lsmmap.mod
lsmmap_mod_SOURCES = commands/lsmmap.c
lsmmap_mod_CFLAGS = $(COMMON_CFLAGS)
lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS)
include $(srcdir)/conf/i386.mk
include $(srcdir)/conf/common.mk

File diff suppressed because it is too large Load Diff

View File

@ -4,80 +4,25 @@ COMMON_ASFLAGS = -nostdinc -fno-builtin -m32
COMMON_CFLAGS = -fno-builtin -m32 COMMON_CFLAGS = -fno-builtin -m32
COMMON_LDFLAGS = -melf_i386 -nostdlib COMMON_LDFLAGS = -melf_i386 -nostdlib
# Used by various components. These rules need to precede them.
script/lexer.c_DEPENDENCIES = grub_script.tab.h
# Utilities. # Utilities.
bin_UTILITIES = grub-mkimage bin_UTILITIES = grub-mkimage
sbin_UTILITIES = grub-mkdevicemap grub-probe
#ifeq ($(enable_grub_emu), yes)
#sbin_UTILITIES += grub-emu
#endif
# For grub-mkimage. # For grub-mkimage.
grub_mkimage_SOURCES = util/i386/efi/grub-mkimage.c util/misc.c \ grub_mkimage_SOURCES = gnulib/progname.c util/i386/efi/grub-mkimage.c \
util/resolve.c util/misc.c util/resolve.c
util/i386/efi/grub-mkimage.c_DEPENDENCIES = Makefile
# For grub-setup. # For grub-setup.
#grub_setup_SOURCES = util/i386/pc/grub-setup.c util/biosdisk.c \ #grub_setup_SOURCES = util/i386/pc/grub-setup.c util/hostdisk.c \
# util/misc.c util/getroot.c kern/device.c kern/disk.c \ # util/misc.c util/getroot.c kern/device.c kern/disk.c \
# kern/err.c kern/misc.c fs/fat.c fs/ext2.c fs/xfs.c fs/affs.c \ # kern/err.c kern/misc.c fs/fat.c fs/ext2.c fs/xfs.c fs/affs.c \
# fs/sfs.c kern/parser.c kern/partition.c partmap/pc.c \ # fs/sfs.c kern/parser.c kern/partition.c partmap/msdos.c \
# fs/ufs.c fs/minix.c fs/hfs.c fs/jfs.c fs/hfsplus.c kern/file.c \ # fs/ufs.c fs/ufs2.c fs/minix.c fs/hfs.c fs/jfs.c fs/hfsplus.c kern/file.c \
# kern/fs.c kern/env.c fs/fshelp.c # kern/fs.c kern/env.c fs/fshelp.c
# For grub-mkdevicemap.
grub_mkdevicemap_SOURCES = util/grub-mkdevicemap.c util/misc.c \
util/i386/get_disk_name.c
# For grub-probe.
util/grub-probe.c_DEPENDENCIES = grub_probe_init.h
grub_probe_SOURCES = util/grub-probe.c \
util/biosdisk.c util/misc.c util/getroot.c \
kern/device.c kern/disk.c kern/err.c kern/misc.c \
kern/parser.c kern/partition.c kern/file.c \
kern/fs.c kern/env.c fs/fshelp.c \
partmap/pc.c partmap/apple.c partmap/gpt.c \
\
fs/affs.c fs/cpio.c fs/ext2.c fs/fat.c fs/hfs.c \
fs/hfsplus.c fs/iso9660.c fs/jfs.c fs/minix.c \
fs/ntfs.c fs/ntfscomp.c fs/reiserfs.c fs/sfs.c \
fs/ufs.c fs/xfs.c \
\
disk/lvm.c disk/raid.c grub_probe_init.c
# For grub-emu.
util/grub-emu.c_DEPENDENCIES = grub_emu_init.h
normal/execute.c_DEPENDENCIES = grub_script.tab.h
grub-emu_DEPENDENCIES = grub_script.tab.c
grub_emu_SOURCES = commands/boot.c commands/cat.c commands/cmp.c \
commands/configfile.c commands/help.c \
commands/terminal.c commands/ls.c commands/test.c \
commands/search.c commands/hexdump.c \
commands/i386/pc/halt.c commands/i386/pc/reboot.c \
commands/i386/cpuid.c \
disk/loopback.c \
\
fs/affs.c fs/cpio.c fs/ext2.c fs/fat.c fs/hfs.c \
fs/hfsplus.c fs/iso9660.c fs/jfs.c fs/minix.c \
fs/ntfs.c fs/ntfscomp.c fs/reiserfs.c fs/sfs.c \
fs/ufs.c fs/xfs.c \
\
io/gzio.c \
kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c \
kern/err.c \
normal/execute.c kern/file.c kern/fs.c normal/lexer.c \
kern/loader.c kern/main.c kern/misc.c kern/parser.c \
grub_script.tab.c kern/partition.c kern/rescue.c kern/term.c \
normal/arg.c normal/cmdline.c normal/command.c normal/function.c\
normal/completion.c normal/context.c normal/main.c \
normal/menu.c normal/menu_entry.c normal/misc.c normal/script.c \
normal/color.c \
partmap/amiga.c partmap/apple.c partmap/pc.c partmap/sun.c \
partmap/acorn.c partmap/gpt.c \
util/console.c util/hostfs.c util/grub-emu.c util/misc.c \
util/biosdisk.c util/getroot.c \
util/i386/pc/misc.c grub_emu_init.c
grub_emu_LDFLAGS = $(LIBCURSES)
# Scripts. # Scripts.
sbin_SCRIPTS = grub-install sbin_SCRIPTS = grub-install
@ -85,69 +30,135 @@ sbin_SCRIPTS = grub-install
grub_install_SOURCES = util/i386/efi/grub-install.in grub_install_SOURCES = util/i386/efi/grub-install.in
# Modules. # Modules.
pkglib_MODULES = kernel.mod normal.mod _chain.mod chain.mod \ pkglib_MODULES = kernel.img chain.mod appleldr.mod \
_linux.mod linux.mod cpuid.mod linux.mod halt.mod reboot.mod pci.mod lspci.mod \
datetime.mod date.mod datehook.mod loadbios.mod \
fixvideo.mod mmap.mod acpi.mod
# For kernel.mod. # For kernel.img.
kernel_mod_EXPORTS = no kernel_img_EXPORTS = no
kernel_mod_SOURCES = kern/i386/efi/startup.S kern/main.c kern/device.c \ kernel_img_SOURCES = kern/i386/efi/startup.S kern/main.c kern/device.c \
kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \ kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \
kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c \ kern/misc.c kern/mm.c kern/term.c \
kern/i386/dl.c kern/i386/efi/init.c kern/parser.c kern/partition.c \ kern/rescue_parser.c kern/rescue_reader.c \
kern/$(target_cpu)/dl.c kern/i386/efi/init.c kern/parser.c kern/partition.c \
kern/env.c symlist.c kern/efi/efi.c kern/efi/init.c kern/efi/mm.c \ kern/env.c symlist.c kern/efi/efi.c kern/efi/init.c kern/efi/mm.c \
term/efi/console.c disk/efi/efidisk.c term/efi/console.c disk/efi/efidisk.c \
kernel_mod_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ kern/time.c kern/list.c kern/handler.c kern/command.c kern/corecmd.c \
kern/i386/tsc.c kern/i386/pit.c \
kern/generic/rtc_get_time_ms.c \
kern/generic/millisleep.c
kernel_img_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \
env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \ env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \
partition.h pc_partition.h rescue.h symbol.h term.h time.h types.h \ partition.h msdos_partition.h reader.h symbol.h term.h time.h types.h \
efi/efi.h efi/time.h efi/disk.h efi/efi.h efi/time.h efi/disk.h i386/pit.h list.h handler.h command.h i18n.h
kernel_mod_CFLAGS = $(COMMON_CFLAGS) kernel_img_CFLAGS = $(COMMON_CFLAGS)
kernel_mod_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
kernel_mod_LDFLAGS = $(COMMON_LDFLAGS) kernel_img_LDFLAGS = $(COMMON_LDFLAGS)
MOSTLYCLEANFILES += symlist.c MOSTLYCLEANFILES += symlist.c
MOSTLYCLEANFILES += symlist.c kernel_syms.lst MOSTLYCLEANFILES += symlist.c kernel_syms.lst
DEFSYMFILES += kernel_syms.lst DEFSYMFILES += kernel_syms.lst
symlist.c: $(addprefix include/grub/,$(kernel_mod_HEADERS)) config.h gensymlist.sh symlist.c: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h gensymlist.sh
/bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) /bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1)
kernel_syms.lst: $(addprefix include/grub/,$(kernel_mod_HEADERS)) config.h genkernsyms.sh kernel_syms.lst: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h genkernsyms.sh
/bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) /bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1)
# For normal.mod. # For boot.mod.
normal_mod_DEPENDENCIES = grub_script.tab.c grub_script.tab.h pkglib_MODULES += boot.mod
normal_mod_SOURCES = normal/arg.c normal/cmdline.c normal/command.c \ boot_mod_SOURCES = commands/boot.c
normal/completion.c normal/execute.c \ boot_mod_CFLAGS = $(COMMON_CFLAGS)
normal/function.c normal/lexer.c normal/main.c normal/menu.c \ boot_mod_LDFLAGS = $(COMMON_LDFLAGS)
normal/menu_entry.c normal/misc.c grub_script.tab.c \
normal/script.c normal/i386/setjmp.S normal/color.c
normal_mod_CFLAGS = $(COMMON_CFLAGS)
normal_mod_ASFLAGS = $(COMMON_ASFLAGS)
normal_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For _chain.mod. # For acpi.mod.
_chain_mod_SOURCES = loader/efi/chainloader.c acpi_mod_SOURCES = commands/acpi.c commands/efi/acpi.c
_chain_mod_CFLAGS = $(COMMON_CFLAGS) acpi_mod_CFLAGS = $(COMMON_CFLAGS)
_chain_mod_LDFLAGS = $(COMMON_LDFLAGS) acpi_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For mmap.mod.
mmap_mod_SOURCES = mmap/mmap.c mmap/i386/uppermem.c mmap/i386/mmap.c \
mmap/efi/mmap.c
mmap_mod_CFLAGS = $(COMMON_CFLAGS)
mmap_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For chain.mod. # For chain.mod.
chain_mod_SOURCES = loader/efi/chainloader_normal.c chain_mod_SOURCES = loader/efi/chainloader.c
chain_mod_CFLAGS = $(COMMON_CFLAGS) chain_mod_CFLAGS = $(COMMON_CFLAGS)
chain_mod_LDFLAGS = $(COMMON_LDFLAGS) chain_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For _linux.mod. # For appleldr.mod.
_linux_mod_SOURCES = loader/i386/efi/linux.c appleldr_mod_SOURCES = loader/efi/appleloader.c
_linux_mod_CFLAGS = $(COMMON_CFLAGS) appleldr_mod_CFLAGS = $(COMMON_CFLAGS)
_linux_mod_LDFLAGS = $(COMMON_LDFLAGS) appleldr_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For linux.mod. # For linux.mod.
linux_mod_SOURCES = loader/i386/efi/linux_normal.c linux_mod_SOURCES = loader/i386/efi/linux.c
linux_mod_CFLAGS = $(COMMON_CFLAGS) linux_mod_CFLAGS = $(COMMON_CFLAGS)
linux_mod_LDFLAGS = $(COMMON_LDFLAGS) linux_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For cpuid.mod. # For halt.mod.
cpuid_mod_SOURCES = commands/i386/cpuid.c halt_mod_SOURCES = commands/halt.c
cpuid_mod_CFLAGS = $(COMMON_CFLAGS) halt_mod_CFLAGS = $(COMMON_CFLAGS)
cpuid_mod_LDFLAGS = $(COMMON_LDFLAGS) halt_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For reboot.mod.
reboot_mod_SOURCES = commands/reboot.c
reboot_mod_CFLAGS = $(COMMON_CFLAGS)
reboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For pci.mod
pci_mod_SOURCES = bus/pci.c
pci_mod_CFLAGS = $(COMMON_CFLAGS)
pci_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For lspci.mod
lspci_mod_SOURCES = commands/lspci.c
lspci_mod_CFLAGS = $(COMMON_CFLAGS)
lspci_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For datetime.mod
datetime_mod_SOURCES = lib/efi/datetime.c
datetime_mod_CFLAGS = $(COMMON_CFLAGS)
datetime_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For date.mod
date_mod_SOURCES = commands/date.c
date_mod_CFLAGS = $(COMMON_CFLAGS)
date_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For datehook.mod
datehook_mod_SOURCES = hook/datehook.c
datehook_mod_CFLAGS = $(COMMON_CFLAGS)
datehook_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For loadbios.mod
loadbios_mod_SOURCES = commands/efi/loadbios.c
loadbios_mod_CFLAGS = $(COMMON_CFLAGS)
loadbios_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For fixvideo.mod
fixvideo_mod_SOURCES = commands/efi/fixvideo.c
fixvideo_mod_CFLAGS = $(COMMON_CFLAGS)
fixvideo_mod_LDFLAGS = $(COMMON_LDFLAGS)
pkglib_MODULES += efi_uga.mod
efi_uga_mod_SOURCES = video/efi_uga.c
efi_uga_mod_CFLAGS = $(COMMON_CFLAGS)
efi_uga_mod_LDFLAGS = $(COMMON_LDFLAGS)
pkglib_MODULES += efi_gop.mod
efi_gop_mod_SOURCES = video/efi_gop.c
efi_gop_mod_CFLAGS = $(COMMON_CFLAGS)
efi_gop_mod_LDFLAGS = $(COMMON_LDFLAGS)
pkglib_MODULES += xnu.mod
xnu_mod_SOURCES = loader/xnu_resume.c loader/i386/xnu.c loader/i386/efi/xnu.c \
loader/macho32.c loader/macho64.c loader/macho.c loader/xnu.c
xnu_mod_CFLAGS = $(COMMON_CFLAGS)
xnu_mod_LDFLAGS = $(COMMON_LDFLAGS)
xnu_mod_ASFLAGS = $(COMMON_ASFLAGS)
include $(srcdir)/conf/i386.mk
include $(srcdir)/conf/common.mk include $(srcdir)/conf/common.mk

File diff suppressed because it is too large Load Diff

View File

@ -2,135 +2,79 @@
COMMON_ASFLAGS = -m32 -nostdinc -fno-builtin COMMON_ASFLAGS = -m32 -nostdinc -fno-builtin
COMMON_CFLAGS = -ffreestanding -mrtd -mregparm=3 COMMON_CFLAGS = -ffreestanding -mrtd -mregparm=3
COMMON_LDFLAGS = -nostdlib -static -lgcc COMMON_LDFLAGS = -nostdlib
# Used by various components. These rules need to precede them.
script/lexer.c_DEPENDENCIES = grub_script.tab.h
# Images. # Images.
pkglib_PROGRAMS = kernel.elf pkglib_PROGRAMS = kernel.img
# For kernel.elf. # For kernel.img.
kernel_elf_SOURCES = kern/i386/ieee1275/startup.S kern/i386/ieee1275/init.c \ kernel_img_SOURCES = kern/i386/ieee1275/startup.S \
kern/powerpc/ieee1275/init.c \ kern/i386/misc.S \
kern/powerpc/ieee1275/cmain.c kern/powerpc/ieee1275/openfw.c \ kern/i386/ieee1275/init.c \
kern/ieee1275/init.c \
kern/ieee1275/mmap.c \
kern/ieee1275/cmain.c kern/ieee1275/openfw.c \
kern/main.c kern/device.c \ kern/main.c kern/device.c \
kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \ kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \
kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c \ kern/misc.c kern/mm.c kern/term.c \
kern/i386/dl.c kern/parser.c kern/partition.c \ kern/rescue_parser.c kern/rescue_reader.c \
kern/$(target_cpu)/dl.c kern/parser.c kern/partition.c \
kern/env.c \ kern/env.c \
kern/time.c kern/list.c kern/handler.c kern/command.c kern/corecmd.c \
kern/generic/millisleep.c \
kern/ieee1275/ieee1275.c \ kern/ieee1275/ieee1275.c \
term/ieee1275/ofconsole.c term/i386/pc/at_keyboard.c \ term/ieee1275/ofconsole.c \
disk/ieee1275/ofdisk.c \ disk/ieee1275/ofdisk.c \
symlist.c symlist.c
kernel_elf_HEADERS = arg.h cache.h device.h disk.h dl.h elf.h elfload.h \ kernel_img_HEADERS = cache.h device.h disk.h dl.h elf.h elfload.h \
env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \ env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \
partition.h pc_partition.h rescue.h symbol.h term.h time.h types.h \ partition.h msdos_partition.h reader.h symbol.h term.h time.h types.h \
ieee1275/ieee1275.h machine/kernel.h machine/loader.h machine/memory.h ieee1275/ieee1275.h machine/kernel.h machine/loader.h machine/memory.h \
kernel_elf_CFLAGS = $(COMMON_CFLAGS) list.h handler.h command.h i18n.h
kernel_elf_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-S,-Ttext,0x10000,-Bstatic kernel_img_CFLAGS = $(COMMON_CFLAGS)
kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
kernel_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-S,-Ttext,0x10000,-Bstatic
MOSTLYCLEANFILES += symlist.c kernel_syms.lst MOSTLYCLEANFILES += symlist.c kernel_syms.lst
DEFSYMFILES += kernel_syms.lst DEFSYMFILES += kernel_syms.lst
symlist.c: $(addprefix include/grub/,$(kernel_elf_HEADERS)) config.h gensymlist.sh symlist.c: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h gensymlist.sh
/bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) /bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1)
kernel_syms.lst: $(addprefix include/grub/,$(kernel_elf_HEADERS)) config.h genkernsyms.sh kernel_syms.lst: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h genkernsyms.sh
/bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) /bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1)
# Utilities. # Scripts.
bin_UTILITIES = grub-mkimage sbin_SCRIPTS = grub-install
sbin_UTILITIES = grub-mkdevicemap grub-probe
ifeq ($(enable_grub_emu), yes)
sbin_UTILITIES += grub-emu
endif
# For grub-mkimage. # For grub-install.
grub_mkimage_SOURCES = util/elf/grub-mkimage.c util/misc.c \ grub_install_SOURCES = util/ieee1275/grub-install.in
util/resolve.c
grub_mkimage_LDFLAGS = $(LIBLZO)
# For grub-mkdevicemap.
grub_mkdevicemap_SOURCES = util/grub-mkdevicemap.c util/misc.c \
util/i386/get_disk_name.c
# For grub-probe.
util/grub-probe.c_DEPENDENCIES = grub_probe_init.h
grub_probe_SOURCES = util/grub-probe.c \
util/biosdisk.c util/misc.c util/getroot.c \
kern/device.c kern/disk.c kern/err.c kern/misc.c \
kern/parser.c kern/partition.c \
partmap/pc.c partmap/apple.c partmap/gpt.c \
kern/fs.c kern/file.c \
\
fs/affs.c fs/cpio.c fs/ext2.c fs/fat.c fs/hfs.c \
fs/hfsplus.c fs/iso9660.c fs/jfs.c fs/minix.c \
fs/ntfs.c fs/ntfscomp.c fs/reiserfs.c fs/sfs.c \
fs/ufs.c fs/xfs.c \
\
kern/env.c fs/fshelp.c \
disk/lvm.c disk/raid.c grub_probe_init.c
# For grub-emu.
util/grub-emu.c_DEPENDENCIES = grub_emu_init.h
normal/execute.c_DEPENDENCIES = grub_script.tab.h
grub-emu_DEPENDENCIES = grub_script.tab.c
grub_emu_SOURCES = commands/boot.c commands/cat.c commands/cmp.c \
commands/configfile.c commands/echo.c commands/help.c \
commands/terminal.c commands/ls.c commands/test.c \
commands/search.c commands/blocklist.c commands/hexdump.c \
commands/ieee1275/halt.c commands/ieee1275/reboot.c \
commands/i386/cpuid.c \
disk/host.c disk/loopback.c disk/raid.c disk/lvm.c \
\
fs/affs.c fs/cpio.c fs/ext2.c fs/fat.c fs/hfs.c \
fs/hfsplus.c fs/iso9660.c fs/jfs.c fs/minix.c \
fs/ntfs.c fs/ntfscomp.c fs/reiserfs.c fs/sfs.c \
fs/ufs.c fs/xfs.c \
\
fs/fshelp.c \
io/gzio.c \
kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c \
kern/err.c \
normal/execute.c kern/file.c kern/fs.c normal/lexer.c \
kern/loader.c kern/main.c kern/misc.c kern/parser.c \
grub_script.tab.c kern/partition.c kern/rescue.c kern/term.c \
normal/arg.c normal/cmdline.c normal/command.c normal/function.c\
normal/completion.c normal/main.c \
normal/menu.c normal/menu_entry.c normal/misc.c normal/script.c \
normal/color.c \
partmap/amiga.c partmap/apple.c partmap/pc.c partmap/sun.c \
partmap/acorn.c partmap/gpt.c \
util/console.c util/hostfs.c util/grub-emu.c util/misc.c \
util/biosdisk.c util/getroot.c \
util/i386/pc/misc.c grub_emu_init.c
grub_emu_LDFLAGS = $(LIBCURSES)
# Modules. # Modules.
pkglib_MODULES = normal.mod halt.mod reboot.mod suspend.mod cpuid.mod \ pkglib_MODULES = halt.mod reboot.mod suspend.mod \
multiboot.mod _multiboot.mod serial.mod aout.mod serial.mod linux.mod \
nand.mod memdisk.mod pci.mod lspci.mod datetime.mod \
date.mod datehook.mod lsmmap.mod mmap.mod
# For normal.mod. # For boot.mod.
normal_mod_DEPENDENCIES = grub_script.tab.c grub_script.tab.h pkglib_MODULES += boot.mod
normal_mod_SOURCES = normal/arg.c normal/cmdline.c normal/command.c \ boot_mod_SOURCES = commands/boot.c
normal/completion.c normal/execute.c \ boot_mod_CFLAGS = $(COMMON_CFLAGS)
normal/function.c normal/lexer.c normal/main.c normal/menu.c \ boot_mod_LDFLAGS = $(COMMON_LDFLAGS)
normal/menu_entry.c normal/misc.c grub_script.tab.c \
normal/script.c normal/i386/setjmp.S normal/color.c
normal_mod_CFLAGS = $(COMMON_CFLAGS)
normal_mod_ASFLAGS = $(COMMON_ASFLAGS)
normal_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For _multiboot.mod. # For mmap.mod.
_multiboot_mod_SOURCES = loader/powerpc/ieee1275/multiboot2.c \ mmap_mod_SOURCES = mmap/mmap.c mmap/i386/uppermem.c mmap/i386/mmap.c
loader/multiboot2.c \ mmap_mod_CFLAGS = $(COMMON_CFLAGS)
loader/multiboot_loader.c mmap_mod_LDFLAGS = $(COMMON_LDFLAGS)
_multiboot_mod_CFLAGS = $(COMMON_CFLAGS) mmap_mod_ASFLAGS = $(COMMON_ASFLAGS)
_multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For multiboot.mod. # For aout.mod.
multiboot_mod_SOURCES = loader/multiboot_loader_normal.c aout_mod_SOURCES = loader/aout.c
multiboot_mod_CFLAGS = $(COMMON_CFLAGS) aout_mod_CFLAGS = $(COMMON_CFLAGS)
multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS) aout_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For suspend.mod # For suspend.mod
suspend_mod_SOURCES = commands/ieee1275/suspend.c suspend_mod_SOURCES = commands/ieee1275/suspend.c
@ -138,23 +82,64 @@ suspend_mod_CFLAGS = $(COMMON_CFLAGS)
suspend_mod_LDFLAGS = $(COMMON_LDFLAGS) suspend_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For reboot.mod # For reboot.mod
reboot_mod_SOURCES = commands/ieee1275/reboot.c reboot_mod_SOURCES = commands/reboot.c
reboot_mod_CFLAGS = $(COMMON_CFLAGS) reboot_mod_CFLAGS = $(COMMON_CFLAGS)
reboot_mod_LDFLAGS = $(COMMON_LDFLAGS) reboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For halt.mod # For halt.mod
halt_mod_SOURCES = commands/ieee1275/halt.c halt_mod_SOURCES = commands/halt.c
halt_mod_CFLAGS = $(COMMON_CFLAGS) halt_mod_CFLAGS = $(COMMON_CFLAGS)
halt_mod_LDFLAGS = $(COMMON_LDFLAGS) halt_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For cpuid.mod.
cpuid_mod_SOURCES = commands/i386/cpuid.c
cpuid_mod_CFLAGS = $(COMMON_CFLAGS)
cpuid_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For serial.mod. # For serial.mod.
serial_mod_SOURCES = term/i386/pc/serial.c serial_mod_SOURCES = term/i386/pc/serial.c
serial_mod_CFLAGS = $(COMMON_CFLAGS) serial_mod_CFLAGS = $(COMMON_CFLAGS)
serial_mod_LDFLAGS = $(COMMON_LDFLAGS) serial_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For linux.mod.
linux_mod_SOURCES = loader/i386/ieee1275/linux.c
linux_mod_CFLAGS = $(COMMON_CFLAGS)
linux_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For nand.mod.
nand_mod_SOURCES = disk/ieee1275/nand.c
nand_mod_CFLAGS = $(COMMON_CFLAGS)
nand_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For memdisk.mod.
memdisk_mod_SOURCES = disk/memdisk.c
memdisk_mod_CFLAGS = $(COMMON_CFLAGS)
memdisk_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For pci.mod
pci_mod_SOURCES = bus/pci.c
pci_mod_CFLAGS = $(COMMON_CFLAGS)
pci_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For lspci.mod
lspci_mod_SOURCES = commands/lspci.c
lspci_mod_CFLAGS = $(COMMON_CFLAGS)
lspci_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For datetime.mod
datetime_mod_SOURCES = lib/i386/datetime.c
datetime_mod_CFLAGS = $(COMMON_CFLAGS)
datetime_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For date.mod
date_mod_SOURCES = commands/date.c
date_mod_CFLAGS = $(COMMON_CFLAGS)
date_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For datehook.mod
datehook_mod_SOURCES = hook/datehook.c
datehook_mod_CFLAGS = $(COMMON_CFLAGS)
datehook_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For lsmmap.mod
lsmmap_mod_SOURCES = commands/lsmmap.c
lsmmap_mod_CFLAGS = $(COMMON_CFLAGS)
lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS)
include $(srcdir)/conf/i386.mk
include $(srcdir)/conf/common.mk include $(srcdir)/conf/common.mk

File diff suppressed because it is too large Load Diff

View File

@ -1,165 +0,0 @@
# -*- makefile -*-
COMMON_ASFLAGS = -m32 -nostdinc -fno-builtin
COMMON_CFLAGS = -ffreestanding -mrtd -mregparm=3
COMMON_LDFLAGS = -nostdlib -static -lgcc
# Images.
pkglib_PROGRAMS = kernel.elf
# For kernel.elf.
kernel_elf_SOURCES = kern/i386/linuxbios/startup.S kern/i386/linuxbios/init.c \
kern/i386/linuxbios/table.c \
kern/main.c kern/device.c \
kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \
kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c \
kern/i386/dl.c kern/parser.c kern/partition.c \
kern/env.c \
term/i386/pc/console.c \
term/i386/pc/at_keyboard.c term/i386/pc/vga_text.c \
symlist.c
kernel_elf_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \
env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \
partition.h pc_partition.h rescue.h symbol.h term.h time.h types.h \
machine/boot.h machine/console.h machine/init.h \
machine/memory.h machine/loader.h
kernel_elf_CFLAGS = $(COMMON_CFLAGS)
kernel_elf_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-S,-Ttext,0x8200,-Bstatic
MOSTLYCLEANFILES += symlist.c kernel_syms.lst
DEFSYMFILES += kernel_syms.lst
symlist.c: $(addprefix include/grub/,$(kernel_elf_HEADERS)) config.h gensymlist.sh
/bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1)
kernel_syms.lst: $(addprefix include/grub/,$(kernel_elf_HEADERS)) config.h genkernsyms.sh
/bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1)
# Utilities.
bin_UTILITIES = grub-mkimage
sbin_UTILITIES = grub-mkdevicemap grub-probe
ifeq ($(enable_grub_emu), yes)
sbin_UTILITIES += grub-emu
endif
# For grub-mkimage.
grub_mkimage_SOURCES = util/elf/grub-mkimage.c util/misc.c \
util/resolve.c
grub_mkimage_LDFLAGS = $(LIBLZO)
# For grub-mkdevicemap.
grub_mkdevicemap_SOURCES = util/grub-mkdevicemap.c util/misc.c \
util/i386/get_disk_name.c
# For grub-probe.
util/grub-probe.c_DEPENDENCIES = grub_probe_init.h
grub_probe_SOURCES = util/grub-probe.c \
util/biosdisk.c util/misc.c util/getroot.c \
kern/device.c kern/disk.c kern/err.c kern/misc.c \
kern/parser.c kern/partition.c kern/file.c \
partmap/pc.c partmap/apple.c partmap/gpt.c \
\
fs/affs.c fs/cpio.c fs/ext2.c fs/fat.c fs/hfs.c \
fs/hfsplus.c fs/iso9660.c fs/jfs.c fs/minix.c \
fs/ntfs.c fs/ntfscomp.c fs/reiserfs.c fs/sfs.c \
fs/ufs.c fs/xfs.c \
\
kern/fs.c kern/env.c fs/fshelp.c \
disk/lvm.c disk/raid.c grub_probe_init.c
# For grub-emu.
util/grub-emu.c_DEPENDENCIES = grub_emu_init.h
normal/execute.c_DEPENDENCIES = grub_script.tab.h
grub-emu_DEPENDENCIES = grub_script.tab.c
grub_emu_SOURCES = commands/boot.c commands/cat.c commands/cmp.c \
commands/configfile.c commands/echo.c commands/help.c \
commands/terminal.c commands/ls.c commands/test.c \
commands/search.c commands/blocklist.c commands/hexdump.c \
commands/i386/pc/halt.c commands/i386/pc/reboot.c \
commands/i386/cpuid.c \
disk/host.c disk/loopback.c disk/raid.c disk/lvm.c \
\
fs/affs.c fs/cpio.c fs/ext2.c fs/fat.c fs/hfs.c \
fs/hfsplus.c fs/iso9660.c fs/jfs.c fs/minix.c \
fs/ntfs.c fs/ntfscomp.c fs/reiserfs.c fs/sfs.c \
fs/ufs.c fs/xfs.c \
\
fs/fshelp.c \
io/gzio.c \
kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c \
kern/err.c \
normal/execute.c kern/file.c kern/fs.c normal/lexer.c \
kern/loader.c kern/main.c kern/misc.c kern/parser.c \
grub_script.tab.c kern/partition.c kern/rescue.c kern/term.c \
normal/arg.c normal/cmdline.c normal/command.c normal/function.c\
normal/completion.c normal/main.c \
normal/menu.c normal/menu_entry.c normal/misc.c normal/script.c \
normal/color.c \
partmap/amiga.c partmap/apple.c partmap/pc.c partmap/sun.c \
partmap/acorn.c partmap/gpt.c \
util/console.c util/hostfs.c util/grub-emu.c util/misc.c \
util/biosdisk.c util/getroot.c \
util/i386/pc/misc.c grub_emu_init.c
grub_emu_LDFLAGS = $(LIBCURSES)
# Modules.
pkglib_MODULES = _linux.mod linux.mod normal.mod \
_multiboot.mod multiboot.mod play.mod \
cpuid.mod serial.mod ata.mod
# For _linux.mod.
_linux_mod_SOURCES = loader/i386/pc/linux.c
_linux_mod_CFLAGS = $(COMMON_CFLAGS)
_linux_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For linux.mod.
linux_mod_SOURCES = loader/i386/pc/linux_normal.c
linux_mod_CFLAGS = $(COMMON_CFLAGS)
linux_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For normal.mod.
normal_mod_DEPENDENCIES = grub_script.tab.c grub_script.tab.h
normal_mod_SOURCES = normal/arg.c normal/cmdline.c normal/command.c \
normal/completion.c normal/execute.c \
normal/function.c normal/lexer.c normal/main.c normal/menu.c \
normal/menu_entry.c normal/misc.c grub_script.tab.c \
normal/script.c normal/i386/setjmp.S normal/color.c
normal_mod_CFLAGS = $(COMMON_CFLAGS)
normal_mod_ASFLAGS = $(COMMON_ASFLAGS)
normal_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For serial.mod.
serial_mod_SOURCES = term/i386/pc/serial.c
serial_mod_CFLAGS = $(COMMON_CFLAGS)
serial_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For _multiboot.mod.
_multiboot_mod_SOURCES = loader/i386/pc/multiboot.c \
loader/i386/pc/multiboot2.c \
loader/multiboot2.c \
loader/multiboot_loader.c
_multiboot_mod_CFLAGS = $(COMMON_CFLAGS)
_multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For multiboot.mod.
multiboot_mod_SOURCES = loader/multiboot_loader_normal.c
multiboot_mod_CFLAGS = $(COMMON_CFLAGS)
multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For play.mod.
play_mod_SOURCES = commands/i386/pc/play.c
play_mod_CFLAGS = $(COMMON_CFLAGS)
play_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For cpuid.mod.
cpuid_mod_SOURCES = commands/i386/cpuid.c
cpuid_mod_CFLAGS = $(COMMON_CFLAGS)
cpuid_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For ata.mod.
ata_mod_SOURCES = disk/ata.c
ata_mod_CFLAGS = $(COMMON_CFLAGS)
ata_mod_LDFLAGS = $(COMMON_LDFLAGS)
include $(srcdir)/conf/common.mk

View File

@ -0,0 +1,53 @@
/* Linker script to create grub .img files on Cygwin. */
SECTIONS
{
.text :
{
start = . ;
*(.text)
etext = . ;
}
.data :
{
__data_start__ = . ;
*(.data)
__data_end__ = . ;
}
.rdata :
{
__rdata_start__ = . ;
*(.rdata)
__rdata_end__ = . ;
}
.pdata :
{
*(.pdata)
edata = . ;
}
.bss :
{
__bss_start__ = . ;
*(.bss)
__common_start__ = . ;
*(COMMON)
__bss_end__ = . ;
}
.edata :
{
*(.edata)
end = . ;
}
.stab :
{
*(.stab)
}
.stabstr :
{
*(.stabstr)
}
}
ASSERT("__rdata_end__"=="edata", ".pdata not empty")
ASSERT("__bss_end__" =="end" , ".edata not empty")

File diff suppressed because it is too large Load Diff

View File

@ -1,50 +1,74 @@
# -*- makefile -*- # -*- makefile -*-
GRUB_MEMORY_MACHINE_LINK_ADDR = 0x8200 GRUB_KERNEL_MACHINE_LINK_ADDR = 0x8200
COMMON_ASFLAGS = -nostdinc -fno-builtin -m32 COMMON_ASFLAGS = -nostdinc -fno-builtin -m32
COMMON_CFLAGS = -fno-builtin -mrtd -mregparm=3 -m32 COMMON_CFLAGS = -fno-builtin -mrtd -mregparm=3 -m32
COMMON_LDFLAGS = -m32 -nostdlib COMMON_LDFLAGS = -m32 -nostdlib
# Used by various components. These rules need to precede them.
script/lexer.c_DEPENDENCIES = grub_script.tab.h
# Images. # Images.
pkglib_IMAGES = boot.img diskboot.img kernel.img pxeboot.img lnxboot.img pkglib_IMAGES = boot.img cdboot.img diskboot.img kernel.img lnxboot.img \
pxeboot.img
# For boot.img. # For boot.img.
boot_img_SOURCES = boot/i386/pc/boot.S boot_img_SOURCES = boot/i386/pc/boot.S
boot_img_ASFLAGS = $(COMMON_ASFLAGS) boot_img_ASFLAGS = $(COMMON_ASFLAGS)
boot_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-Ttext,7C00 boot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)0x7C00
boot_img_FORMAT = binary
# For pxeboot.img # For pxeboot.img
pxeboot_img_SOURCES = boot/i386/pc/pxeboot.S pxeboot_img_SOURCES = boot/i386/pc/pxeboot.S
pxeboot_img_ASFLAGS = $(COMMON_ASFLAGS) pxeboot_img_ASFLAGS = $(COMMON_ASFLAGS)
pxeboot_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-Ttext,7C00 pxeboot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)0x7C00
pxeboot_img_FORMAT = binary
# For diskboot.img. # For diskboot.img.
diskboot_img_SOURCES = boot/i386/pc/diskboot.S diskboot_img_SOURCES = boot/i386/pc/diskboot.S
diskboot_img_ASFLAGS = $(COMMON_ASFLAGS) diskboot_img_ASFLAGS = $(COMMON_ASFLAGS)
diskboot_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-Ttext,8000 diskboot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)0x8000
diskboot_img_FORMAT = binary
# For lnxboot.img. # For lnxboot.img.
lnxboot_img_SOURCES = boot/i386/pc/lnxboot.S lnxboot_img_SOURCES = boot/i386/pc/lnxboot.S
lnxboot_img_ASFLAGS = $(COMMON_ASFLAGS) lnxboot_img_ASFLAGS = $(COMMON_ASFLAGS)
lnxboot_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-Ttext,6000 lnxboot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)0x6000
lnxboot_img_FORMAT = binary
# For cdboot.img.
cdboot_img_SOURCES = boot/i386/pc/cdboot.S
cdboot_img_ASFLAGS = $(COMMON_ASFLAGS)
cdboot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)0x7C00
cdboot_img_FORMAT = binary
# For kernel.img. # For kernel.img.
kernel_img_SOURCES = kern/i386/pc/startup.S kern/main.c kern/device.c \ kernel_img_SOURCES = kern/i386/pc/startup.S \
kern/i386/misc.S \
kern/main.c kern/device.c \
kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \ kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \
kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c \ kern/misc.c kern/mm.c kern/term.c \
kern/i386/dl.c kern/i386/pc/init.c kern/parser.c kern/partition.c \ kern/rescue_parser.c kern/rescue_reader.c \
kern/time.c kern/list.c kern/handler.c kern/command.c kern/corecmd.c \
kern/$(target_cpu)/dl.c kern/i386/pc/init.c kern/i386/pc/mmap.c \
kern/parser.c kern/partition.c \
kern/i386/tsc.c kern/i386/pit.c \
kern/generic/rtc_get_time_ms.c \
kern/generic/millisleep.c \
kern/env.c \ kern/env.c \
term/i386/pc/console.c \ term/i386/pc/console.c term/i386/vga_common.c \
symlist.c symlist.c
kernel_img_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ kernel_img_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \
env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \ env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \
partition.h pc_partition.h rescue.h symbol.h term.h time.h types.h \ partition.h msdos_partition.h reader.h symbol.h term.h time.h types.h \
machine/biosdisk.h machine/boot.h machine/console.h machine/init.h \ machine/biosdisk.h machine/boot.h machine/console.h machine/init.h \
machine/memory.h machine/loader.h machine/vga.h machine/vbe.h machine/kernel.h machine/memory.h machine/loader.h machine/vga.h machine/vbe.h \
kernel_img_CFLAGS = $(COMMON_CFLAGS) machine/kernel.h machine/pxe.h i386/pit.h list.h handler.h command.h i18n.h
kernel_img_CFLAGS = $(COMMON_CFLAGS) $(TARGET_IMG_CFLAGS)
kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
kernel_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-Ttext,$(GRUB_MEMORY_MACHINE_LINK_ADDR) $(COMMON_CFLAGS) kernel_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)$(GRUB_KERNEL_MACHINE_LINK_ADDR) $(COMMON_CFLAGS)
kernel_img_FORMAT = binary
MOSTLYCLEANFILES += symlist.c kernel_syms.lst MOSTLYCLEANFILES += symlist.c kernel_syms.lst
DEFSYMFILES += kernel_syms.lst DEFSYMFILES += kernel_syms.lst
@ -57,144 +81,113 @@ kernel_syms.lst: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h genke
# Utilities. # Utilities.
bin_UTILITIES = grub-mkimage bin_UTILITIES = grub-mkimage
sbin_UTILITIES = grub-setup grub-mkdevicemap grub-probe sbin_UTILITIES = grub-setup
ifeq ($(enable_grub_emu), yes)
sbin_UTILITIES += grub-emu
endif
# For grub-mkimage. # For grub-mkimage.
grub_mkimage_SOURCES = util/i386/pc/grub-mkimage.c util/misc.c \ grub_mkimage_SOURCES = gnulib/progname.c util/i386/pc/grub-mkimage.c util/misc.c \
util/resolve.c util/resolve.c lib/LzmaEnc.c lib/LzFind.c
grub_mkimage_CFLAGS = -DGRUB_MEMORY_MACHINE_LINK_ADDR=$(GRUB_MEMORY_MACHINE_LINK_ADDR) grub_mkimage_CFLAGS = -DGRUB_KERNEL_MACHINE_LINK_ADDR=$(GRUB_KERNEL_MACHINE_LINK_ADDR)
grub_mkimage_LDFLAGS = $(LIBLZO) util/i386/pc/grub-mkimage.c_DEPENDENCIES = Makefile
# For grub-setup. # For grub-setup.
util/i386/pc/grub-setup.c_DEPENDENCIES = grub_setup_init.h util/i386/pc/grub-setup.c_DEPENDENCIES = grub_setup_init.h
grub_setup_SOURCES = util/i386/pc/grub-setup.c util/biosdisk.c \ grub_setup_SOURCES = gnulib/progname.c \
util/i386/pc/grub-setup.c util/hostdisk.c \
util/misc.c util/getroot.c kern/device.c kern/disk.c \ util/misc.c util/getroot.c kern/device.c kern/disk.c \
kern/err.c kern/misc.c kern/parser.c kern/partition.c \ kern/err.c kern/misc.c kern/parser.c kern/partition.c \
kern/file.c kern/fs.c kern/env.c fs/fshelp.c \ kern/file.c kern/fs.c kern/env.c fs/fshelp.c \
\ \
fs/affs.c fs/cpio.c fs/ext2.c fs/fat.c fs/hfs.c \ fs/affs.c fs/cpio.c fs/ext2.c fs/fat.c fs/hfs.c \
fs/hfsplus.c fs/iso9660.c fs/jfs.c fs/minix.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/ntfs.c fs/ntfscomp.c fs/reiserfs.c fs/sfs.c \
fs/ufs.c fs/xfs.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 \
\ \
partmap/pc.c partmap/gpt.c \ partmap/msdos.c partmap/gpt.c \
util/raid.c util/lvm.c grub_setup_init.c
# For grub-mkdevicemap.
grub_mkdevicemap_SOURCES = util/grub-mkdevicemap.c util/misc.c \
util/i386/get_disk_name.c
# For grub-probe.
util/grub-probe.c_DEPENDENCIES = grub_probe_init.h
grub_probe_SOURCES = util/grub-probe.c \
util/biosdisk.c util/misc.c util/getroot.c \
kern/device.c kern/disk.c kern/err.c kern/misc.c \
kern/parser.c kern/partition.c kern/file.c \
\ \
fs/affs.c fs/cpio.c fs/ext2.c fs/fat.c fs/hfs.c \ disk/raid.c disk/mdraid_linux.c disk/lvm.c \
fs/hfsplus.c fs/iso9660.c fs/jfs.c fs/minix.c \ util/raid.c util/lvm.c \
fs/ntfs.c fs/ntfscomp.c fs/reiserfs.c fs/sfs.c \ grub_setup_init.c
fs/ufs.c fs/xfs.c \
\
partmap/pc.c partmap/apple.c partmap/gpt.c \
kern/fs.c kern/env.c fs/fshelp.c \
disk/lvm.c disk/raid.c grub_probe_init.c
# For grub-emu. sbin_SCRIPTS += grub-install
util/grub-emu.c_DEPENDENCIES = grub_emu_init.h grub_install_SOURCES = util/grub-install.in
normal/execute.c_DEPENDENCIES = grub_script.tab.h
grub-emu_DEPENDENCIES = grub_script.tab.c
grub_emu_SOURCES = commands/boot.c commands/cat.c commands/cmp.c \
commands/configfile.c commands/echo.c commands/help.c \
commands/terminal.c commands/ls.c commands/test.c \
commands/search.c commands/blocklist.c commands/hexdump.c \
commands/i386/pc/halt.c commands/i386/pc/reboot.c \
commands/i386/cpuid.c \
disk/host.c disk/loopback.c disk/raid.c disk/lvm.c \
fs/fshelp.c \
\
io/gzio.c \
kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c \
kern/err.c \
normal/execute.c kern/file.c kern/fs.c normal/lexer.c \
kern/loader.c kern/main.c kern/misc.c kern/parser.c \
grub_script.tab.c kern/partition.c kern/rescue.c kern/term.c \
normal/arg.c normal/cmdline.c normal/command.c normal/function.c\
normal/completion.c normal/main.c normal/color.c \
normal/menu.c normal/menu_entry.c normal/misc.c normal/script.c \
partmap/amiga.c partmap/apple.c partmap/pc.c partmap/sun.c \
partmap/acorn.c partmap/gpt.c \
\
fs/affs.c fs/cpio.c fs/ext2.c fs/fat.c fs/hfs.c \
fs/hfsplus.c fs/iso9660.c fs/jfs.c fs/minix.c \
fs/ntfs.c fs/ntfscomp.c fs/reiserfs.c fs/sfs.c \
fs/ufs.c fs/xfs.c \
\
util/console.c util/hostfs.c util/grub-emu.c util/misc.c \
util/biosdisk.c util/getroot.c \
util/i386/pc/misc.c grub_emu_init.c
grub_emu_LDFLAGS = $(LIBCURSES) bin_SCRIPTS += grub-mkrescue
grub_mkrescue_SOURCES = util/grub-mkrescue.in
# Scripts. pkglib_MODULES = biosdisk.mod chain.mod \
sbin_SCRIPTS = grub-install reboot.mod halt.mod \
bin_SCRIPTS = grub-mkrescue vbe.mod vbetest.mod vbeinfo.mod play.mod serial.mod \
vga.mod memdisk.mod pci.mod lspci.mod \
aout.mod bsd.mod pxe.mod pxecmd.mod datetime.mod date.mod \
datehook.mod lsmmap.mod ata_pthru.mod hdparm.mod \
usb.mod uhci.mod ohci.mod usbtest.mod usbms.mod usb_keyboard.mod \
efiemu.mod mmap.mod acpi.mod drivemap.mod
# For grub-install. # For boot.mod.
grub_install_SOURCES = util/i386/pc/grub-install.in pkglib_MODULES += boot.mod
boot_mod_SOURCES = commands/boot.c lib/i386/pc/biosnum.c
boot_mod_CFLAGS = $(COMMON_CFLAGS)
boot_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For grub-mkrescue. # For drivemap.mod.
grub_mkrescue_SOURCES = util/i386/pc/grub-mkrescue.in drivemap_mod_SOURCES = commands/i386/pc/drivemap.c \
commands/i386/pc/drivemap_int13h.S
drivemap_mod_ASFLAGS = $(COMMON_ASFLAGS)
drivemap_mod_CFLAGS = $(COMMON_CFLAGS)
drivemap_mod_LDFLAGS = $(COMMON_LDFLAGS)
# Modules. # For efiemu.mod.
pkglib_MODULES = biosdisk.mod _chain.mod _linux.mod linux.mod normal.mod \ efiemu_mod_SOURCES = efiemu/main.c efiemu/i386/loadcore32.c \
_multiboot.mod chain.mod multiboot.mod reboot.mod halt.mod \ efiemu/i386/loadcore64.c efiemu/i386/pc/cfgtables.c \
vbe.mod vbetest.mod vbeinfo.mod video.mod gfxterm.mod \ efiemu/mm.c efiemu/loadcore_common.c efiemu/symbols.c \
videotest.mod play.mod bitmap.mod tga.mod cpuid.mod serial.mod \ efiemu/loadcore32.c efiemu/loadcore64.c \
ata.mod vga.mod memdisk.mod jpeg.mod efiemu/prepare32.c efiemu/prepare64.c efiemu/pnvram.c \
efiemu/i386/coredetect.c
efiemu_mod_CFLAGS = $(COMMON_CFLAGS)
efiemu_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For acpi.mod.
acpi_mod_SOURCES = commands/acpi.c commands/i386/pc/acpi.c
acpi_mod_CFLAGS = $(COMMON_CFLAGS)
acpi_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For mmap.mod.
mmap_mod_SOURCES = mmap/mmap.c mmap/i386/uppermem.c mmap/i386/mmap.c \
mmap/i386/pc/mmap.c mmap/i386/pc/mmap_helper.S
mmap_mod_CFLAGS = $(COMMON_CFLAGS)
mmap_mod_LDFLAGS = $(COMMON_LDFLAGS)
mmap_mod_ASFLAGS = $(COMMON_ASFLAGS)
# For biosdisk.mod. # For biosdisk.mod.
biosdisk_mod_SOURCES = disk/i386/pc/biosdisk.c biosdisk_mod_SOURCES = disk/i386/pc/biosdisk.c
biosdisk_mod_CFLAGS = $(COMMON_CFLAGS) biosdisk_mod_CFLAGS = $(COMMON_CFLAGS)
biosdisk_mod_LDFLAGS = $(COMMON_LDFLAGS) biosdisk_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For _chain.mod.
_chain_mod_SOURCES = loader/i386/pc/chainloader.c
_chain_mod_CFLAGS = $(COMMON_CFLAGS)
_chain_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For chain.mod. # For chain.mod.
chain_mod_SOURCES = loader/i386/pc/chainloader_normal.c chain_mod_SOURCES = loader/i386/pc/chainloader.c
chain_mod_CFLAGS = $(COMMON_CFLAGS) chain_mod_CFLAGS = $(COMMON_CFLAGS)
chain_mod_LDFLAGS = $(COMMON_LDFLAGS) chain_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For _linux.mod. pkglib_MODULES += linux16.mod
_linux_mod_SOURCES = loader/i386/pc/linux.c linux16_mod_SOURCES = loader/i386/pc/linux.c
_linux_mod_CFLAGS = $(COMMON_CFLAGS) linux16_mod_CFLAGS = $(COMMON_CFLAGS)
_linux_mod_LDFLAGS = $(COMMON_LDFLAGS) linux16_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For linux.mod. pkglib_MODULES += linux.mod
linux_mod_SOURCES = loader/i386/pc/linux_normal.c linux_mod_SOURCES = loader/i386/linux.c
linux_mod_CFLAGS = $(COMMON_CFLAGS) linux_mod_CFLAGS = $(COMMON_CFLAGS)
linux_mod_LDFLAGS = $(COMMON_LDFLAGS) linux_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For normal.mod. pkglib_MODULES += xnu.mod
normal_mod_DEPENDENCIES = grub_script.tab.c grub_script.tab.h xnu_mod_SOURCES = loader/xnu_resume.c loader/i386/xnu.c loader/i386/pc/xnu.c \
normal_mod_SOURCES = normal/arg.c normal/cmdline.c normal/command.c \ loader/macho32.c loader/macho64.c loader/macho.c loader/xnu.c
normal/completion.c normal/execute.c \ xnu_mod_CFLAGS = $(COMMON_CFLAGS)
normal/function.c normal/lexer.c normal/main.c normal/menu.c \ xnu_mod_LDFLAGS = $(COMMON_LDFLAGS)
normal/color.c \ xnu_mod_ASFLAGS = $(COMMON_ASFLAGS)
normal/menu_entry.c normal/misc.c grub_script.tab.c \
normal/script.c normal/i386/setjmp.S
normal_mod_CFLAGS = $(COMMON_CFLAGS)
normal_mod_ASFLAGS = $(COMMON_ASFLAGS)
normal_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For reboot.mod. # For reboot.mod.
reboot_mod_SOURCES = commands/i386/pc/reboot.c reboot_mod_SOURCES = commands/reboot.c
reboot_mod_CFLAGS = $(COMMON_CFLAGS) reboot_mod_CFLAGS = $(COMMON_CFLAGS)
reboot_mod_LDFLAGS = $(COMMON_LDFLAGS) reboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
@ -208,22 +201,8 @@ serial_mod_SOURCES = term/i386/pc/serial.c
serial_mod_CFLAGS = $(COMMON_CFLAGS) serial_mod_CFLAGS = $(COMMON_CFLAGS)
serial_mod_LDFLAGS = $(COMMON_LDFLAGS) serial_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For _multiboot.mod.
_multiboot_mod_SOURCES = loader/i386/pc/multiboot.c \
loader/i386/pc/multiboot2.c \
loader/multiboot2.c \
loader/multiboot_loader.c
_multiboot_mod_CFLAGS = $(COMMON_CFLAGS)
_multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For multiboot.mod.
multiboot_mod_SOURCES = loader/multiboot_loader_normal.c
multiboot_mod_CFLAGS = $(COMMON_CFLAGS)
multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For vbe.mod. # For vbe.mod.
vbe_mod_SOURCES = video/i386/pc/vbe.c video/i386/pc/vbeblit.c \ vbe_mod_SOURCES = video/i386/pc/vbe.c
video/i386/pc/vbefill.c video/i386/pc/vbeutil.c
vbe_mod_CFLAGS = $(COMMON_CFLAGS) vbe_mod_CFLAGS = $(COMMON_CFLAGS)
vbe_mod_LDFLAGS = $(COMMON_LDFLAGS) vbe_mod_LDFLAGS = $(COMMON_LDFLAGS)
@ -242,41 +221,6 @@ play_mod_SOURCES = commands/i386/pc/play.c
play_mod_CFLAGS = $(COMMON_CFLAGS) play_mod_CFLAGS = $(COMMON_CFLAGS)
play_mod_LDFLAGS = $(COMMON_LDFLAGS) play_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For video.mod.
video_mod_SOURCES = video/video.c
video_mod_CFLAGS = $(COMMON_CFLAGS)
video_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For gfxterm.mod.
gfxterm_mod_SOURCES = term/gfxterm.c
gfxterm_mod_CFLAGS = $(COMMON_CFLAGS)
gfxterm_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For videotest.mod.
videotest_mod_SOURCES = commands/videotest.c
videotest_mod_CFLAGS = $(COMMON_CFLAGS)
videotest_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For bitmap.mod
bitmap_mod_SOURCES = video/bitmap.c
bitmap_mod_CFLAGS = $(COMMON_CFLAGS)
bitmap_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For tga.mod
tga_mod_SOURCES = video/readers/tga.c
tga_mod_CFLAGS = $(COMMON_CFLAGS)
tga_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For cpuid.mod.
cpuid_mod_SOURCES = commands/i386/cpuid.c
cpuid_mod_CFLAGS = $(COMMON_CFLAGS)
cpuid_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For ata.mod.
ata_mod_SOURCES = disk/ata.c
ata_mod_CFLAGS = $(COMMON_CFLAGS)
ata_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For vga.mod. # For vga.mod.
vga_mod_SOURCES = term/i386/pc/vga.c vga_mod_SOURCES = term/i386/pc/vga.c
vga_mod_CFLAGS = $(COMMON_CFLAGS) vga_mod_CFLAGS = $(COMMON_CFLAGS)
@ -287,9 +231,142 @@ memdisk_mod_SOURCES = disk/memdisk.c
memdisk_mod_CFLAGS = $(COMMON_CFLAGS) memdisk_mod_CFLAGS = $(COMMON_CFLAGS)
memdisk_mod_LDFLAGS = $(COMMON_LDFLAGS) memdisk_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For jpeg.mod. # For pci.mod
jpeg_mod_SOURCES = video/readers/jpeg.c pci_mod_SOURCES = bus/pci.c
jpeg_mod_CFLAGS = $(COMMON_CFLAGS) pci_mod_CFLAGS = $(COMMON_CFLAGS)
jpeg_mod_LDFLAGS = $(COMMON_LDFLAGS) pci_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For lspci.mod
lspci_mod_SOURCES = commands/lspci.c
lspci_mod_CFLAGS = $(COMMON_CFLAGS)
lspci_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For aout.mod
aout_mod_SOURCES = loader/aout.c
aout_mod_CFLAGS = $(COMMON_CFLAGS)
aout_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For bsd.mod
bsd_mod_SOURCES = loader/i386/bsd.c loader/i386/bsd32.c loader/i386/bsd64.c loader/i386/bsd_helper.S loader/i386/bsd_trampoline.S
bsd_mod_CFLAGS = $(COMMON_CFLAGS)
bsd_mod_LDFLAGS = $(COMMON_LDFLAGS)
bsd_mod_ASFLAGS = $(COMMON_ASFLAGS)
# For usb.mod
usb_mod_SOURCES = bus/usb/usb.c bus/usb/usbtrans.c bus/usb/usbhub.c
usb_mod_CFLAGS = $(COMMON_CFLAGS)
usb_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For usbtest.mod
usbtest_mod_SOURCES = commands/usbtest.c
usbtest_mod_CFLAGS = $(COMMON_CFLAGS)
usbtest_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For uhci.mod
uhci_mod_SOURCES = bus/usb/uhci.c
uhci_mod_CFLAGS = $(COMMON_CFLAGS)
uhci_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For ohci.mod
ohci_mod_SOURCES = bus/usb/ohci.c
ohci_mod_CFLAGS = $(COMMON_CFLAGS)
ohci_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For usbms.mod
usbms_mod_SOURCES = disk/usbms.c
usbms_mod_CFLAGS = $(COMMON_CFLAGS)
usbms_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For usb_keyboard.mod
usb_keyboard_mod_SOURCES = term/usb_keyboard.c
usb_keyboard_mod_CFLAGS = $(COMMON_CFLAGS)
usb_keyboard_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For pxe.mod
pxe_mod_SOURCES = fs/i386/pc/pxe.c
pxe_mod_CFLAGS = $(COMMON_CFLAGS)
pxe_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For pxecmd.mod
pxecmd_mod_SOURCES = commands/i386/pc/pxecmd.c
pxecmd_mod_CFLAGS = $(COMMON_CFLAGS)
pxecmd_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For datetime.mod
datetime_mod_SOURCES = lib/i386/datetime.c
datetime_mod_CFLAGS = $(COMMON_CFLAGS)
datetime_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For date.mod
date_mod_SOURCES = commands/date.c
date_mod_CFLAGS = $(COMMON_CFLAGS)
date_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For datehook.mod
datehook_mod_SOURCES = hook/datehook.c
datehook_mod_CFLAGS = $(COMMON_CFLAGS)
datehook_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For lsmmap.mod
lsmmap_mod_SOURCES = commands/lsmmap.c
lsmmap_mod_CFLAGS = $(COMMON_CFLAGS)
lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For ata_pthru.mod.
ata_pthru_mod_SOURCES = disk/ata_pthru.c
ata_pthru_mod_CFLAGS = $(COMMON_CFLAGS)
ata_pthru_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For hdparm.mod.
hdparm_mod_SOURCES = commands/hdparm.c lib/hexdump.c
hdparm_mod_CFLAGS = $(COMMON_CFLAGS)
hdparm_mod_LDFLAGS = $(COMMON_LDFLAGS)
ifeq ($(enable_efiemu), yes)
efiemu32.o: efiemu/runtime/efiemu.c $(TARGET_OBJ2ELF)
-rm -f $@
ifeq ($(TARGET_APPLE_CC), 1)
-rm -f $@.bin
$(TARGET_CC) -c -m32 -DELF32 -DAPPLE_CC -o $@.bin -Wall -Werror $< -nostdlib -O2 -I$(srcdir)/efiemu/runtime -I$(srcdir)/include -Iinclude
$(OBJCONV) -felf32 -nu -nd $@.bin $@
-rm -f $@.bin
else
$(TARGET_CC) -c -m32 -DELF32 -o $@ -Wall -Werror $< -nostdlib -O2 -I$(srcdir)/efiemu/runtime -I$(srcdir)/include -Iinclude
if test ! -z $(TARGET_OBJ2ELF); then ./$(TARGET_OBJ2ELF) $@ || (rm -f $@; exit 1); fi
endif
efiemu64_c.o: efiemu/runtime/efiemu.c
ifeq ($(TARGET_APPLE_CC), 1)
$(TARGET_CC) -c -m64 -DAPPLE_CC=1 -DELF64 -o $@ -Wall -Werror $< -nostdlib -mno-red-zone -O2 -I$(srcdir)/efiemu/runtime -I$(srcdir)/include -Iinclude
else
$(TARGET_CC) -c -m64 -DELF64 -o $@ -Wall -Werror $< -nostdlib -mcmodel=large -mno-red-zone -O2 -I$(srcdir)/efiemu/runtime -I$(srcdir)/include -Iinclude
endif
efiemu64_s.o: efiemu/runtime/efiemu.S
-rm -f $@
ifeq ($(TARGET_APPLE_CC), 1)
$(TARGET_CC) -c -m64 -DAPPLE_CC=1 -DELF64 -o $@ -Wall -Werror $< -nostdlib -mno-red-zone -O2 -I$(srcdir)/efiemu/runtime -I$(srcdir)/include -Iinclude
else
$(TARGET_CC) -c -m64 -DELF64 -o $@ -Wall -Werror $< -nostdlib -mcmodel=large -mno-red-zone -O2 -I$(srcdir)/efiemu/runtime -I$(srcdir)/include -Iinclude
endif
efiemu64.o: efiemu64_c.o efiemu64_s.o $(TARGET_OBJ2ELF)
-rm -f $@
ifeq ($(TARGET_APPLE_CC), 1)
-rm -f $@.bin
$(TARGET_CC) -m64 -o $@.bin -Wl,-r $^ -nostdlib
$(OBJCONV) -felf64 -nu -nd $@.bin $@
-rm -f $@.bin
else
$(TARGET_CC) -m64 -o $@ -Wl,-r $^ -nostdlib
if test ! -z $(TARGET_OBJ2ELF); then ./$(TARGET_OBJ2ELF) $@ || (rm -f $@; exit 1); fi
endif
CLEANFILES += efiemu32.o efiemu64.o efiemu64_c.o efiemu64_s.o
pkglib_DATA += efiemu32.o efiemu64.o
endif
include $(srcdir)/conf/i386.mk
include $(srcdir)/conf/common.mk include $(srcdir)/conf/common.mk

2
conf/i386-qemu.rmk Normal file
View File

@ -0,0 +1,2 @@
# -*- makefile -*-
include $(srcdir)/conf/i386-coreboot.mk

43
conf/i386.rmk Normal file
View File

@ -0,0 +1,43 @@
# -*- makefile -*-
pkglib_MODULES += cpuid.mod
cpuid_mod_SOURCES = commands/i386/cpuid.c
cpuid_mod_CFLAGS = $(COMMON_CFLAGS)
cpuid_mod_LDFLAGS = $(COMMON_LDFLAGS)
pkglib_MODULES += at_keyboard.mod
at_keyboard_mod_SOURCES = term/i386/pc/at_keyboard.c
at_keyboard_mod_CFLAGS = $(COMMON_CFLAGS)
at_keyboard_mod_LDFLAGS = $(COMMON_LDFLAGS)
pkglib_MODULES += vga_text.mod
vga_text_mod_SOURCES = term/i386/pc/vga_text.c term/i386/vga_common.c
vga_text_mod_CFLAGS = $(COMMON_CFLAGS)
vga_text_mod_LDFLAGS = $(COMMON_LDFLAGS)
pkglib_MODULES += relocator.mod
relocator_mod_SOURCES = lib/i386/relocator.c lib/i386/relocator_asm.S lib/i386/relocator_backward.S
relocator_mod_CFLAGS = $(COMMON_CFLAGS)
relocator_mod_ASFLAGS = $(COMMON_ASFLAGS)
relocator_mod_LDFLAGS = $(COMMON_LDFLAGS)
pkglib_MODULES += ata.mod
ata_mod_SOURCES = disk/ata.c
ata_mod_CFLAGS = $(COMMON_CFLAGS)
ata_mod_LDFLAGS = $(COMMON_LDFLAGS)
pkglib_MODULES += multiboot.mod
multiboot_mod_SOURCES = loader/i386/multiboot.c \
loader/i386/multiboot_mbi.c \
loader/multiboot_loader.c
multiboot_mod_CFLAGS = $(COMMON_CFLAGS)
multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
multiboot_mod_ASFLAGS = $(COMMON_ASFLAGS)
pkglib_MODULES += multiboot2.mod
multiboot2_mod_SOURCES = loader/i386/multiboot.c \
loader/i386/multiboot_mbi.c \
loader/multiboot_loader.c
multiboot2_mod_CFLAGS = $(COMMON_CFLAGS) -DGRUB_USE_MULTIBOOT2
multiboot2_mod_LDFLAGS = $(COMMON_LDFLAGS)
multiboot2_mod_ASFLAGS = $(COMMON_ASFLAGS)

File diff suppressed because it is too large Load Diff

View File

@ -2,171 +2,102 @@
# -*- makefile -*- # -*- makefile -*-
COMMON_ASFLAGS = -nostdinc -D__ASSEMBLY__ COMMON_ASFLAGS = -nostdinc -D__ASSEMBLY__
COMMON_CFLAGS = -ffreestanding -msoft-float COMMON_CFLAGS = -ffreestanding
COMMON_LDFLAGS += -nostdlib COMMON_LDFLAGS += -nostdlib
# Used by various components. These rules need to precede them.
script/lexer.c_DEPENDENCIES = grub_script.tab.h
# Images. # Images.
MOSTLYCLEANFILES += kernel_elf_symlist.c kernel_syms.lst MOSTLYCLEANFILES += symlist.c kernel_syms.lst
DEFSYMFILES += kernel_syms.lst DEFSYMFILES += kernel_syms.lst
kernel_elf_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ kernel_img_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \
env.h err.h file.h fs.h kernel.h misc.h mm.h net.h parser.h rescue.h \ env.h err.h file.h fs.h kernel.h misc.h mm.h net.h parser.h reader.h \
symbol.h term.h time.h types.h powerpc/libgcc.h loader.h partition.h \ symbol.h term.h time.h types.h powerpc/libgcc.h loader.h partition.h \
pc_partition.h ieee1275/ieee1275.h machine/kernel.h msdos_partition.h ieee1275/ieee1275.h machine/kernel.h handler.h list.h \
command.h i18n.h
kernel_elf_symlist.c: $(addprefix include/grub/,$(kernel_elf_HEADERS)) config.h gensymlist.sh symlist.c: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h gensymlist.sh
/bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) /bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1)
kernel_syms.lst: $(addprefix include/grub/,$(kernel_elf_HEADERS)) config.h genkernsyms.sh kernel_syms.lst: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h genkernsyms.sh
/bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) /bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1)
# Programs # Programs
pkglib_PROGRAMS = kernel.elf pkglib_PROGRAMS = kernel.img
# Utilities. kernel_img_SOURCES = kern/powerpc/ieee1275/startup.S kern/ieee1275/cmain.c \
bin_UTILITIES = grub-mkimage
sbin_UTILITIES = grub-mkdevicemap grub-probe
ifeq ($(enable_grub_emu), yes)
sbin_UTILITIES += grub-emu
endif
# For grub-mkimage.
grub_mkimage_SOURCES = util/elf/grub-mkimage.c util/misc.c \
util/resolve.c
# For grub-mkdevicemap.
grub_mkdevicemap_SOURCES = util/grub-mkdevicemap.c util/misc.c \
util/ieee1275/get_disk_name.c
# For grub-probe.
util/grub-probe.c_DEPENDENCIES = grub_probe_init.h
grub_probe_SOURCES = util/grub-probe.c \
util/biosdisk.c util/misc.c util/getroot.c \
kern/device.c kern/disk.c kern/err.c kern/misc.c \
kern/parser.c kern/partition.c kern/file.c \
\
fs/affs.c fs/cpio.c fs/ext2.c fs/fat.c fs/hfs.c \
fs/hfsplus.c fs/iso9660.c fs/jfs.c fs/minix.c \
fs/ntfs.c fs/ntfscomp.c fs/reiserfs.c fs/sfs.c \
fs/ufs.c fs/xfs.c \
\
partmap/pc.c partmap/apple.c partmap/gpt.c \
kern/fs.c kern/env.c fs/fshelp.c \
disk/lvm.c disk/raid.c grub_probe_init.c
# For grub-emu
util/grub-emu.c_DEPENDENCIES = grub_emu_init.h
normal/execute.c_DEPENDENCIES = grub_script.tab.h
grub-emu_DEPENDENCIES = grub_script.tab.c
grub_emu_SOURCES = commands/boot.c commands/cat.c commands/cmp.c \
commands/configfile.c commands/help.c \
commands/search.c commands/terminal.c commands/test.c \
commands/ls.c commands/blocklist.c commands/hexdump.c \
commands/ieee1275/halt.c commands/ieee1275/reboot.c \
disk/loopback.c \
\
fs/affs.c fs/cpio.c fs/ext2.c fs/fat.c fs/hfs.c \
fs/hfsplus.c fs/iso9660.c fs/jfs.c fs/minix.c \
fs/ntfs.c fs/ntfscomp.c fs/reiserfs.c fs/sfs.c \
fs/ufs.c fs/xfs.c \
\
io/gzio.c \
kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c \
kern/err.c kern/file.c kern/fs.c kern/loader.c kern/main.c \
kern/misc.c kern/parser.c kern/partition.c kern/rescue.c \
kern/term.c \
normal/arg.c normal/cmdline.c normal/command.c \
normal/completion.c normal/execute.c \
normal/function.c normal/lexer.c normal/main.c normal/menu.c \
normal/menu_entry.c normal/misc.c normal/script.c \
normal/color.c \
partmap/amiga.c partmap/apple.c partmap/pc.c partmap/sun.c \
partmap/acorn.c \
util/console.c util/hostfs.c util/grub-emu.c util/misc.c \
util/biosdisk.c util/getroot.c \
util/powerpc/ieee1275/misc.c grub_script.tab.c grub_emu_init.c
grub_emu_LDFLAGS = $(LIBCURSES)
kernel_elf_SOURCES = kern/powerpc/ieee1275/crt0.S kern/powerpc/ieee1275/cmain.c \
kern/ieee1275/ieee1275.c kern/main.c kern/device.c \ kern/ieee1275/ieee1275.c kern/main.c kern/device.c \
kern/disk.c kern/dl.c kern/err.c kern/file.c kern/fs.c \ kern/disk.c kern/dl.c kern/err.c kern/file.c kern/fs.c \
kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c \ kern/misc.c kern/mm.c kern/term.c \
kern/powerpc/ieee1275/init.c term/ieee1275/ofconsole.c \ kern/rescue_parser.c kern/rescue_reader.c \
kern/powerpc/ieee1275/openfw.c disk/ieee1275/ofdisk.c \ kern/list.c kern/handler.c kern/command.c kern/corecmd.c \
kern/parser.c kern/partition.c kern/env.c kern/powerpc/dl.c \ kern/ieee1275/init.c \
kernel_elf_symlist.c kern/powerpc/cache.S kern/ieee1275/mmap.c \
kernel_elf_HEADERS = grub/powerpc/ieee1275/ieee1275.h term/ieee1275/ofconsole.c \
kernel_elf_CFLAGS = $(COMMON_CFLAGS) kern/ieee1275/openfw.c disk/ieee1275/ofdisk.c \
kernel_elf_ASFLAGS = $(COMMON_ASFLAGS) kern/parser.c kern/partition.c kern/env.c kern/$(target_cpu)/dl.c \
kernel_elf_LDFLAGS = $(COMMON_LDFLAGS) -static-libgcc -lgcc \ kern/generic/millisleep.c kern/time.c \
-Wl,-N,-S,-Ttext,0x10000,-Bstatic symlist.c kern/$(target_cpu)/cache.S
kernel_img_CFLAGS = $(COMMON_CFLAGS)
kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
kernel_img_LDFLAGS = $(COMMON_LDFLAGS) -static-libgcc -lgcc \
-Wl,-N,-S,-Ttext,0x200000,-Bstatic
# Scripts. # Scripts.
sbin_SCRIPTS = grub-install sbin_SCRIPTS = grub-install
bin_SCRIPTS = grub-mkrescue
# For grub-install. # For grub-install.
grub_install_SOURCES = util/powerpc/ieee1275/grub-install.in grub_install_SOURCES = util/ieee1275/grub-install.in
# For grub-mkrescue.
grub_mkrescue_SOURCES = util/powerpc/ieee1275/grub-mkrescue.in
# Modules. # Modules.
pkglib_MODULES = halt.mod \ pkglib_MODULES = halt.mod \
_linux.mod \
linux.mod \ linux.mod \
normal.mod \
reboot.mod \ reboot.mod \
suspend.mod \ suspend.mod \
_multiboot.mod \ memdisk.mod \
multiboot.mod lsmmap.mod
# For _linux.mod. # For boot.mod.
_linux_mod_SOURCES = loader/powerpc/ieee1275/linux.c pkglib_MODULES += boot.mod
_linux_mod_CFLAGS = $(COMMON_CFLAGS) boot_mod_SOURCES = commands/boot.c lib/i386/pc/biosnum.c
_linux_mod_LDFLAGS = $(COMMON_LDFLAGS) boot_mod_CFLAGS = $(COMMON_CFLAGS)
boot_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For linux.mod. # For linux.mod.
linux_mod_SOURCES = loader/powerpc/ieee1275/linux_normal.c linux_mod_SOURCES = loader/powerpc/ieee1275/linux.c
linux_mod_CFLAGS = $(COMMON_CFLAGS) linux_mod_CFLAGS = $(COMMON_CFLAGS)
linux_mod_LDFLAGS = $(COMMON_LDFLAGS) linux_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For normal.mod.
normal_mod_DEPENDENCIES = grub_script.tab.c grub_script.tab.h
normal_mod_SOURCES = normal/arg.c normal/cmdline.c normal/command.c \
normal/completion.c normal/execute.c \
normal/function.c normal/lexer.c normal/main.c normal/menu.c \
normal/menu_entry.c normal/misc.c grub_script.tab.c \
normal/script.c normal/powerpc/setjmp.S normal/color.c
normal_mod_CFLAGS = $(COMMON_CFLAGS)
normal_mod_LDFLAGS = $(COMMON_LDFLAGS)
normal_mod_ASFLAGS = $(COMMON_ASFLAGS)
# For suspend.mod # For suspend.mod
suspend_mod_SOURCES = commands/ieee1275/suspend.c suspend_mod_SOURCES = commands/ieee1275/suspend.c
suspend_mod_CFLAGS = $(COMMON_CFLAGS) suspend_mod_CFLAGS = $(COMMON_CFLAGS)
suspend_mod_LDFLAGS = $(COMMON_LDFLAGS) suspend_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For reboot.mod # For reboot.mod
reboot_mod_SOURCES = commands/ieee1275/reboot.c reboot_mod_SOURCES = commands/reboot.c
reboot_mod_CFLAGS = $(COMMON_CFLAGS) reboot_mod_CFLAGS = $(COMMON_CFLAGS)
reboot_mod_LDFLAGS = $(COMMON_LDFLAGS) reboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For halt.mod # For halt.mod
halt_mod_SOURCES = commands/ieee1275/halt.c halt_mod_SOURCES = commands/halt.c
halt_mod_CFLAGS = $(COMMON_CFLAGS) halt_mod_CFLAGS = $(COMMON_CFLAGS)
halt_mod_LDFLAGS = $(COMMON_LDFLAGS) halt_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For _multiboot.mod # For memdisk.mod.
_multiboot_mod_SOURCES = loader/powerpc/ieee1275/multiboot2.c \ memdisk_mod_SOURCES = disk/memdisk.c
loader/multiboot2.c \ memdisk_mod_CFLAGS = $(COMMON_CFLAGS)
loader/multiboot_loader.c memdisk_mod_LDFLAGS = $(COMMON_LDFLAGS)
_multiboot_mod_CFLAGS = $(COMMON_CFLAGS)
_multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For multiboot.mod
multiboot_mod_SOURCES = loader/multiboot_loader_normal.c
multiboot_mod_CFLAGS = $(COMMON_CFLAGS)
multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For lsmmap.mod
lsmmap_mod_SOURCES = commands/lsmmap.c
lsmmap_mod_CFLAGS = $(COMMON_CFLAGS)
lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS)
include $(srcdir)/conf/common.mk include $(srcdir)/conf/common.mk

File diff suppressed because it is too large Load Diff

View File

@ -1,277 +1,136 @@
# -*- makefile -*- # -*- makefile -*-
COMMON_ASFLAGS = -nostdinc COMMON_ASFLAGS = -nostdinc -m64
COMMON_CFLAGS = -ggdb -ffreestanding -m64 -mno-app-regs COMMON_CFLAGS = -ffreestanding -m64 -mno-app-regs
COMMON_LDFLAGS = -melf64_sparc -nostdlib COMMON_LDFLAGS = -melf64_sparc -nostdlib -mno-relax
# Used by various components. These rules need to precede them.
script/lexer.c_DEPENDENCIES = grub_script.tab.h
# Images. # Images.
pkglib_IMAGES = boot.img diskboot.img kernel.img
MOSTLYCLEANFILES += kernel_elf_symlist.c kernel_syms.lst # For boot.img.
boot_img_SOURCES = boot/sparc64/ieee1275/boot.S
boot_img_ASFLAGS = $(COMMON_ASFLAGS)
boot_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-Ttext,0x4000
boot_img_FORMAT = a.out-sunos-big
# For diskboot.img.
diskboot_img_SOURCES = boot/sparc64/ieee1275/diskboot.S
diskboot_img_ASFLAGS = $(COMMON_ASFLAGS)
diskboot_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-Ttext,0x4200
diskboot_img_FORMAT = binary
MOSTLYCLEANFILES += symlist.c kernel_syms.lst
DEFSYMFILES += kernel_syms.lst DEFSYMFILES += kernel_syms.lst
kernel_elf_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ kernel_img_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \
env.h err.h file.h fs.h kernel.h misc.h mm.h net.h parser.h rescue.h \ env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \
symbol.h term.h time.h types.h sparc64/libgcc.h loader.h partition.h \ partition.h msdos_partition.h reader.h symbol.h term.h time.h types.h \
pc_partition.h ieee1275/ieee1275.h machine/kernel.h list.h handler.h command.h i18n.h \
sparc64/libgcc.h ieee1275/ieee1275.h machine/kernel.h \
sparc64/ieee1275/ieee1275.h
kernel_img_SOURCES = kern/sparc64/ieee1275/crt0.S kern/ieee1275/cmain.c \
kern/ieee1275/ieee1275.c kern/main.c kern/device.c \
kern/disk.c kern/dl.c kern/err.c kern/file.c kern/fs.c \
kern/misc.c kern/mm.c kern/term.c \
kern/rescue_parser.c kern/rescue_reader.c \
kern/list.c kern/handler.c kern/command.c kern/corecmd.c \
kern/sparc64/ieee1275/ieee1275.c \
kern/sparc64/ieee1275/init.c \
kern/ieee1275/mmap.c \
term/ieee1275/ofconsole.c \
kern/ieee1275/openfw.c disk/ieee1275/ofdisk.c \
kern/parser.c kern/partition.c kern/env.c kern/$(target_cpu)/dl.c \
kern/generic/millisleep.c kern/time.c \
symlist.c kern/$(target_cpu)/cache.S
kernel_img_CFLAGS = $(COMMON_CFLAGS)
kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
kernel_img_LDFLAGS = -nostdlib -Wl,-N,-Ttext,0x200000,-Bstatic,-melf64_sparc -static-libgcc -lgcc
kernel_img_FORMAT = binary
kernel_elf_symlist.c: $(addprefix include/grub/,$(kernel_elf_HEADERS)) config.h gensymlist.sh symlist.c: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h gensymlist.sh
/bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) /bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1)
# For the parser. kernel_syms.lst: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h genkernsyms.sh
grub_script.tab.c grub_script.tab.h: normal/parser.y
$(YACC) -d -p grub_script_yy -b grub_script $(srcdir)/normal/parser.y
kernel_syms.lst: $(addprefix include/grub/,$(kernel_elf_HEADERS)) config.h genkernsyms.sh
/bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) /bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1)
# Programs
pkglib_PROGRAMS = kernel.elf
# Utilities. # Utilities.
#bin_UTILITIES = grub-mkimage bin_UTILITIES = grub-mkimage
#ifeq ($(enable_grub_emu), yes) sbin_UTILITIES = grub-setup grub-ofpathname
#bin_UTILITIES += grub-emu
#endif
# For grub-mkimage. # For grub-mkimage.
grub_mkimage_SOURCES = util/sparc64/ieee1275/grub-mkimage.c util/misc.c \ grub_mkimage_SOURCES = util/sparc64/ieee1275/grub-mkimage.c util/misc.c \
util/resolve.c util/resolve.c gnulib/progname.c
# For grub-emu # For grub-setup.
#grub_emu_SOURCES = commands/boot.c commands/cat.c commands/cmp.c \ util/sparc64/ieee1275/grub-setup.c_DEPENDENCIES = grub_setup_init.h
# commands/configfile.c commands/default.c commands/help.c \ grub_setup_SOURCES = util/sparc64/ieee1275/grub-setup.c util/hostdisk.c \
# commands/search.c commands/terminal.c commands/ls.c \ util/misc.c util/getroot.c kern/device.c kern/disk.c \
# commands/timeout.c commands/test.c \ kern/err.c kern/misc.c kern/parser.c kern/partition.c \
# commands/ieee1275/halt.c commands/ieee1275/reboot.c \ kern/file.c kern/fs.c kern/env.c fs/fshelp.c \
# disk/loopback.c \ \
# fs/affs.c fs/ext2.c fs/fat.c fs/fshelp.c fs/hfs.c fs/iso9660.c \ fs/affs.c fs/cpio.c fs/ext2.c fs/fat.c fs/hfs.c \
# fs/jfs.c fs/minix.c fs/sfs.c fs/ufs.c fs/xfs.c \ fs/hfsplus.c fs/iso9660.c fs/udf.c fs/jfs.c fs/minix.c \
# grub_script.tab.c \ fs/ntfs.c fs/ntfscomp.c fs/reiserfs.c fs/sfs.c \
# io/gzio.c \ fs/ufs.c fs/ufs2.c fs/xfs.c fs/afs.c fs/afs_be.c \
# kern/device.c kern/disk.c kern/dl.c kern/env.c kern/err.c \ fs/befs.c fs/befs_be.c fs/tar.c \
# kern/file.c kern/fs.c kern/loader.c kern/main.c kern/misc.c \ \
# kern/parser.c kern/partition.c kern/rescue.c kern/term.c \ partmap/amiga.c partmap/apple.c partmap/msdos.c \
# normal/arg.c normal/cmdline.c normal/command.c \ partmap/sun.c partmap/acorn.c \
# normal/completion.c normal/context.c normal/execute.c \ \
# normal/function.c normal/lexer.c \ disk/raid.c disk/mdraid_linux.c disk/lvm.c \
# normal/main.c normal/menu.c normal/menu_entry.c normal/misc.c \ util/raid.c util/lvm.c gnulib/progname.c \
# partmap/amiga.c partmap/apple.c partmap/pc.c partmap/sun.c \ grub_setup_init.c
# partmap/acorn.c \
# util/console.c util/grub-emu.c util/misc.c \
# util/biosdisk.c util/getroot.c \
# util/sparc64/ieee1275/misc.c
grub_emu_LDFLAGS = $(LIBCURSES) # For grub-ofpathname.
grub_ofpathname_SOURCES = util/sparc64/ieee1275/grub-ofpathname.c \
util/ieee1275/ofpath.c util/misc.c gnulib/progname.c
kernel_elf_SOURCES = kern/sparc64/ieee1275/init.c kern/ieee1275/ieee1275.c \ # Scripts.
kern/main.c kern/device.c kern/disk.c kern/dl.c kern/file.c \ sbin_SCRIPTS = grub-install
kern/fs.c kern/err.c kern/misc.c kern/mm.c kern/loader.c \
kern/rescue.c kern/term.c term/ieee1275/ofconsole.c \ # For grub-install.
kern/sparc64/ieee1275/openfw.c disk/ieee1275/ofdisk.c \ grub_install_SOURCES = util/grub-install.in
kern/partition.c kern/env.c kern/sparc64/dl.c kernel_elf_symlist.c \
kern/sparc64/cache.S kern/parser.c
kernel_elf_HEADERS = grub/sparc64/ieee1275/ieee1275.h
kernel_elf_CFLAGS = $(COMMON_CFLAGS)
kernel_elf_ASFLAGS = $(COMMON_ASFLAGS)
kernel_elf_LDFLAGS = -mno-app-regs -nostdlib -Wl,-N,-Ttext,0x200000,-Bstatic,-melf64_sparc
# Modules. # Modules.
#_linux.mod linux.mod pkglib_MODULES = halt.mod \
pkglib_MODULES = fat.mod ufs.mod ext2.mod minix.mod \ linux.mod \
hfs.mod jfs.mod normal.mod hello.mod font.mod ls.mod \ reboot.mod \
boot.mod cmp.mod cat.mod terminal.mod fshelp.mod amiga.mod apple.mod \ memdisk.mod \
pc.mod suspend.mod loopback.mod help.mod reboot.mod halt.mod sun.mod \ lsmmap.mod
configfile.mod search.mod gzio.mod xfs.mod \
affs.mod sfs.mod acorn.mod
# For fshelp.mod.
fshelp_mod_SOURCES = fs/fshelp.c
fshelp_mod_CFLAGS = $(COMMON_CFLAGS)
fshelp_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For fat.mod.
fat_mod_SOURCES = fs/fat.c
fat_mod_CFLAGS = $(COMMON_CFLAGS)
fat_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For ext2.mod.
ext2_mod_SOURCES = fs/ext2.c
ext2_mod_CFLAGS = $(COMMON_CFLAGS)
ext2_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For ufs.mod.
ufs_mod_SOURCES = fs/ufs.c
ufs_mod_CFLAGS = $(COMMON_CFLAGS)
ufs_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For minix.mod.
minix_mod_SOURCES = fs/minix.c
minix_mod_CFLAGS = $(COMMON_CFLAGS)
minix_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For hfs.mod.
hfs_mod_SOURCES = fs/hfs.c
hfs_mod_CFLAGS = $(COMMON_CFLAGS)
hfs_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For jfs.mod.
jfs_mod_SOURCES = fs/jfs.c
jfs_mod_CFLAGS = $(COMMON_CFLAGS)
jfs_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For iso9660.mod.
iso9660_mod_SOURCES = fs/iso9660.c
iso9660_mod_CFLAGS = $(COMMON_CFLAGS)
iso9660_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For xfs.mod.
xfs_mod_SOURCES = fs/xfs.c
xfs_mod_CFLAGS = $(COMMON_CFLAGS)
xfs_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For affs.mod.
affs_mod_SOURCES = fs/affs.c
affs_mod_CFLAGS = $(COMMON_CFLAGS)
affs_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For sfs.mod.
sfs_mod_SOURCES = fs/sfs.c
sfs_mod_CFLAGS = $(COMMON_CFLAGS)
sfs_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For _linux.mod.
#_linux_mod_SOURCES = loader/sparc64/ieee1275/linux.c
#_linux_mod_CFLAGS = $(COMMON_CFLAGS)
#_linux_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For linux.mod.
#linux_mod_SOURCES = loader/sparc64/ieee1275/linux_normal.c
#linux_mod_CFLAGS = $(COMMON_CFLAGS)
#linux_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For normal.mod.
normal_mod_DEPENDENCIES = grub_script.tab.c grub_script.tab.h
normal_mod_SOURCES = normal/arg.c normal/cmdline.c normal/command.c \
normal/completion.c normal/execute.c \
normal/function.c normal/lexer.c normal/main.c normal/menu.c \
normal/menu_entry.c normal/misc.c normal/script.c \
normal/sparc64/setjmp.S \
grub_script.tab.c
normal_mod_CFLAGS = $(COMMON_CFLAGS)
normal_mod_ASFLAGS = $(COMMON_ASFLAGS)
normal_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For hello.mod.
hello_mod_SOURCES = hello/hello.c
hello_mod_CFLAGS = $(COMMON_CFLAGS)
hello_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For boot.mod. # For boot.mod.
boot_mod_SOURCES = commands/boot.c pkglib_MODULES += boot.mod
boot_mod_SOURCES = commands/boot.c lib/i386/pc/biosnum.c
boot_mod_CFLAGS = $(COMMON_CFLAGS) boot_mod_CFLAGS = $(COMMON_CFLAGS)
boot_mod_LDFLAGS = $(COMMON_LDFLAGS) boot_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For terminal.mod. # For linux.mod.
terminal_mod_SOURCES = commands/terminal.c linux_mod_SOURCES = loader/sparc64/ieee1275/linux.c
terminal_mod_CFLAGS = $(COMMON_CFLAGS) linux_mod_CFLAGS = $(COMMON_CFLAGS)
terminal_mod_LDFLAGS = $(COMMON_LDFLAGS) linux_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For ls.mod. # For reboot.mod.
ls_mod_SOURCES = commands/ls.c reboot_mod_SOURCES = commands/reboot.c
ls_mod_CFLAGS = $(COMMON_CFLAGS)
ls_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For cmp.mod.
cmp_mod_SOURCES = commands/cmp.c
cmp_mod_CFLAGS = $(COMMON_CFLAGS)
cmp_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For cat.mod.
cat_mod_SOURCES = commands/cat.c
cat_mod_CFLAGS = $(COMMON_CFLAGS)
cat_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For font.mod.
font_mod_SOURCES = font/manager.c
font_mod_CFLAGS = $(COMMON_CFLAGS)
font_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For amiga.mod
amiga_mod_SOURCES = partmap/amiga.c
amiga_mod_CFLAGS = $(COMMON_CFLAGS)
amiga_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For apple.mod
apple_mod_SOURCES = partmap/apple.c
apple_mod_CFLAGS = $(COMMON_CFLAGS)
apple_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For pc.mod
pc_mod_SOURCES = partmap/pc.c
pc_mod_CFLAGS = $(COMMON_CFLAGS)
pc_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For sun.mod
sun_mod_SOURCES = partmap/sun.c
sun_mod_CFLAGS = $(COMMON_CFLAGS)
sun_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For acorn.mod
acorn_mod_SOURCES = partmap/acorn.c
acorn_mod_CFLAGS = $(COMMON_CFLAGS)
# For loopback.mod
loopback_mod_SOURCES = disk/loopback.c
loopback_mod_CFLAGS = $(COMMON_CFLAGS)
loopback_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For suspend.mod
suspend_mod_SOURCES = commands/ieee1275/suspend.c
suspend_mod_CFLAGS = $(COMMON_CFLAGS)
suspend_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For reboot.mod
reboot_mod_SOURCES = commands/ieee1275/reboot.c
reboot_mod_CFLAGS = $(COMMON_CFLAGS) reboot_mod_CFLAGS = $(COMMON_CFLAGS)
reboot_mod_LDFLAGS = $(COMMON_LDFLAGS) reboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For halt.mod # For halt.mod.
halt_mod_SOURCES = commands/ieee1275/halt.c halt_mod_SOURCES = commands/halt.c
halt_mod_CFLAGS = $(COMMON_CFLAGS) halt_mod_CFLAGS = $(COMMON_CFLAGS)
halt_mod_LDFLAGS = $(COMMON_LDFLAGS) halt_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For help.mod. # For memdisk.mod.
help_mod_SOURCES = commands/help.c memdisk_mod_SOURCES = disk/memdisk.c
help_mod_CFLAGS = $(COMMON_CFLAGS) memdisk_mod_CFLAGS = $(COMMON_CFLAGS)
help_mod_LDFLAGS = $(COMMON_LDFLAGS) memdisk_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For default.mod # For lsmmap.mod
default_mod_SOURCES = commands/default.c lsmmap_mod_SOURCES = commands/lsmmap.c
default_mod_CFLAGS = $(COMMON_CFLAGS) lsmmap_mod_CFLAGS = $(COMMON_CFLAGS)
default_mod_LDFLAGS = $(COMMON_LDFLAGS) lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For timeout.mod include $(srcdir)/conf/common.mk
timeout_mod_SOURCES = commands/timeout.c
timeout_mod_CFLAGS = $(COMMON_CFLAGS)
timeout_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For configfile.mod
configfile_mod_SOURCES = commands/configfile.c
configfile_mod_CFLAGS = $(COMMON_CFLAGS)
configfile_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For search.mod.
search_mod_SOURCES = commands/search.c
search_mod_CFLAGS = $(COMMON_CFLAGS)
search_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For gzio.mod.
gzio_mod_SOURCES = io/gzio.c
gzio_mod_CFLAGS = $(COMMON_CFLAGS)
gzio_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For test.mod.
test_mod_SOURCES = commands/test.c
test_mod_CFLAGS = $(COMMON_CFLAGS)
test_mod_LDFLAGS = $(COMMON_LDFLAGS)

50
conf/tests.rmk Normal file
View File

@ -0,0 +1,50 @@
# -*- makefile -*-
# For grub-shell
grub-shell: tests/util/grub-shell.in config.status
./config.status --file=$@:$<
chmod +x $@
check_SCRIPTS += grub-shell
CLEANFILES += grub-shell
# For grub-shell-tester
grub-shell-tester: tests/util/grub-shell-tester.in config.status
./config.status --file=$@:$<
chmod +x $@
check_SCRIPTS += grub-shell-tester
CLEANFILES += grub-shell-tester
pkglib_MODULES += functional_test.mod
functional_test_mod_SOURCES = tests/lib/functional_test.c tests/lib/test.c
functional_test_mod_CFLAGS = $(COMMON_CFLAGS)
functional_test_mod_LDFLAGS = $(COMMON_LDFLAGS)
# Rules for unit tests
check_UTILITIES += example_unit_test
example_unit_test_SOURCES = tests/example_unit_test.c kern/list.c kern/misc.c tests/lib/test.c tests/lib/unit_test.c
example_unit_test_CFLAGS = -Wno-format
# Rules for functional tests
pkglib_MODULES += example_functional_test.mod
example_functional_test_mod_SOURCES = tests/example_functional_test.c
example_functional_test_mod_CFLAGS = -Wno-format $(COMMON_CFLAGS)
example_functional_test_mod_LDFLAGS = $(COMMON_LDFLAGS)
# Rules for scripted tests
check_SCRIPTS += example_scripted_test
example_scripted_test_SOURCES = tests/example_scripted_test.in
check_SCRIPTS += example_grub_script_test
example_grub_script_test_SOURCES = tests/example_grub_script_test.in
# List of tests to execute on "make check"
SCRIPTED_TESTS = example_scripted_test
SCRIPTED_TESTS += example_grub_script_test
UNIT_TESTS = example_unit_test
FUNCTIONAL_TESTS = example_functional_test.mod
# dependencies between tests and testing-tools
$(SCRIPTED_TESTS): grub-shell grub-shell-tester
$(FUNCTIONAL_TESTS): functional_test.mod

Some files were not shown because too many files have changed in this diff Show More