]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
2008-07-30 Robert Millan <rmh@aybabtu.com>
authorrobertmh <robertmh@localhost>
Wed, 30 Jul 2008 10:42:11 +0000 (10:42 +0000)
committerrobertmh <robertmh@localhost>
Wed, 30 Jul 2008 10:42:11 +0000 (10:42 +0000)
        * kern/ieee1275/init.c (grub_machine_set_prefix): If `grub_prefix'
        is non-empty, use it to set the `prefix' environment variable instead
        of the usual approach.
        * kern/i386/linuxbios/init.c (make_install_device): Remove function.
        (grub_machine_set_prefix): Use `grub_prefix' to set the `prefix'
        environment variable instead of dummy make_install_device().

        * kern/i386/ieee1275/startup.S: Include `<grub/machine/kernel.h>'.
        (start): Insert a data section, with `grub_prefix' variable.
        * kern/i386/linuxbios/startup.S: Likewise.

        * include/grub/powerpc/ieee1275/kernel.h [!ASM_FILE] (grub_prefix):
        New variable reference.
        * include/grub/i386/ieee1275/kernel.h (GRUB_KERNEL_MACHINE_PREFIX):
        New macro.  Defines offset of `grub_prefix' within startup.S (relative
        to `start').
        (GRUB_KERNEL_MACHINE_DATA_END): New macro.  Defines the end of data
        section within startup.S (relative to `start').
        * include/grub/i386/coreboot/kernel.h: Likewise.

        * util/elf/grub-mkimage.c (add_segments): Receive `prefix' parameter.
        Overwrite grub_prefix with its contents, at the beginning of the
        first segment.
        (main): Understand -p|--prefix.

ChangeLog
include/grub/i386/coreboot/kernel.h [new file with mode: 0644]
include/grub/i386/ieee1275/kernel.h
include/grub/powerpc/ieee1275/kernel.h
kern/i386/ieee1275/startup.S
kern/i386/linuxbios/init.c
kern/i386/linuxbios/startup.S
kern/ieee1275/init.c
util/elf/grub-mkimage.c

index 797a7dddbb8210d7262e37c2f848acc5da717d23..63f073a466176770499ff6c33fc872e773c6eca3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,30 @@
+2008-07-30  Robert Millan  <rmh@aybabtu.com>
+
+       * kern/ieee1275/init.c (grub_machine_set_prefix): If `grub_prefix'
+       is non-empty, use it to set the `prefix' environment variable instead
+       of the usual approach.
+       * kern/i386/linuxbios/init.c (make_install_device): Remove function.
+       (grub_machine_set_prefix): Use `grub_prefix' to set the `prefix'
+       environment variable instead of dummy make_install_device().
+
+       * kern/i386/ieee1275/startup.S: Include `<grub/machine/kernel.h>'.
+       (start): Insert a data section, with `grub_prefix' variable.
+        * kern/i386/linuxbios/startup.S: Likewise.
+
+       * include/grub/powerpc/ieee1275/kernel.h [!ASM_FILE] (grub_prefix):
+       New variable reference.
+       * include/grub/i386/ieee1275/kernel.h (GRUB_KERNEL_MACHINE_PREFIX):
+       New macro.  Defines offset of `grub_prefix' within startup.S (relative
+       to `start').
+       (GRUB_KERNEL_MACHINE_DATA_END): New macro.  Defines the end of data
+       section within startup.S (relative to `start').
+       * include/grub/i386/coreboot/kernel.h: Likewise.
+
+       * util/elf/grub-mkimage.c (add_segments): Receive `prefix' parameter.
+       Overwrite grub_prefix with its contents, at the beginning of the
+       first segment.
+       (main): Understand -p|--prefix.
+
 2008-07-30  Robert Millan  <rmh@aybabtu.com>
 
        * util/grub.d/10_hurd.in: Source ${libdir}/grub/update-grub_lib.
diff --git a/include/grub/i386/coreboot/kernel.h b/include/grub/i386/coreboot/kernel.h
new file mode 100644 (file)
index 0000000..442d941
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2005,2006,2007,2008  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_KERNEL_MACHINE_HEADER
+#define GRUB_KERNEL_MACHINE_HEADER     1
+
+#include <grub/symbol.h>
+
+#define GRUB_MOD_ALIGN 0x1000
+
+/* Non-zero value is only needed for some IEEE-1275 platforms.  */
+#define GRUB_MOD_GAP 0
+
+#ifndef ASM_FILE
+extern char grub_prefix[];
+#endif
+
+#define GRUB_KERNEL_MACHINE_PREFIX     0x2
+#define GRUB_KERNEL_MACHINE_DATA_END   0x42
+
+#endif /* ! GRUB_KERNEL_MACHINE_HEADER */
index dccf8cbe17a953df298ebdbb4e1a3b6a8bef9d88..66cd4fbf79ef92df8bc9f8e498d3ebbfa28a569a 100644 (file)
@@ -1 +1,4 @@
 #include <grub/powerpc/ieee1275/kernel.h>
+
+#define GRUB_KERNEL_MACHINE_PREFIX     0x2
+#define GRUB_KERNEL_MACHINE_DATA_END   0x42
index 129ee200d0eaec16aa243293528fce9eb9361b1a..5b437f313b94880bc4f9d2ce1baa9379082172bd 100644 (file)
    rewrite grub-mkimage to generate valid ELF files.  */
 #define GRUB_MOD_GAP 0x8000
 
+#ifndef ASM_FILE
+
 void EXPORT_FUNC (grub_reboot) (void);
 void EXPORT_FUNC (grub_halt) (void);
 
+/* The prefix which points to the directory where GRUB modules and its
+   configuration file are located.  */
+extern char grub_prefix[];
+
+#endif
+
 #endif /* ! GRUB_KERNEL_MACHINE_HEADER */
index 8bb731bc3d389bfb5f948bd48b5ae32a451b9aa7..0e1ffd17c0c025b4b5bf30454b8063a9014e1549 100644 (file)
@@ -19,6 +19,7 @@
 #define ASM_FILE       1
 
 #include <grub/symbol.h>
+#include <grub/machine/kernel.h>
 #include <grub/machine/memory.h>
 #include <grub/cpu/linux.h>
 #include <multiboot.h>
 
 start:
 _start:
+       jmp codestart
+
+       /*
+        *  This is a special data area at a fixed offset from the beginning.
+        */
+
+       . = EXT_C(start) + GRUB_KERNEL_MACHINE_PREFIX
+
+VARIABLE(grub_prefix)
+       /* to be filled by grub-mkimage */
+
+       /*
+        *  Leave some breathing room for the prefix.
+        */
+
+       . = EXT_C(start) + GRUB_KERNEL_MACHINE_DATA_END
+
+codestart:
        movl %eax, EXT_C(grub_ieee1275_entry_fn)
        jmp EXT_C(grub_main)
 
index 362131129c95f2931ccc00f3b0b9c79dd08aa291..ed49071f02901d8fbf4b6e3eb226789739d580d6 100644 (file)
@@ -78,12 +78,6 @@ grub_arch_sync_caches (void *address __attribute__ ((unused)),
 {
 }
 
-static char *
-make_install_device (void)
-{
-  return NULL;
-}
-
 void
 grub_machine_init (void)
 {
@@ -155,7 +149,7 @@ void
 grub_machine_set_prefix (void)
 {
   /* Initialize the prefix.  */
-  grub_env_set ("prefix", make_install_device ());
+  grub_env_set ("prefix", grub_prefix);
 }
 
 void
index 2eb2ecdb046f33e081d37ea4643f82f2aace8249..930813f2c82af373c1cb79cee4072b57bde3ca1c 100644 (file)
@@ -19,6 +19,7 @@
 #define ASM_FILE       1
 
 #include <grub/symbol.h>
+#include <grub/machine/kernel.h>
 #include <grub/machine/memory.h>
 #include <grub/cpu/linux.h>
 #include <multiboot.h>
        .file   "startup.S"
        .text
        .globl  start, _start
+start:
+_start:
+       jmp codestart
+
+       /*
+        *  This is a special data area at a fixed offset from the beginning.
+        */
+
+       . = EXT_C(start) + GRUB_KERNEL_MACHINE_PREFIX
+
+VARIABLE(grub_prefix)
+       /* to be filled by grub-mkimage */
+
+       /*
+        *  Leave some breathing room for the prefix.
+        */
+
+       . = EXT_C(start) + GRUB_KERNEL_MACHINE_DATA_END
 
 #if 0
 /*
@@ -49,8 +68,7 @@ multiboot_header:
        .long   -0x1BADB002
 #endif
 
-start:
-_start:
+codestart:
        /* initialize the stack */
        movl $GRUB_MEMORY_MACHINE_PROT_STACK, %esp
 
index efa7ca7ae63b7e7702b37c80e28f287c0b209500..d1d53e0cf21e93e0d70089233ea2cc868dd71c69 100644 (file)
@@ -84,6 +84,13 @@ grub_machine_set_prefix (void)
     /* We already set prefix in grub_machine_init().  */
     return;
 
+  if (grub_prefix[0])
+    {
+      grub_env_set ("prefix", grub_prefix);
+      /* Prefix is hardcoded in the core image.  */
+      return;
+    }
+
   if (grub_ieee1275_get_property (grub_ieee1275_chosen, "bootpath", &bootpath,
                                  sizeof (bootpath), 0))
     {
index 239d3741d3f335ef34a995f5fe03e4b49ea09105..a27567a36c99f77ff12cedb5d6918c40fff1d655 100644 (file)
@@ -158,7 +158,7 @@ load_modules (grub_addr_t modbase, Elf32_Phdr *phdr, const char *dir,
 }
 
 void
-add_segments (char *dir, FILE *out, int chrp, char *mods[])
+add_segments (char *dir, char *prefix, FILE *out, int chrp, char *mods[])
 {
   Elf32_Ehdr ehdr;
   Elf32_Phdr *phdrs = NULL;
@@ -166,7 +166,7 @@ add_segments (char *dir, FILE *out, int chrp, char *mods[])
   FILE *in;
   char *kernel_path;
   grub_addr_t grub_end = 0;
-  off_t offset;
+  off_t offset, first_segment;
   int i, phdr_size;
 
   /* Read ELF header.  */
@@ -192,6 +192,8 @@ add_segments (char *dir, FILE *out, int chrp, char *mods[])
   phdrs = xmalloc (phdr_size);
   offset += ALIGN_UP (phdr_size, GRUB_TARGET_SIZEOF_LONG);
 
+  first_segment = offset;
+
   /* Copy all existing segments.  */
   for (i = 0; i < grub_target_to_host16 (ehdr.e_phnum); i++)
     {
@@ -272,6 +274,13 @@ add_segments (char *dir, FILE *out, int chrp, char *mods[])
   /* Write ELF header.  */
   grub_util_write_image_at (&ehdr, sizeof (ehdr), 0, out);
 
+  if (prefix)
+    {
+      if (GRUB_KERNEL_MACHINE_PREFIX + strlen (prefix) + 1 > GRUB_KERNEL_MACHINE_DATA_END)
+        grub_util_error ("prefix too long");
+      grub_util_write_image_at (prefix, strlen (prefix) + 1, first_segment + GRUB_KERNEL_MACHINE_PREFIX, out);
+    }
+
   free (phdrs);
   free (kernel_path);
 }
@@ -279,6 +288,7 @@ add_segments (char *dir, FILE *out, int chrp, char *mods[])
 static struct option options[] =
   {
     {"directory", required_argument, 0, 'd'},
+    {"prefix", required_argument, 0, 'p'},
     {"output", required_argument, 0, 'o'},
     {"help", no_argument, 0, 'h'},
     {"note", no_argument, 0, 'n'},
@@ -299,6 +309,7 @@ Usage: grub-mkimage -o FILE [OPTION]... [MODULES]\n\
 Make a bootable image of GRUB.\n\
 \n\
 -d, --directory=DIR     use images and modules under DIR [default=%s]\n\
+-p, --prefix=DIR        set grub_prefix directory\n\
 -o, --output=FILE       output a generated image to FILE\n\
 -h, --help              display this message and exit\n\
 -n, --note              add NOTE segment for CHRP Open Firmware\n\
@@ -317,13 +328,14 @@ main (int argc, char *argv[])
   FILE *fp;
   char *output = NULL;
   char *dir = NULL;
+  char *prefix = NULL;
   int chrp = 0;
 
   progname = "grub-mkimage";
 
   while (1)
     {
-      int c = getopt_long (argc, argv, "d:o:hVvn", options, 0);
+      int c = getopt_long (argc, argv, "d:p:o:hVvn", options, 0);
       if (c == -1)
        break;
 
@@ -334,6 +346,11 @@ main (int argc, char *argv[])
              free (dir);
            dir = xstrdup (optarg);
            break;
+         case 'p':
+           if (prefix)
+             free (prefix);
+           prefix = xstrdup (optarg);
+           break;
          case 'h':
            usage (0);
            break;
@@ -364,7 +381,7 @@ main (int argc, char *argv[])
   if (! fp)
     grub_util_error ("cannot open %s", output);
 
-  add_segments (dir ? : GRUB_LIBDIR, fp, chrp, argv + optind);
+  add_segments (dir ? : GRUB_LIBDIR, prefix, fp, chrp, argv + optind);
 
   fclose (fp);