Last active
June 30, 2022 19:21
-
-
Save wuhanstudio/7f78fdd63a6de55651374b10316f0be8 to your computer and use it in GitHub Desktop.
Install Lattice Diamond on Ubuntu / PopOS
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
#!/usr/bin/python | |
# vim: set ts=4 sw=4 expandtab syntax=python: | |
""" | |
FTDI device permission fixer | |
Can be called from a udev rule to ensure connected FTDI devices have | |
world-writable permissions for use by user applications | |
J. Hipps <[email protected]> | |
https://ycnrg.org/ | |
""" | |
import os | |
import sys | |
import usb1 | |
def find_usb_device(vid, pid): | |
"""locate usb device with libusb""" | |
usb = usb1.USBContext() | |
for tdev in usb.getDeviceList(): | |
if tdev.getVendorID() == vid and tdev.getProductID() == pid: | |
n_bus = tdev.getBusNumber() | |
n_dev = tdev.getDeviceAddress() | |
n_port = tdev.getPortNumber() | |
return (n_bus, n_dev) | |
return None | |
def fix_dev_perms(bus, dev): | |
"""fix perms for entry in /dev/bus""" | |
db_path = '/dev/bus/usb/%03d/%03d' % (bus, dev) | |
try: | |
os.stat(db_path) | |
except Exception as e: | |
print("Entry not accessible [%s]: %s" % (db_path, str(e))) | |
return False | |
try: | |
os.chmod(db_path, 0o0666) | |
except Exception as e: | |
print("Failed to update perms for %s: %s" % (db_path, str(e))) | |
return False | |
return True | |
def _main(): | |
"""entry point""" | |
if 'ID_VENDOR_ID' in os.environ and 'ID_MODEL_ID' in os.environ: | |
try: | |
d_vid = int(os.environ['ID_VENDOR_ID'], 16) | |
d_pid = int(os.environ['ID_MODEL_ID'], 16) | |
except: | |
print("Failed to convert values from env") | |
sys.exit(2) | |
else: | |
if len(sys.argv) < 3: | |
print("usage: ftdi_fixer.py [VENDOR_ID PRODUCT_ID]") | |
sys.exit(1) | |
try: | |
d_vid = int(sys.argv[1], 16) | |
d_pid = int(sys.argv[2], 16) | |
except: | |
print("Failed to convert hex values") | |
sys.exit(2) | |
udev = find_usb_device(d_vid, d_pid) | |
if udev: | |
fix_dev_perms(*udev) | |
else: | |
print("Failed to locate device") | |
sys.exit(1) | |
sys.exit(0) | |
if __name__ == '__main__': | |
_main() |
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
1. Download Lattice Dianond | |
wget http://files.latticesemi.com/Diamond/3.12/diamond_3_12-base-240-2-x86_64-linux.rpm | |
2. Convert rpm to deb | |
sudo apt install alien lsb | |
sudo alien --scripts diamond_3_12-base-240-2-x86_64-linux.rpm | |
sudo dpkg -i diamond-3-12-base_3.12-241_amd64.deb | |
3. Install Licence | |
sudo cp ./Downloads/license.dat /usr/local/diamond/3.12/license/ | |
sudo vim /usr/local/diamond/3.12/license/license.dat | |
nodename --> PC hostname | |
line 2 daemon_path --> /usr/local/diamond/3.12/ispfpga/bin/lin64 | |
line 2 mgcld_path --> /usr/local/diamond/3.12/modeltech/linuxloem/mgls/bin/mgcld | |
sudo touch /usr/local/diamond/3.12/license/license.log | |
/usr/local/diamond/3.12/ispfpga/bin/lin64/lmgrd -l /usr/local/diamond/3.12/license/license.log -c /usr/local/diamond/3.12/license/license.dat | |
4. Change USB driver | |
sudo adduser <my_user> dialout | |
sudo vim /etc/udev/rules.d/10-lattice.rules | |
ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6014", MODE="0666", SYMLINK+="ftdi-%n", RUN+="/bin/sh -c 'basename $(dirname $(realpath /sys%p/device)) > /sys/bus/usb/drivers/ftdi_sio/unbind'",RUN+="/opt/ftdi_fixer.py" | |
sudo curl https://ycc.io/scripts/ftdi_fixer.py -o /opt/ftdi_fixer.py | |
sudo chmod +x /opt/ftdi_fixer.py | |
sudo udevadm control --reload | |
5. Start Lattice Diamond | |
/usr/local/diamond/3.12/bin/lin64/diamond & | |
Other solutions (/etc/udev/rules.d/51-lattice.rules): | |
# Lattice | |
SUBSYSTEM=="usb",ACTION=="add",ATTRS{idVendor}=="1134",ATTRS{idProduct}=="8001",MODE="0660",GROUP="plugdev",SYMLINK+="lattice-%n" | |
# FTDI | |
SUBSYSTEM=="usb",ACTION=="add",ATTRS{idVendor}=="0403",ATTRS{idProduct}=="6014",MODE=="0666",GROUP=="plugdev",SYMLINK+="ftdi-%n" | |
SUBSYSTEM=="usb",ATTRS{idVendor}=="0403",ATTRS{idProduct}=="6014",RUN+="/bin/sh -c 'basename %p > /sys/bus/usb/drivers/ftdi_sio/unbind'" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment