antmicro / dts2repl

Apache License 2.0
21 stars 5 forks source link

[Question] How to understand which overlays to use #1

Closed waltergallegog closed 2 years ago

waltergallegog commented 2 years ago

Hello, I was generating a .repl from a .dts for the sensortile_box platform and the hello_world zephyr example.

Initially I tried using the following command

dts2repl --overlays armv7-m <path_to_build>/zephyr/zephyr.dts --output sensortile_box.repl

Then trying to run the elf file resulted in no output in the usart1 analyzer.

Comparing my generated .repl with the one present in renodepedia, I noticed two differences:

  1. My repl file was using uart instead of usart
  2. My repl file was using the rolling-bit script instead of the flipflop one.

Checking the source code of dts2repl, I understood the issue was the missing overlay for the stm32L4.

Using the overlay worked:

dts2repl --overlays stm32l4,armv7-m  ../../zephyr/zephyr/build/zephyr/zephyr.dts --output sensortile_box.repl

Now my question is, how could I understand that I was supposed to use the stm32L4 overlay in the first place? During my initial tests, I did thought of including an overlay of the stm32L4, but in the overlays folder I did not saw any, so I assumed no overlay was required for it.

Is there any rule of thumb you can suggest? (for example, always use overlays for STM platforms )

Is it possible to create a list of all overlays that need to be used, as the overlays in the https://github.com/antmicro/dts2repl/tree/main/dts2repl/overlay folder do not seem to be exhaustive?

Thanks

pgielda commented 2 years ago

Hi @waltergallegog

You are right that you need an overlay to properly generate this board.

This "magic" overlay is due to a "magic" part of the code:

    # compat-based mapping of peripheral models for the following SoCs is not enough
    # as there are ifdefs in the driver; adding a manual map for now as a workaround
    if any(x in overlays for x in ('stm32g4', 'stm32l4', 'stm32wl', 'stm32l0')):
        if compat == "st,stm32-usart":
            compat = "st,stm32-lpuart"
            model = models[compat]

        if compat == "st,stm32-rcc":
            if 'stm32l4' in overlays:
                model = 'Python.PythonPeripheral'
            elif 'stm32l0' in overlays:
                model = 'Miscellaneous.STM32L0_RCC'
            else:
                model = 'Miscellaneous.STM32F4_RCC'

this code is really ugly and there should a better way of doing that but for now it is what it is. The goal is actually to reduce overlays to minimum but some information currently is lacking or does not differentiate things enough for Renode to be able to run the platform. The easy part is if we're just adding stuff (this can be done via files that you pointed to), its worse if we have to patch some matching.

This is definitely on a list for improvement.

waltergallegog commented 2 years ago

Thanks for the feedback @pgielda Ok so when creating new platforms we need to check the code for any overlays used, a not just the list of files. Thankfully the overlays used in the file are not too many.