='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
master
Ville Voipio 17 years ago
parent e07c290fb3
commit 753958c4b5

@ -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);

@ -60,6 +60,7 @@ libcmd_a_SOURCES = \
flashmem.c \
eraseflash.c \
include.c \
addpart.c \
cmd.c \
jtag_data_dir.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 <ville.voipio@iki.fi>, 2008.
*
*/
#include "sysdep.h"
#include <stdio.h>
#include <string.h>
#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
};

@ -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

@ -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;
}

Loading…
Cancel
Save