[PATCH] ELF program header

2007-10-12 Thread Robert Millan

It seems that grub-mkimage generates awkward ELF files, in which the Program
header table is at the end of the file instead of right after the ELF header.

I know very little about ELF, but:

  - This figure in ELF standard seems to indicate which is the normal (not
  sure if mandatory) location:

http://www.cs.ucdavis.edu/~haungs/paper/node11.html

  - Our own ELF loader doesn't like phdroff  0x2000 either, from
loader/i386/pc/multiboot.c:

  /* FIXME: Should we support program headers at strange locations?  */
  if (ehdr-e_phoff + ehdr-e_phnum * ehdr-e_phentsize  MULTIBOOT_SEARCH)
return grub_error (GRUB_ERR_BAD_OS, program header at a too high offset);

This breaks self-boot in the LinuxBIOS target.  Moving the Program header
(see attached patch) fixed it, with no apparent drawbacks or regressions in
any of the ELF loaders around (tested on LinuxBIOS ELF loader and Efika OF).

I'm not completely sure of its correctness though, and would appreciate if
someone with a better understanding of ELF can comment on it.  In particular,
I don't know if my proposed solution could overwrite valid data.  Are the
segments garanteed to always leave room for the program header, do we
have to explicitly check for that, or perhaps we need to relocate the segments
when needed?

-- 
Robert Millan

GPLv2 I know my rights; I want my phone call!
DRM What use is a phone call, if you are unable to speak?
(as seen on /.)
2007-10-12  Robert Millan  [EMAIL PROTECTED]

	* util/elf/grub-mkimage.c (add_segments): Allocate Program header
	table right after ELF header.

diff -ur grub2/util/elf/grub-mkimage.c grub2.phdr/util/elf/grub-mkimage.c
--- grub2/util/elf/grub-mkimage.c	2007-10-12 12:22:27.0 +0200
+++ grub2.phdr/util/elf/grub-mkimage.c	2007-10-12 12:36:38.0 +0200
@@ -250,7 +250,7 @@
   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 (sizeof (ehdr), sizeof (long));
   grub_util_write_image_at (phdrs, grub_target_to_host16 (ehdr.e_phentsize)
 			* grub_target_to_host16 (ehdr.e_phnum), phdroff,
 			out);
___
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] Fixed ieee1275 console

2007-10-12 Thread Marcin Kurek
Hell[o]

 Right, this is because it seems that the MSB is lost when writing a
 character to the screen.  For the borders specific characters are used
 above 127 (non-ASCII).  I wonder if the Pegasos console supports this
 ASCII extension if you change some settings or so...

The problem is in framebuffer mode OF loads glyphs starting from 32 to
127 then any characters abowe 127 are displayed as white '?'. The
solution would be to use set-font to load a proper font to use with
grub. In non framebuffer mode cp437 is used by console then we can use
it to draw borders same as for PC.


 I prefer if it can be detected if this is Efika or for example an
 apple implementation of OF and handle these characters depending on
 that.  IIRC this code does work on the apple, but unfortunately I
 cannot check this anymore.

Ahhh, I see you looked at first version of patch. Please take a look
at recent version of my patches.

  Handle 127 keycode as backspace key in grub_ofconsole_readkey() which fix
 [1]

 Can you explain this?

For some reasons my OF sends \b  127 (Del) sequence for backspace
key. It seems to be same sa ncurses console.

-- 
--- Marcin 'Morgoth' Kurek ---


___
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] generic ELF version of grub-mkimage

2007-10-12 Thread Marco Gerards
Robert Millan [EMAIL PROTECTED] writes:

 Woops.  I've been pointed out that cross-compiles were actually working and
 should be preserved.  I propose this new patch which integrates endianess
 conversion macros with include/grub/types.h.

 -- 
 Robert Millan

 GPLv2 I know my rights; I want my phone call!
 DRM What use is a phone call, if you are unable to speak?
 (as seen on /.)

 2007-10-12  Robert Millan  [EMAIL PROTECTED]

   * conf/powerpc-ieee1275.rmk (grub_mkimage_SOURCES): Replace reference
   to util/powerpc/ieee1275/grub-mkimage.c with util/elf/grub-mkimage.c.

   * include/grub/types.h (#ifdef GRUB_CPU_WORDS_BIGENDIAN): Define
   grub_host_to_target16, grub_host_to_target32, grub_host_to_target64,
   grub_target_to_host16, grub_target_to_host32 and grub_target_to_host64.
   (#else): Likewise.

This syntax is wrong.  It should have been something like:

   * include/grub/types.h (#ifdef GRUB_CPU_WORDS_BIGENDIAN): Define
   grub_host_to_target16, grub_host_to_target32, grub_host_to_target64,
   grub_target_to_host16, grub_target_to_host32 and grub_target_to_host64.
   (#else): Likewise.

* include/grub/types.h (grub_host_to_target16): New macro.
(grub_host_to_target32): Likewise.

etc...

If you are not sure, better wait a few days before committing a
patch.  Or ask me to double check it.

   * include/grub/powerpc/ieee1275/kernel.h (GRUB_IEEE1275_MOD_ALIGN):
   Renamed from to ...
   (GRUB_MOD_ALIGN): ...this.  Update all users.

   * util/elf/grub-mkimage.c: Replace grub_cpu_to_be16, grub_cpu_to_be32,
   grub_be_to_cpu16 and grub_be_to_cpu32 macros with grub_host_to_target16,
   grub_host_to_target32, grub_target_to_host16 and grub_target_to_host32,
   respectively.

You know quite well that this is wrong.  You have to mention which
function you changed.  

If you use diff -up this is easy to see from the patch.

--
Marco



___
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] generic ELF version of grub-mkimage

2007-10-12 Thread Robert Millan
On Fri, Oct 12, 2007 at 05:55:03PM +0200, Robert Millan wrote:
 
 Ok.  But no, I didn't really notice.  I'll fix this entry and keep trying to
 get it right next time.

Does this look good?

-- 
Robert Millan

GPLv2 I know my rights; I want my phone call!
DRM What use is a phone call, if you are unable to speak?
(as seen on /.)
--- grub2/ChangeLog	2007-10-12 12:22:27.0 +0200
+++ ChangeLog	2007-10-12 18:06:51.0 +0200
@@ -3,19 +3,25 @@
 	* conf/powerpc-ieee1275.rmk (grub_mkimage_SOURCES): Replace reference
 	to util/powerpc/ieee1275/grub-mkimage.c with util/elf/grub-mkimage.c.
 
-	* include/grub/types.h (#ifdef GRUB_CPU_WORDS_BIGENDIAN): Define
-	grub_host_to_target16, grub_host_to_target32, grub_host_to_target64,
-	grub_target_to_host16, grub_target_to_host32 and grub_target_to_host64.
-	(#else): Likewise.
+	* include/grub/types.h (grub_host_to_target16): New macro.
+	(grub_host_to_target32): Likewise.
+	(grub_host_to_target64): Likewise.
+	(grub_target_to_host16): Likewise.
+	(grub_target_to_host32): Likewise.
+	(grub_target_to_host64): Likewise.
 
 	* include/grub/powerpc/ieee1275/kernel.h (GRUB_IEEE1275_MOD_ALIGN):
 	Renamed from to ...
 	(GRUB_MOD_ALIGN): ...this.  Update all users.
 
-	* util/elf/grub-mkimage.c: Replace grub_cpu_to_be16, grub_cpu_to_be32,
-	grub_be_to_cpu16 and grub_be_to_cpu32 macros with grub_host_to_target16,
-	grub_host_to_target32, grub_target_to_host16 and grub_target_to_host32,
-	respectively.
+	* util/elf/grub-mkimage.c (load_note): Replace grub_cpu_to_be32 with
+	grub_host_to_target32.
+	Replace grub_be_to_cpu32 with grub_target_to_host32.
+	(load_modules): Likewise.
+	(add_segments): Replace grub_be_to_cpu16 with grub_target_to_host16.
+	Replace grub_be_to_cpu32 with grub_target_to_host32.
+	Replace grub_cpu_to_be16 with grub_host_to_target16.
+	Replace grub_cpu_to_be32 grub_host_to_target32.
 
 2007-10-12  Robert Millan  [EMAIL PROTECTED]
 
___
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] ELF program header

2007-10-12 Thread Stefan Reinauer
* Robert Millan [EMAIL PROTECTED] [071012 18:19]:
 It seems that grub-mkimage generates awkward ELF files, in which the Program
 header table is at the end of the file instead of right after the ELF header.
 
 
   - Our own ELF loader doesn't like phdroff  0x2000 either, from
 loader/i386/pc/multiboot.c:

I think such a fixed address makes little sense, however there are
reasons to put the phdr in front.

   /* FIXME: Should we support program headers at strange locations?  */
   if (ehdr-e_phoff + ehdr-e_phnum * ehdr-e_phentsize  MULTIBOOT_SEARCH)
 return grub_error (GRUB_ERR_BAD_OS, program header at a too high 
 offset);
 
 This breaks self-boot in the LinuxBIOS target.  Moving the Program header
 (see attached patch) fixed it, with no apparent drawbacks or regressions in
 any of the ELF loaders around (tested on LinuxBIOS ELF loader and Efika OF).

I assume this was with LinuxBIOSv3 and Qemu?

 I'm not completely sure of its correctness though, and would appreciate if
 someone with a better understanding of ELF can comment on it.  

There's one good reason to put ELF headers in the beginning, that is
streaming of ELF files. If you get your ELF from a streaming
decompression algorithm you have to 
- either copy your elf to memory completely before loading it a second
  time
- or decompress it twice
- or you put the phdr in the beginning :-)

 I don't know if my proposed solution could overwrite valid data.  Are the
 segments garanteed to always leave room for the program header, do we
 have to explicitly check for that, or perhaps we need to relocate the segments
 when needed?

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. I didn't really get the sense behind the layers of grub
magic around read() and write(). Looking at the code, it looks
completely wrong, but it surprisingly seemed to work in LBv3.

/* 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_target_to_host16 (ehdr.e_phentsize)
   * grub_target_to_host16 (ehdr.e_phnum), phdroff,
   out);

Stefan

-- 
coresystems GmbH • Brahmsstr. 16 • D-79104 Freiburg i. Br.
  Tel.: +49 761 7668825 • Fax: +49 761 7664613
Email: [EMAIL PROTECTED]  • http://www.coresystems.de/


___
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel