Embedded Linux

Saturn, Microblaze and Linux – How to Run Linux on Saturn Spartan 6 FPGA Module – Part II

3085 views March 9, 2016 admin 2

microblaze_Linux

In Part I, we saw how to generate a microblaze based minimal embedded hardware platform for Saturn Spartan 6 FPGA module. Now we recommend that you create a SDK application project for this hardware platform and test it’s basic functionality by creating a “Hello world” application. Please follow the steps under the section “Creating Application program for Microblaze based Embedded Platform” in the article Creating Xilinx EDK test project for Saturn – Your first Microblaze processor based embedded design to create a SDK project. Choose “Hello world” SDK application template when generating the application. Run the application on the board to make sure that everything so far works as expected.

Assuming you were able to build the hardware platform using XPS and test it using SDK successfully, let us move on to the discussion about how to build Linux kernel. There are different ways to do this depending on how much time and effort you would like to invest. The easiest of all is to use a tool such as Buildroot or Yoctoproject. In this example, we will use Buildroot to build our kernel. Buildroot, when properly configured, can download Linux kernel source, build cross compilation tools and build the kernel itself all with a single command.

Please note that we will continue using Windows for running Xilinx tools (and of course Linux for building kernel). I have used Ubuntu 14.04 LTS 64 bit desktop version while putting together this article. We will do the following steps one by one to build the Linux Kernel.

  1. Create a Device Tree file
  2. Download/Install Buildroot and other necessary packages
  3. Create buildroot configuration
  4. Build the kernel

1. Creating Device Tree file

On many platforms, Linux kernel depends on a data structure called Device Tree to discover and configure different hardware components available on the board. Kernel uses the device tree in binary format which is generated by using device tree compiler. The input to the device tree compiler is a text file (with extension .dts) that describes all the hardware and dependencies. This file can be edited manually by hand if necessary. But fortunately, there are tools available that can help us generate device tree from our XPS/SDK projects.

To generate device tree, we will need the following files from XPS/SDK projects.

  • SaturnV3Linux.xml (can be found under the folder SDK\SDK_Export\hw inside the XPS hardware project. Exact file name may be different depending on the XPS project name you chose)
  • system.mss (can be found under the bsp project folder in Hello World SDK workspace)

Copy these two files to a common folder. Open command prompt and move to the folder where the files are copied. Edit the file system.mss and replace the contents of the section that begins with “BEGIN OS” with the following and save.

BEGIN OS
 PARAMETER OS_NAME = device-tree
 PARAMETER OS_VER = 3.10.a
 PARAMETER PROC_INSTANCE = microblaze_0
 PARAMETER CONSOLE DEVICE = ft2232_uart
END

Now download the device-tree_v2_1_0.mld and device-tree_v2_1_0.tcl files from here. Place these files under the folder bsp\device-tree_v3_10_a\data along with SaturnV3Linux.xml and system.mss. Please note that it is critical to use the exact file names and folder names mentioned here. Files should be placed exactly as below.

\SaturnV3Linux.xml
\system.mss
\bsp\device-tree_v3_10_a\data\device-tree_v2_1_0.mld
\bsp\device-tree_v3_10_a\data\device-tree_v2_1_0.tcl

Once all files are placed properly, run the following commands at the command prompt.

cmd>c:\Xilinx\14.6\ISE_DS\settings64.bat
cmd>libgen -hw SaturnV3Linux.xml -lp device-tree -pe microblaze_0 system.mss

make sure to replace 14.6 in the first command with the version of ISE you have on your machine. Run settings32.bat instead of settings64.bat if you have 32 bit system.
If everything went well, libgen should run without any errors and a new folder microblaze_0 will be created. You will see xilinx.dts under the folder microblaze_0\libsrc\device-tree_v3_10_a and this is our device tree file. rename xilinx.dts to saturn_v3.dts. At this point, we will need to make some changes to the dts file manually. Open saturn_v3.dts in your favorite text editor and replace the bootargs = “” line with the following

bootargs = "console=ttyUL0";
linux,stdout-path = "/axi@0/serial@40600000";

Make sure that the base address 40600000 in the above line matches with the base address of FT2232H UART base address in your system.

2. Download/Install Buildroot and other necessary packages

Login to your Linux workstation to download and setup buildroot. On a Ubuntu 14.04 desktop clean installation you will need to install a few packages to make Buildroot work. Run the following command to install those.

cmd>sudo apt-get install build-essential bison flex gettext libncurses5-dev texinfo autoconf automake libtool

You may need install Qt lib if you prefer to use xconfig instead of menuconfig while configuring Buildroot (please note that we will not use xconfig or menuconfig in the article rather load a default configuration that is known to be working).

Now create a convenient folder on your Linux machine and move to that folder on the command line. Download buildroot to that folder. You can download buildroot manually from Buildroot download page or by running the following command.

cmd>wget http://buildroot.uclibc.org/downloads/buildroot-2014.05.tar.gz

If you prefer to use a different buildroot release, change the file name accordingly. Extract the downloaded gzip archive by running the following command

cmd>tar -xvf buildroot-2014.05.tar.gz

All files should be extracted to the folder buildroot-2014.05.

3. Create buildroot configuration

Now download the Linux kernel defconfig for saturn V3 from here and place it under directory \board\numato\saturn_v3 (inside the folder the gzip archive extracted to). And copy the device tree file saturn_v3.dts to the same folder as well. Download buildroot defconfig numato_saturn_v3_defconfig from here and copy it to configs folder under buildroot. Please note that the kernel base address set to 0xa4000000 in the Linux kernel defconfig you have downloaded. Please change it appropriately if the LPDDR base address in your XPS project is different.

After setting up buildroot as mentioned above and execute the following commands at the Buildroot root directory.

cmd>make numato_saturn_v3_defconfig
cmd>make

The first make command will generate a .config file for Buildroot and the second make command will build the kernel. Please note that the machine should be connected to internet for this step to work since Buildroot needs to download Linux kernel sources and other tools before it can begin building the kernel. This step can take up to an hour or more depending on your machine’s speed and internet connection speed. If this step finished without errors, you will see a new file “simpleImage.saturn_v3” in the folder /output/images. This is the Linux kernel with a root file system (initramfs) attached to it. We will use this file to boot Linux on Saturn.

The next step is to try to boot the Linux kernel we just created. Please see part III of this article to see how to boot the kernel image using Xilinx XMD and Xilinx Platform cable USB. If you don’t have platform cable USB handy, you can skip part III and proceed to part IV where we will see how to create a bootable image that can be flashed directly to the SPI flash available on Saturn Spartan 6 FPGA module.

Read Part III of this article series here.

Was this helpful?

1 Comments
Leave A Comment
*
*