Skip to content

Commit a4138fa

Browse files
committed
conf/genconf: support sysrst dts node update.
Signed-off-by: guibing <guibing@nucleisys.com>
1 parent b08dd8d commit a4138fa

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

conf/genconf.json

100755100644
File mode changed.

conf/genconf.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,25 @@ def update_dts_node(dts_file_path, node_name, new_base_address, new_reg_values,
128128
else:
129129
print("Node not found!")
130130

131+
def update_dts_node_simple(dts_file_path, node_name, new_reg_values):
132+
with open(dts_file_path, 'r') as f:
133+
content = f.read()
134+
135+
pattern_str = r'(\b{}\s*{{[\s\S]*?)(\breg\s*=\s*<)([^>]+)([>])([\s\S]*?}})'.format(re.escape(node_name))
136+
pattern = re.compile(pattern_str, re.DOTALL | re.MULTILINE)
137+
138+
def replacer(match):
139+
return f"{match.group(1)}{match.group(2)}{new_reg_values}>{match.group(5)}"
140+
141+
new_content = pattern.sub(replacer, content)
142+
143+
if new_content != content:
144+
with open(dts_file_path, 'w') as f:
145+
f.write(new_content)
146+
print(f"Updated {node_name} reg to <{new_reg_values}>")
147+
else:
148+
print(f"Node '{node_name}' not found or no change")
149+
131150
def update_build_variable(makefile_path, variable_name, new_value):
132151
with open(makefile_path, 'r') as file:
133152
content = file.read()
@@ -505,6 +524,13 @@ def update_openocd_config(file_path, **kwargs):
505524
clint_reg_val = f"0x0 0x{clint_base_hex.lstrip('0x')} 0x0 0x{clint_size_hex.lstrip('0x')}"
506525
update_dts_node(dts_file, 'clint', clint_base_hex.lstrip('0x'), clint_reg_val)
507526

527+
# update sysrst dts node
528+
sysrst_base_addr = int(board_iregion_base, 16) + 0x30FF0
529+
sysrst_high = (sysrst_base_addr >> 32) & 0xFFFFFFFF
530+
sysrst_low = sysrst_base_addr & 0xFFFFFFFF
531+
sysrst_reg_val = f"0x{sysrst_high:x} 0x{sysrst_low:x}"
532+
update_dts_node_simple(dts_file, 'sysrst', sysrst_reg_val)
533+
508534
if board_uart0_base is not None:
509535
# update uart0 dts node
510536
uart0_base_hex = hex(int(board_uart0_base, 16))

0 commit comments

Comments
 (0)