Table of Contents

Getting Started with Codezero Development

This step by step guide explains on how to download, install and configure various tools required to build, run and debug Codezero.

1.) Creating the Directory Structure for Codezero Sources and Tools:

a. Give the following commands on shell:

% mkdir /opt
% mkdir /opt/archives
% mkdir /opt/tools

This will respectively create the directories where Codezero source code and required build tools will be saved and installed in reference to this guide.

2.) Installing Git

Git SCM tool is needed for downloading and managing Codezero sources.

For Ubuntu users, give the following shell command:

% sudo aptitude install git-core

To install git or any other package from the Ubuntu repository, sudo password is required. On Ubuntu, git installation is done by the above step. For non-Ubuntu users, please refer to Installing from Source guide for installation of git from scratch.

3.) Installing SCons

Codezero uses SCons as its build software. SCons is a python-based build tool where builds can be manipulated using Python scripts and functions.

For Ubuntu users, give the following shell command:

% sudo aptitude install scons

Sudo password is required for this step. SConstruct installation is done. For non-Ubuntu users, please refer to Installing SCons section in the Installing from Source guide.

4.) Installing the GCC cross-compiler

Codezero project uses the Codesourcery ARM cross-compilers for compiling the sources. Other cross-compilers such as crosstools may work, but testing is done using this toolchain.

For installing the cross compiler tool chain, follow the steps below.

a. Create a directory for cross compiler tool chain.

% mkdir /opt/archives/cc

b. Download latest gcc arm cross compiler tool chain(IA32 GNU/Linux Installer) for ARM EABI from http://www.codesourcery.com/sgpp/lite/arm/portal/subscription3053.

Download latest gcc arm cross compiler tool chain(IA32 GNU/Linux Installer) for GNU-LINUX from http://www.codesourcery.com/sgpp/lite/arm/portal/subscription3057.

We have tested 2009q1 and 2009q3 tool chains, so preferably download any of these.

c. Save both files to /opt/archives/cc.

d. Give the following shell commands to configure and install tool chain:

% cd /opt/archives/cc
% chmod 777 arm-2009q3-68-arm-none-eabi.bin

The last command would give execution right to run the binary, and root permission may be needed for this.

% . arm-2009q3-68-arm-none-eabi.bin -i console

This will start installing tool chain choose appropriate options when asked during installation of the tool chain. Default options can be chosen.

e. Repeat step (d) above for installing arm-2009q3-67-arm-none-linux-gnueabi.bin binary.

f. Add the following lines in the end of .bashrc file present in the home directory of current user (for example /home/amit for the fictional user named amit):

% PATH=$PATH:/opt/tools/cc/bin
% export PATH

This will add path of installed tool chain binaries to PATH environment variable. Please note for new .bashrc to be effective new console should be started, for making changes in .bashrc to be effective in currently running console, give the following command in console:

% source /home/amit/.bashrc

Here again, amit is the fictional current user, replace it appropriately.

% arm-none-eabi-gcc –help

This should display the help section of gcc cross compiler.

5.) Downloading Codezero Sources

To download/clone Codezero git repository give following shell commands:

% cd /opt
% git clone git://www.git.l4dev.org/codezero.git

This will start cloning the repository and will create the Codezero source tree under the directory /opt/codezero. master branch on this repository contains the stable version of the sources. The devel branch includes the latest development sources.

6.) Building Codezero Sources

Provided here are the minimal instructions needed to build Codezero. Please refer to the Codezero Overview guide for general information about the Codezero directory layout and generated images during a Codezero build.

To build Codezero, build.py script is provided in the project root directory /opt/codezero.

a. Give the following shell commands to run build.py:

% cd /opt/codezero
% ./build.py -c

This command will do both, configure and build for codezero.

Note: In case you want to use old configuration/last used configuration only, give ”./build.py” command.

Note: There is a complete set of options available that can be used with build.py script. Some important options are described here:

For more details please check ”./build.py -h”. In case you just want to configure codezero without building it, you can use configure.py script, as follows:

7.) Installing QEMU

QEMU is a freely available virtual platform emulator.

You may use the patched and prebuilt qemu-system-arm binary provided on this link. If you have any difficulty running this binary, please let us know

Alternatively, if you prefer to build and install QEMU from the sources, please refer to the QEMU section in Installing from Source guide.

8.) Installing Insight

Insight is a GUI front-end for GDB with a focus on cross-debugging of embedded targets. Insight is not necessary to be able to run Codezero, but it greatly simplifies development by providing step-by-step debugging and inspection opportunities for both Codezero Microkernel and its userland applications.

a. Create a directory for insight.

% mkdir /opt/archives/insight

b. Download insight tarball(for example insight-6.8.tar.bz2) from ftp://sourceware.org/pub/insight/releases.

c. Save it to /opt/archives/insight.

d. Use the following shell commands to untar the tarball:

% cd /opt/archives/insight
% tar -xjvf insight-6.8-1.tar.bz2

This will generate insight-6.8-1 directory under /opt/archives/insight.

As an example, in Ubuntu you may do:

% sudo aptitude search libncurses5
% sudo aptitude install libncurses-dev libncurses5-dev
% sudo aptitude search libx11
% sudo aptitude install libx11-dev

In Ubuntu libncurses package has termcap library.

Other dependencies that must be installed:

% sudo aptitude search makeinfo
% sudo aptitude install texi2html
% sudo aptitude install texinfo
% sudo aptitude search expat
% sudo aptitude install libexpat-dev libexpat1-dev

e. Use the following shell commands to configure and install insight:

% mkdir /opt/archives/insight-build
% cd /opt/archives/insight-build
% ../insight-6.8-1/configure --prefix=/opt/tools/insight --target=arm-none-eabi
    --program-prefix=arm-none- --with-expat

For more help type:

% ./configure --help
% make

This will build insight binaries.

% make install

This will install all the binaries in the system at the prefixed directory given during configure.

.gdbinit file

Insight is a gui frontend for GDB. GDB takes its configuration from ”.gdbinit” file which should be present under the home directory of current user. (For example /home/amit for the fictional user named amit). To connect gdb to QEMU that is running Codezero and load its symbols, the following commands should be written to the .gdbinit file, line-by-line. Note the file is broken up below to explain each step.

	target remote localhost:1234

This command tells gdb to connect to qemu.

	load final.elf

Loads the following image everytime gdb connects to qemu.

	sym final.elf

This command tells gdb to use following file name for symbol information.

	break break_virtual

A break_virtual symbol is defined in Codezero right after virtual memory is enabled. From this point onwards, it becomes possible to step through the code as pleased. This command makes gdb stop right after virtual memory is enabled.

	continue
	stepi

These commands tell gdb to start from beginning, step over one instruction after the break_virtual breakpoint is hit. This will allow insight to refresh its screen with the new symbol table.

	sym kernel.elf

This command tells gdb to use kernel.elf file for symbol information which includes Codezero symbol information after virtual memory is enabled.

Copy this file over to your home directory:

% cd codezero
% cp ./tools/gdbinit ~/.gdbinit

Add the following lines in the end of .bashrc file present in the home directory of current user (For example /home/amit for fictional user named amit):

% PATH=$PATH:/opt/tools/insight/bin
% export PATH

This will add the path of Insight binaries to PATH environment variable. Please note for new .bashrc to be effective new console should be started. For making changes in .bashrc to be effective in the currently running console, the following command should be used:

% source /home/username/.bashrc

To test if insight is installed properly and paths are updated correctly, give the following command on shell:

% cd codezero/build
% arm-none-insight

This should start the Insight debugger with its GUI window.

9.) Running Codezero

After all tools have been installed as described in the previous sections and Codezero sources have been successfully built, it is time to put everything together and run Codezero.

After Codezero has been successfully built, a final.elf executable should be present under the /opt/codezero/build directory. This image is the external loader executable that has the microkernel and all userspace tasks embedded inside.

/opt/codezero/tools/run-qemu-insight script

The script run-qemu-insight contains all the necessary commands to start QEMU, load final.elf, start Insight and initiate execution until the point where virtual memory is enabled inside the Codezero Microkernel. Here, some logic is provided by the .gdbinit file under the home directory for loading the symbols, and setting breakpoint during Insight/GDB startup.

Running the script simply starts everthing and executes Codezero until virtual memory is enabled:

% cd /opt/codezero
% ./tools/run-qemu-insight

Taking a closer look at the run-qemu-insight script:

% cd /opt/codezero/tools
% vim run-qemu-insight

Opens up the l4-qemu script file, which contains the lines:

cd build
qemu-system-arm -s -kernel final.elf -m 128 -M versatilepb -nographic &
arm-none-insight ; pkill qemu-system-arm
cd ..
  1. As this script is run from /opt/codezero directory, the shell enters /opt/codezero/build directory.
  2. In the second line, QEMU's ARM emulation binary is called using “qemu-system-arm”.
    • ”-kernel” option tells QEMU to use final.elf image, present in the current working directory as ther kernel image,
    • ”-m 128” option provides emulation of 128MB of available RAM,
    • ”-M” tells qemu to emulate processor/platform type, as specified here “ARM Versatile PB” platform is used. Currently, ARM/Versatile PB926 is the reference platform for running Codezero.
    • ”-s” option tells QEMU to wait for debugger connection before executing anything. This option is particularly broken on newer versions of QEMU.
    • The ”-nographic” option redirects PL011 UART output directly to the console.
  3. “arm-none-insight” in the third line starts the insight debugger.
  4. The next command i.e “pkill qemu-system-arm” is executed by shell only after the debugger is terminated. This enables termination of QEMU as soon as the debugger is shut down.
  5. Finally by the last line the shell goes one directory level up i.e /opt/codezero and finishes.
How it looks

The following is a typical screenshot after Codezero is up and running in control of the Insight debugger. If you have come to this stage, it means you have successfully built and run Codezero for the first time.

From this point onwards, you may step through the Codezero initialization code, place break points and generally do everything possible with the Insight/GDB debugger. In order to debug userspace applications, please refer to the Codezero Application Development tutorial.

10.) Running Codezero provided Examples and Templates

Codezero comes with a set of well designed examples and templates called Baremetal Projects, that a user can run to see how codezero system works, and also these examples can be used as templates to develop and generate new Projects.

If you check folder: codezero/config/cml/baremetal, we have a complete set of various configuration files present that can be used to build baremetal projects provided by codezero.

You can chose any any of the example script and run it simply by issuing the following commands in shell:

% cd codezero
% ./build.py -f </path/to/config_file>

Sources for various baremetal projects are present at: codezero/conts/baremetal/

Note:

11.) Developing new Projects/Containers for Codezero

Developers can follow the following process/cycle to build and integrate new containers/projects in Codezero build system:

codezero/scripts/baremetal/baremetal_add_container.py. Use this script as follows:

% cd codezero
% ./scripts/baremetal/baremetal_add_container.py -a -i <description> -s <source_path>

Here, <description> : short description for the new project to be added, and <source_path>: directory containing the source files for new container to be added.

In above mentioned development scenario <source_path> should be codezero/conts/empty0

And we are done, next time when you build codezero, you can see new project under “Baremetal Projects” menu.

In case you want to delete some earlier added project, use the following commands:

% cd codezero
% ./scripts/baremetal/baremetal_add_container.py -d -s <source_path>

<source_path> gives the path where the project resides. For above mentioned empty project case, <source_path> should be codezero/conts/baremetal/developer_project. For more help on using this script, use:

% ./scripts/baremetal/baremetal_add_container.py -h

Note:

If you are doing some work related to UARTS, you can consider working in UART Service Baremetal Project. Same process/cycle is applicable here also.

If you had problems with this tutorial, please share your experience in our mailing list, and we can improve on it.

12.) The Next Step

If you are aiming to develop and help on improving the Codezero software, the current setup would be sufficient.

The development cycle would be such that new changes would be made, recompiled and tested on QEMU/Insight as described in the above steps.

You should take a look at the Codezero Overview document, Codezero Application Development tutorial, API Reference and finally you may also join our codezero-devel mailing list, where we publicly discuss technical issues about the Codezero Microkernel.