From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1CnQme-000496-3s for mharc-grub-devel@gnu.org; Sat, 08 Jan 2005 19:18:16 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1CnQmU-00046b-Tj for grub-devel@gnu.org; Sat, 08 Jan 2005 19:18:09 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1CnQmJ-000415-Su for grub-devel@gnu.org; Sat, 08 Jan 2005 19:18:03 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1CnQmI-0003k5-RK for grub-devel@gnu.org; Sat, 08 Jan 2005 19:17:55 -0500 Received: from [207.217.121.254] (helo=pop-a065d23.pas.sa.earthlink.net) by monty-python.gnu.org with esmtp (Exim 4.34) id 1CnQHb-0003yf-Ok for grub-devel@gnu.org; Sat, 08 Jan 2005 18:46:11 -0500 Received: from user-0vvde4j.cable.mindspring.com ([63.246.184.147] helo=miracle) by pop-a065d23.pas.sa.earthlink.net with esmtp (Exim 3.33 #1) id 1CnQHV-0002dN-00 for grub-devel@gnu.org; Sat, 08 Jan 2005 15:46:05 -0800 Received: from hollis by miracle with local (Exim 3.36 #1 (Debian)) id 1CnPyL-0001rb-00 for ; Sat, 08 Jan 2005 17:26:17 -0600 Date: Sat, 8 Jan 2005 17:26:17 -0600 To: grub-devel@gnu.org Message-ID: <20050108232617.GA7128@miracle> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.6+20040907i From: Hollis Blanchard Subject: [ppc] fix and improve grub-mkimage X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 09 Jan 2005 00:18:11 -0000 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 * util/powerpc/ieee1275/grub-mkimage.c: Include . (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 #include #include +#include #include #include #include @@ -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. */