Commit 443eb3f3 authored by Marek Vasut's avatar Marek Vasut

mxssb: Reorder the functions

No functional change in the code, just reorder the functions so
they are not in such a state of chaos.
Signed-off-by: Marek Vasut's avatarMarek Vasut <marex@denx.de>
parent 6d63ee6c
......@@ -339,18 +339,6 @@ static void sb_encrypt_key_dictionary_key(struct sb_image_ctx *ictx,
EVP_DigestUpdate(md_ctx, sb_dict_key, sizeof(*sb_dict_key));
}
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_command); i++)
csum += inst_ptr[i];
return csum;
}
static void sb_encrypt_tag(struct sb_image_ctx *ictx,
struct sb_cmd_ctx *cctx)
{
......@@ -362,12 +350,6 @@ static void sb_encrypt_tag(struct sb_image_ctx *ictx,
EVP_DigestUpdate(md_ctx, &cctx->c_payload, sizeof(*cmd));
}
static void sb_emit_data(uint8_t *image, size_t *offset, void *data, size_t len)
{
memcpy(image + *offset, data, len);
*offset += len;
}
static int sb_create_image(struct sb_image_ctx *ictx)
{
/* Start image-wide crypto. */
......@@ -438,6 +420,12 @@ static int sb_create_image(struct sb_image_ctx *ictx)
return 0;
}
static void sb_emit_data(uint8_t *image, size_t *offset, void *data, size_t len)
{
memcpy(image + *offset, data, len);
*offset += len;
}
static int sb_assemble_image(struct sb_image_ctx *ictx, uint8_t **image)
{
struct sb_boot_image_header *sb_header = &ictx->payload;
......@@ -483,16 +471,6 @@ static int sb_assemble_image(struct sb_image_ctx *ictx, uint8_t **image)
return 0;
}
static int sb_load_binary(const char *filename, const unsigned int spl)
{
const int slot = sb_get_boot_list_payload_slot(target_cpu, spl);
struct sb_source_entry *lst = sb_get_boot_list(target_cpu);
lst[slot].filename = (char *)filename;
return 0;
}
static int sb_save_image(const char *filename, uint8_t *image, int len)
{
int fd;
......@@ -512,36 +490,6 @@ static int sb_save_image(const char *filename, uint8_t *image, int len)
return 0;
}
static void print_help(const char *pn)
{
printf(
"Usage: %s -c CPU -s FILE -u FILE -o FILE [-v] [-h]\n\n"
" -c CPU ...... CPU model (\"mx23\" or \"mx28\")\n"
" -s FILE ..... path to U-Boot SPL (spl/u-boot-spl.bin)\n"
" -u FILE ..... path to U-Boot (u-boot.bin)\n"
" -o FILE ..... path to output SB file (u-boot.sb)\n"
" -v .......... verbose boot output from BootROM\n"
" -h .......... print help\n", pn);
}
static int set_cpu(const char *pn, const char *cpu)
{
if (!strcmp("mx23", cpu)) {
target_cpu = CPU_MX23;
return 0;
}
if (!strcmp("mx28", cpu)) {
target_cpu = CPU_MX28;
return 0;
}
fprintf(stderr, "ERROR: Invalid CPU model selected (\"%s\")!\n\n", cpu);
print_help(pn);
return -1;
}
static int sb_load_file(struct sb_cmd_ctx *cctx, struct sb_source_entry *src)
{
off_t real_size, roundup_size;
......@@ -587,6 +535,18 @@ err_open:
return -EINVAL;
}
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_command); i++)
csum += inst_ptr[i];
return csum;
}
static int sb_tag_to_command(struct sb_source_entry *src,
struct sb_cmd_ctx *cctx)
{
......@@ -928,6 +888,46 @@ static void sb_free_image(struct sb_image_ctx *ictx)
}
}
static int sb_load_binary(const char *filename, const unsigned int spl)
{
const int slot = sb_get_boot_list_payload_slot(target_cpu, spl);
struct sb_source_entry *lst = sb_get_boot_list(target_cpu);
lst[slot].filename = (char *)filename;
return 0;
}
static void print_help(const char *pn)
{
printf(
"Usage: %s -c CPU -s FILE -u FILE -o FILE [-v] [-h]\n\n"
" -c CPU ...... CPU model (\"mx23\" or \"mx28\")\n"
" -s FILE ..... path to U-Boot SPL (spl/u-boot-spl.bin)\n"
" -u FILE ..... path to U-Boot (u-boot.bin)\n"
" -o FILE ..... path to output SB file (u-boot.sb)\n"
" -v .......... verbose boot output from BootROM\n"
" -h .......... print help\n", pn);
}
static int set_cpu(const char *pn, const char *cpu)
{
if (!strcmp("mx23", cpu)) {
target_cpu = CPU_MX23;
return 0;
}
if (!strcmp("mx28", cpu)) {
target_cpu = CPU_MX28;
return 0;
}
fprintf(stderr, "ERROR: Invalid CPU model selected (\"%s\")!\n\n", cpu);
print_help(pn);
return -1;
}
int main(int argc, char **argv)
{
uint8_t *image = NULL;
......
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