[U-Boot-Users] [PATCH] tools/envcrc.c: use the target sizeof rather than build

Joakim Tjernlund joakim.tjernlund at transmode.se
Mon Mar 31 17:31:29 CEST 2008


On Sun, 2008-03-30 at 16:27 -0400, Mike Frysinger wrote:
> 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 <vapier at gentoo.org>

[SNIP]

> 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

Cool script, which reminds me about something: Is it possible to
define a script that can output if the cpu is Big Endian or 
Little Endian?

If one ever wanted to port the optimised crc32 from linux to u-boot one
needs to know the endian of the CPU.

 Jocke




More information about the U-Boot mailing list