|
|
 |
FPGA design from scratch. Part 43
Installing a Linux OS
It has been a long and bumpy ride but now we start to see the light in the tunnel. So keep up, stay onboard, we will soon reach the final destination. We are ready for the real challenge, installing a Linux OS in our embedded system.
Why using a Linux OS
Linux use in future embedded, mobile, and real-time projects will grow 278 percent over that in past projects, suggests a recent survey by Venture Development Corp. (VDC). Meanwhile, proprietary commercial embedded operating systems are holding steady, gaining customers from do-it-yourself OS users, but losing them just as fast to Linux, the analyst firm reports.
Embedded Linux OS
The MicroBlaze procssor has one drawback, it doesn't include a Memory Management Unit (MMU). To overcome this limitation, development started early to come up with a Linux kernel that could be used on a MMU-less processor. This work lead to to the introduction of uClinux. Most of the work done in the uClinux was been incorporated into the Linux kernel development and the 2.6 Linux kernel is the first stable release with mainline support for processors, such as MicroBlaze, that do not have an MMU eliminating the need to apply and forward-port uClinux patches.
uClinux
The original uClinux was a derivative of Linux 2.0 kernel intended for microcontrollers without MMUs. However, the Linux/Microcontroller Project has grown both in brand recognition and coverage of processor architectures. Today's uClinux as an operating system includes Linux kernel releases for 2.0 2.4 and 2.6 as well as a collection of user applications, libraries and tool chains.Finding a Linux OSThis table shows some of the Linux OSes that runs on a MicroBlaze processor.
Third Party Real Time Operating Systems (RTOS) Support This table and this table shows RTOS supporting PowerPC and MicroBlaze.
Application notes
You can find a number of application notes from Xilinx describing how to install an RTOS on a MicroBlaze processor.
- Getting Started with uClinux on the MicroBlaze Processor (XAPP730)
- Getting Started with the Nucleus PLUS RTOS and EDGE Tools on the MicroBlaze Processor (XAAP1016)
Choosing a Linux OS
We will use PetaLinux from PetaLogix. PetaLogix is an embedded Linux solution provider founded by Dr John Williams, architect and maintainer of the port of the uClinux operating system to the Xilinx MicroBlaze soft processor.
PetaLinux
PetaLogix has released PetaLinux v0.20, including Linux kernel 2.6.20 support for the Xilinx MicroBlaze soft-CPU architecture. PetaLinux is available as a free download from http://developer.petalogix.com, along with complete documentation, getting started guides and reference designs. Pre-built demo packages for the Xilinx ML401, Spartan3E-500 and Spartan3E-1600 allow a instant preview of the capabilities of Embedded Linux on the MicroBlaze.The "uClinux microblaze port" mailing list
John Williams has setup a mailing list where you can ask all kind of questions about uClinux and the port to MicroBlaze. Embedded Linux developer forumuCdot is the place to find more information about embedded Linux.PetaLinux system requirements
The minimum system requirements to build a PetaLinux ready hardware platform are:
- MicroBlaze soft core processor
- Timer
- Interrupt Controller
- Standard input and output devices
- External memory controller
- RAM (DDR-SDRAM)
- ROM (Flash) optional
- Microprocessor Debug Module (for image download)
PetaLinux installation procedure
Let's read the installation guide. Download
We will start by downloading petalinux-v0.20-rc3.tar.gz. The gzipped tar file is 317MB.
Select an installation directory
Create: mkdir /home/svenand/linux and goto the installation directory: cd /home/svenand/linux and move the tar file to this directory: mv /home/svenand/Desktop/petalinux-v0.20-rc3.tar.gz .
Unpacking
Unzip and unpack the file using the following command: tar zxvf petalinux-v0.20-rc3.tar.gz
 After unpacking the following directory structure has been generated. The total size is 1.77GB
Environment setup
To set up our PetaLinux environment, change to the PetaLinux root directory and run the set up script. This script updates our path to point to the bundled gcc toolchain, and sets the $PETALINUX environment variable to point to the PetaLinux root.
-> cd petalinux-v0.20-rc3 -> source settings.sh (bash and sh) -> source setting.csh (csh and tcsh) We will add the following lines to .bashrc to make sure the script will always be run: cd /home/svenand/linux/petalinux-v0.20-rc3source /home/svenand/linux/petalinux-v0.20-rc3/settings.sh cd /home/svenand
Configure and build our Linux kernel
After we have everything setup it is time to configure and build our Linux kernel. Let's follow the PetaLinux Platform from Scratch tutorial.
Selecting a platform
Selecting a platform is the initial step in the build of a kernel for our target. A platform configuration is essentially a collection of kernel configurations that are associated with that particular platform. This process allows the user to configure for a target platform without having to go through all the configurations associated with that platform.
Create a New Vendor Platform variant
We will use the petalinux-new-platform script to create a new vendor and platform combination for our system.
-> cd $PETALINUX/software/petalinux-dist -> petalinux-new-platform -v Xilinx -p ML403 -k 2.6
The ML403 board has been added to the Xilinx directory.

PetaLinux kernel configuration
To start the configuration program execute the following commands: -> cd software/petalinux-dist -> make xconfig
 Vendor/Product Selection We select vendor Xilinx and the ML403 platform.
Kernel/Library/Defaults selection
We will use the default settings and click Save and Exit. The configuration setup is stored in the file $PETALINUX/software/petalinux-dist/.config. Later on we will change the configuration to match the hardware in our system.Hardware modification
MicroBlaze
Instruction cache : Enabled Data cache : Enabled
RS232 UART
Baudrate : 115200 Interrupt : Enable
Debug module
Enable the UART Interface on OPB: Disable Interrupt : Enable
For more information about the hadware setup read the PetaLinux Platform from Scratch tutorial. Auto configuration
PetaLinux AutoConfig framework allows the hardware configurations to be propagated to the bootloader and Linux kernel configurations. A few simple parameters in the EDK project's MSS (MicroProcessor Software Specification) file are all that is required to automatically configure the kernel and bootloader for our specific hardware platform.
Briefly, the steps are: - Create a new linux platform.
- Create a EDK hardware project
- Edit the MSS file to specifiy the PetaLinux autoconfiguration BSP tools (see below)
- Use XPS to build the hardware project and generate libraries and BSPs
- Use the petalinux-copy-autoconfig helpder script to propagate the system settings from your hardware project, across to your new Linux platform
- Rebuild PetaLinux, to get your fully configured bootloader, Linux kernel and root filesystem image, ready for download.
Editing the MSS file
See the PetaLinux User Guide AutoConfig. Let' take a look in the ETC_system.mss file. This is what the OS part looks like:
BEGIN OS PARAMETER OS_NAME = standalone PARAMETER OS_VER = 1.00.a PARAMETER PROC_INSTANCE = microblaze_0 PARAMETER STDIN = RS232_Uart PARAMETER STDOUT = RS232_Uart END
We will change it like this:
BEGIN OS PARAMETER OS_NAME = petalinux PARAMETER OS_VER = 1.00.b PARAMETER PROC_INSTANCE = microblaze_0 PARAMETER STDIN = RS232_Uart PARAMETER STDOUT = RS232_Uart PARAMETER MAIN_MEMORY = DDR_SDRAM_64Mx32 PARAMETER MAIN_MEMORY_BANK = 0 END
Generate netlist and libraries
Let's start Xilinx Platform Studio and generate a new netlist and libraries and BSPs. --> xps ETC_system.xmp &
The following error stops us from loading our project.
ERROR:MDT - Can not find MLD for the os petalinux 1.00.b INFO:MDT - Directories Searched : - /home/svenand/root/projects/ETC/xps/bsp/petalinux_v1_00_b/data - /home/svenand/cad/edk91i/sw/ThirdParty/bsp/petalinux_v1_00_b/data - /home/svenand/cad/edk91i/sw/XilinxProcessorIPLib/bsp/petalinux_v1_00_b/data - /home/svenand/cad/edk91i/sw/lib/bsp/petalinux_v1_00_b/data
To fix this problem we have to find the petalinux .mld file and copy it to the XPS project directory. The .mld file can be found here: $PETALINUX/hardware/edk_user_repository/PetaLogix/bsp/petalinux_v1_00_b/data. We will make a link to the bsp directory from our EDK project directory.
-> cd $EDK_PROJECT -> ln -s bsp $PETALINUX/hardware/edk_user_repository/PetaLogix/bsp

We use the menu command Hardware->Generate Netlist to generate a new netlist. No configuration files are generated during the netlist generation. We then generate the libraries using the menu command Software->Generate Libraries and BSPs. This process will create the following directory structure.

Here we find the auto-config.in (Linux 2.4.x) and the Kconfig.auto (Linux 2.6.x) configuration files.
Copying the AutoConfig file
To copy the configuration file across to our currently selected PetaLinux platform, we use the petalinux-copy-autoconfig command as follows: petalinux-copy-autoconfig ETC_system.xmp ==>petalinux-copy-autoconfig ETC_system.xmp INFO: Attempting vendor/platform auto-detect INFO: Auto-detected Xilinx/ML403 combination. Auto-config file successfully updated for Xilinx ML403
The script will automatically detect which platform and which Linux kernel we have specified by reading the.config file and copy the right configuration file to the right place.

Platform reconfiguration
Next we have to reconfigure the platform settings of our custom platform into PetaLinux. This step requires us to run through the following configuration options.
More to be added.
Changing the default shell
In Ubuntu 7.04 the default shell (/bin/sh) is defined as /bin/dash instead of /bin/bash. The build process script relays on the bash shell to function. To change the default shell to bash execute the following commands:
--> sudo rm -f /bin/sh --> sudo ln -s /bin/bash /bin/sh
To change back to dash execute the following commands:
--> sudo rm -f /bin/sh --> sudo ln -s /bin/dash /bin/sh
Adding the /tftpboot directory
When working with network-enabled embedded Linux systems, it is often convenient to update Linux images and other files over the TCP/IP network. The directory /tftpboot is commonly used as a transfer directory for this purpose. The PetaLinux tools can optionally copy Linux and bootloader files into this (or another) directory automatically. To create the /tftpboot directory, you must have root access.
-> sudo mkdir /tftpboot -> sudo chmod -R 777 /tftpboot
Installing zlib1g-dev
We need zlib to be able to build the Linux kernel: sudo apt-get install zlib1g-dev
Build the 2.6 kernel and user applications
The build process entails the following tasks. - Build the Linux Kernel
- Build GNU tools
- Build the Root Filesystem
- Build the U-Boot bootloader
To start the build process for the newly added platform, in the $PETALINUX/software/petalinux-dist directory execute the following commands. -> cd $PETALINUX/software/petalinux-dist
1. Build the project dependencies.-> yes "" │ make oldconfig dep
2. Build images. -> make all
The logfile
.......
Image Name: PetaLinux Kernel 2.6 Created: Sun Sep 30 17:36:28 2007 Image Type: MicroBlaze Linux Kernel Image (uncompressed) Data Size: 3289251 Bytes = 3212.16 kB = 3.14 MB Load Address: 0x44000000 Entry Point: 0x44000000 # Run mkimage to build u-boot autoscr script /home/svenand/linux/petalinux-v0.20-rc3/software/petalinux-dist/u-boot/tools/mkimage -A microblaze -O linux -T script -C none -a 0 -e 0 -n "PetaLinux Autoscr Script" -d /home/svenand/linux/petalinux-v0.20-rc3/software/petalinux-dist/u-boot/board/petalogix/microblaze-auto/ub.config /home/svenand/linux/petalinux-v0.20-rc3/software/petalinux-dist/images/ub.config.img Image Name: PetaLinux Autoscr Script Created: Sun Sep 30 17:36:29 2007 Image Type: MicroBlaze Linux Script (uncompressed) Data Size: 1412 Bytes = 1.38 kB = 0.00 MB Load Address: 0x00000000 Entry Point: 0x00000000 Contents: Image 0: 1404 Bytes = 1 kB = 0 MB # Copy image files into /tftpboot, if requested if [ "y" == 'y' ] ; then cp /home/svenand/linux/petalinux-v0.20-rc3/software/petalinux-dist/images/* "/tftpboot"; fi make[2]: Leaving directory `/home/svenand/linux/petalinux-v0.20-rc3/software/petalinux-dist/vendors/Xilinx/ML401' make[1]: Leaving directory `/home/svenand/linux/petalinux-v0.20-rc3/software/petalinux-dist/vendors' ==>
Congratulations to all of us. We made it!!!!
Output images
Once the build process is completed, all the images are located in both the $PETALINUX/software/petalinux-dist/images and the /tftpboot directory. tftpboot directory content Image Name
| Description | File Size
| Linux Kernel
| | | | image.bin | The Linux kernel and root filesystem image in binary format
| 3.1 MB
| | image.elf | The Linux kernel and root filesystem image in ELF format | 3.4 MB
| | image.srec | The Linux kernel and root filesystem image in SREC format
| 9.3 MB
| | image.ub | The Linux kernel and root filesystem image in U-Boot format | 3.1 MB
| | linux.bin | ?? | 1.9 MB
| | romfs.img | The ROMFS image in binary format
| 1.2 MB | | U-Boot | | | | u-boot.bin | The U-Boot image in binary format
| 119 KB
| | u-boot.srec | The U-Boot image in SREC format | 358 KB
| | u-boot-s.bin | The relocatable U-Boot image in binary format | 119 KB | | u-boot-s.elf | The relocatable U-Boot image in ELF format | 120 KB | | u-boot-s.rec | The relocatable U-Boot image in SREC format | 358 KB
| | ub.config.img | U-Boot platform configuration script in binary format
| 1.4 KB
| Top Next Previous
|