# HG changeset patch # User Michael Spacefalcon # Date 1407187026 0 # Node ID 069b79b36228930f15f60c075fd94b67908008cf # Parent 827b8977d3c2cee1dd071afd99fac979fee02a28 tiobjd: chararray extraction command implemented diff -r 827b8977d3c2 -r 069b79b36228 leo-obj/tool/Makefile --- a/leo-obj/tool/Makefile Tue Jul 15 00:24:40 2014 +0000 +++ b/leo-obj/tool/Makefile Mon Aug 04 21:17:06 2014 +0000 @@ -1,8 +1,9 @@ CC= gcc CFLAGS= -O2 PROG= tiobjd -OBJS= armdis.o atcommon.o basics.o disasm.o globals.o hints.o ln.o lowlevel.o\ - main.o profile.o reloc.o richsym.o symtab.o tables.o thumbdis.o +OBJS= armdis.o atcommon.o basics.o chararray.o disasm.o globals.o hints.o \ + ln.o lowlevel.o main.o profile.o reloc.o richsym.o symtab.o tables.o \ + thumbdis.o HDRS= coffconst.h filestruct.h globals.h intstruct.h all: ${PROG} diff -r 827b8977d3c2 -r 069b79b36228 leo-obj/tool/chararray.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/leo-obj/tool/chararray.c Mon Aug 04 21:17:06 2014 +0000 @@ -0,0 +1,90 @@ +/* + * Some COFF objects in TI's firmware semi-src are the result of compiling + * a *.c file that contains nothing more than a const char array. Here + * we support the extraction of these char arrays, to enable recompilation + * with our choice of compiler toolchain. + */ + +#include +#include +#include +#include +#include +#include "intstruct.h" +#include "coffconst.h" +#include "globals.h" + +extern unsigned get_u16(), get_u32(); + +cmd_chararray(argc, argv) + char **argv; +{ + int c, sflag = 0; + unsigned n, array_len; + char *array_name; + struct internal_syment *sym; + u_char *dp; + extern int optind; + extern char *optarg; + + while ((c = getopt(argc, argv, "s:")) != EOF) + switch (c) { + case 's': + array_len = strtoul(optarg, 0, 16); + sflag = 1; + continue; + default: + /* error msg already printed */ + exit(1); + } + if (argc != optind + 1) { + fprintf(stderr, "tiobjd chararray: name argument required\n"); + exit(1); + } + array_name = argv[optind]; + + get_int_section_table(); + get_int_symbol_table(); + for (n = 0; n < nsymtab; n++) { + sym = symtab[n]; + if (!sym) + continue; + if (sym->class != C_EXT) + continue; + if (sym->name[0] != '_') + continue; + if (!strcmp(sym->name + 1, array_name)) + goto found; + } + fprintf(stderr, "error: found no global symbol named %s\n", array_name); + exit(1); + +found: if (!sym->section) { + fprintf(stderr, "error: %s is not defined in a section\n", + array_name); + exit(1); + } + if (!sflag) { + if (sym->type != 0x003C) { + fprintf(stderr, + "error: %s has type != array of u_char\n", + array_name); + exit(1); + } + if (!sym->aux) { + fprintf(stderr, "error: %s has no Aux record\n", + array_name); + exit(1); + } + array_len = get_u16(sym->aux + 8); + } + dp = filemap + sym->section->data_offset + sym->value; + printf("const unsigned char %s[%u] = {", array_name, array_len); + for (n = 0; n < array_len; n++) { + if (!(n & 15)) + putchar('\n'); + printf("0x%02X,", *dp++); + } + puts("\n};"); + exit(0); +} diff -r 827b8977d3c2 -r 069b79b36228 leo-obj/tool/main.c --- a/leo-obj/tool/main.c Tue Jul 15 00:24:40 2014 +0000 +++ b/leo-obj/tool/main.c Mon Aug 04 21:17:06 2014 +0000 @@ -10,6 +10,7 @@ #include "globals.h" extern int cmd_basics(); +extern int cmd_chararray(); extern int cmd_ctypes(); extern int cmd_disasm(); extern int cmd_ln(); @@ -26,6 +27,7 @@ int (*func)(); } cmdtab[] = { {"basics", cmd_basics}, + {"chararray", cmd_chararray}, {"ctypes", cmd_ctypes}, {"disasm", cmd_disasm}, {"dumpsym", cmd_symtab}, /* backward compat */