An introductory overview for CUBICS software team
Written by Devin Headrick, 2023
Reproduced by Ben Tam
Last Updated Oct 10, 2023
The best way to understand how the Petalinux embedded linux OS is built, is to do it yourself! Follow Steven Knudsens well documented steps, using Xilinx Vitis/Vivado software, without the need for any hardware until the last step. Tutorial:
https://github.com/StevenKnudsen/PetaLinux2022.2_Zybo_example/tree/main/docs/PetaLinux
Firstly proprietary Xilinx Vivado software suite must be installed. This software handles the synthesis and analysis of hardware description language (HDL) designs, with features such as system on chip (SoC) development and high level synthesis (HLS).
Then you must download and install PetaLinux tools. This offers everything necessary to build, customize, and deploy embedded linux solutions for devices that use AMD processing systems (Such as the Zybo Z7 hosting the Zynq 7000 series SoC). It provides CLI, App/Device Driver/Lib generators and development templates, as well as a Bootable system image builder, debug agents, GCC tools, and Integrated QEMU system simulator.
To get linux up and running on the Zybo there are three main steps:
- Prepare the CLI
- Create a base project that defines the FPGA entities that are accessible from the linux environment. [configure the ‘hardware’ ]
- Create the linux bootloader and install on the target zybo
For the Zybo Z7 we require the latest board definitions from Digilent, which can be retrieved from cloning the Digilent vivado-board repo , and copying the require Vivado_init.tcl file to the .Xilinx/Vivado directory (used for config, often found in the users home dir).
The associated Zybo Z7 BSP (Board Support Package) must be installed. A Board support package is used to startup and run an embedded target processor, has a bootloader, and contains drivers that enable peripherals to communicate with the OS.
By this point a hardware description of our system must have been exported by Vivado as a proprietary AMD file type .xsa (hardware design file).
The petalinux-config tool is passed a .xsa file (which is a hardware description of our system generated by Vivado), and then a config menu pops up that allows you to configure the OS settings.
The Xilinx Vivado software is used to create an RTL (Register Transfer Level) project within which the FPGA inside the Zynq 7000 SoC is configured using VHDL. This is how the GPIO and led interfaces are configured.
The petalinux image needs to be packaged before we can transfer it to an SD card
Three following items are needed on a separate Fat32 partition
- BOOT.bin: binary executed when system first starts up. Includes FSBL, which handles initial configuration of hardware, and loads SSBL (U-Boot), as well as the bitstream for configuring the fpga in a zynq system
- Boot.scr: Not sure
- Image.ub: Not sure
Root file system goes on an ext4 partition (this is our disk)
Creating a petalinux project using petalinux-create -t project -in MyProject will create a new directory with the name MyProject :
- What happens when we create a petalinux project: (called MyProject in Development folder)
- Creates following directories, inside a
MyProjectparent directory- Project-spec : Contains specifications and configurations for the project. Includes
- Hw-description: Stores hardware description file (
.xsa) containing information about the hardware part of the projects design. - Meta-user: Can add or modify yocto recipes here. Typically used for adding new applications, libraries, or modifying existing ones.
- Clonfig: contains configurations for project, including for device tree source (dts), rootfs, and kernel.
- Hw-description: Stores hardware description file (
- Build: Dir used by the petalinux build system - actual compilation and construction of linux system takes place when you run
petalinux-build. Organized into several sub directories, with one for each major system component.- Kernel
- U-boot
- Rootfs
- Components: Contains source code for various components of linux system, like the kernel, uboot, and rootfs. These components are fetched and compiled when building.
- Images: final output images of the build process are placed here. This includes kernel image, rootfs, device tree blob, and related files.
- The BOOT.bin, and image.ub files are typically what get copied over to an SD card or other boot media to boot the system.
- Project-spec : Contains specifications and configurations for the project. Includes
- Creates following directories, inside a
- Kernel - Linux kernel is the core of the linux OS. Interfaces between hardware and software applications. Manages system resources, allocates processor time, manages memory, handles interrupts, and controls peripherals.
- Root fs - Constitutes the file system hierarchy on a linux system, starting from root directory
/. Contains all the files and directories used to boot the system and run applications. Includes system binaries, libraries, user data, config files etc. - (Das) U-boot - Widely used, open source bootloader. Bootloader is the first piece of code that runs when the system is powered on. Initializes hardware, loads kernel into memory, and transfers control to the kernel.
- Power on or reset triggers the system's ROM code. This initializes critical hardware and starts the bootloader (U-boot).
- U-boot initializes additional hardware, if necessary, then finds and loads the linux kernel image into memory, and starts the kernel.
- Kernel initializes the rest of the system's hardware, mounts the root file system, then starts the init process (the first user space process), from the rootfs.
- Init process runs startup scripts and starts services and applications, according to the systems init configuration.
QEMU - quick emulator, is an open source emulator, which is the main component of the KVM (Kernel-based Virtual Machine) hypervisor (accelerator). Qemu’s tiny code generator (TCG) provides the ability to emulate a number of CPU architectures on various supported host platforms.
These are the steps I had to take to set up the Petalinux image to run on a qemu virtual machine.
Note I am using Ubuntu 22.04.1 LTS on my dell laptop, and these steps may be different for different host OS or hardware:
NOTE: You must have ‘sourced’ the settings.sh file found in the /Petalinux directory created in Stevens tutorial, in order to run petalinux-*** type commands
- Follow Steven Knudsens tutorial and create a Petalinux OS project, and associated OS files.
- Run the following command, to create a WIC file, which is a special file that allows simple deployment of petalinux images by including the required boot, rootfs, and related image partitions into one file:
petalinux-package --wic -o ./pre-built/images/linux
- Now run the following command to use the previously generated WIC file to run the petalinux OS on your device, using QEMU:
petalinux-boot –qemu –prebuilt 3
NOTE: To terminate the QEMU emulator in your terminal , press CTRL+a, then x , on your keyboard. NOT ctrl+c
To ssh into your virtual instance of Petalinx on QEMU, use the following command with associated ‘qemu-args’ to setup a virtual network device provided by the guest, and to setup a network backend with the emulated NIC:
petalinux-boot --qemu --prebuilt 3 --qemu-args "-net nic -net user hostfwd=tcp::2222-:22"
You can then SSH into the virtualized petalinux OS using the following command:
ssh -p 2222 petalinux@localhost
Our linux distro uses a RPM (redhat) package manager.