Skip to content

Commit 0e582ef

Browse files
committed
conf/genconf: support update openocd.cfg according to json file.
Signed-off-by: guibing <guibing@nucleisys.com>
1 parent 6213b69 commit 0e582ef

1 file changed

Lines changed: 41 additions & 1 deletion

File tree

conf/genconf.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,33 @@ def update_plic_intr_num(dts_file_path, irqmax=None):
236236
with open(dts_file_path, 'w') as f:
237237
f.write(modified_content)
238238

239+
def update_openocd_config(file_path, **kwargs):
240+
with open(file_path, "r") as f:
241+
content = f.read()
242+
243+
changes_made = False # 标记是否有修改发生
244+
245+
for key, new_value in kwargs.items():
246+
pattern = rf"(set\s+{key}\s+)(\S+)"
247+
# 先检查是否能匹配到旧值
248+
match = re.search(pattern, content)
249+
if match:
250+
old_value = match.group(2)
251+
if old_value != new_value:
252+
# 只有当新旧值不同时才替换
253+
content = re.sub(pattern, f"set {key} {new_value}", content)
254+
print(f"Update {key.ljust(15)}: {old_value} to {new_value}")
255+
changes_made = True
256+
# else: 值相同则不处理
257+
else:
258+
print(f"[Warning] Config item '{key}' not found")
259+
260+
if changes_made:
261+
with open(file_path, "w") as f:
262+
f.write(content)
263+
else:
264+
print("No changes were made to the config file.")
265+
239266
if __name__ == "__main__":
240267
parser = argparse.ArgumentParser(
241268
description="Generate configuration files based on a reference SOC."
@@ -515,7 +542,20 @@ def update_plic_intr_num(dts_file_path, irqmax=None):
515542
fdt_load_addr = hex(int(board_ddr_base, 16) + 0x8000000)
516543
update_uboot_cmd(uboot_cmd_file, kernel_load_addr, rootfs_load_addr, fdt_load_addr)
517544

518-
print("===generate successfully!===\n")
545+
print("\n>>>Updating openocd config...")
546+
# update openocd config file
547+
openocd_cfg_file = "%s/openocd.cfg" %(cust_file)
548+
workmem_base = hex(int(board_ddr_base, 16))
549+
workmem_size = hex(0x10000)
550+
flashxip_base = hex(int(board_flash_base, 16))
551+
xipnuspi_base = hex(int(board_qspi0_base, 16))
552+
update_openocd_config(openocd_cfg_file,
553+
workmem_base=workmem_base,
554+
workmem_size=workmem_size,
555+
flashxip_base=flashxip_base,
556+
xipnuspi_base=xipnuspi_base)
557+
558+
print("\n===generate successfully!===\n")
519559
print("Here are the reference build commands for compiling Linux SDK for you:")
520560
print("$cd ..")
521561
print("$make SOC=%s CORE=ux900fd BOOT_MODE=sd freeloader bootimages" % args.custsoc)

0 commit comments

Comments
 (0)