We are currently experimenting ubuntu core on a Dell Edge 5000 , the device comes with 4 serial ports (3 RS485 and 1 RS232) and 3 USB ports .
The snap needs access to these serial ports (including USB) , From the interface documentation , it is mentioned that serial-port interface needs to be used but there is also a mention that a gadget needs to be available providing the slot. I could not get any gadgets for DELL 5000 that provides these slots (may be they are private) . The documentation for creating gadgets looks to be a “too much” work for a snap developer (which of-course would be a last resort ) .But just to get the things rolling , are there any ready to use generic gadgets which would provide access to the available serial ports on any device ?
I really do not know the rationale behind not having this feature supported by the core snap.
The core snap is a generic root filesystem that provides generic interfaces. Typically they are more service focused ones, i.e. network-manager, browser-support, timeserver-control or process-control. Or the ones that are rather generically using userspace libs and binaries from the core rootfs but combined with some device like opengl, joystick, ppp or log-observe.
The gadget snap defines everything hardware specific about an image, the partition table, on arm systems the device tree to use (that defines all kernel devices and drivers for the hardware), the type of bootloader used and basic hardware configuration to bring up the system devices. As such, it also defines all interfaces that are specific to that hardware, examples are i2c, gpio mappings, ioports-control, hidraw or serial-port.
If your device came preinstalled with Ubuntu Core 16 then snap interfaces should definitely list serial interfaces provided by the gadget, does it not ?
@ogra thanks for the reply. The device came with a different OS and I installed a generic amd64 ubuntu core image from (http://releases.ubuntu.com/ubuntu-core/16/) . I am sure the devices which come factory installed with ubuntu core from DELL should have some snap providing the serial-interface but in this case (generic ubuntu core image) looks like we hit a dead end.
Well, rolling your own gadget with additional serial interfaces is rather trivial:
install snapcraft:
snap install snapcraft --classic
clone the gadget source tree
git clone https://github.com/snapcore/pc-amd64-gadget.git
cd pc-amd64-gadget
now edit snapcraft.yaml and append something like (this would be for four RS232 ports, i’m not sure how RS485 shows up in /dev, you would have to adjust accordingly):
raw-usb will help you to talk directly to usb devices on the lowest level, you might or might not need to set up additional interfaces for whatever usb device you have attached…
i.e. if you have a usb camera raw-usb would not give you access to /dev/video but only to the raw usb device the camera creates on the bus, you would rather use the camera interface here (which will give you /dev/video and raw access to the very specific device that /dev/video uses in the back) … or disks, raw-usb would not allow you to mount the disk but give you access to the low level device only, here you would instead use the removable-media interface (and perhaps also mount-observe).
Read: for your USB ports you should decide on a case-by-case base which interface is the best suited one for the specific use-case … most of the time the high level ones are likely enough and you will not need anything in the gadget.
In case you did not find it yet, the interface reference list is at:
As far as I understand the current situation, you have to pre plan how many USB to serial converters you want to use. They typically appear as /dev/ttyUSB<x> or /dev/ttyACM<x> and every single one has to be exported in the gadgets snapcraft.yaml. Plugging in new devices or using wild cards is not supported (please correct me if I’m wrong).
if you know the vendor and product ID’s if the to be attached device. After you connect the interface your application can then talk to it on /dev/serial-port-myserial which the interface creates for you …
(i think there was also an option to use serial numbers in the above block, to make the setup even closer bound to a particular device)
@thymythos We have hotplug coming next in our roadmap, as soon as we finish the on-going implementation of interface hooks, which are a requirement for making good use of the dynamic connections.
Thanks @ogra for the gadget creation overview! I’m doing something similar to OP in the context of a Raspberry Pi with an expansion board. I created the gadget, and was able to create the image also (with some slight modifications to the instructions; see below). That said, is there a way to install a gadget snap - e.g. for quick testing - without going through the image build and flash process? Specifically, when trying to install my gadget snap I get the following error:
$ snap install strato-pi3_16.04-0.5_armhf.snap --dangerous
error: cannot perform the following tasks:
- Mount snap "strato-pi3" (unset) (cannot replace signed gadget snap with an unasserted one)
That seems sensible enough - but what’s the right way to add a valid assertion to the gadget snap? If I try to push it to the store I get an error about not being allowed to push gadget snaps.
This isn’t actually an issue for the pc-amd64 gadget, but for the Raspberry Pi. When trying to build a gadget snap using the current master of https://github.com/snapcore/pi3-gadget, when trying to pull the v2017.05 branch of uboot the build fails with fatal: ambiguous argument 'refs/heads/v2017.05': unknown revision or path not in the working tree. That’s because v2017.05 is now a tag in the uboot repo, not a branch. Can be fixed by changing the source-branch: v2017.05 line in snapcraft.yaml to source-tag: v2017.05.
snap install ubuntu-image --beta --classic does not work (with various combinations of switches): the snap ubuntu-image does not appear to exist. What am I missing? That said, sudo apt install ubuntu-image seems to do the job.
@svet I could download ubunut-image with snap install command , I did that on a ubuntu 16.04 machine (not core). I agree with you on the installation part , I got the same error when trying to install the gadget)
On second thought, I’m assuming it’s because I was trying to run this on an armhf and not amd64 - and I guess the snap is just not available for the arch. But also yes - I was running this on a Ubuntu Core device (in classic mode), rather than than regular Ubuntu, so that may have been a problem also.
sadly not … but … if you change files that end up to live in the system-boot partition you can simply replace them directly in /boot/uboot/ from your gadget build (just scp them to your home on the pi and then sudo cp them to the dir) …
that way you only need to test the snap as a last step and only have to flash once … specifically for the pi3 i think the majority of files are actually in that dir somewhere …
if you change contents of uboot.env you can even use the shipped fw_setenv and fw_printenv commands to modify the bootloader config from the running system for testing.
This uses a (admittedly a little gross but working) hack to download the latest linaro cross GCC to solve exactly this issue for the allwinner gadgets i maintain (they all need gcc6) …
I used xz to compress the build image file and used the below command to write tot the HDD
xzcat <path to my img.xz> | sudo dd of=/dev/sda bs=32M; sync
Some more updates. I could build and flash the image but the pc snap I built is not appearing on the device. Also the behavior of snap commands is erratic. For .eg look at the output of snap list command executed .
admin@localhost:~$ sudo snap list
[sudo] password for admin:
No snaps are installed yet. Try "snap install hello-world".
admin@localhost:~$ sudo snap list
No snaps are installed yet. Try "snap install hello-world".
admin@localhost:~$ sudo snap list
No snaps are installed yet. Try "snap install hello-world".
admin@localhost:~$ sudo bash
bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
root@localhost:~# snap list
Name Version Rev Developer Notes
core 16-2.31 4017 canonical core
root@localhost:~# snap list
Name Version Rev Developer Notes
core 16-2.31 4017 canonical core
pc-kernel 4.4.0-112.135 102 canonical kernel
root@localhost:~# snap list
Name Version Rev Developer Notes
core 16-2.31 4017 canonical core
pc-kernel 4.4.0-112.135 102 canonical kernel
root@localhost:~# snap list
Name Version Rev Developer Notes
core 16-2.31 4017 canonical core
pc 16.04-0.8 9 canonical gadget
pc-kernel 4.4.0-112.135 102 canonical kernel
root@localhost:~# snap list
Name Version Rev Developer Notes
core 16-2.31 4017 canonical core
pc 16.04-0.8 9 canonical gadget
pc-kernel 4.4.0-112.135 102 canonical kernel
root@localhost:~# snap list
Name Version Rev Developer Notes
core 16-2.31 4017 canonical core
pc-kernel 4.4.0-112.135 102 canonical kernel
root@localhost:~# snap list
Name Version Rev Developer Notes
core 16-2.31 4017 canonical core
pc-kernel 4.4.0-112.135 102 canonical kernel
Note the pc snap version is still 16.01.0.8 where as the snap I built is pc_16.04-0.9_amd64.snap. Also snap interfaces is not showing the serial slots I have created.
If you seee it dis/enabled in snap list all the time, I suggest to take a look at snap changes (and if you find an error there, use: snap change <id of the change>
That should have some more details about what is going on.