Commit 2f76748a authored by Marek Vasut's avatar Marek Vasut

mxssb: Pass the SB image header via image context

There is only one SB image header, so make it part of the image
context instead of having separate variable for this purpose.
Moreover, it's now possible to constify the SB header template.
Signed-off-by: Marek Vasut's avatarMarek Vasut <marex@denx.de>
parent df656400
......@@ -34,6 +34,8 @@ enum {
struct sb_image_ctx {
EVP_CIPHER_CTX cipher_ctx;
EVP_MD_CTX md_ctx;
struct sb_boot_image_header payload;
};
static int target_cpu = -1;
......@@ -114,7 +116,7 @@ static struct sb_source_entry mx28_boot_list[] = {
}
};
static struct sb_boot_image_header sb_header_template = {
static const struct sb_boot_image_header sb_header_template = {
.signature1 = { 'S', 'T', 'M', 'P' },
.major_version = SB_VERSION_MAJOR,
.minor_version = SB_VERSION_MINOR,
......@@ -295,10 +297,8 @@ static time_t sb_get_timestamp(void)
return seconds_to_now - seconds_to_2000;
}
static void sb_complete_sb_header(void)
static void sb_complete_sb_header(struct sb_boot_image_header *sb_header)
{
struct sb_boot_image_header *sb_header = &sb_header_template;
EVP_MD_CTX md_ctx;
EVP_MD_CTX_init(&md_ctx);
......@@ -329,7 +329,7 @@ static void sb_encrypt_sb_header(
uint8_t *sb_header_ptr = (uint8_t *)sb_header;
/* Fill in the missing parts of the SB image header. */
sb_complete_sb_header();
sb_complete_sb_header(sb_header);
/* Encrypt the header, compute the digest. */
sb_aes_encrypt(cipher_ctx, sb_header_ptr, NULL, sizeof(*sb_header));
......@@ -462,16 +462,16 @@ static void sb_emit_data(uint8_t *image, size_t *offset, void *data, size_t len)
*offset += len;
}
static int sb_create_image(struct sb_boot_image_header *sb_header,
uint8_t **image, struct sb_image_ctx *ctx)
static int sb_create_image(struct sb_image_ctx *ctx, uint8_t **image)
{
struct sb_boot_image_header *sb_header = &ctx->payload;
unsigned int i;
/* The currect offset in the SB image. */
size_t image_offset = 0;
/* Save offset of the TAG tag. */
uint32_t tag_offset = sb_header_template.image_blocks;
uint32_t tag_offset = sb_header->image_blocks;
/* Start image-wide crypto. */
EVP_MD_CTX_init(&ctx->md_ctx);
......@@ -720,11 +720,12 @@ int main(int argc, char **argv)
if (ret)
return ret;
ret = sb_create_image(&sb_header_template, &image, &ctx);
memcpy(&ctx.payload, &sb_header_template, sizeof(sb_header_template));
ret = sb_create_image(&ctx, &image);
if (ret)
return ret;
image_size = sb_header_template.image_blocks * SB_BLOCK_SIZE;
image_size = ctx.payload.image_blocks * SB_BLOCK_SIZE;
ret = sb_save_image(output_filename, image, image_size);
sb_unload_binary(1);
......
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