Plugins Python API » History » Revision 19
Revision 18 (Alexis Jeandet, 21/09/2015 04:39 PM) → Revision 19/21 (Alexis Jeandet, 21/09/2015 04:40 PM)
h1. Plugins Python API All SocExplorer plugins expose some common functions and their own functions to the embedded Python terminal. h2. Common Functions All this functions are either implemented in the base class *socexplorerplugin* or in the plugin itself. They are described with their C++ interface since they are dynamically wrapped in the Python context. To have a better understanding of how the arguments are converted between Python and C++ you can have a look "here":http://pythonqt.sourceforge.net/Developer.html. You can call any of the following methods from any plugin instance; *MyPluginInstance.Method(...)*. Function list: * %{color:green}QVariantList% *[[Plugins_Python_API#Read|Read]]* (%{color:green}unsigned int% address, %{color:green}unsigned int% count); * %{color:blue}void% *[[Plugins_Python_API#Write|Write]]* (%{color:green}unsigned int% address, %{color:green}QList<QVariant>% dataList); * %{color:blue}void% *[[Plugins_Python_API#closeMe|closeMe]]* (); * %{color:blue}void% *[[Plugins_Python_API#activate|activate]]* (%{color:green}bool% flag); * %{color:blue}void% *[[Plugins_Python_API#setInstanceName|setInstanceName]]* (%{color:green}const QString% & newName); * %{color:green}bool% *[[Plugins_Python_API#dumpMemory|dumpMemory]]* (%{color:green}unsigned int% address, %{color:green}unsigned int% count, %{color:green}QString% file); * %{color:green}bool% *[[Plugins_Python_API#dumpMemory2|dumpMemory]]* (%{color:green}unsigned int% address, %{color:green}unsigned int% count, %{color:green}QString% file, %{color:green}const QString% & format); * %{color:green}bool% *[[Plugins_Python_API#memSet|memSet]]* (%{color:green}unsigned int% address, %{color:green}int% value, %{color:green}unsigned int% count); * %{color:green}bool% *[[Plugins_Python_API#loadbin|loadbin]]* (%{color:green}unsigned int% address, %{color:green}QString% file); * %{color:green}bool% *[[Plugins_Python_API#loadfile|loadfile]]* (%{color:green}abstractBinFile% * file); ---- ---- h2(#Read). %{color:green}QVariantList% *Read* (%{color:green}unsigned int% address, %{color:green}unsigned int% count) Reads target memory at given address and return its content. On any root plugin it will read system memory and by default on child plugin it will forward request to parent plugin util it reach root plugin and read system bus. Note that this function could be re-implemented on a child plugin and have a different behavior. The returned list is a *Word* list which means that the smallest data you can read is a word(32 bits) and *count* is the number of words to read. The function respect host endianness so it will convert data depending on target endianness. *See also* %{color:blue}void% *[[Plugins_Python_API#Write|Write]]* (%{color:green}unsigned int% address, %{color:green}QList<QVariant>% dataList); ---- h2(#Write). %{color:blue}void% *Write* (%{color:green}unsigned int% address, %{color:green}QList<QVariant>% dataList) Writes given *datalist* at given *address* in target system bus. On any root plugin it will writes system memory and by default on child plugin it will forward request to parent plugin util it reach root plugin and writes system bus. Note that this function could be re-implemented on a child plugin and have a different behavior. The given list is a Word list which means that the smallest data you can write is a word(32 bits). The function respect host endianness so it will convert data depending on target endianness. *Example:* Let's consider we have a Leon3 with some RAM at 0x40000000 and we want to write 1 2 3 and 0xffffffff. We are connected to the target through *rootplugin* which can be replaced by the plugin are using. <pre><code class="python"> rootplugin.Write(0x40000000,[1,2,3,0xffffffff]) </code></pre> *See also* %{color:green}QVariantList% *[[Plugins_Python_API#Read|Read]]* (%{color:green}unsigned int% address, %{color:green}unsigned int% count); ---- h2(#closeMe). %{color:blue}void% *closeMe* () Closes the plugin. ---- h2(#activate). %{color:blue}void% *activate* (%{color:green}bool% flag) Activates the plugin GUI, this function is called by *SocExplorer* you may not call this function unless you know exactly what you do. By default if the plugin GUI is disabled, it means that the root plugin isn't connected to the target and that any operation on child plugin are forbidden. ---- h2(#setInstanceName). %{color:blue}void% *setInstanceName* (%{color:green}const QString% & newName) This method will be removed from python context since it may not be used from python terminal. ---- h2(#dumpMemory). %{color:green}bool% *dumpMemory* (%{color:green}unsigned int% address, %{color:green}unsigned int% count, %{color:green}QString% file) Dumps the memory content at given *address* in given *file*. As for *[[Plugins_Python_API#Read|Read]]* method it will read memory word by word and it will handle host and target endianness. The data will be written in ascii with the following format: 0x40000000: 0xad4c0136 0x40000004: 0x665b89c0 0x40000008: 0xabc04748 0x4000000c: 0x8e110724 Where left column is address and right column is the corresponding data word. *Example:* One interesting usage of this method is to dump memory space while your system is running to see if some memory space got get modified. In this example we will load an elf file containing an executable to a Leon3 target through the AHBUARTplugin and dump the first 16 bytes before and after execution and compare them. We also assume that the device is attached to *ttyUSB0*. <pre><code class="python"> proxy.loadSysDriver("AHBUARTplugin","AHBUARTplugin0") proxy.loadSysDriverToParent("dsu3plugin","dsu3plugin0",AHBUARTplugin0) AHBUARTplugin0.open("/dev/ttyUSB0",3000000) dsu3plugin0.openFile("/somePath/someElfFile") dsu3plugin0.flashTarget() AHBUARTplugin0.dumpMemory(0x40000000,16,"/somePath/First_dump.txt") dsu3plugin0.run() waitSomeTime() # You can wait or process something or do whatever you want AHBUARTplugin0.dumpMemory(0x40000000,16,"/somePath/Second_dump.txt") </code></pre> Then you can for example diff your two files: <pre><code class="bash"> diff -u /somePath/First_dump.txt /somePath/Second_dump.txt </code></pre> *See also* %{color:green}bool% *[[Plugins_Python_API#dumpMemory|dumpMemory]]* (%{color:green}unsigned int% address, %{color:green}unsigned int% count, %{color:green}QString% file, %{color:green}const QString% & format); ---- h2(#dumpMemory2). %{color:green}bool% *dumpMemory* (%{color:green}unsigned int% address, %{color:green}unsigned int% count, %{color:green}QString% file, %{color:green}const QString% & format) This function behaves like %{color:green}bool% *[[Plugins_Python_API#dumpMemory|dumpMemory]]* (%{color:green}unsigned int% address, %{color:green}unsigned int% count, %{color:green}QString% file) except that it allows you to set output file format. Possible format are "srec", "bin" and "hexa". *See also* %{color:green}bool% *[[Plugins_Python_API#dumpMemory2|dumpMemory]]* (%{color:green}unsigned int% address, %{color:green}unsigned int% count, %{color:green}QString% file, %{color:green}const QString% & format); ---- h2(#memSet). %{color:green}bool% *memSet* (%{color:green}unsigned int% address, %{color:green}int% value, %{color:green}unsigned int% count) Sets memory space with given *value* at given *address*, as for *[[Plugins_Python_API#Write|Write]]* method it will write memory word by word and it will handle host and target endianness. *Example:* In this example we will first clear memory from 0x40000000 to 0x4000000C and then we will write 0x1234 from 0x40000010 to 0x4000002C <pre><code class="python"> proxy.loadSysDriver("AHBUARTplugin","AHBUARTplugin0") AHBUARTplugin0.open("/dev/ttyUSB0",3000000) AHBUARTplugin0.memSet(0x40000000,0,4) AHBUARTplugin0.memSet(0x40000010,0x1234,8) </code></pre> ---- h2(#loadbin). %{color:green}bool% *loadbin* (%{color:green}unsigned int% address, %{color:green}QString% file) ---- h2(#loadfile). %{color:green}bool% *loadfile* (%{color:green}abstractBinFile% * file) ----