sifive / cmsis-svd-generator

Generates CMSIS-SVD xml files from DTS info and Register templates
Apache License 2.0
9 stars 4 forks source link

Am I using `generate_svd.py` correctly? #15

Open U007D opened 3 years ago

U007D commented 3 years ago

When I run ./generate_svd.py -d ~/Development/3rd_party/torvalds/linux/arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts -o ../sifive-unleashed.svd (https://github.com/torvalds/linux.git repo master branch).

the tool rejects the # from #include on line 4:

Traceback (most recent call last):
  File "/Users/sergibli/Development/bg/sifive-riscv/cmsis-svd-generator/./generate_svd.py", line 139, in <module>
    main(sys.argv[1:])
  File "/Users/sergibli/Development/bg/sifive-riscv/cmsis-svd-generator/./generate_svd.py", line 132, in main
    dts = pydevicetree.Devicetree.parseFile(parsed_args.dts, followIncludes=True)
  File "/Users/sergibli/Library/Python/3.9/lib/python/site-packages/pydevicetree/ast/node.py", line 468, in parseFile
    return parseTree(contents, dirname, followIncludes)
  File "/Users/sergibli/Library/Python/3.9/lib/python/site-packages/pydevicetree/source/parser.py", line 185, in parseTree
    return Devicetree(parseElements(dts, pwd, followIncludes))
  File "/Users/sergibli/Library/Python/3.9/lib/python/site-packages/pydevicetree/source/parser.py", line 177, in parseElements
    elements = grammar.devicetree.parseString(dts, parseAll=True)
  File "/usr/local/lib/python3.9/site-packages/pyparsing.py", line 1955, in parseString
    raise exc
  File "/usr/local/lib/python3.9/site-packages/pyparsing.py", line 3814, in parseImpl
    raise ParseException(instring, loc, self.errmsg, self)
pyparsing.ParseException: Expected end of text, found '#'  (at char 88), (line:4, col:1)

I'm new to these tools--any tips?

U007D commented 3 years ago

To put the question more simply, can cmsis-svd-generator generate an .svd from, for example, https://github.com/torvalds/linux/blob/master/arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts?

U007D commented 3 years ago

cpp -nostdinc -I include -I arch -undef -x assembler-with-cpp arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts hifive-unmatched-a00.dts.preprocessed generated a "preprocessed" dts file (and warnings--more below).

This file was also unsuitable for cmsis-svd-generator, but a little more digging found the device tree compiler dtc: dtc -I dts -O dts hifive-unmatched-a00.dts.preprocessed -o hifive-unmatched-a00.dts

This yielded a (postprocessed?) .dts file which was suitable for cmsis-svd-generator:

▶ ./cmsis-svd-generator/generate_svd.py -d hifive-unmatched-a00.dts -o hifive-unmatched-a00.svd
Generating CMSIS SVD file for 'SiFive HiFive Unmatched' model

The tool seemed to work but the peripherals section of the resulting .svd file is empty:

<?xml version="1.0" encoding="utf-8"?>  
  <device schemaVersion="1.3" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="CMSIS-SVD.xsd">
  <name>SiFive HiFive Unmatched</name>
<version>0.1</version>  
  <description>From SiFive HiFive Unmatched,model device generator</description>  
  <addressUnitBits>8</addressUnitBits>  
  <width>32</width>  
  <size>32</size>  
  <access>read-write</access>  
  <peripherals>  
  </peripherals>  
</device>  

Notes:
* The `.dts` and `.dts.processed` files are on the order of 15KB, but the `.svd` is only \~400B.
* `dtc` emits several warnings, but runs to completion:

`hifive-unmatched-a00.dts: Warning (interrupt_provider): /cpus/cpu@0/interrupt-controller: Missing #address-cells in interrupt provider  
`hifive-unmatched-a00.dts: Warning (interrupt_provider): /cpus/cpu@1/interrupt-controller: Missing #address-cells in interrupt provider  
`hifive-unmatched-a00.dts: Warning (interrupt_provider): /cpus/cpu@2/interrupt-controller: Missing #address-cells in interrupt provider  
`hifive-unmatched-a00.dts: Warning (interrupt_provider): /cpus/cpu@3/interrupt-controller: Missing #address-cells in interrupt provider  
`hifive-unmatched-a00.dts: Warning (interrupt_provider): /cpus/cpu@4/interrupt-controller: Missing #address-cells in interrupt provider  
`hifive-unmatched-a00.dts: Warning (interrupt_provider): /soc/i2c@10030000/pmic@58: Missing #interrupt-cells in interrupt provider  
`hifive-unmatched-a00.dts: Warning (interrupt_provider): /soc/i2c@10030000/pmic@58: Missing #address-cells in interrupt provider  
`hifive-unmatched-a00.dts: Warning (interrupt_provider): /soc/gpio@10060000: Missing #address-cells in interrupt provider

If anyone has ideas on what I could be doing wrong, I'd be grateful for a suggestion.