summaryrefslogtreecommitdiff
path: root/utils/sbtools/elftosb.c
diff options
context:
space:
mode:
Diffstat (limited to 'utils/sbtools/elftosb.c')
-rw-r--r--utils/sbtools/elftosb.c595
1 files changed, 10 insertions, 585 deletions
diff --git a/utils/sbtools/elftosb.c b/utils/sbtools/elftosb.c
index cb5cc4c6db..0b659eaf26 100644
--- a/utils/sbtools/elftosb.c
+++ b/utils/sbtools/elftosb.c
@@ -37,6 +37,7 @@
37#include "crypto.h" 37#include "crypto.h"
38#include "elf.h" 38#include "elf.h"
39#include "sb.h" 39#include "sb.h"
40#include "dbparser.h"
40 41
41#define _STR(a) #a 42#define _STR(a) #a
42#define STR(a) _STR(a) 43#define STR(a) _STR(a)
@@ -76,7 +77,7 @@ void *xmalloc(size_t s) /* malloc helper, used in elf.c */
76 return r; 77 return r;
77} 78}
78 79
79static int convxdigit(char digit, byte *val) 80int convxdigit(char digit, byte *val)
80{ 81{
81 if(digit >= '0' && digit <= '9') 82 if(digit >= '0' && digit <= '9')
82 { 83 {
@@ -164,582 +165,6 @@ static key_array_t read_keys(const char *key_file, int *num_keys)
164} 165}
165 166
166/** 167/**
167 * Command file parsing
168 */
169
170enum cmd_source_type_t
171{
172 CMD_SRC_UNK,
173 CMD_SRC_ELF,
174 CMD_SRC_BIN
175};
176
177struct bin_param_t
178{
179 uint32_t size;
180 void *data;
181};
182
183struct cmd_source_t
184{
185 char *identifier;
186 char *filename;
187 struct cmd_source_t *next;
188 /* for later use */
189 enum cmd_source_type_t type;
190 bool loaded;
191 struct elf_params_t elf;
192 struct bin_param_t bin;
193};
194
195enum cmd_inst_type_t
196{
197 CMD_LOAD, /* load image */
198 CMD_JUMP, /* jump at image */
199 CMD_CALL, /* call image */
200 CMD_LOAD_AT, /* load binary at */
201 CMD_CALL_AT, /* call at address */
202 CMD_JUMP_AT, /* jump at address */
203 CMD_MODE, /* change boot mode */
204};
205
206struct cmd_inst_t
207{
208 enum cmd_inst_type_t type;
209 char *identifier;
210 uint32_t argument; // for jump, call, mode
211 uint32_t addr; // for 'at'
212 struct cmd_inst_t *next;
213};
214
215struct cmd_section_t
216{
217 uint32_t identifier;
218 struct cmd_inst_t *inst_list;
219 struct cmd_section_t *next;
220};
221
222struct cmd_file_t
223{
224 struct sb_version_t product_ver;
225 struct sb_version_t component_ver;
226 struct cmd_source_t *source_list;
227 struct cmd_section_t *section_list;
228};
229
230enum lexem_type_t
231{
232 LEX_IDENTIFIER,
233 LEX_LPAREN,
234 LEX_RPAREN,
235 LEX_NUMBER,
236 LEX_STRING, /* double-quoted string */
237 LEX_EQUAL,
238 LEX_SEMICOLON,
239 LEX_LBRACE,
240 LEX_RBRACE,
241 LEX_RANGLE,
242 LEX_EOF
243};
244
245struct lexem_t
246{
247 enum lexem_type_t type;
248 char *str;
249 uint32_t num;
250};
251
252static void __parse_string(char **ptr, char *end, void *user, void (*emit_fn)(void *user, char c))
253{
254 while(*ptr != end)
255 {
256 if(**ptr == '"')
257 break;
258 else if(**ptr == '\\')
259 {
260 (*ptr)++;
261 if(*ptr == end)
262 bug("Unfinished string\n");
263 if(**ptr == '\\') emit_fn(user, '\\');
264 else if(**ptr == '\'') emit_fn(user, '\'');
265 else if(**ptr == '\"') emit_fn(user, '\"');
266 else bug("Unknown escape sequence \\%c\n", **ptr);
267 (*ptr)++;
268 }
269 else
270 emit_fn(user, *(*ptr)++);
271 }
272 if(*ptr == end || **ptr != '"')
273 bug("unfinished string\n");
274 (*ptr)++;
275}
276
277static void __parse_string_emit(void *user, char c)
278{
279 char **pstr = (char **)user;
280 *(*pstr)++ = c;
281}
282
283static void __parse_string_count(void *user, char c)
284{
285 (void) c;
286 (*(int *)user)++;
287}
288
289static void parse_string(char **ptr, char *end, struct lexem_t *lexem)
290{
291 /* skip " */
292 (*ptr)++;
293 char *p = *ptr;
294 /* compute length */
295 int length = 0;
296 __parse_string(&p, end, (void *)&length, __parse_string_count);
297 /* parse again */
298 lexem->type = LEX_STRING;
299 lexem->str = xmalloc(length + 1);
300 lexem->str[length] = 0;
301 char *pstr = lexem->str;
302 __parse_string(ptr, end, (void *)&pstr, __parse_string_emit);
303}
304
305static void parse_ascii_number(char **ptr, char *end, struct lexem_t *lexem)
306{
307 /* skip ' */
308 (*ptr)++;
309 /* we expect 4 character and then ' */
310 int len = 0;
311 uint32_t value = 0;
312 while(*ptr != end)
313 {
314 if(**ptr != '\'')
315 {
316 value = value << 8 | **ptr;
317 len++;
318 (*ptr)++;
319 }
320 else
321 break;
322 }
323 if(*ptr == end || **ptr != '\'')
324 bug("Unterminated ascii number literal\n");
325 if(len != 1 && len != 2 && len != 4)
326 bug("Invalid ascii number literal length: only 1, 2 or 4 are valid\n");
327 /* skip ' */
328 (*ptr)++;
329 lexem->type = LEX_NUMBER;
330 lexem->num = value;
331}
332
333static void parse_number(char **ptr, char *end, struct lexem_t *lexem)
334{
335 int base = 10;
336 if(**ptr == '0' && (*ptr) + 1 != end && (*ptr)[1] == 'x')
337 {
338 (*ptr) += 2;
339 base = 16;
340 }
341
342 lexem->type = LEX_NUMBER;
343 lexem->num = 0;
344 while(*ptr != end && isxdigit(**ptr))
345 {
346 if(base == 10 && !isdigit(**ptr))
347 break;
348 byte v;
349 if(convxdigit(**ptr, &v))
350 break;
351 lexem->num = base * lexem->num + v;
352 (*ptr)++;
353 }
354}
355
356static void parse_identifier(char **ptr, char *end, struct lexem_t *lexem)
357{
358 /* remember position */
359 char *old = *ptr;
360 while(*ptr != end && (isalnum(**ptr) || **ptr == '_'))
361 (*ptr)++;
362 lexem->type = LEX_IDENTIFIER;
363 int len = *ptr - old;
364 lexem->str = xmalloc(len + 1);
365 lexem->str[len] = 0;
366 memcpy(lexem->str, old, len);
367}
368
369static void next_lexem(char **ptr, char *end, struct lexem_t *lexem)
370{
371 #define ret_simple(t, advance) ({(*ptr) += advance; lexem->type = t; return;})
372 while(*ptr != end)
373 {
374 /* skip whitespace */
375 if(**ptr == ' ' || **ptr == '\t' || **ptr == '\n' || **ptr == '\r')
376 {
377 (*ptr)++;
378 continue;
379 }
380 /* skip C++ style comments */
381 if(**ptr == '/' && (*ptr) + 1 != end && (*ptr)[1] == '/')
382 {
383 while(*ptr != end && **ptr != '\n')
384 (*ptr)++;
385 continue;
386 }
387 /* skip C-style comments */
388 if(**ptr == '/' && (*ptr) + 1 != end && (*ptr)[1] == '*')
389 {
390 (*ptr) += 2;
391 if(*ptr == end)
392 bug("invalid command file: unterminated comment");
393 while(true)
394 {
395 if(**ptr == '*' && (*ptr) + 1 != end && (*ptr)[1] == '/')
396 {
397 (*ptr) += 2;
398 break;
399 }
400 (*ptr)++;
401 }
402 continue;
403 }
404 break;
405 }
406 if(*ptr == end) ret_simple(LEX_EOF, 0);
407 if(**ptr == '(') ret_simple(LEX_LPAREN, 1);
408 if(**ptr == ')') ret_simple(LEX_RPAREN, 1);
409 if(**ptr == '{') ret_simple(LEX_LBRACE, 1);
410 if(**ptr == '}') ret_simple(LEX_RBRACE, 1);
411 if(**ptr == '>') ret_simple(LEX_RANGLE, 1);
412 if(**ptr == '=') ret_simple(LEX_EQUAL, 1);
413 if(**ptr == ';') ret_simple(LEX_SEMICOLON, 1);
414 if(**ptr == '"') return parse_string(ptr, end, lexem);
415 if(**ptr == '\'') return parse_ascii_number(ptr, end, lexem);
416 if(isdigit(**ptr)) return parse_number(ptr, end, lexem);
417 if(isalpha(**ptr) || **ptr == '_') return parse_identifier(ptr, end, lexem);
418 bug("Unexpected character '%c' in command file\n", **ptr);
419 #undef ret_simple
420}
421
422#if 0
423static void log_lexem(struct lexem_t *lexem)
424{
425 switch(lexem->type)
426 {
427 case LEX_EOF: printf("<eof>"); break;
428 case LEX_EQUAL: printf("="); break;
429 case LEX_IDENTIFIER: printf("id(%s)", lexem->str); break;
430 case LEX_LPAREN: printf("("); break;
431 case LEX_RPAREN: printf(")"); break;
432 case LEX_LBRACE: printf("{"); break;
433 case LEX_RBRACE: printf("}"); break;
434 case LEX_SEMICOLON: printf(";"); break;
435 case LEX_NUMBER: printf("num(%d)", lexem->num); break;
436 case LEX_STRING: printf("str(%s)", lexem->str); break;
437 default: printf("<unk>");
438 }
439}
440#endif
441
442static struct cmd_source_t *find_source_by_id(struct cmd_file_t *cmd_file, const char *id)
443{
444 struct cmd_source_t *src = cmd_file->source_list;
445 while(src)
446 {
447 if(strcmp(src->identifier, id) == 0)
448 return src;
449 src = src->next;
450 }
451 return NULL;
452}
453
454static void generate_default_version(struct sb_version_t *ver)
455{
456 ver->major = 0x999;
457 ver->minor = 0x999;
458 ver->revision = 0x999;
459}
460
461static uint16_t parse_sb_subversion(char *str)
462{
463 int len = strlen(str);
464 uint16_t n = 0;
465 if(len == 0 || len > 4)
466 bug("invalid command file: invalid version string");
467 for(int i = 0; i < len; i++)
468 {
469 if(!isdigit(str[i]))
470 bug("invalid command file: invalid version string");
471 n = n << 4 | (str[i] - '0');
472 }
473 return n;
474}
475
476static void parse_sb_version(struct sb_version_t *ver, char *str)
477{
478 int len = strlen(str);
479 int cnt = 0;
480 int pos[2];
481
482 for(int i = 0; i < len; i++)
483 {
484 if(str[i] != '.')
485 continue;
486 if(cnt == 2)
487 bug("invalid command file: invalid version string");
488 pos[cnt++] = i + 1;
489 str[i] = 0;
490 }
491 if(cnt != 2)
492 bug("invalid command file: invalid version string");
493 ver->major = parse_sb_subversion(str);
494 ver->minor = parse_sb_subversion(str + pos[0]);
495 ver->revision = parse_sb_subversion(str + pos[1]);
496}
497
498static struct cmd_file_t *read_command_file(const char *file)
499{
500 int size;
501 struct stat st;
502 int fd = open(file,O_RDONLY);
503 if(fd == -1)
504 bugp("opening command file failed");
505 if(fstat(fd,&st) == -1)
506 bugp("command file stat() failed");
507 size = st.st_size;
508 char *buf = xmalloc(size);
509 if(read(fd, buf, size) != (ssize_t)size)
510 bugp("reading command file");
511 close(fd);
512
513 if(g_debug)
514 printf("Parsing command file '%s'...\n", file);
515 struct cmd_file_t *cmd_file = xmalloc(sizeof(struct cmd_file_t));
516 memset(cmd_file, 0, sizeof(struct cmd_file_t));
517
518 generate_default_version(&cmd_file->product_ver);
519 generate_default_version(&cmd_file->component_ver);
520
521 struct lexem_t lexem;
522 char *p = buf;
523 char *end = buf + size;
524 #define next() next_lexem(&p, end, &lexem)
525 /* init lexer */
526 next();
527 /* options ? */
528 if(lexem.type == LEX_IDENTIFIER && !strcmp(lexem.str, "options"))
529 {
530 next();
531 if(lexem.type != LEX_LBRACE)
532 bug("invalid command file: '{' expected after 'options'\n");
533
534 while(true)
535 {
536 next();
537 if(lexem.type == LEX_RBRACE)
538 break;
539 if(lexem.type != LEX_IDENTIFIER)
540 bug("invalid command file: identifier expected in options\n");
541 char *opt = lexem.str;
542 next();
543 if(lexem.type != LEX_EQUAL)
544 bug("invalid command file: '=' expected after identifier\n");
545 next();
546 if(!strcmp(opt, "productVersion") || !strcmp(opt, "componentVersion"))
547 {
548 if(lexem.type != LEX_STRING)
549 bug("invalid command file: string expected after '='\n");
550 if(!strcmp(opt, "productVersion"))
551 parse_sb_version(&cmd_file->product_ver, lexem.str);
552 else
553 parse_sb_version(&cmd_file->component_ver, lexem.str);
554 }
555 else
556 bug("invalid command file: unknown option '%s'\n", opt);
557 next();
558 if(lexem.type != LEX_SEMICOLON)
559 bug("invalid command file: ';' expected after string\n");
560 }
561 next();
562 }
563 /* sources */
564 if(lexem.type != LEX_IDENTIFIER || strcmp(lexem.str, "sources") != 0)
565 bug("invalid command file: 'sources' expected\n");
566 next();
567 if(lexem.type != LEX_LBRACE)
568 bug("invalid command file: '{' expected after 'sources'\n");
569
570 while(true)
571 {
572 next();
573 if(lexem.type == LEX_RBRACE)
574 break;
575 struct cmd_source_t *src = xmalloc(sizeof(struct cmd_source_t));
576 memset(src, 0, sizeof(struct cmd_source_t));
577 src->next = cmd_file->source_list;
578 if(lexem.type != LEX_IDENTIFIER)
579 bug("invalid command file: identifier expected in sources\n");
580 src->identifier = lexem.str;
581 next();
582 if(lexem.type != LEX_EQUAL)
583 bug("invalid command file: '=' expected after identifier\n");
584 next();
585 if(lexem.type != LEX_STRING)
586 bug("invalid command file: string expected after '='\n");
587 src->filename = lexem.str;
588 next();
589 if(lexem.type != LEX_SEMICOLON)
590 bug("invalid command file: ';' expected after string\n");
591 if(find_source_by_id(cmd_file, src->identifier) != NULL)
592 bug("invalid command file: duplicated source identifier\n");
593 /* type filled later */
594 src->type = CMD_SRC_UNK;
595 cmd_file->source_list = src;
596 }
597
598 /* sections */
599 struct cmd_section_t *end_sec = NULL;
600 while(true)
601 {
602 struct cmd_section_t *sec = xmalloc(sizeof(struct cmd_section_t));
603 struct cmd_inst_t *end_list = NULL;
604 memset(sec, 0, sizeof(struct cmd_section_t));
605 next();
606 if(lexem.type == LEX_EOF)
607 break;
608 if(lexem.type != LEX_IDENTIFIER || strcmp(lexem.str, "section") != 0)
609 bug("invalid command file: 'section' expected\n");
610 next();
611 if(lexem.type != LEX_LPAREN)
612 bug("invalid command file: '(' expected after 'section'\n");
613 next();
614 /* can be a number or a 4 character long string */
615 if(lexem.type == LEX_NUMBER)
616 {
617 sec->identifier = lexem.num;
618 }
619 else
620 bug("invalid command file: number expected as section identifier\n");
621
622 next();
623 if(lexem.type != LEX_RPAREN)
624 bug("invalid command file: ')' expected after section identifier\n");
625 next();
626 if(lexem.type != LEX_LBRACE)
627 bug("invalid command file: '{' expected after section directive\n");
628 /* commands */
629 while(true)
630 {
631 struct cmd_inst_t *inst = xmalloc(sizeof(struct cmd_inst_t));
632 memset(inst, 0, sizeof(struct cmd_inst_t));
633 next();
634 if(lexem.type == LEX_RBRACE)
635 break;
636 if(lexem.type != LEX_IDENTIFIER)
637 bug("invalid command file: instruction expected in section\n");
638 if(strcmp(lexem.str, "load") == 0)
639 inst->type = CMD_LOAD;
640 else if(strcmp(lexem.str, "call") == 0)
641 inst->type = CMD_CALL;
642 else if(strcmp(lexem.str, "jump") == 0)
643 inst->type = CMD_JUMP;
644 else if(strcmp(lexem.str, "mode") == 0)
645 inst->type = CMD_MODE;
646 else
647 bug("invalid command file: instruction expected in section\n");
648 next();
649
650 if(inst->type == CMD_LOAD)
651 {
652 if(lexem.type != LEX_IDENTIFIER)
653 bug("invalid command file: identifier expected after instruction\n");
654 inst->identifier = lexem.str;
655 if(find_source_by_id(cmd_file, inst->identifier) == NULL)
656 bug("invalid command file: undefined reference to source '%s'\n", inst->identifier);
657 next();
658 if(lexem.type == LEX_RANGLE)
659 {
660 // load at
661 inst->type = CMD_LOAD_AT;
662 next();
663 if(lexem.type != LEX_NUMBER)
664 bug("invalid command file: number expected for loading address\n");
665 inst->addr = lexem.num;
666 next();
667 }
668 if(lexem.type != LEX_SEMICOLON)
669 bug("invalid command file: expected ';' after command\n");
670 }
671 else if(inst->type == CMD_CALL || inst->type == CMD_JUMP)
672 {
673 if(lexem.type == LEX_IDENTIFIER)
674 {
675 inst->identifier = lexem.str;
676 if(find_source_by_id(cmd_file, inst->identifier) == NULL)
677 bug("invalid command file: undefined reference to source '%s'\n", inst->identifier);
678 next();
679 }
680 else if(lexem.type == LEX_NUMBER)
681 {
682 inst->type = (inst->type == CMD_CALL) ? CMD_CALL_AT : CMD_JUMP_AT;
683 inst->addr = lexem.num;
684 next();
685 }
686 else
687 bug("invalid command file: identifier or number expected after jump/load\n");
688
689 if(lexem.type == LEX_LPAREN)
690 {
691 next();
692 if(lexem.type != LEX_NUMBER)
693 bug("invalid command file: expected numeral expression after (\n");
694 inst->argument = lexem.num;
695 next();
696 if(lexem.type != LEX_RPAREN)
697 bug("invalid command file: expected closing brace\n");
698 next();
699 }
700 if(lexem.type != LEX_SEMICOLON)
701 bug("invalid command file: expected ';' after command\n");
702 }
703 else if(inst->type == CMD_MODE)
704 {
705 if(lexem.type != LEX_NUMBER)
706 bug("invalid command file: number expected after 'mode'\n");
707 inst->argument = lexem.num;
708 next();
709 if(lexem.type != LEX_SEMICOLON)
710 bug("invalid command file: expected ';' after command\n");
711 }
712 else
713 bug("die\n");
714 if(end_list == NULL)
715 {
716 sec->inst_list = inst;
717 end_list = inst;
718 }
719 else
720 {
721 end_list->next = inst;
722 end_list = inst;
723 }
724 }
725
726 if(end_sec == NULL)
727 {
728 cmd_file->section_list = sec;
729 end_sec = sec;
730 }
731 else
732 {
733 end_sec->next = sec;
734 end_sec = sec;
735 }
736 }
737 #undef next
738
739 return cmd_file;
740}
741
742/**
743 * command file to sb conversion 168 * command file to sb conversion
744 */ 169 */
745 170
@@ -798,7 +223,7 @@ static void elf_printf(void *user, bool error, const char *fmt, ...)
798 223
799static void load_elf_by_id(struct cmd_file_t *cmd_file, const char *id) 224static void load_elf_by_id(struct cmd_file_t *cmd_file, const char *id)
800{ 225{
801 struct cmd_source_t *src = find_source_by_id(cmd_file, id); 226 struct cmd_source_t *src = db_find_source_by_id(cmd_file, id);
802 if(src == NULL) 227 if(src == NULL)
803 bug("undefined reference to source '%s'\n", id); 228 bug("undefined reference to source '%s'\n", id);
804 /* avoid reloading */ 229 /* avoid reloading */
@@ -822,7 +247,7 @@ static void load_elf_by_id(struct cmd_file_t *cmd_file, const char *id)
822 247
823static void load_bin_by_id(struct cmd_file_t *cmd_file, const char *id) 248static void load_bin_by_id(struct cmd_file_t *cmd_file, const char *id)
824{ 249{
825 struct cmd_source_t *src = find_source_by_id(cmd_file, id); 250 struct cmd_source_t *src = db_find_source_by_id(cmd_file, id);
826 if(src == NULL) 251 if(src == NULL)
827 bug("undefined reference to source '%s'\n", id); 252 bug("undefined reference to source '%s'\n", id);
828 /* avoid reloading */ 253 /* avoid reloading */
@@ -877,13 +302,13 @@ static struct sb_file_t *apply_cmd_file(struct cmd_file_t *cmd_file)
877 if(cinst->type == CMD_LOAD) 302 if(cinst->type == CMD_LOAD)
878 { 303 {
879 load_elf_by_id(cmd_file, cinst->identifier); 304 load_elf_by_id(cmd_file, cinst->identifier);
880 struct elf_params_t *elf = &find_source_by_id(cmd_file, cinst->identifier)->elf; 305 struct elf_params_t *elf = &db_find_source_by_id(cmd_file, cinst->identifier)->elf;
881 sec->nr_insts += elf_get_nr_sections(elf); 306 sec->nr_insts += elf_get_nr_sections(elf);
882 } 307 }
883 else if(cinst->type == CMD_JUMP || cinst->type == CMD_CALL) 308 else if(cinst->type == CMD_JUMP || cinst->type == CMD_CALL)
884 { 309 {
885 load_elf_by_id(cmd_file, cinst->identifier); 310 load_elf_by_id(cmd_file, cinst->identifier);
886 struct elf_params_t *elf = &find_source_by_id(cmd_file, cinst->identifier)->elf; 311 struct elf_params_t *elf = &db_find_source_by_id(cmd_file, cinst->identifier)->elf;
887 if(!elf_get_start_addr(elf, NULL)) 312 if(!elf_get_start_addr(elf, NULL))
888 bug("cannot jump/call '%s' because it has no starting point !\n", cinst->identifier); 313 bug("cannot jump/call '%s' because it has no starting point !\n", cinst->identifier);
889 sec->nr_insts++; 314 sec->nr_insts++;
@@ -916,7 +341,7 @@ static struct sb_file_t *apply_cmd_file(struct cmd_file_t *cmd_file)
916 { 341 {
917 if(cinst->type == CMD_LOAD) 342 if(cinst->type == CMD_LOAD)
918 { 343 {
919 struct elf_params_t *elf = &find_source_by_id(cmd_file, cinst->identifier)->elf; 344 struct elf_params_t *elf = &db_find_source_by_id(cmd_file, cinst->identifier)->elf;
920 struct elf_section_t *esec = elf->first_section; 345 struct elf_section_t *esec = elf->first_section;
921 while(esec) 346 while(esec)
922 { 347 {
@@ -939,7 +364,7 @@ static struct sb_file_t *apply_cmd_file(struct cmd_file_t *cmd_file)
939 } 364 }
940 else if(cinst->type == CMD_JUMP || cinst->type == CMD_CALL) 365 else if(cinst->type == CMD_JUMP || cinst->type == CMD_CALL)
941 { 366 {
942 struct elf_params_t *elf = &find_source_by_id(cmd_file, cinst->identifier)->elf; 367 struct elf_params_t *elf = &db_find_source_by_id(cmd_file, cinst->identifier)->elf;
943 sec->insts[idx].argument = cinst->argument; 368 sec->insts[idx].argument = cinst->argument;
944 sec->insts[idx].inst = (cinst->type == CMD_JUMP) ? SB_INST_JUMP : SB_INST_CALL; 369 sec->insts[idx].inst = (cinst->type == CMD_JUMP) ? SB_INST_JUMP : SB_INST_CALL;
945 sec->insts[idx++].addr = elf->start_addr; 370 sec->insts[idx++].addr = elf->start_addr;
@@ -952,7 +377,7 @@ static struct sb_file_t *apply_cmd_file(struct cmd_file_t *cmd_file)
952 } 377 }
953 else if(cinst->type == CMD_LOAD_AT) 378 else if(cinst->type == CMD_LOAD_AT)
954 { 379 {
955 struct bin_param_t *bin = &find_source_by_id(cmd_file, cinst->identifier)->bin; 380 struct bin_param_t *bin = &db_find_source_by_id(cmd_file, cinst->identifier)->bin;
956 sec->insts[idx].inst = SB_INST_LOAD; 381 sec->insts[idx].inst = SB_INST_LOAD;
957 sec->insts[idx].addr = cinst->addr; 382 sec->insts[idx].addr = cinst->addr;
958 sec->insts[idx].data = bin->data; 383 sec->insts[idx].data = bin->data;
@@ -1294,7 +719,7 @@ int main(int argc, const char **argv)
1294 g_debug = true; 719 g_debug = true;
1295 720
1296 g_key_array = read_keys(argv[2], &g_nr_keys); 721 g_key_array = read_keys(argv[2], &g_nr_keys);
1297 struct cmd_file_t *cmd_file = read_command_file(argv[1]); 722 struct cmd_file_t *cmd_file = db_parse_file(argv[1]);
1298 struct sb_file_t *sb_file = apply_cmd_file(cmd_file); 723 struct sb_file_t *sb_file = apply_cmd_file(cmd_file);
1299 produce_sb_file(sb_file, argv[3]); 724 produce_sb_file(sb_file, argv[3]);
1300 725