2005-01-04 Hollis Blanchard <hollis@penguinppc.org>
* TODO: Add note about endianness in grub-mkimage. * boot/powerpc/ieee1275/crt0.S (note): Remove unused .note section. * conf/powerpc-ieee1275.rmk (bin_UTILITIES): Add grub-mkimage. (grub_mkimage_SOURCES): New target. * include/grub/kernel.h (grub_start_addr): Remove variable. (grub_end_addr): Likewise. (grub_total_module_size): Likewise. (grub_kernel_image_size): Likewise. (GRUB_MODULE_MAGIC): New constant. (grub_module_info): New structure. (grub_arch_modules_addr): New prototype. (grub_get_end_addr): Remove prototype. * include/grub/i386/pc/kernel.h (grub_end_addr): New prototype. * include/grub/powerpc/ieee1275/kernel.h: New file. * include/grub/util/misc.h (grub_util_get_fp_size): New prototype. (grub_util_read_at): Likewise. (grub_util_write_image_at): Likewise. * kern/main.c (grub_get_end_addr): Remove function. (grub_load_modules): Call grub_arch_modules_addr instead of using grub_end_addr. Look for a grub_module_info struct in memory. Use the grub_module_info fields instead of calling grub_get_end_addr as loop conditions. Move grub_add_unused_region code here. (grub_add_unused_region): Remove function. * kern/i386/pc/init.c: Include grub/cache.h. (grub_machine_init): Remove call to grub_get_end_addr. Remove one call to add_mem_region. (grub_arch_modules_addr): New function. * kern/powerpc/ieee1275/init.c (grub_end_addr): Remove variable. (grub_total_module_size): Likewise. Include grub/machine/kernel.h. (grub_arch_modules_addr): New function. * util/grub-emu.c (grub_end_addr): Remove variable. (grub_total_module_size): Likewise. (grub_arch_modules_addr): New function. * util/misc.c: Include unistd.h. (grub_util_get_fp_size): New function. (grub_util_read_at): Likewise. (grub_util_write_image_at): Likewise. (grub_util_read_image): Call grub_util_read_at. (grub_util_write_image): Call grub_util_write_image_at. * util/i386/pc/grub-mkimage.c (generate_image): Allocate additional memory in kernel_img for a struct grub_module_info. Fill in that grub_module_info. * util/powerpc/ieee1275/grub-mkimage.c: New file.
This commit is contained in:
parent
458786f8fc
commit
0b412211b3
15 changed files with 488 additions and 70 deletions
42
util/misc.c
42
util/misc.c
|
@ -25,6 +25,7 @@
|
|||
#include <sys/stat.h>
|
||||
#include <sys/times.h>
|
||||
#include <malloc.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <grub/util/misc.h>
|
||||
#include <grub/mm.h>
|
||||
|
@ -106,6 +107,20 @@ grub_util_get_path (const char *dir, const char *file)
|
|||
return path;
|
||||
}
|
||||
|
||||
size_t
|
||||
grub_util_get_fp_size (FILE *fp)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if (fflush (fp) == EOF)
|
||||
grub_util_error ("fflush failed");
|
||||
|
||||
if (fstat (fileno (fp), &st) == -1)
|
||||
grub_util_error ("fstat failed");
|
||||
|
||||
return st.st_size;
|
||||
}
|
||||
|
||||
size_t
|
||||
grub_util_get_image_size (const char *path)
|
||||
{
|
||||
|
@ -119,6 +134,16 @@ grub_util_get_image_size (const char *path)
|
|||
return st.st_size;
|
||||
}
|
||||
|
||||
void
|
||||
grub_util_read_at (void *img, size_t size, off_t offset, FILE *fp)
|
||||
{
|
||||
if (fseek (fp, offset, SEEK_SET) == -1)
|
||||
grub_util_error ("fseek failed");
|
||||
|
||||
if (fread (img, 1, size, fp) != size)
|
||||
grub_util_error ("read failed");
|
||||
}
|
||||
|
||||
char *
|
||||
grub_util_read_image (const char *path)
|
||||
{
|
||||
|
@ -134,9 +159,8 @@ grub_util_read_image (const char *path)
|
|||
fp = fopen (path, "rb");
|
||||
if (! fp)
|
||||
grub_util_error ("cannot open %s", path);
|
||||
|
||||
if (fread (img, 1, size, fp) != size)
|
||||
grub_util_error ("cannot read %s", path);
|
||||
|
||||
grub_util_read_at (img, size, 0, fp);
|
||||
|
||||
fclose (fp);
|
||||
|
||||
|
@ -164,13 +188,21 @@ grub_util_load_image (const char *path, char *buf)
|
|||
}
|
||||
|
||||
void
|
||||
grub_util_write_image (const char *img, size_t size, FILE *out)
|
||||
grub_util_write_image_at (const void *img, size_t size, off_t offset, FILE *out)
|
||||
{
|
||||
grub_util_info ("writing 0x%x bytes", size);
|
||||
grub_util_info ("writing 0x%x bytes at offset 0x%x", size, offset);
|
||||
if (fseek (out, offset, SEEK_SET) == -1)
|
||||
grub_util_error ("seek failed");
|
||||
if (fwrite (img, 1, size, out) != size)
|
||||
grub_util_error ("write failed");
|
||||
}
|
||||
|
||||
void
|
||||
grub_util_write_image (const char *img, size_t size, FILE *out)
|
||||
{
|
||||
grub_util_write_image_at (img, size, 0, out);
|
||||
}
|
||||
|
||||
void *
|
||||
grub_malloc (unsigned size)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue