Building a Linux image for Intel Galileo with the Yocto Project
We went through the software specifications of Intel Galileo in the previous section and booted Intel Galileo with the Linux image on its SPI flash.
In this section, we are going to cover how to build a customized image for Intel Galileo with some additional software packages using the Yocto Project, and we will boot Intel Galileo from the microSD card with our new Linux image.
Note
The Yocto Project is an open source project that helps embedded Linux developers by providing a set of tools such as Poky to ease the customization of Linux filesystems, building kernel images. This project uses a folder structure to store the metadata of the build information of individual software projects. Each software application or library has a metadata file called recipes
with the .bb
and .bbclass
files. A quick start guide for developers is available at http://www.yoctoproject.org/docs/current/yocto-project-qs/yocto-project-qs.html, where you can get the basics of the Yocto Project.
You will also learn some basics of the Yocto Project to build and customize Linux filesystems for Intel Galileo.
Note
There are prebuilt SD card images for Intel Galileo; you can easily get them from the Intel download page at https://communities.intel.com/docs/DOC-22226.
Learning about the build process will teach you how to customize Linux for future needs. Before that, the following prerequisites are needed:
- We need to first download the Intel Quark board support package from http://downloadcenter.intel.com/confirm.aspx?httpDown=http://downloadmirror.intel.com/23197/eng/Board_Support_Package_Sources_for_Intel_Quark_v1.0.1.7z&Lang=eng&Dwnldid=23197.
- Then, we should download BSP patches to fix some of the problems with upstream sources. Download the patches from https://github.com/01org/Galileo-Runtime/archive/1.0.4.tar.gz. Patching instructions can be found in the following link: http://downloadmirror.intel.com/24355/eng/BSP-Patches-and-Build_Instructions.1.0.4.txt.
- The next step is to extract the files. As the BSP package is distributed in 7-Zip format, make sure that you have 7-Zip installed on your host:
$ sudo apt-get install p7zip
A good way to deal with the build process and all the mess created is to create a unique folder in our home
directory, such as /home/onur/galileo_build
, and do all the build work in that directory. I will refer to our build in the directory as BUILD_DIR
.
Building Linux filesystems for Intel Galileo
You need to follow these steps to build a Linux filesystem:
- Put your downloaded files in your build directory and extract them, as follows:
$ cd /home/onur/galileo_build $ mv ~/Downloads/board_support_package_sources_for_intel_quark_v1.0 .1.7z . $ mv ~/Downloads/BSP-Patches-and- Build_Instructions.1.0.4.tar.bz2 . $ 7z x board_support_package_sources_for_intel_quark_v1.0.1.7z
BSP includes packages for the layers of software for Intel Galileo. Grub OS Loader, Linux Filesystem build files for Yocto Project, EDKII (Firmware for Quark), Linux Kernel for Intel Quark, SPI-Flash tools, and System Image files are the packages required by developers to rebuild and reuse. Our focus will be on the
meta-clanton_v1.0.1.tar.gz
file to create the Linux filesystem to boot with the SD card.Note
You will see clanton in many places in the files you downloaded. It refers to systems with Intel Quark processors.
The
board_support_package_sources_for_intel_quark_v1.0.1.7z
file includes the following compressed files:grub-legacy_5775f32a+v1.0.1.tar.gz
meta-clanton_v1.0.1.tar.gz
Quark_EDKII_v1.0.1.tar.gz
quark_linux_v3.8.7+v1.0.1.tar.gz
spi-flash-tools_v1.0.1.tar.gz
sysimage_v1.0.1.tar.gz
sha1sum.txt
- The
BSP-Patches-and-Build_Instructions
file includes a folder calledpatches
. It has a number of patches to apply the Yocto Project metadata (recipe
).bb
files:$ tar xvf BSP-Patches-and-Build_Instructions.1.0.4.tar.bz2
- Extract metadata for the Intel Galileo development board to build the Linux filesystem. Metadata files will be extracted into the
meta-clanton_v1.0.1
directory:$ tar xvf meta-clanton_v1.0.1.tar.gz
Tip
It is highly recommended that you apply patches inside the extracted
patches
folder that comes along with theBSP_Patches_and_Instructions
file. Instructions are stored in thepatches/patches.txt
file. If you don't apply the patches before starting the build process, you are highly likely to get errors. - There are a couple of tools that you need to install on your host system to start the building process. Make sure you have installed them:
$ sudo apt-get install git diffstat texinfo gawk chrpath file build-essential gcc-multilib chrpath
- Go to the
meta-clanton_v1.0.1
folder to start the build process:$ cd $BUILD_DIR/meta-clanton_v1.0.1
This is where all the metadata is placed for building Linux filesystems. After applying the patches, we can start executing the scripts to start building:
- The first step is to run the
setup.sh
script in themeta-clanton_v1.0.1
folder to get the required external sources. It will also create the folderyocto_build
with the required configuration files to define metadata layers for the Yocto build tool BitBake:$ ./setup.sh
- Then, we need to initialize the environment variables and specify the build folder for the output of the build process:
$ source poky/oe-init-build-env yocto_build
Tip
If you've closed your current shell session and started on a new one, for each shell that you open, you need to source environment variables with
oe-init-build-env
.After you initialize the environment variables, you will be redirected to the
yocto_build
folder. This is the folder where all the downloaded sources and the output of the build process will be copied.Now we are ready to start the build process with the Yocto Project command tool BitBake.
Note
BitBake take cares of the entire build process by parsing configuration files in all the layers, the metadata (recipes), classes, and configurations files such as the
.bb
,.bbclass
, and.conf
files, respectively.There is already a metadata file defined to build a full image, which includes many open source projects such as Node.js, OpenCV, and additional kernel modules to support mini PCI-E Wi-Fi cards.
- Start the build process with the following command:
$ bitbake image-full-galileo
- An output similar to the following will be seen on your host machine:
Loading cache: 100% |##########################################################################################################################################################################################################| ETA: 00:00:00 Loaded 1617 entries from dependency cache. Build Configuration: BB_VERSION = "1.18.0" BUILD_SYS = "x86_64-linux" NATIVELSBSTRING = "Ubuntu-12.04" TARGET_SYS = "i586-poky-linux-uclibc" MACHINE = "clanton" DISTRO = "clanton-tiny" DISTRO_VERSION = "1.4.2" TUNE_FEATURES = "m32 i586" TARGET_FPU = "" meta meta-yocto meta-yocto-bsp = "clanton:d734ab491a30078d43dee5440c03acce2d251425" meta-intel = "clanton:048def7bae8e3e1a11c91f5071f99bdcf8e6dd16" meta-oe = "clanton:13ae5105ee30410136beeae66ec41ee4a8a2e2b0" meta-clanton-distro meta-clanton-bsp = "<unknown>:<unknown>" Currently 12 running tasks (179 of 2924): 0: uclibc-initial- 0.9.33+gitAUTOINC+946799cd0ce0c6c803c9cb173a84f4d607bde350- r8.4 do_unpack (pid 32309) 1: binutils-cross-2.23.1-r3 do_unpack (pid 32304) 2: linux-libc-headers-3.8-r0 do_fetch (pid 32307) 3: gcc-cross-initial-4.7.2-r20 do_fetch (pid 32308) 4: libmpc-native-0.8.2-r1 do_compile (pid 32305) 5: python-native-2.7.3-r0.1 do_unpack (pid 32316) 6: uclibc- 0.9.33+gitAUTOINC+946799cd0ce0c6c803c9cb173a84f4d607bde350- r8.4 do_unpack (pid 32310) 7: elfutils-native-0.148-r11 do_compile (pid 32314) 8: file-native-5.13-r0 do_compile (pid 32315) 9: readline-native-6.2-r4 do_configure (pid 32311) 10: openssl-native-1.0.1h-r15.0 do_install (pid 32312) 11: attr-native-2.4.46-r4 do_configure (pid 32313)
The build process can take around 2 hours to finish, depending on the processing power of your host machine.
The build process will start by parsing recipes in the board's support package and will fetch the source code, configure, build, and install on the final Linux filesystem image.
If everything goes well and the build process finishes successfully, all the required files will be created in the $BUILD_DIR/meta_clanton_v1.0.1/yocto_build/tmp/deploy/images
folder to be used for your SD card.
Preparing the SD card to boot
When the build process is successful, you can go ahead and copy the required files onto your microSD card to boot with Intel Galileo.
First, you need a microSD card; Intel Galileo supports SD cards up to 32 GB in capacity. Format your microSD card as FAT32 for first-time use and then copy the following files to your microSD card:
- Format the SD card as FAT32, and check the assigned device file for the SD card on your system; something such as
/dev/sdd
or/dev/mmcblk0
should be assigned to it. You can use device messages (thedmesg
command) to check the assigned device file for the SD card. Run thedmesg
command before and after you have attached the SD card on your host PC terminal. Then, you can see the assigned device file. In this section, we will use/dev/sdX
to indicate the SD card's device file:$ sudo mkfs.msdos /dev/sdX
- Mount the SD card on your host system:
$ sudo mount /dev/sdX /mnt/sdcard
- Copy the following files to your SD card:
$ cd $BUILD_DIR/meta- clanton_v1.0.1/yocto_build/tmp/deploy/images/ $ cp image-full-galileo-clanton.ext3 core-image-minimal- initramfs-clanton.cpio.gz bzImage grub.efi -t /mnt/sdcard $ cp –r boot/ -t /mnt/sdcard
Note
The
image-full-galileo-clanton.ext3
file includes the Linux root filesystem. ThebzImage
file is the Linux kernel image. Thecore-image-minimal-initramfs-clanton.cpio.gz
file is the initial RAM file system.grub.efi
is the file, andGRUB/UEFI
is the firmware for Intel Galileo. Theboot
folder includes the GRUB configuration. - Unmount the SD card and detach it from your host system:
$ sudo unmount /mnt/sdcard
- Insert the microSD card into the slot next to the power port on the Intel Galileo development board.
Connect the serial cable, as shown in the previous section, and power up Intel Galileo. When Intel Galileo is booting from the SD card, an LED starts to blink. This is the LED on which the SD card is writing.
When you are prompted to log in, just like when you booted the SPI image in the previous section, you can log in with the root user and wander around the additional installed packages with the SD image.
An advantage of using an SD card instead of using an SPI flash image is that you will have more storage, so you can install more software.
Created files are also not volatile on an SD card; they will not be removed when you reboot the board. If you are using the Intel Galileo board from the SPI flash image, it will remove all the created files when you reboot the board.
Upgrading firmware on Intel Galileo
While booting from the SD card, you may encounter problems. If the version of firmware on the Intel Galileo board and the BSP version that you build on the Linux filesystem don't match, the board doesn't boot the SD card. You can easily see this as the SD card's LED doesn't blink.
Check whether you formatted the SD card correctly to FAT32 and the files have been copied correctly. If the SD card format and files are not corrupted, it is suggested that you upgrade the firmware on the Intel Galileo board you have, as follows:
- Download the Arduino IDE for Intel Galileo, for your host computer's architecture, from https://communities.intel.com/docs/DOC-22226.
- Connect Intel Galileo to your PC using a micro USB-to-USB cable. When Intel Galileo is connected to the host device with a micro USB, it defines a new device,
/dev/ttyACM0
. You can check the device messages (dmesg
) to check whether Intel Galileo is connected correctly. - Extract the downloaded file:
$ tar xvf arduino-linux64-1.0.4.tgz
- Go to the
arduino-linux64-1.0.4.tgz
folder and run theArduino IDE
executable withsudo
:$ cd arduino-linux-1.0.4.tgz
- In the menu bar of the Arduino IDE, navigate to the following:
- Tools | Serial Port | /dev/ttyACM0
- Tools | Board | Intel Galileo (Gen 2)
- Check for the firmware upgrade by navigating to Help | Galileo Firmware Update.
If the firmware on your device has a lower version, the Arduino IDE will prompt you to upgrade. Click on OK to upgrade the firmware and follow the instructions. This should take approximately 5 to 10 minutes. The Arduino IDE will prompt when the upgrade has been successfully installed.
Building the Intel Galileo SDK
We have gone through the steps to get the board's support packages and to build the Linux kernel as well as the filesystem. Since we are going to develop and build applications for Intel Galileo, we need an SDK to compile and build.
The Yocto Project allows you to easily create the SDK for embedded devices, similar to creating a filesystem. We need to run one more command right after we build the filesystem.
All the commands used to build an SDK are similar to the commands used to build a filesystem, but only the last command changes to create a toolchain, as follows:
$ bitbake image-full-galileo –c populate_sdk
After the successful execution of the populate_sdk
command, the SDK installer will be deployed into the $BUILD_DIR/meta_clanton_v1.0.1/yocto_build/tmp/deploy/sdk
folder:
$ ls tmp/deploy/sdk clanton-tiny-uclibc-x86_64-i586-toolchain-1.4.2.sh
In this example, BitBake created an image for a 64-bit host; if you build on a 32-bit host, BitBake will create a toolchain for a 32-bit architecture.
Note
It is also possible to create toolchains for other architectures. Add the SDKMACHINE ?= i686
line to the yocto_build/conf/local.conf
file and rerun the command. It will create the file clanton-tiny-uclibc-i686-i586-toolchain-1.4.2.sh
.