19
Creating a New User Application To run a user application on an ARM Cortex-A9 MPCore system, you need to cross-compile it and build it into the embedded Linux image on a host machine. PetaLinux provides the tools to make these steps easy. 1-1. Set up the working environment for the PetaLinux tools and the Vivado® Design Suite. 2-2-1. Open a new Terminal window. The .bashrc file sources the scripts for the PetaLinux tools (source /opt/pkg/petalinux-v2015.2-final/settings.sh) and the Vivado Design Suite (source /opt/pkg/Xilinx/Vivado/2015.2/settings64.sh). Note: Assume that the PetaLinux tools are installed in the /opt/pkg directory. Modify the path if it is installed in a different location. 3-3. Change the path to the project directory. 4-4-2. Run the following command to change to the project directory path: [host] $ cd ~/training/emblinux/labs/appDevDebug

forums.xilinx.com · Web viewCreating a New User Application To run a user application on an ARM Cortex-A9 MPCore system, you need to cross-compile it and build it into the embedded

Embed Size (px)

Citation preview

Page 1: forums.xilinx.com · Web viewCreating a New User Application To run a user application on an ARM Cortex-A9 MPCore system, you need to cross-compile it and build it into the embedded

Creating a New User ApplicationTo run a user application on an ARM Cortex-A9 MPCore system, you need to cross-compile it and build it into the embedded Linux image on a host machine. PetaLinux provides the tools to make these steps easy.

1-1. Set up the working environment for the PetaLinux tools and the Vivado® Design Suite.

2-2-1. Open a new Terminal window.The .bashrc file sources the scripts for the PetaLinux tools (source /opt/pkg/petalinux-v2015.2-final/settings.sh) and the Vivado Design Suite (source /opt/pkg/Xilinx/Vivado/2015.2/settings64.sh).Note: Assume that the PetaLinux tools are installed in the /opt/pkg direc-tory. Modify the path if it is installed in a different location.

3-3. Change the path to the project directory.4-4-2. Run the following command to change to the project directory path:

[host] $ cd ~/training/emblinux/labs/appDevDebug

Page 2: forums.xilinx.com · Web viewCreating a New User Application To run a user application on an ARM Cortex-A9 MPCore system, you need to cross-compile it and build it into the embedded

5-5. Use the petalinux-create command to create a new embedded Linux platform and choose the platform.

6-6-3. Run the following command from the appDevDebug directory to create a new PetaLinux project:[host] $ petalinux-create -t project -s /opt/pkg/Avnet-Digilent-ZedBoard-v2015.2-final.bsp

INFO: Create project:

INFO: Projects:

INFO: * Avnet-Digilent-ZedBoard-2015.2

INFO: has been successfully installed to /home/petalinux/train-ing/emblinux/labs/appDevDebug/

INFO: New project successfully created in /home/petalinux/train-ing/emblinux/labs/appDevDebug/

The above command assumes that the board support package (BSP) is in-stalled in the /opt/pkg directory. Modify the path if the BSP is in a different location.You will find the project directory (~/training/emblinux/labs/appDevDe-bug): Avnet-Digilent-ZedBoard-2015.2.

7-7-4. Change the directory to the PetaLinux project:~/training/emblinux/labs/appDevDebug/Avnet-Digilent-ZedBoard-2015.2

8-8. Create a new application.The PetaLinux tools allow you to create user application tem-plates for either C or C++. These templates include application source code and makefiles so that you can easily configure and compile applications for the target and install them into the root file system.

9-9-5. Enter the following command to create a new user application inside a PetaLinux project:[host] $ petalinux-create -t apps --name myapp --template c

INFO: Create apps: myapp

INFO: New apps successfully created in /home/petalinux/training/emblinux/labs/appDevDebug/Avnet-Digilent-ZedBoard-2015.2/compo-nents/apps/myapp

The new application you have created can be found in the <project-root>/components/apps/myapp directory, where <project-root> is ~/training/emblinux/labs/appDevDebug/Avnet-Digilent-ZedBoard-2015.2.To create a C++ application template, pass the --template c++ option.

10-10-6. Change to the newly created application directory:

Page 3: forums.xilinx.com · Web viewCreating a New User Application To run a user application on an ARM Cortex-A9 MPCore system, you need to cross-compile it and build it into the embedded

[host] $ cd <project-root>/components/apps/myapp

You will see the following PetaLinux template-generated files:

Figure 3-1: Files Generated After Creating a New Application

Template Description

Kconfig Configuration file template. This file controls how your ap-plication is integrated into the PetaLinux menu configura-tion system and allows you to add configuration options for your own application to control how it is built or in-stalled.

Makefile Compilation file template. This is a basic makefile con-taining targets to build and install your application into the root file system. This file needs to be modified when you add additional source code files to your project.

README A file to introduce how to build the user application.

myapp.c for C ormyapp.cpp for C++

Simple application program in either C or C++, depend-ing upon your choice. These files will be edited or re-placed with the real source code for your application.

Page 4: forums.xilinx.com · Web viewCreating a New User Application To run a user application on an ARM Cortex-A9 MPCore system, you need to cross-compile it and build it into the embedded

Building the Application into the Embedded LinuxOnce you have created the new application, the next step is to configure, compile, and build it.

11-11. Select the new application to be included in the build process. The application is not enabled by default.

12-12-7. Ensure that your current working directory (project directory) is ~/training/emblinux/labs/appDevDebug/Avnet-Digilent-ZedBoard-2015.2.

13-13-8. Launch the rootfs configuration menu by entering the following command:[host] $ petalinux-config -c rootfs

Note: Make sure that the terminal window is at least 80 columns wide. If your terminal is NOT at least 80 columns wide, you will see error "Error: Failed is config linux/rootfs! Your display is too small to run menuconfig".The linux/rootfs configuration menu opens.

Figure 3-2: linux/rootfs Configuration Menu

14-14-9. Press the Down Arrow key to scroll down the menu to Apps.15-15-10. Press <Enter> to go into the Apps submenu.

The new application myapp is listed in the menu. 16-16-11. Move to myapp and press <Y> to select the application.

Page 5: forums.xilinx.com · Web viewCreating a New User Application To run a user application on an ARM Cortex-A9 MPCore system, you need to cross-compile it and build it into the embedded

Selecting the application will be included in the build process.

Figure 3-3: Selecting the New Application

17-17-12. Press <Enter>to open the myapp options.By default, there are no additional options for myapp. Advanced users can modify the Kconfig file in the myapp directory to add custom options.

18-18-13. Select and press Exit to return to the main menu.

Page 6: forums.xilinx.com · Web viewCreating a New User Application To run a user application on an ARM Cortex-A9 MPCore system, you need to cross-compile it and build it into the embedded

19-19. Enable the build debuggable applications. 20-20-14. Scroll down the Linux/rootfs configuration menu to Debugging.21-21-15. Select the Debugging submenu and ensure that build debuggable

applications is selected. Click Y to select build debuggable applications.

22-22-16. Select and press Exit to return to the main menu.

Page 7: forums.xilinx.com · Web viewCreating a New User Application To run a user application on an ARM Cortex-A9 MPCore system, you need to cross-compile it and build it into the embedded

23-23. Enable the TCF agent for debugging support. The PetaLinux tools support debugging Zynq All Programmable SoC user applications with a TCF agent.

24-24-17. Select Filesystem Packages (1).25-25-18. In the Filesystem Packages menu, select base (2).26-26-19. In the base menu, scroll down and select tcf-agent (3).27-27-20. Enable the tcf-agent by clicking Y (4).

Figure 3-4: Enabling the TCF Agent

28-28-21. Select and press Exit to return to the main menu.29-29-22. Exit the linux/rootfs configuration menu. 30-30-23. Select <Yes> to save your new configuration.

It will take a few seconds for the configuration changes to be applied. Wait until you return to the shell prompt on the command console.

Page 8: forums.xilinx.com · Web viewCreating a New User Application To run a user application on an ARM Cortex-A9 MPCore system, you need to cross-compile it and build it into the embedded

31-31. Build the image.32-32-24. Make sure that you are in the <petalinux project> directory.33-33-25. Enter the following command to build the image:

[host] $ petalinux-build

Note: This process will take approximately 12 minutes.Running petalinux-build in the project directory <project-root> will build the system image, including the selected user application myapp.The full compilation log "build.log" is stored in the build subdirectory of the PetaLinux project. The Linux software images and the device tree are gener-ated in the images/linux subdirectory of the PetaLinux project.The output directory for this build process is <project-root>/build/linux/rootfs/apps/myapp.This process will take approximately 12 minutes.

Booting the New Image with QEMUWith the QEMU simulator, you can develop and debug the software application without using hardware at all.

34-34. Run the application in QEMU.35-35-26. Enter the following command to boot the newly built PetaLinux image

through QEMU:# petalinux-boot --qemu --kernel

36-36-27. After the system boots, log into the system by entering root as the both the login name and password.

37-37-28. Examine the /bin directory in the QEMU console:# ls /bin | grep myapp

You should see that the myapp application is there.38-38-29. Execute the myapp application in the QEMU console:

# myapp 1

The following is the output of the command:Hello, PetaLinux World!

cmdline args:

myapp

1

39-39-30. Press <Ctrl + A> then press <X> to exit QEMU.

Page 9: forums.xilinx.com · Web viewCreating a New User Application To run a user application on an ARM Cortex-A9 MPCore system, you need to cross-compile it and build it into the embedded

Debugging the Application Using System Debugger in the Target Board

40-40. Launch XSDK and create a workspace.41-41-31. Open a new terminal.42-42-32. Enter the following command to launch XSDK:

[host] $ xsdk

43-43-33. Select ~/training/emblinux/labs/appDevDebug/workspace as the workspace directory.

Figure 3-5: Setting Up the Workspace Environment Path

44-44-34. Click OK.45-45-35. Close the Welcome screen.

Page 10: forums.xilinx.com · Web viewCreating a New User Application To run a user application on an ARM Cortex-A9 MPCore system, you need to cross-compile it and build it into the embedded

46-46. Create the hardware platform specification.47-47-36. Select File > New > Project.48-48-37. Select Xilinx > Hardware Platform Specification in the pop-up

window.49-49-38. Click Next.50-50-39. Enter zynq_hw_platform as the project name.51-51-40. Under the Target Hardware Specification region, browse to the

~/training/emblinux/labs/appDevDebug/Avnet-Digilent-ZedBoard-2015.2/hardware/Avnet-Digilent-ZedBoard-2015.2/Avnet-Digilent-ZedBoard-2015.2.sdk directory and select system.hdf.

52-52-41. Click OK.53-53-42. Click Finish.

54-54. Make sure that the BOOT.BIN file located in the SD card is copied from "A First Look" lab.

55-55-43. Make sure that the BOOT.BIN file is located in the SD card.If you have done either the "A First Look" lab or the "Build and Boot an Im-age" lab as your last lab, there is no need to make any changes to the SD card.If not, copy the BOOT.BIN from the ~/training/emblinux/support/First-Look/SDCard directory to the SD card.

56-56-44. Insert the SD card back to the target board.

57-57. Power up the board and launch the serial port terminal.58-58-45. Power ON the board.59-59-46. Select Devices > USB > 2012 Cypress Semiconductor Cypress-

USB2UART-0123456 in the VirtualBox.

Figure 3-6: Enable the USB-UART Connection in VirtualBox

60-60-47. In the dashboard, in the Search field, enter the serial port.61-61-48. Select the Serial port terminal application.

Note: Wait for 15 seconds and open the Serial port terminal application. If you see the dialog box "cannot open /dev/ttyACM0: Device or resource

Page 11: forums.xilinx.com · Web viewCreating a New User Application To run a user application on an ARM Cortex-A9 MPCore system, you need to cross-compile it and build it into the embedded

busy" , then open the Serial port terminal application again after 10 seconds or few more seconds.

62-62. Boot the new Linux image on the board.63-63-49. Press any key to stop auto-boot when you see messages similar to the

following in the GtkTerm window:

Figure 3-7: Stopping the Autoboot

If the system has booted, reset the board (BTN7) again and stop auto-boot. Note: If you have finished setting the IP address and server IP address and saved once, you can directly run the command run netboot.

64-64-50. Set the IP address for the target board so that it can communicate to the host and load the new image:U-Boot-PetaLinux> setenv ipaddr 192.168.1.10

65-65-51. Set the TFTP server IP to the host IP by typing the following command in the u-boot console:U-Boot-PetaLinux> setenv serverip 192.168.1.1

66-66-52. Save the environment to the SPI flash:

U-Boot-PetaLinux> saveenv

Page 12: forums.xilinx.com · Web viewCreating a New User Application To run a user application on an ARM Cortex-A9 MPCore system, you need to cross-compile it and build it into the embedded

67-67-53. Download and boot the new image using TFTP by executing this command in the u-boot console:U-Boot-PetaLinux> run netboot

This command will download the image.ub file from /tftpboot on the host to the main memory of the ARM Cortex-A9 MPCore system and boot the system with the image.Note: This may take approximately 2 to 3 minutes to complete the down-load. There is a significant delay in the network because of the VirtualBox en-vironment. But generally, if you are running this command on the Linux ma-chine, it should take less time to download the image.

68-68-54. After the system boots, log into the system by entering root as both the login name and password.

69-69-55. Confirm that TCF agent is running.

Figure 3-8: Verifying the TCF agent is running

70-70-56. Set the IP address for the board.~# ifconfig eth0 192.168.1.10

71-71-57. Verify the eth0 IP address.

Praveen Venugopal, 09/16/16,
Boot the board using boot.bin & image.ub <or> image files from FLASH etc.
Praveen Venugopal, 09/16/16,
if board is locally connected to host then connect them with a LAN cable and go to local machine network settings to set ip address for e.g.192.168.1.1255.255.255.0
Praveen Venugopal, 09/16/16,
Here you are setting ip address of the hardware board
Praveen Venugopal, 09/16/16,
After linux boot on board you will see if configured rootfs for tcf-agent enable is fine. Here you will see “Starting tcf-agent : OK”
Page 13: forums.xilinx.com · Web viewCreating a New User Application To run a user application on an ARM Cortex-A9 MPCore system, you need to cross-compile it and build it into the embedded

72-72. In SDK GUI set the Target Connection Details. 73-73-58. From the Target Connections tab, expand Linux TCF Agent.74-74-59. Double-click Linux Agent [default].75-75-60. Set the Host IP address of the host to 192.168.1.10.76-76-61. Set the Port to 1534.77-77-62. Click OK.

Figure 3-9: Setting the Target Connection Details

Page 14: forums.xilinx.com · Web viewCreating a New User Application To run a user application on an ARM Cortex-A9 MPCore system, you need to cross-compile it and build it into the embedded

78-78. Create a new Debug configuration and configure the setup of the target.

79-79-63. From SDK, select Run > Debug Configurations.Make sure that the SDK window is active as the selected foreground window.

80-80-64. Double-click Xilinx C/C++ application (System Debugger) to create a new configuration (1).

81-81-65. Select Linux Application Debug as the Debug type (2).82-82-66. Select the Connection to Linux Agent (3).

Figure 3-10: Configuring the Target Setup

Page 15: forums.xilinx.com · Web viewCreating a New User Application To run a user application on an ARM Cortex-A9 MPCore system, you need to cross-compile it and build it into the embedded

83-83. Configure both the local and remote file paths.84-84-67. Select the Application tab.85-85-68. Click Browse to set the local file path to be the compiled application in

the project directory.86-86-69. Locate the myapp application:

<project-root>/build/linux/rootfs/apps/myapp/myapp

87-87-70. Click OK.88-88-71. Set the remote file path to be the location on the target file system

where your application can be found:

Page 16: forums.xilinx.com · Web viewCreating a New User Application To run a user application on an ARM Cortex-A9 MPCore system, you need to cross-compile it and build it into the embedded

/bin/myapp

Figure 3-11: Configuring the Application File Paths

89-89-72. Click Apply.

Page 17: forums.xilinx.com · Web viewCreating a New User Application To run a user application on an ARM Cortex-A9 MPCore system, you need to cross-compile it and build it into the embedded

90-90. Debug the program.91-91-73. Click Debug.92-92-74. Click Yes to confirm the perspective switch.

The Debug perspective opens.

Figure 3-12: Debug Perspective Window

Program operation is suspended at the first executable statement in main{} (not running).Note that local variables for the current function are shown in the Variables tab.

93-93-75. Select Window > Show View > Disassembly.

Page 18: forums.xilinx.com · Web viewCreating a New User Application To run a user application on an ARM Cortex-A9 MPCore system, you need to cross-compile it and build it into the embedded

94-94-76. Double-click line number 11 to set a breakpoint there (a check mark becomes visible

).

Figure 3-13: Breakpoint Set at Line Number 11

Note: If line numbers are not displayed, right-click the leftmost column of the editor and select Show Line Numbers.

Page 19: forums.xilinx.com · Web viewCreating a New User Application To run a user application on an ARM Cortex-A9 MPCore system, you need to cross-compile it and build it into the embedded

95-95. Resume the program.96-96-77. Click the Play/Resume button (green triangle ) to run the program.

The program runs until the breakpoint.

Figure 3-14: Program Stops at Breakpoint

You will see the message in the Console window.You can explore other options and disconnect the program by clicking the Disconnect ( ) button.

97-97-78. Close the SDK tool, Serial port terminal and power off the board.