Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script for generating SVD and C-headers #25

Merged
merged 46 commits into from
Aug 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
1169dbf
Add: scripts to scan ghidra generated source
Yangff Jul 19, 2021
ba0d3ce
library to interactively generate SVD and C-header
Yangff Jul 19, 2021
79f076d
Add: Manually extracted reg defines for mdm and partially agc, based …
Yangff Jul 19, 2021
0b8f6ce
reg maps generated by the scripts
Yangff Jul 19, 2021
1e6cbfb
Parse CEVA style comment to generate reg map
Yangff Jul 19, 2021
8505639
Support for interruption
Yangff Jul 19, 2021
ac07f8d
add missing header from latest sdk
Yangff Jul 20, 2021
24b868f
add another missing header
Yangff Jul 20, 2021
4b1e950
add other registers
Yangff Jul 20, 2021
6aa398a
support Bouffalolab style comment
Yangff Jul 20, 2021
1c4c454
generate headers
Yangff Jul 20, 2021
ad259d9
add gain regs
Yangff Jul 20, 2021
07078da
add agc_config code for scan
Yangff Jul 21, 2021
5a49ad2
scan agc
Yangff Jul 21, 2021
d5db576
allow duplicate field for better scanning
Yangff Jul 21, 2021
6c6e5c7
should not mix @breif and @name for alios style and Bouffalolab
Yangff Jul 21, 2021
dd21c20
fix problem with different style header
Yangff Jul 21, 2021
da5ccc9
update agc.h result
Yangff Jul 21, 2021
ada7467
update header format
Yangff Jul 21, 2021
347e5c0
fix dup name
Yangff Jul 21, 2021
2414e04
return field after added
Yangff Jul 21, 2021
cdc3eb9
add more reg from phy_bl602.o
Yangff Jul 21, 2021
45e4118
update mdm.h with regs found in phy_bl602.o
Yangff Jul 21, 2021
42c4e98
add missing bit
Yangff Jul 21, 2021
f15b976
add bit
Yangff Jul 21, 2021
974fe26
add missing rxndpnstsmax
Yangff Jul 21, 2021
d18fd82
support parse bl svd file and find reg with addr and mask
Yangff Jul 22, 2021
5f58860
add bz_phyfunc
Yangff Jul 22, 2021
ec27cd6
add bz_phy.h
Yangff Jul 22, 2021
0dc58f2
add support for 0x
Yangff Jul 22, 2021
dc056a2
format fix
Yangff Jul 22, 2021
5f5e117
more stable name
Yangff Jul 23, 2021
833e83c
add extra information from DWARF
Yangff Jul 24, 2021
ca4abf8
add extra names
Yangff Jul 24, 2021
a3a7308
import other DWARF info and done
Yangff Jul 24, 2021
f2b7fc3
padding to 32
Yangff Jul 24, 2021
d992280
done
Yangff Jul 24, 2021
5cad578
put irqmacccatimeouten as field name
Yangff Jul 24, 2021
0d958c1
fix agc
Yangff Jul 24, 2021
b2ffe27
add scanner for new sources
Yangff Jul 26, 2021
a723f9d
add new sources
Yangff Jul 26, 2021
7898731
update scan result
Yangff Jul 26, 2021
fb1efea
add svd argument
Yangff Jul 26, 2021
ae66bdf
add generated svds
Yangff Jul 26, 2021
f1ea6bd
add scanner for rf
Yangff Jul 26, 2021
47933fa
add fixed svd file, fix reg name bug in svd2c
Yangff Jul 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
support parse bl svd file and find reg with addr and mask
  • Loading branch information
Yangff committed Jul 22, 2021
commit d18fd82f80ccc329a1d24e0c663c8bba5e6d60e0
55 changes: 34 additions & 21 deletions script/manualext.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/usr/bin/env python3
from reglib import *
from typing import Mapping

peris :Mapping[str, peripheral] = {}

############ MDM

Peripheral(peripheral('mdm', 0x44c00000, 0x4000))
peris['mdm'] = Peripheral(peripheral('mdm', 0x44c00000, 0x4000))

Reg('txchan', 0x44c00824)
Field('txcbwmax', 0xfcffffff) # Channel bandwidth
Expand Down Expand Up @@ -92,16 +95,13 @@
Reg('r874', 0x44c00874)
Field('resetto1', 0xf7ffffff)
Field('set1beforewriteagcmem', 0xdfffffff)

open('../src/include/phy/mdm.h', 'w').write('\n'.join(GenHeader()))
#print('\n'.join(GenSVD()))



############# AGC


Peripheral(peripheral('agc', 0x44c0b000, 0x2000))
peris['agc'] = Peripheral(peripheral('agc', 0x44c0b000, 0x2000))
Reg('r000', 0x44c0b000)
FieldBit('iqcomp', 31-10)

Expand Down Expand Up @@ -172,15 +172,15 @@ def scan_write(code):
"write_volatile_4(DAT_44c0b110,uVar4 & 0xfffffffd);",
"write_volatile_4(DAT_44c0b110,uVar4 & 0xfffffffe);",
])
open('../src/include/phy/agc.h', 'w').write('\n'.join(GenHeader()))
#open('../src/include/phy/agc.h', 'w').write('\n'.join(GenHeader()))
#print('\n'.join(GenHeader()))
#print('\n'.join(GenSVD()))


Peripheral(peripheral('agcram', 0x54c0a000, 0x800))
peris['agcram'] = Peripheral(peripheral('agcram', 0x54c0a000, 0x800))
Buf('agcram', 0x54c0a000, 0x54c0a800 - 4)

open('../src/include/phy/agcram.h', 'w').write('\n'.join(GenHeader()))
#open('../src/include/phy/agcram.h', 'w').write('\n'.join(GenHeader()))
#print('\n'.join(GenHeader()))
#print('\n'.join(GenSVD()))
#
Expand Down Expand Up @@ -215,23 +215,23 @@ def getregs(fname, pattern='name'):



Peripheral(peripheral('mac_core', 0x44b00000, 0x1000))
peris['mac_core'] = Peripheral(peripheral('mac_core', 0x44b00000, 0x1000))

for code, offset in getregs("../components/bl602/bl602_wifidrv/bl60x_wifi_driver/reg_mac_core.h", pattern='brief'):
RegFromComment(offset + 0x44b00000, code)

open('../src/include/phy/mac_core.h', 'w').write('\n'.join(GenHeader()))
#open('../src/include/phy/mac_core.h', 'w').write('\n'.join(GenHeader()))
#print('\n'.join(GenHeader()))
#print('\n'.join(GenSVD()))


Peripheral(peripheral('mac_pl', 0x44b08000, 0x1000))
peris['mac_pl'] = Peripheral(peripheral('mac_pl', 0x44b08000, 0x1000))

for code, offset in getregs("../alios/mac_pl.h"):
RegFromComment(offset + 0x44b00000, code)


open('../src/include/phy/mac_pl.h', 'w').write('\n'.join(GenHeader()))
#open('../src/include/phy/mac_pl.h', 'w').write('\n'.join(GenHeader()))
#print('\n'.join(GenHeader()))
#print('\n'.join(GenSVD()))

Expand All @@ -242,7 +242,7 @@ def getregs(fname, pattern='name'):
## look txl_payload_handle_backup for more info
####

Peripheral(peripheral('dma', 0x44a00000, 0x1000))
peris['dma'] = Peripheral(peripheral('dma', 0x44a00000, 0x1000))

Reg('status', 0x44a00024)
Field("TX", 0x1f)
Expand Down Expand Up @@ -278,13 +278,13 @@ def getregs(fname, pattern='name'):
Reg('LinkListItem1', 0x44a000ac)
FieldBit("lli", 0, 16)

open('../src/include/phy/dma.h', 'w').write('\n'.join(GenHeader()))
#open('../src/include/phy/dma.h', 'w').write('\n'.join(GenHeader()))
#print('\n'.join(GenHeader()))
#print('\n'.join(GenSVD()))

############# sysctrl

Peripheral(peripheral('sysctrl', 0x44900000, 0x1000))
peris['sysctrl'] = Peripheral(peripheral('sysctrl', 0x44900000, 0x1000))
Reg('time', 0x44900084)
FieldBit('time_greater_on_bit12', 0)
Reg("sysctrl_r68", 0x44900068) # set to 0x8000000c for init
Expand All @@ -298,28 +298,41 @@ def getregs(fname, pattern='name'):

Reg("r074", 0x44900068) # set to b09

open('../src/include/phy/sysctrl.h', 'w').write('\n'.join(GenHeader()))
#open('../src/include/phy/sysctrl.h', 'w').write('\n'.join(GenHeader()))
#print('\n'.join(GenHeader()))
#print('\n'.join(GenSVD()))


############# Wifi Regs 92
## wtf is this???

Peripheral(peripheral('sysctrl92', 0x44920000, 0x1000))
peris['sysctrl92'] = Peripheral(peripheral('sysctrl92', 0x44920000, 0x1000))
Reg("set5010001f", 0x44920004)

open('../src/include/phy/sysctrl92.h', 'w').write('\n'.join(GenHeader()))
#open('../src/include/phy/sysctrl92.h', 'w').write('\n'.join(GenHeader()))
#print('\n'.join(GenHeader()))
#print('\n'.join(GenSVD()))


############# Wifi IPC (EMB/Core)
Peripheral(peripheral('ipc', 0x44800000, 0x1000))
peris['ipc'] = Peripheral(peripheral('ipc', 0x44800000, 0x1000))

for code, offset in getregs("../components/bl602/bl602_wifidrv/bl60x_wifi_driver/reg_ipc_app.h", pattern='brief'):
RegFromComment(offset + 0x44800000, code)

open('../src/include/phy/ipc.h', 'w').write('\n'.join(GenHeader()))
#open('../src/include/phy/ipc.h', 'w').write('\n'.join(GenHeader()))
#print('\n'.join(GenHeader()))
#print('\n'.join(GenSVD()))
#print('\n'.join(GenSVD()))

if __name__ == '__main__':
import sys
if len(sys.argv) == 1:
for p_name, p in peris.items():
open(f"../src/include/phy/{p_name}.h", "w").write("\n".join(p.genHeader()))
else:
if len(sys.argv) >= 2:
addr = int(sys.argv[1], 16)
mask = 0
if len(sys.argv) == 3:
mask = int(sys.argv[2], 16)
print(CAccess(peris, addr, mask))
18 changes: 18 additions & 0 deletions script/reglib.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,24 @@ def HasField(addr):
return context.r.hasField(addr)
print("You are not in any register")

def CAccess(peris, addr, mask):
for p_name, p in peris.items():
if p.base <= addr and p.base + p.size >= addr:
r = p.findReg(addr)
if r:
if r.fields:
if mask == 0:
return f"{p_name.upper()}->{r.name}.value"
else:
f = r.hasField(mask)
if f:
return f"{p_name.upper()}->{r.name}.{f.name}"
else:
return f"({p_name.upper()}->{r.name}.value) & {hex(mask)}"
else:
return f"{p_name.upper()}->{r.name}"


def RegFromComment(addr, comment:str):
name = ""
import re
Expand Down
45 changes: 45 additions & 0 deletions script/svd2c.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python3
import xml.etree.ElementTree as ET
from reglib import *
from typing import Mapping

peris :Mapping[str, peripheral] = {}

import pickle, os
if os.path.exists("./peris.cache"):
peris = pickle.load(open("./peris.cache", "rb"))
else:
tree = ET.parse('../components/bl602/bl602_std/bl602_std/Device/Bouffalo/BL602/Peripherals/soc602_reg.svd')

root = tree.getroot()

for p in root.iter('peripheral'):
p_name = p.find('name').text
baseAddress = int(p.find('baseAddress').text, 16)
addressSize = int(p.find('./addressBlock/size').text, 16)

pp = Peripheral(peripheral(p_name, baseAddress, addressSize))
for r in p.iter('register'):
r_name = r.find('name').text
r_offset = int(r.find('addressOffset').text, 16)
Reg(r_name, r_offset + baseAddress)
for f in p.iter('field'):
f_name = f.find('name').text
lsb = int(f.find('lsb').text)
msb = int(f.find('msb').text)
FieldBit(f_name, lsb, msb - lsb + 1)
peris[p_name] = pp
pickle.dump(peris, open("./peris.cache", "wb"))

if __name__ == '__main__':
import sys
if len(sys.argv) == 1:
for p_name, p in peris.items():
open(f"../src/include/soc/{p_name}.h", "w").write("\n".join(p.genHeader()))
else:
if len(sys.argv) >= 2:
addr = int(sys.argv[1], 16)
mask = 0
if len(sys.argv) == 3:
mask = int(sys.argv[2], 16)
print(CAccess(peris, addr, mask))