From 2752c3404b0308da797fe06e6fb2e75f0d0e3b50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Sat, 13 Jun 2026 00:10:02 +0200 Subject: [PATCH] bsdl: extract parser into standalone libbsdl, pulled via FetchContent The BSDL loader (seeded from the Viveris parser) now lives in its own LGPL repo, electronics/libbsdl, consumed with CMake FetchContent. Local development override: -DFETCHCONTENT_SOURCE_DIR_BSDL=. src/modules/bsdl_parser/ is removed; callers go through the libbsdl API. Build verified against the libbsdl checkout. --- CLAUDE.md | 16 +- CMakeLists.txt | 15 +- src/modules/bsdl_parser/CMakeLists.txt | 7 - src/modules/bsdl_parser/bsdl_loader.c | 1520 ------------------ src/modules/bsdl_parser/bsdl_loader.h | 87 - src/modules/bsdl_parser/bsdl_strings.c | 93 -- src/modules/bsdl_parser/bsdl_strings.h | 81 - src/modules/bus_over_jtag/CMakeLists.txt | 1 + src/modules/bus_over_jtag/i2c_over_jtag.c | 10 +- src/modules/bus_over_jtag/mdio_over_jtag.c | 10 +- src/modules/bus_over_jtag/memory_over_jtag.c | 14 +- src/modules/bus_over_jtag/spi_over_jtag.c | 18 +- src/modules/drivers/CMakeLists.txt | 2 +- src/modules/drivers/drivers_list.c | 2 +- src/modules/drivers/drv_loader.c | 2 +- src/modules/jtag_core/CMakeLists.txt | 3 +- src/modules/jtag_core/jtag_core.c | 167 +- src/modules/script/CMakeLists.txt | 1 + src/modules/script/script.c | 2 +- 19 files changed, 154 insertions(+), 1897 deletions(-) delete mode 100644 src/modules/bsdl_parser/CMakeLists.txt delete mode 100644 src/modules/bsdl_parser/bsdl_loader.c delete mode 100644 src/modules/bsdl_parser/bsdl_loader.h delete mode 100644 src/modules/bsdl_parser/bsdl_strings.c delete mode 100644 src/modules/bsdl_parser/bsdl_strings.h diff --git a/CLAUDE.md b/CLAUDE.md index 78dd40e..7b0a823 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -20,7 +20,12 @@ other families (Lattice, Microsemi, …) by playing a vendor-exported SVF. The Viveris library itself lives unchanged in `src/modules/`. Everything new is in `src/bs/` (the REPL) and the project modules (`target/`, `bscan/`, `spi_flash/`, `svf/`, `probes/`, `program/`, `arm_debug/`) -sitting alongside the Viveris ones. +sitting alongside the Viveris ones. The BSDL parser was extracted into +a standalone library, **[libbsdl](ssh://gitea@git.beafrancois.fr:8329/electronics/libbsdl.git)** +(LGPL, seeded from the same Viveris loader), and is now pulled in via +CMake `FetchContent` instead of vendored. To build against a local +checkout (e.g. side-by-side dev): configure with +`-DFETCHCONTENT_SOURCE_DIR_BSDL=/path/to/libbsdl`. ## Architecture @@ -30,13 +35,14 @@ src/ └── modules/ — Viveris's library (LGPL, unchanged) — ├── jtag_core/ TAP state machine, IR/DR shifts - ├── bsdl_parser/ .bsd loader ├── bus_over_jtag/ SPI/I²C/MDIO/parallel mem bit-bang over EXTEST ├── drivers/ FTDI, J-Link, Linux GPIO, LPT, Digilent (optional, dlopen) ├── script/ Script engine (the real UI) ├── config/ Built-in config.script ├── os_interface/ Portable fs/network wrappers └── natsort/ Natural pin-name sorting + — pulled via FetchContent (LGPL, separate repo) — + └── (libbsdl) BSDL (.bsd) parser; struct + JSON; stable C ABI — new (this project) — ├── target/ Target registry: FPGAs + CPUs (parses data/targets.yaml) ├── bscan/ JTAG TAP primitives (set_ir/shift_ir/shift_dr/tap_reset/ @@ -528,7 +534,11 @@ mkdir build && cd build && cmake .. && make Build needs **libyaml** (pkg-config `yaml-0.1`; Arch `libyaml`, Debian `libyaml-dev`) for the registry, and **libftdi1** + **libusb-1.0** (pkg-config `libftdi1`; Arch `libftdi`, Debian `libftdi1-dev`) for the -FTDI/Olimex driver. Run `bs` from the repo root so it finds +FTDI/Olimex driver. **libbsdl** (the BSDL parser, separate repo) is +pulled in by CMake `FetchContent` at configure time — needs network on +first build. For a local checkout, configure with +`-DFETCHCONTENT_SOURCE_DIR_BSDL=/path/to/libbsdl` (built-in FetchContent +override, no clone happens). Run `bs` from the repo root so it finds `data/targets.yaml` (and `data/bsdl_files/`, `data/bscan_proxies/`), or point `$BS_TARGETS` at it. diff --git a/CMakeLists.txt b/CMakeLists.txt index e1e0a91..32811d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.14) project(BoundaryScanExplorer) @@ -6,6 +6,19 @@ project(BoundaryScanExplorer) # build/src/bs/ where the source tree would otherwise mirror it. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) +# ---- libbsdl (BSDL parser, extracted from this repo and now standalone) ---- +# Pulled via FetchContent from the canonical Gitea URL. For a local checkout, +# set -DFETCHCONTENT_SOURCE_DIR_BSDL=/path/to/libbsdl at configure time +# (built-in FetchContent override — no clone happens). +include(FetchContent) +set(BSDL_BUILD_CLI OFF CACHE BOOL "" FORCE) +set(BSDL_BUILD_TESTS OFF CACHE BOOL "" FORCE) +FetchContent_Declare(bsdl + GIT_REPOSITORY ssh://gitea@git.beafrancois.fr:8329/electronics/libbsdl.git + GIT_TAG main +) +FetchContent_MakeAvailable(bsdl) + # Digilent JTAG-SMT* backend. The driver dlopen's libdjtg/libdmgr at # runtime and degrades to "no probe" if they're absent, so building it # in costs nothing — default ON. Needs , so UNIX only. diff --git a/src/modules/bsdl_parser/CMakeLists.txt b/src/modules/bsdl_parser/CMakeLists.txt deleted file mode 100644 index b41df43..0000000 --- a/src/modules/bsdl_parser/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -set(SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") - -file(GLOB_RECURSE ALL_SOURCES "*.c") - -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..) - -add_library(bsdl_parser ${ALL_SOURCES}) diff --git a/src/modules/bsdl_parser/bsdl_loader.c b/src/modules/bsdl_parser/bsdl_loader.c deleted file mode 100644 index 44c2162..0000000 --- a/src/modules/bsdl_parser/bsdl_loader.c +++ /dev/null @@ -1,1520 +0,0 @@ -/* - * JTAG Core library - * Copyright (c) 2008 - 2024 Viveris Technologies - * - * JTAG Core library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * JTAG Core library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with JTAG Core library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file bsdl_loader.c - * @brief bsdl file parser - * @author Jean-François DEL NERO - */ - -#include -#include -#include -#include -#include - -#include "script/env.h" -#include "jtag_core/jtag_core.h" -#include "bsdl_loader.h" -#include "bsdl_strings.h" -#include "natsort/strnatcmp.h" -#include "os_interface/os_interface.h" -#include "jtag_core/dbg_logs.h" - -#define DEBUG 1 - -char *string_upper(char *str) -{ - while (*str != '\0') - { - *str = toupper((unsigned char)*str); - str++; - } - return str; -} - -int strcmp_nocase(char *str1,char *str2) -{ - int d; - - for(;; str1++, str2++) - { - d = tolower(*str1) - tolower(*str2); - - if(d != 0 || !*str1) - return d; - } - - return 0; -} - -int getnextvalidline(char *buffer,int buffersize,int * offset) -{ - int l_offset; - int current_line_offset; - - l_offset = *offset; - current_line_offset = *offset; - - do - { - // Skip all the blank characters - while( (l_offset < buffersize) && (buffer[l_offset] == ' ' || buffer[l_offset] == '\t') ) - { - l_offset++; - } - - // End of buffer reached ? - if(l_offset == buffersize) - { - *offset = l_offset; - - return 1; - } - - // Is it a return or comment ? - if( buffer[l_offset] != '\r' && buffer[l_offset] != '\n' && (buffer[l_offset] != '-' || buffer[l_offset+1] != '-')) - { - // No. There is something interesting into this line. - *offset = current_line_offset; - return 0; - } - else - { - // Is it a comment ? - if(buffer[l_offset] == '-' && buffer[l_offset+1] == '-') - { - // Yes. Go to the end of the line... - while(buffer[l_offset] != 0 && buffer[l_offset] != '\r' && buffer[l_offset] != '\n') - { - l_offset += 1; - } - } - } - - if( buffer[l_offset] == '\r' || buffer[l_offset] == '\n') - { - l_offset++; - - if(l_offset < buffersize) - { - if( buffer[l_offset] == '\n' ) - { - l_offset++; - } - } - - current_line_offset = l_offset; - } - }while ( (l_offset < buffersize) && buffer[l_offset] ); - - *offset = l_offset; - - return 1; -} - -char getnextchar(char *buffer,int buffersize,int * offset) -{ - char c; - - if (*offset < buffersize) - { - c = buffer[*offset]; - - switch (c) - { - case 0: - return 0; - break; - - case '\r': - *offset += 1; - - if (*offset < buffersize) - { - if (buffer[*offset] == '\n') - { - *offset += 1; - } - - getnextvalidline(buffer, buffersize, offset); - } - - return ' '; - break; - case '\t': - *offset += 1; - return ' '; - break; - case '\n': - *offset += 1; - getnextvalidline(buffer, buffersize, offset); - return ' '; - break; - case '-': - if (buffer[*offset + 1] == '-') - { - while ((*offset < buffersize) && buffer[*offset] != 0 && buffer[*offset] != '\r' && buffer[*offset] != '\n') - { - *offset += 1; - } - - if (*offset < buffersize) - { - if (buffer[*offset] == '\r') - { - *offset += 1; - if (buffer[*offset] == '\n') - { - *offset += 1; - } - - getnextvalidline(buffer, buffersize, offset); - - return ' '; - } - - if (buffer[*offset] == '\n') - { - *offset += 1; - getnextvalidline(buffer, buffersize, offset); - - return ' '; - } - } - else - return 0; - - return ' '; - } - else - { - *offset += 1; - return '-'; - } - - break; - - default: - *offset += 1; - return c; - break; - } - } - - return 0; -} - -int extract_bsdl_lines(char * bsdl_txt, char ** lines) -{ - int offset; - int line_start_offset; - int line_end_offset; - int endofline; - int parenthesis_number; - int inside_quote; - int number_of_lines; - - offset = 0; - number_of_lines = 0; - - do - { - // Find the first word offset into the line... - while( bsdl_txt[offset] ==' ' && bsdl_txt[offset] ) - { - offset++; - } - - line_start_offset = offset; - - parenthesis_number = 0; - endofline = 0; - inside_quote = 0; - - // Scan the line - while( !endofline ) - { - switch( bsdl_txt[offset] ) - { - case 0: - endofline = 1; - break; - - case '(': - if( !inside_quote ) - parenthesis_number++; - offset++; - break; - case ')': - if(parenthesis_number && !inside_quote) - parenthesis_number--; - offset++; - break; - case ';': - if( !parenthesis_number && !inside_quote ) - { - line_end_offset = offset; - - if( line_end_offset - line_start_offset > 0 ) - { - if(lines) - { - lines[number_of_lines] = malloc( (line_end_offset - line_start_offset) + 2 ); - if( lines[number_of_lines] ) - { - memset(lines[number_of_lines],0, (line_end_offset - line_start_offset) + 2 ); - memcpy(lines[number_of_lines],&bsdl_txt[line_start_offset], (line_end_offset - line_start_offset) ); - } - } - - number_of_lines++; - } - - endofline = 1; - - } - offset++; - break; - - case '"': - if(!inside_quote) - inside_quote = 1; - else - inside_quote = 0; - - offset++; - break; - - default: - offset++; - break; - } - } - }while(bsdl_txt[offset]); - - return number_of_lines; -} - -void preprocess_line(char * line) -{ - int inside_quote; - int read_offset,write_offset; - int is_string; - int number_of_spaces; - - inside_quote = 0; - read_offset = 0; - write_offset = 0; - number_of_spaces = 0; - - if(!line) - return; - - // first pass : remove extra blank - while( line[read_offset] ) - { - switch( line[read_offset] ) - { - case ' ': - - if(!number_of_spaces || inside_quote) - { - line[write_offset] = line[read_offset]; - write_offset++; - } - - read_offset++; - number_of_spaces++; - - break; - - case '"': - if(!inside_quote) - inside_quote = 1; - else - inside_quote = 0; - - line[write_offset] = line[read_offset]; - write_offset++; - read_offset++; - number_of_spaces = 0; - - break; - - default: - line[write_offset] = line[read_offset]; - number_of_spaces = 0; - - write_offset++; - read_offset++; - break; - - } - } - - line[write_offset] = 0; - - // second pass : concatenate strings. - - inside_quote = 0; - read_offset = 0; - write_offset = 0; - number_of_spaces = 0; - is_string = 0; - - while( line[read_offset] ) - { - switch( line[read_offset] ) - { - - case '&': - if( inside_quote || !is_string) - { - line[write_offset] = line[read_offset]; - write_offset++; - } - read_offset++; - break; - - case ' ': - if( inside_quote || !is_string) - { - line[write_offset] = line[read_offset]; - write_offset++; - } - read_offset++; - break; - - case '"': - if(!inside_quote) - { - inside_quote = 1; - if( !is_string ) - { - line[write_offset] = line[read_offset]; - write_offset++; - } - - is_string = 1; - } - else - { - inside_quote = 0; - - } - - read_offset++; - break; - - default: - if( !inside_quote ) - { - if( is_string ) - { - line[write_offset] = '"'; - write_offset++; - } - is_string = 0; - } - - line[write_offset] = line[read_offset]; - - write_offset++; - read_offset++; - break; - - } - } - - if( is_string ) - { - line[write_offset] = '"'; - write_offset++; - line[write_offset] = 0; - } -}; - -char * check_next_keyword(char * buffer, char * keyword, char sep) -{ - int i; - char sep_list[16]; - - sep_list[0] = sep; - sep_list[1] = '\0'; - strcat((char*)sep_list,"\"() "); - - if( !buffer ) - return 0; - - // skip the current word - i = 0; - while (buffer[i] && !strchr(sep_list, buffer[i]) ) - { - i++; - } - - // skip the following blank - while (buffer[i] && strchr(sep_list, buffer[i]) ) - { - i++; - } - - if( !strncmp(&buffer[i],keyword,strlen(keyword)) ) - { - return &buffer[i + strlen(keyword)]; - } - - return 0; -} - -int get_next_keyword(jtag_core * jc,char * buffer, char * keyword) -{ - int i,j; - - if( !buffer ) - return 0; - - // skip the current word - i = 0; - while (buffer[i] && !strchr("\"():, ", buffer[i]) ) - { - i++; - } - - // skip the following blank - while (buffer[i] && strchr("\"():, ", buffer[i])) - { - i++; - } - - // copy the word - j = 0; - while (buffer[i] && !strchr("\"():;, ", buffer[i])) - { - if(j < MAX_ELEMENT_SIZE-1) - { - keyword[j] = buffer[i]; - j++; - } - i++; - } - - keyword[j] = 0; - - if( j >= (MAX_ELEMENT_SIZE-1) ) - { - jtagcore_logs_printf(jc,MSG_WARNING,"BSDL loader / get_next_keyword : element too long / truncated : %s\r\n",keyword); - } - - return i; -} - -int get_next_parameter(jtag_core * jc,char * buffer, char * parameter) -{ - int i,j; - - if( !buffer ) - return 0; - - // skip the current word - i = 0; - while (buffer[i] && !strchr("\":, ", buffer[i])) - { - i++; - } - - // skip the following blank - while (buffer[i] && strchr("\":, ", buffer[i])) - { - i++; - } - - // copy the word - j = 0; - while (buffer[i] && !strchr("\":, ;", buffer[i])) - { - if(j < MAX_ELEMENT_SIZE-1) - { - parameter[j] = buffer[i]; - j++; - } - i++; - } - - parameter[j] = 0; - - if( j >= (MAX_ELEMENT_SIZE-1) ) - { - jtagcore_logs_printf(jc,MSG_WARNING,"BSDL loader / get_next_parameter : element too long / truncated : %s\r\n",parameter); - } - - return i; -} - -int check_next_symbol(char * buffer, char c ) -{ - int i; - - if( !buffer ) - return 0; - - // skip the current word - i = 0; - while (buffer[i] && !strchr("\"(): ", buffer[i]) && buffer[i] != c) - { - i++; - } - - // skip the following blank - while(buffer[i] && ( buffer[i] == ' ') ) - { - i++; - } - - if( buffer[i] == c ) - { - return i; - } - else - { - return -1; - } -} - -char * get_attribut(char ** lines,char * name, char * entity) -{ - int i,j; - char * ptr; - i = 0; - - while( lines[i] ) - { - if(!strncmp(lines[i],"attribute ",10)) - { - if(!strncmp(&lines[i][10],name,strlen(name))) - { - ptr = check_next_keyword(&lines[i][10], "of", '\0'); - ptr = check_next_keyword(ptr, entity, ':'); - - if( ptr ) - { - j = 0; - while( ptr[j] && ptr[j] != ':' && ptr[j] == ' ') - { - j++; - } - - if( ptr[j] == ':' ) - { - ptr = check_next_keyword(&ptr[j], "entity", ':'); - ptr = check_next_keyword(ptr, "is", '\0'); - - return ptr; - } - } - - return NULL; - } - } - i++; - } - - return NULL; -} - -char * get_attribut_txt(char ** lines,char * name, char * entity) -{ - int i; - char * attribut_data; - - attribut_data = get_attribut(lines,name, entity); - - if( attribut_data ) - { - i = 0; - while( attribut_data[i] && attribut_data[i]!='"') - { - i++; - } - - if( attribut_data[i] == '"' ) - { - return &attribut_data[i]; - } - - return 0; - } - - return 0; -} - -int get_attribut_int(char ** lines,char * name, char * entity) -{ - int i; - char * attribut_data; - - attribut_data = get_attribut(lines,name, entity); - - if( attribut_data ) - { - i = 0; - while( attribut_data[i] && !( attribut_data[i]>='0' && attribut_data[i]<='9' ) ) - { - i++; - } - - if( ( attribut_data[i]>='0' && attribut_data[i]<='9' ) ) - { - return atoi(&attribut_data[i]); - } - - return 0; - } - - return 0; -} - -int get_next_pin(jtag_core * jc,char * name,int * type, char *line, int * start_index, int * end_index ) -{ - int i; - int io_list_offset; - char tmp_str[256]; - int line_parsed,inside_block; - - i = get_next_keyword(jc,line,name); - - io_list_offset = 0; - - while(line[i] == ' ') - i++; - - if( line[i] == ':' || line[i] == ',' ) - { - *start_index = 0; - *end_index = 0; - - if( line[i] == ',' ) - { - io_list_offset = i + 1; - - while(line[i] != ':' && line[i] != ';' && line[i]) - i++; - if( line[i] != ':' ) - return 0; - } - - i += get_next_keyword(jc,&line[i],(char*)&tmp_str); - - string_upper(tmp_str); - - *type = get_typecode(pintype_str,tmp_str); - - i += get_next_keyword(jc,&line[i],(char*)&tmp_str); - - if (!strcmp_nocase("bit_vector",tmp_str)) - { - while(line[i] != '(' && line[i] != ')' && line[i] != ';') - { - i++; - } - - line_parsed = 0; - inside_block = 0; - - do - { - - switch( line[i] ) - { - case '(': - inside_block++; - if(!line_parsed) - { - i += get_next_keyword(jc,&line[i],(char*)&tmp_str); - *start_index = atoi(tmp_str); - - i += get_next_keyword(jc,&line[i],(char*)&tmp_str); - - i += get_next_keyword(jc,&line[i],(char*)&tmp_str); - *end_index = atoi(tmp_str); - - line_parsed = 1; - - } - break; - case ')': - if ( !inside_block ) - { - return 0; - } - - inside_block--; - break; - case ';': - if( io_list_offset ) - return io_list_offset; - else - return i; - break; - case 0: - break; - - } - i++; - }while (line[i]); - - return 0; - } - - if (!strcmp_nocase("bit",tmp_str)) - { - do - { - switch( line[i] ) - { - case ';': - if( io_list_offset ) - return io_list_offset; - else - return i; - break; - case 0: - break; - } - i++; - }while (line[i]); - } - - } - - return 0; -} - -int get_pins_list(jtag_core * jc,jtag_bsdl * bsdl_desc,char ** lines) -{ - int i,j,k,inc,offset, number_of_pins,vector_size; - char tmp_str[MAX_ELEMENT_SIZE]; - int tmp_type,tmp_start,tmp_end; - i = 0; - - while( lines[i] ) - { - if( !strncmp(lines[i],"port ",5) || !strncmp(lines[i],"port(",5)) - { - j = 0; - number_of_pins = 0; - - while( lines[i][j] != '(' && lines[i][j]) - { - j++; - } - - do - { - offset = get_next_pin(jc,(char*)&tmp_str,&tmp_type, &lines[i][j], &tmp_start, &tmp_end ); - - if( tmp_start <=tmp_end) - { - number_of_pins += ( (tmp_end - tmp_start) + 1 ); - } - else - { - number_of_pins += ( (tmp_start - tmp_end) + 1 ); - } - - j += offset; - - } while( offset); - - if (number_of_pins == 0 || ( number_of_pins > MAX_NUMBER_PINS_PER_DEV ) ) - { - jtagcore_logs_printf(jc, MSG_ERROR, "get_pins_list : bad number of pin found ! : %d\r\n", number_of_pins); - return -1; - } - - bsdl_desc->pins_list = malloc (sizeof(pin_ctrl) * (number_of_pins+1)); - if( bsdl_desc->pins_list ) - { - memset( bsdl_desc->pins_list, 0, sizeof(pin_ctrl) * (number_of_pins+1) ); - - j = 0; - number_of_pins = 0; - - while( lines[i][j] != '(' && lines[i][j]) - { - j++; - } - - do - { - offset = get_next_pin(jc,(char*)&tmp_str,&tmp_type, &lines[i][j], &tmp_start, &tmp_end ); - - if( tmp_start <= tmp_end ) - { - vector_size = ( (tmp_end - tmp_start) + 1 ); - inc = 1; - } - else - { - vector_size = ( (tmp_start - tmp_end) + 1 ); - inc = -1; - } - - j += offset; - - for(k = 0;k < vector_size; k++) - { - snprintf((char*)&bsdl_desc->pins_list[number_of_pins].pinname,sizeof(((pin_ctrl *)0)->pinname),"%s",(char*)tmp_str); - - if( vector_size > 1 ) - { - char digistr[32]; - snprintf((char*)digistr,sizeof(digistr),"(%d)",tmp_start); - genos_strndstcat((char*)&bsdl_desc->pins_list[number_of_pins].pinname,digistr,sizeof(((pin_ctrl *)0)->pinname)); - } - bsdl_desc->pins_list[number_of_pins].pinname[sizeof(((pin_ctrl *)0)->pinname)-1] = '\0'; - - bsdl_desc->pins_list[number_of_pins].pintype = tmp_type; - number_of_pins++; - tmp_start += inc; - } - - } while( offset ); - - bsdl_desc->number_of_pins = number_of_pins; - - return number_of_pins; - } - } - i++; - }; - - return 0; -} - -int get_jtag_chain(jtag_core * jc,jtag_bsdl * bsdl_desc,char ** lines, char * entityname) -{ - char * jtagchain_str; - int i,j,bit_count,end_parse; - char tmp_str[MAX_ELEMENT_SIZE]; - int bit_index; - - bit_count = 0; - bsdl_desc->number_of_chainbits = get_attribut_int(lines,"BOUNDARY_LENGTH", entityname); - if ( ( bsdl_desc->number_of_chainbits > 0 ) && ( bsdl_desc->number_of_chainbits < MAX_NUMBER_BITS_IN_CHAIN ) ) - { - jtagcore_logs_printf(jc,MSG_DEBUG,"Number of bit in the chain = %d\r\n",bsdl_desc->number_of_chainbits); - - bsdl_desc->chain_list = malloc( sizeof(jtag_chain) * bsdl_desc->number_of_chainbits ); - if( !bsdl_desc->chain_list ) - { - jtagcore_logs_printf(jc,MSG_ERROR,"get_jtag_chain : memory alloc error !\r\n"); - return -1; - } - - memset(bsdl_desc->chain_list,0, sizeof(jtag_chain) * bsdl_desc->number_of_chainbits ); - - jtagchain_str = get_attribut_txt(lines,"BOUNDARY_REGISTER", entityname); - - end_parse = 0; - - if(jtagchain_str) - { - if( jtagchain_str[0] == '"' ) - { - i = 0; - while( jtagchain_str[i] && !end_parse ) - { - jtagcore_logs_printf(jc,MSG_DEBUG,"--------------\r\n"); - - // Get index - i += get_next_keyword(jc,&jtagchain_str[i], tmp_str); - bit_index = atoi(tmp_str); - if (bit_index >= 0 && bit_index < bsdl_desc->number_of_chainbits) - { - bsdl_desc->chain_list[bit_index].bit_index = bit_index; - - jtagcore_logs_printf(jc, MSG_DEBUG, "%d\r\n", bsdl_desc->chain_list[bit_index].bit_index); - - // Look for ( - while (jtagchain_str[i] != '(' && jtagchain_str[i]) - i++; - - // Get the pin type - i += get_next_keyword(jc,&jtagchain_str[i], tmp_str); - string_upper(tmp_str); - bsdl_desc->chain_list[bit_index].bit_cell_type = get_typecode(celltype_str, tmp_str); - - jtagcore_logs_printf(jc, MSG_DEBUG, "%d\r\n", bsdl_desc->chain_list[bit_index].bit_cell_type); - - // , - j = check_next_symbol(&jtagchain_str[i], ','); - if (j < 0) - return -1; - i += j; - - // Get the name - i += get_next_parameter(jc,&jtagchain_str[i], bsdl_desc->chain_list[bit_index].pinname); - - jtagcore_logs_printf(jc, MSG_DEBUG, "%s\r\n", bsdl_desc->chain_list[bit_index].pinname); - - // , - j = check_next_symbol(&jtagchain_str[i], ','); - if (j < 0) - return -1; - i += j; - - // Get the type - i += get_next_keyword(jc,&jtagchain_str[i], tmp_str); - string_upper(tmp_str); - bsdl_desc->chain_list[bit_index].bit_type = get_typecode(bittype_str, tmp_str); - - jtagcore_logs_printf(jc, MSG_DEBUG, "%s , %d\r\n", tmp_str, bsdl_desc->chain_list[bit_index].bit_type); - - // , - j = check_next_symbol(&jtagchain_str[i], ','); - if (j < 0) - return -1; - i += j; - - // Get the default state - i += get_next_keyword(jc,&jtagchain_str[i], tmp_str); - string_upper(tmp_str); - bsdl_desc->chain_list[bit_index].safe_state = get_typecode(statetype_str, tmp_str); - - bsdl_desc->chain_list[bit_index].control_bit_index = -1; - - // If no ) Get the ctrl index - j = check_next_symbol(&jtagchain_str[i], ')'); - - if (jtagchain_str[i]==',' || j < 0) - { - // , - j = check_next_symbol(&jtagchain_str[i], ','); - if (j < 0) - return -1; - i += j; - - // Get the control bit - i += get_next_keyword(jc,&jtagchain_str[i], tmp_str); - - bsdl_desc->chain_list[bit_index].control_bit_index = atoi(tmp_str); - - j = check_next_symbol(&jtagchain_str[i], ','); - if (j < 0) - return -1; - i += j; - - // Get the polarity - i += get_next_keyword(jc,&jtagchain_str[i], tmp_str); - string_upper(tmp_str); - bsdl_desc->chain_list[bit_index].control_disable_state = get_typecode(statetype_str, tmp_str); - - j = check_next_symbol(&jtagchain_str[i], ','); - if (j < 0) - return -1; - i += j; - - // Get the off state - i += get_next_keyword(jc,&jtagchain_str[i], tmp_str); - string_upper(tmp_str); - bsdl_desc->chain_list[bit_index].control_disable_result = get_typecode(statetype_str, tmp_str); - - // Find and skip ) - j = check_next_symbol(&jtagchain_str[i], ')'); - if (j < 0) - return -1; - } - - i += j; - - // Find , (Next bit) or " (End of the chain) - i++; - bit_count++; - - if (check_next_symbol(&jtagchain_str[i], '"') >= 0) - { - end_parse = 1; - } - } - else - { - jtagcore_logs_printf(jc, MSG_ERROR, "get_jtag_chain : Error bit index overrun !\r\n"); - } - } - } - } - } - - if( ( bit_count == bsdl_desc->number_of_chainbits ) && ( bsdl_desc->number_of_chainbits != 0 ) ) - { - jtagcore_logs_printf(jc,MSG_DEBUG,"Jtag chain parsing Ok !\r\n"); - - for( i = 0 ; i < (long)bsdl_desc->number_of_pins ; i++ ) - { - - bsdl_desc->pins_list[i].in_bit_number = -1; - bsdl_desc->pins_list[i].out_bit_number = -1; - bsdl_desc->pins_list[i].ctrl_bit_number = -1; - - switch( bsdl_desc->pins_list[i].pintype) - { - case IO_IN: - case IO_OUT: - case IO_INOUT: - - for( j = 0 ; j < (long)bsdl_desc->number_of_chainbits ; j++ ) - { - if(!strcmp(bsdl_desc->chain_list[j].pinname, bsdl_desc->pins_list[i].pinname)) - { - switch( bsdl_desc->chain_list[j].bit_type) - { - case BITTYPE_INPUT: - bsdl_desc->pins_list[i].in_bit_number = bsdl_desc->chain_list[j].bit_index; - break; - case BITTYPE_OUTPUT: - bsdl_desc->pins_list[i].out_bit_number = bsdl_desc->chain_list[j].bit_index; - break; - case BITTYPE_TRISTATE_OUTPUT: - bsdl_desc->pins_list[i].out_bit_number = bsdl_desc->chain_list[j].bit_index; - bsdl_desc->pins_list[i].ctrl_bit_number = bsdl_desc->chain_list[j].control_bit_index; - break; - case BITTYPE_INOUT: - bsdl_desc->pins_list[i].in_bit_number = bsdl_desc->chain_list[j].bit_index; - bsdl_desc->pins_list[i].out_bit_number = bsdl_desc->chain_list[j].bit_index; - bsdl_desc->pins_list[i].ctrl_bit_number = bsdl_desc->chain_list[j].control_bit_index; - break; - } - } - } - break; - } - } - - return 1; - } - else - { - jtagcore_logs_printf(jc,MSG_DEBUG,"JTAG chain parsing error : %d - %d !\r\n",bit_count,bsdl_desc->number_of_chainbits); - return -1; - } -} - -static int compare_pin_name(const void *a, const void *b) -{ - int ret; - pin_ctrl const *pa = (pin_ctrl const *)a; - pin_ctrl const *pb = (pin_ctrl const *)b; - - ret = strnatcmp(pa->pinname, pb->pinname); - - return ret; -} - -jtag_bsdl * load_bsdlfile(jtag_core * jc,char *filename) -{ - FILE * bsdl_file; - jtag_bsdl * bsdl; - int file_size,offset; - char * bsdl_txt,*tmp_bsdl_txt; - char * tmp_ptr; - int i,number_of_bsdl_lines; - char entityname[256]; - char * chipid_str,* instruct_str; - char * instruct_strchr; - char ** lines; - - jtagcore_logs_printf(jc,MSG_INFO_0,"Open BSDL file %s\r\n",filename); - - bsdl = 0; - - bsdl_file = fopen(filename,"rb"); - if (bsdl_file) - { - fseek(bsdl_file, 0, SEEK_END); - file_size = ftell(bsdl_file); - fseek(bsdl_file, 0, SEEK_SET); - - if ( file_size <= 0 || file_size > MAX_BSDL_FILE_SIZE ) - { - jtagcore_logs_printf(jc, MSG_ERROR, "Bad BSDL File size ! : %d\r\n", file_size); - fclose(bsdl_file); - return 0; - } - - jtagcore_logs_printf(jc, MSG_DEBUG, "BSDL file size : %d\r\n", file_size); - - bsdl_txt = malloc(file_size + 1); - if (bsdl_txt) - { - memset(bsdl_txt, 0, file_size + 1); - if( fread(bsdl_txt, file_size, 1, bsdl_file) != 1 ) - { - free(bsdl_txt); - jtagcore_logs_printf(jc, MSG_ERROR, "BSDL File read error !\r\n"); - fclose(bsdl_file); - return 0; - } - - tmp_bsdl_txt = malloc(file_size + 1); - if (tmp_bsdl_txt) - { - memset(tmp_bsdl_txt, 0, file_size + 1); - offset = 0; - - i = 0; - while (offset < file_size && i < file_size) - { - tmp_bsdl_txt[i] = getnextchar(bsdl_txt, file_size, &offset); - i++; - } - - free(bsdl_txt); - - if (offset < i) - { - jtagcore_logs_printf(jc, MSG_ERROR, "Preprocessing error !\r\n"); - free(tmp_bsdl_txt); - return 0; - } - - bsdl_txt = tmp_bsdl_txt; - } - else - { - jtagcore_logs_printf(jc, MSG_ERROR, "Can't allocate file memory !\r\n"); - free(bsdl_txt); - fclose(bsdl_file); - return 0; - } - } - else - { - jtagcore_logs_printf(jc, MSG_ERROR, "Can't allocate file memory !\r\n"); - fclose(bsdl_file); - return 0; - } - } - else - { - jtagcore_logs_printf(jc, MSG_ERROR, "Can't open %s !\r\n", filename); - return 0; - } - - fclose(bsdl_file); - - // Get the first entity offset - tmp_ptr = strstr(bsdl_txt,"entity"); - if (!tmp_ptr) - { - jtagcore_logs_printf(jc, MSG_ERROR, "entry \"entity\" not found !\r\n"); - free(bsdl_txt); - return 0; - } - - offset = tmp_ptr - bsdl_txt; - - // skip the entity keyword - while( bsdl_txt[offset] !=' ' && bsdl_txt[offset] ) - offset++; - - // skip the blank spaces - while( bsdl_txt[offset] ==' ' && bsdl_txt[offset] ) - offset++; - - // copy the entity name - i = 0; - memset(entityname,0,sizeof(entityname)); - while( bsdl_txt[offset] !=' ' && bsdl_txt[offset] && i < ( sizeof(entityname) - 1 )) - { - entityname[i] = bsdl_txt[offset]; - - offset++; - i++; - } - - // skip the blank spaces - while( bsdl_txt[offset] ==' ' && bsdl_txt[offset] ) - offset++; - - // Check the "is" keyword presence - if( strncmp(&bsdl_txt[offset],"is",2) ) - { - jtagcore_logs_printf(jc, MSG_ERROR, "Bad entity entry (\"is\" not found)\r\n"); - free(bsdl_txt); - return 0; - } - - jtagcore_logs_printf(jc,MSG_DEBUG,"Entity : %s\r\n",entityname); - - offset += 2; - - // extract and separate each bsdl line - number_of_bsdl_lines = extract_bsdl_lines(&bsdl_txt[offset],0); - jtagcore_logs_printf(jc,MSG_DEBUG,"lines :%d\r\n",number_of_bsdl_lines); - - if (number_of_bsdl_lines <= 0 || number_of_bsdl_lines > MAX_NUMBER_OF_BSDL_LINES) - { - jtagcore_logs_printf(jc, MSG_ERROR, "No line found !\r\n"); - free(bsdl_txt); - return 0; - } - - lines = malloc( sizeof(char*) * ( number_of_bsdl_lines + 1 ) ); - if( !lines ) - { - jtagcore_logs_printf(jc,MSG_ERROR,"load_bsdlfile : memory alloc error !\r\n"); - free(tmp_bsdl_txt); - return 0; - } - - memset( lines, 0, sizeof(char*) * ( number_of_bsdl_lines + 1 ) ); - - extract_bsdl_lines(&bsdl_txt[offset],lines); - - for(i= 0 ;i< number_of_bsdl_lines;i++) - { - preprocess_line(lines[i]); - } - - bsdl = malloc ( sizeof(jtag_bsdl) ); - if (!bsdl) - { - jtagcore_logs_printf(jc, MSG_ERROR, "load_bsdlfile : memory alloc error !\r\n"); - for( i = 0 ;i < number_of_bsdl_lines ; i++ ) - { - if(lines[i]) - { - free(lines[i]); - lines[i] = 0; - } - } - free(lines); - - free(bsdl_txt); - - return 0; - } - - memset( bsdl , 0 , sizeof(jtag_bsdl) ); - - /////////////////////// - // copy the entity name & the file name - strncpy(bsdl->entity_name,entityname,sizeof(((jtag_bsdl *)0)->entity_name) - 1); - bsdl->entity_name[ sizeof(((jtag_bsdl *)0)->entity_name) - 1 ] = '\0'; - - i = strlen(filename); - while(i && filename[i] != '\\') - { - i--; - } - - if(filename[i] == '\\') - i++; - - strncpy(bsdl->src_filename,&filename[i],sizeof(bsdl->src_filename) - 1); - bsdl->src_filename[ sizeof(bsdl->src_filename) - 1 ] = '0'; - - /////////////////////// - // Extract the chip ID - bsdl->chip_id = 0x00000000; - bsdl->chip_id_mask = 0xFFFFFFFF; - - chipid_str = get_attribut_txt(lines,"IDCODE_REGISTER", entityname); - if(chipid_str) - { - if( chipid_str[0] == '"' ) - { - chipid_str++; - i = 0; - while(chipid_str[i]!='"' && chipid_str[i]!=';' && chipid_str[i] && i < 32) - { - switch( chipid_str[i] ) - { - case '0': - bsdl->chip_id &= ~(0x80000000 >> i); - break; - - case '1': - bsdl->chip_id |= (0x80000000 >> i); - break; - - case 'x': - case 'X': - bsdl->chip_id_mask &= ~(0x80000000 >> i); - break; - - default: - break; - } - - i++; - } - } - } - - jtagcore_logs_printf(jc,MSG_INFO_0,"ID Code: 0x%.8X\r\n",bsdl->chip_id); - - /////////////////////// - // Extract the pins list - get_pins_list(jc,bsdl,lines); - - /////////////////////// - // Extract the JTAG Chain - if(get_jtag_chain(jc,bsdl,lines,entityname)<0) - { - jtagcore_logs_printf(jc,MSG_ERROR,"load_bsdlfile : Error during jtag chain parsing !\r\n"); - } - - if(jtagcore_getEnvVarValue( jc, "BSDL_LOADER_SORT_PINS_NAME" ) > 0) - { - // Count the pins - i = 0; - while(bsdl->pins_list[i].pinname[0]) - { - i++; - } - - // Sort them - qsort(bsdl->pins_list, i, sizeof bsdl->pins_list[0], compare_pin_name); - } - - if(bsdl->pins_list) - { - i = 0; - while(bsdl->pins_list[i].pinname[0]) - { - char dbg_str[512]; - int namelen,j,k; - char disval; - - namelen = strlen(bsdl->pins_list[i].pinname); - - sprintf(dbg_str,"Pin %s",bsdl->pins_list[i].pinname); - for(j=0;j<(16 - namelen);j++) - { - strcat(dbg_str," "); - } - - k = strlen(dbg_str); - - disval = 'X'; - - if(bsdl->pins_list[i].out_bit_number >=0 ) - { - if( bsdl->chain_list[bsdl->pins_list[i].out_bit_number].control_disable_state >= 0 ) - { - disval = '0' + bsdl->chain_list[bsdl->pins_list[i].out_bit_number].control_disable_state; - } - } - - sprintf(&dbg_str[k]," type %.2d, ctrl %.3d (disval:%c), out %.3d, in %.3d\r\n", - bsdl->pins_list[i].pintype, - bsdl->pins_list[i].ctrl_bit_number, - disval, - bsdl->pins_list[i].out_bit_number, - bsdl->pins_list[i].in_bit_number); - - jtagcore_logs_printf(jc,MSG_DEBUG,dbg_str); - - i++; - } - } - - /////////////////////// - // Get the instruction code - - bsdl->number_of_bits_per_instruction = get_attribut_int(lines,"INSTRUCTION_LENGTH", entityname); - - jtagcore_logs_printf(jc,MSG_INFO_0,"Instructions lenght : %d\r\n",bsdl->number_of_bits_per_instruction); - - instruct_str = get_attribut_txt(lines,"INSTRUCTION_OPCODE", entityname); - if(instruct_str) - { - instruct_strchr = strstr(instruct_str,"IDCODE"); - if(!instruct_strchr) - instruct_strchr = strstr(instruct_str,"idcode"); - if(instruct_strchr) - { - get_next_keyword(jc,instruct_strchr, bsdl->IDCODE_Instruction); - jtagcore_logs_printf(jc,MSG_DEBUG,"IDCODE : %s\r\n",bsdl->IDCODE_Instruction); - } - - instruct_strchr = strstr(instruct_str,"EXTEST"); - if(!instruct_strchr) - instruct_strchr = strstr(instruct_str,"extest"); - - if(instruct_strchr) - { - get_next_keyword(jc,instruct_strchr, bsdl->EXTEST_Instruction); - jtagcore_logs_printf(jc,MSG_DEBUG,"EXTEST : %s\r\n",bsdl->EXTEST_Instruction); - } - - instruct_strchr = strstr(instruct_str,"BYPASS"); - if(!instruct_strchr) - instruct_strchr = strstr(instruct_str,"bypass"); - - if(instruct_strchr) - { - get_next_keyword(jc,instruct_strchr, bsdl->BYPASS_Instruction); - jtagcore_logs_printf(jc,MSG_DEBUG,"BYPASS : %s\r\n",bsdl->BYPASS_Instruction); - } - - instruct_strchr = strstr(instruct_str,"SAMPLE"); - if(!instruct_strchr) - instruct_strchr = strstr(instruct_str,"sample"); - if(instruct_strchr) - { - get_next_keyword(jc,instruct_strchr, bsdl->SAMPLE_Instruction); - jtagcore_logs_printf(jc,MSG_DEBUG,"SAMPLE : %s\r\n",bsdl->SAMPLE_Instruction); - } - } - - free( bsdl_txt ); - - for( i = 0 ;i < number_of_bsdl_lines ; i++ ) - { - if(lines[i]) - { - free(lines[i]); - lines[i] = 0; - } - } - - free(lines); - - jtagcore_logs_printf(jc,MSG_INFO_0,"BSDL file %s loaded and parsed\r\n",filename); - - return bsdl; -} - -void unload_bsdlfile(jtag_core * jc, jtag_bsdl * bsdl) -{ - if( bsdl ) - { - if(bsdl->chain_list) - free(bsdl->chain_list); - - if(bsdl->pins_list) - free(bsdl->pins_list); - - free( bsdl ); - } -} diff --git a/src/modules/bsdl_parser/bsdl_loader.h b/src/modules/bsdl_parser/bsdl_loader.h deleted file mode 100644 index 938176f..0000000 --- a/src/modules/bsdl_parser/bsdl_loader.h +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef _BSDL_LOADER_H -#define _BSDL_LOADER_H -/* - * JTAG Core library - * Copyright (c) 2008 - 2024 Viveris Technologies - * - * JTAG Core library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * JTAG Core library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with JTAG Core library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file bsdl_loader.h - * @brief bsdl file parser header - * @author Jean-François DEL NERO - */ - -#include "jtag_core/jtag_core.h" - -#define MAX_ELEMENT_SIZE (64+1) - -typedef struct _pin_ctrl -{ - char pinname[MAX_ELEMENT_SIZE]; - int pintype; - - char physical_pin[MAX_ELEMENT_SIZE]; - - int ctrl_bit_number; - int out_bit_number; - int in_bit_number; -}pin_ctrl; - -typedef struct _jtag_chain -{ - int bit_index; - - int bit_cell_type; // BC_1,BC_2,... - - char pinname[MAX_ELEMENT_SIZE]; // Pin name. - - int bit_type; // None , ctrl , in, out. - - int safe_state; // Default - Safe state. (0,1,-1) - - int control_bit_index; // Indicate the associated control bit. -1 if no control bit. - int control_disable_state; - int control_disable_result; - -}jtag_chain; - -typedef struct _jtag_bsdl -{ - unsigned long chip_id; - unsigned long chip_id_mask; - - char src_filename[512]; - char entity_name[512]; - - int number_of_chainbits; - jtag_chain * chain_list; - - int number_of_pins; - pin_ctrl * pins_list; - - int number_of_bits_per_instruction; - char IDCODE_Instruction[MAX_ELEMENT_SIZE]; - char EXTEST_Instruction[MAX_ELEMENT_SIZE]; - char BYPASS_Instruction[MAX_ELEMENT_SIZE]; - char SAMPLE_Instruction[MAX_ELEMENT_SIZE]; - -}jtag_bsdl; - -jtag_bsdl * load_bsdlfile(jtag_core * jc,char *filename); -void unload_bsdlfile(jtag_core * jc, jtag_bsdl * bsdl); - -#endif \ No newline at end of file diff --git a/src/modules/bsdl_parser/bsdl_strings.c b/src/modules/bsdl_parser/bsdl_strings.c deleted file mode 100644 index 0dee4cd..0000000 --- a/src/modules/bsdl_parser/bsdl_strings.c +++ /dev/null @@ -1,93 +0,0 @@ -/* - * JTAG Core library - * Copyright (c) 2008 - 2024 Viveris Technologies - * - * JTAG Core library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * JTAG Core library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with JTAG Core library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file bsdl_strings.c - * @brief bsdl file string keywords - * @author Jean-François DEL NERO - */ - -#include - -#include "jtag_core/jtag_core.h" - -#include "bsdl_loader.h" -#include "bsdl_strings.h" - -type_strings celltype_str[]= -{ - {"BC_1",CELLTYPE_BC1}, - {"BC_2",CELLTYPE_BC2}, - {"BC_3",CELLTYPE_BC3}, - {"BC_4",CELLTYPE_BC4}, - {"BC_5",CELLTYPE_BC5}, - {"BC_6",CELLTYPE_BC6}, - {"BC_7",CELLTYPE_BC7}, - - {0,CELLTYPE_UNKNOWN} -}; - -type_strings bittype_str[]= -{ - {"INPUT",BITTYPE_INPUT}, - {"OBSERVE_ONLY",BITTYPE_INPUT}, - {"OUTPUT",BITTYPE_OUTPUT}, - {"OUTPUT2", BITTYPE_OUTPUT }, - {"OUTPUT3",BITTYPE_TRISTATE_OUTPUT}, - {"BIDIR",BITTYPE_INOUT}, - {"CONTROL",BITTYPE_CONTROL}, - {"CONTROLR",BITTYPE_CONTROL}, - {"INTERNAL",BITTYPE_INTERNAL}, - {0,BITTYPE_UNKNOWN} -}; - -type_strings statetype_str[]= -{ - {"X",STATE_UNDEF}, - {"1",STATE_HIGH}, - {"0",STATE_LOW}, - {"Z",STATE_HIGHZ}, - {0,STATE_UNKNOWN} -}; - -type_strings pintype_str[]= -{ - {"IN",IO_IN}, - {"OUT",IO_OUT}, - {"INOUT",IO_INOUT}, - {"BUFFER", IO_OUT }, - {0,IO_UNDEF} -}; - -int get_typecode(type_strings * typelist,char * name) -{ - int i; - - i = 0; - while( typelist[i].type_name ) - { - if(!strcmp( typelist[i].type_name, name ) ) - { - return typelist[i].type_code; - } - i++; - } - - return typelist[i].type_code; -} diff --git a/src/modules/bsdl_parser/bsdl_strings.h b/src/modules/bsdl_parser/bsdl_strings.h deleted file mode 100644 index 80c3bc9..0000000 --- a/src/modules/bsdl_parser/bsdl_strings.h +++ /dev/null @@ -1,81 +0,0 @@ -#ifndef _BSDL_STRING_H -#define _BSDL_STRING_H -/* - * JTAG Core library - * Copyright (c) 2008 - 2024 Viveris Technologies - * - * JTAG Core library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * JTAG Core library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with JTAG Core library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file bsdl_strings.h - * @brief bsdl file string keywords header - * @author Jean-François DEL NERO - */ - -typedef struct type_strings_ -{ - char * type_name; - int type_code; -}type_strings; - -enum CELLTYPE -{ - CELLTYPE_UNKNOWN = 0x00, - CELLTYPE_BC1, - CELLTYPE_BC2, - CELLTYPE_BC3, - CELLTYPE_BC4, - CELLTYPE_BC5, - CELLTYPE_BC6, - CELLTYPE_BC7 -}; - -enum BITTYPE -{ - BITTYPE_UNKNOWN = 0x00, - BITTYPE_INPUT, - BITTYPE_OUTPUT, - BITTYPE_TRISTATE_OUTPUT, - BITTYPE_INOUT, - BITTYPE_CONTROL, - BITTYPE_INTERNAL -}; - -enum STATETYPE -{ - STATE_UNKNOWN = 0x00, - STATE_UNDEF, - STATE_HIGH, - STATE_LOW, - STATE_HIGHZ -}; - -enum PINIOTYPE -{ - IO_UNDEF = 0x00, - IO_IN, - IO_OUT, - IO_INOUT -}; - -extern type_strings celltype_str[]; -extern type_strings bittype_str[]; -extern type_strings statetype_str[]; -extern type_strings pintype_str[]; - -int get_typecode(type_strings * typelist,char * name); - -#endif \ No newline at end of file diff --git a/src/modules/bus_over_jtag/CMakeLists.txt b/src/modules/bus_over_jtag/CMakeLists.txt index 478a892..47f8f5f 100644 --- a/src/modules/bus_over_jtag/CMakeLists.txt +++ b/src/modules/bus_over_jtag/CMakeLists.txt @@ -5,3 +5,4 @@ file(GLOB_RECURSE ALL_SOURCES "*.c") include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..) add_library(bus_over_jtag ${ALL_SOURCES}) +target_link_libraries(bus_over_jtag PUBLIC bsdl::bsdl) diff --git a/src/modules/bus_over_jtag/i2c_over_jtag.c b/src/modules/bus_over_jtag/i2c_over_jtag.c index 61b1254..5d73de3 100644 --- a/src/modules/bus_over_jtag/i2c_over_jtag.c +++ b/src/modules/bus_over_jtag/i2c_over_jtag.c @@ -29,7 +29,7 @@ #include "jtag_core/jtag_core.h" -#include "bsdl_parser/bsdl_loader.h" +#include #include "drivers/drivers_list.h" @@ -41,7 +41,7 @@ int jtagcore_i2c_set_scl_pin(jtag_core * jc, int device, int pin) { - jtag_bsdl * bsdl_file; + bsdl_t * bsdl_file; if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >= 0) { @@ -49,7 +49,7 @@ int jtagcore_i2c_set_scl_pin(jtag_core * jc, int device, int pin) { bsdl_file = jc->devices_list[device].bsdl; - if (pin < bsdl_file->number_of_pins && pin >= 0) + if (pin < (int)bsdl_file->pin_count && pin >= 0) { jc->i2c_scl_pin = pin; jc->i2c_scl_device = device; @@ -70,7 +70,7 @@ int jtagcore_i2c_set_scl_pin(jtag_core * jc, int device, int pin) int jtagcore_i2c_set_sda_pin(jtag_core * jc, int device, int pin) { - jtag_bsdl * bsdl_file; + bsdl_t * bsdl_file; if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >= 0) { @@ -78,7 +78,7 @@ int jtagcore_i2c_set_sda_pin(jtag_core * jc, int device, int pin) { bsdl_file = jc->devices_list[device].bsdl; - if (pin < bsdl_file->number_of_pins && pin >= 0) + if (pin < (int)bsdl_file->pin_count && pin >= 0) { jc->i2c_sda_pin = pin; jc->i2c_sda_device = device; diff --git a/src/modules/bus_over_jtag/mdio_over_jtag.c b/src/modules/bus_over_jtag/mdio_over_jtag.c index 11b9e7b..b2f4bee 100644 --- a/src/modules/bus_over_jtag/mdio_over_jtag.c +++ b/src/modules/bus_over_jtag/mdio_over_jtag.c @@ -29,7 +29,7 @@ #include "jtag_core/jtag_core.h" -#include "bsdl_parser/bsdl_loader.h" +#include #include "drivers/drivers_list.h" @@ -39,7 +39,7 @@ int jtagcore_mdio_set_mdc_pin(jtag_core * jc, int device, int pin) { - jtag_bsdl * bsdl_file; + bsdl_t * bsdl_file; if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >= 0) { @@ -47,7 +47,7 @@ int jtagcore_mdio_set_mdc_pin(jtag_core * jc, int device, int pin) { bsdl_file = jc->devices_list[device].bsdl; - if (pin < bsdl_file->number_of_pins && pin >= 0) + if (pin < (int)bsdl_file->pin_count && pin >= 0) { jc->mdio_mdc_pin = pin; jc->mdio_mdc_device = device; @@ -61,7 +61,7 @@ int jtagcore_mdio_set_mdc_pin(jtag_core * jc, int device, int pin) int jtagcore_mdio_set_mdio_pin(jtag_core * jc, int device, int pin) { - jtag_bsdl * bsdl_file; + bsdl_t * bsdl_file; if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >=0) { @@ -69,7 +69,7 @@ int jtagcore_mdio_set_mdio_pin(jtag_core * jc, int device, int pin) { bsdl_file = jc->devices_list[device].bsdl; - if (pin < bsdl_file->number_of_pins && pin >= 0) + if (pin < (int)bsdl_file->pin_count && pin >= 0) { jc->mdio_mdio_pin = pin; jc->mdio_mdio_device = device; diff --git a/src/modules/bus_over_jtag/memory_over_jtag.c b/src/modules/bus_over_jtag/memory_over_jtag.c index fcb3c0a..3b4af2b 100644 --- a/src/modules/bus_over_jtag/memory_over_jtag.c +++ b/src/modules/bus_over_jtag/memory_over_jtag.c @@ -29,7 +29,7 @@ #include "jtag_core/jtag_core.h" -#include "bsdl_parser/bsdl_loader.h" +#include #include "drivers/drivers_list.h" @@ -61,7 +61,7 @@ int jtagcore_memory_clear_pins(jtag_core * jc) int jtagcore_memory_set_address_pin(jtag_core * jc, int address_bit, int device, int pin) { - jtag_bsdl * bsdl_file; + bsdl_t * bsdl_file; if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >= 0 && address_bit < MAX_BUS_WIDTH) { @@ -69,7 +69,7 @@ int jtagcore_memory_set_address_pin(jtag_core * jc, int address_bit, int device, { bsdl_file = jc->devices_list[device].bsdl; - if ( pin < bsdl_file->number_of_pins && pin >= 0 ) + if ( pin < (int)bsdl_file->pin_count && pin >= 0 ) { jc->ram_address_pin[address_bit] = pin; jc->ram_address_device[address_bit] = device; @@ -83,7 +83,7 @@ int jtagcore_memory_set_address_pin(jtag_core * jc, int address_bit, int device, int jtagcore_memory_set_data_pin(jtag_core * jc, int data_bit, int device, int pin) { - jtag_bsdl * bsdl_file; + bsdl_t * bsdl_file; if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >= 0 && data_bit < MAX_BUS_WIDTH) { @@ -91,7 +91,7 @@ int jtagcore_memory_set_data_pin(jtag_core * jc, int data_bit, int device, int p { bsdl_file = jc->devices_list[device].bsdl; - if ( pin < bsdl_file->number_of_pins && pin >= 0 ) + if ( pin < (int)bsdl_file->pin_count && pin >= 0 ) { jc->ram_data_pin[data_bit] = pin; jc->ram_data_device[data_bit] = device; @@ -105,7 +105,7 @@ int jtagcore_memory_set_data_pin(jtag_core * jc, int data_bit, int device, int p int jtagcore_memory_set_ctrl_pin(jtag_core * jc, int ctrl, int polarity, int device, int pin) { - jtag_bsdl * bsdl_file; + bsdl_t * bsdl_file; if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >= 0 && ctrl < 16) { @@ -113,7 +113,7 @@ int jtagcore_memory_set_ctrl_pin(jtag_core * jc, int ctrl, int polarity, int dev { bsdl_file = jc->devices_list[device].bsdl; - if ( pin < bsdl_file->number_of_pins && pin >= 0 ) + if ( pin < (int)bsdl_file->pin_count && pin >= 0 ) { jc->ram_ctrl_pin[ctrl] = pin; jc->ram_ctrl_pin_pol[ctrl] = polarity; diff --git a/src/modules/bus_over_jtag/spi_over_jtag.c b/src/modules/bus_over_jtag/spi_over_jtag.c index 2babe14..25b2427 100644 --- a/src/modules/bus_over_jtag/spi_over_jtag.c +++ b/src/modules/bus_over_jtag/spi_over_jtag.c @@ -29,7 +29,7 @@ #include "jtag_core/jtag_core.h" -#include "bsdl_parser/bsdl_loader.h" +#include #include "drivers/drivers_list.h" @@ -39,7 +39,7 @@ int jtagcore_spi_set_mosi_pin(jtag_core * jc, int device, int pin, int sample_clk_phase) { - jtag_bsdl * bsdl_file; + bsdl_t * bsdl_file; if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >= 0) { @@ -47,7 +47,7 @@ int jtagcore_spi_set_mosi_pin(jtag_core * jc, int device, int pin, int sample_cl { bsdl_file = jc->devices_list[device].bsdl; - if (pin < bsdl_file->number_of_pins && pin >= 0) + if (pin < (int)bsdl_file->pin_count && pin >= 0) { jc->spi_mosi_pin = pin; if(sample_clk_phase) @@ -65,7 +65,7 @@ int jtagcore_spi_set_mosi_pin(jtag_core * jc, int device, int pin, int sample_cl int jtagcore_spi_set_miso_pin(jtag_core * jc, int device, int pin, int sample_clk_phase) { - jtag_bsdl * bsdl_file; + bsdl_t * bsdl_file; if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >= 0) { @@ -73,7 +73,7 @@ int jtagcore_spi_set_miso_pin(jtag_core * jc, int device, int pin, int sample_cl { bsdl_file = jc->devices_list[device].bsdl; - if (pin < bsdl_file->number_of_pins && pin >= 0) + if (pin < (int)bsdl_file->pin_count && pin >= 0) { jc->spi_miso_pin = pin; if(sample_clk_phase) @@ -91,7 +91,7 @@ int jtagcore_spi_set_miso_pin(jtag_core * jc, int device, int pin, int sample_cl int jtagcore_spi_set_clk_pin(jtag_core * jc, int device, int pin, int polarity) { - jtag_bsdl * bsdl_file; + bsdl_t * bsdl_file; if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >= 0) { @@ -99,7 +99,7 @@ int jtagcore_spi_set_clk_pin(jtag_core * jc, int device, int pin, int polarity) { bsdl_file = jc->devices_list[device].bsdl; - if (pin < bsdl_file->number_of_pins && pin >= 0) + if (pin < (int)bsdl_file->pin_count && pin >= 0) { jc->spi_clk_pin = pin; if(polarity) @@ -117,7 +117,7 @@ int jtagcore_spi_set_clk_pin(jtag_core * jc, int device, int pin, int polarity) int jtagcore_spi_set_cs_pin(jtag_core * jc, int device, int pin, int polarity) { - jtag_bsdl * bsdl_file; + bsdl_t * bsdl_file; if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >= 0) { @@ -125,7 +125,7 @@ int jtagcore_spi_set_cs_pin(jtag_core * jc, int device, int pin, int polarity) { bsdl_file = jc->devices_list[device].bsdl; - if (pin < bsdl_file->number_of_pins && pin >= 0) + if (pin < (int)bsdl_file->pin_count && pin >= 0) { jc->spi_cs_pin = pin; if(polarity) diff --git a/src/modules/drivers/CMakeLists.txt b/src/modules/drivers/CMakeLists.txt index fb3a7eb..ab79b10 100644 --- a/src/modules/drivers/CMakeLists.txt +++ b/src/modules/drivers/CMakeLists.txt @@ -20,7 +20,7 @@ add_library(drivers ${MAIN_SOURCES} ${FTDI_SOURCES} ${GPIO_SOURCES} ${JLINK_SOUR find_package(PkgConfig REQUIRED) pkg_check_modules(LIBFTDI REQUIRED IMPORTED_TARGET libftdi1) pkg_check_modules(LIBUSB REQUIRED IMPORTED_TARGET libusb-1.0) -target_link_libraries(drivers PUBLIC PkgConfig::LIBFTDI PkgConfig::LIBUSB) +target_link_libraries(drivers PUBLIC PkgConfig::LIBFTDI PkgConfig::LIBUSB bsdl::bsdl) if(BS_ENABLE_DIGILENT) target_link_libraries(drivers PUBLIC ${CMAKE_DL_LIBS}) diff --git a/src/modules/drivers/drivers_list.c b/src/modules/drivers/drivers_list.c index 6940a51..d1b143c 100644 --- a/src/modules/drivers/drivers_list.c +++ b/src/modules/drivers/drivers_list.c @@ -25,7 +25,7 @@ #include "jtag_core/jtag_core.h" -#include "bsdl_parser/bsdl_loader.h" +#include #ifdef WIN32 #include "./lpt_jtag/lpt_jtag_drv.h" diff --git a/src/modules/drivers/drv_loader.c b/src/modules/drivers/drv_loader.c index c465104..d30f5c8 100644 --- a/src/modules/drivers/drv_loader.c +++ b/src/modules/drivers/drv_loader.c @@ -28,7 +28,7 @@ #include "jtag_core/jtag_core.h" -#include "bsdl_parser/bsdl_loader.h" +#include #include "drivers_list.h" diff --git a/src/modules/jtag_core/CMakeLists.txt b/src/modules/jtag_core/CMakeLists.txt index e96af35..a920be6 100644 --- a/src/modules/jtag_core/CMakeLists.txt +++ b/src/modules/jtag_core/CMakeLists.txt @@ -20,4 +20,5 @@ add_custom_target( include_directories(${DIR_MODULES}) add_library(jtag_core ${ALL_SOURCES}) -add_dependencies(jtag_core prebuild) \ No newline at end of file +add_dependencies(jtag_core prebuild) +target_link_libraries(jtag_core PUBLIC bsdl::bsdl) \ No newline at end of file diff --git a/src/modules/jtag_core/jtag_core.c b/src/modules/jtag_core/jtag_core.c index 7f9fc42..36a6255 100644 --- a/src/modules/jtag_core/jtag_core.c +++ b/src/modules/jtag_core/jtag_core.c @@ -32,13 +32,27 @@ #include "script/env.h" -#include "bsdl_parser/bsdl_loader.h" -#include "bsdl_parser/bsdl_strings.h" +#include #include "drivers/drivers_list.h" /* #include "config_script.h" */ +/* Look up an INSTRUCTION_OPCODE by name. Returns the bit-string (e.g. + * "00000000001") or NULL if absent. */ +static const char * jc_bsdl_opcode(const bsdl_t * b, const char * name) +{ + size_t i; + if (!b) + return NULL; + for (i = 0; i < b->instruction_count; i++) + { + if (b->instructions[i].name && !strcmp(b->instructions[i].name, name)) + return b->instructions[i].opcode; + } + return NULL; +} + jtag_core * jtagcore_init() { jtag_core * jc; @@ -86,7 +100,7 @@ int jtagcore_scan_and_init_chain(jtag_core * jc) { if (jc->devices_list[i].bsdl) { - unload_bsdlfile(jc,jc->devices_list[i].bsdl); + bsdl_free(jc->devices_list[i].bsdl); jc->devices_list[i].bsdl = 0; } } @@ -272,12 +286,12 @@ unsigned long jtagcore_get_dev_id(jtag_core * jc,int device) int jtagcore_loadbsdlfile(jtag_core * jc, char * path, int device) { - jtag_bsdl * bsdl_file; + bsdl_t * bsdl_file; int i; if ( (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >= 0) || device == -1) { - bsdl_file = load_bsdlfile(jc,path); + bsdl_file = bsdl_parse_file(path, NULL); if (bsdl_file) { if (device == -1) @@ -288,7 +302,7 @@ int jtagcore_loadbsdlfile(jtag_core * jc, char * path, int device) { if (jc->devices_list[i].bsdl) { - unload_bsdlfile(jc,jc->devices_list[i].bsdl); + bsdl_free(jc->devices_list[i].bsdl); jc->devices_list[i].bsdl = 0; } @@ -304,7 +318,7 @@ int jtagcore_loadbsdlfile(jtag_core * jc, char * path, int device) { if (jc->devices_list[device].bsdl) { - unload_bsdlfile(jc,jc->devices_list[device].bsdl); + bsdl_free(jc->devices_list[device].bsdl); } jc->devices_list[device].bsdl = bsdl_file; @@ -316,20 +330,21 @@ int jtagcore_loadbsdlfile(jtag_core * jc, char * path, int device) if (jc->devices_list[device].out_boundary_scan) free(jc->devices_list[device].out_boundary_scan); - jc->devices_list[device].in_boundary_scan = malloc(bsdl_file->number_of_chainbits); + jc->devices_list[device].in_boundary_scan = malloc(bsdl_file->chain_count); if (jc->devices_list[device].in_boundary_scan) - memset(jc->devices_list[device].in_boundary_scan, 0, bsdl_file->number_of_chainbits); + memset(jc->devices_list[device].in_boundary_scan, 0, bsdl_file->chain_count); - jc->devices_list[device].out_boundary_scan = malloc(bsdl_file->number_of_chainbits); + jc->devices_list[device].out_boundary_scan = malloc(bsdl_file->chain_count); if (jc->devices_list[device].out_boundary_scan) { - memset(jc->devices_list[device].out_boundary_scan, 0, bsdl_file->number_of_chainbits); - for (i = 0; i < bsdl_file->number_of_chainbits; i++) + size_t bi; + memset(jc->devices_list[device].out_boundary_scan, 0, bsdl_file->chain_count); + for (bi = 0; bi < bsdl_file->chain_count; bi++) { - if(bsdl_file->chain_list[i].safe_state == STATE_HIGH) - jc->devices_list[device].out_boundary_scan[i] = 0x01; + if(bsdl_file->chain[bi].safe == BSDL_STATE_HIGH) + jc->devices_list[device].out_boundary_scan[bi] = 0x01; else - jc->devices_list[device].out_boundary_scan[i] = 0x00; + jc->devices_list[device].out_boundary_scan[bi] = 0x00; } @@ -346,18 +361,18 @@ int jtagcore_loadbsdlfile(jtag_core * jc, char * path, int device) unsigned long jtagcore_get_bsdl_id(jtag_core * jc, char * path, unsigned long * mask) { - jtag_bsdl * bsdl_file; + bsdl_t * bsdl_file; unsigned long chip_id; - bsdl_file = load_bsdlfile(jc,path); + bsdl_file = bsdl_parse_file(path, NULL); if (bsdl_file) { - chip_id = bsdl_file->chip_id; + chip_id = bsdl_file->idcode; if( mask ) { - *mask = bsdl_file->chip_id_mask; + *mask = bsdl_file->idcode_mask; } - unload_bsdlfile(jc,bsdl_file); + bsdl_free(bsdl_file); return chip_id; } @@ -366,7 +381,7 @@ unsigned long jtagcore_get_bsdl_id(jtag_core * jc, char * path, unsigned long * int jtagcore_get_dev_name(jtag_core * jc, int device, char * devname, char * bsdlpath) { - jtag_bsdl * bsdl_file; + bsdl_t * bsdl_file; if ( device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >= 0 ) { @@ -376,7 +391,7 @@ int jtagcore_get_dev_name(jtag_core * jc, int device, char * devname, char * bsd if(devname) { - strcpy(devname,bsdl_file->entity_name); + strcpy(devname,bsdl_file->entity); } if(bsdlpath) @@ -405,7 +420,7 @@ int jtagcore_get_dev_name(jtag_core * jc, int device, char * devname, char * bsd int jtagcore_get_number_of_pins(jtag_core * jc, int device) { - jtag_bsdl * bsdl_file; + bsdl_t * bsdl_file; if ( device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >= 0 ) { @@ -413,7 +428,7 @@ int jtagcore_get_number_of_pins(jtag_core * jc, int device) { bsdl_file = jc->devices_list[device].bsdl; - return bsdl_file->number_of_pins; + return (int)bsdl_file->pin_count; } } @@ -422,7 +437,7 @@ int jtagcore_get_number_of_pins(jtag_core * jc, int device) int jtagcore_get_pin_properties(jtag_core * jc, int device,int pin,char * pinname,int maxsize,int * type) { - jtag_bsdl * bsdl_file; + bsdl_t * bsdl_file; int type_code; if (device >= jc->nb_of_devices_in_chain || @@ -437,25 +452,25 @@ int jtagcore_get_pin_properties(jtag_core * jc, int device,int pin,char * pinnam { bsdl_file = jc->devices_list[device].bsdl; - if (pin < bsdl_file->number_of_pins ) + if (pin < (int)bsdl_file->pin_count ) { type_code = 0x00; if (pinname) { - strncpy(pinname, bsdl_file->pins_list[pin].pinname, maxsize - 1); + strncpy(pinname, bsdl_file->pins[pin].name, maxsize - 1); pinname[maxsize - 1] = '\0'; } if (type) { - if (bsdl_file->pins_list[pin].ctrl_bit_number != -1) + if (bsdl_file->pins[pin].ctrl_bit != -1) type_code |= JTAG_CORE_PIN_IS_TRISTATES; - if (bsdl_file->pins_list[pin].out_bit_number != -1) + if (bsdl_file->pins[pin].out_bit != -1) type_code |= JTAG_CORE_PIN_IS_OUTPUT; - if (bsdl_file->pins_list[pin].in_bit_number != -1) + if (bsdl_file->pins[pin].in_bit != -1) type_code |= JTAG_CORE_PIN_IS_INPUT; *type = type_code; @@ -470,7 +485,7 @@ int jtagcore_get_pin_properties(jtag_core * jc, int device,int pin,char * pinnam int jtagcore_get_pin_state(jtag_core * jc, int device, int pin, int type) { - jtag_bsdl * bsdl_file; + bsdl_t * bsdl_file; int bit_number, ret; int disable_state; @@ -481,12 +496,12 @@ int jtagcore_get_pin_state(jtag_core * jc, int device, int pin, int type) { bsdl_file = jc->devices_list[device].bsdl; - if (pin < bsdl_file->number_of_pins) + if (pin < (int)bsdl_file->pin_count) { switch (type) { case JTAG_CORE_OUTPUT: - bit_number = bsdl_file->pins_list[pin].out_bit_number; + bit_number = bsdl_file->pins[pin].out_bit; if (bit_number != -1) { @@ -509,14 +524,14 @@ int jtagcore_get_pin_state(jtag_core * jc, int device, int pin, int type) break; case JTAG_CORE_OE: - bit_number = bsdl_file->pins_list[pin].ctrl_bit_number; + bit_number = bsdl_file->pins[pin].ctrl_bit; if (bit_number != -1) { - disable_state = bsdl_file->chain_list[bsdl_file->pins_list[pin].out_bit_number].control_disable_state; + disable_state = bsdl_file->chain[bsdl_file->pins[pin].out_bit].disable_state; if (jc->devices_list[device].scan_mode == JTAG_CORE_EXTEST_SCANMODE) { - if (disable_state == STATE_HIGH) + if (disable_state == BSDL_STATE_HIGH) { if (jc->devices_list[device].out_boundary_scan[bit_number]) ret = 0x00; @@ -552,7 +567,7 @@ int jtagcore_get_pin_state(jtag_core * jc, int device, int pin, int type) break; case JTAG_CORE_INPUT: - bit_number = bsdl_file->pins_list[pin].in_bit_number; + bit_number = bsdl_file->pins[pin].in_bit; if (bit_number != -1) { @@ -572,7 +587,7 @@ int jtagcore_get_pin_state(jtag_core * jc, int device, int pin, int type) int jtagcore_set_pin_state(jtag_core * jc, int device, int pin, int type,int state) { - jtag_bsdl * bsdl_file; + bsdl_t * bsdl_file; int bit_number,ret; int disable_state; @@ -584,12 +599,12 @@ int jtagcore_set_pin_state(jtag_core * jc, int device, int pin, int type,int sta { bsdl_file = jc->devices_list[device].bsdl; - if (pin < bsdl_file->number_of_pins) + if (pin < (int)bsdl_file->pin_count) { switch (type) { case JTAG_CORE_OUTPUT: - bit_number = bsdl_file->pins_list[pin].out_bit_number; + bit_number = bsdl_file->pins[pin].out_bit; if (bit_number != -1) { @@ -604,13 +619,13 @@ int jtagcore_set_pin_state(jtag_core * jc, int device, int pin, int type,int sta break; case JTAG_CORE_OE: - bit_number = bsdl_file->pins_list[pin].ctrl_bit_number; + bit_number = bsdl_file->pins[pin].ctrl_bit; if (bit_number != -1) { - disable_state = bsdl_file->chain_list[bsdl_file->pins_list[pin].out_bit_number].control_disable_state; + disable_state = bsdl_file->chain[bsdl_file->pins[pin].out_bit].disable_state; - if (disable_state == STATE_HIGH) + if (disable_state == BSDL_STATE_HIGH) { if (state) jc->devices_list[device].out_boundary_scan[bit_number] = 0x00; @@ -638,7 +653,7 @@ int jtagcore_set_pin_state(jtag_core * jc, int device, int pin, int type,int sta int jtagcore_get_pin_id(jtag_core * jc, int device, char * pinname) { - jtag_bsdl * bsdl_file; + bsdl_t * bsdl_file; int pin; if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >= 0 && pinname) @@ -647,11 +662,11 @@ int jtagcore_get_pin_id(jtag_core * jc, int device, char * pinname) { bsdl_file = jc->devices_list[device].bsdl; - for ( pin = 0; pin < bsdl_file->number_of_pins; pin++) + for ( pin = 0; pin < (int)bsdl_file->pin_count; pin++) { - if(bsdl_file->pins_list[pin].pinname) + if(bsdl_file->pins[pin].name) { - if(!strcmp(bsdl_file->pins_list[pin].pinname, pinname)) + if(!strcmp(bsdl_file->pins[pin].name, pinname)) { return pin; } @@ -702,7 +717,7 @@ int jtagcore_push_and_pop_chain(jtag_core * jc, int mode) unsigned char buf_in[512]; int d,i,irlen; int bit,first_bit,jtag_chain_check_needed; - jtag_bsdl * bsdl; + bsdl_t * bsdl; jtag_chain_check_needed = 0; @@ -725,26 +740,26 @@ int jtagcore_push_and_pop_chain(jtag_core * jc, int mode) { if (d == (jc->nb_of_devices_in_chain - 1)) // Last device in chain ? { - jc->io_functions.drv_TXRX_DATA(jc, jc->devices_list[d].out_boundary_scan, jc->devices_list[d].in_boundary_scan, bsdl->number_of_chainbits - 1); - buf_out[0] = jc->devices_list[d].out_boundary_scan[bsdl->number_of_chainbits - 1] | JTAG_STR_TMS; - jc->io_functions.drv_TXRX_DATA(jc, (unsigned char *)&buf_out, &jc->devices_list[d].in_boundary_scan[bsdl->number_of_chainbits - 1], 1); + jc->io_functions.drv_TXRX_DATA(jc, jc->devices_list[d].out_boundary_scan, jc->devices_list[d].in_boundary_scan, (int)bsdl->chain_count - 1); + buf_out[0] = jc->devices_list[d].out_boundary_scan[(int)bsdl->chain_count - 1] | JTAG_STR_TMS; + jc->io_functions.drv_TXRX_DATA(jc, (unsigned char *)&buf_out, &jc->devices_list[d].in_boundary_scan[(int)bsdl->chain_count - 1], 1); } else { - jc->io_functions.drv_TXRX_DATA(jc, jc->devices_list[d].out_boundary_scan, jc->devices_list[d].in_boundary_scan, bsdl->number_of_chainbits); + jc->io_functions.drv_TXRX_DATA(jc, jc->devices_list[d].out_boundary_scan, jc->devices_list[d].in_boundary_scan, (int)bsdl->chain_count); } // Check the incomming data - if(bsdl->number_of_chainbits) + if((int)bsdl->chain_count) { first_bit = jc->devices_list[d].in_boundary_scan[0]; bit = 0; - while( (bit < bsdl->number_of_chainbits) && (first_bit == jc->devices_list[d].in_boundary_scan[bit]) ) + while( (bit < (int)bsdl->chain_count) && (first_bit == jc->devices_list[d].in_boundary_scan[bit]) ) { bit++; } - if( bit == bsdl->number_of_chainbits) + if( bit == (int)bsdl->chain_count) { // All bits have the same value. // Program a jtag chain check @@ -758,13 +773,13 @@ int jtagcore_push_and_pop_chain(jtag_core * jc, int mode) // Write only mode - Ignore incoming chain. if (d == (jc->nb_of_devices_in_chain - 1)) // Last device in chain ? { - jc->io_functions.drv_TXRX_DATA(jc, jc->devices_list[d].out_boundary_scan, 0, bsdl->number_of_chainbits - 1); - buf_out[0] = jc->devices_list[d].out_boundary_scan[bsdl->number_of_chainbits - 1] | JTAG_STR_TMS; + jc->io_functions.drv_TXRX_DATA(jc, jc->devices_list[d].out_boundary_scan, 0, (int)bsdl->chain_count - 1); + buf_out[0] = jc->devices_list[d].out_boundary_scan[(int)bsdl->chain_count - 1] | JTAG_STR_TMS; jc->io_functions.drv_TXRX_DATA(jc, (unsigned char *)&buf_out, 0, 1); } else { - jc->io_functions.drv_TXRX_DATA(jc, jc->devices_list[d].out_boundary_scan, 0, bsdl->number_of_chainbits); + jc->io_functions.drv_TXRX_DATA(jc, jc->devices_list[d].out_boundary_scan, 0, (int)bsdl->chain_count); } } @@ -878,32 +893,36 @@ int jtagcore_push_and_pop_chain(jtag_core * jc, int mode) bsdl = jc->devices_list[d].bsdl; if ( bsdl ) { - switch ( jc->devices_list[d].scan_mode ) { - case JTAG_CORE_SAMPLE_SCANMODE: - for (i = 0; i < bsdl->number_of_bits_per_instruction; i++) + const char *opcode = NULL; + switch ( jc->devices_list[d].scan_mode ) + { + case JTAG_CORE_SAMPLE_SCANMODE: + opcode = jc_bsdl_opcode(bsdl, "SAMPLE"); + break; + case JTAG_CORE_EXTEST_SCANMODE: + opcode = jc_bsdl_opcode(bsdl, "EXTEST"); + break; + } + if (opcode) + { + for (i = 0; i < bsdl->instruction_length; i++) { - buf_out[(bsdl->number_of_bits_per_instruction - 1) - i] = bsdl->SAMPLE_Instruction[i] - '0'; + buf_out[(bsdl->instruction_length - 1) - i] = opcode[i] - '0'; } - break; - case JTAG_CORE_EXTEST_SCANMODE: - for (i = 0; i < bsdl->number_of_bits_per_instruction; i++) - { - buf_out[(bsdl->number_of_bits_per_instruction - 1) - i] = bsdl->EXTEST_Instruction[i] - '0'; - } - break; + } } if (d == (jc->nb_of_devices_in_chain - 1)) // Last device in chain ? { - jc->io_functions.drv_TXRX_DATA(jc, (unsigned char *)&buf_out, 0, bsdl->number_of_bits_per_instruction - 1); - buf_out[0] = buf_out[bsdl->number_of_bits_per_instruction - 1] | JTAG_STR_TMS; + jc->io_functions.drv_TXRX_DATA(jc, (unsigned char *)&buf_out, 0, bsdl->instruction_length - 1); + buf_out[0] = buf_out[bsdl->instruction_length - 1] | JTAG_STR_TMS; jc->io_functions.drv_TXRX_DATA(jc, (unsigned char *)&buf_out, 0, 1); } else { - jc->io_functions.drv_TXRX_DATA(jc, (unsigned char *)&buf_out, 0, bsdl->number_of_bits_per_instruction); + jc->io_functions.drv_TXRX_DATA(jc, (unsigned char *)&buf_out, 0, bsdl->instruction_length); } } else @@ -921,7 +940,7 @@ int jtagcore_push_and_pop_chain(jtag_core * jc, int mode) if ( jc->devices_list[0].bsdl ) { bsdl = jc->devices_list[0].bsdl; - irlen = jc->total_IR_lenght - bsdl->number_of_bits_per_instruction; + irlen = jc->total_IR_lenght - bsdl->instruction_length; } } else @@ -929,7 +948,7 @@ int jtagcore_push_and_pop_chain(jtag_core * jc, int mode) if ( jc->devices_list[1].bsdl ) { bsdl = jc->devices_list[1].bsdl; - irlen = jc->total_IR_lenght - bsdl->number_of_bits_per_instruction; + irlen = jc->total_IR_lenght - bsdl->instruction_length; } } break; diff --git a/src/modules/script/CMakeLists.txt b/src/modules/script/CMakeLists.txt index 35d80da..391cabf 100644 --- a/src/modules/script/CMakeLists.txt +++ b/src/modules/script/CMakeLists.txt @@ -6,3 +6,4 @@ include_directories(${DIR_MODULES}) include_directories(${DIR_LIBS}) add_library(script ${ALL_SOURCES}) +target_link_libraries(script PUBLIC bsdl::bsdl) diff --git a/src/modules/script/script.c b/src/modules/script/script.c index ef68a22..0542869 100644 --- a/src/modules/script/script.c +++ b/src/modules/script/script.c @@ -35,7 +35,7 @@ #include "jtag_core/jtag_core.h" #include "config/version.h" -#include "bsdl_parser/bsdl_loader.h" +#include #include "os_interface/os_interface.h" #include "target/target.h" #include "probes/probes.h"