From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1DKffa-0000zT-Pu for mharc-grub-devel@gnu.org; Sun, 10 Apr 2005 12:52:23 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DKffW-0000xt-NZ for grub-devel@gnu.org; Sun, 10 Apr 2005 12:52:18 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DKffT-0000xE-K4 for grub-devel@gnu.org; Sun, 10 Apr 2005 12:52:16 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DKffT-0000vV-7Z for grub-devel@gnu.org; Sun, 10 Apr 2005 12:52:15 -0400 Received: from [145.74.66.11] (helo=mail-cn.han.nl) by monty-python.gnu.org with esmtp (Exim 4.34) id 1DKg4b-0000zP-Od for grub-devel@gnu.org; Sun, 10 Apr 2005 13:18:14 -0400 Received: from vscan-cn.han.nl (venus.han.nl [145.74.65.6]) by mail-cn.han.nl (Postfix) with ESMTP id 5C8199149 for ; Sun, 10 Apr 2005 19:06:51 +0200 (CEST) Received: from mail-cn.han.nl ([145.74.66.11]) by vscan-cn.han.nl (venus.han.nl [145.74.65.6]) (amavisd-new, port 10024) with ESMTP id 18787-08 for ; Sun, 10 Apr 2005 19:06:50 +0200 (CEST) Received: from mail1.han.nl (mail1.han.nl [145.74.103.11]) by mail-cn.han.nl (Postfix) with ESMTP id 09765913A for ; Sun, 10 Apr 2005 19:06:50 +0200 (CEST) Received: from localhost.localdomain (mgerards.xs4all.nl [82.92.27.129]) by mail1.han.nl (Postfix) with ESMTP id 2780BC045 for ; Sun, 10 Apr 2005 19:06:49 +0200 (CEST) Mail-Copies-To: metgerards@student.han.nl To: grub-devel@gnu.org From: Marco Gerards Date: Sun, 10 Apr 2005 19:06:49 +0200 Message-ID: <87y8bq8st2.fsf@student.han.nl> User-Agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new (2.2.0) at vscan-cn.han.nl Subject: Cross-compiling GRUB 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, 10 Apr 2005 16:52:20 -0000 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 * 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);