Commit 0b11a406 authored by Marek Vasut's avatar Marek Vasut
Browse files

mxssb: Fix handling of unaligned payload

The unaligned payload case is not well defined. The FSL tool luckily handles
it so that it stuffs random data at the end of the payload to align it. We will
do the same when verifying the image, we will up-align the data we read to 16b
and then operate on this as if it was aligned.
Signed-off-by: Marek Vasut's avatarMarek Vasut <>
parent b8baf3b0
......@@ -1481,7 +1481,7 @@ static int sb_verify_command(struct sb_image_ctx *ictx,
unsigned long *tsize)
struct sb_command *ccmd = &cctx->payload;
unsigned long size;
unsigned long size, asize;
char *csum, *flag = "";
int ret;
unsigned int i;
......@@ -1511,12 +1511,13 @@ static int sb_verify_command(struct sb_image_ctx *ictx,
ccmd->load.address, ccmd->load.count, csum);
cctx->length = ccmd->load.count;
cctx->data = malloc(cctx->length);
asize = roundup(cctx->length, SB_BLOCK_SIZE);
cctx->data = malloc(asize);
if (!cctx->data)
return -ENOMEM;
size = fread(cctx->data, 1, cctx->length, fp);
if (size != cctx->length) {
size = fread(cctx->data, 1, asize, fp);
if (size != asize) {
"ERR: SB LOAD command payload too short!\n");
return -EINVAL;
......@@ -1524,10 +1525,10 @@ static int sb_verify_command(struct sb_image_ctx *ictx,
*tsize += size;
EVP_DigestUpdate(&ictx->md_ctx, cctx->data, cctx->length);
sb_aes_crypt(ictx, cctx->data, cctx->data, cctx->length);
EVP_DigestUpdate(&ictx->md_ctx, cctx->data, asize);
sb_aes_crypt(ictx, cctx->data, cctx->data, asize);
if (ccmd->load.crc32 != crc32(cctx->data, cctx->length)) {
if (ccmd->load.crc32 != crc32(cctx->data, asize)) {
"ERR: SB LOAD command payload CRC32 invalid!\n");
return -EINVAL;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment