From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1IiES3-0004j2-HE for mharc-grub-devel@gnu.org; Wed, 17 Oct 2007 15:21:07 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IiES2-0004ic-4V for grub-devel@gnu.org; Wed, 17 Oct 2007 15:21:06 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IiERx-0004hy-Mt for grub-devel@gnu.org; Wed, 17 Oct 2007 15:21:04 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IiERx-0004hs-Ce for grub-devel@gnu.org; Wed, 17 Oct 2007 15:21:01 -0400 Received: from khepri.openbios.org ([80.190.231.112]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1IiERw-0006ad-OW for grub-devel@gnu.org; Wed, 17 Oct 2007 15:21:01 -0400 Received: from stepan by khepri.openbios.org with local (Exim 4.68) (envelope-from ) id 1IiERu-0008El-9J for grub-devel@gnu.org; Wed, 17 Oct 2007 21:20:58 +0200 Date: Wed, 17 Oct 2007 21:20:58 +0200 From: Stefan Reinauer To: The development of GRUB 2 Message-ID: <20071017192058.GA30543@coresystems.de> References: <20071012161955.GA26491@thorin> <20071012220337.GB21996@coresystems.de> <20071014120055.GB16638@thorin> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="AhhlLboLdkugWU4S" Content-Disposition: inline In-Reply-To: <20071014120055.GB16638@thorin> X-Operating-System: Linux 2.6.22.5-29-default on an x86_64 User-Agent: Mutt/1.5.16 (2007-06-09) X-Duff: Orig. Duff, Duff Lite, Duff Dry, Duff Dark, Raspberry Duff, Lady Duff, Red Duff, Tartar Control Duff X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) Subject: Re: [PATCH] ELF program header 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: Wed, 17 Oct 2007 19:21:06 -0000 --AhhlLboLdkugWU4S Content-Type: text/plain; charset=us-ascii Content-Disposition: inline * Robert Millan [071014 14:00]: > > We tried the same but the patch was a lot bigger, trying to actually > > leave space in the beginning. Your patch might be enough, that would be > > really nice. > > That's the question. Do we really have to add more space, or is that space > already allocated for us? Ok, I am not exactly sure how to correctly adapt to the latest grub-mkimage changes, so please bear that the attached patch is against Patrick's GSoC version of grub-mkimage.c With this patch attached, grub-mkimage produces an image that works when being loaded as payload from LinuxBIOS version 2. Your smaller version of the patch unfortunately did not work for me. Flames and suggestions please! Best wishes, Stefan --AhhlLboLdkugWU4S Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="grub-mkimage-working.diff" --- grub-mkimage.c.orig 2007-10-05 20:33:50.000000000 +0000 +++ grub-mkimage.c 2007-10-15 18:20:03.000000000 +0000 @@ -104,7 +104,7 @@ FILE *in; char *kernel_path; grub_addr_t grub_end = 0; - off_t phdroff; + off_t phdroff, pstart; int i; /* Read ELF header. */ @@ -115,18 +115,27 @@ grub_util_read_at (&ehdr, sizeof (ehdr), 0, in); + /* The +1 is to leave a hole for the program header for extra modules. */ phdrs = xmalloc (grub_le_to_cpu16 (ehdr.e_phentsize) - * (grub_le_to_cpu16 (ehdr.e_phnum) + 2)); + * (grub_le_to_cpu16 (ehdr.e_phnum) + 1)); + + /* Append entire segment table to the file. */ + //phdroff = ALIGN_UP (grub_util_get_fp_size (out), sizeof (long)); + phdroff = ALIGN_UP (sizeof(ehdr), sizeof (long)); + grub_util_write_image_at (phdrs, grub_le_to_cpu16 (ehdr.e_phentsize) + *(grub_le_to_cpu16 (ehdr.e_phnum) + 1), phdroff, + out); + /* Copy all existing segments. */ grub_util_info ("%u segments", grub_le_to_cpu16 (ehdr.e_phnum)); + pstart = grub_util_get_fp_size (out); + /* set up first phdr offset */ for (i = 0; i < grub_le_to_cpu16 (ehdr.e_phnum); i++) { char *segment_img; grub_size_t segment_end; - phdr = phdrs + i; - - /* Read segment header. */ + /* Read segment header. */ grub_util_read_at (phdr, sizeof (Elf32_Phdr), (grub_le_to_cpu32 (ehdr.e_phoff) + (i * grub_le_to_cpu16 (ehdr.e_phentsize))), @@ -146,9 +155,11 @@ grub_util_read_at (segment_img, grub_le_to_cpu32 (phdr->p_filesz), grub_le_to_cpu32 (phdr->p_offset), in); - grub_util_write_image_at (segment_img, grub_le_to_cpu32 (phdr->p_filesz), + phdr->p_offset = grub_cpu_to_le32(pstart); + grub_util_write_image_at (segment_img, grub_le_to_cpu32 (phdr->p_filesz), grub_le_to_cpu32 (phdr->p_offset), out); + pstart += phdr->p_filesz; free (segment_img); } @@ -176,9 +187,9 @@ ehdr.e_shstrndx = 0; /* Append entire segment table to the file. */ - phdroff = ALIGN_UP (grub_util_get_fp_size (out), sizeof (long)); + // phdroff = ALIGN_UP (grub_util_get_fp_size (out), sizeof (long)); grub_util_write_image_at (phdrs, grub_le_to_cpu16 (ehdr.e_phentsize) - * grub_le_to_cpu16 (ehdr.e_phnum), phdroff, + * (grub_le_to_cpu16 (ehdr.e_phnum)), phdroff, out); /* Write ELF header. */ --AhhlLboLdkugWU4S--