Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DTS zephyr updates #1974

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions litex/tools/litex_json2dts_zephyr.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def indent(line, levels=1):


def indent_all(text, levels=1):
return '\n'.join(map(indent, text.splitlines()))
return '\n'.join([indent(line, levels) for line in text.splitlines()])


def indent_all_but_first(text, levels=1):
Expand All @@ -66,38 +66,37 @@ def dts_close():
return "};\n"


def dts_intr(name, csr):
return indent("interrupts = <{} 0>;\n".format(
hex(csr['constants'][name + '_interrupt'])
))
def dts_intr(name, csr, levels=1):
irq = csr['constants'].get(name + '_interrupt', None)
return indent(f"interrupts = <{irq} 0>;\n" if irq else "", levels)


def dts_reg(regs):
def dts_reg(regs, levels=1):
dtsi = 'reg = <'

formatted_registers = '\n'.join(
formatted_registers = '>,\n<'.join(
'0x{:x} 0x{:x}'.format(reg['addr'], reg['size'])
for reg in regs
)

dtsi += indent_all_but_first(formatted_registers)
dtsi += indent_all_but_first(formatted_registers, 1)
dtsi += '>;'

return indent_all(dtsi) + '\n'
return indent_all(dtsi, levels) + '\n'


def dts_reg_names(regs):
def dts_reg_names(regs, levels=1):
dtsi = 'reg-names = '

formatted_registers = ',\n'.join(
'"{}"'.format(reg['name'])
for reg in regs
)

dtsi += indent_all_but_first(formatted_registers)
dtsi += indent_all_but_first(formatted_registers, 1)
dtsi += ';'

return indent_all(dtsi) + '\n'
return indent_all(dtsi, levels) + '\n'


# DTS handlers
Expand Down
Loading