diff --git a/src/Makefile.am b/src/Makefile.am index 502a63d50..0cb13ab6f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,6 @@ -bin_PROGRAMS = openocd +bin_PROGRAMS = openocd bin2char + +bin2char_SOURCES = bin2char.c if ECOSBOARD MAINFILE = ecosboard.c @@ -6,7 +8,7 @@ else MAINFILE = main.c jim.c endif -openocd_SOURCES = $(MAINFILE) openocd.c +openocd_SOURCES = $(MAINFILE) openocd.c startup_tcl.c # set the include path found by configure INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/src/helper \ @@ -70,7 +72,7 @@ FTD2XXLIB = endif endif -openocd_LDADD = $(top_builddir)/src/startup.o $(top_builddir)/src/xsvf/libxsvf.a \ +openocd_LDADD = $(top_builddir)/src/xsvf/libxsvf.a \ $(top_builddir)/src/target/libtarget.a $(top_builddir)/src/jtag/libjtag.a \ $(top_builddir)/src/helper/libhelper.a \ $(top_builddir)/src/server/libserver.a $(top_builddir)/src/helper/libhelper.a \ @@ -94,9 +96,6 @@ nobase_dist_pkglib_DATA = \ tcl/mmr_helpers.tcl \ tcl/readable.tcl -# Convert .tcl to object - -$(top_builddir)/src/startup.o: $(top_srcdir)/src/startup.tcl - abs_builddir=`cd $(top_builddir) && pwd` && \ - cd $(top_srcdir)/src && \ - ${OBJCOPY} -I binary -O ${OBJCOPY_FORMAT} -B ${OBJCOPY_ARCH} startup.tcl $$abs_builddir/src/startup.o +# Convert .tcl to cfile +startup_tcl.c: bin2char startup.tcl + ./bin2char startup_tcl < $(srcdir)/startup.tcl > startup_tcl.c diff --git a/src/bin2char.c b/src/bin2char.c new file mode 100644 index 000000000..de00aebac --- /dev/null +++ b/src/bin2char.c @@ -0,0 +1,30 @@ +#include +#include + +int +main(int argc, char **argv) +{ + int c; + unsigned int n; + char *name; + + if (argc == 1) { + fprintf(stderr, "bin2char \n"); + fprintf(stderr, "read from standard input and write a char" + " array out to standard output\n"); + exit(1); + } + + n = 0; + name = argv[1]; + fprintf(stdout, "/* autogenerated from %s */\n", argv[0]); + fprintf(stdout, "unsigned const char %s[] = {\n", name); + while ((c = getc(stdin)) != EOF) { + fprintf(stdout, "0x%02x,", c & 0xff); + if ((++n % 16) == 0) + fprintf(stdout, "\n"); + } + fprintf(stdout, "0 /* terminate with a nil */};\n"); + fprintf(stdout, "unsigned int %s_len = %u;\n", name, n); + return 0; +} diff --git a/src/openocd.c b/src/openocd.c index 6c1f57031..813c021cb 100644 --- a/src/openocd.c +++ b/src/openocd.c @@ -714,8 +714,8 @@ void add_jim(const char *name, int (*cmd)(Jim_Interp *interp, int argc, Jim_Obj Jim_ListAppendElement(interp, helptext, cmd_entry); } -extern char binary_startup_tcl_start; -extern char binary_startup_tcl_size; +extern unsigned const char startup_tcl[]; +extern unsigned int startup_tcl_len; void initJim(void) { @@ -741,10 +741,10 @@ void initJim(void) add_default_dirs(); - script_len = (int)&binary_startup_tcl_size; + script_len = startup_tcl_len; script = malloc(script_len + sizeof(char)); - memcpy(script, &binary_startup_tcl_start, script_len); - + memcpy(script, startup_tcl, script_len); + /* null terminate */ script[script_len] = 0;