Commit 81f302c2 authored by Marek Vasut's avatar Marek Vasut

mxssb: Streamline section count calculation and bootable flag handling

The section count can be calculated while parsing the configuration
file. Do it and then use it when filling the SB image header. Moreover,
the bootable section and possible multiple bootable sections collision
can also be much better identified while parsing the configuration file.
Signed-off-by: Marek Vasut's avatarMarek Vasut <marex@denx.de>
parent b9b3cf68
......@@ -76,17 +76,23 @@ struct sb_section_ctx {
};
struct sb_image_ctx {
enum sb_target_cpu target_cpu;
/* Image configuration */
unsigned int verbose_boot:1;
enum sb_target_cpu target_cpu;
char *cfg_filename;
/* Number of section in the image */
unsigned int sect_count;
/* Bootable section */
unsigned int sect_boot;
unsigned int sect_boot_found:1;
struct sb_section_ctx *sect_head;
struct sb_section_ctx *sect_tail;
EVP_CIPHER_CTX cipher_ctx;
EVP_MD_CTX md_ctx;
int section_count;
uint8_t digest[32];
char *cfg_filename;
struct sb_key_dictionary_key sb_dict_key;
struct sb_boot_image_header payload;
......@@ -526,7 +532,19 @@ static int sb_build_section(struct sb_image_ctx *ictx, struct sb_cmd_list *cmd)
* WARNING: The section size is still not computed and will
* be updated while parsing it's commands.
*/
ictx->section_count++;
ictx->sect_count++;
/* Mark that this section is bootable one. */
if (bootable) {
if (ictx->sect_boot_found) {
fprintf(stderr, "#%i WARN: Multiple bootable section!\n",
cmd->lineno);
} else {
ictx->sect_boot = id;
ictx->sect_boot_found = 1;
}
}
if (!ictx->sect_head) {
ictx->sect_head = sctx;
ictx->sect_tail = sctx;
......@@ -877,7 +895,6 @@ static int sb_postfill_image_header(struct sb_image_ctx *ictx)
struct sb_boot_image_header *hdr = &ictx->payload;
struct sb_section_ctx *sctx = ictx->sect_head;
uint32_t kd_size, sections_blocks;
signed int bootable_section = -1;
EVP_MD_CTX md_ctx;
/* The main SB header size in blocks. */
......@@ -888,31 +905,17 @@ static int sb_postfill_image_header(struct sb_image_ctx *ictx)
hdr->image_blocks += kd_size / SB_BLOCK_SIZE;
/* Now count the payloads. */
hdr->section_count = 0;
hdr->section_count = ictx->sect_count;
while (sctx) {
/* Check if this section is bootable. */
if (sctx->boot) {
if (bootable_section < 0)
bootable_section = hdr->section_count;
else
fprintf(stderr, "WARN: Multiple bootable sections!\n");
}
hdr->image_blocks += sctx->size / SB_BLOCK_SIZE;
/* Check for degenerated section. */
if (!sctx->cmd_head)
fprintf(stderr, "WARN: Empty section!\n");
/* Move section pointer. */
sctx = sctx->sect;
hdr->section_count++;
}
if (bootable_section < 0)
fprintf(stderr, "WARN: No bootable section selected!\n");
else
hdr->first_boot_section_id = bootable_section;
if (!ictx->sect_boot_found) {
fprintf(stderr, "ERR: No bootable section selected!\n");
return -EINVAL;
}
hdr->first_boot_section_id = ictx->sect_boot;
/* The n * SB section size in blocks. */
sections_blocks = hdr->section_count * hdr->section_header_size;
......
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