Search This Blog

Wednesday, October 9, 2013

Developing Linux OS for ARM - Part IV


Bootstrap is in place ------- > Yes

U-boot is in place      ------->  Yes

Now its time to build kernel image, which will take­over control of the hardware.
We would be discussing the procedure for booting the Linux operating system on board. However,  AT91SAM9260 also supports other popular operating systems like WinCE, FreeRTOS, uC/OS­II, eCOS etc. Refer to http://at91.com/  for more information on the same.

The primary site for the Linux kernel source is http://www.kernel.org.

we will download the kernel source at the following path:

 http://www.kernel.org/pub/linux/kernel/v2.6/linux-­2.6.27.tar.bz2

Download it to the following path: /Embedded_Linux_Complete/Sources/Linux_kernel/ . A copy of the source is also present in the archives under the following path:

~/Embedded_Linux_Complete/Sources/Linux_kernel

Extract the contents in the current directory.

/Embedded_Linux_Complete/Sources/Linux_kernel$ ls
linux-2.6.27   linux-2.6.27.tar.bz2



Next step would be to download the AT91 maintainers patch, which is the stable patch for AT91. This can be downloaded from:

http://maxim.org.za/AT91RM9200/2.6/2.6.27-at91.patch.gz

Download/Copy this to the following path:
/Embedded_Linux_Complete/Sources/Linux_kernel/linux­2.6.27
 
After downloading the maintainer's patch apply it on top of the Linux kernel as shown:
  
/Embedded_Linux_Complete/Sources/Linux_kernel/linux-2.6.27$ 
 zcat 2.6.27-at91.patch.gz  | patch -p1

Next you can also take the experimental patchset

ftp://www.linux4sam.org/pub/linux/2.6.27-at91/2.6.27-at91-exp.2.patch.gz

to the same location and apply it on top of the AT91 one as shown:

/Embedded_Linux_Complete/Sources/Linux_kernel/linux-2.6.27$ zcat 2.6.27-at91-exp.2.patch.gz  |  patch -p1

Now you have to configure the Linux kernel according to your hardware. First identify your kernel revision, your board and then, download the corresponding configuration file. In our case, for AT91SAM9260, the configuration file can be downloaded from

ftp://www.linux4sam.org/pub/linux/2.6.27-at91/at91sam9260ek_defconfig

Download the configuration file in

/Embedded_Linux_Complete/Sources/Linux_kernel/linux­2.6.27

Follow the below mentioned steps to configure the build process:

~/linux-2.6.27$ cp at91sam9260ek_defconfig .config

~/linux-2.6.27$ make CROSS_COMPILE=/home/sanket/Download/Embedded_Linux_Complete/Package/GNU_GCC_toolchain/arm-2007q1/bin/arm-none-linux-gnueabi- ARCH=arm oldconfig

In the above case, the default config that was stored in ~/Linux_kernel/linux­-2.6.27/arch/arm/configs will be used based on the target controller that you have specified.


In case you want to make your own customised kernel, you can configure all options individually using a menu based configuration interface. This can be done using:


~/linux-2.6.27$ make CROSS_COMPILE=/home/sanket/Download/Embedded_Linux_Complete/Package/GNU_GCC_toolchain/arm-2007q1/bin/arm-none-linux-gnueabi- ARCH=arm menuconfig

But before that, for kernel compilation and buildroot, you need to have the some software packages installed on the the host machine. The folliwing is the list of softwares required:

• GNU C/C++
• GNU make
• wget
• sed
• flex
• bison
• m4
• patch
• gettext
• libtool • texinfo
• autoconf
• automake
• ncurses library (development install)
• zlib library (development install)
• libacl library (development install)
• lzo2 library (development install)
• glib library (development install) ­ if some packages selected


On ubuntu, one can install all of these packages simultaneously in the following way:

~/linux-2.6.27$ sudo apt-get install make flex bison m4 ncurses-dev gettext texi2html texinfo zlib1g zlib1g-dev liblzo2-2 liblzo2-dev libacl1 libacl1-dev libglib2.0-dev autoconf automake libtool

Once these packages have been correctly installed , we would be able to have a menu based configuration as shown below:

~/linux-2.6.27$ make CROSS_COMPILE=/home/sanket/Download/Embedded_Linux_Complete/Package/GNU_GCC_toolchain/arm-2007q1/bin/arm-none-linux-gnueabi- ARCH=arm menuconfig

 On typing the above command you would see a menu based configuration utility

Each of the categories shown above will further have kernel modules which can be either retained or removed. Linux supports the concept of loadable kernel modules, which means that many of these kernel modules can also be dynamically loaded/unloaded after the kernel has booted on the target hardware instead of including them at compile time.

Typically, [*] or <Y> symbolises that the corresponding modules are to be retained in the kernel image at the time of compilation, [ ] or <N> symbolises that the corresponding modules are not to be included in the kernel during the compilation, while <M> symbolises that the corresponding modules will not be loaded during the compile time but the kernel will include modules that would support the dynamic loading of these modules.

There are two options available while doing this:

   1. Load a default configuration: We have a default configuration file called
at91sam9260ek_defconfig, which we can load using the “Load an Alternate
configuration file”
option.

    2. Make your own configuration: If we want to prepare a new configuration altogether, we can select the appropriate options.

Once these steps have been performed we can then save the required configuration using the “Save an Alternate configuration file” option. You will get a .config file generated within your current directory. Also, if there was a previous .config file existing within your current directory, a .config.old would be generated so that you can load it at some time in future if required again.

We will go with the default configuration file supplied to us by the AT91 maintainers. Once this is done, you can ensure that the .config file has been generated in the following way:

/linux-2.6.27$ ls -al| grep "config"

Finally , we arrive to the point where we are ready to build the kernel image:

/linux-2.6.27$ make CROSS_COMPILE=/home/sanket/Download/Embedded_Linux_Complete/Package/GNU_GCC_toolchain/arm-2007q1/bin/arm-none-linux-gnueabi- ARCH=arm

At the end of the compilation process, a zImage and Image file would be generated under the following path: /Linux_kernel/linux­2.6.27/arch/arm/boot.

U­Boot does not support normal linux kernel images like zImage or Image (arch/arm/boot/), so you have to create an uImage file with the mkimage tool which encapsulates kernel image with header information, CRC32 checksum, etc. Download mkimage using:

/linux-2.6.27$ sudo apt-get install uboot-mkimage
 
Once mkimage is available run the following command to generate an uncompressed uImage file:

/linux-2.6.27$ mkimage -A arm -O linux -C none -T kernel -a 20008000 -e 20008000 -n linux-2.6 -d arch/arm/boot/Image uImage

Once the above steps are performed you will get a uImage file generated in your current directory, which would be used as the kernel image for booting Linux on your ARM platform.

Next step would be to build a rootfs image. That we would be continuing in my next post.



continue.......




Developing Linux OS for ARM - Part III

Hello. I am back. Its really very long time to pen down where I have stop. I will continue with PART III of developing Linus OS for ARM.

As we already configure primary bootloader AR91Bootstrap in PART II. Its time to configure a secondary bootloader.

In most cases, U­Boot is the secondary bootloader, which is in charge of downloading kernel binaries from FLASH, SD/MMC, USB or ethernet and starting the kernel.

Download the secondary bootloader (U­boot). It can be downloaded
from the following link:

ftp://ftp.denx.de/pub/u-boot/


we will download the u­boot­1.3.4.tar.bz2 at the following path:

/home/sanket/Download/Embedded_Linux_Complete/Sources/u­boot.

Extract the same in the current directory.

Download u­boot patch provided by the AT91 community from the below mentioned link:

ftp://www.linux4sam.org/pub/uboot/u-boot-1.3.4-exp/u-boot-1.3.4-exp.diff

 
Creating a patch is a standard way of adding newly generated code to a large existing code base. It is created by comparing the updated code with the code base for which the patch is to be generated.

Save this to the ~/Embedded_Linux_Complete/Sources/u­boot/u­boot­1.3.4.

/u-boot-1.3.4$ ls

Apply it (patch) on top of the original u­boot in the following way:

/u-boot-1.3.4$ cat u-boot-1.3.4-exp.diff | patch -p1

Once the AT91 u­boot sources  are available, cross­compiling u­boot can be done in two steps : configuration and compiling. Note that both arm­elf­ and arm­linux­ ARM GCC cross­compiler types are suitable for u­boot building. We will use arm­none­-linux­-gnueabi­-gcc.

Here are the building steps for the AT91SAM9260EK board:

/u-boot-1.3.4$ make CROSS_COMPILE=/home/sanket/Download/Embedded_Linux_Complete/Package/GNU_GCC_toolchain/arm-2007q1/bin/arm-none-linux-gnueabi- distclean

distclean command removes the binaries and object files files that 'configure' created. Distclean is like make clean with the exception that make clean removes all the files created by make, where as distclean removes all files that are created by make config.

The U­boot can be made to reside on any of the following storage media: Data flash/NAND flash/NOR flash. In our case we are using the dataflash, but NAND flash can also be used since AT91Bootstap supports both. The AT91Bootstrap will pass the environment variables to U­boot while it tries to bring U­boot up.

So while we compile U­boot we will configure it for Dataflash.

/u-boot-1.3.4$ make CROSS_COMPILE=/home/sanket/Download/Embedded_Linux_Complete/Package/GNU_GCC_toolchain/arm-2007q1/bin/arm-none-linux-gnueabi- at91sam9260ek_dataflash_cs1_config

These environment variables includes the IP address setting of the host, the server from which U­boot would tftp to retrieve some packages and more. When U­boot is up and running on our board we will try and view all these environment variables.

NOTE: In our case, the software packages have been made to reside in the dataflash. In some cases, they might reside in NAND Flash or NOR flash. While compiling u­boot the environment variable location needs to be choosen accordingly. 

To compile u­boot after configuration,

/u-boot-1.3.4$ make CROSS_COMPILE=/home/sanket/Download/Embedded_Linux_Complete/Package/GNU_GCC_toolchain/arm-2007q1/bin/arm-none-linux-gnueabi- 

If the compilation goes well, a uboot.bin file would be generated in your current directory which would be ultimately flashed to the dataflash using a software utility called SAM­BA (Burning Application for SAM controllers).

Once the bootloader is in place, next step would be to build a kernel image. That we would be discussing in my next post.


continue................