Class: SWD_DEBUG_PORT
- Inherits:
-
Object
- Object
- SWD_DEBUG_PORT
- Defined in:
- lib/HardsploitAPI/SWD/HardsploitAPI_SWD_DEBUG.rb
Overview
Hardsploit API - By Opale Security
www.opale-security.com || www.hardsploit.io
License: GNU General Public License v3
License URI: http://www.gnu.org/licenses/gpl.txt
Instance Method Summary collapse
- #abort(orunerr, wdataerr, stickyerr, stickycmp, dap) ⇒ Object
- #control(trnCount = 0, trnMode = 0, maskLane = 0, orunDetect = 0) ⇒ Object
- #getAPI ⇒ Object
- #idcode ⇒ Object
-
#initialize(hardAPI) ⇒ SWD_DEBUG_PORT
constructor
A new instance of SWD_DEBUG_PORT.
- #readAP(apsel, address) ⇒ Object
- #readRB ⇒ Object
- #select(apsel, apbank) ⇒ Object
- #status ⇒ Object
- #writeAP(apsel, address, data) ⇒ Object
Constructor Details
#initialize(hardAPI) ⇒ SWD_DEBUG_PORT
Returns a new instance of SWD_DEBUG_PORT.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/HardsploitAPI/SWD/HardsploitAPI_SWD_DEBUG.rb', line 10 def initialize(hardAPI) @HardAPI = hardAPI @HardAPI.startFPGA sleep(0.5) @HardAPI.resetSWD # read the IDCODE # if HardAPI.resetSWD() != 0x1ba01477 then # raise "warning: unexpected idcode" # else # puts "MCU DETECTED" # end abort(1,1,1,1,1) select(0,0) # power shit up puts "Power shit up" @HardAPI.writeSWD(FALSE, 1, 0x54000000) if (status() >> 24) != 0xF4 then raise "error powering up system" exit(0) else puts "POWERING UP SYTEM OK" end #get the SELECT register to a known state select(0,0) @curAP = 0 @curBank = 0 end |
Instance Method Details
#abort(orunerr, wdataerr, stickyerr, stickycmp, dap) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/HardsploitAPI/SWD/HardsploitAPI_SWD_DEBUG.rb', line 46 def abort (orunerr, wdataerr, stickyerr, stickycmp, dap) value = 0x00000000 (orunerr ? value |= 0x10 : value |= 0x00) (wdataerr ? value |= 0x08 : value |= 0x00) (stickyerr ? value |= 0x04 : value |= 0x00) (stickycmp ? value |= 0x02 : value |= 0x00) (dap ? value |= 0x01 : value |= 0x00) @HardAPI.writeSWD(FALSE, 0, value) end |
#control(trnCount = 0, trnMode = 0, maskLane = 0, orunDetect = 0) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/HardsploitAPI/SWD/HardsploitAPI_SWD_DEBUG.rb', line 61 def control (trnCount = 0, trnMode = 0, maskLane = 0, orunDetect = 0) value = 0x54000000 value = value | ((trnCount & 0xFFF) << 12) value = value | ((maskLane & 0x00F) << 8) value = value | ((trnMode & 0x003) << 2) (orunDetect ? value |= 0x01 : value |= 0x00) @HardAPI.writeSWD(False, 1, value) end |
#getAPI ⇒ Object
38 39 40 |
# File 'lib/HardsploitAPI/SWD/HardsploitAPI_SWD_DEBUG.rb', line 38 def getAPI return @HardAPI end |
#idcode ⇒ Object
42 43 44 |
# File 'lib/HardsploitAPI/SWD/HardsploitAPI_SWD_DEBUG.rb', line 42 def idcode return @HardAPI.readSWD(FALSE, 0) end |
#readAP(apsel, address) ⇒ Object
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/HardsploitAPI/SWD/HardsploitAPI_SWD_DEBUG.rb', line 81 def readAP ( apsel, address) adrBank = (address >> 4) & 0xF adrReg = (address >> 2) & 0x3 if apsel != @curAP or adrBank != @curBank then select(apsel, adrBank) @curAP = apsel @curBank = adrBank end return @HardAPI.readSWD(TRUE, adrReg) end |
#readRB ⇒ Object
78 79 80 |
# File 'lib/HardsploitAPI/SWD/HardsploitAPI_SWD_DEBUG.rb', line 78 def readRB return @HardAPI.readSWD(FALSE, 3) end |
#select(apsel, apbank) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/HardsploitAPI/SWD/HardsploitAPI_SWD_DEBUG.rb', line 70 def select (apsel, apbank) value = 0x00000000 value = value | ((apsel & 0xFF) << 24) value = value | ((apbank & 0x0F) << 4) @HardAPI.writeSWD(FALSE, 2, value) end |
#status ⇒ Object
56 57 58 59 |
# File 'lib/HardsploitAPI/SWD/HardsploitAPI_SWD_DEBUG.rb', line 56 def status val= @HardAPI.readSWD(FALSE,1) return val end |
#writeAP(apsel, address, data) ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/HardsploitAPI/SWD/HardsploitAPI_SWD_DEBUG.rb', line 92 def writeAP (apsel, address, data) adrBank = (address >> 4) & 0xF adrReg = (address >> 2) & 0x3 if apsel != @curAP or adrBank != @curBank then select(apsel, adrBank) @curAP = apsel @curBank = adrBank end @HardAPI.writeSWD(TRUE, adrReg, data) end |