Merge mainline into yeeloongfw
This commit is contained in:
commit
a6132b9f3f
172 changed files with 12449 additions and 6208 deletions
|
@ -107,10 +107,6 @@ grub_machine_fini (void)
|
|||
grub_console_fini ();
|
||||
}
|
||||
|
||||
void
|
||||
read_command_list (void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
static struct option options[] =
|
||||
|
@ -150,6 +146,11 @@ usage (int status)
|
|||
}
|
||||
|
||||
|
||||
void grub_hostfs_init (void);
|
||||
void grub_hostfs_fini (void);
|
||||
void grub_host_init (void);
|
||||
void grub_host_fini (void);
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
|
@ -161,8 +162,6 @@ main (int argc, char *argv[])
|
|||
|
||||
set_program_name (argv[0]);
|
||||
|
||||
grub_util_init_nls ();
|
||||
|
||||
while ((opt = getopt_long (argc, argv, "r:d:m:vH:hV", options, 0)) != -1)
|
||||
switch (opt)
|
||||
{
|
||||
|
@ -210,6 +209,8 @@ main (int argc, char *argv[])
|
|||
|
||||
signal (SIGINT, SIG_IGN);
|
||||
grub_console_init ();
|
||||
grub_host_init ();
|
||||
grub_hostfs_init ();
|
||||
|
||||
/* XXX: This is a bit unportable. */
|
||||
grub_util_biosdisk_init (dev_map);
|
||||
|
@ -242,6 +243,8 @@ main (int argc, char *argv[])
|
|||
grub_main ();
|
||||
|
||||
grub_fini_all ();
|
||||
grub_hostfs_fini ();
|
||||
grub_host_fini ();
|
||||
|
||||
grub_machine_fini ();
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ platform=@platform@
|
|||
host_os=@host_os@
|
||||
font=@datadir@/@PACKAGE_TARNAME@/ascii.pf2
|
||||
pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}`
|
||||
localedir=@datadir@/locale
|
||||
|
||||
grub_setup=${sbindir}/`echo grub-setup | sed ${transform}`
|
||||
if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] || [ "${target_cpu}-${platform}" = "mips-yeeloong" ] ; then
|
||||
|
@ -218,8 +219,7 @@ else
|
|||
fi
|
||||
|
||||
# Create the GRUB directory if it is not present.
|
||||
test -d "$bootdir" || mkdir "$bootdir" || exit 1
|
||||
test -d "$grubdir" || mkdir "$grubdir" || exit 1
|
||||
mkdir -p "$grubdir" || exit 1
|
||||
|
||||
# If --recheck is specified, remove the device map, if present.
|
||||
if test $recheck = yes; then
|
||||
|
@ -263,14 +263,14 @@ fi
|
|||
|
||||
# Copy gettext files
|
||||
mkdir -p ${grubdir}/locale/
|
||||
for file in ${grubdir}/locale/*.mo ${pkglibdir}/locale/*.mo; do
|
||||
if test -f "$file"; then
|
||||
cp -f "$file" ${grubdir}/locale/
|
||||
for dir in ${localedir}/*; do
|
||||
if test -f "$dir/LC_MESSAGES/grub.mo"; then
|
||||
cp -f "$dir/LC_MESSAGES/grub.mo" "${grubdir}/locale/${dir##*/}.mo"
|
||||
fi
|
||||
done
|
||||
|
||||
# Write device to a variable so we don't have to traverse /dev every time.
|
||||
grub_device=`$grub_probe --target=device ${grubdir}`
|
||||
grub_device=`$grub_probe --target=device ${grubdir}` || exit 1
|
||||
|
||||
if ! test -f ${grubdir}/grubenv; then
|
||||
$grub_editenv ${grubdir}/grubenv create
|
||||
|
@ -287,7 +287,10 @@ 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=`$grub_probe --target=partmap --device ${grub_device} 2> /dev/null`
|
||||
partmap_module=
|
||||
for x in `$grub_probe --target=partmap --device ${grub_device} 2> /dev/null`; do
|
||||
partmap_module="$partmap_module part_$x";
|
||||
done
|
||||
|
||||
# Device abstraction module, if any (lvm, raid).
|
||||
devabstraction_module=`$grub_probe --target=abstraction --device ${grub_device}`
|
||||
|
@ -309,11 +312,11 @@ if [ "x${devabstraction_module}" = "x" ] ; then
|
|||
if echo "${install_device}" | grep -qx "(.*)" ; then
|
||||
install_drive="${install_device}"
|
||||
else
|
||||
install_drive="`$grub_probe --target=drive --device ${install_device}`"
|
||||
install_drive="`$grub_probe --target=drive --device ${install_device}`" || exit 1
|
||||
fi
|
||||
install_drive="`echo ${install_drive} | sed -e s/,[0-9]*[a-z]*//g`"
|
||||
fi
|
||||
grub_drive="`$grub_probe --target=drive --device ${grub_device}`"
|
||||
grub_drive="`$grub_probe --target=drive --device ${grub_device}`" || exit 1
|
||||
|
||||
# Strip partition number
|
||||
grub_drive="`echo ${grub_drive} | sed -e s/,[0-9]*[a-z]*//g`"
|
||||
|
@ -340,7 +343,7 @@ if [ "x${devabstraction_module}" = "x" ] ; then
|
|||
modules="$modules search_fs_uuid"
|
||||
fi
|
||||
else
|
||||
prefix_drive=`$grub_probe --target=drive --device ${grub_device}`
|
||||
prefix_drive=`$grub_probe --target=drive --device ${grub_device}` || exit 1
|
||||
fi
|
||||
|
||||
if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <grub/machine/kernel.h>
|
||||
#include <grub/machine/memory.h>
|
||||
#include <grub/elf.h>
|
||||
#include <grub/aout.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/kernel.h>
|
||||
#include <grub/disk.h>
|
||||
|
@ -232,6 +233,36 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
|
|||
|
||||
grub_util_info ("the core size is 0x%x", core_size);
|
||||
|
||||
#ifdef GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE
|
||||
*((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE))
|
||||
= grub_host_to_target32 (total_module_size);
|
||||
#endif
|
||||
*((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_KERNEL_IMAGE_SIZE))
|
||||
= grub_host_to_target32 (kernel_size);
|
||||
#ifdef GRUB_KERNEL_MACHINE_COMPRESSED_SIZE
|
||||
*((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_COMPRESSED_SIZE))
|
||||
= grub_host_to_target32 (core_size - GRUB_KERNEL_MACHINE_RAW_SIZE);
|
||||
#endif
|
||||
|
||||
#if defined(GRUB_KERNEL_MACHINE_INSTALL_DOS_PART) && defined(GRUB_KERNEL_MACHINE_INSTALL_BSD_PART)
|
||||
/* If we included a drive in our prefix, let GRUB know it doesn't have to
|
||||
prepend the drive told by BIOS. */
|
||||
if (prefix[0] == '(')
|
||||
{
|
||||
*((grub_int32_t *) (core_img + GRUB_KERNEL_MACHINE_INSTALL_DOS_PART))
|
||||
= grub_host_to_target32 (-2);
|
||||
*((grub_int32_t *) (core_img + GRUB_KERNEL_MACHINE_INSTALL_BSD_PART))
|
||||
= grub_host_to_target32 (-2);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef GRUB_MACHINE_PCBIOS
|
||||
if (GRUB_KERNEL_MACHINE_LINK_ADDR + core_size > GRUB_MEMORY_MACHINE_UPPER)
|
||||
grub_util_error (_("core image is too big (%p > %p)"),
|
||||
GRUB_KERNEL_MACHINE_LINK_ADDR + core_size,
|
||||
GRUB_MEMORY_MACHINE_UPPER);
|
||||
#endif
|
||||
|
||||
#if defined(GRUB_MACHINE_PCBIOS)
|
||||
{
|
||||
unsigned num;
|
||||
|
@ -300,39 +331,52 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
|
|||
free (boot_img);
|
||||
free (boot_path);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE
|
||||
*((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE))
|
||||
= grub_host_to_target32 (total_module_size);
|
||||
#endif
|
||||
*((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_KERNEL_IMAGE_SIZE))
|
||||
= grub_host_to_target32 (kernel_size);
|
||||
#ifdef GRUB_KERNEL_MACHINE_COMPRESSED_SIZE
|
||||
*((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_COMPRESSED_SIZE))
|
||||
= grub_host_to_target32 (core_size - GRUB_KERNEL_MACHINE_RAW_SIZE);
|
||||
#endif
|
||||
|
||||
#if defined(GRUB_KERNEL_MACHINE_INSTALL_DOS_PART) && defined(GRUB_KERNEL_MACHINE_INSTALL_BSD_PART)
|
||||
/* If we included a drive in our prefix, let GRUB know it doesn't have to
|
||||
prepend the drive told by BIOS. */
|
||||
if (prefix[0] == '(')
|
||||
#elif defined (GRUB_MACHINE_SPARC64)
|
||||
if (format == GRUB_PLATFORM_IMAGE_AOUT)
|
||||
{
|
||||
*((grub_int32_t *) (core_img + GRUB_KERNEL_MACHINE_INSTALL_DOS_PART))
|
||||
= grub_host_to_target32 (-2);
|
||||
*((grub_int32_t *) (core_img + GRUB_KERNEL_MACHINE_INSTALL_BSD_PART))
|
||||
= grub_host_to_target32 (-2);
|
||||
void *aout_img;
|
||||
size_t aout_size;
|
||||
struct grub_aout32_header *aout_head;
|
||||
|
||||
aout_size = core_size + sizeof (*aout_head);
|
||||
aout_img = xmalloc (aout_size);
|
||||
aout_head = aout_img;
|
||||
aout_head->a_midmag = grub_host_to_target32 ((AOUT_MID_SUN << 16)
|
||||
| AOUT32_OMAGIC);
|
||||
aout_head->a_text = grub_host_to_target32 (core_size);
|
||||
aout_head->a_entry
|
||||
= grub_host_to_target32 (GRUB_BOOT_MACHINE_IMAGE_ADDRESS);
|
||||
memcpy (aout_img + sizeof (*aout_head), core_img, core_size);
|
||||
|
||||
free (core_img);
|
||||
core_img = aout_img;
|
||||
core_size = aout_size;
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
unsigned int num;
|
||||
char *boot_path, *boot_img;
|
||||
size_t boot_size;
|
||||
|
||||
#ifdef GRUB_MACHINE_PCBIOS
|
||||
if (GRUB_KERNEL_MACHINE_LINK_ADDR + core_size > GRUB_MEMORY_MACHINE_UPPER)
|
||||
grub_util_error (_("core image is too big (%p > %p)"),
|
||||
GRUB_KERNEL_MACHINE_LINK_ADDR + core_size,
|
||||
GRUB_MEMORY_MACHINE_UPPER);
|
||||
#endif
|
||||
num = ((core_size + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS);
|
||||
num <<= GRUB_DISK_SECTOR_BITS;
|
||||
|
||||
#if defined(GRUB_MACHINE_MIPS)
|
||||
boot_path = grub_util_get_path (dir, "diskboot.img");
|
||||
boot_size = grub_util_get_image_size (boot_path);
|
||||
if (boot_size != GRUB_DISK_SECTOR_SIZE)
|
||||
grub_util_error ("diskboot.img is not one sector size");
|
||||
|
||||
boot_img = grub_util_read_image (boot_path);
|
||||
|
||||
*((grub_uint32_t *) (boot_img + GRUB_DISK_SECTOR_SIZE
|
||||
- GRUB_BOOT_MACHINE_LIST_SIZE + 8))
|
||||
= grub_host_to_target32 (num);
|
||||
|
||||
grub_util_write_image (boot_img, boot_size, out);
|
||||
free (boot_img);
|
||||
free (boot_path);
|
||||
}
|
||||
#elif defined(GRUB_MACHINE_MIPS)
|
||||
if (format == GRUB_PLATFORM_IMAGE_ELF)
|
||||
{
|
||||
char *elf_img;
|
||||
|
@ -534,6 +578,11 @@ main (int argc, char *argv[])
|
|||
if (strcmp (optarg, "elf") == 0)
|
||||
format = GRUB_PLATFORM_IMAGE_ELF;
|
||||
else
|
||||
#endif
|
||||
#ifdef GRUB_PLATFORM_IMAGE_AOUT
|
||||
if (strcmp (optarg, "aout") == 0)
|
||||
format = GRUB_PLATFORM_IMAGE_AOUT;
|
||||
else
|
||||
#endif
|
||||
usage (1);
|
||||
break;
|
||||
|
|
|
@ -145,7 +145,7 @@ if test -e "${coreboot_dir}" ; then
|
|||
memdisk_dir=`mktemp -d "$MKTEMP_TEMPLATE"`
|
||||
mkdir -p ${memdisk_dir}/boot/grub
|
||||
# obtain date-based UUID
|
||||
iso_uuid=$(date +%Y-%m-%d-%H-%M-%S-00)
|
||||
iso_uuid=$(date -u +%Y-%m-%d-%H-%M-%S-00)
|
||||
|
||||
modules="$(cat ${coreboot_dir}/partmap.lst) ${modules}"
|
||||
cat << EOF > ${memdisk_dir}/boot/grub/grub.cfg
|
||||
|
|
|
@ -82,13 +82,16 @@ grub_refresh (void)
|
|||
static void
|
||||
probe_partmap (grub_disk_t disk)
|
||||
{
|
||||
grub_partition_t part;
|
||||
|
||||
if (disk->partition == NULL)
|
||||
{
|
||||
grub_util_info ("no partition map found for %s", disk->name);
|
||||
return;
|
||||
}
|
||||
|
||||
printf ("%s\n", disk->partition->partmap->name);
|
||||
for (part = disk->partition; part; part = part->parent)
|
||||
printf ("%s\n", part->partmap->name);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* grub-script-check.c - check grub script file for syntax errors */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2003,2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
|
||||
* Copyright (C) 2009,2010 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -81,6 +81,12 @@ grub_script_execute_cmdif (struct grub_script_cmd *cmd __attribute__ ((unused)))
|
|||
return 0;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_script_execute_cmdfor (struct grub_script_cmd *cmd __attribute__ ((unused)))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_script_execute_menuentry (struct grub_script_cmd *cmd __attribute__ ((unused)))
|
||||
{
|
||||
|
|
167
util/hostdisk.c
167
util/hostdisk.c
|
@ -26,6 +26,7 @@
|
|||
#include <grub/util/hostdisk.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/list.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -103,6 +104,13 @@ struct
|
|||
char *device;
|
||||
} map[256];
|
||||
|
||||
struct grub_util_biosdisk_data
|
||||
{
|
||||
char *dev;
|
||||
int access_mode;
|
||||
int fd;
|
||||
};
|
||||
|
||||
#ifdef __linux__
|
||||
/* Check if we have devfs support. */
|
||||
static int
|
||||
|
@ -165,14 +173,19 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk)
|
|||
{
|
||||
int drive;
|
||||
struct stat st;
|
||||
struct grub_util_biosdisk_data *data;
|
||||
|
||||
drive = find_grub_drive (name);
|
||||
if (drive < 0)
|
||||
return grub_error (GRUB_ERR_BAD_DEVICE,
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE,
|
||||
"no mapping exists for `%s'", name);
|
||||
|
||||
disk->has_partitions = 1;
|
||||
disk->id = drive;
|
||||
disk->data = data = xmalloc (sizeof (struct grub_util_biosdisk_data));
|
||||
data->dev = NULL;
|
||||
data->access_mode = 0;
|
||||
data->fd = -1;
|
||||
|
||||
/* Get the size. */
|
||||
#if defined(__MINGW32__)
|
||||
|
@ -198,7 +211,7 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk)
|
|||
|
||||
fd = open (map[drive].device, O_RDONLY);
|
||||
if (fd == -1)
|
||||
return grub_error (GRUB_ERR_BAD_DEVICE, "cannot open `%s' while attempting to get disk size", map[drive].device);
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "cannot open `%s' while attempting to get disk size", map[drive].device);
|
||||
|
||||
# if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__)
|
||||
if (fstat (fd, &st) < 0 || ! S_ISCHR (st.st_mode))
|
||||
|
@ -244,7 +257,7 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk)
|
|||
# warning "No special routine to get the size of a block device is implemented for your OS. This is not possibly fatal."
|
||||
#endif
|
||||
if (stat (map[drive].device, &st) < 0)
|
||||
return grub_error (GRUB_ERR_BAD_DEVICE, "cannot stat `%s'", map[drive].device);
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "cannot stat `%s'", map[drive].device);
|
||||
|
||||
disk->total_sectors = st.st_size >> GRUB_DISK_SECTOR_BITS;
|
||||
|
||||
|
@ -254,6 +267,17 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk)
|
|||
}
|
||||
|
||||
#ifdef __linux__
|
||||
/* Cache of partition start sectors for each disk. */
|
||||
struct linux_partition_cache
|
||||
{
|
||||
struct linux_partition_cache *next;
|
||||
char *dev;
|
||||
unsigned long start;
|
||||
int partno;
|
||||
};
|
||||
|
||||
struct linux_partition_cache *linux_partition_cache_list;
|
||||
|
||||
static int
|
||||
linux_find_partition (char *dev, unsigned long sector)
|
||||
{
|
||||
|
@ -262,6 +286,7 @@ linux_find_partition (char *dev, unsigned long sector)
|
|||
char *p;
|
||||
int i;
|
||||
char real_dev[PATH_MAX];
|
||||
struct linux_partition_cache *cache;
|
||||
|
||||
strcpy(real_dev, dev);
|
||||
|
||||
|
@ -281,6 +306,16 @@ linux_find_partition (char *dev, unsigned long sector)
|
|||
format = "%d";
|
||||
}
|
||||
|
||||
for (cache = linux_partition_cache_list; cache; cache = cache->next)
|
||||
{
|
||||
if (strcmp (cache->dev, dev) == 0 && cache->start == sector)
|
||||
{
|
||||
sprintf (p, format, cache->partno);
|
||||
strcpy (dev, real_dev);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 1; i < 10000; i++)
|
||||
{
|
||||
int fd;
|
||||
|
@ -301,6 +336,15 @@ linux_find_partition (char *dev, unsigned long sector)
|
|||
|
||||
if (hdg.start == sector)
|
||||
{
|
||||
struct linux_partition_cache *new_cache_item;
|
||||
|
||||
new_cache_item = xmalloc (sizeof *new_cache_item);
|
||||
new_cache_item->dev = xstrdup (dev);
|
||||
new_cache_item->start = hdg.start;
|
||||
new_cache_item->partno = i;
|
||||
grub_list_push (GRUB_AS_LIST_P (&linux_partition_cache_list),
|
||||
GRUB_AS_LIST (new_cache_item));
|
||||
|
||||
strcpy (dev, real_dev);
|
||||
return 1;
|
||||
}
|
||||
|
@ -314,6 +358,7 @@ static int
|
|||
open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags)
|
||||
{
|
||||
int fd;
|
||||
struct grub_util_biosdisk_data *data = disk->data;
|
||||
|
||||
#ifdef O_LARGEFILE
|
||||
flags |= O_LARGEFILE;
|
||||
|
@ -334,27 +379,47 @@ open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags)
|
|||
{
|
||||
int is_partition = 0;
|
||||
char dev[PATH_MAX];
|
||||
grub_disk_addr_t part_start = 0;
|
||||
|
||||
part_start = grub_partition_get_start (disk->partition);
|
||||
|
||||
strcpy (dev, map[disk->id].device);
|
||||
if (disk->partition && sector >= disk->partition->start
|
||||
if (disk->partition && sector >= part_start
|
||||
&& strncmp (map[disk->id].device, "/dev/", 5) == 0)
|
||||
is_partition = linux_find_partition (dev, disk->partition->start);
|
||||
is_partition = linux_find_partition (dev, part_start);
|
||||
|
||||
/* Open the partition. */
|
||||
grub_dprintf ("hostdisk", "opening the device `%s' in open_device()\n", dev);
|
||||
fd = open (dev, flags);
|
||||
if (fd < 0)
|
||||
if (data->dev && strcmp (data->dev, dev) == 0 &&
|
||||
data->access_mode == (flags & O_ACCMODE))
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_DEVICE, "cannot open `%s'", dev);
|
||||
return -1;
|
||||
grub_dprintf ("hostdisk", "reusing open device `%s'\n", dev);
|
||||
fd = data->fd;
|
||||
}
|
||||
else
|
||||
{
|
||||
free (data->dev);
|
||||
if (data->fd != -1)
|
||||
close (data->fd);
|
||||
|
||||
/* Open the partition. */
|
||||
grub_dprintf ("hostdisk", "opening the device `%s' in open_device()\n", dev);
|
||||
fd = open (dev, flags);
|
||||
if (fd < 0)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_DEVICE, "cannot open `%s'", dev);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Flush the buffer cache to the physical disk.
|
||||
XXX: This also empties the buffer cache. */
|
||||
ioctl (fd, BLKFLSBUF, 0);
|
||||
|
||||
data->dev = xstrdup (dev);
|
||||
data->access_mode = (flags & O_ACCMODE);
|
||||
data->fd = fd;
|
||||
}
|
||||
|
||||
/* Flush the buffer cache to the physical disk.
|
||||
XXX: This also empties the buffer cache. */
|
||||
ioctl (fd, BLKFLSBUF, 0);
|
||||
|
||||
if (is_partition)
|
||||
sector -= disk->partition->start;
|
||||
sector -= part_start;
|
||||
}
|
||||
#else /* ! __linux__ */
|
||||
#if defined (__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||
|
@ -375,7 +440,26 @@ open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags)
|
|||
}
|
||||
#endif
|
||||
|
||||
fd = open (map[disk->id].device, flags);
|
||||
if (data->dev && strcmp (data->dev, map[disk->id].device) == 0 &&
|
||||
data->access_mode == (flags & O_ACCMODE))
|
||||
{
|
||||
grub_dprintf ("hostdisk", "reusing open device `%s'\n", data->dev);
|
||||
fd = data->fd;
|
||||
}
|
||||
else
|
||||
{
|
||||
free (data->dev);
|
||||
if (data->fd != -1)
|
||||
close (data->fd);
|
||||
|
||||
fd = open (map[disk->id].device, flags);
|
||||
if (fd >= 0)
|
||||
{
|
||||
data->dev = xstrdup (map[disk->id].device);
|
||||
data->access_mode = (flags & O_ACCMODE);
|
||||
data->fd = fd;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||
if (! (sysctl_oldflags & 0x10)
|
||||
|
@ -535,7 +619,6 @@ grub_util_biosdisk_read (grub_disk_t disk, grub_disk_addr_t sector,
|
|||
!= (ssize_t) (size << GRUB_DISK_SECTOR_BITS))
|
||||
grub_error (GRUB_ERR_READ_ERROR, "cannot read from `%s'", map[disk->id].device);
|
||||
|
||||
close (fd);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
|
@ -570,17 +653,27 @@ grub_util_biosdisk_write (grub_disk_t disk, grub_disk_addr_t sector,
|
|||
!= (ssize_t) (size << GRUB_DISK_SECTOR_BITS))
|
||||
grub_error (GRUB_ERR_WRITE_ERROR, "cannot write to `%s'", map[disk->id].device);
|
||||
|
||||
close (fd);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
static void
|
||||
grub_util_biosdisk_close (struct grub_disk *disk)
|
||||
{
|
||||
struct grub_util_biosdisk_data *data = disk->data;
|
||||
|
||||
free (data->dev);
|
||||
if (data->fd != -1)
|
||||
close (data->fd);
|
||||
free (data);
|
||||
}
|
||||
|
||||
static struct grub_disk_dev grub_util_biosdisk_dev =
|
||||
{
|
||||
.name = "biosdisk",
|
||||
.id = GRUB_DISK_DEVICE_BIOSDISK_ID,
|
||||
.iterate = grub_util_biosdisk_iterate,
|
||||
.open = grub_util_biosdisk_open,
|
||||
.close = 0,
|
||||
.close = grub_util_biosdisk_close,
|
||||
.read = grub_util_biosdisk_read,
|
||||
.write = grub_util_biosdisk_write,
|
||||
.next = 0
|
||||
|
@ -987,39 +1080,25 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
|
|||
int find_partition (grub_disk_t dsk __attribute__ ((unused)),
|
||||
const grub_partition_t partition)
|
||||
{
|
||||
struct grub_msdos_partition *pcdata = NULL;
|
||||
grub_disk_addr_t part_start = 0;
|
||||
grub_util_info ("Partition %d starts from %lu",
|
||||
partition->number, partition->start);
|
||||
|
||||
if (strcmp (partition->partmap->name, "part_msdos") == 0)
|
||||
pcdata = partition->data;
|
||||
part_start = grub_partition_get_start (partition);
|
||||
|
||||
if (pcdata)
|
||||
if (hdg.start == part_start)
|
||||
{
|
||||
if (pcdata->bsd_part < 0)
|
||||
grub_util_info ("DOS partition %d starts from %lu",
|
||||
pcdata->dos_part, partition->start);
|
||||
else
|
||||
grub_util_info ("BSD partition %d,%c starts from %lu",
|
||||
pcdata->dos_part, pcdata->bsd_part + 'a',
|
||||
partition->start);
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_util_info ("Partition %d starts from %lu",
|
||||
partition->index, partition->start);
|
||||
}
|
||||
|
||||
if (hdg.start == partition->start)
|
||||
{
|
||||
if (pcdata)
|
||||
if (partition->parent)
|
||||
{
|
||||
dos_part = pcdata->dos_part;
|
||||
bsd_part = pcdata->bsd_part;
|
||||
dos_part = partition->parent->number;
|
||||
bsd_part = partition->number;
|
||||
}
|
||||
else
|
||||
{
|
||||
dos_part = partition->index;
|
||||
dos_part = partition->number;
|
||||
bsd_part = -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
if [ x$1 == x ]; then
|
||||
if [ "x$1" = "x" ]; then
|
||||
echo "Filename required".
|
||||
fi
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ target_cpu=@target_cpu@
|
|||
platform=@platform@
|
||||
host_os=@host_os@
|
||||
pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}`
|
||||
localedir=@datadir@/locale
|
||||
|
||||
grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}`
|
||||
grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}`
|
||||
|
@ -144,8 +145,7 @@ else
|
|||
fi
|
||||
|
||||
# Create the GRUB directory if it is not present.
|
||||
test -d "$bootdir" || mkdir "$bootdir" || exit 1
|
||||
test -d "$grubdir" || mkdir "$grubdir" || exit 1
|
||||
mkdir -p "$grubdir" || exit 1
|
||||
|
||||
# If --recheck is specified, remove the device map, if present.
|
||||
if test $recheck = yes; then
|
||||
|
@ -182,9 +182,9 @@ done
|
|||
|
||||
# Copy gettext files
|
||||
mkdir -p ${grubdir}/locale/
|
||||
for file in ${grubdir}/locale/*.mo ${pkglibdir}/locale/*.mo; do
|
||||
if test -f "$file"; then
|
||||
cp -f "$file" ${grubdir}/locale/
|
||||
for dir in ${localedir}/*; do
|
||||
if test -f "$dir/LC_MESSAGES/grub.mo"; then
|
||||
cp -f "$dir/LC_MESSAGES/grub.mo" "${grubdir}/locale/${dir##*/}.mo"
|
||||
fi
|
||||
done
|
||||
|
||||
|
@ -202,7 +202,10 @@ 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=`$grub_probe --target=partmap --device-map=${device_map} ${grubdir} 2> /dev/null`
|
||||
partmap_module=
|
||||
for x in `$grub_probe --target=partmap --device ${grub_device} 2> /dev/null`; do
|
||||
partmap_module="$partmap_module part_$x";
|
||||
done
|
||||
|
||||
# Device abstraction module, if any (lvm, raid).
|
||||
devabstraction_module=`$grub_probe --target=abstraction --device-map=${device_map} ${grubdir}`
|
||||
|
|
|
@ -116,15 +116,10 @@ setup (const char *dir,
|
|||
int NESTED_FUNC_ATTR find_usable_region_msdos (grub_disk_t disk __attribute__ ((unused)),
|
||||
const grub_partition_t p)
|
||||
{
|
||||
struct grub_msdos_partition *pcdata = p->data;
|
||||
|
||||
/* There's always an embed region, and it starts right after the MBR. */
|
||||
embed_region.start = 1;
|
||||
|
||||
/* For its end offset, include as many dummy partitions as we can. */
|
||||
if (! grub_msdos_partition_is_empty (pcdata->dos_type)
|
||||
&& ! grub_msdos_partition_is_bsd (pcdata->dos_type)
|
||||
&& embed_region.end > p->start)
|
||||
if (embed_region.end > p->start)
|
||||
embed_region.end = p->start;
|
||||
|
||||
return 0;
|
||||
|
@ -135,17 +130,21 @@ setup (const char *dir,
|
|||
int NESTED_FUNC_ATTR find_usable_region_gpt (grub_disk_t disk __attribute__ ((unused)),
|
||||
const grub_partition_t p)
|
||||
{
|
||||
struct grub_gpt_partentry *gptdata = p->data;
|
||||
struct grub_gpt_partentry gptdata;
|
||||
|
||||
disk->partition = p->parent;
|
||||
if (grub_disk_read (disk, p->offset, p->index,
|
||||
sizeof (gptdata), &gptdata))
|
||||
return 0;
|
||||
|
||||
/* If there's an embed region, it is in a dedicated partition. */
|
||||
if (! memcmp (&gptdata->type, &grub_gpt_partition_type_bios_boot, 16))
|
||||
if (! memcmp (&gptdata.type, &grub_gpt_partition_type_bios_boot, 16))
|
||||
{
|
||||
embed_region.start = p->start;
|
||||
embed_region.end = p->start + p->len;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -289,22 +288,19 @@ setup (const char *dir,
|
|||
/* Embed information about the installed location. */
|
||||
if (root_dev->disk->partition)
|
||||
{
|
||||
if (strcmp (root_dev->disk->partition->partmap->name,
|
||||
"part_msdos") == 0)
|
||||
{
|
||||
struct grub_msdos_partition *pcdata =
|
||||
root_dev->disk->partition->data;
|
||||
dos_part = pcdata->dos_part;
|
||||
bsd_part = pcdata->bsd_part;
|
||||
}
|
||||
else if (strcmp (root_dev->disk->partition->partmap->name,
|
||||
"part_gpt") == 0)
|
||||
{
|
||||
dos_part = root_dev->disk->partition->index;
|
||||
bsd_part = -1;
|
||||
}
|
||||
if (root_dev->disk->partition->parent)
|
||||
{
|
||||
if (root_dev->disk->partition->parent->parent)
|
||||
grub_util_error ("Installing on doubly nested partitions is "
|
||||
"not supported");
|
||||
dos_part = root_dev->disk->partition->parent->number;
|
||||
bsd_part = root_dev->disk->partition->number;
|
||||
}
|
||||
else
|
||||
grub_util_error (_("no DOS-style partitions found"));
|
||||
{
|
||||
dos_part = root_dev->disk->partition->number;
|
||||
bsd_part = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
dos_part = bsd_part = -1;
|
||||
|
@ -337,6 +333,8 @@ setup (const char *dir,
|
|||
int NESTED_FUNC_ATTR identify_partmap (grub_disk_t disk __attribute__ ((unused)),
|
||||
const grub_partition_t p)
|
||||
{
|
||||
if (p->parent)
|
||||
return 0;
|
||||
dest_partmap = p->partmap->name;
|
||||
return 1;
|
||||
}
|
||||
|
@ -349,16 +347,16 @@ setup (const char *dir,
|
|||
goto unable_to_embed;
|
||||
}
|
||||
|
||||
if (strcmp (dest_partmap, "part_msdos") == 0)
|
||||
if (strcmp (dest_partmap, "msdos") == 0)
|
||||
grub_partition_iterate (dest_dev->disk, find_usable_region_msdos);
|
||||
else if (strcmp (dest_partmap, "part_gpt") == 0)
|
||||
else if (strcmp (dest_partmap, "gpt") == 0)
|
||||
grub_partition_iterate (dest_dev->disk, find_usable_region_gpt);
|
||||
else
|
||||
grub_util_error (_("No DOS-style partitions found"));
|
||||
|
||||
if (embed_region.end == embed_region.start)
|
||||
{
|
||||
if (! strcmp (dest_partmap, "part_msdos"))
|
||||
if (! strcmp (dest_partmap, "msdos"))
|
||||
grub_util_warn (_("This msdos-style partition label has no post-MBR gap; embedding won't be possible!"));
|
||||
else
|
||||
grub_util_warn (_("This GPT partition label has no BIOS Boot Partition; embedding won't be possible!"));
|
||||
|
@ -418,7 +416,7 @@ unable_to_embed:
|
|||
|
||||
grub_util_warn (_("Embedding is not possible. GRUB can only be installed in this "
|
||||
"setup by using blocklists. However, blocklists are UNRELIABLE and "
|
||||
"its use is discouraged."));
|
||||
"their use is discouraged."));
|
||||
if (! force)
|
||||
grub_util_error (_("if you really want blocklists, use --force"));
|
||||
|
||||
|
|
|
@ -141,8 +141,7 @@ fi
|
|||
# XXX warn on firmware-unreadable filesystems?
|
||||
|
||||
# Create the GRUB directory if it is not present.
|
||||
test -d "$bootdir" || mkdir "$bootdir" || exit 1
|
||||
test -d "$grubdir" || mkdir "$grubdir" || exit 1
|
||||
mkdir -p "$grubdir" || exit 1
|
||||
|
||||
# Create the device map file if it is not present.
|
||||
if test -f "$device_map"; then
|
||||
|
@ -179,7 +178,10 @@ 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=`$grub_probe --target=partmap --device-map=${device_map} ${grubdir} 2> /dev/null`
|
||||
partmap_module=
|
||||
for x in `$grub_probe --target=partmap --device ${grub_device} 2> /dev/null`; do
|
||||
partmap_module="$partmap_module part_$x";
|
||||
done
|
||||
|
||||
# Device abstraction module, if any (lvm, raid).
|
||||
devabstraction_module=`$grub_probe --target=abstraction --device-map=${device_map} ${grubdir}`
|
||||
|
|
|
@ -104,6 +104,7 @@ grub_util_error (const char *fmt, ...)
|
|||
exit (1);
|
||||
}
|
||||
|
||||
#ifdef GRUB_UTIL
|
||||
int
|
||||
grub_err_printf (const char *fmt, ...)
|
||||
{
|
||||
|
@ -116,6 +117,7 @@ grub_err_printf (const char *fmt, ...)
|
|||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
void *
|
||||
xmalloc (size_t size)
|
||||
|
@ -598,12 +600,14 @@ make_system_path_relative_to_its_root (const char *path)
|
|||
return buf3;
|
||||
}
|
||||
|
||||
#ifdef GRUB_UTIL
|
||||
void
|
||||
grub_util_init_nls (void)
|
||||
{
|
||||
#if ENABLE_NLS
|
||||
#if (defined(ENABLE_NLS) && ENABLE_NLS)
|
||||
setlocale (LC_ALL, "");
|
||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
textdomain (PACKAGE);
|
||||
#endif /* ENABLE_NLS */
|
||||
#endif /* (defined(ENABLE_NLS) && ENABLE_NLS) */
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -640,11 +640,11 @@ int FDECL2(main, int, argc, char **, argv){
|
|||
char *log_file = 0;
|
||||
|
||||
set_program_name (argv[0]);
|
||||
#if ENABLE_NLS
|
||||
#if (defined(ENABLE_NLS) && ENABLE_NLS)
|
||||
setlocale (LC_ALL, "");
|
||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
textdomain (PACKAGE);
|
||||
#endif /* ENABLE_NLS */
|
||||
#endif /* (defined(ENABLE_NLS) && ENABLE_NLS) */
|
||||
|
||||
if (argc < 2)
|
||||
usage();
|
||||
|
|
|
@ -30,12 +30,12 @@
|
|||
#include <prototyp.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#if ENABLE_NLS
|
||||
#if (defined(ENABLE_NLS) && ENABLE_NLS)
|
||||
|
||||
# include <locale.h>
|
||||
# include <libintl.h>
|
||||
|
||||
#else /* ! ENABLE_NLS */
|
||||
#else /* ! (defined(ENABLE_NLS) && ENABLE_NLS) */
|
||||
|
||||
/* Disabled NLS.
|
||||
The casts to 'const char *' serve the purpose of producing warnings
|
||||
|
@ -43,7 +43,7 @@
|
|||
On pre-ANSI systems without 'const', the config.h file is supposed to
|
||||
contain "#define const". */
|
||||
# define gettext(Msgid) ((const char *) (Msgid))
|
||||
#endif /* ENABLE_NLS */
|
||||
#endif /* (defined(ENABLE_NLS) && ENABLE_NLS) */
|
||||
|
||||
#define _(str) gettext(str)
|
||||
#define N_(str) str
|
||||
|
|
|
@ -1,300 +0,0 @@
|
|||
/* grub-mkimage.c - make a bootable image */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2008,2009,2010 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <config.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/machine/boot.h>
|
||||
#include <grub/machine/kernel.h>
|
||||
#include <grub/kernel.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/disk.h>
|
||||
#include <grub/util/misc.h>
|
||||
#include <grub/util/resolve.h>
|
||||
#include <grub/misc.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define _GNU_SOURCE 1
|
||||
#include <getopt.h>
|
||||
|
||||
#include "progname.h"
|
||||
|
||||
static void
|
||||
compress_kernel (char *kernel_img, size_t kernel_size,
|
||||
char **core_img, size_t *core_size)
|
||||
{
|
||||
/* No compression support yet. */
|
||||
grub_util_info ("kernel_img=%p, kernel_size=0x%x", kernel_img, kernel_size);
|
||||
*core_img = xmalloc (kernel_size);
|
||||
memcpy (*core_img, kernel_img, kernel_size);
|
||||
*core_size = kernel_size;
|
||||
}
|
||||
|
||||
static void
|
||||
generate_image (const char *dir, const char *prefix, FILE *out, char *mods[], char *memdisk_path)
|
||||
{
|
||||
size_t kernel_size, total_module_size, memdisk_size, core_size, boot_size, offset;
|
||||
char *kernel_path, *kernel_img, *core_img, *boot_path, *boot_img;
|
||||
struct grub_util_path_list *path_list, *p;
|
||||
struct grub_module_info *modinfo;
|
||||
grub_addr_t module_addr;
|
||||
unsigned int num;
|
||||
|
||||
path_list = grub_util_resolve_dependencies (dir, "moddep.lst", mods);
|
||||
|
||||
kernel_path = grub_util_get_path (dir, "kernel.img");
|
||||
kernel_size = grub_util_get_image_size (kernel_path);
|
||||
|
||||
total_module_size = sizeof (struct grub_module_info);
|
||||
for (p = path_list; p; p = p->next)
|
||||
total_module_size += (grub_util_get_image_size (p->name)
|
||||
+ sizeof (struct grub_module_header));
|
||||
|
||||
memdisk_size = 0;
|
||||
if (memdisk_path)
|
||||
{
|
||||
memdisk_size = ALIGN_UP(grub_util_get_image_size (memdisk_path), 512);
|
||||
grub_util_info ("the size of memory disk is 0x%x", memdisk_size);
|
||||
total_module_size += memdisk_size + sizeof (struct grub_module_header);
|
||||
}
|
||||
|
||||
grub_util_info ("the total module size is 0x%x", total_module_size);
|
||||
|
||||
kernel_img = xmalloc (kernel_size + total_module_size);
|
||||
grub_util_load_image (kernel_path, kernel_img);
|
||||
|
||||
if ((GRUB_KERNEL_MACHINE_PREFIX + strlen (prefix) + 1)
|
||||
> GRUB_KERNEL_MACHINE_DATA_END)
|
||||
grub_util_error ("prefix too long");
|
||||
strcpy (kernel_img + GRUB_KERNEL_MACHINE_PREFIX, prefix);
|
||||
|
||||
/* Fill in the grub_module_info structure. */
|
||||
modinfo = (struct grub_module_info *) (kernel_img + kernel_size);
|
||||
modinfo->magic = GRUB_MODULE_MAGIC;
|
||||
modinfo->offset = sizeof (struct grub_module_info);
|
||||
modinfo->size = total_module_size;
|
||||
|
||||
offset = kernel_size + sizeof (struct grub_module_info);
|
||||
for (p = path_list; p; p = p->next)
|
||||
{
|
||||
struct grub_module_header *header;
|
||||
size_t mod_size;
|
||||
|
||||
mod_size = grub_util_get_image_size (p->name);
|
||||
|
||||
header = (struct grub_module_header *) (kernel_img + offset);
|
||||
header->type = OBJ_TYPE_ELF;
|
||||
header->size = grub_host_to_target32 (mod_size + sizeof (*header));
|
||||
offset += sizeof (*header);
|
||||
|
||||
grub_util_load_image (p->name, kernel_img + offset);
|
||||
offset += mod_size;
|
||||
}
|
||||
|
||||
if (memdisk_path)
|
||||
{
|
||||
struct grub_module_header *header;
|
||||
|
||||
header = (struct grub_module_header *) (kernel_img + offset);
|
||||
header->type = OBJ_TYPE_MEMDISK;
|
||||
header->size = grub_host_to_target32 (memdisk_size + sizeof (*header));
|
||||
offset += sizeof (*header);
|
||||
|
||||
grub_util_load_image (memdisk_path, kernel_img + offset);
|
||||
offset += memdisk_size;
|
||||
}
|
||||
|
||||
compress_kernel (kernel_img, kernel_size + total_module_size,
|
||||
&core_img, &core_size);
|
||||
|
||||
grub_util_info ("the core size is 0x%x", core_size);
|
||||
|
||||
num = ((core_size + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS);
|
||||
num <<= GRUB_DISK_SECTOR_BITS;
|
||||
|
||||
boot_path = grub_util_get_path (dir, "diskboot.img");
|
||||
boot_size = grub_util_get_image_size (boot_path);
|
||||
if (boot_size != GRUB_DISK_SECTOR_SIZE)
|
||||
grub_util_error ("diskboot.img is not one sector size");
|
||||
|
||||
boot_img = grub_util_read_image (boot_path);
|
||||
|
||||
/* sparc is a big endian architecture. */
|
||||
*((grub_uint32_t *) (boot_img + GRUB_DISK_SECTOR_SIZE
|
||||
- GRUB_BOOT_MACHINE_LIST_SIZE + 8))
|
||||
= grub_cpu_to_be32 (num);
|
||||
|
||||
grub_util_write_image (boot_img, boot_size, out);
|
||||
free (boot_img);
|
||||
free (boot_path);
|
||||
|
||||
module_addr = (path_list
|
||||
? (GRUB_BOOT_MACHINE_IMAGE_ADDRESS + kernel_size)
|
||||
: 0);
|
||||
|
||||
grub_util_info ("the first module address is 0x%x", module_addr);
|
||||
|
||||
*((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE))
|
||||
= grub_cpu_to_be32 (total_module_size);
|
||||
*((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_KERNEL_IMAGE_SIZE))
|
||||
= grub_cpu_to_be32 (kernel_size);
|
||||
|
||||
/* No compression support yet. */
|
||||
*((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_COMPRESSED_SIZE))
|
||||
= grub_cpu_to_be32 (0);
|
||||
|
||||
grub_util_write_image (core_img, core_size, out);
|
||||
free (kernel_img);
|
||||
free (core_img);
|
||||
free (kernel_path);
|
||||
|
||||
while (path_list)
|
||||
{
|
||||
struct grub_util_path_list *next = path_list->next;
|
||||
free ((void *) path_list->name);
|
||||
free (path_list);
|
||||
path_list = next;
|
||||
}
|
||||
}
|
||||
|
||||
static struct option options[] =
|
||||
{
|
||||
{"directory", required_argument, 0, 'd'},
|
||||
{"prefix", required_argument, 0, 'p'},
|
||||
{"memdisk", required_argument, 0, 'm'},
|
||||
{"output", required_argument, 0, 'o'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"version", no_argument, 0, 'V'},
|
||||
{"verbose", no_argument, 0, 'v'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
static void
|
||||
usage (int status)
|
||||
{
|
||||
if (status)
|
||||
fprintf (stderr, "Try `%s --help' for more information.\n", program_name);
|
||||
else
|
||||
printf ("\
|
||||
Usage: %s [OPTION]... [MODULES]\n\
|
||||
\n\
|
||||
Make a bootable image of GRUB.\n\
|
||||
\n\
|
||||
-d, --directory=DIR use images and modules under DIR [default=%s]\n\
|
||||
-p, --prefix=DIR set grub_prefix directory [default=%s]\n\
|
||||
-m, --memdisk=FILE embed FILE as a memdisk image\n\
|
||||
-o, --output=FILE output a generated image to FILE [default=stdout]\n\
|
||||
-h, --help display this message and exit\n\
|
||||
-V, --version print version information and exit\n\
|
||||
-v, --verbose print verbose messages\n\
|
||||
\n\
|
||||
Report bugs to <%s>.\n\
|
||||
", program_name, GRUB_LIBDIR, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT);
|
||||
|
||||
exit (status);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
char *output = NULL;
|
||||
char *dir = NULL;
|
||||
char *prefix = NULL;
|
||||
char *memdisk = NULL;
|
||||
FILE *fp = stdout;
|
||||
|
||||
set_program_name (argv[0]);
|
||||
|
||||
grub_util_init_nls ();
|
||||
|
||||
while (1)
|
||||
{
|
||||
int c = getopt_long (argc, argv, "d:p:m:o:hVv", options, 0);
|
||||
|
||||
if (c == -1)
|
||||
break;
|
||||
else
|
||||
switch (c)
|
||||
{
|
||||
case 'o':
|
||||
if (output)
|
||||
free (output);
|
||||
output = xstrdup (optarg);
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
if (dir)
|
||||
free (dir);
|
||||
dir = xstrdup (optarg);
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
if (memdisk)
|
||||
free (memdisk);
|
||||
memdisk = xstrdup (optarg);
|
||||
|
||||
if (prefix)
|
||||
free (prefix);
|
||||
prefix = xstrdup ("(memdisk)/boot/grub");
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
usage (0);
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
if (prefix)
|
||||
free (prefix);
|
||||
prefix = xstrdup (optarg);
|
||||
break;
|
||||
|
||||
case 'V':
|
||||
printf ("grub-mkimage (%s) %s\n", PACKAGE_NAME, PACKAGE_VERSION);
|
||||
return 0;
|
||||
|
||||
case 'v':
|
||||
verbosity++;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage (1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (output)
|
||||
{
|
||||
fp = fopen (output, "wb");
|
||||
if (! fp)
|
||||
grub_util_error ("cannot open %s", output);
|
||||
}
|
||||
|
||||
generate_image (dir ? : GRUB_LIBDIR,
|
||||
prefix ? : DEFAULT_DIRECTORY, fp,
|
||||
argv + optind, memdisk);
|
||||
|
||||
fclose (fp);
|
||||
|
||||
if (dir)
|
||||
free (dir);
|
||||
|
||||
return 0;
|
||||
}
|
46
util/time.c
Normal file
46
util/time.c
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2010 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/datetime.h>
|
||||
#include <time.h>
|
||||
|
||||
grub_err_t
|
||||
grub_get_datetime (struct grub_datetime *datetime)
|
||||
{
|
||||
struct tm *mytm;
|
||||
time_t mytime;
|
||||
|
||||
mytime = time (&mytime);
|
||||
mytm = gmtime (&mytime);
|
||||
|
||||
datetime->year = mytm->tm_year + 1900;
|
||||
datetime->month = mytm->tm_mon + 1;
|
||||
datetime->day = mytm->tm_mday;
|
||||
datetime->hour = mytm->tm_hour;
|
||||
datetime->minute = mytm->tm_min;
|
||||
datetime->second = mytm->tm_sec;
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_set_datetime (struct grub_datetime *datetime __attribute__ ((unused)))
|
||||
{
|
||||
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
||||
"no clock setting routine available");
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue