litex
litex copied to clipboard
RFC: refactor devicetree (DTS) generation (draft)
Current status
The current state of litex_json2dts_linux.py
is just enough to generate a DTS for {linux_on_litex_vexriscv,rocket} with some of the standard devices, however it is hardcoded to just the standard litex peripherals with linux drivers and does not cater for other litex cores in separate git modules or custom peripherals. Some devices are only partially supported with mostly hard coded configuration, eg custom instances of gpio for leds and pwm for rgb_led.
Motivation
To generalise the dts to cater for standard peripherals in a generic way and also support additional peripherals.
Proposal
- [ ] Move some generic
dts
functions fromlitex.tools.litex_json2dts_zephyr
into a commonjson2dts
module: maybelitex.tools.json2dts
- [x] add
dts
helpersget_csr_regions_of()
get_mem_regions_of()
to extract regions from csr_bases (csr_base size by parsing car_registers) and memories. - [ ] maybe move the generic
dts
functions into a JSON2DTS class - [x] improve handling of
levels
for indentation to support the linux dts - [x] start to use generic
dts
functions in litex.tools.litex_json2dts_linux - [x] add
of
related metadata to the soc 1. usesoc.add_constant()
to inject constants with a prefix of "{name}of" to provide some required dts information, for examplesoc.add_constant(name + "_of_compatible", "litex,timer")
(prototyped), OR 2. add a dts specific dictionary to the soc and write this into csr.json. Some dts names such as#gpio-cells
don't suit also being generated into c#defines
- [x] fix linux dts schema validation warnings, eg #1905
- [ ] fix inconsistencies between soc and device tree, eg
sdcard_block2mem
in soc translated toreader
in dts 1. be consistent: use eitherblock2mem
orreader
in bothsoc
anddts
, or 2, add an optionalalias
attribute for csr_regions and mem_regions that can be supplied by the soc.
Status
I have some work in progress that implements the checked items above (using soc.add_constant
) and can generate device tree entries for simple peripherals.
TODO
- [ ] DRAFT PR for discussion