Merge trunk

This commit is contained in:
Felix Zielcke 2009-11-16 21:53:32 +01:00
commit a8e24b11db
28 changed files with 1024 additions and 487 deletions

55
.bzrignore Normal file
View file

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

123
ChangeLog
View file

@ -1,3 +1,126 @@
2009-11-16 Robert Millan <rmh.grub@aybabtu.com>
Fix build for systems without error().
* gnulib/error.c: New file (imported from Gnulib).
* gnulib/error.h: Likewise.
* conf/common.rmk (grub_mkisofs_SOURCES): Add `gnulib/error.c'.
* util/mkisofs/mkisofs.c (program_name): Remove `static' qualifier
(this variable is now used by error()).
2009-11-16 Felix Zielcke <fzielcke@z-51.de>
* util/mkisofs/name.c (iso9660_file_length): Use isascii macro
instead of relying that char is signed.
2009-11-16 Vladimir Serbinenko <phcoder@gmail.com>
* fs/i386/pc/pxe.c (grub_pxefs_open): Correctly handle PXE choosing
blocksize different from specified.
(grub_pxefs_read): Likewise.
2009-11-16 Felix Zielcke <fzielcke@z-51.de>
Enable ata.mod on x86_64-efi, i386-efi and i386-ieee1275.
* disk/ata.c (grub_ata_dumpinfo): Add a cast.
(grub_ata_readwrite): Likewise. Update 2 format strings.
(grub_atapi_read): Likewise.
* conf/i386-coreboot.rmk (pkglib_MODULES): Move `ata.mod' from here ...
* conf/i386.rmk (pkglib_MODULES): ... to here ...
* conf/x86_64-efi.rmk (pkglib_MODULES): ... and here.
* conf/i386-coreboot.rmk (ata_mod_SOURCES, ata_mod_CFLAGS)
(ata_mod_LDFLAGS): Move from here ...
* conf/i386.rmk: ... to here ...
* conf/x86_64-efi.rmk: ... and here.
* conf/i386-pc.rmk (pkglib_MODULES): Remove `ata.mod'
(ata_mod_SOURCES, ata_mod_CFLAGS, ata_mod_LDFLAGS): Remove.
2009-11-16 Robert Millan <rmh.grub@aybabtu.com>
Relicense multiboot.h, with RMS' blessing.
* include/multiboot.h: Change to X11 license.
2009-11-15 Robert Millan <rmh.grub@aybabtu.com>
Support --version in grub-mkisofs.
* util/mkisofs/mkisofs.c (rcsid): Remove variable.
(OPTION_VERSION): New macro.
(ld_options): Recognize --version.
(usage): Move `program_name' from here ...
(program_name): ... to here. Add `static' qualifier.
(main): Recognize `OPTION_VERSION'.
2009-11-15 Felix Zielcke <fzielcke@z-51.de>
* Makefile.in (TARGET_CPPFLAGS): Replace `-isystem=$(srcdir)/include'
with `-nostdinc -isystem $(shell $(TARGET_CC) -print-file-name=include)'.
2009-11-14 Robert Millan <rmh.grub@aybabtu.com>
Fix help2man generation for mkisofs.
* util/mkisofs/mkisofs.c (ld_options): Recognize --help.
(usage): Send output to stdout (rather than stderr).
2009-11-14 Robert Millan <rmh.grub@aybabtu.com>
* conf/i386-coreboot.rmk (grub_mkrescue_SOURCES): Replace
`util/i386/coreboot/grub-mkrescue.in' with `util/grub-mkrescue.in'.
* conf/i386-pc.rmk (grub_mkrescue_SOURCES): Replace
`util/i386/pc/grub-mkrescue.in' with `util/grub-mkrescue.in'.
(bin_SCRIPTS): Add `grub-mkfloppy'.
(grub_mkfloppy_SOURCES): New variable.
* util/grub-mkrescue.in: New file.
* util/i386/pc/grub-mkfloppy.in: New file.
* util/i386/coreboot/grub-mkrescue.in: Remove.
* util/i386/pc/grub-mkrescue.in: Remove.
2009-11-13 Robert Millan <rmh.grub@aybabtu.com>
* include/grub/multiboot.h (struct grub_multiboot_header): Move
from here ...
* include/multiboot.h (struct multiboot_header): ... to here. Update
all users.
* include/grub/multiboot.h (struct grub_multiboot_info): Move
from here ...
* include/multiboot.h (struct multiboot_info): ... to here. Update
all users.
* include/grub/multiboot.h (struct grub_multiboot_mmap_entry): Move
from here ...
* include/multiboot.h (struct multiboot_mmap_entry): ... to here.
Update all users.
* include/grub/multiboot.h (struct grub_mod_list): Move
from here ...
* include/multiboot.h (struct multiboot_mod_list): ... to here.
Update all users.
2009-11-13 Robert Millan <rmh.grub@aybabtu.com>
* include/multiboot2.h (multiboot_word): Rename from this ...
(multiboot2_word): ... to this. Update all users.
(multiboot_header): Rename from this ...
(multiboot2_header): ... to this. Update all users.
(multiboot_tag_header): Rename from this ...
(multiboot2_tag_header): ... to this. Update all users.
(multiboot_tag_start): Rename from this ...
(multiboot2_tag_start): ... to this. Update all users.
(multiboot_tag_name): Rename from this ...
(multiboot2_tag_name): ... to this. Update all users.
(multiboot_tag_module): Rename from this ...
(multiboot2_tag_module): ... to this. Update all users.
(multiboot_tag_memory): Rename from this ...
(multiboot2_tag_memory): ... to this. Update all users.
(multiboot_tag_unused): Rename from this ...
(multiboot2_tag_unused): ... to this. Update all users.
(multiboot_tag_end): Rename from this ...
(multiboot2_tag_end): ... to this. Update all users.
2009-11-13 Robert Millan <rmh.grub@aybabtu.com> 2009-11-13 Robert Millan <rmh.grub@aybabtu.com>
Disable Multiboot2 in i386-ieee1275. It didn't actually work, and on Disable Multiboot2 in i386-ieee1275. It didn't actually work, and on

View file

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

View file

@ -36,7 +36,8 @@ grub_mkisofs_SOURCES = util/mkisofs/eltorito.c \
util/mkisofs/rock.c util/mkisofs/tree.c \ util/mkisofs/rock.c util/mkisofs/tree.c \
util/mkisofs/write.c \ util/mkisofs/write.c \
\ \
gnulib/fnmatch.c gnulib/getopt1.c gnulib/getopt.c gnulib/fnmatch.c gnulib/getopt1.c gnulib/getopt.c \
gnulib/error.c
grub_mkisofs_CFLAGS = -D_FILE_OFFSET_BITS=64 \ grub_mkisofs_CFLAGS = -D_FILE_OFFSET_BITS=64 \
-I$(srcdir)/util/mkisofs/include -I$(srcdir)/gnulib \ -I$(srcdir)/util/mkisofs/include -I$(srcdir)/gnulib \
-Wno-all -Werror -Wno-all -Werror

View file

@ -153,11 +153,11 @@ sbin_SCRIPTS += grub-install
grub_install_SOURCES = util/grub-install.in grub_install_SOURCES = util/grub-install.in
bin_SCRIPTS += grub-mkrescue bin_SCRIPTS += grub-mkrescue
grub_mkrescue_SOURCES = util/i386/coreboot/grub-mkrescue.in grub_mkrescue_SOURCES = util/grub-mkrescue.in
# Modules. # Modules.
pkglib_MODULES = linux.mod multiboot.mod \ pkglib_MODULES = linux.mod multiboot.mod \
aout.mod play.mod serial.mod ata.mod \ aout.mod play.mod serial.mod \
memdisk.mod pci.mod lspci.mod reboot.mod \ memdisk.mod pci.mod lspci.mod reboot.mod \
halt.mod datetime.mod date.mod datehook.mod \ halt.mod datetime.mod date.mod datehook.mod \
lsmmap.mod mmap.mod lsmmap.mod mmap.mod
@ -221,11 +221,6 @@ play_mod_SOURCES = commands/i386/pc/play.c
play_mod_CFLAGS = $(COMMON_CFLAGS) play_mod_CFLAGS = $(COMMON_CFLAGS)
play_mod_LDFLAGS = $(COMMON_LDFLAGS) play_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For ata.mod.
ata_mod_SOURCES = disk/ata.c
ata_mod_CFLAGS = $(COMMON_CFLAGS)
ata_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For memdisk.mod. # For memdisk.mod.
memdisk_mod_SOURCES = disk/memdisk.c memdisk_mod_SOURCES = disk/memdisk.c
memdisk_mod_CFLAGS = $(COMMON_CFLAGS) memdisk_mod_CFLAGS = $(COMMON_CFLAGS)

View file

@ -168,22 +168,21 @@ grub_emu_SOURCES += disk/usbms.c util/usb.c bus/usb/usb.c \
grub_emu_LDFLAGS += $(LIBCURSES) $(LIBUSB) grub_emu_LDFLAGS += $(LIBCURSES) $(LIBUSB)
endif endif
# Scripts. sbin_SCRIPTS += grub-install
sbin_SCRIPTS = grub-install
bin_SCRIPTS = grub-mkrescue
# For grub-install.
grub_install_SOURCES = util/grub-install.in grub_install_SOURCES = util/grub-install.in
# For grub-mkrescue. bin_SCRIPTS += grub-mkrescue
grub_mkrescue_SOURCES = util/i386/pc/grub-mkrescue.in grub_mkrescue_SOURCES = util/grub-mkrescue.in
pkglib_MODULES = biosdisk.mod chain.mod \ bin_SCRIPTS += grub-mkfloppy
multiboot.mod reboot.mod halt.mod \ grub_mkfloppy_SOURCES = util/i386/pc/grub-mkfloppy.in
vbe.mod vbetest.mod vbeinfo.mod play.mod serial.mod \
ata.mod vga.mod memdisk.mod pci.mod lspci.mod \ pkglib_MODULES = biosdisk.mod chain.mod \
aout.mod bsd.mod pxe.mod pxecmd.mod datetime.mod date.mod \ multiboot.mod reboot.mod halt.mod \
datehook.mod lsmmap.mod ata_pthru.mod hdparm.mod \ vbe.mod vbetest.mod vbeinfo.mod play.mod serial.mod \
vga.mod memdisk.mod pci.mod lspci.mod \
aout.mod bsd.mod pxe.mod pxecmd.mod datetime.mod date.mod \
datehook.mod lsmmap.mod ata_pthru.mod hdparm.mod \
usb.mod uhci.mod ohci.mod usbtest.mod usbms.mod usb_keyboard.mod \ usb.mod uhci.mod ohci.mod usbtest.mod usbms.mod usb_keyboard.mod \
efiemu.mod mmap.mod acpi.mod drivemap.mod efiemu.mod mmap.mod acpi.mod drivemap.mod
@ -294,11 +293,6 @@ play_mod_SOURCES = commands/i386/pc/play.c
play_mod_CFLAGS = $(COMMON_CFLAGS) play_mod_CFLAGS = $(COMMON_CFLAGS)
play_mod_LDFLAGS = $(COMMON_LDFLAGS) play_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For ata.mod.
ata_mod_SOURCES = disk/ata.c
ata_mod_CFLAGS = $(COMMON_CFLAGS)
ata_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For vga.mod. # For vga.mod.
vga_mod_SOURCES = term/i386/pc/vga.c vga_mod_SOURCES = term/i386/pc/vga.c
vga_mod_CFLAGS = $(COMMON_CFLAGS) vga_mod_CFLAGS = $(COMMON_CFLAGS)

View file

@ -14,3 +14,8 @@ pkglib_MODULES += vga_text.mod
vga_text_mod_SOURCES = term/i386/pc/vga_text.c term/i386/vga_common.c vga_text_mod_SOURCES = term/i386/pc/vga_text.c term/i386/vga_common.c
vga_text_mod_CFLAGS = $(COMMON_CFLAGS) vga_text_mod_CFLAGS = $(COMMON_CFLAGS)
vga_text_mod_LDFLAGS = $(COMMON_LDFLAGS) vga_text_mod_LDFLAGS = $(COMMON_LDFLAGS)
pkglib_MODULES += ata.mod
ata_mod_SOURCES = disk/ata.c
ata_mod_CFLAGS = $(COMMON_CFLAGS)
ata_mod_LDFLAGS = $(COMMON_LDFLAGS)

View file

@ -81,10 +81,10 @@ sbin_SCRIPTS = grub-install
grub_install_SOURCES = util/i386/efi/grub-install.in grub_install_SOURCES = util/i386/efi/grub-install.in
# Modules. # Modules.
pkglib_MODULES = kernel.mod chain.mod appleldr.mod \ pkglib_MODULES = kernel.mod chain.mod appleldr.mod \
halt.mod reboot.mod linux.mod pci.mod lspci.mod \ halt.mod reboot.mod linux.mod pci.mod lspci.mod \
datetime.mod date.mod datehook.mod loadbios.mod \ datetime.mod date.mod datehook.mod loadbios.mod \
fixvideo.mod mmap.mod acpi.mod fixvideo.mod mmap.mod acpi.mod ata.mod
# For kernel.mod. # For kernel.mod.
kernel_mod_EXPORTS = no kernel_mod_EXPORTS = no
@ -129,6 +129,11 @@ acpi_mod_SOURCES = commands/acpi.c commands/efi/acpi.c
acpi_mod_CFLAGS = $(COMMON_CFLAGS) acpi_mod_CFLAGS = $(COMMON_CFLAGS)
acpi_mod_LDFLAGS = $(COMMON_LDFLAGS) acpi_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For ata.mod
ata_mod_SOURCES = disk/ata.c
ata_mod_CFLAGS = $(COMMON_CFLAGS)
ata_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For mmap.mod. # For mmap.mod.
mmap_mod_SOURCES = mmap/mmap.c mmap/i386/uppermem.c mmap/i386/mmap.c \ mmap_mod_SOURCES = mmap/mmap.c mmap/i386/uppermem.c mmap/i386/mmap.c \
mmap/efi/mmap.c mmap/efi/mmap.c

View file

@ -140,7 +140,7 @@ grub_ata_dumpinfo (struct grub_ata_device *dev, char *info)
if (! dev->atapi) if (! dev->atapi)
{ {
grub_dprintf ("ata", "Addressing: %d\n", dev->addr); grub_dprintf ("ata", "Addressing: %d\n", dev->addr);
grub_dprintf ("ata", "Sectors: %lld\n", dev->size); grub_dprintf ("ata", "Sectors: %lld\n", (unsigned long long) dev->size);
} }
} }
@ -569,7 +569,7 @@ grub_ata_readwrite (grub_disk_t disk, grub_disk_addr_t sector,
{ {
struct grub_ata_device *dev = (struct grub_ata_device *) disk->data; struct grub_ata_device *dev = (struct grub_ata_device *) disk->data;
grub_dprintf("ata", "grub_ata_readwrite (size=%u, rw=%d)\n", size, rw); grub_dprintf("ata", "grub_ata_readwrite (size=%llu, rw=%d)\n", (unsigned long long) size, rw);
grub_ata_addressing_t addressing = dev->addr; grub_ata_addressing_t addressing = dev->addr;
grub_size_t batch; grub_size_t batch;
@ -596,7 +596,7 @@ grub_ata_readwrite (grub_disk_t disk, grub_disk_addr_t sector,
if (size - nsectors < batch) if (size - nsectors < batch)
batch = size - nsectors; batch = size - nsectors;
grub_dprintf("ata", "rw=%d, sector=%llu, batch=%u\n", rw, sector, batch); grub_dprintf("ata", "rw=%d, sector=%llu, batch=%llu\n", rw, (unsigned long long) sector, (unsigned long long) batch);
/* Send read/write command. */ /* Send read/write command. */
if (grub_ata_setaddress (dev, addressing, sector, batch)) if (grub_ata_setaddress (dev, addressing, sector, batch))
@ -755,7 +755,7 @@ grub_atapi_read (struct grub_scsi *scsi,
{ {
struct grub_ata_device *dev = (struct grub_ata_device *) scsi->data; struct grub_ata_device *dev = (struct grub_ata_device *) scsi->data;
grub_dprintf("ata", "grub_atapi_read (size=%u)\n", size); grub_dprintf("ata", "grub_atapi_read (size=%llu)\n", (unsigned long long) size);
if (grub_atapi_packet (dev, cmd, size)) if (grub_atapi_packet (dev, cmd, size))
return grub_errno; return grub_errno;

View file

@ -150,7 +150,7 @@ grub_pxefs_open (struct grub_file *file, const char *name)
if (! data) if (! data)
return grub_errno; return grub_errno;
data->block_size = grub_pxe_blksize; data->block_size = c.c2.packet_size;
grub_strcpy (data->filename, name); grub_strcpy (data->filename, name);
file_int = grub_malloc (sizeof (*file_int)); file_int = grub_malloc (sizeof (*file_int));
@ -205,13 +205,14 @@ grub_pxefs_read (grub_file_t file, char *buf, grub_size_t len)
o.gateway_ip = grub_pxe_gateway_ip; o.gateway_ip = grub_pxe_gateway_ip;
grub_strcpy ((char *)&o.filename[0], data->filename); grub_strcpy ((char *)&o.filename[0], data->filename);
o.tftp_port = grub_cpu_to_be16 (GRUB_PXE_TFTP_PORT); o.tftp_port = grub_cpu_to_be16 (GRUB_PXE_TFTP_PORT);
o.packet_size = data->block_size; o.packet_size = grub_pxe_blksize;
grub_pxe_call (GRUB_PXENV_TFTP_OPEN, &o); grub_pxe_call (GRUB_PXENV_TFTP_OPEN, &o);
if (o.status) if (o.status)
{ {
grub_error (GRUB_ERR_BAD_FS, "open fails"); grub_error (GRUB_ERR_BAD_FS, "open fails");
return -1; return -1;
} }
data->block_size = o.packet_size;
data->packet_number = 0; data->packet_number = 0;
curr_file = file; curr_file = file;
} }
@ -219,7 +220,7 @@ grub_pxefs_read (grub_file_t file, char *buf, grub_size_t len)
c.buffer = SEGOFS (GRUB_MEMORY_MACHINE_SCRATCH_ADDR); c.buffer = SEGOFS (GRUB_MEMORY_MACHINE_SCRATCH_ADDR);
while (pn >= data->packet_number) while (pn >= data->packet_number)
{ {
c.buffer_size = grub_pxe_blksize; c.buffer_size = data->block_size;
grub_pxe_call (GRUB_PXENV_TFTP_READ, &c); grub_pxe_call (GRUB_PXENV_TFTP_READ, &c);
if (c.status) if (c.status)
{ {

352
gnulib/error.c Normal file
View file

@ -0,0 +1,352 @@
/* Error handler for noninteractive utilities
Copyright (C) 1990-1998, 2000-2007, 2009 Free Software Foundation, Inc.
This file is part of the GNU C Library.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
#if !_LIBC
# include <config.h>
#endif
#include "error.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if !_LIBC && ENABLE_NLS
# include "gettext.h"
# define _(msgid) gettext (msgid)
#endif
#ifdef _LIBC
# include <libintl.h>
# include <stdbool.h>
# include <stdint.h>
# include <wchar.h>
# define mbsrtowcs __mbsrtowcs
#endif
#if USE_UNLOCKED_IO
# include "unlocked-io.h"
#endif
#ifndef _
# define _(String) String
#endif
/* If NULL, error will flush stdout, then print on stderr the program
name, a colon and a space. Otherwise, error will call this
function without parameters instead. */
void (*error_print_progname) (void);
/* This variable is incremented each time `error' is called. */
unsigned int error_message_count;
#ifdef _LIBC
/* In the GNU C library, there is a predefined variable for this. */
# define program_name program_invocation_name
# include <errno.h>
# include <limits.h>
# include <libio/libioP.h>
/* In GNU libc we want do not want to use the common name `error' directly.
Instead make it a weak alias. */
extern void __error (int status, int errnum, const char *message, ...)
__attribute__ ((__format__ (__printf__, 3, 4)));
extern void __error_at_line (int status, int errnum, const char *file_name,
unsigned int line_number, const char *message,
...)
__attribute__ ((__format__ (__printf__, 5, 6)));;
# define error __error
# define error_at_line __error_at_line
# include <libio/iolibio.h>
# define fflush(s) INTUSE(_IO_fflush) (s)
# undef putc
# define putc(c, fp) INTUSE(_IO_putc) (c, fp)
# include <bits/libc-lock.h>
#else /* not _LIBC */
# include <fcntl.h>
# if !HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P
# ifndef HAVE_DECL_STRERROR_R
"this configure-time declaration test was not run"
# endif
char *strerror_r ();
# endif
/* The calling program should define program_name and set it to the
name of the executing program. */
extern char *program_name;
# if HAVE_STRERROR_R || defined strerror_r
# define __strerror_r strerror_r
# endif /* HAVE_STRERROR_R || defined strerror_r */
#endif /* not _LIBC */
static void
print_errno_message (int errnum)
{
char const *s;
#if defined HAVE_STRERROR_R || _LIBC
char errbuf[1024];
# if STRERROR_R_CHAR_P || _LIBC
s = __strerror_r (errnum, errbuf, sizeof errbuf);
# else
if (__strerror_r (errnum, errbuf, sizeof errbuf) == 0)
s = errbuf;
else
s = 0;
# endif
#else
s = strerror (errnum);
#endif
#if !_LIBC
if (! s)
s = _("Unknown system error");
#endif
#if _LIBC
__fxprintf (NULL, ": %s", s);
#else
fprintf (stderr, ": %s", s);
#endif
}
static void
error_tail (int status, int errnum, const char *message, va_list args)
{
#if _LIBC
if (_IO_fwide (stderr, 0) > 0)
{
# define ALLOCA_LIMIT 2000
size_t len = strlen (message) + 1;
wchar_t *wmessage = NULL;
mbstate_t st;
size_t res;
const char *tmp;
bool use_malloc = false;
while (1)
{
if (__libc_use_alloca (len * sizeof (wchar_t)))
wmessage = (wchar_t *) alloca (len * sizeof (wchar_t));
else
{
if (!use_malloc)
wmessage = NULL;
wchar_t *p = (wchar_t *) realloc (wmessage,
len * sizeof (wchar_t));
if (p == NULL)
{
free (wmessage);
fputws_unlocked (L"out of memory\n", stderr);
return;
}
wmessage = p;
use_malloc = true;
}
memset (&st, '\0', sizeof (st));
tmp = message;
res = mbsrtowcs (wmessage, &tmp, len, &st);
if (res != len)
break;
if (__builtin_expect (len >= SIZE_MAX / 2, 0))
{
/* This really should not happen if everything is fine. */
res = (size_t) -1;
break;
}
len *= 2;
}
if (res == (size_t) -1)
{
/* The string cannot be converted. */
if (use_malloc)
{
free (wmessage);
use_malloc = false;
}
wmessage = (wchar_t *) L"???";
}
__vfwprintf (stderr, wmessage, args);
if (use_malloc)
free (wmessage);
}
else
#endif
vfprintf (stderr, message, args);
va_end (args);
++error_message_count;
if (errnum)
print_errno_message (errnum);
#if _LIBC
__fxprintf (NULL, "\n");
#else
putc ('\n', stderr);
#endif
fflush (stderr);
if (status)
exit (status);
}
/* Print the program name and error message MESSAGE, which is a printf-style
format string with optional args.
If ERRNUM is nonzero, print its corresponding system error message.
Exit with status STATUS if it is nonzero. */
void
error (int status, int errnum, const char *message, ...)
{
va_list args;
#if defined _LIBC && defined __libc_ptf_call
/* We do not want this call to be cut short by a thread
cancellation. Therefore disable cancellation for now. */
int state = PTHREAD_CANCEL_ENABLE;
__libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state),
0);
#endif
#if !_LIBC && defined F_GETFL
/* POSIX states that fflush (stdout) after fclose is unspecified; it
is safe in glibc, but not on all other platforms. fflush (NULL)
is always defined, but too draconian. */
if (0 <= fcntl (1, F_GETFL))
#endif
fflush (stdout);
#ifdef _LIBC
_IO_flockfile (stderr);
#endif
if (error_print_progname)
(*error_print_progname) ();
else
{
#if _LIBC
__fxprintf (NULL, "%s: ", program_name);
#else
fprintf (stderr, "%s: ", program_name);
#endif
}
va_start (args, message);
error_tail (status, errnum, message, args);
#ifdef _LIBC
_IO_funlockfile (stderr);
# ifdef __libc_ptf_call
__libc_ptf_call (pthread_setcancelstate, (state, NULL), 0);
# endif
#endif
}
/* Sometimes we want to have at most one error per line. This
variable controls whether this mode is selected or not. */
int error_one_per_line;
void
error_at_line (int status, int errnum, const char *file_name,
unsigned int line_number, const char *message, ...)
{
va_list args;
if (error_one_per_line)
{
static const char *old_file_name;
static unsigned int old_line_number;
if (old_line_number == line_number
&& (file_name == old_file_name
|| strcmp (old_file_name, file_name) == 0))
/* Simply return and print nothing. */
return;
old_file_name = file_name;
old_line_number = line_number;
}
#if defined _LIBC && defined __libc_ptf_call
/* We do not want this call to be cut short by a thread
cancellation. Therefore disable cancellation for now. */
int state = PTHREAD_CANCEL_ENABLE;
__libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state),
0);
#endif
#if !_LIBC && defined F_GETFL
/* POSIX states that fflush (stdout) after fclose is unspecified; it
is safe in glibc, but not on all other platforms. fflush (NULL)
is always defined, but too draconian. */
if (0 <= fcntl (1, F_GETFL))
#endif
fflush (stdout);
#ifdef _LIBC
_IO_flockfile (stderr);
#endif
if (error_print_progname)
(*error_print_progname) ();
else
{
#if _LIBC
__fxprintf (NULL, "%s:", program_name);
#else
fprintf (stderr, "%s:", program_name);
#endif
}
#if _LIBC
__fxprintf (NULL, file_name != NULL ? "%s:%d: " : " ",
file_name, line_number);
#else
fprintf (stderr, file_name != NULL ? "%s:%d: " : " ",
file_name, line_number);
#endif
va_start (args, message);
error_tail (status, errnum, message, args);
#ifdef _LIBC
_IO_funlockfile (stderr);
# ifdef __libc_ptf_call
__libc_ptf_call (pthread_setcancelstate, (state, NULL), 0);
# endif
#endif
}
#ifdef _LIBC
/* Make the weak alias. */
# undef error
# undef error_at_line
weak_alias (__error, error)
weak_alias (__error_at_line, error_at_line)
#endif

65
gnulib/error.h Normal file
View file

@ -0,0 +1,65 @@
/* Declaration for error-reporting function
Copyright (C) 1995, 1996, 1997, 2003, 2006, 2008 Free Software Foundation, Inc.
This file is part of the GNU C Library.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#ifndef _ERROR_H
#define _ERROR_H 1
#ifndef __attribute__
/* This feature is available in gcc versions 2.5 and later. */
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
# define __attribute__(Spec) /* empty */
# endif
/* The __-protected variants of `format' and `printf' attributes
are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
# define __format__ format
# define __printf__ printf
# endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* Print a message with `fprintf (stderr, FORMAT, ...)';
if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
If STATUS is nonzero, terminate the program with `exit (STATUS)'. */
extern void error (int __status, int __errnum, const char *__format, ...)
__attribute__ ((__format__ (__printf__, 3, 4)));
extern void error_at_line (int __status, int __errnum, const char *__fname,
unsigned int __lineno, const char *__format, ...)
__attribute__ ((__format__ (__printf__, 5, 6)));
/* If NULL, error will flush stdout, then print on stderr the program
name, a colon and a space. Otherwise, error will call this
function without parameters instead. */
extern void (*error_print_progname) (void);
/* This variable is incremented each time `error' is called. */
extern unsigned int error_message_count;
/* Sometimes we want to have at most one error per line. This
variable controls whether this mode is selected or not. */
extern int error_one_per_line;
#ifdef __cplusplus
}
#endif
#endif /* error.h */

View file

@ -21,10 +21,10 @@
/* The asm part of the multiboot loader. */ /* The asm part of the multiboot loader. */
void grub_multiboot_real_boot (grub_addr_t entry, void grub_multiboot_real_boot (grub_addr_t entry,
struct grub_multiboot_info *mbi) struct multiboot_info *mbi)
__attribute__ ((noreturn)); __attribute__ ((noreturn));
void grub_multiboot2_real_boot (grub_addr_t entry, void grub_multiboot2_real_boot (grub_addr_t entry,
struct grub_multiboot_info *mbi) struct multiboot_info *mbi)
__attribute__ ((noreturn)); __attribute__ ((noreturn));
extern grub_addr_t grub_multiboot_payload_orig; extern grub_addr_t grub_multiboot_payload_orig;

View file

@ -25,105 +25,4 @@
void grub_multiboot (int argc, char *argv[]); void grub_multiboot (int argc, char *argv[]);
void grub_module (int argc, char *argv[]); void grub_module (int argc, char *argv[]);
#ifndef ASM_FILE
#include <grub/types.h>
struct grub_multiboot_header
{
/* Must be MULTIBOOT_MAGIC - see above. */
grub_uint32_t magic;
/* Feature flags. */
grub_uint32_t flags;
/* The above fields plus this one must equal 0 mod 2^32. */
grub_uint32_t checksum;
/* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */
grub_uint32_t header_addr;
grub_uint32_t load_addr;
grub_uint32_t load_end_addr;
grub_uint32_t bss_end_addr;
grub_uint32_t entry_addr;
/* These are only valid if MULTIBOOT_VIDEO_MODE is set. */
grub_uint32_t mode_type;
grub_uint32_t width;
grub_uint32_t height;
grub_uint32_t depth;
};
struct grub_multiboot_info
{
/* Multiboot info version number */
grub_uint32_t flags;
/* Available memory from BIOS */
grub_uint32_t mem_lower;
grub_uint32_t mem_upper;
/* "root" partition */
grub_uint32_t boot_device;
/* Kernel command line */
grub_uint32_t cmdline;
/* Boot-Module list */
grub_uint32_t mods_count;
grub_uint32_t mods_addr;
grub_uint32_t syms[4];
/* Memory Mapping buffer */
grub_uint32_t mmap_length;
grub_uint32_t mmap_addr;
/* Drive Info buffer */
grub_uint32_t drives_length;
grub_uint32_t drives_addr;
/* ROM configuration table */
grub_uint32_t config_table;
/* Boot Loader Name */
grub_uint32_t boot_loader_name;
/* APM table */
grub_uint32_t apm_table;
/* Video */
grub_uint32_t vbe_control_info;
grub_uint32_t vbe_mode_info;
grub_uint16_t vbe_mode;
grub_uint16_t vbe_interface_seg;
grub_uint16_t vbe_interface_off;
grub_uint16_t vbe_interface_len;
};
struct grub_multiboot_mmap_entry
{
grub_uint32_t size;
grub_uint64_t addr;
grub_uint64_t len;
#define GRUB_MULTIBOOT_MEMORY_AVAILABLE 1
#define GRUB_MULTIBOOT_MEMORY_RESERVED 2
grub_uint32_t type;
} __attribute__((packed));
struct grub_mod_list
{
/* the memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive */
grub_uint32_t mod_start;
grub_uint32_t mod_end;
/* Module command line */
grub_uint32_t cmdline;
/* padding to take it to 16 bytes (must be zero) */
grub_uint32_t pad;
};
#endif /* ! ASM_FILE */
#endif /* ! GRUB_MULTIBOOT_HEADER */ #endif /* ! GRUB_MULTIBOOT_HEADER */

View file

@ -30,7 +30,7 @@ typedef grub_uint64_t uint64_t;
#define __WORDSIZE GRUB_TARGET_WORDSIZE #define __WORDSIZE GRUB_TARGET_WORDSIZE
#endif #endif
struct multiboot_tag_header; struct multiboot2_tag_header;
grub_err_t grub_err_t
grub_mb2_tag_alloc (grub_addr_t *addr, int key, grub_size_t len); grub_mb2_tag_alloc (grub_addr_t *addr, int key, grub_size_t len);
@ -42,7 +42,7 @@ void
grub_mb2_arch_boot (grub_addr_t entry, void *tags); grub_mb2_arch_boot (grub_addr_t entry, void *tags);
void void
grub_mb2_arch_unload (struct multiboot_tag_header *tags); grub_mb2_arch_unload (struct multiboot2_tag_header *tags);
grub_err_t grub_err_t
grub_mb2_arch_elf32_hook (Elf32_Phdr *phdr, grub_addr_t *addr, int *do_load); grub_mb2_arch_elf32_hook (Elf32_Phdr *phdr, grub_addr_t *addr, int *do_load);
@ -65,6 +65,6 @@ grub_module2 (int argc, char *argv[]);
#define for_each_tag(tag, tags) \ #define for_each_tag(tag, tags) \
for (tag = tags; \ for (tag = tags; \
tag && tag->key != MULTIBOOT2_TAG_END; \ tag && tag->key != MULTIBOOT2_TAG_END; \
tag = (struct multiboot_tag_header *)((char *)tag + tag->len)) tag = (struct multiboot2_tag_header *)((char *)tag + tag->len))
#endif /* ! GRUB_MULTIBOOT2_HEADER */ #endif /* ! GRUB_MULTIBOOT2_HEADER */

View file

@ -1,20 +1,23 @@
/* multiboot.h - multiboot header file. */
/* /*
* GRUB -- GRand Unified Bootloader * multiboot.h - Multiboot header file.
* Copyright (C) 2003,2007,2009 Free Software Foundation, Inc. * Copyright (C) 2003,2007,2008,2009 Free Software Foundation, Inc.
* *
* GRUB is free software: you can redistribute it and/or modify * Permission is hereby granted, free of charge, to any person obtaining a copy
* it under the terms of the GNU General Public License as published by * of this software and associated documentation files (the "Software"), to
* the Free Software Foundation, either version 3 of the License, or * deal in the Software without restriction, including without limitation the
* (at your option) any later version. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* *
* GRUB is distributed in the hope that it will be useful, * The above copyright notice and this permission notice shall be included in
* but WITHOUT ANY WARRANTY; without even the implied warranty of * all copies or substantial portions of the Software.
* 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 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* along with GRUB. If not, see <http://www.gnu.org/licenses/>. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ANY
* DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#ifndef MULTIBOOT_HEADER #ifndef MULTIBOOT_HEADER
@ -92,4 +95,105 @@
/* Is there video information? */ /* Is there video information? */
#define MULTIBOOT_INFO_VIDEO_INFO 0x00000800 #define MULTIBOOT_INFO_VIDEO_INFO 0x00000800
#ifndef ASM_FILE
#include <grub/types.h>
struct multiboot_header
{
/* Must be MULTIBOOT_MAGIC - see above. */
grub_uint32_t magic;
/* Feature flags. */
grub_uint32_t flags;
/* The above fields plus this one must equal 0 mod 2^32. */
grub_uint32_t checksum;
/* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */
grub_uint32_t header_addr;
grub_uint32_t load_addr;
grub_uint32_t load_end_addr;
grub_uint32_t bss_end_addr;
grub_uint32_t entry_addr;
/* These are only valid if MULTIBOOT_VIDEO_MODE is set. */
grub_uint32_t mode_type;
grub_uint32_t width;
grub_uint32_t height;
grub_uint32_t depth;
};
struct multiboot_info
{
/* Multiboot info version number */
grub_uint32_t flags;
/* Available memory from BIOS */
grub_uint32_t mem_lower;
grub_uint32_t mem_upper;
/* "root" partition */
grub_uint32_t boot_device;
/* Kernel command line */
grub_uint32_t cmdline;
/* Boot-Module list */
grub_uint32_t mods_count;
grub_uint32_t mods_addr;
grub_uint32_t syms[4];
/* Memory Mapping buffer */
grub_uint32_t mmap_length;
grub_uint32_t mmap_addr;
/* Drive Info buffer */
grub_uint32_t drives_length;
grub_uint32_t drives_addr;
/* ROM configuration table */
grub_uint32_t config_table;
/* Boot Loader Name */
grub_uint32_t boot_loader_name;
/* APM table */
grub_uint32_t apm_table;
/* Video */
grub_uint32_t vbe_control_info;
grub_uint32_t vbe_mode_info;
grub_uint16_t vbe_mode;
grub_uint16_t vbe_interface_seg;
grub_uint16_t vbe_interface_off;
grub_uint16_t vbe_interface_len;
};
struct multiboot_mmap_entry
{
grub_uint32_t size;
grub_uint64_t addr;
grub_uint64_t len;
#define MULTIBOOT_MEMORY_AVAILABLE 1
#define MULTIBOOT_MEMORY_RESERVED 2
grub_uint32_t type;
} __attribute__((packed));
struct multiboot_mod_list
{
/* the memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive */
grub_uint32_t mod_start;
grub_uint32_t mod_end;
/* Module command line */
grub_uint32_t cmdline;
/* padding to take it to 16 bytes (must be zero) */
grub_uint32_t pad;
};
#endif /* ! ASM_FILE */
#endif /* ! MULTIBOOT_HEADER */ #endif /* ! MULTIBOOT_HEADER */

View file

@ -40,18 +40,18 @@
/* XXX not portable? */ /* XXX not portable? */
#if __WORDSIZE == 64 #if __WORDSIZE == 64
typedef uint64_t multiboot_word; typedef uint64_t multiboot2_word;
#else #else
typedef uint32_t multiboot_word; typedef uint32_t multiboot2_word;
#endif #endif
struct multiboot_header struct multiboot2_header
{ {
uint32_t magic; uint32_t magic;
uint32_t flags; uint32_t flags;
}; };
struct multiboot_tag_header struct multiboot2_tag_header
{ {
uint32_t key; uint32_t key;
uint32_t len; uint32_t len;
@ -61,48 +61,48 @@ struct multiboot_tag_header
#define MULTIBOOT2_TAG_RESERVED2 (~0) #define MULTIBOOT2_TAG_RESERVED2 (~0)
#define MULTIBOOT2_TAG_START 1 #define MULTIBOOT2_TAG_START 1
struct multiboot_tag_start struct multiboot2_tag_start
{ {
struct multiboot_tag_header header; struct multiboot2_tag_header header;
multiboot_word size; /* Total size of all multiboot tags. */ multiboot2_word size; /* Total size of all multiboot tags. */
}; };
#define MULTIBOOT2_TAG_NAME 2 #define MULTIBOOT2_TAG_NAME 2
struct multiboot_tag_name struct multiboot2_tag_name
{ {
struct multiboot_tag_header header; struct multiboot2_tag_header header;
char name[1]; char name[1];
}; };
#define MULTIBOOT2_TAG_MODULE 3 #define MULTIBOOT2_TAG_MODULE 3
struct multiboot_tag_module struct multiboot2_tag_module
{ {
struct multiboot_tag_header header; struct multiboot2_tag_header header;
multiboot_word addr; multiboot2_word addr;
multiboot_word size; multiboot2_word size;
char type[36]; char type[36];
char cmdline[1]; char cmdline[1];
}; };
#define MULTIBOOT2_TAG_MEMORY 4 #define MULTIBOOT2_TAG_MEMORY 4
struct multiboot_tag_memory struct multiboot2_tag_memory
{ {
struct multiboot_tag_header header; struct multiboot2_tag_header header;
multiboot_word addr; multiboot2_word addr;
multiboot_word size; multiboot2_word size;
multiboot_word type; multiboot2_word type;
}; };
#define MULTIBOOT2_TAG_UNUSED 5 #define MULTIBOOT2_TAG_UNUSED 5
struct multiboot_tag_unused struct multiboot2_tag_unused
{ {
struct multiboot_tag_header header; struct multiboot2_tag_header header;
}; };
#define MULTIBOOT2_TAG_END 0xffff #define MULTIBOOT2_TAG_END 0xffff
struct multiboot_tag_end struct multiboot2_tag_end
{ {
struct multiboot_tag_header header; struct multiboot2_tag_header header;
}; };
#endif /* ! ASM_FILE */ #endif /* ! ASM_FILE */

View file

@ -26,15 +26,15 @@
grub_size_t grub_lower_mem, grub_upper_mem; grub_size_t grub_lower_mem, grub_upper_mem;
/* A pointer to the MBI in its initial location. */ /* A pointer to the MBI in its initial location. */
struct grub_multiboot_info *startup_multiboot_info; struct multiboot_info *startup_multiboot_info;
/* The MBI has to be copied to our BSS so that it won't be /* The MBI has to be copied to our BSS so that it won't be
overwritten. This is its final location. */ overwritten. This is its final location. */
static struct grub_multiboot_info kern_multiboot_info; static struct multiboot_info kern_multiboot_info;
/* Unfortunately we can't use heap at this point. But 32 looks like a sane /* Unfortunately we can't use heap at this point. But 32 looks like a sane
limit (used by memtest86). */ limit (used by memtest86). */
static grub_uint8_t mmap_entries[sizeof (struct grub_multiboot_mmap_entry) * 32]; static grub_uint8_t mmap_entries[sizeof (struct multiboot_mmap_entry) * 32];
void void
grub_machine_mmap_init () grub_machine_mmap_init ()
@ -43,7 +43,7 @@ grub_machine_mmap_init ()
grub_fatal ("Unable to find Multiboot Information (is CONFIG_MULTIBOOT disabled in coreboot?)"); grub_fatal ("Unable to find Multiboot Information (is CONFIG_MULTIBOOT disabled in coreboot?)");
/* Move MBI to a safe place. */ /* Move MBI to a safe place. */
grub_memmove (&kern_multiboot_info, startup_multiboot_info, sizeof (struct grub_multiboot_info)); grub_memmove (&kern_multiboot_info, startup_multiboot_info, sizeof (struct multiboot_info));
if ((kern_multiboot_info.flags & MULTIBOOT_INFO_MEM_MAP) == 0) if ((kern_multiboot_info.flags & MULTIBOOT_INFO_MEM_MAP) == 0)
grub_fatal ("Missing Multiboot memory information"); grub_fatal ("Missing Multiboot memory information");
@ -73,7 +73,7 @@ grub_machine_mmap_init ()
grub_err_t grub_err_t
grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t)) grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t))
{ {
struct grub_multiboot_mmap_entry *entry = (void *) kern_multiboot_info.mmap_addr; struct multiboot_mmap_entry *entry = (void *) kern_multiboot_info.mmap_addr;
while ((unsigned long) entry < kern_multiboot_info.mmap_addr + kern_multiboot_info.mmap_length) while ((unsigned long) entry < kern_multiboot_info.mmap_addr + kern_multiboot_info.mmap_length)
{ {

View file

@ -50,7 +50,7 @@
#endif #endif
extern grub_dl_t my_mod; extern grub_dl_t my_mod;
static struct grub_multiboot_info *mbi, *mbi_dest; static struct multiboot_info *mbi, *mbi_dest;
static grub_addr_t entry; static grub_addr_t entry;
static char *playground = 0; static char *playground = 0;
@ -74,9 +74,9 @@ grub_multiboot_unload (void)
for (i = 0; i < mbi->mods_count; i++) for (i = 0; i < mbi->mods_count; i++)
{ {
grub_free ((void *) grub_free ((void *)
((struct grub_mod_list *) mbi->mods_addr)[i].mod_start); ((struct multiboot_mod_list *) mbi->mods_addr)[i].mod_start);
grub_free ((void *) grub_free ((void *)
((struct grub_mod_list *) mbi->mods_addr)[i].cmdline); ((struct multiboot_mod_list *) mbi->mods_addr)[i].cmdline);
} }
grub_free ((void *) mbi->mods_addr); grub_free ((void *) mbi->mods_addr);
grub_free (playground); grub_free (playground);
@ -107,14 +107,14 @@ grub_get_multiboot_mmap_len (void)
grub_mmap_iterate (hook); grub_mmap_iterate (hook);
return count * sizeof (struct grub_multiboot_mmap_entry); return count * sizeof (struct multiboot_mmap_entry);
} }
/* Fill previously allocated Multiboot mmap. */ /* Fill previously allocated Multiboot mmap. */
static void static void
grub_fill_multiboot_mmap (struct grub_multiboot_mmap_entry *first_entry) grub_fill_multiboot_mmap (struct multiboot_mmap_entry *first_entry)
{ {
struct grub_multiboot_mmap_entry *mmap_entry = (struct grub_multiboot_mmap_entry *) first_entry; struct multiboot_mmap_entry *mmap_entry = (struct multiboot_mmap_entry *) first_entry;
auto int NESTED_FUNC_ATTR hook (grub_uint64_t, grub_uint64_t, grub_uint32_t); auto int NESTED_FUNC_ATTR hook (grub_uint64_t, grub_uint64_t, grub_uint32_t);
int NESTED_FUNC_ATTR hook (grub_uint64_t addr, grub_uint64_t size, grub_uint32_t type) int NESTED_FUNC_ATTR hook (grub_uint64_t addr, grub_uint64_t size, grub_uint32_t type)
@ -122,7 +122,7 @@ grub_fill_multiboot_mmap (struct grub_multiboot_mmap_entry *first_entry)
mmap_entry->addr = addr; mmap_entry->addr = addr;
mmap_entry->len = size; mmap_entry->len = size;
mmap_entry->type = type; mmap_entry->type = type;
mmap_entry->size = sizeof (struct grub_multiboot_mmap_entry) - sizeof (mmap_entry->size); mmap_entry->size = sizeof (struct multiboot_mmap_entry) - sizeof (mmap_entry->size);
mmap_entry++; mmap_entry++;
return 0; return 0;
@ -197,7 +197,7 @@ grub_multiboot (int argc, char *argv[])
{ {
grub_file_t file = 0; grub_file_t file = 0;
char buffer[MULTIBOOT_SEARCH], *cmdline = 0, *p; char buffer[MULTIBOOT_SEARCH], *cmdline = 0, *p;
struct grub_multiboot_header *header; struct multiboot_header *header;
grub_ssize_t len, cmdline_length, boot_loader_name_length; grub_ssize_t len, cmdline_length, boot_loader_name_length;
grub_uint32_t mmap_length; grub_uint32_t mmap_length;
int i; int i;
@ -228,9 +228,9 @@ grub_multiboot (int argc, char *argv[])
/* Look for the multiboot header in the buffer. The header should /* Look for the multiboot header in the buffer. The header should
be at least 12 bytes and aligned on a 4-byte boundary. */ be at least 12 bytes and aligned on a 4-byte boundary. */
for (header = (struct grub_multiboot_header *) buffer; for (header = (struct multiboot_header *) buffer;
((char *) header <= buffer + len - 12) || (header = 0); ((char *) header <= buffer + len - 12) || (header = 0);
header = (struct grub_multiboot_header *) ((char *) header + 4)) header = (struct multiboot_header *) ((char *) header + 4))
{ {
if (header->magic == MULTIBOOT_MAGIC if (header->magic == MULTIBOOT_MAGIC
&& !(header->magic + header->flags + header->checksum)) && !(header->magic + header->flags + header->checksum))
@ -275,12 +275,12 @@ grub_multiboot (int argc, char *argv[])
#define boot_loader_name_addr(x) \ #define boot_loader_name_addr(x) \
((void *) ((x) + code_size + cmdline_length)) ((void *) ((x) + code_size + cmdline_length))
#define mbi_addr(x) ((void *) ((x) + code_size + cmdline_length + boot_loader_name_length)) #define mbi_addr(x) ((void *) ((x) + code_size + cmdline_length + boot_loader_name_length))
#define mmap_addr(x) ((void *) ((x) + code_size + cmdline_length + boot_loader_name_length + sizeof (struct grub_multiboot_info))) #define mmap_addr(x) ((void *) ((x) + code_size + cmdline_length + boot_loader_name_length + sizeof (struct multiboot_info)))
grub_multiboot_payload_size = cmdline_length grub_multiboot_payload_size = cmdline_length
/* boot_loader_name_length might need to grow for mbi,etc to be aligned (see below) */ /* boot_loader_name_length might need to grow for mbi,etc to be aligned (see below) */
+ boot_loader_name_length + 3 + boot_loader_name_length + 3
+ sizeof (struct grub_multiboot_info) + mmap_length; + sizeof (struct multiboot_info) + mmap_length;
if (header->flags & MULTIBOOT_AOUT_KLUDGE) if (header->flags & MULTIBOOT_AOUT_KLUDGE)
{ {
@ -324,7 +324,7 @@ grub_multiboot (int argc, char *argv[])
mbi = mbi_addr (grub_multiboot_payload_orig); mbi = mbi_addr (grub_multiboot_payload_orig);
mbi_dest = mbi_addr (grub_multiboot_payload_dest); mbi_dest = mbi_addr (grub_multiboot_payload_dest);
grub_memset (mbi, 0, sizeof (struct grub_multiboot_info)); grub_memset (mbi, 0, sizeof (struct multiboot_info));
mbi->mmap_length = mmap_length; mbi->mmap_length = mmap_length;
grub_fill_multiboot_mmap (mmap_addr (grub_multiboot_payload_orig)); grub_fill_multiboot_mmap (mmap_addr (grub_multiboot_payload_orig));
@ -462,10 +462,10 @@ grub_module (int argc, char *argv[])
if (mbi->flags & MULTIBOOT_INFO_MODS) if (mbi->flags & MULTIBOOT_INFO_MODS)
{ {
struct grub_mod_list *modlist = (struct grub_mod_list *) mbi->mods_addr; struct multiboot_mod_list *modlist = (struct multiboot_mod_list *) mbi->mods_addr;
modlist = grub_realloc (modlist, (mbi->mods_count + 1) modlist = grub_realloc (modlist, (mbi->mods_count + 1)
* sizeof (struct grub_mod_list)); * sizeof (struct multiboot_mod_list));
if (! modlist) if (! modlist)
goto fail; goto fail;
mbi->mods_addr = (grub_uint32_t) modlist; mbi->mods_addr = (grub_uint32_t) modlist;
@ -478,7 +478,7 @@ grub_module (int argc, char *argv[])
} }
else else
{ {
struct grub_mod_list *modlist = grub_zalloc (sizeof (struct grub_mod_list)); struct multiboot_mod_list *modlist = grub_zalloc (sizeof (struct multiboot_mod_list));
if (! modlist) if (! modlist)
goto fail; goto fail;
modlist->mod_start = (grub_uint32_t) module; modlist->mod_start = (grub_uint32_t) module;

View file

@ -95,17 +95,17 @@ grub_mb2_arch_boot (grub_addr_t entry, void *tags)
} }
void void
grub_mb2_arch_unload (struct multiboot_tag_header *tags) grub_mb2_arch_unload (struct multiboot2_tag_header *tags)
{ {
struct multiboot_tag_header *tag; struct multiboot2_tag_header *tag;
/* Free all module memory in the tag list. */ /* Free all module memory in the tag list. */
for_each_tag (tag, tags) for_each_tag (tag, tags)
{ {
if (tag->key == MULTIBOOT2_TAG_MODULE) if (tag->key == MULTIBOOT2_TAG_MODULE)
{ {
struct multiboot_tag_module *module = struct multiboot2_tag_module *module =
(struct multiboot_tag_module *) tag; (struct multiboot2_tag_module *) tag;
grub_free((void *) module->addr); grub_free((void *) module->addr);
} }
} }

View file

@ -115,17 +115,17 @@ grub_mb2_tags_arch_create (void)
/* Release the memory we claimed from Open Firmware above. */ /* Release the memory we claimed from Open Firmware above. */
void void
grub_mb2_arch_unload (struct multiboot_tag_header *tags) grub_mb2_arch_unload (struct multiboot2_tag_header *tags)
{ {
struct multiboot_tag_header *tag; struct multiboot2_tag_header *tag;
/* Free all module memory in the tag list. */ /* Free all module memory in the tag list. */
for_each_tag (tag, tags) for_each_tag (tag, tags)
{ {
if (tag->key == MULTIBOOT2_TAG_MODULE) if (tag->key == MULTIBOOT2_TAG_MODULE)
{ {
struct multiboot_tag_module *module = struct multiboot2_tag_module *module =
(struct multiboot_tag_module *) tag; (struct multiboot2_tag_module *) tag;
grub_ieee1275_release (module->addr, module->size); grub_ieee1275_release (module->addr, module->size);
} }
} }

View file

@ -51,7 +51,7 @@ grub_mb2_tags_free (void)
grub_err_t grub_err_t
grub_mb2_tag_alloc (grub_addr_t *addr, int key, grub_size_t len) grub_mb2_tag_alloc (grub_addr_t *addr, int key, grub_size_t len)
{ {
struct multiboot_tag_header *tag; struct multiboot2_tag_header *tag;
grub_size_t used; grub_size_t used;
grub_size_t needed; grub_size_t needed;
@ -59,7 +59,7 @@ grub_mb2_tag_alloc (grub_addr_t *addr, int key, grub_size_t len)
key, (unsigned long) len); key, (unsigned long) len);
used = grub_mb2_tags_pos - grub_mb2_tags; used = grub_mb2_tags_pos - grub_mb2_tags;
len = ALIGN_UP (len, sizeof (multiboot_word)); len = ALIGN_UP (len, sizeof (multiboot2_word));
needed = used + len; needed = used + len;
@ -83,7 +83,7 @@ grub_mb2_tag_alloc (grub_addr_t *addr, int key, grub_size_t len)
grub_mb2_tags_pos = newarea + used; grub_mb2_tags_pos = newarea + used;
} }
tag = (struct multiboot_tag_header *) grub_mb2_tags_pos; tag = (struct multiboot2_tag_header *) grub_mb2_tags_pos;
grub_mb2_tags_pos += len; grub_mb2_tags_pos += len;
tag->key = key; tag->key = key;
@ -103,24 +103,24 @@ static grub_err_t
grub_mb2_tag_start_create (void) grub_mb2_tag_start_create (void)
{ {
return grub_mb2_tag_alloc (0, MULTIBOOT2_TAG_START, return grub_mb2_tag_alloc (0, MULTIBOOT2_TAG_START,
sizeof (struct multiboot_tag_start)); sizeof (struct multiboot2_tag_start));
} }
static grub_err_t static grub_err_t
grub_mb2_tag_name_create (void) grub_mb2_tag_name_create (void)
{ {
struct multiboot_tag_name *name; struct multiboot2_tag_name *name;
grub_addr_t name_addr; grub_addr_t name_addr;
grub_err_t err; grub_err_t err;
const char *grub_version = PACKAGE_STRING; const char *grub_version = PACKAGE_STRING;
err = grub_mb2_tag_alloc (&name_addr, MULTIBOOT2_TAG_NAME, err = grub_mb2_tag_alloc (&name_addr, MULTIBOOT2_TAG_NAME,
sizeof (struct multiboot_tag_name) + sizeof (struct multiboot2_tag_name) +
sizeof (grub_version) + 1); sizeof (grub_version) + 1);
if (err) if (err)
return err; return err;
name = (struct multiboot_tag_name *) name_addr; name = (struct multiboot2_tag_name *) name_addr;
grub_strcpy (name->name, grub_version); grub_strcpy (name->name, grub_version);
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
@ -159,17 +159,17 @@ error:
static grub_err_t static grub_err_t
grub_mb2_tags_finish (void) grub_mb2_tags_finish (void)
{ {
struct multiboot_tag_start *start; struct multiboot2_tag_start *start;
grub_err_t err; grub_err_t err;
/* Create the `end' tag. */ /* Create the `end' tag. */
err = grub_mb2_tag_alloc (0, MULTIBOOT2_TAG_END, err = grub_mb2_tag_alloc (0, MULTIBOOT2_TAG_END,
sizeof (struct multiboot_tag_end)); sizeof (struct multiboot2_tag_end));
if (err) if (err)
goto error; goto error;
/* We created the `start' tag first. Update it now. */ /* We created the `start' tag first. Update it now. */
start = (struct multiboot_tag_start *) grub_mb2_tags; start = (struct multiboot2_tag_start *) grub_mb2_tags;
start->size = grub_mb2_tags_pos - grub_mb2_tags; start->size = grub_mb2_tags_pos - grub_mb2_tags;
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
@ -195,17 +195,17 @@ grub_mb2_boot (void)
static grub_err_t static grub_err_t
grub_mb2_unload (void) grub_mb2_unload (void)
{ {
struct multiboot_tag_header *tag; struct multiboot2_tag_header *tag;
struct multiboot_tag_header *tags = struct multiboot2_tag_header *tags =
(struct multiboot_tag_header *) grub_mb2_tags; (struct multiboot2_tag_header *) grub_mb2_tags;
/* Free all module memory in the tag list. */ /* Free all module memory in the tag list. */
for_each_tag (tag, tags) for_each_tag (tag, tags)
{ {
if (tag->key == MULTIBOOT2_TAG_MODULE) if (tag->key == MULTIBOOT2_TAG_MODULE)
{ {
struct multiboot_tag_module *module = struct multiboot2_tag_module *module =
(struct multiboot_tag_module *) tag; (struct multiboot2_tag_module *) tag;
grub_free ((void *) module->addr); grub_free ((void *) module->addr);
} }
} }
@ -233,7 +233,7 @@ static grub_err_t
grub_mb2_tag_module_create (grub_addr_t modaddr, grub_size_t modsize, grub_mb2_tag_module_create (grub_addr_t modaddr, grub_size_t modsize,
char *type, int key, int argc, char *argv[]) char *type, int key, int argc, char *argv[])
{ {
struct multiboot_tag_module *module; struct multiboot2_tag_module *module;
grub_ssize_t argslen = 0; grub_ssize_t argslen = 0;
grub_err_t err; grub_err_t err;
char *p; char *p;
@ -246,11 +246,11 @@ grub_mb2_tag_module_create (grub_addr_t modaddr, grub_size_t modsize,
/* Note: includes implicit 1-byte cmdline. */ /* Note: includes implicit 1-byte cmdline. */
err = grub_mb2_tag_alloc (&module_addr, key, err = grub_mb2_tag_alloc (&module_addr, key,
sizeof (struct multiboot_tag_module) + argslen); sizeof (struct multiboot2_tag_module) + argslen);
if (err) if (err)
return grub_errno; return grub_errno;
module = (struct multiboot_tag_module *) module_addr; module = (struct multiboot2_tag_module *) module_addr;
module->addr = modaddr; module->addr = modaddr;
module->size = modsize; module->size = modsize;
grub_strcpy(module->type, type); grub_strcpy(module->type, type);
@ -308,7 +308,7 @@ grub_multiboot2 (int argc, char *argv[])
char *buffer; char *buffer;
grub_file_t file = 0; grub_file_t file = 0;
grub_elf_t elf = 0; grub_elf_t elf = 0;
struct multiboot_header *header = 0; struct multiboot2_header *header = 0;
char *p; char *p;
grub_ssize_t len; grub_ssize_t len;
grub_err_t err; grub_err_t err;
@ -344,7 +344,7 @@ grub_multiboot2 (int argc, char *argv[])
be at least 8 bytes and aligned on a 8-byte boundary. */ be at least 8 bytes and aligned on a 8-byte boundary. */
for (p = buffer; p <= buffer + len - 8; p += 8) for (p = buffer; p <= buffer + len - 8; p += 8)
{ {
header = (struct multiboot_header *) p; header = (struct multiboot2_header *) p;
if (header->magic == MULTIBOOT2_HEADER_MAGIC) if (header->magic == MULTIBOOT2_HEADER_MAGIC)
{ {
header_found = 1; header_found = 1;

View file

@ -44,7 +44,7 @@ static unsigned int module_version_status = 1;
static int static int
find_multi_boot1_header (grub_file_t file) find_multi_boot1_header (grub_file_t file)
{ {
struct grub_multiboot_header *header; struct multiboot_header *header;
char buffer[MULTIBOOT_SEARCH]; char buffer[MULTIBOOT_SEARCH];
int found_status = 0; int found_status = 0;
grub_ssize_t len; grub_ssize_t len;
@ -55,9 +55,9 @@ find_multi_boot1_header (grub_file_t file)
/* Look for the multiboot header in the buffer. The header should /* Look for the multiboot header in the buffer. The header should
be at least 12 bytes and aligned on a 4-byte boundary. */ be at least 12 bytes and aligned on a 4-byte boundary. */
for (header = (struct grub_multiboot_header *) buffer; for (header = (struct multiboot_header *) buffer;
((char *) header <= buffer + len - 12) || (header = 0); ((char *) header <= buffer + len - 12) || (header = 0);
header = (struct grub_multiboot_header *) ((char *) header + 4)) header = (struct multiboot_header *) ((char *) header + 4))
{ {
if (header->magic == MULTIBOOT_MAGIC if (header->magic == MULTIBOOT_MAGIC
&& !(header->magic + header->flags + header->checksum)) && !(header->magic + header->flags + header->checksum))

151
util/grub-mkrescue.in Normal file
View file

@ -0,0 +1,151 @@
#! /bin/sh -e
# Make GRUB rescue image
# 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.
transform="@program_transform_name@"
prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@
libdir=@libdir@
PACKAGE_NAME=@PACKAGE_NAME@
PACKAGE_TARNAME=@PACKAGE_TARNAME@
PACKAGE_VERSION=@PACKAGE_VERSION@
target_cpu=@target_cpu@
coreboot_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/${target_cpu}-coreboot
pc_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/${target_cpu}-pc
grub_mkisofs="grub-mkisofs"
# Usage: usage
# Print the usage.
usage () {
cat <<EOF
Usage: $0 [OPTION] SOURCE...
Make GRUB rescue image.
-h, --help print this message and exit
-v, --version print the version information and exit
--modules=MODULES pre-load specified modules MODULES
--output=FILE save output in FILE
$0 generates a bootable rescue image with specified source files or directories.
Report bugs to <bug-grub@gnu.org>.
EOF
}
# Check the arguments.
for option in "$@"; do
case "$option" in
-h | --help)
usage
exit 0 ;;
-v | --version)
echo "$0 (GNU GRUB ${PACKAGE_VERSION})"
exit 0 ;;
--modules=*)
modules=`echo "$option" | sed 's/--modules=//'` ;;
--output=*)
output_image=`echo "$option" | sed 's/--output=//'` ;;
-*)
echo "Unrecognized option \`$option'" 1>&2
usage
exit 1
;;
*)
source="${source} ${option}" ;;
esac
done
iso9660_dir=`mktemp -d`
mkdir -p ${iso9660_dir}/boot/grub
for platform in pc coreboot ; do
input_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/${target_cpu}-${platform}
if test -e ${input_dir} ; then
mkdir -p ${iso9660_dir}/boot/grub/${target_cpu}-${platform}
for file in ${input_dir}/*.mod ${input_dir}/efiemu??.o \
${input_dir}/command.lst ${input_dir}/moddep.lst ${input_dir}/fs.lst \
${input_dir}/handler.lst ${input_dir}/parttool.lst; do
if test -f "$file"; then
cp -f "$file" ${iso9660_dir}/boot/grub/${target_cpu}-${platform}/
fi
done
fi
done
# build coreboot core.img
if test -e ${coreboot_dir} ; then
memdisk_img=`mktemp`
memdisk_dir=`mktemp -d`
mkdir -p ${memdisk_dir}/boot/grub
# obtain date-based UUID
iso_uuid=$(date +%Y-%m-%d-%H-%M-%S-00)
modules="$(cat ${coreboot_dir}/partmap.lst) ${modules}"
cat << EOF > ${memdisk_dir}/boot/grub/grub.cfg
search --fs-uuid --set ${iso_uuid}
set prefix=(\${root})/boot/grub/${target_cpu}-coreboot
EOF
(for i in ${modules} ; do
echo "insmod $i"
done ; \
echo "source /boot/grub/grub.cfg") \
> ${iso9660_dir}/boot/grub/i386-pc/grub.cfg
tar -C ${memdisk_dir} -cf ${memdisk_img} boot
rm -rf ${memdisk_dir}
grub-mkelfimage -d ${coreboot_dir}/ -m ${memdisk_img} -o ${iso9660_dir}/boot/multiboot.img \
memdisk tar search iso9660 configfile sh \
ata at_keyboard
rm -f ${memdisk_img}
grub_mkisofs="${grub_mkisofs} --modification-date=$(echo ${iso_uuid} | sed -e s/-//g)"
fi
if [ "${source}" != "" ] ; then
for d in ${source}; do
echo "Processing $d"
cp -dpRl "${d}" ${iso9660_dir}/
done
fi
# build eltorito core.img
if test -e ${pc_dir} ; then
core_img=`mktemp`
grub-mkimage -d ${pc_dir}/ -o ${core_img} --prefix=/boot/grub/i386-pc \
memdisk tar search iso9660 configfile sh \
biosdisk
cat ${pc_dir}/cdboot.img ${core_img} > ${iso9660_dir}/boot/grub/i386-pc/eltorito.img
rm -f ${core_img}
modules="$(cat ${pc_dir}/partmap.lst) ${modules}"
(for i in ${modules} ; do
echo "insmod $i"
done ; \
echo "source /boot/grub/grub.cfg") \
> ${iso9660_dir}/boot/grub/i386-pc/grub.cfg
grub_mkisofs="${grub_mkisofs} -b boot/grub/i386-pc/eltorito.img -boot-info-table"
fi
# build iso image
${grub_mkisofs} -o ${output_image} -r -J ${iso9660_dir}
rm -rf ${iso9660_dir}
exit 0

View file

@ -1,7 +1,7 @@
#! /bin/sh -e #! /bin/sh -e
# Make GRUB rescue image # Make GRUB rescue floppy
# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. # Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008 Free Software Foundation, Inc.
# #
# GRUB is free software: you can redistribute it and/or modify # GRUB is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -30,26 +30,19 @@ target_cpu=@target_cpu@
platform=@platform@ platform=@platform@
pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}` pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}`
grub_mkimage=${bindir}/`echo grub-mkelfimage | sed ${transform}`
grub_mkisofs=${bindir}/`echo grub-mkisofs | sed ${transform}`
# Usage: usage # Usage: usage
# Print the usage. # Print the usage.
usage () { usage () {
cat <<EOF cat <<EOF
Usage: $0 [OPTION] output_image Usage: $0 [OPTION] output_image
Make GRUB rescue image. Make GRUB rescue floppy.
-h, --help print this message and exit -h, --help print this message and exit
-v, --version print the version information and exit -v, --version print the version information and exit
--modules=MODULES pre-load specified modules MODULES --modules=MODULES pre-load specified modules MODULES
--overlay=DIR overlay directory DIR in the memdisk image --output=FILE save output in FILE
(may be specified multiple times)
--pkglibdir=DIR use images from directory DIR instead of ${pkglibdir}
--grub-mkimage=FILE use FILE as grub-mkimage
--grub-mkisofs=FILE use FILE as grub-mkisofs
$0 generates a bootable rescue image. $0 generates a bootable rescue floppy.
Report bugs to <bug-grub@gnu.org>. Report bugs to <bug-grub@gnu.org>.
EOF EOF
@ -68,14 +61,8 @@ for option in "$@"; do
exit 0 ;; exit 0 ;;
--modules=*) --modules=*)
modules=`echo "$option" | sed 's/--modules=//'` ;; modules=`echo "$option" | sed 's/--modules=//'` ;;
--overlay=*) --output=*)
overlay=${overlay}${overlay:+ }`echo "$option" | sed 's/--overlay=//'` ;; output_image=`echo "$option" | sed 's/--output=//'` ;;
--pkglibdir=*)
input_dir=`echo "$option" | sed 's/--pkglibdir=//'` ;;
--grub-mkimage=*)
grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;;
--grub-mkisofs=*)
grub_mkisofs=`echo "$option" | sed 's/--grub-mkisofs=//'` ;;
-*) -*)
echo "Unrecognized option \`$option'" 1>&2 echo "Unrecognized option \`$option'" 1>&2
usage usage
@ -96,53 +83,34 @@ if test "x$output_image" = x; then
exit 1 exit 1
fi fi
memdisk_dir=`mktemp -d` aux_dir=`mktemp -d`
iso9660_dir=`mktemp -d` mkdir -p ${aux_dir}/boot/grub
mkdir -p ${memdisk_dir}/boot/grub ${iso9660_dir}/boot/grub
for file in ${input_dir}/*.mod ${input_dir}/efiemu??.o \ for file in ${input_dir}/*.mod ${input_dir}/efiemu??.o \
${input_dir}/command.lst ${input_dir}/moddep.lst ${input_dir}/fs.lst \ ${input_dir}/command.lst ${input_dir}/moddep.lst ${input_dir}/fs.lst \
${input_dir}/handler.lst ${input_dir}/parttool.lst; do ${input_dir}/handler.lst ${input_dir}/parttool.lst; do
if test -f "$file"; then if test -f "$file"; then
cp -f "$file" ${iso9660_dir}/boot/grub/ cp -f "$file" ${aux_dir}/boot/grub/
fi fi
done done
# obtain date-based UUID modules="$(cat ${input_dir}/partmap.lst) ${modules}"
iso_uuid=$(date +%Y-%m-%d-%H-%M-%S-00) for i in ${modules} ; do
echo "insmod $i"
# first-stage grub.cfg done > ${aux_dir}/boot/grub/grub.cfg
cat << EOF >> ${memdisk_dir}/boot/grub/grub.cfg
search --fs-uuid --set ${iso_uuid}
set prefix=(\${root})/boot/grub
source /boot/grub/grub.cfg
EOF
# build memdisk # build memdisk
memdisk_img=`mktemp` memdisk_img=`mktemp`
tar -C ${memdisk_dir} -cf ${memdisk_img} boot tar -C ${aux_dir} -cf ${memdisk_img} boot
rm -rf ${memdisk_dir} rm -rf ${aux_dir}
# build core.img # build core.img
mkdir -p ${iso9660_dir}/boot/grub core_img=`mktemp`
${grub_mkimage} -d ${input_dir}/ -m ${memdisk_img} -o ${iso9660_dir}/boot/multiboot.img \ grub-mkimage -d ${input_dir}/ -m ${memdisk_img} -o ${core_img} memdisk tar biosdisk
at_keyboard memdisk tar ata search iso9660 configfile sh
rm -f ${memdisk_img} rm -f ${memdisk_img}
for d in ${overlay}; do # build floppy image
echo "Overlaying $d" cat ${input_dir}/boot.img ${core_img} /dev/zero | dd bs=1024 count=1440 > ${output_image}
cp -dpR "${d}"/* "${iso9660_dir}"/ rm -f ${core_img}
done
# second-stage grub.cfg
modules="`cat ${input_dir}/partmap.lst` ${modules}"
for i in ${modules} ; do
echo "insmod $i"
done > ${iso9660_dir}/boot/grub/grub.cfg
# build iso image
${grub_mkisofs} \
--modification-date=$(echo ${iso_uuid} | sed -e s/-//g) \
-o ${output_image} -r -J ${iso9660_dir}
exit 0 exit 0

View file

@ -1,180 +0,0 @@
#! /bin/sh -e
# Make GRUB rescue image
# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008 Free Software Foundation, Inc.
#
# GRUB is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GRUB is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
# Initialize some variables.
transform="@program_transform_name@"
prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@
libdir=@libdir@
PACKAGE_NAME=@PACKAGE_NAME@
PACKAGE_TARNAME=@PACKAGE_TARNAME@
PACKAGE_VERSION=@PACKAGE_VERSION@
target_cpu=@target_cpu@
platform=@platform@
pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}`
grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}`
# Usage: usage
# Print the usage.
usage () {
cat <<EOF
Usage: $0 [OPTION] output_image
Make GRUB rescue image.
-h, --help print this message and exit
-v, --version print the version information and exit
--modules=MODULES pre-load specified modules MODULES
--overlay=DIR overlay directory DIR in the memdisk image
(may be specified multiple times)
--pkglibdir=DIR use images from directory DIR instead of ${pkglibdir}
--grub-mkimage=FILE use FILE as grub-mkimage
--image-type=TYPE select floppy or cdrom (default)
--emulation=TYPE select El Torito boot emulation type floppy
or none (default) (cdrom only)
$0 generates a bootable rescue image of the specified type.
Report bugs to <bug-grub@gnu.org>.
EOF
}
image_type=cdrom
input_dir=${pkglibdir}
emulation=none
# Check the arguments.
for option in "$@"; do
case "$option" in
-h | --help)
usage
exit 0 ;;
-v | --version)
echo "$0 (GNU GRUB ${PACKAGE_VERSION})"
exit 0 ;;
--modules=*)
modules=`echo "$option" | sed 's/--modules=//'` ;;
--overlay=*)
overlay=${overlay}${overlay:+ }`echo "$option" | sed 's/--overlay=//'` ;;
--pkglibdir=*)
input_dir=`echo "$option" | sed 's/--pkglibdir=//'` ;;
--grub-mkimage=*)
grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;;
--image-type=*)
image_type=`echo "$option" | sed 's/--image-type=//'`
case "$image_type" in
floppy|cdrom) ;;
*)
echo "Unknown image type \`$image_type'" 1>&2
exit 1 ;;
esac ;;
--emulation=*)
emulation=`echo "$option" | sed 's/--emulation=//'`
case "$emulation" in
floppy|none) ;;
*)
echo "Unknown emulation type \`$emulation'" 1>&2
exit 1 ;;
esac ;;
-*)
echo "Unrecognized option \`$option'" 1>&2
usage
exit 1
;;
*)
if test "x$output_image" != x; then
echo "Unrecognized option \`$option'" 1>&2
usage
exit 1
fi
output_image="${option}" ;;
esac
done
if test "x$output_image" = x; then
usage
exit 1
fi
aux_dir=`mktemp -d`
mkdir -p ${aux_dir}/boot/grub
for file in ${input_dir}/*.mod ${input_dir}/efiemu??.o \
${input_dir}/command.lst ${input_dir}/moddep.lst ${input_dir}/fs.lst \
${input_dir}/handler.lst ${input_dir}/parttool.lst; do
if test -f "$file"; then
cp -f "$file" ${aux_dir}/boot/grub/
fi
done
modules="biosdisk `cat ${input_dir}/partmap.lst` ${modules}"
for i in ${modules} ; do
echo "insmod $i"
done > ${aux_dir}/boot/grub/grub.cfg
for d in ${overlay}; do
echo "Overlaying $d"
cp -dpR "${d}"/* "${aux_dir}"/
done
if [ "x${image_type}" = xfloppy -o "x${emulation}" = xfloppy ] ; then
# build memdisk
memdisk_img=`mktemp`
tar -C ${aux_dir} -cf ${memdisk_img} boot
rm -rf ${aux_dir}
# build core.img
core_img=`mktemp`
${grub_mkimage} -d ${input_dir}/ -m ${memdisk_img} -o ${core_img} memdisk tar
rm -f ${memdisk_img}
# build floppy image
if [ "x${image_type}" = xcdrom ] ; then
floppy_dir=`mktemp -d`
floppy_img=${floppy_dir}/grub_floppy.img
else
floppy_img=${output_image}
fi
cat ${input_dir}/boot.img ${core_img} /dev/zero | dd bs=1024 count=1440 > ${floppy_img}
rm -f ${core_img}
if [ "x${image_type}" = xcdrom ] ; then
# build iso image
genisoimage -b grub_floppy.img \
-o ${output_image} -r -J ${floppy_dir}
rm -rf ${floppy_dir}
fi
else
# build core.img
core_img=`mktemp`
${grub_mkimage} -d ${input_dir}/ -o ${core_img} biosdisk iso9660
# build grub_eltorito image
cat ${input_dir}/cdboot.img ${core_img} > ${aux_dir}/boot/grub/grub_eltorito
rm -f ${core_img}
# build iso image
genisoimage -b boot/grub/grub_eltorito \
-no-emul-boot -boot-load-size 4 -boot-info-table \
-o ${output_image} -r -J ${aux_dir}
rm -rf ${aux_dir}
fi
exit 0

View file

@ -22,7 +22,7 @@
along with this program; if not, see <http://www.gnu.org/licenses/>. along with this program; if not, see <http://www.gnu.org/licenses/>.
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
static char rcsid[] ="$Id: mkisofs.c,v 1.32 1999/03/07 21:48:49 eric Exp $"; const char *program_name = "grub-mkisofs";
#include <errno.h> #include <errno.h>
#include "config.h" #include "config.h"
@ -195,6 +195,8 @@ struct ld_option
#define OPTION_NO_EMUL_BOOT 171 #define OPTION_NO_EMUL_BOOT 171
#define OPTION_ELTORITO_EMUL_FLOPPY 172 #define OPTION_ELTORITO_EMUL_FLOPPY 172
#define OPTION_VERSION 173
static const struct ld_option ld_options[] = static const struct ld_option ld_options[] =
{ {
{ {"all-files", no_argument, NULL, 'a'}, { {"all-files", no_argument, NULL, 'a'},
@ -227,6 +229,10 @@ static const struct ld_option ld_options[] =
'f', NULL, "Follow symbolic links", ONE_DASH }, 'f', NULL, "Follow symbolic links", ONE_DASH },
{ {"help", no_argument, NULL, OPTION_HELP}, { {"help", no_argument, NULL, OPTION_HELP},
'\0', NULL, "Print option help", ONE_DASH }, '\0', NULL, "Print option help", ONE_DASH },
{ {"help", no_argument, NULL, OPTION_HELP},
'\0', NULL, "Print option help", TWO_DASHES },
{ {"version", no_argument, NULL, OPTION_VERSION},
'\0', NULL, "Print version information and exit", TWO_DASHES },
{ {"hide", required_argument, NULL, OPTION_I_HIDE}, { {"hide", required_argument, NULL, OPTION_I_HIDE},
'\0', "GLOBFILE", "Hide ISO9660/RR file" , ONE_DASH }, '\0', "GLOBFILE", "Hide ISO9660/RR file" , ONE_DASH },
{ {"hide-joliet", required_argument, NULL, OPTION_J_HIDE}, { {"hide-joliet", required_argument, NULL, OPTION_J_HIDE},
@ -462,23 +468,12 @@ int goof = 0;
#endif #endif
void usage(){ void usage(){
const char * program_name = "mkisofs";
#if 0
fprintf(stderr,"Usage:\n");
fprintf(stderr,
"mkisofs [-o outfile] [-R] [-V volid] [-v] [-a] \
[-T]\n [-l] [-d] [-V] [-D] [-L] [-p preparer]"
"[-P publisher] [ -A app_id ] [-z] \n \
[-b boot_image_name] [-c boot_catalog-name] \
[-x path -x path ...] path\n");
#endif
unsigned int i; unsigned int i;
/* const char **targets, **pp;*/ /* const char **targets, **pp;*/
fprintf (stderr, "Usage: %s [options] file...\n", program_name); printf ("Usage: %s [options] file...\n", program_name);
fprintf (stderr, "Options:\n"); printf ("Options:\n");
for (i = 0; i < OPTION_COUNT; i++) for (i = 0; i < OPTION_COUNT; i++)
{ {
if (ld_options[i].doc != NULL) if (ld_options[i].doc != NULL)
@ -487,7 +482,7 @@ void usage(){
int len; int len;
unsigned int j; unsigned int j;
fprintf (stderr, " "); printf (" ");
comma = FALSE; comma = FALSE;
len = 2; len = 2;
@ -498,16 +493,16 @@ void usage(){
if (ld_options[j].shortopt != '\0' if (ld_options[j].shortopt != '\0'
&& ld_options[j].control != NO_HELP) && ld_options[j].control != NO_HELP)
{ {
fprintf (stderr, "%s-%c", comma ? ", " : "", ld_options[j].shortopt); printf ("%s-%c", comma ? ", " : "", ld_options[j].shortopt);
len += (comma ? 2 : 0) + 2; len += (comma ? 2 : 0) + 2;
if (ld_options[j].arg != NULL) if (ld_options[j].arg != NULL)
{ {
if (ld_options[j].opt.has_arg != optional_argument) if (ld_options[j].opt.has_arg != optional_argument)
{ {
fprintf (stderr, " "); putchar (' ');
++len; ++len;
} }
fprintf (stderr, "%s", ld_options[j].arg); printf ("%s", ld_options[j].arg);
len += strlen (ld_options[j].arg); len += strlen (ld_options[j].arg);
} }
comma = TRUE; comma = TRUE;
@ -522,7 +517,7 @@ void usage(){
if (ld_options[j].opt.name != NULL if (ld_options[j].opt.name != NULL
&& ld_options[j].control != NO_HELP) && ld_options[j].control != NO_HELP)
{ {
fprintf (stderr, "%s-%s%s", printf ("%s-%s%s",
comma ? ", " : "", comma ? ", " : "",
ld_options[j].control == TWO_DASHES ? "-" : "", ld_options[j].control == TWO_DASHES ? "-" : "",
ld_options[j].opt.name); ld_options[j].opt.name);
@ -532,7 +527,7 @@ void usage(){
+ strlen (ld_options[j].opt.name)); + strlen (ld_options[j].opt.name));
if (ld_options[j].arg != NULL) if (ld_options[j].arg != NULL)
{ {
fprintf (stderr, " %s", ld_options[j].arg); printf (" %s", ld_options[j].arg);
len += 1 + strlen (ld_options[j].arg); len += 1 + strlen (ld_options[j].arg);
} }
comma = TRUE; comma = TRUE;
@ -543,14 +538,14 @@ void usage(){
if (len >= 30) if (len >= 30)
{ {
fprintf (stderr, "\n"); printf ("\n");
len = 0; len = 0;
} }
for (; len < 30; len++) for (; len < 30; len++)
fputc (' ', stderr); putchar (' ');
fprintf (stderr, "%s\n", ld_options[i].doc); printf ("%s\n", ld_options[i].doc);
} }
} }
exit(1); exit(1);
@ -886,6 +881,10 @@ int FDECL2(main, int, argc, char **, argv){
usage (); usage ();
exit (0); exit (0);
break; break;
case OPTION_VERSION:
printf ("%s (%s %s)\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
exit (0);
break;
case OPTION_NOSPLIT_SL_COMPONENT: case OPTION_NOSPLIT_SL_COMPONENT:
split_SL_component = 0; split_SL_component = 0;
break; break;

View file

@ -213,7 +213,7 @@ int FDECL3(iso9660_file_length,
} }
if(current_length < 30) if(current_length < 30)
{ {
if( *pnt < 0 ) if( !isascii (*pnt))
{ {
*result++ = '_'; *result++ = '_';
} }
@ -281,7 +281,7 @@ int FDECL3(iso9660_file_length,
switch (*pnt) switch (*pnt)
{ {
default: default:
if( *pnt < 0 ) if( !isascii (*pnt) )
{ {
*result++ = '_'; *result++ = '_';
} }