November 25, 2016

Intel Galileo - Running linux from an SD card image

My ultimate goal here is to run an executable that I have compiled myself; an ordinary C program. So I need either a galileo hosted C compiler, or a way to transfer files and a toolchain on my linux desktop. I would like to imagine that gcc that I use on my desktop will work fine, but we shall see.

Linux SD card image

You have a variety of choices. The board ships with an immutable image in the 8M of SPI flash onboard. This may be fine for people using this board as a super-Arduino, but it is almost useless for anything I want to do. Some crazy people do some contorted thing and run debian inside of virtual box inside of the linux Intel supplies as an SD card image.

What I did was to download the 400M image at the "Intel IoT developer zone" here:

On this page, I selected the link labelled "latest Yocto Pokey image" and downloaded it. This provided me with iot-devkit-prof-dev-image-galileo-20160606.zip. This unzips to a 1.8G file: iot-devkit-prof-dev-image-galileo-20160606.direct.

I have a brand new "SanDisk Ultra microSDHD UHS-1 card" in an 8G size. I put this into my trust USB card reader and plug it into my linux desktop. It automounts. The mount command tells me that /dev/sdc1 is mounted with type vfat.

Bad linux instructions from Intel

I wasted time following the bogus instructions from Intel on how to prepare the SD card. First of all, there is no reason whatsoever to format or partition it since you are going to overwrite all of that using the "dd" command. But most importantly you do not want to do the dd to a partition on the drive (like /dev/sdc1), you must do the "dd" to the device itself (such as /dev/sdc) not a partition.

My instructions (that actually work)

Warning!! Be absolutely sure to have the correct device name in the following step. If you do something stupid like doing the dd to device "sda" you will overwrite your system disk on your desktop machine!

I am using a Fedora 24 linux desktop to do this. When I plug in my card reader, it detects it and automounts it. But we want to unmount it and then use dd, as follows:

su
umount /dev/sdc1
dd if=iot-devkit-prof-dev-image-galileo-20160606.direct of=/dev/sdc bs=16M
108+1 records in
108+1 records out
1819280384 bytes (1.8 GB, 1.7 GiB) copied, 234.939 s, 7.7 MB/s
sync
That is it. Easy as pie. Just for the record, looking at this card with fdisk shows:
Command (m for help): p
Disk /dev/sdc: 7.4 GiB, 7948206080 bytes, 15523840 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x55f2787e

Device     Boot  Start     End Sectors  Size Id Type
/dev/sdc1  *      2048  106495  104448   51M 83 Linux
/dev/sdc2       106496 3553279 3446784  1.7G 83 Linux

Put the card in the Galileo

First I connect my serial console and start picocom running on my desktop. Then I insert the microSD card into the slot on the Galileo. The SD card socket is unlike any other I have enountered. The card goes in, but it does not pop back out on a second push. Needlenose pliers or some similar tool are needed to pull the card out. Lastly we plug in the power connector and watch the boot. This turns out rather nicely though. I plug in a network cable and it configures itself, and is running sshd so I can use ifconfig -a to see the IP addresses my DHCP has assigned and immediately can ssh to the galileo.

I have vi and cc (vim and gcc) so I can immediately write a hello world program.

And to my pleasant surprise, this has sshd ready to go and performs dhcp as soon as a network cable is attached. Very nice. The following is part of the output from "ps -l"

S     0   105     1  9932  1296 0:0   18:02 00:00:00 /lib/systemd/systemd-udevd
S   996   126     1 12212  1196 0:0   18:02 00:00:08 /lib/systemd/systemd-timesyncd
S     0   154     1  5648  2072 0:0   18:02 00:00:00 /usr/sbin/ofonod -n
S     0   156     1  5848   652 0:0   18:02 00:00:00 /usr/sbin/tcf-agent -d -L- -l0
S   998   160     1  3436  1608 0:0   18:02 00:00:00 avahi-daemon: running [galileo.local]
S     0   162     1  3352  1264 0:0   18:02 00:00:00 /bin/sh /opt/cln/galileo/launcher.sh
S   998   163   160  3328   468 0:0   18:02 00:00:00 avahi-daemon: chroot helper
S     0   168     1  2768  1184 0:0   18:02 00:00:00 /lib/systemd/systemd-logind
S   999   169     1  3088  1400 0:0   18:02 00:00:00 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
S     0   170   162  1820   380 0:0   18:02 00:00:00 /opt/cln/galileo/galileo_sketch_reset -i 63 -o 47
S     0   171   162  2012   516 0:0   18:02 00:00:00 /opt/cln/galileo/clloader --escape --binary --zmodem --disable-timeouts
S     0   183     1  7288  2516 0:0   18:02 00:00:07 /usr/sbin/connmand -n
S     0   190     1  2392   836 0:0   18:02 00:00:01 /usr/sbin/lighttpd -D -f /etc/lighttpd.conf
S 65534   191     1  2720  1128 0:0   18:02 00:00:00 /usr/sbin/mdnsd
S   995   194     1  2268   748 0:0   18:02 00:00:00 avahi-autoipd: [enp0s20f6] sleeping
S     0   195   194  2012   348 0:0   18:02 00:00:00 avahi-autoipd: [enp0s20f6] callout dispatcher
S     0   200     1  6988  1492 0:0   18:02 00:00:00 /usr/sbin/wpa_supplicant -u
S     0   203     1  5116  1744 0:0   18:02 00:00:00 /usr/lib/bluez5/bluetooth/bluetoothd -E
S     0   204     1  3352  1264 0:0   18:02 00:00:00 {xdk-daemon} /bin/sh /opt/xdk-daemon/xdk-daemon
S     0   213   204 77080 11456 0:0   18:02 00:00:05 /usr/bin/node /opt/xdk-daemon/main.js
S     0   219     1  3416  1504 ttyS1 18:02 00:00:00 -sh
S     0   220     1  2244   736 tty1  18:02 00:00:00 /sbin/agetty --noclear tty1 linux
S     0   236   213  110m 16148 0:0   18:02 00:00:08 /usr/bin/node /opt/xdk-daemon/current/appDaemon.js
S     0   257     1 20060  1192 0:0   18:03 00:03:12 /usr/bin/redis-server /etc/redis/redis.conf
S     0   285     2     0     0 0:0   19:14 00:00:00 [kworker/0:0]
S     0   288     1  5520  2340 0:0   19:15 00:00:01 sshd: root@pts/0
And for the record, here are the mounted filesystems
root@galileo:~# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/root        1668912 1360604    222164  86% /
/dev/mmcblk0p1     50412    2287     48126   5% /media/card
mount
/dev/mmcblk0p2 on / type ext3 (rw,relatime,errors=continue,user_xattr,acl,barrier=1,data=writeback)
/dev/mmcblk0p1 on /media/card type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)
Apparently /dev/root was equivalent to /dev/mmcblk0p2 as some stage of the boot process.

Small thinking

I am surprised by what I will call "small thinking" on the part of the Galileo developers. Why doesn't Intel supply a full linux distro on an SD card image? For that matter why didn't they put 4G of eMMC flash on board like the BBB? They certainly could have. The BBB sells for $50 and has it, and runs a full blown debian distribution with a native hosted C compiler, vim and you name it. Remember that the Galileo sold for $80 until recently and perhaps more originally.

But Intel was thinking of the Galileo as a "super arduino" or some such. We should be thankful that they included an SD slot I suppose. Maybe they were afraid of suggesting to people that the Galileo is capable of being a linux machine, expecting people to use the Arduino sandbox and neither know nor care that it was running linux under the hood. I have seen companies "cripple" a product to ensure that it does not compete with other products in their overall "strategy". Well, who knows.


Feedback? Questions? Drop me a line!

Tom's Computer Info / tom@mmto.org

Feedback? Questions? Drop me a line!

Tom's Computer Info / tom@mmto.org