2009-06-20 Robert Millan <rmh.grub@aybabtu.com>
* include/grub/i386/loader.h (grub_linux_prot_size) (grub_linux_tmp_addr, grub_linux_real_addr) (grub_linux_is_bzimage, grub_linux16_boot): Declare only on GRUB_MACHINE_PCBIOS. * util/i386/pc/grub-mkimage.c (compress_kernel): Move common grub_util_info() call to ... (generate_image): ... here. Fix use of uninitialized memory, comparison of signed with unsigned integers and memory leak. Remove bogus module address message.
This commit is contained in:
parent
ab32d3b5fe
commit
cd7310d5d5
3 changed files with 29 additions and 16 deletions
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
||||||
|
2009-06-20 Robert Millan <rmh.grub@aybabtu.com>
|
||||||
|
|
||||||
|
* include/grub/i386/loader.h (grub_linux_prot_size)
|
||||||
|
(grub_linux_tmp_addr, grub_linux_real_addr)
|
||||||
|
(grub_linux_is_bzimage, grub_linux16_boot): Declare only on
|
||||||
|
GRUB_MACHINE_PCBIOS.
|
||||||
|
* util/i386/pc/grub-mkimage.c (compress_kernel): Move
|
||||||
|
common grub_util_info() call to ...
|
||||||
|
(generate_image): ... here.
|
||||||
|
Fix use of uninitialized memory, comparison of signed with
|
||||||
|
unsigned integers and memory leak.
|
||||||
|
Remove bogus module address message.
|
||||||
|
|
||||||
2009-06-20 Vladimir Serbinenko <phcoder@gmail.com>
|
2009-06-20 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
* disk/mdraid_linux.c (GRUB_MOD_FINI): use grub_raid_unregister and not
|
* disk/mdraid_linux.c (GRUB_MOD_FINI): use grub_raid_unregister and not
|
||||||
|
|
|
@ -22,14 +22,17 @@
|
||||||
#include <grub/types.h>
|
#include <grub/types.h>
|
||||||
#include <grub/err.h>
|
#include <grub/err.h>
|
||||||
#include <grub/symbol.h>
|
#include <grub/symbol.h>
|
||||||
|
#include <grub/machine/machine.h>
|
||||||
|
|
||||||
|
extern grub_addr_t EXPORT_VAR(grub_os_area_addr);
|
||||||
|
extern grub_size_t EXPORT_VAR(grub_os_area_size);
|
||||||
|
|
||||||
|
#ifdef GRUB_MACHINE_PCBIOS
|
||||||
extern grub_uint32_t EXPORT_VAR(grub_linux_prot_size);
|
extern grub_uint32_t EXPORT_VAR(grub_linux_prot_size);
|
||||||
extern char *EXPORT_VAR(grub_linux_tmp_addr);
|
extern char *EXPORT_VAR(grub_linux_tmp_addr);
|
||||||
extern char *EXPORT_VAR(grub_linux_real_addr);
|
extern char *EXPORT_VAR(grub_linux_real_addr);
|
||||||
extern grub_int32_t EXPORT_VAR(grub_linux_is_bzimage);
|
extern grub_int32_t EXPORT_VAR(grub_linux_is_bzimage);
|
||||||
extern grub_addr_t EXPORT_VAR(grub_os_area_addr);
|
|
||||||
extern grub_size_t EXPORT_VAR(grub_os_area_size);
|
|
||||||
|
|
||||||
grub_err_t EXPORT_FUNC(grub_linux16_boot) (void);
|
grub_err_t EXPORT_FUNC(grub_linux16_boot) (void);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* ! GRUB_LOADER_CPU_HEADER */
|
#endif /* ! GRUB_LOADER_CPU_HEADER */
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/* grub-mkimage.c - make a bootable image */
|
/* grub-mkimage.c - make a bootable image */
|
||||||
/*
|
/*
|
||||||
* GRUB -- GRand Unified Bootloader
|
* GRUB -- GRand Unified Bootloader
|
||||||
* Copyright (C) 2002,2003,2004,2005,2006,2007,2008 Free Software Foundation, Inc.
|
* Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009 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
|
||||||
|
@ -59,7 +59,6 @@ compress_kernel (char *kernel_img, size_t kernel_size,
|
||||||
lzo_uint size;
|
lzo_uint size;
|
||||||
char *wrkmem;
|
char *wrkmem;
|
||||||
|
|
||||||
grub_util_info ("kernel_img=%p, kernel_size=0x%x", kernel_img, kernel_size);
|
|
||||||
if (kernel_size < GRUB_KERNEL_MACHINE_RAW_SIZE)
|
if (kernel_size < GRUB_KERNEL_MACHINE_RAW_SIZE)
|
||||||
grub_util_error ("the core image is too small");
|
grub_util_error ("the core image is too small");
|
||||||
|
|
||||||
|
@ -107,7 +106,6 @@ compress_kernel (char *kernel_img, size_t kernel_size,
|
||||||
props.pb = 2;
|
props.pb = 2;
|
||||||
props.numThreads = 1;
|
props.numThreads = 1;
|
||||||
|
|
||||||
grub_util_info ("kernel_img=%p, kernel_size=0x%x", kernel_img, kernel_size);
|
|
||||||
if (kernel_size < GRUB_KERNEL_MACHINE_RAW_SIZE)
|
if (kernel_size < GRUB_KERNEL_MACHINE_RAW_SIZE)
|
||||||
grub_util_error ("the core image is too small");
|
grub_util_error ("the core image is too small");
|
||||||
|
|
||||||
|
@ -132,7 +130,6 @@ static void
|
||||||
generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
|
generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
|
||||||
char *memdisk_path, char *config_path)
|
char *memdisk_path, char *config_path)
|
||||||
{
|
{
|
||||||
grub_addr_t module_addr = 0;
|
|
||||||
char *kernel_img, *boot_img, *core_img;
|
char *kernel_img, *boot_img, *core_img;
|
||||||
size_t kernel_size, boot_size, total_module_size, core_size;
|
size_t kernel_size, boot_size, total_module_size, core_size;
|
||||||
size_t memdisk_size = 0, config_size = 0;
|
size_t memdisk_size = 0, config_size = 0;
|
||||||
|
@ -178,6 +175,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
|
||||||
|
|
||||||
/* Fill in the grub_module_info structure. */
|
/* Fill in the grub_module_info structure. */
|
||||||
modinfo = (struct grub_module_info *) (kernel_img + kernel_size);
|
modinfo = (struct grub_module_info *) (kernel_img + kernel_size);
|
||||||
|
memset (modinfo, 0, sizeof (struct grub_module_info));
|
||||||
modinfo->magic = GRUB_MODULE_MAGIC;
|
modinfo->magic = GRUB_MODULE_MAGIC;
|
||||||
modinfo->offset = sizeof (struct grub_module_info);
|
modinfo->offset = sizeof (struct grub_module_info);
|
||||||
modinfo->size = total_module_size;
|
modinfo->size = total_module_size;
|
||||||
|
@ -191,6 +189,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
|
||||||
mod_size = grub_util_get_image_size (p->name);
|
mod_size = grub_util_get_image_size (p->name);
|
||||||
|
|
||||||
header = (struct grub_module_header *) (kernel_img + offset);
|
header = (struct grub_module_header *) (kernel_img + offset);
|
||||||
|
memset (header, 0, sizeof (struct grub_module_header));
|
||||||
header->type = grub_cpu_to_le32 (OBJ_TYPE_ELF);
|
header->type = grub_cpu_to_le32 (OBJ_TYPE_ELF);
|
||||||
header->size = grub_cpu_to_le32 (mod_size + sizeof (*header));
|
header->size = grub_cpu_to_le32 (mod_size + sizeof (*header));
|
||||||
offset += sizeof (*header);
|
offset += sizeof (*header);
|
||||||
|
@ -204,6 +203,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
|
||||||
struct grub_module_header *header;
|
struct grub_module_header *header;
|
||||||
|
|
||||||
header = (struct grub_module_header *) (kernel_img + offset);
|
header = (struct grub_module_header *) (kernel_img + offset);
|
||||||
|
memset (header, 0, sizeof (struct grub_module_header));
|
||||||
header->type = grub_cpu_to_le32 (OBJ_TYPE_MEMDISK);
|
header->type = grub_cpu_to_le32 (OBJ_TYPE_MEMDISK);
|
||||||
header->size = grub_cpu_to_le32 (memdisk_size + sizeof (*header));
|
header->size = grub_cpu_to_le32 (memdisk_size + sizeof (*header));
|
||||||
offset += sizeof (*header);
|
offset += sizeof (*header);
|
||||||
|
@ -217,6 +217,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
|
||||||
struct grub_module_header *header;
|
struct grub_module_header *header;
|
||||||
|
|
||||||
header = (struct grub_module_header *) (kernel_img + offset);
|
header = (struct grub_module_header *) (kernel_img + offset);
|
||||||
|
memset (header, 0, sizeof (struct grub_module_header));
|
||||||
header->type = grub_cpu_to_le32 (OBJ_TYPE_CONFIG);
|
header->type = grub_cpu_to_le32 (OBJ_TYPE_CONFIG);
|
||||||
header->size = grub_cpu_to_le32 (config_size + sizeof (*header));
|
header->size = grub_cpu_to_le32 (config_size + sizeof (*header));
|
||||||
offset += sizeof (*header);
|
offset += sizeof (*header);
|
||||||
|
@ -226,6 +227,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
|
||||||
*(kernel_img + offset - 1) = 0;
|
*(kernel_img + offset - 1) = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
grub_util_info ("kernel_img=%p, kernel_size=0x%x", kernel_img, kernel_size);
|
||||||
compress_kernel (kernel_img, kernel_size + total_module_size,
|
compress_kernel (kernel_img, kernel_size + total_module_size,
|
||||||
&core_img, &core_size);
|
&core_img, &core_size);
|
||||||
|
|
||||||
|
@ -251,12 +253,6 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
|
||||||
free (boot_img);
|
free (boot_img);
|
||||||
free (boot_path);
|
free (boot_path);
|
||||||
|
|
||||||
module_addr = (path_list
|
|
||||||
? (GRUB_BOOT_MACHINE_KERNEL_ADDR + GRUB_DISK_SECTOR_SIZE
|
|
||||||
+ 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_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE))
|
||||||
= grub_cpu_to_le32 (total_module_size);
|
= grub_cpu_to_le32 (total_module_size);
|
||||||
*((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_KERNEL_IMAGE_SIZE))
|
*((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_KERNEL_IMAGE_SIZE))
|
||||||
|
@ -274,9 +270,9 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
|
||||||
= grub_cpu_to_le32 (-2);
|
= grub_cpu_to_le32 (-2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (core_size > GRUB_MEMORY_MACHINE_UPPER - GRUB_MEMORY_MACHINE_LINK_ADDR)
|
if (GRUB_MEMORY_MACHINE_LINK_ADDR + core_size > GRUB_MEMORY_MACHINE_UPPER)
|
||||||
grub_util_error ("Core image is too big (%p > %p)\n", core_size,
|
grub_util_error ("Core image is too big (%p > %p)\n",
|
||||||
GRUB_MEMORY_MACHINE_UPPER - GRUB_MEMORY_MACHINE_LINK_ADDR);
|
GRUB_MEMORY_MACHINE_LINK_ADDR + core_size, GRUB_MEMORY_MACHINE_UPPER);
|
||||||
|
|
||||||
grub_util_write_image (core_img, core_size, out);
|
grub_util_write_image (core_img, core_size, out);
|
||||||
free (kernel_img);
|
free (kernel_img);
|
||||||
|
@ -415,6 +411,7 @@ main (int argc, char *argv[])
|
||||||
if (output)
|
if (output)
|
||||||
{
|
{
|
||||||
fp = fopen (output, "wb");
|
fp = fopen (output, "wb");
|
||||||
|
free (output);
|
||||||
if (! fp)
|
if (! fp)
|
||||||
grub_util_error ("cannot open %s", output);
|
grub_util_error ("cannot open %s", output);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue