Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
13 years ago

Jtagd in kernel 3.5 under linux

Since the release of linux kernel 3.5 the usbfs support has been dropped

This means that under linux, with the new kernel, jtagd is unable to locate programming hardware, because it scans /proc/bus/usb to find them

Will altera make an available corrected jtagd binary for those who want to keep with kernel development and keep old versions of quartus running?

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    By the way, i made a patch for the linux kernel to reenable usbfs and work-around this issue, although it is not a long-term solution, for the moment, it works.

    If anyone needs it, ask for it. :)
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I did a horrible workaround that seems to work, at least until Altera fix it properly. It involves a bit of file system manipulation and some hex editing (it's also possible to edit with 'vim -b' or another 8-bit clean text editor if you're careful). It also relies on the debugfs filesystem mounted at /sys/kernel/debug but modern Linux systems should do that automatically.

    First for the filesystem manipulation, run these commands as 'root':

    mkdir -p /hack/bus
    ln -snf ../../sys/kernel/debug/usb /hack/bus/usb

    Now there should be a file /hack/bus/usb/devices that is a list of attached USB devices in the same format as the old /proc/bus/usb/devices file.

    One "gotcha" with the above is that some systems such as Ubuntu mount the /sys/kernel/debug directory with permissions 0700 so that it is only accessible by root. On recent Ubuntu systems, it is necessary to edit the /etc/init/mounted-debugfs.conf file and either change the 'chmod 0700' to 'chmod 0755' or comment out the chmod command altogether.

    The next step is to hex edit (or text edit with an 8-bit clean editor such as 'vim -b') the 'jtagd' binary file. There may be two of these, one in ${QUARTUS_ROOTDIR}/linux/ and the other in ${QUARTUS_ROOTDIR}/linux64/. Make backups of the original files in case you need to restore the originals (I copied the originals to jtagd.orig).

    There are two strings in 'jtagd' that need editing. The first string is '/proc/bus/usb/%03u/%03u'. This needs to be changed to '/dev/bus/usb/%03u/%03u' plus an extra NUL terminator on the end to compensate for the fact that the new string is one character shorter than the old string. (I.e. the new string will be terminated with two zero bytes, whereas the original was terminated by a single zero byte).

    The second string is '/proc/bus/usb/devices'. This needs to be changed to '/hack/bus/usb/devices'. The new string is the same length as the old one, so no extra NUL bytes are needed.

    The edited 'jtagd' should end up the same length as original, and doing a 'cmp -lb jtagd.orig jtagd' should show minimal differences between the original file and the edited file.

    EDIT 2013-11-19

    Having been away from this for awhile, and having to use the programmer again on my Gentoo system, I had to edit "/etc/init.d/sysfs" on my Gentoo system to change the mount options of "/sys/kernel/debugfs", appending ",mode=0755" to the mount options. I also needed the hex-edited jtagd and the special "/hack" directory as described above.

    Finally, I needed to change the udev rules to allow write access to the USB blaster. There are various ways to do that, but I chose to create a new system group "usbblaster", make myself a member of that group, and add the following udev rule in "/etc/udev/rules.d/99-usbblaster.rules":

    SUBSYSTEM="usb", ATTR{product}=="USB-Blaster", GROUP="usbblaster"

    Alternatively, instead of creating a special group, the GROUP="usbblaster" part can be replaced with MODE="0666" to allow write-access to everyone. It's less secure, but that doesn't matter if you're the only user of the system.