* [PATCH] generic ELF version of grub-mkimage
@ 2007-08-30 10:03 Patrick Georgi
2007-10-01 14:53 ` Robert Millan
0 siblings, 1 reply; 10+ messages in thread
From: Patrick Georgi @ 2007-08-30 10:03 UTC (permalink / raw)
To: grub-devel
[-- Attachment #1: Type: text/plain, Size: 1047 bytes --]
Hi,
the attached patch makes powerpc-ieee1275's grub-mkimage work with
little endian ELF images, too.
I did this, as I need basically the same functionality for
i386-linuxbios, just with little endian ELFs. I first copied and changed
the file for my needs, but it might be more generally useful (other
architectures), and having to maintain two very similar files seems like
a waste of time to me - hence the merged version.
I also moved the file to util/elf, to denote that it's a generic ELF
mangler now and adapted the powerpc makefile.
Description of changes:
1.
Detect endianess of the kernel (and check it's actually an ELF file)
2.
Configure a set of function pointers appropriately. This also required
me to wrap the grub_cpu_to_be* (and reverse) functions as those are macros.
3.
Replace all grub_cpu_to_be* and grub_be_to_cpu* calls with calls to the
function pointers.
4.
Undefine the old macros in this file as a debugging aid (there should be
any need for them)
Comments are very appreciated.
Regards,
Patrick Georgi
[-- Attachment #2: patch-20070830-1-portable-elf-grub-mkimage --]
[-- Type: text/plain, Size: 11229 bytes --]
#
#
# rename "util/powerpc/ieee1275/grub-mkimage.c"
# to "util/elf/grub-mkimage.c"
#
# add_dir "util/elf"
#
# patch "conf/powerpc-ieee1275.rmk"
# from [dd6aa1b34a30806ec5739e36ac0c8dd9c3f90cd4]
# to [e41cc58b76b3d62bef76cee905e953629024f753]
#
# patch "util/elf/grub-mkimage.c"
# from [0d5043da1774f2f00e4eb10823f82623735d8976]
# to [f36bb74ba54243e417c618d4294d23f8761afd57]
#
============================================================
--- conf/powerpc-ieee1275.rmk dd6aa1b34a30806ec5739e36ac0c8dd9c3f90cd4
+++ conf/powerpc-ieee1275.rmk e41cc58b76b3d62bef76cee905e953629024f753
@@ -32,7 +32,7 @@ endif
endif
# For grub-mkimage.
-grub_mkimage_SOURCES = util/powerpc/ieee1275/grub-mkimage.c util/misc.c \
+grub_mkimage_SOURCES = util/elf/grub-mkimage.c util/misc.c \
util/resolve.c
# For grub-mkdevicemap.
============================================================
--- util/powerpc/ieee1275/grub-mkimage.c 0d5043da1774f2f00e4eb10823f82623735d8976
+++ util/elf/grub-mkimage.c f36bb74ba54243e417c618d4294d23f8761afd57
@@ -62,6 +62,35 @@ struct grub_ieee1275_note
struct grub_ieee1275_note_desc descriptor;
};
+#define wrapmacro(name, len) \
+ static grub_uint ## len ## _t \
+ name ## len (grub_uint ## len ## _t x) \
+ { return grub_ ## name ## len (x); }
+
+wrapmacro(le_to_cpu, 32)
+wrapmacro(cpu_to_le, 32)
+wrapmacro(le_to_cpu, 16)
+wrapmacro(cpu_to_le, 16)
+wrapmacro(be_to_cpu, 32)
+wrapmacro(cpu_to_be, 32)
+wrapmacro(be_to_cpu, 16)
+wrapmacro(cpu_to_be, 16)
+
+/* those macros should not be used after this. use cpu_to_file32 etc instead */
+#undef grub_cpu_to_le16
+#undef grub_cpu_to_le32
+#undef grub_cpu_to_be16
+#undef grub_cpu_to_be32
+#undef grub_le_to_cpu16
+#undef grub_le_to_cpu32
+#undef grub_be_to_cpu16
+#undef grub_be_to_cpu32
+
+grub_uint32_t (*file_to_cpu32)(grub_uint32_t) = 0;
+grub_uint16_t (*file_to_cpu16)(grub_uint16_t) = 0;
+grub_uint32_t (*cpu_to_file32)(grub_uint32_t) = 0;
+grub_uint16_t (*cpu_to_file16)(grub_uint16_t) = 0;
+
void
load_note (Elf32_Phdr *phdr, FILE *out)
{
@@ -70,28 +99,28 @@ load_note (Elf32_Phdr *phdr, FILE *out)
grub_util_info ("adding CHRP NOTE segment");
- 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);
+ note.header.namesz = cpu_to_file32 (sizeof (GRUB_IEEE1275_NOTE_NAME));
+ note.header.descsz = cpu_to_file32 (note_size);
+ note.header.type = cpu_to_file32 (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);
+ note.descriptor.real_mode = cpu_to_file32 (0xffffffff);
+ note.descriptor.real_base = cpu_to_file32 (0x00c00000);
+ note.descriptor.real_size = cpu_to_file32 (0xffffffff);
+ note.descriptor.virt_base = cpu_to_file32 (0xffffffff);
+ note.descriptor.virt_size = cpu_to_file32 (0xffffffff);
+ note.descriptor.load_base = cpu_to_file32 (0x00004000);
/* Write the note data to the new segment. */
grub_util_write_image_at (¬e, note_size,
- grub_be_to_cpu32 (phdr->p_offset), out);
+ file_to_cpu32 (phdr->p_offset), out);
/* Fill in the rest of the segment header. */
- phdr->p_type = grub_cpu_to_be32 (PT_NOTE);
- phdr->p_flags = grub_cpu_to_be32 (PF_R);
- phdr->p_align = grub_cpu_to_be32 (sizeof (long));
+ phdr->p_type = cpu_to_file32 (PT_NOTE);
+ phdr->p_flags = cpu_to_file32 (PF_R);
+ phdr->p_align = cpu_to_file32 (sizeof (long));
phdr->p_vaddr = 0;
phdr->p_paddr = 0;
- phdr->p_filesz = grub_cpu_to_be32 (note_size);
+ phdr->p_filesz = cpu_to_file32 (note_size);
phdr->p_memsz = 0;
}
@@ -120,9 +149,9 @@ load_modules (grub_addr_t modbase, Elf32
module_img = xmalloc (total_module_size);
modinfo = (struct grub_module_info *) module_img;
- modinfo->magic = grub_cpu_to_be32 (GRUB_MODULE_MAGIC);
- modinfo->offset = grub_cpu_to_be32 (sizeof (struct grub_module_info));
- modinfo->size = grub_cpu_to_be32 (total_module_size);
+ modinfo->magic = cpu_to_file32 (GRUB_MODULE_MAGIC);
+ modinfo->offset = cpu_to_file32 (sizeof (struct grub_module_info));
+ modinfo->size = cpu_to_file32 (total_module_size);
/* Load all the modules, with headers, into module_img. */
for (p = path_list; p; p = p->next)
@@ -135,8 +164,8 @@ load_modules (grub_addr_t modbase, Elf32
mod_size = grub_util_get_image_size (p->name);
header = (struct grub_module_header *) (module_img + offset);
- header->offset = grub_cpu_to_be32 (sizeof (*header));
- header->size = grub_cpu_to_be32 (mod_size + sizeof (*header));
+ header->offset = cpu_to_file32 (sizeof (*header));
+ header->size = cpu_to_file32 (mod_size + sizeof (*header));
grub_util_load_image (p->name, module_img + offset + sizeof (*header));
@@ -145,16 +174,16 @@ load_modules (grub_addr_t modbase, Elf32
/* Write the module data to the new segment. */
grub_util_write_image_at (module_img, total_module_size,
- grub_cpu_to_be32 (phdr->p_offset), out);
+ cpu_to_file32 (phdr->p_offset), out);
/* Fill in the rest of the segment header. */
- phdr->p_type = grub_cpu_to_be32 (PT_LOAD);
- phdr->p_flags = grub_cpu_to_be32 (PF_R | PF_W | PF_X);
- phdr->p_align = grub_cpu_to_be32 (sizeof (long));
- phdr->p_vaddr = grub_cpu_to_be32 (modbase);
- phdr->p_paddr = grub_cpu_to_be32 (modbase);
- phdr->p_filesz = grub_cpu_to_be32 (total_module_size);
- phdr->p_memsz = grub_cpu_to_be32 (total_module_size);
+ phdr->p_type = cpu_to_file32 (PT_LOAD);
+ phdr->p_flags = cpu_to_file32 (PF_R | PF_W | PF_X);
+ phdr->p_align = cpu_to_file32 (0x1000);
+ phdr->p_vaddr = cpu_to_file32 (modbase);
+ phdr->p_paddr = cpu_to_file32 (modbase);
+ phdr->p_filesz = cpu_to_file32 (total_module_size);
+ phdr->p_memsz = cpu_to_file32 (total_module_size);
}
void
@@ -176,11 +205,31 @@ add_segments (char *dir, FILE *out, int
grub_util_error ("cannot open %s", kernel_path);
grub_util_read_at (&ehdr, sizeof (ehdr), 0, in);
-
- phdrs = xmalloc (grub_be_to_cpu16 (ehdr.e_phentsize)
- * (grub_be_to_cpu16 (ehdr.e_phnum) + 2));
+ if ((ehdr.e_ident[EI_MAG0]!=ELFMAG0) ||
+ (ehdr.e_ident[EI_MAG1]!=ELFMAG1) ||
+ (ehdr.e_ident[EI_MAG2]!=ELFMAG2) ||
+ (ehdr.e_ident[EI_MAG3]!=ELFMAG3)) {
+ grub_util_error("%s is not an ELF image", kernel_path);
+ }
+
+ if (ehdr.e_ident[EI_DATA]==ELFDATA2LSB) {
+ file_to_cpu16 = le_to_cpu16;
+ file_to_cpu32 = le_to_cpu32;
+ cpu_to_file16 = cpu_to_le16;
+ cpu_to_file32 = cpu_to_le32;
+ } else if (ehdr.e_ident[EI_DATA]==ELFDATA2MSB) {
+ file_to_cpu16 = be_to_cpu16;
+ file_to_cpu32 = be_to_cpu32;
+ cpu_to_file16 = cpu_to_be16;
+ cpu_to_file32 = cpu_to_be32;
+ } else {
+ grub_util_error("Unknown file encoding");
+ }
+
+ phdrs = xmalloc (file_to_cpu16 (ehdr.e_phentsize)
+ * (file_to_cpu16 (ehdr.e_phnum) + 2));
/* Copy all existing segments. */
- for (i = 0; i < grub_be_to_cpu16 (ehdr.e_phnum); i++)
+ for (i = 0; i < file_to_cpu16 (ehdr.e_phnum); i++)
{
char *segment_img;
grub_size_t segment_end;
@@ -189,26 +238,26 @@ add_segments (char *dir, FILE *out, int
/* Read segment header. */
grub_util_read_at (phdr, sizeof (Elf32_Phdr),
- (grub_be_to_cpu32 (ehdr.e_phoff)
- + (i * grub_be_to_cpu16 (ehdr.e_phentsize))),
+ (file_to_cpu32 (ehdr.e_phoff)
+ + (i * file_to_cpu16 (ehdr.e_phentsize))),
in);
grub_util_info ("copying segment %d, type %d", i,
- grub_be_to_cpu32 (phdr->p_type));
+ file_to_cpu32 (phdr->p_type));
/* Locate _end. */
- segment_end = grub_be_to_cpu32 (phdr->p_paddr)
- + grub_be_to_cpu32 (phdr->p_memsz);
+ segment_end = file_to_cpu32 (phdr->p_paddr)
+ + file_to_cpu32 (phdr->p_memsz);
grub_util_info ("segment %u end 0x%lx", i, segment_end);
if (segment_end > grub_end)
grub_end = segment_end;
/* Read segment data and write it to new file. */
- segment_img = xmalloc (grub_be_to_cpu32 (phdr->p_filesz));
+ segment_img = xmalloc (file_to_cpu32 (phdr->p_filesz));
- grub_util_read_at (segment_img, grub_be_to_cpu32 (phdr->p_filesz),
- grub_be_to_cpu32 (phdr->p_offset), in);
- grub_util_write_image_at (segment_img, grub_be_to_cpu32 (phdr->p_filesz),
- grub_be_to_cpu32 (phdr->p_offset), out);
+ grub_util_read_at (segment_img, file_to_cpu32 (phdr->p_filesz),
+ file_to_cpu32 (phdr->p_offset), in);
+ grub_util_write_image_at (segment_img, file_to_cpu32 (phdr->p_filesz),
+ file_to_cpu32 (phdr->p_offset), out);
free (segment_img);
}
@@ -218,14 +267,14 @@ add_segments (char *dir, FILE *out, int
grub_addr_t modbase;
/* Place modules just after grub segment. */
- modbase = ALIGN_UP(grub_end, GRUB_IEEE1275_MOD_ALIGN);
+ modbase = ALIGN_UP(grub_end, GRUB_MOD_ALIGN);
/* Construct new segment header for modules. */
- phdr = phdrs + grub_be_to_cpu16 (ehdr.e_phnum);
- ehdr.e_phnum = grub_cpu_to_be16 (grub_be_to_cpu16 (ehdr.e_phnum) + 1);
+ phdr = phdrs + file_to_cpu16 (ehdr.e_phnum);
+ ehdr.e_phnum = cpu_to_file16 (file_to_cpu16 (ehdr.e_phnum) + 1);
/* Fill in p_offset so the callees know where to write. */
- phdr->p_offset = grub_cpu_to_be32 (ALIGN_UP (grub_util_get_fp_size (out),
+ phdr->p_offset = cpu_to_file32 (ALIGN_UP (grub_util_get_fp_size (out),
sizeof (long)));
load_modules (modbase, phdr, dir, mods, out);
@@ -234,11 +283,11 @@ add_segments (char *dir, FILE *out, int
if (chrp)
{
/* Construct new segment header for the CHRP note. */
- phdr = phdrs + grub_be_to_cpu16 (ehdr.e_phnum);
- ehdr.e_phnum = grub_cpu_to_be16 (grub_be_to_cpu16 (ehdr.e_phnum) + 1);
+ phdr = phdrs + file_to_cpu16 (ehdr.e_phnum);
+ ehdr.e_phnum = cpu_to_file16 (file_to_cpu16 (ehdr.e_phnum) + 1);
/* Fill in p_offset so the callees know where to write. */
- phdr->p_offset = grub_cpu_to_be32 (ALIGN_UP (grub_util_get_fp_size (out),
+ phdr->p_offset = cpu_to_file32 (ALIGN_UP (grub_util_get_fp_size (out),
sizeof (long)));
load_note (phdr, out);
@@ -251,12 +300,12 @@ add_segments (char *dir, FILE *out, int
/* Append entire segment table to the file. */
phdroff = ALIGN_UP (grub_util_get_fp_size (out), sizeof (long));
- grub_util_write_image_at (phdrs, grub_be_to_cpu16 (ehdr.e_phentsize)
- * grub_be_to_cpu16 (ehdr.e_phnum), phdroff,
+ grub_util_write_image_at (phdrs, file_to_cpu16 (ehdr.e_phentsize)
+ * file_to_cpu16 (ehdr.e_phnum), phdroff,
out);
/* Write ELF header. */
- ehdr.e_phoff = grub_cpu_to_be32 (phdroff);
+ ehdr.e_phoff = cpu_to_file32 (phdroff);
grub_util_write_image_at (&ehdr, sizeof (ehdr), 0, out);
free (phdrs);
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] generic ELF version of grub-mkimage
2007-08-30 10:03 [PATCH] generic ELF version of grub-mkimage Patrick Georgi
@ 2007-10-01 14:53 ` Robert Millan
2007-10-11 22:58 ` Robert Millan
0 siblings, 1 reply; 10+ messages in thread
From: Robert Millan @ 2007-10-01 14:53 UTC (permalink / raw)
To: The development of GRUB 2; +Cc: Patrick Georgi
[-- Attachment #1: Type: text/plain, Size: 1803 bytes --]
Hi!
On Thu, Aug 30, 2007 at 12:03:47PM +0200, Patrick Georgi wrote:
> Hi,
>
> the attached patch makes powerpc-ieee1275's grub-mkimage work with
> little endian ELF images, too.
> I did this, as I need basically the same functionality for
> i386-linuxbios, just with little endian ELFs. I first copied and changed
> the file for my needs, but it might be more generally useful (other
> architectures), and having to maintain two very similar files seems like
> a waste of time to me - hence the merged version.
> I also moved the file to util/elf, to denote that it's a generic ELF
> mangler now and adapted the powerpc makefile.
I think the endianess checks are overkill. AFAICT grub-mkimage isn't really
meant for non-native use (as exemplified by the fact that it's not called
grub-mkelfimage vs grub-mkaoutimage).
I propose the following:
2007-10-01 Robert Millan <rmh@aybabtu.com>
* conf/powerpc-ieee1275.rmk (grub_mkimage_SOURCES): Replace reference
to util/powerpc/ieee1275/grub-mkimage.c with util/elf/grub-mkimage.c.
* include/grub/powerpc/ieee1275/kernel.h: Rename
GRUB_IEEE1275_MOD_ALIGN to GRUB_MOD_ALIGN.
* kern/powerpc/ieee1275/init.c: Replace GRUB_IEEE1275_MOD_ALIGN with
GRUB_MOD_ALIGN.
* util/elf/grub-mkimage.c: Replace GRUB_IEEE1275_MOD_ALIGN with
GRUB_MOD_ALIGN. Remove all use of endian conversion macros, since
they break LE platforms and grub-mkimage is only meant for native
use anyway.
2007-10-01 Robert Millan <rmh@aybabtu.com>
* util/powerpc/ieee1275/grub-mkimage.c: Moved to ...
* util/elf/grub-mkimage.c: ... here.
The attached patch has been tested on Qemu/LinuxBIOS and on my Efika
(powerpc).
--
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 /.)
[-- Attachment #2: mkimage.diff --]
[-- Type: text/x-diff, Size: 10207 bytes --]
2007-10-01 Robert Millan <rmh@aybabtu.com>
* conf/powerpc-ieee1275.rmk (grub_mkimage_SOURCES): Replace reference
to util/powerpc/ieee1275/grub-mkimage.c with util/elf/grub-mkimage.c.
* include/grub/powerpc/ieee1275/kernel.h: Rename
GRUB_IEEE1275_MOD_ALIGN to GRUB_MOD_ALIGN.
* kern/powerpc/ieee1275/init.c: Replace GRUB_IEEE1275_MOD_ALIGN with
GRUB_MOD_ALIGN.
* util/elf/grub-mkimage.c: Replace GRUB_IEEE1275_MOD_ALIGN with
GRUB_MOD_ALIGN. Remove all use of endian conversion macros, since
they break LE platforms and grub-mkimage is only meant for native
use anyway.
2007-10-01 Robert Millan <rmh@aybabtu.com>
* util/powerpc/ieee1275/grub-mkimage.c: Moved to ...
* util/elf/grub-mkimage.c: ... here.
Index: conf/powerpc-ieee1275.rmk
===================================================================
RCS file: /sources/grub/grub2/conf/powerpc-ieee1275.rmk,v
retrieving revision 1.71
diff -u -r1.71 powerpc-ieee1275.rmk
--- conf/powerpc-ieee1275.rmk 29 Aug 2007 10:39:42 -0000 1.71
+++ conf/powerpc-ieee1275.rmk 1 Oct 2007 14:38:31 -0000
@@ -32,7 +32,7 @@
endif
# For grub-mkimage.
-grub_mkimage_SOURCES = util/powerpc/ieee1275/grub-mkimage.c util/misc.c \
+grub_mkimage_SOURCES = util/elf/grub-mkimage.c util/misc.c \
util/resolve.c
# For grub-mkdevicemap.
Index: include/grub/powerpc/ieee1275/kernel.h
===================================================================
RCS file: /sources/grub/grub2/include/grub/powerpc/ieee1275/kernel.h,v
retrieving revision 1.6
diff -u -r1.6 kernel.h
--- include/grub/powerpc/ieee1275/kernel.h 21 Jul 2007 23:32:24 -0000 1.6
+++ include/grub/powerpc/ieee1275/kernel.h 1 Oct 2007 14:38:31 -0000
@@ -21,7 +21,7 @@
#include <grub/symbol.h>
-#define GRUB_IEEE1275_MOD_ALIGN 0x1000
+#define GRUB_MOD_ALIGN 0x1000
void EXPORT_FUNC (grub_reboot) (void);
void EXPORT_FUNC (grub_halt) (void);
Index: kern/powerpc/ieee1275/init.c
===================================================================
RCS file: /sources/grub/grub2/kern/powerpc/ieee1275/init.c,v
retrieving revision 1.31
diff -u -r1.31 init.c
--- kern/powerpc/ieee1275/init.c 21 Jul 2007 23:32:27 -0000 1.31
+++ kern/powerpc/ieee1275/init.c 1 Oct 2007 14:38:31 -0000
@@ -205,5 +205,5 @@
grub_addr_t
grub_arch_modules_addr (void)
{
- return ALIGN_UP(_end, GRUB_IEEE1275_MOD_ALIGN);
+ return ALIGN_UP(_end, GRUB_MOD_ALIGN);
}
Index: util/powerpc/ieee1275/grub-mkimage.c
===================================================================
RCS file: /sources/grub/grub2/util/powerpc/ieee1275/grub-mkimage.c,v
retrieving revision 1.9
diff -u -r1.9 grub-mkimage.c
--- util/powerpc/ieee1275/grub-mkimage.c 21 Jul 2007 23:32:32 -0000 1.9
+++ util/powerpc/ieee1275/grub-mkimage.c 1 Oct 2007 14:38:31 -0000
@@ -70,28 +70,27 @@
grub_util_info ("adding CHRP NOTE segment");
- 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);
+ note.header.namesz = sizeof (GRUB_IEEE1275_NOTE_NAME);
+ note.header.descsz = note_size;
+ note.header.type = 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);
+ note.descriptor.real_mode = 0xffffffff;
+ note.descriptor.real_base = 0x00c00000;
+ note.descriptor.real_size = 0xffffffff;
+ note.descriptor.virt_base = 0xffffffff;
+ note.descriptor.virt_size = 0xffffffff;
+ note.descriptor.load_base = 0x00004000;
/* Write the note data to the new segment. */
- grub_util_write_image_at (¬e, note_size,
- grub_be_to_cpu32 (phdr->p_offset), out);
+ grub_util_write_image_at (¬e, note_size, phdr->p_offset, out);
/* Fill in the rest of the segment header. */
- phdr->p_type = grub_cpu_to_be32 (PT_NOTE);
- phdr->p_flags = grub_cpu_to_be32 (PF_R);
- phdr->p_align = grub_cpu_to_be32 (sizeof (long));
+ phdr->p_type = PT_NOTE;
+ phdr->p_flags = PF_R;
+ phdr->p_align = sizeof (long);
phdr->p_vaddr = 0;
phdr->p_paddr = 0;
- phdr->p_filesz = grub_cpu_to_be32 (note_size);
+ phdr->p_filesz = note_size;
phdr->p_memsz = 0;
}
@@ -120,9 +119,9 @@
module_img = xmalloc (total_module_size);
modinfo = (struct grub_module_info *) module_img;
- modinfo->magic = grub_cpu_to_be32 (GRUB_MODULE_MAGIC);
- modinfo->offset = grub_cpu_to_be32 (sizeof (struct grub_module_info));
- modinfo->size = grub_cpu_to_be32 (total_module_size);
+ modinfo->magic = GRUB_MODULE_MAGIC;
+ modinfo->offset = sizeof (struct grub_module_info);
+ modinfo->size = total_module_size;
/* Load all the modules, with headers, into module_img. */
for (p = path_list; p; p = p->next)
@@ -135,8 +134,8 @@
mod_size = grub_util_get_image_size (p->name);
header = (struct grub_module_header *) (module_img + offset);
- header->offset = grub_cpu_to_be32 (sizeof (*header));
- header->size = grub_cpu_to_be32 (mod_size + sizeof (*header));
+ header->offset = sizeof (*header);
+ header->size = mod_size + sizeof (*header);
grub_util_load_image (p->name, module_img + offset + sizeof (*header));
@@ -144,17 +143,16 @@
}
/* Write the module data to the new segment. */
- grub_util_write_image_at (module_img, total_module_size,
- grub_cpu_to_be32 (phdr->p_offset), out);
+ grub_util_write_image_at (module_img, total_module_size, phdr->p_offset, out);
/* Fill in the rest of the segment header. */
- phdr->p_type = grub_cpu_to_be32 (PT_LOAD);
- phdr->p_flags = grub_cpu_to_be32 (PF_R | PF_W | PF_X);
- phdr->p_align = grub_cpu_to_be32 (sizeof (long));
- phdr->p_vaddr = grub_cpu_to_be32 (modbase);
- phdr->p_paddr = grub_cpu_to_be32 (modbase);
- phdr->p_filesz = grub_cpu_to_be32 (total_module_size);
- phdr->p_memsz = grub_cpu_to_be32 (total_module_size);
+ phdr->p_type = PT_LOAD;
+ phdr->p_flags = PF_R | PF_W | PF_X;
+ phdr->p_align = sizeof (long);
+ phdr->p_vaddr = modbase;
+ phdr->p_paddr = modbase;
+ phdr->p_filesz = total_module_size;
+ phdr->p_memsz = total_module_size;
}
void
@@ -177,10 +175,10 @@
grub_util_read_at (&ehdr, sizeof (ehdr), 0, in);
- phdrs = xmalloc (grub_be_to_cpu16 (ehdr.e_phentsize)
- * (grub_be_to_cpu16 (ehdr.e_phnum) + 2));
+ phdrs = xmalloc (ehdr.e_phentsize
+ * (ehdr.e_phnum + 2));
/* Copy all existing segments. */
- for (i = 0; i < grub_be_to_cpu16 (ehdr.e_phnum); i++)
+ for (i = 0; i < ehdr.e_phnum; i++)
{
char *segment_img;
grub_size_t segment_end;
@@ -189,26 +187,22 @@
/* Read segment header. */
grub_util_read_at (phdr, sizeof (Elf32_Phdr),
- (grub_be_to_cpu32 (ehdr.e_phoff)
- + (i * grub_be_to_cpu16 (ehdr.e_phentsize))),
- in);
- grub_util_info ("copying segment %d, type %d", i,
- grub_be_to_cpu32 (phdr->p_type));
+ (ehdr.e_phoff + (i * ehdr.e_phentsize)), in);
+ grub_util_info ("copying segment %d, type %d", i, phdr->p_type);
/* Locate _end. */
- segment_end = grub_be_to_cpu32 (phdr->p_paddr)
- + grub_be_to_cpu32 (phdr->p_memsz);
+ segment_end = phdr->p_paddr
+ + phdr->p_memsz;
grub_util_info ("segment %u end 0x%lx", i, segment_end);
if (segment_end > grub_end)
grub_end = segment_end;
/* Read segment data and write it to new file. */
- segment_img = xmalloc (grub_be_to_cpu32 (phdr->p_filesz));
+ segment_img = xmalloc (phdr->p_filesz);
- grub_util_read_at (segment_img, grub_be_to_cpu32 (phdr->p_filesz),
- grub_be_to_cpu32 (phdr->p_offset), in);
- grub_util_write_image_at (segment_img, grub_be_to_cpu32 (phdr->p_filesz),
- grub_be_to_cpu32 (phdr->p_offset), out);
+ grub_util_read_at (segment_img, phdr->p_filesz, phdr->p_offset, in);
+ grub_util_write_image_at (segment_img, phdr->p_filesz,
+ phdr->p_offset, out);
free (segment_img);
}
@@ -218,15 +212,14 @@
grub_addr_t modbase;
/* Place modules just after grub segment. */
- modbase = ALIGN_UP(grub_end, GRUB_IEEE1275_MOD_ALIGN);
+ modbase = ALIGN_UP(grub_end, GRUB_MOD_ALIGN);
/* Construct new segment header for modules. */
- phdr = phdrs + grub_be_to_cpu16 (ehdr.e_phnum);
- ehdr.e_phnum = grub_cpu_to_be16 (grub_be_to_cpu16 (ehdr.e_phnum) + 1);
+ phdr = phdrs + ehdr.e_phnum;
+ ehdr.e_phnum = ehdr.e_phnum + 1;
/* Fill in p_offset so the callees know where to write. */
- phdr->p_offset = grub_cpu_to_be32 (ALIGN_UP (grub_util_get_fp_size (out),
- sizeof (long)));
+ phdr->p_offset = ALIGN_UP (grub_util_get_fp_size (out), sizeof (long));
load_modules (modbase, phdr, dir, mods, out);
}
@@ -234,12 +227,11 @@
if (chrp)
{
/* Construct new segment header for the CHRP note. */
- phdr = phdrs + grub_be_to_cpu16 (ehdr.e_phnum);
- ehdr.e_phnum = grub_cpu_to_be16 (grub_be_to_cpu16 (ehdr.e_phnum) + 1);
+ phdr = phdrs + ehdr.e_phnum;
+ ehdr.e_phnum = ehdr.e_phnum + 1;
/* Fill in p_offset so the callees know where to write. */
- phdr->p_offset = grub_cpu_to_be32 (ALIGN_UP (grub_util_get_fp_size (out),
- sizeof (long)));
+ phdr->p_offset = ALIGN_UP (grub_util_get_fp_size (out), sizeof (long));
load_note (phdr, out);
}
@@ -251,12 +243,11 @@
/* Append entire segment table to the file. */
phdroff = ALIGN_UP (grub_util_get_fp_size (out), sizeof (long));
- grub_util_write_image_at (phdrs, grub_be_to_cpu16 (ehdr.e_phentsize)
- * grub_be_to_cpu16 (ehdr.e_phnum), phdroff,
- out);
+ grub_util_write_image_at (phdrs, ehdr.e_phentsize *
+ ehdr.e_phnum, phdroff, out);
/* Write ELF header. */
- ehdr.e_phoff = grub_cpu_to_be32 (phdroff);
+ ehdr.e_phoff = phdroff;
grub_util_write_image_at (&ehdr, sizeof (ehdr), 0, out);
free (phdrs);
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] generic ELF version of grub-mkimage
2007-10-01 14:53 ` Robert Millan
@ 2007-10-11 22:58 ` Robert Millan
2007-10-12 10:52 ` Marco Gerards
0 siblings, 1 reply; 10+ messages in thread
From: Robert Millan @ 2007-10-11 22:58 UTC (permalink / raw)
To: The development of GRUB 2
[-- Attachment #1: Type: text/plain, Size: 340 bytes --]
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 /.)
[-- Attachment #2: mkimage.diff --]
[-- Type: text/x-diff, Size: 13390 bytes --]
2007-10-12 Robert Millan <rmh@aybabtu.com>
* 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/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.
2007-10-12 Robert Millan <rmh@aybabtu.com>
* util/powerpc/ieee1275/grub-mkimage.c: Moved to ...
* util/elf/grub-mkimage.c: ... here.
diff -ur grub2/conf/powerpc-ieee1275.rmk grub2.mkimage/conf/powerpc-ieee1275.rmk
--- grub2/conf/powerpc-ieee1275.rmk 2007-10-02 23:34:47.000000000 +0200
+++ grub2.mkimage/conf/powerpc-ieee1275.rmk 2007-10-04 23:22:37.000000000 +0200
@@ -32,7 +32,7 @@
endif
# For grub-mkimage.
-grub_mkimage_SOURCES = util/powerpc/ieee1275/grub-mkimage.c util/misc.c \
+grub_mkimage_SOURCES = util/elf/grub-mkimage.c util/misc.c \
util/resolve.c
# For grub-mkdevicemap.
diff -ur grub2/include/grub/powerpc/ieee1275/kernel.h grub2.mkimage/include/grub/powerpc/ieee1275/kernel.h
--- grub2/include/grub/powerpc/ieee1275/kernel.h 2007-07-22 01:32:24.000000000 +0200
+++ grub2.mkimage/include/grub/powerpc/ieee1275/kernel.h 2007-10-04 23:22:37.000000000 +0200
@@ -21,7 +21,7 @@
#include <grub/symbol.h>
-#define GRUB_IEEE1275_MOD_ALIGN 0x1000
+#define GRUB_MOD_ALIGN 0x1000
void EXPORT_FUNC (grub_reboot) (void);
void EXPORT_FUNC (grub_halt) (void);
diff -ur grub2/include/grub/types.h grub2.mkimage/include/grub/types.h
--- grub2/include/grub/types.h 2007-07-22 01:32:22.000000000 +0200
+++ grub2.mkimage/include/grub/types.h 2007-10-04 23:17:49.000000000 +0200
@@ -140,6 +140,21 @@
# define grub_be_to_cpu16(x) ((grub_uint16_t) (x))
# define grub_be_to_cpu32(x) ((grub_uint32_t) (x))
# define grub_be_to_cpu64(x) ((grub_uint64_t) (x))
+# ifdef GRUB_TARGET_WORDS_BIGENDIAN
+# define grub_target_to_host16(x) ((grub_uint16_t) (x))
+# define grub_target_to_host32(x) ((grub_uint32_t) (x))
+# define grub_target_to_host64(x) ((grub_uint64_t) (x))
+# define grub_host_to_target16(x) ((grub_uint16_t) (x))
+# define grub_host_to_target32(x) ((grub_uint32_t) (x))
+# define grub_host_to_target64(x) ((grub_uint64_t) (x))
+# else /* ! GRUB_TARGET_WORDS_BIGENDIAN */
+# define grub_target_to_host16(x) grub_swap_bytes16(x)
+# define grub_target_to_host32(x) grub_swap_bytes32(x)
+# define grub_target_to_host64(x) grub_swap_bytes64(x)
+# define grub_host_to_target16(x) grub_swap_bytes16(x)
+# define grub_host_to_target32(x) grub_swap_bytes32(x)
+# define grub_host_to_target64(x) grub_swap_bytes64(x)
+# endif
#else /* ! WORDS_BIGENDIAN */
# define grub_cpu_to_le16(x) ((grub_uint16_t) (x))
# define grub_cpu_to_le32(x) ((grub_uint32_t) (x))
@@ -153,6 +168,21 @@
# define grub_be_to_cpu16(x) grub_swap_bytes16(x)
# define grub_be_to_cpu32(x) grub_swap_bytes32(x)
# define grub_be_to_cpu64(x) grub_swap_bytes64(x)
+# ifdef GRUB_TARGET_WORDS_BIGENDIAN
+# define grub_target_to_host16(x) grub_swap_bytes16(x)
+# define grub_target_to_host32(x) grub_swap_bytes32(x)
+# define grub_target_to_host64(x) grub_swap_bytes64(x)
+# define grub_host_to_target16(x) grub_swap_bytes16(x)
+# define grub_host_to_target32(x) grub_swap_bytes32(x)
+# define grub_host_to_target64(x) grub_swap_bytes64(x)
+# else /* ! GRUB_TARGET_WORDS_BIGENDIAN */
+# define grub_target_to_host16(x) ((grub_uint16_t) (x))
+# define grub_target_to_host32(x) ((grub_uint32_t) (x))
+# define grub_target_to_host64(x) ((grub_uint64_t) (x))
+# define grub_host_to_target16(x) ((grub_uint16_t) (x))
+# define grub_host_to_target32(x) ((grub_uint32_t) (x))
+# define grub_host_to_target64(x) ((grub_uint64_t) (x))
+# endif
#endif /* ! WORDS_BIGENDIAN */
#endif /* ! GRUB_TYPES_HEADER */
diff -ur grub2/kern/powerpc/ieee1275/init.c grub2.mkimage/kern/powerpc/ieee1275/init.c
--- grub2/kern/powerpc/ieee1275/init.c 2007-07-22 01:32:27.000000000 +0200
+++ grub2.mkimage/kern/powerpc/ieee1275/init.c 2007-10-04 23:22:37.000000000 +0200
@@ -205,5 +205,5 @@
grub_addr_t
grub_arch_modules_addr (void)
{
- return ALIGN_UP(_end, GRUB_IEEE1275_MOD_ALIGN);
+ return ALIGN_UP(_end, GRUB_MOD_ALIGN);
}
diff -ur grub2/util/powerpc/ieee1275/grub-mkimage.c grub2.mkimage/util/powerpc/ieee1275/grub-mkimage.c
--- grub2/util/powerpc/ieee1275/grub-mkimage.c 2007-07-22 01:32:32.000000000 +0200
+++ grub2.mkimage/util/powerpc/ieee1275/grub-mkimage.c 2007-10-04 23:23:16.000000000 +0200
@@ -70,28 +70,28 @@
grub_util_info ("adding CHRP NOTE segment");
- 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);
+ note.header.namesz = grub_host_to_target32 (sizeof (GRUB_IEEE1275_NOTE_NAME));
+ note.header.descsz = grub_host_to_target32 (note_size);
+ note.header.type = grub_host_to_target32 (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);
+ note.descriptor.real_mode = grub_host_to_target32 (0xffffffff);
+ note.descriptor.real_base = grub_host_to_target32 (0x00c00000);
+ note.descriptor.real_size = grub_host_to_target32 (0xffffffff);
+ note.descriptor.virt_base = grub_host_to_target32 (0xffffffff);
+ note.descriptor.virt_size = grub_host_to_target32 (0xffffffff);
+ note.descriptor.load_base = grub_host_to_target32 (0x00004000);
/* Write the note data to the new segment. */
grub_util_write_image_at (¬e, note_size,
- grub_be_to_cpu32 (phdr->p_offset), out);
+ grub_target_to_host32 (phdr->p_offset), out);
/* Fill in the rest of the segment header. */
- phdr->p_type = grub_cpu_to_be32 (PT_NOTE);
- phdr->p_flags = grub_cpu_to_be32 (PF_R);
- phdr->p_align = grub_cpu_to_be32 (sizeof (long));
+ phdr->p_type = grub_host_to_target32 (PT_NOTE);
+ phdr->p_flags = grub_host_to_target32 (PF_R);
+ phdr->p_align = grub_host_to_target32 (sizeof (long));
phdr->p_vaddr = 0;
phdr->p_paddr = 0;
- phdr->p_filesz = grub_cpu_to_be32 (note_size);
+ phdr->p_filesz = grub_host_to_target32 (note_size);
phdr->p_memsz = 0;
}
@@ -120,9 +120,9 @@
module_img = xmalloc (total_module_size);
modinfo = (struct grub_module_info *) module_img;
- modinfo->magic = grub_cpu_to_be32 (GRUB_MODULE_MAGIC);
- modinfo->offset = grub_cpu_to_be32 (sizeof (struct grub_module_info));
- modinfo->size = grub_cpu_to_be32 (total_module_size);
+ modinfo->magic = grub_host_to_target32 (GRUB_MODULE_MAGIC);
+ modinfo->offset = grub_host_to_target32 (sizeof (struct grub_module_info));
+ modinfo->size = grub_host_to_target32 (total_module_size);
/* Load all the modules, with headers, into module_img. */
for (p = path_list; p; p = p->next)
@@ -135,8 +135,8 @@
mod_size = grub_util_get_image_size (p->name);
header = (struct grub_module_header *) (module_img + offset);
- header->offset = grub_cpu_to_be32 (sizeof (*header));
- header->size = grub_cpu_to_be32 (mod_size + sizeof (*header));
+ header->offset = grub_host_to_target32 (sizeof (*header));
+ header->size = grub_host_to_target32 (mod_size + sizeof (*header));
grub_util_load_image (p->name, module_img + offset + sizeof (*header));
@@ -145,16 +145,16 @@
/* Write the module data to the new segment. */
grub_util_write_image_at (module_img, total_module_size,
- grub_cpu_to_be32 (phdr->p_offset), out);
+ grub_host_to_target32 (phdr->p_offset), out);
/* Fill in the rest of the segment header. */
- phdr->p_type = grub_cpu_to_be32 (PT_LOAD);
- phdr->p_flags = grub_cpu_to_be32 (PF_R | PF_W | PF_X);
- phdr->p_align = grub_cpu_to_be32 (sizeof (long));
- phdr->p_vaddr = grub_cpu_to_be32 (modbase);
- phdr->p_paddr = grub_cpu_to_be32 (modbase);
- phdr->p_filesz = grub_cpu_to_be32 (total_module_size);
- phdr->p_memsz = grub_cpu_to_be32 (total_module_size);
+ phdr->p_type = grub_host_to_target32 (PT_LOAD);
+ phdr->p_flags = grub_host_to_target32 (PF_R | PF_W | PF_X);
+ phdr->p_align = grub_host_to_target32 (sizeof (long));
+ phdr->p_vaddr = grub_host_to_target32 (modbase);
+ phdr->p_paddr = grub_host_to_target32 (modbase);
+ phdr->p_filesz = grub_host_to_target32 (total_module_size);
+ phdr->p_memsz = grub_host_to_target32 (total_module_size);
}
void
@@ -177,10 +177,10 @@
grub_util_read_at (&ehdr, sizeof (ehdr), 0, in);
- phdrs = xmalloc (grub_be_to_cpu16 (ehdr.e_phentsize)
- * (grub_be_to_cpu16 (ehdr.e_phnum) + 2));
+ phdrs = xmalloc (grub_target_to_host16 (ehdr.e_phentsize)
+ * (grub_target_to_host16 (ehdr.e_phnum) + 2));
/* Copy all existing segments. */
- for (i = 0; i < grub_be_to_cpu16 (ehdr.e_phnum); i++)
+ for (i = 0; i < grub_target_to_host16 (ehdr.e_phnum); i++)
{
char *segment_img;
grub_size_t segment_end;
@@ -189,26 +189,26 @@
/* Read segment header. */
grub_util_read_at (phdr, sizeof (Elf32_Phdr),
- (grub_be_to_cpu32 (ehdr.e_phoff)
- + (i * grub_be_to_cpu16 (ehdr.e_phentsize))),
+ (grub_target_to_host32 (ehdr.e_phoff)
+ + (i * grub_target_to_host16 (ehdr.e_phentsize))),
in);
grub_util_info ("copying segment %d, type %d", i,
- grub_be_to_cpu32 (phdr->p_type));
+ grub_target_to_host32 (phdr->p_type));
/* Locate _end. */
- segment_end = grub_be_to_cpu32 (phdr->p_paddr)
- + grub_be_to_cpu32 (phdr->p_memsz);
+ segment_end = grub_target_to_host32 (phdr->p_paddr)
+ + grub_target_to_host32 (phdr->p_memsz);
grub_util_info ("segment %u end 0x%lx", i, segment_end);
if (segment_end > grub_end)
grub_end = segment_end;
/* Read segment data and write it to new file. */
- segment_img = xmalloc (grub_be_to_cpu32 (phdr->p_filesz));
+ segment_img = xmalloc (grub_target_to_host32 (phdr->p_filesz));
- grub_util_read_at (segment_img, grub_be_to_cpu32 (phdr->p_filesz),
- grub_be_to_cpu32 (phdr->p_offset), in);
- grub_util_write_image_at (segment_img, grub_be_to_cpu32 (phdr->p_filesz),
- grub_be_to_cpu32 (phdr->p_offset), out);
+ grub_util_read_at (segment_img, grub_target_to_host32 (phdr->p_filesz),
+ grub_target_to_host32 (phdr->p_offset), in);
+ grub_util_write_image_at (segment_img, grub_target_to_host32 (phdr->p_filesz),
+ grub_target_to_host32 (phdr->p_offset), out);
free (segment_img);
}
@@ -218,14 +218,14 @@
grub_addr_t modbase;
/* Place modules just after grub segment. */
- modbase = ALIGN_UP(grub_end, GRUB_IEEE1275_MOD_ALIGN);
+ modbase = ALIGN_UP(grub_end, GRUB_MOD_ALIGN);
/* Construct new segment header for modules. */
- phdr = phdrs + grub_be_to_cpu16 (ehdr.e_phnum);
- ehdr.e_phnum = grub_cpu_to_be16 (grub_be_to_cpu16 (ehdr.e_phnum) + 1);
+ phdr = phdrs + grub_target_to_host16 (ehdr.e_phnum);
+ ehdr.e_phnum = grub_host_to_target16 (grub_target_to_host16 (ehdr.e_phnum) + 1);
/* Fill in p_offset so the callees know where to write. */
- phdr->p_offset = grub_cpu_to_be32 (ALIGN_UP (grub_util_get_fp_size (out),
+ phdr->p_offset = grub_host_to_target32 (ALIGN_UP (grub_util_get_fp_size (out),
sizeof (long)));
load_modules (modbase, phdr, dir, mods, out);
@@ -234,11 +234,11 @@
if (chrp)
{
/* Construct new segment header for the CHRP note. */
- phdr = phdrs + grub_be_to_cpu16 (ehdr.e_phnum);
- ehdr.e_phnum = grub_cpu_to_be16 (grub_be_to_cpu16 (ehdr.e_phnum) + 1);
+ phdr = phdrs + grub_target_to_host16 (ehdr.e_phnum);
+ ehdr.e_phnum = grub_host_to_target16 (grub_target_to_host16 (ehdr.e_phnum) + 1);
/* Fill in p_offset so the callees know where to write. */
- phdr->p_offset = grub_cpu_to_be32 (ALIGN_UP (grub_util_get_fp_size (out),
+ phdr->p_offset = grub_host_to_target32 (ALIGN_UP (grub_util_get_fp_size (out),
sizeof (long)));
load_note (phdr, out);
@@ -251,12 +251,12 @@
/* Append entire segment table to the file. */
phdroff = ALIGN_UP (grub_util_get_fp_size (out), sizeof (long));
- grub_util_write_image_at (phdrs, grub_be_to_cpu16 (ehdr.e_phentsize)
- * grub_be_to_cpu16 (ehdr.e_phnum), phdroff,
+ grub_util_write_image_at (phdrs, grub_target_to_host16 (ehdr.e_phentsize)
+ * grub_target_to_host16 (ehdr.e_phnum), phdroff,
out);
/* Write ELF header. */
- ehdr.e_phoff = grub_cpu_to_be32 (phdroff);
+ ehdr.e_phoff = grub_host_to_target32 (phdroff);
grub_util_write_image_at (&ehdr, sizeof (ehdr), 0, out);
free (phdrs);
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] generic ELF version of grub-mkimage
2007-10-11 22:58 ` Robert Millan
@ 2007-10-12 10:52 ` Marco Gerards
2007-10-12 15:55 ` Robert Millan
0 siblings, 1 reply; 10+ messages in thread
From: Marco Gerards @ 2007-10-12 10:52 UTC (permalink / raw)
To: The development of GRUB 2
Robert Millan <rmh@aybabtu.com> 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 <rmh@aybabtu.com>
>
> * 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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] generic ELF version of grub-mkimage
2007-10-12 10:52 ` Marco Gerards
@ 2007-10-12 15:55 ` Robert Millan
2007-10-12 16:07 ` Robert Millan
0 siblings, 1 reply; 10+ messages in thread
From: Robert Millan @ 2007-10-12 15:55 UTC (permalink / raw)
To: The development of GRUB 2
On Fri, Oct 12, 2007 at 12:52:42PM +0200, Marco Gerards wrote:
> > 2007-10-12 Robert Millan <rmh@aybabtu.com>
> >
> > * 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...
Ok.
> If you are not sure, better wait a few days before committing a
> patch. Or ask me to double check it.
I *was* sure. I just happen to be not very good at learning a particular
ChangeLog style.
> > * 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.
Ok. But no, I didn't really notice. I'll fix this entry and keep trying to
get it right next time.
> If you use diff -up this is easy to see from the patch.
Sounds very useful, thanks.
--
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 /.)
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] generic ELF version of grub-mkimage
2007-10-12 15:55 ` Robert Millan
@ 2007-10-12 16:07 ` Robert Millan
2007-11-10 17:29 ` Marco Gerards
2007-11-18 11:39 ` Marco Gerards
0 siblings, 2 replies; 10+ messages in thread
From: Robert Millan @ 2007-10-12 16:07 UTC (permalink / raw)
To: The development of GRUB 2
[-- Attachment #1: Type: text/plain, Size: 337 bytes --]
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 /.)
[-- Attachment #2: changelog.diff --]
[-- Type: text/x-diff, Size: 1591 bytes --]
--- grub2/ChangeLog 2007-10-12 12:22:27.000000000 +0200
+++ ChangeLog 2007-10-12 18:06:51.000000000 +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 <rmh@aybabtu.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] generic ELF version of grub-mkimage
2007-10-12 16:07 ` Robert Millan
@ 2007-11-10 17:29 ` Marco Gerards
2007-11-10 20:12 ` Robert Millan
2007-11-18 11:39 ` Marco Gerards
1 sibling, 1 reply; 10+ messages in thread
From: Marco Gerards @ 2007-11-10 17:29 UTC (permalink / raw)
To: The development of GRUB 2
Robert Millan <rmh@aybabtu.com> writes:
> 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?
This was committed, right? Otherwise poke me and I will look :-)
--
Marco
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] generic ELF version of grub-mkimage
2007-11-10 17:29 ` Marco Gerards
@ 2007-11-10 20:12 ` Robert Millan
0 siblings, 0 replies; 10+ messages in thread
From: Robert Millan @ 2007-11-10 20:12 UTC (permalink / raw)
To: The development of GRUB 2
On Sat, Nov 10, 2007 at 06:29:12PM +0100, Marco Gerards wrote:
> Robert Millan <rmh@aybabtu.com> writes:
>
> > 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?
>
> This was committed, right? Otherwise poke me and I will look :-)
No.
--
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 /.)
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] generic ELF version of grub-mkimage
2007-10-12 16:07 ` Robert Millan
2007-11-10 17:29 ` Marco Gerards
@ 2007-11-18 11:39 ` Marco Gerards
2007-11-18 11:54 ` Robert Millan
1 sibling, 1 reply; 10+ messages in thread
From: Marco Gerards @ 2007-11-18 11:39 UTC (permalink / raw)
To: The development of GRUB 2
Robert Millan <rmh@aybabtu.com> writes:
> 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?
Yes.
--
Marco
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] generic ELF version of grub-mkimage
2007-11-18 11:39 ` Marco Gerards
@ 2007-11-18 11:54 ` Robert Millan
0 siblings, 0 replies; 10+ messages in thread
From: Robert Millan @ 2007-11-18 11:54 UTC (permalink / raw)
To: The development of GRUB 2
On Sun, Nov 18, 2007 at 12:39:29PM +0100, Marco Gerards wrote:
> Robert Millan <rmh@aybabtu.com> writes:
>
> > 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?
>
> Yes.
Ok, fixed.
--
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 /.)
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2007-11-18 11:54 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-30 10:03 [PATCH] generic ELF version of grub-mkimage Patrick Georgi
2007-10-01 14:53 ` Robert Millan
2007-10-11 22:58 ` Robert Millan
2007-10-12 10:52 ` Marco Gerards
2007-10-12 15:55 ` Robert Millan
2007-10-12 16:07 ` Robert Millan
2007-11-10 17:29 ` Marco Gerards
2007-11-10 20:12 ` Robert Millan
2007-11-18 11:39 ` Marco Gerards
2007-11-18 11:54 ` Robert Millan
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.