Porting Linux Kernel on PPC Target Boards

by Madepogu Rajendra Prasad, HCL Technologies

This paper describes the procedure for porting embedded Linux to PPC based custom boards, which means making the operating system work on unfamiliar hardware. This paper also describes the procedure for setting up the development environment on host PC, obtaining kernel source, configuring the Linux kernel, how to cross compile Linux kernel, and how to load and run linux kernel on PPC based custom boards. The resulting embedded systems are used as application-specific computers that interact with the physical world.

1. Introduction
Like most firmware projects, this project consisted of software and hardware, specifically the embedded Linux Operating System and test code that we ported to custom board, which is based on the MPC 85xx processor. Porting Linux to a new board requires several activities:

  • Determining the system’s architecture
  • Studying and identifying files to change based on the architecture
  • Making changes to the files; this includes writing the code
  • Configuring kernel source based on the board architecture
  • Creating test code and exercising the board to ensure that the embedded Linux is working properly

The kernel source tree is composed of various subdirectories depicted in Figure 1. The most important is the arch subdirectory. Looking at linux-, many architectures are represented such as x86, sun, and ppc. This paper concentrates on ppc, the PowerPC section. The kernel source tree has three major parts, the architecture independent, the architecture dependent, and the configuration. The PowerPC-architecture dependent code is under the linux- directory.

The configuration information is under the linux- The architecture independent code is at the top level, linux-, mm, net, fs, and others. Generally speaking, no changes are needed in the architecture independent code. However, (there are always some exceptions) the linux- directory may need changes. This directory contains all the code for various drivers, such as for IDE, PCI, video, and audio. The diagrams below indicate the top level directories.

1. linux- contains the architecture dependent directories.

2. linux- contains the driver code directories.

3. linux- contains all the header files for all the architectures; this paper is concerned with only the asm-ppc includes files. Note that these are not the same include files as in the standard compiler tool, which is located usually in the /usr/include directory of the root file system. These includes are specifically for the kernel code. In fact, the Makefile uses these include files.

kernel source tree with various subdirectories
Figure 1

4. linux- contains the architecture independent code for the kernel, such as fork, spinlock, and many other source files.

5. linux- contains the scripts used by the Makefiles.

6. linux- is the memory management directory.

7. linux- is the Ethernet directory.

8. linux- is the file systems directory.

1.1 The subdirectories
All the important subdirectories are discussed here:

linux- – This directory contains all the standard (that is, known board) configurations. If a board is defined here, then a generic configuration for that board can be built.

For example, to build a generic configuration for the Sandpoint board, use this command:
make sandpoint_defconfig

linux- – This is the starting directory for all the architecture dependent code for the PowerPC.

linux- – This directory has all the code for the Linux boot loader. The file, head.S is the first program called by the BIOS to begin loading the Linux OS.

linux- – After the build, this directory contains the combination Linux boot loader, kernel, and optional RAM disk. It is called zImage or zImage.initrd.

linux- – This directory contains the low level code for initializing the board. Generally, there is a source (.c) and a header (.h ) file, which contains the low level code to continue to bring up the kernel. For the Sandpoint board, these files are sandpoint.c and sandpoint.h. These are the files that have to be copied, renamed, and modified for your board (platform). linux- This directory contains header files for all the supported architectures.

During the make menuconfig phase, a soft link, asm points to the correct architecture header files. In the PowerPC case, asm -> asm-ppc.

Note: These include files are specific to the kernel and are different and are not interchangeable with the standard gcc include files normally found in /usr/include.

linux- – This is the architecture dependent code for the kernel, such as head.S, the CPU specific start up code, cputable.c, the description of all known PowerPC processors, and many other source files.

2. Building linux kernel Image

2.1 Development Environment

1. Download “tc-mtwk-lnx-e500-sp-3.4.3-1.i686.rpm ” from http://www.bitshrine.org/gpp/

2. Install “tc-mtwk-lnx-e500-sp-3.4.3-1.i686.rpm” as a root user using following command.

# rpm -i tc-mtwk-lnx-e500-sp-3.4.3-1.i686.rpm

3. The new cross compiler is now available as “/opt/mtwk/usr/local/gcc-3.4.3-glibc-2.3.3-spe/powerpc-linux-gnuspe/bin/powerpc-linux-gnuspe-gcc”

4. Add the PATH as the last line of .bashrc

# cd /root
# vi .bashrc

5. A snapshot of .bashrc file is provided below.

.bashrc file contents

# .bashrc

# User specific aliases and functions

alias rm=’rm i’
alias cp=’cp i’
alias mv=’mv i’

# Source global definitions
if [ f /etc/bashrc ]; then
. /etc/bashrc

6. run “bash” command as a root user.

2.2 Get the kernel source Tree

1. Download kernel source from kernel.org.

2. Edit the cross compilation option for powerpc target as “CROSS_COMPILE”=”powerpc-linux-gnuspe-gcc”,”ARCH”=”ppc” in the Make file.

2.3 Building kernel Image

1. Starting in the top level of the source tree, first build a configuration, then make a kernel. Every level has a Makefile. Each top level Makefile calls a lower level Make file.

2. make menuconfig ARCH=ppc to configure kernel source.

3. make

4. After successful cross ccompilationof kernel “vmlinux.gz” is available in arch/ppc/boot/images.

5. Generate PPC bootable image using mkimage available in U-boot source.

2.4 Deploying and booting kernel image on PPC based Target board

Connect serial cable from the PPC based board to the serial port of the linux host system
Figure 2
Linux host running on Fedora core 4 PPC based target board

1. Connect serial cable from the PPC based board to the serial port of the linux host system as shown in the above figure. An Ethernet connection is also established between the host and the target.

2. The kernel image generated from section 2.3 can be deployed to PPC based target board using tftp utility.

3. Make sure that tftp server on host system is properly configured and on u-boot prompt, set u-boot environment parameters as shown below

=>setenv ipaddr board_ipaddress
=>setenv serveip tftp_serverip
=>setenv gatewayip system_gatewayip
=>setenv ipaddr board_ipaddress
=>setenv serveip tftp_serverip
=>setenv gatewayip system_gatewayip

4. The kernel image for the PPC based board is available on the host system and copies this image to “tftpboot” directory on the host system. The kernel image can be flashed to the PPC based board by following the steps below at boot prompt

=> tftp 2000000 kernelimage
=> erase <kernelimage loacation> <kernelimagelocation +1ffff>
=> cp.b 2000000 <kernelimage loacation> <kernelimagelocation +1ffff>
=> protect on <kernelimage loacation> <kernelimagelocation +1ffff>

5. For booting the PPC based board, execute the “boot” command on U-boot prompt

NOTE: This paper does not focus on u-boot and rams disk image development and assumes that PPC based board already contains u-boot (boot loader) and ram disk (file system) images.

3. Conclusion
That’s pretty much it. Porting linux operating system to a new hardware board doesn’t need to be hard. With a firm plan porting just got a lot easier.

4. References

[1] Craig Hollabaugh: “Embedded Linux: Hardware, Software, and Interfacing”, Paperback: 432 pages ;Addison Wesley Professional; (March 7, 2002); ISBN 0672322269

[2] Karim Yaghmour: “Building Embedded Linux Systems”, Paperback: 400 pages, O’Reilly & Associates; (May 2003); ISBN 059600222X – IMHO

[3] Introduction to Assembly on the PowerPC

[4] DENX Embedded Linux Development Kit