1 From d7603745eb4cd64397f741746afaeba230e69bc4 Mon Sep 17 00:00:00 2001
2 From: Mike Frysinger <vapier@gentoo.org>
3 Date: Sun, 30 Mar 2008 21:36:07 -0400
4 Subject: [PATCH] tools/envcrc.c: use the target sizeof rather than build
6 The envcrc.c does sizeof(unsigned long) when calculating the crc, but this
7 is done with the build toolchain instead of the target toolchain, so if
8 the build is a 64bit system but the target is 32bits, the size will
9 obviously be wrong. This introduces a sizeof.sh script to calculate the
10 required sizeof() value of any type with any compiler.
12 Signed-off-by: Mike Frysinger <vapier@gentoo.org>
15 tools/envcrc.c | 4 ++--
16 tools/sizeof.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++
17 3 files changed, 48 insertions(+), 3 deletions(-)
18 create mode 100755 tools/sizeof.sh
20 diff --git a/tools/Makefile b/tools/Makefile
21 index 8784a6d..7351f28 100644
24 @@ -168,7 +168,7 @@ $(obj)mpc86x_clk$(SFX): $(obj)mpc86x_clk.o
27 $(obj)envcrc.o: $(src)envcrc.c
28 - $(CC) -g $(CFLAGS) -c -o $@ $<
29 + $(CC) -g $(CFLAGS) -c -o $@ $< -DTARGET_SIZEOF_ULONG=$(shell $(CONFIG_SHELL) $(src)sizeof.sh unsigned long)
31 $(obj)ubsha1.o: $(src)ubsha1.c
32 $(CC) -g $(CFLAGS) -c -o $@ $<
33 diff --git a/tools/envcrc.c b/tools/envcrc.c
34 index 7b77183..afde912 100644
38 #endif /* CFG_ENV_IS_IN_FLASH */
40 #ifdef CFG_REDUNDAND_ENVIRONMENT
41 -# define ENV_HEADER_SIZE (sizeof(unsigned long) + 1)
42 +# define ENV_HEADER_SIZE (TARGET_SIZEOF_ULONG + 1)
44 -# define ENV_HEADER_SIZE (sizeof(unsigned long))
45 +# define ENV_HEADER_SIZE (TARGET_SIZEOF_ULONG)
48 #define ENV_SIZE (CFG_ENV_SIZE - ENV_HEADER_SIZE)
49 diff --git a/tools/sizeof.sh b/tools/sizeof.sh
51 index 0000000..4eadb3c
56 +# Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006 Free Software
58 +# Licensed under the GPL-2 or later.
61 +# Get the sizeof(type) for a compiler
67 +if [ -z "$type" ] ; then
68 + echo "Usage: sizeof.sh <type>" 1>&2
73 + cat <<-EOF > sizeof.c
74 + typedef $type ac__type_sizeof_;
76 + static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) <= $size)];
81 + ${CC} -c sizeof.c >/dev/null 2>&1
88 +while [ ${size} -lt 512 ] ; do
89 + if test_size ${size} ; then
91 + while test_size ${size} ; do