The envcrc.c does sizeof(unsigned long) when calculating the crc, but this
is done with the build toolchain instead of the target toolchain, so if
the build is a 64bit system but the target is 32bits, the size will
obviously be wrong.  This introduces a sizeof.sh script to calculate the
required sizeof() value of any type with any compiler.

Signed-off-by: Mike Frysinger <[EMAIL PROTECTED]>
---
 tools/Makefile  |    2 +-
 tools/envcrc.c  |    4 ++--
 tools/sizeof.sh |   35 +++++++++++++++++++++++++++++++++++
 3 files changed, 38 insertions(+), 3 deletions(-)
 create mode 100755 tools/sizeof.sh

diff --git a/tools/Makefile b/tools/Makefile
index 8784a6d..7351f28 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -168,7 +168,7 @@ $(obj)mpc86x_clk$(SFX):     $(obj)mpc86x_clk.o
                $(STRIP) $@
 
 $(obj)envcrc.o:        $(src)envcrc.c
-               $(CC) -g $(CFLAGS) -c -o $@ $<
+               $(CC) -g $(CFLAGS) -c -o $@ $< -DTARGET_SIZEOF_ULONG=$(shell 
$(CONFIG_SHELL) $(src)sizeof.sh unsigned long)
 
 $(obj)ubsha1.o:        $(src)ubsha1.c
                $(CC) -g $(CFLAGS) -c -o $@ $<
diff --git a/tools/envcrc.c b/tools/envcrc.c
index 7b77183..afde912 100644
--- a/tools/envcrc.c
+++ b/tools/envcrc.c
@@ -58,9 +58,9 @@
 #endif /* CFG_ENV_IS_IN_FLASH */
 
 #ifdef CFG_REDUNDAND_ENVIRONMENT
-# define ENV_HEADER_SIZE       (sizeof(unsigned long) + 1)
+# define ENV_HEADER_SIZE       (TARGET_SIZEOF_ULONG + 1)
 #else
-# define ENV_HEADER_SIZE       (sizeof(unsigned long))
+# define ENV_HEADER_SIZE       (TARGET_SIZEOF_ULONG)
 #endif
 
 #define ENV_SIZE (CFG_ENV_SIZE - ENV_HEADER_SIZE)
diff --git a/tools/sizeof.sh b/tools/sizeof.sh
new file mode 100755
index 0000000..e17596c
--- /dev/null
+++ b/tools/sizeof.sh
@@ -0,0 +1,35 @@
+#!/bin/sh
+# Get the sizeof(type) for a compiler
+
+type="$*"
+CC=${CC:-gcc}
+
+if [ -z "$type" ] ; then
+       echo "Usage: sizeof.sh <type>" 1>&2
+       exit 1
+fi
+
+test_size() {
+       cat <<-EOF > sizeof.c
+       typedef $type ac__type_sizeof_;
+       int main() {
+               static int test_array [1 - 2 * !(((long int) (sizeof 
(ac__type_sizeof_))) <= $size)];
+               test_array [0] = 0;
+               return 0;
+       }
+       EOF
+       ${CC} -c sizeof.c >/dev/null 2>&1
+       ret=$?
+       rm -f sizeof.[co]
+       return $ret
+}
+
+size=0
+while [ ${size} -lt 64 ] ; do
+       if test_size ${size} ; then
+               echo ${size}
+               exit 0
+       fi
+       ((size+=1))
+done
+exit 1
-- 
1.5.4.4


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
U-Boot-Users mailing list
U-Boot-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/u-boot-users

Reply via email to