UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

AR# 55998

PetaLinux - How do I add a script to my PetaLinux root file system that runs at startup?

Description

I have a script that I would like to include in my PetaLinux root file system to have it execute at system startup.

How do I have the PetaLinux build process incorporate this code properly?

Solution

To have the PetaLinux build tools incorporate pre-build binary code, follow this general flow:

PetaLinux 2013.04 (and prior)

  1. Ensure that the root file system includes an interpreter for your script (e.g., Perl, Python, etc.).
  2. Use the petalinux-new-app to create an application. The new application will be located in ${PETALINUX}/software/user-apps/<APP>/. The -e option for petalinux-new-app will automatically select the application from menuconfig and will allow the application to be automatically built when the PetaLinux system is built.
  3. Place the scripts into ${PETALINUX}/software/user-apps/<APP>/
  4. Modify the makefile for the new application located inside ${PETALINUX}/software/user-apps/<APP>/.
    • Ensure that the all: and clean: sections of the makefile are empty.
    • Update the romfs: section to copy the scripts into ${PETALINUX}/software/petalinux-dist/romfs/.

Below is an example of the modifications:

{{{
all:
 
clean:
romfs:
     $(ROMFSINST) -d -p 0755 mystartup /etc/init.d/mystartup
     $(ROMFSINST) -s /etc/init.d/mystartup /etc/rcS.d/S99mystartup
}}}

Note: The scripts in /etc/rcS.d/ run in alphabetical order.

PetaLinux 2013.10 (and later)

  1. Ensure that the root filesystem includes an interpreter for your script (e.g., Perl, Python, etc.).
  2. Use petalinux-create -t apps -n <APP> to create an application.  The new application will be located in <PETALINUX_PROJECT_DIR>/components/apps/<APP>/. The --enable option for petalinux-create will automatically select the application from menuconfig and will allow the application to be automatically built when the PetaLinux system is built.
  3. Place the script(s) into <PETALINUX_PROJECT_DIR>/components/apps/<APP>/
  4. Modify the makefile for the new application located inside <PETALINUX_PROJECT_DIR>/components/apps/<APP>/.
    • Ensure that the all:, build:, and clean: sections of the makefile are empty.
    • Update the install:: section to copy the scripts into <PETALINUX_PROJECT_DIR>/build/linux/roofts/targetroot/.
Below is an example of the modifications:
all: build install
build: $(APP)
clean:
.PHONY: install image
install: $(APP)
 $(TARGETINST) -d -p 0755 mystartup /etc/init.d/mystartup
 $(TARGETINST) -s /etc/init.d/mystartup /etc/rc5.d/S99mystartup
Note: The scripts in /etc/rc5.d/ run in alphabetical order.
AR# 55998
Date Created 05/14/2013
Last Updated 04/23/2014
Status Active
Type General Article
Devices
  • SoC
  • XA Zynq-7000
  • Zynq-7000
  • More
  • Zynq-7000Q
  • FPGA Device Families
  • Artix-7
  • Kintex-7
  • Spartan-6
  • Virtex-6
  • Virtex-7
  • Less
Tools
  • PetaLinux
  • PetaLinux - 2012.12
  • PetaLinux - 2013.04
  • PetaLinux - 2013.10