2005-01-09 Hollis Blanchard <hollis@penguinppc.org>

* util/powerpc/ieee1275/grub-mkimage.c: Include <string.h>.
	(note_path): Remove variable.
	(GRUB_IEEE1275_NOTE_NAME): New macro.
	(GRUB_IEEE1275_NOTE_TYPE): Likewise.
	(grub_ieee1275_note_hdr): New structure.
	(grub_ieee1275_note_desc): Likewise.
	(grub_ieee1275_note): Likewise.
	(load_note): Remove `dir' argument.  All callers updated.  Remove
	`note_img' and `path'.  Do not load a file from `note_path'.
	Initialize a struct grub_ieee1275_note and write that to `out'.
	Use GRUB_IEEE1275_MODULE_BASE instead of MODULE_BASE.
This commit is contained in:
hollisb 2005-01-09 18:11:05 +00:00
parent 4ca7004c3e
commit d0ff18e182
3 changed files with 96 additions and 15 deletions

View File

@ -1,3 +1,17 @@
2005-01-09 Hollis Blanchard <hollis@penguinppc.org>
* util/powerpc/ieee1275/grub-mkimage.c: Include <string.h>.
(note_path): Remove variable.
(GRUB_IEEE1275_NOTE_NAME): New macro.
(GRUB_IEEE1275_NOTE_TYPE): Likewise.
(grub_ieee1275_note_hdr): New structure.
(grub_ieee1275_note_desc): Likewise.
(grub_ieee1275_note): Likewise.
(load_note): Remove `dir' argument. All callers updated. Remove
`note_img' and `path'. Do not load a file from `note_path'.
Initialize a struct grub_ieee1275_note and write that to `out'.
Use GRUB_IEEE1275_MODULE_BASE instead of MODULE_BASE.
2005-01-05 Marco Gerards <metgerards@student.han.nl>
* util/misc.c (grub_util_read_image): Revert last change. It

View File

@ -24,9 +24,43 @@ kernel_syms.lst: $(addprefix include/grub/,$(grubof_HEADERS)) genkernsyms.sh
pkgdata_PROGRAMS = grubof
# Utilities.
bin_UTILITIES = grub-emu
bin_UTILITIES = grub-emu grub-mkimage
noinst_UTILITIES = genmoddep
# For grub-mkimage.
grub_mkimage_SOURCES = util/powerpc/ieee1275/grub-mkimage.c util/misc.c \
util/resolve.c
CLEANFILES += grub-mkimage grub_mkimage-util_powerpc_ieee1275_grub_mkimage.o grub_mkimage-util_misc.o grub_mkimage-util_resolve.o
MOSTLYCLEANFILES += grub_mkimage-util_powerpc_ieee1275_grub_mkimage.d grub_mkimage-util_misc.d grub_mkimage-util_resolve.d
grub-mkimage: grub_mkimage-util_powerpc_ieee1275_grub_mkimage.o grub_mkimage-util_misc.o grub_mkimage-util_resolve.o
$(BUILD_CC) -o $@ $^ $(BUILD_LDFLAGS) $(grub_mkimage_LDFLAGS)
grub_mkimage-util_powerpc_ieee1275_grub_mkimage.o: util/powerpc/ieee1275/grub-mkimage.c
$(BUILD_CC) -Iutil/powerpc/ieee1275 -I$(srcdir)/util/powerpc/ieee1275 $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) -DGRUB_UTIL=1 $(grub_mkimage_CFLAGS) -c -o $@ $<
grub_mkimage-util_powerpc_ieee1275_grub_mkimage.d: util/powerpc/ieee1275/grub-mkimage.c
set -e; $(BUILD_CC) -Iutil/powerpc/ieee1275 -I$(srcdir)/util/powerpc/ieee1275 $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) -DGRUB_UTIL=1 $(grub_mkimage_CFLAGS) -M $< | sed 's,grub\-mkimage\.o[ :]*,grub_mkimage-util_powerpc_ieee1275_grub_mkimage.o $@ : ,g' > $@; [ -s $@ ] || rm -f $@
-include grub_mkimage-util_powerpc_ieee1275_grub_mkimage.d
grub_mkimage-util_misc.o: util/misc.c
$(BUILD_CC) -Iutil -I$(srcdir)/util $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) -DGRUB_UTIL=1 $(grub_mkimage_CFLAGS) -c -o $@ $<
grub_mkimage-util_misc.d: util/misc.c
set -e; $(BUILD_CC) -Iutil -I$(srcdir)/util $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) -DGRUB_UTIL=1 $(grub_mkimage_CFLAGS) -M $< | sed 's,misc\.o[ :]*,grub_mkimage-util_misc.o $@ : ,g' > $@; [ -s $@ ] || rm -f $@
-include grub_mkimage-util_misc.d
grub_mkimage-util_resolve.o: util/resolve.c
$(BUILD_CC) -Iutil -I$(srcdir)/util $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) -DGRUB_UTIL=1 $(grub_mkimage_CFLAGS) -c -o $@ $<
grub_mkimage-util_resolve.d: util/resolve.c
set -e; $(BUILD_CC) -Iutil -I$(srcdir)/util $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) -DGRUB_UTIL=1 $(grub_mkimage_CFLAGS) -M $< | sed 's,resolve\.o[ :]*,grub_mkimage-util_resolve.o $@ : ,g' > $@; [ -s $@ ] || rm -f $@
-include grub_mkimage-util_resolve.d
# For grub-emu
grub_emu_SOURCES = kern/main.c kern/device.c \
kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \

View File

@ -23,6 +23,7 @@
#include <fcntl.h>
#include <getopt.h>
#include <stdlib.h>
#include <string.h>
#include <grub/elf.h>
#include <grub/util/misc.h>
#include <grub/util/resolve.h>
@ -32,26 +33,58 @@
#define ALIGN_UP(addr, align) ((long)((char *)addr + align - 1) & ~(align - 1))
static char *kernel_path = "grubof";
static char *note_path = "note";
#define GRUB_IEEE1275_NOTE_NAME "PowerPC"
#define GRUB_IEEE1275_NOTE_TYPE 0x1275
/* These structures are defined according to the CHRP binding to IEEE1275,
"Client Program Format" section. */
struct grub_ieee1275_note_hdr
{
grub_uint32_t namesz;
grub_uint32_t descsz;
grub_uint32_t type;
char name[sizeof (GRUB_IEEE1275_NOTE_NAME)];
};
struct grub_ieee1275_note_desc
{
grub_uint32_t real_mode;
grub_uint32_t real_base;
grub_uint32_t real_size;
grub_uint32_t virt_base;
grub_uint32_t virt_size;
grub_uint32_t load_base;
};
struct grub_ieee1275_note
{
struct grub_ieee1275_note_hdr header;
struct grub_ieee1275_note_desc descriptor;
};
void
load_note (Elf32_Phdr *phdr, const char *dir, FILE *out)
load_note (Elf32_Phdr *phdr, FILE *out)
{
char *note_img;
char *path;
int note_size;
struct grub_ieee1275_note note;
int note_size = sizeof (struct grub_ieee1275_note);
grub_util_info ("adding CHRP NOTE segment");
path = grub_util_get_path (dir, note_path);
note_size = grub_util_get_image_size (path);
note_img = xmalloc (note_size);
grub_util_load_image (path, note_img);
free (path);
note.header.namesz = grub_cpu_to_be32 (sizeof (GRUB_IEEE1275_NOTE_NAME));
note.header.descsz = grub_cpu_to_be32 (note_size);
note.header.type = grub_cpu_to_be32 (GRUB_IEEE1275_NOTE_TYPE);
strcpy (note.header.name, GRUB_IEEE1275_NOTE_NAME);
note.descriptor.real_mode = grub_cpu_to_be32 (0xffffffff);
note.descriptor.real_base = grub_cpu_to_be32 (0x00c00000);
note.descriptor.real_size = grub_cpu_to_be32 (0xffffffff);
note.descriptor.virt_base = grub_cpu_to_be32 (0xffffffff);
note.descriptor.virt_size = grub_cpu_to_be32 (0xffffffff);
note.descriptor.load_base = grub_cpu_to_be32 (0x00004000);
/* Write the note data to the new segment. */
grub_util_write_image_at (note_img, note_size, phdr->p_offset, out);
grub_util_write_image_at (&note, note_size, phdr->p_offset, out);
/* Fill in the rest of the segment header. */
phdr->p_type = PT_NOTE;
@ -117,8 +150,8 @@ load_modules (Elf32_Phdr *phdr, const char *dir, char *mods[], FILE *out)
phdr->p_type = PT_LOAD;
phdr->p_flags = PF_R | PF_W | PF_X;
phdr->p_align = sizeof (long);
phdr->p_vaddr = MODULE_BASE;
phdr->p_paddr = MODULE_BASE;
phdr->p_vaddr = GRUB_IEEE1275_MODULE_BASE;
phdr->p_paddr = GRUB_IEEE1275_MODULE_BASE;
phdr->p_filesz = total_module_size;
phdr->p_memsz = total_module_size;
}
@ -183,7 +216,7 @@ add_segments (char *dir, FILE *out, int chrp, char *mods[])
/* Fill in p_offset so the callees know where to write. */
phdr->p_offset = ALIGN_UP (grub_util_get_fp_size (out), sizeof (long));
load_note (phdr, dir, out);
load_note (phdr, out);
}
/* Don't bother preserving the section headers. */