From 2776b63d1acda354b455d72532b10ec2b966711c Mon Sep 17 00:00:00 2001 From: Andrew Dennison Date: Fri, 24 May 2024 12:05:28 +1000 Subject: [PATCH 1/2] tools/litex_json2dts_zephyr: improve indentation To support linux dts generation. --- litex/tools/litex_json2dts_zephyr.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/litex/tools/litex_json2dts_zephyr.py b/litex/tools/litex_json2dts_zephyr.py index 1d4b39c9b..7dbc46daf 100755 --- a/litex/tools/litex_json2dts_zephyr.py +++ b/litex/tools/litex_json2dts_zephyr.py @@ -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): @@ -66,13 +66,12 @@ 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( @@ -80,13 +79,13 @@ def dts_reg(regs): 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( @@ -94,10 +93,10 @@ def dts_reg_names(regs): 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 From e19dfa880037855b4e42e2f066f8dc696380bdbb Mon Sep 17 00:00:00 2001 From: Andrew Dennison Date: Mon, 27 May 2024 17:03:45 +1000 Subject: [PATCH 2/2] tools/litex_json2dts_zephyr: fix reg format addr size pairs should be enclosed '< >' and comma separated to be dts compliant. --- litex/tools/litex_json2dts_zephyr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litex/tools/litex_json2dts_zephyr.py b/litex/tools/litex_json2dts_zephyr.py index 7dbc46daf..78c8d9be6 100755 --- a/litex/tools/litex_json2dts_zephyr.py +++ b/litex/tools/litex_json2dts_zephyr.py @@ -74,7 +74,7 @@ def dts_intr(name, csr, levels=1): 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 )