[U-Boot] [PATCH] crc32: Correct endianness of crc32 result

Simon Glass sjg at chromium.org
Tue Apr 16 23:57:10 CEST 2013


Hi Wolfgang,

On Sat, Apr 6, 2013 at 12:04 AM, Wolfgang Denk <wd at denx.de> wrote:
> Dear Simon Glass,
>
> In message <1365203470-9099-1-git-send-email-sjg at chromium.org> you wrote:
>> When crc32 is handled by the hash library, it requires the data to be in
>> big-endian format, since it reads it byte-wise. Thus at present the 'crc32'
>> command reports incorrect data. For example, previously we might see:
>
>
>> +#ifdef USE_HOSTCC
>> +     crc = htobe32(crc);
>>       memcpy(output, &crc, sizeof(crc));
>> +#else
>> +     put_unaligned_be32(crc, output);
>> +#endif
>
> Why is this depending on USE_HOSTCC, and not on the endianess?

We always want big-endian in this case, since the bytes have to date
been written that way by the crc32 command.

>
> And why do we need the #ifdef?  Can we not always use htobe32() and
> put_unaligned_be32() ?

Well I don't think put_unaligned_be32 is available to user space,
which is the environment that the tools are built under. It is
available in the kernel, but that's not our environment.

I'm not happy with this solution and would be pleased to find a better
way, but I'm not sure what it is.

But this patch does fix a real bug which we should sort out before the
release, one way or another.

>
> Best regards,
>
> Wolfgang Denk

Regards,
Simon


More information about the U-Boot mailing list