From 68aa18543736bf15a127c6bdf282c2c23ef0a53c Mon Sep 17 00:00:00 2001 From: MX682X <58419867+MX682X@users.noreply.github.com> Date: Thu, 16 Jul 2026 08:12:37 +0200 Subject: [PATCH] added script version information --- src/pickit5_lut.h | 1 + src/pickit5_lut_dw.c | 1 + src/pickit5_lut_isp.c | 1 + src/pickit5_lut_jtag.c | 1 + src/pickit5_lut_pdi.c | 1 + src/pickit5_lut_tpi.c | 1 + src/pickit5_lut_updi.c | 1 + tools/scripts_decoder.py | 50 ++++++++++++++++++++++++++++++++-------- 8 files changed, 47 insertions(+), 10 deletions(-) diff --git a/src/pickit5_lut.h b/src/pickit5_lut.h index dcb35259..4a275970 100644 --- a/src/pickit5_lut.h +++ b/src/pickit5_lut.h @@ -1,5 +1,6 @@ /* This file was auto-generated by scripts_decoder.py. * Any changes will be overwritten on regeneration + * version:001079 */ /* diff --git a/src/pickit5_lut_dw.c b/src/pickit5_lut_dw.c index 21013d21..7c060278 100644 --- a/src/pickit5_lut_dw.c +++ b/src/pickit5_lut_dw.c @@ -1,5 +1,6 @@ /* This file was auto-generated by scripts_decoder.py. * Any changes will be overwritten on regeneration + * version:001079 */ /* diff --git a/src/pickit5_lut_isp.c b/src/pickit5_lut_isp.c index b89898f5..e56b121a 100644 --- a/src/pickit5_lut_isp.c +++ b/src/pickit5_lut_isp.c @@ -1,5 +1,6 @@ /* This file was auto-generated by scripts_decoder.py. * Any changes will be overwritten on regeneration + * version:001079 */ /* diff --git a/src/pickit5_lut_jtag.c b/src/pickit5_lut_jtag.c index 04c5980f..cf4294ec 100644 --- a/src/pickit5_lut_jtag.c +++ b/src/pickit5_lut_jtag.c @@ -1,5 +1,6 @@ /* This file was auto-generated by scripts_decoder.py. * Any changes will be overwritten on regeneration + * version:001079 */ /* diff --git a/src/pickit5_lut_pdi.c b/src/pickit5_lut_pdi.c index cc238d8e..189e0232 100644 --- a/src/pickit5_lut_pdi.c +++ b/src/pickit5_lut_pdi.c @@ -1,5 +1,6 @@ /* This file was auto-generated by scripts_decoder.py. * Any changes will be overwritten on regeneration + * version:001079 */ /* diff --git a/src/pickit5_lut_tpi.c b/src/pickit5_lut_tpi.c index c3c53bf8..a62e09a7 100644 --- a/src/pickit5_lut_tpi.c +++ b/src/pickit5_lut_tpi.c @@ -1,5 +1,6 @@ /* This file was auto-generated by scripts_decoder.py. * Any changes will be overwritten on regeneration + * version:001079 */ /* diff --git a/src/pickit5_lut_updi.c b/src/pickit5_lut_updi.c index 75b07d1b..2bdd535b 100644 --- a/src/pickit5_lut_updi.c +++ b/src/pickit5_lut_updi.c @@ -1,5 +1,6 @@ /* This file was auto-generated by scripts_decoder.py. * Any changes will be overwritten on regeneration + * version:001079 */ /* diff --git a/tools/scripts_decoder.py b/tools/scripts_decoder.py index 7d641bf6..427eb533 100644 --- a/tools/scripts_decoder.py +++ b/tools/scripts_decoder.py @@ -100,13 +100,17 @@ cache_dir = os.path.join(work_dir, "scripts_cache") print(work_dir) print(cache_dir) +version = "000000" # placeholder +use_older = False # used for version comparison # Beginning of C and H Files -common_header = \ -'''\ +def get_common_header(): + global version + common_header = f'''\ /* This file was auto-generated by scripts_decoder.py. * Any changes will be overwritten on regeneration + * version:{version} */ /* @@ -128,6 +132,7 @@ common_header = \ */ ''' + return common_header # generates the h-file. generates the struct definition def generate_h_file(c_funcs, file_dir): @@ -162,7 +167,6 @@ int get_pickit_tpi_script(SCRIPT *scr, const char *partdesc); #endif // pickit5_lut_h ''' - global common_header if file_dir is None: return @@ -171,7 +175,7 @@ int get_pickit_tpi_script(SCRIPT *scr, const char *partdesc); os.remove(h_lut_path) with open(h_lut_path, 'w') as h_file: - h_file.write(common_header) + h_file.write(get_common_header()) h_file.write(h_header) for func_name in c_funcs: h_file.write(" const unsigned char *{0};\n unsigned int {0}_len;\n".format(func_name)) @@ -180,6 +184,24 @@ int get_pickit_tpi_script(SCRIPT *scr, const char *partdesc); #EOF +# check version numbers, ask if user wants an older version +def version_check(file_dir, new_version): + old_version_int = 0 + if file_dir is not None: + h_lut_path = os.path.join(file_dir, "pickit5_lut.h") + if (os.path.exists(h_lut_path)): + with open(h_lut_path, "r") as h_file: + for _ in range(5): # read at most the first 5 lines + line = h_file.readline() + if len(line) == 0: # EOF + break + if line.startswith(" * version:"): + old_version_int = int(line.split(":")[1], 10) + if old_version_int > int(new_version, 10): + print("WARNING: Overwriting lut files with an older scripts version!") + print(f"Old version: {old_version_int:06}\nNew Vesion: {new_version}") + return int(new_version, 10) - old_version_int + #EOF # Tries to locate the xml file in a known location @@ -252,10 +274,6 @@ def convert_xml(xml_path, c_funcs): print("Parent Dir: {0}".format(parent_dir)) print("Src directory: {0}".format(src_dir)) - - # create h-File (make sure to provide all function definitions) - generate_h_file(c_funcs, src_dir) - with open(xml_path, "r") as xml_script: print ("XML File opened") @@ -332,13 +350,25 @@ def convert_xml(xml_path, c_funcs): # } #} # /if starts with + elif line.startswith(" "): + global version + vers_str = line[11:] # remove " " + vers_str = vers_str.split("<", 2)[0] # remove trailing element + version = vers_str + + # 0: equal / < 0: current xml older then current lut / > 0: newer, or if old is non-existent + ver_diff = version_check(src_dir, version) + # /while True # /with open + # create h-File (make sure to provide all function definitions) + # create only after processing XML File with version info + generate_h_file(c_funcs, src_dir) + print("XML File processed") # create c-File - global common_header for prog_iface, prog_mcu_list in program_iface.items(): lower_prog_iface = prog_iface.lower() @@ -346,7 +376,7 @@ def convert_xml(xml_path, c_funcs): if (os.path.exists(c_lut_path)): os.remove(c_lut_path) with open(c_lut_path, 'w') as c_file: - c_file.write(common_header) + c_file.write(get_common_header()) c_file.write("#include \n") c_file.write("#include \n") c_file.write("#include \n")