[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ppc] fix and improve grub-mkimage
From: |
Hollis Blanchard |
Subject: |
[ppc] fix and improve grub-mkimage |
Date: |
Sat, 8 Jan 2005 17:26:17 -0600 |
User-agent: |
Mutt/1.5.6+20040907i |
PPC grub-mkimage is broken in CVS, as MODULE_BASE was renamed to
GRUB_IEEE1275_MODULE_BASE. This patch fixes the build break.
In addition, this patch improves the CHRP NOTE segment support.
Currently grub-mkimage expects to find a pre-built file named "note", but
that's not a good solution (and the build system does not create this
file). Instead, we can easily create the note data at runtime.
This patch has been tested on briQ (the only affected hardware we can
get our hands on at the moment).
-Hollis
2005-01-08 Hollis Blanchard <address@hidden>
* util/powerpc/ieee1275/grub-mkimage.c: Include <string.h>.
(note_path): Remove variable.
(GRUB_IEEE1275_NOTE_NAME): New constant.
(GRUB_IEEE1275_NOTE_TYPE): Likewise.
(grub_ieee1275_note): New structure.
(load_note): Remove `dir' argument. All callers updated. Remove
`note_img' and `path'. Do note 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.
Index: util/powerpc/ieee1275/grub-mkimage.c
===================================================================
RCS file: /cvsroot/grub/grub2/util/powerpc/ieee1275/grub-mkimage.c,v
retrieving revision 1.1
diff -u -p -r1.1 grub-mkimage.c
--- util/powerpc/ieee1275/grub-mkimage.c 4 Jan 2005 14:01:45 -0000
1.1
+++ util/powerpc/ieee1275/grub-mkimage.c 8 Jan 2005 23:39:50 -0000
@@ -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,49 @@
#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
+
+/* See the CHRP binding to IEEE1275, "Client Program Format". */
+struct grub_ieee1275_note {
+ struct grub_ieee1275_note_hdr {
+ grub_uint32_t namesz;
+ grub_uint32_t descsz;
+ grub_uint32_t type;
+ char name[sizeof (GRUB_IEEE1275_NOTE_NAME)];
+ } header;
+ 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;
+ } 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 (¬e, note_size, phdr->p_offset, out);
/* Fill in the rest of the segment header. */
phdr->p_type = PT_NOTE;
@@ -117,8 +141,8 @@ load_modules (Elf32_Phdr *phdr, const ch
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 +207,7 @@ add_segments (char *dir, FILE *out, int
/* 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. */
- [ppc] fix and improve grub-mkimage,
Hollis Blanchard <=