Commit 1545df4f authored by Marek Vasut's avatar Marek Vasut
Browse files

mxssb: Separate the dumping of the image from it's creation



This patch pulls out the function calls that dump the final image
at the end of function that creates the image. This will now allow
easy separation of them into self-standing function.
Signed-off-by: Marek Vasut's avatarMarek Vasut <marex@denx.de>
parent c2d36932
......@@ -376,18 +376,12 @@ static int sb_create_image(struct sb_image_ctx *ictx, uint8_t **image)
EVP_MD_CTX_init(&ictx->md_ctx);
EVP_DigestInit(&ictx->md_ctx, EVP_sha1());
/* Allocate the resulting SB image. */
*image = malloc(sb_header->image_blocks * SB_BLOCK_SIZE);
if (!*image)
return -ENOMEM;
/*
* SB image header.
*/
sb_aes_init(ictx, NULL);
sb_encrypt_sb_header(ictx, sb_header);
sb_emit_data(*image, &image_offset, sb_header, sizeof(*sb_header));
/*
* SB sections header.
......@@ -396,11 +390,6 @@ static int sb_create_image(struct sb_image_ctx *ictx, uint8_t **image)
struct sb_section_ctx *sctx = ictx->sect;
sb_encrypt_sb_sections_header(ictx, sb_section_header_cbc_mac);
while (sctx) {
sb_emit_data(*image, &image_offset, &sctx->payload,
sizeof(struct sb_sections_header));
sctx = sctx->sect;
};
/*
* Key dictionary.
......@@ -413,8 +402,6 @@ static int sb_create_image(struct sb_image_ctx *ictx, uint8_t **image)
sb_encrypt_key_dictionary_key(ictx,
&sb_dict_key, sb_section_header_cbc_mac);
sb_emit_data(*image, &image_offset, &sb_dict_key, sizeof(sb_dict_key));
/*
* Section tags.
*/
......@@ -431,15 +418,12 @@ static int sb_create_image(struct sb_image_ctx *ictx, uint8_t **image)
ccmd = &cctx->payload;
sb_encrypt_tag(ictx, cctx);
sb_emit_data(*image, &image_offset, &cctx->c_payload,
sizeof(cctx->payload));
if (ccmd->header.tag == ROM_TAG_CMD) {
sb_aes_reinit(ictx, sb_header->iv);
} else if (ccmd->header.tag == ROM_LOAD_CMD) {
sb_aes_encrypt(ictx, cctx->data, cctx->data, cctx->length);
EVP_DigestUpdate(&ictx->md_ctx, cctx->data, cctx->length);
sb_emit_data(*image, &image_offset, cctx->data, cctx->length);
}
cctx = cctx->cmd;
......@@ -448,7 +432,6 @@ static int sb_create_image(struct sb_image_ctx *ictx, uint8_t **image)
sctx = sctx->sect;
};
/*
* Dump the SHA1 of the whole image.
*/
......@@ -459,11 +442,45 @@ static int sb_create_image(struct sb_image_ctx *ictx, uint8_t **image)
memset(digest, 0, sizeof(digest));
EVP_DigestFinal(&ictx->md_ctx, digest, NULL);
sb_aes_encrypt(ictx, digest, digest, sizeof(digest));
sb_emit_data(*image, &image_offset, digest, sizeof(digest));
/* Stop the encryption session. */
sb_aes_deinit(&ictx->cipher_ctx);
/*
* Export the image
*/
/* Allocate the resulting SB image. */
*image = malloc(sb_header->image_blocks * SB_BLOCK_SIZE);
if (!*image)
return -ENOMEM;
sb_emit_data(*image, &image_offset, sb_header, sizeof(*sb_header));
sctx = ictx->sect;
while (sctx) {
sb_emit_data(*image, &image_offset, &sctx->payload,
sizeof(struct sb_sections_header));
sctx = sctx->sect;
};
sb_emit_data(*image, &image_offset, &sb_dict_key, sizeof(sb_dict_key));
sctx = ictx->sect;
while (sctx) {
cctx = sctx->cmd;
while (cctx) {
ccmd = &cctx->payload;
sb_emit_data(*image, &image_offset, &cctx->c_payload,
sizeof(cctx->payload));
if (ccmd->header.tag == ROM_LOAD_CMD)
sb_emit_data(*image, &image_offset, cctx->data, cctx->length);
cctx = cctx->cmd;
}
sctx = sctx->sect;
};
sb_emit_data(*image, &image_offset, digest, sizeof(digest));
return 0;
}
......
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