Commit 88395e16 authored by Marek Vasut's avatar Marek Vasut
Browse files

mxssb: Pull out the instruction filling



Implement a function that allocates space for an instructions
and fills in the fields on a per-command basis. Note that some
commands are still not implemented.
Signed-off-by: Marek Vasut's avatarMarek Vasut <marex@denx.de>
parent 29c4e9ae
...@@ -376,44 +376,78 @@ static uint8_t sb_command_checksum(struct sb_command *inst) ...@@ -376,44 +376,78 @@ static uint8_t sb_command_checksum(struct sb_command *inst)
return csum; return csum;
} }
static void sb_encrypt_tag( static int sb_tag_to_command(struct sb_source_entry *src,
EVP_CIPHER_CTX *cipher_ctx, EVP_MD_CTX *md_ctx, struct sb_command **rcmd)
struct sb_source_entry *src,
uint8_t result[sizeof(struct sb_command)])
{ {
struct sb_command inst = { struct sb_command *cmd;
.header = {
.checksum = 0x5a, cmd = calloc(1, sizeof(*cmd));
.tag = src->tag, if (!cmd)
.flags = src->flags, return -ENOMEM;
},
}; cmd->header.checksum = 0x5a;
uint8_t *inst_ptr = (uint8_t *)&inst; cmd->header.tag = src->tag;
cmd->header.flags = src->flags;
switch (src->tag) { switch (src->tag) {
case ROM_NOP_CMD: /* UNSUPPORTED */
goto unsupp;
case ROM_TAG_CMD: case ROM_TAG_CMD:
inst.tag.section_number = 0; /* FIXME ... support multiple sections */
inst.tag.section_length = sb_get_sections_block_size() - 1; cmd->tag.section_number = 0;
inst.tag.section_flags = SB_SECTION_FLAG_BOOTABLE; /* FIXME ... copy this from section header! */
cmd->tag.section_length = sb_get_sections_block_size() - 1;
/* FIXME ... copy this from section header! */
cmd->tag.section_flags = SB_SECTION_FLAG_BOOTABLE;
break; break;
case ROM_LOAD_CMD: case ROM_LOAD_CMD:
inst.load.address = src->address; cmd->load.address = src->address;
inst.load.count = src->length; cmd->load.count = src->length;
inst.load.crc32 = crc32(src->payload, src->length); cmd->load.crc32 = crc32(src->payload, src->length);
break; break;
case ROM_FILL_CMD: /* UNSUPPORTED */
goto unsupp;
case ROM_JUMP_CMD: /* UNSUPPORTED */
goto unsupp;
case ROM_CALL_CMD: case ROM_CALL_CMD:
inst.call.address = src->address; cmd->call.address = src->address;
/* FIXME ... make this configurable */
cmd->jump.argument = 0x00000000;
break; break;
default: case ROM_MODE_CMD: /* UNSUPPORTED */
printf("Error\n"); goto unsupp;
}
*rcmd = cmd;
return 0;
unsupp:
free(cmd);
return -ENOTSUP;
}
static void sb_encrypt_tag(
EVP_CIPHER_CTX *cipher_ctx, EVP_MD_CTX *md_ctx,
struct sb_source_entry *src,
uint8_t result[sizeof(struct sb_command)])
{
struct sb_command *cmd;
int ret;
ret = sb_tag_to_command(src, &cmd);
if (ret) {
fprintf(stderr, "Failed to generate instruction!\n");
exit(ret);
} }
inst.header.checksum = sb_command_checksum(&inst); cmd->header.checksum = sb_command_checksum(cmd);
sb_aes_encrypt(cipher_ctx, (uint8_t *)cmd, (uint8_t *)cmd, sizeof(*cmd));
EVP_DigestUpdate(md_ctx, cmd, sizeof(*cmd));
sb_aes_encrypt(cipher_ctx, inst_ptr, inst_ptr, sizeof(inst)); memcpy(result, cmd, sizeof(*cmd));
EVP_DigestUpdate(md_ctx, inst_ptr, sizeof(inst));
memcpy(result, inst_ptr, sizeof(inst)); free(cmd);
} }
static void sb_emit_data(uint8_t *image, size_t *offset, void *data, size_t len) static void sb_emit_data(uint8_t *image, size_t *offset, void *data, size_t len)
......
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