Skip to content

Commit 9ab8fb8

Browse files
committed
Moving towards a model where the svd file is processed at startup.
1 parent fe4c8f4 commit 9ab8fb8

File tree

507 files changed

+457
-8
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

507 files changed

+457
-8
lines changed

Makefile

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
all:
22
make -C darm
3-
make -C soc
3+
4+
svdtest:
5+
make -C vendor $@
46

57
clean:
68
-rm *.pyc
79
-rm target/*.pyc
810
make -C darm $@
9-
make -C soc $@
11+
make -C vendor $@

mk/svd2py.mk

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11

2-
SVD2PY = $(TOP)/tools/svd2py
3-
PATCH = patch
2+
SVD2PY = $(TOP)/svd2py2
43

54
PY_FILES = $(patsubst %, %.py, $(FILES))
65

76
%.py: ./svd/%.svd.gz
8-
@echo "[svd2py]" $*
7+
@echo "[svd2py2]" $*
98
@$(SVD2PY) $< $@
10-
@if [ -e $*.patch ]; then $(PATCH) -i $*.patch -b --suffix .original; fi;
119

12-
all: $(PY_FILES)
10+
svdtest: $(PY_FILES)
1311

1412
clean:
1513
-rm *.pyc

soc.py

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# -----------------------------------------------------------------------------
2+
"""
3+
4+
SoC Object
5+
6+
Takes an SVD file, parses it, and then re-expresses it as a python object
7+
that matches the requirements of pycs. Typically the resulting data structures
8+
will need some vendor/device specific tweaking to make up for things in the svd
9+
file that are missing or wrong. These tweaks are done by the vendor specific SoC
10+
code.
11+
12+
Note: The str() functions are setup so printing the structures will produce
13+
*.py code to represent the structures. This is useful for debugging svd contents.
14+
15+
"""
16+
# -----------------------------------------------------------------------------
17+
18+
import svd
19+
20+
# -----------------------------------------------------------------------------
21+
22+
def attribute_string(s):
23+
if s is None:
24+
return 'None'
25+
return "'%s'" % s
26+
27+
# -----------------------------------------------------------------------------
28+
29+
class cpu(object):
30+
31+
def __init__(self, cpu):
32+
# this is more or less a straight copy of the cpu info from the svd file
33+
if cpu is None:
34+
return
35+
self.name = cpu.name
36+
self.revision = cpu.revision
37+
self.endian = cpu.endian
38+
self.mpuPresent = cpu.mpuPresent
39+
self.fpuPresent = cpu.fpuPresent
40+
self.fpuDP = cpu.fpuDP
41+
self.icachePresent = cpu.icachePresent
42+
self.dcachePresent = cpu.dcachePresent
43+
self.itcmPresent = cpu.itcmPresent
44+
self.dtcmPresent = cpu.dtcmPresent
45+
self.vtorPresent = cpu.vtorPresent
46+
self.nvicPrioBits = cpu.nvicPrioBits
47+
self.vendorSystickConfig = cpu.vendorSystickConfig
48+
self.deviceNumInterrupts = cpu.deviceNumInterrupts
49+
50+
def __str__(self):
51+
s = []
52+
s.append('cpu = soc.cpu(None)')
53+
s.append('cpu.name = %s' % attribute_string(self.name))
54+
s.append('cpu.revision = %s' % attribute_string(self.revision))
55+
s.append('cpu.endian = %s' % attribute_string(self.endian))
56+
s.append('cpu.mpuPresent = %s' % self.mpuPresent)
57+
s.append('cpu.fpuPresent = %s' % self.fpuPresent)
58+
s.append('cpu.fpuDP = %s' % self.fpuDP)
59+
s.append('cpu.icachePresent = %s' % self.icachePresent)
60+
s.append('cpu.dcachePresent = %s' % self.dcachePresent)
61+
s.append('cpu.itcmPresent = %s' % self.itcmPresent)
62+
s.append('cpu.dtcmPresent = %s' % self.dtcmPresent)
63+
s.append('cpu.vtorPresent = %s' % self.vtorPresent)
64+
s.append('cpu.nvicPrioBits = %s' % self.nvicPrioBits)
65+
s.append('cpu.vendorSystickConfig = %s' % self.vendorSystickConfig)
66+
s.append('cpu.deviceNumInterrupts = %s' % self.deviceNumInterrupts)
67+
return '\n'.join(s)
68+
69+
# -----------------------------------------------------------------------------
70+
71+
class device(object):
72+
73+
def __init__(self):
74+
pass
75+
76+
def read_svd(self, svdpath):
77+
self.svdpath = svdpath
78+
svd_device = svd.parser(self.svdpath).parse()
79+
# general device information
80+
self.vendor = svd_device.vendor
81+
self.name = svd_device.name
82+
self.description = svd_device.description
83+
self.series = svd_device.series
84+
self.version = svd_device.version
85+
# cpu information
86+
self.cpu = cpu(svd_device.cpu)
87+
88+
def __str__(self):
89+
s = []
90+
s.append('import soc')
91+
s.append('%s\n' % self.cpu)
92+
s.append('device = soc.device()')
93+
s.append('device.svdpath = %s' % attribute_string(self.svdpath))
94+
s.append('device.vendor = %s' % attribute_string(self.vendor))
95+
s.append('device.name = %s' % attribute_string(self.name))
96+
s.append('device.description = %s' % attribute_string(self.description))
97+
s.append('device.series = %s' % attribute_string(self.series))
98+
s.append('device.version = %s' % attribute_string(self.version))
99+
s.append('device.cpu = cpu')
100+
# inception!
101+
s.append("print('%s') % device")
102+
return '\n'.join(s)
103+
104+
# -----------------------------------------------------------------------------

0 commit comments

Comments
 (0)