Last active
October 22, 2023 18:04
-
-
Save erique/5c6a1d042f820d3e6ce7a847ae72eb55 to your computer and use it in GitHub Desktop.
Script to set up flashing tools for the CPLD and the FPGA on the TF4060
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/bin/bash | |
# | |
# 1) Write out the LITE version of the 32-bit Raspberry PI OS to an SDCARD | |
# Either using the 'Raspberry PI Imager': | |
# Use : 'Raspberry PI OS (other)' -> 'Raspberry PI OS Lite (32-bit)' | |
# Or download the image and write it out manually | |
# xzcat yyyy-mm-dd-...-armhf-lite.img.xz | ddxof=/dev/sdX bs=65536 status=progress | |
# | |
# 2) Boot the SDCARD with HDMI and USB Keyboard attached | |
# The PI will reboot several times, ask to setup keyboard layout, user name & password | |
# | |
# 3) Set up network and remote access (SSH) | |
# Run 'sudo raspi-config' and select | |
# * 'System Options' -> 'Wireless LAN' (if required) | |
# * 'Interface Options' -> 'SSH' (for remote config) | |
# | |
# 4) Copy / download this script and run it | |
# (remote) scp setup_tf4060_pi.sh <user>@<ip>: (use 'ifconfig' to find the IP) | |
# (local) wget https://gist.githubusercontent.com/erique/<id>/setup_tf4060_pi.sh | |
# | |
# $ chmod +x setup_tf4060_pi.sh | |
# $ ./setup_tf4060_pi.sh | |
# | |
# 5) Update the TF4060 | |
# * Copy the firmware archive to Raspberry PI | |
# $ scp tf4060rX_??_.zip <user>@<ip>: | |
# * Flash the contents of the archive | |
# $ ssh <user>@<ip> ./update_tf4060.sh tf4060rX_??_.zip | |
# | |
fomu_flash() | |
{ | |
echo -e "\033[1;33m****** BUILD FOMU-FLASH ******\033[0m" | |
make -C fomu-flash -j4 | |
sudo install fomu-flash/fomu-flash /usr/local/bin/fomu-flash | |
} | |
build_xc3sprog() | |
{ | |
echo -e "\033[1;33m****** BUILD XC3SPROG ******\033[0m" | |
cmake -S xc3sprog -B build_xc3sprog | |
make -C build_xc3sprog -j4 | |
sudo make -C build_xc3sprog install | |
} | |
build_icestorm() | |
{ | |
echo -e "\033[1;33m****** BUILD ICEPACK ******\033[0m" | |
make -C icestorm/icepack | |
make -C icestorm/icebram | |
sudo make -C icestorm/icepack install | |
sudo make -C icestorm/icebram install | |
} | |
set -xe | |
mkdir -p build && cd build | |
echo -e "\033[1;33m****** INSTALL DEPENDENCIES ******\033[0m" | |
sudo apt update | |
sudo apt install -y git cmake libftdi-dev libusb-dev | |
[ -f wiringpi-latest.deb ] || wget https://project-downloads.drogon.net/wiringpi-latest.deb | |
sudo dpkg -i wiringpi-latest.deb | |
echo -e "\033[1;33m****** CLONE TOOLING ******\033[0m" | |
[ -d fomu-flash ] || git clone https://github.com/terriblefire/fomu-flash.git | |
[ -d xc3sprog ] || git clone https://github.com/matrix-io/xc3sprog.git | |
[ -d icestorm ] || git clone https://github.com/YosysHQ/icestorm.git | |
command -v fomu-flash || fomu_flash | |
command -v xc3sprog || build_xc3sprog | |
command -v icepack || build_icestorm | |
echo -e "\033[1;33m****** WRITE UPDATE SCRIPT ******\033[0m" | |
cat << 'EOF' > ~/update_tf4060.sh | |
#!/bin/bash | |
if [ $# -eq 0 ] | |
then | |
echo "$0 <tf4060rX_??_.zip> [<bootrom.mif>]" | |
exit 1 | |
fi | |
if [ ! -f $1 ]; then | |
echo "File not found : $1" | |
exit 1 | |
fi | |
TMPDIR=/tmp/tf4060 | |
rm -rf /tmp/tf4060 | |
unzip -d $TMPDIR -j $1 | |
unzip -d $TMPDIR -j $TMPDIR/*.zip | |
JED=`compgen -G $TMPDIR/tf4060r?_*.jed` | |
BIN=`compgen -G $TMPDIR/tf4060r?_*.bin` | |
if [ -z $JED ]; then | |
echo "no CPLD bin" | |
exit 1 | |
fi | |
if [ -z $BIN ]; then | |
echo "no FPGA bin" | |
exit 1 | |
fi | |
if ! xc3sprog -c matrix_creator -p0 $JED:v; then | |
echo "MUST FLASH CPLD" | |
xc3sprog -c matrix_creator -p0 $JED | |
else | |
echo "SKIP CPLD FLASH" | |
fi | |
if [ $# -eq 2 ]; then | |
# patch | |
if [ ! -f $2 ]; then | |
echo "File not found : $2" | |
exit 1 | |
fi | |
ASC=`compgen -G $TMPDIR/tf4060r?_ram.asc` | |
FIN=`compgen -G $TMPDIR/tf4060r?_ram_final.asc` | |
MIF=`compgen -G $TMPDIR/bootrom_syn.mif` | |
if [ -z $ASC ]; then | |
echo "File not found : tf4060r?_ram.asc" | |
exit 1 | |
fi | |
if [ -z $FIN ]; then | |
echo "File not found : tf4060r?_ram_final.asc" | |
exit 1 | |
fi | |
if [ -z $MIF ]; then | |
echo "File not found : bootrom_syn.mif" | |
exit 1 | |
fi | |
icebram -v $MIF $2 < $ASC > $FIN | |
icepack -v $FIN $BIN | |
fi | |
if ! fomu-flash -qv $BIN; then | |
echo "MUST FLASH FPGA" | |
fomu-flash -u -w $BIN | |
else | |
echo "SKIP FPGA FLASH" | |
fi | |
fomu-flash -r | |
EOF | |
chmod +x ~/update_tf4060.sh | |
echo -e "\033[1;33m****** DONE ******\033[0m" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment