diff options
author | Amaury Pouly <amaury.pouly@gmail.com> | 2013-08-22 14:39:46 +0200 |
---|---|---|
committer | Amaury Pouly <amaury.pouly@gmail.com> | 2013-08-22 14:39:46 +0200 |
commit | 260399ee8c44970aaa1cc9fd27db20df96604c5d (patch) | |
tree | a0e9ae8de0de9c8f656d7a64759209e4183fd747 /utils/imxtools/sbtools/elftosb.c | |
parent | a122b52d66464db7310022872e9eed1e55ea980c (diff) | |
download | rockbox-260399ee8c44970aaa1cc9fd27db20df96604c5d.tar.gz rockbox-260399ee8c44970aaa1cc9fd27db20df96604c5d.zip |
sbtools: more work on sbtoelf and elftosb, support more attributes
Now handle timestamp, sb minor version, component/product versions,
section flags.
Change-Id: I35313efe60c28f04ea3732b36e5e01be3213cf9e
Diffstat (limited to 'utils/imxtools/sbtools/elftosb.c')
-rw-r--r-- | utils/imxtools/sbtools/elftosb.c | 82 |
1 files changed, 49 insertions, 33 deletions
diff --git a/utils/imxtools/sbtools/elftosb.c b/utils/imxtools/sbtools/elftosb.c index c904e42f79..b65b65d402 100644 --- a/utils/imxtools/sbtools/elftosb.c +++ b/utils/imxtools/sbtools/elftosb.c @@ -118,13 +118,51 @@ static void load_bin_by_id(struct cmd_file_t *cmd_file, const char *id) src->loaded = true; } +static const char *get_str_opt(struct cmd_option_t *opt_list, const char *id, const char *dflt) +{ + struct cmd_option_t *opt = db_find_option_by_id(opt_list, id); + if(!opt) + return dflt; + if(!opt->is_string) + bug("'%s' option must be a string\n", id); + return opt->str; +} + +static uint32_t get_int_opt(struct cmd_option_t *opt_list, const char *id, uint32_t dflt) +{ + struct cmd_option_t *opt = db_find_option_by_id(opt_list, id); + if(!opt) + return dflt; + if(opt->is_string) + bug("'%s' option must be an integer\n", id); + return opt->val; +} + static struct sb_file_t *apply_cmd_file(struct cmd_file_t *cmd_file) { struct sb_file_t *sb = xmalloc(sizeof(struct sb_file_t)); memset(sb, 0, sizeof(struct sb_file_t)); - - db_generate_default_sb_version(&sb->product_ver); - db_generate_default_sb_version(&sb->component_ver); + sb_build_default_image(sb); + + if(db_find_option_by_id(cmd_file->opt_list, "componentVersion") && + !db_parse_sb_version(&sb->component_ver, get_str_opt(cmd_file->opt_list, "componentVersion", ""))) + bug("Invalid 'componentVersion' format\n"); + if(db_find_option_by_id(cmd_file->opt_list, "productVersion") && + !db_parse_sb_version(&sb->product_ver, get_str_opt(cmd_file->opt_list, "productVersion", ""))) + bug("Invalid 'productVersion' format\n"); + if(db_find_option_by_id(cmd_file->opt_list, "sbMinorVersion")) + sb->minor_version = get_int_opt(cmd_file->opt_list, "sbMinorVersion", 0); + if(db_find_option_by_id(cmd_file->opt_list, "flags")) + sb->flags = get_int_opt(cmd_file->opt_list, "flags", 0); + if(db_find_option_by_id(cmd_file->opt_list, "driveTag")) + sb->drive_tag = get_int_opt(cmd_file->opt_list, "driveTag", 0); + if(db_find_option_by_id(cmd_file->opt_list, "timestampLow")) + { + if(!db_find_option_by_id(cmd_file->opt_list, "timestampHigh")) + bug("Option 'timestampLow' and 'timestampHigh' must both specified\n"); + sb->timestamp = (uint64_t)get_int_opt(cmd_file->opt_list, "timestampHigh", 0) << 32 | + get_int_opt(cmd_file->opt_list, "timestampLow", 0); + } if(g_debug) printf("Applying command file...\n"); @@ -149,32 +187,16 @@ static struct sb_file_t *apply_cmd_file(struct cmd_file_t *cmd_file) do { /* cleartext */ - struct cmd_option_t *opt = db_find_option_by_id(csec->opt_list, "cleartext"); - if(opt != NULL) - { - if(opt->is_string) - bug("Cleartext section attribute must be an integer\n"); - if(opt->val != 0 && opt->val != 1) - bug("Cleartext section attribute must be 0 or 1\n"); - sec->is_cleartext = opt->val; - } + sec->is_cleartext = get_int_opt(csec->opt_list, "cleartext", false); /* alignment */ - opt = db_find_option_by_id(csec->opt_list, "alignment"); - if(opt != NULL) - { - if(opt->is_string) - bug("Cleartext section attribute must be an integer\n"); - // n is a power of 2 iff n & (n - 1) = 0 - // alignement cannot be lower than block size - if((opt->val & (opt->val - 1)) != 0) - bug("Cleartext section attribute must be a power of two\n"); - if(opt->val < BLOCK_SIZE) - sec->alignment = BLOCK_SIZE; - else - sec->alignment = opt->val; - } - else + sec->alignment = get_int_opt(csec->opt_list, "alignment", BLOCK_SIZE); + // alignement cannot be lower than block size + if((sec->alignment & (sec->alignment - 1)) != 0) + bug("Alignment section attribute must be a power of two\n"); + if(sec->alignment < BLOCK_SIZE) sec->alignment = BLOCK_SIZE; + /* other flags */ + sec->other_flags = get_int_opt(csec->opt_list, "sectionFlags", 0) & ~SECTION_STD_MASK; }while(0); if(csec->is_data) @@ -424,12 +446,6 @@ int main(int argc, char **argv) memcpy(sb_file->crypto_iv, crypto_iv.u.key, 16); } - /* fill with default parameters since there is no command file support for them */ - sb_file->drive_tag = 0; - sb_file->first_boot_sec_id = sb_file->sections[0].identifier; - sb_file->flags = 0; - sb_file->minor_version = 1; - sb_write_file(sb_file, output_filename, 0, generic_std_printf); sb_free(sb_file); clear_keys(); |