From 753958c4b52373a12943237656418d717efd92c5 Mon Sep 17 00:00:00 2001 From: Ville Voipio Date: Wed, 7 May 2008 12:56:25 +0000 Subject: [PATCH] ='addpart' instruction added for manual chain building without 'detect'. git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1208 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- jtag/include/jtag.h | 1 + jtag/src/cmd/Makefile.am | 1 + jtag/src/cmd/addpart.c | 82 ++++++++++++++++++++++++++++++++++++++++ jtag/src/cmd/cmd.c | 2 + jtag/src/tap/detect.c | 73 +++++++++++++++++++++++++++++++++++ 5 files changed, 159 insertions(+) create mode 100644 jtag/src/cmd/addpart.c diff --git a/jtag/include/jtag.h b/jtag/include/jtag.h index f87a1598..23ac5226 100644 --- a/jtag/include/jtag.h +++ b/jtag/include/jtag.h @@ -45,6 +45,7 @@ int jtag_parse_line( chain_t *chain, char *line ); int jtag_parse_stream( chain_t *chain, FILE *f ); int detect_parts( chain_t *chain, const char *db_path ); +int manual_add( chain_t *chain, int instr_len ); int detect_register_size( chain_t *chain ); void discovery( chain_t *chain ); void idcode( chain_t *chain , unsigned int bytes); diff --git a/jtag/src/cmd/Makefile.am b/jtag/src/cmd/Makefile.am index 831c6c70..fd95a6a2 100644 --- a/jtag/src/cmd/Makefile.am +++ b/jtag/src/cmd/Makefile.am @@ -60,6 +60,7 @@ libcmd_a_SOURCES = \ flashmem.c \ eraseflash.c \ include.c \ + addpart.c \ cmd.c \ jtag_data_dir.c diff --git a/jtag/src/cmd/addpart.c b/jtag/src/cmd/addpart.c new file mode 100644 index 00000000..bb93a7a4 --- /dev/null +++ b/jtag/src/cmd/addpart.c @@ -0,0 +1,82 @@ +/* + * $Id$ + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written by Ville Voipio , 2008. + * + */ + +#include "sysdep.h" + +#include +#include + +#include "jtag.h" +#include "chain.h" +#include "bus.h" + +#include "cmd.h" + +static int +cmd_addpart_run( chain_t *chain, char *params[] ) +{ + unsigned int len; + + if (cmd_params( params ) != 2) + return -1; + + if (cmd_get_number( params[1], &len )) + return -1; + + if (!cmd_test_cable( chain )) + return 1; + + manual_add( chain, len ); + + if (chain->parts == NULL) + return 1; + + if (chain->parts->len == 0) { + parts_free( chain->parts ); + chain->parts = NULL; + } + + parts_set_instruction(chain->parts, "BYPASS"); + chain_shift_instructions(chain); + + return 1; +} + + +static void +cmd_addpart_help( void ) +{ + printf( _( + "Usage: %s IRLENGTH\n" + "Manually add a part to the end of the chain.\n" + "\n" + "IRLENGTH instruction register length\n" + ), "addpart" ); +} + + +cmd_t cmd_addpart = { + "addpart", + N_("manually adds parts on the JTAG chain"), + cmd_addpart_help, + cmd_addpart_run +}; diff --git a/jtag/src/cmd/cmd.c b/jtag/src/cmd/cmd.c index 13b857a1..253d4ce0 100644 --- a/jtag/src/cmd/cmd.c +++ b/jtag/src/cmd/cmd.c @@ -68,6 +68,7 @@ extern cmd_t cmd_flashmem; extern cmd_t cmd_eraseflash; extern cmd_t cmd_script; extern cmd_t cmd_include; +extern cmd_t cmd_addpart; #ifdef ENABLE_SVF extern cmd_t cmd_svf; #endif @@ -111,6 +112,7 @@ const cmd_t *cmds[] = { &cmd_eraseflash, &cmd_script, &cmd_include, + &cmd_addpart, #ifdef ENABLE_SVF &cmd_svf, #endif diff --git a/jtag/src/tap/detect.c b/jtag/src/tap/detect.c index ef823b5d..cae2ef31 100644 --- a/jtag/src/tap/detect.c +++ b/jtag/src/tap/detect.c @@ -389,3 +389,76 @@ detect_parts( chain_t *chain, const char *db_path ) return ps->len; } + + +/* In case we do not want to detect, we can add parts manually */ + +int manual_add(chain_t *chain, int instr_len) +{ + tap_register *id; + part_t *part; + char *cmd[] = {NULL, NULL, NULL, NULL, NULL}; + char *str; + int result; + + id = register_alloc( 1 ); + if (id == NULL) { + printf( _("Error: Unable to allocate a register!\n") ); + return 0; + } + + /* if there are no parts, create the parts list */ + if (chain->parts == NULL) { + chain->parts = parts_alloc(); + if (chain->parts == NULL) { + printf( _("Error: Unable to allocate space for parts!\n") ); + return 0; + } + } + + part = part_alloc(id); + if (part == NULL) { + printf( _("Error: Unable to allocate space for a part!\n") ); + return 0; + } + + strncpy(part->part, "unknown", MAXLEN_PART); + part->instruction_length = instr_len; + + parts_add_part(chain->parts, part); + chain->active_part = chain->parts->len - 1; + + /* make the BR register available */ + cmd[0] = "register"; + cmd[1] = "BR"; + cmd[2] = "1"; + cmd[3] = NULL; + if (cmd_run(chain, cmd) < 1) { + printf( _("Error: could not set BR register") ); + return 0; + } + + /* create a string of 1's for BYPASS instruction */ + cmd[0] = "instruction"; + cmd[1] = "BYPASS"; + cmd[3] = "BR"; + cmd[4] = NULL; + str = (char *)calloc(instr_len + 1, sizeof(char)); + if (str == NULL) { + printf( _("Out of memory!\n") ); + return 0; + } + + memset(str, '1', instr_len); + str[instr_len] = '\0'; + cmd[2] = str; + result = cmd_run(chain, cmd); + free(str); + + if (result < 1) { + printf( _("Error: could not set BYPASS instruction") ); + return 0; + } + + return chain->parts->len; +}