diff options
-rw-r--r-- | utils/imxtools/sbtools/elf.c | 5 | ||||
-rw-r--r-- | utils/imxtools/sbtools/elf.h | 1 | ||||
-rw-r--r-- | utils/imxtools/sbtools/sbtoelf.c | 52 |
3 files changed, 54 insertions, 4 deletions
diff --git a/utils/imxtools/sbtools/elf.c b/utils/imxtools/sbtools/elf.c index 481ab98dd6..53adcd1160 100644 --- a/utils/imxtools/sbtools/elf.c +++ b/utils/imxtools/sbtools/elf.c | |||
@@ -217,6 +217,11 @@ void elf_add_fill_section(struct elf_params_t *params, | |||
217 | sec->pattern = pattern; | 217 | sec->pattern = pattern; |
218 | } | 218 | } |
219 | 219 | ||
220 | void elf_simplify(struct elf_params_t *params) | ||
221 | { | ||
222 | |||
223 | } | ||
224 | |||
220 | void elf_write_file(struct elf_params_t *params, elf_write_fn_t write, | 225 | void elf_write_file(struct elf_params_t *params, elf_write_fn_t write, |
221 | elf_printf_fn_t printf, void *user) | 226 | elf_printf_fn_t printf, void *user) |
222 | { | 227 | { |
diff --git a/utils/imxtools/sbtools/elf.h b/utils/imxtools/sbtools/elf.h index 2166833276..ae4e3b4225 100644 --- a/utils/imxtools/sbtools/elf.h +++ b/utils/imxtools/sbtools/elf.h | |||
@@ -82,6 +82,7 @@ void elf_add_fill_section(struct elf_params_t *params, | |||
82 | uint32_t fill_addr, uint32_t size, uint32_t pattern); | 82 | uint32_t fill_addr, uint32_t size, uint32_t pattern); |
83 | uint32_t elf_translate_virtual_address(struct elf_params_t *params, uint32_t addr); | 83 | uint32_t elf_translate_virtual_address(struct elf_params_t *params, uint32_t addr); |
84 | void elf_translate_addresses(struct elf_params_t *params); | 84 | void elf_translate_addresses(struct elf_params_t *params); |
85 | void elf_simplify(struct elf_params_t *params); | ||
85 | void elf_write_file(struct elf_params_t *params, elf_write_fn_t write, elf_printf_fn_t printf, void *user); | 86 | void elf_write_file(struct elf_params_t *params, elf_write_fn_t write, elf_printf_fn_t printf, void *user); |
86 | bool elf_read_file(struct elf_params_t *params, elf_read_fn_t read, elf_printf_fn_t printf, | 87 | bool elf_read_file(struct elf_params_t *params, elf_read_fn_t read, elf_printf_fn_t printf, |
87 | void *user); | 88 | void *user); |
diff --git a/utils/imxtools/sbtools/sbtoelf.c b/utils/imxtools/sbtools/sbtoelf.c index 01a51cae90..f86200f184 100644 --- a/utils/imxtools/sbtools/sbtoelf.c +++ b/utils/imxtools/sbtools/sbtoelf.c | |||
@@ -157,12 +157,56 @@ static void extract_sb_file(struct sb_file_t *file) | |||
157 | extract_sb_section(&file->sections[i]); | 157 | extract_sb_section(&file->sections[i]); |
158 | } | 158 | } |
159 | 159 | ||
160 | static void extract_elf(struct elf_params_t *elf, int count) | ||
161 | { | ||
162 | char *filename = xmalloc(strlen(g_out_prefix) + 32); | ||
163 | sprintf(filename, "%s.%d.elf", g_out_prefix, count); | ||
164 | if(g_debug) | ||
165 | printf("Write boot content to %s\n", filename); | ||
166 | |||
167 | FILE *fd = fopen(filename, "wb"); | ||
168 | free(filename); | ||
169 | |||
170 | if(fd == NULL) | ||
171 | return ; | ||
172 | elf_simplify(elf); | ||
173 | elf_write_file(elf, elf_write, elf_printf, fd); | ||
174 | fclose(fd); | ||
175 | } | ||
176 | |||
160 | static void extract_sb1_file(struct sb1_file_t *file) | 177 | static void extract_sb1_file(struct sb1_file_t *file) |
161 | { | 178 | { |
162 | FILE *f = fopen(g_out_prefix, "wb"); | 179 | int elf_count = 0; |
163 | if(f == NULL) | 180 | struct elf_params_t elf; |
164 | bugp("Cannot open %s for writing\n", g_out_prefix); | 181 | elf_init(&elf); |
165 | fclose(f); | 182 | |
183 | for(int i = 0; i < file->nr_insts; i++) | ||
184 | { | ||
185 | struct sb1_inst_t *inst = &file->insts[i]; | ||
186 | switch(inst->cmd) | ||
187 | { | ||
188 | case SB1_INST_LOAD: | ||
189 | elf_add_load_section(&elf, inst->addr, inst->size, inst->data); | ||
190 | break; | ||
191 | case SB1_INST_FILL: | ||
192 | elf_add_fill_section(&elf, inst->addr, inst->size, inst->pattern); | ||
193 | break; | ||
194 | case SB1_INST_CALL: | ||
195 | case SB1_INST_JUMP: | ||
196 | elf_set_start_addr(&elf, inst->addr); | ||
197 | extract_elf(&elf, elf_count++); | ||
198 | elf_release(&elf); | ||
199 | elf_init(&elf); | ||
200 | break; | ||
201 | default: | ||
202 | /* ignore mode and nop */ | ||
203 | break; | ||
204 | } | ||
205 | } | ||
206 | |||
207 | if(!elf_is_empty(&elf)) | ||
208 | extract_elf(&elf, elf_count); | ||
209 | elf_release(&elf); | ||
166 | } | 210 | } |
167 | 211 | ||
168 | static void usage(void) | 212 | static void usage(void) |