From 1e0e20535638122a86f0e44f0505c0eccc4a9fee Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Tue, 20 Nov 2012 11:27:56 -0600 Subject: [PATCH] Add verified Xilinx programming script and device type extractor --- fpga/xilinx/programmer/bit2svf/Makefile | 9 ++- fpga/xilinx/programmer/bit2svf/bitdevice.c | 83 ++++++++++++++++++++++ fpga/xilinx/programmer/program_device.sh | 16 +++++ 3 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 fpga/xilinx/programmer/bit2svf/bitdevice.c create mode 100755 fpga/xilinx/programmer/program_device.sh diff --git a/fpga/xilinx/programmer/bit2svf/Makefile b/fpga/xilinx/programmer/bit2svf/Makefile index b5df378..a2387ad 100644 --- a/fpga/xilinx/programmer/bit2svf/Makefile +++ b/fpga/xilinx/programmer/bit2svf/Makefile @@ -2,7 +2,7 @@ CC=gcc CFLAGS=-Wall -g3 -I$(BIDIR) BIDIR=bitinfo-0.3 LDFLAGS=-I$(BIDIR) -PROYECTO=dumpbit bit2svf +PROYECTO=dumpbit bitdevice bit2svf VERSION=1.3.1 PKG=bit2svf-$(VERSION) @@ -13,6 +13,8 @@ $(BIDIR)/bitfile.o: bit2svf: bit2svf.o $(BIDIR)/bitfile.o parts.o commands.o bitshandle.o +bitdevice: bitdevice.o $(BIDIR)/bitfile.o + dumpbit: dumpbit.o $(BIDIR)/bitfile.o debian/control: debian/packages debian/yada @@ -39,3 +41,8 @@ clean: debian/rules clean +install: + mkdir -p /usr/share/bit2svf/ + cp -Rp templates/* /usr/share/bit2svf/ + cp -Rp bitdevice /usr/bin/ + cp -Rp bit2svf /usr/bin/ diff --git a/fpga/xilinx/programmer/bit2svf/bitdevice.c b/fpga/xilinx/programmer/bit2svf/bitdevice.c new file mode 100644 index 0000000..cad4b7e --- /dev/null +++ b/fpga/xilinx/programmer/bit2svf/bitdevice.c @@ -0,0 +1,83 @@ +/************************************************************************** + + Copyright (c) 2012 Timothy Pearson + + 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; version 2. + + 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 + + Description: Dumps the specified device in a xilinx bit file to stdout + +***************************************************************************/ +#include +#include +#include +#include +#include "bitfile.h" + +#define BSIZE 1048576 /* 1k */ + +void convertToUpperCase(char *str) +{ + while(*str != '\0') { + *str = toupper((unsigned char)*str); + str++; + } +} + +void findAndRemoveEndString(char *str, char* text) +{ + char *location = strstr(str, text); + int len = strlen(str); + int sublen = strlen(text); + if (location && (location == (str+(len-sublen)))) { + *location = 0; + } +} + +void stripPackageSuffix(char *str) +{ + findAndRemoveEndString(str, "FG256"); + findAndRemoveEndString(str, "CSG324"); +} + +/* read a bit file from stdin */ +int main(int argc, char *argv[]) +{ + struct bithead bh; + FILE *bitfile; + + if (argc < 1) { + fprintf(stderr,"Insufficient args %s filename.bit\n",argv[0]); + return 1; + } + + if ((bitfile=fopen(argv[1],"rb"))==NULL) { + perror("BITFILE"); + return 2; + } + + initbh(&bh); + if (readhead(&bh, bitfile)) { + fprintf(stderr,"Invalid bit file header\n"); + return 3; + } + + convertToUpperCase(bh.part); + stripPackageSuffix(bh.part); + printf("XC%s\n", bh.part); + + fclose(bitfile); + freebh(&bh); + return 0; +} diff --git a/fpga/xilinx/programmer/program_device.sh b/fpga/xilinx/programmer/program_device.sh new file mode 100755 index 0000000..364330f --- /dev/null +++ b/fpga/xilinx/programmer/program_device.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# (c) 2012 Timothy Pearson +# Licensed under the GPL v2 + +if [[ $1 == "" ]]; then + echo "Usage: ./program_device.sh bitfile.bit" + exit 1 +fi + +UNIQUEID=$(date "+%s%N") +DEVICETYPE=$(bitdevice $1) +SVFFILE=/tmp/${UNIQUEID}.svf +bit2svf $1 $SVFFILE $DEVICETYPE +xsvf-rpi -v -s $SVFFILE +rm $SVFFILE