Embedded Linux on ARM | Sample Programs

Home Embedded Linux on ARM  | Course Home  Embedded Linux on ARM | Sample Programs

Embedded Linux on ARM – Porting Steps

Sample programs is the first step you take to transition from theory to practical. These sample programs typically demonstrated in a classroom will ensure you are able to immediately see it running in front of your eyes. Added to that our mentors will provide you some exercises where you will be modifying the code in the class itself. By doing this fill-in-the-blank approach, will take out your fear of coding.

Step 1 : Workspace Creation

Brief:

– Create a directory named, EOS (Embedded Operating System) in your home directory (or where ever you wish)

– Assuming you wish to create it in home directory

  |$ cd && mkdir EOS

– Change directory to EOS

  |$ cd EOS

– Now please follow the commands mentioned has is in the document

Brief:

– This section helps you to get all the needed files. Here we have used the available version as of updating this page. You may download       the latest version by visiting the corresponding package website.

– Create a directory named, Sources and store all the required tar files into it.

  |$ mkdir Sources

– Change directory to Sources

  |$ cd Sources

– Download Buildroot

  |$ wget https://buildroot.org/downloads/buildroot-2021.02.3.tar.bz2

– Download U-Boot

  |$ wget https://ftp.denx.de/pub/u-boot/u-boot-2021.04.tar.bz2

– Download Linux kernel

 

  |$ wget https://cdn.kernel.org/pub/linux/kernel/v5 .x/linux-5.12.10.tar.xz

Brief:

– The simplest method of building toolchain is using automated scripts provided by the build system.

– In our case we will be using Buildroot to build all the necessary stuffs (including toolchains) to bring up our board

– Create a directory named Buildroot under EOS and change directory to it

  |$ mkdir Buildroot && cd Buildroot

– Untar the provided buildroot file from the Sources directory

  |$ tar xvf ../Sources/<buildroot_tar_file>
  |$ cd <buildroot_directory>

– Start buildroot configuration

  |$ make menuconfig

– Just change the Target Architecture and its Variant and keep everything else default and just type

  |$ make

– If everything goes fine the build should be successful
– The toolchain output can be found in output/host/usr/bin

Brief:

– The embedded linux system can be emulated in the host system with the help of Qemu

– Follow the step to install qemu on your host

  |$ sudo apt update
  |$ sudo apt install qemu-system-arm -y

– To list the available system try

  |$ qemu-system-arm -machine help

– Pick the closest board you try to emulate

– This document follows vexpress-a9 (ARM Versatile Express for Cortex-A9) board

Brief:

– Create a directory named UBoot under EOS and change directory to it

  |$ mkdir UBoot && cd UBoot

– Untar the provided u-boot file from the Sources directory

  |$ tar xvf ../Sources/<u-boot_tar_file>
  |$ cd <u-boot>

– Do u-boot configuration

  |$ make vexpress_ca9x4_defconfig

– Build the package

|$ make ARCH=arm CROSS_COMPILE=<arm-linux- path>

– On successful compilation you should get spl/u-boot-spl.bin and u-boot.img files

Brief:

– It is assumed that you have created a network bridge with tap

– To run the bootloader image just run the following command

  |$ sudo qemu-system-arm -M vexpress-a9 -m 512M -kernel u-boot -nographic -net nic -net tap,ifname=tap1,script=no

 

Brief:

– Create a directory named LinuxKernel under EOS and change directory to it

  |$ mkdir Linux&& cd Linux

– Untar the provided linux tar file from the Sources directory

  |$ tar xvf ../Sources/<linux.tar>
  |$ cd <linux>

– Do kernel configuration

  |$ make ARCH=arm CROSS_COMPILE=<arm-linux- path> uImage LOADADDR=0x62008000 dtbs

– On a successful build you should get the final outputs in arch/arm/boot/ directory

– Copy the required file to tftpboot folder

 

  |$ cp arch/arm/boot/uImage /var/lib/tftpboot
  |$ cp arch/arm/boot/dts/vexpress-v2p-ca9.dtb /var/lib/tftpboot

Brief:

– Assuming the tap is configured

– Check the ip address of the host and note it

  |$ ifconfig

– Assuming the target is running the u-boot.

– Set the IP addresses of client and server on target board

  |> setenv serverip <Host IP Address>
  |> setenv ipaddr <Local IP Address>
  |> ping <Host IP Address>

– You should get “Host is alive” message on target on successful connection
– Load the kernel image on target

  |> tftp 0x62008000 uImage

– You should see ‘###’ printed on screen with transfer summary

– Load the dtb image on target

  |> tftp 0x62F00000 vexpress-v2p-ca9.dtb

– You should see ‘###’ printed on screen with transfer summary

– Set kernel command line arguments

  |> setenv bootargs console=ttyAMA0,38400n8

– Boot the loaded image

  |> bootm 0x62008000 – 0x62F00000

– The target board should boot up with a kernel panic

Brief:

Adding the RootFS directory path to Initramfs

– Create a directory named RootFS under EOS and change directory to it

  |$ mkdir RootFS && cd RootFS

– Untar the built rootfs tar file from the buildroot directory

  |$ sudo tar xvf ../Buildroot/buildroot-2015.11.1/output/images/rootfs.tar

– You should see the entire file system present in the current directory

– Link busybox as init

  |$ ln -s bin/busybox init

– Configure the kernel for initramfs

  |$ make ARCH=arm menuconfig

– A ncurses based configuration window will be opened, follow the below steps

  |% General setup —>
  |% [*]Initial RAM filesystem and RAM disk (initramfs/initrd) support
  |% (provide the path of RootFS) Initramfs source file(s)

– Save and exit the configuration window and build again

  |$ make ARCH=arm CROSS_COMPILE=<arm-linux- path> uImage dtbs LOADADDR=0x62008000
  |$ cp arch/arm/boot/uImage /var/lib/tftpboot

– Load the new image

– The board should boot fine. But this time it should complain about null

Brief:

– Change directory to your RootFS

– Change directory to init.d as

  |$ cd etc/init.d/

– Write a rc script like with folloing lines

  |$ vi S01create_nodes
  |~ #!/bin/sh
  |~ mdev -s

– Save and exit

– Give the file executable permission

  |$ chmod +x S01create_nodes

– Build the kernel

– Load the image

– The board should boot fine

– Login and type

  |# ls /

– You should see edit the file system created by you

Well you target board up with Embedded Linux running on it. Now you may proceed further to explore your system as needed and take it further.