From 766b0ca8ac484a37d878623a189985b8e51e73cd Mon Sep 17 00:00:00 2001 From: oharboe Date: Sun, 13 Jul 2008 17:31:40 +0000 Subject: [PATCH] Charles Hardin - hopefully final word on startup.tcl => c conversion git-svn-id: svn://svn.berlios.de/openocd/trunk@803 b42882b7-edfa-0310-969c-e2dbd0fdcd60 --- src/Makefile.am | 17 ++++++++--------- src/bin2char.c | 30 ++++++++++++++++++++++++++++++ src/openocd.c | 10 +++++----- 3 files changed, 43 insertions(+), 14 deletions(-) create mode 100644 src/bin2char.c diff --git a/src/Makefile.am b/src/Makefile.am index 502a63d5..0cb13ab6 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 00000000..de00aeba --- /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 6c1f5703..813c021c 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; -- 2.39.5