Linux application debugging through Remote System Explorer Importing Sample Application 1. Start an Embedded Command Shell by running the script /home/admin/altera /13.0sp1/ embedded/embedded_command_shell.sh 2. Start Eclipse by running eclipse command and select a workspace if asked to 3. Go to File >Import… 4. In the Import window, select General > Existing Project into Workspace and click Next. 5. Choose Select Archive file option and browse to ~/altera/ 13.0sp1 /embedded /examples/software/Altera-SoCFPGA-HelloWorld-Linux-GNU.tar.gz. 6. Click Finish to complete importing the sample application. At the end of the import process, Eclipse shows the project files: • hello.c - Sample application source code • Makefile - Makefile used to compile the sample application Compiling Sample Application The sample application is compiled in Eclipse by selecting to Project > Build Project. This compiles the project using the Linaro gcc suite for Linux, which is part of SoC EDS. After a successful compilation, the following files are created: • hello.o – object file, • hello – executable file, • hello.map – linker output map file. Setting up Remote System Explorer The ARM DS-5 AE can run and debug programs directly on the target with the help of the RSE (Remote System Explorer). Before this feature can be used, the RSE needs to be configured to connect to the target board running Linux. Before doing the steps presented in this section, the board must be connected to the network and have an assigned IP address. Also there has to be a valid username with a password on the Linux board. This can be achieved by assigning a password to the root account, which does not have a password set up by default. 0. Open an terminal and type: sudo minicom then enter password After the Linux is booted from the SD card, type root to login. Type ifconfig to get the IP address of the board. Type passwd to set a password for the root. 1. In your Eclipse workspace, select Window > Open Perspective > Other. 2. In the Open Perspective window, select the Remote System Explorer and click OK. 3. In the Remote System Explorer view, right click Local and select New > Connection. 4. In the Remote System Type view, select SSH only and click Next. 5. Enter the IP address of the board in the Host Name, Connection name, and Description fields. Click Finish to create the connection. 6. Click the SocKitLinux > Sftp Files > Root. This opens a window to enter the username and password. Use root for username and the password you have set up for it. 7. Eclipse asks for confirmation of authenticity of the board. Press Yes. 8. Remote System Explorer shows the files currently on the SocKit board on the left panel. Debugging Linux Application At this stage we have a compiled Linux application and a properly configured Remote System Explorer. This section shows how to create a Debugger Configuration and use it to run and debug the application. 1. Select Run >Debug Configurations. 2. Right-click the DS-5 Debugger and click New. 3. Name the new Debugger Configuration LinuxAppDebug_SocKit. 4. In the Connection Panel a. For the Free Web Edition license, select Generic > gdb server > Linux Application Debug > Download and Debug Application. b. For the Subscription Edition or 30-day Evaluation Edition, select Altera > Cyclone 5 SoC > Linux Application Debug > Download and Debug Application. c. Select the newly created RSE connection and keep the default values. 5. Go to Files tab, and complete the following steps a. Select the Application on host to download to be the hello executable file. Use the Workspace… button to browse for the application. b. Edit the Target download directory to be “/home/root” (the root folder). c. Edit the Target working directory to be “/home/root” (the root folder). 6. On the Debugger tab, make sure the Debug from symbol is selected and the symbol name is main. 7. Click the Debug button. Eclipse asks to switch to Debug perspective. Click Yes. Eclipse downloads the application to the board and stop at main, as instructed. 8. At this stage all the usual debugging features of DS-5 can be used: breakpoints, view variables, registers, tracing, threads etc. Click the Continue green button or press F8 to run the application. The hello message prints on the App Cons. Linux Kernel and Driver Debugging Getting Started Notes: • In the scenario presented here the Linux kernel is already running on the board, but it can also be downloaded through the debugger. • This scenario uses the pre-built Linux images and Linux source code included in the SoC EDS. These are examples only; use the latest sources from http://software.altera.com/linux_socfpga for development. Linux Kernel and Driver Debugging We can use the dedicated Linux debugging features presented in this section together with the basic debugging features such as viewing registers, inspecting variables and setting breakpoints. 1. Make sure the desired Linux kernel version is already running on the board. See Running Linux docs for instructions on how to run the provided Linux binaries on the board. 2. Make sure the Linux kernel executable file is accessible on the host computer. The kernel executable for the pre-built Linux image is located at /home/admin/altera/13.0sp1/embedded/embeddedsw/socfpga/prebuilt_images/vmli nux 3. Make sure the source code corresponding to the kernel running on the board are accessible on the host computer. The sources for the pre-built Linux image can be 4. 5. 6. 7. 8. obtained by extracting the file /home/admin/altera/13.0sp1/embedded/embeddedsw/socfpga/sources/linux-altera3.7.tgz. This can be achieved with the following commands: a. $ cd /home/admin/altera/13.0sp1/embedded/embeddedsw/socfpga/sources/ b. $ tar xzf linux-altera-3.7.tgz Start an Embedded Command Shell by running the script /home/admin/altera/13.0sp1 /embedded/embedded_command_shell.sh Start Eclipse by running eclipse command and select a workspace if asked. Select Run > Debug Configurations. Right-click DS-5 Debugger on the left panel and select New. In the Debug Configuration window, perform the following: a. Rename the configuration to DebugLinux_SocKit using the Name edit box b. Select the Target to be Altera > CycloneVSoC >Linux Kernel and/or Device Driver Debug >Debug Cortex-A9x2 SMP via Altera USB-Blaster. c. Click the Browse button near the Connection edit box and select the desired USB Blaster instance. 9. Click the Files tab. At this design phase you specify the Linux kernel executable and the symbols file. They are not required in the current scenario, because the Linux kernel is already present on the board. Load the symbols file from a debugger command. This tab also shows the Soft IP peripheral registers, as described in ARM DS-5 AE – Soft IP Register Visibility. 10. In the Debugger tab perform the following steps: a. Select option Connect Only for Run Control. b. Check Execute debugger commands check box. c. Add the debugger commands to stop cores and load image symbols for the Linux executable, as shown in the following picture. d. Add the path to the Linux source files on the host machine, to allow debugger to locate them. 11. Click Debug. The debugger connects to the board, stop the cores as instructed and load the symbols. It determines where the cores are stopped, and highlight it in the source code. In the following snapshot it stopped in the idle instruction. 12. To view the running threads, maximize the top left panel. It shows Active Threads with the two currently executing threads. Also the All Threads can be expanded to show all threads in the system. 13. Minimize the Debug Control panel and maximize the Functions panel from top right. It shows all the functions currently in the kernel. The Functions panel supports the following operations for each function: a. Run up to the function. b. Set PC to function. c. Locate in source code/memory/disassembly. d. Set breakpoints software/hardware. e. Set tracepoints: enable/disable/toggle. 14. Press the Continue green button or press F8 to let the kernel continue execution. Select Modules panel to show the currently loaded modules (in this case just the ipv6). 15. On the serial console window, type the following command: insmod /lib/modules/ 3.7.0/kernel/drivers/gpio/gpio-dw.ko. The DS-5 briefly pauses to update, and then the modules window shows the newly loaded module. 16. Similarly, when a module is unloaded using rmmod, the DS-5 updates to reflect the changes. This is achieved by the fact that the debugger sets two breakpoints, on module load and module remove. Select Breakpoints window to see this.