Zephyr Kernel Installation & Setup Manual Zephyr kernel is a small footprint Single address space OS, i.e, it combines application specific code with a custom kernel to create a monolithic image that gets loaded and executed on a system s hardware. Both the application code and kernel code execute in a single shared address space. You ll need to complete the following steps on your Linux Virtual Machine or Host Linux Machine, Update Your Operating System Before proceeding with the build, ensure your OS is up to date. On Ubuntu, you ll first need to update the local database list of available packages before upgrading: $ sudo apt get update $ sudo apt get upgrade Installing the Requirements and Dependencies Install the required packages in a Ubuntu host system with: $ sudo apt get install git make gcc g++ python3 ply ncurses dev Installing the Zephyr Software Development Kit Zephyr s SDK contains all necessary tools and cross compilers needed to build the kernel on all supported architectures. Follow these steps to install the SDK on your Linux Host System. 1. Use the following command to download the required version of the SDK $ wget https://nexus.zephyrproject.org/content/repositories/releases/org/zephyrproject/zephyr sdk/ 0.8.2 i686/zephyr sdk 0.8.2 i686 setup.run 2. Run the installation binary, follow this example: $ chmod +x zephyr sdk <version> i686 setup.run
$ sudo./zephyr sdk <version> i686 setup.run Use the default directory for installation. 3. To use the Zephyr SDK, export the following environment variables and use the target location where SDK was installed, type: $ export ZEPHYR_GCC_VARIANT=zephyr $ export ZEPHYR_SDK_INSTALL_DIR=/opt/zephyr sdk/ Building and Running an Application Using the Hello World sample application as a base model, the following section will describe the pieces necessary for creating a Zephyr application. Clone the open source repository of the Zephyr project To clone the repository, enter: $ git clone https://gerrit.zephyrproject.org/r/zephyr zephyr project You have successfully checked out a copy of the source code to your local machine. To build an example application follow these steps: 1. Make sure your environment is setup by exporting the following environment variables. $ export ZEPHYR_GCC_VARIANT=zephyr $ export ZEPHYR_SDK_INSTALL_DIR=/opt/zephyr sdk/ 2. Navigate to the main project directory: $ cd zephyr project 3. Source the project environment file to set the project environment variables: $ source zephyr env.sh
4. To Build the sample hello world provided by Zephyr, enter: $ cd $ZEPHYR_BASE/samples/hello_world/microkernel 5. Make the kernel. The invocation of make will build the hello_world sample application using the default settings defined in the application s Makefile which you need to modify as follows: #BOARD?= qemu_x86 BOARD?= galileo Now make the kernel $ make Alternatively, you can build for galileo board by defining the variable BOARD instead of changing the makefile, for example: $ make BOARD=galileo After building an application successfully, the results can be found in the outdir sub directory under the application root directory, in a subdirectory that matches the BOARD string. In our case you can find the results in : $cd outdir/galileo Porting the kernel image to the Galileo Board and booting it Creating a GRUB2 Boot Loader Image from a Linux Host Follow these steps to test on Galileo2 boards using a custom GRUB. 1. Install the requirements to build GRUB on your host machine. $ sudo apt get install bison autoconf libopts25 dev flex automake 2. Navigate to the main project directory: $ cd zephyr project 3. Clone and build the GRUB repository using the script in Zephyr tree, type: $./scripts/build_grub.sh
4. You can find the binary at zephyr project/scripts/grub/bin/grub.efi Preparing the Boot Device 1. Format your microsd as FAT. A. Go to disks from the Dashboard B. Unmount the mounted partitions using the stop button. Delete any already existing partitions if they exist using the (minus) button, until only no partitions remain. C. Click on more actions, and choose the Format option. Format with FAT 2. We need to create a directory structure in the microsd card as shown below:
3. Create efi, efi/boot, and kernel directories: $ mkdir p efi/boot $ mkdir kernel 4. Copy the kernel file outdir/zephyr.strip to the kernel folder. 5. Copy your built version of GRUB to efi/boot/grub.efi. You can find the built binary at zephyr project/scripts/grub/bin/grub.efi 6. Create efi/boot/grub.cfg file containing the following data: set default=0 set timeout=10 menuentry "Zephyr Kernel" { multiboot /kernel/zephyr.strip } 7. Create a boot/grub folder: $ mkdir p boot/grub and create grub.conf file in this folder containing the following: default=0 timeout=5 title Zephyr rootnoverify (hd0,0) chainloader /efi/boot/grub.efi Booting the Galileo Board
Boot the Galileo board from the boot device using GRUB2 with the firmware present in the on board flash. 1. Insert the prepared boot device (micro SD card or USB flash drive) into the Galileo board. 2. Connect the board to the host system using the serial cable and configure your host system to watch for serial data using PuTTY. 3. Power on the Galileo board. 4. When the following output appears, press F7 5. Select the Zephyr image you want to boot into press Enter. When the boot process completes, you have finished booting the Zephyr application image. 6. You should observe the following output on your PuTTY terminal for the hello_world sample application
If the above messages of WARNING and ERROR appear during boot, they can be safely ignored. Congratulations! You ve successfully booted with the Zephyr application lmage! For any future builds of the monolithic kernel for other applications, you will only need to replace the zephyr.strip image in the kernel folder of the SD card, with the zephyr.strip image of your new application.