diff options
Diffstat (limited to 'utils/imxtools/sbtools/elf.c')
-rw-r--r-- | utils/imxtools/sbtools/elf.c | 35 |
1 files changed, 12 insertions, 23 deletions
diff --git a/utils/imxtools/sbtools/elf.c b/utils/imxtools/sbtools/elf.c index 5017251da3..c875cc7963 100644 --- a/utils/imxtools/sbtools/elf.c +++ b/utils/imxtools/sbtools/elf.c | |||
@@ -430,7 +430,7 @@ void elf_sort_by_address(struct elf_params_t *params) | |||
430 | } | 430 | } |
431 | 431 | ||
432 | void elf_write_file(struct elf_params_t *params, elf_write_fn_t write, | 432 | void elf_write_file(struct elf_params_t *params, elf_write_fn_t write, |
433 | elf_printf_fn_t printf, void *user) | 433 | generic_printf_t printf, void *user) |
434 | { | 434 | { |
435 | (void) printf; | 435 | (void) printf; |
436 | 436 | ||
@@ -607,13 +607,13 @@ void elf_write_file(struct elf_params_t *params, elf_write_fn_t write, | |||
607 | free(strtbl_content); | 607 | free(strtbl_content); |
608 | } | 608 | } |
609 | 609 | ||
610 | static void *elf_load_section(Elf32_Shdr *sh, elf_read_fn_t read, elf_printf_fn_t printf, void *user) | 610 | static void *elf_load_section(Elf32_Shdr *sh, elf_read_fn_t read, generic_printf_t printf, void *user) |
611 | { | 611 | { |
612 | void *data = xmalloc(sh->sh_size); | 612 | void *data = xmalloc(sh->sh_size); |
613 | if(!read(user, sh->sh_offset, data, sh->sh_size)) | 613 | if(!read(user, sh->sh_offset, data, sh->sh_size)) |
614 | { | 614 | { |
615 | free(data); | 615 | free(data); |
616 | printf(user, true, "error reading elf section data\n"); | 616 | printf(user, true, OFF, "error reading elf section data\n"); |
617 | return NULL; | 617 | return NULL; |
618 | } | 618 | } |
619 | return data; | 619 | return data; |
@@ -633,15 +633,15 @@ bool elf_guess(elf_read_fn_t read, void *user) | |||
633 | } | 633 | } |
634 | 634 | ||
635 | bool elf_read_file(struct elf_params_t *params, elf_read_fn_t read, | 635 | bool elf_read_file(struct elf_params_t *params, elf_read_fn_t read, |
636 | elf_printf_fn_t printf, void *user) | 636 | generic_printf_t printf, void *user) |
637 | { | 637 | { |
638 | #define error_printf(...) ({printf(user, true, __VA_ARGS__); return false;}) | 638 | #define error_printf(...) ({printf(user, true, GREY, __VA_ARGS__); return false;}) |
639 | 639 | ||
640 | /* read header */ | 640 | /* read header */ |
641 | Elf32_Ehdr ehdr; | 641 | Elf32_Ehdr ehdr; |
642 | if(!read(user, 0, &ehdr, sizeof(ehdr))) | 642 | if(!read(user, 0, &ehdr, sizeof(ehdr))) |
643 | { | 643 | { |
644 | printf(user, true, "error reading elf header\n"); | 644 | printf(user, true, GREY, "error reading elf header\n"); |
645 | return false; | 645 | return false; |
646 | } | 646 | } |
647 | /* basic checks */ | 647 | /* basic checks */ |
@@ -667,16 +667,16 @@ bool elf_read_file(struct elf_params_t *params, elf_read_fn_t read, | |||
667 | elf_set_start_addr(params, ehdr.e_entry); | 667 | elf_set_start_addr(params, ehdr.e_entry); |
668 | 668 | ||
669 | /* run through sections */ | 669 | /* run through sections */ |
670 | printf(user, false, "ELF file:\n"); | 670 | printf(user, false, OFF, "ELF file:\n"); |
671 | Elf32_Shdr *shdr = xmalloc(sizeof(Elf32_Shdr) * ehdr.e_shnum); | 671 | Elf32_Shdr *shdr = xmalloc(sizeof(Elf32_Shdr) * ehdr.e_shnum); |
672 | if(!read(user, ehdr.e_shoff, shdr, sizeof(Elf32_Shdr) * ehdr.e_shnum)) | 672 | if(!read(user, ehdr.e_shoff, shdr, sizeof(Elf32_Shdr) * ehdr.e_shnum)) |
673 | { | 673 | { |
674 | printf(user, true, "cannot read elf section headers\n"); | 674 | printf(user, true, GREY, "cannot read elf section headers\n"); |
675 | return false; | 675 | return false; |
676 | } | 676 | } |
677 | char *strtab = elf_load_section(&shdr[ehdr.e_shstrndx], read, printf, user); | 677 | char *strtab = elf_load_section(&shdr[ehdr.e_shstrndx], read, printf, user); |
678 | if(!strtab) | 678 | if(!strtab) |
679 | printf(user, false, "elf file has no valid section string table\n"); | 679 | printf(user, false, OFF, "elf file has no valid section string table\n"); |
680 | for(int i = 1; i < ehdr.e_shnum; i++) | 680 | for(int i = 1; i < ehdr.e_shnum; i++) |
681 | { | 681 | { |
682 | const char *sec_name = &strtab[shdr[i].sh_name]; | 682 | const char *sec_name = &strtab[shdr[i].sh_name]; |
@@ -688,7 +688,7 @@ bool elf_read_file(struct elf_params_t *params, elf_read_fn_t read, | |||
688 | void *data = elf_load_section(&shdr[i], read, printf, user); | 688 | void *data = elf_load_section(&shdr[i], read, printf, user); |
689 | if(!data) | 689 | if(!data) |
690 | { | 690 | { |
691 | printf(user, true, "cannot read elf section %s\n", sec_name); | 691 | printf(user, true, GREY, "cannot read elf section %s\n", sec_name); |
692 | goto Lerr; | 692 | goto Lerr; |
693 | } | 693 | } |
694 | elf_add_load_section(params, shdr[i].sh_addr, shdr[i].sh_size, data, sec_name); | 694 | elf_add_load_section(params, shdr[i].sh_addr, shdr[i].sh_size, data, sec_name); |
@@ -707,7 +707,7 @@ bool elf_read_file(struct elf_params_t *params, elf_read_fn_t read, | |||
707 | char *symstrtab = elf_load_section(&shdr[shdr[i].sh_link], read, printf, user); | 707 | char *symstrtab = elf_load_section(&shdr[shdr[i].sh_link], read, printf, user); |
708 | if(!symstrtab) | 708 | if(!symstrtab) |
709 | { | 709 | { |
710 | printf(user, true, "cannot load string table for symbol table %s\n", sec_name); | 710 | printf(user, true, GREY, "cannot load string table for symbol table %s\n", sec_name); |
711 | goto Lerr; | 711 | goto Lerr; |
712 | } | 712 | } |
713 | // load symbol table data | 713 | // load symbol table data |
@@ -772,7 +772,7 @@ bool elf_read_file(struct elf_params_t *params, elf_read_fn_t read, | |||
772 | seg->paddr = phdr.p_paddr; | 772 | seg->paddr = phdr.p_paddr; |
773 | seg->vsize = phdr.p_memsz; | 773 | seg->vsize = phdr.p_memsz; |
774 | seg->psize = phdr.p_filesz; | 774 | seg->psize = phdr.p_filesz; |
775 | printf(user, false, "create segment [%#x,+%#x[ -> [%#x,+%#x[\n", | 775 | printf(user, false, OFF, "create segment [%#x,+%#x[ -> [%#x,+%#x[\n", |
776 | seg->vaddr, seg->vsize, seg->paddr, seg->psize); | 776 | seg->vaddr, seg->vsize, seg->paddr, seg->psize); |
777 | } | 777 | } |
778 | 778 | ||
@@ -855,17 +855,6 @@ void elf_release(struct elf_params_t *params) | |||
855 | } | 855 | } |
856 | } | 856 | } |
857 | 857 | ||
858 | void elf_std_printf(void *user, bool error, const char *fmt, ...) | ||
859 | { | ||
860 | if(!g_debug && !error) | ||
861 | return; | ||
862 | (void) user; | ||
863 | va_list args; | ||
864 | va_start(args, fmt); | ||
865 | vprintf(fmt, args); | ||
866 | va_end(args); | ||
867 | } | ||
868 | |||
869 | void elf_std_write(void *user, uint32_t addr, const void *buf, size_t count) | 858 | void elf_std_write(void *user, uint32_t addr, const void *buf, size_t count) |
870 | { | 859 | { |
871 | FILE *f = user; | 860 | FILE *f = user; |