Skip to content

Instantly share code, notes, and snippets.

@imrickysu
Last active July 13, 2018 11:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imrickysu/8c9bb9a0a0c40f24d718 to your computer and use it in GitHub Desktop.
Save imrickysu/8c9bb9a0a0c40f24d718 to your computer and use it in GitHub Desktop.
The instructions of creating an AMP example design with PetaLinux tools

Xapp1078 Instructions for Vivado 2014.4

NOTE: The zedBoard flow has not been verified

Note: This xapp requires using a Linux host to compile the embedded Linux kernel. The instructions have been setup such that all implementation work will be done in a directory called xapp1078_2014.4/design and all linux work will be done in a directory called xapp1078_2014.4/plnx-project. The instructions will require files to be copied between xapp1078_2014.4/design and xapp1078_2014.4/plnx-project so if the Vivado and SDK tools are ran on a Windows machine, the files will need to be copied from the Windows xapp1078_2014.4/design to the Linux machine's xapp1078_2014.4/plnx-project.

  • Create a new directory 'xapp1078_2014.4' where the design will be placed
  • Extract xapp1078_2014.4.zip into <xapp1078_2014.4>
  • Create a new work directory, <xapp1078_2014.4>/design/work
  • Copy the directory <xapp1078_2014.4>/design/src/bootgen to <xapp1078_2014.4>/design/work/bootgen
  • Open Vivado 2014.4
  • In the Tcl command window, cd <xapp1078_2014.4>/design/work
  • Create, build, and export the hdwr design to SDK by running the included script using tcl:
    • For the ZC702 design, run the tcl command source ../src/scripts/create_proj_702.tcl
    • For the ZC706 design, run the tcl command source ../src/scripts/create_proj_706.tcl
    • For the MicroZed design, run the tcl command source ../src/scripts/create_proj_microZed.tcl
    • For the ZedBoard design, run the tcl command source ../src/scripts/create_proj_zedBoard.tcl
    • Note: the updated board files from Avnet are included as a local repository within this project

Review the create_proj_706.tcl file.

This script does the following:

  • Create a new project
  • Set the properties of the project such as part used and board used
  • Set Vivado to use the included I.P. repository in <xapp1078_2014.4>/src/pcores. This repository includes the custom IP that can create interrupts towards the PS using either a register or chipscope VIO
  • Create the IPI design using the tcl script <xapp1078_2014.4>/src/scripts/create_bd_706.tcl. This script was originally created after creating the IPI design manually, and then issuing the command write_bd_tcl ../src/scripts/create_bd_706.tcl'
  • validate and save the IPI design
  • Create the top level HDL wrapper and add it to the project. (Same as navigating to 'Project Manager', right clicking on design_1.bd, and selecting 'Create HDL Wrapper')
  • Create bitstream. This command will recognize that the design hasn't been implemented yet and will run 'generate files' on design_1.bd, synthesis, implementation, and bitstream generation.
  • Exports the hdf file to SDK and launch SDK. The hdf file contains system information, PS startup information, and bitfile information

When the script finishes running it will open SDK. In the SDK workspace a hardware platform project is created automatically.

app_cpu1.elf creation

Setup SDK to use the included <xapp1078_2014.4>/design/src/sdk_repo. This repository includes a modified standalone BSP.

Note: The standalone v4.2 BSP was modified as follows:

  • armcc/_sys_write.c, gcc/write.c, printc, xil_printf.c
    • These changes add a new define 'STDOUT_REDIR' that prevents the removal of calls to outbyte() if STDOUT_BASEADDRESS is not defined
  • armcc/bootS, gcc/boot.S: These changes remove remapping of virtual address 0x20000000 to physical address 0x00000000, configures address 0x00000000-0x2fffffff to be unavailable, and disables sharing and L2 cache on address 0x30000000-0x3fffffff. The startup code was also modified to allow redirecting cpu0 or cpu1 to a different starting address (This redirecting ability is not used for xapp1078).
  • xtime_l.c: The change to this file prevents re-initializing the global timer.
  • asm_vectors.S: Two extra vectors are added at the end of the vector table and are used by the boot.S
    • redirecting code. (This redirecting ability is not used for xapp1078).
    • select Xilinx_Tools->Repositories
    • Beside the Local Repositories window, select New
    • Browse to and select <xapp1078_2014.4>/design/src/sdk_repo, select OK
    • Select OK
  • Create the BSP for CPU1
    • Select File->New->Board_Support_Package
    • Enter the project name 'app_cpu1_bsp'
    • Change CPU to ps7_cortexa9_1.
    • Notice that Board Support Package OS defaults to standalone and the description starts with 'Modified Standalone based on ....' This description lets you know that the modified BSP is used from the local repository that was configured.
    • Select Finish
    • In the 'Board Support Package Settings' Select Overview->standalone and change stdin and stdout to None
    • Select Overview->drivers->ps7_cortexa9_1 and change the extra_compiler_flags value to contain '-g -DUSE_AMP=1 -DSTDOUT_REDIR=1'
    • Select OK
  • Create the Application that will run on CPU1
    • Select File->New->Application_Project
    • Enter the project name 'app_cpu1'
    • Change Processor to ps7_cortexa9_1
    • Change 'Board Support Package' to 'Use existing' 'app_cpu1_bsp' and select Next
    • Select the template 'Empty Application' then select Finish.
    • Import the C and linkerscript file for app_cpu1 by navigating to SDK Project Explorer and right clicking on app_cpu1/src and select 'Import'
    • Select General->File_System then select Next
    • In the 'From directory', browse to and select <xapp1078_2014.4>/design/src/apps/app_cpu1
    • In the right window, select all .c, .h and lscript.ld then select Finish. Answer Yes to overwrite lscript.ld
    • Note: instead of using Import, the files could be dragged from MS Windows File Explorer to the SDK Project Explorer app_cpu1/src directory. Select 'Copy files' when prompted and 'Yes' to overwrite lscript.ld

Create, configure & build Petalinux Project

Create PetaLinux project

On a linux host machine that includes the Petalinux 2014.4 build environment, create the directory <xapp1078_2014.4>

  • cd <xapp1078_2014.4>
  • source </opt/petalinux-v2014.4-final>/settings.sh
    • This command will setup the Petalinux environment. If Petalinux is not installed in the directory /opt/petalinux-v2014.4-final, then replace this part of the path with the location of your petalinux install
  • petalinux-create -t project -n plnx-project
    • This command creates a new petalinux project named plnx-project in the current directory
  • cd plnx-project
  • mkdir ../hwdef
    • Create a directory that will contain the Vivado exported hdf file
  • cp <xapp1078_2014.4>/design/work/project_1/project_1.sdk/design_1_wrapper.hdf ../hwdef
    • This command copies the Vivado exported hdf file
  • petalinux-config --get-hw-description=../hwdef
    • This command configures petalinux to point to the directory that contains the hdf file
    • A dts file is created in subsystems/linux/configs/device-tree. This dts file can be modified
  • When the Linux System Configuration window appears:
    • select Kernel Bootargs
    • Deselect 'generate boot args automatically' by pressing 'n'
    • Select 'user set kernel bootargs' and press enter
    • Enter the following: console=ttyPS0,115200 earlyprintk maxcpus=1 mem=768M
    • Select Ok
    • Select Exit
    • Select Exit
    • Select Yes
      • Saves the new configuration

Create softuart app

  • petalinux-create -t apps --template c --name softuart
    • Create a new application template for the linux softuart function
  • cp <xapp1078_2014.4>/design/src/apps/softUart/softuart.c components/apps/softuart/softuart.c
    • Replace the petalinux project's templated softuart.c with the src that was included in the xapp
  • petalinux-config -c rootfs
    • Configure the petalinux project to include softuart on the rootfs and optionally enable Dropbear for ssh access to the board. Once the Linux/rootfs configuration window appears:
      //Add softuart app to filesystem
        Select apps
        Select softuart and press 'y'
        Select Exit
      //*OPTIONAL* Enable Dropbear for ssh
        Select Filesystem Packages
        Select console/network
        Select dropbear
        Select dropbear and press 'y'
        Select Exit
        Select Exit
        Select Exit
    Select Exit
    Select Yes
      Saves the new configuration

Modify device tree

Add one of the following sections to the end of subsystems/linux/configs/device-tree/system-top.dts This action will add peripherals that are external to the FPGA and it will disable the driver for the PL330 dma controller. Currently, there is a problem in the PL330 driver that causes cpu1 to randomly run code when maxcpu=1.

/* *********************************
 * zc702 Board peripherals
 * *********************************
 */
&dmac_s {
			status = "disabled";
};

&i2c0 {
	#address-cells = <1>;
	#size-cells = <0>;
	i2cswitch@74 {
		compatible = "nxp,pca9548";
		#address-cells = <1>;
		#size-cells = <0>;
		reg = <0x74>;
		i2c@0 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <0>;
			si570: clock-generator@5d {
				#clock-cells = <0>;
				compatible = "silabs,si570";
				temperature-stability = <50>;
				reg = <0x5d>;
				factory-fout = <156250000>;
				clock-frequency = <148500000>;
			};
		};

		i2c@2 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <2>;
			eeprom@54 {
				compatible = "at,24c08";
				reg = <0x54>;
			};
		};

		i2c@3 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <3>;
			gpio@21 {
				compatible = "ti,tca6416";
				reg = <0x21>;
				gpio-controller;
				#gpio-cells = <2>;
			};
		};

		i2c@4 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <4>;
			rtc@54 {
				compatible = "nxp,pcf8563";
				reg = <0x51>;
			};
		};

		i2c@7 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <7>;
			hwmon@52 {
				compatible = "ti,ucd9248";
				reg = <52>;
			};
			hwmon@53 {
				compatible = "ti,ucd9248";
				reg = <53>;
			};
			hwmon@54 {
				compatible = "ti,ucd9248";
				reg = <54>;
			};
		};
	};
};

&qspi {
	flash0: flash@0 {
		compatible = "micron,n25q128a13";
	};
};

&gem0 {
	phy-handle = <&phy0>;
	ps7_ethernet_0_mdio: mdio {
		phy0: phy@7 {
			compatible = "marvell,88e1116r";
			device_type = "ethernet-phy";
			reg = <7>;
		};
	};
};
/* *********************************
 * zc706 Board peripherals
 * *********************************
 */
&dmac_s {
			status = "disabled";
};

&i2c0 {
	#address-cells = <1>;
	#size-cells = <0>;
	i2cswitch@74 {
		compatible = "nxp,pca9548";
		#address-cells = <1>;
		#size-cells = <0>;
		reg = <0x74>;

		i2c@0 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <0>;
			si570: clock-generator@5d {
				#clock-cells = <0>;
				compatible = "silabs,si570";
				temperature-stability = <50>;
				reg = <0x5d>;
				factory-fout = <156250000>;
				clock-frequency = <148500000>;
			};
		};

		i2c@2 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <2>;
			eeprom@54 {
				compatible = "at,24c08";
				reg = <0x54>;
			};
		};

		i2c@3 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <3>;
			gpio@21 {
				compatible = "ti,tca6416";
				reg = <0x21>;
				gpio-controller;
				#gpio-cells = <2>;
			};
		};

		i2c@4 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <4>;
			rtc@51 {
				compatible = "nxp,pcf8563";
				reg = <0x51>;
			};
		};


		i2c@7 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <7>;
			ucd90120@65 {
				compatible = "ti,ucd90120";
				reg = <0x65>;
			};
		};
	};
};

&qspi {
	flash0: flash@0 {
		compatible = "micron,n25q128a13";
	};
};

&gem0 {
	phy-handle = <&phy0>;
	ps7_ethernet_0_mdio: mdio {
		phy0: phy@7 {
			compatible = "marvell,88e1116r";
			device_type = "ethernet-phy";
			reg = <7>;
		};
	};
};
/* *********************************
 * microZed Board peripherals
 * *********************************
 */
&dmac_s {
			status = "disabled";
};

&gem0 {
	phy-handle = <&phy0>;
  phy-mode = "rgmii-id";
	ps7_ethernet_0_mdio: mdio {
		#address-cells = <1>;
		#size-cells = <0>;
		phy0: phy@0 {
			compatible = "marvell,88e1510";
			device_type = "ethernet-phy";
			reg = <0>;
      marvell,reg-init = <3 16 0xff00 0x1e 3 17 0xfff0 0x00>;
		} ;
	} ;
};

&flash0 {
	compatible = "spansion,s25fl128s1";
};


/* *********************************
 * zedBoard Board peripherals
 * *********************************
 */
&dmac_s {
			status = "disabled";
};

&gem0 {
	phy-handle = <&phy0>;
	ps7_ethernet_0_mdio: mdio {
		#address-cells = <1>;
		#size-cells = <0>;
		phy0: phy@0 {
			compatible = "marvell,88e1510";
			device_type = "ethernet-phy";
			reg = <0>;
		} ;
	} ;
};

&flash0 {
	compatible = "spansion,s25fl256s1";
};

&usb0 {
	dr_mode = "otg";
} ;

Build Project

  • petalinux-build
    • Builds the petalinux project.
    • Log is at build/build.log
    • Generated output files are in images/linux
    • Compiled softuart app is found in build/linux/rootfs/apps/softuart
    • The built image.ub is a FIT format and contains: linux kernel, ramdisk, and device tree

Create the bootable file for the SD card

  • cp images/linux/zynq_fsbl.elf <xapp1078_2014.4>/design/work/bootgen

  • cp images/linux/u-boot.elf <xapp1078_2014.4>/design/work/bootgen

  • Within SDK, select Xilinx_tools->launch_shell

    • A new command shell is started with an environment pointing to the SDK and Vivado tools
    • cd ..\..\bootgen
    • createBoot.bat
      • This batch file runs bootgen and uses bootimage.bif for input. The bif is used to package the fsbl, u-boot, cpu1 app, and fpga bit file into boot.bin
  • Copy the boot and embedded Linux files to the SD card

    • cp <xapp1078_2014.4>/design/work/bootgen/BOOT.BIN <SD card>
    • cp <xapp1078_2014.4>/plnx-project/images/linux/image.ub <SD card>

Optional

Create non-FIT formated file

The petalinux build creates a FIT formated file image.ub. This file contains the kernel, root filesystem, and the devicetree. The following optional commands seperates the devicetree and creates a uImage file that contains the kernel and root filesystem. This flow can be handy when working with multiple devicetrees.

The following command will remove the devicetree and create uImage

./build/linux/u-boot/u-boot-plnx/tools/mkimage \
  -A arm -O linux -T kernel -C none \
  -a 0x8000 -e 0x8000 \
  -n 'PetaLinux' \
  -d images/linux/zImage \
  images/linux/uImage

Convert the binary devicetree.dtb that was created by petalinux-build to a human readable dts file:

dtc -I dtb -O dts -o images/linux/system.dts images/linux/system.dtb

cp images/linux/system.dts images/linux/system1.dts

Edit images/linux/system1.dts and make customizations, then save:

Recompile the new system1.dts to system1.dtb dtc -I dts -O dtb -o images/linux/system1.dtb images/linux/system1.dts

Copy uImage and the devicetree to the SD card. (image.ub could be removed from the SD)

  • cp <xapp1078_2014.4>/plnx-project/images/linux/system1.dtb <SD card>
  • cp <xapp1078_2014.4>/plnx-project/images/linux/uImage <SD card>

In order to boot using the uImage and system1.dtb files, the uboot environment needs to be changed to use uImage and system1.dtb instead of the original FIT image.ub file. This change only needs to be done once since the uboot environment is saved in QSPI flash.

Configure the board to boot from SD, apply power, and start a terminal emulator (115200 baud). Hit any key to stop autoboot.

Issue the following uboot commands to configure the uboot environment:

U-Boot-PetaLinux> env default -a	  # resets environment
U-Boot-PetaLinux> setenv sdboot_devtree "echo boot Petalinux; mmcinfo && fatload mmc 0 0x01000000 uImage && fatload mmc 0 0x03800000 system1.dtb && bootm 0x01000000 - 0x03800000"
U-Boot-PetaLinux> setenv default_bootcmd run sdboot_devtree
U-Boot-PetaLinux> saveenv    #save env to qspi
U-Boot-PetaLinux> run sdboot_devtree   #boot from sd card

The next time u-boot runs, it will automatically boot using the devicetree on the SD card.

Copy files to SD Card using tftp

If already booted in linux, new boot files can be copied to the SD card using tftp if a tftp daemon on a host machine is available.

on the running embedded system, mount sd card

mount /dev/mmcblk0p1 /media
cd /media
tftp <hostIP> -g -r uImage

Working with the design

Boot from u-boot

Boot the board from the SD card and open a terminal emulator configured for 115200 baud.

  • U-boot will automatically run sdboot and start the kernel.
  • If old uboot environment settings have been stored, it may be necessary to enter uboot and run the following command which will set the environment to the defaults that were defined during the petalinux build:
      env default -a
      saveenv

The kernel will boot.

Operations in Linux

  • Login as user 'root' and passwd 'root'

  • Enter the linux commands:

    • peek 0xffff8000 Checks the heartbeat. It should be 0 because cpu1 hasn't started
    • poke 0xfffffff0 0x30000000 Start cpu1 by writing a start address to the wfe loop
    • peek 0xffff8000 Checks the heartbeat. cpu1 is now started so the read value should increment every second
    • softuart& Start the softuart application and run it in the background
    • poke 0x78600000 0x00000001 Using Linux on cpu0, create an interrupt towards cpu1 by writing to the control register within the irq_gen_0 core. Cpu1 will received an interrupt then service it. Upon servicing the irq, cpu1 uses OCM to communicate to the Linux softuart app. Cpu1 will cause the app to display: 'CPU1: IRQ clr '
  • Another way to generate an interrupt towards cpu1 is by using the chipscope VIO:

    • In vivado's flow navigator, select select program_and_debug->open_hardware_manager
      • Select 'Open target' -> 'auto connect'
      • In the hardware manager, debug probes window, select all probes under 'hw_ila_1', then right-click, Add probes to basic trigger setup
      • Focus will change to the ILA-hw_ila_1 tab. Change the compare value of design_1_i/vio_o_probe_out_1 to 'R'. Ok
      • Change the 'ILA properties', 'trigger position in window' to 100
      • Select Run trigger. The is now waiting for a trigger
      • In the hardware manager, debug probes window, right click on the only hw_vio_1 signal and select 'add probes to VIO window'
      • Focus will change to the VIO-hw_vio_1 tab. Right click on the signal and select 'Active-high button'
      • When you press the VIO button, an interrupt is generated and cpu1 will acknowledge it by printing to the linux softuart:
        • 'CPU1: IRQ clr '
        • The ILA will also trigger capturing the assertion and deassertion of the IRQ
@julian-bauer1
Copy link

is it possible to use LWIP in the modified BSP on core1?

when i try to porting my bare-metal app to xapp1078 i dont get any tcp connection. i dont receive the connected_callback() after calling tcp_connect() but in whireshark i get an APR message from fpga to host pc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment