New upstream snapshot.

This commit is contained in:
Colin Watson 2013-11-19 18:51:06 +00:00
commit 54154f04b8
111 changed files with 7244 additions and 2687 deletions

314
ChangeLog
View File

@ -1,3 +1,317 @@
2013-11-19 Josh Triplett <josh@joshtriplett.org>
* grub-core/kern/x86_64/efi/startup.S (_start): Align the stack to a
16-byte boundary, as required by the x86-64 ABI, before calling
grub_main. In some cases, GCC emits code that assumes this
alignment, which crashes if not aligned. The EFI firmware is also
entitled to assume that stack alignment without checking.
2013-11-18 Josh Triplett <josh@joshtriplett.org>
* grub-core/mmap/efi/mmap.c (grub_mmap_register): Round up/down to
4k page boundaries as expected by firmware rather than 1k
boundaries.
(grub_mmap_malign_and_register): Likewise.
2013-11-18 Vladimir Serbinenko <phcoder@gmail.com>
* tests/grub_func_test.in: Decrease RAM size to 512M. With less
fragmentation 512M is enough.
2013-11-18 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/kern/mm.c (grub_real_malloc): Decrease cut-off of moving the
pointer to 32K. This is the size of cache element which is the most
common allocation >1K. This way the pointer is always around blocks
of 32K and so we keep performance while decreasing fragmentation.
2013-11-18 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/kern/mm.c (grub_real_malloc): Don't update the pointer to
current memory when allocating large chunks. This significantly
decreases memory fragmentation.
2013-11-18 Colin Watson <cjwatson@ubuntu.com>
* tests/gzcompress_test.in: Skip if gzip is not installed (unlikely,
but for symmetry).
* tests/lzocompress_test.in: Skip if lzop is not installed.
* tests/xzcompress_test.in: Skip if xz is not installed.
2013-11-18 Colin Watson <cjwatson@ubuntu.com>
* util/grub-mkrescue.c (main): Fix typo.
2013-11-18 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/kern/mips/qemu_mips/init.c (grub_machine_init): Update
clock frequency to 200 MHz,
2013-11-18 Vladimir Serbinenko <phcoder@gmail.com>
* tests/util/grub-shell.in: Increase console size to 1024x1024.
2013-11-18 Vladimir Serbinenko <phcoder@gmail.com>
* Makefile.am (default_payload.elf): Add pata to loaded modules.
Load config file from (cbfsdisk)/etc/grub.cfg.
2013-11-18 Vladimir Serbinenko <phcoder@gmail.com>
* util/grub-install-common.c (grub_install_copy_files): Fix module
destination directory.
2013-11-18 Colin Watson <cjwatson@ubuntu.com>
* tests/util/grub-shell.in: Don't fail on emu platform if po/*.gmo
files have not been built.
2013-11-18 Colin Watson <cjwatson@ubuntu.com>
* grub-core/osdep/unix/hostdisk.c (grub_util_make_temporary_file):
Handle errors from mkstemp.
(grub_util_make_temporary_dir): Handle errors from mkdtemp.
2013-11-18 Vladimir Serbinenko <phcoder@gmail.com>
* tests/util/grub-shell.in: Use -cdrom and don't force cdrom
on primary master on pseries.
2013-11-18 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/tests/videotest_checksum.c: Don't reload unifont if it's
already loaded. This saves memory needed for tests,
2013-11-18 Vladimir Serbinenko <phcoder@gmail.com>
* util/grub-mkrescue.c (main): Fix a typo to make yeeloong part
work again.
2013-11-18 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/term/terminfo.c (grub_cmd_terminfo): Fix a typo to make -g
work again.
2013-11-18 Vladimir Serbinenko <phcoder@gmail.com>
* tests/util/grub-shell.in: For powerpc tests put the CD-ROM as primary
master since with some combinations of qemu and firmware only primary
IDE channel is available.
2013-11-18 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/tests/gfxterm_menu.c: Skip high-resolution tests on
low-memory platforms where we don't have enough memory for them.
* grub-core/tests/videotest_checksum.c: Likewise.
2013-11-18 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/tests/cmdline_cat_test.c: Don't reload unifont if it's
already loaded. This saves memory needed for tests,
2013-11-18 Vladimir Serbinenko <phcoder@gmail.com>
Fix handling of install lists.
2013-11-18 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/lib/sparc64/setjmp.S: Force spilling of current window.
2013-11-18 Vladimir Serbinenko <phcoder@gmail.com>
On i386-ieee1275 we run in paged mode. So we need to explicitly map
the devices before accessing them.
2013-11-18 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/lib/relocator.c (grub_mm_check_real): Accept const char *
as file argument.
2013-11-18 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/normal/cmdline.c (grub_cmdline_get): Plug memory leak.
2013-11-18 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/kern/file.c (grub_file_open): Free file->name on failure.
(grub_file_close): Free file->name.
2013-11-18 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/commands/verify.c (free_pk): Plug memory leak.
(grub_load_public_key): Likewise.
(grub_verify_signature_real): Likewise.
(grub_cmd_verify_signature): Likewise.
2013-11-18 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/commands/legacycfg.c (grub_legacy_check_md5_password): Plug
memory leak.
2013-11-18 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/lib/powerpc/setjmp.S (grub_setjmp): Save r31.
(grub_longjmp): Restore r31.
* include/grub/powerpc/setjmp.h (grub_jmp_buf): Reserve space for r31.
2013-11-18 Vladimir Serbinenko <phcoder@gmail.com>
* util/grub-mkrescue.c (make_image_fwdisk_abs): Insert all partmap
modules to be in line with make_image_abs.
2013-11-18 Vladimir Serbinenko <phcoder@gmail.com>
* include/grub/mips/setjmp.h (grub_jmp_buf): Fix buffer size.
setjmp.S uses 12 entries but buffer is declared with only 11 entries.
2013-11-17 Ian Campbell <ijc@hellion.org.uk>
* grub-core/disk/uboot/ubootdisk.c: Include SCSI disks.
2013-11-17 Vladimir Serbinenko <phcoder@gmail.com>
* tests/grub_func_test.in: Increase memory reservation as on EFI we need
to leave some memory to firmware.
2013-11-17 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/tests/cmdline_cat_test.c (cmdline_cat_test): Ignore errors
of loading gfxterm as gfxterm is embed in kernel on some platforms.
* grub-core/tests/gfxterm_menu.c (gfxterm_menu): Likewise.
Load gfxmenu.
2013-11-17 Vladimir Serbinenko <phcoder@gmail.com>
* tests/core_compress_test.in: Use full arguments as grub-mkimage-extra
now needs full arguments.
2013-11-17 Vladimir Serbinenko <phcoder@gmail.com>
* util/grub-mkrescue.c (main): Add trailing \n in
.disk_label.contentDetails to be in line with previous shell script.
2013-11-17 Vladimir Serbinenko <phcoder@gmail.com>
* util/grub-mkrescue.c (main): Use right source file for bootinfo.txt.
2013-11-17 Vladimir Serbinenko <phcoder@gmail.com>
* util/grub-install-common.c (grub_install_parse): Recognize
--compress=none like shell script did.
2013-11-17 Vladimir Serbinenko <phcoder@gmail.com>
* include/grub/misc.h: Replace check for __sparc64__ with one for
__sparc__ as __sparc64__ isn't actually defined.
2013-11-17 Vladimir Serbinenko <phcoder@gmail.com>
* tests/util/grub-shell.in: Use escc-ch-b on powerpc. This is missing
counterpart of fixing the naming of escc ports.
2013-11-17 Vladimir Serbinenko <phcoder@gmail.com>
* util/grub-install-common.c (platforms): Fix the order of entries and
remove useless field val.
2013-11-16 Vladimir Serbinenko <phcoder@gmail.com>
* util/grub-install.c: Add new option --no-bootsector to skip
installing of bootsector. Accept --grub-setup=/bin/true as
backwards-compatible synonym.
2013-11-16 Andrey Borzenkov <arvidjaar@gmail.com>
* util/grub-install.c (device_map_check_duplicates): Fix incorrect
order of qsort arguments (number of elements vs. element size).
2013-11-16 Vladimir Serbinenko <phcoder@gmail.com>
Rewrite grub-install, grub-mkrescue, grub-mkstandalone and grub-mknetdir
the function of these files exceeds what can be sanely handled in shell
in posix-comaptible way. Also writing it in C extends the functionality
to non-UNIX-like OS and minimal environments.
2013-11-16 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/kern/arm/cache.S: Don't switch back to ARM mode when
compiling to thumb2.
* grub-core/kern/arm/cache_armv7.S: Likewise.
* grub-core/lib/arm/setjmp.S: Likewise.
2013-11-16 Leif Lindholm <leif.lindholm@linaro.org>
* grub-core/kern/arm/uboot/startup.S: delete superflouous save of r8
in grub_uboot_syscall
2013-11-16 Vladimir Serbinenko <phcoder@gmail.com>
Decrease stack usage in lexer.
We have only 92K of stack and using over 4K per frame is wasteful
* grub-core/script/yylex.l (yyalloc), (yyfree), (yyrealloc): Declare
as macros so that compiler would remove useless structure on stack.
Better solution would be to fix flex not to put this structure on
the stack but flex is external program.
2013-11-16 Vladimir Serbinenko <phcoder@gmail.com>
Decrease stack usage in signature verification.
We have only 92K of stack and using over 4K per frame is wasteful
* grub-core/commands/verify.c (grub_load_public_key): Allocate on heap
rather than stack.
(grub_verify_signature_real): Likewise.
2013-11-16 Vladimir Serbinenko <phcoder@gmail.com>
Decrease stack usage in mdraid 0.9x.
We have only 92K of stack and using over 4K per frame is wasteful
* grub-core/disk/mdraid_linux.c (grub_mdraid_detect): Allocate on heap
rather than stack.
2013-11-16 Vladimir Serbinenko <phcoder@gmail.com>
Decrease stack usage in BtrFS.
We have only 92K of stack and using over 4K per frame is wasteful
* grub-core/fs/btrfs.c (grub_btrfs_lzo_decompress): Allocate on heap
rather than stack.
2013-11-16 Vladimir Serbinenko <phcoder@gmail.com>
Decrease stack usage in JFS.
We have only 92K of stack and using over 4K per frame is wasteful
* grub-core/fs/jfs.c (getblk): Allocate on heap rather than on
stack. Note: this function is recursive.
(grub_jfs_read_inode): Read only part we care about.
2013-11-16 Leif Lindholm <leif.lindholm@linaro.org>
* grub-core/kern/arm/uboot/startup.S: fix grub_uboot_syscall va_arg
handling
2013-11-16 Andrey Borzenkov <arvidjaar@gmail.com>
* configure.ac: Restore -nostdlib for libgcc symbols tests.
2013-11-16 Andrey Borzenkov <arvidjaar@gmail.com>
* docs/grub.texi (Environment): Document cmdpath.
2013-11-16 Andrey Borzenkov <arvidjaar@gmail.com>
* grub-core/kern/mips/arc/init.c (grub_machine_get_bootlocation):
Remove "unused" attribute from arguments, they are used.
2013-11-15 Colin Watson <cjwatson@debian.org>
* .gitignore: Only ignore grub-mk* at the top level.

View File

@ -394,8 +394,30 @@ bootcheck: $(BOOTCHECKS)
if COND_i386_coreboot
default_payload.elf: grub-mkstandalone grub-mkimage
pkgdatadir=. ./grub-mkstandalone --grub-mkimage=./grub-mkimage -O i386-coreboot -o $@ --modules='ahci ehci uhci ohci usb_keyboard usbms part_msdos xfs ext2 fat at_keyboard part_gpt usbserial_usbdebug cbfs' --install-modules='ls linux search configfile normal cbtime cbls memrw iorw minicmd lsmmap lspci halt reboot hexdump pcidump setpci lsacpi chain' --fonts= --themes= --locales= -d grub-core/
pkgdatadir=. ./grub-mkstandalone --grub-mkimage=./grub-mkimage -O i386-coreboot -o $@ --modules='ahci pata ehci uhci ohci usb_keyboard usbms part_msdos xfs ext2 fat at_keyboard part_gpt usbserial_usbdebug cbfs' --install-modules='ls linux search configfile normal cbtime cbls memrw iorw minicmd lsmmap lspci halt reboot hexdump pcidump regexp setpci lsacpi chain test' --fonts= --themes= --locales= -d grub-core/ /boot/grub/grub.cfg=$(srcdir)/coreboot.cfg
endif
windowsdir=$(top_builddir)/$(PACKAGE)-$(VERSION)-for-windows
windowsdir: $(PROGRAMS) $(starfield_DATA) $(platform_DATA)
test -d $(windowsdir) && rm -rf $(windowsdir) || true
test -d $(windowsdir) || mkdir $(windowsdir)
$(MAKE) -C po $(AM_MAKEFLAGS) windowsdir
$(MAKE) -C grub-core $(AM_MAKEFLAGS) windowsdir
test -d $(windowsdir)/themes || mkdir $(windowsdir)/themes
test -d $(windowsdir)/themes/starfield || mkdir $(windowsdir)/themes/starfield
for x in $(PROGRAMS); do \
$(STRIP) $$x -o $(windowsdir)/$$x; \
done
for x in $(pkgdata_DATA); do \
cp -fp $$x $(windowsdir)/$$x; \
done
for x in $(starfield_DATA); do \
cp -fp $$x $(windowsdir)/themes/starfield/$$(basename $$x); \
done
windowszip=$(top_builddir)/$(PACKAGE)-$(VERSION)-for-windows.zip
windowszip: windowsdir
test -f $(windowszip) && rm $(windowszip) || true
zip -r $(windowszip) $(windowsdir)
EXTRA_DIST += linguas.sh

View File

@ -171,6 +171,10 @@ program = {
common = util/resolve.c;
common = grub-core/kern/emu/argp_common.c;
common = grub-core/osdep/init.c;
common = grub-core/osdep/config.c;
extra_dist = grub-core/osdep/windows/config.c;
extra_dist = grub-core/osdep/unix/config.c;
common = util/config.c;
common = grub-core/kern/arm/dl_helper.c;
@ -326,6 +330,7 @@ program = {
installdir = sbin;
mansection = 8;
common = util/grub-probe.c;
common = util/probe.c;
common = grub-core/osdep/ofpath.c;
common = grub-core/kern/emu/argp_common.c;
common = grub-core/osdep/init.c;
@ -501,38 +506,165 @@ script = {
installdir = grubconf;
};
script = {
program = {
mansection = 1;
name = grub-mkrescue;
common = util/grub-install_header;
common = util/grub-mkrescue.in;
enable = noemu;
common = util/grub-mkrescue.c;
common = util/render-label.c;
common = util/glue-efi.c;
common = util/mkimage.c;
common = util/grub-install-common.c;
common = util/setup_bios.c;
common = util/setup_sparc.c;
common = grub-core/lib/reed_solomon.c;
common = grub-core/osdep/random.c;
common = grub-core/osdep/ofpath.c;
common = grub-core/osdep/platform.c;
common = grub-core/osdep/platform_unix.c;
common = grub-core/osdep/compress.c;
extra_dist = grub-core/osdep/unix/compress.c;
extra_dist = grub-core/osdep/basic/compress.c;
common = util/editenv.c;
common = grub-core/osdep/blocklist.c;
common = grub-core/osdep/config.c;
common = util/config.c;
common = grub-core/kern/emu/hostfs.c;
common = grub-core/disk/host.c;
common = grub-core/kern/arm/dl_helper.c;
common = util/resolve.c;
common = grub-core/kern/emu/argp_common.c;
common = grub-core/osdep/init.c;
ldadd = '$(LIBLZMA)';
ldadd = libgrubmods.a;
ldadd = libgrubgcry.a;
ldadd = libgrubkern.a;
ldadd = grub-core/gnulib/libgnu.a;
ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)';
condition = COND_HAVE_EXEC;
};
script = {
program = {
mansection = 1;
name = grub-mkstandalone;
common = util/grub-install_header;
common = util/grub-mkstandalone.in;
common = util/grub-mkstandalone.c;
common = util/render-label.c;
common = util/glue-efi.c;
common = util/mkimage.c;
common = util/grub-install-common.c;
common = util/setup_bios.c;
common = util/setup_sparc.c;
common = grub-core/lib/reed_solomon.c;
common = grub-core/osdep/random.c;
common = grub-core/osdep/ofpath.c;
common = grub-core/osdep/platform.c;
common = grub-core/osdep/platform_unix.c;
extra_dist = grub-core/osdep/linux/platform.c;
extra_dist = grub-core/osdep/basic/platform.c;
extra_dist = grub-core/osdep/basic/no_platform.c;
extra_dist = grub-core/osdep/unix/platform.c;
common = grub-core/osdep/compress.c;
common = util/editenv.c;
common = grub-core/osdep/blocklist.c;
common = grub-core/osdep/config.c;
common = util/config.c;
common = grub-core/kern/emu/hostfs.c;
common = grub-core/disk/host.c;
common = grub-core/kern/arm/dl_helper.c;
common = util/resolve.c;
common = grub-core/kern/emu/argp_common.c;
common = grub-core/osdep/init.c;
ldadd = '$(LIBLZMA)';
ldadd = libgrubmods.a;
ldadd = libgrubgcry.a;
ldadd = libgrubkern.a;
ldadd = grub-core/gnulib/libgnu.a;
ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)';
};
script = {
program = {
mansection = 8;
installdir = sbin;
name = grub-install;
common = util/grub-install_header;
common = util/grub-install.in;
common = util/grub-install.c;
common = util/probe.c;
common = util/mkimage.c;
common = util/grub-install-common.c;
common = util/setup_bios.c;
common = util/setup_sparc.c;
common = grub-core/lib/reed_solomon.c;
common = grub-core/osdep/random.c;
common = grub-core/osdep/ofpath.c;
common = grub-core/osdep/platform.c;
common = grub-core/osdep/platform_unix.c;
common = grub-core/osdep/compress.c;
common = util/editenv.c;
common = grub-core/osdep/blocklist.c;
common = grub-core/osdep/config.c;
common = util/config.c;
common = grub-core/kern/arm/dl_helper.c;
common = util/resolve.c;
enable = noemu;
common = grub-core/kern/emu/argp_common.c;
common = grub-core/osdep/init.c;
ldadd = '$(LIBLZMA)';
ldadd = libgrubmods.a;
ldadd = libgrubgcry.a;
ldadd = libgrubkern.a;
ldadd = grub-core/gnulib/libgnu.a;
ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)';
};
script = {
program = {
mansection = 1;
installdir = bin;
name = grub-mknetdir;
common = util/grub-install_header;
common = util/grub-mknetdir.in;
common = util/grub-mknetdir.c;
common = util/mkimage.c;
common = util/grub-install-common.c;
common = util/setup_bios.c;
common = util/setup_sparc.c;
common = grub-core/lib/reed_solomon.c;
common = grub-core/osdep/random.c;
common = grub-core/osdep/ofpath.c;
common = grub-core/osdep/platform.c;
common = grub-core/osdep/platform_unix.c;
common = grub-core/osdep/compress.c;
common = util/editenv.c;
common = grub-core/osdep/blocklist.c;
common = grub-core/osdep/config.c;
common = util/config.c;
common = grub-core/kern/arm/dl_helper.c;
common = util/resolve.c;
common = grub-core/kern/emu/argp_common.c;
common = grub-core/osdep/init.c;
ldadd = '$(LIBLZMA)';
ldadd = libgrubmods.a;
ldadd = libgrubgcry.a;
ldadd = libgrubkern.a;
ldadd = grub-core/gnulib/libgnu.a;
ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)';
};
script = {

View File

@ -75,14 +75,10 @@ if test "x$TARGET_CFLAGS" = x; then
TARGET_CFLAGS="$TARGET_CFLAGS -Os"
fi
BUILD_CPPFLAGS="$BUILD_CPPFLAGS -DLOCALEDIR=\\\"\$(localedir)\\\""
# Default HOST_CPPFLAGS
HOST_CPPFLAGS="$HOST_CPPFLAGS -Wall -W"
HOST_CPPFLAGS="$HOST_CPPFLAGS -I\$(top_builddir)/include"
HOST_CPPFLAGS="$HOST_CPPFLAGS -DGRUB_UTIL=1"
HOST_CPPFLAGS="$HOST_CPPFLAGS -DGRUB_LIBDIR=\\\"\$(pkglibdir)\\\""
HOST_CPPFLAGS="$HOST_CPPFLAGS -DLOCALEDIR=\\\"\$(localedir)\\\""
TARGET_CPPFLAGS="$TARGET_CPPFLAGS -Wall -W"
TARGET_CPPFLAGS="$TARGET_CPPFLAGS -I\$(top_srcdir)/include"
@ -192,6 +188,12 @@ case "$host_os" in
cygwin | windows* | mingw32*) host_kernel=windows ;;
esac
case "$host_os" in
cygwin | windows* | mingw32*) have_exec=n ;;
aros*) have_exec=n ;;
*) have_exec=y;;
esac
case "$platform" in
coreboot) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_COREBOOT=1" ;;
multiboot) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MULTIBOOT=1" ;;
@ -815,9 +817,9 @@ LIBS="$TARGET_LIBGCC"
grub_ASM_USCORE
if test "x$TARGET_APPLE_LINKER" = x0 ; then
if test x$grub_cv_asm_uscore = xyes; then
CFLAGS="$TARGET_CFLAGS -Wl,--defsym,_abort=_main"
CFLAGS="$TARGET_CFLAGS -nostdlib -Wl,--defsym,_abort=_main"
else
CFLAGS="$TARGET_CFLAGS -Wl,--defsym,abort=main"
CFLAGS="$TARGET_CFLAGS -nostdlib -Wl,--defsym,abort=main"
fi
fi
@ -1513,6 +1515,20 @@ AM_CONDITIONAL([COND_HAVE_CXX], [test x$HAVE_CXX = xyes])
AM_CONDITIONAL([COND_HAVE_ASM_USCORE], [test x$HAVE_ASM_USCORE = x1])
AM_CONDITIONAL([COND_CYGWIN], [test x$target_os = xcygwin])
AM_CONDITIONAL([COND_STARFIELD], [test "x$starfield_excuse" = x])
AM_CONDITIONAL([COND_HAVE_EXEC], [test "x$have_exec" = xy])
test "x$prefix" = xNONE && prefix="$ac_default_prefix"
test "x$exec_prefix" = xNONE && exec_prefix="${prefix}"
datarootdir="$(eval echo "$datarootdir")"
grub_libdir="$(eval echo "$libdir")"
grub_localedir="$(eval echo "$localedir")"
grub_datadir="$(eval echo "$datadir")"
grub_sysconfdir="$(eval echo "$sysconfdir")"
AC_DEFINE_UNQUOTED(LOCALEDIR, "$grub_localedir", [Locale dir])
AC_DEFINE_UNQUOTED(GRUB_LIBDIR, "$grub_libdir", [Library dir])
AC_DEFINE_UNQUOTED(GRUB_DATADIR, "$grub_datadir", [Data dir])
AC_DEFINE_UNQUOTED(GRUB_SYSCONFDIR, "$grub_sysconfdir", [Configuration dir])
# Output files.
cpudir="${target_cpu}"

4
debian/changelog vendored
View File

@ -1,4 +1,4 @@
grub2 (2.00+20131115-1) UNRELEASED; urgency=low
grub2 (2.00+20131119-1) UNRELEASED; urgency=low
* New upstream snapshot.
- Skip issuing cursor on/off sequences on Macs (closes: #683068).
@ -28,6 +28,8 @@ grub2 (2.00+20131115-1) UNRELEASED; urgency=low
* Move working directories around (build/<package> -> obj/<package>,
build/stamps -> debian/stamps) so that "debian/rules build" still works
after working directories have been created.
* Drop "grub-mkrescue --diet" option; never merged upstream and only
matters for floppies. Please let me know if you were using this.
-- Colin Watson <cjwatson@debian.org> Fri, 15 Nov 2013 10:18:57 +0000

View File

@ -2,24 +2,92 @@ Description: Read /etc/default/grub.d/*.cfg after /etc/default/grub
Author: Colin Watson <cjwatson@ubuntu.com>
Bug-Ubuntu: https://bugs.launchpad.net/bugs/901600
Forwarded: no
Last-Update: 2013-11-15
Last-Update: 2013-11-19
Index: b/util/grub-install.in
Index: b/grub-core/osdep/unix/config.c
===================================================================
--- a/util/grub-install.in
+++ b/util/grub-install.in
@@ -45,6 +45,11 @@
if test -f "${sysconfdir}/default/grub" ; then
. "${sysconfdir}/default/grub"
fi
+for x in "${sysconfdir}/default/grub.d"/*.cfg ; do
+ if [ -e "${x}" ]; then
+ . "${x}"
+ fi
+done
--- a/grub-core/osdep/unix/config.c
+++ b/grub-core/osdep/unix/config.c
@@ -61,28 +61,16 @@
return LOCALEDIR;
}
bootloader_id="$(echo "$GRUB_DISTRIBUTOR" | tr 'A-Z' 'a-z' | cut -d' ' -f1)"
if test -z "$bootloader_id"; then
-void
-grub_util_load_config (struct grub_util_config *cfg)
+static void
+grub_util_load_one_config (struct grub_util_config *cfg, const char *cfgfile)
{
pid_t pid;
const char *argv[4];
char *script, *ptr;
- const char *cfgfile, *iptr;
+ const char *iptr;
FILE *f = NULL;
int fd;
- const char *v;
- memset (cfg, 0, sizeof (*cfg));
-
- v = getenv ("GRUB_ENABLE_CRYPTODISK");
- if (v && v[0] == 'y' && v[1] == '\0')
- cfg->is_cryptodisk_enabled = 1;
-
- v = getenv ("GRUB_DISTRIBUTOR");
- if (v)
- cfg->grub_distributor = xstrdup (v);
-
- cfgfile = grub_util_get_config_filename ();
if (!grub_util_is_regular (cfgfile))
return;
@@ -137,3 +125,47 @@
grub_util_warn (_("cannot open config file `%s': %s"),
cfgfile, strerror (errno));
}
+
+void
+grub_util_load_config (struct grub_util_config *cfg)
+{
+ const char *cfgfile;
+ const char *v;
+ char *cfgdir;
+ grub_util_fd_dir_t d;
+
+ memset (cfg, 0, sizeof (*cfg));
+
+ v = getenv ("GRUB_ENABLE_CRYPTODISK");
+ if (v && v[0] == 'y' && v[1] == '\0')
+ cfg->is_cryptodisk_enabled = 1;
+
+ v = getenv ("GRUB_DISTRIBUTOR");
+ if (v)
+ cfg->grub_distributor = xstrdup (v);
+
+ cfgfile = grub_util_get_config_filename ();
+
+ grub_util_load_one_config (cfg, cfgfile);
+
+ cfgdir = xasprintf ("%s.d", cfgfile);
+ d = grub_util_fd_opendir (cfgdir);
+ if (d)
+ {
+ grub_util_fd_dirent_t de;
+
+ while ((de = grub_util_fd_readdir (d)))
+ {
+ const char *ext = strrchr (de->d_name, '.');
+ char *x;
+
+ if (!ext || strcmp (ext, ".cfg") != 0)
+ continue;
+
+ x = grub_util_path_concat (2, cfgdir, de->d_name);
+ grub_util_load_one_config (cfg, x);
+ free (x);
+ }
+ grub_util_fd_closedir (d);
+ }
+}
Index: b/util/grub-mkconfig.in
===================================================================
--- a/util/grub-mkconfig.in

View File

@ -5,13 +5,13 @@ Description: Add configure option to enable gfxpayload=keep dynamically
Author: Evan Broder <evan@ebroder.net>
Author: Colin Watson <cjwatson@ubuntu.com>
Forwarded: no
Last-Update: 2013-11-17
Last-Update: 2013-11-19
Index: b/configure.ac
===================================================================
--- a/configure.ac
+++ b/configure.ac
@@ -1374,6 +1374,17 @@
@@ -1376,6 +1376,17 @@
fi
AC_SUBST([QUICK_BOOT])
@ -33,7 +33,7 @@ Index: b/grub-core/Makefile.core.def
===================================================================
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -888,6 +888,16 @@
@@ -889,6 +889,16 @@
};
module = {

View File

@ -2,13 +2,13 @@ Description: Ignore functional test failures for now as they are broken
See: https://lists.gnu.org/archive/html/grub-devel/2013-11/msg00242.html
Author: Colin Watson <cjwatson@debian.org>
Forwarded: not-needed
Last-Update: 2013-11-18
Last-Update: 2013-11-19
Index: b/tests/grub_func_test.in
===================================================================
--- a/tests/grub_func_test.in
+++ b/tests/grub_func_test.in
@@ -8,6 +8,8 @@
@@ -16,6 +16,8 @@
if [ "$(echo "$out" | tail -n 1)" != "ALL TESTS PASSED" ]; then
echo "Functional test failure: $out"

View File

@ -1,20 +0,0 @@
Description: Look for grub-bios-setup in /usr/lib/grub/i386-pc/ as well
Author: Colin Watson <cjwatson@debian.org>
Bug-Debian: http://bugs.debian.org/705636
Forwarded: no
Last-Update: 2013-11-15
Index: b/util/grub-install.in
===================================================================
--- a/util/grub-install.in
+++ b/util/grub-install.in
@@ -321,6 +321,9 @@
if test "x$grub_setup" = x && [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-pc" ]; then
grub_setup="${sbindir}/@grub_bios_setup@"
+ if [ ! -e "$grub_setup" ]; then
+ grub_setup="${source_dir}/@grub_bios_setup@"
+ fi
fi
if test "x$grub_setup" = x && [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "sparc64-ieee1275" ]; then

View File

@ -5,29 +5,49 @@ Description: Fall back to i386-pc if booted using EFI but -efi is missing
better than returning a confusing error.
Author: Colin Watson <cjwatson@ubuntu.com>
Forwarded: no
Last-Update: 2013-11-15
Last-Update: 2013-11-19
Index: b/util/grub-install.in
Index: b/grub-core/osdep/linux/platform.c
===================================================================
--- a/util/grub-install.in
+++ b/util/grub-install.in
@@ -248,7 +248,8 @@
linux*)
modprobe -q efivars 2>/dev/null || true ;;
esac
- if [ -d /sys/firmware/efi ]; then
+ if [ -d /sys/firmware/efi ] && \
+ [ -d "${libdir}/@PACKAGE@/x86_64-efi" ]; then
target="x86_64-efi"
else
target=i386-pc
@@ -264,7 +265,8 @@
linux*)
modprobe -q efivars 2>/dev/null || true ;;
esac
- if [ -d /sys/firmware/efi ]; then
+ if [ -d /sys/firmware/efi ] && \
+ [ -d "${libdir}/@PACKAGE@/i386-efi" ]; then
target="i386-efi"
elif [ -e /proc/device-tree ]; then
target=i386-pc
--- a/grub-core/osdep/linux/platform.c
+++ b/grub-core/osdep/linux/platform.c
@@ -19,9 +19,11 @@
#include <config.h>
#include <grub/util/install.h>
+#include <grub/emu/config.h>
#include <grub/emu/exec.h>
#include <sys/types.h>
#include <dirent.h>
+#include <stdlib.h>
#include <string.h>
#include <sys/utsname.h>
@@ -73,12 +75,24 @@
"efivars", NULL });
if (is_not_empty_directory ("/sys/firmware/efi"))
{
+ const char *pkglibdir = grub_util_get_pkglibdir ();
+ const char *platform;
+ char *pd;
+ int found;
+
if (is_64_kernel ())
- return "x86_64-efi";
+ platform = "x86_64-efi";
else
- return "i386-efi";
+ platform = "i386-efi";
+
+ pd = grub_util_path_concat (2, pkglibdir, platform);
+ found = grub_util_is_directory (pd);
+ free (pd);
+ if (found)
+ return platform;
}
- else if (is_not_empty_directory ("/proc/device-tree"))
+
+ if (is_not_empty_directory ("/proc/device-tree"))
return "i386-ieee1275";
else
return "i386-pc";

View File

@ -5,20 +5,18 @@ Description: Cope with Kubuntu setting GRUB_DISTRIBUTOR
Author: Colin Watson <cjwatson@ubuntu.com>
Bug-Ubuntu: https://bugs.launchpad.net/bugs/1242417
Forwarded: not-needed
Last-Update: 2013-11-15
Last-Update: 2013-11-19
Index: b/util/grub-install.in
Index: b/util/grub-install.c
===================================================================
--- a/util/grub-install.in
+++ b/util/grub-install.in
@@ -433,6 +433,10 @@
# not collide with other vendors. To minimise collisions, we use the
# name of our distributor if possible.
efi_distributor="$bootloader_id"
+ case $efi_distributor in
+ kubuntu)
+ efi_distributor=ubuntu ;;
+ esac
# It is convenient for each architecture to have a different
# efi_file, so that different versions can be installed in parallel.
case "$grub_modinfo_target_cpu" in
--- a/util/grub-install.c
+++ b/util/grub-install.c
@@ -932,6 +932,8 @@
*/
char *t;
efi_distributor = bootloader_id;
+ if (strcmp (efi_distributor, "kubuntu") == 0)
+ efi_distributor = "ubuntu";
switch (platform)
{
case GRUB_INSTALL_PLATFORM_I386_EFI:

View File

@ -2,27 +2,102 @@ Description: Prefer translations from Ubuntu language packs if available
Author: Colin Watson <cjwatson@ubuntu.com>
Bug-Ubuntu: https://bugs.launchpad.net/bugs/537998
Forwarded: not-needed
Last-Update: 2013-11-15
Last-Update: 2013-11-19
Index: b/util/grub-install_header
Index: b/util/grub-install-common.c
===================================================================
--- a/util/grub-install_header
+++ b/util/grub-install_header
@@ -119,7 +119,7 @@
grub_compress_file "$file" "${grub_install_files_target_directory}"/locale/"$(basename "$file")"
fi
done
- for dir in "${localedir}"/*; do
+ for dir in "${localedir}"/* "${localedir}-langpack"/*; do
if test -f "$dir/LC_MESSAGES/@PACKAGE@.mo" && ! test -f "${grub_install_files_target_directory}"/locale/"${dir##*/}.mo"; then
grub_compress_file "$dir/LC_MESSAGES/@PACKAGE@.mo" "${grub_install_files_target_directory}"/locale/"${dir##*/}.mo"
fi
@@ -128,6 +128,8 @@
for locale in $install_locales; do
if test -f "${grub_install_files_source_directory}"/po/$locale.mo; then
grub_compress_file "${grub_install_files_source_directory}"/po/locale.mo "${grub_install_files_target_directory}"/locale/$locale.mo
+ elif test -f "${localedir}-langpack/$locale/LC_MESSAGES/@PACKAGE@.mo"; then
+ grub_compress_file "${localedir}-langpack/$locale/LC_MESSAGES/@PACKAGE@.mo" "${grub_install_files_target_directory}"/locale/$locale.mo
elif test -f "${localedir}/$locale/LC_MESSAGES/@PACKAGE@.mo"; then
grub_compress_file "${localedir}/$locale/LC_MESSAGES/@PACKAGE@.mo" "${grub_install_files_target_directory}"/locale/$locale.mo
fi
--- a/util/grub-install-common.c
+++ b/util/grub-install-common.c
@@ -552,17 +552,24 @@
}
static void
-copy_locales (const char *dstd)
+copy_locales (const char *dstd, int langpack)
{
grub_util_fd_dir_t d;
grub_util_fd_dirent_t de;
const char *locale_dir = grub_util_get_localedir ();
+ char *dir;
- d = grub_util_fd_opendir (LOCALEDIR);
+ if (langpack)
+ dir = xasprintf ("%s-langpack", locale_dir);
+ else
+ dir = xstrdup (locale_dir);
+
+ d = grub_util_fd_opendir (dir);
if (!d)
{
grub_util_warn (_("cannot open directory `%s': %s"),
- locale_dir, grub_util_fd_strerror ());
+ dir, grub_util_fd_strerror ());
+ free (dir);
return;
}
@@ -574,7 +581,7 @@
continue;
if (strcmp (de->d_name, "..") == 0)
continue;
- srcf = grub_util_path_concat_ext (4, locale_dir, de->d_name,
+ srcf = grub_util_path_concat_ext (4, dir, de->d_name,
"LC_MESSAGES", PACKAGE, ".mo");
dstf = grub_util_path_concat_ext (2, dstd, de->d_name, ".mo");
grub_install_compress_file (srcf, dstf, 0);
@@ -582,6 +589,7 @@
free (dstf);
}
grub_util_fd_closedir (d);
+ free (dir);
}
static struct
@@ -701,11 +709,15 @@
{
char *srcd = grub_util_path_concat (2, src, "po");
copy_by_ext (srcd, dst_locale, ".mo", 0);
- copy_locales (dst_locale);
+ copy_locales (dst_locale, 0);
+ copy_locales (dst_locale, 1);
free (srcd);
}
else
{
+ const char *locale_dir = grub_util_get_localedir ();
+ char *locale_langpack_dir = xasprintf ("%s-langpack", locale_dir);
+
for (i = 0; i < install_locales.n_entries; i++)
{
char *srcf = grub_util_path_concat_ext (3, src,
@@ -723,7 +735,20 @@
}
free (srcf);
srcf = grub_util_path_concat_ext (4,
- LOCALEDIR,
+ locale_langpack_dir,
+ install_locales.entries[i],
+ "LC_MESSAGES",
+ PACKAGE,
+ ".mo");
+ if (grub_install_compress_file (srcf, dstf, 0))
+ {
+ free (srcf);
+ free (dstf);
+ continue;
+ }
+ free (srcf);
+ srcf = grub_util_path_concat_ext (4,
+ locale_dir,
install_locales.entries[i],
"LC_MESSAGES",
PACKAGE,
@@ -737,6 +762,8 @@
grub_util_error (_("cannot find locale `%s'"),
install_locales.entries[i]);
}
+
+ free (locale_langpack_dir);
}
if (install_themes.is_default)

View File

@ -3,163 +3,240 @@ Author: Colin Watson <cjwatson@ubuntu.com>
Author: Stéphane Graber <stgraber@ubuntu.com>
Author: Steve Langasek <steve.langasek@ubuntu.com>
Forwarded: no
Last-Update: 2013-11-15
Last-Update: 2013-11-19
Index: b/util/grub-install.in
Index: b/util/grub-install.c
===================================================================
--- a/util/grub-install.in
+++ b/util/grub-install.in
@@ -40,6 +40,7 @@
--- a/util/grub-install.c
+++ b/util/grub-install.c
@@ -69,6 +69,7 @@
static FILE * load_cfg_f = NULL;
static char *load_cfg;
static int install_bootsector = 1;
+static int uefi_secure_boot = 1;
removable=no
efi_quiet=-q
+uefi_secure_boot=yes
enum
{
@@ -94,7 +95,9 @@
OPTION_DEBUG_IMAGE,
OPTION_NO_FLOPPY,
OPTION_DISK_MODULE,
- OPTION_NO_BOOTSECTOR
+ OPTION_NO_BOOTSECTOR,
+ OPTION_UEFI_SECURE_BOOT,
+ OPTION_NO_UEFI_SECURE_BOOT
};
# Get GRUB_DISTRIBUTOR.
if test -f "${sysconfdir}/default/grub" ; then
@@ -91,6 +92,8 @@
print_option_help "--removable" "$(gettext "the installation device is removable. This option is only available on EFI.")"
print_option_help "--bootloader-id=$(gettext "ID")" "$(gettext "the ID of bootloader. This option is only available on EFI.")"
print_option_help "--efi-directory=$(gettext "DIR")" "$(gettext "use DIR as the EFI System Partition root.")"
+ print_option_help "--uefi-secure-boot" "$(gettext "install an image usable with UEFI Secure Boot. This option is only available on EFI and if the grub-efi-amd64-signed package is installed.")"
+ print_option_help "--no-uefi-secure-boot" "$(gettext "do not install an image usable with UEFI Secure Boot, even if the system was currently started using it. This option is only available on EFI.")"
echo
gettext "INSTALL_DEVICE must be system device filename.";echo
echo
@@ -214,6 +217,11 @@
-f | --force)
setup_force="--force" ;;
static int fs_probe = 1;
@@ -190,6 +193,14 @@
bootloader_id = xstrdup (arg);
return 0;
+ --uefi-secure-boot)
+ uefi_secure_boot=yes ;;
+ --no-uefi-secure-boot)
+ uefi_secure_boot=no ;;
+ case OPTION_UEFI_SECURE_BOOT:
+ uefi_secure_boot = 1;
+ return 0;
+
-*)
gettext_printf "Unrecognized option \`%s'\n" "$option" 1>&2
usage
@@ -422,43 +430,34 @@
# not collide with other vendors. To minimise collisions, we use the
# name of our distributor if possible.
efi_distributor="$bootloader_id"
+ # It is convenient for each architecture to have a different
+ # efi_file, so that different versions can be installed in parallel.
+ case "$grub_modinfo_target_cpu" in
+ i386)
+ efi_suffix=ia32 ;;
+ x86_64)
+ efi_suffix=x64 ;;
+ # GRUB does not yet support these architectures, but they're defined
+ # by the specification so we include them here to ease future
+ # expansion.
+ ia64)
+ efi_suffix=ia64 ;;
+ arm)
+ efi_suffix=arm ;;
+ *)
+ efi_suffix= ;;
+ esac
if test $removable = yes; then
# The specification makes stricter requirements of removable
# devices, in order that only one image can be automatically loaded
# from them. The image must always reside under /EFI/BOOT, and it
# must have a specific file name depending on the architecture.
efi_distributor=BOOT
- case "$grub_modinfo_target_cpu" in
- i386)
- efi_file=BOOTIA32.EFI ;;
- x86_64)
- efi_file=BOOTX64.EFI ;;
- # GRUB does not yet support these architectures, but they're defined
- # by the specification so we include them here to ease future
- # expansion.
- ia64)
- efi_file=BOOTIA64.EFI ;;
- arm)
- efi_file=BOOTARM.EFI ;;
- esac
+ efi_file="BOOT$(printf %s "$efi_suffix" | tr a-z A-Z).EFI"
else
# It is convenient for each architecture to have a different
# efi_file, so that different versions can be installed in parallel.
- case "$grub_modinfo_target_cpu" in
- i386)
- efi_file=grubia32.efi ;;
- x86_64)
- efi_file=grubx64.efi ;;
- # GRUB does not yet support these architectures, but they're defined
- # by the specification so we include them here to ease future
- # expansion.
- ia64)
- efi_file=grubia64.efi ;;
- arm)
- efi_file=grubarm.efi ;;
- *)
- efi_file=grub.efi ;;
- esac
+ efi_file="grub$efi_suffix.efi"
fi
efidir="$efidir/EFI/$efi_distributor"
mkdir -p "$efidir" || exit 1
@@ -574,7 +573,15 @@
config_opt_file="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/load.cfg"
fi
-if [ "x${devabstraction_module}" = "x" ] ; then
+if [ x"$grub_modinfo_platform" = xefi ]; then
+ if [ $removable = yes ]; then
+ efi_signed="${source_dir}-signed/gcd$efi_suffix.efi.signed"
+ else
+ efi_signed="${source_dir}-signed/grub$efi_suffix.efi.signed"
+ fi
+fi
+ case OPTION_NO_UEFI_SECURE_BOOT:
+ uefi_secure_boot = 0;
+ return 0;
+
+if [ "x${devabstraction_module}" = "x" ] || ([ x"$grub_modinfo_platform" = xefi ] && [ "$uefi_secure_boot" = yes ] && [ -e "$efi_signed" ]); then
if [ x"${install_device}" != x ]; then
if echo "${install_device}" | grep -qx "(.*)" ; then
install_drive="${install_device}"
@@ -593,7 +600,7 @@
install_drive="$grub_drive"
fi
case ARGP_KEY_ARG:
if (install_device)
grub_util_error ("%s", _("More than one install device?"));
@@ -250,6 +261,14 @@
N_("the ID of bootloader. This option is only available on EFI."), 2},
{"efi-directory", OPTION_EFI_DIRECTORY, N_("DIR"), 0,
N_("use DIR as the EFI System Partition root."), 2},
+ {"uefi-secure-boot", OPTION_UEFI_SECURE_BOOT, 0, 0,
+ N_("install an image usable with UEFI Secure Boot. "
+ "This option is only available on EFI and if the grub-efi-amd64-signed "
+ "package is installed."), 2},
+ {"no-uefi-secure-boot", OPTION_NO_UEFI_SECURE_BOOT, 0, 0,
+ N_("do not install an image usable with UEFI Secure Boot, even if the "
+ "system was currently started using it. "
+ "This option is only available on EFI."), 2},
{0, 0, 0, 0, 0, 0}
};
- if ([ "x$disk_module" != x ] && [ "x$disk_module" != xbiosdisk ]) || [ "x${grub_drive}" != "x${install_drive}" ] || ([ "x$grub_modinfo_platform" != xefi ] && [ "x$grub_modinfo_platform" != xpc ] && [ x"${grub_modinfo_platform}" != x"ieee1275" ]); then
+ if ([ "x$disk_module" != x ] && [ "x$disk_module" != xbiosdisk ]) || [ "x${grub_drive}" != "x${install_drive}" ] || ([ "x$grub_modinfo_platform" != xefi ] && [ "x$grub_modinfo_platform" != xpc ] && [ x"${grub_modinfo_platform}" != x"ieee1275" ]) || ([ "x$grub_modinfo_platform" = xefi ] && [ "$uefi_secure_boot" = yes ]); then
# generic method (used on coreboot and ata mod)
uuid=
if [ x"$force_file_id" != xy ]; then
@@ -775,10 +782,31 @@
gettext "You will have to set \`SystemPartition' and \`OSLoader' manually." 1>&2
echo 1>&2
elif [ x"$grub_modinfo_platform" = xefi ]; then
- cp "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" "${efidir}/${efi_file}"
- # For old macs. Suggested by Peter Jones.
- if [ x$grub_modinfo_target_cpu = xi386 ]; then
- cp "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" "${efidir}/boot.efi"
+ if [ "$uefi_secure_boot" = yes ] && [ -e "$efi_signed" ]; then
+ shim_signed=/usr/lib/shim/shim.efi.signed
+ if [ -e "$shim_signed" ]; then
+ if [ "$removable" != yes ]; then
+ efi_file="shim$efi_suffix.efi"
+ fi
+ cp "$shim_signed" "${efidir}/${efi_file}"
+ cp "$efi_signed" "${efidir}/grub$efi_suffix.efi"
+ # Not critical, so not an error if it's not present (as it won't
+ # be for older releases); but if we have it, make sure it's
+ # installed.
+ if [ -e /usr/lib/shim/MokManager.efi.signed ]; then
+ cp /usr/lib/shim/MokManager.efi.signed "${efidir}/MokManager.efi"
+ fi
@@ -683,7 +702,8 @@
{
int is_efi = 0;
const char *efi_distributor = NULL;
- const char *efi_file = NULL;
+ const char *efi_suffix = NULL, *efi_suffix_upper = NULL;
+ char *efi_file = NULL;
char **grub_devices;
grub_fs_t grub_fs;
grub_device_t grub_dev = NULL;
@@ -912,6 +932,27 @@
*/
char *t;
efi_distributor = bootloader_id;
+ switch (platform)
+ {
+ case GRUB_INSTALL_PLATFORM_I386_EFI:
+ efi_suffix = "ia32";
+ efi_suffix_upper = "IA32";
+ break;
+ case GRUB_INSTALL_PLATFORM_X86_64_EFI:
+ efi_suffix = "x64";
+ efi_suffix_upper = "X64";
+ break;
+ case GRUB_INSTALL_PLATFORM_IA64_EFI:
+ efi_suffix = "ia64";
+ efi_suffix_upper = "IA64";
+ break;
+ case GRUB_INSTALL_PLATFORM_ARM_EFI:
+ efi_suffix = "arm";
+ efi_suffix_upper = "ARM";
+ break;
+ default:
+ break;
+ }
if (removable)
{
/* The specification makes stricter requirements of removable
@@ -920,48 +961,16 @@
must have a specific file name depending on the architecture.
*/
efi_distributor = "BOOT";
- switch (platform)
- {
- case GRUB_INSTALL_PLATFORM_I386_EFI:
- efi_file = "BOOTIA32.EFI";
- break;
- case GRUB_INSTALL_PLATFORM_X86_64_EFI:
- efi_file = "BOOTX64.EFI";
- break;
- case GRUB_INSTALL_PLATFORM_IA64_EFI:
- efi_file = "BOOTIA64.EFI";
- break;
- case GRUB_INSTALL_PLATFORM_ARM_EFI:
- efi_file = "BOOTARM.EFI";
- break;
- default:
- grub_util_error ("%s", _("You've found a bug"));
- break;
- }
+ if (!efi_suffix)
+ grub_util_error ("%s", _("You've found a bug"));
+ efi_file = xasprintf ("BOOT%s.EFI", efi_suffix_upper);
}
else
{
/* It is convenient for each architecture to have a different
efi_file, so that different versions can be installed in parallel.
*/
- switch (platform)
- {
- case GRUB_INSTALL_PLATFORM_I386_EFI:
- efi_file = "grubia32.efi";
- break;
- case GRUB_INSTALL_PLATFORM_X86_64_EFI:
- efi_file = "grubx64.efi";
- break;
- case GRUB_INSTALL_PLATFORM_IA64_EFI:
- efi_file = "grubia64.efi";
- break;
- case GRUB_INSTALL_PLATFORM_ARM_EFI:
- efi_file = "grubarm.efi";
- break;
- default:
- efi_file = "grub.efi";
- break;
- }
+ efi_file = xasprintf ("grub%s.efi", efi_suffix);
}
t = grub_util_path_concat (3, efidir, "EFI", efi_distributor);
free (efidir);
@@ -1091,6 +1100,31 @@
}
}
+ char *efi_signed = NULL;
+ switch (platform)
+ {
+ case GRUB_INSTALL_PLATFORM_I386_EFI:
+ case GRUB_INSTALL_PLATFORM_X86_64_EFI:
+ case GRUB_INSTALL_PLATFORM_ARM_EFI:
+ case GRUB_INSTALL_PLATFORM_IA64_EFI:
+ {
+ char *dir = xasprintf ("%s-signed", grub_install_source_directory);
+ char *signed_image;
+ if (removable)
+ signed_image = xasprintf ("gcd%s.efi.signed", efi_suffix);
+ else
+ cp "$efi_signed" "${efidir}/${efi_file}"
+ fi
+ cp "${config_opt_file}" "${efidir}/grub.cfg"
+ echo 'configfile $prefix/grub.cfg' >> "${efidir}/grub.cfg"
+ else
+ cp "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" "${efidir}/${efi_file}"
+ # For old macs. Suggested by Peter Jones.
+ if [ x$grub_modinfo_target_cpu = xi386 ]; then
+ cp "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" "${efidir}/boot.efi"
+ fi
fi
# Try to make this image bootable using the EFI Boot Manager, if available.
+ signed_image = xasprintf ("grub%s.efi.signed", efi_suffix);
+ efi_signed = grub_util_path_concat (2, dir, signed_image);
+ break;
+ }
+
+ default:
+ break;
+ }
+
+ if (!efi_signed || !grub_util_is_regular (efi_signed))
+ uefi_secure_boot = 0;
+
if (!have_abstractions)
{
if ((disk_module && grub_strcmp (disk_module, "biosdisk") != 0)
@@ -1098,7 +1132,8 @@
|| (!install_drive
&& platform != GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275)
|| (install_drive && !is_same_disk (grub_drives[0], install_drive))
- || !have_bootdev (platform))
+ || !have_bootdev (platform)
+ || uefi_secure_boot)
{
char *uuid = NULL;
/* generic method (used on coreboot and ata mod). */
@@ -1520,7 +1555,47 @@
case GRUB_INSTALL_PLATFORM_IA64_EFI:
{
char *dst = grub_util_path_concat (2, efidir, efi_file);
- grub_install_copy_file (imgfile, dst, 1);
+ if (uefi_secure_boot)
+ {
+ const char *shim_signed = "/usr/lib/shim/shim.efi.signed";
+ char *config_dst;
+ FILE *config_dst_f;
+
+ if (grub_util_is_regular (shim_signed))
+ {
+ char *chained_base, *chained_dst, *mok_signed;
+ if (!removable)
+ {
+ free (efi_file);
+ efi_file = xasprintf ("shim%s.efi", efi_suffix);
+ }
+ grub_install_copy_file (shim_signed, dst, 1);
+ chained_base = xasprintf ("grub%s.efi", efi_suffix);
+ chained_dst = grub_util_path_concat (2, efidir, chained_base);
+ grub_install_copy_file (efi_signed, chained_dst, 1);
+ /* Not critical, so not an error if it's not present (as it
+ won't be for older releases); but if we have it, make
+ sure it's installed. */
+ mok_signed = grub_util_path_concat (2, efidir,
+ "MokManager.efi");
+ grub_install_copy_file ("/usr/lib/shim/MokManager.efi.signed",
+ mok_signed, 0);
+ free (mok_signed);
+ free (chained_dst);
+ free (chained_base);
+ }
+ else
+ grub_install_copy_file (efi_signed, dst, 1);
+
+ config_dst = grub_util_path_concat (2, efidir, "grub.cfg");
+ grub_install_copy_file (load_cfg, config_dst, 1);
+ config_dst_f = grub_util_fopen (config_dst, "ab");
+ fprintf (config_dst_f, "configfile $prefix/grub.cfg\n");
+ fclose (config_dst_f);
+ free (config_dst);
+ }
+ else
+ grub_install_copy_file (imgfile, dst, 1);
free (dst);
}
if (!removable)

View File

@ -2,23 +2,37 @@ Description: If GRUB Legacy is still around, tell packaging to ignore it
Author: Colin Watson <cjwatson@debian.org>
Bug-Debian: http://bugs.debian.org/586143
Forwarded: not-needed
Last-Update: 2013-11-15
Last-Update: 2013-11-19
Index: b/util/grub-install.in
Index: b/util/grub-install.c
===================================================================
--- a/util/grub-install.in
+++ b/util/grub-install.in
@@ -822,6 +822,13 @@
echo 1>&2
fi
--- a/util/grub-install.c
+++ b/util/grub-install.c
@@ -41,6 +41,7 @@
#include <grub/gpt_partition.h>
#include <grub/emu/config.h>
#include <grub/util/ofpath.h>
+#include <grub/emu/hostfile.h>
+# If vestiges of GRUB Legacy still exist, tell the Debian packaging that
+# they can ignore them.
+if test -z "$rootdir" && \
+ test -e /boot/grub/stage2 && test -e /boot/grub/menu.lst; then
+ touch /boot/grub/grub2-installed
+fi
#include <string.h>
@@ -1414,6 +1415,19 @@
grub_util_bios_setup (platdir, "boot.img", "core.img",
install_drive, force,
fs_probe, allow_floppy);
+
gettext "Installation finished. No error reported." 1>&2
echo 1>&2
+ /* If vestiges of GRUB Legacy still exist, tell the Debian packaging
+ that they can ignore them. */
+ if (!rootdir && grub_util_is_regular ("/boot/grub/stage2") &&
+ grub_util_is_regular ("/boot/grub/menu.lst"))
+ {
+ grub_util_fd_t fd;
+
+ fd = grub_util_fd_open ("/boot/grub/grub2-installed",
+ GRUB_UTIL_FD_O_WRONLY);
+ grub_util_fd_close (fd);
+ }
+
break;
}
case GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275:

View File

@ -2,13 +2,13 @@ Description: Add "linuxefi" loader which avoids ExitBootServices
Author: Matthew Garrett <mjg@redhat.com>
Origin: vendor, http://pkgs.fedoraproject.org/cgit/grub2.git/tree/grub2-linuxefi.patch
Forwarded: no
Last-Update: 2013-11-14
Last-Update: 2013-11-19
Index: b/grub-core/Makefile.core.def
===================================================================
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -1681,6 +1681,14 @@
@@ -1682,6 +1682,14 @@
};
module = {

View File

@ -1,13 +1,13 @@
Description: Only build linuxefi on amd64
Author: Colin Watson <cjwatson@ubuntu.com>
Forwarded: no
Last-Update: 2013-11-14
Last-Update: 2013-11-19
Index: b/grub-core/Makefile.core.def
===================================================================
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -1684,7 +1684,6 @@
@@ -1685,7 +1685,6 @@
name = linuxefi;
efi = loader/i386/efi/linux.c;
efi = lib/cmdline.c;

View File

@ -25,7 +25,7 @@ Author: Colin Watson <cjwatson@ubuntu.com>
Bug-Ubuntu: https://bugs.launchpad.net/bugs/386922
Bug-Ubuntu: https://bugs.launchpad.net/bugs/861048
Forwarded: (partial) http://lists.gnu.org/archive/html/grub-devel/2009-09/msg00056.html
Last-Update: 2013-11-17
Last-Update: 2013-11-19
Index: b/config.h.in
===================================================================
@ -44,7 +44,7 @@ Index: b/configure.ac
===================================================================
--- a/configure.ac
+++ b/configure.ac
@@ -1352,6 +1352,17 @@
@@ -1354,6 +1354,17 @@
fi
AC_SUBST([UBUNTU_RECOVERY])
@ -62,7 +62,7 @@ Index: b/configure.ac
LIBS=""
AC_SUBST([FONT_SOURCE])
@@ -1585,5 +1596,10 @@
@@ -1601,5 +1612,10 @@
else
echo "With liblzma from $LIBLZMA (support for XZ-compressed mips images)"
fi

View File

@ -6,13 +6,13 @@ Description: "single" -> "recovery" when friendly-recovery is installed
Author: Colin Watson <cjwatson@ubuntu.com>
Author: Stéphane Graber <stgraber@ubuntu.com>
Forwarded: no
Last-Update: 2013-11-15
Last-Update: 2013-11-19
Index: b/configure.ac
===================================================================
--- a/configure.ac
+++ b/configure.ac
@@ -1341,6 +1341,17 @@
@@ -1343,6 +1343,17 @@
AC_SUBST([LIBZFS])
AC_SUBST([LIBNVPAIR])

View File

@ -1,54 +0,0 @@
Description: Allow reducing size of xorriso-created rescue images
This lets us create smaller images that will fit on floppy disks. It has
been approved by the upstream maintainer but has not yet been applied.
Author: Thomas Schmitt <scdbackup@gmx.net>
Origin: other, http://lists.gnu.org/archive/html/grub-devel/2010-05/msg00100.html
Forwarded: yes
Last-Update: 2013-11-15
Index: b/util/grub-mkrescue.in
===================================================================
--- a/util/grub-mkrescue.in
+++ b/util/grub-mkrescue.in
@@ -43,6 +43,7 @@
product_version="${PACKAGE_VERSION}"
xorriso=xorriso
+diet=no
# Usage: usage
# Print the usage.
@@ -67,6 +68,7 @@
print_option_help "--product-version=$(gettext "STRING")" "$(gettext "use STRING as product version")"
print_option_help "--sparc-boot" "$(gettext "enable sparc boot. Disables HFS+, APM, ARCS and boot as disk image for i386-pc")"
print_option_help "--arcs-boot" "$(gettext "enable ARCS (big-endian mips machines, mostly SGI) boot. Disables HFS+, APM, sparc64 and boot as disk image for i386-pc")"
+ print_option_help "--diet" "$(gettext "apply size reducing measures [optional]")"
echo
gettext_printf "%s generates a bootable rescue image with specified source files, source directories, or mkisofs options listed by the output of \`%s'\n" "xorriso -as mkisofs -help" "$self" | grub_fmt
echo
@@ -158,6 +160,9 @@
--xorriso=*)
xorriso=`echo "${option}" | sed 's/--xorriso=//'` ;;
+ --diet)
+ diet=yes ;;
+
*)
source="${source} ${option} $@"; break ;;
esac
@@ -485,7 +490,14 @@
fi
# build iso image
-"${xorriso}" -as mkisofs -graft-points ${grub_mkisofs_arguments} --protective-msdos-label -o "${output_image}" -r "${iso9660_dir}" --sort-weight 0 / --sort-weight 1 /boot ${source}
+if [ "${diet}" = yes ]; then
+ if [ -e "${output_image}" ]; then
+ rm "${output_image}" || exit 1
+ fi
+ "${xorriso}" -report_about HINT -as mkisofs -graft-points -no-pad ${grub_mkisofs_arguments} --protective-msdos-label -r "${iso9660_dir}" --sort-weight 0 / --sort-weight 1 /boot ${source} | cat >"${output_image}"
+else
+ "${xorriso}" -report_about HINT -as mkisofs -graft-points ${grub_mkisofs_arguments} --protective-msdos-label -o "${output_image}" -r "${iso9660_dir}" --sort-weight 0 / --sort-weight 1 /boot ${source}
+fi
rm -rf "${iso9660_dir}"
rm -f "${sysarea_img}"

View File

@ -1,22 +1,30 @@
Description: Build part_msdos and vfat into EFI boot images
Author: Mario Limonciello <Mario_Limonciello@dell.com>
Author: Colin Watson <cjwatson@ubuntu.com>
Bug-Ubuntu: https://bugs.launchpad.net/bugs/677758
Forwarded: http://lists.gnu.org/archive/html/grub-devel/2011-01/msg00028.html
Last-Update: 2013-11-15
Last-Update: 2013-11-19
Index: b/util/grub-mkrescue.in
Index: b/util/grub-mkrescue.c
===================================================================
--- a/util/grub-mkrescue.in
+++ b/util/grub-mkrescue.in
@@ -375,9 +375,9 @@
# build bootia64.efi
make_image_fwdisk "${ia64_dir}" ia64-efi "${efi_dir}"/efi/boot/bootia64.efi ""
# build bootx64.efi
- make_image_fwdisk "${efi64_dir}" x86_64-efi "${efi_dir}"/efi/boot/bootx64.efi ""
+ make_image_fwdisk "${efi64_dir}" x86_64-efi "${efi_dir}"/efi/boot/bootx64.efi "part_msdos fat"
# build bootia32.efi
- make_image_fwdisk "${efi32_dir}" i386-efi "${efi_dir}"/efi/boot/bootia32.efi ""
+ make_image_fwdisk "${efi32_dir}" i386-efi "${efi_dir}"/efi/boot/bootia32.efi "part_msdos fat"
if [ -e "${efi_dir}"/efi/boot/bootia32.efi ]; then
# For old macs. Suggested by Peter Jones.
cp "${efi_dir}"/efi/boot/bootia32.efi "${efi_dir}"/efi/boot/boot.efi
--- a/util/grub-mkrescue.c
+++ b/util/grub-mkrescue.c
@@ -634,12 +634,18 @@
make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_IA64_EFI, "ia64-efi", imgname);
free (imgname);
+ grub_install_push_module ("part_msdos");
+ grub_install_push_module ("fat");
+
img64 = grub_util_path_concat (2, efidir_efi_boot, "bootx64.efi");
make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_X86_64_EFI, "x86_64-efi", img64);
img32 = grub_util_path_concat (2, efidir_efi_boot, "bootia32.efi");
make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_I386_EFI, "i386-efi", img32);
+ grub_install_pop_module ();
+ grub_install_pop_module ();
+
imgname = grub_util_path_concat (2, efidir_efi_boot, "bootarm.efi");
make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_ARM_EFI, "arm-efi", imgname);
free (imgname);

View File

@ -14,13 +14,13 @@ Description: Add configure option to bypass boot menu if possible
Author: Colin Watson <cjwatson@ubuntu.com>
Author: Richard Laager <rlaager@wiktel.com>
Forwarded: no
Last-Update: 2013-11-15
Last-Update: 2013-11-19
Index: b/configure.ac
===================================================================
--- a/configure.ac
+++ b/configure.ac
@@ -1363,6 +1363,17 @@
@@ -1365,6 +1365,17 @@
fi
AC_SUBST([QUIET_BOOT])

View File

@ -2,7 +2,7 @@ Index: b/Makefile.util.def
===================================================================
--- a/Makefile.util.def
+++ b/Makefile.util.def
@@ -306,6 +306,22 @@
@@ -310,6 +310,22 @@
};
program = {

View File

@ -5,7 +5,6 @@ grub_legacy_0_based_partitions.patch
disable_floppies.patch
grub.cfg_400.patch
gfxpayload_keep_default.patch
mkrescue_diet.patch
mkconfig_skip_dmcrypt.patch
install_stage2_confusion.patch
mkrescue_efi_modules.patch
@ -29,7 +28,6 @@ linuxefi_require_shim.patch
linuxefi_non_sb_fallback.patch
mkconfig_signed_kernel.patch
install_signed.patch
install_bios_setup_path.patch
sleep_shift.patch
wubi_no_windows.patch
maybe_quiet.patch

View File

@ -1,13 +1,13 @@
Description: Output a menu entry for firmware setup on UEFI FastBoot systems
Author: Steve Langasek <steve.langasek@ubuntu.com>
Forwarded: no
Last-Update: 2013-11-14
Last-Update: 2013-11-19
Index: b/Makefile.util.def
===================================================================
--- a/Makefile.util.def
+++ b/Makefile.util.def
@@ -484,6 +484,12 @@
@@ -489,6 +489,12 @@
};
script = {

View File

@ -4,13 +4,13 @@ Description: Add configure option to use vt.handoff=7
Author: Colin Watson <cjwatson@ubuntu.com>
Author: Andy Whitcroft <apw@canonical.com>
Forwarded: not-needed
Last-Update: 2013-11-15
Last-Update: 2013-11-19
Index: b/configure.ac
===================================================================
--- a/configure.ac
+++ b/configure.ac
@@ -1385,6 +1385,17 @@
@@ -1387,6 +1387,17 @@
fi
AC_SUBST([GFXPAYLOAD_DYNAMIC])

View File

@ -2998,6 +2998,7 @@ These variables have special meaning to GRUB.
* biosnum::
* check_signatures::
* chosen::
* cmdpath::
* color_highlight::
* color_normal::
* debug::
@ -3067,6 +3068,16 @@ the titles of each of the submenus starting from the top level followed by
the title of the menu entry itself, separated by @samp{>}.
@node cmdpath
@subsection cmdpath
The location from which @file{core.img} was loaded as an absolute
directory name (@pxref{File name syntax}). This is set by GRUB at
startup based on information returned by platform firmware. Not every
platform provides this information and some may return only device
without path name.
@node color_highlight
@subsection color_highlight

View File

@ -428,3 +428,10 @@ efiemu64.o: efiemu64_c.o efiemu64_s.o $(TARGET_OBJ2ELEF)
platform_DATA += efiemu32.o efiemu64.o
CLEANFILES += efiemu32.o efiemu64.o efiemu64_c.o efiemu64_s.o
endif
windowsdir=$(top_builddir)/$(PACKAGE)-$(VERSION)-for-windows
windowsdir: $(PROGRAMS) $(starfield_DATA) $(platform_DATA)
test -d $(windowsdir)/$(target_cpu)-$(platform) || mkdir $(windowsdir)/$(target_cpu)-$(platform)
for x in $(platform_DATA); do \
cp -fp $$x $(windowsdir)/$(target_cpu)-$(platform)/$$x; \
done

View File

@ -563,6 +563,7 @@ module = {
module = {
name = pci;
common = bus/pci.c;
i386_ieee1275 = bus/i386/ieee1275/pci.c;
enable = i386_pc;
enable = i386_ieee1275;

View File

@ -0,0 +1,42 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2013 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/dl.h>
#include <grub/pci.h>
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/ieee1275/ieee1275.h>
volatile void *
grub_pci_device_map_range (grub_pci_device_t dev __attribute__ ((unused)),
grub_addr_t base,
grub_size_t size)
{
if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_REAL_MODE))
return (volatile void *) base;
if (grub_ieee1275_map (base, base, size, 7))
grub_fatal ("couldn't map 0x%lx", base);
return (volatile void *) base;
}
void
grub_pci_device_unmap_range (grub_pci_device_t dev __attribute__ ((unused)),
volatile void *mem __attribute__ ((unused)),
grub_size_t size __attribute__ ((unused)))
{
}

View File

@ -735,6 +735,7 @@ grub_legacy_check_md5_password (int argc, char **args,
char *entered)
{
struct legacy_md5_password *pw = NULL;
int ret;
if (args[0][0] != '-' || args[0][1] != '-')
{
@ -751,7 +752,9 @@ grub_legacy_check_md5_password (int argc, char **args,
if (!pw)
return 0;
return check_password_md5_real (entered, pw);
ret = check_password_md5_real (entered, pw);
grub_free (pw);
return ret;
}
static grub_err_t

View File

@ -192,23 +192,26 @@ free_pk (struct grub_public_key *pk)
struct grub_public_subkey *nsk, *sk;
for (sk = pk->subkeys; sk; sk = nsk)
{
grub_size_t i;
for (i = 0; i < ARRAY_SIZE (sk->mpis); i++)
if (sk->mpis[i])
gcry_mpi_release (sk->mpis[i]);
nsk = sk->next;
grub_free (sk);
}
grub_free (pk);
}
#define READBUF_SIZE 4096
struct grub_public_key *
grub_load_public_key (grub_file_t f)
{
grub_err_t err;
struct grub_public_key *ret;
struct grub_public_subkey **last = 0;
void *fingerprint_context;
fingerprint_context = grub_zalloc (GRUB_MD_SHA1->contextsize);
if (!fingerprint_context)
return NULL;
void *fingerprint_context = NULL;
grub_uint8_t *buffer = NULL;
ret = grub_zalloc (sizeof (*ret));
if (!ret)
@ -217,6 +220,12 @@ grub_load_public_key (grub_file_t f)
return NULL;
}
buffer = grub_zalloc (READBUF_SIZE);
fingerprint_context = grub_zalloc (GRUB_MD_SHA1->contextsize);
if (!buffer || !fingerprint_context)
goto fail;
last = &ret->subkeys;
while (1)
@ -239,6 +248,7 @@ grub_load_public_key (grub_file_t f)
if (type == 0xff)
{
grub_free (fingerprint_context);
grub_free (buffer);
return ret;
}
@ -304,7 +314,6 @@ grub_load_public_key (grub_file_t f)
{
grub_uint16_t l;
grub_size_t lb;
grub_uint8_t buffer[4096];
if (grub_file_read (f, &l, sizeof (l)) != sizeof (l))
{
grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
@ -312,7 +321,7 @@ grub_load_public_key (grub_file_t f)
}
lb = (grub_be_to_cpu16 (l) + GRUB_CHAR_BIT - 1) / GRUB_CHAR_BIT;
if (lb > sizeof (buffer) - sizeof (grub_uint16_t))
if (lb > READBUF_SIZE - sizeof (grub_uint16_t))
{
grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
goto fail;
@ -348,6 +357,7 @@ grub_load_public_key (grub_file_t f)
fail:
free_pk (ret);
grub_free (fingerprint_context);
grub_free (buffer);
return NULL;
}
@ -486,10 +496,12 @@ grub_verify_signature_real (char *buf, grub_size_t size,
gcry_mpi_t hmpi;
grub_uint64_t keyid = 0;
struct grub_public_subkey *sk;
grub_uint8_t *readbuf = NULL;
context = grub_zalloc (hash->contextsize);
if (!context)
return grub_errno;
readbuf = grub_zalloc (READBUF_SIZE);
if (!context || !readbuf)
goto fail;
hash->init (context);
if (buf)
@ -497,8 +509,7 @@ grub_verify_signature_real (char *buf, grub_size_t size,
else
while (1)
{
grub_uint8_t readbuf[4096];
r = grub_file_read (f, readbuf, sizeof (readbuf));
r = grub_file_read (f, readbuf, READBUF_SIZE);
if (r < 0)
goto fail;
if (r == 0)
@ -510,8 +521,8 @@ grub_verify_signature_real (char *buf, grub_size_t size,
hash->write (context, &v4, sizeof (v4));
while (rem)
{
grub_uint8_t readbuf[4096];
r = grub_file_read (sig, readbuf, rem < (grub_ssize_t) sizeof (readbuf) ? rem : (grub_ssize_t) sizeof (readbuf));
r = grub_file_read (sig, readbuf,
rem < READBUF_SIZE ? rem : READBUF_SIZE);
if (r < 0)
goto fail;
if (r == 0)
@ -527,11 +538,10 @@ grub_verify_signature_real (char *buf, grub_size_t size,
if (r != sizeof (unhashed_sub))
goto fail;
{
grub_uint8_t readbuf[4096];
grub_uint8_t *ptr;
grub_uint32_t l;
rem = grub_be_to_cpu16 (unhashed_sub);
if (rem > (int) sizeof (readbuf))
if (rem > READBUF_SIZE)
goto fail;
r = grub_file_read (sig, readbuf, rem);
if (r != rem)
@ -576,24 +586,23 @@ grub_verify_signature_real (char *buf, grub_size_t size,
{
grub_uint16_t l;
grub_size_t lb;
grub_uint8_t buffer[4096];
grub_dprintf ("crypt", "alive\n");
if (grub_file_read (sig, &l, sizeof (l)) != sizeof (l))
goto fail;
grub_dprintf ("crypt", "alive\n");
lb = (grub_be_to_cpu16 (l) + 7) / 8;
grub_dprintf ("crypt", "l = 0x%04x\n", grub_be_to_cpu16 (l));
if (lb > sizeof (buffer) - sizeof (grub_uint16_t))
if (lb > READBUF_SIZE - sizeof (grub_uint16_t))
goto fail;
grub_dprintf ("crypt", "alive\n");
if (grub_file_read (sig, buffer + sizeof (grub_uint16_t), lb) != (grub_ssize_t) lb)
if (grub_file_read (sig, readbuf + sizeof (grub_uint16_t), lb) != (grub_ssize_t) lb)
goto fail;
grub_dprintf ("crypt", "alive\n");
grub_memcpy (buffer, &l, sizeof (l));
grub_memcpy (readbuf, &l, sizeof (l));
grub_dprintf ("crypt", "alive\n");
if (gcry_mpi_scan (&mpis[i], GCRYMPI_FMT_PGP,
buffer, lb + sizeof (grub_uint16_t), 0))
readbuf, lb + sizeof (grub_uint16_t), 0))
goto fail;
grub_dprintf ("crypt", "alive\n");
}
@ -627,10 +636,14 @@ grub_verify_signature_real (char *buf, grub_size_t size,
if ((*pkalgos[pk].algo)->verify (0, hmpi, mpis, sk->mpis, 0, 0))
goto fail;
grub_free (context);
grub_free (readbuf);
return GRUB_ERR_NONE;
fail:
grub_free (context);
grub_free (readbuf);
if (!grub_errno)
return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
return grub_errno;
@ -731,8 +744,8 @@ static grub_err_t
grub_cmd_verify_signature (grub_extcmd_context_t ctxt,
int argc, char **args)
{
grub_file_t f, sig;
grub_err_t err;
grub_file_t f = NULL, sig = NULL;
grub_err_t err = GRUB_ERR_NONE;
struct grub_public_key *pk = NULL;
grub_dprintf ("crypt", "alive\n");
@ -763,19 +776,27 @@ grub_cmd_verify_signature (grub_extcmd_context_t ctxt,
grub_file_filter_disable_all ();
f = grub_file_open (args[0]);
if (!f)
return grub_errno;
{
err = grub_errno;
goto fail;
}
grub_file_filter_disable_all ();
sig = grub_file_open (args[1]);
if (!sig)
{
grub_file_close (f);
return grub_errno;
err = grub_errno;
goto fail;
}
err = grub_verify_signature (f, sig, pk);
grub_file_close (f);
grub_file_close (sig);
fail:
if (sig)
grub_file_close (sig);
if (f)
grub_file_close (f);
if (pk)
free_pk (pk);
return err;
}

View File

@ -184,9 +184,10 @@ grub_mdraid_detect (grub_disk_t disk,
{
grub_disk_addr_t sector;
grub_uint64_t size;
struct grub_raid_super_09 sb;
struct grub_raid_super_09 *sb = NULL;
grub_uint32_t *uuid;
grub_uint32_t level;
struct grub_diskfilter_vg *ret;
/* The sector where the mdraid 0.90 superblock is stored, if available. */
size = grub_disk_get_size (disk);
@ -195,27 +196,31 @@ grub_mdraid_detect (grub_disk_t disk,
return NULL;
sector = NEW_SIZE_SECTORS (size);
if (grub_disk_read (disk, sector, 0, SB_BYTES, &sb))
sb = grub_malloc (sizeof (*sb));
if (!sb)
return NULL;
if (grub_disk_read (disk, sector, 0, SB_BYTES, sb))
goto fail;
/* Look whether there is a mdraid 0.90 superblock. */
if (sb.md_magic != grub_cpu_to_md32_compile_time (SB_MAGIC))
if (sb->md_magic != grub_cpu_to_md32_compile_time (SB_MAGIC))
/* not 0.9x raid. */
return NULL;
goto fail;
if (sb.major_version != grub_cpu_to_md32_compile_time (0)
|| sb.minor_version != grub_cpu_to_md32_compile_time (90))
if (sb->major_version != grub_cpu_to_md32_compile_time (0)
|| sb->minor_version != grub_cpu_to_md32_compile_time (90))
/* Unsupported version. */
return NULL;
goto fail;
/* No need for explicit check that sb.size is 0 (unspecified) since
/* No need for explicit check that sb->size is 0 (unspecified) since
0 >= non-0 is false. */
if (((grub_disk_addr_t) grub_md_to_cpu32 (sb.size)) * 2 >= size)
return NULL;
if (((grub_disk_addr_t) grub_md_to_cpu32 (sb->size)) * 2 >= size)
goto fail;
/* FIXME: Check the checksum. */
level = grub_md_to_cpu32 (sb.level);
level = grub_md_to_cpu32 (sb->level);
/* Multipath. */
if ((int) level == -4)
level = 1;
@ -225,37 +230,43 @@ grub_mdraid_detect (grub_disk_t disk,
{
grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"unsupported RAID level: %d", level);
return NULL;
goto fail;
}
if (grub_md_to_cpu32 (sb.this_disk.number) == 0xffff
|| grub_md_to_cpu32 (sb.this_disk.number) == 0xfffe)
if (grub_md_to_cpu32 (sb->this_disk.number) == 0xffff
|| grub_md_to_cpu32 (sb->this_disk.number) == 0xfffe)
/* Spares aren't implemented. */
return NULL;
goto fail;
uuid = grub_malloc (16);
if (!uuid)
return NULL;
goto fail;
uuid[0] = grub_swap_bytes32 (sb.set_uuid0);
uuid[1] = grub_swap_bytes32 (sb.set_uuid1);
uuid[2] = grub_swap_bytes32 (sb.set_uuid2);
uuid[3] = grub_swap_bytes32 (sb.set_uuid3);
uuid[0] = grub_swap_bytes32 (sb->set_uuid0);
uuid[1] = grub_swap_bytes32 (sb->set_uuid1);
uuid[2] = grub_swap_bytes32 (sb->set_uuid2);
uuid[3] = grub_swap_bytes32 (sb->set_uuid3);
*start_sector = 0;
id->uuidlen = 0;
id->id = grub_md_to_cpu32 (sb.this_disk.number);
id->id = grub_md_to_cpu32 (sb->this_disk.number);
char buf[32];
grub_snprintf (buf, sizeof (buf), "md%d", grub_md_to_cpu32 (sb.md_minor));
return grub_diskfilter_make_raid (16, (char *) uuid,
grub_md_to_cpu32 (sb.raid_disks), buf,
(sb.size) ? ((grub_disk_addr_t)
grub_md_to_cpu32 (sb.size)) * 2
: sector,
grub_md_to_cpu32 (sb.chunk_size) >> 9,
grub_md_to_cpu32 (sb.layout),
level);
grub_snprintf (buf, sizeof (buf), "md%d", grub_md_to_cpu32 (sb->md_minor));
ret = grub_diskfilter_make_raid (16, (char *) uuid,
grub_md_to_cpu32 (sb->raid_disks), buf,
(sb->size) ? ((grub_disk_addr_t)
grub_md_to_cpu32 (sb->size)) * 2
: sector,
grub_md_to_cpu32 (sb->chunk_size) >> 9,
grub_md_to_cpu32 (sb->layout),
level);
grub_free (sb);
return ret;
fail:
grub_free (sb);
return NULL;
}
static struct grub_diskfilter grub_mdraid_dev = {

View File

@ -47,6 +47,7 @@ grub_ubootdisk_register (struct device_info *newdev)
{
case DT_STOR_IDE:
case DT_STOR_SATA:
case DT_STOR_SCSI:
case DT_STOR_MMC:
case DT_STOR_USB:
/* hd */

View File

@ -911,7 +911,6 @@ grub_btrfs_lzo_decompress(char *ibuf, grub_size_t isize, grub_off_t off,
{
grub_uint32_t total_size, cblock_size;
grub_size_t ret = 0;
unsigned char buf[GRUB_BTRFS_LZO_BLOCK_SIZE];
char *ibuf0 = ibuf;
total_size = grub_le_to_cpu32 (grub_get_unaligned32 (ibuf));
@ -955,13 +954,21 @@ grub_btrfs_lzo_decompress(char *ibuf, grub_size_t isize, grub_off_t off,
if (off > 0 || osize < GRUB_BTRFS_LZO_BLOCK_SIZE)
{
grub_size_t to_copy = GRUB_BTRFS_LZO_BLOCK_SIZE - off;
grub_uint8_t *buf;
if (to_copy > osize)
to_copy = osize;
buf = grub_malloc (GRUB_BTRFS_LZO_BLOCK_SIZE);
if (!buf)
return -1;
if (lzo1x_decompress_safe ((lzo_bytep)ibuf, cblock_size, buf, &usize,
NULL) != LZO_E_OK)
return -1;
{
grub_free (buf);
return -1;
}
if (to_copy > usize)
to_copy = usize;
@ -972,6 +979,8 @@ grub_btrfs_lzo_decompress(char *ibuf, grub_size_t isize, grub_off_t off,
obuf += to_copy;
ibuf += cblock_size;
off = 0;
grub_free (buf);
continue;
}

View File

@ -72,10 +72,13 @@ struct grub_jfs_extent
grub_uint32_t blk2;
} __attribute__ ((packed));
#define GRUB_JFS_IAG_INODES_OFFSET 3072
#define GRUB_JFS_IAG_INODES_COUNT 128
struct grub_jfs_iag
{
grub_uint8_t unused[3072];
struct grub_jfs_extent inodes[128];
grub_uint8_t unused[GRUB_JFS_IAG_INODES_OFFSET];
struct grub_jfs_extent inodes[GRUB_JFS_IAG_INODES_COUNT];
} __attribute__ ((packed));
@ -283,20 +286,25 @@ getblk (struct grub_jfs_treehead *treehead,
if (found != -1)
{
grub_int64_t ret = -1;
struct
{
struct grub_jfs_treehead treehead;
struct grub_jfs_tree_extent extents[254];
} tree;
} *tree;
if (grub_disk_read (data->disk,
((grub_disk_addr_t) grub_le_to_cpu32 (extents[found].extent.blk2))
<< (grub_le_to_cpu16 (data->sblock.log2_blksz)
- GRUB_DISK_SECTOR_BITS), 0,
sizeof (tree), (char *) &tree))
tree = grub_zalloc (sizeof (*tree));
if (!tree)
return -1;
return getblk (&tree.treehead, &tree.extents[0], data, blk);
if (!grub_disk_read (data->disk,
((grub_disk_addr_t) grub_le_to_cpu32 (extents[found].extent.blk2))
<< (grub_le_to_cpu16 (data->sblock.log2_blksz)
- GRUB_DISK_SECTOR_BITS), 0,
sizeof (*tree), (char *) tree))
ret = getblk (&tree->treehead, &tree->extents[0], data, blk);
grub_free (tree);
return ret;
}
return -1;
@ -316,7 +324,7 @@ static grub_err_t
grub_jfs_read_inode (struct grub_jfs_data *data, grub_uint32_t ino,
struct grub_jfs_inode *inode)
{
struct grub_jfs_iag iag;
struct grub_jfs_extent iag_inodes[GRUB_JFS_IAG_INODES_COUNT];
grub_uint32_t iagnum = ino / 4096;
unsigned inoext = (ino % 4096) / 32;
unsigned inonum = (ino % 4096) % 32;
@ -330,11 +338,12 @@ grub_jfs_read_inode (struct grub_jfs_data *data, grub_uint32_t ino,
/* Read in the IAG. */
if (grub_disk_read (data->disk,
iagblk << (grub_le_to_cpu16 (data->sblock.log2_blksz)
- GRUB_DISK_SECTOR_BITS), 0,
sizeof (struct grub_jfs_iag), &iag))
- GRUB_DISK_SECTOR_BITS),
GRUB_JFS_IAG_INODES_OFFSET,
sizeof (iag_inodes), &iag_inodes))
return grub_errno;
inoblk = grub_le_to_cpu32 (iag.inodes[inoext].blk2);
inoblk = grub_le_to_cpu32 (iag_inodes[inoext].blk2);
inoblk <<= (grub_le_to_cpu16 (data->sblock.log2_blksz)
- GRUB_DISK_SECTOR_BITS);
inoblk += inonum;

View File

@ -21,7 +21,12 @@
.file "cache.S"
.text
.syntax unified
#if !defined (__thumb2__) || !defined (ARMV7)
.arm
#else
.thumb
#endif
#if !defined (ARMV6) && !defined (ARMV7)
# error Unsupported architecture version!
#endif

View File

@ -21,8 +21,13 @@
.file "cache_armv7.S"
.text
.syntax unified
.arm
#if !defined (__thumb2__)
.arch armv7a
.arm
#else
.arch armv7
.thumb
#endif
# define DMB dmb
# define DSB dsb
# define ISB isb
@ -58,11 +63,17 @@ clean_invalidate_dcache:
@ read current cache information
mrc p15, 1, r8, c0, c0, 0 @ Read CCSIDR
lsr r3, r8, #13 @ Number of sets -1
ldr r9, =0x3fff
and r3, r3, r9
@ Keep only 14 bits of r3
lsl r3, r3, #18
lsr r3, r3, #18
lsr r4, r8, #3 @ Number of ways -1
ldr r9, =0x1ff
and r4, r4, r9
@ Keep only 9 bits of r4
lsl r4, r4, #23
lsr r4, r4, #23
and r7, r8, #7 @ log2(line size in words) - 2
add r7, r7, #2 @ adjust
mov r8, #1

View File

@ -131,23 +131,16 @@ FUNCTION(grub_uboot_syscall)
str r8, transition_space
str lr, transition_space + 4
str r9, transition_space + 8
str sp, transition_space + 12
sub sp, sp, #0x20
lsr sp, sp, #3
lsl sp, sp, #3
ldr r8, gd_backup
ldr r9, gd_backup + 4
mov lr, pc
ldr pc, grub_uboot_syscall_ptr
str r8, gd_backup
ldr r8, transition_space
ldr lr, transition_space + 4
ldr r9, transition_space + 8
ldr sp, transition_space + 12
bx lr
@ -166,8 +159,8 @@ entry_state_end:
.long 0 @ r6
.long 0 @ r7
gd_backup:
.long 0 @ r8 - U-Boot global data pointer
.long 0 @ r9
.long 0 @ r8 - U-Boot global data pointer up to 2013-09-21
.long 0 @ r9 - U-Boot global data pointer 2013-09-21 onwards
.long 0 @ r10
.long 0 @ r11
VARIABLE(grub_uboot_search_hint)@ U-Boot stack pointer -
@ -180,7 +173,6 @@ transition_space:
.long 0 @ r8
.long 0 @ lr
.long 0 @ r9
.long 0 @ sp
VARIABLE(grub_uboot_syscall_ptr)
.long 0 @

View File

@ -621,3 +621,78 @@ grub_util_biosdisk_get_osdev (grub_disk_t disk)
return map[disk->id].device;
}
static char *
grub_util_path_concat_real (size_t n, int ext, va_list ap)
{
size_t totlen = 0;
char **l = xmalloc ((n + ext) * sizeof (l[0]));
char *r, *p, *pi;
size_t i;
int first = 1;
for (i = 0; i < n + ext; i++)
{
l[i] = va_arg (ap, char *);
if (l[i])
totlen += strlen (l[i]) + 1;
}
r = xmalloc (totlen + 10);
p = r;
for (i = 0; i < n; i++)
{
pi = l[i];
if (!pi)
continue;
while (*pi == '/')
pi++;
if ((p != r || (pi != l[i] && first)) && (p == r || *(p - 1) != '/'))
*p++ = '/';
first = 0;
p = grub_stpcpy (p, pi);
while (p != r && p != r + 1 && *(p - 1) == '/')
p--;
}
if (ext && l[i])
p = grub_stpcpy (p, l[i]);
*p = '\0';
free (l);
return r;
}
char *
grub_util_path_concat (size_t n, ...)
{
va_list ap;
char *r;
va_start (ap, n);
r = grub_util_path_concat_real (n, 0, ap);
va_end (ap);
return r;
}
char *
grub_util_path_concat_ext (size_t n, ...)
{
va_list ap;
char *r;
va_start (ap, n);
r = grub_util_path_concat_real (n, 1, ap);
va_end (ap);
return r;
}

View File

@ -87,9 +87,6 @@ grub_file_open (const char *name)
if (! file)
goto fail;
file->name = grub_strdup (name);
grub_errno = GRUB_ERR_NONE;
file->device = device;
if (device->disk && file_name[0] != '/')
@ -105,6 +102,9 @@ grub_file_open (const char *name)
if ((file->fs->open) (file, file_name) != GRUB_ERR_NONE)
goto fail;
file->name = grub_strdup (name);
grub_errno = GRUB_ERR_NONE;
for (filter = 0; file && filter < ARRAY_SIZE (grub_file_filters_enabled);
filter++)
if (grub_file_filters_enabled[filter])
@ -187,6 +187,7 @@ grub_file_close (grub_file_t file)
if (file->device)
grub_device_close (file->device);
grub_free (file->name);
grub_free (file);
return grub_errno;
}

View File

@ -355,8 +355,7 @@ get_device_name_iter (grub_disk_t disk __attribute__ ((unused)),
}
void
grub_machine_get_bootlocation (char **device __attribute__ ((unused)),
char **path __attribute__ ((unused)))
grub_machine_get_bootlocation (char **device, char **path)
{
char *loaddev = boot_location;
char *pptr, *partptr;

View File

@ -49,7 +49,7 @@ grub_machine_init (void)
}
/* FIXME: measure this. */
grub_arch_cpuclock = 64000000;
grub_arch_cpuclock = 200000000;
modend = grub_modules_get_end ();
grub_mm_init_region ((void *) modend, grub_arch_memsize

View File

@ -298,7 +298,10 @@ grub_real_malloc (grub_mm_header_t *first, grub_size_t n, grub_size_t align)
/* Mark find as a start marker for next allocation to fasten it.
This will have side effect of fragmenting memory as small
pieces before this will be un-used. */
*first = q;
/* So do it only for chunks under 64K. */
if (n < (0x8000 >> GRUB_MM_ALIGN_LOG2)
|| *first == p)
*first = q;
return p + 1;
}

View File

@ -30,6 +30,6 @@ _start:
movq %rcx, EXT_C(grub_efi_image_handle)(%rip)
movq %rdx, EXT_C(grub_efi_system_table)(%rip)
andq $~0xf, %rsp
call EXT_C(grub_main)
ret
/* Doesn't return. */

View File

@ -24,7 +24,11 @@
GRUB_MOD_LICENSE "GPLv3+"
.syntax unified
#if !defined (__thumb2__)
.arm
#else
.thumb
#endif
.text
@ -32,7 +36,8 @@ GRUB_MOD_LICENSE "GPLv3+"
* int grub_setjmp (grub_jmp_buf env)
*/
FUNCTION(grub_setjmp)
stm r0, { r4-r11, sp, lr }
mov r12, sp
stm r0, { r4-r12, lr }
mov r0, #0
bx lr
@ -40,7 +45,9 @@ FUNCTION(grub_setjmp)
* int grub_longjmp (grub_jmp_buf env, int val)
*/
FUNCTION(grub_longjmp)
ldm r0, { r4-r11, sp, lr }
ldm r0, { r4-r12, lr }
mov sp, r12
movs r0, r1
it eq
moveq r0, #1
bx lr

View File

@ -47,10 +47,11 @@ FUNCTION(grub_setjmp)
stw 28, 60(3)
stw 29, 64(3)
stw 30, 68(3)
stw 31, 72(3)
mflr 4
stw 4, 72(3)
mfcr 4
stw 4, 76(3)
mfcr 4
stw 4, 80(3)
li 3, 0
blr
@ -76,9 +77,10 @@ FUNCTION(grub_longjmp)
lwz 28, 60(3)
lwz 29, 64(3)
lwz 30, 68(3)
lwz 5, 72(3)
mtlr 5
lwz 31, 72(3)
lwz 5, 76(3)
mtlr 5
lwz 5, 80(3)
mtcr 5
mr. 3, 4
bne 1f

View File

@ -1618,7 +1618,7 @@ grub_relocator_prepare_relocs (struct grub_relocator *rel, grub_addr_t addr,
}
void
grub_mm_check_real (char *file, int line)
grub_mm_check_real (const char *file, int line)
{
grub_mm_region_t r;
grub_mm_header_t p, pa;

View File

@ -41,7 +41,11 @@ FUNCTION(grub_setjmp)
FUNCTION(grub_longjmp)
ldx [%o0 + 0x10], %g1
movrz %o1, 1, %o1
save %sp, -64, %sp
flushw
restore
ldx [%o0 + 0x00], %o7
ldx [%o0 + 0x08], %fp
sub %fp, 192, %sp

View File

@ -184,8 +184,8 @@ grub_mmap_register (grub_uint64_t start, grub_uint64_t size, int type)
return 0;
b = grub_efi_system_table->boot_services;
address = start & (~0x3ffULL);
pages = (end - address + 0x3ff) >> 12;
address = start & (~0xfffULL);
pages = (end - address + 0xfff) >> 12;
status = efi_call_2 (b->free_pages, address, pages);
if (status != GRUB_EFI_SUCCESS && status != GRUB_EFI_NOT_FOUND)
{
@ -263,7 +263,7 @@ grub_mmap_malign_and_register (grub_uint64_t align __attribute__ ((unused)),
atype = GRUB_EFI_ALLOCATE_ANY_PAGES;
#endif
pages = (size + 0x3ff) >> 12;
pages = (size + 0xfff) >> 12;
status = efi_call_4 (b->allocate_pages, atype,
make_efi_memtype (type), pages, &address);
if (status != GRUB_EFI_SUCCESS)

View File

@ -379,12 +379,18 @@ grub_cmdline_get (const char *prompt_translated)
cl_terms = grub_malloc (sizeof (cl_terms[0]) * nterms);
if (!cl_terms)
return 0;
{
grub_free (buf);
return 0;
}
cl_term_cur = cl_terms;
unicode_msg = grub_malloc (msg_len * sizeof (grub_uint32_t));
if (!unicode_msg)
return 0;;
{
grub_free (buf);
return 0;
}
msg_len = grub_utf8_to_ucs4 (unicode_msg, msg_len - 1,
(grub_uint8_t *) prompt_translated, -1, 0);
unicode_msg[msg_len++] = ' ';
@ -621,6 +627,7 @@ grub_cmdline_get (const char *prompt_translated)
case '\e':
grub_free (cl_terms);
grub_free (buf);
return 0;
case '\b':

View File

@ -0,0 +1,94 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2004,2006,2007,2008,2009,2010,2011,2012,2013 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <config-util.h>
#include <grub/emu/hostdisk.h>
#include <grub/emu/exec.h>
#include <grub/emu/config.h>
#include <grub/util/install.h>
#include <grub/util/misc.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>
#include <stdlib.h>
const char *
grub_util_get_config_filename (void)
{
static char *value = NULL;
if (!value)
value = grub_util_path_concat (3, GRUB_SYSCONFDIR,
"default", "grub");
return value;
}
const char *
grub_util_get_pkgdatadir (void)
{
const char *ret = getenv ("pkgdatadir");
if (ret)
return ret;
return GRUB_DATADIR "/" PACKAGE;
}
const char *
grub_util_get_pkglibdir (void)
{
return GRUB_LIBDIR "/" PACKAGE;
}
const char *
grub_util_get_localedir (void)
{
return LOCALEDIR;
}
void
grub_util_load_config (struct grub_util_config *cfg)
{
const char *cfgfile;
FILE *f = NULL;
const char *v;
memset (cfg, 0, sizeof (*cfg));
v = getenv ("GRUB_ENABLE_CRYPTODISK");
if (v && v[0] == 'y' && v[1] == '\0')
cfg->is_cryptodisk_enabled = 1;
v = getenv ("GRUB_DISTRIBUTOR");
if (v)
cfg->grub_distributor = xstrdup (v);
cfgfile = grub_util_get_config_filename ();
if (!grub_util_is_regular (cfgfile))
return;
f = grub_util_fopen (cfgfile, "r");
if (f)
{
grub_util_parse_config (f, cfg, 0);
fclose (f);
}
else
grub_util_warn (_("cannot open config file `%s': %s"),
cfgfile, strerror (errno));
}

View File

@ -41,6 +41,7 @@
#include <fcntl.h>
#include <errno.h>
#include <limits.h>
#include <time.h>
#include <string.h>
#include <dos/dos.h>
@ -516,6 +517,17 @@ grub_util_is_directory (const char *path)
return S_ISDIR (st.st_mode);
}
int
grub_util_is_regular (const char *path)
{
struct stat st;
if (stat (path, &st) == -1)
return 0;
return S_ISREG (st.st_mode);
}
int
grub_util_is_special_file (const char *path)
{
@ -525,3 +537,53 @@ grub_util_is_special_file (const char *path)
return 1;
return (!S_ISREG (st.st_mode) && !S_ISDIR (st.st_mode));
}
static char *
get_temp_name (void)
{
static int ctr = 0;
char *t;
struct stat st;
while (1)
{
t = xasprintf ("T:grub.%d.%d.%d.%d", (int) getpid (), (int) getppid (),
ctr++, time (0));
if (stat (t, &st) == -1)
return t;
free (t);
}
}
char *
grub_util_make_temporary_file (void)
{
char *ret = get_temp_name ();
FILE *f;
f = grub_util_fopen (ret, "wb");
if (f)
fclose (f);
return ret;
}
char *
grub_util_make_temporary_dir (void)
{
char *ret = get_temp_name ();
grub_util_mkdir (ret);
return ret;
}
grub_uint32_t
grub_util_get_mtime (const char *path)
{
struct stat st;
if (stat (path, &st) == -1)
return 0;
return st.st_mtime;
}

View File

@ -0,0 +1,21 @@
#include <config.h>
#include <grub/util/install.h>
#include <grub/util/misc.h>
int
grub_install_compress_gzip (const char *src, const char *dest)
{
grub_util_error ("no compression is available for your platform");
}
int
grub_install_compress_xz (const char *src, const char *dest)
{
grub_util_error ("no compression is available for your platform");
}
int
grub_install_compress_lzop (const char *src, const char *dest)
{
grub_util_error ("no compression is available for your platform");
}

View File

@ -20,6 +20,7 @@
#include <config-util.h>
#include <grub/util/misc.h>
#include <grub/i18n.h>
#include "progname.h"
@ -29,7 +30,9 @@ grub_util_host_init (int *argc __attribute__ ((unused)),
{
set_program_name ((*argv)[0]);
#ifdef GRUB_UTIL
grub_util_init_nls ();
#endif
#if (defined (GRUB_UTIL) && defined(ENABLE_NLS) && ENABLE_NLS)
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
#endif /* (defined(ENABLE_NLS) && ENABLE_NLS) */
}

View File

@ -0,0 +1,46 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2013 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/emu/misc.h>
#include <grub/util/install.h>
#include <grub/util/misc.h>
#include "platform.c"
void
grub_install_register_ieee1275 (int is_prep, const char *install_device,
int partno, const char *relpath)
{
grub_util_error ("%s", "no IEEE1275 routines are available for your platform");
}
void
grub_install_register_efi (const char *efidir_disk, int efidir_part,
const char *efifile_path,
const char *efi_distributor)
{
grub_util_error ("%s", "no EFI routines are available for your platform");
}
void
grub_install_sgi_setup (const char *install_device,
const char *imgfile, const char *destname)
{
grub_util_error ("%s", "no SGI routines are available for your platform");
}

View File

@ -0,0 +1,26 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2013 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/util/install.h>
const char *
grub_install_get_default_x86_platform (void)
{
return "i386-pc";
}

View File

@ -0,0 +1,5 @@
#if !defined (__MINGW32__) && !defined (__CYGWIN__) && !defined (__AROS__)
#include "unix/compress.c"
#else
#include "basic/compress.c"
#endif

7
grub-core/osdep/config.c Normal file
View File

@ -0,0 +1,7 @@
#if defined (__MINGW32__) && !defined (__CYGWIN__)
#include "windows/config.c"
#elif defined (__AROS__)
#include "aros/config.c"
#else
#include "unix/config.c"
#endif

View File

@ -0,0 +1,99 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2013 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <grub/util/install.h>
#include <grub/emu/config.h>
#include <grub/emu/exec.h>
#include <sys/types.h>
#include <dirent.h>
#include <stdlib.h>
#include <string.h>
#include <sys/utsname.h>
static int
is_not_empty_directory (const char *dir)
{
DIR *d;
struct dirent *de;
d = opendir (dir);
if (!d)
return 0;
while ((de = readdir (d)))
{
if (strcmp (de->d_name, ".") == 0
|| strcmp (de->d_name, "..") == 0)
continue;
closedir (d);
return 1;
}
closedir (d);
return 0;
}
static int
is_64_kernel (void)
{
struct utsname un;
if (uname (&un) < 0)
return 0;
return strcmp (un.machine, "x86_64") == 0;
}
const char *
grub_install_get_default_x86_platform (void)
{
/*
On Linux, we need the efivars kernel modules.
If no EFI is available this module just does nothing
besides a small hello and if we detect efi we'll load it
anyway later. So it should be safe to
try to load it here.
*/
grub_util_exec ((const char * []){ "modprobe", "-q",
"efivars", NULL });
if (is_not_empty_directory ("/sys/firmware/efi"))
{
const char *pkglibdir = grub_util_get_pkglibdir ();
const char *platform;
char *pd;
int found;
if (is_64_kernel ())
platform = "x86_64-efi";
else
platform = "i386-efi";
pd = grub_util_path_concat (2, pkglibdir, platform);
found = grub_util_is_directory (pd);
free (pd);
if (found)
return platform;
}
if (is_not_empty_directory ("/proc/device-tree"))
return "i386-ieee1275";
else
return "i386-pc";
}

View File

@ -0,0 +1,7 @@
#ifdef __linux__
#include "linux/platform.c"
#elif defined (__MINGW32__) || defined (__CYGWIN__) || defined (__AROS__)
#include "basic/no_platform.c"
#else
#include "basic/platform.c"
#endif

View File

@ -0,0 +1,3 @@
#if !defined (__MINGW32__) && !defined (__CYGWIN__) && !defined (__AROS__)
#include "unix/platform.c"
#endif

View File

@ -0,0 +1,41 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2013 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/emu/exec.h>
#include <grub/util/install.h>
int
grub_install_compress_gzip (const char *src, const char *dest)
{
return grub_util_exec_redirect ((const char * []) { "gzip", "--best",
"--stdout", NULL }, src, dest);
}
int
grub_install_compress_xz (const char *src, const char *dest)
{
return grub_util_exec_redirect ((const char * []) { "xz",
"--lzma2=dict=128KiB", "--check=none", "--stdout", NULL }, src, dest);
}
int
grub_install_compress_lzop (const char *src, const char *dest)
{
return grub_util_exec_redirect ((const char * []) { "lzop", "-9", "-c",
NULL }, src, dest);
}

View File

@ -0,0 +1,171 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2004,2006,2007,2008,2009,2010,2011,2012,2013 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <config-util.h>
#include <grub/emu/hostdisk.h>
#include <grub/emu/exec.h>
#include <grub/emu/config.h>
#include <grub/util/install.h>
#include <grub/util/misc.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>
#include <stdlib.h>
const char *
grub_util_get_config_filename (void)
{
static char *value = NULL;
if (!value)
value = grub_util_path_concat (3, GRUB_SYSCONFDIR,
"default", "grub");
return value;
}
const char *
grub_util_get_pkgdatadir (void)
{
const char *ret = getenv ("pkgdatadir");
if (ret)
return ret;
return GRUB_DATADIR "/" PACKAGE;
}
const char *
grub_util_get_pkglibdir (void)
{
return GRUB_LIBDIR "/" PACKAGE;
}
const char *
grub_util_get_localedir (void)
{
return LOCALEDIR;
}
static void
grub_util_load_one_config (struct grub_util_config *cfg, const char *cfgfile)
{
pid_t pid;
const char *argv[4];
char *script, *ptr;
const char *iptr;
FILE *f = NULL;
int fd;
if (!grub_util_is_regular (cfgfile))
return;
argv[0] = "sh";
argv[1] = "-c";
script = xmalloc (4 * strlen (cfgfile) + 300);
ptr = script;
memcpy (ptr, ". '", 3);
ptr += 3;
for (iptr = cfgfile; *iptr; iptr++)
{
if (*iptr == '\\')
{
memcpy (ptr, "'\\''", 4);
ptr += 4;
continue;
}
*ptr++ = *iptr;
}
strcpy (ptr, "'; printf \"GRUB_ENABLE_CRYPTODISK=%s\\nGRUB_DISTRIBUTOR=%s\\n\", "
"\"$GRUB_ENABLE_CRYPTODISK\", \"$GRUB_DISTRIBUTOR\"");
argv[2] = script;
argv[3] = '\0';
pid = grub_util_exec_pipe (argv, &fd);
if (pid)
f = fdopen (fd, "r");
if (f)
{
grub_util_parse_config (f, cfg, 1);
fclose (f);
}
if (pid)
{
close (fd);
waitpid (pid, NULL, 0);
}
if (f)
return;
f = grub_util_fopen (cfgfile, "r");
if (f)
{
grub_util_parse_config (f, cfg, 0);
fclose (f);
}
else
grub_util_warn (_("cannot open config file `%s': %s"),
cfgfile, strerror (errno));
}
void
grub_util_load_config (struct grub_util_config *cfg)
{
const char *cfgfile;
const char *v;
char *cfgdir;
grub_util_fd_dir_t d;
memset (cfg, 0, sizeof (*cfg));
v = getenv ("GRUB_ENABLE_CRYPTODISK");
if (v && v[0] == 'y' && v[1] == '\0')
cfg->is_cryptodisk_enabled = 1;
v = getenv ("GRUB_DISTRIBUTOR");
if (v)
cfg->grub_distributor = xstrdup (v);
cfgfile = grub_util_get_config_filename ();
grub_util_load_one_config (cfg, cfgfile);
cfgdir = xasprintf ("%s.d", cfgfile);
d = grub_util_fd_opendir (cfgdir);
if (d)
{
grub_util_fd_dirent_t de;
while ((de = grub_util_fd_readdir (d)))
{
const char *ext = strrchr (de->d_name, '.');
char *x;
if (!ext || strcmp (ext, ".cfg") != 0)
continue;
x = grub_util_path_concat (2, cfgdir, de->d_name);
grub_util_load_one_config (cfg, x);
free (x);
}
grub_util_fd_closedir (d);
}
}

View File

@ -38,6 +38,23 @@ grub_util_exec (const char *const *argv)
{
pid_t pid;
int status = -1;
char *str, *pstr;
const char *const *ptr;
grub_size_t strl = 0;
for (ptr = argv; *ptr; ptr++)
strl += grub_strlen (*ptr) + 1;
pstr = str = xmalloc (strl);
for (ptr = argv; *ptr; ptr++)
{
pstr = grub_stpcpy (pstr, *ptr);
*pstr++ = ' ';
}
if (pstr > str)
pstr--;
*pstr = '\0';
grub_util_info ("executing %s", str);
grub_free (str);
pid = fork ();
if (pid < 0)
@ -71,6 +88,29 @@ grub_util_exec_redirect (const char *const *argv, const char *stdin_file,
{
pid_t mdadm_pid;
int status = -1;
char *str, *pstr;
const char *const *ptr;
grub_size_t strl = 0;
for (ptr = argv; *ptr; ptr++)
strl += grub_strlen (*ptr) + 1;
strl += grub_strlen (stdin_file) + 2;
strl += grub_strlen (stdout_file) + 2;
pstr = str = xmalloc (strl);
for (ptr = argv; *ptr; ptr++)
{
pstr = grub_stpcpy (pstr, *ptr);
*pstr++ = ' ';
}
*pstr++ = '<';
pstr = grub_stpcpy (pstr, stdin_file);
*pstr++ = ' ';
*pstr++ = '>';
pstr = grub_stpcpy (pstr, stdout_file);
*pstr = '\0';
grub_util_info ("executing %s", str);
grub_free (str);
mdadm_pid = fork ();
if (mdadm_pid < 0)
@ -87,6 +127,8 @@ grub_util_exec_redirect (const char *const *argv, const char *stdin_file,
#endif
in = open (stdin_file, O_RDONLY);
if (in < 0)
exit (127);
dup2 (in, STDIN_FILENO);
close (in);
@ -94,6 +136,9 @@ grub_util_exec_redirect (const char *const *argv, const char *stdin_file,
dup2 (out, STDOUT_FILENO);
close (out);
if (out < 0)
exit (127);
/* Ensure child is not localised. */
setenv ("LC_ALL", "C", 1);

View File

@ -246,6 +246,17 @@ grub_util_is_regular (const char *path)
return S_ISREG (st.st_mode);
}
grub_uint32_t
grub_util_get_mtime (const char *path)
{
struct stat st;
if (stat (path, &st) == -1)
return 0;
return st.st_mtime;
}
int
grub_util_is_special_file (const char *path)
{
@ -256,4 +267,42 @@ grub_util_is_special_file (const char *path)
return (!S_ISREG (st.st_mode) && !S_ISDIR (st.st_mode));
}
char *
grub_util_make_temporary_file (void)
{
const char *t = getenv ("TMPDIR");
size_t tl;
char *tmp;
if (!t)
t = "/tmp";
tl = strlen (t);
tmp = xmalloc (tl + sizeof ("/grub.XXXXXX"));
memcpy (tmp, t, tl);
memcpy (tmp + tl, "/grub.XXXXXX",
sizeof ("/grub.XXXXXX"));
if (mkstemp (tmp) == -1)
grub_util_error (_("cannot make temporary file: %s"), strerror (errno));
return tmp;
}
char *
grub_util_make_temporary_dir (void)
{
const char *t = getenv ("TMPDIR");
size_t tl;
char *tmp;
if (!t)
t = "/tmp";
tl = strlen (t);
tmp = xmalloc (tl + sizeof ("/grub.XXXXXX"));
memcpy (tmp, t, tl);
memcpy (tmp + tl, "/grub.XXXXXX",
sizeof ("/grub.XXXXXX"));
if (!mkdtemp (tmp))
grub_util_error (_("cannot make temporary directory: %s"),
strerror (errno));
return tmp;
}
#endif

View File

@ -0,0 +1,213 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2013 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <grub/util/install.h>
#include <grub/util/misc.h>
#include <grub/misc.h>
#include <grub/i18n.h>
#include <grub/emu/exec.h>
#include <sys/types.h>
#include <dirent.h>
#include <string.h>
#include <errno.h>
static char *
get_ofpathname (const char *dev)
{
char *ret = xmalloc (2 * PATH_MAX);
char *end = ret + 2 * PATH_MAX - 1;
int fd;
pid_t pid;
char *ptr = ret;
pid = grub_util_exec_pipe ((const char * []){ "ofpathname", dev, NULL }, &fd);
if (!pid)
goto fail;
FILE *fp = fdopen (fd, "r");
if (!fp)
goto fail;
while (!feof (fp) && ptr < end)
{
size_t r;
r = fread (ptr, 1, end - ptr, fp);
ptr += r;
}
fclose (fp);
return ret;
fail:
grub_util_error (_("couldn't find IEEE1275 device tree path for %s.\nYou will have to set `boot-device' variable manually"),
dev);
}
static void
grub_install_remove_efi_entries_by_distributor (const char *efi_distributor)
{
int fd;
pid_t pid = grub_util_exec_pipe ((const char * []){ "efibootmgr", NULL }, &fd);
char *line = NULL;
size_t len = 0;
if (!pid)
{
grub_util_warn (_("Unable to open stream from %s: %s"),
"efibootmgr", strerror (errno));
return;
}
FILE *fp = fdopen (fd, "r");
if (!fp)
{
grub_util_warn (_("Unable to open stream from %s: %s"),
"efibootmgr", strerror (errno));
return;
}
line = xmalloc (80);
len = 80;
while (1)
{
int ret;
char *bootnum;
ret = getline (&line, &len, fp);
if (ret == -1)
break;
if (grub_memcmp (line, "Boot", sizeof ("Boot") - 1) != 0
|| line[sizeof ("Boot") - 1] < '0'
|| line[sizeof ("Boot") - 1] > '9')
continue;
if (!strcasestr (line, efi_distributor))
continue;
bootnum = line + sizeof ("Boot") - 1;
bootnum[4] = '\0';
if (!verbosity)
grub_util_exec ((const char * []){ "efibootmgr", "-q",
"-b", bootnum, "-B", NULL });
else
grub_util_exec ((const char * []){ "efibootmgr",
"-b", bootnum, "-B", NULL });
}
free (line);
}
void
grub_install_register_efi (const char *efidir_disk, int efidir_part,
const char *efifile_path,
const char *efi_distributor)
{
if (grub_util_exec_redirect_null ((const char * []){ "efibootmgr", "--version", NULL }))
{
/* TRANSLATORS: This message is shown when required executable `%s'
isn't found. */
grub_util_error (_("%s: not found"), "efibootmgr");
}
/* On Linux, we need the efivars kernel modules. */
#ifdef __linux__
grub_util_exec ((const char * []){ "modprobe", "-q", "efivars", NULL });
#endif
/* Delete old entries from the same distributor. */
grub_install_remove_efi_entries_by_distributor (efi_distributor);
char *efidir_part_str = xasprintf ("%d", efidir_part);
if (!verbosity)
grub_util_exec ((const char * []){ "efibootmgr", "-q",
"-c", "-d", efidir_disk,
"-p", efidir_part_str, "-w",
"-L", efi_distributor, "-l",
efifile_path, NULL });
else
grub_util_exec ((const char * []){ "efibootmgr",
"-c", "-d", efidir_disk,
"-p", efidir_part_str, "-w",
"-L", efi_distributor, "-l",
efifile_path, NULL });
free (efidir_part_str);
}
void
grub_install_register_ieee1275 (int is_prep, const char *install_device,
int partno, const char *relpath)
{
char *boot_device;
if (grub_util_exec_redirect_null ((const char * []){ "ofpathname", "--version", NULL }))
{
/* TRANSLATORS: This message is shown when required executable `%s'
isn't found. */
grub_util_error (_("%s: not found"), "ofpathname");
}
/* Get the Open Firmware device tree path translation. */
if (!is_prep)
{
char *ptr;
char *ofpath;
const char *iptr;
ofpath = get_ofpathname (install_device);
boot_device = xmalloc (strlen (ofpath) + 1
+ sizeof ("XXXXXXXXXXXXXXXXXXXX")
+ 1 + strlen (relpath) + 1);
ptr = grub_stpcpy (boot_device, ofpath);
*ptr++ = ':';
grub_snprintf (ptr, sizeof ("XXXXXXXXXXXXXXXXXXXX"), "%d",
partno);
ptr += strlen (ptr);
*ptr++ = ',';
for (iptr = relpath; *iptr; iptr++, ptr++)
{
if (*iptr == '/')
*ptr = '\\';
else
*ptr = *iptr;
}
*ptr = '\0';
}
else
boot_device = get_ofpathname (install_device);
if (grub_util_exec ((const char * []){ "nvsetenv", "boot-device",
boot_device, NULL }))
{
char *cmd = xasprintf ("setenv boot-device %s", boot_device);
grub_util_error ("`nvsetenv' failed. \nYou will have to set `boot-device' variable manually. At the IEEE1275 prompt, type:\n %s\n",
cmd);
free (cmd);
}
free (boot_device);
}
void
grub_install_sgi_setup (const char *install_device,
const char *imgfile, const char *destname)
{
grub_util_exec ((const char * []){ "dvhtool", "-d",
install_device, "--unix-to-vh",
imgfile, destname, NULL });
grub_util_warn ("%s", _("You will have to set `SystemPartition' and `OSLoader' manually."));
}

View File

@ -0,0 +1,57 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2004,2006,2007,2008,2009,2010,2011,2012,2013 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <config-util.h>
#include <grub/emu/hostfile.h>
#include <grub/emu/config.h>
#include <grub/util/install.h>
#include <grub/util/misc.h>
void
grub_util_load_config (struct grub_util_config *cfg)
{
const char *cfgfile;
FILE *f = NULL;
const char *v;
cfgfile = grub_util_get_config_filename ();
if (!grub_util_is_regular (cfgfile))
return;
memset (cfg, 0, sizeof (*cfg));
v = getenv ("GRUB_ENABLE_CRYPTODISK");
if (v && v[0] == 'y' && v[1] == '\0')
cfg->is_cryptodisk_enabled = 1;
v = getenv ("GRUB_DISTRIBUTOR");
if (v)
cfg->grub_distributor = xstrdup (v);
f = grub_util_fopen (cfgfile, "r");
if (f)
{
grub_util_parse_config (f, cfg, 0);
fclose (f);
}
else
grub_util_warn (_("cannot open config file `%s': %s"),
cfgfile, strerror (errno));
}

View File

@ -46,6 +46,7 @@
#include <windows.h>
#include <winioctl.h>
#include <wincrypt.h>
#if SIZEOF_TCHAR == 1
@ -411,6 +412,89 @@ grub_util_unlink (const char *name)
return ret;
}
int
grub_util_rmdir (const char *name)
{
LPTSTR name_windows;
int ret;
name_windows = grub_util_get_windows_path (name);
ret = !RemoveDirectory (name_windows);
free (name_windows);
return ret;
}
static char *
get_temp_name (void)
{
TCHAR rt[1024];
TCHAR *ptr;
HCRYPTPROV hCryptProv;
grub_uint8_t rnd[5];
const size_t sz = sizeof (rnd) * GRUB_CHAR_BIT / 5;
int i;
GetTempPath (ARRAY_SIZE (rt) - 100, rt);
if (!CryptAcquireContext (&hCryptProv,
NULL,
MS_DEF_PROV,
PROV_RSA_FULL,
CRYPT_VERIFYCONTEXT)
|| !CryptGenRandom (hCryptProv, 5, rnd))
grub_util_error ("%s", _("couldn't retrieve random data"));
CryptReleaseContext (hCryptProv, 0);
for (ptr = rt; *ptr; ptr++);
memcpy (ptr, TEXT("\\GRUB."), sizeof (TEXT("\\GRUB.")));
ptr += sizeof ("\\GRUB.") - 1;
for (i = 0; i < 8; i++)
{
grub_size_t b = i * 5;
grub_uint8_t r;
grub_size_t f1 = GRUB_CHAR_BIT - b % GRUB_CHAR_BIT;
grub_size_t f2;
if (f1 > 5)
f1 = 5;
f2 = 5 - f1;
r = (rnd[b / GRUB_CHAR_BIT] >> (b % GRUB_CHAR_BIT)) & ((1 << f1) - 1);
if (f2)
r |= (rnd[b / GRUB_CHAR_BIT + 1] & ((1 << f2) - 1)) << f1;
if (r < 10)
*ptr++ = '0' + r;
else
*ptr++ = 'a' + (r - 10);
}
*ptr = '\0';
return grub_util_tchar_to_utf8 (rt);
}
char *
grub_util_make_temporary_file (void)
{
char *ret = get_temp_name ();
FILE *f;
f = grub_util_fopen (ret, "wb");
if (f)
fclose (f);
return ret;
}
char *
grub_util_make_temporary_dir (void)
{
char *ret = get_temp_name ();
grub_util_mkdir (ret);
return ret;
}
int
grub_util_is_directory (const char *name)
{
@ -444,6 +528,33 @@ grub_util_is_regular (const char *name)
&& !(attr & FILE_ATTRIBUTE_REPARSE_POINT) && attr;
}
grub_uint32_t
grub_util_get_mtime (const char *path)
{
LPTSTR name_windows;
BOOL b;
WIN32_FILE_ATTRIBUTE_DATA attr;
ULARGE_INTEGER us_ul;
name_windows = grub_util_get_windows_path (path);
if (!name_windows)
return 0;
b = GetFileAttributesEx (name_windows, GetFileExInfoStandard, &attr);
grub_free (name_windows);
if (!b)
return 0;
us_ul.LowPart = attr.ftLastWriteTime.dwLowDateTime;
us_ul.HighPart = attr.ftLastWriteTime.dwHighDateTime;
return (us_ul.QuadPart / 10000000)
- 86400ULL * 365 * (1970 - 1601)
- 86400ULL * ((1970 - 1601) / 4) + 86400ULL * ((1970 - 1601) / 100);
}
#ifdef __MINGW32__
FILE *

View File

@ -21,6 +21,7 @@
#include <grub/util/misc.h>
#include <grub/osdep/hostfile.h>
#include <grub/util/windows.h>
#include <grub/emu/config.h>
#include <wincon.h>
#include <windows.h>
@ -111,10 +112,42 @@ set_console_unicode_font (void)
}
}
static char *grub_util_base_directory;
static char *locale_dir;
const char *
grub_util_get_config_filename (void)
{
static char *value = NULL;
if (!value)
value = grub_util_path_concat (2, grub_util_base_directory, "grub.cfg");
return value;
}
const char *
grub_util_get_pkgdatadir (void)
{
return grub_util_base_directory;
}
const char *
grub_util_get_localedir (void)
{
return locale_dir;
}
const char *
grub_util_get_pkglibdir (void)
{
return grub_util_base_directory;
}
void
grub_util_host_init (int *argc __attribute__ ((unused)),
char ***argv)
{
char *ptr;
SetConsoleOutputCP (CP_UTF8);
SetConsoleCP (CP_UTF8);
@ -137,9 +170,21 @@ grub_util_host_init (int *argc __attribute__ ((unused)),
#error "Unsupported TCHAR size"
#endif
grub_util_base_directory = canonicalize_file_name ((*argv)[0]);
if (!grub_util_base_directory)
grub_util_base_directory = xstrdup ((*argv)[0]);
for (ptr = grub_util_base_directory + strlen (grub_util_base_directory) - 1;
ptr >= grub_util_base_directory && *ptr != '/' && *ptr != '\\'; ptr--);
if (ptr >= grub_util_base_directory)
*ptr = '\0';
locale_dir = grub_util_path_concat (2, grub_util_base_directory, "locale");
set_program_name ((*argv)[0]);
#ifdef GRUB_UTIL
grub_util_init_nls ();
#endif
#if (defined (GRUB_UTIL) && defined(ENABLE_NLS) && ENABLE_NLS)
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, locale_dir);
textdomain (PACKAGE);
#endif /* (defined(ENABLE_NLS) && ENABLE_NLS) */
}

View File

@ -31,9 +31,9 @@
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wsign-compare"
#define yyfree grub_lexer_yyfree
#define yyalloc grub_lexer_yyalloc
#define yyrealloc grub_lexer_yyrealloc
#define yyalloc(size, scanner) (grub_malloc((size)))
#define yyfree(ptr, scanner) (grub_free((ptr)))
#define yyrealloc(ptr, size, scanner) (grub_realloc((ptr), (size)))
/*
* As we don't have access to yyscanner, we cannot do much except to
@ -68,9 +68,6 @@
static int grub_lexer_unput (const char *input, yyscan_t yyscanner);
static int grub_lexer_resplit (const char *input, yyscan_t yyscanner);
static void grub_lexer_yyfree (void *, yyscan_t yyscanner);
static void* grub_lexer_yyalloc (yy_size_t, yyscan_t yyscanner);
static void* grub_lexer_yyrealloc (void*, yy_size_t, yyscan_t yyscanner);
static void copy_string (struct grub_parser_param *, const char *,
unsigned hint);
@ -339,25 +336,6 @@ yywrap (yyscan_t yyscanner)
return grub_script_lexer_yywrap (yyget_extra (yyscanner), 0);
}
static void
grub_lexer_yyfree (void *ptr, yyscan_t yyscanner __attribute__ ((unused)))
{
grub_free(ptr);
}
static void*
grub_lexer_yyalloc (yy_size_t size, yyscan_t yyscanner __attribute__ ((unused)))
{
return grub_malloc (size);
}
static void*
grub_lexer_yyrealloc (void *ptr, yy_size_t size,
yyscan_t yyscanner __attribute__ ((unused)))
{
return grub_realloc (ptr, size);
}
static void copy_string (struct grub_parser_param *parser, const char *str, unsigned hint)
{
grub_size_t size;

View File

@ -748,8 +748,8 @@ grub_cmd_terminfo (grub_extcmd_context_t ctxt, int argc, char **args)
{
struct grub_terminfo_output_state *data
= (struct grub_terminfo_output_state *) cur->data;
data->pos.x = w;
data->pos.y = h;
data->size.x = w;
data->size.y = h;
}
if (argc == 1)

View File

@ -66,16 +66,25 @@ struct grub_procfs_entry test_txt =
.get_contents = get_test_txt
};
#define FONT_NAME "Unknown Regular 16"
/* Functional test main method. */
static void
cmdline_cat_test (void)
{
unsigned i;
grub_font_t font;
grub_dl_load ("gfxterm");
grub_errno = GRUB_ERR_NONE;
if (grub_font_load ("unicode") == 0)
font = grub_font_get (FONT_NAME);
if (font && grub_strcmp (font->name, FONT_NAME) != 0)
font = 0;
if (!font)
font = grub_font_load ("unicode");
if (!font)
{
grub_test_assert (0, "unicode font not found: %s", grub_errmsg);
return;

View File

@ -91,17 +91,30 @@ struct
{ "gfxterm_high", "menu_color_highlight", "blue/red" },
};
#define FONT_NAME "Unknown Regular 16"
/* Functional test main method. */
static void
gfxterm_menu (void)
{
unsigned i, j;
grub_font_t font;
grub_dl_load ("png");
grub_dl_load ("gettext");
grub_dl_load ("gfxterm");
if (grub_font_load ("unicode") == 0)
grub_errno = GRUB_ERR_NONE;
grub_dl_load ("gfxmenu");
font = grub_font_get (FONT_NAME);
if (font && grub_strcmp (font->name, FONT_NAME) != 0)
font = 0;
if (!font)
font = grub_font_load ("unicode");
if (!font)
{
grub_test_assert (0, "unicode font not found: %s", grub_errmsg);
return;
@ -112,7 +125,16 @@ gfxterm_menu (void)
for (j = 0; j < ARRAY_SIZE (tests); j++)
for (i = 0; i < GRUB_TEST_VIDEO_SMALL_N_MODES; i++)
{
grub_uint64_t start = grub_get_time_ms ();
grub_uint64_t start;
#if defined (GRUB_MACHINE_MIPS_QEMU_MIPS) || defined (GRUB_MACHINE_IEEE1275)
if (grub_test_video_modes[i].width > 1024)
continue;
if (grub_strcmp (tests[j].name, "gfxmenu") == 0
&& grub_test_video_modes[i].width > 800)
continue;
#endif
start = grub_get_time_ms ();
grub_video_capture_start (&grub_test_video_modes[i],
grub_video_fbstd_colors,

View File

@ -26,13 +26,22 @@
GRUB_MOD_LICENSE ("GPLv3+");
#define FONT_NAME "Unknown Regular 16"
/* Functional test main method. */
static void
videotest_checksum (void)
{
unsigned i;
grub_font_t font;
if (grub_font_load ("unicode") == 0)
font = grub_font_get (FONT_NAME);
if (font && grub_strcmp (font->name, FONT_NAME) != 0)
font = 0;
if (!font)
font = grub_font_load ("unicode");
if (!font)
{
grub_test_assert (0, "unicode font not found: %s", grub_errmsg);
return;
@ -40,9 +49,20 @@ videotest_checksum (void)
for (i = 0; i < ARRAY_SIZE (grub_test_video_modes); i++)
{
grub_video_capture_start (&grub_test_video_modes[i],
grub_video_fbstd_colors,
grub_test_video_modes[i].number_of_colors);
grub_err_t err;
#if defined (GRUB_MACHINE_MIPS_QEMU_MIPS) || defined (GRUB_MACHINE_IEEE1275)
if (grub_test_video_modes[i].width > 1024)
continue;
#endif
err = grub_video_capture_start (&grub_test_video_modes[i],
grub_video_fbstd_colors,
grub_test_video_modes[i].number_of_colors);
if (err)
{
grub_test_assert (0, "can't start capture: %s", grub_errmsg);
grub_print_error ();
continue;
}
grub_terminal_input_fake_sequence ((int []) { '\n' }, 1);
grub_video_checksum ("videotest");

48
include/grub/emu/config.h Normal file
View File

@ -0,0 +1,48 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2013 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/>.
*/
#ifndef GRUB_CONFIG_EMU_HEADER
#define GRUB_CONFIG_EMU_HEADER 1
#include <grub/disk.h>
#include <grub/partition.h>
#include <grub/emu/hostfile.h>
#include <stdio.h>
const char *
grub_util_get_config_filename (void);
const char *
grub_util_get_pkgdatadir (void);
const char *
grub_util_get_pkglibdir (void);
const char *
grub_util_get_localedir (void);
struct grub_util_config
{
int is_cryptodisk_enabled;
char *grub_distributor;
};
void
grub_util_load_config (struct grub_util_config *cfg);
void
grub_util_parse_config (FILE *f, struct grub_util_config *cfg, int simple);
#endif

View File

@ -20,8 +20,10 @@
#define GRUB_UTIL_GETROOT_HEADER 1
#include <grub/types.h>
#include <grub/device.h>
#include <sys/types.h>
#include <stdio.h>
enum grub_dev_abstraction_types {
GRUB_DEV_ABSTRACTION_NONE,
@ -89,4 +91,14 @@ grub_util_get_grub_dev_os (const char *os_dev);
grub_disk_addr_t
grub_util_find_partition_start_os (const char *dev);
char *
grub_util_guess_bios_drive (const char *orig_path);
char *
grub_util_guess_efi_drive (const char *orig_path);
char *
grub_util_guess_baremetal_drive (const char *orig_path);
void
grub_util_fprint_full_disk_name (FILE *f,
const char *drive, grub_device_t dev);
#endif /* ! GRUB_UTIL_GETROOT_HEADER */

View File

@ -31,6 +31,11 @@ grub_util_is_special_file (const char *path);
int
grub_util_is_regular (const char *path);
char *
grub_util_path_concat (size_t n, ...);
char *
grub_util_path_concat_ext (size_t n, ...);
int
grub_util_fd_seek (grub_util_fd_t fd, grub_uint64_t off);
ssize_t
@ -49,5 +54,13 @@ EXPORT_FUNC(grub_util_fd_close) (grub_util_fd_t fd);
grub_uint64_t
grub_util_get_fd_size (grub_util_fd_t fd, const char *name, unsigned *log_secsize);
char *
grub_util_make_temporary_file (void);
char *
grub_util_make_temporary_dir (void);
void
grub_util_unlink_recursive (const char *name);
grub_uint32_t
grub_util_get_mtime (const char *name);
#endif /* ! GRUB_BIOSDISK_MACHINE_UTIL_HEADER */

View File

@ -70,6 +70,8 @@ grub_pci_write_byte (grub_pci_address_t addr, grub_uint8_t data)
grub_outb (data, GRUB_PCI_DATA_REG + (addr & 3));
}
#ifndef GRUB_MACHINE_IEEE1275
static inline volatile void *
grub_pci_device_map_range (grub_pci_device_t dev __attribute__ ((unused)),
grub_addr_t base,
@ -85,5 +87,19 @@ grub_pci_device_unmap_range (grub_pci_device_t dev __attribute__ ((unused)),
{
}
#else
volatile void *
grub_pci_device_map_range (grub_pci_device_t dev,
grub_addr_t base,
grub_size_t size);
void
grub_pci_device_unmap_range (grub_pci_device_t dev,
volatile void *mem,
grub_size_t size);
#endif
#endif /* GRUB_CPU_PCI_H */

View File

@ -19,7 +19,7 @@
#ifndef GRUB_SETJMP_CPU_HEADER
#define GRUB_SETJMP_CPU_HEADER 1
typedef unsigned long grub_jmp_buf[11];
typedef unsigned long grub_jmp_buf[12];
int grub_setjmp (grub_jmp_buf env) RETURNS_TWICE;
void grub_longjmp (grub_jmp_buf env, int val) __attribute__ ((noreturn));

View File

@ -465,7 +465,7 @@ EXPORT_FUNC (__umodsi3) (grub_uint32_t a, grub_uint32_t b);
#endif
#if defined (__sparc64__) || defined (__powerpc__)
#if defined (__sparc__) || defined (__powerpc__)
unsigned
EXPORT_FUNC (__ctzdi2) (grub_uint64_t x);
#define NEED_CTZDI2 1

View File

@ -35,7 +35,7 @@ void EXPORT_FUNC(grub_free) (void *ptr);
void *EXPORT_FUNC(grub_realloc) (void *ptr, grub_size_t size);
void *EXPORT_FUNC(grub_memalign) (grub_size_t align, grub_size_t size);
void grub_mm_check_real (char *file, int line);
void grub_mm_check_real (const char *file, int line);
#define grub_mm_check() grub_mm_check_real (GRUB_FILE, __LINE__);
/* For debugging. */

View File

@ -0,0 +1,39 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2013 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/>.
*/
#ifndef GRUB_EMU_EXEC_H
#define GRUB_EMU_EXEC_H 1
#include <config.h>
#include <stdarg.h>
#include <sys/types.h>
pid_t
grub_util_exec_pipe (const char *const *argv, int *fd);
pid_t
grub_util_exec_pipe_stderr (const char *const *argv, int *fd);
int
grub_util_exec (const char *const *argv);
int
grub_util_exec_redirect (const char *const *argv, const char *stdin_file,
const char *stdout_file);
int
grub_util_exec_redirect_null (const char *const *argv);
#endif

View File

@ -50,6 +50,12 @@ grub_util_fd_readdir (grub_util_fd_dir_t dirp)
return readdir (dirp);
}
static inline int
grub_util_rmdir (const char *pathname)
{
return rmdir (pathname);
}
static inline int
grub_util_unlink (const char *pathname)
{
@ -62,7 +68,7 @@ grub_util_rename (const char *from, const char *to)
return rename (from, to);
}
#define grub_util_mkdir(a) mkdir (a)
#define grub_util_mkdir(a) mkdir (a, 0700)
struct grub_util_fd
{
@ -86,7 +92,7 @@ enum grub_util_fd_open_flags_t
GRUB_UTIL_FD_O_RDONLY = O_RDONLY,
GRUB_UTIL_FD_O_WRONLY = O_WRONLY,
GRUB_UTIL_FD_O_RDWR = O_RDWR,
GRUB_UTIL_FD_O_CREAT = O_CREAT,
GRUB_UTIL_FD_O_CREATTRUNC = O_CREAT | O_TRUNC,
GRUB_UTIL_FD_O_SYNC = (0
#ifdef O_SYNC
| O_SYNC

View File

@ -59,6 +59,12 @@ grub_util_unlink (const char *pathname)
return unlink (pathname);
}
static inline int
grub_util_rmdir (const char *pathname)
{
return rmdir (pathname);
}
static inline int
grub_util_rename (const char *from, const char *to)
{

View File

@ -55,6 +55,9 @@ grub_util_fd_closedir (grub_util_fd_dir_t dirp);
grub_util_fd_dirent_t
grub_util_fd_readdir (grub_util_fd_dir_t dirp);
int
grub_util_rmdir (const char *pathname);
enum grub_util_fd_open_flags_t
{
GRUB_UTIL_FD_O_RDONLY = 1,

View File

@ -19,7 +19,7 @@
#ifndef GRUB_SETJMP_CPU_HEADER
#define GRUB_SETJMP_CPU_HEADER 1
typedef unsigned long grub_jmp_buf[20];
typedef unsigned long grub_jmp_buf[21];
int grub_setjmp (grub_jmp_buf env) RETURNS_TWICE;
void grub_longjmp (grub_jmp_buf env, int val) __attribute__ ((noreturn));

View File

@ -26,6 +26,104 @@
#include <grub/disk.h>
#include <grub/emu/hostfile.h>
#define GRUB_INSTALL_OPTIONS \
{ "modules", GRUB_INSTALL_OPTIONS_MODULES, N_("MODULES"), \
0, N_("pre-load specified modules MODULES"), 1 }, \
{ "install-modules", GRUB_INSTALL_OPTIONS_INSTALL_MODULES, \
N_("MODULES"), 0, \
N_("install only MODULES and their dependencies [default=all]"), 1 }, \
{ "themes", GRUB_INSTALL_OPTIONS_INSTALL_THEMES, N_("THEMES"), \
0, N_("install THEMES [default=%s]"), 1 }, \
{ "fonts", GRUB_INSTALL_OPTIONS_INSTALL_FONTS, N_("FONTS"), \
0, N_("install FONTS [default=%s]"), 1 }, \
{ "locales", GRUB_INSTALL_OPTIONS_INSTALL_LOCALES, N_("LOCALES"),\
0, N_("install only LOCALES [default=all]"), 1 }, \
{ "compress", GRUB_INSTALL_OPTIONS_INSTALL_COMPRESS, \
"no,xz,gz,lzo", OPTION_ARG_OPTIONAL, \
N_("compress GRUB files [optional]"), 1 }, \
/* TRANSLATORS: platform here isn't identifier. It can be translated. */ \
{ "directory", 'd', N_("DIR"), 0, \
N_("use images and modules under DIR [default=%s/<platform>]"), 1 }, \
{ "override-directory", GRUB_INSTALL_OPTIONS_DIRECTORY2, \
N_("DIR"), OPTION_HIDDEN, \
N_("use images and modules under DIR [default=%s/<platform>]"), 1 }, \
{ "grub-mkimage", GRUB_INSTALL_OPTIONS_GRUB_MKIMAGE, \
"FILE", OPTION_HIDDEN, 0, 1 }, \
/* TRANSLATORS: "embed" is a verb (command description). "*/ \
{ "pubkey", 'k', N_("FILE"), 0, \
N_("embed FILE as public key for signature checking"), 0}, \
{ "verbose", 'v', 0, 0, \
N_("increase verbosity"), 1 }
int
grub_install_parse (int key, char *arg);
void
grub_install_push_module (const char *val);
void
grub_install_pop_module (void);
char *
grub_install_help_filter (int key, const char *text,
void *input __attribute__ ((unused)));
enum grub_install_plat
{
GRUB_INSTALL_PLATFORM_I386_PC,
GRUB_INSTALL_PLATFORM_I386_EFI,
GRUB_INSTALL_PLATFORM_I386_QEMU,
GRUB_INSTALL_PLATFORM_I386_COREBOOT,
GRUB_INSTALL_PLATFORM_I386_MULTIBOOT,
GRUB_INSTALL_PLATFORM_I386_IEEE1275,
GRUB_INSTALL_PLATFORM_X86_64_EFI,
GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON,
GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275,
GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275,
GRUB_INSTALL_PLATFORM_MIPSEL_ARC,
GRUB_INSTALL_PLATFORM_MIPS_ARC,
GRUB_INSTALL_PLATFORM_IA64_EFI,
GRUB_INSTALL_PLATFORM_ARM_UBOOT,
GRUB_INSTALL_PLATFORM_ARM_EFI,
GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS,
GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS,
GRUB_INSTALL_PLATFORM_MAX
};
enum grub_install_options {
GRUB_INSTALL_OPTIONS_DIRECTORY = 'd',
GRUB_INSTALL_OPTIONS_VERBOSITY = 'v',
GRUB_INSTALL_OPTIONS_MODULES = 0x201,
GRUB_INSTALL_OPTIONS_INSTALL_MODULES,
GRUB_INSTALL_OPTIONS_INSTALL_THEMES,
GRUB_INSTALL_OPTIONS_INSTALL_FONTS,
GRUB_INSTALL_OPTIONS_INSTALL_LOCALES,
GRUB_INSTALL_OPTIONS_INSTALL_COMPRESS,
GRUB_INSTALL_OPTIONS_DIRECTORY2,
GRUB_INSTALL_OPTIONS_GRUB_MKIMAGE
};
extern char *grub_install_source_directory;
enum grub_install_plat
grub_install_get_target (const char *src);
void
grub_install_mkdir_p (const char *dst);
void
grub_install_copy_files (const char *src,
const char *dst,
enum grub_install_plat platid);
char *
grub_install_get_platform_name (enum grub_install_plat platid);
const char *
grub_install_get_platform_cpu (enum grub_install_plat platid);
const char *
grub_install_get_platform_platform (enum grub_install_plat platid);
typedef enum {
GRUB_COMPRESSION_AUTO,
GRUB_COMPRESSION_NONE,
@ -33,6 +131,25 @@ typedef enum {
GRUB_COMPRESSION_LZMA
} grub_compression_t;
void
grub_install_make_image_wrap (const char *dir, const char *prefix,
const char *outname, char *memdisk_path,
char *config_path,
const char *format, int note,
grub_compression_t comp);
void
grub_install_make_image_wrap_file (const char *dir, const char *prefix,
FILE *fp, const char *outname,
char *memdisk_path,
char *config_path,
const char *mkimage_target, int note,
grub_compression_t comp);
int
grub_install_copy_file (const char *src,
const char *dst,
int is_critical);
struct grub_install_image_target_desc;
void
@ -66,6 +183,32 @@ grub_install_get_image_targets_string (void);
const char *
grub_util_get_target_dirname (const struct grub_install_image_target_desc *t);
void
grub_install_create_envblk_file (const char *name);
const char *
grub_install_get_default_x86_platform (void);
void
grub_install_register_efi (const char *efidir_disk, int efidir_part,
const char *efifile_path,
const char *efi_distributor);
void
grub_install_register_ieee1275 (int is_prep, const char *install_device,
int partno, const char *relpath);
void
grub_install_sgi_setup (const char *install_device,
const char *imgfile, const char *destname);
int
grub_install_compress_gzip (const char *src, const char *dest);
int
grub_install_compress_lzop (const char *src, const char *dest);
int
grub_install_compress_xz (const char *src, const char *dest);
void
grub_install_get_blocklist (grub_device_t root_dev,
const char *core_path, const char *core_img,
@ -89,4 +232,10 @@ grub_util_render_label (const char *label_font,
const char *label_string,
const char *label);
const char *
grub_util_get_target_name (const struct grub_install_image_target_desc *t);
extern char *grub_install_copy_buffer;
#define GRUB_INSTALL_COPY_BUFFER_SIZE 1048576
#endif

View File

@ -68,10 +68,10 @@ UPDATEPOFILES = @UPDATEPOFILES@
DUMMYPOFILES = @DUMMYPOFILES@
DISTFILES.common = Makefile.in.in remove-potcdate.sin \
$(DISTFILES.common.extra1) $(DISTFILES.common.extra2) \
$(DISTFILES.common.extra3) $(DISTFILES.common.extra4)
$(DISTFILES.common.extra3) $(DISTFILES.common.extra4) $(DISTFILES.common.extra5)
DISTFILES = $(DISTFILES.common) Makevars POTFILES.in POTFILES-shell.in \
$(POFILES) $(GMOFILES) \
$(DISTFILES.extra1) $(DISTFILES.extra2) $(DISTFILES.extra3) $(DISTFILES.extra4) grub.d.sed README
$(DISTFILES.extra1) $(DISTFILES.extra2) $(DISTFILES.extra3) $(DISTFILES.extra4) $(DISTFILES.extra5) grub.d.sed README
POTFILES = \

11
po/Rules-windowsdir Normal file
View File

@ -0,0 +1,11 @@
# generate windowsdir
DISTFILES.common.extra5 = Rules-windowsdir
windowsdir="$(top_builddir)/$(PACKAGE)-$(VERSION)-for-windows"
windowsdir: $(GMOFILES)
test -d "$(windowsdir)/locale" || mkdir "$(windowsdir)/locale"
for x in $(CATALOGS); do \
test -d "$(windowsdir)/locale/$${x%.gmo}" || mkdir "$(windowsdir)/locale/$${x%.gmo}"; \
cp -fp "$(srcdir)/$$x" "$(windowsdir)/locale/$${x%.gmo}/grub.mo"; \
done

View File

@ -27,10 +27,10 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
esac
if [ "$(echo hello | "${grubshell}" --grub-mkimage-extra=-C --grub-mkimage-extra=xz)" != "Hello World" ]; then
if [ "$(echo hello | "${grubshell}" --grub-mkimage-extra=--compress=xz)" != "Hello World" ]; then
exit 1
fi
if [ "$(echo hello | "${grubshell}" --grub-mkimage-extra=-C --grub-mkimage-extra=none)" != "Hello World" ]; then
if [ "$(echo hello | "${grubshell}" --grub-mkimage-extra=--compress=none)" != "Hello World" ]; then
exit 1
fi

View File

@ -3,8 +3,16 @@ set -e
. "@builddir@/grub-core/modinfo.sh"
case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
# PLATFORM: Max RAM is 256M
mips-qemu_mips | mipsel-qemu_mips)
mem=256M;;
*)
mem=512M;;
esac
# Increase memory as some of tests are high-resolution and need a lot of memory.
out=`echo all_functional_test | @builddir@/grub-shell --timeout=3600 --files="/boot/grub/fonts/unicode.pf2"="@builddir@/"unicode.pf2 --qemu-opts="-m 512"`
out=`echo all_functional_test | @builddir@/grub-shell --timeout=3600 --files="/boot/grub/fonts/unicode.pf2"="@builddir@/"unicode.pf2 --qemu-opts="-m $mem"`
if [ "$(echo "$out" | tail -n 1)" != "ALL TESTS PASSED" ]; then
echo "Functional test failure: $out"

View File

@ -19,6 +19,11 @@ grubshell=@builddir@/grub-shell
. "@builddir@/grub-core/modinfo.sh"
if ! which gzip >/dev/null 2>&1; then
echo "gzip not installed; cannot test gzip compression."
exit 77
fi
if [ "$(echo hello | "${grubshell}" --mkrescue-arg=--compress=gz)" != "Hello World" ]; then
exit 1
fi

View File

@ -19,6 +19,11 @@ grubshell=@builddir@/grub-shell
. "@builddir@/grub-core/modinfo.sh"
if ! which lzop >/dev/null 2>&1; then
echo "lzop not installed; cannot test lzo compression."
exit 77
fi
if [ "$(echo hello | "${grubshell}" --mkrescue-arg=--compress=lzo)" != "Hello World" ]; then
exit 1
fi

View File

@ -79,7 +79,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
boot=hd
qemu=qemu-system-ppc
console=console
serial_port=escc-ch-a
serial_port=escc-ch-b
serial_null="-serial null"
netbootext=elf
;;
@ -211,6 +211,7 @@ for option in "$@"; do
serial_null=
qemuopts="$qemuopts -M pseries -no-reboot"
trim=1
pseries=y
;;
--qemu-opts=*)
qs=`echo "$option" | sed -e 's/--qemu-opts=//'`
@ -306,7 +307,7 @@ else
fi
cat <<EOF >>${cfgfile}
terminfo -g 255x255 ${term} dumb
terminfo -g 1024x1024 ${term} dumb
terminal_input ${term}
terminal_output ${term}
EOF
@ -347,46 +348,50 @@ fi
if [ x$boot != xnet ] && [ x$boot != xemu ]; then
cp -R "@srcdir@/themes" "@builddir@"
pkgdatadir="@builddir@" sh "@builddir@/grub-mkrescue" "--grub-mkimage=${builddir}/grub-mkimage" "--grub-render-label=${builddir}/grub-render-label" "--output=${isofile}" "--override-directory=${builddir}/grub-core" \
--rom-directory="${rom_directory}" "--grub-mkimage-extra=$mkimage_extra_arg" ${mkrescue_args} \
pkgdatadir="@builddir@" "@builddir@/grub-mkrescue" "--output=${isofile}" "--override-directory=${builddir}/grub-core" \
--rom-directory="${rom_directory}" $mkimage_extra_arg ${mkrescue_args} \
"/boot/grub/grub.cfg=${cfgfile}" "/boot/grub/testcase.cfg=${source}" \
${files} >/dev/null 2>&1
fi
if [ x$boot = xhd ]; then
if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = mips-arc ]; then
device=hdb
device="hdb "
else
device=hda
device="hda "
fi
bootdev="-boot c"
fi
if [ x$boot = xcd ]; then
device=cdrom
if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = powerpc-ieee1275 ] && [ x$pseries != xy ] ; then
device="-drive if=ide,media=cdrom,file="
else
device="cdrom "
fi
bootdev="-boot d"
fi
if [ x$boot = xfd ]; then
device=fda
device="fda "
bootdev="-boot a"
fi
if [ x$boot = xqemu ]; then
bootdev="-bios ${rom_directory}/qemu.img"
device=cdrom
device="cdrom "
fi
if [ x$boot = xmipsel_qemu ]; then
bootdev="-kernel ${rom_directory}/mipsel-qemu_mips.elf"
device=cdrom
device="cdrom "
fi
if [ x$boot = xmipsel_fulong2e ]; then
bootdev="-kernel ${rom_directory}/mipsel-loongson.elf -append machtype=lemote-fuloong-2e"
device=cdrom
device="cdrom "
fi
if [ x$boot = xmips_qemu ]; then
bootdev="-kernel ${rom_directory}/mips-qemu_mips.elf"
device=cdrom
device="cdrom "
fi
if [ x$boot = xcoreboot ]; then
@ -394,7 +399,7 @@ if [ x$boot = xcoreboot ]; then
cp "${GRUB_COREBOOT_ROM}" "${imgfile}"
"${GRUB_CBFSTOOL}" "${imgfile}" add-payload "${rom_directory}/coreboot.elf" fallback/payload
bootdev="-bios ${imgfile}"
device=cdrom
device="cdrom "
test -z "$debug" || echo "Coreboot image: ${imgfile}" >&2
fi
@ -418,7 +423,7 @@ do_trim ()
if [ x$boot = xnet ]; then
netdir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
pkgdatadir="@builddir@" sh "@builddir@/grub-mknetdir" "--grub-mkimage=${builddir}/grub-mkimage" "--directory=${builddir}/grub-core" "--net-directory=$netdir" ${mkrescue_args} > /dev/null
pkgdatadir="@builddir@" "@builddir@/grub-mknetdir" "--grub-mkimage=${builddir}/grub-mkimage" "--directory=${builddir}/grub-core" "--net-directory=$netdir" ${mkrescue_args} > /dev/null
cp "${cfgfile}" "$netdir/boot/grub/grub.cfg"
cp "${source}" "$netdir/boot/grub/testcase.cfg"
timeout -s KILL $timeout "${qemu}" ${qemuopts} ${serial_null} -serial file:/dev/stdout -boot n -net "user,tftp=$netdir,bootfile=/boot/grub/${grub_modinfo_target_cpu}-${grub_modinfo_platform}/core.$netbootext" -net nic | cat | tr -d "\r" | do_trim
@ -429,13 +434,17 @@ elif [ x$boot = xemu ]; then
mkdir -p "$grubdir/locale"
cp "@builddir@/"unicode.pf2 "$grubdir/fonts/unicode.pf2"
cp -R "@srcdir@/themes/starfield" "$grubdir/themes/starfield"
cp -R "@srcdir@/po/"*.gmo "$grubdir/locale/"
for file in "@srcdir@/po/"*.gmo; do
if [ -f "$file" ]; then
cp "$file" "$grubdir/locale/"
fi
done
cp "${cfgfile}" "$grubdir/grub.cfg"
cp "${source}" "$grubdir/testcase.cfg"
@builddir@/grub-core/grub-emu -m "$device_map" -d "$grubdir" | tr -d "\r" | do_trim
rm -rf "$grubdir"
else
timeout -s KILL $timeout "${qemu}" ${qemuopts} ${serial_null} -serial file:/dev/stdout -${device} ${isofile} ${bootdev} | cat | tr -d "\r" | do_trim
timeout -s KILL $timeout "${qemu}" ${qemuopts} ${serial_null} -serial file:/dev/stdout -${device}"${isofile}" ${bootdev} | cat | tr -d "\r" | do_trim
fi
if [ x$boot = xcoreboot ]; then
test -n "$debug" || rm -f "${imgfile}"

View File

@ -19,6 +19,11 @@ grubshell=@builddir@/grub-shell
. "@builddir@/grub-core/modinfo.sh"
if ! which xz >/dev/null 2>&1; then
echo "xz not installed; cannot test xz compression."
exit 77
fi
if [ "$(echo hello | "${grubshell}" --mkrescue-arg=--compress=xz)" != "Hello World" ]; then
exit 1
fi

112
util/config.c Normal file
View File

@ -0,0 +1,112 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2013 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <string.h>
#include <grub/emu/config.h>
#include <grub/util/misc.h>
void
grub_util_parse_config (FILE *f, struct grub_util_config *cfg, int simple)
{
char *buffer = NULL;
size_t sz = 0;
while (getline (&buffer, &sz, f) >= 0)
{
const char *ptr;
for (ptr = buffer; *ptr && grub_isspace (*ptr); ptr++);
if (grub_strncmp (ptr, "GRUB_ENABLE_CRYPTODISK=",
sizeof ("GRUB_ENABLE_CRYPTODISK=") - 1) == 0)
{
ptr += sizeof ("GRUB_ENABLE_CRYPTODISK=") - 1;
if (*ptr == '"' || *ptr == '\'')
ptr++;
if (*ptr == 'y')
cfg->is_cryptodisk_enabled = 1;
continue;
}
if (grub_strncmp (ptr, "GRUB_DISTRIBUTOR=",
sizeof ("GRUB_DISTRIBUTOR=") - 1) == 0)
{
char *optr;
enum { NONE, SNGLQUOT, DBLQUOT } state;
if (simple)
{
free (cfg->grub_distributor);
cfg->grub_distributor = xstrdup (ptr);
continue;
}
free (cfg->grub_distributor);
cfg->grub_distributor = xmalloc (strlen (ptr) + 1);
optr = cfg->grub_distributor;
state = NONE;
for (; *ptr; ptr++)
switch (*ptr)
{
case '\\':
if (state == SNGLQUOT)
{
*optr++ = *ptr;
continue;
}
if (ptr[1])
{
*optr++ = ptr[1];
ptr++;
continue;
}
ptr++;
break;
case '"':
if (state == NONE)
{
state = DBLQUOT;
continue;
}
if (state == DBLQUOT)
{
state = NONE;
continue;
}
*optr++ = *ptr;
continue;
case '\'':
if (state == SNGLQUOT)
{
state = NONE;
continue;
}
if (state == NONE)
{
state = SNGLQUOT;
continue;
}
*optr++ = *ptr;
continue;
default:
*optr++ = *ptr;
continue;
}
*optr = '\0';
}
}
}

897
util/grub-install-common.c Normal file
View File

@ -0,0 +1,897 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <grub/types.h>
#include <grub/emu/misc.h>
#include <grub/util/misc.h>
#include <grub/misc.h>
#include <grub/device.h>
#include <grub/disk.h>
#include <grub/file.h>
#include <grub/fs.h>
#include <grub/env.h>
#include <grub/term.h>
#include <grub/mm.h>
#include <grub/lib/hexdump.h>
#include <grub/crypto.h>
#include <grub/command.h>
#include <grub/i18n.h>
#include <grub/zfs/zfs.h>
#include <grub/util/install.h>
#include <grub/util/resolve.h>
#include <grub/emu/hostfile.h>
#include <grub/emu/config.h>
#include <grub/emu/hostfile.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
char *
grub_install_help_filter (int key, const char *text,
void *input __attribute__ ((unused)))
{
switch (key)
{
case GRUB_INSTALL_OPTIONS_INSTALL_THEMES:
return xasprintf(text, "starfield");
case GRUB_INSTALL_OPTIONS_INSTALL_FONTS:
return xasprintf(text, "unicode");
case GRUB_INSTALL_OPTIONS_DIRECTORY:
case GRUB_INSTALL_OPTIONS_DIRECTORY2:
return xasprintf(text, grub_util_get_pkglibdir ());
default:
return (char *) text;
}
}
static int (*compress_func) (const char *src, const char *dest) = NULL;
char *grub_install_copy_buffer;
int
grub_install_copy_file (const char *src,
const char *dst,
int is_needed)
{
grub_util_fd_t in, out;
ssize_t r;
grub_util_info ("copying `%s' -> `%s'", src, dst);
in = grub_util_fd_open (src, GRUB_UTIL_FD_O_RDONLY);
if (!GRUB_UTIL_FD_IS_VALID (in))
{
if (is_needed)
grub_util_error (_("cannot open `%s': %s"), src, grub_util_fd_strerror ());
else
grub_util_info (_("cannot open `%s': %s"), src, grub_util_fd_strerror ());
return 0;
}
out = grub_util_fd_open (dst, GRUB_UTIL_FD_O_WRONLY
| GRUB_UTIL_FD_O_CREATTRUNC);
if (!GRUB_UTIL_FD_IS_VALID (out))
{
grub_util_error (_("cannot open `%s': %s"), dst,
grub_util_fd_strerror ());
grub_util_fd_close (in);
return 0;
}
if (!grub_install_copy_buffer)
grub_install_copy_buffer = xmalloc (GRUB_INSTALL_COPY_BUFFER_SIZE);
while (1)
{
r = grub_util_fd_read (in, grub_install_copy_buffer, GRUB_INSTALL_COPY_BUFFER_SIZE);
if (r <= 0)
break;
grub_util_fd_write (out, grub_install_copy_buffer, r);
}
grub_util_fd_sync (out);
grub_util_fd_close (in);
grub_util_fd_close (out);
if (r < 0)
grub_util_error ("cannot copy `%s' to `%s': %s",
src, dst, grub_util_fd_strerror ());
return 1;
}
int
grub_install_compress_file (const char *in_name,
const char *out_name,
int is_needed)
{
int ret;
if (!compress_func)
ret = grub_install_copy_file (in_name, out_name, is_needed);
else
{
grub_util_info ("compressing `%s' -> `%s'", in_name, out_name);
ret = !compress_func (in_name, out_name);
if (!ret && is_needed)
grub_util_warn ("can't compress `%s' to `%s'", in_name, out_name);
}
if (!ret && is_needed)
grub_util_error ("cannot copy `%s' to `%s': %s",
in_name, out_name, grub_util_fd_strerror ());
return ret;
}
static int
is_path_separator (char c)
{
#if defined (__MINGW32__) || defined (__CYGWIN__)
if (c == '\\')
return 1;
#endif
if (c == '/')
return 1;
return 0;
}
void
grub_install_mkdir_p (const char *dst)
{
char *t = xstrdup (dst);
char *p;
for (p = t; *p; p++)
{
if (is_path_separator (*p))
{
char s = *p;
*p = '\0';
grub_util_mkdir (t);
*p = s;
}
}
grub_util_mkdir (t);
free (t);
}
static void
clean_grub_dir (const char *di)
{
grub_util_fd_dir_t d;
grub_util_fd_dirent_t de;
d = grub_util_fd_opendir (di);
if (!d)
grub_util_error (_("cannot open directory `%s': %s"),
di, grub_util_fd_strerror ());
while ((de = grub_util_fd_readdir (d)))
{
const char *ext = strrchr (de->d_name, '.');
if ((ext && (strcmp (ext, ".mod") == 0
|| strcmp (ext, ".lst") == 0
|| strcmp (ext, ".img") == 0
|| strcmp (ext, ".mo") == 0)
&& strcmp (de->d_name, "menu.lst") != 0)
|| strcmp (de->d_name, "efiemu32.o") == 0
|| strcmp (de->d_name, "efiemu64.o") == 0)
{
char *x = grub_util_path_concat (2, di, de->d_name);
if (grub_util_unlink (x) < 0)
grub_util_error ("cannont delete `%s': %s", x,
grub_util_fd_strerror ());
free (x);
}
}
grub_util_fd_closedir (d);
}
struct install_list
{
int is_default;
char **entries;
size_t n_entries;
size_t n_alloc;
};
struct install_list install_modules = { 1, 0, 0, 0 };
struct install_list modules = { 1, 0, 0, 0 };
struct install_list install_locales = { 1, 0, 0, 0 };
struct install_list install_fonts = { 1, 0, 0, 0 };
struct install_list install_themes = { 1, 0, 0, 0 };
char *grub_install_source_directory = NULL;
void
grub_install_push_module (const char *val)
{
modules.is_default = 0;
if (modules.n_entries + 1 >= modules.n_alloc)
{
modules.n_alloc <<= 1;
if (modules.n_alloc < 16)
modules.n_alloc = 16;
modules.entries = xrealloc (modules.entries,
modules.n_alloc * sizeof (modules.entries));
}
modules.entries[modules.n_entries++] = xstrdup (val);
modules.entries[modules.n_entries] = NULL;
}
void
grub_install_pop_module (void)
{
modules.n_entries--;
free (modules.entries[modules.n_entries]);
modules.entries[modules.n_entries] = NULL;
}
static void
handle_install_list (struct install_list *il, const char *val,
int default_all)
{
const char *ptr;
char **ce;
il->is_default = 0;
free (il->entries);
il->entries = NULL;
il->n_entries = 0;
if (strcmp (val, "all") == 0 && default_all)
{
il->is_default = 1;
return;
}
ptr = val;
while (1)
{
while (*ptr && grub_isspace (*ptr))
ptr++;
if (!*ptr)
break;
while (*ptr && !grub_isspace (*ptr))
ptr++;
il->n_entries++;
}
il->n_alloc = il->n_entries + 1;
il->entries = xmalloc (il->n_alloc * sizeof (il->entries[0]));
ptr = val;
for (ce = il->entries; ; ce++)
{
const char *bptr;
while (*ptr && grub_isspace (*ptr))
ptr++;
if (!*ptr)
break;
bptr = ptr;
while (*ptr && !grub_isspace (*ptr))
ptr++;
*ce = xmalloc (ptr - bptr + 1);
memcpy (*ce, bptr, ptr - bptr);
(*ce)[ptr - bptr] = '\0';
}
*ce = NULL;
}
static char **pubkeys;
static size_t npubkeys;
int
grub_install_parse (int key, char *arg)
{
switch (key)
{
case 'k':
pubkeys = xrealloc (pubkeys,
sizeof (pubkeys[0])
* (npubkeys + 1));
pubkeys[npubkeys++] = xstrdup (arg);
return 1;
case GRUB_INSTALL_OPTIONS_VERBOSITY:
verbosity++;
return 1;
case GRUB_INSTALL_OPTIONS_DIRECTORY:
case GRUB_INSTALL_OPTIONS_DIRECTORY2:
free (grub_install_source_directory);
grub_install_source_directory = xstrdup (arg);
return 1;
case GRUB_INSTALL_OPTIONS_INSTALL_MODULES:
handle_install_list (&install_modules, arg, 0);
return 1;
case GRUB_INSTALL_OPTIONS_MODULES:
handle_install_list (&modules, arg, 0);
return 1;
case GRUB_INSTALL_OPTIONS_INSTALL_LOCALES:
handle_install_list (&install_locales, arg, 0);
return 1;
case GRUB_INSTALL_OPTIONS_INSTALL_THEMES:
handle_install_list (&install_themes, arg, 0);
return 1;
case GRUB_INSTALL_OPTIONS_INSTALL_FONTS:
handle_install_list (&install_fonts, arg, 0);
return 1;
case GRUB_INSTALL_OPTIONS_INSTALL_COMPRESS:
if (strcmp (arg, "no") == 0
|| strcmp (arg, "none") == 0)
{
compress_func = NULL;
return 1;
}
if (strcmp (arg, "gz") == 0)
{
compress_func = grub_install_compress_gzip;
return 1;
}
if (strcmp (arg, "xz") == 0)
{
compress_func = grub_install_compress_xz;
return 1;
}
if (strcmp (arg, "lzo") == 0)
{
compress_func = grub_install_compress_lzop;
return 1;
}
grub_util_error (_("Unrecognized compression `%s'"), arg);
case GRUB_INSTALL_OPTIONS_GRUB_MKIMAGE:
return 1;
default:
return 0;
}
}
static int
decompressors (void)
{
if (compress_func == grub_install_compress_gzip)
{
grub_install_push_module ("gzio");
return 1;
}
if (compress_func == grub_install_compress_xz)
{
grub_install_push_module ("xzio");
grub_install_push_module ("gcry_crc");
return 2;
}
if (compress_func == grub_install_compress_lzop)
{
grub_install_push_module ("lzopio");
grub_install_push_module ("adler32");
grub_install_push_module ("gcry_crc");
return 3;
}
return 0;
}
void
grub_install_make_image_wrap_file (const char *dir, const char *prefix,
FILE *fp, const char *outname,
char *memdisk_path,
char *config_path,
const char *mkimage_target, int note,
grub_compression_t comp)
{
const struct grub_install_image_target_desc *tgt;
const char *const compnames[] =
{
[GRUB_COMPRESSION_AUTO] = "auto",
[GRUB_COMPRESSION_NONE] = "none",
[GRUB_COMPRESSION_XZ] = "xz",
[GRUB_COMPRESSION_LZMA] = "lzma",
};
grub_size_t slen = 1;
char *s, *p;
char **pk, **md;
int dc = decompressors ();
if (memdisk_path)
slen += 20 + grub_strlen (memdisk_path);
if (config_path)
slen += 20 + grub_strlen (config_path);
for (pk = pubkeys; pk < pubkeys + npubkeys; pk++)
slen += 20 + grub_strlen (*pk);
for (md = modules.entries; *md; md++)
{
slen += 10 + grub_strlen (*md);
}
p = s = xmalloc (slen);
if (memdisk_path)
{
p = grub_stpcpy (p, "--memdisk '");
p = grub_stpcpy (p, memdisk_path);
*p++ = '\'';
*p++ = ' ';
}
if (config_path)
{
p = grub_stpcpy (p, "--config '");
p = grub_stpcpy (p, config_path);
*p++ = '\'';
*p++ = ' ';
}
for (pk = pubkeys; pk < pubkeys + npubkeys; pk++)
{
p = grub_stpcpy (p, "--pubkey '");
p = grub_stpcpy (p, *pk);
*p++ = '\'';
*p++ = ' ';
}
for (md = modules.entries; *md; md++)
{
*p++ = '\'';
p = grub_stpcpy (p, *md);
*p++ = '\'';
*p++ = ' ';
}
*p = '\0';
grub_util_info ("grub-mkimage --directory '%s' --prefix '%s'"
" --output '%s' "
"--format '%s' --compression '%s' %s %s\n",
dir, prefix,
outname, mkimage_target,
compnames[comp], note ? "--note" : "", s);
tgt = grub_install_get_image_target (mkimage_target);
if (!tgt)
grub_util_error (_("unknown target format %s\n"), mkimage_target);
grub_install_generate_image (dir, prefix, fp, outname,
modules.entries, memdisk_path,
pubkeys, npubkeys, config_path, tgt,
note, comp);
while (dc--)
grub_install_pop_module ();
}
void
grub_install_make_image_wrap (const char *dir, const char *prefix,
const char *outname, char *memdisk_path,
char *config_path,
const char *mkimage_target, int note,
grub_compression_t comp)
{
FILE *fp;
fp = grub_util_fopen (outname, "wb");
if (! fp)
grub_util_error (_("cannot open `%s': %s"), outname,
strerror (errno));
grub_install_make_image_wrap_file (dir, prefix, fp, outname,
memdisk_path, config_path,
mkimage_target, note, comp);
fflush (fp);
fsync (fileno (fp));
fclose (fp);
}
static void
copy_by_ext (const char *srcd,
const char *dstd,
const char *extf,
int req)
{
grub_util_fd_dir_t d;
grub_util_fd_dirent_t de;
d = grub_util_fd_opendir (srcd);
if (!d && !req)
return;
if (!d)
grub_util_error (_("cannot open directory `%s': %s"),
srcd, grub_util_fd_strerror ());
while ((de = grub_util_fd_readdir (d)))
{
const char *ext = strrchr (de->d_name, '.');
if (ext && strcmp (ext, extf) == 0)
{
char *srcf = grub_util_path_concat (2, srcd, de->d_name);
char *dstf = grub_util_path_concat (2, dstd, de->d_name);
grub_install_compress_file (srcf, dstf, 1);
free (srcf);
free (dstf);
}
}
grub_util_fd_closedir (d);
}
static void
copy_all (const char *srcd,
const char *dstd)
{
grub_util_fd_dir_t d;
grub_util_fd_dirent_t de;
d = grub_util_fd_opendir (srcd);
if (!d)
grub_util_error (_("cannot open directory `%s': %s"),
srcd, grub_util_fd_strerror ());
while ((de = grub_util_fd_readdir (d)))
{
char *srcf;
char *dstf;
if (strcmp (de->d_name, ".") == 0
|| strcmp (de->d_name, "..") == 0)
continue;
srcf = grub_util_path_concat (2, srcd, de->d_name);
if (grub_util_is_special_file (srcf)
|| grub_util_is_directory (srcf))
continue;
dstf = grub_util_path_concat (2, dstd, de->d_name);
grub_install_compress_file (srcf, dstf, 1);
free (srcf);
free (dstf);
}
grub_util_fd_closedir (d);
}
static void
copy_locales (const char *dstd, int langpack)
{
grub_util_fd_dir_t d;
grub_util_fd_dirent_t de;
const char *locale_dir = grub_util_get_localedir ();
char *dir;
if (langpack)
dir = xasprintf ("%s-langpack", locale_dir);
else
dir = xstrdup (locale_dir);
d = grub_util_fd_opendir (dir);
if (!d)
{
grub_util_warn (_("cannot open directory `%s': %s"),
dir, grub_util_fd_strerror ());
free (dir);
return;
}
while ((de = grub_util_fd_readdir (d)))
{
char *srcf;
char *dstf;
if (strcmp (de->d_name, ".") == 0)
continue;
if (strcmp (de->d_name, "..") == 0)
continue;
srcf = grub_util_path_concat_ext (4, dir, de->d_name,
"LC_MESSAGES", PACKAGE, ".mo");
dstf = grub_util_path_concat_ext (2, dstd, de->d_name, ".mo");
grub_install_compress_file (srcf, dstf, 0);
free (srcf);
free (dstf);
}
grub_util_fd_closedir (d);
free (dir);
}
static struct
{
const char *cpu;
const char *platform;
} platforms[GRUB_INSTALL_PLATFORM_MAX] =
{
[GRUB_INSTALL_PLATFORM_I386_PC] = { "i386", "pc" },
[GRUB_INSTALL_PLATFORM_I386_EFI] = { "i386", "efi" },
[GRUB_INSTALL_PLATFORM_I386_QEMU] = { "i386", "qemu" },
[GRUB_INSTALL_PLATFORM_I386_COREBOOT] = { "i386", "coreboot" },
[GRUB_INSTALL_PLATFORM_I386_MULTIBOOT] = { "i386", "multiboot" },
[GRUB_INSTALL_PLATFORM_I386_IEEE1275] = { "i386", "ieee1275" },
[GRUB_INSTALL_PLATFORM_X86_64_EFI] = { "x86_64", "efi" },
[GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON] = { "mipsel", "loongson" },
[GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS] = { "mipsel", "qemu_mips" },
[GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS] = { "mips", "qemu_mips" },
[GRUB_INSTALL_PLATFORM_MIPSEL_ARC] = { "mipsel", "arc" },
[GRUB_INSTALL_PLATFORM_MIPS_ARC] = { "mips", "arc" },
[GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275] = { "sparc64", "ieee1275" },
[GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275] = { "powerpc", "ieee1275" },
[GRUB_INSTALL_PLATFORM_IA64_EFI] = { "ia64", "efi" },
[GRUB_INSTALL_PLATFORM_ARM_EFI] = { "arm", "efi" },
[GRUB_INSTALL_PLATFORM_ARM_UBOOT] = { "arm", "uboot" },
};
char *
grub_install_get_platform_name (enum grub_install_plat platid)
{
return xasprintf ("%s-%s", platforms[platid].cpu,
platforms[platid].platform);
}
const char *
grub_install_get_platform_cpu (enum grub_install_plat platid)
{
return platforms[platid].cpu;
}
const char *
grub_install_get_platform_platform (enum grub_install_plat platid)
{
return platforms[platid].platform;
}
void
grub_install_copy_files (const char *src,
const char *dst,
enum grub_install_plat platid)
{
char *dst_platform, *dst_locale, *dst_fonts;
const char *pkgdatadir = grub_util_get_pkgdatadir ();
{
char *platform;
platform = xasprintf ("%s-%s", platforms[platid].cpu,
platforms[platid].platform);
dst_platform = grub_util_path_concat (2, dst, platform);
free (platform);
}
dst_locale = grub_util_path_concat (2, dst, "locale");
dst_fonts = grub_util_path_concat (2, dst, "fonts");
grub_install_mkdir_p (dst_platform);
grub_install_mkdir_p (dst_locale);
clean_grub_dir (dst);
clean_grub_dir (dst_platform);
clean_grub_dir (dst_locale);
if (install_modules.is_default)
copy_by_ext (src, dst_platform, ".mod", 1);
else
{
struct grub_util_path_list *path_list, *p;
path_list = grub_util_resolve_dependencies (src, "moddep.lst",
install_modules.entries);
for (p = path_list; p; p = p->next)
{
const char *srcf = p->name;
const char *dir;
char *dstf;
dir = grub_strrchr (srcf, '/');
if (dir)
dir++;
else
dir = srcf;
dstf = grub_util_path_concat (2, dst_platform, dir);
grub_install_compress_file (srcf, dstf, 1);
free (dstf);
}
}
const char *pkglib_DATA[] = {"efiemu32.o", "efiemu64.o",
"moddep.lst", "command.lst",
"fs.lst", "partmap.lst",
"parttool.lst",
"video.lst", "crypto.lst",
"terminal.lst" };
size_t i;
for (i = 0; i < ARRAY_SIZE (pkglib_DATA); i++)
{
char *srcf = grub_util_path_concat (2, src, pkglib_DATA[i]);
char *dstf = grub_util_path_concat (2, dst_platform, pkglib_DATA[i]);
if (i == 0 || i == 1)
grub_install_compress_file (srcf, dstf, 0);
else
grub_install_compress_file (srcf, dstf, 1);
free (srcf);
free (dstf);
}
if (install_locales.is_default)
{
char *srcd = grub_util_path_concat (2, src, "po");
copy_by_ext (srcd, dst_locale, ".mo", 0);
copy_locales (dst_locale, 0);
copy_locales (dst_locale, 1);
free (srcd);
}
else
{
const char *locale_dir = grub_util_get_localedir ();
char *locale_langpack_dir = xasprintf ("%s-langpack", locale_dir);
for (i = 0; i < install_locales.n_entries; i++)
{
char *srcf = grub_util_path_concat_ext (3, src,
"po",
install_locales.entries[i],
".mo");
char *dstf = grub_util_path_concat_ext (2, dst_locale,
install_locales.entries[i],
".mo");
if (grub_install_compress_file (srcf, dstf, 0))
{
free (srcf);
free (dstf);
continue;
}
free (srcf);
srcf = grub_util_path_concat_ext (4,
locale_langpack_dir,
install_locales.entries[i],
"LC_MESSAGES",
PACKAGE,
".mo");
if (grub_install_compress_file (srcf, dstf, 0))
{
free (srcf);
free (dstf);
continue;
}
free (srcf);
srcf = grub_util_path_concat_ext (4,
locale_dir,
install_locales.entries[i],
"LC_MESSAGES",
PACKAGE,
".mo");
if (grub_install_compress_file (srcf, dstf, 0))
{
free (srcf);
free (dstf);
continue;
}
grub_util_error (_("cannot find locale `%s'"),
install_locales.entries[i]);
}
free (locale_langpack_dir);
}
if (install_themes.is_default)
{
install_themes.is_default = 0;
install_themes.n_entries = 1;
install_themes.entries = xmalloc (2 * sizeof (install_themes.entries[0]));
install_themes.entries[0] = xstrdup ("starfield");
install_themes.entries[1] = NULL;
}
for (i = 0; i < install_themes.n_entries; i++)
{
char *srcf = grub_util_path_concat (4, pkgdatadir, "themes",
install_themes.entries[i],
"theme.txt");
if (grub_util_is_regular (srcf))
{
char *srcd = grub_util_path_concat (3, pkgdatadir, "themes",
install_themes.entries[i]);
char *dstd = grub_util_path_concat (3, dst, "themes",
install_themes.entries[i]);
grub_install_mkdir_p (dstd);
copy_all (srcd, dstd);
free (srcd);
free (dstd);
}
free (srcf);
}
if (install_fonts.is_default)
{
install_fonts.is_default = 0;
install_fonts.n_entries = 1;
install_fonts.entries = xmalloc (2 * sizeof (install_fonts.entries[0]));
install_fonts.entries[0] = xstrdup ("unicode");
install_fonts.entries[1] = NULL;
}
grub_install_mkdir_p (dst_fonts);
for (i = 0; i < install_fonts.n_entries; i++)
{
char *srcf = grub_util_path_concat_ext (2, pkgdatadir,
install_fonts.entries[i],
".pf2");
char *dstf = grub_util_path_concat_ext (2, dst_fonts,
install_fonts.entries[i],
".pf2");
grub_install_compress_file (srcf, dstf, 0);
free (srcf);
free (dstf);
}
free (dst_platform);
free (dst_locale);
free (dst_fonts);
}
enum grub_install_plat
grub_install_get_target (const char *src)
{
char *fn;
grub_util_fd_t f;
char buf[2048];
size_t r;
char *c, *pl, *p;
size_t i;
fn = grub_util_path_concat (2, src, "modinfo.sh");
f = grub_util_fd_open (fn, GRUB_UTIL_FD_O_RDONLY);
if (!GRUB_UTIL_FD_IS_VALID (f))
grub_util_error (_("%s doesn't exist. Please specify --target or --directory"),
fn);
r = grub_util_fd_read (f, buf, sizeof (buf) - 1);
grub_util_fd_close (f);
buf[r] = '\0';
c = strstr (buf, "grub_modinfo_target_cpu=");
if (!c || (c != buf && !grub_isspace (*(c-1))))
grub_util_error (_("invalid modinfo file `%s'"), fn);
pl = strstr (buf, "grub_modinfo_platform=");
if (!pl || (pl != buf && !grub_isspace (*(pl-1))))
grub_util_error (_("invalid modinfo file `%s'"), fn);
c += sizeof ("grub_modinfo_target_cpu=") - 1;
pl += sizeof ("grub_modinfo_platform=") - 1;
for (p = c; *p && !grub_isspace (*p); p++);
*p = '\0';
for (p = pl; *p && !grub_isspace (*p); p++);
*p = '\0';
for (i = 0; i < ARRAY_SIZE (platforms); i++)
if (strcmp (platforms[i].cpu, c) == 0
&& strcmp (platforms[i].platform, pl) == 0)
{
free (fn);
return i;
}
grub_util_error (_("Unknown platform `%s-%s'"), c, pl);
}
void
grub_util_unlink_recursive (const char *name)
{
grub_util_fd_dir_t d;
grub_util_fd_dirent_t de;
d = grub_util_fd_opendir (name);
while ((de = grub_util_fd_readdir (d)))
{
char *fp;
if (strcmp (de->d_name, ".") == 0)
continue;
if (strcmp (de->d_name, "..") == 0)
continue;
fp = grub_util_path_concat (2, name, de->d_name);
if (grub_util_is_special_file (fp))
{
free (fp);
continue;
}
if (grub_util_is_regular (fp))
grub_util_unlink (fp);
else if (grub_util_is_directory (fp))
grub_util_unlink_recursive (fp);
free (fp);
}
grub_util_rmdir (name);
grub_util_fd_closedir (d);
}

1645
util/grub-install.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,878 +0,0 @@
#! /bin/sh
# Install GRUB on your drive.
# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
#
# GRUB is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GRUB is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
# Initialize some variables.
sbindir="@sbindir@"
sysconfdir="@sysconfdir@"
host_os=@host_os@
target=
grub_probe="${sbindir}/@grub_probe@"
grub_editenv="${bindir}/@grub_editenv@"
grub_mkrelpath="${bindir}/@grub_mkrelpath@"
rootdir=
bootdir=
grubdir="`echo "/@bootdirname@/@grubdirname@" | sed 's,//*,/,g'`"
install_device=
force_lba=
recheck=no
debug=no
debug_image=
update_nvram=yes
removable=no
efi_quiet=-q
uefi_secure_boot=yes
# Get GRUB_DISTRIBUTOR.
if test -f "${sysconfdir}/default/grub" ; then
. "${sysconfdir}/default/grub"
fi
for x in "${sysconfdir}/default/grub.d"/*.cfg ; do
if [ -e "${x}" ]; then
. "${x}"
fi
done
bootloader_id="$(echo "$GRUB_DISTRIBUTOR" | tr 'A-Z' 'a-z' | cut -d' ' -f1)"
if test -z "$bootloader_id"; then
bootloader_id=grub
fi
disk_module=unspecified
# Usage: usage
# Print the usage.
usage () {
# TRANSLATORS: INSTALL_DEVICE isn't an identifier and is the DEVICE you
# install to.
gettext_printf "Usage: %s [OPTION] [INSTALL_DEVICE]" "$self"
echo
gettext "Install GRUB on your drive." ; echo
echo
print_option_help "-h, --help" "$(gettext "print this message and exit")"
grub_print_install_files_help
dirmsg="$(gettext_printf "install GRUB images under the directory DIR/%s instead of the %s directory" "@grubdirname@" "$grubdir")"
print_option_help "--boot-directory=$(gettext "DIR")" "$dirmsg"
# TRANSLATORS: "TARGET" as in "target platform".
target_trans="$(gettext "TARGET")"
# TRANSLATORS: "current" refers to the platform user's currently running on
print_option_help "--target=$target_trans" "$(gettext "install GRUB for TARGET platform [default=current]")"
print_option_help "--grub-setup=$(gettext "FILE")" "$(gettext "use FILE as grub-setup")"
print_option_help "--grub-mkrelpath=$(gettext "FILE")" "$(gettext "use FILE as grub-mkrelpath")"
print_option_help "--grub-probe=$(gettext "FILE")" "$(gettext "use FILE as grub-probe")"
print_option_help "--grub-editenv=$(gettext "FILE")" "$(gettext "use FILE as grub-editenv")"
# TRANSLATORS: "may break" doesn't just mean that option wouldn't have any
# effect but that it will make the resulting install unbootable from HDD.
print_option_help "--allow-floppy" "$(gettext "make the drive also bootable as floppy (default for fdX devices). May break on some BIOSes.")"
print_option_help "--recheck" "$(gettext "delete device map if it already exists")"
print_option_help "--force" "$(gettext "install even if problems are detected")"
print_option_help "--force-file-id" "$(gettext "use identifier file even if UUID is available")"
print_option_help "--disk-module=$(gettext "MODULE")" "$(gettext "disk module to use (biosdisk or native). This option is only available on BIOS target.")"
print_option_help "--no-nvram" "$(gettext "don't update the \`boot-device' NVRAM variable. This option is only available on IEEE1275 targets.")"
print_option_help "--removable" "$(gettext "the installation device is removable. This option is only available on EFI.")"
print_option_help "--bootloader-id=$(gettext "ID")" "$(gettext "the ID of bootloader. This option is only available on EFI.")"
print_option_help "--efi-directory=$(gettext "DIR")" "$(gettext "use DIR as the EFI System Partition root.")"
print_option_help "--uefi-secure-boot" "$(gettext "install an image usable with UEFI Secure Boot. This option is only available on EFI and if the grub-efi-amd64-signed package is installed.")"
print_option_help "--no-uefi-secure-boot" "$(gettext "do not install an image usable with UEFI Secure Boot, even if the system was currently started using it. This option is only available on EFI.")"
echo
gettext "INSTALL_DEVICE must be system device filename.";echo
echo
gettext_printf "%s copies GRUB images into %s. On some platforms, it
may also install GRUB into the boot sector.\n" "$self" "$grubdir";echo
echo
gettext "Report bugs to <bug-grub@gnu.org>."; echo
}
allow_floppy=""
force_file_id=
efidir=
# Check the arguments.
while test $# -gt 0
do
grub_process_install_options "$@"
case "$grub_process_install_options_consumed" in
1) shift; continue;;
2) shift; shift; continue;;
esac
option=$1
shift
case "$option" in
-h | --help)
usage
exit 0 ;;
--force-file-id)
force_file_id=y ;;
# Accept and ignore for compatibility
--font)
shift;;
--font=*)
;;
# Accept for compatibility
--root-directory)
rootdir="`argument $option "$@"`"; shift;;
--root-directory=*)
rootdir="`echo "$option" | sed 's/--root-directory=//'`" ;;
--boot-directory)
bootdir="`argument $option "$@"`"; shift;;
--boot-directory=*)
bootdir="`echo "$option" | sed 's/--boot-directory=//'`" ;;
--efi-directory)
efidir="`argument $option "$@"`"; shift;;
--efi-directory=*)
efidir="`echo "$option" | sed 's/--efi-directory=//'`" ;;
--target)
target="`argument $option "$@"`"; shift;;
--target=*)
target="`echo "$option" | sed 's/--target=//'`" ;;
--grub-setup)
grub_setup="`argument "$option" "$@"`"; shift;;
--grub-setup=*)
grub_setup="`echo "$option" | sed 's/--grub-setup=//'`" ;;
--bootloader-id)
bootloader_id="`argument $option "$@"`"; shift;;
--bootloader-id=*)
bootloader_id="`echo "$option" | sed 's/--bootloader-id=//'`" ;;
--grub-mkrelpath)
grub_mkrelpath="`argument "$option" "$@"`"; shift;;
--grub-mkrelpath=*)
grub_mkrelpath="`echo "$option" | sed 's/--grub-mkrelpath=//'`" ;;
# Ignore: for compatibility
--grub-mkdevicemap)
shift;;
--grub-mkdevicemap=*)
;;
--grub-probe)
grub_probe="`argument "$option" "$@"`"; shift;;
--grub-probe=*)
grub_probe="`echo "$option" | sed 's/--grub-probe=//'`" ;;
--grub-editenv)
grub_editenv="`argument "$option" "$@"`"; shift;;
--grub-editenv=*)
grub_editenv="`echo "$option" | sed 's/--grub-editenv=//'`" ;;
--no-floppy)
;;
--recheck)
recheck=yes ;;
--removable)
removable=yes ;;
--allow-floppy)
allow_floppy="--allow-floppy" ;;
--disk-module)
disk_module="`argument "$option" "$@"`"; shift;
;;
--disk-module=*)
disk_module="`echo "$option" | sed 's/--disk-module=//'`"
;;
--no-nvram)
update_nvram=no ;;
# This is an undocumented feature...
--debug)
debug=yes ;;
--debug-image)
debug_image="`argument "$option" "$@"`"; shift;;
--debug-image=*)
debug_image="`echo "$option" | sed 's/--debug-image=//'`" ;;
-f | --force)
setup_force="--force" ;;
--uefi-secure-boot)
uefi_secure_boot=yes ;;
--no-uefi-secure-boot)
uefi_secure_boot=no ;;
-*)
gettext_printf "Unrecognized option \`%s'\n" "$option" 1>&2
usage
exit 1
;;
*)
if test "x$install_device" != x; then
gettext "More than one install device?" 1>&2
echo 1>&2
usage
exit 1
fi
install_device="${option}" ;;
esac
done
if [ x$source_directory = x ]; then
if [ x$target = x ]; then
case x"`uname -m`" in
x"powerpc"* | x"ppc"*)
target="powerpc-ieee1275";;
x"sparc"*)
target="sparc64-ieee1275";;
x"mips"*"el")
target="mipsel-loongson";;
x"mips"*)
target="mips-arc";;
x"ia64"*)
target="ia64-efi";;
x"x86_64"* | x"amd64"*)
# On Linux, we need the efivars kernel modules.
# If no EFI is available this module just does nothing
# besides a small hello and if we detect efi we'll load it
# anyway later. So it should be safe to
# try to load it here.
case "$host_os" in
linux*)
modprobe -q efivars 2>/dev/null || true ;;
esac
if [ -d /sys/firmware/efi ] && \
[ -d "${libdir}/@PACKAGE@/x86_64-efi" ]; then
target="x86_64-efi"
else
target=i386-pc
fi
;;
x"i"?"86"*)
# On Linux, we need the efivars kernel modules.
# If no EFI is available this module just does nothing
# besides a small hello and if we detect efi we'll load it
# anyway later. So it should be safe to
# try to load it here.
case "$host_os" in
linux*)
modprobe -q efivars 2>/dev/null || true ;;
esac
if [ -d /sys/firmware/efi ] && \
[ -d "${libdir}/@PACKAGE@/i386-efi" ]; then
target="i386-efi"
elif [ -e /proc/device-tree ]; then
target=i386-pc
for x in /proc/device-tree/*; do
if [ -e "$x" ]; then
target="i386-ieee1275"
fi
done
else
target=i386-pc
fi
;;
x"arm"*)
target="arm-uboot";;
*)
gettext "Unable to determine your platform. Use --target." ;
echo ;;
esac
fi
source_directory="${libdir}/@PACKAGE@/$target"
fi
if ! [ -d "$source_directory" ]; then
gettext_printf "%s doesn't exist. Please specify --target or --directory\\n" "$source_directory"
exit 1
fi
. "${source_directory}"/modinfo.sh
if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-pc" ] ; then
if [ x$disk_module = xunspecified ]; then
disk_module=biosdisk
fi
elif [ "${grub_modinfo_platform}" = "ieee1275" ] || [ "${grub_modinfo_platform}" = "efi" ] || [ "${grub_modinfo_platform}" = "arc" ] || [ "${grub_modinfo_platform}" = "uboot" ] ; then
disk_module=
else
disk_module=native
fi
if test "x$grub_setup" = x && [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-pc" ]; then
grub_setup="${sbindir}/@grub_bios_setup@"
if [ ! -e "$grub_setup" ]; then
grub_setup="${source_dir}/@grub_bios_setup@"
fi
fi
if test "x$grub_setup" = x && [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "sparc64-ieee1275" ]; then
grub_setup="${sbindir}/@grub_sparc64_setup@"
fi
if test "x$install_device" = x && ([ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-pc" ] \
|| [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "sparc64-ieee1275" ]); then
gettext "Install device isn't specified." 1>&2
echo 1>&2
usage
exit 1
fi
if ! ([ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-pc" ] \
|| [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "sparc64-ieee1275" ] \
|| [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "powerpc-ieee1275" ] \
|| [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "mips-arc" ]); then
install_device=
fi
# If the debugging feature is enabled, print commands.
setup_verbose=
if test x"$debug" = xyes; then
set -x
setup_verbose="--verbose"
efi_quiet=
fi
if [ -z "$bootdir" ]; then
# Default bootdir if bootdir not initialized.
bootdir="/@bootdirname@"
if [ -n "$rootdir" ] ; then
# Initialize bootdir if rootdir was initialized.
bootdir="${rootdir}/@bootdirname@"
fi
fi
grubdir="`echo "${bootdir}/@grubdirname@" | sed 's,//*,/,g'`"
device_map="${grubdir}/device.map"
# Check if GRUB is installed.
if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-pc" ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "sparc64-ieee1275" ] ; then
set $grub_setup dummy
if test -f "$1"; then
:
else
# TRANSLATORS: This message is shown when required executable `%s'
# isn't found
gettext_printf "%s: Not found.\n" "$1" 1>&2
exit 1
fi
fi
set "$grub_mkimage" dummy
if test -f "$1"; then
:
else
# TRANSLATORS: This message is shown when required executable `%s'
# isn't found
gettext_printf "%s: Not found.\n" "$1" 1>&2
exit 1
fi
if [ x"$grub_modinfo_platform" = xefi ]; then
# Find the EFI System Partition.
if test -n "$efidir"; then
install_device="`"$grub_probe" --target=device --device-map= "${efidir}"`"
else
if test -d "${bootdir}/efi"; then
install_device="`"$grub_probe" --target=device --device-map= "${bootdir}/efi"`"
# Is it a mount point?
if test "x$install_device" != "x`"$grub_probe" --target=device --device-map= "${bootdir}"`"; then
efidir="${bootdir}/efi"
fi
elif test -d "${bootdir}/EFI"; then
install_device="`"$grub_probe" --target=device --device-map= "${bootdir}/EFI"`"
# Is it a mount point?
if test "x$install_device" != "x`"$grub_probe" --target=device --device-map= "${bootdir}"`"; then
efidir="${bootdir}/EFI"
fi
elif test -n "$rootdir" && test "x$rootdir" != "x/"; then
# The EFI System Partition may have been given directly using
# --root-directory.
install_device="`"$grub_probe" --target=device --device-map= "${rootdir}"`"
# Is it a mount point?
if test "x$install_device" != "x`"$grub_probe" --target=device --device-map= "${rootdir}/.."`"; then
efidir="${rootdir}"
fi
fi
if test -n "$efidir"; then
efi_fs=`"$grub_probe" --target=fs "--device-map=${device_map}" "${efidir}"`
if test "x$efi_fs" = xfat; then :; else
gettext_printf "%s doesn't look like an EFI partition.\n" "${efidir}" 1>&2
efidir=
fi
fi
fi
if test -n "$efidir"; then
# The EFI specification requires that an EFI System Partition must
# contain an "EFI" subdirectory, and that OS loaders are stored in
# subdirectories below EFI. Vendors are expected to pick names that do
# not collide with other vendors. To minimise collisions, we use the
# name of our distributor if possible.
efi_distributor="$bootloader_id"
case $efi_distributor in
kubuntu)
efi_distributor=ubuntu ;;
esac
# It is convenient for each architecture to have a different
# efi_file, so that different versions can be installed in parallel.
case "$grub_modinfo_target_cpu" in
i386)
efi_suffix=ia32 ;;
x86_64)
efi_suffix=x64 ;;
# GRUB does not yet support these architectures, but they're defined
# by the specification so we include them here to ease future
# expansion.
ia64)
efi_suffix=ia64 ;;
arm)
efi_suffix=arm ;;
*)
efi_suffix= ;;
esac
if test $removable = yes; then
# The specification makes stricter requirements of removable
# devices, in order that only one image can be automatically loaded
# from them. The image must always reside under /EFI/BOOT, and it
# must have a specific file name depending on the architecture.
efi_distributor=BOOT
efi_file="BOOT$(printf %s "$efi_suffix" | tr a-z A-Z).EFI"
else
# It is convenient for each architecture to have a different
# efi_file, so that different versions can be installed in parallel.
efi_file="grub$efi_suffix.efi"
fi
efidir="$efidir/EFI/$efi_distributor"
mkdir -p "$efidir" || exit 1
else
# We don't know what's going on. Fall back to traditional
# (non-specification-compliant) behaviour.
efidir="$grubdir"
efi_distributor=
efi_file=grub.efi
fi
fi
# Create the GRUB directory if it is not present.
mkdir -p "$grubdir" || exit 1
mkdir -p "$grubdir/${grub_modinfo_target_cpu}-$grub_modinfo_platform" || exit 1
# If --recheck is specified, remove the device map, if present.
if test $recheck = yes; then
rm -f "$device_map"
fi
# Device map file is optional
if test -f "$device_map"; then
# Make sure that there is no duplicated entry.
tmp=`sed -n '/^([fh]d[0-9]*)/s/\(^(.*)\).*/\1/p' "$device_map" \
| sort | uniq -d | sed -n 1p`
if test -n "$tmp"; then
gettext_printf "The drive %s is defined multiple times in the device map %s\n" "$tmp" "$device_map" 1>&2
exit 1
fi
else
device_map=
fi
# Copy the GRUB images to the GRUB directory.
grub_install_files "${source_directory}" "${grubdir}" "${grub_modinfo_target_cpu}-$grub_modinfo_platform" all
if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-pc" ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "sparc64-ieee1275" ] ; then
for file in "${source_directory}"/*.img "${source_directory}"/efiemu??.o; do
if test -f "$file"; then
cp -f "$file" "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform" || exit 1
fi
done
fi
if ! is_path_readable_by_grub "${grubdir}"; then
gettext_printf "Path \`%s' is not readable by GRUB on boot. Installation is impossible. Aborting.\n" "${grubdir}" 1>&2
exit 1
fi
# Write device to a variable so we don't have to traverse /dev every time.
grub_device="`"$grub_probe" --device-map="${device_map}" --target=device "${grubdir}"`" || exit 1
if ! test -f "${grubdir}"/grubenv; then
"$grub_editenv" "${grubdir}"/grubenv create
fi
# Create the core image. First, auto-detect the filesystem module.
fs_module="`echo "${grub_device}" | xargs "$grub_probe" --device-map="${device_map}" --target=fs --device `"
if test "x$fs_module" = x ; then
gettext_printf "Auto-detection of a filesystem of %s failed.\n" "${grub_device}" 1>&2
gettext "Try with --recheck." 1>&2
echo 1>&2
gettext_printf "If the problem persists please report this together with the output of %s to <%s>" "\"$grub_probe --device-map=\"${device_map}\" --target=fs -v ${grubdir}\"" "bug-grub@gnu.org" 1>&2
exit 1
fi
# Then the partition map module. In order to support partition-less media,
# this command is allowed to fail (--target=fs already grants us that the
# filesystem will be accessible).
partmap_module=
for x in `echo "${grub_device}" | xargs "$grub_probe" --device-map="${device_map}" --target=partmap --device 2> /dev/null`; do
case "$x" in
netbsd | openbsd)
partmap_module="$partmap_module part_bsd";;
"") ;;
*)
partmap_module="$partmap_module part_$x";;
esac
done
# Device abstraction module, if any (lvm, raid).
devabstraction_module="`echo "${grub_device}" | xargs "$grub_probe" --device-map="${device_map}" --target=abstraction --device`"
if [ "x$disk_module" = xata ]; then
disk_module=pata
fi
if [ "x$disk_module" = xnative ]; then
disk_module="pata ahci ohci"
if [ "x$grub_modinfo_target_cpu" = "xi386" ] || [ "x$grub_modinfo_target_cpu" = "xx86_64" ]; then
disk_module="$disk_module uhci"
fi
disk_module="$disk_module usbms"
fi
# The order in this list is critical. Be careful when modifying it.
modules="$modules $disk_module"
modules="$modules $fs_module $partmap_module $devabstraction_module"
relative_grubdir="`"$grub_mkrelpath" "${grubdir}"`" || exit 1
if [ "x${relative_grubdir}" = "x" ] ; then
relative_grubdir=/
fi
prefix_drive=
config_opt_file=
rm -f "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/load.cfg"
if [ "x${debug_image}" != x ]; then
echo "set debug='${debug_image}'" >> "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/load.cfg"
config_opt_file="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/load.cfg"
fi
if [ x"$grub_modinfo_platform" = xefi ]; then
if [ $removable = yes ]; then
efi_signed="${source_dir}-signed/gcd$efi_suffix.efi.signed"
else
efi_signed="${source_dir}-signed/grub$efi_suffix.efi.signed"
fi
fi
if [ "x${devabstraction_module}" = "x" ] || ([ x"$grub_modinfo_platform" = xefi ] && [ "$uefi_secure_boot" = yes ] && [ -e "$efi_signed" ]); then
if [ x"${install_device}" != x ]; then
if echo "${install_device}" | grep -qx "(.*)" ; then
install_drive="${install_device}"
else
install_drive="`"$grub_probe" --device-map="${device_map}" --target=drive --device "${install_device}"`" || exit 1
fi
install_drive="`echo "${install_drive}" | sed -e 's/^(\(\([^,\\\\]\|\\\\\\\\\|\\\\,\)*\)\(\(,[a-zA-Z0-9]*\)*\))$/\1/'`"
fi
grub_drive="`echo "${grub_device}" | xargs "$grub_probe" --device-map="${device_map}" --target=drive --device`" || exit 1
# Strip partition number
grub_partition="`echo "${grub_drive}" | sed -e 's/^(\(\([^,\\\\]\|\\\\\\\\\|\\\\,\)*\)\(\(,[a-zA-Z0-9]*\)*\))$/\3/'`"
grub_drive="`echo "${grub_drive}" | sed -e 's/^(\(\([^,\\\\]\|\\\\\\\\\|\\\\,\)*\)\(\(,[a-zA-Z0-9]*\)*\))$/\1/'`"
if [ x"${install_device}" = x ] && [ x"${grub_modinfo_target_cpu}-$grub_modinfo_platform" = x"powerpc-ieee1275" ]; then
install_drive="$grub_drive"
fi
if ([ "x$disk_module" != x ] && [ "x$disk_module" != xbiosdisk ]) || [ "x${grub_drive}" != "x${install_drive}" ] || ([ "x$grub_modinfo_platform" != xefi ] && [ "x$grub_modinfo_platform" != xpc ] && [ x"${grub_modinfo_platform}" != x"ieee1275" ]) || ([ "x$grub_modinfo_platform" = xefi ] && [ "$uefi_secure_boot" = yes ]); then
# generic method (used on coreboot and ata mod)
uuid=
if [ x"$force_file_id" != xy ]; then
uuid="`echo "${grub_device}" | xargs "$grub_probe" --device-map="${device_map}" --target=fs_uuid --device`"
fi
if [ x"$disk_module" != x ] && [ x"$disk_module" != xbiosdisk ]; then
hints="`echo "${grub_device}" | xargs "$grub_probe" --device-map="${device_map}" --target=baremetal_hints --device`"
elif [ x"$grub_modinfo_platform" = xpc ]; then
hints="`echo "${grub_device}" | xargs "$grub_probe" --device-map="${device_map}" --target=bios_hints --device`"
elif [ x"$grub_modinfo_platform" = xefi ]; then
hints="`echo "${grub_device}" | xargs "$grub_probe" --device-map="${device_map}" --target=efi_hints --device`"
elif [ x"$grub_modinfo_platform" = xieee1275 ]; then
hints="`echo "${grub_device}" | xargs "$grub_probe" --device-map="${device_map}" --target=ieee1275_hints --device`"
elif [ x"$grub_modinfo_platform" = xloongson ] || [ x"$grub_modinfo_platform" = xqemu ] || [ x"$grub_modinfo_platform" = xcoreboot ] || [ x"$grub_modinfo_platform" = xmultiboot ] || [ x"$grub_modinfo_platform" = xqemu-mips ]; then
hints="`echo "${grub_device}" | xargs "$grub_probe" --device-map="${device_map}" --target=baremetal_hints --device`"
else
gettext "No hints available for your platform. Expect reduced performance." 1>&2
echo 1>&2
hints=
fi
if [ x"$uuid" != x ]; then
echo "search.fs_uuid ${uuid} root $hints " >> "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/load.cfg"
search_module=search_fs_uuid
else
mkdir -p "${grubdir}/uuid"
file="`mktemp "${grubdir}/uuid/XXXXXXXXXXXXXXXXXXXXXXXXX"`"
relfile="`${grub_mkrelpath} "$file"`"
echo "search.file '${relfile}' root $hints " >> "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/load.cfg"
search_module=search_fs_file
fi
echo 'set prefix=($root)'"$(echo "${relative_grubdir}" | sed "s,\\([ \"'\\\\]\\),\\\\\\1,g")" >> "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/load.cfg"
config_opt_file="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/load.cfg"
modules="$modules $search_module"
else
# we need to hardcode the partition number in the core image's prefix.
if [ x"$grub_partition" = x ]; then
prefix_drive="()"
else
# Comma is already there
prefix_drive="($grub_partition)"
fi
fi
else
if [ x$GRUB_ENABLE_CRYPTODISK = xy ]; then
for uuid in "`echo "${grub_device}" | xargs "${grub_probe}" --target=cryptodisk_uuid --device`"; do
echo "cryptomount -u $uuid" >> "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/load.cfg"
done
config_opt_file="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/load.cfg"
fi
prefix_drive=`"$grub_probe" --device-map="${device_map}" --target=drive --device "${grub_device}"` || exit 1
fi
case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
sparc64-ieee1275) mkimage_target=sparc64-ieee1275-raw ;;
mipsel-loongson) mkimage_target=mipsel-loongson-elf ;;
mips-qemu_mips | mipsel-qemu_mips) mkimage_target="${grub_modinfo_target_cpu}-${grub_modinfo_platform}"-elf ;;
*) mkimage_target="${grub_modinfo_target_cpu}-${grub_modinfo_platform}" ;;
esac
case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
i386-efi | x86_64-efi | ia64-efi) imgext=efi ;;
mipsel-loongson | i386-coreboot | i386-multiboot | i386-ieee1275 \
| powerpc-ieee1275 | mips-qemu_mips | mipsel-qemu_mips) imgext=elf ;;
*) imgext=img ;;
esac
if [ x"$config_opt_file" = x ]; then
"$grub_mkimage" -d "${source_directory}" -O "${mkimage_target}" --output="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" --prefix="${prefix_drive}${relative_grubdir}" $grub_decompression_module $modules || exit 1
else
"$grub_mkimage" -c "${config_opt_file}" -d "${source_directory}" -O "${mkimage_target}" --output="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" --prefix="${prefix_drive}${relative_grubdir}" $grub_decompression_module $modules || exit 1
fi
# Backward-compatibility kludges
if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "mipsel-loongson" ]; then
cp "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" "${bootdir}"/grub.elf
elif [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-ieee1275" ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "powerpc-ieee1275" ]; then
cp "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" "${grubdir}/grub"
elif [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-efi" ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "x86_64-efi" ]; then
if [ x"$config_opt_file" = x ]; then
"$grub_mkimage" -d "${source_directory}" -O "${mkimage_target}" --output="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/grub.efi" --prefix="" $grub_decompression_module $modules || exit 1
else
"$grub_mkimage" -c "${config_opt_file}" -d "${source_directory}" -O "${mkimage_target}" --output="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/grub.efi" --prefix="" $grub_decompression_module $modules || exit 1
fi
fi
# Perform the grub_modinfo_platform-dependent install
if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-pc" ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "sparc64-ieee1275" ] ; then
# Now perform the installation.
"$grub_setup" ${allow_floppy} ${setup_verbose} ${setup_force} --directory="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform" \
--device-map="${device_map}" "${install_device}" || exit 1
elif [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-ieee1275" ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "powerpc-ieee1275" ]; then
# If a install device is defined, copy the core.elf to PReP partition.
if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "powerpc-ieee1275" ] && [ -n "${install_device}" ]; then
if [ "$("${grub_probe}" -m "${device_map}" -d "${install_device}" -t msdos_parttype)" != "41" ] \
&& [ "$("${grub_probe}" -m "${device_map}" -d "${install_device}" -t gpt_parttype)" != "9e1a2d38-c612-4316-aa26-8b49521e5a8b" ]; then
gettext "The chosen partition is not a PReP partition." 1>&2
echo 1>&2
exit 1
fi
if [ "$(file -s -b -L "${install_device}" | awk '{ print $1 }')" = ELF ] || [ x$("${grub_probe}" -m "${device_map}" -d "${install_device}" -t zero_check) = xtrue ]; then
dd if="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" of="${install_device}" status=noxfer || {
gettext "Failed to copy Grub to the PReP partition." 1>&2
echo 1>&2
exit 1
}
else
gettext "The PReP partition is not empty. If you are sure you want to use it, run dd to clear it:" 1>&2
echo 1>&2
echo " dd if=/dev/zero of=${install_device}"
exit 1
fi
fi
if [ x"$update_nvram" = xyes ]; then
ofpathname="`which ofpathname`"
nvsetenv="`which nvsetenv`"
set "$ofpathname" dummy
if test -f "$1"; then
:
else
# TRANSLATORS: This message is shown when required executable `%s'
# isn't found
gettext_printf "%s: Not found.\n" "$1" 1>&2
exit 1
fi
set "$nvsetenv" dummy
if test -f "$1"; then
:
else
# TRANSLATORS: This message is shown when required executable `%s'
# isn't found
gettext_printf "%s: Not found.\n" "$1" 1>&2
exit 1
fi
if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" != "powerpc-ieee1275" ] \
|| [ -z "${install_device}" ]; then
# Get the Open Firmware device tree path translation.
dev="`echo $grub_device | sed -e 's/\/dev\///' -e 's/[0-9]\+//'`"
partno="`echo $grub_device | sed -e 's/.*[^0-9]\([0-9]\+\)$/\1/'`"
ofpath="`$ofpathname $dev`" || {
# TRANSLATORS: "device tree path" is the name of the device
# for IEEE1275
gettext_printf "Couldn't find IEEE1275 device tree path for %s.\nYou will have to set \`boot-device' variable manually.\n" "$dev" 1>&2
exit 1
}
# Point boot-device at the new grub install
boot_device="$ofpath:$partno,"`"$grub_mkrelpath" "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" | sed 's,/,\\\\,g'`
else
dev="`echo "${install_device}" | sed -e 's/\/dev\///' -e 's/[0-9]\+//'`"
boot_device="`$ofpathname "$dev"`" || {
# TRANSLATORS: "device tree path" is the name of the device
# for IEEE1275
gettext_printf "Couldn't find IEEE1275 device tree path for %s.\nYou will have to set \`boot-device' variable manually.\n" "$dev" 1>&2
exit 1
}
fi
"$nvsetenv" boot-device "$boot_device" || {
# TRANSLATORS: The %s will be replaced by an external program name.
gettext_printf "\`%s' failed.\n" "$nvsetenv" 1>&2
gettext "You will have to set \`boot-device' variable manually. At the IEEE1275 prompt, type:" 1>&2
echo 1>&2
echo " setenv boot-device $boot_device" 1>&2
exit 1
}
fi
elif [ x"${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = xmips-arc ]; then
dvhtool -d "${install_device}" --unix-to-vh "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" grub
gettext "You will have to set \`SystemPartition' and \`OSLoader' manually." 1>&2
echo 1>&2
elif [ x"$grub_modinfo_platform" = xefi ]; then
if [ "$uefi_secure_boot" = yes ] && [ -e "$efi_signed" ]; then
shim_signed=/usr/lib/shim/shim.efi.signed
if [ -e "$shim_signed" ]; then
if [ "$removable" != yes ]; then
efi_file="shim$efi_suffix.efi"
fi
cp "$shim_signed" "${efidir}/${efi_file}"
cp "$efi_signed" "${efidir}/grub$efi_suffix.efi"
# Not critical, so not an error if it's not present (as it won't
# be for older releases); but if we have it, make sure it's
# installed.
if [ -e /usr/lib/shim/MokManager.efi.signed ]; then
cp /usr/lib/shim/MokManager.efi.signed "${efidir}/MokManager.efi"
fi
else
cp "$efi_signed" "${efidir}/${efi_file}"
fi
cp "${config_opt_file}" "${efidir}/grub.cfg"
echo 'configfile $prefix/grub.cfg' >> "${efidir}/grub.cfg"
else
cp "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" "${efidir}/${efi_file}"
# For old macs. Suggested by Peter Jones.
if [ x$grub_modinfo_target_cpu = xi386 ]; then
cp "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" "${efidir}/boot.efi"
fi
fi
# Try to make this image bootable using the EFI Boot Manager, if available.
if test "$removable" = no; then
efibootmgr="`which efibootmgr`" || {
# TRANSLATORS: This message is shown when required executable `%s'
# isn't found
gettext_printf "%s: Not found.\n" "efibootmgr" 1>&2
exit 1
}
test -n "$efi_distributor" || {
gettext "EFI distributor id isn't specified." 1>&2
echo 1>&2
exit 1
}
# On Linux, we need the efivars kernel modules.
case "$host_os" in
linux*)
modprobe -q efivars 2>/dev/null || true ;;
esac
# Delete old entries from the same distributor.
for bootnum in `efibootmgr | grep '^Boot[0-9]' | \
fgrep -i " $efi_distributor" | cut -b5-8`; do
efibootmgr $efi_quiet -b "$bootnum" -B
done
# Add a new entry for the image we just created. efibootmgr needs to be
# given the disk device and partition number separately, so we have to
# fiddle about with grub-probe to get hold of this reasonably reliably.
# Use fresh device map text to avoid any problems with stale data, since
# all we need here is a one-to-one mapping.
efidir_drive="$("$grub_probe" --target=drive --device-map= "$efidir")"
efidir_disk="$("$grub_probe" --target=disk --device-map= "$efidir")"
if test -z "$efidir_drive" || test -z "$efidir_disk"; then
gettext_printf "Can't find GRUB drive for %s; unable to create EFI Boot Manager entry.\n" "$efidir" >&2
else
efidir_part="$(echo "$efidir_drive" | sed 's/^([^,]*,[^0-9]*//; s/[^0-9].*//')"
efibootmgr $efi_quiet -c -d "$efidir_disk" -p "$efidir_part" -w \
-L "$bootloader_id" -l "\\EFI\\$efi_distributor\\$efi_file"
fi
fi
else
gettext "WARNING: no platform-specific install was performed" 1>&2
echo 1>&2
fi
# If vestiges of GRUB Legacy still exist, tell the Debian packaging that
# they can ignore them.
if test -z "$rootdir" && \
test -e /boot/grub/stage2 && test -e /boot/grub/menu.lst; then
touch /boot/grub/grub2-installed
fi
gettext "Installation finished. No error reported." 1>&2
echo 1>&2
# Bye.
exit 0

View File

@ -1,265 +0,0 @@
#! /bin/sh
set -e
# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012 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/>.
prefix="@prefix@"
exec_prefix="@exec_prefix@"
datarootdir="@datarootdir@"
bindir="@bindir@"
libdir="@libdir@"
PACKAGE_NAME=@PACKAGE_NAME@
PACKAGE_TARNAME=@PACKAGE_TARNAME@
PACKAGE_VERSION=@PACKAGE_VERSION@
datadir="@datadir@"
if [ "x$pkgdatadir" = x ]; then
pkgdatadir="${datadir}/@PACKAGE@"
fi
localedir="@datadir@/locale"
self=`basename $0`
export TEXTDOMAIN=@PACKAGE@
export TEXTDOMAINDIR="@localedir@"
. "${pkgdatadir}/grub-mkconfig_lib"
modules=
pkglib_DATA="moddep.lst command.lst fs.lst partmap.lst parttool.lst \
handler.lst video.lst crypto.lst terminal.lst"
grub_mkimage="${bindir}/@grub_mkimage@"
grub_compress_file () {
if [ -f "$1" ] ; then
if [ "$compressor" != "" ] ; then
"$compressor" $compressor_opts "$1" > "$2"
else
cp -f "$1" "$2"
fi
else
gettext_printf "Skipping file \`%s': not a plain file\n" "$1" 1>&2
fi
}
grub_install_files () {
grub_install_files_source_directory="$1"
grub_install_files_target_directory="$2"
grub_install_files_platform="$3"
mkdir -p "${grub_install_files_target_directory}"/"${grub_install_files_platform}"
for file in "${grub_install_files_target_directory}"/*.mod \
"${grub_install_files_target_directory}"/*.lst \
"${grub_install_files_target_directory}"/*.img \
"${grub_install_files_target_directory}"/efiemu??.o \
"${grub_install_files_target_directory}"/"${grub_install_files_platform}"/*.mod \
"${grub_install_files_target_directory}"/"${grub_install_files_platform}"/*.lst \
"${grub_install_files_target_directory}"/"${grub_install_files_platform}"/*.img \
"${grub_install_files_target_directory}"/"${grub_install_files_platform}"/efiemu??.o;
do
if test -f "$file" && [ "`basename $file`" != menu.lst ]; then
rm -f "$file" || exit 1
fi
done
if [ x"$install_modules" = xall ]; then
for file in "${grub_install_files_source_directory}/"*.mod; do
grub_compress_file "$file" "${grub_install_files_target_directory}"/"${grub_install_files_platform}/$(basename "$file")"
done
else
modules1=
modules2="$install_modules"
while [ x"$modules2" != x ]; do
modules3=
for x in $modules2; do
modules3="$modules3 $(grep "^$x:" "${grub_install_files_source_directory}/moddep.lst" | sed 's,^[^:]*:,,')"
done
modules1="$modules1 $modules2"
modules2="$modules3"
done
for file in $(echo "$modules1" | sed 's, ,\n,g' |sort -u); do
grub_compress_file "${grub_install_files_source_directory}/$file.mod" "${grub_install_files_target_directory}"/"${grub_install_files_platform}/$file.mod"
done
fi
for file in ${pkglib_DATA} efiemu32.o efiemu64.o; do
if test -f "${grub_install_files_source_directory}/${file}"; then
grub_compress_file "${grub_install_files_source_directory}/${file}" "${grub_install_files_target_directory}"/"${grub_install_files_platform}/${file}"
fi
done
# Copy gettext files
mkdir -p "${grub_install_files_target_directory}"/locale
for file in "${grub_install_files_target_directory}"/locale/*.mo; do
if test -f "$file"; then
rm -f "$file" || exit 1
fi
done
if [ x"$install_locales" = xall ]; then
for file in "${grub_install_files_source_directory}"/po/*.mo; do
if test -f "$file"; then
grub_compress_file "$file" "${grub_install_files_target_directory}"/locale/"$(basename "$file")"
fi
done
for dir in "${localedir}"/* "${localedir}-langpack"/*; do
if test -f "$dir/LC_MESSAGES/@PACKAGE@.mo" && ! test -f "${grub_install_files_target_directory}"/locale/"${dir##*/}.mo"; then
grub_compress_file "$dir/LC_MESSAGES/@PACKAGE@.mo" "${grub_install_files_target_directory}"/locale/"${dir##*/}.mo"
fi
done
else
for locale in $install_locales; do
if test -f "${grub_install_files_source_directory}"/po/$locale.mo; then
grub_compress_file "${grub_install_files_source_directory}"/po/locale.mo "${grub_install_files_target_directory}"/locale/$locale.mo
elif test -f "${localedir}-langpack/$locale/LC_MESSAGES/@PACKAGE@.mo"; then
grub_compress_file "${localedir}-langpack/$locale/LC_MESSAGES/@PACKAGE@.mo" "${grub_install_files_target_directory}"/locale/$locale.mo
elif test -f "${localedir}/$locale/LC_MESSAGES/@PACKAGE@.mo"; then
grub_compress_file "${localedir}/$locale/LC_MESSAGES/@PACKAGE@.mo" "${grub_install_files_target_directory}"/locale/$locale.mo
fi
done
fi
for theme in ${install_themes} ; do
if test -f "${pkgdatadir}"/themes/"${theme}"/theme.txt; then
mkdir -p "${grub_install_files_target_directory}"/themes/"${theme}"
for file in "${pkgdatadir}"/themes/"${theme}"/*; do
grub_compress_file "$file" "${grub_install_files_target_directory}"/themes/"${theme}"/"$(basename "$file")"
done
fi
done
for font in ${install_fonts} ; do
if test -f "${pkgdatadir}"/"$font".pf2; then
mkdir -p "${grub_install_files_target_directory}"/fonts
grub_compress_file "${pkgdatadir}"/"$font".pf2 "${grub_install_files_target_directory}"/fonts/"$font".pf2
fi
done
}
grub_print_install_files_help () {
print_option_help "--modules=$(gettext "MODULES")" "$(gettext "pre-load specified modules MODULES")"
print_option_help "--install-modules=$(gettext "MODULES")" "$(gettext "install only MODULES and their dependencies [default=all]")"
print_option_help "--themes=THEMES" "$(gettext_printf "install THEMES [default=%s]" "starfield")"
print_option_help "--fonts=FONTS" "$(gettext_printf "install FONTS [default=%s]" "unicode")"
print_option_help "--locales=LOCALES" "$(gettext_printf "install only LOCALES [default=all]")"
print_option_help "--compress[=no,xz,gz,lzo]" "$(gettext "compress GRUB files [optional]")"
# TRANSLATORS: platform here isn't identifier. It can be translated.
dir_msg="$(gettext_printf "use images and modules under DIR [default=%s/<platform>]" "${libdir}/@PACKAGE@")"
print_option_help "-d, --directory=$(gettext "DIR")" "$dir_msg"
print_option_help "--grub-mkimage=$(gettext "FILE")" "$(gettext "use FILE as grub-mkimage")"
print_option_help "-v, --version" "$(gettext "print the version information and exit")"
}
install_modules=all
install_themes=starfield
install_fonts=unicode
install_locales=all
compress=no
grub_decompression_module=""
compressor=""
compressor_opts=""
source_directory=""
argument () {
opt=$1
shift
if test $# -eq 0; then
gettext_printf "%s: option requires an argument -- \`%s'\n" "$0" "$opt" 1>&2
exit 1
fi
echo $1
}
grub_parse_compress () {
compress="$1"
case x"$compress" in
xno) ;;
xgz)
compressor=`which gzip || true`
grub_decompression_module="gzio"
compressor_opts="--best --stdout";;
xxz)
compressor=`which xz || true`
grub_decompression_module="xzio gcry_crc"
compressor_opts="--lzma2=dict=128KiB --check=none --stdout";;
xlzo)
compressor=`which lzop || true`
grub_decompression_module="lzopio adler32 gcry_crc"
compressor_opts="-9 -c";;
*)
gettext_printf "Unrecognized compression \`%s'\n" "$compress" 1>&2
usage
exit 1
esac
}
grub_process_install_options () {
option=$1
shift
grub_process_install_options_consumed=0
case "$option" in
--install-modules)
install_modules=`argument $option "$@"`; grub_process_install_options_consumed=2; return ;;
--install-modules=*)
install_modules=`echo "$option" | sed 's/--install-modules=//'`; grub_process_install_options_consumed=1; return ;;
--themes)
install_themes=`argument $option "$@"`; grub_process_install_options_consumed=2; return ;;
--themes=*)
install_themes=`echo "$option" | sed 's/--themes=//'`; grub_process_install_options_consumed=1; return ;;
--fonts)
install_fonts=`argument $option "$@"`; grub_process_install_options_consumed=2; return ;;
--fonts=*)
install_fonts=`echo "$option" | sed 's/--fonts=//'`; grub_process_install_options_consumed=1; return ;;
--locales)
install_locales=`argument $option "$@"`; grub_process_install_options_consumed=2; return ;;
--locales=*)
install_locales=`echo "$option" | sed 's/--locales=//'`; grub_process_install_options_consumed=1; return ;;
--compress)
grub_parse_compress `argument $option "$@"`; grub_process_install_options_consumed=2; return ;;
--compress=*)
grub_parse_compress `echo "${option}" | sed 's/--compress=//'`; grub_process_install_options_consumed=1; return ;;
--directory | -d)
source_directory=`argument $option "$@"`; grub_process_install_options_consumed=2 ;;
--directory=*)
source_directory=`echo "$option" | sed 's/--directory=//'` grub_process_install_options_consumed=1;;
# For backwards compatibility
--override-directory)
source_directory=`argument $option "$@"`; grub_process_install_options_consumed=2 ;;
--override-directory=*)
source_directory=`echo "$option" | sed 's/--override-directory=//'` grub_process_install_options_consumed=1;;
--grub-mkimage)
grub_mkimage=`argument $option "$@"`; grub_process_install_options_consumed=2 ;;
--grub-mkimage=*)
grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'`;grub_process_install_options_consumed=1 ;;
--modules)
modules=`argument $option "$@"`; grub_process_install_options_consumed=2;;
--modules=*)
modules=`echo "$option" | sed 's/--modules=//'` grub_process_install_options_consumed=1;;
-v | --version)
echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
exit 0 ;;
esac
}
export grub_decompression_module

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