Skip to content

Instantly share code, notes, and snippets.

@svet-b svet-b/snapd_on_moxa.md
Last active May 16, 2018

Embed
What would you like to do?
Running snapd and snaps on a Moxa UC-8100 board

The Moxa UC-8100 line of "industrial IoT gateways", such as the Moxa UC-8112-LX, can be a good solution for on-site data acquisition. To get the most out of them we want to enable them to run snaps, like https://snapcraft.io/ammp-edge. Unfortunately, as of writing, the latest v2.0 firmware provided with these devices does not support this, for two main reasons:

  1. The pre-installed OS is Debian 8, while snapd requires at least Debian 9.
  2. The stock kernel does not include SquashFS support, and does not have the required CONFIG_DEVPTS_MULTIPLE_INSTANCES option set.

The steps for rectifying these shortcomings are roughly as follows:

Compiling and installing a custom kernel

The following commands assume you're doing this on the Moxa device itself, though for more expedient results you'll want to cross-compile on something more powerful. Also note that in order to build the kernel you'll need a couple of GB of free space, which is more than the built-in storage of the UC-8112-LX.

  1. Get in touch with Moxa support and request (1) the source code for the latest kernel firmware, and (2) a version of the u-boot bootloader (u-boot.img) that will load with a custom kernel. For some reason neither of these is available for download directly from the Moxa website (though older kernel sources are).

  2. Put the bootloader aside for now and untar the kernel source

tar -xjf uc8100_v2.0_source.tar.bz2
cd am335x-linux-4.1/
  1. Grab the kernel build tools
sudo apt install build-essential bc libncurses5-dev liblz4-tool u-boot-tools
  1. Use the default supplied configuration, but modify the following required configuration options in make menuconfig
  • Device drivers > Character devices > [*] Support multiple instances of devpts
  • File systems > Miscellaneous filesystems > [M] SquashFS 4.0. Also [*] Include support for XZ compressed file system

Save the configuration to the default .config file

  1. Clean up a random glitch that would otherwise lead to a fatal error: dt-bindings/gpio/gpio.h: No such file or directory (from https://support.criticallink.com/redmine/projects/armc8-platforms/wiki/Mityarm-linux-stable_)
cd arch/arm/boot/dts/include/
ln -s ../../../../../include/dt-bindings .
cd ../../../../..
  1. Build the relevant bits, namely: kernel image for u-boot, device tree binary, and SquashFS kernel image.
make uImage
make moxa-uc8100.dtb
make M=fs/squashfs

Note that there's no real need to build the rest of the modules, as these are already included with the stock image.

  1. The u-boot.img bootloader which I was provided by Moxa support was for an older version of the firmware (and an older kernel version), and therefore did not support (or at least look for) the device tree file. Trying to boot my custom uImage that way led to the system hanging after the Starting kernel ... message. Enabling low-level debug in the kernel image produced the following cryptic message:
Error: unrecognized/unsupported machine ID (r1 = 0x00000e05).

Available machine support:

ID (hex)        NAME
ffffffff        Generic DT based system
ffffffff        Generic AM43 (Flattened Device Tree)
ffffffff        Generic AM33XX (Flattened Device Tree)

Please check your kernel config and/or bootloader.

Anyway, it came out to be down to the device trees.

The way to fix the situation is to append the DTB to the uImage file itself. Based on https://community.nxp.com/thread/315543, the following should accomplish that for our situation:

cd arch/arm/boot
cat ./zImage ./dts/moxa-uc8100.dtb > zImage_with_dtb
mkimage -A arm -O linux -T kernel -C none -a 0x80008000 -e 0x80008000 -d zImage_with_dtb uImage
  1. Now mount the boot partition of the image you want to "upgrade" (e.g. /dev/mmcblk0p1). Copy the final ~/am335x-linux-4.1/arch/arm/boot/uImage file there. Also grab the custom u-boot.img file you got from Moxa support and copy it to the boot partition. (after having backed up the originals...)

Related to this, note that the following is what you would likely get if trying to use a custom-compiled kernel with the locked-down u-boot bootloader in the stock Moxa firmware:

## Booting kernel from Legacy Image at 80007fc0 ...
Bad Header Checksum
ERROR: can't get kernel image!

This appears to be by design, though is not really documented.

  1. Boot up the new kernel. Hopefully everything goes without a hitch.

  2. Finally, install the SquashFS module:

cd /lib/modules/4.1.0-ltsi-rt-uc8100+/
sudo mkdir extra
sudo cp ~/am335x-linux-4.1/fs/squashfs/squashfs.ko extra/
sudo depmod

Check that it loads ok with sudo modprobe squashfs and lsmod.

Upgrade to Debian 9

Note that Moxa support also indicated they'll be releasing Debian 9-based firmware in mid-2018. For the time being, doing an in-place upgrade from Debian 8 to 9 appears to work decently well, following instructions similar to https://www.rootusers.com/how-to-upgrade-debian-8-jessie-to-debian-9-stretch/. Specifically:

  1. Make sure the existing Debian 8 is completely up-to-date.
sudo apt-get update && sudo apt-get upgrade -y
  1. Change the package sources from Jessie (8) to Stretch (9):
sudo sed -i 's/jessie/stretch/g' /etc/apt/sources.list

This may mess with the Moxa-specific sources, but didn't appear to lead to issue in my case (if you ignore the Moxa repository GPG error thrown when doing the update in the next step).

  1. Go through the following again as many times as is necessary to get all packages upgraded:
sudo apt-get update && sudo apt-get upgrade -y
  1. Then
sudo apt-get dist-upgrade -y
reboot
sudo apt-get autoremove && sudo apt-get autoclean

(again, repeat if necessary)

Install snapd

You should now be able to

sudo apt-get install snapd -y

and

sudo snap install hello-world

Happy snapping!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.