diff options
author | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2010-12-01 09:51:44 +1100 |
---|---|---|
committer | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2010-12-01 09:51:44 +1100 |
commit | aaad509cdca2ed5f2c92a26f5279ec0e89c4fd5f (patch) | |
tree | dfffc0d8f3d21f6736b7f09219c95e2370052d8a /tools | |
download | SLOF-aaad509cdca2ed5f2c92a26f5279ec0e89c4fd5f.zip SLOF-aaad509cdca2ed5f2c92a26f5279ec0e89c4fd5f.tar.gz SLOF-aaad509cdca2ed5f2c92a26f5279ec0e89c4fd5f.tar.bz2 |
Initial import of slof-JX-1.7.0-4
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/Makefile | 33 | ||||
-rwxr-xr-x | tools/create_reloc_table.sh | 60 | ||||
-rw-r--r-- | tools/gen_reloc_table.c | 95 |
3 files changed, 188 insertions, 0 deletions
diff --git a/tools/Makefile b/tools/Makefile new file mode 100644 index 0000000..6de8fe6 --- /dev/null +++ b/tools/Makefile @@ -0,0 +1,33 @@ +# ***************************************************************************** +# * Copyright (c) 2004, 2008 IBM Corporation +# * All rights reserved. +# * This program and the accompanying materials +# * are made available under the terms of the BSD License +# * which accompanies this distribution, and is available at +# * http://www.opensource.org/licenses/bsd-license.php +# * +# * Contributors: +# * IBM Corporation - initial implementation +# ****************************************************************************/ + +include ../make.rules + +all: gen_reloc_table + +%.o: %.c + $(HOSTCC) -W $(HOSTCFLAGS) -c $^ + +elf2tst: elf2tst.o + $(HOSTCC) $(HOSTCFLAGS) -o $@ $^ + +gen_reloc_table: gen_reloc_table.o + $(HOSTCC) $(HOSTCFLAGS) -o $@ $^ + +clean_here: + rm -f elf2tst *.o gen_reloc_table + +clean: clean_here + + +distclean: clean_here + diff --git a/tools/create_reloc_table.sh b/tools/create_reloc_table.sh new file mode 100755 index 0000000..8cacb74 --- /dev/null +++ b/tools/create_reloc_table.sh @@ -0,0 +1,60 @@ +# ***************************************************************************** +# * Copyright (c) 2004, 2008 IBM Corporation +# * All rights reserved. +# * This program and the accompanying materials +# * are made available under the terms of the BSD License +# * which accompanies this distribution, and is available at +# * http://www.opensource.org/licenses/bsd-license.php +# * +# * Contributors: +# * IBM Corporation - initial implementation +# ****************************************************************************/ +#!/bin/sh + + +CROSSTMP=`grep ^CROSS $(dirname $0)/../make.rules | cut -d\ -f2` + +CROSS=${CROSS-$CROSSTMP} + +# Set defaults: +LD="${CROSS}ld" +LDFLAGS="-nostdlib" +LDSFILE="" +OBJCOPY="${CROSS}objcopy" + +DIRNAME=`dirname $0` + +# Parse parameters: +while [ $# -gt 0 ] ; do + case "$1" in + --ld) LD=$2 ; shift 2 ;; + --ldflags) LDFLAGS=$2 ; shift 2 ;; + --lds) LDSFILE=$2 ; shift 2 ;; + --objcopy) OBJCOPY=$2 ; shift 2 ;; + *.o|*.a|-l*|-L*) OBJFILES="$OBJFILES $1" ; shift ;; + *) echo "$0:" ; echo " Unsupported argument: $1"; exit -1 ;; + esac +done + +if [ -z $LDSFILE ]; then + echo "Please specifiy an lds file with the --lds option" + exit 42 +fi + +TMP1=`mktemp` +TMP2=`mktemp` + +# Now create the two object files: +$LD $LDFLAGS -T $LDSFILE -o $TMP1.o $OBJFILES || exit -1 +$LD $LDFLAGS -T $LDSFILE -o $TMP2.o $OBJFILES --section-start .text=0x4000000000000000 || exit -1 + +$OBJCOPY -O binary $TMP1.o $TMP1.bin || exit -1 +$OBJCOPY -O binary $TMP2.o $TMP2.bin || exit -1 + +# Create the relocation table with gen_reloc_table: +$DIRNAME/gen_reloc_table $TMP1.bin $TMP2.bin reloc_table.bin + +$LD -o reloc_table.o -bbinary reloc_table.bin -e0 || exit -1 +$OBJCOPY --rename-section .data=.reloc reloc_table.o reloc_table.o || exit -1 + +rm -f $TMP1.o $TMP2.o $TMP1.bin $TMP2.bin reloc_table.bin diff --git a/tools/gen_reloc_table.c b/tools/gen_reloc_table.c new file mode 100644 index 0000000..b2e2176 --- /dev/null +++ b/tools/gen_reloc_table.c @@ -0,0 +1,95 @@ +/****************************************************************************** + * Copyright (c) 2004, 2008 IBM Corporation + * All rights reserved. + * This program and the accompanying materials + * are made available under the terms of the BSD License + * which accompanies this distribution, and is available at + * http://www.opensource.org/licenses/bsd-license.php + * + * Contributors: + * IBM Corporation - initial implementation + *****************************************************************************/ + +#include <stdio.h> +#include <stdlib.h> + +static int reloc_64_cnt; + +static int reloc_64[4096]; + +static void +output_int(FILE *output_file, int i) +{ + fputc((i>>24) & 0xff, output_file); + fputc((i>>16) & 0xff, output_file); + fputc((i>>8) & 0xff, output_file); + fputc(i & 0xff, output_file); +} + +static void +output_reloc_table(FILE * output_file, int reloc_cnt, int reloc[]) +{ + int i; + for (i=0; i < reloc_cnt; i++) + { +#ifdef DEBUG + printf ("reloc %x\n", reloc[i]); +#endif + output_int (output_file, reloc[i]); + } + if ((reloc_cnt & 1) == 0) + output_int (output_file, 0); +} + +int +main(int argc, char *argv[]) +{ + int cnt_a, cnt_b, offset = -1; + unsigned char a, b; + FILE *orig, *other, *output_file; + + if (argc != 4) + { + fprintf (stderr, "reloc_diff orig_file other_file output_file\n"); + exit(-1); + } + + orig = fopen(argv[1], "rb"); + other = fopen(argv[2], "rb"); + output_file = fopen(argv[3], "wb"); + if(orig == NULL || other == NULL || output_file == NULL) { + printf("Could not open file.\n"); + return -1; + } + + while (1) + { + cnt_a = fread(&a, 1, 1, orig); + cnt_b = fread(&b, 1, 1, other); + offset ++; + if (cnt_a != cnt_b) + { + fprintf (stderr, "Files >%s< and >%s< have not the same lenght\n",argv[1],argv[2]); + exit(-1); + } + + if (cnt_a == 0) + break; + + if (a == b) continue; + + if (a + 0x40 == b) + { + reloc_64[reloc_64_cnt++] = offset; + } + else + { + fprintf(stderr, "Unknown relocation"); + fprintf(stderr, "Offset %x: %02x %02x\n", offset, a, b); + break; + } + } + + output_reloc_table(output_file, reloc_64_cnt, reloc_64); + return 0; +} |