Top Banner
Lab 2: Build and Boot an Image Acknowledgements This module is derived from the Xilinx University Program course: Embedded Linux on Xilinx Micorblaze given at Simon Fraser University in April 2011. Many thanks to Xilinx, and PetaLogix for allowing us to use and modify their material. Introduction The most basic skill required for developing with embedded Linux is working in the cross-compilation environment: compiling the kernel, libraries and applications and downloading the resulting images onto the embedded target. The purpose of this lab is to familiarize you with this process. This lab will load the MicroBlaze™ processor Linux system in QEMU. QEMU is a generic and open-source machine emulator, integrated into PetaLinux SDK. In this lab, you will use QEMU to run the Linux built for the MicroBlaze processor system. It can achieve near native performance by executing the guest code directly on the host CPU. This lab will prepare you for the most basic task of working with embedded Linux—how to build and boot the operating system and applications. Small embedded Linux targets, such as the MicroBlaze processor, are usually developed in a cross-compilation environment. This means that the kernel and applications are compiled on a development machine (in this case, a Linux PC), and then downloaded onto the target. The PetaLinux distribution contains a number of tools and a configuration architecture that automates much of this process. In this lab, you will learn how to use these tools and how to download the resulting embedded Linux image onto the hardware platform. Objectives After completing this lab, you will be able to: Explore the Linux configuration menus, including how to configure a default Linux kernel and user environment Build the MicroBlaze processor Linux kernel and applications Boot the resulting system image in QEMU Download the resulting system image to the development board Typographic Conventions Commands to be executed on the development (desktop) workstation look like the following: [host]$ command and parameters Commands to be executed on the MicroBlaze processor Linux target look like the following: # run my Linux application
9
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lab2

Lab 2: Build and Boot an Image

Acknowledgements This module is derived from the Xilinx University Program course: Embedded Linux on Xilinx Micorblaze given at Simon Fraser University in April 2011. Many thanks to Xilinx, and PetaLogix for allowing us to use and modify their material.

Introduction The most basic skill required for developing with embedded Linux is working in the cross-compilation environment: compiling the kernel, libraries and applications and downloading the resulting images onto the embedded target. The purpose of this lab is to familiarize you with this process. This lab will load the MicroBlaze™ processor Linux system in QEMU. QEMU is a generic and open-source machine emulator, integrated into PetaLinux SDK. In this lab, you will use QEMU to run the Linux built for the MicroBlaze processor system. It can achieve near native performance by executing the guest code directly on the host CPU. This lab will prepare you for the most basic task of working with embedded Linux—how to build and boot the operating system and applications. Small embedded Linux targets, such as the MicroBlaze processor, are usually developed in a cross-compilation environment. This means that the kernel and applications are compiled on a development machine (in this case, a Linux PC), and then downloaded onto the target. The PetaLinux distribution contains a number of tools and a configuration architecture that automates much of this process. In this lab, you will learn how to use these tools and how to download the resulting embedded Linux image onto the hardware platform.

Objectives After completing this lab, you will be able to:

• Explore the Linux configuration menus, including how to configure a default Linux kernel and user environment

• Build the MicroBlaze processor Linux kernel and applications

• Boot the resulting system image in QEMU

• Download the resulting system image to the development board

Typographic Conventions Commands to be executed on the development (desktop) workstation look like the following:

[host]$ command and parameters

Commands to be executed on the MicroBlaze processor Linux target look like the following:

# run my Linux application

Page 2: Lab2

Preparation Before we can build and boot an image we need to set up the environment variables Start by opening a new terminal. Change directories to the main petalinux directory:

[host] $ cd ~/petalinux-v2.1-final-full

HINT: Bash will auto complete names for you. Simply start typing the name and push tab. If it doesn’t auto complete it either means that the name doesn’t exist in that directory, or there are multiple options. Push tab again to list the other options. HINT: The tilde symbol (~) is a shortcut to your home directory. In this case it is exactly the same as typing /home/student. You can see this by typing pwd, which will print your current working directory. List and examine the contents of this directory:

[host] $ ls

Notice the Shell script settings.sh. Running this script will add the petalinux directories to the PATH and allow us to run the petalinux tools. (Note: this needs to be done every time you open a new terminal window.)

[host] $ source settings.sh

Now set up the hardware as shown in figure 1, and power on the board.

Page 3: Lab2

Figure 1 Atlys FPGA Board

Warning: Be extremely gentle with the Micro USB ports. They are fragile!

Building the Linux Image Step 1 1-1. Build a Linux image for the platform Atlys Board. 1-1-1. Make everything by executing the following command in the

~/petalinux-v2.1-final-full/software/petalinux-dist directory by executing:

[host] $ make

This may take a few minutes. During this time, the following are occurring: o Cross-compiling and linking the Linux kernel (linux-2.6.x/*)

o Cross-compiling and linking the default user libs and applications (lib/* and user/*)

o Building a local copy of the MicroBlaze Linux root file system (romfs/*)

o Assembling the kernel and root file system into a single downloadable binary image file (images/*)

o Copying the image files in from images/ to /tftpboot.

The compilation log is saved in the build.log file. The console shows the compilation progress.

Page 4: Lab2

For example:

[host] $ make

[INFO ] Building ucfront tool

[INFO ] Building kernel

[INFO ] Building kernel modules

[00:04] /

1-1-2. Once compilation completes, look in the images subdirectory by executing:

[host] $ ls -al images

Example output:

total 147288

9472 image.elf

9468 image-s.bin

9472 image-s.elf

28360 image.srec

28380 image-s.srec

9468 image.ub

9464 linux.bin

32808 pflash.bin

6836 rootfs.cpio

572 System.map

244 u-boot.bin

832 u-boot.elf

244 u-boot-s.bin

244 u-boot-s.elf

712 u-boot.srec

712 u-boot-s.srec

You can see the various components that constitute the final image – linux.bin and rootfs.cpio. 1-1-3. Examine the contents of the /tftpboot directory by executing:

[host] $ ls /tftpboot

All the image files in the ~/petalinux-v2.1-final-full/software/petalinux-dist/images directory have a copy in /tftpboot, because as part of the build process, the image files have also been copied there. The development machine has been configured as a TFTP (trivial FTP) server, allowing the board to pull new kernel images directly over the network. You will use this capability in the next exercise.

Page 5: Lab2

Booting the System Step 2 2-1. As mentioned earlier, you can run Linux for the MicroBlaze processor system on

QEMU.

Load the MicroBlaze processor Linux on QEMU. 2-1-1. Run the following command to load the latest built Linux in QEMU:

[host] $ touch ~/petalinux-v2.1-final-full/software/petalinux-

dist/images/pflash.bin

[host] $ petalinux-qemu-boot

The touch command allows you to ensure that the pflash.bin file exists in the ~/petalinux/software/petalinux-dist/images directory. The pflash.bin file is needed by the QEMU to treat as a Flash. By default, the tool loads the petalinux-dist/images/image.elf in QEMU. You can get more options of the tool by using the ―--helpǁ argument. You should see the Linux boot messages that are similar to what you have seen in Lab 1.1 on the console, which is running QEMU. The boot procedure message shows when the Linux is built.

Page 6: Lab2

Linux version 2.6.31.12 (petalinux@petalinux) (gcc version 4.1.2) #4

Thu Nov 4 05:47:07 UTC 2010

2-1-2. When prompted, login as “root”, using password “root” (no quotes) If you miss out some of the boot log, you can login as “root” with password “root”, then enter reboot to soft reboot the board.

# reboot

2-1-2. Exit QEMU by pressing <Ctrl-A> then press <X>.

2-2. Boot the new Linux image on the board. An FPGA can be thought of as a sea of reconfigurable logic, that must be programmed in order to do anything useful. We can accomplish this using the Xilinx Impact program to download a bit stream (.bit file). It should be noted that the SRAM cells that are being programmed inside the FPGA are volatile, and will need to be reprogrammed every time the board is turned off, or a new kernel image is about to be downloaded. 2-2-1. Source the Xilinx tools

[host] $ source /Xilinx/13.2/ISE_DS/settings32.sh

2-2-2. Open Impact

[host] $ impact &

HINT: In a Bash shell the ampersand is used to ‘fork’ a process. This allows the process to run, and allow you to continue to type in new commands to the shell. This is particularly useful with applications that have GUIs.

2-2-3. In the New iMPACT Project window, select the create new project (.ipf) option, and click Ok.

Page 7: Lab2

2-2-4. In the Auto Assign Configuration File Query Dialog window click Yes. 2-2-5. In the welcome to iMPACT window select Configure devices using Boundary-Scan (JTAG) and click Ok.

Page 8: Lab2

2-2-6. In the Auto Assign Configuration Files Query Dialog window click Ok. Browse to the impact_petalinux directory, and select the download.bit file and click Open. 2-2-7. In the Attach SPI or BPI PROM window click No. 2-2-8. In the Device Programming Properties – Device 1 Programming Properties window click Ok. 2-2-9. Right click on the green square labelled XC6SLX45 download.bit. This square represents the FPGA, and the file you have assigned to download to it. Click Program. After a few seconds a blue bar saying Programming Succeeded will appear.

2-3. Boot the new Linux image on the board. 2-3-1. Connect to kermit in a new terminal window. The ouput from the kermit is the Linux running on the real hardware while the QEMU is a simulator which is running on the host to simulate the MicroBlaze system.

[host] $ kermit –y ~/.kermrc

kermit> connect

2-3-2. Run the following commands:

[host] $ cd ~/petalinux-v2.1-final-full/software/petalinux-dist

[host] $ petalinux-jtag-boot

Page 9: Lab2

By default, the petalinux-jtag-boot command will use the latest built Linux image in the PetaLinux tree. Use ―--

helpǁ argument so see more details of all the options of the tool.

The petalinux-jtag-boot uses Xilinx JTAG to load the image. It will take a few minutes. Be patient until it

finishes.

2-3-3. Watch the booting messages on the kermit window. A message similar to the following is displayed when the image is built.

## Booting kernel from Legacy Image at 48002000 ...

Image Name: PetaLinux Kernel 2.6-MMU

Image Type: MicroBlaze Linux Kernel Image (uncompressed)

Data Size: 9801732 Bytes = 9.4 MB

Load Address: 48000000

Entry Point: 48000000

Verifying Checksum ... OK

Loading Kernel Image ... OK

OK

## Transferring control to Linux (at address 48000000), 0x48000000

ramdisk 0x00000000, FDT 0x00000000...

Ramdisk addr 0x00000003, Compiled-in FDT at 0xc01fb610

Linux version 2.6.31.12 (petalinux@petalinux) (gcc version 4.1.2) #4

Thu Nov 22 05:47:07 UTC 2010

setup_cpuinfo: initialising 2-3-3 Do not turn off the board, and continue on to Lab 2.