Commit 29b35780 authored by Marek Vasut's avatar Marek Vasut
Browse files

mxssb: Add MX23 support



Add support for i.MX23 u-boot.sb generation.
Signed-off-by: Marek Vasut's avatarMarek Vasut <marex@denx.de>
parent 2aa86681
......@@ -26,6 +26,11 @@
#include "mxssb.h"
enum {
CPU_MX23,
CPU_MX28,
};
static int target_cpu = -1;
static int verbose_boot = 0;
#define SB_IVT_LOAD_ADDR 0x8000
......@@ -45,6 +50,29 @@ static struct sb_ivt_header sb_uboot_ivt = {
.self = SB_IVT_LOAD_ADDR,
};
static struct sb_source_entry mx23_boot_list[] = {
{
.instruction = SB_INSTRUCTION_TAG,
.flags = SB_INSTRUCTION_FLAG_LAST_TAG,
}, {
.instruction = SB_INSTRUCTION_LOAD,
.address = SB_SPL_LOAD_ADDR,
/* .payload is loaded at run time. */
/* .length is loaded at run time. */
}, {
.instruction = SB_INSTRUCTION_CALL,
.address = SB_SPL_ENTRY_ADDR,
}, {
.instruction = SB_INSTRUCTION_LOAD,
.address = SB_UBOOT_LOAD_ADDR,
/* .payload is loaded at run time. */
/* .length is loaded at run time. */
}, {
.instruction = SB_INSTRUCTION_CALL,
.address = SB_UBOOT_LOAD_ADDR,
}
};
static struct sb_source_entry mx28_boot_list[] = {
{
.instruction = SB_INSTRUCTION_TAG,
......@@ -77,7 +105,7 @@ static struct sb_source_entry mx28_boot_list[] = {
.instruction = SB_INSTRUCTION_CALL,
.flags = SB_INSTRUCTION_FLAG_HAB,
.address = SB_IVT_LOAD_ADDR,
}
}
};
static struct sb_boot_image_header sb_header_template = {
......@@ -196,14 +224,53 @@ static uint32_t crc32(uint8_t *data, int len)
/*
* Code
*/
static struct sb_source_entry *sb_get_boot_list(const int cpu)
{
switch (cpu) {
case CPU_MX23:
return mx23_boot_list;
case CPU_MX28:
return mx28_boot_list;
}
return 0;
}
static int sb_get_boot_list_size(const int cpu)
{
switch (cpu) {
case CPU_MX23:
return ARRAY_SIZE(mx23_boot_list);
case CPU_MX28:
return ARRAY_SIZE(mx28_boot_list);
}
return 0;
}
static int sb_get_boot_list_payload_slot(const int cpu, const int spl)
{
if (spl)
return 1;
switch (cpu) {
case CPU_MX23:
return 3;
case CPU_MX28:
return 4;
}
return 0;
}
static int sb_get_sections_block_size(void)
{
struct sb_source_entry *src = mx28_boot_list;
unsigned int insts = ARRAY_SIZE(mx28_boot_list);
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 i;
for(i = 0; i < ARRAY_SIZE(mx28_boot_list); i++, src++)
for(i = 0; i < sb_get_boot_list_size(target_cpu); i++, src++)
if(src->instruction == SB_INSTRUCTION_LOAD)
size += src->length;
......@@ -420,11 +487,12 @@ static int sb_create_image(struct sb_boot_image_header *sb_header,
*/
uint8_t encrypted_instruction[sizeof(struct sb_instruction)];
struct sb_source_entry *src;
struct sb_source_entry *lst = sb_get_boot_list(target_cpu);
sb_aes_reinit(&cipher_ctx, sb_header_ptr);
for (i = 0; i < ARRAY_SIZE(mx28_boot_list); i++) {
src = &mx28_boot_list[i];
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,
......@@ -457,12 +525,14 @@ static int sb_create_image(struct sb_boot_image_header *sb_header,
return 0;
}
static int sb_load_binary(const char *filename, const unsigned int slot)
static int sb_load_binary(const char *filename, const unsigned int spl)
{
off_t real_size, roundup_size;
uint8_t *data;
int fd, ret;
const int slot = sb_get_boot_list_payload_slot(target_cpu, spl);
struct sb_source_entry *lst = sb_get_boot_list(target_cpu);
fd = open(filename, O_RDONLY);
if (fd < 0)
goto err_open;
......@@ -482,8 +552,8 @@ static int sb_load_binary(const char *filename, const unsigned int slot)
if (ret != real_size)
goto err_alloc;
mx28_boot_list[slot].payload = data;
mx28_boot_list[slot].length = roundup_size;
lst[slot].payload = data;
lst[slot].length = roundup_size;
close(fd);
return 0;
......@@ -497,9 +567,12 @@ err_open:
return -EINVAL;
}
static void sb_unload_binary(const unsigned int slot)
static void sb_unload_binary(const unsigned int spl)
{
free(mx28_boot_list[slot].payload);
const int slot = sb_get_boot_list_payload_slot(target_cpu, spl);
struct sb_source_entry *lst = sb_get_boot_list(target_cpu);
free(lst[slot].payload);
}
static int sb_save_image(const char *filename, uint8_t *image, int len)
......@@ -524,7 +597,8 @@ static int sb_save_image(const char *filename, uint8_t *image, int len)
static void print_help(const char *pn)
{
printf(
"Usage: %s -s FILE -u FILE -o FILE [-v] [-h]\n\n"
"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"
......@@ -532,6 +606,24 @@ static void print_help(const char *pn)
" -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;
......@@ -542,8 +634,13 @@ int main(int argc, char **argv)
char *spl_filename = NULL;
char *uboot_filename = NULL;
while ((opt = getopt(argc, argv, "s:u:o:v:h")) != -1) {
while ((opt = getopt(argc, argv, "c:s:u:o:vh")) != -1) {
switch (opt) {
case 'c':
ret = set_cpu(argv[0], optarg);
if (ret)
return ret;
break;
case 's':
spl_filename = optarg;
break;
......@@ -566,7 +663,7 @@ int main(int argc, char **argv)
}
}
if (optind >= argc) {
if (optind != argc) {
fprintf(stderr, "ERROR: Expected argument after options!\n\n");
print_help(argv[0]);
return -1;
......@@ -582,7 +679,7 @@ int main(int argc, char **argv)
if (ret)
return ret;
ret = sb_load_binary(uboot_filename, 4);
ret = sb_load_binary(uboot_filename, 0);
if (ret)
return ret;
......@@ -594,7 +691,7 @@ int main(int argc, char **argv)
ret = sb_save_image(output_filename, image, image_size);
sb_unload_binary(1);
sb_unload_binary(4);
sb_unload_binary(0);
free(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