[U-Boot] [PATCH 07/51] tools: socfpga: Add socfpga preloader signing to mkimage
Marek Vasut
marex at denx.de
Wed Oct 1 13:51:32 CEST 2014
On Wednesday, October 01, 2014 at 12:10:47 PM, Chin Liang See wrote:
[...]
> > + * The image is padded out to 64k, because that is what is
> > + * typically used to write the image to the boot medium.
> > + */
> > +
> > +#include "pbl_crc32.h"
>
> Seems I cannot find this file
See tools/pbl_crc32.h
[...]
> > +static void build_header(uint8_t *buf,
> > + uint8_t version,
> > + uint8_t flags,
> > + uint16_t length_bytes)
> > +{
> > + header.validation = htole32(VALIDATION_WORD);
> > + header.version = version;
> > + header.flags = flags;
> > + header.length_u32 = htole16(length_bytes/4);
> > + header.zero = 0;
> > + header.checksum = htole16(hdr_checksum((const uint8_t *)&header, 10));
>
> Seems 10 is a magic number here.
> Suggest to use sizeof(header) - sizeof(header.checksum)
Even better, I can pass the whole *header into hdr_checksum and contain all that
size computation in there. Your formula included.
[...]
> > +/* Sign the buffer and return the signed buffer size */
> > +static int sign_buffer(uint8_t *buf,
> > + uint8_t version, uint8_t flags,
> > + int len, int pad_64k)
> > +{
> > + uint32_t calc_crc;
> > +
> > + /* Align the length up */
> > + len = (len + 3) & (~3);
> > +
> > + /* Build header, adding 4 bytes to length to hold the CRC32. */
> > + build_header(buf + HEADER_OFFSET, version, flags, len + 4);
> > +
> > + /* Calculate and apply the CRC */
> > + calc_crc = ~pbl_crc32(0, (char *)buf, len);
> > +
>
> For this, we can reuse the lib/bzlib_private.h
>
> /* Calculate and apply the CRC */
> BZ_INITIALISE_CRC(calc_crc);
> while (len--) {
> BZ_UPDATE_CRC(calc_crc, *buf);
> buf++;
> }
> calc_crc ^= ~0;
Do you mean I should replace the one function call with this whole block ?
[...]
The rest was addressed.
More information about the U-Boot
mailing list