add dvf2svd

This commit is contained in:
Triss 2022-06-01 16:48:12 +02:00
parent 748b88e71e
commit 356d4841b3
1 changed files with 103 additions and 0 deletions

103
dvf2svd.py Executable file
View File

@ -0,0 +1,103 @@
#!/usr/bin/env python3
import argparse, sys, os
sys.path.append(os.path.dirname(os.path.abspath(__file__))+"/svd")
from dvf import dvfparse
#from svd import svd, svdparse, svdgen
import svd, svdparse, svdgen
from typing import *
WIDTHS = {
dvfparse.Dvf.MCU_78K0: 16,
dvfparse.Dvf.MCU_78K0R: 20,
dvfparse.Dvf.MCU_RL78x1y: 20,
dvfparse.Dvf.MCU_RL78x2y: 20,
}
SERIES = {
# TODO: better categorization in subtypes and stuff
dvfparse.Dvf.MCU_78K0: "78K0(S)",
dvfparse.Dvf.MCU_78K0R: "78K0R",
dvfparse.Dvf.MCU_RL78x1y: "RL78/x1y",
dvfparse.Dvf.MCU_RL78x2y: "RL78/x2y",
}
CPUS = {
# TODO: better categorization in subtypes and stuff
dvfparse.Dvf.MCU_78K0: "78K0(S)",
dvfparse.Dvf.MCU_78K0R: "78K0R",
dvfparse.Dvf.MCU_RL78x1y: "RL78/S[13]",
dvfparse.Dvf.MCU_RL78x2y: "RL78/S3",
}
def conv_per(dvf: dvfparse.Dvf) -> List[svd.SvdPeripheral]:
r=[]
base = 0xFFF00 & ((1<<WIDTHS[dvf.mcutype])-1)
r.append(svd.SvdPeripheral(
name="SFR",
description="Special Function Register space",
baseAddress=base,
registers=[
# fields, properties, widths, etc etc etc are still to be reversed...
svd.SvdRegister(
name=r.name,
addressOffset=(r.address|base)-base
) for r in dvf.sections[dvfparse.DvfSect.SN]
]
))
if dvfparse.DvfSect.ES in dvf.sections: # 78K0 has none
base = 0xF0000
r.append(svd.SvdPeripheral(
name="SFR2",
description="Extended Special Function Register space",
baseAddress=base,
registers=[
svd.SvdRegister(
name=r.name,
addressOffset=(r.address|base)-base
) for r in dvf.sections[dvfparse.DvfSect.ES]
]
))
return r
def conv(dvf: dvfparse.Dvf) -> svd.SvdDevice:
md = dvf.sections[dvfparse.DvfSect.MD][0]
return svd.SvdDevice(
vendor="Renesas",
vendorID="Renesas",
name=dvf.chipname_disp,
series=SERIES[dvf.mcutype],
description=md.version + " " + md.timestamp,
licenseText=dvf.copyright_notice,
addressUnitBits=8,
width=16,#WIDTHS[dvf.mcutype],
cpu=svd.SvdCpu(
name=CPUS[dvf.mcutype],
endian='little',
deviceNumInterrupts=len(dvf.sections[dvfparse.DvfSect.VN]),
),
peripherals=conv_per(dvf),
# TODO: MI to memory map somehow?
)
if __name__ == '__main__':
parser = argparse.ArgumentParser(prog="dvf2h",
description="Convert NEC/Renesas Device "+\
"Files to CMSIS-SVD files")
parser.add_argument('input', type=argparse.FileType('rb'))
#parser.add_argument('output', type=argparse.FileType('w'))
parser.add_argument('output', type=str, default=None)
args = parser.parse_args()
output = sys.stdout if args.output is None else open(args.output, 'w')
try:
dvffile = dvfparse.Dvf.parse(args.input.read())
svdc = conv(dvffile)
svdgen.generate(output, svdc)
finally:
if args.output is not None:
output.close()