* Cross-compiling GRUB
@ 2005-04-10 17:06 Marco Gerards
2005-04-10 19:06 ` Hollis Blanchard
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Marco Gerards @ 2005-04-10 17:06 UTC (permalink / raw)
To: grub-devel
Hi,
At the moment I am compiling GRUB on one PPC system and running it on
another. At the moment this is very unproductive for me and making it
hard, if not impossible, to do any testing. So I set up a
cross-compiler so I can compile GRUB 2 for the PPC on my AMD64.
There are three problems with GRUB 2 CVS ATM. Most importantly is
that grub-mkimage can not be run on the AMD64 because it is little
endian. This patch fixed the endian issues in grub-mkimage and it all
works now. Another issue is that some check in configure.ac was
wrong. The last is that genmk.rb did not work correctly because it
produces PPC .o files which it tries to link with the AMD64 linker. :)
I think all these fixes are too obvious and should not cause any
copyright problems. Okuji, do you agree with this?
Johan, Hollis, this patch touches some of your files. It would be
nice if both of you could have a quick look at this patch. :)
Thanks,
Marco
2005-04-10 Marco Gerards <metgerards@student.han.nl>
* configure.ac: Fix the test for cross-compiling.
* genmk.rb (Program): Use `$(CC)' instead of `$(BUILD_CC)'. Don't
define GRUB_UTIL anymore.
* util/powerpc/ieee1275/grub-mkimage.c (load_note): Endian fixes
so this function works on other systems than just big endian.
(load_modules): Likewise.
(add_segments): Likewise.
Index: configure.ac
===================================================================
RCS file: /cvsroot/grub/grub2/configure.ac,v
retrieving revision 1.9
diff -u -p -u -p -r1.9 configure.ac
--- configure.ac 4 Apr 2004 13:45:59 -0000 1.9
+++ configure.ac 10 Apr 2005 16:36:43 -0000
@@ -109,7 +109,7 @@ AC_CHECK_TOOL(LD, ld)
AC_PATH_PROG(RUBY, ruby)
# For cross-compiling.
-if test "x$build" = "x$host"; then
+if test "x$build" != "x$host"; then
AC_CHECK_PROGS(BUILD_CC, [gcc egcs cc],
[AC_MSG_ERROR([none of gcc, egcs and cc is found. set BUILD_CC manually.])])
else
Index: genmk.rb
===================================================================
RCS file: /cvsroot/grub/grub2/genmk.rb,v
retrieving revision 1.12
diff -u -p -u -p -r1.12 genmk.rb
--- genmk.rb 8 Mar 2005 01:01:06 -0000 1.12
+++ genmk.rb 10 Apr 2005 16:36:43 -0000
@@ -236,7 +236,7 @@ class Program
MOSTLYCLEANFILES += #{deps_str}
#{@name}: #{objs_str}
- $(BUILD_CC) -o $@ $^ $(BUILD_LDFLAGS) $(#{prefix}_LDFLAGS)
+ $(CC) -o $@ $^ $(LDFLAGS) $(#{prefix}_LDFLAGS)
" + objs.collect_with_index do |obj, i|
src = sources[i]
@@ -245,11 +245,11 @@ MOSTLYCLEANFILES += #{deps_str}
dir = File.dirname(src)
"#{obj}: #{src}
- $(CC) -I#{dir} -I$(srcdir)/#{dir} $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(#{prefix}_CFLAGS) -c -o $@ $<
+ $(CC) -I#{dir} -I$(srcdir)/#{dir} $(CPPFLAGS) $(CFLAGS) $(#{prefix}_CFLAGS) -c -o $@ $<
#{dep}: #{src}
set -e; \
- $(CC) -I#{dir} -I$(srcdir)/#{dir} $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(#{prefix}_CFLAGS) -M $< \
+ $(CC) -I#{dir} -I$(srcdir)/#{dir} $(CPPFLAGS) $(CFLAGS) $(#{prefix}_CFLAGS) -M $< \
| sed 's,#{Regexp.quote(fake_obj)}[ :]*,#{obj} $@ : ,g' > $@; \
[ -s $@ ] || rm -f $@
Index: util/powerpc/ieee1275/grub-mkimage.c
===================================================================
RCS file: /cvsroot/grub/grub2/util/powerpc/ieee1275/grub-mkimage.c,v
retrieving revision 1.2
diff -u -p -u -p -r1.2 grub-mkimage.c
--- util/powerpc/ieee1275/grub-mkimage.c 9 Jan 2005 18:11:05 -0000 1.2
+++ util/powerpc/ieee1275/grub-mkimage.c 10 Apr 2005 16:36:44 -0000
@@ -84,15 +84,16 @@ load_note (Elf32_Phdr *phdr, FILE *out)
note.descriptor.load_base = grub_cpu_to_be32 (0x00004000);
/* Write the note data to the new segment. */
- grub_util_write_image_at (¬e, note_size, phdr->p_offset, out);
+ grub_util_write_image_at (¬e, note_size,
+ grub_be_to_cpu32 (phdr->p_offset), out);
/* Fill in the rest of the segment header. */
- phdr->p_type = PT_NOTE;
- phdr->p_flags = PF_R;
- phdr->p_align = sizeof (long);
+ 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_vaddr = 0;
phdr->p_paddr = 0;
- phdr->p_filesz = note_size;
+ phdr->p_filesz = grub_cpu_to_be32 (note_size);
phdr->p_memsz = 0;
}
@@ -120,9 +121,9 @@ load_modules (Elf32_Phdr *phdr, const ch
module_img = xmalloc (total_module_size);
modinfo = (struct grub_module_info *) module_img;
- modinfo->magic = GRUB_MODULE_MAGIC;
- modinfo->offset = sizeof (struct grub_module_info);
- modinfo->size = total_module_size;
+ 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);
/* Load all the modules, with headers, into module_img. */
for (p = path_list; p; p = p->next)
@@ -144,16 +145,17 @@ load_modules (Elf32_Phdr *phdr, const ch
}
/* Write the module data to the new segment. */
- grub_util_write_image_at (module_img, total_module_size, phdr->p_offset, out);
+ grub_util_write_image_at (module_img, total_module_size,
+ grub_cpu_to_be32 (phdr->p_offset), out);
/* Fill in the rest of the segment header. */
- phdr->p_type = PT_LOAD;
- phdr->p_flags = PF_R | PF_W | PF_X;
- phdr->p_align = sizeof (long);
- phdr->p_vaddr = GRUB_IEEE1275_MODULE_BASE;
- phdr->p_paddr = GRUB_IEEE1275_MODULE_BASE;
- phdr->p_filesz = total_module_size;
- phdr->p_memsz = total_module_size;
+ 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 (GRUB_IEEE1275_MODULE_BASE);
+ phdr->p_paddr = grub_cpu_to_be32 (GRUB_IEEE1275_MODULE_BASE);
+ phdr->p_filesz = grub_cpu_to_be32 (total_module_size);
+ phdr->p_memsz = grub_cpu_to_be32 (total_module_size);
}
void
@@ -170,27 +172,33 @@ add_segments (char *dir, FILE *out, int
in = fopen (kernel_path, "rb");
if (! in)
grub_util_error ("cannot open %s", kernel_path);
- grub_util_read_at (&ehdr, sizeof (ehdr), 0, in);
-
- phdrs = xmalloc (ehdr.e_phentsize * (ehdr.e_phnum + 2));
+ 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));
/* Copy all existing segments. */
- for (i = 0; i < ehdr.e_phnum; i++)
+ for (i = 0; i < grub_be_to_cpu16 (ehdr.e_phnum); i++)
{
char *segment_img;
phdr = phdrs + i;
/* Read segment header. */
- grub_util_read_at (phdr, sizeof (Elf32_Phdr), (ehdr.e_phoff
- + (i * ehdr.e_phentsize)),
+ 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, phdr->p_type);
+ grub_util_info ("copying segment %d, type %d", i,
+ grub_be_to_cpu32 (phdr->p_type));
/* Read segment data and write it to new file. */
- segment_img = xmalloc (phdr->p_filesz);
- 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);
+ segment_img = xmalloc (grub_be_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);
free (segment_img);
}
@@ -198,11 +206,12 @@ add_segments (char *dir, FILE *out, int
if (mods[0] != NULL)
{
/* Construct new segment header for modules. */
- phdr = phdrs + ehdr.e_phnum;
- ehdr.e_phnum++;
+ phdr = phdrs + grub_be_to_cpu16 (ehdr.e_phnum);
+ ehdr.e_phnum = grub_cpu_to_be16 (grub_be_to_cpu16 (ehdr.e_phnum) + 1);
/* Fill in p_offset so the callees know where to write. */
- phdr->p_offset = ALIGN_UP (grub_util_get_fp_size (out), sizeof (long));
+ phdr->p_offset = grub_cpu_to_be32 (ALIGN_UP (grub_util_get_fp_size (out),
+ sizeof (long)));
load_modules (phdr, dir, mods, out);
}
@@ -210,11 +219,12 @@ add_segments (char *dir, FILE *out, int
if (chrp)
{
/* Construct new segment header for the CHRP note. */
- phdr = phdrs + ehdr.e_phnum;
- ehdr.e_phnum++;
+ phdr = phdrs + grub_be_to_cpu16 (ehdr.e_phnum);
+ ehdr.e_phnum = grub_cpu_to_be16 (grub_be_to_cpu16 (ehdr.e_phnum) + 1);
/* Fill in p_offset so the callees know where to write. */
- phdr->p_offset = ALIGN_UP (grub_util_get_fp_size (out), sizeof (long));
+ phdr->p_offset = grub_cpu_to_be32 (ALIGN_UP (grub_util_get_fp_size (out),
+ sizeof (long)));
load_note (phdr, out);
}
@@ -226,11 +236,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, ehdr.e_phentsize * ehdr.e_phnum, phdroff,
+ grub_util_write_image_at (phdrs, grub_be_to_cpu16 (ehdr.e_phentsize)
+ * grub_be_to_cpu16 (ehdr.e_phnum), phdroff,
out);
/* Write ELF header. */
- ehdr.e_phoff = phdroff;
+ ehdr.e_phoff = grub_cpu_to_be32 (phdroff);
grub_util_write_image_at (&ehdr, sizeof (ehdr), 0, out);
free (phdrs);
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: Cross-compiling GRUB
2005-04-10 17:06 Cross-compiling GRUB Marco Gerards
@ 2005-04-10 19:06 ` Hollis Blanchard
2005-04-12 10:42 ` Yoshinori K. Okuji
2005-07-16 21:13 ` Hollis Blanchard
2 siblings, 0 replies; 7+ messages in thread
From: Hollis Blanchard @ 2005-04-10 19:06 UTC (permalink / raw)
To: The development of GRUB 2
On Apr 10, 2005, at 12:06 PM, Marco Gerards wrote:
>
> Johan, Hollis, this patch touches some of your files. It would be
> nice if both of you could have a quick look at this patch. :)
From a quick skim, it looks fine to me.
-Hollis
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Cross-compiling GRUB
2005-04-10 17:06 Cross-compiling GRUB Marco Gerards
2005-04-10 19:06 ` Hollis Blanchard
@ 2005-04-12 10:42 ` Yoshinori K. Okuji
2005-04-12 17:00 ` Marco Gerards
2005-06-21 15:51 ` Marco Gerards
2005-07-16 21:13 ` Hollis Blanchard
2 siblings, 2 replies; 7+ messages in thread
From: Yoshinori K. Okuji @ 2005-04-12 10:42 UTC (permalink / raw)
To: The development of GRUB 2
On Sunday 10 April 2005 07:06 pm, Marco Gerards wrote:
> I think all these fixes are too obvious and should not cause any
> copyright problems. Okuji, do you agree with this?
It is not obvious. Please understand that "obvious" in copyright laws means
"small" in most cases. Haven't you talked with your employer about GRUB yet?
Okuji
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Cross-compiling GRUB
2005-04-12 10:42 ` Yoshinori K. Okuji
@ 2005-04-12 17:00 ` Marco Gerards
2005-06-21 15:51 ` Marco Gerards
1 sibling, 0 replies; 7+ messages in thread
From: Marco Gerards @ 2005-04-12 17:00 UTC (permalink / raw)
To: The development of GRUB 2
"Yoshinori K. Okuji" <okuji@enbug.org> writes:
> On Sunday 10 April 2005 07:06 pm, Marco Gerards wrote:
>> I think all these fixes are too obvious and should not cause any
>> copyright problems. Okuji, do you agree with this?
>
> It is not obvious. Please understand that "obvious" in copyright laws means
> "small" in most cases. Haven't you talked with your employer about GRUB yet?
I thought obvious means both small and that there is just a single
solution possible.
--
Marco
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Cross-compiling GRUB
2005-04-12 10:42 ` Yoshinori K. Okuji
2005-04-12 17:00 ` Marco Gerards
@ 2005-06-21 15:51 ` Marco Gerards
2005-06-21 21:27 ` Yoshinori K. Okuji
1 sibling, 1 reply; 7+ messages in thread
From: Marco Gerards @ 2005-06-21 15:51 UTC (permalink / raw)
To: The development of GRUB 2
"Yoshinori K. Okuji" <okuji@enbug.org> writes:
> On Sunday 10 April 2005 07:06 pm, Marco Gerards wrote:
>> I think all these fixes are too obvious and should not cause any
>> copyright problems. Okuji, do you agree with this?
>
> It is not obvious. Please understand that "obvious" in copyright laws means
> "small" in most cases. Haven't you talked with your employer about GRUB yet?
I contacted the FSF about this patch and explained my personal
situation. They told me it is legally ok to apply this patch.
If there are no objections, I will apply this patch this Tuesday.
Thanks,
Marco
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Cross-compiling GRUB
2005-04-10 17:06 Cross-compiling GRUB Marco Gerards
2005-04-10 19:06 ` Hollis Blanchard
2005-04-12 10:42 ` Yoshinori K. Okuji
@ 2005-07-16 21:13 ` Hollis Blanchard
2 siblings, 0 replies; 7+ messages in thread
From: Hollis Blanchard @ 2005-07-16 21:13 UTC (permalink / raw)
To: The development of GRUB 2
On Apr 10, 2005, at 1:06 PM, Marco Gerards wrote:
>
> At the moment I am compiling GRUB on one PPC system and running it on
> another. At the moment this is very unproductive for me and making it
> hard, if not impossible, to do any testing. So I set up a
> cross-compiler so I can compile GRUB 2 for the PPC on my AMD64.
I have a powerpc64-unknown-linux-gnu toolchain (which can produce ppc32
binaries), but configure is being very annoying. I think I need to be
able to specify host and cross-compile prefix separately (like Linux
kbuild does). In other words, `configure
--crosscompiler=powerpc64-unknown-linux-gnu-
--host=powerpc-unknown-linux-gnu`.
How did you run configure?
-Hollis
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2005-07-17 3:58 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-10 17:06 Cross-compiling GRUB Marco Gerards
2005-04-10 19:06 ` Hollis Blanchard
2005-04-12 10:42 ` Yoshinori K. Okuji
2005-04-12 17:00 ` Marco Gerards
2005-06-21 15:51 ` Marco Gerards
2005-06-21 21:27 ` Yoshinori K. Okuji
2005-07-16 21:13 ` Hollis Blanchard
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.