From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1KNCzp-0001eG-BH for mharc-grub-devel@gnu.org; Sun, 27 Jul 2008 16:37:37 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KNCzn-0001c6-Gq for grub-devel@gnu.org; Sun, 27 Jul 2008 16:37:35 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KNCzm-0001aJ-1t for grub-devel@gnu.org; Sun, 27 Jul 2008 16:37:34 -0400 Received: from [199.232.76.173] (port=35507 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KNCzl-0001a8-RQ for grub-devel@gnu.org; Sun, 27 Jul 2008 16:37:33 -0400 Received: from aybabtu.com ([69.60.117.155]:58647) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KNCzl-0005y5-Lr for grub-devel@gnu.org; Sun, 27 Jul 2008 16:37:33 -0400 Received: from [192.168.10.10] (helo=thorin) by aybabtu.com with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1KNCtM-0002rZ-3z for grub-devel@gnu.org; Sun, 27 Jul 2008 22:30:57 +0200 Received: from rmh by thorin with local (Exim 4.63) (envelope-from ) id 1KNCyp-0003jt-MJ for grub-devel@gnu.org; Sun, 27 Jul 2008 22:36:35 +0200 Date: Sun, 27 Jul 2008 22:36:35 +0200 From: Robert Millan To: The development of GRUB 2 Message-ID: <20080727203635.GA14339@thorin> References: <1216918145.22586.14.camel@dv> <20080725210840.GA19505@thorin> <1217022420.3957.3.camel@dv> <20080725221050.GA31179@thorin> <1217034532.6376.13.camel@dv> <20080727121914.GA11242@thorin> <1217176183.4029.20.camel@ct> <20080727183737.GB16393@thorin> <20080727192857.GA7361@thorin> <20080727201319.GA5378@thorin> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="fUYQa+Pmc3FrFX/N" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20080727201319.GA5378@thorin> Organization: free as in freedom X-Message-Flag: Worried about Outlook viruses? Switch to Thunderbird! www.mozilla.com/thunderbird X-Debbugs-No-Ack: true User-Agent: Mutt/1.5.13 (2006-08-11) X-detected-kernel: by monty-python.gnu.org: Genre and OS details not recognized. Subject: Re: [PATCH] UUID boot on ieee1275 (Re: [PATCH] use UUIDs for cross-disk installs (Re: Issue with boot != root and chainloading)) 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, 27 Jul 2008 20:37:35 -0000 --fUYQa+Pmc3FrFX/N Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Sun, Jul 27, 2008 at 10:13:19PM +0200, Robert Millan wrote: > > So I'm submitting a patch that implements --prefix, without having grub-install > use it. This is useful already (for manual installs), and I'd like to use that > --prefix option for Coreboot later too. Here's a combined patch which also implements --prefix for Coreboot (and on Coreboot it's the only option for automated boot we provide so far). -- Robert Millan I know my rights; I want my phone call! What good is a phone call… if you are unable to speak? (as seen on /.) --fUYQa+Pmc3FrFX/N Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="elf_prefix.diff" 2008-07-27 Robert Millan * 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 `'. (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. Index: kern/ieee1275/init.c =================================================================== --- kern/ieee1275/init.c (revision 1734) +++ kern/ieee1275/init.c (working copy) @@ -84,6 +84,13 @@ /* We already set prefix in grub_machine_init(). */ return; + if (grub_prefix[0]) + { + grub_env_set ("prefix", grub_prefix); + /* Prefix is hardcoded in kernel.elf. */ + return; + } + if (grub_ieee1275_get_property (grub_ieee1275_chosen, "bootpath", &bootpath, sizeof (bootpath), 0)) { Index: kern/i386/ieee1275/startup.S =================================================================== --- kern/i386/ieee1275/startup.S (revision 1734) +++ kern/i386/ieee1275/startup.S (working copy) @@ -19,6 +19,7 @@ #define ASM_FILE 1 #include +#include #include #include #include @@ -38,6 +39,24 @@ 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: kern/i386/linuxbios/startup.S =================================================================== --- kern/i386/linuxbios/startup.S (revision 1734) +++ kern/i386/linuxbios/startup.S (working copy) @@ -19,6 +19,7 @@ #define ASM_FILE 1 #include +#include #include #include #include @@ -35,7 +36,25 @@ .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 /* * Support for booting GRUB from a Multiboot boot loader (e.g. GRUB itself). @@ -49,8 +68,7 @@ .long -0x1BADB002 #endif -start: -_start: +codestart: /* initialize the stack */ movl $GRUB_MEMORY_MACHINE_PROT_STACK, %esp Index: kern/i386/linuxbios/init.c =================================================================== --- kern/i386/linuxbios/init.c (revision 1734) +++ kern/i386/linuxbios/init.c (working copy) @@ -78,12 +78,6 @@ { } -static char * -make_install_device (void) -{ - return NULL; -} - void grub_machine_init (void) { @@ -155,7 +149,7 @@ grub_machine_set_prefix (void) { /* Initialize the prefix. */ - grub_env_set ("prefix", make_install_device ()); + grub_env_set ("prefix", grub_prefix); } void Index: include/grub/powerpc/ieee1275/kernel.h =================================================================== --- include/grub/powerpc/ieee1275/kernel.h (revision 1734) +++ include/grub/powerpc/ieee1275/kernel.h (working copy) @@ -28,7 +28,15 @@ 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: include/grub/i386/ieee1275/kernel.h =================================================================== --- include/grub/i386/ieee1275/kernel.h (revision 1734) +++ include/grub/i386/ieee1275/kernel.h (working copy) @@ -1 +1,4 @@ #include + +#define GRUB_KERNEL_MACHINE_PREFIX 0x2 +#define GRUB_KERNEL_MACHINE_DATA_END 0x42 Index: include/grub/i386/coreboot/kernel.h =================================================================== --- include/grub/i386/coreboot/kernel.h (revision 1734) +++ include/grub/i386/coreboot/kernel.h (working copy) @@ -26,4 +26,11 @@ /* 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: util/elf/grub-mkimage.c =================================================================== --- util/elf/grub-mkimage.c (revision 1734) +++ util/elf/grub-mkimage.c (working copy) @@ -158,7 +158,7 @@ } 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 @@ 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 @@ 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 @@ /* 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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); --fUYQa+Pmc3FrFX/N--