Fix some problems with the bin2char utility 76/2176/3
authorAndreas Fritiofson <andreas.fritiofson@gmail.com>
Wed, 18 Jun 2014 21:10:45 +0000 (23:10 +0200)
committerAndreas Fritiofson <andreas.fritiofson@gmail.com>
Sat, 2 Aug 2014 09:01:32 +0000 (09:01 +0000)
Don't hardcode the type for the array, just output the array initializer
so the includer can choose the type and storage class, zero-terminate at
will and so on.

Change-Id: I6d5e0710eaaba0a218b3eb32f6569177356f4462
Signed-off-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
Reviewed-on: http://openocd.zylin.com/2176
Tested-by: jenkins
Reviewed-by: Paul Fertser <fercerpav@gmail.com>
.gitignore
src/Makefile.am
src/helper/bin2char.sh
src/openocd.c
src/openocd.h
src/target/Makefile.am
src/target/xscale.c

index bfb22ed6ee4dbf50187a6408ea5baf122ca772c7..3e6e1e94feb7d94eff32ce482000382db5994f58 100644 (file)
@@ -30,8 +30,8 @@ src/jtag/drivers/OpenULINK/*.rst
 *.swp
 
 src/startup.tcl
-startup_tcl.c
-xscale_debug.h
+startup_tcl.inc
+xscale_debug.inc
 
 bin2char
 bin2char.exe
index b539ec433c89bcb5908bb05697588fa8c38b72c7..7d67e3d7e95f51063888799338ba737b54daa8b1 100644 (file)
@@ -32,8 +32,7 @@ endif
 
 libopenocd_la_SOURCES = \
        hello.c \
-       openocd.c \
-       startup_tcl.c
+       openocd.c
 
 noinst_HEADERS = \
        hello.h \
@@ -86,23 +85,23 @@ STARTUP_TCL_SRCS = \
 
 EXTRA_DIST = $(STARTUP_TCL_SRCS)
 
-BUILT_SOURCES = startup.tcl
+BUILT_SOURCES = startup_tcl.inc
 
 startup.tcl: $(STARTUP_TCL_SRCS)
        cat $^ > $@
 
 BIN2C = $(top_srcdir)/src/helper/bin2char.sh
 
-# Convert .tcl to cfile
-startup_tcl.c: startup.tcl $(BIN2C)
-       $(BIN2C) openocd_startup_tcl < $< > $@ || rm -f $@
+# Convert .tcl to c-array
+startup_tcl.inc: startup.tcl $(BIN2C)
+       $(BIN2C) < $< > $@ || { rm -f $@; false; }
 
-# add startup_tcl.c to make clean list
-CLEANFILES = startup.tcl startup_tcl.c
+# add generated files to make clean list
+CLEANFILES = startup.tcl startup_tcl.inc
 
 # we do not want generated file in the dist
 dist-hook:
-       rm -f $(distdir)/startup_tcl.c
+       rm -f $(distdir)/startup_tcl.inc
 
 MAINTAINERCLEANFILES = $(srcdir)/Makefile.in
 
index f9da30944ac33b1c0254dfa754ae83d8d08dfc8e..85a0fd6a88546cd61d33683f53a22d55568cb8ef 100755 (executable)
@@ -1,14 +1,14 @@
 #!/bin/sh
 
-[ $# = 0 ] && {
-    echo "Usage: $0 <varname>"
+[ $# != 0 ] && {
+    echo "Usage: $0"
     echo
-    echo "Read binary data from standard input and write it as a C character"
-    echo "array <varname> to standard output. Add a final NULL for terminating."
+    echo "Read binary data from standard input and write it as a comma separated"
+    echo "list of hexadecimal byte values to standard ouput. The output is usable"
+    echo "as a C array initializer. It is terminated with a comma so it can be"
+    echo "continued e.g. for zero termination."
     exit 1
 }
 
 echo "/* Autogenerated with $0 */"
-echo "unsigned const char $1[] = {"
 od -v -A n -t x1 | sed 's/ *\(..\) */0x\1,/g'
-echo "0 /* NULL-terminated */ };"
index 71e047f40e9705224f4f2d409ed8d8b308d89a11..758febb4df7533ddcede040ab007ca7a22af92e5 100644 (file)
 #define OPENOCD_VERSION        \
        "Open On-Chip Debugger " VERSION RELSTR " (" PKGBLDDATE ")"
 
+static const char openocd_startup_tcl[] = {
+#include "startup_tcl.inc"
+0 /* Terminate with zero */
+};
+
 /* Give scripts and TELNET a way to find out what version this is */
 static int jim_version_command(Jim_Interp *interp, int argc,
        Jim_Obj * const *argv)
@@ -228,8 +233,7 @@ struct command_context *setup_command_handler(Jim_Interp *interp)
        log_init();
        LOG_DEBUG("log_init: complete");
 
-       const char *startup = openocd_startup_tcl;
-       struct command_context *cmd_ctx = command_init(startup, interp);
+       struct command_context *cmd_ctx = command_init(openocd_startup_tcl, interp);
 
        /* register subsystem commands */
        typedef int (*command_registrant_t)(struct command_context *cmd_ctx_value);
index 57bf4551268ea26812a9811af951ce24a00b7976..6d87c2af9012359043ea715382fb1ad73df66a82 100644 (file)
@@ -31,7 +31,4 @@
  */
 int openocd_main(int argc, char *argv[]);
 
-/** provides a hard-coded command environment setup */
-extern const char openocd_startup_tcl[];
-
 #endif
index efbeb33afd190c8140020cb61b18d9d658f0f893..bf80c64c021aa9ef4e261751ff31a5ec057f9147 100644 (file)
@@ -16,12 +16,12 @@ EXTRA_DIST = \
        startup.tcl \
        $(wildcard $(srcdir)/xscale/*)
 
-DEBUG_HEADER   = xscale_debug.h
+DEBUG_HEADER   = xscale_debug.inc
 BUILT_SOURCES = $(DEBUG_HEADER)
 CLEANFILES = $(DEBUG_HEADER)
 
-$(DEBUG_HEADER): $(BIN2C) $(DEBUG_HANDLER)
-       $(BIN2C) < $(DEBUG_HANDLER) xscale_debug_handler > xscale_debug.h
+$(DEBUG_HEADER): $(DEBUG_HANDLER) $(BIN2C)
+       $(BIN2C) < $< > $@ || { rm -f $@; false; }
 
 METASOURCES = AUTO
 noinst_LTLIBRARIES = libtarget.la
index e88a23112b0dd17f964783fbbccf28abf9c218a5..04189a1484bab6fda631d30b78185ecc8b0208e8 100644 (file)
@@ -73,14 +73,10 @@ static int xscale_read_trace(struct target *);
 
 /* This XScale "debug handler" is loaded into the processor's
  * mini-ICache, which is 2K of code writable only via JTAG.
- *
- * FIXME  the OpenOCD "bin2char" utility currently doesn't handle
- * binary files cleanly.  It's string oriented, and terminates them
- * with a NUL character.  Better would be to generate the constants
- * and let other code decide names, scoping, and other housekeeping.
  */
-static /* unsigned const char xscale_debug_handler[] = ... */
-#include "xscale_debug.h"
+static const uint8_t xscale_debug_handler[] = {
+#include "xscale_debug.inc"
+};
 
 static char *const xscale_reg_list[] = {
        "XSCALE_MAINID",                /* 0 */
@@ -1549,7 +1545,7 @@ static int xscale_deassert_reset(struct target *target)
                 * coprocessors, trace data, etc.
                 */
                address = xscale->handler_address;
-               for (unsigned binary_size = sizeof xscale_debug_handler - 1;
+               for (unsigned binary_size = sizeof xscale_debug_handler;
                        binary_size > 0;
                        binary_size -= buf_cnt, buffer += buf_cnt) {
                        uint32_t cache_line[8];
@@ -3028,7 +3024,7 @@ static int xscale_target_create(struct target *target, Jim_Interp *interp)
 {
        struct xscale_common *xscale;
 
-       if (sizeof xscale_debug_handler - 1 > 0x800) {
+       if (sizeof xscale_debug_handler > 0x800) {
                LOG_ERROR("debug_handler.bin: larger than 2kb");
                return ERROR_FAIL;
        }

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)