From: Hilko Bengen Date: Wed, 24 Aug 2011 15:16:51 +0000 (+0200) Subject: febootstrap-supermin-helper: Replace objcopy call for embedding init binary X-Git-Tag: 3.9~3 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=df569d49aa10af5995f771362ddc1400f16486e8;p=febootstrap.git febootstrap-supermin-helper: Replace objcopy call for embedding init binary objcopy needs "output-target" and "binary-architecture" parameters which makes it necessary to keep a list of known architectures. The bin2s.pl script generates input for the GNU assembler which should produce an object file that is equivalent to that produced by objcopy. I have successfully tested the change on an amd64 Debian/unstable system. RWMJ: Added bin2s.pl to EXTRA_DIST and updated .gitignore. --- diff --git a/.gitignore b/.gitignore index f1339cb..bfb6c08 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,7 @@ febootstrap febootstrap*.8 febootstrap*.txt febootstrap-*.tar.gz +helper/ext2init.S helper/febootstrap-supermin-helper helper/init html/febootstrap-supermin-helper.8.html diff --git a/helper/Makefile.am b/helper/Makefile.am index 01a6af1..f60e80e 100644 --- a/helper/Makefile.am +++ b/helper/Makefile.am @@ -45,11 +45,17 @@ init_LDFLAGS = -static # http://www.doof.me.uk/2010/05/07/cute-objcopy-hack/ ELF_DEFAULT_ARCH = $(shell $(srcdir)/elf-default-arch | gawk '{ print $$1 }') DEFAULT_ARCH = $(shell $(srcdir)/elf-default-arch | gawk '{ print $$2 }') -ext2init.o: init + +CLEANFILES = ext2init.S + +ext2init.o: ext2init.S + $(CC) -o $@ -c $< + +ext2init.S: init strip --strip-all $< @file $< | grep -isq static || \ (echo "*** error: init is not staticly linked"; exit 1) - objcopy -I binary -B $(DEFAULT_ARCH) -O $(ELF_DEFAULT_ARCH) $< $@ + ./bin2s.pl $< $@ man_MANS = \ febootstrap-supermin-helper.8 @@ -79,4 +85,4 @@ endif EXTRA_DIST = \ febootstrap-supermin-helper.8 \ febootstrap-supermin-helper.pod \ - elf-default-arch + bin2s.pl diff --git a/helper/bin2s.pl b/helper/bin2s.pl new file mode 100755 index 0000000..2c78b5e --- /dev/null +++ b/helper/bin2s.pl @@ -0,0 +1,45 @@ +#!/usr/bin/perl + +# This script creates a source file for the GNU assembler which shuold +# result in an object file equivalent to that of +# +# objcopy -I binary -B $(DEFAULT_ARCH) -O $(ELF_DEFAULT_ARCH) + +use strict; +use warnings; + +die "usage: $0 \n" if @ARGV != 2; + +my ($infile, $outfile) = @ARGV; +my ($buf, $i, $sz); +open my $ifh, '<', $infile or die "open $infile: $!"; +open my $ofh, '>', $outfile or die "open $outfile: $!"; + +print $ofh <<"EOF"; +/* This file has been automatically generated from $infile by $0 */ + +\t.globl\t_binary_${infile}_start +\t.globl\t_binary_${infile}_end +\t.globl\t_binary_${infile}_size + +\t.section\t.data +_binary_${infile}_start: +EOF + +$sz = 0; +while ( $i = read $ifh, $buf, 12 ) { + print $ofh "\t.byte\t" + . join( ',', map { sprintf '0x%02x', ord $_ } split //, $buf ) . "\n"; + $sz += $i; +} +die "read $infile (at offset $sz): $!\n" if not defined $i; +close $ifh; + +print $ofh <<"EOF"; + +_binary_${infile}_end: + +\t.equ _binary_${infile}_size, $sz +EOF + +close $ofh; diff --git a/helper/elf-default-arch b/helper/elf-default-arch deleted file mode 100755 index 54af14d..0000000 --- a/helper/elf-default-arch +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/sh - -# Copyright (C) 2010 Red Hat Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -# Calculate the default ELF object architecture for this format. -# There doesn't seem to be an easy way to derive this from binutils, -# so instead we hard code it. - -case $(uname -m) in - i[3456]86) echo "elf32-i386 i386" ;; - x86_64) echo "elf64-x86-64 i386" ;; - s390) echo "elf32-s390 s390:31-bit" ;; - s390x) echo "elf64-s390 s390:31-bit" ;; - ppc) echo "elf32-powerpc powerpc" ;; - ppc64) echo "elf64-powerpc powerpc" ;; - *) - echo "This architecture is not recognized. Please update helper/elf-default-arch." - exit 1 -esac