Enable Remote JTAGD

We have a system that we are just using to remotely program a board that does not have easy access. We're using remote-enabled jtagd running on an Ubuntu 20.04 system to do this. These are just some notes for how we set this all up.

  1. Install Quartus Prime 17.1 (just the software, no devices)
    There are some required packages that I found here: https://www.intel.com/content/www/us/en/docs/programmable/683472/21-4/software-requirements-07130.html
  2. Create an empty directory /etc/jtagd and change the permissions on it to allow anyone to read/write to it.
    $ sudo mkdir /etc/jtagd
    $ sudo chmod 777 /etc/jtagd 
    
  3. Start the jtag daemon as the logged in user
    $ cd intelFPGA/17.1/quartus/bin
    $ ./jtagd
    
  4. Enable remote jtag
    $./jtagconfig --enableremote <password>
    
    If you get an error here, it's most likely because you haven't allowed the logged in user to write to /etc/jtagd.
  5. Make sure the firewall allows port 1309 through.
    $ sudo iptables -L
    Chain INPUT (policy ACCEPT)
    target     prot opt source               destination         
    ACCEPT     udp  --  anywhere             anywhere             multiport dports 4011
    ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:1309   <--!!!
    ACCEPT     udp  --  anywhere             anywhere             multiport dports mdns
    ACCEPT     tcp  --  anywhere             anywhere             multiport dports 4000,4080,4443
    
    Chain FORWARD (policy ACCEPT)
    target     prot opt source               destination         
    
    Chain OUTPUT (policy ACCEPT)
    Target     prot opt source               destination         
    
  6. ***********

    Startup Scripts

    In order for this process to start at boot, here are the startup scripts we're using.

    1. jtag_environment_setup
    2. jtagd

    Our system is Ubuntu 20.04. So the scripts that define the service go in /etc/systemd/system and the actual scripts to run are in /usr/lib/systemd/system.

    jtag_environment_setup

    $ cat jtag_environment_setup.service 
    [Unit]
    Description=Setup JTAG Environment
     
    [Service]
    ExecStart=/usr/lib/systemd/system/jtag_environment_setup
     
    [Install]
    WantedBy=default.target
    
    $ cd
    $ cat /etc/systemd/system/jtag_environment_setup.service 
    [Unit]
    Description=Setup JTAG Environment
     
    [Service]
    ExecStart=/usr/lib/systemd/system/jtag_environment_setup
     
    [Install]
    WantedBy=default.target
    

    I couldn't get this script to work properly in bash, so I used ruby to get it to work.

    $ cat /usr/lib/systemd/system/jtag_environment_setup
    #!/usr/bin/env ruby
    
    jtag_dir = '/etc/jtagd'
    
    # Change the permissions on the directory, unless they're already set correctly
    result = File.chmod(0777, jtag_dir) unless File.world_writable?(jtag_dir)
    

    jtagd

    $ cat /etc/systemd/system/jtagd.service                 
    [Unit]
    Description=JTAG Control
     
    [Service]
    Type=forking
    User=jtaguser
    ExecStart=/usr/lib/systemd/system/jtag_enable
    ExecStop=/usr/lib/systemd/system/jtag_disable
    ExecStartPost=/usr/lib/systemd/system/jtag_enableremote
     
    [Install]
    WantedBy=default.target
    

    This script starts the jtagd service and then it calls another script that remote enables jtag.

    $ cat /usr/lib/systemd/system/jtag_enable
    #!/usr/bin/bash
    
    `/home/jtaguser/intelFPGA/17.1/quartus/bin/jtagd`
    
    $ cat /usr/lib/systemd/system/jtag_enableremote
    #!/usr/bin/bash
    
    `/home/jtaguser/intelFPGA/17.1/quartus/bin/jtagconfig --enableremote 'secretpassword'`
    
    
    $ cat /usr/lib/systemd/system/jtag_disable
    #!/usr/bin/bash
    
    pid=`/usr/bin/pidof jtagd`
    `kill -9 $pid`
    

    Then can enable the scripts to automatically start on boot.

    $ sudo systemctl daemon-reload
    $ sudo systemctl enable jtag_environment_setup
    $ sudo systemctl enable jtagd
    

    And to start/stop run

    $ sudo systemctl start jtagd
    $ sudo systemctl stop jtagd
    
    Updated: August 2022