Entry: Zynq design from scratch. Part 41. Saturday, April 26, 2014

Petalinux board bringup

One of the great strengths of an FPGA platform is the ability to completely customise our processor system architecture, either for an off-the-shelf evaluation board, or for our own custom designs. PetaLinux SDK was created to embrace that flexibility, and includes a set of tools specifically designed to make it as easy as possible to boot a Zynq or MicroBlaze Linux platform on a new board or CPU subsystem design.

Let's build our own PetaLinux for the LED Controller design in lab2.

Documentation

We will follow the procedure described in the document PetaLinux SDK Board Bringup Guide.

Hardware platform

Hardware platforms can be created from a number of sources, such as an existing Vivado/XPS project. Regardless of how the hardware system is created and configured, there is a small number of hardware IP and software platform configuration changes required to make the hardware system Linux ready. These are described below.

  1. One Triple Timer Counter
  2. External memory controller with at least 32MB of memory
  3. UART for serial console
  4. Non-volatile memory (QSPI Flash, SD/MMC)
  5. Ethernet

Our design fulfills all these requirements.

Configure software settings and bootloader

After designing the hardware system, it is necessary to configure a PetaLinux BSP for the platform. This is required to automate the PetaLinux board bringup. We will use Xilinx SDK to setup the PetaLinux Board Support Package (BSP) and the First Stage BootLoader (FSBL).

Launching Xilinx SDK

->xsdk &



Add PetaLinux SDK repositories

To add PetaLinux SDK repository select from the top menu:

Xilinx Tools->Repositories

Click the New button and browse to the directory: /opt/PetaLinux/petalinux-v2013.10-final/components/edk_user_repository



Click OK to finish adding local repositories.

Create Zynq FSBL

See part 40 for a decription on how to add the first stage bootloader program.

Create PetaLinux BSP

We will create the BSP and configure it for U-boot and the Linux operating system.

1. Select from the top menu:

File->New->Project and select the Board Support Package wizard.



Click Next. The New Board Support Package Project window appears. Select PetaLinux as BSP OS.



Click Finish and wait for settings window to open.



Select Petalinux from the left sidebar.



Change the settings for:

  • stdout
  • stdin
  • main_memory
  • flash_memory
  • gpio
  • sdio
  • ethernet


Click OK to finish the PetaLinux BSP setup. The directories fsbl_0 and petalinux_bsp_0 have been added to our workspace.



Create a new PetaLinux platform

The next step is to create a new PetaLinux SDK software platform, ready for building a Linux system customized to our new hardware platform. The petalinux-create command is used to achieve this:

-> petalinux-create --type project --template <CPU_TYPE> --name <PROJECT_NAME>

CPU_TYPE      (zynq or microblaze)
PROJECT_NAME  (the name of the platform we are building)



This command will create a new PetaLinux project folder from a default template. Later steps customize these settings to match the hardware project created previously. Here is the result:



Configure the software platform

The final step is to customize the software platform template to precisely match our unique hardware system. This is done by copying and merging the platform configuration files generated during the hardware build phase, into the newly created software platform, as described below:

1. Navigate to appropriate directory before using the petalinux-config command. In general the XSDK BSP directory is for example: "<XSDK workspace directory>/petalinux_bsp_0/"

2. Use the petalinux-config command to import the hardware configuration.

-> cd .../workspace/petalinux_bsp_0
-> petalinux-config --get-hw-description -p <plnx-proj-root>



The -p option points to the PetaLinux project that will be updated to match the hardware platform configurations. This step may take a few minutes to complete. This is because it merges the existing platform configuration to Kernel configuration and enables the appropriated drivers in the Kernel configuration.

This tool generates the hardware configuration files, if required and copies the configuration files to the correct location in our project directory. The configuration files are stored in the directory: PetaZed/subsystem/linux/hw-description



3. Change into the PetaLinux project root:

-> cd .../PetaZed

4. Launch the top level system settings configuration menu. Change the boot device to SD card.

-> petalinux-config



5. Launch the Linux kernel configuration menu. No changes made now.

-> petalinux-config -c kernel

5. Launch the rootfs configuration menu. No changes made now.

-> petalinux-config -c rootfs


Build the system image


Run petalinux-build to build the system image:





The compilation log: build.log is stored in the build directory. The result of the build can be found in the images/linux directory.





Generate BOOT.BIN image

Use this command to generate the boot image:

-> petalinux-package --boot --fsbl <FSBL image> --fpga <FPGA bitstream> --uboot

The FSBL image file and the bitstream files can be found here:





Boot system image on the ZedBoard

We will boot from SD card.

1. Copy the files BOOT.BIN and image.ub to the SD card
2. Insert the SD card into the ZedBoard.
3. Set the jumpers to SD boot
4. Connect a terminal
5. Power up the board.

Our Linux image will boot in a few seconds.





Running the LED_Dimmer application

We can not run the bare-metal LED_Dimmer application program inside the PetaLinux OS. We have to rewrite it to use direct memory accesses. Let's find out how to do it. We will start by studying the GPIO documentation. Here is the GPIO register map:




We find the GPIO base address in the PetaZed/hw-description/xparameters.h file

#define XILINX_GPIO_BASEADDR      0x41200000

Using the peek/poke program


Using the poke command we can write to any memory/register location in the Zynq address map. We can use this command to turn on/off the LEDs and set the dimming factor.



Writing Linux device drivers

I wrote a blog entry about this subject a few years ago. It is still valid. Let's study the poke.c source code,  found in the directory: /opt/Petalinux/petalinux-v2013.10-final/components/apps to get some ideas.

Userspace access via /dev/mem

"/dev/mem" is a virtual file representing the memory map of the whole system. To access the device from user space, we can open "/dev/mem", and then use mmap() to map the device to memory, and then we can access the device by using the pointer which points to the mapped memory. Here are some of the characteristics:

  • Userspace interface to system address space
  • Accessed via mmap() system call
  • Must be root or have appropriate permissions
  • Quite a blunt tool, must be used carefully
  • Can bypass protections provided by the MMU
  • Possible to corrupt kernel, device or other processes memory

Pro

  • Very simple, no kernel module or code
  • Good for quick prototyping / IP verification
  • peek/poke utilities
  • Portable (in a very basic sense)

Con

  • No interrupt handling possible
  • No protection against simultaneous access
  • Need to know physical address of IP

OK for prototyping, not recommended for production


Rewriting LED_Dimmer.c


Here is a version of LED_Dimmer.c we can run in PetaLinux. To use it:
  1. Create a new application (LED_Dimmer) and add this program
  2. Run petalinux-config -c rootfs and add the LED_Dimmer application
  3. Build a new Linux kernel.
  4. Boot PetaLinux
  5. Execute LED_Dimmer





Top   Previous   Next


   2 comments

Anton
June 7, 2014   03:25 PM PDT
 
Thorsten,
I had exactly the same problem, this fixed it for me:
http://www.xilinx.com/support/answers/59809.htm
Thorsten
June 5, 2014   07:21 PM PDT
 
Hi, when I'm trying to create a BSP for Petalinux under Vivado 2014.1 and Petalinux 2013.10 I just get "Error generating bsp sources : Failed to generate BSP in the log files and as a message.
Any idea about this issue ?

The repository path is correctly set !

Best, Thorsten

Leave a Comment:

Name


Homepage (optional)


Comments