diff options
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) | |||
118 | src->loaded = true; | 118 | src->loaded = true; |
119 | } | 119 | } |
120 | 120 | ||
121 | static const char *get_str_opt(struct cmd_option_t *opt_list, const char *id, const char *dflt) | ||
122 | { | ||
123 | struct cmd_option_t *opt = db_find_option_by_id(opt_list, id); | ||
124 | if(!opt) | ||
125 | return dflt; | ||
126 | if(!opt->is_string) | ||
127 | bug("'%s' option must be a string\n", id); | ||
128 | return opt->str; | ||
129 | } | ||
130 | |||
131 | static uint32_t get_int_opt(struct cmd_option_t *opt_list, const char *id, uint32_t dflt) | ||
132 | { | ||
133 | struct cmd_option_t *opt = db_find_option_by_id(opt_list, id); | ||
134 | if(!opt) | ||
135 | return dflt; | ||
136 | if(opt->is_string) | ||
137 | bug("'%s' option must be an integer\n", id); | ||
138 | return opt->val; | ||
139 | } | ||
140 | |||
121 | static struct sb_file_t *apply_cmd_file(struct cmd_file_t *cmd_file) | 141 | static struct sb_file_t *apply_cmd_file(struct cmd_file_t *cmd_file) |
122 | { | 142 | { |
123 | struct sb_file_t *sb = xmalloc(sizeof(struct sb_file_t)); | 143 | struct sb_file_t *sb = xmalloc(sizeof(struct sb_file_t)); |
124 | memset(sb, 0, sizeof(struct sb_file_t)); | 144 | memset(sb, 0, sizeof(struct sb_file_t)); |
125 | 145 | sb_build_default_image(sb); | |
126 | db_generate_default_sb_version(&sb->product_ver); | 146 | |
127 | db_generate_default_sb_version(&sb->component_ver); | 147 | if(db_find_option_by_id(cmd_file->opt_list, "componentVersion") && |
148 | !db_parse_sb_version(&sb->component_ver, get_str_opt(cmd_file->opt_list, "componentVersion", ""))) | ||
149 | bug("Invalid 'componentVersion' format\n"); | ||
150 | if(db_find_option_by_id(cmd_file->opt_list, "productVersion") && | ||
151 | !db_parse_sb_version(&sb->product_ver, get_str_opt(cmd_file->opt_list, "productVersion", ""))) | ||
152 | bug("Invalid 'productVersion' format\n"); | ||
153 | if(db_find_option_by_id(cmd_file->opt_list, "sbMinorVersion")) | ||
154 | sb->minor_version = get_int_opt(cmd_file->opt_list, "sbMinorVersion", 0); | ||
155 | if(db_find_option_by_id(cmd_file->opt_list, "flags")) | ||
156 | sb->flags = get_int_opt(cmd_file->opt_list, "flags", 0); | ||
157 | if(db_find_option_by_id(cmd_file->opt_list, "driveTag")) | ||
158 | sb->drive_tag = get_int_opt(cmd_file->opt_list, "driveTag", 0); | ||
159 | if(db_find_option_by_id(cmd_file->opt_list, "timestampLow")) | ||
160 | { | ||
161 | if(!db_find_option_by_id(cmd_file->opt_list, "timestampHigh")) | ||
162 | bug("Option 'timestampLow' and 'timestampHigh' must both specified\n"); | ||
163 | sb->timestamp = (uint64_t)get_int_opt(cmd_file->opt_list, "timestampHigh", 0) << 32 | | ||
164 | get_int_opt(cmd_file->opt_list, "timestampLow", 0); | ||
165 | } | ||
128 | 166 | ||
129 | if(g_debug) | 167 | if(g_debug) |
130 | printf("Applying command file...\n"); | 168 | printf("Applying command file...\n"); |
@@ -149,32 +187,16 @@ static struct sb_file_t *apply_cmd_file(struct cmd_file_t *cmd_file) | |||
149 | do | 187 | do |
150 | { | 188 | { |
151 | /* cleartext */ | 189 | /* cleartext */ |
152 | struct cmd_option_t *opt = db_find_option_by_id(csec->opt_list, "cleartext"); | 190 | sec->is_cleartext = get_int_opt(csec->opt_list, "cleartext", false); |
153 | if(opt != NULL) | ||
154 | { | ||
155 | if(opt->is_string) | ||
156 | bug("Cleartext section attribute must be an integer\n"); | ||
157 | if(opt->val != 0 && opt->val != 1) | ||
158 | bug("Cleartext section attribute must be 0 or 1\n"); | ||
159 | sec->is_cleartext = opt->val; | ||
160 | } | ||
161 | /* alignment */ | 191 | /* alignment */ |
162 | opt = db_find_option_by_id(csec->opt_list, "alignment"); | 192 | sec->alignment = get_int_opt(csec->opt_list, "alignment", BLOCK_SIZE); |
163 | if(opt != NULL) | 193 | // alignement cannot be lower than block size |
164 | { | 194 | if((sec->alignment & (sec->alignment - 1)) != 0) |
165 | if(opt->is_string) | 195 | bug("Alignment section attribute must be a power of two\n"); |
166 | bug("Cleartext section attribute must be an integer\n"); | 196 | if(sec->alignment < BLOCK_SIZE) |
167 | // n is a power of 2 iff n & (n - 1) = 0 | ||
168 | // alignement cannot be lower than block size | ||
169 | if((opt->val & (opt->val - 1)) != 0) | ||
170 | bug("Cleartext section attribute must be a power of two\n"); | ||
171 | if(opt->val < BLOCK_SIZE) | ||
172 | sec->alignment = BLOCK_SIZE; | ||
173 | else | ||
174 | sec->alignment = opt->val; | ||
175 | } | ||
176 | else | ||
177 | sec->alignment = BLOCK_SIZE; | 197 | sec->alignment = BLOCK_SIZE; |
198 | /* other flags */ | ||
199 | sec->other_flags = get_int_opt(csec->opt_list, "sectionFlags", 0) & ~SECTION_STD_MASK; | ||
178 | }while(0); | 200 | }while(0); |
179 | 201 | ||
180 | if(csec->is_data) | 202 | if(csec->is_data) |
@@ -424,12 +446,6 @@ int main(int argc, char **argv) | |||
424 | memcpy(sb_file->crypto_iv, crypto_iv.u.key, 16); | 446 | memcpy(sb_file->crypto_iv, crypto_iv.u.key, 16); |
425 | } | 447 | } |
426 | 448 | ||
427 | /* fill with default parameters since there is no command file support for them */ | ||
428 | sb_file->drive_tag = 0; | ||
429 | sb_file->first_boot_sec_id = sb_file->sections[0].identifier; | ||
430 | sb_file->flags = 0; | ||
431 | sb_file->minor_version = 1; | ||
432 | |||
433 | sb_write_file(sb_file, output_filename, 0, generic_std_printf); | 449 | sb_write_file(sb_file, output_filename, 0, generic_std_printf); |
434 | sb_free(sb_file); | 450 | sb_free(sb_file); |
435 | clear_keys(); | 451 | clear_keys(); |