{"id":1012,"date":"2016-08-11T15:25:06","date_gmt":"2016-08-11T23:25:06","guid":{"rendered":"http:\/\/www.beyond-circuits.com\/wordpress\/?page_id=1012"},"modified":"2016-10-08T12:13:33","modified_gmt":"2016-10-08T20:13:33","slug":"tutorial25","status":"publish","type":"page","link":"https:\/\/www.beyond-circuits.com\/wordpress\/tutorial\/tutorial25\/","title":{"rendered":"Tutorial 25: Debugging Linux Applications from SDK"},"content":{"rendered":"<p>In this tutorial, we will debug the simple SPI application from\u00a0<a href=\"https:\/\/www.beyond-circuits.com\/wordpress\/tutorial\/tutorial24\/\">Tutorial 24<\/a>.<\/p>\n<h1>Configuring Linux for Debugging<\/h1>\n<p>SDK talks to a debug server that runs\u00a0on the ZedBoard. We need to modify our Linux build to turn on the debug server. First, run <code>petalinux-config<\/code>, as shown in <a href=\"https:\/\/www.beyond-circuits.com\/wordpress\/tutorial\/tutorial23\/\">Tutorial 23<\/a>:<\/p>\n<pre>% petalinux-config -c rootfs --project zedboard_linux<\/pre>\n<p><a href=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/06\/T23-Menuconfig1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-968 alignright\" src=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/06\/T23-Menuconfig1-300x180.png\" alt=\"T23-Menuconfig1\" width=\"300\" height=\"180\" srcset=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/06\/T23-Menuconfig1-300x180.png 300w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/06\/T23-Menuconfig1-500x300.png 500w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/06\/T23-Menuconfig1.png 723w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Press return to select Filesystem Packages.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/07\/petalinux-config-base.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-1015 alignright\" src=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/07\/petalinux-config-base-300x181.png\" alt=\"petalinux-config-base\" width=\"300\" height=\"181\" srcset=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/07\/petalinux-config-base-300x181.png 300w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/07\/petalinux-config-base-498x300.png 498w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/07\/petalinux-config-base.png 720w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a>Then, use the arrow keys to select base, and press return.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/07\/petalinux-config-tcf-agent.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-1016 alignright\" src=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/07\/petalinux-config-tcf-agent-300x180.png\" alt=\"petalinux-config-tcf-agent\" width=\"300\" height=\"180\" srcset=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/07\/petalinux-config-tcf-agent-300x180.png 300w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/07\/petalinux-config-tcf-agent-500x300.png 500w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/07\/petalinux-config-tcf-agent.png 719w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a>Press return to select the tcf-agent option, then press space to enable it.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/07\/petalinux-config-tcf-agent-select.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-1017 alignright\" src=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/07\/petalinux-config-tcf-agent-select-300x179.png\" alt=\"petalinux-config-tcf-agent-select\" width=\"300\" height=\"179\" srcset=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/07\/petalinux-config-tcf-agent-select-300x179.png 300w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/07\/petalinux-config-tcf-agent-select-500x298.png 500w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/07\/petalinux-config-tcf-agent-select.png 719w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a>Then use the arrow keys to save and exit back out of petalinux-config.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Then run petalinux-build and petalinux-package as shown below to build the kernel and filesystem and package it for copying to the SD card.<\/p>\n<pre>\u2192% petalinux-build --project zedboard_linux\r\n% petalinux-package --boot --format BIN --project zedboard_linux \\\r\n--format BIN \\\r\n--fsbl zedboard_spi\/zedboard_spi.sdk\/Zynq_FSBL\/Debug\/Zynq_FSBL.elf \\\r\n--fpga zedboard_spi\/zedboard_spi.runs\/impl_1\/system_wrapper.bit \\\r\n--u-boot\r\n<\/pre>\n<p>After you have packaged the distribution copy, the <code>BOOT.BIN<\/code>, and <code>zedboard_linux\/images\/linux\/image.ub<\/code> files to the SD card,<br \/>\nplace the SD card back in the ZedBoard and reboot.<\/p>\n<h1>Building the application in SDK<\/h1>\n<p>Form Vivado, export the FPGA design to SDK by selecting <em>File\u2192<\/em><em>Export Hardware<\/em>. Check the <em>Include bitstream<\/em> option and click <em>OK<\/em>.\u00a0Now launch SDK by selecting <em>File\u2192Launch SDK<\/em>,\u00a0then clicking<em> OK.<\/em><br \/>\nOnce in SDK, create a new application project by selecting <em>New\u2192Application Project<\/em>. Set the project name to <em>max5216pmb1<\/em> and\u00a0the OS Platform to <em>linux<\/em>, then click <em>Next<\/em>. Choose the <em>Linux Empty Application<\/em> template and then click <em>Finish<\/em>. This will create a new application project. We&#8217;re going to import\u00a0the code from the <a href=\"https:\/\/www.beyond-circuits.com\/wordpress\/tutorial\/tutorial24\/\">previous tutorial<\/a> to this project. Select <em>File\u2192Import&#8230;<\/em>. Expand the <em>General<\/em> category and select <em>File System<\/em>, then click<em> Next<\/em>. Click Browse and go to the directory which contains the\u00a0<code>max5216pmb1.c\u00a0<\/code>file. Remember that you need to select the directory containing the file. Don&#8217;t browse into the directory. Once you have selected the directory, click <em>OK<\/em>. You will now be presented with a screen showing all the files in the directory you selected. Check the\u00a0<code>max5216pmb1.c<\/code>\u00a0file. Change the <em>Info folder<\/em> field to <code>max5216pmb1\/src<\/code> so that the file is imported into the <code>src<\/code> folder within the project. Now click <em>Finish<\/em>.<\/p>\n<p>With the code successfully imported, SDK will try to compile the project. This will fail with link errors. We need to link with the math library so we will set that up now.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-medium wp-image-1032\" src=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/08\/tutorial25_linker_libs-300x232.png\" alt=\"tutorial25_linker_libs\" width=\"300\" height=\"232\" srcset=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/08\/tutorial25_linker_libs-300x232.png 300w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/08\/tutorial25_linker_libs-768x595.png 768w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/08\/tutorial25_linker_libs-387x300.png 387w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/08\/tutorial25_linker_libs.png 875w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/>Select the <em>max5216pmb1<\/em> project in the <em>Project Explorer<\/em> pane, then select <em>Project\u2192Properties<\/em>. Expand the <em>C\/C++ Build<\/em> field and select the <em>Tool Settings<\/em> tab. Now, expand the <em>ARM Linux gcc linker<\/em> field and select <em>Libraries<\/em>. Click on the button with a plus sign and page and enter m for the library name. Your dialog box should look like that shown on the right. Click OK to dismiss the dialog box. The project should now link properly.<\/p>\n<h1>Configuring the Target Connection<\/h1>\n<p><a href=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/08\/tutorial25_target_connections.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-medium wp-image-1035\" src=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/08\/tutorial25_target_connections-300x156.png\" alt=\"tutorial25_target_connections\" width=\"300\" height=\"156\" srcset=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/08\/tutorial25_target_connections-300x156.png 300w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/08\/tutorial25_target_connections.png 477w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a>We need to tell the debugger how to communicate with our ZedBoard. This communication channel is called a <em>Target Connection<\/em>. You should see a window pane in the lower left of the SDK window called <em>Target Connections<\/em>. If you don&#8217;t, you can make it show up by clicking <em>Window\u2192Show View\u2192Other<\/em>, then selecting <em>Target Connections<\/em> and clicking <em>OK<\/em>. The Target Connections panel is shown to the right. Select the <em>Linux Agent [default]<\/em> entry and right-click and select <em>Edit<\/em> from the popup menu. Enter in the IP address for your ZedBoard in the <em>Host<\/em> field. Make sure the port is set to 1534. Then click <em>OK<\/em>. This configures SDK to talk to the TCF debug daemon on your ZedBoard over the Ethernet connection.<\/p>\n<h1>Configure the debug session<\/h1>\n<p>We now need to configure the debug session. Select the max5216pmb1 project and select\u00a0<em>Run\u2192Debug Configurations<\/em>. Select <em>Xilinx C\/C++ application (System Debugger)<\/em> and click the new <img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1037 alignnone\" src=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/08\/tutorial25_new_button.png\" alt=\"tutorial25_new_button\" width=\"21\" height=\"22\" \/>\u00a0button. This will create a new debug configuration called max5216pmb1 Debug. In the <em>Target Setup<\/em> tab, set <em>Debug Type<\/em> to <em>Linux Application Debug<\/em>. The <em>Connection<\/em> field should be set to <em>Linux Agent<\/em>. Next in the <em>Application<\/em> tab use the <em>Browse<\/em> button to set the <em>Project Name<\/em> to <em>max5216pmb1<\/em>. The <em>Application Local File Path<\/em> will be automatically set to <em>Debug\/max5216pmb1.elf<\/em>. We also need to set the <em>Remote File Path<\/em> to <em>\/home\/root\/max5216pmb1.elf<\/em>. Now click <em>Apply<\/em> set set the changes and then click <em>Run<\/em>. This should bring up a debugger view and start the debugger.<\/p>\n<p>You should be able to step through\u00a0the program and step into\u00a0function calls. The Console panel\u00a0at the bottom of the SDK window will show program output. You can type program input there as well, just as you would do from the console.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we will debug the simple SPI application from\u00a0Tutorial 24. Configuring Linux for Debugging SDK talks to a debug server that runs\u00a0on the ZedBoard. We need to modify our Linux build to turn on the debug server. First, &hellip; <a href=\"https:\/\/www.beyond-circuits.com\/wordpress\/tutorial\/tutorial25\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":226,"menu_order":25,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1012","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/pages\/1012","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/comments?post=1012"}],"version-history":[{"count":13,"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/pages\/1012\/revisions"}],"predecessor-version":[{"id":1133,"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/pages\/1012\/revisions\/1133"}],"up":[{"embeddable":true,"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/pages\/226"}],"wp:attachment":[{"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1012"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}