URL
https://opencores.org/ocsvn/riscv_vhdl/riscv_vhdl/trunk
Subversion Repositories riscv_vhdl
[/] [riscv_vhdl/] [trunk/] [docs/] [doxygen/] [07_debugger.doxy] - Rev 5
Compare with Previous | Blame | View Log
/**@page debugger_page RISC-V debugger@section dbg_overview_section OverviewThis debugger was specially developed as a software utility to interactwith our SOC implementation in \c riscv_soc repository. The mainpurpose was to provide convinient way to develop and debug ourSatellite Navigation firmware that can not be debugged by any othertool provided RISC-V community. Additionally, we would like to usethe single unified application capable to work with Real and Simulatedplatforms without any modification of source code.Debugger provides base functionality such as: run control,read/write memory, registers and CSRs, breakpoints. It allows toreload FW image and reset target.Also we are developing own version of the CPU simulator(analog of \c spike) that can be extended with peripheries models toFull SOC simulator. These extensions for the debugger simplifyporting procedure (Zephyr OS for an example) so thatsimulation doesn't require any hardware and allows to develop SW and HWsimultaneously.@section dbg_prj_structure_section Project structureGeneral idea of the project is to develop one \c Core libraryproviding API methods for registering \c classes, \c services, \c attributesand methods to interact with them. Each extension plugin registers one orseveral class services performing some usefull work. All plugins arebuilt as an independent libraries that are opening by \c Core libraryat initialization stage with the call of method <b>plugin_init()</b>.All Core API methods start with \c RISCV_... prefix:@codevoid RISCV_register_class(IFace *icls);*IFace *RISCV_create_service(IFace *iclass, const char *name,AttributeType *args);*IFace *RISCV_get_service(const char *name);...@endcodeConfiguration of the debugger and plugins is fully described in JSONformatted configuration files <b>targets/target_name.json</b>.These files store all instantiated services names, attributes valuesand interconnect among plugins.This configuration can be saved to/load from file at anytime. By default command \c exit will save current debugger state intofile (including full command history).@note You can manually add/change new Registers/CSRs names and indexesby modifying this config file without changing source code.@par Folders description-# \b libdgb64g - Core library (so/dll) that provides standard APImethods defined in file \c api_core.h.-# \b appdbg64g - Executable (exe) file implements functionality ofthe console debugger.-# \a Plugins:-# \b simple_plugin - Simple plugin (so/dll library) just fordemonstration of the integration with debugger.-# \b cpu_fnc_plugin - Functional model of the RISC-V CPU(so/dll library).-# \b cpu_sysc_plugin - Precise SystemC model of RIVER CPU(so/dll library).-# \b socsim_plugin - Functional models of the peripheriesand assembled board (so/dll library). This pluginregisters several classes: \c UART, \c GPIO, \c SRAM,\c ROMs and etc.@section eth_link_section Ethernet setupThe Ethernet Media Access Controller (GRETH) provides an interface betweenan AMBA-AXI bus and Ethernet network. It supports 10/100 Mbit speed in bothfull- and half-duplex modes. Integrated EDCL submodule implements hardwaredecoding of UDP traffic and redirects EDCL request directly on AXI systembus. The AMBA interface consists of an AXI slaveinterface for configuration and control and an AXI master interfacefor transmit and receive data. There is one DMA engine for the transmitterand one for receiver. EDCL submodule and both DMA engines share the sameAXI master interface.@subsection eth_confgure_section Configure Host ComputerTo make development board visible in your local network your shouldproperly specify connection properties. In this chapter I will show how toconfigure the host computer (Windows 7 or Linux) to communicate with theFPGA hardware over Ethernet.@note <em>If you also want simultaneous Internet access your host computerrequires a second Ethernet port. I couldn't find workableconfiguration via router.</em>@warning I recommend you to make restore point before you start.@subsection eth_cfgwin Configure Windows HostLet's setup the following network configuration that allows to work withFPGA board and to be connected to Internet. I use different Ethernetports and different subnets (192.168.0.x and 192.168.1.x accordingly).<img src="../doxygen/pics/eth_common.png" alt="Ethernet config">@latexonly {\includegraphics{../doxygen/pics/eth_common.png}} @endlatexonly@par Host IP and subnet definition:-# Open \c cmd console.-# Use \c ipconfig command to determine network settings.</b>@verbatimipconfig /all@endverbatim-# Find your IP address (in my case it's 192.168.1.4)-# Check and change if needed default IP address of SOC as follow.@par Setup hard-reset FPGA IP address:-# Open in editor <i>rocket_soc.vhd</i>.-# Find place where <i>grethaxi</i> module is instantiated.-# Change generic <b>ipaddrh</b> and <b>ipaddrl</b> parameters so thatthey belonged another subnet (Default values: C0A8.0033 correspondingto 192.168.0.51) than Internet connection.@par Configure the Ethernet card for your FPGA hardware-# Load pre-built image file into FPGA board (located in<i>./rocket_soc/bit_files/</i> folder) or use your own one.<br>-# Open <b>Network and Sharing Center</b> via Control Panel<img src="../doxygen/pics/eth_win1.png" alt="ControlPanel">@latexonly {\includegraphics[scale=0.7]{../doxygen/pics/eth_win1.png}} @endlatexonly-# Click on <b>Local Area Connection 2</b> link<img src="../doxygen/pics/eth_win2.png" alt="ControlPanel">@latexonly {\includegraphics{../doxygen/pics/eth_win2.png}} @endlatexonly-# Click on <b>Properties</b> to open properties dialog.<img src="../doxygen/pics/eth_win3.png" alt="ControlPanel">@latexonly {\includegraphics{../doxygen/pics/eth_win3.png}} @endlatexonly-# Disable all network services except <b>Internet Protocol Version 4</b>as shown on figure above.<br>-# Select enabled service and click on <b>Properties</b> button.<img src="../doxygen/pics/eth_win4.png" alt="ControlPanel">@latexonly {\includegraphics{../doxygen/pics/eth_win4.png}} @endlatexonly-# Specify unique IP as shown above so that FPGA and your LocalConnection were placed <b>in the same subnet</b>.<br>-# Leave the subnet mask set to the default value 255.255.255.0.<br>-# Click OK.@par Check connection-# Check presence of the Ethernet activity by blinking LEDs near theEthernet connector on FPGA board-# Run \c arp command to see arp table entries.@verbatimarp -a -v@endverbatim<img src="../doxygen/pics/eth_check1.png" alt="Check arp">@latexonly {\includegraphics{../doxygen/pics/eth_check1.png}} @endlatexonly-# MAC supports only ARP and EDCL requests on hardware level and it cannotrespond on others without properly installed software. By this reason pingwon't work without running OS on FPGA target but it maybe usefull to pingFPGA target so that it can force updating of the ARP table or use thecommands:@verbatimipconfig /releaseipconfig /renew@endverbatim@subsection eth_cfglin_section Configure Linux HostLet's setup the similar network configuration on Linux host.-# Check <b>ipaddrh</b> and <b>ipaddrl</b> values that are hardcodedon top-level of SOC (default values: C0A8.0033 correspondingto 192.168.0.51).-# Set host IP value in the same subnet using the \c ifconfig command.You might need to enter a password to use the \c sudo command.@verbatim% sudo ifconfig eth0 192.168.0.53 netmask 255.255.255.0@endverbatim-# Enter the following command in the shell to check that the changestook effect:@verbatim% ifconfig eth0@endverbatim@subsection eth_appl_section Run ApplicationNow your FPGA board is ready to interact with the host computer via Ethernet.You can find detailed information about MAC (GRETH)in [GRLIB IP Core User's Manual](http://gaisler.com/products/grlib/grip.pdf).There you can find:-# DMA Configuration registers description (Rx/Tx Descriptors tables and entries).-# EDCL message format.-# \c GRLIB itself includes C-example that configure MAC Rx/Tx queuesand start transmission of the 1500 Mbyte of data to define Bitrate in Mbps.We provide debugger functionality via Ethernet.See @link dbg_link Debugger description @endlink page.@section dbg_connect_section Debug session@subsection dbg_connect_1 Plugins interactionCore library uses UDP protocol to communicate with all targets: FPGA orsimulators. The general structure is looking like on the following figure:<img src="../doxygen/pics/dbg_sim.png" alt="sim debug">@latexonly {\includegraphics[scale=0.9]{../doxygen/pics/dbg_sim.png}} @endlatexonlyor with real Hardware<img src="../doxygen/pics/dbg_fpga.png" alt="fpga debug">@latexonly {\includegraphics[scale=0.8]{../doxygen/pics/dbg_fpga.png}} @endlatexonlyGUI plugin uses QT-libraries and interacts with the core library using thetext console input interface. GUI generates the same text commandsthat are available in debugger console for any who's using this debugger.That's why any presented in GUI widgets information can be achievedin console mode.@subsection dbg_connect_2 Start DebuggerWe provide several targets that can run software (bootloader, firmwareor user specific application) without any source code modifications:Start Configuration | Description-------------------------------|-----------------$ ./_run_functional_sim.sh[bat]| Functional RISC-V Full System Model$ ./_run_systemc_sim.sh[bat] | Use SystemC Precise Model of RIVER CPU$ ./_run_fpga_gui.sh[bat] | FPGA board. Default port 'COM3', TAP IP = 192.168.0.51*To run debugger with the real FPGA target connected via Ethernet do:@code# cd rocket_soc/debugger/win32build/debug# _run_functional_sim.bat@endcodeThe result should look like on the picture below:<img src="../doxygen/pics/dbg_gui_start.png" alt="debugger 1-st look">@latexonly {\includegraphics[scale=0.8]{../doxygen/pics/dbg_gui_start.png}} @endlatexonly@par Example of the debug sessionSwitch ON all User LEDs on board:@coderiscv# help -- Print full list of commandsriscv# csr MCPUID -- Read supported ISA extensionsriscv# read 0xfffff000 20 -- Read 20 bytes from PNP moduleriscv# write 0x80000000 4 0xff -- Write into GPIO new LED valueriscv# loadelf helloworld -- Load elf-file to board RAM and run@endcodeConsole mode view<img src="../doxygen/pics/dbg_testhw.png" alt="HW debug example">@latexonly {\includegraphics{../doxygen/pics/dbg_testhw.png}} @endlatexonly@subsection dbg_connect_3 Debug Zephyr OS kernel with symbolsBuild Zephyr kernel from scratch using our patches enabling 64-bits RISC-Varchitecture support:@code$ mkdir zephyr_160$ cd zephyr_160$ git clone https://gerrit.zephyrproject.org/r/zephyr$ cd zephyr$ git checkout tags/v1.6.0$ cp ../../riscv_vhdl/zephyr/v1.6.0-riscv64-base.diff .$ cp ../../riscv_vhdl/zephyr/v1.6.0-riscv64-exten.diff .$ git apply v1.6.0-riscv64-base.diff$ git apply v1.6.0-riscv64-exten.diff@endcodeThen build elf-file:@code$ export ZEPHYR_BASE=/home/zephyr_160/zephyr$ cd zephyr/samples/shell$ make ARCH=riscv64 CROSS_COMPILE=/home/your_path/gnu-toolchain-rv64ima/bin/riscv64-unknown-elf- BOARD=riscv_gnss 2>&1@endcodeLoad debug symbols from elf-file without target reprogramming (or with):@coderiscv# loadelf zephyr.elfriscv# loadelf zephyr.elf nocode@endcode<img src="../doxygen/pics/dbg_gui_symb.png" alt="debugger symbols">@latexonly {\includegraphics[scale=1.0]{../doxygen/pics/dbg_gui_symb.png}} @endlatexonlyNow becomes available the following features:- Stack trace with function names- Function names in Disassembler including additional information forbranch and jump instructions in column \c 'comment'.- Symbol Browser with filter.- Opening Disassembler and Memory Viewer widgets in a new window by name.Debugger provides additional features that could simplify softwaredevelopment:- Clock Per Instruction (CPI) hardware measure- Bus utilization information- Others. List of a new features is constantly increasing.<img src="../doxygen/pics/dbg_fpga_gui1.png" alt="debugger FPGA+GUI">@latexonly {\includegraphics[scale=0.8]{../doxygen/pics/dbg_fpga_gui1.png}} @endlatexonly@section dbg_troubles_section Troubleshooting@subsection dbg_trouble_1 Image Files not foundIf you'll get the error messages that image files not found<img src="../doxygen/pics/dbg_err1.png" alt="File not found">@latexonly {\includegraphics[scale=0.8]{../doxygen/pics/dbg_err1.png}} @endlatexonlyTo fix this problem do the following steps:-# Close debugger console using \c exit command.-# Open <em>config_file_name.json</em> file in any editor.-# Find strings that specify these paths and correct them. Simulatoruses the same images as VHDL platform for ROMs intialization. You can findthem in <em>'rocket_soc/fw_images'</em> directory. After that you shouldsee something like follow:<img src="../doxygen/pics/dbg_simout1.png" alt="Simulator output">@latexonly {\includegraphics[scale=0.8]{../doxygen/pics/dbg_simout1.png}} @endlatexonlyDebug your target. All commands that are available for Real Hardwareabsolutely valid for the Simulation. Users shouldn't see any differencebetween these targets this is our purpose.@subsection dbg_trouble_2 Can't open COM3 when FPGA is used-# Open <em>fpga_gui.json</em>-# Change value <b>['ComPortName','COM3'],</b> on your one(for an example on \c ttyUSB0).@subsection dbg_trouble_3 EDCL: No response. Break read transactionThis error means that host cannot locate board with specified IP address.Before you continue pass through the following checklist:-# You should properly @link eth_link setup network connection @endlinkand see FPGA board in ARP-table.-# If you've changed default FPGA IP address:-# Open <em>_run_fpga_gui.bat (*.sh)</em>-# Change value <b>['BoardIP','192.168.0.51']</b> on your one.-# Run debugger*/
