All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hollis Blanchard <hollis@penguinppc.org>
To: grub-devel@gnu.org
Subject: [ppc] fix and improve grub-mkimage
Date: Sat, 8 Jan 2005 17:26:17 -0600	[thread overview]
Message-ID: <20050108232617.GA7128@miracle> (raw)

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  <hollis@penguinppc.org>

	* 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 (&note, 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.  */



             reply	other threads:[~2005-01-09  0:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-08 23:26 Hollis Blanchard [this message]
2005-01-09 13:20 ` [ppc] fix and improve grub-mkimage Marco Gerards

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050108232617.GA7128@miracle \
    --to=hollis@penguinppc.org \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.