Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,5 @@ pip-log.txt
# Mac crap
.DS_Store

# Temp files while making linux package
linux-package/GadgetFactory/
Binary file modified Java-GUI/papilio-loader.jar
Binary file not shown.
Binary file added Java-GUI/programmer/linux/papilio-prog
Binary file not shown.
Binary file removed Java-GUI/programmer/linux32/papilio-prog
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public PapilioLoader(String initial_bit_file, String initial_hex_file, String er
}
else
{
programmerPath = new File(rootProgrammerPath, "linux32");
programmerPath = new File(rootProgrammerPath, "linux");
papilioProgrammerFile = new File(programmerPath, "papilio-prog");
srecCatFile = new File(programmerPath, "srec_cat");
dataToMemFile = new File(programmerPath, "data2mem");
Expand Down
4 changes: 2 additions & 2 deletions linux-installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ cd Java-GUI
sudo ./build.sh
sudo mkdir -p /opt/GadgetFactory/papilio-loader/
sudo cp -pr papilio-loader.jar papilio-loader.sh programmer/ images/ help/ /opt/GadgetFactory/papilio-loader/
sudo ln -s /opt/GadgetFactory/papilio-loader/papilio-loader.sh /usr/local/bin/papilio-loader-gui
sudo ln -s /opt/GadgetFactory/papilio-loader/programmer/linux32/papilio-prog /usr/local/bin/papilio-prog
sudo ln -sf /opt/GadgetFactory/papilio-loader/papilio-loader.sh /usr/local/bin/papilio-loader-gui
sudo ln -sf /opt/GadgetFactory/papilio-loader/programmer/linux/papilio-prog /usr/local/bin/papilio-prog
22 changes: 22 additions & 0 deletions linux-package/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

if [ "$SUDO_USER" == "" ]; then
echo "Please run as sudo"
exit 7
fi

apt-get install -y default-jdk
apt-get install -y libftdi-dev
cp -r ./GadgetFactory /opt/
ln -sf /opt/GadgetFactory/papilio-loader/papilio-loader.sh /usr/local/bin/papilio-loader-gui
ln -sf /opt/GadgetFactory/papilio-loader/programmer/linux/papilio-prog /usr/local/bin/papilio-prog

# Setup for use as non-root
usermod -a -G dialout $SUDO_USER
chgrp dialout /usr/local/bin/papilio-prog
rulestr1="SUBSYSTEMS==\"usb\", ATTRS{idVendor}==\"0403\", ATTRS{idProduct}==\"6010\", GROUP=\"dialout\""
rulestr2="SUBSYSTEMS==\"usb\", ATTRS{idVendor}==\"0403\", ATTRS{idProduct}==\"7bc0\", GROUP=\"dialout\""
echo $rulestr1 > /etc/udev/rules.d/papilio.rules
echo $rulestr2 >> /etc/udev/rules.d/papilio.rules
echo
echo "Note: to work without sudo, logout/login and replug any connected boards (or reboot)"
14 changes: 14 additions & 0 deletions linux-package/uninstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

if [ "$SUDO_USER" == "" ]; then
echo "Please run as sudo"
exit 7
fi


rm -rf /opt/GadgetFactory
rm -f /usr/local/bin/papilio-loader-gui
rm -f /usr/local/bin/papilio-prog
rm -f /etc/udev/rules.d/papilio.rules

gpasswd -d $SUDO_USER dialout
31 changes: 31 additions & 0 deletions make-linux-package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh

# will need sudo apt-get install default-jdk libftdi-dev

# Build papilio-prog
cd papilio-prog
./autogen.sh
./configure
make clean
make
cp papilio-prog ../Java-GUI/programmer/linux/
cd ..

# Build Java and copy everything to linux-package folder for zipping
cd Java-GUI
sudo ./build.sh
rm -rf ../linux-package/GadgetFactory
mkdir -p ../linux-package/GadgetFactory/papilio-loader
cp -pr papilio-loader.jar papilio-loader.sh programmer/ images/ help/ ../linux-package/GadgetFactory/papilio-loader
cd ..

cd linux-package
rm -f ../papilio-loader-linux.zip
zip -r ../papilio-loader-linux.zip *
cd ..






Binary file added papilio-loader-linux.zip
Binary file not shown.
14 changes: 14 additions & 0 deletions papilio-prog/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
*.o
.deps/
Makefile
Makefile.in
aclocal.m4
autom4te.cache/
compile
config.h.in
config.status
configure
depcomp
install-sh
missing
stamp-h1
123 changes: 112 additions & 11 deletions papilio-prog/butterfly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Mike Field [hamster@snap.net.nz] 15 Oct 2012
*/


#pragma GCC diagnostic ignored "-Wdeprecated-declarations"

// C standard libraries
#include <stdio.h> // fprintf() printf() stderr
Expand All @@ -35,6 +36,7 @@ Mike Field [hamster@snap.net.nz] 15 Oct 2012

// C POSIX
#include <unistd.h> // getopt()
#include <sys/stat.h>

// C++ standard libraries
#include <iostream>
Expand All @@ -51,7 +53,7 @@ Mike Field [hamster@snap.net.nz] 15 Oct 2012
#include "bitfile.h"


unsigned int get_id(Jtag &jtag, DeviceDB &db, int chainpos, bool verbose)
unsigned int get_id(Jtag &jtag, DeviceDB &db, int chainpos, bool verbose, const char** pdd)
{
int num=jtag.getChain();
unsigned int id;
Expand Down Expand Up @@ -83,11 +85,11 @@ unsigned int get_id(Jtag &jtag, DeviceDB &db, int chainpos, bool verbose)
return 0;
}

const char *dd=db.getDeviceDescription(chainpos);
*pdd=db.getDeviceDescription(chainpos);
id = jtag.getDeviceID(chainpos);
if (verbose)
{
printf("JTAG chainpos: %d Device IDCODE = 0x%08x\tDesc: %s\n", chainpos,id, dd);
printf("JTAG chainpos: %d Device IDCODE = 0x%08x\tDesc: %s\n", chainpos,id, *pdd);
fflush(stdout);
}
return id;
Expand All @@ -96,13 +98,13 @@ unsigned int get_id(Jtag &jtag, DeviceDB &db, int chainpos, bool verbose)
void usage(char *name)
{
fprintf(stderr,
"\nUsage:\%s [-v] [-j] [-f <bitfile>] [-b <bitfile>] [-s e|v|p|a] [-c] [-C] [-r] [-A <addr>:<binfile>]\n"
"\nUsage:\%s [-v] [-j] [-f <bitfile>] [-b <bitfile>|auto] [-s e|v|p|a] [-c] [-C] [-r] [-A <addr>:<binfile>]\n"
" -h\t\t\tprint this help\n"
" -v\t\t\tverbose output\n"
" -j\t\t\tDetect JTAG chain, nothing else\n"
" -d\t\t\tFTDI device name\n"
" -f <bitfile>\t\tMain bit file\n"
" -b <bitfile>\t\tbscan_spi bit file (enables spi access via JTAG)\n"
" -b <bitfile>|auto\tbscan_spi bit file (enables spi access via JTAG)\n"
" -s [e|v|p|a]\t\tSPI Flash options: e=Erase Only, v=Verify Only,\n"
" \t\tp=Program Only or a=ALL (Default)\n"
" -c\t\t\tDisplay current status of FPGA\n"
Expand Down Expand Up @@ -146,6 +148,60 @@ int append_data(BitFile &fpga_bit, char *append_str, bool flip, int verbose)
return 1;
}

// Helper to check if file exists
int file_exist (char *filename)
{
struct stat buffer;
return (stat (filename, &buffer) == 0);
}

const char* map_desc_to_bscan(const char* dd)
{
if (!dd)
return NULL;
if (strcmp(dd, "XC3S250E")==0)
return "bscan_spi_xc3s250e.bit";
if (strcmp(dd, "XC3S500E")==0)
return "bscan_spi_xc3s500e.bit";
if (strcmp(dd, "XC3S100E")==0)
return "bscan_spi_xc3s100e.bit";
if (strcmp(dd, "XC6SLX9")==0)
return "bscan_spi_xc6slx9.bit";
if (strcmp(dd, "XC6SLX4")==0)
return "bscan_spi_xc6slx4.bit";
return NULL;
}

int getExeLocation(char* buf, int len)
{
// Read /proc/self/exe
char temp[PATH_MAX];
int tempLen = readlink("/proc/self/exe", temp, sizeof(temp));
if (tempLen == 0)
return 0;
temp[tempLen] = '\0';

// Get file stat
struct stat file_stat;
if (lstat(temp, &file_stat) != 0)
return 0;

// Is it a link?
if (!S_ISREG(file_stat.st_mode))
{
// Yes,
int bufLen = readlink(temp, buf, len);
buf[bufLen] = '0';
return len;
}
else
{
// No, regular file
strncpy(buf, temp, len);
return len;
}
}

int main(int argc, char **argv)
{
int chainpos = 0;
Expand All @@ -159,6 +215,7 @@ int main(int argc, char **argv)
int displaystatus = 0; // 0=no status, 1=JTAG IR data, 2=STAT Register readback
bool result;
char *desc = 0;
const char* dd = 0;
char const *serial = 0;
int subtype = FTDI_NO_EN;
char *devicedb = NULL;
Expand All @@ -172,7 +229,6 @@ int main(int argc, char **argv)

std::auto_ptr<IOBase> io;


while ((c = getopt (argc, argv, "hd:b:f:s:A:a:jvcCr")) != EOF)
switch (c)
{
Expand Down Expand Up @@ -301,18 +357,19 @@ int main(int argc, char **argv)
}

Jtag jtag = Jtag(io.operator->());
unsigned int family, manufacturer;
unsigned int family;//, manufacturer;
fprintf(stderr, "Using %s\n", db.getFile().c_str());

id = get_id (jtag, db, chainpos, true);
id = get_id (jtag, db, chainpos, true, &dd);
if (id == 0)
return 1;
family = (id>>21) & 0x7f;
manufacturer = (id>>1) & 0x3ff;
//manufacturer = (id>>1) & 0x3ff;
if(detectchain)
return 0;



ProgAlgXC3S alg(jtag,io.operator*(), family);
//alg.getStatusRegister();

Expand All @@ -328,11 +385,55 @@ int main(int argc, char **argv)
{
if(spiflash)
{
// Auto fpga bit file?
if (strcmp(cBscan_fn, "auto") == 0)
{
// Work out name of bscan_spi_*.bit file from device description
const char* bscanFile = map_desc_to_bscan(dd);
if (!bscanFile)
{
fprintf(stderr, "Auto bscan file not found for device: '%s'\n", dd);
return 7;
}

char buf[PATH_MAX];
if (!getExeLocation(buf, PATH_MAX))
{
fprintf(stderr, "Auto bscan failed - can't read /proc/self/exe\n");
return 7;
}
char* p = strrchr(buf, '/');
strcpy(p+1, bscanFile);
if (file_exist(buf))
{
if (verbose)
printf("Using bscan file: %s\n", buf);
}
else
{
strcpy(p+1, "../");
strcat(p, bscanFile);
if (file_exist(buf))
{
if (verbose)
printf("Using bscan file: %s\n", buf);
}
else
{
fprintf(stderr, "Auto bscan failed: %s doesn't exist\n", buf);
return 7;
}
}

// Use the discovered file name
cBscan_fn = buf;
}

BitFile fpga_bit;
fpga_bit.readFile(cBscan_fn);
//fpga_bit.print();

printf("\nUploading \"%s\". ", cBscan_fn);
printf("\nUploading \"%s\". \n", cBscan_fn);
alg.array_program(fpga_bit);

BitFile flash_bit;
Expand Down Expand Up @@ -380,7 +481,7 @@ int main(int argc, char **argv)

fpga_bit.print();

printf("\nUploading \"%s\". ", cFpga_fn);
printf("\nUploading \"%s\". \n", cFpga_fn);
alg.array_program(fpga_bit);
return 0;
}
Expand Down
12 changes: 6 additions & 6 deletions papilio-prog/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@
/* config.h.in. Generated from configure.ac by autoheader. */

/* Name of package */
#define PACKAGE "butterflyprog"
#define PACKAGE "papilio-prog"

/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT ""

/* Define to the full name of this package. */
#define PACKAGE_NAME "butterflyprog"
#define PACKAGE_NAME "papilio-prog"

/* Define to the full name and version of this package. */
#define PACKAGE_STRING "butterflyprog 1.4"
#define PACKAGE_STRING "papilio-prog 1.5"

/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "butterflyprog"
#define PACKAGE_TARNAME "papilio-prog"

/* Define to the home page for this package. */
#define PACKAGE_URL ""

/* Define to the version of this package. */
#define PACKAGE_VERSION "1.4"
#define PACKAGE_VERSION "1.5"

/* Version number of package */
#define VERSION "1.4"
#define VERSION "1.5"

/* Cross-compiling for windows */
/* #undef WINDOWS */
3 changes: 3 additions & 0 deletions papilio-prog/makezip
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
rm -f papilio-prog-linux64.zip
zip -j papilio-prog-linux64.zip papilio-prog ../Java-GUI/programmer/bscan_spi_*.*
Binary file added papilio-prog/papilio-prog
Binary file not shown.
Binary file added papilio-prog/papilio-prog-linux64.zip
Binary file not shown.