litex icon indicating copy to clipboard operation
litex copied to clipboard

RFC: refactor devicetree (DTS) generation (draft)

Open AndrewD opened this issue 9 months ago • 4 comments

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 from litex.tools.litex_json2dts_zephyr into a common json2dts module: maybe litex.tools.json2dts
  • [x] add dts helpers get_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. use soc.add_constant() to inject constants with a prefix of "{name}of" to provide some required dts information, for example soc.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 to reader in dts 1. be consistent: use either block2mem or reader in both soc and dts, or 2, add an optional alias 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

AndrewD avatar May 21 '24 04:05 AndrewD