2008-08-02 Robert Millan <rmh@aybabtu.com>

* disk/memdisk.c (memdisk_size): Don't initialize.
        (GRUB_MOD_INIT(memdisk)): Find memdisk using grub_module_iterate().

        * include/grub/i386/pc/kernel.h
        (GRUB_KERNEL_MACHINE_MEMDISK_IMAGE_SIZE): Remove macro.
        (GRUB_KERNEL_MACHINE_PREFIX, GRUB_KERNEL_MACHINE_DATA_END): Shift.
        (grub_memdisk_image_size, grub_arch_memdisk_addr)
        (grub_arch_memdisk_size): Remove.

        * include/grub/kernel.h (struct grub_module_header): Remove `offset'
        field (was only used to transfer a constant).  Add `type' field to
        support multiple module types.
        (grub_module_iterate): New function.

        * kern/device.c (grub_device_open): Do not hide error messages
        when grub_disk_open() fails.  Use grub_print_error() instead.

        * kern/i386/pc/init.c (grub_arch_modules_addr)
        (grub_arch_memdisk_size): Remove functions.
        (grub_arch_modules_addr): Return the module address in high memory
        (now that it isn't copied anymore).

        * kern/i386/pc/startup.S (grub_memdisk_image_size): Remove variable.
        (codestart): Don't add grub_memdisk_image_size to %ecx in LZMA
        decompression routine (grub_total_module_size already includes that
        now).  Don't copy modules back to low memory.

        * kern/main.c: Include `<grub/mm.h>'.
        (grub_load_modules): Split out (and use) ...
        (grub_module_iterate): ... this function, which iterates through
        module objects and runs a hook.
        Comment out grub_mm_init_region() call, as it would cause non-ELF
        modules to be overwritten.

        * util/i386/pc/grub-mkimage.c (generate_image): Instead of appending
        the memdisk image in its own region, make it part of the module list.
        * util/elf/grub-mkimage.c (options): Add "memdisk"|'m' option.
        (main): Parse --memdisk|-m option, and pass user-provided path as
        parameter to generate_image().
        (add_segments): Pass `memdisk_path' down to load_modules().
        (load_modules): Embed memdisk image in module section when requested.
        * util/i386/efi/grub-mkimage.c (make_mods_section): Initialize
        `header.type' instead of `header.offset'.

        * conf/powerpc-ieee1275.rmk (pkglib_MODULES): Add `memdisk.mod'.
        (memdisk_mod_SOURCES, memdisk_mod_CFLAGS)
        (memdisk_mod_LDFLAGS): New variables.
        * conf/i386-coreboot.rmk: Likewise.
        * conf/i386-ieee1275.rmk: Likewise.
This commit is contained in:
robertmh 2008-08-02 12:17:44 +00:00
parent a927cc7383
commit 3bd0a12aca
17 changed files with 368 additions and 79 deletions

View file

@ -50,7 +50,8 @@ grub_device_open (const char *name)
disk = grub_disk_open (name);
if (! disk)
{
grub_error (GRUB_ERR_BAD_DEVICE, "unknown device %s", name);
grub_print_error ();
grub_errno = GRUB_ERR_NONE;
goto fail;
}

View file

@ -249,22 +249,7 @@ grub_machine_fini (void)
/* Return the end of the core image. */
grub_addr_t
grub_arch_modules_addr (void)
{
return grub_end_addr;
}
/* Return the start of the memdisk image. */
grub_addr_t
grub_arch_memdisk_addr (void)
{
return GRUB_MEMORY_MACHINE_DECOMPRESSION_ADDR
+ (grub_kernel_image_size - GRUB_KERNEL_MACHINE_RAW_SIZE)
+ grub_total_module_size;
}
/* Return the size of the memdisk image. */
grub_off_t
grub_arch_memdisk_size (void)
{
return grub_memdisk_image_size;
+ (grub_kernel_image_size - GRUB_KERNEL_MACHINE_RAW_SIZE);
}

View file

@ -96,8 +96,6 @@ VARIABLE(grub_install_dos_part)
.long 0xFFFFFFFF
VARIABLE(grub_install_bsd_part)
.long 0xFFFFFFFF
VARIABLE(grub_memdisk_image_size)
.long 0
VARIABLE(grub_prefix)
/* to be filled by grub-mkimage */
@ -211,7 +209,6 @@ codestart:
call lzo1x_decompress
addl $12, %esp
/* copy back the decompressed part */
movl %eax, %ecx
cld
#elif defined(ENABLE_LZMA)
@ -221,19 +218,22 @@ codestart:
pushl %esi
movl EXT_C(grub_kernel_image_size), %ecx
addl EXT_C(grub_total_module_size), %ecx
addl EXT_C(grub_memdisk_image_size), %ecx
subl $GRUB_KERNEL_MACHINE_RAW_SIZE, %ecx
pushl %ecx
leal (%edi, %ecx), %ebx
call _LzmaDecodeA
/* _LzmaDecodeA clears DF, so no need to run cld */
popl %ecx
popl %edi
popl %esi
#endif
/* copy back the decompressed part (except the modules) */
subl EXT_C(grub_total_module_size), %ecx
rep
movsb
#if 0
/* copy modules before cleaning out the bss */
movl EXT_C(grub_total_module_size), %ecx
movl EXT_C(grub_kernel_image_size), %esi
@ -246,6 +246,7 @@ codestart:
std
rep
movsb
#endif
/* clean out the bss */
movl $BSS_START_SYMBOL, %edi

View file

@ -19,7 +19,6 @@
#include <grub/kernel.h>
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/symbol.h>
#include <grub/dl.h>
#include <grub/term.h>
@ -28,9 +27,8 @@
#include <grub/device.h>
#include <grub/env.h>
/* Load all modules in core. */
static void
grub_load_modules (void)
void
grub_module_iterate (int (*hook) (struct grub_module_header *header))
{
struct grub_module_info *modinfo;
struct grub_module_header *header;
@ -47,13 +45,30 @@ grub_load_modules (void)
header < (struct grub_module_header *) (modbase + modinfo->size);
header = (struct grub_module_header *) ((char *) header + header->size))
{
if (! grub_dl_load_core ((char *) header + header->offset,
(header->size - header->offset)))
if (hook (header))
break;
}
}
/* Load all modules in core. */
static void
grub_load_modules (void)
{
auto int hook (struct grub_module_header *);
int hook (struct grub_module_header *header)
{
/* Not an ELF module, skip. */
if (header->type != OBJ_TYPE_ELF)
return 0;
if (! grub_dl_load_core ((char *) header + sizeof (struct grub_module_header),
(header->size - sizeof (struct grub_module_header))))
grub_fatal ("%s", grub_errmsg);
return 0;
}
/* Add the region where modules reside into dynamic memory. */
grub_mm_init_region ((void *) modinfo, modinfo->size);
grub_module_iterate (hook);
}
/* Write hook for the environment variables of root. Remove surrounding