merge mainline

This commit is contained in:
Colin Watson 2010-06-12 12:17:28 +01:00
commit 934302d00b
545 changed files with 51148 additions and 23539 deletions

View file

@ -3,6 +3,8 @@
30_os-prober 30_os-prober
40_custom 40_custom
aclocal.m4 aclocal.m4
ascii.bitmaps
ascii.h
autom4te.cache autom4te.cache
build_env.mk build_env.mk
.bzrignore .bzrignore
@ -25,6 +27,8 @@ docs/version.texi
*.exec *.exec
genkernsyms.sh genkernsyms.sh
gensymlist.sh gensymlist.sh
gentrigtables
grub-bin2h
grub-dumpbios grub-dumpbios
grub-editenv grub-editenv
grub-emu grub-emu
@ -40,8 +44,15 @@ grub-pe2elf
grub-probe grub-probe
grub_probe_init.c grub_probe_init.c
grub_probe_init.h grub_probe_init.h
grub-reboot
grub-script-check
grub_script_check_init.c
grub_script_check_init.h
grub_script.tab.c grub_script.tab.c
grub_script.tab.h grub_script.tab.h
grub_script.yy.c
grub_script.yy.h
grub-set-default
grub-setup grub-setup
grub_setup_init.c grub_setup_init.c
grub_setup_init.h grub_setup_init.h
@ -62,4 +73,5 @@ stamp-h
stamp-h1 stamp-h1
stamp-h.in stamp-h.in
symlist.c symlist.c
trigtables.c
update-grub_lib update-grub_lib

3892
ChangeLog

File diff suppressed because it is too large Load diff

21
INSTALL
View file

@ -14,9 +14,26 @@ configuring the GRUB.
* GCC 4.1.3 or later * GCC 4.1.3 or later
* GNU Make * GNU Make
* GNU Bison 2.3 or later * GNU Bison 2.3 or later
* GNU gettext 0.17 or later
* GNU binutils 2.9.1.0.23 or later * GNU binutils 2.9.1.0.23 or later
* Flex 2.5.35 or later
* Other standard GNU/Unix tools * Other standard GNU/Unix tools
On GNU/Linux, you also need:
* libdevmapper (recommended)
To build grub-emu, you need:
* ncurses
* libusb (recommended)
* SDL (recommended)
To build GRUB's graphical terminal (gfxterm), you need:
* FreeType 2 or later
* GNU Unifont
If you use a development snapshot or want to hack on GRUB you may If you use a development snapshot or want to hack on GRUB you may
need the following. need the following.
@ -25,6 +42,10 @@ need the following.
* Autoconf 2.60 or later * Autoconf 2.60 or later
* Automake 1.10.1 or later * Automake 1.10.1 or later
Prerequisites for make-check:
* qemu, specifically the binary 'qemu-system-i386'
Configuring the GRUB Configuring the GRUB
==================== ====================

View file

@ -35,6 +35,7 @@ sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@ sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@ localstatedir = @localstatedir@
libdir = @libdir@ libdir = @libdir@
localedir = @localedir@
infodir = @infodir@ infodir = @infodir@
mandir = @mandir@ mandir = @mandir@
includedir = @includedir@ includedir = @includedir@
@ -43,6 +44,10 @@ pkglibdir = $(libdir)/`echo @PACKAGE_TARNAME@/$(target_cpu)-$(platform) | sed '
# Internationalization library. # Internationalization library.
LIBINTL = @LIBINTL@ LIBINTL = @LIBINTL@
TARGET_NO_MODULES = @TARGET_NO_MODULES@
# Util library.
LIBUTIL = @LIBUTIL@
XGETTEXT = @XGETTEXT@ XGETTEXT = @XGETTEXT@
MSGMERGE = @MSGMERGE@ MSGMERGE = @MSGMERGE@
@ -75,27 +80,31 @@ MKDIR_P = @MKDIR_P@
mkinstalldirs = $(srcdir)/mkinstalldirs mkinstalldirs = $(srcdir)/mkinstalldirs
LIBS = @LIBS@ $(LIBINTL) LIBS = @LIBS@ $(LIBINTL) $(LIBUTIL)
CC = @CC@ CC = @CC@
CFLAGS = @CFLAGS@ CFLAGS = @CFLAGS@
POSIX_CFLAGS = -I$(srcdir)/lib/posix_wrap
GNULIB_UTIL_CFLAGS = -Wno-undef -Wno-sign-compare -Wno-unused -D_GL_UNUSED="__attribute__ ((unused))" -I$(srcdir)/gnulib
GNULIB_CFLAGS = $(GNULIB_UTIL_CFLAGS) $(POSIX_CFLAGS)
ASFLAGS = @ASFLAGS@ ASFLAGS = @ASFLAGS@
LDFLAGS = @LDFLAGS@ $(LIBS) LDFLAGS = @LDFLAGS@ $(LIBS)
CPPFLAGS = @CPPFLAGS@ -I$(builddir) -I$(builddir)/include -I$(srcdir)/gnulib -I$(srcdir)/include -Wall -W \ CPPFLAGS = @CPPFLAGS@ -I$(builddir) -I$(builddir)/include -I$(srcdir)/gnulib -I$(srcdir)/include -Wall -W \
-DGRUB_LIBDIR=\"$(pkglibdir)\" -DLOCALEDIR=\"$(localedir)\" -DGRUB_PKGLIBROOTDIR=\"$(libdir)/`echo @PACKAGE_TARNAME@ | sed '$(transform)'`\" -DLOCALEDIR=\"$(localedir)\"
TARGET_CC = @TARGET_CC@ TARGET_CC = @TARGET_CC@
TARGET_CFLAGS = @TARGET_CFLAGS@ TARGET_CFLAGS = -ffreestanding @TARGET_CFLAGS@
TARGET_ASFLAGS = @TARGET_ASFLAGS@ TARGET_ASFLAGS = -nostdinc -fno-builtin @TARGET_ASFLAGS@
TARGET_MODULE_FORMAT = @TARGET_MODULE_FORMAT@ TARGET_MODULE_FORMAT = @TARGET_MODULE_FORMAT@
TARGET_APPLE_CC = @TARGET_APPLE_CC@ TARGET_APPLE_CC = @TARGET_APPLE_CC@
OBJCONV = @OBJCONV@ OBJCONV = @OBJCONV@
TARGET_CPPFLAGS = @TARGET_CPPFLAGS@ -nostdinc -isystem $(shell $(TARGET_CC) -print-file-name=include) -I$(srcdir)/include -I$(builddir) -I$(builddir)/include \ TARGET_CPPFLAGS = @TARGET_CPPFLAGS@ -I$(srcdir)/include -I$(builddir) -I$(builddir)/include \
-Wall -W -Wall -W
TARGET_LDFLAGS = @TARGET_LDFLAGS@ TARGET_LDFLAGS = -nostdlib -static-libgcc @TARGET_LDFLAGS@
TARGET_IMG_LDSCRIPT = @TARGET_IMG_LDSCRIPT@ TARGET_IMG_LDSCRIPT = @TARGET_IMG_LDSCRIPT@
TARGET_IMG_LDFLAGS = @TARGET_IMG_LDFLAGS@ TARGET_IMG_LDFLAGS = -nostdlib @TARGET_IMG_LDFLAGS@
TARGET_IMG_CFLAGS = @TARGET_IMG_CFLAGS@ TARGET_IMG_CFLAGS = @TARGET_IMG_CFLAGS@
TARGET_OBJ2ELF = @TARGET_OBJ2ELF@ TARGET_OBJ2ELF = @TARGET_OBJ2ELF@
kernel_img_LDFLAGS = -lgcc
EXEEXT = @EXEEXT@ EXEEXT = @EXEEXT@
OBJCOPY = @OBJCOPY@ OBJCOPY = @OBJCOPY@
STRIP = @STRIP@ STRIP = @STRIP@
@ -114,12 +123,15 @@ endif
AWK = @AWK@ AWK = @AWK@
LIBCURSES = @LIBCURSES@ LIBCURSES = @LIBCURSES@
LIBUSB = @LIBUSB@ LIBUSB = @LIBUSB@
LIBSDL = @LIBSDL@
LIBPCIACCESS = @LIBPCIACCESS@ LIBPCIACCESS = @LIBPCIACCESS@
LEX = @LEX@
YACC = @YACC@ YACC = @YACC@
FONT_SOURCE = @FONT_SOURCE@ FONT_SOURCE = @FONT_SOURCE@
# Options. # Options.
enable_grub_emu_usb = @enable_grub_emu_usb@ enable_grub_emu_usb = @enable_grub_emu_usb@
enable_grub_emu_sdl = @enable_grub_emu_sdl@
enable_grub_emu_pci = @enable_grub_emu_pci@ enable_grub_emu_pci = @enable_grub_emu_pci@
enable_grub_fstest = @enable_grub_fstest@ enable_grub_fstest = @enable_grub_fstest@
enable_grub_pe2elf = @enable_grub_pe2elf@ enable_grub_pe2elf = @enable_grub_pe2elf@
@ -130,7 +142,7 @@ enable_efiemu = @enable_efiemu@
### General variables. ### General variables.
RMKFILES = $(wildcard conf/*.rmk) RMKFILES = $(wildcard $(srcdir)/conf/*.rmk)
MKFILES = $(patsubst %.rmk,%.mk,$(RMKFILES)) MKFILES = $(patsubst %.rmk,%.mk,$(RMKFILES))
@ -145,11 +157,13 @@ 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 stamp-h1 include/grub/cpu include/grub/machine \
gensymlist.sh genkernsyms.sh build_env.mk \ gensymlist.sh genkernsyms.sh build_env.mk \
docs/grub.info docs/version.texi docs/stamp-vti docs/grub.info docs/version.texi docs/stamp-vti
MAINTAINER_CLEANFILES = $(srcdir)/configure $(addprefix $(srcdir)/,$(MKFILES)) \ MAINTAINER_CLEANFILES = $(srcdir)/configure $(srcdir)/aclocal.m4 \
$(MKFILES) $(srcdir)/config.guess \
$(srcdir)/config.sub $(srcdir)/install-sh $(srcdir)/missing \
$(srcdir)/DISTLIST $(srcdir)/config.h.in $(srcdir)/stamp-h.in $(INFOS) $(srcdir)/DISTLIST $(srcdir)/config.h.in $(srcdir)/stamp-h.in $(INFOS)
# The default target. # The default target.
@ -173,10 +187,17 @@ include $(srcdir)/conf/tests.mk
-include $(wildcard $(GRUB_CONTRIB)/*/conf/common.mk) -include $(wildcard $(GRUB_CONTRIB)/*/conf/common.mk)
endif endif
ifeq ($(TARGET_NO_MODULES), yes)
TARGET_CFLAGS += -DGRUB_TARGET_NO_MODULES=1
CFLAGS += -DGRUB_TARGET_NO_MODULES=1
endif
### General targets. ### General targets.
CLEANFILES += $(pkglib_DATA) $(pkgdata_DATA) po/*.mo CLEANFILES += $(pkglib_DATA) $(pkgdata_DATA) po/*.mo
ifneq ($(TARGET_NO_MODULES), yes)
pkglib_DATA += moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst video.lst crypto.lst terminal.lst pkglib_DATA += moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst video.lst crypto.lst terminal.lst
endif
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) > $@ \
@ -236,7 +257,8 @@ else
ifeq ($(enable_grub_mkfont),yes) ifeq ($(enable_grub_mkfont),yes)
pkgdata_DATA += unicode.pf2 ascii.pf2 pkgdata_DATA += unicode.pf2 ascii.pf2 ascii.h
CLEANFILES += ascii.bitmaps
# Arrows and lines are needed to draw the menu, so we always include them # Arrows and lines are needed to draw the menu, so we always include them
UNICODE_ARROWS=0x2190-0x2193 UNICODE_ARROWS=0x2190-0x2193
@ -247,6 +269,14 @@ unicode.pf2: $(FONT_SOURCE) grub-mkfont
ascii.pf2: $(FONT_SOURCE) grub-mkfont ascii.pf2: $(FONT_SOURCE) grub-mkfont
$(builddir)/grub-mkfont -o $@ $(FONT_SOURCE) -r 0x0-0x7f,$(UNICODE_ARROWS),$(UNICODE_LINES) $(builddir)/grub-mkfont -o $@ $(FONT_SOURCE) -r 0x0-0x7f,$(UNICODE_ARROWS),$(UNICODE_LINES)
ascii.bitmaps: $(FONT_SOURCE) grub-mkfont
$(builddir)/grub-mkfont --ascii-bitmaps -o $@ $(FONT_SOURCE)
ascii.h: ascii.bitmaps grub-bin2h
$(builddir)/grub-bin2h ascii_bitmaps < $< > $@
TARGET_CFLAGS += -DUSE_ASCII_FAILBACK=1
endif endif
endif endif
@ -268,7 +298,7 @@ build_env.mk: Makefile
) > $@ ) > $@
pkglib_BUILDDIR += config.h grub_script.tab.h pkglib_BUILDDIR += config.h grub_script.tab.h
all-local: $(PROGRAMS) $(PKGLIB) $(PKGDATA) $(SCRIPTS) $(INFOS) $(MKFILES) $(foreach lang, $(LINGUAS), po/$(lang).mo) all-local: $(PROGRAMS) $(GRUB_EMU) $(PKGLIB) $(PKGDATA) $(SCRIPTS) $(INFOS) $(MKFILES) $(foreach lang, $(LINGUAS), po/$(lang).mo)
install: install-local install: install-local
@ -289,30 +319,30 @@ install-local: all
$(INSTALL_DATA) $$dir$$file $(DESTDIR)$(pkgdatadir)/$$dest; \ $(INSTALL_DATA) $$dir$$file $(DESTDIR)$(pkgdatadir)/$$dest; \
done done
$(SHELL) $(mkinstalldirs) $(DESTDIR)$(bindir) $(DESTDIR)$(mandir)/man1 $(SHELL) $(mkinstalldirs) $(DESTDIR)$(bindir) $(DESTDIR)$(mandir)/man1
@list='$(bin_UTILITIES)'; for file in $$list; do \ @list='$(bin_UTILITIES) $(GRUB_EMU)'; 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; \ $(HELP2MAN) --section=1 -i $(srcdir)/docs/man/$$dest.h2m -o $(DESTDIR)$(mandir)/man1/$$dest.1 $(builddir)/$$file; \
done done
$(SHELL) $(mkinstalldirs) $(DESTDIR)$(sbindir) $(DESTDIR)$(mandir)/man8 $(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; \ $(HELP2MAN) --section=8 -i $(srcdir)/docs/man/$$dest.h2m -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; \ $(HELP2MAN) --section=1 -i $(srcdir)/docs/man/$$dest.h2m -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; \ $(HELP2MAN) --section=8 -i $(srcdir)/docs/man/$$dest.h2m -o $(DESTDIR)$(mandir)/man8/$$dest.8 $(builddir)/$$file; \
done done
$(SHELL) $(mkinstalldirs) $(DESTDIR)$(sysconfdir)/grub.d $(SHELL) $(mkinstalldirs) $(DESTDIR)$(sysconfdir)/grub.d
@list='$(grub-mkconfig_SCRIPTS)'; for file in $$list; do \ @list='$(grub-mkconfig_SCRIPTS)'; for file in $$list; do \
@ -365,7 +395,7 @@ uninstall:
dest="`echo $$file | sed 's,.*/,,'`"; \ dest="`echo $$file | sed 's,.*/,,'`"; \
rm -f $(DESTDIR)$(pkgdatadir)/$$dest; \ rm -f $(DESTDIR)$(pkgdatadir)/$$dest; \
done done
@list='$(bin_UTILITIES) $(bin_SCRIPTS)'; for file in $$list; do \ @list='$(bin_UTILITIES) $(bin_SCRIPTS) $(GRUB_EMU)'; 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; \ rm -f $(DESTDIR)$(mandir)/man1/$$dest.1; \
@ -382,7 +412,6 @@ uninstall:
@list='$(lib_SCRIPTS)'; \ @list='$(lib_SCRIPTS)'; \
for file in $$list; do \ for file in $$list; do \
dest="`echo $$file | sed 's,.*/,,'`"; \ dest="`echo $$file | sed 's,.*/,,'`"; \
echo rm -f $(DESTDIR)$(libdir)/$$dest; \
rm -f $(DESTDIR)$(libdir)/grub/$$dest; \ rm -f $(DESTDIR)$(libdir)/grub/$$dest; \
done done
@list='$(info_INFOS)'; \ @list='$(info_INFOS)'; \
@ -411,6 +440,8 @@ distclean: mostlyclean
maintainer-clean: distclean maintainer-clean: distclean
-test -z "$(MAINTAINER_CLEANFILES)" || rm -f $(MAINTAINER_CLEANFILES) -test -z "$(MAINTAINER_CLEANFILES)" || rm -f $(MAINTAINER_CLEANFILES)
-rmdir $(srcdir)/lib/libgcrypt-grub/cipher
-rmdir $(srcdir)/lib/libgcrypt-grub
info: info:
@ -465,23 +496,21 @@ distcheck: dist
check: all $(UNIT_TESTS) $(FUNCTIONAL_TESTS) $(SCRIPTED_TESTS) check: all $(UNIT_TESTS) $(FUNCTIONAL_TESTS) $(SCRIPTED_TESTS)
@list="$(UNIT_TESTS)"; \ @list="$(UNIT_TESTS)"; \
set -e; \
for file in $$list; do \ for file in $$list; do \
$(builddir)/$$file; \ $(builddir)/$$file; \
done done
@list="$(FUNCTIONAL_TESTS)"; \ @list="$(FUNCTIONAL_TESTS)"; \
set -e; \
for file in $$list; do \ for file in $$list; do \
mod=`basename $$file .mod`; \ mod=`basename $$file .mod`; \
echo "insmod functional_test; insmod $$mod; functional_test" \ echo "insmod functional_test; insmod $$mod; functional_test" \
| $(builddir)/grub-shell; \ | $(builddir)/grub-shell; \
done done
@list="$(SCRIPTED_TESTS)"; \ @list="$(SCRIPTED_TESTS)"; \
set -e; \
for file in $$list; do \ for file in $$list; do \
echo "$$file:"; \ $(builddir)/$$file; \
if $(builddir)/$$file; then \
echo "$$file: PASS"; \
else \
echo "$$file: FAIL"; \
fi; \
done done
.SUFFIX: .SUFFIX:
@ -516,8 +545,8 @@ genkernsyms.sh: genkernsyms.sh.in config.status
$(SHELL) ./config.status $(SHELL) ./config.status
$(srcdir)/po/$(PACKAGE).pot: po/POTFILES po/POTFILES-shell $(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 po/$(PACKAGE).pot -f po/POTFILES --keyword=_ --keyword=N_
cd $(srcdir) && $(XGETTEXT) -ctranslate --from-code=utf-8 -o $@ -f po/POTFILES-shell -j --language=Shell cd $(srcdir) && $(XGETTEXT) -ctranslate --from-code=utf-8 -o po/$(PACKAGE).pot -f po/POTFILES-shell -j --language=Shell
$(foreach lang, $(LINGUAS), $(srcdir)/po/$(lang).po): po/$(PACKAGE).pot $(foreach lang, $(LINGUAS), $(srcdir)/po/$(lang).po): po/$(PACKAGE).pot
$(MSGMERGE) -U $@ $^ $(MSGMERGE) -U $@ $^

19
NEWS
View file

@ -1,4 +1,21 @@
New in 1.98: New in 1.98 - 2010-03-06:
* Multiboot on EFI support.
* Graphical menu support.
* MIPS support.
* Saved default menu entry support, with new utilities `grub-reboot' and
`grub-set-default'.
* Unit testing framework.
* Support for multiple terminals.
* Encrypted password support, with a new utility `grub-mkpasswd-pbkdf2'.
* `grub-mkfloppy' removed; use `grub-mkrescue' to create floppy images.
* Add grub-probe support for GNU/Hurd. * Add grub-probe support for GNU/Hurd.

View file

@ -14,11 +14,11 @@ $2
dnl Check whether target compiler is working dnl Check whether target compiler is working
AC_DEFUN(grub_PROG_TARGET_CC, AC_DEFUN([grub_PROG_TARGET_CC],
[AC_MSG_CHECKING([whether target compiler is working]) [AC_MSG_CHECKING([whether target compiler is working])
AC_CACHE_VAL(grub_cv_prog_target_cc, AC_CACHE_VAL(grub_cv_prog_target_cc,
[AC_LINK_IFELSE([AC_LANG_PROGRAM([[ [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
asm (".globl start; start: nop"); asm (".globl start; start:");
int main (void); int main (void);
]], [[]])], ]], [[]])],
[grub_cv_prog_target_cc=yes], [grub_cv_prog_target_cc=yes],
@ -36,7 +36,7 @@ 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
dnl Erich Boleyn and modified by Yoshinori K. Okuji. dnl Erich Boleyn and modified by Yoshinori K. Okuji.
AC_DEFUN(grub_ASM_USCORE, AC_DEFUN([grub_ASM_USCORE],
[AC_REQUIRE([AC_PROG_CC]) [AC_REQUIRE([AC_PROG_CC])
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,
@ -75,7 +75,7 @@ AC_MSG_RESULT([$grub_cv_asm_uscore])
dnl Some versions of `objcopy -O binary' vary their output depending dnl Some versions of `objcopy -O binary' vary their output depending
dnl on the link address. dnl on the link address.
AC_DEFUN(grub_PROG_OBJCOPY_ABSOLUTE, 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
@ -93,7 +93,7 @@ else
fi fi
grub_cv_prog_objcopy_absolute=yes grub_cv_prog_objcopy_absolute=yes
for link_addr in 0x2000 0x8000 0x7C00; do for link_addr in 0x2000 0x8000 0x7C00; do
if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -nostdlib ${TARGET_IMG_LDFLAGS_AC} -Wl,-Ttext -Wl,$link_addr conftest.o -o conftest.exec]); then : if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -nostdlib ${TARGET_IMG_LDFLAGS_AC}$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
@ -119,7 +119,7 @@ fi
dnl Supply --build-id=none to ld if building modules. dnl Supply --build-id=none to ld if building modules.
dnl This suppresses warnings from ld on some systems dnl This suppresses warnings from ld on some systems
AC_DEFUN(grub_PROG_LD_BUILD_ID_NONE, AC_DEFUN([grub_PROG_LD_BUILD_ID_NONE],
[AC_MSG_CHECKING([whether linker accepts --build-id=none]) [AC_MSG_CHECKING([whether linker accepts --build-id=none])
AC_CACHE_VAL(grub_cv_prog_ld_build_id_none, AC_CACHE_VAL(grub_cv_prog_ld_build_id_none,
[save_LDFLAGS="$LDFLAGS" [save_LDFLAGS="$LDFLAGS"
@ -150,7 +150,7 @@ dnl
dnl We only support the newer versions, because the old versions cause dnl We only support the newer versions, because the old versions cause
dnl major pain, by requiring manual assembly to get 16-bit instructions into dnl major pain, by requiring manual assembly to get 16-bit instructions into
dnl asm files. dnl asm files.
AC_DEFUN(grub_I386_ASM_ADDR32, AC_DEFUN([grub_I386_ASM_ADDR32],
[AC_REQUIRE([AC_PROG_CC]) [AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([grub_I386_ASM_PREFIX_REQUIREMENT]) AC_REQUIRE([grub_I386_ASM_PREFIX_REQUIREMENT])
AC_MSG_CHECKING([for .code16 addr32 assembler support]) AC_MSG_CHECKING([for .code16 addr32 assembler support])
@ -178,7 +178,7 @@ AC_MSG_RESULT([$grub_cv_i386_asm_addr32])])
dnl check if our compiler is apple cc dnl check if our compiler is apple cc
dnl because it requires numerous workarounds dnl because it requires numerous workarounds
AC_DEFUN(grub_apple_cc, AC_DEFUN([grub_apple_cc],
[AC_REQUIRE([AC_PROG_CC]) [AC_REQUIRE([AC_PROG_CC])
AC_MSG_CHECKING([whether our compiler is apple cc]) AC_MSG_CHECKING([whether our compiler is apple cc])
AC_CACHE_VAL(grub_cv_apple_cc, AC_CACHE_VAL(grub_cv_apple_cc,
@ -193,7 +193,7 @@ AC_MSG_RESULT([$grub_cv_apple_cc])])
dnl check if our target compiler is apple cc dnl check if our target compiler is apple cc
dnl because it requires numerous workarounds dnl because it requires numerous workarounds
AC_DEFUN(grub_apple_target_cc, AC_DEFUN([grub_apple_target_cc],
[AC_REQUIRE([AC_PROG_CC]) [AC_REQUIRE([AC_PROG_CC])
AC_MSG_CHECKING([whether our target compiler is apple cc]) AC_MSG_CHECKING([whether our target compiler is apple cc])
AC_CACHE_VAL(grub_cv_apple_target_cc, AC_CACHE_VAL(grub_cv_apple_target_cc,
@ -210,7 +210,7 @@ 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
dnl earlier versions requires that they appear in separate lines. dnl earlier versions requires that they appear in separate lines.
AC_DEFUN(grub_I386_ASM_PREFIX_REQUIREMENT, AC_DEFUN([grub_I386_ASM_PREFIX_REQUIREMENT],
[AC_REQUIRE([AC_PROG_CC]) [AC_REQUIRE([AC_PROG_CC])
AC_MSG_CHECKING(dnl AC_MSG_CHECKING(dnl
[whether addr32 must be in the same line as the instruction]) [whether addr32 must be in the same line as the instruction])
@ -246,7 +246,7 @@ AC_MSG_RESULT([$grub_cv_i386_asm_prefix_requirement])])
dnl Older versions of GAS require that absolute indirect calls/jumps are dnl Older versions of GAS require that absolute indirect calls/jumps are
dnl not prefixed with `*', while later versions warn if not prefixed. dnl not prefixed with `*', while later versions warn if not prefixed.
AC_DEFUN(grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK, AC_DEFUN([grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK],
[AC_REQUIRE([AC_PROG_CC]) [AC_REQUIRE([AC_PROG_CC])
AC_MSG_CHECKING(dnl 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])
@ -276,7 +276,7 @@ AC_MSG_RESULT([$grub_cv_i386_asm_absolute_without_asterisk])])
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,
@ -320,7 +320,7 @@ fi
dnl Check what symbol is defined as an end symbol. dnl Check what symbol is defined as an end symbol.
dnl Written by Yoshinori K. Okuji. dnl Written by Yoshinori K. Okuji.
AC_DEFUN(grub_CHECK_END_SYMBOL, 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,
@ -352,7 +352,7 @@ fi
]) ])
dnl Check if the C compiler generates calls to `__enable_execute_stack()'. dnl Check if the C compiler generates calls to `__enable_execute_stack()'.
AC_DEFUN(grub_CHECK_ENABLE_EXECUTE_STACK,[ AC_DEFUN([grub_CHECK_ENABLE_EXECUTE_STACK],[
AC_MSG_CHECKING([whether `$CC' generates calls to `__enable_execute_stack()']) AC_MSG_CHECKING([whether `$CC' generates calls to `__enable_execute_stack()'])
AC_LANG_CONFTEST([[ AC_LANG_CONFTEST([[
void f (int (*p) (void)); void f (int (*p) (void));
@ -379,7 +379,7 @@ 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],[
[# Smashing stack protector. [# Smashing stack protector.
ssp_possible=yes] ssp_possible=yes]
AC_MSG_CHECKING([whether `$CC' accepts `-fstack-protector']) AC_MSG_CHECKING([whether `$CC' accepts `-fstack-protector'])
@ -398,7 +398,7 @@ else
]) ])
dnl Check if the C compiler supports `-mstack-arg-probe' (Cygwin). dnl Check if the C compiler supports `-mstack-arg-probe' (Cygwin).
AC_DEFUN(grub_CHECK_STACK_ARG_PROBE,[ AC_DEFUN([grub_CHECK_STACK_ARG_PROBE],[
[# Smashing stack arg probe. [# Smashing stack arg probe.
sap_possible=yes] sap_possible=yes]
AC_MSG_CHECKING([whether `$CC' accepts `-mstack-arg-probe']) AC_MSG_CHECKING([whether `$CC' accepts `-mstack-arg-probe'])
@ -414,7 +414,7 @@ else
]) ])
dnl Check if ln can handle directories properly (mingw). dnl Check if ln can handle directories properly (mingw).
AC_DEFUN(grub_CHECK_LINK_DIR,[ AC_DEFUN([grub_CHECK_LINK_DIR],[
AC_MSG_CHECKING([whether ln can handle directories properly]) AC_MSG_CHECKING([whether ln can handle directories properly])
[mkdir testdir 2>/dev/null [mkdir testdir 2>/dev/null
case $srcdir in case $srcdir in
@ -432,7 +432,7 @@ rm -rf testdir]
]) ])
dnl Check if the C compiler supports `-fPIE'. dnl Check if the C compiler supports `-fPIE'.
AC_DEFUN(grub_CHECK_PIE,[ AC_DEFUN([grub_CHECK_PIE],[
[# Position independent executable. [# Position independent executable.
pie_possible=yes] pie_possible=yes]
AC_MSG_CHECKING([whether `$CC' has `-fPIE' as default]) AC_MSG_CHECKING([whether `$CC' has `-fPIE' as default])

View file

@ -27,6 +27,7 @@
/* Print message string */ /* Print message string */
#define MSG(x) movw $x, %si; call LOCAL(message) #define MSG(x) movw $x, %si; call LOCAL(message)
#define ERR(x) movw $x, %si; jmp LOCAL(error_message)
.file "boot.S" .file "boot.S"
@ -233,7 +234,7 @@ LOCAL(chs_mode):
jz LOCAL(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 LOCAL(hd_probe_error) ERR(hd_probe_error_string)
LOCAL(final_init): LOCAL(final_init):
/* set the mode to zero */ /* set the mode to zero */
@ -360,22 +361,15 @@ LOCAL(copy_buffer):
* BIOS Geometry translation error (past the end of the disk geometry!). * BIOS Geometry translation error (past the end of the disk geometry!).
*/ */
LOCAL(geometry_error): LOCAL(geometry_error):
MSG(geometry_error_string) ERR(geometry_error_string)
jmp LOCAL(general_error)
/*
* Disk probe failure.
*/
LOCAL(hd_probe_error):
MSG(hd_probe_error_string)
jmp LOCAL(general_error)
/* /*
* Read error on the disk. * Read error on the disk.
*/ */
LOCAL(read_error): LOCAL(read_error):
MSG(read_error_string) movw $read_error_string, %si
LOCAL(error_message):
call LOCAL(message)
LOCAL(general_error): LOCAL(general_error):
MSG(general_error_string) MSG(general_error_string)

View file

@ -1,6 +1,6 @@
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2000,2005,2007,2008,2009 Free Software Foundation, Inc. * Copyright (C) 2000,2005,2007,2008,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,6 +16,8 @@
* 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/boot.h>
.file "pxeboot.S" .file "pxeboot.S"
.text .text
@ -28,7 +30,7 @@ _start:
start: start:
/* Use drive number 0x7F for PXE */ /* Use drive number 0x7F for PXE */
movb $0x7F, %dl movb $GRUB_BOOT_MACHINE_PXE_DL, %dl
/* Jump to the real world */ /* Jump to the real world */
ljmp $0, $0x8200 ljmp $0, $0x8200

View file

@ -31,7 +31,7 @@ _start:
jmp 1f jmp 1f
. = _start + GRUB_BOOT_MACHINE_CORE_ENTRY_ADDR . = _start + GRUB_BOOT_I386_QEMU_CORE_ENTRY_ADDR
VARIABLE(grub_core_entry_addr) VARIABLE(grub_core_entry_addr)
.long 0 .long 0
1: 1:
@ -63,5 +63,8 @@ VARIABLE(grub_core_entry_addr)
*right here* and this is why we need this kludge. */ *right here* and this is why we need this kludge. */
. = GRUB_BOOT_MACHINE_SIZE - 16 . = GRUB_BOOT_MACHINE_SIZE - 16
.code16
jmp _start jmp _start
. = GRUB_BOOT_MACHINE_SIZE . = GRUB_BOOT_MACHINE_SIZE

View file

@ -45,8 +45,9 @@ boot_version: .byte GRUB_BOOT_VERSION_MAJOR, GRUB_BOOT_VERSION_MINOR
* load address plus the size of the prepended A.OUT header (32 bytes). * load address plus the size of the prepended A.OUT header (32 bytes).
*/ */
boot_path: boot_path:
. = _start + GRUB_BOOT_MACHINE_KERNEL_SECTOR . = _start + GRUB_BOOT_MACHINE_KERNEL_BYTE
kernel_sector: .xword 2 boot_path_end:
kernel_byte: .xword (2 << 9)
kernel_address: .word GRUB_BOOT_MACHINE_KERNEL_ADDR kernel_address: .word GRUB_BOOT_MACHINE_KERNEL_ADDR
prom_finddev_name: .asciz "finddevice" prom_finddev_name: .asciz "finddevice"
@ -77,11 +78,23 @@ prom_error:
/* %o0: OF call name /* %o0: OF call name
* %o1: input arg 1 * %o1: input arg 1
*/ */
prom_call_1_1: prom_call_1_1_o2:
mov 1, %g1 clr %o2
ba prom_call ba prom_call_x_1
mov 1, %o5 mov 1, %g1
prom_call_getprop:
mov 4, %g1
stx %g1, [%l1 + 256]
mov CHOSEN_NODE_REG, %o1
ba prom_call_x_1
GET_ABS(prom_getprop_name, %o0)
prom_call_3_1_o1:
ba prom_call_3_1
mov BOOTDEV_REG, %o1
/* %o2: message string /* %o2: message string
* %o3: message length * %o3: message length
*/ */
@ -95,8 +108,9 @@ console_write:
* %o2: input arg 2 * %o2: input arg 2
* %o3: input arg 3 * %o3: input arg 3
*/ */
prom_call_3_1: prom_call_3_1:
mov 3, %g1 mov 3, %g1
prom_call_x_1:
mov 1, %o5 mov 1, %o5
/* fallthru */ /* fallthru */
@ -118,7 +132,7 @@ prom_call:
boot_continue: boot_continue:
mov %o7, PIC_REG /* PIC base */ mov %o7, PIC_REG /* PIC base */
sethi %hi(SCRATCH_PAD), %l1 /* OF argument slots */ sethi %hi(SCRATCH_PAD_BOOT), %l1 /* OF argument slots */
/* Find the /chosen node so we can fetch the stdout handle, /* Find the /chosen node so we can fetch the stdout handle,
* and thus perform console output. * and thus perform console output.
@ -126,23 +140,17 @@ boot_continue:
* chosen_node = prom_finddevice("/chosen") * chosen_node = prom_finddevice("/chosen")
*/ */
GET_ABS(prom_finddev_name, %o0) GET_ABS(prom_finddev_name, %o0)
GET_ABS(prom_chosen_path, %o1) call prom_call_1_1_o2
call prom_call_1_1 GET_ABS(prom_chosen_path, %o1)
clr %o2
ldx [%l1 + 0x20], CHOSEN_NODE_REG ldx [%l1 + 0x20], CHOSEN_NODE_REG
brz CHOSEN_NODE_REG, prom_error brz CHOSEN_NODE_REG, prom_error
/* getprop(chosen_node, "stdout", &buffer, buffer_size) */ /* getprop(chosen_node, "stdout", &buffer, buffer_size) */
GET_ABS(prom_getprop_name, %o0) GET_ABS(prom_stdout_name, %o2)
mov 4, %g1
mov 1, %o5
mov CHOSEN_NODE_REG, %o1
GET_ABS(prom_stdout_name, %o2)
add %l1, 256, %o3 add %l1, 256, %o3
mov 1024, %o4 call prom_call_getprop
call prom_call mov 1024, %o4
stx %g1, [%l1 + 256]
lduw [%l1 + 256], STDOUT_NODE_REG lduw [%l1 + 256], STDOUT_NODE_REG
brz,pn STDOUT_NODE_REG, prom_error brz,pn STDOUT_NODE_REG, prom_error
@ -152,15 +160,25 @@ boot_continue:
call console_write call console_write
mov GRUB_NAME_LEN, %o3 mov GRUB_NAME_LEN, %o3
GET_ABS(boot_path, %o3)
ldub [%o3], %o1
brnz,pn %o1, bootpath_known
/* getprop(chosen_node, "bootpath", &buffer, buffer_size) */
GET_ABS(prom_bootpath_name, %o2)
call prom_call_getprop
mov (boot_path_end - boot_path), %o4
bootpath_known:
/* Open up the boot_path, and use that handle to read the /* Open up the boot_path, and use that handle to read the
* first block of the GRUB kernel image. * first block of the GRUB kernel image.
* *
* bootdev_handle = open(boot_path) * bootdev_handle = open(boot_path)
*/ */
GET_ABS(prom_open_name, %o0) GET_ABS(prom_open_name, %o0)
GET_ABS(boot_path, %o1) call prom_call_1_1_o2
call prom_call_1_1 GET_ABS(boot_path, %o1)
clr %o2
ldx [%l1 + 0x20], BOOTDEV_REG ldx [%l1 + 0x20], BOOTDEV_REG
brz,pn BOOTDEV_REG, prom_open_error brz,pn BOOTDEV_REG, prom_open_error
@ -168,28 +186,23 @@ boot_continue:
/* Since we have 64-bit cells, the high cell of the seek offset /* Since we have 64-bit cells, the high cell of the seek offset
* is zero and the low cell is the entire value. * is zero and the low cell is the entire value.
* *
* seek(bootdev, 0, *kernel_sector << 9) * seek(bootdev, 0, *kernel_byte)
*/ */
GET_ABS(prom_seek_name, %o0) GET_ABS(prom_seek_name, %o0)
mov BOOTDEV_REG, %o1
clr %o2 clr %o2
LDX_ABS(kernel_sector, 0x00, %o3) call prom_call_3_1_o1
call prom_call_3_1 LDX_ABS(kernel_byte, 0x00, %o3)
sllx %o3, 9, %o3
/* read(bootdev, *kernel_address, 512) */ /* read(bootdev, *kernel_address, 512) */
GET_ABS(prom_read_name, %o0) GET_ABS(prom_read_name, %o0)
mov BOOTDEV_REG, %o1
LDUW_ABS(kernel_address, 0x00, %o2) LDUW_ABS(kernel_address, 0x00, %o2)
call prom_call_3_1 call prom_call_3_1_o1
mov 512, %o3 mov 512, %o3
LDUW_ABS(kernel_address, 0x00, %o2) LDUW_ABS(kernel_address, 0x00, %o2)
jmpl %o2, %o7 jmpl %o2, %o7
nop nop
1: ba,a 1b
. = _start + GRUB_BOOT_MACHINE_CODE_END . = _start + GRUB_BOOT_MACHINE_CODE_END
/* the last 4 bytes in the sector 0 contain the signature */ /* the last 4 bytes in the sector 0 contain the signature */

View file

@ -19,6 +19,7 @@
#include <grub/boot.h> #include <grub/boot.h>
#include <grub/machine/boot.h> #include <grub/machine/boot.h>
#include <grub/offsets.h>
.text .text
.align 4 .align 4
@ -81,14 +82,14 @@ prom_call:
after_info_block: after_info_block:
sethi %hi(SCRATCH_PAD), %l1 /* OF argument slots */ sethi %hi(SCRATCH_PAD_DISKBOOT), %l1 /* OF argument slots */
GET_ABS(notification_string, %o2) GET_ABS(notification_string, %o2)
call console_write call console_write
mov NOTIFICATION_STRING_LEN, %o3 mov NOTIFICATION_STRING_LEN, %o3
GET_ABS(firstlist - GRUB_BOOT_MACHINE_LIST_SIZE, %l2) GET_ABS(firstlist - GRUB_BOOT_SPARC64_IEEE1275_LIST_SIZE, %l2)
set GRUB_BOOT_MACHINE_IMAGE_ADDRESS, %l3 set GRUB_BOOT_SPARC64_IEEE1275_IMAGE_ADDRESS, %l3
bootloop: bootloop:
lduw [%l2 + 0x08], %o0 lduw [%l2 + 0x08], %o0
brz %o0, bootit brz %o0, bootit
@ -115,7 +116,7 @@ bootloop:
mov NOTIFICATION_STEP_LEN, %o3 mov NOTIFICATION_STEP_LEN, %o3
ba bootloop ba bootloop
sub %l2, GRUB_BOOT_MACHINE_LIST_SIZE, %l2 sub %l2, GRUB_BOOT_SPARC64_IEEE1275_LIST_SIZE, %l2
bootit: bootit:
GET_ABS(prom_close_name, %o0) GET_ABS(prom_close_name, %o0)
@ -127,16 +128,16 @@ bootit:
GET_ABS(notification_done, %o2) GET_ABS(notification_done, %o2)
call console_write call console_write
mov NOTIFICATION_DONE_LEN, %o3 mov NOTIFICATION_DONE_LEN, %o3
sethi %hi(GRUB_BOOT_MACHINE_IMAGE_ADDRESS), %o2 sethi %hi(GRUB_BOOT_SPARC64_IEEE1275_IMAGE_ADDRESS), %o2
jmpl %o2 + %lo(GRUB_BOOT_MACHINE_IMAGE_ADDRESS), %o7 jmpl %o2 + %lo(GRUB_BOOT_SPARC64_IEEE1275_IMAGE_ADDRESS), %o7
mov CIF_REG, %o0 mov CIF_REG, %o4
1: ba,a 1b 1: ba,a 1b
lastlist: lastlist:
.word 0 .word 0
.word 0 .word 0
. = _start + (0x200 - GRUB_BOOT_MACHINE_LIST_SIZE) . = _start + (0x200 - GRUB_BOOT_SPARC64_IEEE1275_LIST_SIZE)
blocklist_default_start: blocklist_default_start:
.word 0 .word 0
.word 2 .word 2

90
bus/bonito.c Normal file
View file

@ -0,0 +1,90 @@
/* bonito.c - PCI bonito interface. */
/*
* 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/pci.h>
#include <grub/misc.h>
static grub_uint32_t base_win[GRUB_MACHINE_PCI_NUM_WIN];
static const grub_size_t sizes_win[GRUB_MACHINE_PCI_NUM_WIN] =
{GRUB_MACHINE_PCI_WIN1_SIZE, GRUB_MACHINE_PCI_WIN_SIZE,
GRUB_MACHINE_PCI_WIN_SIZE};
/* Usage counters. */
static int usage_win[GRUB_MACHINE_PCI_NUM_WIN];
static grub_addr_t addr_win[GRUB_MACHINE_PCI_NUM_WIN] =
{GRUB_MACHINE_PCI_WIN1_ADDR, GRUB_MACHINE_PCI_WIN2_ADDR,
GRUB_MACHINE_PCI_WIN3_ADDR};
static inline void
write_bases (void)
{
int i;
grub_uint32_t reg = 0;
for (i = 0; i < GRUB_MACHINE_PCI_NUM_WIN; i++)
reg |= (((base_win[i] >> GRUB_MACHINE_PCI_WIN_SHIFT)
& GRUB_MACHINE_PCI_WIN_MASK)
>> (i * GRUB_MACHINE_PCI_WIN_MASK_SIZE));
GRUB_MACHINE_PCI_IO_CTRL_REG = reg;
}
volatile void *
grub_pci_device_map_range (grub_pci_device_t dev __attribute__ ((unused)),
grub_addr_t base, grub_size_t size)
{
int i;
grub_addr_t newbase;
/* First try already used registers. */
for (i = 0; i < GRUB_MACHINE_PCI_NUM_WIN; i++)
if (usage_win[i] && base_win[i] <= base
&& base_win[i] + sizes_win[i] > base + size)
{
usage_win[i]++;
return (void *)
(addr_win[i] | (base & GRUB_MACHINE_PCI_WIN_OFFSET_MASK));
}
/* Map new register. */
newbase = base & ~GRUB_MACHINE_PCI_WIN_OFFSET_MASK;
for (i = 0; i < GRUB_MACHINE_PCI_NUM_WIN; i++)
if (!usage_win[i] && newbase <= base
&& newbase + sizes_win[i] > base + size)
{
usage_win[i]++;
base_win[i] = newbase;
write_bases ();
return (void *)
(addr_win[i] | (base & GRUB_MACHINE_PCI_WIN_OFFSET_MASK));
}
grub_fatal ("Out of PCI windows.");
}
void
grub_pci_device_unmap_range (grub_pci_device_t dev __attribute__ ((unused)),
volatile void *mem __attribute__ ((unused)),
grub_size_t size __attribute__ ((unused)))
{
int i;
for (i = 0; i < GRUB_MACHINE_PCI_NUM_WIN; i++)
if (usage_win[i] && addr_win[i]
== (((grub_addr_t) mem) & ~GRUB_MACHINE_PCI_WIN_OFFSET_MASK))
{
usage_win[i]--;
return;
}
grub_fatal ("Tried to unmap not mapped region");
}

215
bus/cs5536.c Normal file
View file

@ -0,0 +1,215 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 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/types.h>
#include <grub/cs5536.h>
#include <grub/pci.h>
#include <grub/time.h>
#include <grub/ata.h>
int
grub_cs5536_find (grub_pci_device_t *devp)
{
int found = 0;
auto int NESTED_FUNC_ATTR hook (grub_pci_device_t dev,
grub_pci_id_t pciid);
int NESTED_FUNC_ATTR hook (grub_pci_device_t dev,
grub_pci_id_t pciid)
{
if (pciid == GRUB_CS5536_PCIID)
{
*devp = dev;
found = 1;
return 1;
}
return 0;
}
grub_pci_iterate (hook);
return found;
}
grub_uint64_t
grub_cs5536_read_msr (grub_pci_device_t dev, grub_uint32_t addr)
{
grub_uint64_t ret = 0;
grub_pci_write (grub_pci_make_address (dev, GRUB_CS5536_MSR_MAILBOX_ADDR),
addr);
ret = (grub_uint64_t)
grub_pci_read (grub_pci_make_address (dev, GRUB_CS5536_MSR_MAILBOX_DATA0));
ret |= (((grub_uint64_t)
grub_pci_read (grub_pci_make_address (dev,
GRUB_CS5536_MSR_MAILBOX_DATA1)))
<< 32);
return ret;
}
void
grub_cs5536_write_msr (grub_pci_device_t dev, grub_uint32_t addr,
grub_uint64_t val)
{
grub_pci_write (grub_pci_make_address (dev, GRUB_CS5536_MSR_MAILBOX_ADDR),
addr);
grub_pci_write (grub_pci_make_address (dev, GRUB_CS5536_MSR_MAILBOX_DATA0),
val & 0xffffffff);
grub_pci_write (grub_pci_make_address (dev, GRUB_CS5536_MSR_MAILBOX_DATA1),
val >> 32);
}
grub_err_t
grub_cs5536_smbus_wait (grub_port_t smbbase)
{
grub_uint64_t start = grub_get_time_ms ();
while (1)
{
grub_uint8_t status;
status = grub_inb (smbbase + GRUB_CS5536_SMB_REG_STATUS);
if (status & GRUB_CS5536_SMB_REG_STATUS_SDAST)
return GRUB_ERR_NONE;
if (status & GRUB_CS5536_SMB_REG_STATUS_BER)
return grub_error (GRUB_ERR_IO, "SM bus error");
if (status & GRUB_CS5536_SMB_REG_STATUS_NACK)
return grub_error (GRUB_ERR_IO, "NACK received");
if (grub_get_time_ms () > start + 40)
return grub_error (GRUB_ERR_IO, "SM stalled");
}
return GRUB_ERR_NONE;
}
grub_err_t
grub_cs5536_read_spd_byte (grub_port_t smbbase, grub_uint8_t dev,
grub_uint8_t addr, grub_uint8_t *res)
{
grub_err_t err;
/* Send START. */
grub_outb (grub_inb (smbbase + GRUB_CS5536_SMB_REG_CTRL1)
| GRUB_CS5536_SMB_REG_CTRL1_START,
smbbase + GRUB_CS5536_SMB_REG_CTRL1);
/* Send device address. */
err = grub_cs5536_smbus_wait (smbbase);
if (err)
return err;
grub_outb (dev << 1, smbbase + GRUB_CS5536_SMB_REG_DATA);
/* Send ACK. */
err = grub_cs5536_smbus_wait (smbbase);
if (err)
return err;
grub_outb (grub_inb (smbbase + GRUB_CS5536_SMB_REG_CTRL1)
| GRUB_CS5536_SMB_REG_CTRL1_ACK,
smbbase + GRUB_CS5536_SMB_REG_CTRL1);
/* Send byte address. */
grub_outb (addr, smbbase + GRUB_CS5536_SMB_REG_DATA);
/* Send START. */
err = grub_cs5536_smbus_wait (smbbase);
if (err)
return err;
grub_outb (grub_inb (smbbase + GRUB_CS5536_SMB_REG_CTRL1)
| GRUB_CS5536_SMB_REG_CTRL1_START,
smbbase + GRUB_CS5536_SMB_REG_CTRL1);
/* Send device address. */
err = grub_cs5536_smbus_wait (smbbase);
if (err)
return err;
grub_outb ((dev << 1) | 1, smbbase + GRUB_CS5536_SMB_REG_DATA);
/* Send STOP. */
err = grub_cs5536_smbus_wait (smbbase);
if (err)
return err;
grub_outb (grub_inb (smbbase + GRUB_CS5536_SMB_REG_CTRL1)
| GRUB_CS5536_SMB_REG_CTRL1_STOP,
smbbase + GRUB_CS5536_SMB_REG_CTRL1);
err = grub_cs5536_smbus_wait (smbbase);
if (err)
return err;
*res = grub_inb (smbbase + GRUB_CS5536_SMB_REG_DATA);
return GRUB_ERR_NONE;
}
grub_err_t
grub_cs5536_init_smbus (grub_pci_device_t dev, grub_uint16_t divisor,
grub_port_t *smbbase)
{
grub_uint64_t smbbar;
smbbar = grub_cs5536_read_msr (dev, GRUB_CS5536_MSR_SMB_BAR);
/* FIXME */
if (!(smbbar & GRUB_CS5536_LBAR_ENABLE))
return grub_error(GRUB_ERR_IO, "SMB controller not enabled\n");
*smbbase = (smbbar & GRUB_CS5536_LBAR_ADDR_MASK) + GRUB_MACHINE_PCI_IO_BASE;
if (divisor < 8)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid divisor");
/* Disable SMB. */
grub_outb (0, *smbbase + GRUB_CS5536_SMB_REG_CTRL2);
/* Disable interrupts. */
grub_outb (0, *smbbase + GRUB_CS5536_SMB_REG_CTRL1);
/* Set as master. */
grub_outb (GRUB_CS5536_SMB_REG_ADDR_MASTER,
*smbbase + GRUB_CS5536_SMB_REG_ADDR);
/* Launch. */
grub_outb (((divisor >> 7) & 0xff), *smbbase + GRUB_CS5536_SMB_REG_CTRL3);
grub_outb (((divisor << 1) & 0xfe) | GRUB_CS5536_SMB_REG_CTRL2_ENABLE,
*smbbase + GRUB_CS5536_SMB_REG_CTRL2);
return GRUB_ERR_NONE;
}
grub_err_t
grub_cs5536_read_spd (grub_port_t smbbase, grub_uint8_t dev,
struct grub_smbus_spd *res)
{
grub_err_t err;
grub_size_t size;
grub_uint8_t b;
grub_size_t ptr;
err = grub_cs5536_read_spd_byte (smbbase, dev, 0, &b);
if (err)
return err;
if (b == 0)
return grub_error (GRUB_ERR_IO, "no SPD found");
size = b;
((grub_uint8_t *) res)[0] = b;
for (ptr = 1; ptr < size; ptr++)
{
err = grub_cs5536_read_spd_byte (smbbase, dev, ptr,
&((grub_uint8_t *) res)[ptr]);
if (err)
return err;
}
return GRUB_ERR_NONE;
}

View file

@ -26,7 +26,7 @@ grub_pci_make_address (grub_pci_device_t dev, int reg)
{ {
grub_pci_address_t ret; grub_pci_address_t ret;
ret.dev = dev; ret.dev = dev;
ret.pos = reg << 2; ret.pos = reg;
return ret; return ret;
} }

View file

@ -19,12 +19,56 @@
#include <grub/dl.h> #include <grub/dl.h>
#include <grub/pci.h> #include <grub/pci.h>
#include <grub/mm.h>
/* FIXME: correctly support 64-bit architectures. */
/* #if GRUB_TARGET_SIZEOF_VOID_P == 4 */
struct grub_pci_dma_chunk *
grub_memalign_dma32 (grub_size_t align, grub_size_t size)
{
return grub_memalign (align, size);
}
void
grub_dma_free (struct grub_pci_dma_chunk *ch)
{
grub_free (ch);
}
/* #endif */
#ifdef GRUB_MACHINE_MIPS_YEELOONG
volatile void *
grub_dma_get_virt (struct grub_pci_dma_chunk *ch)
{
return (void *) ((((grub_uint32_t) ch) & 0x1fffffff) | 0xa0000000);
}
grub_uint32_t
grub_dma_get_phys (struct grub_pci_dma_chunk *ch)
{
return (((grub_uint32_t) ch) & 0x1fffffff) | 0x80000000;
}
#else
volatile void *
grub_dma_get_virt (struct grub_pci_dma_chunk *ch)
{
return (void *) ch;
}
grub_uint32_t
grub_dma_get_phys (struct grub_pci_dma_chunk *ch)
{
return (grub_uint32_t) (grub_addr_t) ch;
}
#endif
grub_pci_address_t grub_pci_address_t
grub_pci_make_address (grub_pci_device_t dev, int reg) grub_pci_make_address (grub_pci_device_t dev, int reg)
{ {
return (1 << 31) | (dev.bus << 16) | (dev.device << 11) return (1 << 31) | (dev.bus << 16) | (dev.device << 11)
| (dev.function << 8) | (reg << 2); | (dev.function << 8) | reg;
} }
void void
@ -35,26 +79,36 @@ grub_pci_iterate (grub_pci_iteratefunc_t hook)
grub_pci_id_t id; grub_pci_id_t id;
grub_uint32_t hdr; grub_uint32_t hdr;
for (dev.bus = 0; dev.bus < 256; dev.bus++) for (dev.bus = 0; dev.bus < GRUB_PCI_NUM_BUS; dev.bus++)
{ {
for (dev.device = 0; dev.device < 32; dev.device++) for (dev.device = 0; dev.device < GRUB_PCI_NUM_DEVICES; dev.device++)
{ {
for (dev.function = 0; dev.function < 8; dev.function++) for (dev.function = 0; dev.function < 8; dev.function++)
{ {
addr = grub_pci_make_address (dev, 0); addr = grub_pci_make_address (dev, GRUB_PCI_REG_PCI_ID);
id = grub_pci_read (addr); id = grub_pci_read (addr);
/* Check if there is a device present. */ /* Check if there is a device present. */
if (id >> 16 == 0xFFFF) if (id >> 16 == 0xFFFF)
continue; continue;
#ifdef GRUB_MACHINE_MIPS_YEELOONG
/* Skip ghosts. */
if (id == GRUB_YEELOONG_OHCI_PCIID
&& dev.function == GRUB_YEELOONG_OHCI_GHOST_FUNCTION)
continue;
if (id == GRUB_YEELOONG_EHCI_PCIID
&& dev.function == GRUB_YEELOONG_EHCI_GHOST_FUNCTION)
continue;
#endif
if (hook (dev, id)) if (hook (dev, id))
return; return;
/* Probe only func = 0 if the device if not multifunction */ /* Probe only func = 0 if the device if not multifunction */
if (dev.function == 0) if (dev.function == 0)
{ {
addr = grub_pci_make_address (dev, 3); addr = grub_pci_make_address (dev, GRUB_PCI_REG_CACHELINE);
hdr = grub_pci_read (addr); hdr = grub_pci_read (addr);
if (!(hdr & 0x800000)) if (!(hdr & 0x800000))
break; break;

View file

@ -105,14 +105,14 @@ grub_usb_root_hub (grub_usb_controller_t controller __attribute__((unused)))
grub_usb_err_t grub_usb_err_t
grub_usb_control_msg (grub_usb_device_t dev, grub_uint8_t reqtype, grub_usb_control_msg (grub_usb_device_t dev, grub_uint8_t reqtype,
grub_uint8_t request, grub_uint16_t value, grub_uint8_t request, grub_uint16_t value,
grub_uint16_t index, grub_size_t size, char *data) grub_uint16_t idx, grub_size_t size, char *data)
{ {
usb_dev_handle *devh; usb_dev_handle *devh;
struct usb_device *d = dev->data; struct usb_device *d = dev->data;
devh = usb_open (d); devh = usb_open (d);
if (usb_control_msg (devh, reqtype, request, if (usb_control_msg (devh, reqtype, request,
value, index, data, size, 20) < 0) value, idx, data, size, 20) < 0)
{ {
usb_close (devh); usb_close (devh);
return GRUB_USB_ERR_STALL; return GRUB_USB_ERR_STALL;

View file

@ -24,8 +24,10 @@
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/pci.h> #include <grub/pci.h>
#include <grub/cpu/pci.h> #include <grub/cpu/pci.h>
#include <grub/i386/io.h> #include <grub/cpu/io.h>
#include <grub/time.h> #include <grub/time.h>
#include <grub/cs5536.h>
#include <grub/loader.h>
struct grub_ohci_hcca struct grub_ohci_hcca
{ {
@ -63,13 +65,15 @@ struct grub_ohci_td
grub_uint32_t buffer_end; grub_uint32_t buffer_end;
} __attribute__((packed)); } __attribute__((packed));
typedef struct grub_ohci_td *grub_ohci_td_t; typedef volatile struct grub_ohci_td *grub_ohci_td_t;
typedef struct grub_ohci_ed *grub_ohci_ed_t; typedef volatile struct grub_ohci_ed *grub_ohci_ed_t;
struct grub_ohci struct grub_ohci
{ {
volatile grub_uint32_t *iobase; volatile grub_uint32_t *iobase;
volatile struct grub_ohci_hcca *hcca; volatile struct grub_ohci_hcca *hcca;
grub_uint32_t hcca_addr;
struct grub_pci_dma_chunk *hcca_chunk;
struct grub_ohci *next; struct grub_ohci *next;
}; };
@ -91,10 +95,32 @@ typedef enum
GRUB_OHCI_REG_BULKCURR, GRUB_OHCI_REG_BULKCURR,
GRUB_OHCI_REG_DONEHEAD, GRUB_OHCI_REG_DONEHEAD,
GRUB_OHCI_REG_FRAME_INTERVAL, GRUB_OHCI_REG_FRAME_INTERVAL,
GRUB_OHCI_REG_PERIODIC_START = 16,
GRUB_OHCI_REG_RHUBA = 18, GRUB_OHCI_REG_RHUBA = 18,
GRUB_OHCI_REG_RHUBPORT = 21 GRUB_OHCI_REG_RHUBPORT = 21,
GRUB_OHCI_REG_LEGACY_CONTROL = 0x100,
GRUB_OHCI_REG_LEGACY_INPUT = 0x104,
GRUB_OHCI_REG_LEGACY_OUTPUT = 0x108,
GRUB_OHCI_REG_LEGACY_STATUS = 0x10c
} grub_ohci_reg_t; } grub_ohci_reg_t;
#define GRUB_OHCI_RHUB_PORT_POWER_MASK 0x300
#define GRUB_OHCI_RHUB_PORT_ALL_POWERED 0x200
#define GRUB_OHCI_REG_FRAME_INTERVAL_FSMPS_MASK 0x8fff0000
#define GRUB_OHCI_REG_FRAME_INTERVAL_FSMPS_SHIFT 16
#define GRUB_OHCI_REG_FRAME_INTERVAL_FI_SHIFT 0
/* XXX: Is this choice of timings sane? */
#define GRUB_OHCI_FSMPS 0x2778
#define GRUB_OHCI_PERIODIC_START 0x257f
#define GRUB_OHCI_FRAME_INTERVAL 0x2edf
#define GRUB_OHCI_SET_PORT_ENABLE (1 << 1)
#define GRUB_OHCI_CLEAR_PORT_ENABLE (1 << 0)
#define GRUB_OHCI_SET_PORT_RESET (1 << 4)
#define GRUB_OHCI_SET_PORT_RESET_STATUS_CHANGE (1 << 20)
static grub_uint32_t static grub_uint32_t
grub_ohci_readreg32 (struct grub_ohci *o, grub_ohci_reg_t reg) grub_ohci_readreg32 (struct grub_ohci *o, grub_ohci_reg_t reg)
{ {
@ -114,51 +140,81 @@ grub_ohci_writereg32 (struct grub_ohci *o,
controller. If this is the case, initialize it. */ controller. If this is the case, initialize it. */
static int NESTED_FUNC_ATTR static int NESTED_FUNC_ATTR
grub_ohci_pci_iter (grub_pci_device_t dev, grub_ohci_pci_iter (grub_pci_device_t dev,
grub_pci_id_t pciid __attribute__((unused))) grub_pci_id_t pciid)
{ {
grub_uint32_t class_code;
grub_uint32_t class;
grub_uint32_t subclass;
grub_uint32_t interf; grub_uint32_t interf;
grub_uint32_t base; grub_uint32_t base;
grub_pci_address_t addr; grub_pci_address_t addr;
struct grub_ohci *o; struct grub_ohci *o;
grub_uint32_t revision; grub_uint32_t revision;
grub_uint32_t frame_interval; int cs5536;
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. */ /* Determine IO base address. */
addr = grub_pci_make_address (dev, 4); grub_dprintf ("ohci", "pciid = %x\n", pciid);
base = grub_pci_read (addr);
if (pciid == GRUB_CS5536_PCIID)
{
grub_uint64_t basereg;
cs5536 = 1;
basereg = grub_cs5536_read_msr (dev, GRUB_CS5536_MSR_USB_OHCI_BASE);
if (!(basereg & GRUB_CS5536_MSR_USB_BASE_MEMORY_ENABLE))
{
/* Shouldn't happen. */
grub_dprintf ("ohci", "No OHCI address is assigned\n");
return 0;
}
base = (basereg & GRUB_CS5536_MSR_USB_BASE_ADDR_MASK);
basereg |= GRUB_CS5536_MSR_USB_BASE_BUS_MASTER;
basereg &= ~GRUB_CS5536_MSR_USB_BASE_PME_ENABLED;
basereg &= ~GRUB_CS5536_MSR_USB_BASE_PME_STATUS;
grub_cs5536_write_msr (dev, GRUB_CS5536_MSR_USB_OHCI_BASE, basereg);
}
else
{
grub_uint32_t class_code;
grub_uint32_t class;
grub_uint32_t subclass;
addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
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;
addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG0);
base = grub_pci_read (addr);
#if 0 #if 0
/* Stop if there is no IO space base address defined. */ /* Stop if there is no IO space base address defined. */
if (! (base & 1)) if (! (base & 1))
return 0; return 0;
#endif #endif
grub_dprintf ("ohci", "class=0x%02x 0x%02x interface 0x%02x\n",
class, subclass, interf);
}
/* Allocate memory for the controller and register it. */ /* Allocate memory for the controller and register it. */
o = grub_malloc (sizeof (*o)); o = grub_malloc (sizeof (*o));
if (! o) if (! o)
return 1; return 1;
o->iobase = (grub_uint32_t *) base; o->iobase = grub_pci_device_map_range (dev, base, 0x800);
grub_dprintf ("ohci", "base=%p\n", o->iobase);
/* Reserve memory for the HCCA. */ /* Reserve memory for the HCCA. */
o->hcca = (struct grub_ohci_hcca *) grub_memalign (256, 256); o->hcca_chunk = grub_memalign_dma32 (256, 256);
if (! o->hcca_chunk)
grub_dprintf ("ohci", "class=0x%02x 0x%02x interface 0x%02x base=%p\n", return 1;
class, subclass, interf, o->iobase); o->hcca = grub_dma_get_virt (o->hcca_chunk);
o->hcca_addr = grub_dma_get_phys (o->hcca_chunk);
/* Check if the OHCI revision is actually 1.0 as supported. */ /* Check if the OHCI revision is actually 1.0 as supported. */
revision = grub_ohci_readreg32 (o, GRUB_OHCI_REG_REVISION); revision = grub_ohci_readreg32 (o, GRUB_OHCI_REG_REVISION);
@ -166,27 +222,116 @@ grub_ohci_pci_iter (grub_pci_device_t dev,
if ((revision & 0xFF) != 0x10) if ((revision & 0xFF) != 0x10)
goto fail; goto fail;
/* Backup the frame interval register. */
frame_interval = grub_ohci_readreg32 (o, GRUB_OHCI_REG_FRAME_INTERVAL); {
grub_uint32_t control;
/* Check SMM/BIOS ownership of OHCI (SMM = USB Legacy Support driver for BIOS) */
control = grub_ohci_readreg32 (o, GRUB_OHCI_REG_CONTROL);
if ((control & 0x100) != 0)
{
unsigned i;
grub_dprintf("ohci", "OHCI is owned by SMM\n");
/* Do change of ownership */
/* Ownership change request */
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CMDSTATUS, (1<<3)); /* XXX: Magic. */
/* Waiting for SMM deactivation */
for (i=0; i < 10; i++)
{
if ((grub_ohci_readreg32 (o, GRUB_OHCI_REG_CONTROL) & 0x100) == 0)
{
grub_dprintf("ohci", "Ownership changed normally.\n");
break;
}
grub_millisleep (100);
}
if (i >= 10)
{
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CONTROL,
grub_ohci_readreg32 (o, GRUB_OHCI_REG_CONTROL) & ~0x100);
grub_dprintf("ohci", "Ownership changing timeout, change forced !\n");
}
}
else if (((control & 0x100) == 0) &&
((control & 0xc0) != 0)) /* Not owned by SMM nor reset */
{
grub_dprintf("ohci", "OHCI is owned by BIOS\n");
/* Do change of ownership - not implemented yet... */
/* In fact we probably need to do nothing ...? */
}
else
{
grub_dprintf("ohci", "OHCI is not owned by SMM nor BIOS\n");
/* We can setup OHCI. */
}
}
/* Suspend the OHCI by issuing a reset. */ /* Suspend the OHCI by issuing a reset. */
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CMDSTATUS, 1); /* XXX: Magic. */ grub_ohci_writereg32 (o, GRUB_OHCI_REG_CMDSTATUS, 1); /* XXX: Magic. */
grub_millisleep (1); grub_millisleep (1);
grub_dprintf ("ohci", "OHCI reset\n"); grub_dprintf ("ohci", "OHCI reset\n");
/* Restore the frame interval register. */ grub_ohci_writereg32 (o, GRUB_OHCI_REG_FRAME_INTERVAL,
grub_ohci_writereg32 (o, GRUB_OHCI_REG_FRAME_INTERVAL, frame_interval); (GRUB_OHCI_FSMPS
<< GRUB_OHCI_REG_FRAME_INTERVAL_FSMPS_SHIFT)
| (GRUB_OHCI_FRAME_INTERVAL
<< GRUB_OHCI_REG_FRAME_INTERVAL_FI_SHIFT));
grub_ohci_writereg32 (o, GRUB_OHCI_REG_PERIODIC_START,
GRUB_OHCI_PERIODIC_START);
/* Setup the HCCA. */ /* Setup the HCCA. */
grub_ohci_writereg32 (o, GRUB_OHCI_REG_HCCA, (grub_uint32_t) o->hcca); o->hcca->donehead = 0;
grub_ohci_writereg32 (o, GRUB_OHCI_REG_HCCA, o->hcca_addr);
grub_dprintf ("ohci", "OHCI HCCA\n"); grub_dprintf ("ohci", "OHCI HCCA\n");
/* Misc. pre-sets. */
o->hcca->donehead = 0;
grub_ohci_writereg32 (o, GRUB_OHCI_REG_INTSTATUS, 0x7f); /* Clears everything */
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CONTROLHEAD, 0);
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CONTROLCURR, 0);
grub_ohci_writereg32 (o, GRUB_OHCI_REG_BULKHEAD, 0);
grub_ohci_writereg32 (o, GRUB_OHCI_REG_BULKCURR, 0);
/* Check OHCI Legacy Support */
if ((revision & 0x100) != 0)
{
grub_dprintf ("ohci", "Legacy Support registers detected\n");
grub_dprintf ("ohci", "Current state of legacy control reg.: 0x%04x\n",
grub_ohci_readreg32 (o, GRUB_OHCI_REG_LEGACY_CONTROL));
grub_ohci_writereg32 (o, GRUB_OHCI_REG_LEGACY_CONTROL,
(grub_ohci_readreg32 (o, GRUB_OHCI_REG_LEGACY_CONTROL)) & ~1);
grub_dprintf ("ohci", "OHCI Legacy Support disabled.\n");
}
/* Enable the OHCI. */ /* Enable the OHCI. */
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CONTROL, grub_ohci_writereg32 (o, GRUB_OHCI_REG_CONTROL,
(2 << 6)); (2 << 6));
grub_dprintf ("ohci", "OHCI enable: 0x%02x\n", grub_dprintf ("ohci", "OHCI enable: 0x%02x\n",
(grub_ohci_readreg32 (o, GRUB_OHCI_REG_CONTROL) >> 6) & 3); (grub_ohci_readreg32 (o, GRUB_OHCI_REG_CONTROL) >> 6) & 3);
/* Power on all ports */
grub_ohci_writereg32 (o, GRUB_OHCI_REG_RHUBA,
(grub_ohci_readreg32 (o, GRUB_OHCI_REG_RHUBA)
& ~GRUB_OHCI_RHUB_PORT_POWER_MASK)
| GRUB_OHCI_RHUB_PORT_ALL_POWERED);
/* Wait for stable power (100ms) and stable attachment (100ms) */
/* I.e. minimum wait time should be probably 200ms. */
/* We assume that device is attached when ohci is loaded. */
/* Some devices take long time to power-on or indicate attach. */
/* Here is some experimental value which should probably mostly work. */
/* Cameras with manual USB mode selection and maybe some other similar
* devices will not work in some cases - they are repowered during
* ownership change and then they are starting slowly and mostly they
* are wanting select proper mode again...
* The same situation can be on computers where BIOS not set-up OHCI
* to be at least powered USB bus (maybe it is Yeelong case...?)
* Possible workaround could be for example some prompt
* for user with confirmation of proper USB device connection.
* Another workaround - "rmmod usbms", "rmmod ohci", proper start
* and configuration of USB device and then "insmod ohci"
* and "insmod usbms". */
grub_millisleep (500);
/* Link to ohci now that initialisation is successful. */ /* Link to ohci now that initialisation is successful. */
o->next = ohci; o->next = ohci;
ohci = o; ohci = o;
@ -195,10 +340,10 @@ grub_ohci_pci_iter (grub_pci_device_t dev,
fail: fail:
if (o) if (o)
grub_free ((void *) o->hcca); grub_dma_free (o->hcca_chunk);
grub_free (o); grub_free (o);
return 1; return 0;
} }
@ -229,7 +374,7 @@ grub_ohci_iterate (int (*hook) (grub_usb_controller_t dev))
static void static void
grub_ohci_transaction (grub_ohci_td_t td, grub_ohci_transaction (grub_ohci_td_t td,
grub_transfer_type_t type, unsigned int toggle, grub_transfer_type_t type, unsigned int toggle,
grub_size_t size, char *data) grub_size_t size, grub_uint32_t data)
{ {
grub_uint32_t token; grub_uint32_t token;
grub_uint32_t buffer; grub_uint32_t buffer;
@ -254,20 +399,38 @@ grub_ohci_transaction (grub_ohci_td_t td,
break; break;
} }
#if 0 /* Always generate interrupt */
/* Generate no interrupts. */ /* Generate no interrupts. */
token |= 7 << 21; token |= 7 << 21;
#endif
/* Set the token. */ /* Set the token. */
token |= toggle << 24; token |= toggle << 24;
token |= 1 << 25; token |= 1 << 25;
buffer = (grub_uint32_t) data; /* Set "Not accessed" error code */
token |= 15 << 28;
buffer = data;
buffer_end = buffer + size - 1; buffer_end = buffer + size - 1;
/* Set correct buffer values in TD if zero transfer occurs */
if (size)
{
buffer = (grub_uint32_t) data;
buffer_end = buffer + size - 1;
td->buffer = grub_cpu_to_le32 (buffer);
td->buffer_end = grub_cpu_to_le32 (buffer_end);
}
else
{
td->buffer = 0;
td->buffer_end = 0;
}
/* Set the rest of TD */
td->token = grub_cpu_to_le32 (token); td->token = grub_cpu_to_le32 (token);
td->buffer = grub_cpu_to_le32 (buffer);
td->next_td = 0; td->next_td = 0;
td->buffer_end = grub_cpu_to_le32 (buffer_end);
} }
static grub_usb_err_t static grub_usb_err_t
@ -276,7 +439,10 @@ grub_ohci_transfer (grub_usb_controller_t dev,
{ {
struct grub_ohci *o = (struct grub_ohci *) dev->data; struct grub_ohci *o = (struct grub_ohci *) dev->data;
grub_ohci_ed_t ed; grub_ohci_ed_t ed;
grub_uint32_t ed_addr;
struct grub_pci_dma_chunk *ed_chunk, *td_list_chunk;
grub_ohci_td_t td_list; grub_ohci_td_t td_list;
grub_uint32_t td_list_addr;
grub_uint32_t target; grub_uint32_t target;
grub_uint32_t td_tail; grub_uint32_t td_tail;
grub_uint32_t td_head; grub_uint32_t td_head;
@ -284,20 +450,30 @@ grub_ohci_transfer (grub_usb_controller_t dev,
grub_uint32_t control; grub_uint32_t control;
grub_usb_err_t err; grub_usb_err_t err;
int i; int i;
grub_uint64_t maxtime;
int err_timeout = 0;
int err_unrec = 0;
grub_uint32_t intstatus;
grub_uint32_t tderr_addr = 0;
/* Allocate an Endpoint Descriptor. */ /* Allocate an Endpoint Descriptor. */
ed = grub_memalign (16, sizeof (*ed)); ed_chunk = grub_memalign_dma32 (256, sizeof (*ed));
if (! ed) if (! ed_chunk)
return GRUB_USB_ERR_INTERNAL; return GRUB_USB_ERR_INTERNAL;
ed = grub_dma_get_virt (ed_chunk);
ed_addr = grub_dma_get_phys (ed_chunk);
td_list = grub_memalign (16, sizeof (*td_list) * (transfer->transcnt + 1)); td_list_chunk = grub_memalign_dma32 (256, sizeof (*td_list)
if (! td_list) * (transfer->transcnt + 1));
if (! td_list_chunk)
{ {
grub_free ((void *) ed); grub_dma_free (ed_chunk);
return GRUB_USB_ERR_INTERNAL; return GRUB_USB_ERR_INTERNAL;
} }
td_list = grub_dma_get_virt (td_list_chunk);
td_list_addr = grub_dma_get_phys (td_list_chunk);
grub_dprintf ("ohci", "alloc=%p\n", td_list); grub_dprintf ("ohci", "alloc=%p/0x%x\n", td_list, td_list_addr);
/* Setup all Transfer Descriptors. */ /* Setup all Transfer Descriptors. */
for (i = 0; i < transfer->transcnt; i++) for (i = 0; i < transfer->transcnt; i++)
@ -307,16 +483,31 @@ grub_ohci_transfer (grub_usb_controller_t dev,
grub_ohci_transaction (&td_list[i], tr->pid, tr->toggle, grub_ohci_transaction (&td_list[i], tr->pid, tr->toggle,
tr->size, tr->data); tr->size, tr->data);
td_list[i].next_td = grub_cpu_to_le32 (&td_list[i + 1]); td_list[i].next_td = grub_cpu_to_le32 (td_list_addr
+ (i + 1) * sizeof (td_list[0]));
} }
#if 0 /* Better will be enable interrupt on all TDs. */
/* The last-1 TD token we should change to enable interrupt when TD finishes.
* As OHCI interrupts are disabled, it does only setting of WDH bit in
* HcInterruptStatus register - and that is what we want to safely detect
* normal end of all transactions. */
td_list[transfer->transcnt - 1].token &= ~(7 << 21);
#endif
td_list[transfer->transcnt].token = 0;
td_list[transfer->transcnt].buffer = 0;
td_list[transfer->transcnt].buffer_end = 0;
td_list[transfer->transcnt].next_td =
(grub_uint32_t) &td_list[transfer->transcnt];
/* Setup the Endpoint Descriptor. */ /* Setup the Endpoint Descriptor. */
/* Set the device address. */ /* Set the device address. */
target = transfer->devaddr; target = transfer->devaddr;
/* Set the endpoint. */ /* Set the endpoint. It should be masked, we need 4 bits only. */
target |= transfer->endpoint << 7; target |= (transfer->endpoint & 15) << 7;
/* Set the device speed. */ /* Set the device speed. */
target |= (transfer->dev->speed == GRUB_USB_SPEED_LOW) << 13; target |= (transfer->dev->speed == GRUB_USB_SPEED_LOW) << 13;
@ -324,9 +515,9 @@ grub_ohci_transfer (grub_usb_controller_t dev,
/* Set the maximum packet size. */ /* Set the maximum packet size. */
target |= transfer->max << 16; target |= transfer->max << 16;
td_head = (grub_uint32_t) td_list; td_head = td_list_addr;
td_tail = (grub_uint32_t) &td_list[transfer->transcnt]; td_tail = td_list_addr + transfer->transcnt * sizeof (*td_list);
ed->target = grub_cpu_to_le32 (target); ed->target = grub_cpu_to_le32 (target);
ed->td_head = grub_cpu_to_le32 (td_head); ed->td_head = grub_cpu_to_le32 (td_head);
@ -335,6 +526,30 @@ grub_ohci_transfer (grub_usb_controller_t dev,
grub_dprintf ("ohci", "program OHCI\n"); grub_dprintf ("ohci", "program OHCI\n");
/* 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 &= ~(3 << 1);
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CMDSTATUS, status);
/* Now we should wait for start of next frame. Because we are not using
* interrupt, we reset SF bit and wait when it goes to 1. */
/* SF bit reset. (SF bit indicates Start Of Frame (SOF) packet) */
grub_ohci_writereg32 (o, GRUB_OHCI_REG_INTSTATUS, (1<<2));
/* Wait for new SOF */
while ((grub_ohci_readreg32 (o, GRUB_OHCI_REG_INTSTATUS) & 0x4) == 0);
/* Now it should be safe to change CONTROL and BULK lists. */
/* This we do for safety's sake - it should be done in previous call
* of grub_ohci_transfer and nobody should change it in meantime...
* It should be done before start of control or bulk OHCI list. */
o->hcca->donehead = 0;
grub_ohci_writereg32 (o, GRUB_OHCI_REG_INTSTATUS, (1 << 1)); /* Clears WDH */
/* Program the OHCI to actually transfer. */ /* Program the OHCI to actually transfer. */
switch (transfer->type) switch (transfer->type)
{ {
@ -342,24 +557,22 @@ grub_ohci_transfer (grub_usb_controller_t dev,
{ {
grub_dprintf ("ohci", "add to bulk list\n"); grub_dprintf ("ohci", "add to bulk list\n");
status = grub_ohci_readreg32 (o, GRUB_OHCI_REG_CMDSTATUS); /* Set BulkList Head and Current */
control = grub_ohci_readreg32 (o, GRUB_OHCI_REG_CONTROL); grub_ohci_writereg32 (o, GRUB_OHCI_REG_BULKHEAD, ed_addr);
grub_ohci_writereg32 (o, GRUB_OHCI_REG_BULKCURR, 0);
/* Disable the Control and Bulk lists. */ #define GRUB_OHCI_REG_CONTROL_BULK_ENABLE (1 << 5)
control &= ~(3 << 4); #define GRUB_OHCI_REG_CONTROL_CONTROL_ENABLE (1 << 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. */ /* Enable the Bulk list. */
control |= 1 << 5; control = grub_ohci_readreg32 (o, GRUB_OHCI_REG_CONTROL);
control |= GRUB_OHCI_REG_CONTROL_BULK_ENABLE;
control &= ~GRUB_OHCI_REG_CONTROL_CONTROL_ENABLE;
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CONTROL, control); grub_ohci_writereg32 (o, GRUB_OHCI_REG_CONTROL, control);
/* Set BulkListFilled. */ /* Set BulkListFilled. */
status = grub_ohci_readreg32 (o, GRUB_OHCI_REG_CMDSTATUS);
status |= 1 << 2; status |= 1 << 2;
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CMDSTATUS, status); grub_ohci_writereg32 (o, GRUB_OHCI_REG_CMDSTATUS, status);
@ -369,24 +582,14 @@ grub_ohci_transfer (grub_usb_controller_t dev,
case GRUB_USB_TRANSACTION_TYPE_CONTROL: case GRUB_USB_TRANSACTION_TYPE_CONTROL:
{ {
grub_dprintf ("ohci", "add to control list\n"); 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. */ /* Set ControlList Head and Current */
control &= ~(3 << 4); grub_ohci_writereg32 (o, GRUB_OHCI_REG_CONTROLHEAD, ed_addr);
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CONTROL, control); grub_ohci_writereg32 (o, GRUB_OHCI_REG_CONTROLCURR, 0);
/* 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. */ /* Enable the Control list. */
control |= 1 << 4; control |= GRUB_OHCI_REG_CONTROL_CONTROL_ENABLE;
control &= ~GRUB_OHCI_REG_CONTROL_BULK_ENABLE;
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CONTROL, control); grub_ohci_writereg32 (o, GRUB_OHCI_REG_CONTROL, control);
/* Set ControlListFilled. */ /* Set ControlListFilled. */
@ -397,37 +600,138 @@ grub_ohci_transfer (grub_usb_controller_t dev,
} }
grub_dprintf ("ohci", "wait for completion\n"); grub_dprintf ("ohci", "wait for completion\n");
grub_dprintf ("ohci", "control=0x%02x status=0x%02x\n", grub_dprintf ("ohci", "begin: control=0x%02x status=0x%02x\n",
grub_ohci_readreg32 (o, GRUB_OHCI_REG_CONTROL), grub_ohci_readreg32 (o, GRUB_OHCI_REG_CONTROL),
grub_ohci_readreg32 (o, GRUB_OHCI_REG_CMDSTATUS)); grub_ohci_readreg32 (o, GRUB_OHCI_REG_CMDSTATUS));
grub_dprintf ("ohci","intstatus=0x%02x\n",
grub_ohci_readreg32 (o, GRUB_OHCI_REG_INTSTATUS));
/* Safety measure to avoid a hang. */
maxtime = grub_get_time_ms () + 1000;
/* Wait until the transfer is completed or STALLs. */ /* Wait until the transfer is completed or STALLs. */
while ((ed->td_head & ~0xf) != (ed->td_tail & ~0xf)) do
{ {
grub_cpu_idle (); /* Check transfer status */
intstatus = grub_ohci_readreg32 (o, GRUB_OHCI_REG_INTSTATUS);
if ((intstatus & 0x2) != 0)
{
grub_dprintf ("ohci", "Current HccaDoneHead=0x%08x\n",
o->hcca->donehead);
/* Remember last successful TD */
tderr_addr = grub_le_to_cpu32 (o->hcca->donehead) & ~0xf;
/* Reset DoneHead */
o->hcca->donehead = 0;
grub_ohci_writereg32 (o, GRUB_OHCI_REG_INTSTATUS, (1 << 1));
/* if TD is last, finish */
if (tderr_addr == td_list_addr
+ sizeof (td_list[0]) * (transfer->transcnt - 1))
break;
continue;
}
grub_dprintf ("ohci", "head=0x%02x tail=0x%02x\n", ed->td_head, ed->td_tail); if ((intstatus & 0x10) != 0)
{ /* Unrecoverable error - only reset can help...! */
err_unrec = 1;
break;
}
/* Detected a STALL. */ /* Detected a HALT. */
if (ed->td_head & 1) if (grub_le_to_cpu32 (ed->td_head) & 1)
break;
/* Timeout ? */
if (grub_get_time_ms () > maxtime)
{
/* Disable the Control and Bulk lists. */
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CONTROL,
grub_ohci_readreg32 (o, GRUB_OHCI_REG_CONTROL) & ~(3 << 4));
err_timeout = 1;
break;
}
if ((ed->td_head & ~0xf) == (ed->td_tail & ~0xf))
break; break;
grub_cpu_idle ();
} }
while (1);
grub_dprintf ("ohci", "complete\n"); grub_dprintf ("ohci", "end: control=0x%02x status=0x%02x\n",
grub_ohci_readreg32 (o, GRUB_OHCI_REG_CONTROL),
grub_ohci_readreg32 (o, GRUB_OHCI_REG_CMDSTATUS));
grub_dprintf ("ohci", "intstatus=0x%02x\n",
grub_ohci_readreg32 (o, GRUB_OHCI_REG_INTSTATUS));
/* if (ed->td_head & 1) */ if (!tderr_addr)
/* err = GRUB_USB_ERR_STALL; */ {
/* else if (ed->td */ /* It means that something wrong happened,
* it could be:
* - timeout and no TD processed
* - some or unrecoverable error and no TD processed
* - something unexpected... :-( */
/* Try look into DONEHEAD reg., but there should be also zero */
grub_dprintf("ohci", "HCCA DoneHead is zero, something is bad!\n");
tderr_addr = grub_ohci_readreg32 (o, GRUB_OHCI_REG_DONEHEAD) & ~0xf;
}
/* Remember last processed transaction (TD) - it is necessary for
* proper setting of toggle bit in next transaction. */
transfer->last_trans = ((tderr_addr - td_list_addr) / sizeof (*td_list));
grub_dprintf("ohci", "tderr_addr=0x%x, td_list_addr=0x%x,\n",
tderr_addr, td_list_addr);
if ((ed->td_head & ~0xf) == (ed->td_tail & ~0xf))
transfer->last_trans = transfer->transcnt - 1;
if (ed->td_head & 1) /* Check correct value in last_trans */
/* It could happen if timeout happens and no TD was retired */
if (transfer->last_trans >= transfer->transcnt || !tderr_addr)
{
grub_dprintf("ohci", "tderr==0 or out of TDs range!\n");
grub_dprintf("ohci", "last_trans=%d, transcnt=%d\n",
transfer->last_trans, transfer->transcnt);
/* We should set something valid... */
transfer->last_trans = -1; /* Probably no TD done */
tderr_addr = td_list_addr;
}
/* In case of timeout do not detect error from TD */
if (err_timeout)
{
err = GRUB_ERR_TIMEOUT;
grub_dprintf("ohci", "Timeout, target=%08x, head=%08x\n",
grub_le_to_cpu32(ed->target),
grub_le_to_cpu32(ed->td_head));
grub_dprintf("ohci", "tail=%08x, next=%08x\n",
grub_le_to_cpu32(ed->td_tail),
grub_le_to_cpu32(ed->next_ed));
}
/* In case of unrecoverable error do not detect error from TD */
else if (err_unrec)
{
err = GRUB_USB_ERR_UNRECOVERABLE;
grub_dprintf("ohci",
"Unrecoverable error, target=%08x, head=%08x\n",
grub_le_to_cpu32(ed->target),
grub_le_to_cpu32(ed->td_head));
grub_dprintf("ohci", "tail=%08x, next=%08x\n",
grub_le_to_cpu32(ed->td_tail),
grub_le_to_cpu32(ed->next_ed));
}
else if (grub_le_to_cpu32 (ed->td_head) & 1)
{ {
grub_uint8_t errcode; grub_uint8_t errcode;
grub_ohci_td_t tderr; grub_ohci_td_t tderr = NULL;
tderr = (grub_ohci_td_t) grub_ohci_readreg32 (o, transfer->last_trans--;
GRUB_OHCI_REG_DONEHEAD);
errcode = tderr->token >> 28; tderr = (grub_ohci_td_t) ((char *) td_list
+ (tderr_addr - td_list_addr));
errcode = grub_le_to_cpu32 (tderr->token) >> 28;
grub_dprintf ("ohci", "OHCI errcode=0x%02x\n", errcode);
switch (errcode) switch (errcode)
{ {
@ -473,11 +777,17 @@ grub_ohci_transfer (grub_usb_controller_t dev,
case 8: case 8:
/* XXX: Data overrun error. */ /* XXX: Data overrun error. */
err = GRUB_USB_ERR_DATA; err = GRUB_USB_ERR_DATA;
grub_dprintf ("ohci", "Overrun, failed TD address: %p, index: %d\n",
tderr, transfer->last_trans);
break; break;
case 9: case 9:
/* XXX: Data underrun error. */ /* XXX: Data underrun error. */
err = GRUB_USB_ERR_DATA; err = GRUB_USB_ERR_DATA;
grub_dprintf ("ohci", "Underrun, failed TD address: %p, index: %d\n",
tderr, transfer->last_trans);
grub_dprintf ("ohci", "Underrun, number of not transferred bytes: %d\n",
1 + grub_le_to_cpu32 (tderr->buffer_end) - grub_le_to_cpu32 (tderr->buffer));
break; break;
case 10: case 10:
@ -515,12 +825,58 @@ grub_ohci_transfer (grub_usb_controller_t dev,
/* Clear BulkListFilled and ControlListFilled. */ /* Clear BulkListFilled and ControlListFilled. */
status = grub_ohci_readreg32 (o, GRUB_OHCI_REG_CMDSTATUS); status = grub_ohci_readreg32 (o, GRUB_OHCI_REG_CMDSTATUS);
status &= ~((1 << 2) | (1 << 3)); status &= ~(3 << 1);
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CMDSTATUS, status); grub_ohci_writereg32 (o, GRUB_OHCI_REG_CMDSTATUS, status);
/* Set ED to be skipped - for safety */
ed->target |= grub_cpu_to_le32 (1 << 14);
/* Now we should wait for start of next frame.
* It is necessary because we will invalidate pointer to ED and it
* can be on OHCI active till SOF!
* Because we are not using interrupt, we reset SF bit and wait when
* it goes to 1. */
/* SF bit reset. (SF bit indicates Start Of Frame (SOF) packet) */
grub_ohci_writereg32 (o, GRUB_OHCI_REG_INTSTATUS, (1<<2));
/* Wait for new SOF */
while (((grub_ohci_readreg32 (o, GRUB_OHCI_REG_INTSTATUS) & 0x4) == 0)
&& !err_unrec);
/* Now it should be safe to change CONTROL and BULK lists. */
/* Important cleaning. */
o->hcca->donehead = 0;
grub_ohci_writereg32 (o, GRUB_OHCI_REG_INTSTATUS, (1 << 1)); /* Clears WDH */
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CONTROLHEAD, 0);
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CONTROLCURR, 0);
grub_ohci_writereg32 (o, GRUB_OHCI_REG_BULKHEAD, 0);
grub_ohci_writereg32 (o, GRUB_OHCI_REG_BULKCURR, 0);
/* XXX */ if (err_unrec)
grub_free (td_list); {
grub_free (ed); /* Do OHCI reset in case of unrecoverable error - maybe we will need
* do more - re-enumerate bus etc. (?) */
/* Suspend the OHCI by issuing a reset. */
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CMDSTATUS, 1); /* XXX: Magic. */
grub_millisleep (1);
grub_dprintf ("ohci", "Unrecoverable error - OHCI reset\n");
/* Misc. resets. */
o->hcca->donehead = 0;
grub_ohci_writereg32 (o, GRUB_OHCI_REG_INTSTATUS, 0x7f); /* Clears everything */
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CONTROLHEAD, 0);
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CONTROLCURR, 0);
grub_ohci_writereg32 (o, GRUB_OHCI_REG_BULKHEAD, 0);
grub_ohci_writereg32 (o, GRUB_OHCI_REG_BULKCURR, 0);
/* Enable the OHCI. */
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CONTROL, (2 << 6));
}
grub_dprintf ("ohci", "OHCI finished, freeing, err=0x%02x\n", err);
grub_dma_free (td_list_chunk);
grub_dma_free (ed_chunk);
return err; return err;
} }
@ -530,28 +886,30 @@ grub_ohci_portstatus (grub_usb_controller_t dev,
unsigned int port, unsigned int enable) unsigned int port, unsigned int enable)
{ {
struct grub_ohci *o = (struct grub_ohci *) dev->data; struct grub_ohci *o = (struct grub_ohci *) dev->data;
grub_uint32_t status;
/* Reset the port. */ grub_dprintf ("ohci", "begin of portstatus=0x%02x\n",
status = grub_ohci_readreg32 (o, GRUB_OHCI_REG_RHUBPORT + port); 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. */ grub_ohci_writereg32 (o, GRUB_OHCI_REG_RHUBPORT + port,
status = grub_ohci_readreg32 (o, GRUB_OHCI_REG_RHUBPORT + port); GRUB_OHCI_SET_PORT_RESET);
status |= (1 << 20); /* XXX: Magic. */ grub_millisleep (50); /* For root hub should be nominaly 50ms */
grub_ohci_writereg32 (o, GRUB_OHCI_REG_RHUBPORT + port, status);
/* End the reset signaling. */
grub_ohci_writereg32 (o, GRUB_OHCI_REG_RHUBPORT + port,
GRUB_OHCI_SET_PORT_RESET_STATUS_CHANGE);
grub_millisleep (10); grub_millisleep (10);
/* Enable the port. */ if (enable)
status = grub_ohci_readreg32 (o, GRUB_OHCI_REG_RHUBPORT + port); grub_ohci_writereg32 (o, GRUB_OHCI_REG_RHUBPORT + port,
status |= (enable << 1); /* XXX: Magic. */ GRUB_OHCI_SET_PORT_ENABLE);
grub_ohci_writereg32 (o, GRUB_OHCI_REG_RHUBPORT + port, status); else
grub_ohci_writereg32 (o, GRUB_OHCI_REG_RHUBPORT + port,
status = grub_ohci_readreg32 (o, GRUB_OHCI_REG_RHUBPORT + port); GRUB_OHCI_CLEAR_PORT_ENABLE);
grub_dprintf ("ohci", "portstatus=0x%02x\n", status); grub_millisleep (10);
grub_dprintf ("ohci", "end of portstatus=0x%02x\n",
grub_ohci_readreg32 (o, GRUB_OHCI_REG_RHUBPORT + port));
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
} }
@ -587,6 +945,42 @@ grub_ohci_hubports (grub_usb_controller_t dev)
return portinfo & 0xFF; return portinfo & 0xFF;
} }
static grub_err_t
grub_ohci_fini_hw (int noreturn __attribute__ ((unused)))
{
struct grub_ohci *o;
for (o = ohci; o; o = o->next)
{
int i, nports = grub_ohci_readreg32 (o, GRUB_OHCI_REG_RHUBA) & 0xff;
for (i = 0; i < nports; i++)
grub_ohci_writereg32 (o, GRUB_OHCI_REG_RHUBPORT + i,
GRUB_OHCI_CLEAR_PORT_ENABLE);
grub_ohci_writereg32 (o, GRUB_OHCI_REG_HCCA, 0);
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CONTROLHEAD, 0);
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CONTROLCURR, 0);
grub_ohci_writereg32 (o, GRUB_OHCI_REG_BULKHEAD, 0);
grub_ohci_writereg32 (o, GRUB_OHCI_REG_BULKCURR, 0);
grub_ohci_writereg32 (o, GRUB_OHCI_REG_DONEHEAD, 0);
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CONTROL, 0);
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CMDSTATUS, 1);
}
grub_millisleep (10);
return GRUB_ERR_NONE;
}
static grub_err_t
grub_ohci_restore_hw (void)
{
struct grub_ohci *o;
for (o = ohci; o; o = o->next)
grub_ohci_writereg32 (o, GRUB_OHCI_REG_HCCA, o->hcca_addr);
return GRUB_ERR_NONE;
}
static struct grub_usb_controller_dev usb_controller = static struct grub_usb_controller_dev usb_controller =
@ -603,9 +997,12 @@ GRUB_MOD_INIT(ohci)
{ {
grub_ohci_inithw (); grub_ohci_inithw ();
grub_usb_controller_dev_register (&usb_controller); grub_usb_controller_dev_register (&usb_controller);
grub_loader_register_preboot_hook (grub_ohci_fini_hw, grub_ohci_restore_hw,
GRUB_LOADER_PREBOOT_HOOK_PRIO_DISK);
} }
GRUB_MOD_FINI(ohci) GRUB_MOD_FINI(ohci)
{ {
grub_ohci_fini_hw (0);
grub_usb_controller_dev_unregister (&usb_controller); grub_usb_controller_dev_unregister (&usb_controller);
} }

View file

@ -150,7 +150,7 @@ grub_uhci_pci_iter (grub_pci_device_t dev,
struct grub_uhci *u; struct grub_uhci *u;
int i; int i;
addr = grub_pci_make_address (dev, 2); addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
class_code = grub_pci_read (addr) >> 8; class_code = grub_pci_read (addr) >> 8;
interf = class_code & 0xFF; interf = class_code & 0xFF;
@ -162,7 +162,7 @@ grub_uhci_pci_iter (grub_pci_device_t dev,
return 0; return 0;
/* Determine IO base address. */ /* Determine IO base address. */
addr = grub_pci_make_address (dev, 8); addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG4);
base = grub_pci_read (addr); base = grub_pci_read (addr);
/* Stop if there is no IO space base address defined. */ /* Stop if there is no IO space base address defined. */
if (! (base & 1)) if (! (base & 1))
@ -174,14 +174,15 @@ grub_uhci_pci_iter (grub_pci_device_t dev,
return 1; return 1;
u->iobase = base & GRUB_UHCI_IOMASK; 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. */ /* Reserve a page for the frame list. */
u->framelist = grub_memalign (4096, 4096); u->framelist = grub_memalign (4096, 4096);
if (! u->framelist) if (! u->framelist)
goto fail; goto fail;
grub_dprintf ("uhci", "class=0x%02x 0x%02x interface 0x%02x base=0x%x framelist=%p\n",
class, subclass, interf, u->iobase, u->framelist);
/* The framelist pointer of UHCI is only 32 bits, make sure this /* The framelist pointer of UHCI is only 32 bits, make sure this
code works on on 64 bits architectures. */ code works on on 64 bits architectures. */
#if GRUB_CPU_SIZEOF_VOID_P == 8 #if GRUB_CPU_SIZEOF_VOID_P == 8
@ -221,6 +222,9 @@ grub_uhci_pci_iter (grub_pci_device_t dev,
} }
#endif #endif
grub_dprintf ("uhci", "QH=%p, TD=%p\n",
u->qh, u->td);
/* Link all Transfer Descriptors in a list of available Transfer /* Link all Transfer Descriptors in a list of available Transfer
Descriptors. */ Descriptors. */
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
@ -328,13 +332,20 @@ grub_free_td (struct grub_uhci *u, grub_uhci_td_t td)
} }
static void static void
grub_free_queue (struct grub_uhci *u, grub_uhci_td_t td) grub_free_queue (struct grub_uhci *u, grub_uhci_td_t td,
grub_usb_transfer_t transfer)
{ {
/* Free the TDs in this queue. */ int i; /* Index of TD in transfer */
while (td)
/* Free the TDs in this queue and set last_trans. */
for (i=0; td; i++)
{ {
grub_uhci_td_t tdprev; grub_uhci_td_t tdprev;
/* Check state of TD and possibly set last_trans */
if (transfer && (td->linkptr & 1))
transfer->last_trans = i;
/* Unlink the queue. */ /* Unlink the queue. */
tdprev = td; tdprev = td;
td = (grub_uhci_td_t) td->linkptr2; td = (grub_uhci_td_t) td->linkptr2;
@ -380,7 +391,7 @@ static grub_uhci_td_t
grub_uhci_transaction (struct grub_uhci *u, unsigned int endp, grub_uhci_transaction (struct grub_uhci *u, unsigned int endp,
grub_transfer_type_t type, unsigned int addr, grub_transfer_type_t type, unsigned int addr,
unsigned int toggle, grub_size_t size, unsigned int toggle, grub_size_t size,
char *data) grub_uint32_t data)
{ {
grub_uhci_td_t td; grub_uhci_td_t td;
static const unsigned int tf[] = { 0x69, 0xE1, 0x2D }; static const unsigned int tf[] = { 0x69, 0xE1, 0x2D };
@ -398,7 +409,7 @@ grub_uhci_transaction (struct grub_uhci *u, unsigned int endp,
} }
grub_dprintf ("uhci", grub_dprintf ("uhci",
"transaction: endp=%d, type=%d, addr=%d, toggle=%d, size=%d data=%p td=%p\n", "transaction: endp=%d, type=%d, addr=%d, toggle=%d, size=%d data=0x%x td=%p\n",
endp, type, addr, toggle, size, data, td); endp, type, addr, toggle, size, data, td);
/* Don't point to any TD, just terminate. */ /* Don't point to any TD, just terminate. */
@ -418,7 +429,7 @@ grub_uhci_transaction (struct grub_uhci *u, unsigned int endp,
td->token = ((size << 21) | (toggle << 19) | (endp << 15) td->token = ((size << 21) | (toggle << 19) | (endp << 15)
| (addr << 8) | tf[type]); | (addr << 8) | tf[type]);
td->buffer = (grub_uint32_t) data; td->buffer = data;
return td; return td;
} }
@ -441,6 +452,8 @@ grub_uhci_transfer (grub_usb_controller_t dev,
if (! qh) if (! qh)
return grub_errno; return grub_errno;
grub_dprintf ("uhci", "transfer, iobase:%08x\n", u->iobase);
for (i = 0; i < transfer->transcnt; i++) for (i = 0; i < transfer->transcnt; i++)
{ {
grub_usb_transaction_t tr = &transfer->transactions[i]; grub_usb_transaction_t tr = &transfer->transactions[i];
@ -455,7 +468,7 @@ grub_uhci_transfer (grub_usb_controller_t dev,
td_prev->linkptr = 1; td_prev->linkptr = 1;
if (td_first) if (td_first)
grub_free_queue (u, td_first); grub_free_queue (u, td_first, NULL);
return GRUB_USB_ERR_INTERNAL; return GRUB_USB_ERR_INTERNAL;
} }
@ -548,12 +561,13 @@ grub_uhci_transfer (grub_usb_controller_t dev,
fail: fail:
grub_dprintf ("uhci", "transaction failed\n"); if (err != GRUB_USB_ERR_NONE)
grub_dprintf ("uhci", "transaction failed\n");
/* Place the QH back in the free list and deallocate the associated /* Place the QH back in the free list and deallocate the associated
TDs. */ TDs. */
qh->elinkptr = 1; qh->elinkptr = 1;
grub_free_queue (u, td_first); grub_free_queue (u, td_first, transfer);
return err; return err;
} }
@ -583,6 +597,8 @@ grub_uhci_portstatus (grub_usb_controller_t dev,
unsigned int status; unsigned int status;
grub_uint64_t endtime; grub_uint64_t endtime;
grub_dprintf ("uhci", "portstatus, iobase:%08x\n", u->iobase);
grub_dprintf ("uhci", "enable=%d port=%d\n", enable, port); grub_dprintf ("uhci", "enable=%d port=%d\n", enable, port);
if (port == 0) if (port == 0)
@ -600,7 +616,7 @@ grub_uhci_portstatus (grub_usb_controller_t dev,
grub_uhci_writereg16 (u, reg, enable << 9); grub_uhci_writereg16 (u, reg, enable << 9);
/* Wait for the reset to complete. XXX: How long exactly? */ /* Wait for the reset to complete. XXX: How long exactly? */
grub_millisleep (10); grub_millisleep (50); /* For root hub should be nominaly 50ms */
status = grub_uhci_readreg16 (u, reg); status = grub_uhci_readreg16 (u, reg);
grub_uhci_writereg16 (u, reg, status & ~(1 << 9)); grub_uhci_writereg16 (u, reg, status & ~(1 << 9));
grub_dprintf ("uhci", "reset completed\n"); grub_dprintf ("uhci", "reset completed\n");
@ -631,6 +647,8 @@ grub_uhci_detect_dev (grub_usb_controller_t dev, int port)
int reg; int reg;
unsigned int status; unsigned int status;
grub_dprintf ("uhci", "detect_dev, iobase:%08x\n", u->iobase);
if (port == 0) if (port == 0)
reg = GRUB_UHCI_REG_PORTSC1; reg = GRUB_UHCI_REG_PORTSC1;
else if (port == 1) else if (port == 1)

View file

@ -105,10 +105,7 @@ grub_usb_clear_halt (grub_usb_device_t dev, int endpoint)
grub_usb_err_t grub_usb_err_t
grub_usb_set_configuration (grub_usb_device_t dev, int configuration) grub_usb_set_configuration (grub_usb_device_t dev, int configuration)
{ {
int i; grub_memset (dev->toggle, 0, sizeof (dev->toggle));
for (i = 0; i < 16; i++)
dev->toggle[i] = 0;
return grub_usb_control_msg (dev, (GRUB_USB_REQTYPE_OUT return grub_usb_control_msg (dev, (GRUB_USB_REQTYPE_OUT
| GRUB_USB_REQTYPE_STANDARD | GRUB_USB_REQTYPE_STANDARD
@ -163,6 +160,16 @@ grub_usb_device_initialize (grub_usb_device_t dev)
grub_usb_err_t err; grub_usb_err_t err;
int i; int i;
/* First we have to read first 8 bytes only and determine
* max. size of packet */
dev->descdev.maxsize0 = 0; /* invalidating, for safety only, can be removed if it is sure it is zero here */
err = grub_usb_get_descriptor (dev, GRUB_USB_DESCRIPTOR_DEVICE,
0, 8, (char *) &dev->descdev);
if (err)
return err;
/* Now we have valid value in dev->descdev.maxsize0,
* so we can read whole device descriptor */
err = grub_usb_get_descriptor (dev, GRUB_USB_DESCRIPTOR_DEVICE, err = grub_usb_get_descriptor (dev, GRUB_USB_DESCRIPTOR_DEVICE,
0, sizeof (struct grub_usb_desc_device), 0, sizeof (struct grub_usb_desc_device),
(char *) &dev->descdev); (char *) &dev->descdev);

View file

@ -18,6 +18,7 @@
*/ */
#include <grub/dl.h> #include <grub/dl.h>
#include <grub/pci.h>
#include <grub/mm.h> #include <grub/mm.h>
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/usb.h> #include <grub/usb.h>
@ -29,30 +30,59 @@ grub_usb_control_msg (grub_usb_device_t dev,
grub_uint8_t request, grub_uint8_t request,
grub_uint16_t value, grub_uint16_t value,
grub_uint16_t index, grub_uint16_t index,
grub_size_t size, char *data) grub_size_t size0, char *data_in)
{ {
int i; int i;
grub_usb_transfer_t transfer; grub_usb_transfer_t transfer;
int datablocks; int datablocks;
struct grub_usb_packet_setup setupdata; volatile struct grub_usb_packet_setup *setupdata;
grub_uint32_t setupdata_addr;
grub_usb_err_t err; grub_usb_err_t err;
unsigned int max; unsigned int max;
struct grub_pci_dma_chunk *data_chunk, *setupdata_chunk;
volatile char *data;
grub_uint32_t data_addr;
grub_size_t size = size0;
/* FIXME: avoid allocation any kind of buffer in a first place. */
data_chunk = grub_memalign_dma32 (128, size ? : 16);
if (!data_chunk)
return GRUB_USB_ERR_INTERNAL;
data = grub_dma_get_virt (data_chunk);
data_addr = grub_dma_get_phys (data_chunk);
grub_memcpy ((char *) data, data_in, size);
grub_dprintf ("usb", grub_dprintf ("usb",
"control: reqtype=0x%02x req=0x%02x val=0x%02x idx=0x%02x size=%d\n", "control: reqtype=0x%02x req=0x%02x val=0x%02x idx=0x%02x size=%d\n",
reqtype, request, value, index, size); reqtype, request, value, index, size);
/* Create a transfer. */ /* Create a transfer. */
transfer = grub_malloc (sizeof (struct grub_usb_transfer)); transfer = grub_malloc (sizeof (*transfer));
if (! transfer) if (! transfer)
return grub_errno; {
grub_dma_free (data_chunk);
return grub_errno;
}
setupdata_chunk = grub_memalign_dma32 (32, sizeof (*setupdata));
if (! setupdata_chunk)
{
grub_free (transfer);
grub_dma_free (data_chunk);
return grub_errno;
}
setupdata = grub_dma_get_virt (setupdata_chunk);
setupdata_addr = grub_dma_get_phys (setupdata_chunk);
/* Determine the maximum packet size. */ /* Determine the maximum packet size. */
if (dev->initialized) if (dev->descdev.maxsize0)
max = dev->descdev.maxsize0; max = dev->descdev.maxsize0;
else else
max = 64; max = 64;
grub_dprintf ("usb", "transfer = %p, dev = %p\n", transfer, dev);
datablocks = (size + max - 1) / max; datablocks = (size + max - 1) / max;
/* XXX: Discriminate between different types of control /* XXX: Discriminate between different types of control
@ -71,18 +101,20 @@ grub_usb_control_msg (grub_usb_device_t dev,
if (! transfer->transactions) if (! transfer->transactions)
{ {
grub_free (transfer); grub_free (transfer);
grub_dma_free (setupdata_chunk);
grub_dma_free (data_chunk);
return grub_errno; return grub_errno;
} }
/* Build a Setup packet. XXX: Endianness. */ /* Build a Setup packet. XXX: Endianness. */
setupdata.reqtype = reqtype; setupdata->reqtype = reqtype;
setupdata.request = request; setupdata->request = request;
setupdata.value = value; setupdata->value = value;
setupdata.index = index; setupdata->index = index;
setupdata.length = size; setupdata->length = size;
transfer->transactions[0].size = sizeof (setupdata); transfer->transactions[0].size = sizeof (*setupdata);
transfer->transactions[0].pid = GRUB_USB_TRANSFER_TYPE_SETUP; transfer->transactions[0].pid = GRUB_USB_TRANSFER_TYPE_SETUP;
transfer->transactions[0].data = (char *) &setupdata; transfer->transactions[0].data = setupdata_addr;
transfer->transactions[0].toggle = 0; transfer->transactions[0].toggle = 0;
/* Now the data... XXX: Is this the right way to transfer control /* Now the data... XXX: Is this the right way to transfer control
@ -99,14 +131,14 @@ grub_usb_control_msg (grub_usb_device_t dev,
tr->pid = GRUB_USB_TRANSFER_TYPE_IN; tr->pid = GRUB_USB_TRANSFER_TYPE_IN;
else else
tr->pid = GRUB_USB_TRANSFER_TYPE_OUT; tr->pid = GRUB_USB_TRANSFER_TYPE_OUT;
tr->data = &data[i * max]; tr->data = data_addr + i * max;
size -= max; size -= max;
} }
/* End with an empty OUT transaction. */ /* End with an empty OUT transaction. */
transfer->transactions[datablocks + 1].size = 0; transfer->transactions[datablocks + 1].size = 0;
transfer->transactions[datablocks + 1].data = NULL; transfer->transactions[datablocks + 1].data = 0;
if (reqtype & 128) if ((reqtype & 128) && datablocks)
transfer->transactions[datablocks + 1].pid = GRUB_USB_TRANSFER_TYPE_OUT; transfer->transactions[datablocks + 1].pid = GRUB_USB_TRANSFER_TYPE_OUT;
else else
transfer->transactions[datablocks + 1].pid = GRUB_USB_TRANSFER_TYPE_IN; transfer->transactions[datablocks + 1].pid = GRUB_USB_TRANSFER_TYPE_IN;
@ -116,14 +148,19 @@ grub_usb_control_msg (grub_usb_device_t dev,
err = dev->controller.dev->transfer (&dev->controller, transfer); err = dev->controller.dev->transfer (&dev->controller, transfer);
grub_free (transfer->transactions); grub_free (transfer->transactions);
grub_free (transfer); grub_free (transfer);
grub_dma_free (data_chunk);
grub_dma_free (setupdata_chunk);
grub_memcpy (data_in, (char *) data, size0);
return err; return err;
} }
static grub_usb_err_t static grub_usb_err_t
grub_usb_bulk_readwrite (grub_usb_device_t dev, grub_usb_bulk_readwrite (grub_usb_device_t dev,
int endpoint, grub_size_t size, char *data, int endpoint, grub_size_t size0, char *data_in,
grub_transfer_type_t type) grub_transfer_type_t type)
{ {
int i; int i;
@ -132,6 +169,19 @@ grub_usb_bulk_readwrite (grub_usb_device_t dev,
unsigned int max; unsigned int max;
grub_usb_err_t err; grub_usb_err_t err;
int toggle = dev->toggle[endpoint]; int toggle = dev->toggle[endpoint];
volatile char *data;
grub_uint32_t data_addr;
struct grub_pci_dma_chunk *data_chunk;
grub_size_t size = size0;
/* FIXME: avoid allocation any kind of buffer in a first place. */
data_chunk = grub_memalign_dma32 (128, size);
if (!data_chunk)
return GRUB_USB_ERR_INTERNAL;
data = grub_dma_get_virt (data_chunk);
data_addr = grub_dma_get_phys (data_chunk);
if (type == GRUB_USB_TRANSFER_TYPE_OUT)
grub_memcpy ((char *) data, data_in, size);
/* Use the maximum packet size given in the endpoint descriptor. */ /* Use the maximum packet size given in the endpoint descriptor. */
if (dev->initialized) if (dev->initialized)
@ -150,16 +200,20 @@ grub_usb_bulk_readwrite (grub_usb_device_t dev,
/* Create a transfer. */ /* Create a transfer. */
transfer = grub_malloc (sizeof (struct grub_usb_transfer)); transfer = grub_malloc (sizeof (struct grub_usb_transfer));
if (! transfer) if (! transfer)
return grub_errno; {
grub_dma_free (data_chunk);
return grub_errno;
}
datablocks = ((size + max - 1) / max); datablocks = ((size + max - 1) / max);
transfer->transcnt = datablocks; transfer->transcnt = datablocks;
transfer->size = size - 1; transfer->size = size - 1;
transfer->endpoint = endpoint; transfer->endpoint = endpoint & 15;
transfer->devaddr = dev->addr; transfer->devaddr = dev->addr;
transfer->type = GRUB_USB_TRANSACTION_TYPE_BULK; transfer->type = GRUB_USB_TRANSACTION_TYPE_BULK;
transfer->max = max; transfer->max = max;
transfer->dev = dev; transfer->dev = dev;
transfer->last_trans = -1; /* Reset index of last processed transaction (TD) */
/* Allocate an array of transfer data structures. */ /* Allocate an array of transfer data structures. */
transfer->transactions = grub_malloc (transfer->transcnt transfer->transactions = grub_malloc (transfer->transcnt
@ -167,6 +221,7 @@ grub_usb_bulk_readwrite (grub_usb_device_t dev,
if (! transfer->transactions) if (! transfer->transactions)
{ {
grub_free (transfer); grub_free (transfer);
grub_dma_free (data_chunk);
return grub_errno; return grub_errno;
} }
@ -181,16 +236,27 @@ grub_usb_bulk_readwrite (grub_usb_device_t dev,
tr->toggle = toggle; tr->toggle = toggle;
toggle = toggle ? 0 : 1; toggle = toggle ? 0 : 1;
tr->pid = type; tr->pid = type;
tr->data = &data[i * max]; tr->data = data_addr + i * max;
size -= tr->size; size -= tr->size;
} }
err = dev->controller.dev->transfer (&dev->controller, transfer); err = dev->controller.dev->transfer (&dev->controller, transfer);
/* We must remember proper toggle value even if some transactions
* were not processed - correct value should be inversion of last
* processed transaction (TD). */
if (transfer->last_trans >= 0)
toggle = transfer->transactions[transfer->last_trans].toggle ? 0 : 1;
else
toggle = dev->toggle[endpoint]; /* Nothing done, take original */
grub_dprintf ("usb", "toggle=%d\n", toggle); grub_dprintf ("usb", "toggle=%d\n", toggle);
dev->toggle[endpoint] = toggle; dev->toggle[endpoint] = toggle;
grub_free (transfer->transactions); grub_free (transfer->transactions);
grub_free (transfer); grub_free (transfer);
grub_dma_free (data_chunk);
if (type == GRUB_USB_TRANSFER_TYPE_IN)
grub_memcpy (data_in, (char *) data, size0);
return err; return err;
} }

View file

@ -90,8 +90,7 @@ grub_cmd_blocklist (grub_command_t cmd __attribute__ ((unused)),
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) 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;

View file

@ -41,7 +41,7 @@ grub_cmd_cat (grub_command_t cmd __attribute__ ((unused)),
file = grub_gzfile_open (args[0], 1); file = grub_gzfile_open (args[0], 1);
if (! file) if (! file)
return 0; return grub_errno;
while ((size = grub_file_read (file, buf, sizeof (buf))) > 0 while ((size = grub_file_read (file, buf, sizeof (buf))) > 0
&& key != GRUB_TERM_ESC) && key != GRUB_TERM_ESC)

View file

@ -43,7 +43,7 @@ scan_card (grub_pci_device_t dev, grub_pci_id_t pciid)
{ {
grub_pci_address_t addr; grub_pci_address_t addr;
addr = grub_pci_make_address (dev, 2); addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
if (grub_pci_read_byte (addr + 3) == 0x3) if (grub_pci_read_byte (addr + 3) == 0x3)
{ {
struct grub_video_patch *p = video_patches; struct grub_video_patch *p = video_patches;

View file

@ -51,7 +51,8 @@ enable_rom_area (void)
return 0; return 0;
} }
addr = grub_pci_make_address (dev, 36); /* FIXME: should be macroified. */
addr = grub_pci_make_address (dev, 144);
grub_pci_write_byte (addr++, 0x30); 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);
@ -77,7 +78,8 @@ lock_rom_area (void)
grub_pci_address_t addr; grub_pci_address_t addr;
grub_pci_device_t dev = { .bus = 0, .device = 0, .function = 0}; grub_pci_device_t dev = { .bus = 0, .device = 0, .function = 0};
addr = grub_pci_make_address (dev, 36); /* FIXME: should be macroified. */
addr = grub_pci_make_address (dev, 144);
grub_pci_write_byte (addr++, 0x10); 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);

View file

@ -138,8 +138,8 @@ grub_cmd_gptsync (grub_command_t cmd __attribute__ ((unused)),
{ {
grub_device_close (dev); grub_device_close (dev);
return grub_error (GRUB_ERR_OUT_OF_RANGE, return grub_error (GRUB_ERR_OUT_OF_RANGE,
"only partitions resding in the first 2TB " "only partitions residing in the first 2TB "
"can be presen in hybrid MBR"); "can be present in hybrid MBR");
} }
@ -243,8 +243,8 @@ GRUB_MOD_INIT(gptsync)
cmd = grub_register_command ("gptsync", grub_cmd_gptsync, cmd = grub_register_command ("gptsync", grub_cmd_gptsync,
N_("DEVICE [PARTITION[+/-[TYPE]]] ..."), N_("DEVICE [PARTITION[+/-[TYPE]]] ..."),
N_("Fill hybrid MBR of GPT drive DEVICE. " N_("Fill hybrid MBR of GPT drive DEVICE. "
"specified partitions will be a part " "Specified partitions will be a part "
"of hybrid mbr. Up to 3 partitions are " "of hybrid MBR. Up to 3 partitions are "
"allowed. TYPE is an MBR type. " "allowed. TYPE is an MBR type. "
"+ means that partition is active. " "+ means that partition is active. "
"Only one partition can be active.")); "Only one partition can be active."));

View file

@ -1,101 +0,0 @@
/* 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);
}

View file

@ -24,13 +24,14 @@
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/crypto.h> #include <grub/crypto.h>
#include <grub/normal.h> #include <grub/normal.h>
#include <grub/i18n.h>
static const struct grub_arg_option options[] = { static const struct grub_arg_option options[] = {
{"hash", 'h', 0, "Specify hash to use.", "HASH", ARG_TYPE_STRING}, {"hash", 'h', 0, N_("Specify hash to use."), N_("HASH"), ARG_TYPE_STRING},
{"check", 'c', 0, "Check hash list file.", "FILE", ARG_TYPE_STRING}, {"check", 'c', 0, N_("Check hash list file."), N_("FILE"), ARG_TYPE_STRING},
{"prefix", 'p', 0, "Base directory for hash list.", "DIRECTORY", {"prefix", 'p', 0, N_("Base directory for hash list."), N_("DIRECTORY"),
ARG_TYPE_STRING}, ARG_TYPE_STRING},
{"keep-going", 'k', 0, "Don't stop after first error.", 0, 0}, {"keep-going", 'k', 0, N_("Don't stop after first error."), 0, 0},
{0, 0, 0, 0, 0, 0} {0, 0, 0, 0, 0, 0}
}; };
@ -57,7 +58,7 @@ static grub_err_t
hash_file (grub_file_t file, const gcry_md_spec_t *hash, void *result) hash_file (grub_file_t file, const gcry_md_spec_t *hash, void *result)
{ {
grub_uint8_t context[hash->contextsize]; grub_uint8_t context[hash->contextsize];
char *readbuf[4096]; grub_uint8_t readbuf[4096];
grub_memset (context, 0, sizeof (context)); grub_memset (context, 0, sizeof (context));
hash->init (context); hash->init (context);
@ -111,11 +112,9 @@ check_list (const gcry_md_spec_t *hash, const char *hashfilename,
{ {
char *filename; char *filename;
filename = grub_malloc (grub_strlen (prefix) filename = grub_xasprintf ("%s/%s", prefix, p);
+ grub_strlen (p) + 2);
if (!filename) if (!filename)
return grub_errno; return grub_errno;
grub_sprintf (filename, "%s/%s", prefix, p);
file = grub_file_open (filename); file = grub_file_open (filename);
grub_free (filename); grub_free (filename);
} }
@ -251,21 +250,21 @@ GRUB_MOD_INIT(hashsum)
options); options);
cmd_md5 = grub_register_extcmd ("md5sum", grub_cmd_hashsum, cmd_md5 = grub_register_extcmd ("md5sum", grub_cmd_hashsum,
GRUB_COMMAND_FLAG_BOTH, GRUB_COMMAND_FLAG_BOTH,
"md5sum [-c FILE [-p PREFIX]] " N_("[-c FILE [-p PREFIX]] "
"[FILE1 [FILE2 ...]]", "[FILE1 [FILE2 ...]]"),
"Compute or check hash checksum.", N_("Compute or check hash checksum."),
options); options);
cmd_sha256 = grub_register_extcmd ("sha256sum", grub_cmd_hashsum, cmd_sha256 = grub_register_extcmd ("sha256sum", grub_cmd_hashsum,
GRUB_COMMAND_FLAG_BOTH, GRUB_COMMAND_FLAG_BOTH,
"sha256sum [-c FILE [-p PREFIX]] " N_("[-c FILE [-p PREFIX]] "
"[FILE1 [FILE2 ...]]", "[FILE1 [FILE2 ...]]"),
"Compute or check hash checksum.", "Compute or check hash checksum.",
options); options);
cmd_sha512 = grub_register_extcmd ("sha512sum", grub_cmd_hashsum, cmd_sha512 = grub_register_extcmd ("sha512sum", grub_cmd_hashsum,
GRUB_COMMAND_FLAG_BOTH, GRUB_COMMAND_FLAG_BOTH,
"sha512sum [-c FILE [-p PREFIX]] " N_("[-c FILE [-p PREFIX]] "
"[FILE1 [FILE2 ...]]", "[FILE1 [FILE2 ...]]"),
"Compute or check hash checksum.", N_("Compute or check hash checksum."),
options); options);
} }

View file

@ -33,96 +33,87 @@ grub_cmd_help (grub_extcmd_t ext __attribute__ ((unused)), int argc,
int cnt = 0; int cnt = 0;
char *currarg; char *currarg;
auto int print_command_info (grub_command_t cmd);
auto int print_command_help (grub_command_t cmd);
int print_command_info (grub_command_t cmd)
{
if ((cmd->prio & GRUB_PRIO_LIST_FLAG_ACTIVE) &&
(cmd->flags & GRUB_COMMAND_FLAG_CMDLINE))
{
struct grub_term_output *term;
const char *summary_translated = _(cmd->summary);
char *command_help;
grub_uint32_t *unicode_command_help;
grub_uint32_t *unicode_last_position;
command_help = grub_malloc (grub_strlen (cmd->name) +
sizeof (" ") - 1 +
grub_strlen (summary_translated));
grub_sprintf(command_help, "%s %s", cmd->name, summary_translated);
grub_utf8_to_ucs4_alloc (command_help, &unicode_command_help,
&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;
}
int print_command_help (grub_command_t cmd)
{
if (cmd->prio & GRUB_PRIO_LIST_FLAG_ACTIVE)
{
if (! grub_strncmp (cmd->name, currarg, grub_strlen (currarg)))
{
if (cnt++ > 0)
grub_printf ("\n\n");
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;
}
if (argc == 0) if (argc == 0)
{ {
grub_command_iterate (print_command_info); grub_command_t cmd;
FOR_COMMANDS(cmd)
{
if ((cmd->prio & GRUB_PRIO_LIST_FLAG_ACTIVE) &&
(cmd->flags & GRUB_COMMAND_FLAG_CMDLINE))
{
struct grub_term_output *term;
const char *summary_translated = _(cmd->summary);
char *command_help;
grub_uint32_t *unicode_command_help;
grub_uint32_t *unicode_last_position;
command_help = grub_xasprintf ("%s %s", cmd->name, summary_translated);
if (!command_help)
break;
grub_utf8_to_ucs4_alloc (command_help, &unicode_command_help,
&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);
}
}
if (!(cnt % 2)) if (!(cnt % 2))
grub_printf ("\n"); grub_printf ("\n");
} }
else else
{ {
int i; int i;
grub_command_t cmd;
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
{ {
currarg = args[i]; currarg = args[i];
grub_command_iterate (print_command_help); FOR_COMMANDS(cmd)
{
if (cmd->prio & GRUB_PRIO_LIST_FLAG_ACTIVE)
{
if (! grub_strncmp (cmd->name, currarg, grub_strlen (currarg)))
{
if (cnt++ > 0)
grub_printf ("\n\n");
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));
}
}
}
} }
} }

59
commands/i386/cmostest.c Normal file
View file

@ -0,0 +1,59 @@
/*
* 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/misc.h>
#include <grub/cmos.h>
static grub_err_t
grub_cmd_cmostest (struct grub_command *cmd __attribute__ ((unused)),
int argc, char *argv[])
{
int byte, bit;
char *rest;
if (argc != 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "Address required.");
byte = grub_strtoul (argv[0], &rest, 0);
if (*rest != ':')
return grub_error (GRUB_ERR_BAD_ARGUMENT, "Address required.");
bit = grub_strtoul (rest + 1, 0, 0);
if (grub_cmos_read (byte) & (1 << bit))
return GRUB_ERR_NONE;
return grub_error (GRUB_ERR_TEST_FAILURE, "false");
}
static grub_command_t cmd;
GRUB_MOD_INIT(cmostest)
{
cmd = grub_register_command ("cmostest", grub_cmd_cmostest,
"cmostest BYTE:BIT",
"Test bit at BYTE:BIT in CMOS.");
}
GRUB_MOD_FINI(cmostest)
{
grub_unregister_command (cmd);
}

View file

@ -402,11 +402,10 @@ GRUB_MOD_INIT (drivemap)
grub_get_root_biosnumber_saved = grub_get_root_biosnumber; grub_get_root_biosnumber_saved = grub_get_root_biosnumber;
grub_get_root_biosnumber = grub_get_root_biosnumber_drivemap; grub_get_root_biosnumber = grub_get_root_biosnumber_drivemap;
cmd = grub_register_extcmd ("drivemap", grub_cmd_drivemap, cmd = grub_register_extcmd ("drivemap", grub_cmd_drivemap,
GRUB_COMMAND_FLAG_BOTH, GRUB_COMMAND_FLAG_BOTH,
"drivemap" N_("-l | -r | [-s] grubdev osdisk."),
N_("-l | -r | [-s] grubdev osdisk."), N_("Manage the BIOS drive mappings."),
N_("Manage the BIOS drive mappings."), options);
options);
drivemap_hook = drivemap_hook =
grub_loader_register_preboot_hook (&install_int13_handler, grub_loader_register_preboot_hook (&install_int13_handler,
&uninstall_int13_handler, &uninstall_int13_handler,

View file

@ -19,7 +19,7 @@
#include <grub/symbol.h> #include <grub/symbol.h>
#define INT13H_OFFSET(x) ((x) - EXT_C(grub_drivemap_handler)) #define INT13H_OFFSET(x) ((x) - LOCAL (base))
.code16 .code16
@ -27,6 +27,7 @@
/* The replacement int13 handler. Preserve all registers. */ /* The replacement int13 handler. Preserve all registers. */
FUNCTION(grub_drivemap_handler) FUNCTION(grub_drivemap_handler)
LOCAL (base):
/* Save %dx for future restore. */ /* Save %dx for future restore. */
push %dx push %dx
/* Push flags. Used to simulate interrupt with original flags. */ /* Push flags. Used to simulate interrupt with original flags. */
@ -35,12 +36,7 @@ FUNCTION(grub_drivemap_handler)
/* Map the drive number (always in DL). */ /* Map the drive number (always in DL). */
push %ax push %ax
push %bx push %bx
#ifdef APPLE_CC movw $INT13H_OFFSET(LOCAL (mapstart)), %bx
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: more_remaining:
movw %cs:(%bx), %ax movw %cs:(%bx), %ax
@ -66,12 +62,7 @@ not_found:
popf popf
pushf pushf
#ifdef APPLE_CC lcall *%cs:INT13H_OFFSET (LOCAL (oldhandler))
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 push %bp
mov %sp, %bp mov %sp, %bp
@ -94,11 +85,7 @@ norestore:
popf popf
pushf pushf
#ifdef APPLE_CC lcall *%cs:INT13H_OFFSET (LOCAL (oldhandler))
lcall *%cs:grub_drivemap_oldhandler_ofs
#else
lcall *%cs:INT13H_OFFSET (EXT_C (grub_drivemap_oldhandler))
#endif
push %bp push %bp
mov %sp, %bp mov %sp, %bp
@ -111,9 +98,13 @@ norestore:
/* Far pointer to the old handler. Stored as a CS:IP in the style of real-mode /* Far pointer to the old handler. Stored as a CS:IP in the style of real-mode
IVT entries (thus PI:SC in mem). */ IVT entries (thus PI:SC in mem). */
VARIABLE(grub_drivemap_oldhandler) VARIABLE(grub_drivemap_oldhandler)
LOCAL (oldhandler):
.word 0x0, 0x0 .word 0x0, 0x0
/* This label MUST be at the end of the copied block, since the installer code /* 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. */ reserves additional space for mappings at runtime and copies them over it. */
.align 2 .align 2
VARIABLE(grub_drivemap_mapstart) VARIABLE(grub_drivemap_mapstart)
LOCAL (mapstart):
.byte 0

View file

@ -29,7 +29,7 @@
#include <grub/command.h> #include <grub/command.h>
#include <grub/i18n.h> #include <grub/i18n.h>
#define BASE_TEMPO 120 #define BASE_TEMPO (60 * GRUB_TICKS_PER_SECOND)
/* The speaker port. */ /* The speaker port. */
#define SPEAKER 0x61 #define SPEAKER 0x61
@ -101,13 +101,13 @@
#define PIT_CTRL_COUNT_BINARY 0x00 /* 16-bit binary counter. */ #define PIT_CTRL_COUNT_BINARY 0x00 /* 16-bit binary counter. */
#define PIT_CTRL_COUNT_BCD 0x01 /* 4-decade BCD counter. */ #define PIT_CTRL_COUNT_BCD 0x01 /* 4-decade BCD counter. */
#define T_REST ((short) 0) #define T_REST ((grub_uint16_t) 0)
#define T_FINE ((short) -1) #define T_FINE ((grub_uint16_t) -1)
struct note struct note
{ {
short pitch; grub_uint16_t pitch;
short duration; grub_uint16_t duration;
}; };
static void static void
@ -120,7 +120,7 @@ beep_off (void)
} }
static void static void
beep_on (short pitch) beep_on (grub_uint16_t pitch)
{ {
unsigned char status; unsigned char status;
unsigned int counter; unsigned int counter;
@ -143,60 +143,115 @@ beep_on (short pitch)
grub_outb (status | SPEAKER_TMR2 | SPEAKER_DATA, SPEAKER); grub_outb (status | SPEAKER_TMR2 | SPEAKER_DATA, SPEAKER);
} }
/* Returns whether playing should continue. */
static int
play (unsigned tempo, struct note *note)
{
unsigned int to;
if (note->pitch == T_FINE || grub_checkkey () >= 0)
return 1;
grub_dprintf ("play", "pitch = %d, duration = %d\n", note->pitch,
note->duration);
switch (note->pitch)
{
case T_REST:
beep_off ();
break;
default:
beep_on (note->pitch);
break;
}
to = grub_get_rtc () + BASE_TEMPO * note->duration / tempo;
while (((unsigned int) grub_get_rtc () <= to) && (grub_checkkey () < 0))
;
return 0;
}
static grub_err_t static grub_err_t
grub_cmd_play (grub_command_t cmd __attribute__ ((unused)), grub_cmd_play (grub_command_t cmd __attribute__ ((unused)),
int argc, char **args) int argc, char **args)
{ {
grub_file_t file;
struct note buf;
int tempo;
unsigned int to;
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 or tempo and notes required");
file = grub_file_open (args[0]); if (argc == 1)
if (! file)
return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found");
if (grub_file_read (file, &tempo, sizeof(tempo)) != sizeof(tempo))
{ {
grub_file_close (file); struct note buf;
return grub_error (GRUB_ERR_FILE_READ_ERROR, grub_uint32_t tempo;
"file doesn't even contains a full tempo record"); grub_file_t file;
}
grub_dprintf ("play","tempo = %d\n", tempo); file = grub_file_open (args[0]);
while (grub_file_read (file, &buf, if (! file)
sizeof (struct note)) == sizeof (struct note) return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found");
&& buf.pitch != T_FINE && grub_checkkey () < 0)
{
grub_dprintf ("play", "pitch = %d, duration = %d\n", buf.pitch, if (grub_file_read (file, &tempo, sizeof (tempo)) != sizeof (tempo))
buf.duration);
switch (buf.pitch)
{ {
case T_REST: grub_file_close (file);
beep_off (); return grub_error (GRUB_ERR_FILE_READ_ERROR,
break; "file doesn't even contains a full tempo record");
}
default: tempo = grub_le_to_cpu32 (tempo);
beep_on (buf.pitch); grub_dprintf ("play","tempo = %d\n", tempo);
while (grub_file_read (file, &buf,
sizeof (struct note)) == sizeof (struct note))
{
buf.pitch = grub_le_to_cpu16 (buf.pitch);
buf.duration = grub_le_to_cpu16 (buf.duration);
if (play (tempo, &buf))
break; break;
} }
to = grub_get_rtc () + BASE_TEMPO * buf.duration / tempo; grub_file_close (file);
while (((unsigned int) grub_get_rtc () <= to) && (grub_checkkey () < 0)) }
; else
{
char *end;
unsigned tempo;
struct note note;
int i;
tempo = grub_strtoul (args[0], &end, 0);
if (*end)
/* Was not a number either, assume it was supposed to be a file name. */
return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found");
grub_dprintf ("play","tempo = %d\n", tempo);
for (i = 1; i + 1 < argc; i += 2)
{
note.pitch = grub_strtoul (args[i], &end, 0);
if (*end)
{
grub_error (GRUB_ERR_BAD_NUMBER, "bogus pitch number");
break;
}
note.duration = grub_strtoul (args[i + 1], &end, 0);
if (*end)
{
grub_error (GRUB_ERR_BAD_NUMBER, "bogus duration number");
break;
}
if (play (tempo, &note))
break;
}
} }
beep_off (); beep_off ();
grub_file_close (file);
while (grub_checkkey () > 0) while (grub_checkkey () > 0)
grub_getkey (); grub_getkey ();
@ -208,7 +263,8 @@ static grub_command_t cmd;
GRUB_MOD_INIT(play) GRUB_MOD_INIT(play)
{ {
cmd = grub_register_command ("play", grub_cmd_play, cmd = grub_register_command ("play", grub_cmd_play,
N_("FILE"), N_("Play a tune.")); N_("FILE | TEMPO [PITCH1 DURATION1] [PITCH2 DURATION2] ... "),
N_("Play a tune."));
} }
GRUB_MOD_FINI(play) GRUB_MOD_FINI(play)

View file

@ -24,6 +24,7 @@
#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/video.h>
#include <grub/err.h> #include <grub/err.h>
#include <grub/i18n.h> #include <grub/i18n.h>

150
commands/iorw.c Normal file
View file

@ -0,0 +1,150 @@
/* 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/cpu/io.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."),
N_("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 ("in") - 1])
{
case 'l':
value = grub_inl (addr);
break;
case 'w':
value = grub_inw (addr);
break;
case 'b':
value = grub_inb (addr);
break;
}
if (cmd->state[0].set)
{
grub_snprintf (buf, sizeof (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 ("out") - 1])
{
case 'l':
if (mask != 0xffffffff)
grub_outl ((grub_inl (addr) & ~mask) | value, addr);
else
grub_outl (value, addr);
break;
case 'w':
if ((mask & 0xffff) != 0xffff)
grub_outw ((grub_inw (addr) & ~mask) | value, addr);
else
grub_outw (value, addr);
break;
case 'b':
if ((mask & 0xff) != 0xff)
grub_outb ((grub_inb (addr) & ~mask) | value, addr);
else
grub_outb (value, addr);
break;
}
return 0;
}
GRUB_MOD_INIT(memrw)
{
cmd_read_byte =
grub_register_extcmd ("inb", grub_cmd_read, GRUB_COMMAND_FLAG_BOTH,
N_("PORT"), N_("Read byte from PORT."), options);
cmd_read_word =
grub_register_extcmd ("inw", grub_cmd_read, GRUB_COMMAND_FLAG_BOTH,
N_("PORT"), N_("Read word from PORT."), options);
cmd_read_dword =
grub_register_extcmd ("inl", grub_cmd_read, GRUB_COMMAND_FLAG_BOTH,
N_("PORT"), N_("Read dword from PORT."), options);
cmd_write_byte =
grub_register_command ("outb", grub_cmd_write,
N_("PORT VALUE [MASK]"),
N_("Write byte VALUE to PORT."));
cmd_write_word =
grub_register_command ("outw", grub_cmd_write,
N_("PORT VALUE [MASK]"),
N_("Write word VALUE to PORT."));
cmd_write_dword =
grub_register_command ("outl", grub_cmd_write,
N_("ADDR VALUE [MASK]"),
N_("Write dword VALUE to PORT."));
}
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);
}

View file

@ -1,7 +1,7 @@
/* loadenv.c - command to load/save environment variable. */ /* loadenv.c - command to load/save environment variable. */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2008,2009 Free Software Foundation, Inc. * Copyright (C) 2008,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
@ -196,7 +196,7 @@ free_blocklists (struct blocklist *p)
} }
} }
static int static grub_err_t
check_blocklists (grub_envblk_t envblk, struct blocklist *blocklists, check_blocklists (grub_envblk_t envblk, struct blocklist *blocklists,
grub_file_t file) grub_file_t file)
{ {
@ -219,8 +219,7 @@ check_blocklists (grub_envblk_t envblk, struct blocklist *blocklists,
{ {
/* This might be actually valid, but it is unbelievable that /* This might be actually valid, but it is unbelievable that
any filesystem makes such a silly allocation. */ any filesystem makes such a silly allocation. */
grub_error (GRUB_ERR_BAD_FS, "malformed file"); return grub_error (GRUB_ERR_BAD_FS, "malformed file");
return 0;
} }
} }
@ -230,17 +229,14 @@ check_blocklists (grub_envblk_t envblk, struct blocklist *blocklists,
if (total_length != grub_file_size (file)) if (total_length != grub_file_size (file))
{ {
/* Maybe sparse, unallocated sectors. No way in GRUB. */ /* Maybe sparse, unallocated sectors. No way in GRUB. */
grub_error (GRUB_ERR_BAD_FILE_TYPE, "sparse file not allowed"); return 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 /* One more sanity check. Re-read all sectors by blocklists, and compare
those with the data read via a file. */ those with the data read via a file. */
disk = file->device->disk; disk = file->device->disk;
if (disk->partition)
part_start = grub_partition_get_start (disk->partition); part_start = grub_partition_get_start (disk->partition);
else
part_start = 0;
buf = grub_envblk_buffer (envblk); buf = grub_envblk_buffer (envblk);
for (p = blocklists, index = 0; p; index += p->length, p = p->next) for (p = blocklists, index = 0; p; index += p->length, p = p->next)
@ -249,16 +245,13 @@ check_blocklists (grub_envblk_t envblk, struct blocklist *blocklists,
if (grub_disk_read (disk, p->sector - part_start, if (grub_disk_read (disk, p->sector - part_start,
p->offset, p->length, blockbuf)) p->offset, p->length, blockbuf))
return 0; return grub_errno;
if (grub_memcmp (buf + index, blockbuf, p->length) != 0) if (grub_memcmp (buf + index, blockbuf, p->length) != 0)
{ return grub_error (GRUB_ERR_FILE_READ_ERROR, "invalid blocklist");
grub_error (GRUB_ERR_FILE_READ_ERROR, "invalid blocklist");
return 0;
}
} }
return 1; return GRUB_ERR_NONE;
} }
static int static int
@ -273,10 +266,7 @@ write_blocklists (grub_envblk_t envblk, struct blocklist *blocklists,
buf = grub_envblk_buffer (envblk); buf = grub_envblk_buffer (envblk);
disk = file->device->disk; disk = file->device->disk;
if (disk->partition) part_start = grub_partition_get_start (disk->partition);
part_start = grub_partition_get_start (disk->partition);
else
part_start = 0;
index = 0; index = 0;
for (p = blocklists; p; index += p->length, p = p->next) for (p = blocklists; p; index += p->length, p = p->next)
@ -347,7 +337,7 @@ grub_cmd_save_env (grub_extcmd_t cmd, int argc, char **args)
if (! envblk) if (! envblk)
goto fail; goto fail;
if (! check_blocklists (envblk, head, file)) if (check_blocklists (envblk, head, file))
goto fail; goto fail;
while (argc) while (argc)

View file

@ -87,19 +87,21 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
int print_files_long (const char *filename, int print_files_long (const char *filename,
const struct grub_dirhook_info *info) const struct grub_dirhook_info *info)
{ {
char pathname[grub_strlen (dirname) + grub_strlen (filename) + 1];
if ((! all) && (filename[0] == '.')) if ((! all) && (filename[0] == '.'))
return 0; return 0;
if (! info->dir) if (! info->dir)
{ {
grub_file_t file; grub_file_t file;
char *pathname;
if (dirname[grub_strlen (dirname) - 1] == '/') if (dirname[grub_strlen (dirname) - 1] == '/')
grub_sprintf (pathname, "%s%s", dirname, filename); pathname = grub_xasprintf ("%s%s", dirname, filename);
else else
grub_sprintf (pathname, "%s/%s", dirname, filename); pathname = grub_xasprintf ("%s/%s", dirname, filename);
if (!pathname)
return 1;
/* XXX: For ext2fs symlinks are detected as files while they /* XXX: For ext2fs symlinks are detected as files while they
should be reported as directories. */ should be reported as directories. */
@ -107,6 +109,7 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
if (! file) if (! file)
{ {
grub_errno = 0; grub_errno = 0;
grub_free (pathname);
return 0; return 0;
} }
@ -131,8 +134,9 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
grub_uint32_t whole, fraction; grub_uint32_t whole, fraction;
whole = grub_divmod64 (fsize, 100, &fraction); whole = grub_divmod64 (fsize, 100, &fraction);
grub_sprintf (buf, "%u.%02u%c", whole, fraction, grub_snprintf (buf, sizeof (buf),
grub_human_sizes[units]); "%u.%02u%c", whole, fraction,
grub_human_sizes[units]);
grub_printf ("%-12s", buf); grub_printf ("%-12s", buf);
} }
else else
@ -140,6 +144,7 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
} }
grub_file_close (file); grub_file_close (file);
grub_free (pathname);
} }
else else
grub_printf ("%-12s", "DIR"); grub_printf ("%-12s", "DIR");

View file

@ -16,7 +16,9 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef GRUB_MACHINE_EMU
#include <grub/machine/memory.h> #include <grub/machine/memory.h>
#endif
#include <grub/dl.h> #include <grub/dl.h>
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/command.h> #include <grub/command.h>
@ -34,7 +36,9 @@ grub_cmd_lsmmap (grub_command_t cmd __attribute__ ((unused)),
(long long) addr, (long long) size, type); (long long) addr, (long long) size, type);
return 0; return 0;
} }
#ifndef GRUB_MACHINE_EMU
grub_machine_mmap_iterate (hook); grub_machine_mmap_iterate (hook);
#endif
return 0; return 0;
} }

View file

@ -135,7 +135,7 @@ grub_lspci_iter (grub_pci_device_t dev, grub_pci_id_t pciid)
grub_printf ("%02x:%02x.%x %04x:%04x", grub_pci_get_bus (dev), grub_printf ("%02x:%02x.%x %04x:%04x", grub_pci_get_bus (dev),
grub_pci_get_device (dev), grub_pci_get_function (dev), grub_pci_get_device (dev), grub_pci_get_function (dev),
pciid & 0xFFFF, pciid >> 16); pciid & 0xFFFF, pciid >> 16);
addr = grub_pci_make_address (dev, 2); addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
class = grub_pci_read (addr); class = grub_pci_read (addr);
/* Lookup the class name, if there isn't a specific one, /* Lookup the class name, if there isn't a specific one,
@ -156,22 +156,24 @@ grub_lspci_iter (grub_pci_device_t dev, grub_pci_id_t pciid)
if (iospace) if (iospace)
{ {
reg = 4; reg = GRUB_PCI_REG_ADDRESSES;
while (reg < 10) while (reg < GRUB_PCI_REG_CIS_POINTER)
{ {
grub_uint64_t space; grub_uint64_t space;
addr = grub_pci_make_address (dev, reg); addr = grub_pci_make_address (dev, reg);
space = grub_pci_read (addr); space = grub_pci_read (addr);
reg++; reg += sizeof (grub_uint32_t);
if (space == 0) if (space == 0)
continue; continue;
switch (space & GRUB_PCI_ADDR_SPACE_MASK) switch (space & GRUB_PCI_ADDR_SPACE_MASK)
{ {
case GRUB_PCI_ADDR_SPACE_IO: case GRUB_PCI_ADDR_SPACE_IO:
grub_printf ("\tIO space %d at 0x%llx\n", (reg - 1) - 4, grub_printf ("\tIO space %d at 0x%llx\n",
(unsigned) ((reg - GRUB_PCI_REG_ADDRESSES)
/ sizeof (grub_uint32_t)) - 1,
(unsigned long long) (unsigned long long)
(space & GRUB_PCI_ADDR_IO_MASK)); (space & GRUB_PCI_ADDR_IO_MASK));
break; break;
@ -181,9 +183,11 @@ grub_lspci_iter (grub_pci_device_t dev, grub_pci_id_t pciid)
{ {
addr = grub_pci_make_address (dev, reg); addr = grub_pci_make_address (dev, reg);
space |= ((grub_uint64_t) grub_pci_read (addr)) << 32; space |= ((grub_uint64_t) grub_pci_read (addr)) << 32;
reg++; reg += sizeof (grub_uint32_t);
grub_printf ("\t64-bit memory space %d at 0x%016llx [%s]\n", grub_printf ("\t64-bit memory space %d at 0x%016llx [%s]\n",
(reg - 2) - 4, (unsigned long long) (unsigned) ((reg - GRUB_PCI_REG_ADDRESSES)
/ sizeof (grub_uint32_t)) - 2,
(unsigned long long)
(space & GRUB_PCI_ADDR_MEM_MASK), (space & GRUB_PCI_ADDR_MEM_MASK),
space & GRUB_PCI_ADDR_MEM_PREFETCH space & GRUB_PCI_ADDR_MEM_PREFETCH
? "prefetchable" : "non-prefetchable"); ? "prefetchable" : "non-prefetchable");
@ -191,7 +195,9 @@ grub_lspci_iter (grub_pci_device_t dev, grub_pci_id_t pciid)
} }
else else
grub_printf ("\t32-bit memory space %d at 0x%016llx [%s]\n", grub_printf ("\t32-bit memory space %d at 0x%016llx [%s]\n",
(reg - 1) - 4, (unsigned long long) (unsigned) ((reg - GRUB_PCI_REG_ADDRESSES)
/ sizeof (grub_uint32_t)) - 1,
(unsigned long long)
(space & GRUB_PCI_ADDR_MEM_MASK), (space & GRUB_PCI_ADDR_MEM_MASK),
space & GRUB_PCI_ADDR_MEM_PREFETCH space & GRUB_PCI_ADDR_MEM_PREFETCH
? "prefetchable" : "non-prefetchable"); ? "prefetchable" : "non-prefetchable");

View file

@ -62,7 +62,7 @@ grub_cmd_read (grub_extcmd_t cmd, int argc, char **argv)
if (cmd->state[0].set) if (cmd->state[0].set)
{ {
grub_sprintf (buf, "%x", value); grub_snprintf (buf, sizeof (buf), "%x", value);
grub_env_set (cmd->state[0].arg, buf); grub_env_set (cmd->state[0].arg, buf);
} }
else else

View file

@ -301,28 +301,23 @@ grub_mini_cmd_lsmod (struct grub_command *cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)), int argc __attribute__ ((unused)),
char *argv[] __attribute__ ((unused))) char *argv[] __attribute__ ((unused)))
{ {
auto int print_module (grub_dl_t mod); 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_printf ("Name\tRef Count\tDependencies\n");
grub_dl_iterate (print_module); FOR_DL_MODULES (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');
}
return 0; return 0;
} }

View file

@ -175,7 +175,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
} }
/* Load modules. */ /* Load modules. */
#ifndef GRUB_UTIL #if !GRUB_NO_MODULES
{ {
const char *prefix; const char *prefix;
prefix = grub_env_get ("prefix"); prefix = grub_env_get ("prefix");
@ -183,12 +183,11 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
{ {
char *filename; char *filename;
filename = grub_malloc (grub_strlen (prefix) + sizeof ("/parttool.lst")); filename = grub_xasprintf ("%s/parttool.lst", prefix);
if (filename) if (filename)
{ {
grub_file_t file; grub_file_t file;
grub_sprintf (filename, "%s/parttool.lst", prefix);
file = grub_file_open (filename); file = grub_file_open (filename);
if (file) if (file)
{ {

View file

@ -24,6 +24,7 @@
#include <grub/env.h> #include <grub/env.h>
#include <grub/normal.h> #include <grub/normal.h>
#include <grub/dl.h> #include <grub/dl.h>
#include <grub/i18n.h>
static grub_dl_t my_mod; static grub_dl_t my_mod;
@ -186,8 +187,8 @@ GRUB_MOD_INIT(password_pbkdf2)
{ {
my_mod = mod; my_mod = mod;
cmd = grub_register_command ("password_pbkdf2", grub_cmd_password, cmd = grub_register_command ("password_pbkdf2", grub_cmd_password,
"password_pbkdf2 USER PBKDF2_PASSWORD", N_("USER PBKDF2_PASSWORD"),
"Set user password (PBKDF2). "); N_("Set user password (PBKDF2). "));
} }
GRUB_MOD_FINI(password_pbkdf2) GRUB_MOD_FINI(password_pbkdf2)

80
commands/regexp.c Normal file
View file

@ -0,0 +1,80 @@
/* regexp.c -- The regexp command. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2005,2007 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/dl.h>
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/command.h>
#include <grub/i18n.h>
#include <regex.h>
static grub_err_t
grub_cmd_regexp (grub_command_t cmd __attribute__ ((unused)),
int argc, char **args)
{
int argn = 0;
int matches = 0;
regex_t regex;
int ret;
grub_size_t s;
char *comperr;
grub_err_t err;
if (argc != 2)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "2 arguments expected");
ret = regcomp (&regex, args[0], RE_SYNTAX_GNU_AWK);
if (ret)
goto fail;
ret = regexec (&regex, args[1], 0, 0, 0);
if (!ret)
{
regfree (&regex);
return GRUB_ERR_NONE;
}
fail:
s = regerror (ret, &regex, 0, 0);
comperr = grub_malloc (s);
if (!comperr)
{
regfree (&regex);
return grub_errno;
}
regerror (ret, &regex, comperr, s);
err = grub_error (GRUB_ERR_TEST_FAILURE, "%s", comperr);
regfree (&regex);
grub_free (comperr);
return err;
}
static grub_command_t cmd;
GRUB_MOD_INIT(regexp)
{
cmd = grub_register_command ("regexp", grub_cmd_regexp,
N_("REGEXP STRING"),
N_("Test if REGEXP matches STRING."));
}
GRUB_MOD_FINI(regexp)
{
grub_unregister_command (cmd);
}

View file

@ -33,7 +33,6 @@ void
FUNC_NAME (const char *key, const char *var, int no_floppy) FUNC_NAME (const char *key, const char *var, int no_floppy)
{ {
int count = 0; int count = 0;
char *buf = NULL;
grub_fs_autoload_hook_t saved_autoload; grub_fs_autoload_hook_t saved_autoload;
auto int iterate_device (const char *name); auto int iterate_device (const char *name);
@ -48,24 +47,20 @@ FUNC_NAME (const char *key, const char *var, int no_floppy)
#ifdef DO_SEARCH_FILE #ifdef DO_SEARCH_FILE
{ {
grub_size_t len; char *buf;
char *p;
grub_file_t file; grub_file_t file;
len = grub_strlen (name) + 2 + grub_strlen (key) + 1; buf = grub_xasprintf ("(%s)%s", name, key);
p = grub_realloc (buf, len); if (! buf)
if (! p)
return 1; return 1;
buf = p;
grub_sprintf (buf, "(%s)%s", name, key);
file = grub_file_open (buf); file = grub_file_open (buf);
if (file) if (file)
{ {
found = 1; found = 1;
grub_file_close (file); grub_file_close (file);
} }
grub_free (buf);
} }
#else #else
{ {
@ -135,8 +130,6 @@ FUNC_NAME (const char *key, const char *var, int no_floppy)
else else
grub_device_iterate (iterate_device); grub_device_iterate (iterate_device);
grub_free (buf);
if (grub_errno == GRUB_ERR_NONE && count == 0) 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);
} }
@ -156,11 +149,11 @@ grub_cmd_do_search (grub_command_t cmd __attribute__ ((unused)), int argc,
static grub_command_t cmd; static grub_command_t cmd;
#ifdef DO_SEARCH_FILE #ifdef DO_SEARCH_FILE
GRUB_MOD_INIT(search_file) GRUB_MOD_INIT(search_fs_file)
#elif defined (DO_SEARCH_FS_UUID) #elif defined (DO_SEARCH_FS_UUID)
GRUB_MOD_INIT(search_fs_uuid) GRUB_MOD_INIT(search_fs_uuid)
#else #else
GRUB_MOD_INIT(search_fs_label) GRUB_MOD_INIT(search_label)
#endif #endif
{ {
cmd = cmd =
@ -170,11 +163,11 @@ GRUB_MOD_INIT(search_fs_label)
} }
#ifdef DO_SEARCH_FILE #ifdef DO_SEARCH_FILE
GRUB_MOD_FINI(search_file) GRUB_MOD_FINI(search_fs_file)
#elif defined (DO_SEARCH_FS_UUID) #elif defined (DO_SEARCH_FS_UUID)
GRUB_MOD_FINI(search_fs_uuid) GRUB_MOD_FINI(search_fs_uuid)
#else #else
GRUB_MOD_FINI(search_fs_label) GRUB_MOD_FINI(search_label)
#endif #endif
{ {
grub_unregister_command (cmd); grub_unregister_command (cmd);

341
commands/setpci.c Normal file
View file

@ -0,0 +1,341 @@
/* 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/env.h>
#include <grub/mm.h>
#include <grub/i18n.h>
struct pci_register
{
const char *name;
grub_uint16_t addr;
unsigned size;
};
struct pci_register pci_registers[] =
{
{"VENDOR_ID", GRUB_PCI_REG_VENDOR , 2},
{"DEVICE_ID", GRUB_PCI_REG_DEVICE , 2},
{"COMMAND", GRUB_PCI_REG_COMMAND , 2},
{"STATUS", GRUB_PCI_REG_STATUS , 2},
{"REVISION", GRUB_PCI_REG_REVISION , 1},
{"CLASS_PROG", GRUB_PCI_REG_CLASS + 1 , 1},
{"CLASS_DEVICE", GRUB_PCI_REG_CLASS + 2 , 2},
{"CACHE_LINE_SIZE", GRUB_PCI_REG_CACHELINE , 1},
{"LATENCY_TIMER", GRUB_PCI_REG_LAT_TIMER , 1},
{"HEADER_TYPE", GRUB_PCI_REG_HEADER_TYPE , 1},
{"BIST", GRUB_PCI_REG_BIST , 1},
{"BASE_ADDRESS_0", GRUB_PCI_REG_ADDRESS_REG0, 4},
{"BASE_ADDRESS_1", GRUB_PCI_REG_ADDRESS_REG1, 4},
{"BASE_ADDRESS_2", GRUB_PCI_REG_ADDRESS_REG2, 4},
{"BASE_ADDRESS_3", GRUB_PCI_REG_ADDRESS_REG3, 4},
{"BASE_ADDRESS_4", GRUB_PCI_REG_ADDRESS_REG4, 4},
{"BASE_ADDRESS_5", GRUB_PCI_REG_ADDRESS_REG5, 4},
{"CARDBUS_CIS", GRUB_PCI_REG_CIS_POINTER , 4},
{"SUBVENDOR_ID", GRUB_PCI_REG_SUBVENDOR , 2},
{"SUBSYSTEM_ID", GRUB_PCI_REG_SUBSYSTEM , 2},
{"ROM_ADDRESS", GRUB_PCI_REG_ROM_ADDRESS , 4},
{"CAP_POINTER", GRUB_PCI_REG_CAP_POINTER , 1},
{"INTERRUPT_LINE", GRUB_PCI_REG_IRQ_LINE , 1},
{"INTERRUPT_PIN", GRUB_PCI_REG_IRQ_PIN , 1},
{"MIN_GNT", GRUB_PCI_REG_MIN_GNT , 1},
{"MAX_LAT", GRUB_PCI_REG_MIN_GNT , 1},
};
static const struct grub_arg_option options[] =
{
{0, 'd', 0, "Select device by vendor and device IDs.",
"[vendor]:[device]", ARG_TYPE_STRING},
{0, 's', 0, "Select device by its position on the bus.",
"[bus]:[slot][.func]", ARG_TYPE_STRING},
{0, 'v', 0, "Save read value into variable VARNAME.",
"VARNAME", ARG_TYPE_STRING},
{0, 0, 0, 0, 0, 0}
};
static grub_uint32_t pciid_check_mask, pciid_check_value;
static int bus, device, function;
static int check_bus, check_device, check_function;
static grub_uint32_t write_mask, regwrite;
static int regsize;
static grub_uint16_t regaddr;
static const char *varname;
static int NESTED_FUNC_ATTR
grub_setpci_iter (grub_pci_device_t dev, grub_pci_id_t pciid)
{
grub_uint32_t regval = 0;
grub_pci_address_t addr;
if ((pciid & pciid_check_mask) != pciid_check_value)
return 0;
if (check_bus && grub_pci_get_bus (dev) != bus)
return 0;
if (check_device && grub_pci_get_device (dev) != device)
return 0;
if (check_function && grub_pci_get_function (dev) != function)
return 0;
addr = grub_pci_make_address (dev, regaddr);
switch (regsize)
{
case 1:
regval = grub_pci_read_byte (addr);
break;
case 2:
regval = grub_pci_read_word (addr);
break;
case 4:
regval = grub_pci_read (addr);
break;
}
if (varname)
{
char buf[sizeof ("XXXXXXXX")];
grub_snprintf (buf, sizeof (buf), "%x", regval);
grub_env_set (varname, buf);
return 1;
}
if (!write_mask)
{
grub_printf ("Register %x of %d:%d.%d is %x\n", regaddr,
grub_pci_get_bus (dev),
grub_pci_get_device (dev),
grub_pci_get_function (dev),
regval);
return 0;
}
regval = (regval & ~write_mask) | regwrite;
switch (regsize)
{
case 1:
grub_pci_write_byte (addr, regval);
break;
case 2:
grub_pci_write_word (addr, regval);
break;
case 4:
grub_pci_write (addr, regval);
break;
}
return 0;
}
static grub_err_t
grub_cmd_setpci (grub_extcmd_t cmd, int argc, char **argv)
{
const char *ptr;
unsigned i;
pciid_check_value = 0;
pciid_check_mask = 0;
if (cmd->state[0].set)
{
ptr = cmd->state[0].arg;
pciid_check_value |= (grub_strtoul (ptr, (char **) &ptr, 16) & 0xffff);
if (grub_errno == GRUB_ERR_BAD_NUMBER)
{
grub_errno = GRUB_ERR_NONE;
ptr = cmd->state[0].arg;
}
else
pciid_check_mask |= 0xffff;
if (grub_errno)
return grub_errno;
if (*ptr != ':')
return grub_error (GRUB_ERR_BAD_ARGUMENT, "Colon expected.");
ptr++;
pciid_check_value |= (grub_strtoul (ptr, (char **) &ptr, 16) & 0xffff)
<< 16;
if (grub_errno == GRUB_ERR_BAD_NUMBER)
grub_errno = GRUB_ERR_NONE;
else
pciid_check_mask |= 0xffff0000;
}
pciid_check_value &= pciid_check_mask;
check_bus = check_device = check_function = 0;
if (cmd->state[1].set)
{
const char *optr;
ptr = cmd->state[1].arg;
optr = ptr;
bus = grub_strtoul (ptr, (char **) &ptr, 16);
if (grub_errno == GRUB_ERR_BAD_NUMBER)
{
grub_errno = GRUB_ERR_NONE;
ptr = optr;
}
else
check_bus = 1;
if (grub_errno)
return grub_errno;
if (*ptr != ':')
return grub_error (GRUB_ERR_BAD_ARGUMENT, "Colon expected.");
ptr++;
optr = ptr;
device = grub_strtoul (ptr, (char **) &ptr, 16);
if (grub_errno == GRUB_ERR_BAD_NUMBER)
{
grub_errno = GRUB_ERR_NONE;
ptr = optr;
}
else
check_device = 1;
if (*ptr == '.')
{
ptr++;
function = grub_strtoul (ptr, (char **) &ptr, 16);
if (grub_errno)
return grub_errno;
check_function = 1;
}
}
if (cmd->state[2].set)
varname = cmd->state[2].arg;
else
varname = NULL;
write_mask = 0;
if (argc == 0)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "Command expected.");
if (argc > 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "Only one command is supported.");
ptr = argv[0];
for (i = 0; i < ARRAY_SIZE (pci_registers); i++)
{
if (grub_strncmp (ptr, pci_registers[i].name,
grub_strlen (pci_registers[i].name)) == 0)
break;
}
if (i == ARRAY_SIZE (pci_registers))
{
regsize = 0;
regaddr = grub_strtoul (ptr, (char **) &ptr, 16);
if (grub_errno)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "Unknown register");
}
else
{
regaddr = pci_registers[i].addr;
regsize = pci_registers[i].size;
ptr += grub_strlen (pci_registers[i].name);
}
if (grub_errno)
return grub_errno;
if (*ptr == '+')
{
ptr++;
regaddr += grub_strtoul (ptr, (char **) &ptr, 16);
if (grub_errno)
return grub_errno;
}
if (grub_memcmp (ptr, ".L", sizeof (".L") - 1) == 0
|| grub_memcmp (ptr, ".l", sizeof (".l") - 1) == 0)
{
regsize = 4;
ptr += sizeof (".l") - 1;
}
else if (grub_memcmp (ptr, ".W", sizeof (".W") - 1) == 0
|| grub_memcmp (ptr, ".w", sizeof (".w") - 1) == 0)
{
regsize = 2;
ptr += sizeof (".w") - 1;
}
else if (grub_memcmp (ptr, ".B", sizeof (".B") - 1) == 0
|| grub_memcmp (ptr, ".b", sizeof (".b") - 1) == 0)
{
regsize = 1;
ptr += sizeof (".b") - 1;
}
if (!regsize)
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"Unknown register size.");
write_mask = 0;
if (*ptr == '=')
{
ptr++;
regwrite = grub_strtoul (ptr, (char **) &ptr, 16);
if (grub_errno)
return grub_errno;
write_mask = 0xffffffff;
if (*ptr == ':')
{
ptr++;
write_mask = grub_strtoul (ptr, (char **) &ptr, 16);
if (grub_errno)
return grub_errno;
write_mask = 0xffffffff;
}
regwrite &= write_mask;
}
if (write_mask && varname)
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"Option -v isn't valid for writes.");
grub_pci_iterate (grub_setpci_iter);
return GRUB_ERR_NONE;
}
static grub_extcmd_t cmd;
GRUB_MOD_INIT(setpci)
{
cmd = grub_register_extcmd ("setpci", grub_cmd_setpci, GRUB_COMMAND_FLAG_BOTH,
N_("[-s POSITION] [-d DEVICE] [-v VAR] "
"[REGISTER][=VALUE[:MASK]]"),
N_("Manipulate PCI devices."), options);
}
GRUB_MOD_FINI(setpci)
{
grub_unregister_extcmd (cmd);
}

View file

@ -22,7 +22,6 @@
#include <grub/time.h> #include <grub/time.h>
#include <grub/types.h> #include <grub/types.h>
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/machine/time.h>
#include <grub/extcmd.h> #include <grub/extcmd.h>
#include <grub/i18n.h> #include <grub/i18n.h>

View file

@ -1,6 +1,6 @@
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 Free Software Foundation, Inc. * Copyright (C) 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
@ -26,37 +26,48 @@
struct grub_term_autoload *grub_term_input_autoload = NULL; struct grub_term_autoload *grub_term_input_autoload = NULL;
struct grub_term_autoload *grub_term_output_autoload = NULL; struct grub_term_autoload *grub_term_output_autoload = NULL;
struct abstract_terminal
{
struct abstract_terminal *next;
const char *name;
grub_err_t (*init) (void);
grub_err_t (*fini) (void);
};
static grub_err_t static grub_err_t
grub_cmd_terminal_input (grub_command_t cmd __attribute__ ((unused)), handle_command (int argc, char **args, struct abstract_terminal **enabled,
int argc, char **args) struct abstract_terminal **disabled,
struct grub_term_autoload *autoloads,
const char *active_str,
const char *available_str)
{ {
int i; int i;
grub_term_input_t term; struct abstract_terminal *term;
struct grub_term_autoload *aut; struct grub_term_autoload *aut;
if (argc == 0) if (argc == 0)
{ {
grub_puts_ (N_ ("Active input terminals:")); grub_puts_ (active_str);
FOR_ACTIVE_TERM_INPUTS(term) for (term = *enabled; term; term = term->next)
grub_printf ("%s ", term->name); grub_printf ("%s ", term->name);
grub_printf ("\n"); grub_printf ("\n");
grub_puts_ (N_ ("Available input terminals:")); grub_puts_ (available_str);
FOR_DISABLED_TERM_INPUTS(term) for (term = *disabled; term; term = term->next)
grub_printf ("%s ", term->name); grub_printf ("%s ", term->name);
/* This is quadratic but we don't expect mode than 30 terminal /* This is quadratic but we don't expect mode than 30 terminal
modules ever. */ modules ever. */
for (aut = grub_term_input_autoload; aut; aut = aut->next) for (aut = autoloads; aut; aut = aut->next)
{ {
FOR_DISABLED_TERM_INPUTS(term) for (term = *disabled; term; term = term->next)
if (grub_strcmp (term->name, aut->name) == 0) if (grub_strcmp (term->name, aut->name) == 0)
break; break;
if (!term) if (!term)
FOR_ACTIVE_TERM_INPUTS(term) for (term = *enabled; term; term = term->next)
if (grub_strcmp (term->name, aut->name) == 0) if (grub_strcmp (term->name, aut->name) == 0)
break; break;
if (!term) if (!term)
grub_printf ("%s ", aut->name); grub_printf ("%s ", aut->name);
} }
grub_printf ("\n"); grub_printf ("\n");
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
} }
@ -73,110 +84,108 @@ grub_cmd_terminal_input (grub_command_t cmd __attribute__ ((unused)),
{ {
int again = 0; int again = 0;
while (1) while (1)
{ {
FOR_DISABLED_TERM_INPUTS(term) for (term = *disabled; term; term = term->next)
if (grub_strcmp (args[i], term->name) == 0) if (grub_strcmp (args[i], term->name) == 0)
break; break;
if (term == 0) if (term == 0)
FOR_ACTIVE_TERM_INPUTS(term) for (term = *enabled; term; term = term->next)
if (grub_strcmp (args[i], term->name) == 0) if (grub_strcmp (args[i], term->name) == 0)
break; break;
if (term) if (term)
break; break;
if (again) if (again)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown terminal '%s'\n", return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown terminal '%s'\n",
args[i]); args[i]);
for (aut = grub_term_input_autoload; aut; aut = aut->next) for (aut = autoloads; aut; aut = aut->next)
if (grub_strcmp (args[i], aut->name) == 0) if (grub_strcmp (args[i], aut->name) == 0)
{ {
grub_dl_t mod; grub_dl_t mod;
mod = grub_dl_load (aut->modname); mod = grub_dl_load (aut->modname);
if (mod) if (mod)
grub_dl_ref (mod); grub_dl_ref (mod);
grub_errno = GRUB_ERR_NONE; grub_errno = GRUB_ERR_NONE;
break; break;
} }
if (!aut) if (!aut)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown terminal '%s'\n", return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown terminal '%s'\n",
args[i]); args[i]);
again = 1; again = 1;
} }
} }
if (grub_strcmp (args[0], "--append") == 0) if (grub_strcmp (args[0], "--append") == 0)
{ {
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
{ {
FOR_DISABLED_TERM_INPUTS(term) for (term = *disabled; term; term = term->next)
if (grub_strcmp (args[i], term->name) == 0) if (grub_strcmp (args[i], term->name) == 0)
break; break;
if (term) if (term)
{ {
grub_list_remove (GRUB_AS_LIST_P (&(grub_term_inputs_disabled)), if (term->init && term->init () != GRUB_ERR_NONE)
GRUB_AS_LIST (term)); return grub_errno;
if (term->init)
term->init (); grub_list_remove (GRUB_AS_LIST_P (disabled), GRUB_AS_LIST (term));
grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs), grub_list_push (GRUB_AS_LIST_P (enabled), GRUB_AS_LIST (term));
GRUB_AS_LIST (term)); }
} }
}
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
} }
if (grub_strcmp (args[0], "--remove") == 0) if (grub_strcmp (args[0], "--remove") == 0)
{ {
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
{ {
FOR_ACTIVE_TERM_INPUTS(term) for (term = *enabled; term; term = term->next)
if (grub_strcmp (args[i], term->name) == 0) if (grub_strcmp (args[i], term->name) == 0)
break; break;
if (term) if (term)
{ {
if (!term->next && term == grub_term_inputs) if (!term->next && term == *enabled)
return grub_error (GRUB_ERR_BAD_ARGUMENT, return grub_error (GRUB_ERR_BAD_ARGUMENT,
"can't remove the last terminal"); "can't remove the last terminal");
grub_list_remove (GRUB_AS_LIST_P (&(grub_term_inputs)), grub_list_remove (GRUB_AS_LIST_P (enabled), GRUB_AS_LIST (term));
GRUB_AS_LIST (term)); if (term->fini)
if (term->fini) term->fini ();
term->fini (); grub_list_push (GRUB_AS_LIST_P (disabled), GRUB_AS_LIST (term));
grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs_disabled), }
GRUB_AS_LIST (term)); }
}
}
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
} }
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
{ {
FOR_DISABLED_TERM_INPUTS(term) for (term = *disabled; term; term = term->next)
if (grub_strcmp (args[i], term->name) == 0) if (grub_strcmp (args[i], term->name) == 0)
break; break;
if (term) if (term)
{ {
grub_list_remove (GRUB_AS_LIST_P (&(grub_term_inputs_disabled)), if (term->init && term->init () != GRUB_ERR_NONE)
GRUB_AS_LIST (term)); return grub_errno;
if (term->init)
term->init ();
grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs),
GRUB_AS_LIST (term));
}
}
FOR_ACTIVE_TERM_INPUTS(term) grub_list_remove (GRUB_AS_LIST_P (disabled), GRUB_AS_LIST (term));
grub_list_push (GRUB_AS_LIST_P (enabled), GRUB_AS_LIST (term));
}
}
{ {
for (i = 0; i < argc; i++) struct abstract_terminal *next;
if (grub_strcmp (args[i], term->name) == 0) for (term = *enabled; term; term = next)
break;
if (i == argc)
{ {
if (!term->next && term == grub_term_inputs) next = term->next;
return grub_error (GRUB_ERR_BAD_ARGUMENT, for (i = 0; i < argc; i++)
"can't remove the last terminal"); if (grub_strcmp (args[i], term->name) == 0)
grub_list_remove (GRUB_AS_LIST_P (&(grub_term_inputs)), break;
GRUB_AS_LIST (term)); if (i == argc)
if (term->fini) {
term->fini (); if (!term->next && term == *enabled)
grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs_disabled), return grub_error (GRUB_ERR_BAD_ARGUMENT,
GRUB_AS_LIST (term)); "can't remove the last terminal");
grub_list_remove (GRUB_AS_LIST_P (enabled), GRUB_AS_LIST (term));
if (term->fini)
term->fini ();
grub_list_push (GRUB_AS_LIST_P (disabled), GRUB_AS_LIST (term));
}
} }
} }
@ -184,161 +193,34 @@ grub_cmd_terminal_input (grub_command_t cmd __attribute__ ((unused)),
} }
static grub_err_t static grub_err_t
grub_cmd_terminal_output (grub_command_t cmd __attribute__ ((unused)), grub_cmd_terminal_input (grub_command_t cmd __attribute__ ((unused)),
int argc, char **args) int argc, char **args)
{ {
int i; (void) GRUB_FIELD_MATCH (grub_term_inputs, struct abstract_terminal *, next);
grub_term_output_t term; (void) GRUB_FIELD_MATCH (grub_term_inputs, struct abstract_terminal *, name);
struct grub_term_autoload *aut; (void) GRUB_FIELD_MATCH (grub_term_inputs, struct abstract_terminal *, init);
(void) GRUB_FIELD_MATCH (grub_term_inputs, struct abstract_terminal *, fini);
return handle_command (argc, args,
(struct abstract_terminal **) &grub_term_inputs,
(struct abstract_terminal **) &grub_term_inputs_disabled,
grub_term_input_autoload,
N_ ("Active input terminals:"),
N_ ("Available input terminals:"));
}
if (argc == 0) static grub_err_t
{ grub_cmd_terminal_output (grub_command_t cmd __attribute__ ((unused)),
grub_puts_ (N_ ("Active output terminals:")); int argc, char **args)
FOR_ACTIVE_TERM_OUTPUTS(term) {
grub_printf ("%s ", term->name); (void) GRUB_FIELD_MATCH (grub_term_outputs, struct abstract_terminal *, next);
grub_printf ("\n"); (void) GRUB_FIELD_MATCH (grub_term_outputs, struct abstract_terminal *, name);
grub_puts_ (N_ ("Available output terminals:")); (void) GRUB_FIELD_MATCH (grub_term_outputs, struct abstract_terminal *, init);
FOR_DISABLED_TERM_OUTPUTS(term) (void) GRUB_FIELD_MATCH (grub_term_outputs, struct abstract_terminal *, fini);
grub_printf ("%s ", term->name); return handle_command (argc, args, (struct abstract_terminal **) &grub_term_outputs,
/* This is quadratic but we don't expect mode than 30 terminal (struct abstract_terminal **) &grub_term_outputs_disabled,
modules ever. */ grub_term_output_autoload,
for (aut = grub_term_output_autoload; aut; aut = aut->next) N_ ("Active output terminals:"),
{ N_ ("Available output terminals:"));
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; static grub_command_t cmd_terminal_input, cmd_terminal_output;
@ -347,14 +229,14 @@ GRUB_MOD_INIT(terminal)
{ {
cmd_terminal_input = cmd_terminal_input =
grub_register_command ("terminal_input", grub_cmd_terminal_input, grub_register_command ("terminal_input", grub_cmd_terminal_input,
"[--append|--remove] " N_("[--append|--remove] "
"[TERMINAL1] [TERMINAL2] ...", "[TERMINAL1] [TERMINAL2] ..."),
"List or select an input terminal."); N_("List or select an input terminal."));
cmd_terminal_output = cmd_terminal_output =
grub_register_command ("terminal_output", grub_cmd_terminal_output, grub_register_command ("terminal_output", grub_cmd_terminal_output,
"[--append|--remove] " N_("[--append|--remove] "
"[TERMINAL1] [TERMINAL2] ...", "[TERMINAL1] [TERMINAL2] ..."),
"List or select an output terminal."); N_("List or select an output terminal."));
} }
GRUB_MOD_FINI(terminal) GRUB_MOD_FINI(terminal)

View file

@ -83,15 +83,24 @@ grub_usb_get_string (grub_usb_device_t dev, grub_uint8_t index, int langid,
0x06, (3 << 8) | index, 0x06, (3 << 8) | index,
langid, descstr.length, (char *) descstrp); langid, descstr.length, (char *) descstrp);
*string = grub_malloc (descstr.length / 2); if (descstrp->length == 0)
{
grub_free (descstrp);
*string = grub_strdup ("");
if (! *string)
return GRUB_USB_ERR_INTERNAL;
return GRUB_USB_ERR_NONE;
}
*string = grub_malloc (descstr.length * 2 + 1);
if (! *string) if (! *string)
{ {
grub_free (descstrp); grub_free (descstrp);
return GRUB_USB_ERR_INTERNAL; return GRUB_USB_ERR_INTERNAL;
} }
grub_utf16_to_utf8 ((grub_uint8_t *) *string, descstrp->str, descstrp->length / 2 - 1); *grub_utf16_to_utf8 ((grub_uint8_t *) *string, descstrp->str,
(*string)[descstr.length / 2 - 1] = '\0'; descstrp->length / 2 - 1) = 0;
grub_free (descstrp); grub_free (descstrp);
return GRUB_USB_ERR_NONE; return GRUB_USB_ERR_NONE;

View file

@ -69,9 +69,9 @@ grub_cmd_videotest (grub_command_t cmd __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);
sansbig = grub_font_get ("Helvetica Bold 24"); sansbig = grub_font_get ("Unknown Regular 16");
sans = grub_font_get ("Helvetica Bold 14"); sans = grub_font_get ("Unknown Regular 16");
sanssmall = grub_font_get ("Helvetica 8"); sanssmall = grub_font_get ("Unknown Regular 16");
fixed = grub_font_get ("Fixed 20"); fixed = grub_font_get ("Fixed 20");
if (! sansbig || ! sans || ! sanssmall || ! fixed) if (! sansbig || ! sans || ! sanssmall || ! fixed)
return grub_error (GRUB_ERR_BAD_FONT, "no font loaded"); return grub_error (GRUB_ERR_BAD_FONT, "no font loaded");
@ -126,11 +126,6 @@ grub_cmd_videotest (grub_command_t cmd __attribute__ ((unused)),
grub_font_draw_string (str, fixed, color, 16, texty); grub_font_draw_string (str, fixed, color, 16, texty);
texty += grub_font_get_descent (fixed) + grub_font_get_leading (fixed); 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); texty += grub_font_get_ascent(sansbig);
grub_font_draw_string (str, sansbig, color, 16, texty); grub_font_draw_string (str, sansbig, color, 16, texty);
texty += grub_font_get_descent (sansbig) + grub_font_get_leading (sansbig); texty += grub_font_get_descent (sansbig) + grub_font_get_leading (sansbig);

View file

@ -61,7 +61,7 @@ grub_cmd_xnu_uuid (grub_command_t cmd __attribute__ ((unused)),
GRUB_MD_MD5->final (&ctx); GRUB_MD_MD5->final (&ctx);
xnu_uuid = GRUB_MD_MD5->read (&ctx); xnu_uuid = GRUB_MD_MD5->read (&ctx);
grub_sprintf (uuid_string, grub_snprintf (uuid_string, sizeof (uuid_string),
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", "%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[0], (unsigned int) xnu_uuid[1],
(unsigned int) xnu_uuid[2], (unsigned int) xnu_uuid[3], (unsigned int) xnu_uuid[2], (unsigned int) xnu_uuid[3],

View file

@ -1,100 +1,112 @@
# -*- makefile -*- # -*- makefile -*-
# Used by various components. These rules need to precede them. kernel_img_RELOCATABLE = yes
script/lexer.c_DEPENDENCIES = grub_script.tab.h pkglib_PROGRAMS = kernel.img
kernel_img_SOURCES = kern/device.c kern/disk.c kern/dl.c kern/env.c \
sbin_UTILITIES += grub-emu kern/err.c kern/list.c kern/command.c \
util/grub-emu.c_DEPENDENCIES = grub_emu_init.h kern/corecmd.c kern/file.c kern/fs.c kern/main.c kern/misc.c \
grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ kern/parser.c kern/partition.c kern/term.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 \ 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 \ kern/emu/main.c kern/emu/mm.c kern/emu/misc.c \
normal/completion.c normal/main.c normal/color.c \ kern/emu/getroot.c kern/emu/time.c kern/emu/hostdisk.c \
normal/menu.c normal/menu_entry.c \ kern/emu/hostfs.c kern/emu/console.c \
normal/menu_text.c normal/crypto.c normal/term.c \ \
commands/terminal.c lib/charset.c \ gnulib/progname.c disk/host.c
script/main.c script/execute.c script/function.c \ kernel_img_HEADERS += datetime.h emu/misc.h
script/lexer.c script/script.c grub_script.tab.c \ kernel_img_CFLAGS = $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -Wno-char-subscripts -Wno-unused -Wno-deprecated-declarations -Wno-undef -I$(srcdir)/gnulib
partmap/amiga.c partmap/apple.c partmap/msdos.c partmap/sun.c \ kernel_img_LDFLAGS = $(COMMON_LDFLAGS)
partmap/acorn.c partmap/gpt.c \ TARGET_NO_STRIP = yes
\
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
ifneq ($(TARGET_NO_MODULES), yes)
kernel_img_SOURCES += symlist.c kern/$(target_cpu)/dl.c
else
kernel_img_SOURCES += grub_emu_init.c
endif
ifneq ($(target_cpu), i386)
ifneq ($(target_cpu), x86_64)
kernel_img_SOURCES += kern/$(target_cpu)/cache.S
endif
endif
# For halt.mod.
pkglib_MODULES += halt.mod
halt_mod_SOURCES = commands/halt.c
halt_mod_CFLAGS = $(COMMON_CFLAGS)
halt_mod_LDFLAGS = $(COMMON_LDFLAGS)
ifeq ($(target_cpu), i386) ifeq ($(target_cpu), i386)
grub_emu_SOURCES += commands/i386/cpuid.c pkglib_MODULES += cpuid.mod
cpuid_mod_SOURCES = commands/i386/cpuid.c
cpuid_mod_CFLAGS = $(COMMON_CFLAGS)
cpuid_mod_LDFLAGS = $(COMMON_LDFLAGS)
endif endif
grub_emu_LDFLAGS = $(LIBCURSES) grub_emu_LDFLAGS = $(LIBCURSES)
ifeq ($(enable_grub_emu_usb), yes) ifeq ($(enable_grub_emu_usb), yes)
grub_emu_SOURCES += disk/usbms.c util/usb.c bus/usb/usb.c \ kernel_img_HEADERS += libusb.h
commands/usbtest.c
grub_emu_LDFLAGS += $(LIBCURSES) $(LIBUSB) pkglib_MODULES += libusb.mod
libusb_mod_SOURCES = bus/usb/emu/usb.c
libusb_mod_CFLAGS =
libusb_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For usb.mod
pkglib_MODULES += usb.mod
usb_mod_SOURCES = bus/usb/usb.c
usb_mod_CFLAGS = $(COMMON_CFLAGS)
usb_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For usbtest.mod
pkglib_MODULES += usbtest.mod
usbtest_mod_SOURCES = commands/usbtest.c
usbtest_mod_CFLAGS = $(COMMON_CFLAGS)
usbtest_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For usbms.mod
pkglib_MODULES += usbms.mod
usbms_mod_SOURCES = disk/usbms.c
usbms_mod_CFLAGS = $(COMMON_CFLAGS)
usbms_mod_LDFLAGS = $(COMMON_LDFLAGS)
grub_emu_LDFLAGS += $(LIBUSB)
endif
ifeq ($(enable_grub_emu_sdl), yes)
pkglib_MODULES += sdl.mod
sdl_mod_SOURCES = video/emu/sdl.c
sdl_mod_CFLAGS =
sdl_mod_LDFLAGS = $(COMMON_LDFLAGS)
grub_emu_LDFLAGS += $(LIBSDL)
kernel_img_HEADERS += sdl.h
endif endif
ifeq ($(enable_grub_emu_pci), yes) ifeq ($(enable_grub_emu_pci), yes)
grub_emu_SOURCES += util/pci.c commands/lspci.c pkglib_MODULES += pci.mod
pci_mod_SOURCES = bus/emu/pci.c commands/lspci.c
pci_mod_LDFLAGS = $(COMMON_LDFLAGS)
grub_emu_LDFLAGS += $(LIBPCIACCESS) grub_emu_LDFLAGS += $(LIBPCIACCESS)
kernel_img_HEADERS += libpciaccess.h
endif endif
grub_emu_init.lst: geninit.sh $(filter-out grub_emu_init.c,$(grub_emu_SOURCES)) include $(srcdir)/conf/common.mk
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 grub_emu_init.h: genemuinitheader.sh $(pkglib_MODULES)
rm -f $@; sh $(srcdir)/geninitheader.sh $< > $@ rm -f $@; echo $(pkglib_MODULES) | sh $(srcdir)/genemuinitheader.sh $(NM) > $@
DISTCLEANFILES += grub_emu_init.h 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 grub_emu_init.c: genemuinit.sh $(pkglib_MODULES) grub_emu_init.h
rm -f $@; sh $(srcdir)/geninit.sh $< $(filter %.c,$^) > $@ rm -f $@; echo $(pkglib_MODULES) | sh $(srcdir)/genemuinit.sh $(NM) > $@
DISTCLEANFILES += grub_emu_init.c DISTCLEANFILES += grub_emu_init.c
CLEANFILES += grub-emu
ifneq ($(TARGET_NO_MODULES), yes)
grub-emu: $(pkglib_PROGRAMS)
# FIXME: this could be shared with common.rmk $(CC) -o $@ $^ $(grub_emu_LDFLAGS) $(LDFLAGS)
else
# For grub-mkfont. grub-emu: $(pkglib_MODULES) $(pkglib_PROGRAMS)
ifeq ($(enable_grub_mkfont), yes) $(CC) -o $@ $^ $(grub_emu_LDFLAGS) $(LDFLAGS)
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 endif
GRUB_EMU=grub-emu
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

View file

@ -1,9 +1,13 @@
# -*- makefile -*- # -*- makefile -*-
# Used by various components. These rules need to precede them.
script/lexer.c_DEPENDENCIES = grub_script.tab.h grub_script.yy.h
sbin_UTILITIES += grub-mkdevicemap sbin_UTILITIES += grub-mkdevicemap
grub_mkdevicemap_SOURCES = gnulib/progname.c util/grub-mkdevicemap.c \ grub_mkdevicemap_SOURCES = gnulib/progname.c util/grub-mkdevicemap.c \
util/deviceiter.c \ util/deviceiter.c \
util/misc.c util/misc.c kern/emu/misc.c \
kern/env.c kern/err.c kern/list.c kern/misc.c kern/emu/mm.c
ifeq ($(target_cpu)-$(platform), sparc64-ieee1275) ifeq ($(target_cpu)-$(platform), sparc64-ieee1275)
grub_mkdevicemap_SOURCES += util/ieee1275/ofpath.c util/ieee1275/devicemap.c grub_mkdevicemap_SOURCES += util/ieee1275/ofpath.c util/ieee1275/devicemap.c
@ -11,28 +15,28 @@ else
grub_mkdevicemap_SOURCES += util/devicemap.c grub_mkdevicemap_SOURCES += util/devicemap.c
endif endif
# For grub-mkelfimage. # For grub-mkimage.
bin_UTILITIES += grub-mkelfimage bin_UTILITIES += grub-mkimage
grub_mkelfimage_SOURCES = gnulib/progname.c \ grub_mkimage_SOURCES = gnulib/progname.c util/grub-mkimage.c util/misc.c \
util/elf/grub-mkimage.c util/misc.c \ util/resolve.c kern/emu/misc.c lib/LzmaEnc.c lib/LzFind.c
util/resolve.c util/grub-mkimage.c_DEPENDENCIES = Makefile
util/elf/grub-mkimage.c_DEPENDENCIES = Makefile
# For grub-probe. # For grub-probe.
sbin_UTILITIES += grub-probe sbin_UTILITIES += grub-probe
util/grub-probe.c_DEPENDENCIES = grub_probe_init.h util/grub-probe.c_DEPENDENCIES = grub_probe_init.h
grub_probe_SOURCES = gnulib/progname.c util/grub-probe.c \ grub_probe_SOURCES = gnulib/progname.c util/grub-probe.c \
util/hostdisk.c util/misc.c util/getroot.c \ kern/emu/hostdisk.c util/misc.c kern/emu/misc.c kern/emu/getroot.c kern/emu/mm.c \
kern/device.c kern/disk.c kern/err.c kern/misc.c \ kern/device.c kern/disk.c kern/err.c kern/misc.c \
kern/parser.c kern/partition.c kern/file.c \ kern/partition.c kern/file.c kern/list.c \
\ \
fs/affs.c fs/cpio.c fs/fat.c fs/ext2.c fs/hfs.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/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/nilfs2.c fs/ntfs.c fs/ntfscomp.c fs/reiserfs.c \
fs/ufs.c fs/ufs2.c fs/xfs.c fs/afs.c fs/afs_be.c \ fs/sfs.c fs/ufs.c fs/ufs2.c fs/xfs.c fs/afs.c \
fs/befs.c fs/befs_be.c fs/tar.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\ partmap/msdos.c partmap/bsdlabel.c partmap/apple.c \
partmap/sun.c partmap/sunpc.c partmap/gpt.c \
kern/fs.c kern/env.c fs/fshelp.c \ kern/fs.c kern/env.c fs/fshelp.c \
disk/raid.c disk/mdraid_linux.c disk/lvm.c grub_probe_init.c disk/raid.c disk/mdraid_linux.c disk/lvm.c grub_probe_init.c
@ -40,24 +44,10 @@ ifeq ($(enable_grub_fstest), yes)
bin_UTILITIES += grub-fstest bin_UTILITIES += grub-fstest
endif 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. # For grub-fstest.
util/grub-fstest.c_DEPENDENCIES = grub_fstest_init.h util/grub-fstest.c_DEPENDENCIES = grub_fstest_init.h
grub_fstest_SOURCES = gnulib/progname.c util/grub-fstest.c util/hostfs.c \ grub_fstest_SOURCES = gnulib/progname.c util/grub-fstest.c kern/emu/hostfs.c \
util/misc.c \ util/misc.c kern/emu/misc.c kern/emu/mm.c \
kern/file.c kern/device.c kern/disk.c kern/err.c kern/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 \ 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/arg.c commands/extcmd.c normal/datetime.c normal/misc.c \
@ -65,12 +55,12 @@ grub_fstest_SOURCES = gnulib/progname.c util/grub-fstest.c util/hostfs.c \
\ \
fs/affs.c fs/cpio.c fs/fat.c fs/ext2.c fs/hfs.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/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/nilfs2.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/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 \ fs/befs_be.c fs/tar.c \
\ \
kern/partition.c partmap/msdos.c partmap/apple.c partmap/sun.c \ kern/partition.c partmap/msdos.c partmap/bsdlabel.c \
partmap/gpt.c \ partmap/apple.c partmap/sun.c partmap/sunpc.c partmap/gpt.c \
kern/fs.c kern/env.c fs/fshelp.c disk/raid.c \ kern/fs.c kern/env.c fs/fshelp.c disk/raid.c \
disk/raid5_recover.c disk/raid6_recover.c \ disk/raid5_recover.c disk/raid6_recover.c \
disk/mdraid_linux.c disk/dmraid_nvidia.c disk/lvm.c \ disk/mdraid_linux.c disk/dmraid_nvidia.c disk/lvm.c \
@ -79,14 +69,49 @@ grub_fstest_SOURCES = gnulib/progname.c util/grub-fstest.c util/hostfs.c \
# For grub-mkfont. # For grub-mkfont.
ifeq ($(enable_grub_mkfont), yes) ifeq ($(enable_grub_mkfont), yes)
bin_UTILITIES += grub-mkfont bin_UTILITIES += grub-mkfont
grub_mkfont_SOURCES = gnulib/progname.c util/grub-mkfont.c util/misc.c grub_mkfont_SOURCES = gnulib/progname.c util/grub-mkfont.c util/misc.c kern/emu/misc.c
grub_mkfont_CFLAGS = $(freetype_cflags) grub_mkfont_CFLAGS = $(freetype_cflags)
grub_mkfont_LDFLAGS = $(freetype_libs) grub_mkfont_LDFLAGS = $(freetype_libs)
endif endif
# For grub-mkrelpath. # For grub-mkrelpath.
bin_UTILITIES += grub-mkrelpath bin_UTILITIES += grub-mkrelpath
grub_mkrelpath_SOURCES = gnulib/progname.c util/grub-mkrelpath.c util/misc.c grub_mkrelpath_SOURCES = gnulib/progname.c util/grub-mkrelpath.c util/misc.c kern/emu/misc.c
bin_UTILITIES += grub-bin2h
grub_bin2h_SOURCES = gnulib/progname.c util/bin2h.c
# For the lexer.
grub_script.yy.c grub_script.yy.h: script/yylex.l
$(LEX) -o grub_script.yy.c --header-file=grub_script.yy.h $(srcdir)/script/yylex.l
DISTCLEANFILES += grub_script.yy.c grub_script.yy.h
# For grub-script-check.
bin_UTILITIES += grub-script-check
grub_script_check_SOURCES = gnulib/progname.c gnulib/getdelim.c gnulib/getline.c \
util/grub-script-check.c util/misc.c kern/emu/misc.c kern/emu/mm.c \
script/main.c script/script.c script/function.c script/lexer.c \
kern/err.c kern/list.c \
kern/misc.c kern/env.c grub_script.tab.c \
grub_script.yy.c
grub_script_check_CFLAGS = $(GNULIB_UTIL_CFLAGS)
MOSTLYCLEANFILES += symlist.c kernel_syms.lst
DEFSYMFILES += kernel_syms.lst
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 \
list.h command.h i18n.h env_private.h libgcc.h
ifneq ($(platform), emu)
kernel_img_HEADERS += machine/memory.h machine/loader.h
endif
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)
# For the parser. # For the parser.
grub_script.tab.c grub_script.tab.h: script/parser.y grub_script.tab.c grub_script.tab.h: script/parser.y
@ -134,7 +159,7 @@ DISTCLEANFILES += grub_fstest_init.c
# for grub-editenv # for grub-editenv
bin_UTILITIES += 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 grub_editenv_SOURCES = gnulib/progname.c util/grub-editenv.c lib/envblk.c util/misc.c kern/emu/misc.c kern/emu/mm.c kern/misc.c kern/err.c
CLEANFILES += grub-editenv CLEANFILES += grub-editenv
# Needed for genmk.rb to work # Needed for genmk.rb to work
@ -142,7 +167,7 @@ ifeq (0,1)
bin_UTILITIES += grub-macho2img grub-pe2elf bin_UTILITIES += grub-macho2img grub-pe2elf
endif endif
grub_pe2elf_SOURCES = gnulib/progname.c util/grub-pe2elf.c util/misc.c grub_pe2elf_SOURCES = gnulib/progname.c util/grub-pe2elf.c util/misc.c kern/emu/misc.c
CLEANFILES += grub-pe2elf CLEANFILES += grub-pe2elf
grub_macho2img_SOURCES = util/grub-macho2img.c grub_macho2img_SOURCES = util/grub-macho2img.c
@ -245,6 +270,12 @@ minix_mod_SOURCES = fs/minix.c
minix_mod_CFLAGS = $(COMMON_CFLAGS) minix_mod_CFLAGS = $(COMMON_CFLAGS)
minix_mod_LDFLAGS = $(COMMON_LDFLAGS) minix_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For nilfs2.mod.
pkglib_MODULES += nilfs2.mod
nilfs2_mod_SOURCES = fs/nilfs2.c
nilfs2_mod_CFLAGS = $(COMMON_CFLAGS)
nilfs2_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For hfs.mod. # For hfs.mod.
hfs_mod_SOURCES = fs/hfs.c hfs_mod_SOURCES = fs/hfs.c
hfs_mod_CFLAGS = $(COMMON_CFLAGS) hfs_mod_CFLAGS = $(COMMON_CFLAGS)
@ -352,6 +383,16 @@ part_gpt_mod_SOURCES = partmap/gpt.c
part_gpt_mod_CFLAGS = $(COMMON_CFLAGS) part_gpt_mod_CFLAGS = $(COMMON_CFLAGS)
part_gpt_mod_LDFLAGS = $(COMMON_LDFLAGS) part_gpt_mod_LDFLAGS = $(COMMON_LDFLAGS)
pkglib_MODULES += part_bsd.mod
part_bsd_mod_SOURCES = partmap/bsdlabel.c
part_bsd_mod_CFLAGS = $(COMMON_CFLAGS)
part_bsd_mod_LDFLAGS = $(COMMON_LDFLAGS)
pkglib_MODULES += part_sunpc.mod
part_sunpc_mod_SOURCES = partmap/sunpc.c
part_sunpc_mod_CFLAGS = $(COMMON_CFLAGS)
part_sunpc_mod_LDFLAGS = $(COMMON_LDFLAGS)
# Special disk structures and generic drivers # Special disk structures and generic drivers
pkglib_MODULES += raid.mod raid5rec.mod raid6rec.mod mdraid.mod dm_nv.mod \ pkglib_MODULES += raid.mod raid5rec.mod raid6rec.mod mdraid.mod dm_nv.mod \
@ -393,12 +434,12 @@ scsi_mod_CFLAGS = $(COMMON_CFLAGS)
scsi_mod_LDFLAGS = $(COMMON_LDFLAGS) scsi_mod_LDFLAGS = $(COMMON_LDFLAGS)
# Commands. # Commands.
pkglib_MODULES += minicmd.mod extcmd.mod hello.mod handler.mod \ pkglib_MODULES += minicmd.mod extcmd.mod hello.mod \
ls.mod cmp.mod cat.mod help.mod search.mod loopback.mod \ ls.mod cmp.mod cat.mod help.mod search.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 \ read.mod sleep.mod loadenv.mod crc.mod parttool.mod \
msdospart.mod memrw.mod normal.mod sh.mod \ msdospart.mod memrw.mod normal.mod \
gptsync.mod true.mod probe.mod password.mod \ gptsync.mod true.mod probe.mod password.mod \
keystatus.mod keystatus.mod
@ -427,6 +468,28 @@ 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 gfxmenu.mod.
pkglib_MODULES += gfxmenu.mod
gfxmenu_mod_SOURCES = \
gfxmenu/gfxmenu.c \
gfxmenu/model.c \
gfxmenu/view.c \
gfxmenu/icon_manager.c \
gfxmenu/theme_loader.c \
gfxmenu/widget-box.c \
gfxmenu/gui_canvas.c \
gfxmenu/gui_circular_progress.c \
gfxmenu/gui_box.c \
gfxmenu/gui_label.c \
gfxmenu/gui_list.c \
gfxmenu/gui_image.c \
gfxmenu/gui_progress_bar.c \
gfxmenu/gui_util.c \
gfxmenu/gui_string_util.c \
gfxmenu/named_colors.c
gfxmenu_mod_CFLAGS = $(COMMON_CFLAGS)
gfxmenu_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For parttool.mod. # For parttool.mod.
parttool_mod_SOURCES = commands/parttool.c parttool_mod_SOURCES = commands/parttool.c
parttool_mod_CFLAGS = $(COMMON_CFLAGS) parttool_mod_CFLAGS = $(COMMON_CFLAGS)
@ -437,11 +500,6 @@ msdospart_mod_SOURCES = parttool/msdospart.c
msdospart_mod_CFLAGS = $(COMMON_CFLAGS) msdospart_mod_CFLAGS = $(COMMON_CFLAGS)
msdospart_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
ls_mod_CFLAGS = $(COMMON_CFLAGS) ls_mod_CFLAGS = $(COMMON_CFLAGS)
@ -561,70 +619,87 @@ keystatus_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For normal.mod. # For normal.mod.
normal_mod_SOURCES = normal/main.c normal/cmdline.c normal/dyncmd.c \ normal_mod_SOURCES = normal/main.c normal/cmdline.c normal/dyncmd.c \
normal/auth.c normal/autofs.c normal/handler.c \ normal/auth.c normal/autofs.c \
normal/color.c normal/completion.c normal/datetime.c normal/menu.c \ normal/color.c normal/completion.c normal/datetime.c normal/menu.c \
normal/menu_entry.c normal/menu_text.c \ normal/menu_entry.c normal/menu_text.c \
normal/misc.c normal/crypto.c normal/term.c normal/misc.c normal/crypto.c normal/term.c normal/context.c \
normal_mod_CFLAGS = $(COMMON_CFLAGS) script/main.c script/script.c script/execute.c \
script/function.c script/lexer.c grub_script.tab.c grub_script.yy.c
normal_mod_CFLAGS = $(COMMON_CFLAGS) $(POSIX_CFLAGS) -Wno-error
normal_mod_LDFLAGS = $(COMMON_LDFLAGS) normal_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For sh.mod. ifneq (, $(FONT_SOURCE))
sh_mod_SOURCES = script/main.c script/script.c script/execute.c \ font/font.c_DEPENDENCIES = ascii.h
script/function.c script/lexer.c grub_script.tab.c endif
sh_mod_CFLAGS = $(COMMON_CFLAGS)
sh_mod_LDFLAGS = $(COMMON_LDFLAGS)
# Common Video Subsystem specific modules. # Common Video Subsystem specific modules.
pkglib_MODULES += video.mod videotest.mod bitmap.mod tga.mod jpeg.mod \ # On Yeeloong it's part of kernel
png.mod font.mod gfxterm.mod video_fb.mod ifneq ($(platform), yeeloong)
# For video.mod. # For video.mod.
pkglib_MODULES += video.mod
video_mod_SOURCES = video/video.c video_mod_SOURCES = video/video.c
video_mod_CFLAGS = $(COMMON_CFLAGS) video_mod_CFLAGS = $(COMMON_CFLAGS)
video_mod_LDFLAGS = $(COMMON_LDFLAGS) video_mod_LDFLAGS = $(COMMON_LDFLAGS)
pkglib_MODULES += video_fb.mod
video_fb_mod_SOURCES = video/fb/video_fb.c video/fb/fbblit.c \ video_fb_mod_SOURCES = video/fb/video_fb.c video/fb/fbblit.c \
video/fb/fbfill.c video/fb/fbutil.c video/fb/fbfill.c video/fb/fbutil.c
video_fb_mod_CFLAGS = $(COMMON_CFLAGS) video_fb_mod_CFLAGS = $(COMMON_CFLAGS)
video_fb_mod_LDFLAGS = $(COMMON_LDFLAGS) 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 # For bitmap.mod
pkglib_MODULES += bitmap.mod
bitmap_mod_SOURCES = video/bitmap.c bitmap_mod_SOURCES = video/bitmap.c
bitmap_mod_CFLAGS = $(COMMON_CFLAGS) bitmap_mod_CFLAGS = $(COMMON_CFLAGS)
bitmap_mod_LDFLAGS = $(COMMON_LDFLAGS) bitmap_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For tga.mod # For bitmap_scale.mod
tga_mod_SOURCES = video/readers/tga.c pkglib_MODULES += bitmap_scale.mod
tga_mod_CFLAGS = $(COMMON_CFLAGS) bitmap_scale_mod_SOURCES = video/bitmap_scale.c
tga_mod_LDFLAGS = $(COMMON_LDFLAGS) bitmap_scale_mod_CFLAGS = $(COMMON_CFLAGS)
bitmap_scale_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For jpeg.mod. pkglib_MODULES += font.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_SOURCES = font/font_cmd.c font/font.c
font_mod_CFLAGS = $(COMMON_CFLAGS) font_mod_CFLAGS = $(COMMON_CFLAGS)
font_mod_LDFLAGS = $(COMMON_LDFLAGS) font_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For gfxterm.mod. # For gfxterm.mod.
pkglib_MODULES += gfxterm.mod
gfxterm_mod_SOURCES = term/gfxterm.c gfxterm_mod_SOURCES = term/gfxterm.c
gfxterm_mod_CFLAGS = $(COMMON_CFLAGS) gfxterm_mod_CFLAGS = $(COMMON_CFLAGS)
gfxterm_mod_LDFLAGS = $(COMMON_LDFLAGS) gfxterm_mod_LDFLAGS = $(COMMON_LDFLAGS)
endif
# For videotest.mod.
pkglib_MODULES += videotest.mod
videotest_mod_SOURCES = commands/videotest.c
videotest_mod_CFLAGS = $(COMMON_CFLAGS)
videotest_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For tga.mod
pkglib_MODULES += tga.mod
tga_mod_SOURCES = video/readers/tga.c
tga_mod_CFLAGS = $(COMMON_CFLAGS)
tga_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For jpeg.mod.
pkglib_MODULES += jpeg.mod
jpeg_mod_SOURCES = video/readers/jpeg.c
jpeg_mod_CFLAGS = $(COMMON_CFLAGS)
jpeg_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For png.mod.
pkglib_MODULES += png.mod
png_mod_SOURCES = video/readers/png.c
png_mod_CFLAGS = $(COMMON_CFLAGS)
png_mod_LDFLAGS = $(COMMON_LDFLAGS)
# Misc. # Misc.
pkglib_MODULES += gzio.mod bufio.mod elf.mod pkglib_MODULES += gzio.mod elf.mod
# For elf.mod. # For elf.mod.
elf_mod_SOURCES = kern/elf.c elf_mod_SOURCES = kern/elf.c
@ -636,10 +711,14 @@ 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)
# On Yeeloong it's part of kernel
ifneq ($(platform), yeeloong)
# For bufio.mod. # For bufio.mod.
pkglib_MODULES += bufio.mod
bufio_mod_SOURCES = io/bufio.c bufio_mod_SOURCES = io/bufio.c
bufio_mod_CFLAGS = $(COMMON_CFLAGS) bufio_mod_CFLAGS = $(COMMON_CFLAGS)
bufio_mod_LDFLAGS = $(COMMON_LDFLAGS) bufio_mod_LDFLAGS = $(COMMON_LDFLAGS)
endif
# For gettext.mod. # For gettext.mod.
pkglib_MODULES += gettext.mod pkglib_MODULES += gettext.mod
@ -655,6 +734,18 @@ xnu_uuid_mod_SOURCES = commands/xnu_uuid.c
xnu_uuid_mod_CFLAGS = $(COMMON_CFLAGS) xnu_uuid_mod_CFLAGS = $(COMMON_CFLAGS)
xnu_uuid_mod_LDFLAGS = $(COMMON_LDFLAGS) xnu_uuid_mod_LDFLAGS = $(COMMON_LDFLAGS)
pkglib_MODULES += trig.mod
trig_mod_SOURCES = trigtables.c
trig_mod_CFLAGS = $(COMMON_CFLAGS)
trig_mod_LDFLAGS = $(COMMON_LDFLAGS)
trigtables.c: gentrigtables
./gentrigtables > $@
DISTCLEANFILES += trigtables.c
gentrigtables: gentrigtables.c
$(CC) -o $@ $^ $(CPPFLAGS) -lm
DISTCLEANFILES += gentrigtables
pkglib_MODULES += setjmp.mod pkglib_MODULES += setjmp.mod
setjmp_mod_SOURCES = lib/$(target_cpu)/setjmp.S setjmp_mod_SOURCES = lib/$(target_cpu)/setjmp.S
setjmp_mod_ASFLAGS = $(COMMON_ASFLAGS) setjmp_mod_ASFLAGS = $(COMMON_ASFLAGS)
@ -665,6 +756,11 @@ charset_mod_SOURCES = lib/charset.c
charset_mod_CFLAGS = $(COMMON_CFLAGS) charset_mod_CFLAGS = $(COMMON_CFLAGS)
charset_mod_LDFLAGS = $(COMMON_LDFLAGS) charset_mod_LDFLAGS = $(COMMON_LDFLAGS)
pkglib_MODULES += regexp.mod
regexp_mod_SOURCES = gnulib/regex.c commands/regexp.c
regexp_mod_CFLAGS = $(COMMON_CFLAGS) $(GNULIB_CFLAGS)
regexp_mod_LDFLAGS = $(COMMON_LDFLAGS)
pkglib_MODULES += terminal.mod pkglib_MODULES += terminal.mod
terminal_mod_SOURCES = commands/terminal.c terminal_mod_SOURCES = commands/terminal.c
terminal_mod_CFLAGS = $(COMMON_CFLAGS) terminal_mod_CFLAGS = $(COMMON_CFLAGS)
@ -691,8 +787,44 @@ password_pbkdf2_mod_SOURCES = commands/password_pbkdf2.c
password_pbkdf2_mod_CFLAGS = $(COMMON_CFLAGS) password_pbkdf2_mod_CFLAGS = $(COMMON_CFLAGS)
password_pbkdf2_mod_LDFLAGS = $(COMMON_LDFLAGS) password_pbkdf2_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For memdisk.mod.
pkglib_MODULES += memdisk.mod
memdisk_mod_SOURCES = disk/memdisk.c
memdisk_mod_CFLAGS = $(COMMON_CFLAGS)
memdisk_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For reboot.mod.
pkglib_MODULES += reboot.mod
reboot_mod_SOURCES = commands/reboot.c
reboot_mod_CFLAGS = $(COMMON_CFLAGS)
reboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For date.mod
pkglib_MODULES += date.mod
date_mod_SOURCES = commands/date.c
date_mod_CFLAGS = $(COMMON_CFLAGS)
date_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For datehook.mod
pkglib_MODULES += datehook.mod
datehook_mod_SOURCES = hook/datehook.c
datehook_mod_CFLAGS = $(COMMON_CFLAGS)
datehook_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For lsmmap.mod
pkglib_MODULES += lsmmap.mod
lsmmap_mod_SOURCES = commands/lsmmap.c
lsmmap_mod_CFLAGS = $(COMMON_CFLAGS)
lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For boot.mod.
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)
bin_UTILITIES += grub-mkpasswd-pbkdf2 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_SOURCES = gnulib/progname.c gnulib/getdelim.c gnulib/getline.c util/grub-mkpasswd-pbkdf2.c lib/crypto.c lib/libgcrypt-grub/cipher/sha512.c lib/pbkdf2.c util/misc.c kern/emu/misc.c kern/emu/mm.c kern/err.c
grub_mkpasswd_pbkdf2_CFLAGS += -Wno-missing-field-initializers -Wno-error -I$(srcdir)/lib/libgcrypt_wrap -DGRUB_MKPASSWD=1 grub_mkpasswd_pbkdf2_CFLAGS += -Wno-missing-field-initializers -Wno-error -I$(srcdir)/lib/libgcrypt_wrap -DGRUB_MKPASSWD=1
include $(srcdir)/conf/gcry.mk include $(srcdir)/conf/gcry.mk

View file

@ -1,29 +1,20 @@
# -*- makefile -*- # -*- makefile -*-
COMMON_ASFLAGS = -nostdinc -fno-builtin -m32 COMMON_CFLAGS = -mrtd -mregparm=3
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. # Images.
GRUB_KERNEL_MACHINE_LINK_ADDR = 0x8200
ifeq ($(platform), coreboot)
pkglib_PROGRAMS += kernel.img pkglib_PROGRAMS += kernel.img
kernel_img_SOURCES = kern/i386/coreboot/startup.S \ kernel_img_SOURCES = kern/i386/coreboot/startup.S \
kern/i386/misc.S \ kern/i386/misc.S \
kern/i386/coreboot/init.c \ kern/i386/coreboot/init.c \
kern/i386/multiboot_mmap.c \ kern/i386/coreboot/mmap.c \
kern/i386/halt.c \ kern/i386/halt.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/term.c \ kern/misc.c kern/mm.c kern/term.c \
kern/rescue_parser.c kern/rescue_reader.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/time.c kern/list.c kern/command.c kern/corecmd.c \
kern/$(target_cpu)/dl.c kern/parser.c kern/partition.c \ kern/$(target_cpu)/dl.c kern/parser.c kern/partition.c \
kern/i386/tsc.c kern/i386/pit.c \ kern/i386/tsc.c kern/i386/pit.c \
kern/generic/rtc_get_time_ms.c \ kern/generic/rtc_get_time_ms.c \
@ -31,69 +22,9 @@ kernel_img_SOURCES = kern/i386/coreboot/startup.S \
kern/env.c \ kern/env.c \
term/i386/pc/vga_text.c term/i386/vga_common.c \ term/i386/pc/vga_text.c term/i386/vga_common.c \
symlist.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_CFLAGS = $(COMMON_CFLAGS)
kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
kernel_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-S,-Ttext,$(GRUB_KERNEL_MACHINE_LINK_ADDR),-Bstatic kernel_img_LDFLAGS += $(COMMON_LDFLAGS) -Wl,-N,-S,-Ttext,0x8200,-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 sbin_SCRIPTS += grub-install
grub_install_SOURCES = util/grub-install.in grub_install_SOURCES = util/grub-install.in
@ -102,17 +33,7 @@ bin_SCRIPTS += grub-mkrescue
grub_mkrescue_SOURCES = util/grub-mkrescue.in grub_mkrescue_SOURCES = util/grub-mkrescue.in
# Modules. # Modules.
pkglib_MODULES = linux.mod \ pkglib_MODULES = linux.mod aout.mod halt.mod datetime.mod mmap.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. # For mmap.mod.
mmap_mod_SOURCES = mmap/mmap.c mmap/i386/uppermem.c mmap/i386/mmap.c mmap_mod_SOURCES = mmap/mmap.c mmap/i386/uppermem.c mmap/i386/mmap.c
@ -125,21 +46,11 @@ 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 reboot.mod.
reboot_mod_SOURCES = commands/reboot.c
reboot_mod_CFLAGS = $(COMMON_CFLAGS)
reboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For halt.mod. # For halt.mod.
halt_mod_SOURCES = commands/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 serial.mod.
serial_mod_SOURCES = term/i386/pc/serial.c
serial_mod_CFLAGS = $(COMMON_CFLAGS)
serial_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For aout.mod. # For aout.mod.
aout_mod_SOURCES = loader/aout.c aout_mod_SOURCES = loader/aout.c
aout_mod_CFLAGS = $(COMMON_CFLAGS) aout_mod_CFLAGS = $(COMMON_CFLAGS)
@ -152,45 +63,16 @@ bsd_mod_CFLAGS = $(COMMON_CFLAGS)
bsd_mod_LDFLAGS = $(COMMON_LDFLAGS) bsd_mod_LDFLAGS = $(COMMON_LDFLAGS)
bsd_mod_ASFLAGS = $(COMMON_ASFLAGS) 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 # For datetime.mod
datetime_mod_SOURCES = lib/i386/datetime.c datetime_mod_SOURCES = lib/cmos_datetime.c
datetime_mod_CFLAGS = $(COMMON_CFLAGS) datetime_mod_CFLAGS = $(COMMON_CFLAGS)
datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) datetime_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For date.mod # For cmostest.mod
date_mod_SOURCES = commands/date.c pkglib_MODULES += cmostest.mod
date_mod_CFLAGS = $(COMMON_CFLAGS) cmostest_mod_SOURCES = commands/i386/cmostest.c
date_mod_LDFLAGS = $(COMMON_LDFLAGS) cmostest_mod_CFLAGS = $(COMMON_CFLAGS)
cmostest_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/i386.mk
include $(srcdir)/conf/common.mk include $(srcdir)/conf/common.mk

View file

@ -1,164 +1,5 @@
# -*- makefile -*- # -*- makefile -*-
COMMON_ASFLAGS = -nostdinc -fno-builtin -m32 COMMON_LDFLAGS = -melf_i386
COMMON_CFLAGS = -fno-builtin -m32
COMMON_LDFLAGS = -melf_i386 -nostdlib
# Used by various components. These rules need to precede them. include $(srcdir)/conf/x86-efi.mk
script/lexer.c_DEPENDENCIES = grub_script.tab.h
# Utilities.
bin_UTILITIES = grub-mkimage
# For grub-mkimage.
grub_mkimage_SOURCES = gnulib/progname.c util/i386/efi/grub-mkimage.c \
util/misc.c util/resolve.c
util/i386/efi/grub-mkimage.c_DEPENDENCIES = Makefile
# For grub-setup.
#grub_setup_SOURCES = util/i386/pc/grub-setup.c util/hostdisk.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 \
# fs/sfs.c kern/parser.c kern/partition.c partmap/msdos.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
# Scripts.
sbin_SCRIPTS = grub-install
# For grub-install.
grub_install_SOURCES = util/i386/efi/grub-install.in
# Modules.
pkglib_MODULES = kernel.img chain.mod appleldr.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.img.
kernel_img_EXPORTS = no
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/misc.c kern/mm.c kern/term.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 \
term/efi/console.c disk/efi/efidisk.c \
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 \
partition.h msdos_partition.h reader.h symbol.h term.h time.h types.h \
efi/efi.h efi/time.h efi/disk.h i386/pit.h list.h handler.h command.h i18n.h
kernel_img_CFLAGS = $(COMMON_CFLAGS)
kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
kernel_img_LDFLAGS = $(COMMON_LDFLAGS)
MOSTLYCLEANFILES += symlist.c
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)
# For boot.mod.
pkglib_MODULES += boot.mod
boot_mod_SOURCES = commands/boot.c
boot_mod_CFLAGS = $(COMMON_CFLAGS)
boot_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For acpi.mod.
acpi_mod_SOURCES = commands/acpi.c commands/efi/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/efi/mmap.c
mmap_mod_CFLAGS = $(COMMON_CFLAGS)
mmap_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For chain.mod.
chain_mod_SOURCES = loader/efi/chainloader.c
chain_mod_CFLAGS = $(COMMON_CFLAGS)
chain_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For appleldr.mod.
appleldr_mod_SOURCES = loader/efi/appleloader.c
appleldr_mod_CFLAGS = $(COMMON_CFLAGS)
appleldr_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For linux.mod.
linux_mod_SOURCES = loader/i386/efi/linux.c
linux_mod_CFLAGS = $(COMMON_CFLAGS)
linux_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For halt.mod.
halt_mod_SOURCES = commands/halt.c
halt_mod_CFLAGS = $(COMMON_CFLAGS)
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/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

View file

@ -1,11 +1,6 @@
# -*- makefile -*- # -*- makefile -*-
COMMON_ASFLAGS = -m32 -nostdinc -fno-builtin COMMON_CFLAGS = -mrtd -mregparm=3
COMMON_CFLAGS = -ffreestanding -mrtd -mregparm=3
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.img pkglib_PROGRAMS = kernel.img
@ -23,29 +18,16 @@ kernel_img_SOURCES = kern/i386/ieee1275/startup.S \
kern/rescue_parser.c kern/rescue_reader.c \ kern/rescue_parser.c kern/rescue_reader.c \
kern/$(target_cpu)/dl.c kern/parser.c kern/partition.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/time.c kern/list.c kern/command.c kern/corecmd.c \
kern/generic/millisleep.c \ kern/generic/millisleep.c \
kern/ieee1275/ieee1275.c \ kern/ieee1275/ieee1275.c \
term/ieee1275/ofconsole.c \ term/ieee1275/ofconsole.c \
disk/ieee1275/ofdisk.c \ disk/ieee1275/ofdisk.c \
symlist.c symlist.c
kernel_img_HEADERS = cache.h device.h disk.h dl.h elf.h elfload.h \ kernel_img_HEADERS += ieee1275/ieee1275.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 \
ieee1275/ieee1275.h machine/kernel.h machine/loader.h machine/memory.h \
list.h handler.h command.h i18n.h
kernel_img_CFLAGS = $(COMMON_CFLAGS) kernel_img_CFLAGS = $(COMMON_CFLAGS)
kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
kernel_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-S,-Ttext,0x10000,-Bstatic kernel_img_LDFLAGS += $(COMMON_LDFLAGS) -Wl,-N,-S,-Ttext,0x10000,-Bstatic
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)
# Scripts. # Scripts.
sbin_SCRIPTS = grub-install sbin_SCRIPTS = grub-install
@ -54,16 +36,10 @@ sbin_SCRIPTS = grub-install
grub_install_SOURCES = util/ieee1275/grub-install.in grub_install_SOURCES = util/ieee1275/grub-install.in
# Modules. # Modules.
pkglib_MODULES = halt.mod reboot.mod suspend.mod \ pkglib_MODULES = halt.mod suspend.mod \
aout.mod serial.mod linux.mod \ aout.mod linux.mod \
nand.mod memdisk.mod pci.mod lspci.mod datetime.mod \ nand.mod datetime.mod \
date.mod datehook.mod lsmmap.mod mmap.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. # For mmap.mod.
mmap_mod_SOURCES = mmap/mmap.c mmap/i386/uppermem.c mmap/i386/mmap.c mmap_mod_SOURCES = mmap/mmap.c mmap/i386/uppermem.c mmap/i386/mmap.c
@ -81,21 +57,11 @@ 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
reboot_mod_SOURCES = commands/reboot.c
reboot_mod_CFLAGS = $(COMMON_CFLAGS)
reboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For halt.mod # For halt.mod
halt_mod_SOURCES = commands/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 serial.mod.
serial_mod_SOURCES = term/i386/pc/serial.c
serial_mod_CFLAGS = $(COMMON_CFLAGS)
serial_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For linux.mod. # For linux.mod.
linux_mod_SOURCES = loader/i386/ieee1275/linux.c linux_mod_SOURCES = loader/i386/ieee1275/linux.c
linux_mod_CFLAGS = $(COMMON_CFLAGS) linux_mod_CFLAGS = $(COMMON_CFLAGS)
@ -106,40 +72,10 @@ nand_mod_SOURCES = disk/ieee1275/nand.c
nand_mod_CFLAGS = $(COMMON_CFLAGS) nand_mod_CFLAGS = $(COMMON_CFLAGS)
nand_mod_LDFLAGS = $(COMMON_LDFLAGS) 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 # For datetime.mod
datetime_mod_SOURCES = lib/i386/datetime.c datetime_mod_SOURCES = lib/cmos_datetime.c
datetime_mod_CFLAGS = $(COMMON_CFLAGS) datetime_mod_CFLAGS = $(COMMON_CFLAGS)
datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) 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/i386.mk
include $(srcdir)/conf/common.mk include $(srcdir)/conf/common.mk

74
conf/i386-multiboot.rmk Normal file
View file

@ -0,0 +1,74 @@
# -*- makefile -*-
COMMON_CFLAGS = -mrtd -mregparm=3
# Images.
GRUB_KERNEL_MACHINE_LINK_ADDR = 0x8200
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_CFLAGS = $(COMMON_CFLAGS)
kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
kernel_img_LDFLAGS += $(COMMON_LDFLAGS) -Wl,-N,-S,-Ttext,$(GRUB_KERNEL_MACHINE_LINK_ADDR),-Bstatic
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 halt.mod datetime.mod mmap.mod
# 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 halt.mod.
halt_mod_SOURCES = commands/halt.c
halt_mod_CFLAGS = $(COMMON_CFLAGS)
halt_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 datetime.mod
datetime_mod_SOURCES = lib/cmos_datetime.c
datetime_mod_CFLAGS = $(COMMON_CFLAGS)
datetime_mod_LDFLAGS = $(COMMON_LDFLAGS)
include $(srcdir)/conf/i386.mk
include $(srcdir)/conf/common.mk

View file

@ -1,17 +1,9 @@
# -*- makefile -*- # -*- makefile -*-
GRUB_KERNEL_MACHINE_LINK_ADDR = 0x8200 COMMON_CFLAGS = -mrtd -mregparm=3
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. # Images.
pkglib_IMAGES = boot.img cdboot.img diskboot.img kernel.img lnxboot.img \ pkglib_IMAGES = boot.img cdboot.img diskboot.img lnxboot.img pxeboot.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
@ -44,13 +36,14 @@ cdboot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)0x7C00
cdboot_img_FORMAT = binary cdboot_img_FORMAT = binary
# For kernel.img. # For kernel.img.
pkglib_PROGRAMS = kernel.img
kernel_img_SOURCES = kern/i386/pc/startup.S \ kernel_img_SOURCES = kern/i386/pc/startup.S \
kern/i386/misc.S \ kern/i386/misc.S \
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/term.c \ kern/misc.c kern/mm.c kern/term.c \
kern/rescue_parser.c kern/rescue_reader.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/time.c kern/list.c kern/command.c kern/corecmd.c \
kern/$(target_cpu)/dl.c kern/i386/pc/init.c kern/i386/pc/mmap.c \ kern/$(target_cpu)/dl.c kern/i386/pc/init.c kern/i386/pc/mmap.c \
kern/parser.c kern/partition.c \ kern/parser.c kern/partition.c \
kern/i386/tsc.c kern/i386/pit.c \ kern/i386/tsc.c kern/i386/pit.c \
@ -59,54 +52,34 @@ kernel_img_SOURCES = kern/i386/pc/startup.S \
kern/env.c \ kern/env.c \
term/i386/pc/console.c term/i386/vga_common.c \ term/i386/pc/console.c term/i386/vga_common.c \
symlist.c symlist.c
kernel_img_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ kernel_img_HEADERS += machine/biosdisk.h machine/vga.h machine/vbe.h \
env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \ machine/pxe.h i386/pit.h machine/kernel.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/memory.h machine/loader.h machine/vga.h machine/vbe.h \
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_CFLAGS = $(COMMON_CFLAGS) $(TARGET_IMG_CFLAGS)
kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
kernel_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)$(GRUB_KERNEL_MACHINE_LINK_ADDR) $(COMMON_CFLAGS) kernel_img_LDFLAGS += $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)0x8200 $(COMMON_CFLAGS)
kernel_img_FORMAT = binary
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)
# Utilities. # Utilities.
bin_UTILITIES = grub-mkimage
sbin_UTILITIES = grub-setup sbin_UTILITIES = grub-setup
# For grub-mkimage.
grub_mkimage_SOURCES = gnulib/progname.c util/i386/pc/grub-mkimage.c util/misc.c \
util/resolve.c lib/LzmaEnc.c lib/LzFind.c
grub_mkimage_CFLAGS = -DGRUB_KERNEL_MACHINE_LINK_ADDR=$(GRUB_KERNEL_MACHINE_LINK_ADDR)
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 = gnulib/progname.c \ grub_setup_SOURCES = gnulib/progname.c util/i386/pc/grub-setup.c \
util/i386/pc/grub-setup.c util/hostdisk.c \ util/misc.c kern/emu/misc.c kern/emu/getroot.c \
util/misc.c util/getroot.c kern/device.c kern/disk.c \ kern/emu/hostdisk.c kern/device.c kern/disk.c kern/err.c \
kern/err.c kern/misc.c kern/parser.c kern/partition.c \ kern/misc.c kern/partition.c kern/file.c \
kern/file.c kern/fs.c kern/env.c fs/fshelp.c \ kern/emu/mm.c kern/fs.c kern/env.c kern/list.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/udf.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/nilfs2.c fs/ntfs.c fs/ntfscomp.c fs/reiserfs.c \
fs/ufs.c fs/ufs2.c fs/xfs.c fs/afs.c fs/afs_be.c \ fs/sfs.c fs/ufs.c fs/ufs2.c fs/xfs.c fs/afs.c \
fs/befs.c fs/befs_be.c fs/tar.c \ fs/afs_be.c fs/befs.c fs/befs_be.c fs/tar.c \
\ \
partmap/msdos.c partmap/gpt.c \ partmap/msdos.c partmap/bsdlabel.c partmap/sunpc.c \
\ partmap/gpt.c \
disk/raid.c disk/mdraid_linux.c disk/lvm.c \ \
util/raid.c util/lvm.c \ disk/raid.c disk/mdraid_linux.c disk/lvm.c \
util/raid.c util/lvm.c \
grub_setup_init.c grub_setup_init.c
sbin_SCRIPTS += grub-install sbin_SCRIPTS += grub-install
@ -116,20 +89,14 @@ bin_SCRIPTS += grub-mkrescue
grub_mkrescue_SOURCES = util/grub-mkrescue.in grub_mkrescue_SOURCES = util/grub-mkrescue.in
pkglib_MODULES = biosdisk.mod chain.mod \ pkglib_MODULES = biosdisk.mod chain.mod \
reboot.mod halt.mod \ halt.mod \
vbe.mod vbetest.mod vbeinfo.mod play.mod serial.mod \ vbe.mod vbetest.mod vbeinfo.mod \
vga.mod memdisk.mod pci.mod lspci.mod \ vga.mod \
aout.mod bsd.mod pxe.mod pxecmd.mod datetime.mod date.mod \ aout.mod bsd.mod pxe.mod pxecmd.mod datetime.mod \
datehook.mod lsmmap.mod ata_pthru.mod hdparm.mod \ ata_pthru.mod hdparm.mod \
usb.mod uhci.mod ohci.mod usbtest.mod usbms.mod usb_keyboard.mod \ usb.mod uhci.mod ohci.mod usbtest.mod usbms.mod usb_keyboard.mod \
efiemu.mod mmap.mod acpi.mod drivemap.mod efiemu.mod mmap.mod acpi.mod drivemap.mod
# For boot.mod.
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 drivemap.mod. # For drivemap.mod.
drivemap_mod_SOURCES = commands/i386/pc/drivemap.c \ drivemap_mod_SOURCES = commands/i386/pc/drivemap.c \
commands/i386/pc/drivemap_int13h.S commands/i386/pc/drivemap_int13h.S
@ -186,21 +153,11 @@ xnu_mod_CFLAGS = $(COMMON_CFLAGS)
xnu_mod_LDFLAGS = $(COMMON_LDFLAGS) xnu_mod_LDFLAGS = $(COMMON_LDFLAGS)
xnu_mod_ASFLAGS = $(COMMON_ASFLAGS) xnu_mod_ASFLAGS = $(COMMON_ASFLAGS)
# For reboot.mod.
reboot_mod_SOURCES = commands/reboot.c
reboot_mod_CFLAGS = $(COMMON_CFLAGS)
reboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For halt.mod. # For halt.mod.
halt_mod_SOURCES = commands/i386/pc/halt.c halt_mod_SOURCES = commands/i386/pc/halt.c
halt_mod_CFLAGS = $(COMMON_CFLAGS) halt_mod_CFLAGS = $(COMMON_CFLAGS)
halt_mod_LDFLAGS = $(COMMON_LDFLAGS) 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 vbe.mod. # For vbe.mod.
vbe_mod_SOURCES = video/i386/pc/vbe.c vbe_mod_SOURCES = video/i386/pc/vbe.c
vbe_mod_CFLAGS = $(COMMON_CFLAGS) vbe_mod_CFLAGS = $(COMMON_CFLAGS)
@ -216,31 +173,11 @@ vbetest_mod_SOURCES = commands/i386/pc/vbetest.c
vbetest_mod_CFLAGS = $(COMMON_CFLAGS) vbetest_mod_CFLAGS = $(COMMON_CFLAGS)
vbetest_mod_LDFLAGS = $(COMMON_LDFLAGS) vbetest_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 vga.mod. # For vga.mod.
vga_mod_SOURCES = term/i386/pc/vga.c vga_mod_SOURCES = video/i386/pc/vga.c
vga_mod_CFLAGS = $(COMMON_CFLAGS) vga_mod_CFLAGS = $(COMMON_CFLAGS)
vga_mod_LDFLAGS = $(COMMON_LDFLAGS) vga_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 aout.mod # For aout.mod
aout_mod_SOURCES = loader/aout.c aout_mod_SOURCES = loader/aout.c
aout_mod_CFLAGS = $(COMMON_CFLAGS) aout_mod_CFLAGS = $(COMMON_CFLAGS)
@ -293,25 +230,10 @@ pxecmd_mod_CFLAGS = $(COMMON_CFLAGS)
pxecmd_mod_LDFLAGS = $(COMMON_LDFLAGS) pxecmd_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For datetime.mod # For datetime.mod
datetime_mod_SOURCES = lib/i386/datetime.c datetime_mod_SOURCES = lib/cmos_datetime.c
datetime_mod_CFLAGS = $(COMMON_CFLAGS) datetime_mod_CFLAGS = $(COMMON_CFLAGS)
datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) 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. # For ata_pthru.mod.
ata_pthru_mod_SOURCES = disk/ata_pthru.c ata_pthru_mod_SOURCES = disk/ata_pthru.c
ata_pthru_mod_CFLAGS = $(COMMON_CFLAGS) ata_pthru_mod_CFLAGS = $(COMMON_CFLAGS)
@ -322,6 +244,12 @@ hdparm_mod_SOURCES = commands/hdparm.c lib/hexdump.c
hdparm_mod_CFLAGS = $(COMMON_CFLAGS) hdparm_mod_CFLAGS = $(COMMON_CFLAGS)
hdparm_mod_LDFLAGS = $(COMMON_LDFLAGS) hdparm_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For cmostest.mod
pkglib_MODULES += cmostest.mod
cmostest_mod_SOURCES = commands/i386/cmostest.c
cmostest_mod_CFLAGS = $(COMMON_CFLAGS)
cmostest_mod_LDFLAGS = $(COMMON_LDFLAGS)
ifeq ($(enable_efiemu), yes) ifeq ($(enable_efiemu), yes)
efiemu32.o: efiemu/runtime/efiemu.c $(TARGET_OBJ2ELF) efiemu32.o: efiemu/runtime/efiemu.c $(TARGET_OBJ2ELF)

View file

@ -1,2 +1,82 @@
# -*- makefile -*- # -*- makefile -*-
include $(srcdir)/conf/i386-coreboot.mk
COMMON_CFLAGS = -mrtd -mregparm=3
# Images.
GRUB_KERNEL_MACHINE_LINK_ADDR = 0x8200
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
pkglib_PROGRAMS += 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/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_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
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 halt.mod datetime.mod mmap.mod
# 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 halt.mod.
halt_mod_SOURCES = commands/halt.c
halt_mod_CFLAGS = $(COMMON_CFLAGS)
halt_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 datetime.mod
datetime_mod_SOURCES = lib/cmos_datetime.c
datetime_mod_CFLAGS = $(COMMON_CFLAGS)
datetime_mod_LDFLAGS = $(COMMON_LDFLAGS)
include $(srcdir)/conf/i386.mk
include $(srcdir)/conf/common.mk

View file

@ -6,7 +6,7 @@ cpuid_mod_CFLAGS = $(COMMON_CFLAGS)
cpuid_mod_LDFLAGS = $(COMMON_LDFLAGS) cpuid_mod_LDFLAGS = $(COMMON_LDFLAGS)
pkglib_MODULES += at_keyboard.mod pkglib_MODULES += at_keyboard.mod
at_keyboard_mod_SOURCES = term/i386/pc/at_keyboard.c at_keyboard_mod_SOURCES = term/at_keyboard.c
at_keyboard_mod_CFLAGS = $(COMMON_CFLAGS) at_keyboard_mod_CFLAGS = $(COMMON_CFLAGS)
at_keyboard_mod_LDFLAGS = $(COMMON_LDFLAGS) at_keyboard_mod_LDFLAGS = $(COMMON_LDFLAGS)
@ -26,18 +26,56 @@ ata_mod_SOURCES = disk/ata.c
ata_mod_CFLAGS = $(COMMON_CFLAGS) ata_mod_CFLAGS = $(COMMON_CFLAGS)
ata_mod_LDFLAGS = $(COMMON_LDFLAGS) ata_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For setpci.mod
pkglib_MODULES += setpci.mod
setpci_mod_SOURCES = commands/setpci.c
setpci_mod_CFLAGS = $(COMMON_CFLAGS)
setpci_mod_LDFLAGS = $(COMMON_LDFLAGS)
pkglib_MODULES += multiboot.mod pkglib_MODULES += multiboot.mod
multiboot_mod_SOURCES = loader/i386/multiboot.c \ multiboot_mod_SOURCES = loader/multiboot.c loader/i386/multiboot_mbi.c
loader/i386/multiboot_mbi.c \
loader/multiboot_loader.c
multiboot_mod_CFLAGS = $(COMMON_CFLAGS) multiboot_mod_CFLAGS = $(COMMON_CFLAGS)
multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS) multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
multiboot_mod_ASFLAGS = $(COMMON_ASFLAGS) multiboot_mod_ASFLAGS = $(COMMON_ASFLAGS)
pkglib_MODULES += multiboot2.mod pkglib_MODULES += multiboot2.mod
multiboot2_mod_SOURCES = loader/i386/multiboot.c \ multiboot2_mod_SOURCES = loader/multiboot.c loader/multiboot_mbi2.c
loader/i386/multiboot_mbi.c \
loader/multiboot_loader.c
multiboot2_mod_CFLAGS = $(COMMON_CFLAGS) -DGRUB_USE_MULTIBOOT2 multiboot2_mod_CFLAGS = $(COMMON_CFLAGS) -DGRUB_USE_MULTIBOOT2
multiboot2_mod_LDFLAGS = $(COMMON_LDFLAGS) multiboot2_mod_LDFLAGS = $(COMMON_LDFLAGS)
multiboot2_mod_ASFLAGS = $(COMMON_ASFLAGS) multiboot2_mod_ASFLAGS = $(COMMON_ASFLAGS)
# For serial.mod.
pkglib_MODULES += serial.mod
serial_mod_SOURCES = term/serial.c
serial_mod_CFLAGS = $(COMMON_CFLAGS)
serial_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For pci.mod
pkglib_MODULES += pci.mod
pci_mod_SOURCES = bus/pci.c
pci_mod_CFLAGS = $(COMMON_CFLAGS)
pci_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For cs5536.mod
pkglib_MODULES += cs5536.mod
cs5536_mod_SOURCES = bus/cs5536.c
cs5536_mod_CFLAGS = $(COMMON_CFLAGS)
cs5536_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For lspci.mod
pkglib_MODULES += lspci.mod
lspci_mod_SOURCES = commands/lspci.c
lspci_mod_CFLAGS = $(COMMON_CFLAGS)
lspci_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For play.mod.
pkglib_MODULES += play.mod
play_mod_SOURCES = commands/i386/pc/play.c
play_mod_CFLAGS = $(COMMON_CFLAGS)
play_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For iorw.mod.
pkglib_MODULES += iorw.mod
iorw_mod_SOURCES = commands/iorw.c
iorw_mod_CFLAGS = $(COMMON_CFLAGS)
iorw_mod_LDFLAGS = $(COMMON_LDFLAGS)

22
conf/mips-qemu-mips.rmk Normal file
View file

@ -0,0 +1,22 @@
# -*- makefile -*-
LINK_BASE = 0x80010000
target_machine=qemu-mips
COMMON_CFLAGS += -march=mips3
COMMON_ASFLAGS += -march=mips3
include $(srcdir)/conf/mips.mk
pkglib_PROGRAMS = kernel.img
kernel_img_SOURCES = kern/$(target_cpu)/startup.S \
kern/main.c kern/device.c kern/$(target_cpu)/init.c \
kern/$(target_cpu)/$(target_machine)/init.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/command.c kern/corecmd.c \
kern/parser.c kern/partition.c kern/env.c kern/$(target_cpu)/dl.c \
kern/generic/millisleep.c kern/generic/rtc_get_time_ms.c kern/time.c \
symlist.c kern/$(target_cpu)/cache.S
kernel_img_CFLAGS = $(COMMON_CFLAGS)
kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
kernel_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-S,-Ttext,$(LINK_BASE),-Bstatic
kernel_img_FORMAT = binary

105
conf/mips-yeeloong.rmk Normal file
View file

@ -0,0 +1,105 @@
# -*- makefile -*-
LINK_BASE = 0x80200000
target_machine=yeeloong
COMMON_CFLAGS += -march=mips3
COMMON_ASFLAGS += -march=mips3
kernel_img_HEADERS += pci.h bitmap.h video.h gfxterm.h font.h \
bitmap_scale.h bufio.h cs5536.h machine/pci.h
include $(srcdir)/conf/mips.mk
pkglib_PROGRAMS = kernel.img
kernel_img_SOURCES = kern/$(target_cpu)/startup.S \
kern/main.c kern/device.c kern/$(target_cpu)/init.c \
kern/$(target_cpu)/$(target_machine)/init.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/command.c kern/corecmd.c \
kern/parser.c kern/partition.c kern/env.c kern/$(target_cpu)/dl.c \
kern/generic/millisleep.c kern/generic/rtc_get_time_ms.c kern/time.c \
kern/$(target_cpu)/cache.S \
\
term/at_keyboard.c \
font/font_cmd.c font/font.c io/bufio.c \
video/video.c video/fb/video_fb.c video/fb/fbblit.c \
video/fb/fbfill.c video/fb/fbutil.c video/bitmap.c \
video/bitmap_scale.c video/sm712.c bus/pci.c bus/bonito.c \
term/gfxterm.c commands/extcmd.c lib/arg.c \
bus/cs5536.c \
symlist.c
kernel_img_CFLAGS = $(COMMON_CFLAGS) -DUSE_ASCII_FAILBACK
kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
kernel_img_LDFLAGS += $(COMMON_LDFLAGS) -Wl,-N,-S,-Ttext,$(LINK_BASE),-Bstatic
kernel_img_FORMAT = binary
# For ata.mod.
pkglib_MODULES += ata.mod
ata_mod_SOURCES = disk/ata.c
ata_mod_CFLAGS = $(COMMON_CFLAGS)
ata_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For lspci.mod
pkglib_MODULES += lspci.mod
lspci_mod_SOURCES = commands/lspci.c
lspci_mod_CFLAGS = $(COMMON_CFLAGS)
lspci_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For ata_pthru.mod.
pkglib_MODULES += ata_pthru.mod
ata_pthru_mod_SOURCES = disk/ata_pthru.c
ata_pthru_mod_CFLAGS = $(COMMON_CFLAGS)
ata_pthru_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For mmap.mod.
pkglib_MODULES += mmap.mod
mmap_mod_SOURCES = mmap/mmap.c mmap/mips/yeeloong/uppermem.c
mmap_mod_CFLAGS = $(COMMON_CFLAGS)
mmap_mod_LDFLAGS = $(COMMON_LDFLAGS)
mmap_mod_ASFLAGS = $(COMMON_ASFLAGS)
# For datetime.mod
pkglib_MODULES += datetime.mod
datetime_mod_SOURCES = lib/cmos_datetime.c
datetime_mod_CFLAGS = $(COMMON_CFLAGS)
datetime_mod_LDFLAGS = $(COMMON_LDFLAGS)
pkglib_MODULES += linux.mod
linux_mod_SOURCES = loader/$(target_cpu)/linux.c
linux_mod_CFLAGS = $(COMMON_CFLAGS)
linux_mod_ASFLAGS = $(COMMON_ASFLAGS)
linux_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For usb.mod
pkglib_MODULES += 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
pkglib_MODULES += usbtest.mod
usbtest_mod_SOURCES = commands/usbtest.c
usbtest_mod_CFLAGS = $(COMMON_CFLAGS)
usbtest_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For ohci.mod
pkglib_MODULES += ohci.mod
ohci_mod_SOURCES = bus/usb/ohci.c
ohci_mod_CFLAGS = $(COMMON_CFLAGS)
ohci_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For usbms.mod
pkglib_MODULES += usbms.mod
usbms_mod_SOURCES = disk/usbms.c
usbms_mod_CFLAGS = $(COMMON_CFLAGS)
usbms_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For usb_keyboard.mod
pkglib_MODULES += usb_keyboard.mod
usb_keyboard_mod_SOURCES = term/usb_keyboard.c
usb_keyboard_mod_CFLAGS = $(COMMON_CFLAGS)
usb_keyboard_mod_LDFLAGS = $(COMMON_LDFLAGS)
sbin_SCRIPTS += grub-install
grub_install_SOURCES = util/grub-install.in

33
conf/mips.rmk Normal file
View file

@ -0,0 +1,33 @@
# -*- makefile -*-
COMMON_CFLAGS += -mexplicit-relocs -mflush-func=grub_cpu_flush_cache
# Images.
kernel_img_HEADERS += cpu/cache.h
# Scripts.
sbin_SCRIPTS =
bin_SCRIPTS =
# For serial.mod.
pkglib_MODULES += serial.mod
serial_mod_SOURCES = term/serial.c
serial_mod_CFLAGS = $(COMMON_CFLAGS)
serial_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For relocator.mod.
pkglib_MODULES += relocator.mod
relocator_mod_SOURCES = lib/$(target_cpu)/relocator.c lib/$(target_cpu)/relocator_asm.S
relocator_mod_CFLAGS = $(COMMON_CFLAGS)
relocator_mod_ASFLAGS = $(COMMON_ASFLAGS)
relocator_mod_LDFLAGS = $(COMMON_LDFLAGS)
pkglib_MODULES += multiboot2.mod
multiboot2_mod_SOURCES = loader/multiboot.c \
loader/multiboot_mbi2.c
multiboot2_mod_CFLAGS = $(COMMON_CFLAGS) -DGRUB_USE_MULTIBOOT2
multiboot2_mod_LDFLAGS = $(COMMON_LDFLAGS)
multiboot2_mod_ASFLAGS = $(COMMON_ASFLAGS)
include $(srcdir)/conf/common.mk

View file

@ -1,29 +1,9 @@
# -*- makefile -*- # -*- makefile -*-
COMMON_ASFLAGS = -nostdinc -D__ASSEMBLY__
COMMON_CFLAGS = -ffreestanding
COMMON_LDFLAGS += -nostdlib
# Used by various components. These rules need to precede them.
script/lexer.c_DEPENDENCIES = grub_script.tab.h
# Images. # Images.
MOSTLYCLEANFILES += symlist.c kernel_syms.lst kernel_img_HEADERS += ieee1275/ieee1275.h
DEFSYMFILES += kernel_syms.lst
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 reader.h \
symbol.h term.h time.h types.h powerpc/libgcc.h loader.h partition.h \
msdos_partition.h ieee1275/ieee1275.h machine/kernel.h handler.h list.h \
command.h i18n.h
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)
# Programs # Programs
pkglib_PROGRAMS = kernel.img pkglib_PROGRAMS = kernel.img
@ -33,7 +13,7 @@ kernel_img_SOURCES = kern/powerpc/ieee1275/startup.S kern/ieee1275/cmain.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/term.c \ kern/misc.c kern/mm.c kern/term.c \
kern/rescue_parser.c kern/rescue_reader.c \ kern/rescue_parser.c kern/rescue_reader.c \
kern/list.c kern/handler.c kern/command.c kern/corecmd.c \ kern/list.c kern/command.c kern/corecmd.c \
kern/ieee1275/init.c \ kern/ieee1275/init.c \
kern/ieee1275/mmap.c \ kern/ieee1275/mmap.c \
term/ieee1275/ofconsole.c \ term/ieee1275/ofconsole.c \
@ -43,8 +23,7 @@ kernel_img_SOURCES = kern/powerpc/ieee1275/startup.S kern/ieee1275/cmain.c \
symlist.c kern/$(target_cpu)/cache.S symlist.c kern/$(target_cpu)/cache.S
kernel_img_CFLAGS = $(COMMON_CFLAGS) kernel_img_CFLAGS = $(COMMON_CFLAGS)
kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
kernel_img_LDFLAGS = $(COMMON_LDFLAGS) -static-libgcc -lgcc \ kernel_img_LDFLAGS += $(COMMON_LDFLAGS) -Wl,-N,-S,-Ttext,0x200000,-Bstatic
-Wl,-N,-S,-Ttext,0x200000,-Bstatic
# Scripts. # Scripts.
sbin_SCRIPTS = grub-install sbin_SCRIPTS = grub-install
@ -57,47 +36,33 @@ grub_install_SOURCES = util/ieee1275/grub-install.in
grub_mkrescue_SOURCES = util/powerpc/ieee1275/grub-mkrescue.in grub_mkrescue_SOURCES = util/powerpc/ieee1275/grub-mkrescue.in
# Modules. # Modules.
pkglib_MODULES = halt.mod \ pkglib_MODULES += ieee1275_fb.mod
linux.mod \ ieee1275_fb_mod_SOURCES = video/ieee1275.c
reboot.mod \ ieee1275_fb_mod_CFLAGS = $(COMMON_CFLAGS)
suspend.mod \ ieee1275_fb_mod_LDFLAGS = $(COMMON_LDFLAGS)
memdisk.mod \
lsmmap.mod
# For boot.mod.
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 linux.mod. # For linux.mod.
pkglib_MODULES += linux.mod
linux_mod_SOURCES = loader/powerpc/ieee1275/linux.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 suspend.mod # For suspend.mod
pkglib_MODULES += 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
reboot_mod_SOURCES = commands/reboot.c
reboot_mod_CFLAGS = $(COMMON_CFLAGS)
reboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For halt.mod # For halt.mod
pkglib_MODULES += halt.mod
halt_mod_SOURCES = commands/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 memdisk.mod. # For datetime.mod
memdisk_mod_SOURCES = disk/memdisk.c pkglib_MODULES += datetime.mod
memdisk_mod_CFLAGS = $(COMMON_CFLAGS) datetime_mod_SOURCES = lib/ieee1275/datetime.c
memdisk_mod_LDFLAGS = $(COMMON_LDFLAGS) datetime_mod_CFLAGS = $(COMMON_CFLAGS)
datetime_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

View file

@ -1,15 +1,12 @@
# -*- makefile -*- # -*- makefile -*-
COMMON_ASFLAGS = -nostdinc -m64 COMMON_CFLAGS = -mno-app-regs
COMMON_CFLAGS = -ffreestanding -m64 -mno-app-regs COMMON_LDFLAGS = -melf64_sparc -mno-relax
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 pkglib_IMAGES = boot.img diskboot.img
pkglib_PROGRAMS = kernel.img
# For boot.img. # For boot.img.
boot_img_SOURCES = boot/sparc64/ieee1275/boot.S boot_img_SOURCES = boot/sparc64/ieee1275/boot.S
@ -23,21 +20,13 @@ diskboot_img_ASFLAGS = $(COMMON_ASFLAGS)
diskboot_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-Ttext,0x4200 diskboot_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-Ttext,0x4200
diskboot_img_FORMAT = binary diskboot_img_FORMAT = binary
MOSTLYCLEANFILES += symlist.c kernel_syms.lst kernel_img_HEADERS += ieee1275/ieee1275.h cpu/ieee1275/ieee1275.h
DEFSYMFILES += kernel_syms.lst
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 \
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 \ kernel_img_SOURCES = kern/sparc64/ieee1275/crt0.S kern/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/term.c \ kern/misc.c kern/mm.c kern/term.c \
kern/rescue_parser.c kern/rescue_reader.c \ kern/rescue_parser.c kern/rescue_reader.c \
kern/list.c kern/handler.c kern/command.c kern/corecmd.c \ kern/list.c kern/command.c kern/corecmd.c \
kern/sparc64/ieee1275/ieee1275.c \ kern/sparc64/ieee1275/ieee1275.c \
kern/sparc64/ieee1275/init.c \ kern/sparc64/ieee1275/init.c \
kern/ieee1275/mmap.c \ kern/ieee1275/mmap.c \
@ -48,46 +37,37 @@ kernel_img_SOURCES = kern/sparc64/ieee1275/crt0.S kern/ieee1275/cmain.c \
symlist.c kern/$(target_cpu)/cache.S symlist.c kern/$(target_cpu)/cache.S
kernel_img_CFLAGS = $(COMMON_CFLAGS) kernel_img_CFLAGS = $(COMMON_CFLAGS)
kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
kernel_img_LDFLAGS = -nostdlib -Wl,-N,-Ttext,0x200000,-Bstatic,-melf64_sparc -static-libgcc -lgcc kernel_img_LDFLAGS += -nostdlib -Wl,-N,-Ttext,0x4400,-Bstatic,-melf64_sparc
kernel_img_FORMAT = binary kernel_img_FORMAT = binary
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)
# Utilities. # Utilities.
bin_UTILITIES = grub-mkimage
sbin_UTILITIES = grub-setup grub-ofpathname sbin_UTILITIES = grub-setup grub-ofpathname
# For grub-mkimage.
grub_mkimage_SOURCES = util/sparc64/ieee1275/grub-mkimage.c util/misc.c \
util/resolve.c gnulib/progname.c
# For grub-setup. # For grub-setup.
util/sparc64/ieee1275/grub-setup.c_DEPENDENCIES = grub_setup_init.h util/sparc64/ieee1275/grub-setup.c_DEPENDENCIES = grub_setup_init.h
grub_setup_SOURCES = util/sparc64/ieee1275/grub-setup.c util/hostdisk.c \ grub_setup_SOURCES = util/sparc64/ieee1275/grub-setup.c \
util/misc.c util/getroot.c kern/device.c kern/disk.c \ util/ieee1275/ofpath.c util/misc.c kern/emu/hostdisk.c \
kern/err.c kern/misc.c kern/parser.c kern/partition.c \ kern/emu/misc.c kern/emu/getroot.c kern/emu/mm.c kern/device.c \
kern/file.c kern/fs.c kern/env.c fs/fshelp.c \ kern/disk.c kern/err.c kern/misc.c \
\ kern/partition.c kern/file.c kern/fs.c kern/env.c kern/list.c \
fs/affs.c fs/cpio.c fs/ext2.c fs/fat.c fs/hfs.c \ fs/fshelp.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/affs.c fs/cpio.c fs/ext2.c fs/fat.c fs/hfs.c \
fs/ufs.c fs/ufs2.c fs/xfs.c fs/afs.c fs/afs_be.c \ fs/hfsplus.c fs/iso9660.c fs/udf.c fs/jfs.c fs/minix.c \
fs/befs.c fs/befs_be.c fs/tar.c \ fs/nilfs2.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 \
partmap/amiga.c partmap/apple.c partmap/msdos.c \ fs/afs_be.c fs/befs.c fs/befs_be.c fs/tar.c \
partmap/sun.c partmap/acorn.c \ \
\ partmap/amiga.c partmap/apple.c partmap/msdos.c \
disk/raid.c disk/mdraid_linux.c disk/lvm.c \ partmap/bsdlabel.c partmap/sun.c partmap/acorn.c \
util/raid.c util/lvm.c gnulib/progname.c \ \
grub_setup_init.c disk/raid.c disk/mdraid_linux.c disk/lvm.c util/raid.c \
util/lvm.c gnulib/progname.c grub_setup_init.c
# For grub-ofpathname. # For grub-ofpathname.
grub_ofpathname_SOURCES = util/sparc64/ieee1275/grub-ofpathname.c \ grub_ofpathname_SOURCES = util/ieee1275/grub-ofpathname.c \
util/ieee1275/ofpath.c util/misc.c gnulib/progname.c util/ieee1275/ofpath.c util/misc.c kern/emu/misc.c \
gnulib/progname.c
# Scripts. # Scripts.
sbin_SCRIPTS = grub-install sbin_SCRIPTS = grub-install
@ -96,41 +76,27 @@ sbin_SCRIPTS = grub-install
grub_install_SOURCES = util/grub-install.in grub_install_SOURCES = util/grub-install.in
# Modules. # Modules.
pkglib_MODULES = halt.mod \ pkglib_MODULES += ieee1275_fb.mod
linux.mod \ ieee1275_fb_mod_SOURCES = video/ieee1275.c
reboot.mod \ ieee1275_fb_mod_CFLAGS = $(COMMON_CFLAGS)
memdisk.mod \ ieee1275_fb_mod_LDFLAGS = $(COMMON_LDFLAGS)
lsmmap.mod
# For boot.mod.
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 linux.mod. # For linux.mod.
pkglib_MODULES += linux.mod
linux_mod_SOURCES = loader/sparc64/ieee1275/linux.c linux_mod_SOURCES = loader/sparc64/ieee1275/linux.c
linux_mod_CFLAGS = $(COMMON_CFLAGS) linux_mod_CFLAGS = $(COMMON_CFLAGS)
linux_mod_LDFLAGS = $(COMMON_LDFLAGS) 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. # For halt.mod.
pkglib_MODULES += halt.mod
halt_mod_SOURCES = commands/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 memdisk.mod. # For datetime.mod
memdisk_mod_SOURCES = disk/memdisk.c pkglib_MODULES += datetime.mod
memdisk_mod_CFLAGS = $(COMMON_CFLAGS) datetime_mod_SOURCES = lib/ieee1275/datetime.c
memdisk_mod_LDFLAGS = $(COMMON_LDFLAGS) datetime_mod_CFLAGS = $(COMMON_CFLAGS)
datetime_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

View file

@ -37,12 +37,56 @@ example_scripted_test_SOURCES = tests/example_scripted_test.in
check_SCRIPTS += example_grub_script_test check_SCRIPTS += example_grub_script_test
example_grub_script_test_SOURCES = tests/example_grub_script_test.in example_grub_script_test_SOURCES = tests/example_grub_script_test.in
#
# Rules for real tests
#
check_SCRIPTS += grub_script_echo1
grub_script_echo1_SOURCES = tests/grub_script_echo1.in
check_SCRIPTS += grub_script_echo_keywords
grub_script_echo_keywords_SOURCES = tests/grub_script_echo_keywords.in
check_SCRIPTS += grub_script_vars1
grub_script_vars1_SOURCES = tests/grub_script_vars1.in
check_SCRIPTS += grub_script_for1
grub_script_for1_SOURCES = tests/grub_script_for1.in
check_SCRIPTS += grub_script_while1
grub_script_while1_SOURCES = tests/grub_script_while1.in
check_SCRIPTS += grub_script_if
grub_script_if_SOURCES = tests/grub_script_if.in
check_SCRIPTS += grub_script_blanklines
grub_script_blanklines_SOURCES = tests/grub_script_blanklines.in
check_SCRIPTS += grub_script_final_semicolon
grub_script_final_semicolon_SOURCES = tests/grub_script_final_semicolon.in
check_SCRIPTS += grub_script_dollar
grub_script_dollar_SOURCES = tests/grub_script_dollar.in
check_SCRIPTS += grub_script_comments
grub_script_comments_SOURCES = tests/grub_script_comments.in
# List of tests to execute on "make check" # List of tests to execute on "make check"
SCRIPTED_TESTS = example_scripted_test # SCRIPTED_TESTS = example_scripted_test
SCRIPTED_TESTS += example_grub_script_test # SCRIPTED_TESTS += example_grub_script_test
UNIT_TESTS = example_unit_test # UNIT_TESTS = example_unit_test
FUNCTIONAL_TESTS = example_functional_test.mod # FUNCTIONAL_TESTS = example_functional_test.mod
SCRIPTED_TESTS = grub_script_echo1
SCRIPTED_TESTS += grub_script_echo_keywords
SCRIPTED_TESTS += grub_script_vars1
SCRIPTED_TESTS += grub_script_for1
SCRIPTED_TESTS += grub_script_while1
SCRIPTED_TESTS += grub_script_if
SCRIPTED_TESTS += grub_script_blanklines
SCRIPTED_TESTS += grub_script_final_semicolon
SCRIPTED_TESTS += grub_script_dollar
SCRIPTED_TESTS += grub_script_comments
# dependencies between tests and testing-tools # dependencies between tests and testing-tools
$(SCRIPTED_TESTS): grub-shell grub-shell-tester $(SCRIPTED_TESTS): grub-shell grub-shell-tester

112
conf/x86-efi.rmk Normal file
View file

@ -0,0 +1,112 @@
# -*- makefile -*-
# Scripts.
sbin_SCRIPTS = grub-install
# For grub-install.
grub_install_SOURCES = util/i386/efi/grub-install.in
bin_SCRIPTS += grub-mkrescue
grub_mkrescue_SOURCES = util/grub-mkrescue.in
# Modules.
pkglib_PROGRAMS = kernel.img
pkglib_MODULES = chain.mod appleldr.mod \
linux.mod halt.mod \
datetime.mod loadbios.mod \
fixvideo.mod mmap.mod acpi.mod
# For kernel.img.
kernel_img_RELOCATABLE = yes
kernel_img_SOURCES = kern/$(target_cpu)/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/misc.c kern/mm.c kern/term.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 \
term/efi/console.c disk/efi/efidisk.c \
kern/time.c kern/list.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
ifeq ($(target_cpu),x86_64)
kernel_img_SOURCES += kern/x86_64/efi/callwrap.S
endif
kernel_img_HEADERS += efi/efi.h efi/time.h efi/disk.h i386/pit.h
kernel_img_CFLAGS = $(COMMON_CFLAGS)
kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
kernel_img_LDFLAGS += $(COMMON_LDFLAGS)
# For acpi.mod.
acpi_mod_SOURCES = commands/acpi.c commands/efi/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/efi/mmap.c
mmap_mod_CFLAGS = $(COMMON_CFLAGS)
mmap_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For chain.mod.
chain_mod_SOURCES = loader/efi/chainloader.c
chain_mod_CFLAGS = $(COMMON_CFLAGS)
chain_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For appleldr.mod.
appleldr_mod_SOURCES = loader/efi/appleloader.c
appleldr_mod_CFLAGS = $(COMMON_CFLAGS)
appleldr_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For linux.mod.
ifeq ($(target_cpu), x86_64)
linux_mod_SOURCES = loader/i386/efi/linux.c loader/i386/linux_trampoline.S
linux_mod_CFLAGS = $(COMMON_CFLAGS)
linux_mod_ASFLAGS = $(COMMON_ASFLAGS)
linux_mod_LDFLAGS = $(COMMON_LDFLAGS)
else
linux_mod_SOURCES = loader/i386/efi/linux.c
linux_mod_CFLAGS = $(COMMON_CFLAGS)
linux_mod_ASFLAGS = $(COMMON_ASFLAGS)
linux_mod_LDFLAGS = $(COMMON_LDFLAGS)
endif
# For halt.mod.
halt_mod_SOURCES = commands/halt.c
halt_mod_CFLAGS = $(COMMON_CFLAGS)
halt_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 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/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

View file

@ -1,165 +1,5 @@
# -*- makefile -*- # -*- makefile -*-
COMMON_ASFLAGS = -nostdinc -fno-builtin -m64 COMMON_LDFLAGS = -melf_x86_64
COMMON_CFLAGS = -fno-builtin -m64
COMMON_LDFLAGS = -melf_x86_64 -nostdlib
# Used by various components. These rules need to precede them. include $(srcdir)/conf/x86-efi.mk
script/lexer.c_DEPENDENCIES = grub_script.tab.h
# Utilities.
bin_UTILITIES = grub-mkimage
# For grub-mkimage.
grub_mkimage_SOURCES = gnulib/progname.c util/i386/efi/grub-mkimage.c \
util/misc.c util/resolve.c
# For grub-setup.
#grub_setup_SOURCES = util/i386/pc/grub-setup.c util/hostdisk.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 \
# fs/sfs.c kern/parser.c kern/partition.c partmap/msdos.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
# Scripts.
sbin_SCRIPTS = grub-install
# For grub-install.
grub_install_SOURCES = util/i386/efi/grub-install.in
# Modules.
pkglib_MODULES = kernel.img chain.mod appleldr.mod \
halt.mod reboot.mod linux.mod pci.mod lspci.mod \
datetime.mod date.mod datehook.mod loadbios.mod \
fixvideo.mod mmap.mod acpi.mod
# For kernel.img.
kernel_img_EXPORTS = no
kernel_img_SOURCES = kern/x86_64/efi/startup.S kern/x86_64/efi/callwrap.S \
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/$(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/time.c kern/list.c kern/handler.c kern/command.c kern/corecmd.c \
kern/i386/tsc.c kern/i386/pit.c \
kern/generic/millisleep.c kern/generic/rtc_get_time_ms.c \
term/efi/console.c disk/efi/efidisk.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 \
efi/efi.h efi/time.h efi/disk.h machine/loader.h i386/pit.h list.h \
handler.h command.h i18n.h
kernel_img_CFLAGS = $(COMMON_CFLAGS)
kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
kernel_img_LDFLAGS = $(COMMON_LDFLAGS)
MOSTLYCLEANFILES += symlist.c
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)
# For boot.mod.
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 acpi.mod.
acpi_mod_SOURCES = commands/acpi.c commands/efi/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/efi/mmap.c
mmap_mod_CFLAGS = $(COMMON_CFLAGS)
mmap_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For chain.mod.
chain_mod_SOURCES = loader/efi/chainloader.c
chain_mod_CFLAGS = $(COMMON_CFLAGS)
chain_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For appleldr.mod.
appleldr_mod_SOURCES = loader/efi/appleloader.c
appleldr_mod_CFLAGS = $(COMMON_CFLAGS)
appleldr_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For linux.mod.
linux_mod_SOURCES = loader/i386/efi/linux.c loader/i386/linux_trampoline.S
linux_mod_CFLAGS = $(COMMON_CFLAGS)
linux_mod_ASFLAGS = $(COMMON_ASFLAGS)
linux_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For halt.mod.
halt_mod_SOURCES = commands/halt.c
halt_mod_CFLAGS = $(COMMON_CFLAGS)
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/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

View file

@ -31,7 +31,7 @@ dnl (such as TARGET_CC, TARGET_CFLAGS, etc.) are used for the target
dnl type. dnl type.
AC_INIT([GRUB],[1.97],[bug-grub@gnu.org]) AC_INIT([GRUB],[1.98],[bug-grub@gnu.org])
AM_INIT_AUTOMAKE() AM_INIT_AUTOMAKE()
AC_PREREQ(2.60) AC_PREREQ(2.60)
AC_CONFIG_SRCDIR([include/grub/dl.h]) AC_CONFIG_SRCDIR([include/grub/dl.h])
@ -51,7 +51,18 @@ fi
case "$target_cpu" in case "$target_cpu" in
i[[3456]]86) target_cpu=i386 ;; i[[3456]]86) target_cpu=i386 ;;
amd64) target_cpu=x86_64 ;;
sparc) target_cpu=sparc64 ;; sparc) target_cpu=sparc64 ;;
mipsel|mips64el)
target_cpu=mips;
TARGET_CFLAGS="$TARGET_CFLAGS -DGRUB_CPU_MIPSEL=1";
CFLAGS="$CFLAGS -DGRUB_CPU_MIPSEL=1";
;;
mips|mips64)
target_cpu=mips;
TARGET_CFLAGS="$TARGET_CFLAGS -DGRUB_CPU_MIPS=1";
CFLAGS="$CFLAGS -DGRUB_CPU_MIPS=1";
;;
esac esac
# Specify the platform (such as firmware). # Specify the platform (such as firmware).
@ -69,6 +80,7 @@ if test "x$with_platform" = x; then
powerpc-*) platform=ieee1275 ;; powerpc-*) platform=ieee1275 ;;
powerpc64-*) platform=ieee1275 ;; powerpc64-*) platform=ieee1275 ;;
sparc64-*) platform=ieee1275 ;; sparc64-*) platform=ieee1275 ;;
mips-*) platform=yeeloong ;;
*) AC_MSG_ERROR([unsupported CPU: "$target_cpu"]) ;; *) AC_MSG_ERROR([unsupported CPU: "$target_cpu"]) ;;
esac esac
else else
@ -79,6 +91,7 @@ fi
if test -z "$target_alias"; then if test -z "$target_alias"; then
case "$target_cpu"-"$platform" in case "$target_cpu"-"$platform" in
x86_64-efi) ;; x86_64-efi) ;;
x86_64-emu) ;;
x86_64-*) target_cpu=i386 ;; x86_64-*) target_cpu=i386 ;;
powerpc64-ieee1275) target_cpu=powerpc ;; powerpc64-ieee1275) target_cpu=powerpc ;;
esac esac
@ -89,12 +102,15 @@ case "$target_cpu"-"$platform" in
i386-efi) ;; i386-efi) ;;
x86_64-efi) ;; x86_64-efi) ;;
i386-pc) ;; i386-pc) ;;
i386-multiboot) ;;
i386-coreboot) ;; i386-coreboot) ;;
i386-linuxbios) platform=coreboot ;; i386-linuxbios) platform=coreboot ;;
i386-ieee1275) ;; i386-ieee1275) ;;
i386-qemu) ;; i386-qemu) ;;
powerpc-ieee1275) ;; powerpc-ieee1275) ;;
sparc64-ieee1275) ;; sparc64-ieee1275) ;;
mips-qemu-mips) ;;
mips-yeeloong) ;;
*-emu) ;; *-emu) ;;
*) AC_MSG_ERROR([platform "$platform" is not supported for target CPU "$target_cpu"]) ;; *) AC_MSG_ERROR([platform "$platform" is not supported for target CPU "$target_cpu"]) ;;
esac esac
@ -115,17 +131,27 @@ case "$host_os" in
gnu*) host_kernel=hurd ;; gnu*) host_kernel=hurd ;;
linux*) host_kernel=linux ;; linux*) host_kernel=linux ;;
freebsd* | kfreebsd*-gnu) host_kernel=kfreebsd ;; freebsd* | kfreebsd*-gnu) host_kernel=kfreebsd ;;
netbsd*) host_kernel=netbsd ;;
cygwin) host_kernel=windows ;; cygwin) host_kernel=windows ;;
esac esac
case "$platform" in case "$platform" in
coreboot) machine_CFLAGS="-DGRUB_MACHINE_COREBOOT=1" ;; coreboot) machine_CFLAGS="-DGRUB_MACHINE_COREBOOT=1" ;;
multiboot) machine_CFLAGS="-DGRUB_MACHINE_MULTIBOOT=1" ;;
efi) machine_CFLAGS="-DGRUB_MACHINE_EFI=1" ;; efi) machine_CFLAGS="-DGRUB_MACHINE_EFI=1" ;;
ieee1275) machine_CFLAGS="-DGRUB_MACHINE_IEEE1275=1" ;; ieee1275) machine_CFLAGS="-DGRUB_MACHINE_IEEE1275=1" ;;
qemu) machine_CFLAGS="-DGRUB_MACHINE_QEMU=1" ;; qemu) machine_CFLAGS="-DGRUB_MACHINE_QEMU=1" ;;
pc) machine_CFLAGS="-DGRUB_MACHINE_PCBIOS=1" ;; pc) machine_CFLAGS="-DGRUB_MACHINE_PCBIOS=1" ;;
emu) machine_CFLAGS="-DGRUB_MACHINE_EMU=1" ;; emu) machine_CFLAGS="-DGRUB_MACHINE_EMU=1" ;;
yeeloong) machine_CFLAGS="-DGRUB_MACHINE_MIPS_YEELOONG=1 -DGRUB_MACHINE_MIPS_BONITO=1" ;;
qemu-mips) machine_CFLAGS="-DGRUB_MACHINE_MIPS_QEMU_MIPS=1 -DGRUB_MACHINE_MIPS_BONITO=1" ;;
esac esac
case "$target_cpu" in
mips) machine_CFLAGS="$machine_CFLAGS -DGRUB_MACHINE_MIPS=1" ;;
sparc64) machine_CFLAGS="$machine_CFLAGS -DGRUB_MACHINE_SPARC64=1" ;;
esac
machine_CFLAGS="$machine_CFLAGS -DMACHINE=`echo ${target_cpu}_$platform | sed y,abcdefghijklmnopqrstuvwxyz,ABCDEFGHIJKLMNOPQRSTUVWXYZ,`"
CFLAGS="$CFLAGS $machine_CFLAGS" CFLAGS="$CFLAGS $machine_CFLAGS"
TARGET_ASFLAGS="$TARGET_ASFLAGS $machine_CFLAGS" TARGET_ASFLAGS="$TARGET_ASFLAGS $machine_CFLAGS"
TARGET_CFLAGS="$TARGET_CFLAGS $machine_CFLAGS" TARGET_CFLAGS="$TARGET_CFLAGS $machine_CFLAGS"
@ -153,18 +179,32 @@ if test "x$YACC" = x; then
AC_MSG_ERROR([bison is not found]) AC_MSG_ERROR([bison is not found])
fi fi
for file in /usr/src/unifont.bdf /usr/share/fonts/X11/misc/unifont.pcf.gz ; do for ext in pcf pcf.gz bdf bdf.gz ttf ttf.gz; do
if test -e $file ; then for dir in . /usr/src /usr/share/fonts/X11/misc /usr/share/fonts/unifont; do
AC_SUBST([FONT_SOURCE], [$file]) if test -f "$dir/unifont.$ext"; then
break AC_SUBST([FONT_SOURCE], [$dir/unifont.$ext])
fi break 2
fi
done
done done
AC_PROG_INSTALL AC_PROG_INSTALL
AC_PROG_AWK AC_PROG_AWK
AC_PROG_LEX
AC_PROG_MAKE_SET AC_PROG_MAKE_SET
AC_PROG_MKDIR_P AC_PROG_MKDIR_P
if test "x$LEX" = "x:"; then
AC_MSG_ERROR([flex is not found])
else
version=`$LEX --version | $AWK '{ split($NF,x,"."); print x[[1]]*10000+x[[2]]*100+x[[3]]; }'`
if test -n "$version" -a "$version" -ge 20535; then
:
else
AC_MSG_ERROR([flex is too old. GRUB requires 2.5.35 or above])
fi
fi
# These are not a "must". # These are not a "must".
AC_PATH_PROG(RUBY, ruby) AC_PATH_PROG(RUBY, ruby)
AC_PATH_PROG(MAKEINFO, makeinfo) AC_PATH_PROG(MAKEINFO, makeinfo)
@ -206,7 +246,21 @@ AC_HEADER_MAJOR
AC_HEADER_DIRENT AC_HEADER_DIRENT
AC_CHECK_FUNCS(memmove sbrk strdup lstat getuid getgid) AC_CHECK_FUNCS(memmove sbrk strdup lstat getuid getgid)
AC_CHECK_HEADERS(sys/mkdev.h sys/sysmacros.h malloc.h termios.h sys/types.h) AC_CHECK_HEADERS(sys/mkdev.h sys/sysmacros.h malloc.h termios.h sys/types.h)
AC_CHECK_HEADERS(unistd.h string.h strings.h sys/stat.h sys/fcntl.h) AC_CHECK_HEADERS(unistd.h string.h strings.h sys/stat.h sys/fcntl.h limits.h)
# For opendisk() and getrawpartition() on NetBSD.
# Used in util/deviceiter.c and in util/hostdisk.c.
AC_CHECK_HEADER([util.h], [
AC_CHECK_LIB([util], [opendisk], [
LIBUTIL="-lutil"
AC_DEFINE(HAVE_OPENDISK, 1, [Define if opendisk() in -lutil can be used])
])
AC_CHECK_LIB([util], [getrawpartition], [
LIBUTIL="-lutil"
AC_DEFINE(HAVE_GETRAWPARTITION, 1, [Define if getrawpartition() in -lutil can be used])
])
])
AC_SUBST([LIBUTIL])
# #
# Check for target programs. # Check for target programs.
@ -311,7 +365,7 @@ else
if test -f "${srcdir}/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"; then if test -f "${srcdir}/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"; then
TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc" TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"
TARGET_IMG_LDFLAGS="-Wl,-T${TARGET_IMG_LDSCRIPT} -Wl,-Ttext," TARGET_IMG_LDFLAGS="-Wl,-T${TARGET_IMG_LDSCRIPT} -Wl,-Ttext,"
TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc" TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc -Wl,-Ttext,"
else else
TARGET_IMG_LDSCRIPT= TARGET_IMG_LDSCRIPT=
TARGET_IMG_LDFLAGS='-Wl,-N -Wl,-Ttext,' TARGET_IMG_LDFLAGS='-Wl,-N -Wl,-Ttext,'
@ -327,7 +381,11 @@ AC_SUBST(TARGET_IMG_CFLAGS)
# For platforms where ELF is not the default link format. # For platforms where ELF is not the default link format.
AC_MSG_CHECKING([for command to convert module to ELF format]) AC_MSG_CHECKING([for command to convert module to ELF format])
case "${host_os}" in case "${host_os}" in
cygwin) TARGET_OBJ2ELF='grub-pe2elf' ;; cygwin) TARGET_OBJ2ELF='grub-pe2elf';
# FIXME: put proper test here
AC_DEFINE([NEED_REGISTER_FRAME_INFO], 1,
[Define to 1 if GCC generates calls to __register_frame_info()])
;;
*) ;; *) ;;
esac esac
AC_SUBST(TARGET_OBJ2ELF) AC_SUBST(TARGET_OBJ2ELF)
@ -337,6 +395,7 @@ AC_MSG_RESULT([$TARGET_OBJ2ELF])
if test "x$target_m32" = x1; then if test "x$target_m32" = x1; then
# Force 32-bit mode. # Force 32-bit mode.
TARGET_CFLAGS="$TARGET_CFLAGS -m32" TARGET_CFLAGS="$TARGET_CFLAGS -m32"
TARGET_ASFLAGS="$TARGET_CFLAGS -m32"
TARGET_LDFLAGS="$TARGET_LDFLAGS -m32" TARGET_LDFLAGS="$TARGET_LDFLAGS -m32"
TARGET_MODULE_FORMAT="elf32" TARGET_MODULE_FORMAT="elf32"
fi fi
@ -344,6 +403,7 @@ fi
if test "x$target_m64" = x1; then if test "x$target_m64" = x1; then
# Force 64-bit mode. # Force 64-bit mode.
TARGET_CFLAGS="$TARGET_CFLAGS -m64" TARGET_CFLAGS="$TARGET_CFLAGS -m64"
TARGET_ASFLAGS="$TARGET_ASFLAGS -m64"
TARGET_LDFLAGS="$TARGET_LDFLAGS -m64" TARGET_LDFLAGS="$TARGET_LDFLAGS -m64"
TARGET_MODULE_FORMAT="elf64" TARGET_MODULE_FORMAT="elf64"
fi fi
@ -358,9 +418,7 @@ if test "$target_cpu"-"$platform" = x86_64-efi; then
[grub_cv_cc_mcmodel=no]) [grub_cv_cc_mcmodel=no])
]) ])
if test "x$grub_cv_cc_mcmodel" = xno; then if test "x$grub_cv_cc_mcmodel" = xno; then
CFLAGS="$SAVED_CFLAGS -m64 -DMCMODEL_SMALL=1" AC_MSG_ERROR([-mcmodel=large not supported. Upgrade your gcc.])
TARGET_CFLAGS="$TARGET_CFLAGS -DMCMODEL_SMALL=1"
AC_MSG_WARN([-mcmodel=large not supported. You won't be able to use the memory over 4GiB. Upgrade your gcc])
else else
TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large" TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large"
fi fi
@ -423,18 +481,33 @@ AC_SUBST(TARGET_ASFLAGS)
AC_SUBST(TARGET_CPPFLAGS) AC_SUBST(TARGET_CPPFLAGS)
AC_SUBST(TARGET_LDFLAGS) AC_SUBST(TARGET_LDFLAGS)
# Check for libgcc symbols (must be performed before we add -nostdlib to LDFLAGS)
AC_CHECK_FUNCS(__bswapsi2 __bswapdi2 __ashldi3 __ashrdi3 __lshrdi3 __trampoline_setup __ucmpdi2)
# Set them to their new values for the tests below. # Set them to their new values for the tests below.
CC="$TARGET_CC" CC="$TARGET_CC"
if test "x$TARGET_APPLE_CC" = x1 ; then
CFLAGS="$TARGET_CFLAGS -nostdlib -Wno-error"
else
CFLAGS="$TARGET_CFLAGS -nostdlib -Wl,--defsym,___main=0x8100 -Wno-error"
fi
CPPFLAGS="$TARGET_CPPFLAGS"
LDFLAGS="$TARGET_LDFLAGS"
LIBS=-lgcc
grub_ASM_USCORE
if test x$grub_cv_asm_uscore = xyes; then
CFLAGS="$CFLAGS -Wl,--defsym,_abort=_main"
else
CFLAGS="$CFLAGS -Wl,--defsym,abort=main"
fi
# Check for libgcc symbols
AC_CHECK_FUNCS(__bswapsi2 __bswapdi2 __ashldi3 __ashrdi3 __lshrdi3 __trampoline_setup __ucmpdi2 _restgpr_14_x)
if test "x$TARGET_APPLE_CC" = x1 ; then if test "x$TARGET_APPLE_CC" = x1 ; then
CFLAGS="$TARGET_CFLAGS -nostdlib" CFLAGS="$TARGET_CFLAGS -nostdlib"
else else
CFLAGS="$TARGET_CFLAGS -nostdlib -Wl,--defsym,___main=0x8100" CFLAGS="$TARGET_CFLAGS -nostdlib -Wl,--defsym,___main=0x8100"
fi fi
CPPFLAGS="$TARGET_CPPFLAGS" LIBS=""
LDFLAGS="$TARGET_LDFLAGS"
# Defined in aclocal.m4. # Defined in aclocal.m4.
grub_PROG_TARGET_CC grub_PROG_TARGET_CC
@ -442,13 +515,12 @@ if test "x$TARGET_APPLE_CC" != x1 ; then
grub_PROG_OBJCOPY_ABSOLUTE grub_PROG_OBJCOPY_ABSOLUTE
fi fi
grub_PROG_LD_BUILD_ID_NONE grub_PROG_LD_BUILD_ID_NONE
grub_ASM_USCORE
if test "x$target_cpu" = xi386; then if test "x$target_cpu" = xi386; then
if test ! -z "$TARGET_IMG_LDSCRIPT"; then if test "$platform" != emu && test "x$TARGET_APPLE_CC" != x1 ; then
# Check symbols provided by linker script. if test ! -z "$TARGET_IMG_LDSCRIPT"; then
CFLAGS="$TARGET_CFLAGS -nostdlib $TARGET_IMG_LDFLAGS_AC -Wl,-Ttext,8000,--defsym,___main=0x8100" # Check symbols provided by linker script.
fi CFLAGS="$TARGET_CFLAGS -nostdlib ${TARGET_IMG_LDFLAGS_AC}8000 -Wl,--defsym,___main=0x8100"
if test "x$TARGET_APPLE_CC" != x1 ; then fi
grub_CHECK_BSS_START_SYMBOL grub_CHECK_BSS_START_SYMBOL
grub_CHECK_END_SYMBOL grub_CHECK_END_SYMBOL
fi fi
@ -493,6 +565,21 @@ enable_efiemu=no
fi fi
AC_SUBST([enable_efiemu]) AC_SUBST([enable_efiemu])
if test "$platform" != emu; then
AC_CACHE_CHECK([whether -nostdinc -isystem works], [grub_cv_cc_isystem], [
SAVED_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$TARGET_CPPFLAGS -nostdinc -isystem `$TARGET_CC -print-file-name=include`"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdarg.h>
int va_arg_func (int fixed, va_list args);]], [[]])],
[grub_cv_cc_isystem=yes],
[grub_cv_cc_isystem=no])
CPPFLAGS="$SAVED_CPPFLAGS"
])
if test x"$grub_cv_cc_isystem" = xyes ; then
TARGET_CPPFLAGS="$TARGET_CPPFLAGS -nostdinc -isystem `$TARGET_CC -print-file-name=include`"
fi
fi
# Restore the flags. # Restore the flags.
CC="$tmp_CC" CC="$tmp_CC"
@ -516,10 +603,18 @@ AC_ARG_ENABLE([grub-emu-usb],
[AS_HELP_STRING([--enable-grub-emu-usb], [AS_HELP_STRING([--enable-grub-emu-usb],
[build and install the `grub-emu' debugging utility with USB support (default=guessed)])]) [build and install the `grub-emu' debugging utility with USB support (default=guessed)])])
AC_ARG_ENABLE([grub-emu-sdl],
[AS_HELP_STRING([--enable-grub-emu-sdl],
[build and install the `grub-emu' debugging utility with SDL support (default=guessed)])])
AC_ARG_ENABLE([grub-emu-pci], AC_ARG_ENABLE([grub-emu-pci],
[AS_HELP_STRING([--enable-grub-emu-pci], [AS_HELP_STRING([--enable-grub-emu-pci],
[build and install the `grub-emu' debugging utility with PCI support (potentially dangerous) (default=no)])]) [build and install the `grub-emu' debugging utility with PCI support (potentially dangerous) (default=no)])])
AC_ARG_ENABLE([grub-emu-modules],
[AS_HELP_STRING([--enable-grub-emu-modules],
[Support module loading in `grub-emu' debugging utility (default=no)])])
if test "$platform" = emu; then if test "$platform" = emu; then
missing_ncurses= missing_ncurses=
[# Check for curses libraries.] [# Check for curses libraries.]
@ -538,6 +633,19 @@ if test x"$missing_ncurses" = xtrue ; then
AC_MSG_ERROR([grub-emu can't be compiled without ncurses]) AC_MSG_ERROR([grub-emu can't be compiled without ncurses])
fi fi
if test x"$enable_grub_emu_modules" = xyes ; then
TARGET_NO_MODULES=no
else
TARGET_NO_MODULES=yes
fi
AC_SUBST(TARGET_NO_MODULES)
if test "$TARGET_NO_MODULES" = yes ; then
# Do not convert modules, otherwise linkage may fail (Cygwin only).
# FIXME: Should be checked above before TARGET_OBJ2ELF is set first.
TARGET_OBJ2ELF=
fi
if test x"$enable_grub_emu_usb" = xno ; then if test x"$enable_grub_emu_usb" = xno ; then
grub_emu_usb_excuse="explicitly disabled" grub_emu_usb_excuse="explicitly disabled"
fi fi
@ -566,6 +674,31 @@ else
enable_grub_emu_usb=no enable_grub_emu_usb=no
fi fi
if test x"$enable_grub_emu_sdl" = xno ; then
grub_emu_sdl_excuse="explicitely disabled"
fi
[if [ x"$grub_emu_sdl_excuse" = x ]; then
# Check for libSDL libraries.]
AC_CHECK_LIB([SDL], [SDL_Init], [LIBSDL="-lSDL"],
[grub_emu_sdl_excuse=["libSDL libraries are required to build \`grub-emu' with SDL support"]])
AC_SUBST([LIBSDL])
[fi]
[if [ x"$grub_emu_sdl_excuse" = x ]; then
# Check for headers.]
AC_CHECK_HEADERS([SDL/SDL.h], [],
[grub_emu_sdl_excuse=["libSDL header file is required to build \`grub-emu' with SDL support"]])
[fi]
if test x"enable_grub_emu_sdl" = xyes && test x"$grub_emu_sdl_excuse" != x ; then
AC_MSG_ERROR([SDL support for grub-emu was explicitely requested but can't be compiled])
fi
if test x"$grub_emu_sdl_excuse" = x ; then
enable_grub_emu_sdl=yes
else
enable_grub_emu_sdl=no
fi
if test x"$enable_grub_emu_pci" != xyes ; then if test x"$enable_grub_emu_pci" != xyes ; then
grub_emu_pci_excuse="not enabled" grub_emu_pci_excuse="not enabled"
fi fi
@ -589,9 +722,11 @@ fi
if test x"$grub_emu_pci_excuse" = x ; then if test x"$grub_emu_pci_excuse" = x ; then
enable_grub_emu_pci=yes enable_grub_emu_pci=yes
else else
enable_grub_emu_pci=no enable_grub_emu_pci=no
fi fi
AC_SUBST([enable_grub_emu_sdl])
AC_SUBST([enable_grub_emu_usb]) AC_SUBST([enable_grub_emu_usb])
AC_SUBST([enable_grub_emu_pci]) AC_SUBST([enable_grub_emu_pci])
fi fi
@ -625,6 +760,16 @@ if test x"$grub_mkfont_excuse" = x ; then
freetype_cflags=`freetype-config --cflags` freetype_cflags=`freetype-config --cflags`
freetype_libs=`freetype-config --libs` freetype_libs=`freetype-config --libs`
fi fi
if test x"$grub_mkfont_excuse" = x ; then
# Check for freetype libraries.
SAVED_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $freetype_cflags"
AC_CHECK_HEADERS([ft2build.h], [],
[grub_mkfont_excuse=["need freetype2 headers"]])
CPPFLAGS="$SAVED_CPPFLAGS"
fi
if test x"$enable_grub_mkfont" = xyes && test x"$grub_mkfont_excuse" != x ; then if test x"$enable_grub_mkfont" = xyes && test x"$grub_mkfont_excuse" != x ; then
AC_MSG_ERROR([grub-mkfont was explicitly requested but can't be compiled]) AC_MSG_ERROR([grub-mkfont was explicitly requested but can't be compiled])
fi fi
@ -637,6 +782,22 @@ AC_SUBST([enable_grub_mkfont])
AC_SUBST([freetype_cflags]) AC_SUBST([freetype_cflags])
AC_SUBST([freetype_libs]) AC_SUBST([freetype_libs])
AC_ARG_ENABLE([device-mapper],
[AS_HELP_STRING([--enable-device-mapper],
[enable Linux device-mapper support (default=guessed)])])
if test x"$enable_device_mapper" = xno ; then
device_mapper_excuse="explicitly disabled"
fi
if test x"$device_mapper_excuse" = x ; then
# Check for device-mapper library.
AC_CHECK_LIB([devmapper], [dm_task_create],
[LDFLAGS="$LDFLAGS -ldevmapper"
AC_DEFINE([HAVE_DEVICE_MAPPER], [1],
[Define to 1 if you have the devmapper library.])],
[device_mapper_excuse="need devmapper library"])
fi
AC_SUBST(ASFLAGS) AC_SUBST(ASFLAGS)
# Output files. # Output files.
@ -668,11 +829,21 @@ echo USB support for grub-emu: Yes
else else
echo USB support for grub-emu: No "($grub_emu_usb_excuse)" echo USB support for grub-emu: No "($grub_emu_usb_excuse)"
fi fi
if [ x"$grub_emu_sdl_excuse" = x ]; then
echo SDL support for grub-emu: Yes
else
echo SDL support for grub-emu: No "($grub_emu_sdl_excuse)"
fi
if [ x"$grub_emu_pci_excuse" = x ]; then if [ x"$grub_emu_pci_excuse" = x ]; then
echo PCI support for grub-emu: Yes echo PCI support for grub-emu: Yes
else else
echo PCI support for grub-emu: No "($grub_emu_pci_excuse)" echo PCI support for grub-emu: No "($grub_emu_pci_excuse)"
fi fi
if [ x"$TARGET_NO_MODULES" = xno ]; then
echo Module support for grub-emu: Yes
else
echo Module support for grub-emu: No
fi
fi fi
if [ x"$enable_mm_debug" = xyes ]; then if [ x"$enable_mm_debug" = xyes ]; then
echo With memory debugging: Yes echo With memory debugging: Yes

View file

@ -26,8 +26,8 @@
#include <grub/scsi.h> #include <grub/scsi.h>
/* At the moment, only two IDE ports are supported. */ /* At the moment, only two IDE ports are supported. */
static const int grub_ata_ioaddress[] = { 0x1f0, 0x170 }; static const grub_port_t grub_ata_ioaddress[] = { 0x1f0, 0x170 };
static const int grub_ata_ioaddress2[] = { 0x3f6, 0x376 }; static const grub_port_t grub_ata_ioaddress2[] = { 0x3f6, 0x376 };
static struct grub_ata_device *grub_ata_devices; static struct grub_ata_device *grub_ata_devices;
@ -347,8 +347,8 @@ grub_ata_device_initialize (int port, int device, int addr, int addr2)
/* Setup the device information. */ /* Setup the device information. */
dev->port = port; dev->port = port;
dev->device = device; dev->device = device;
dev->ioaddress = addr; dev->ioaddress = addr + GRUB_MACHINE_PCI_IO_BASE;
dev->ioaddress2 = addr2; dev->ioaddress2 = addr2 + GRUB_MACHINE_PCI_IO_BASE;
dev->next = NULL; dev->next = NULL;
grub_ata_regset (dev, GRUB_ATA_REG_DISK, dev->device << 4); grub_ata_regset (dev, GRUB_ATA_REG_DISK, dev->device << 4);
@ -389,7 +389,7 @@ grub_ata_device_initialize (int port, int device, int addr, int addr2)
static int NESTED_FUNC_ATTR static int NESTED_FUNC_ATTR
grub_ata_pciinit (grub_pci_device_t dev, grub_ata_pciinit (grub_pci_device_t dev,
grub_pci_id_t pciid __attribute__((unused))) grub_pci_id_t pciid)
{ {
static int compat_use[2] = { 0 }; static int compat_use[2] = { 0 };
grub_pci_address_t addr; grub_pci_address_t addr;
@ -400,19 +400,34 @@ grub_ata_pciinit (grub_pci_device_t dev,
int regb; int regb;
int i; int i;
static int controller = 0; static int controller = 0;
int cs5536 = 0;
int nports = 2;
/* Read class. */ /* Read class. */
addr = grub_pci_make_address (dev, 2); addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
class = grub_pci_read (addr); class = grub_pci_read (addr);
/* AMD CS5536 Southbridge. */
if (pciid == 0x208f1022)
{
cs5536 = 1;
nports = 1;
}
/* Check if this class ID matches that of a PCI IDE Controller. */ /* Check if this class ID matches that of a PCI IDE Controller. */
if (class >> 16 != 0x0101) if (!cs5536 && (class >> 16 != 0x0101))
return 0; return 0;
for (i = 0; i < 2; i++) for (i = 0; i < nports; i++)
{ {
/* Set to 0 when the channel operated in compatibility mode. */ /* Set to 0 when the channel operated in compatibility mode. */
int compat = (class >> (8 + 2 * i)) & 1; int compat;
/* We don't support non-compatibility mode for CS5536. */
if (cs5536)
compat = 0;
else
compat = (class >> (8 + 2 * i)) & 1;
rega = 0; rega = 0;
regb = 0; regb = 0;
@ -429,9 +444,12 @@ grub_ata_pciinit (grub_pci_device_t dev,
{ {
/* Read the BARs, which either contain a mmapped IO address /* Read the BARs, which either contain a mmapped IO address
or the IO port address. */ or the IO port address. */
addr = grub_pci_make_address (dev, 4 + 2 * i); addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESSES
+ sizeof (grub_uint64_t) * i);
bar1 = grub_pci_read (addr); bar1 = grub_pci_read (addr);
addr = grub_pci_make_address (dev, 5 + 2 * i); addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESSES
+ sizeof (grub_uint64_t) * i
+ sizeof (grub_uint32_t));
bar2 = grub_pci_read (addr); bar2 = grub_pci_read (addr);
/* Check if the BARs describe an IO region. */ /* Check if the BARs describe an IO region. */
@ -485,7 +503,6 @@ grub_ata_initialize (void)
return 0; return 0;
} }
static void static void
grub_ata_setlba (struct grub_ata_device *dev, grub_disk_addr_t sector, grub_ata_setlba (struct grub_ata_device *dev, grub_disk_addr_t sector,
grub_size_t size) grub_size_t size)
@ -648,12 +665,14 @@ grub_ata_iterate (int (*hook) (const char *name))
for (dev = grub_ata_devices; dev; dev = dev->next) for (dev = grub_ata_devices; dev; dev = dev->next)
{ {
char devname[5]; char devname[10];
grub_sprintf (devname, "ata%d", dev->port * 2 + dev->device);
if (dev->atapi) if (dev->atapi)
continue; continue;
grub_snprintf (devname, sizeof (devname),
"ata%d", dev->port * 2 + dev->device);
if (hook (devname)) if (hook (devname))
return 1; return 1;
} }
@ -668,8 +687,9 @@ grub_ata_open (const char *name, grub_disk_t disk)
for (dev = grub_ata_devices; dev; dev = dev->next) for (dev = grub_ata_devices; dev; dev = dev->next)
{ {
char devname[5]; char devname[10];
grub_sprintf (devname, "ata%d", dev->port * 2 + dev->device); grub_snprintf (devname, sizeof (devname),
"ata%d", dev->port * 2 + dev->device);
if (grub_strcmp (name, devname) == 0) if (grub_strcmp (name, devname) == 0)
break; break;
} }
@ -735,8 +755,9 @@ grub_atapi_iterate (int (*hook) (const char *name, int luns))
for (dev = grub_ata_devices; dev; dev = dev->next) for (dev = grub_ata_devices; dev; dev = dev->next)
{ {
char devname[7]; char devname[10];
grub_sprintf (devname, "ata%d", dev->port * 2 + dev->device); grub_snprintf (devname, sizeof (devname),
"ata%d", dev->port * 2 + dev->device);
if (! dev->atapi) if (! dev->atapi)
continue; continue;
@ -808,8 +829,9 @@ grub_atapi_open (const char *name, struct grub_scsi *scsi)
for (dev = grub_ata_devices; dev; dev = dev->next) for (dev = grub_ata_devices; dev; dev = dev->next)
{ {
char devname[7]; char devname[10];
grub_sprintf (devname, "ata%d", dev->port * 2 + dev->device); grub_snprintf (devname, sizeof (devname),
"ata%d", dev->port * 2 + dev->device);
if (!grub_strcmp (devname, name)) if (!grub_strcmp (devname, name))
{ {

View file

@ -440,7 +440,7 @@ grub_efidisk_iterate (int (*hook) (const char *name))
for (d = fd_devices, count = 0; d; d = d->next, count++) for (d = fd_devices, count = 0; d; d = d->next, count++)
{ {
grub_sprintf (buf, "fd%d", count); grub_snprintf (buf, sizeof (buf), "fd%d", count);
grub_dprintf ("efidisk", "iterating %s\n", buf); grub_dprintf ("efidisk", "iterating %s\n", buf);
if (hook (buf)) if (hook (buf))
return 1; return 1;
@ -448,7 +448,7 @@ grub_efidisk_iterate (int (*hook) (const char *name))
for (d = hd_devices, count = 0; d; d = d->next, count++) for (d = hd_devices, count = 0; d; d = d->next, count++)
{ {
grub_sprintf (buf, "hd%d", count); grub_snprintf (buf, sizeof (buf), "hd%d", count);
grub_dprintf ("efidisk", "iterating %s\n", buf); grub_dprintf ("efidisk", "iterating %s\n", buf);
if (hook (buf)) if (hook (buf))
return 1; return 1;
@ -456,7 +456,7 @@ grub_efidisk_iterate (int (*hook) (const char *name))
for (d = cd_devices, count = 0; d; d = d->next, count++) for (d = cd_devices, count = 0; d; d = d->next, count++)
{ {
grub_sprintf (buf, "cd%d", count); grub_snprintf (buf, sizeof (buf), "cd%d", count);
grub_dprintf ("efidisk", "iterating %s\n", buf); grub_dprintf ("efidisk", "iterating %s\n", buf);
if (hook (buf)) if (hook (buf))
return 1; return 1;
@ -805,18 +805,10 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle)
return 0; return 0;
} }
device_name = grub_malloc (grub_strlen (parent->name) + 1 device_name = grub_xasprintf ("%s,%s", parent->name, partition_name);
+ grub_strlen (partition_name) + 1);
if (! device_name)
{
grub_free (partition_name);
grub_disk_close (parent);
return 0;
}
grub_sprintf (device_name, "%s,%s", parent->name, partition_name);
grub_free (partition_name); grub_free (partition_name);
grub_disk_close (parent); grub_disk_close (parent);
return device_name; return device_name;
} }
else else
@ -833,7 +825,7 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle)
if (! disk) if (! disk)
return 1; return 1;
if (disk->id == GRUB_DISK_DEVICE_EFIDISK_ID) if (disk->dev->id == GRUB_DISK_DEVICE_EFIDISK_ID)
{ {
struct grub_efidisk_data *d; struct grub_efidisk_data *d;

View file

@ -56,7 +56,8 @@ grub_biosdisk_call_hook (int (*hook) (const char *name), int drive)
{ {
char name[10]; char name[10];
grub_sprintf (name, (drive & 0x80) ? "hd%d" : "fd%d", drive & (~0x80)); grub_snprintf (name, sizeof (name),
(drive & 0x80) ? "hd%d" : "fd%d", drive & (~0x80));
return hook (name); return hook (name);
} }
@ -119,7 +120,8 @@ grub_biosdisk_open (const char *name, grub_disk_t disk)
{ {
data->flags = GRUB_BIOSDISK_FLAG_LBA | GRUB_BIOSDISK_FLAG_CDROM; data->flags = GRUB_BIOSDISK_FLAG_LBA | GRUB_BIOSDISK_FLAG_CDROM;
data->sectors = 32; data->sectors = 32;
total_sectors = GRUB_ULONG_MAX; /* TODO: get the correct size. */ /* TODO: get the correct size. */
total_sectors = GRUB_DISK_SIZE_UNKNOWN;
} }
else if (drive & 0x80) else if (drive & 0x80)
{ {
@ -306,8 +308,17 @@ grub_biosdisk_read (grub_disk_t disk, grub_disk_addr_t sector,
while (size) while (size)
{ {
grub_size_t len; grub_size_t len;
grub_size_t cdoff = 0;
len = get_safe_sectors (sector, data->sectors); len = get_safe_sectors (sector, data->sectors);
if (data->flags & GRUB_BIOSDISK_FLAG_CDROM)
{
cdoff = (sector & 3) << GRUB_DISK_SECTOR_BITS;
len = ALIGN_UP (sector + len, 4) - (sector & ~3);
sector &= ~3;
}
if (len > size) if (len > size)
len = size; len = size;
@ -315,7 +326,7 @@ grub_biosdisk_read (grub_disk_t disk, grub_disk_addr_t sector,
GRUB_MEMORY_MACHINE_SCRATCH_SEG)) GRUB_MEMORY_MACHINE_SCRATCH_SEG))
return grub_errno; return grub_errno;
grub_memcpy (buf, (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR, grub_memcpy (buf, (void *) (GRUB_MEMORY_MACHINE_SCRATCH_ADDR + cdoff),
len << GRUB_DISK_SECTOR_BITS); len << GRUB_DISK_SECTOR_BITS);
buf += len << GRUB_DISK_SECTOR_BITS; buf += len << GRUB_DISK_SECTOR_BITS;
sector += len; sector += len;
@ -331,6 +342,9 @@ grub_biosdisk_write (grub_disk_t disk, grub_disk_addr_t sector,
{ {
struct grub_biosdisk_data *data = disk->data; struct grub_biosdisk_data *data = disk->data;
if (data->flags & GRUB_BIOSDISK_FLAG_CDROM)
return grub_error (GRUB_ERR_IO, "can't write to CDROM");
while (size) while (size)
{ {
grub_size_t len; grub_size_t len;

View file

@ -118,7 +118,7 @@ grub_ofdisk_iterate (int (*hook) (const char *name))
static char * static char *
compute_dev_path (const char *name) compute_dev_path (const char *name)
{ {
char *devpath = grub_malloc (grub_strlen (name) + 2); char *devpath = grub_malloc (grub_strlen (name) + 3);
char *p, c; char *p, c;
if (!devpath) if (!devpath)
@ -172,16 +172,6 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)
grub_dprintf ("disk", "Opening `%s'.\n", op->devpath); grub_dprintf ("disk", "Opening `%s'.\n", op->devpath);
grub_ieee1275_open (op->devpath, &dev_ihandle);
if (! dev_ihandle)
{
grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
goto fail;
}
grub_dprintf ("disk", "Opened `%s' as handle %p.\n", op->devpath,
(void *) (unsigned long) dev_ihandle);
if (grub_ieee1275_finddevice (op->devpath, &dev)) if (grub_ieee1275_finddevice (op->devpath, &dev))
{ {
grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't read device properties"); grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't read device properties");
@ -201,10 +191,20 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)
goto fail; goto fail;
} }
grub_ieee1275_open (op->devpath, &dev_ihandle);
if (! dev_ihandle)
{
grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
goto fail;
}
grub_dprintf ("disk", "Opened `%s' as handle %p.\n", op->devpath,
(void *) (unsigned long) dev_ihandle);
/* XXX: There is no property to read the number of blocks. There /* XXX: There is no property to read the number of blocks. There
should be a property `#blocks', but it is not there. Perhaps it should be a property `#blocks', but it is not there. Perhaps it
is possible to use seek for this. */ is possible to use seek for this. */
disk->total_sectors = 0xFFFFFFFFUL; disk->total_sectors = GRUB_DISK_SIZE_UNKNOWN;
disk->id = (unsigned long) op; disk->id = (unsigned long) op;
@ -234,21 +234,17 @@ grub_ofdisk_read (grub_disk_t disk, grub_disk_addr_t sector,
grub_ssize_t status, actual; grub_ssize_t status, actual;
unsigned long long pos; unsigned long long pos;
grub_dprintf ("disk",
"Reading handle %p: sector 0x%llx, size 0x%lx, buf %p.\n",
(void *) disk->data, (long long) sector, (long) size, buf);
pos = sector * 512UL; pos = sector * 512UL;
grub_ieee1275_seek ((grub_ieee1275_ihandle_t) (unsigned long) disk->data, grub_ieee1275_seek ((grub_ieee1275_ihandle_t) (unsigned long) disk->data,
(int) (pos >> 32), (int) pos & 0xFFFFFFFFUL, &status); pos, &status);
if (status < 0) if (status < 0)
return grub_error (GRUB_ERR_READ_ERROR, return grub_error (GRUB_ERR_READ_ERROR,
"seek error, can't seek block %llu", "seek error, can't seek block %llu",
(long long) sector); (long long) sector);
grub_ieee1275_read ((grub_ieee1275_ihandle_t) (unsigned long) disk->data, grub_ieee1275_read ((grub_ieee1275_ihandle_t) (unsigned long) disk->data,
buf, size * 512UL, &actual); buf, size * 512UL, &actual);
if (actual != actual) if (actual != (grub_ssize_t) (size * 512UL))
return grub_error (GRUB_ERR_READ_ERROR, "read error on block: %llu", return grub_error (GRUB_ERR_READ_ERROR, "read error on block: %llu",
(long long) sector); (long long) sector);

View file

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

View file

@ -24,6 +24,10 @@
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/lvm.h> #include <grub/lvm.h>
#ifdef GRUB_UTIL
#include <grub/emu/misc.h>
#endif
static struct grub_lvm_vg *vg_list; static struct grub_lvm_vg *vg_list;
static int lv_count; static int lv_count;
@ -68,6 +72,9 @@ grub_lvm_memberlist (grub_disk_t disk)
if (lv->vg->pvs) if (lv->vg->pvs)
for (pv = lv->vg->pvs; pv; pv = pv->next) for (pv = lv->vg->pvs; pv; pv = pv->next)
{ {
if (!pv->disk)
grub_util_error ("Couldn't find PV %s. Check your device.map",
pv->name);
tmp = grub_malloc (sizeof (*tmp)); tmp = grub_malloc (sizeof (*tmp));
tmp->disk = pv->disk; tmp->disk = pv->disk;
tmp->next = list; tmp->next = list;

View file

@ -23,7 +23,6 @@
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/mm.h> #include <grub/mm.h>
#include <grub/types.h> #include <grub/types.h>
#include <grub/machine/kernel.h>
static char *memdisk_addr; static char *memdisk_addr;
static grub_off_t memdisk_size = 0; static grub_off_t memdisk_size = 0;

View file

@ -556,7 +556,7 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array,
} }
} }
array->name = grub_malloc (13); array->name = grub_xasprintf ("md%d", array->number);
if (! array->name) if (! array->name)
{ {
grub_free (array->uuid); grub_free (array->uuid);
@ -565,8 +565,6 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array,
return grub_errno; return grub_errno;
} }
grub_sprintf (array->name, "md%d", array->number);
grub_dprintf ("raid", "Found array %s (%s)\n", array->name, grub_dprintf ("raid", "Found array %s (%s)\n", array->name,
scanner_name); scanner_name);

View file

@ -25,6 +25,7 @@
#include <grub/types.h> #include <grub/types.h>
#include <grub/scsi.h> #include <grub/scsi.h>
#include <grub/scsicmd.h> #include <grub/scsicmd.h>
#include <grub/time.h>
static grub_scsi_dev_t grub_scsi_dev_list; static grub_scsi_dev_t grub_scsi_dev_list;
@ -50,7 +51,62 @@ grub_scsi_dev_unregister (grub_scsi_dev_t dev)
} }
/* Determine the the device is removable and the type of the device /* Check result of previous operation. */
static grub_err_t
grub_scsi_request_sense (grub_scsi_t scsi)
{
struct grub_scsi_request_sense rs;
struct grub_scsi_request_sense_data rsd;
grub_err_t err;
rs.opcode = grub_scsi_cmd_request_sense;
rs.lun = scsi->lun << GRUB_SCSI_LUN_SHIFT;
rs.reserved1 = 0;
rs.reserved2 = 0;
rs.alloc_length = 0x12; /* XXX: Hardcoded for now */
rs.control = 0;
grub_memset (rs.pad, 0, sizeof(rs.pad));
err = scsi->dev->read (scsi, sizeof (rs), (char *) &rs,
sizeof (rsd), (char *) &rsd);
if (err)
return err;
return GRUB_ERR_NONE;
}
/* Self commenting... */
static grub_err_t
grub_scsi_test_unit_ready (grub_scsi_t scsi)
{
struct grub_scsi_test_unit_ready tur;
grub_err_t err;
grub_err_t err_sense;
tur.opcode = grub_scsi_cmd_test_unit_ready;
tur.lun = scsi->lun << GRUB_SCSI_LUN_SHIFT;
tur.reserved1 = 0;
tur.reserved2 = 0;
tur.reserved3 = 0;
tur.control = 0;
grub_memset (tur.pad, 0, sizeof(tur.pad));
err = scsi->dev->read (scsi, sizeof (tur), (char *) &tur,
0, NULL);
/* Each SCSI command should be followed by Request Sense.
If not so, many devices STALLs or definitely freezes. */
err_sense = grub_scsi_request_sense (scsi);
if (err_sense != GRUB_ERR_NONE)
grub_errno = err;
/* err_sense is ignored for now and Request Sense Data also... */
if (err)
return err;
return GRUB_ERR_NONE;
}
/* Determine if the device is removable and the type of the device
SCSI. */ SCSI. */
static grub_err_t static grub_err_t
grub_scsi_inquiry (grub_scsi_t scsi) grub_scsi_inquiry (grub_scsi_t scsi)
@ -58,15 +114,26 @@ grub_scsi_inquiry (grub_scsi_t scsi)
struct grub_scsi_inquiry iq; struct grub_scsi_inquiry iq;
struct grub_scsi_inquiry_data iqd; struct grub_scsi_inquiry_data iqd;
grub_err_t err; grub_err_t err;
grub_err_t err_sense;
iq.opcode = grub_scsi_cmd_inquiry; iq.opcode = grub_scsi_cmd_inquiry;
iq.lun = scsi->lun << GRUB_SCSI_LUN_SHIFT; iq.lun = scsi->lun << GRUB_SCSI_LUN_SHIFT;
iq.page = 0;
iq.reserved = 0; iq.reserved = 0;
iq.alloc_length = 0x24; /* XXX: Hardcoded for now */ iq.alloc_length = 0x24; /* XXX: Hardcoded for now */
iq.reserved2 = 0; iq.control = 0;
grub_memset (iq.pad, 0, sizeof(iq.pad));
err = scsi->dev->read (scsi, sizeof (iq), (char *) &iq, err = scsi->dev->read (scsi, sizeof (iq), (char *) &iq,
sizeof (iqd), (char *) &iqd); sizeof (iqd), (char *) &iqd);
/* Each SCSI command should be followed by Request Sense.
If not so, many devices STALLs or definitely freezes. */
err_sense = grub_scsi_request_sense (scsi);
if (err_sense != GRUB_ERR_NONE)
grub_errno = err;
/* err_sense is ignored for now and Request Sense Data also... */
if (err) if (err)
return err; return err;
@ -83,13 +150,27 @@ grub_scsi_read_capacity (grub_scsi_t scsi)
struct grub_scsi_read_capacity rc; struct grub_scsi_read_capacity rc;
struct grub_scsi_read_capacity_data rcd; struct grub_scsi_read_capacity_data rcd;
grub_err_t err; grub_err_t err;
grub_err_t err_sense;
rc.opcode = grub_scsi_cmd_read_capacity; rc.opcode = grub_scsi_cmd_read_capacity;
rc.lun = scsi->lun << GRUB_SCSI_LUN_SHIFT; rc.lun = scsi->lun << GRUB_SCSI_LUN_SHIFT;
grub_memset (rc.reserved, 0, sizeof (rc.reserved)); rc.logical_block_addr = 0;
rc.reserved1 = 0;
rc.reserved2 = 0;
rc.PMI = 0;
rc.control = 0;
rc.pad = 0;
err = scsi->dev->read (scsi, sizeof (rc), (char *) &rc, err = scsi->dev->read (scsi, sizeof (rc), (char *) &rc,
sizeof (rcd), (char *) &rcd); sizeof (rcd), (char *) &rcd);
/* Each SCSI command should be followed by Request Sense.
If not so, many devices STALLs or definitely freezes. */
err_sense = grub_scsi_request_sense (scsi);
if (err_sense != GRUB_ERR_NONE)
grub_errno = err;
/* err_sense is ignored for now and Request Sense Data also... */
if (err) if (err)
return err; return err;
@ -107,6 +188,8 @@ grub_scsi_read10 (grub_disk_t disk, grub_disk_addr_t sector,
{ {
grub_scsi_t scsi; grub_scsi_t scsi;
struct grub_scsi_read10 rd; struct grub_scsi_read10 rd;
grub_err_t err;
grub_err_t err_sense;
scsi = disk->data; scsi = disk->data;
@ -118,7 +201,16 @@ grub_scsi_read10 (grub_disk_t disk, grub_disk_addr_t sector,
rd.reserved2 = 0; rd.reserved2 = 0;
rd.pad = 0; rd.pad = 0;
return scsi->dev->read (scsi, sizeof (rd), (char *) &rd, size * scsi->blocksize, buf); err = scsi->dev->read (scsi, sizeof (rd), (char *) &rd, size * scsi->blocksize, buf);
/* Each SCSI command should be followed by Request Sense.
If not so, many devices STALLs or definitely freezes. */
err_sense = grub_scsi_request_sense (scsi);
if (err_sense != GRUB_ERR_NONE)
grub_errno = err;
/* err_sense is ignored for now and Request Sense Data also... */
return err;
} }
/* Send a SCSI request for DISK: read SIZE sectors starting with /* Send a SCSI request for DISK: read SIZE sectors starting with
@ -129,6 +221,8 @@ grub_scsi_read12 (grub_disk_t disk, grub_disk_addr_t sector,
{ {
grub_scsi_t scsi; grub_scsi_t scsi;
struct grub_scsi_read12 rd; struct grub_scsi_read12 rd;
grub_err_t err;
grub_err_t err_sense;
scsi = disk->data; scsi = disk->data;
@ -139,7 +233,16 @@ grub_scsi_read12 (grub_disk_t disk, grub_disk_addr_t sector,
rd.reserved = 0; rd.reserved = 0;
rd.control = 0; rd.control = 0;
return scsi->dev->read (scsi, sizeof (rd), (char *) &rd, size * scsi->blocksize, buf); err = scsi->dev->read (scsi, sizeof (rd), (char *) &rd, size * scsi->blocksize, buf);
/* Each SCSI command should be followed by Request Sense.
If not so, many devices STALLs or definitely freezes. */
err_sense = grub_scsi_request_sense (scsi);
if (err_sense != GRUB_ERR_NONE)
grub_errno = err;
/* err_sense is ignored for now and Request Sense Data also... */
return err;
} }
#if 0 #if 0
@ -151,6 +254,8 @@ grub_scsi_write10 (grub_disk_t disk, grub_disk_addr_t sector,
{ {
grub_scsi_t scsi; grub_scsi_t scsi;
struct grub_scsi_write10 wr; struct grub_scsi_write10 wr;
grub_err_t err;
grub_err_t err_sense;
scsi = disk->data; scsi = disk->data;
@ -162,7 +267,16 @@ grub_scsi_write10 (grub_disk_t disk, grub_disk_addr_t sector,
wr.reserved2 = 0; wr.reserved2 = 0;
wr.pad = 0; wr.pad = 0;
return scsi->dev->write (scsi, sizeof (wr), (char *) &wr, size * scsi->blocksize, buf); err = scsi->dev->write (scsi, sizeof (wr), (char *) &wr, size * scsi->blocksize, buf);
/* Each SCSI command should be followed by Request Sense.
If not so, many devices STALLs or definitely freezes. */
err_sense = grub_scsi_request_sense (scsi);
if (err_sense != GRUB_ERR_NONE)
grub_errno = err;
/* err_sense is ignored for now and Request Sense Data also... */
return err;
} }
/* Send a SCSI request for DISK: write the data stored in BUF to SIZE /* Send a SCSI request for DISK: write the data stored in BUF to SIZE
@ -172,7 +286,9 @@ grub_scsi_write12 (grub_disk_t disk, grub_disk_addr_t sector,
grub_size_t size, char *buf) grub_size_t size, char *buf)
{ {
grub_scsi_t scsi; grub_scsi_t scsi;
struct grub_scsi_write10 wr; struct grub_scsi_write12 wr;
grub_err_t err;
grub_err_t err_sense;
scsi = disk->data; scsi = disk->data;
@ -181,9 +297,18 @@ grub_scsi_write12 (grub_disk_t disk, grub_disk_addr_t sector,
wr.lba = grub_cpu_to_be32 (sector); wr.lba = grub_cpu_to_be32 (sector);
wr.size = grub_cpu_to_be32 (size); wr.size = grub_cpu_to_be32 (size);
wr.reserved = 0; wr.reserved = 0;
wr.pad = 0; wr.control = 0;
return scsi->dev->write (scsi, sizeof (wr), (char *) &wr, size * scsi->blocksize, buf); err = scsi->dev->write (scsi, sizeof (wr), (char *) &wr, size * scsi->blocksize, buf);
/* Each SCSI command should be followed by Request Sense.
If not so, many devices STALLs or definitely freezes. */
err_sense = grub_scsi_request_sense (scsi);
if (err_sense != GRUB_ERR_NONE)
grub_errno = err;
/* err_sense is ignored for now and Request Sense Data also... */
return err;
} }
#endif #endif
@ -197,7 +322,6 @@ grub_scsi_iterate (int (*hook) (const char *name))
int scsi_iterate (const char *name, int luns) int scsi_iterate (const char *name, int luns)
{ {
char sname[40];
int i; int i;
/* In case of a single LUN, just return `usbX'. */ /* In case of a single LUN, just return `usbX'. */
@ -208,8 +332,14 @@ grub_scsi_iterate (int (*hook) (const char *name))
distinguish it. */ distinguish it. */
for (i = 0; i < luns; i++) for (i = 0; i < luns; i++)
{ {
grub_sprintf (sname, "%s%c", name, 'a' + i); char *sname;
if (hook (sname)) int ret;
sname = grub_xasprintf ("%s%c", name, 'a' + i);
if (!sname)
return 1;
ret = hook (sname);
grub_free (sname);
if (ret)
return 1; return 1;
} }
return 0; return 0;
@ -230,6 +360,7 @@ grub_scsi_open (const char *name, grub_disk_t disk)
grub_err_t err; grub_err_t err;
int len; int len;
int lun; int lun;
grub_uint64_t maxtime;
scsi = grub_malloc (sizeof (*scsi)); scsi = grub_malloc (sizeof (*scsi));
if (! scsi) if (! scsi)
@ -287,6 +418,31 @@ grub_scsi_open (const char *name, grub_disk_t disk)
else else
disk->has_partitions = 1; disk->has_partitions = 1;
/* According to USB MS tests specification, issue Test Unit Ready
* until OK */
maxtime = grub_get_time_ms () + 5000; /* It is safer value */
do
{
/* Timeout is necessary - for example in case when we have
* universal card reader with more LUNs and we have only
* one card inserted (or none), so only one LUN (or none)
* will be ready - and we want not to hang... */
if (grub_get_time_ms () > maxtime)
{
err = GRUB_ERR_READ_ERROR;
grub_free (scsi);
grub_dprintf ("scsi", "LUN is not ready - timeout\n");
return err;
}
err = grub_scsi_test_unit_ready (scsi);
}
while (err == GRUB_ERR_READ_ERROR);
/* Reset grub_errno !
* It is set to some error code in loop before... */
grub_errno = GRUB_ERR_NONE;
/* Read capacity of media */
err = grub_scsi_read_capacity (scsi); err = grub_scsi_read_capacity (scsi);
if (err) if (err)
{ {
@ -297,12 +453,14 @@ grub_scsi_open (const char *name, grub_disk_t disk)
/* SCSI blocks can be something else than 512, although GRUB /* SCSI blocks can be something else than 512, although GRUB
wants 512 byte blocks. */ wants 512 byte blocks. */
disk->total_sectors = ((scsi->size * scsi->blocksize) disk->total_sectors = ((grub_uint64_t)scsi->size
<< GRUB_DISK_SECTOR_BITS); * (grub_uint64_t)scsi->blocksize)
>> GRUB_DISK_SECTOR_BITS;
grub_dprintf ("scsi", "capacity=%llu, blksize=%d\n", grub_dprintf ("scsi", "blocks=%u, blocksize=%u\n",
(unsigned long long) disk->total_sectors, scsi->size, scsi->blocksize);
scsi->blocksize); grub_dprintf ("scsi", "Disk total 512 sectors = %llu\n",
(unsigned long long) disk->total_sectors);
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
} }
@ -361,6 +519,37 @@ grub_scsi_read (grub_disk_t disk, grub_disk_addr_t sector,
/* XXX: Never reached. */ /* XXX: Never reached. */
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
#if 0 /* Workaround - it works - but very slowly, from some reason
* unknown to me (specially on OHCI). Do not use it. */
/* Split transfer requests to device sector size because */
/* some devices are not able to transfer more than 512-1024 bytes */
grub_err_t err = GRUB_ERR_NONE;
for ( ; size; size--)
{
/* Depending on the type, select a read function. */
switch (scsi->devtype)
{
case grub_scsi_devtype_direct:
err = grub_scsi_read10 (disk, sector, 1, buf);
break;
case grub_scsi_devtype_cdrom:
err = grub_scsi_read12 (disk, sector, 1, buf);
break;
default: /* This should not happen */
return GRUB_ERR_READ_ERROR;
}
if (err)
return err;
sector++;
buf += scsi->blocksize;
}
return err;
#endif
} }
static grub_err_t static grub_err_t

View file

@ -84,7 +84,8 @@ grub_usbms_finddevs (void)
struct grub_usb_desc_device *descdev = &usbdev->descdev; struct grub_usb_desc_device *descdev = &usbdev->descdev;
int i; int i;
if (descdev->class != 0 || descdev->subclass || descdev->protocol != 0) if (descdev->class != 0 || descdev->subclass || descdev->protocol != 0
|| descdev->configcnt == 0)
return 0; return 0;
/* XXX: Just check configuration 0 for now. */ /* XXX: Just check configuration 0 for now. */
@ -93,19 +94,31 @@ grub_usbms_finddevs (void)
struct grub_usbms_dev *usbms; struct grub_usbms_dev *usbms;
struct grub_usb_desc_if *interf; struct grub_usb_desc_if *interf;
int j; int j;
grub_uint8_t luns; grub_uint8_t luns = 0;
grub_dprintf ("usbms", "alive\n");
interf = usbdev->config[0].interf[i].descif; interf = usbdev->config[0].interf[i].descif;
/* If this is not a USB Mass Storage device with a supported /* If this is not a USB Mass Storage device with a supported
protocol, just skip it. */ protocol, just skip it. */
grub_dprintf ("usbms", "iterate: interf=%d, class=%d, subclass=%d, protocol=%d\n",
i, interf->class, interf->subclass, interf->protocol);
if (interf->class != GRUB_USB_CLASS_MASS_STORAGE if (interf->class != GRUB_USB_CLASS_MASS_STORAGE
|| interf->subclass != GRUB_USBMS_SUBCLASS_BULK || ( interf->subclass != GRUB_USBMS_SUBCLASS_BULK &&
/* Experimental support of RBC, MMC-2, UFI, SFF-8070i devices */
interf->subclass != GRUB_USBMS_SUBCLASS_RBC &&
interf->subclass != GRUB_USBMS_SUBCLASS_MMC2 &&
interf->subclass != GRUB_USBMS_SUBCLASS_UFI &&
interf->subclass != GRUB_USBMS_SUBCLASS_SFF8070 )
|| interf->protocol != GRUB_USBMS_PROTOCOL_BULK) || interf->protocol != GRUB_USBMS_PROTOCOL_BULK)
{ {
continue; continue;
} }
grub_dprintf ("usbms", "alive\n");
devcnt++; devcnt++;
usbms = grub_zalloc (sizeof (struct grub_usbms_dev)); usbms = grub_zalloc (sizeof (struct grub_usbms_dev));
if (! usbms) if (! usbms)
@ -114,6 +127,8 @@ grub_usbms_finddevs (void)
usbms->dev = usbdev; usbms->dev = usbdev;
usbms->interface = i; usbms->interface = i;
grub_dprintf ("usbms", "alive\n");
/* Iterate over all endpoints of this interface, at least a /* Iterate over all endpoints of this interface, at least a
IN and OUT bulk endpoint are required. */ IN and OUT bulk endpoint are required. */
for (j = 0; j < interf->endpointcnt; j++) for (j = 0; j < interf->endpointcnt; j++)
@ -125,14 +140,16 @@ grub_usbms_finddevs (void)
{ {
/* Bulk IN endpoint. */ /* Bulk IN endpoint. */
usbms->in = endp; usbms->in = endp;
grub_usb_clear_halt (usbdev, endp->endp_addr & 128); /* Clear Halt is not possible yet! */
/* grub_usb_clear_halt (usbdev, endp->endp_addr); */
usbms->in_maxsz = endp->maxpacket; usbms->in_maxsz = endp->maxpacket;
} }
else if (!(endp->endp_addr & 128) && (endp->attrib & 3) == 2) else if (!(endp->endp_addr & 128) && (endp->attrib & 3) == 2)
{ {
/* Bulk OUT endpoint. */ /* Bulk OUT endpoint. */
usbms->out = endp; usbms->out = endp;
grub_usb_clear_halt (usbdev, endp->endp_addr & 128); /* Clear Halt is not possible yet! */
/* grub_usb_clear_halt (usbdev, endp->endp_addr); */
usbms->out_maxsz = endp->maxpacket; usbms->out_maxsz = endp->maxpacket;
} }
} }
@ -143,51 +160,63 @@ grub_usbms_finddevs (void)
return 0; return 0;
} }
grub_dprintf ("usbms", "alive\n");
/* XXX: Activate the first configuration. */
grub_usb_set_configuration (usbdev, 1);
/* Query the amount of LUNs. */ /* Query the amount of LUNs. */
err = grub_usb_control_msg (usbdev, 0xA1, 254, err = grub_usb_control_msg (usbdev, 0xA1, 254,
0, i, 1, (char *) &luns); 0, i, 1, (char *) &luns);
if (err) if (err)
{ {
/* In case of a stall, clear the stall. */ /* In case of a stall, clear the stall. */
if (err == GRUB_USB_ERR_STALL) if (err == GRUB_USB_ERR_STALL)
{ {
grub_usb_clear_halt (usbdev, usbms->in->endp_addr & 3); grub_usb_clear_halt (usbdev, usbms->in->endp_addr);
grub_usb_clear_halt (usbdev, usbms->out->endp_addr & 3); grub_usb_clear_halt (usbdev, usbms->out->endp_addr);
} }
/* Just set the amount of LUNs to one. */ /* Just set the amount of LUNs to one. */
grub_errno = GRUB_ERR_NONE; grub_errno = GRUB_ERR_NONE;
usbms->luns = 1; usbms->luns = 1;
} }
else else
usbms->luns = luns; /* luns = 0 means one LUN with ID 0 present ! */
/* We get from device not number of LUNs but highest
* LUN number. LUNs are numbered from 0,
* i.e. number of LUNs is luns+1 ! */
usbms->luns = luns + 1;
/* XXX: Check the magic values, does this really make grub_dprintf ("usbms", "alive\n");
sense? */
grub_usb_control_msg (usbdev, (1 << 6) | 1, 255,
0, i, 0, 0);
/* XXX: To make Qemu work? */
if (usbms->luns == 0)
usbms->luns = 1;
usbms->next = grub_usbms_dev_list; usbms->next = grub_usbms_dev_list;
grub_usbms_dev_list = usbms; grub_usbms_dev_list = usbms;
/* XXX: Activate the first configuration. */ #if 0 /* All this part should be probably deleted.
grub_usb_set_configuration (usbdev, 1); * This make trouble on some devices if they are not in
* Phase Error state - and there they should be not in such state...
* Bulk only mass storage reset procedure should be used only
* on place and in time when it is really necessary. */
/* Reset recovery procedure */
/* Bulk-Only Mass Storage Reset, after the reset commands /* Bulk-Only Mass Storage Reset, after the reset commands
will be accepted. */ will be accepted. */
grub_usbms_reset (usbdev, i); grub_usbms_reset (usbdev, i);
grub_usb_clear_halt (usbdev, usbms->in->endp_addr);
grub_usb_clear_halt (usbdev, usbms->out->endp_addr);
#endif
return 0; return 0;
} }
grub_dprintf ("usbms", "alive\n");
return 0; return 0;
} }
grub_dprintf ("usbms", "alive\n");
grub_usb_iterate (usb_iterate); grub_usb_iterate (usb_iterate);
grub_dprintf ("usbms", "alive\n");
} }
@ -200,11 +229,15 @@ grub_usbms_iterate (int (*hook) (const char *name, int luns))
for (p = grub_usbms_dev_list; p; p = p->next) for (p = grub_usbms_dev_list; p; p = p->next)
{ {
char devname[20]; char *devname;
grub_sprintf (devname, "usb%d", cnt); devname = grub_xasprintf ("usb%d", cnt);
if (hook (devname, p->luns)) if (hook (devname, p->luns))
return 1; {
grub_free (devname);
return 1;
}
grub_free (devname);
cnt++; cnt++;
} }
@ -220,7 +253,9 @@ grub_usbms_transfer (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd,
struct grub_usbms_csw status; struct grub_usbms_csw status;
static grub_uint32_t tag = 0; static grub_uint32_t tag = 0;
grub_usb_err_t err = GRUB_USB_ERR_NONE; grub_usb_err_t err = GRUB_USB_ERR_NONE;
grub_usb_err_t errCSW = GRUB_USB_ERR_NONE;
int retrycnt = 3 + 1; int retrycnt = 3 + 1;
grub_size_t i;
retry: retry:
retrycnt--; retrycnt--;
@ -233,73 +268,102 @@ grub_usbms_transfer (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd,
cbw.tag = tag++; cbw.tag = tag++;
cbw.transfer_length = grub_cpu_to_le32 (size); cbw.transfer_length = grub_cpu_to_le32 (size);
cbw.flags = (!read_write) << GRUB_USBMS_DIRECTION_BIT; cbw.flags = (!read_write) << GRUB_USBMS_DIRECTION_BIT;
cbw.lun = scsi->lun << GRUB_SCSI_LUN_SHIFT; cbw.lun = scsi->lun; /* In USB MS CBW are LUN bits on another place than in SCSI CDB, both should be set correctly. */
cbw.length = cmdsize; cbw.length = cmdsize;
grub_memcpy (cbw.cbwcb, cmd, cmdsize); grub_memcpy (cbw.cbwcb, cmd, cmdsize);
/* Debug print of CBW content. */
grub_dprintf ("usb", "CBW: sign=0x%08x tag=0x%08x len=0x%08x\n",
cbw.signature, cbw.tag, cbw.transfer_length);
grub_dprintf ("usb", "CBW: flags=0x%02x lun=0x%02x CB_len=0x%02x\n",
cbw.flags, cbw.lun, cbw.length);
grub_dprintf ("usb", "CBW: cmd:\n %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
cbw.cbwcb[ 0], cbw.cbwcb[ 1], cbw.cbwcb[ 2], cbw.cbwcb[ 3],
cbw.cbwcb[ 4], cbw.cbwcb[ 5], cbw.cbwcb[ 6], cbw.cbwcb[ 7],
cbw.cbwcb[ 8], cbw.cbwcb[ 9], cbw.cbwcb[10], cbw.cbwcb[11],
cbw.cbwcb[12], cbw.cbwcb[13], cbw.cbwcb[14], cbw.cbwcb[15]);
/* Write the request. */ /* Write the request.
err = grub_usb_bulk_write (dev->dev, dev->out->endp_addr & 15, * XXX: Error recovery is maybe still not fully correct. */
err = grub_usb_bulk_write (dev->dev, dev->out->endp_addr,
sizeof (cbw), (char *) &cbw); sizeof (cbw), (char *) &cbw);
if (err) if (err)
{ {
if (err == GRUB_USB_ERR_STALL) if (err == GRUB_USB_ERR_STALL)
{ {
grub_usb_clear_halt (dev->dev, dev->out->endp_addr); grub_usb_clear_halt (dev->dev, dev->out->endp_addr);
goto retry; goto CheckCSW;
} }
return grub_error (GRUB_ERR_IO, "USB Mass Storage request failed"); return grub_error (GRUB_ERR_IO, "USB Mass Storage request failed");
} }
/* Read/write the data. */ /* Read/write the data, (maybe) according to specification. */
if (read_write == 0) if (size && (read_write == 0))
{ {
err = grub_usb_bulk_read (dev->dev, dev->in->endp_addr & 15, size, buf); err = grub_usb_bulk_read (dev->dev, dev->in->endp_addr, size, buf);
grub_dprintf ("usb", "read: %d %d\n", err, GRUB_USB_ERR_STALL); grub_dprintf ("usb", "read: %d %d\n", err, GRUB_USB_ERR_STALL);
if (err) if (err)
{ {
if (err == GRUB_USB_ERR_STALL) if (err == GRUB_USB_ERR_STALL)
{ grub_usb_clear_halt (dev->dev, dev->in->endp_addr);
grub_usb_clear_halt (dev->dev, dev->in->endp_addr); goto CheckCSW;
goto retry; }
} /* Debug print of received data. */
return grub_error (GRUB_ERR_READ_ERROR, grub_dprintf ("usb", "buf:\n");
"can't read from USB Mass Storage device"); if (size <= 64)
} for (i=0; i<size; i++)
grub_dprintf ("usb", "0x%02x: 0x%02x\n", i, buf[i]);
else
grub_dprintf ("usb", "Too much data for debug print...\n");
} }
else else if (size)
{ {
err = grub_usb_bulk_write (dev->dev, dev->in->endp_addr & 15, size, buf); err = grub_usb_bulk_write (dev->dev, dev->out->endp_addr, size, buf);
grub_dprintf ("usb", "write: %d %d\n", err, GRUB_USB_ERR_STALL); grub_dprintf ("usb", "write: %d %d\n", err, GRUB_USB_ERR_STALL);
grub_dprintf ("usb", "buf:\n");
if (err) if (err)
{ {
if (err == GRUB_USB_ERR_STALL) if (err == GRUB_USB_ERR_STALL)
{ grub_usb_clear_halt (dev->dev, dev->out->endp_addr);
grub_usb_clear_halt (dev->dev, dev->out->endp_addr); goto CheckCSW;
goto retry; }
} /* Debug print of sent data. */
return grub_error (GRUB_ERR_WRITE_ERROR, if (size <= 256)
"can't write to USB Mass Storage device"); for (i=0; i<size; i++)
} grub_dprintf ("usb", "0x%02x: 0x%02x\n", i, buf[i]);
else
grub_dprintf ("usb", "Too much data for debug print...\n");
} }
/* Read the status. */ /* Read the status - (maybe) according to specification. */
err = grub_usb_bulk_read (dev->dev, dev->in->endp_addr & 15, CheckCSW:
sizeof (status), (char *) &status); errCSW = grub_usb_bulk_read (dev->dev, dev->in->endp_addr,
if (err) sizeof (status), (char *) &status);
if (errCSW)
{ {
if (err == GRUB_USB_ERR_STALL) grub_usb_clear_halt (dev->dev, dev->in->endp_addr);
{ errCSW = grub_usb_bulk_read (dev->dev, dev->in->endp_addr,
grub_usb_clear_halt (dev->dev, dev->in->endp_addr); sizeof (status), (char *) &status);
if (errCSW)
{ /* Bulk-only reset device. */
grub_dprintf ("usb", "Bulk-only reset device - errCSW\n");
grub_usbms_reset (dev->dev, dev->interface);
grub_usb_clear_halt (dev->dev, dev->in->endp_addr);
grub_usb_clear_halt (dev->dev, dev->out->endp_addr);
goto retry; goto retry;
} }
return grub_error (GRUB_ERR_READ_ERROR,
"can't read status from USB Mass Storage device");
} }
/* XXX: Magic and check this code. */ /* Debug print of CSW content. */
if (status.status == 2) grub_dprintf ("usb", "CSW: sign=0x%08x tag=0x%08x resid=0x%08x\n",
{ status.signature, status.tag, status.residue);
/* XXX: Phase error, reset device. */ grub_dprintf ("usb", "CSW: status=0x%02x\n", status.status);
/* If phase error or not valid signature, do bulk-only reset device. */
if ((status.status == 2) ||
(status.signature != grub_cpu_to_le32(0x53425355)))
{ /* Bulk-only reset device. */
grub_dprintf ("usb", "Bulk-only reset device - bad status\n");
grub_usbms_reset (dev->dev, dev->interface); grub_usbms_reset (dev->dev, dev->interface);
grub_usb_clear_halt (dev->dev, dev->in->endp_addr); grub_usb_clear_halt (dev->dev, dev->in->endp_addr);
grub_usb_clear_halt (dev->dev, dev->out->endp_addr); grub_usb_clear_halt (dev->dev, dev->out->endp_addr);
@ -307,9 +371,13 @@ grub_usbms_transfer (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd,
goto retry; goto retry;
} }
if (status.status) /* If "command failed" status or data transfer failed -> error */
if ((status.status || err) && !read_write)
return grub_error (GRUB_ERR_READ_ERROR, return grub_error (GRUB_ERR_READ_ERROR,
"error communication with USB Mass Storage device"); "error communication with USB Mass Storage device");
else if ((status.status || err) && read_write)
return grub_error (GRUB_ERR_WRITE_ERROR,
"error communication with USB Mass Storage device");
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
} }

File diff suppressed because it is too large Load diff

2
docs/man/grub-bin2h.h2m Normal file
View file

@ -0,0 +1,2 @@
[NAME]
grub-bin2h \- convert a binary file to a C header

View file

@ -0,0 +1,2 @@
[NAME]
grub-editenv \- edit GRUB environment block

2
docs/man/grub-fstest.h2m Normal file
View file

@ -0,0 +1,2 @@
[NAME]
grub-fstest \- debug tool for GRUB filesystem drivers

View file

@ -0,0 +1,2 @@
[NAME]
grub-install \- install GRUB to a device

View file

@ -0,0 +1,2 @@
[NAME]
grub-macho2img \- convert Mach-O to raw image

View file

@ -0,0 +1,2 @@
[NAME]
grub-mkconfig \- generate a GRUB configuration file

View file

@ -0,0 +1,2 @@
[NAME]
grub-mkdevicemap \- generate a GRUB device map file automatically

2
docs/man/grub-mkfont.h2m Normal file
View file

@ -0,0 +1,2 @@
[NAME]
grub-mkfont \- make GRUB font files

View file

@ -0,0 +1,2 @@
[NAME]
grub-mkimage \- make a bootable image of GRUB

View file

@ -0,0 +1,2 @@
[NAME]
grub-mkpasswd-pbkdf2 \- generate hashed password for GRUB

View file

@ -0,0 +1,2 @@
[NAME]
grub-mkrelpath \- make a system path relative to its root

View file

@ -0,0 +1,2 @@
[NAME]
grub-mkrescue \- make a GRUB rescue image

View file

@ -0,0 +1,2 @@
[NAME]
grub-ofpathname \- find OpenBOOT path for a device

2
docs/man/grub-pe2elf.h2m Normal file
View file

@ -0,0 +1,2 @@
[NAME]
grub-pe2elf \- convert PE image to ELF

2
docs/man/grub-probe.h2m Normal file
View file

@ -0,0 +1,2 @@
[NAME]
grub-probe \- probe device information for GRUB

2
docs/man/grub-reboot.h2m Normal file
View file

@ -0,0 +1,2 @@
[NAME]
grub-reboot \- set the default boot entry for GRUB, for the next boot only

View file

@ -0,0 +1,2 @@
[NAME]
grub-script-check \- check grub.cfg for syntax errors

View file

@ -0,0 +1,2 @@
[NAME]
grub-set-default \- set the default boot entry for GRUB

2
docs/man/grub-setup.h2m Normal file
View file

@ -0,0 +1,2 @@
[NAME]
grub-setup \- set up a device to boot using GRUB

View file

@ -31,6 +31,7 @@
#include <grub/efiemu/efiemu.h> #include <grub/efiemu/efiemu.h>
#include <grub/machine/efiemu.h> #include <grub/machine/efiemu.h>
#include <grub/command.h> #include <grub/command.h>
#include <grub/i18n.h>
/* System table. Two version depending on mode */ /* System table. Two version depending on mode */
grub_efi_system_table32_t *grub_efiemu_system_table32 = 0; grub_efi_system_table32_t *grub_efiemu_system_table32 = 0;
@ -255,18 +256,17 @@ grub_efiemu_autocore (void)
suffix = grub_efiemu_get_default_core_name (); suffix = grub_efiemu_get_default_core_name ();
filename = grub_malloc (grub_strlen (prefix) + grub_strlen (suffix) + 2); filename = grub_xasprintf ("%s/%s", prefix, suffix);
if (! filename) if (! filename)
return grub_error (GRUB_ERR_OUT_OF_MEMORY, return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"couldn't allocate temporary space"); "couldn't allocate temporary space");
grub_sprintf (filename, "%s/%s", prefix, suffix);
err = grub_efiemu_load_file (filename); err = grub_efiemu_load_file (filename);
grub_free (filename); grub_free (filename);
if (err) if (err)
return err; return err;
#ifndef GRUB_UTIL #ifndef GRUB_MACHINE_EMU
err = grub_machine_efiemu_init_tables (); err = grub_machine_efiemu_init_tables ();
if (err) if (err)
return err; return err;
@ -314,7 +314,7 @@ grub_cmd_efiemu_load (grub_command_t cmd __attribute__ ((unused)),
err = grub_efiemu_load_file (args[0]); err = grub_efiemu_load_file (args[0]);
if (err) if (err)
return err; return err;
#ifndef GRUB_UTIL #ifndef GRUB_MACHINE_EMU
err = grub_machine_efiemu_init_tables (); err = grub_machine_efiemu_init_tables ();
if (err) if (err)
return err; return err;
@ -328,15 +328,15 @@ GRUB_MOD_INIT(efiemu)
{ {
cmd_loadcore = grub_register_command ("efiemu_loadcore", cmd_loadcore = grub_register_command ("efiemu_loadcore",
grub_cmd_efiemu_load, grub_cmd_efiemu_load,
"FILE", N_("FILE"),
"Load and initialize EFI emulator."); N_("Load and initialize EFI emulator."));
cmd_prepare = grub_register_command ("efiemu_prepare", cmd_prepare = grub_register_command ("efiemu_prepare",
grub_cmd_efiemu_prepare, grub_cmd_efiemu_prepare,
0, 0,
"Finalize loading of EFI emulator."); N_("Finalize loading of EFI emulator."));
cmd_unload = grub_register_command ("efiemu_unload", grub_cmd_efiemu_unload, cmd_unload = grub_register_command ("efiemu_unload", grub_cmd_efiemu_unload,
0, 0,
"Unload EFI emulator."); N_("Unload EFI emulator."));
} }
GRUB_MOD_FINI(efiemu) GRUB_MOD_FINI(efiemu)

View file

@ -281,7 +281,7 @@ grub_efiemu_mmap_init (void)
// the place for memory used by efiemu itself // the place for memory used by efiemu itself
mmap_reserved_size = GRUB_EFI_MAX_MEMORY_TYPE + 1; mmap_reserved_size = GRUB_EFI_MAX_MEMORY_TYPE + 1;
#ifndef GRUB_UTIL #ifndef GRUB_MACHINE_EMU
grub_machine_mmap_iterate (bounds_hook); grub_machine_mmap_iterate (bounds_hook);
#endif #endif
@ -394,7 +394,7 @@ grub_efiemu_mmap_fill (void)
} }
} }
#ifndef GRUB_UTIL #ifndef GRUB_MACHINE_EMU
grub_machine_mmap_iterate (fill_hook); grub_machine_mmap_iterate (fill_hook);
#endif #endif

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