Commit 4c5bd7d4 authored by Marek Vasut's avatar Marek Vasut
Browse files

mxssb: Pull command blocks from the tree



Pull the SB command blocks from the image tree.
Signed-off-by: Marek Vasut's avatarMarek Vasut <marex@denx.de>
parent dfc34da2
......@@ -412,27 +412,14 @@ unsupp:
}
static void sb_encrypt_tag(struct sb_image_ctx *ictx,
struct sb_source_entry *src,
struct sb_command *cmd,
uint8_t result[sizeof(struct sb_command)])
{
EVP_MD_CTX *md_ctx = &ictx->md_ctx;
struct sb_command *cmd;
int ret;
ret = sb_tag_to_command(src, &cmd);
if (ret) {
fprintf(stderr, "Failed to generate instruction!\n");
exit(ret);
}
cmd->header.checksum = sb_command_checksum(cmd);
sb_aes_encrypt(ictx, (uint8_t *)cmd, (uint8_t *)cmd, sizeof(*cmd));
EVP_DigestUpdate(md_ctx, cmd, sizeof(*cmd));
memcpy(result, cmd, sizeof(*cmd));
free(cmd);
sb_aes_encrypt(ictx, (uint8_t *)cmd, result, sizeof(*cmd));
EVP_DigestUpdate(md_ctx, result, sizeof(*cmd));
}
static void sb_emit_data(uint8_t *image, size_t *offset, void *data, size_t len)
......@@ -444,7 +431,6 @@ static void sb_emit_data(uint8_t *image, size_t *offset, void *data, size_t len)
static int sb_create_image(struct sb_image_ctx *ictx, uint8_t **image)
{
struct sb_boot_image_header *sb_header = &ictx->payload;
unsigned int i;
/* The currect offset in the SB image. */
size_t image_offset = 0;
......@@ -489,28 +475,40 @@ static int sb_create_image(struct sb_image_ctx *ictx, uint8_t **image)
sb_emit_data(*image, &image_offset, &sb_dict_key, sizeof(sb_dict_key));
/*
* Section #0 tags.
* Section tags.
*/
uint8_t encrypted_tag[sizeof(struct sb_command)];
struct sb_source_entry *src;
struct sb_source_entry *lst = sb_get_boot_list(target_cpu);
struct sb_section_ctx *sctx = ictx->sect;
struct sb_cmd_ctx *cctx;
struct sb_command *ccmd;
sb_aes_reinit(ictx, sb_header->iv);
for (i = 0; i < sb_get_boot_list_size(target_cpu); i++) {
src = &lst[i];
sb_encrypt_tag(ictx, src, encrypted_tag);
sb_emit_data(*image, &image_offset, encrypted_tag,
sizeof(struct sb_command));
if(src->tag == ROM_TAG_CMD) {
sb_aes_reinit(ictx, sb_header->iv);
} else if(src->tag == ROM_LOAD_CMD) {
sb_aes_encrypt(ictx, src->payload, src->payload, src->length);
EVP_DigestUpdate(&ictx->md_ctx, src->payload, src->length);
sb_emit_data(*image, &image_offset, src->payload, src->length);
while (sctx) {
cctx = sctx->cmd;
while (cctx) {
ccmd = &cctx->payload;
sb_encrypt_tag(ictx, ccmd, encrypted_tag);
sb_emit_data(*image, &image_offset, encrypted_tag,
sizeof(struct sb_command));
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;
}
}
sctx = sctx->sect;
};
/*
* Dump the SHA1 of the whole image.
......
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