newspaint

Documenting Problems That Were Difficult To Find The Answer To

Monthly Archives: November 2018

Running MPLAB-X In LXC Container With Snap Programmer

Installing MPLAB-X into Ubuntu 16.04 (Xenial) LXC container:

ubuntu@mplabx:/tmp$ sudo ./MPLABX-v5.05-linux-installer.sh
64 Bit, check libraries
Check for 32 Bit libraries
These 32 bit libraries were not found and are needed for MPLAB X to run:
libc.so
libdl.so
libgcc_s.so
libm.so
libpthread.so
librt.so
libstdc++.so
libexpat.so
libX11.so
libXext.so

ubuntu@mplabx:/tmp$ sudo dpkg --add-architecture i386

ubuntu@mplabx:/tmp$ sudo apt-get install libc6-i386 lib32gcc1 lib32stdc++6 libexpat1:i386 libx11-6:i386 libxext6:i386

ubuntu@mplabx:/tmp$ sudo ./MPLABX-v5.05-linux-installer.sh
64 Bit, check libraries
Check for 32 Bit libraries
Verifying archive integrity... All good.
Uncompressing MPLAB X v5.05 Installer....

Also needed libXrender.so.1, and libXi.so.6 (64-bit version) from error message in ~/.mplab_ide/dev/v5.05/var/log/messages.log:

ubuntu@mplabx:/tmp$ sudo apt-get install libxrender1 libxi6

ubuntu@mplabx:/tmp$ /usr/bin/mplab_ide

Now, getting the Snap programmer to run through LXC requires first creating a udev rule in the host system (outside the LXC container):

# 2018.11.05 Rules file created

SUBSYSTEM=="usb", ATTR{idVendor}=="04d8", ATTR{idProduct}=="9018", MODE="0666", GROUP="plugdev", SYMLINK+="mplab-snap"
SUBSYSTEM=="usb", ATTR{idVendor}=="04d8", ATTR{idProduct}=="9019", MODE="0666", GROUP="plugdev", SYMLINK+="mplab-snap-2"

Note I had to update the idProduct when I got the following error message from MPLAB-X:

ubuntu@mplabx:~$ /usr/bin/mplab_ide
libusb couldn't open USB device /dev/bus/usb/003/025: Permission denied.
libusb requires write access to USB device nodes.

Next we need to find out the device major and minor numbers as per this forum post:

me@baremetal:~$ ls -ald /dev/mplab-snap
lrwxrwxrwx 1 root root 15 Nov  5 18:16 /dev/mplab-snap -> bus/usb/003/017

me@baremetal:~$ ls -ald /dev/bus/usb/003/017
crw-rw-rw- 1 root plugdev 189, 272 Nov  5 18:16 /dev/bus/usb/003/017

Right, so in this instance the major number is 189 and the minor number is 272 (it may differ for you). Then I edit the LXC configuration for the container:

# USB Passthrough
lxc.cgroup.devices.allow = c 189:* rwm
lxc.mount.entry = /dev/bus/usb dev/bus/usb none bind,optional,create=dir