helper: Add converter from JEP106 ID to manufacturer name

Use it to print the manufacturer of detected TAPs

Change-Id: Ic4384c61c7f6f7ae2a9b860a805a5997542f72cc
Signed-off-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
Reviewed-on: http://openocd.zylin.com/3177
Tested-by: jenkins
Reviewed-by: Jiri Kastner <cz172638@gmail.com>
Reviewed-by: Paul Fertser <fercerpav@gmail.com>
This commit is contained in:
Andreas Fritiofson 2015-12-28 18:05:54 +01:00
parent c520fdf902
commit 1919dbbfd2
6 changed files with 1233 additions and 1 deletions

View File

@ -17,6 +17,7 @@ libhelper_la_SOURCES = \
replacements.c \
fileio.c \
util.c \
jep106.c \
jim-nvp.c
if IOUTIL
@ -45,6 +46,9 @@ noinst_HEADERS = \
fileio.h \
system.h \
bin2char.sh \
jep106.h \
jep106.inc \
update_jep106.pl \
jim-nvp.h
EXTRA_DIST = startup.tcl

41
src/helper/jep106.c Normal file
View File

@ -0,0 +1,41 @@
/***************************************************************************
* Copyright (C) 2015 Andreas Fritiofson *
* andreas.fritiofson@gmail.com *
* *
* 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. *
***************************************************************************/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "jep106.h"
#include "log.h"
static const char * const jep106[][126] = {
#include "jep106.inc"
};
const char *jep106_manufacturer(unsigned bank, unsigned id)
{
if (id < 1 || id > 126) {
LOG_DEBUG("BUG: Caller passed out-of-range JEP106 ID!");
return "<invalid>";
}
/* index is zero based */
id--;
if (bank >= ARRAY_SIZE(jep106) || jep106[bank][id] == 0)
return "<unknown>";
return jep106[bank][id];
}

29
src/helper/jep106.h Normal file
View File

@ -0,0 +1,29 @@
/***************************************************************************
* Copyright (C) 2015 Andreas Fritiofson *
* andreas.fritiofson@gmail.com *
* *
* 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. *
***************************************************************************/
#ifndef JEP106_H
#define JEP106_H
/**
* Get the manufacturer name associated with a JEP106 ID.
* @param bank The bank (number of continuation codes) of the manufacturer ID.
* @param id The 7-bit manufacturer ID (i.e. with parity stripped).
* @return A pointer to static const storage containing the name of the
* manufacturer associated with bank and id, or one of the strings
* "<invalid>" and "<unknown>".
*/
const char *jep106_manufacturer(unsigned bank, unsigned id);
#endif

1119
src/helper/jep106.inc Normal file

File diff suppressed because it is too large Load Diff

35
src/helper/update_jep106.pl Executable file
View File

@ -0,0 +1,35 @@
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename;
if (@ARGV != 1) {
die "Usage: $0 <JEP106 PDF document>\n\n"
. "Convert the JEDEC document containing manufacturer identification codes\n"
. "to an array initializer suitable for incusion into jep106.c. The latest\n"
. "version of the document can be found here:\n"
. "http://www.jedec.org/standards-documents/results/jep106\n";
};
my $outfile = dirname($0) . "/jep106.inc";
open(my $out, ">", $outfile) || die "Cannot open $outfile: $!\n";
open(my $pdftotext, "pdftotext -layout $ARGV[0] - |") || die "Cannot fork: $!\n";
print $out "/* Autogenerated with " . basename($0) . "*/\n";
my $bank = -1;
while (<$pdftotext>) {
if (/^[0-9]+[[:space:]]+(.*?)[[:space:]]+([01][[:space:]]+){8}([0-9A-F]{2})$/) {
if ($3 eq "01") {
$bank++
}
my $id=sprintf("0x%02x",hex($3)&0x7f);
print $out "[$bank][$id - 1] = \"$1\",\n";
}
}
close $pdftotext || die "Error: $! $?\n";
print $out "/* EOF */\n";

View File

@ -36,6 +36,7 @@
#include "swd.h"
#include "interface.h"
#include <transport/transport.h>
#include <helper/jep106.h>
#ifdef HAVE_STRINGS_H
#include <strings.h>
@ -894,6 +895,8 @@ void jtag_sleep(uint32_t us)
#define JTAG_MAX_AUTO_TAPS 20
#define EXTRACT_JEP106_BANK(X) (((X) & 0xf00) >> 8)
#define EXTRACT_JEP106_ID(X) (((X) & 0xfe) >> 1)
#define EXTRACT_MFG(X) (((X) & 0xffe) >> 1)
#define EXTRACT_PART(X) (((X) & 0xffff000) >> 12)
#define EXTRACT_VER(X) (((X) & 0xf0000000) >> 28)
@ -957,10 +960,11 @@ static void jtag_examine_chain_display(enum log_levels level, const char *msg,
{
log_printf_lf(level, __FILE__, __LINE__, __func__,
"JTAG tap: %s %16.16s: 0x%08x "
"(mfg: 0x%3.3x, part: 0x%4.4x, ver: 0x%1.1x)",
"(mfg: 0x%3.3x (%s), part: 0x%4.4x, ver: 0x%1.1x)",
name, msg,
(unsigned int)idcode,
(unsigned int)EXTRACT_MFG(idcode),
jep106_manufacturer(EXTRACT_JEP106_BANK(idcode), EXTRACT_JEP106_ID(idcode)),
(unsigned int)EXTRACT_PART(idcode),
(unsigned int)EXTRACT_VER(idcode));
}