Commit 7cf33fd2 authored by Marek Vasut's avatar Marek Vasut
Browse files

mxssb: Replace the .instruction with .tag name



The SB image format specification calls the command identifier
a tag, so align the source this way. Also rename the commands
so they match the SB format specification.
Signed-off-by: Marek Vasut's avatarMarek Vasut <marex@denx.de>
parent 063efcd4
......@@ -52,58 +52,58 @@ static struct sb_ivt_header sb_uboot_ivt = {
static struct sb_source_entry mx23_boot_list[] = {
{
.instruction = SB_INSTRUCTION_TAG,
.flags = SB_INSTRUCTION_FLAG_LAST_TAG,
.tag = ROM_TAG_CMD,
.flags = ROM_TAG_CMD_FLAG_LAST_TAG,
}, {
.instruction = SB_INSTRUCTION_LOAD,
.tag = ROM_LOAD_CMD,
.address = SB_SPL_LOAD_ADDR,
/* .payload is loaded at run time. */
/* .length is loaded at run time. */
}, {
.instruction = SB_INSTRUCTION_CALL,
.tag = ROM_CALL_CMD,
.address = SB_SPL_ENTRY_ADDR,
}, {
.instruction = SB_INSTRUCTION_LOAD,
.tag = ROM_LOAD_CMD,
.address = SB_UBOOT_LOAD_ADDR,
/* .payload is loaded at run time. */
/* .length is loaded at run time. */
}, {
.instruction = SB_INSTRUCTION_CALL,
.tag = ROM_CALL_CMD,
.address = SB_UBOOT_LOAD_ADDR,
}
};
static struct sb_source_entry mx28_boot_list[] = {
{
.instruction = SB_INSTRUCTION_TAG,
.flags = SB_INSTRUCTION_FLAG_LAST_TAG,
.tag = ROM_TAG_CMD,
.flags = ROM_TAG_CMD_FLAG_LAST_TAG,
}, {
.instruction = SB_INSTRUCTION_LOAD,
.tag = ROM_LOAD_CMD,
.address = SB_SPL_LOAD_ADDR,
/* .payload is loaded at run time. */
/* .length is loaded at run time. */
}, {
.instruction = SB_INSTRUCTION_LOAD,
.tag = ROM_LOAD_CMD,
.address = SB_IVT_LOAD_ADDR,
.payload = (uint8_t *)&sb_spl_ivt,
.length = sizeof(sb_spl_ivt),
}, {
.instruction = SB_INSTRUCTION_CALL,
.flags = SB_INSTRUCTION_FLAG_HAB,
.tag = ROM_CALL_CMD,
.flags = ROM_CALL_CMD_FLAG_HAB,
.address = SB_IVT_LOAD_ADDR,
}, {
.instruction = SB_INSTRUCTION_LOAD,
.tag = ROM_LOAD_CMD,
.address = SB_UBOOT_LOAD_ADDR,
/* .payload is loaded at run time. */
/* .length is loaded at run time. */
}, {
.instruction = SB_INSTRUCTION_LOAD,
.tag = ROM_LOAD_CMD,
.address = SB_IVT_LOAD_ADDR,
.payload = (uint8_t *)&sb_uboot_ivt,
.length = sizeof(sb_uboot_ivt),
}, {
.instruction = SB_INSTRUCTION_CALL,
.flags = SB_INSTRUCTION_FLAG_HAB,
.tag = ROM_CALL_CMD,
.flags = ROM_CALL_CMD_FLAG_HAB,
.address = SB_IVT_LOAD_ADDR,
}
};
......@@ -267,11 +267,11 @@ static int sb_get_sections_block_size(void)
{
struct sb_source_entry *src = sb_get_boot_list(target_cpu);
unsigned int insts = sb_get_boot_list_size(target_cpu);
unsigned int size = insts * sizeof(struct sb_instruction);
unsigned int size = insts * sizeof(struct sb_command);
unsigned int i;
for(i = 0; i < sb_get_boot_list_size(target_cpu); i++, src++)
if(src->instruction == SB_INSTRUCTION_LOAD)
if(src->tag == ROM_LOAD_CMD)
size += src->length;
return size / SB_BLOCK_SIZE;
......@@ -339,7 +339,7 @@ static void sb_encrypt_sb_sections_header(
uint8_t *sb_sections_header_ptr = (uint8_t *)sb_sections_header;
const int size = sizeof(*sb_sections_header);
/* Skip the "TAG" instruction. */
/* Skip the "TAG" tag. */
sb_sections_header->section_offset = tag_offset + 1;
sb_sections_header->section_size = sb_get_sections_block_size() - 1;
/* Section #0 is bootable. */
......@@ -364,51 +364,51 @@ static void sb_encrypt_key_dictionary_key(
EVP_DigestUpdate(md_ctx, sb_dict_key, sizeof(*sb_dict_key));
}
static uint8_t sb_instruction_checksum(struct sb_instruction *inst)
static uint8_t sb_command_checksum(struct sb_command *inst)
{
uint8_t *inst_ptr = (uint8_t *)inst;
uint8_t csum = 0;
unsigned int i;
for(i = 0; i < sizeof(struct sb_instruction); i++)
for(i = 0; i < sizeof(struct sb_command); i++)
csum += inst_ptr[i];
return csum;
}
static void sb_encrypt_instruction(
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_instruction)])
uint8_t result[sizeof(struct sb_command)])
{
struct sb_instruction inst = {
struct sb_command inst = {
.header = {
.checksum = 0x5a,
.instruction = src->instruction,
.tag = src->tag,
.flags = src->flags,
},
};
uint8_t *inst_ptr = (uint8_t *)&inst;
switch (src->instruction) {
case SB_INSTRUCTION_TAG:
switch (src->tag) {
case ROM_TAG_CMD:
inst.tag.section_number = 0;
inst.tag.section_length = sb_get_sections_block_size() - 1;
inst.tag.section_flags = SB_SECTION_FLAG_BOOTABLE;
break;
case SB_INSTRUCTION_LOAD:
case ROM_LOAD_CMD:
inst.load.address = src->address;
inst.load.length = src->length;
inst.load.crc32 = crc32(src->payload, src->length);
break;
case SB_INSTRUCTION_CALL:
case ROM_CALL_CMD:
inst.call.address = src->address;
break;
default:
printf("Error\n");
}
inst.header.checksum = sb_instruction_checksum(&inst);
inst.header.checksum = sb_command_checksum(&inst);
sb_aes_encrypt(cipher_ctx, inst_ptr, inst_ptr, sizeof(inst));
EVP_DigestUpdate(md_ctx, inst_ptr, sizeof(inst));
......@@ -432,7 +432,7 @@ static int sb_create_image(struct sb_boot_image_header *sb_header,
/* The currect offset in the SB image. */
size_t image_offset = 0;
/* Save offset of the TAG instruction. */
/* Save offset of the TAG tag. */
uint32_t tag_offset = sb_header_template.image_blocks;
/* Start image-wide crypto. */
......@@ -483,9 +483,9 @@ static int sb_create_image(struct sb_boot_image_header *sb_header,
sb_emit_data(*image, &image_offset, &sb_dict_key, sizeof(sb_dict_key));
/*
* Section #0 instructions.
* Section #0 tags.
*/
uint8_t encrypted_instruction[sizeof(struct sb_instruction)];
uint8_t encrypted_tag[sizeof(struct sb_command)];
struct sb_source_entry *src;
struct sb_source_entry *lst = sb_get_boot_list(target_cpu);
......@@ -493,14 +493,14 @@ static int sb_create_image(struct sb_boot_image_header *sb_header,
for (i = 0; i < sb_get_boot_list_size(target_cpu); i++) {
src = &lst[i];
sb_encrypt_instruction(&cipher_ctx, &md_ctx,
src, encrypted_instruction);
sb_emit_data(*image, &image_offset, encrypted_instruction,
sizeof(struct sb_instruction));
sb_encrypt_tag(&cipher_ctx, &md_ctx,
src, encrypted_tag);
sb_emit_data(*image, &image_offset, encrypted_tag,
sizeof(struct sb_command));
if(src->instruction == SB_INSTRUCTION_TAG) {
if(src->tag == ROM_TAG_CMD) {
sb_aes_reinit(&cipher_ctx, sb_header_ptr);
} else if(src->instruction == SB_INSTRUCTION_LOAD) {
} else if(src->tag == ROM_LOAD_CMD) {
sb_aes_encrypt(&cipher_ctx, src->payload, src->payload, src->length);
EVP_DigestUpdate(&md_ctx, src->payload, src->length);
sb_emit_data(*image, &image_offset, src->payload, src->length);
......
......@@ -94,8 +94,8 @@ struct sb_ivt_header {
SB_HAB_VERSION \
)
#define SB_INSTRUCTION_FLAG_HAB 0x1
#define SB_INSTRUCTION_FLAG_LAST_TAG 0x1
#define ROM_CALL_CMD_FLAG_HAB 0x1
#define ROM_TAG_CMD_FLAG_LAST_TAG 0x1
struct sb_sections_header {
uint32_t section_number; /* Section number. */
......@@ -106,10 +106,10 @@ struct sb_sections_header {
#define SB_SECTION_FLAG_BOOTABLE (1 << 0)
struct sb_instruction {
struct sb_command {
struct {
uint8_t checksum;
uint8_t instruction;
uint8_t tag;
uint16_t flags;
} header;
......@@ -134,12 +134,12 @@ struct sb_instruction {
};
};
#define SB_INSTRUCTION_TAG 0x1
#define SB_INSTRUCTION_LOAD 0x2
#define SB_INSTRUCTION_CALL 0x5
#define ROM_TAG_CMD 0x1
#define ROM_LOAD_CMD 0x2
#define ROM_CALL_CMD 0x5
struct sb_source_entry {
uint8_t instruction;
uint8_t tag;
uint32_t address;
uint32_t flags;
uint8_t *payload;
......
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