How to debug Linux Application in SDK 2019.1
How to debug Linux Application in SDK 2019,1
In this brief tutorial we shall discuss how to debug a Linux application running on Zynq Ultrascale
Building the Linux Images:
The steps to build the project here are explained in the wiki page here.- petalinux-build --sdk
- petainux-package --sysroot
Setting up the LAN:
To debug an linux application running on the kernel, then the local machine needs to be connected to the board in a Local Area Network (LAN).
Below are my HOST settings:
Then boot your kernel, and setup the board IP address:
Make sure you can ping the host before continuingCreate the SDK Linux Application Project:
Launch SDK on the same machine as the HOST settings are set up on.
Then File -> New -> Application Project:
For the Linux System Root, browse to the plnx_aarch64 copied over in previous step.
Select Next, and choose the Linux Empty Application template and select finish.
Note: you may see an error on the console. To address this, right click on the gpio_linux application in the Project Explorer in SDK,
and select C/C++ Build Settings:
Right click on the gpio_linux/src folder in the Project Explorer and select New -> Source File. Give this a name, and then copy the contents below into this newly created one.#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/mman.h> #include <fcntl.h> #define GPIO_MAP_SIZE 0x10000 #define GPIO_DATA 0x00 #define GPIO_TRI 0x04 #define LED_NUM 256 #define LED_DELAY 10000000 int main(int argc, char *argv[]) { int fd; char *uiod = "/dev/uio0"; void *gpio_ptr; volatile int Delay; printf("AXI GPIO UIO test.\n"); // open the UIO device file to allow access to the device in user space fd = open(uiod, O_RDWR); if (fd < 1) { printf("Invalid UIO device file:%s.\n", uiod); return -1; } // mmap the GPIO device into user space gpio_ptr = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); if (gpio_ptr == MAP_FAILED) { printf("Mmap call failure.\n"); return -1; } // set bit0 on the GPIO to be output // see pg144 for ref *((volatile unsigned *)(gpio_ptr + GPIO_TRI)) = 0x0; // Toggle the LED while (1) { int i; unsigned char led_pin = 0x0; for (i = 0; i < LED_NUM; i++) { *((volatile unsigned *)(gpio_ptr + GPIO_DATA)) = led_pin; for (Delay = 0; Delay < LED_DELAY; Delay++); *((volatile unsigned *)(gpio_ptr + GPIO_DATA)) = 0x0; led_pin++; } } // unmap the GPIO device from user space munmap(gpio_ptr, 4096); return 0; }
Next, we need to setup the Target connection. In the Target connection, drop down the Linux Agent, and select Add new target connection: