initial commit

This commit is contained in:
valentineautos
2025-12-05 09:22:55 +00:00
parent 46949642a2
commit 16ffc2ab10
4033 changed files with 980542 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
#!/usr/bin/env python
#
# SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
# check that the CHANGELOG.md file contains the changelog for the version
# in idf_component.yml
# exit with 0 if ok
# exit with 1 if fail
# to be run whenever idf_component.yml is updated
import re
import sys
# paths to files to check
yml_file = "idf_component.yml"
changelog_file = "CHANGELOG.md"
def get_idf_yml_version_as_string() -> str:
# read the yml file
file_info = open(yml_file, "r")
info = file_info.read()
file_info.close()
# extract the version info
ver = re.search("^version: \"([0-9.]+)\"", info)
# print("yml:", ver.group(1))
return ver.group(1)
def changelog_has_version(ver_string: str) -> int:
# iterate over the changelog file
matching_line = "## " + ver_string
with open(changelog_file, "r") as changelog:
for line in changelog:
if re.match(matching_line, line):
return 0
return 1
def check() -> int:
yml_string = get_idf_yml_version_as_string()
result = changelog_has_version(yml_string)
if result:
print(f"Changelog for version {yml_string} not found in {changelog_file}")
return 1
return 0
if __name__ == '__main__':
sys.exit(check())

View File

@@ -0,0 +1,37 @@
# don't modify this section!
DEFAULT:
perform_check: yes # should the check be performed?
# Sections setting this to 'no' don't need to include any other options as they are ignored
# When a file is using a section with the option set to 'no', no checks are performed.
# what licenses (or license expressions) are allowed for files in this section
# when setting this option in a section, you need to list all the allowed licenses
allowed_licenses:
- Apache-2.0
- Unlicense
- CC0-1.0
license_for_new_files: Apache-2.0 # license to be used when inserting a new copyright notice
new_notice_c: | # notice for new C, CPP, H, HPP and LD files
/*
* SPDX-FileCopyrightText: {years} Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: {license}
*/
new_notice_python: | # notice for new python files
# SPDX-FileCopyrightText: {years} Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: {license}
# comment lines matching:
# SPDX-FileCopyrightText: year[-year] Espressif Systems
# or
# SPDX-FileContributor: year[-year] Espressif Systems
# are replaced with this template prefixed with the correct comment notation (# or // or *) and SPDX- notation
espressif_copyright: '{years} Espressif Systems (Shanghai) CO LTD'
ignore: # You can also select ignoring files here
perform_check: no # Don't check files from that block
include:
- common/proto/
- common/protobuf-c/
- build/
- docs/

View File

@@ -0,0 +1,213 @@
#!/usr/bin/env python
#
# SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
# check the host and co-processor version numbers aginst the value in
# idf_component.yml
# exit with 0 if ok
# exit with 1 if fail
import argparse
from datetime import date
import os
import re
import sys
# paths to files to check
yml_file = "idf_component.yml"
coprocessor_version_file = "slave/main/esp_hosted_coprocessor_fw_ver.h"
host_version_file = "host/esp_hosted_host_fw_ver.h"
# year starts from 2025
start_year = 2025
def get_idf_yml_version() -> (int, int, int):
# read the yml file
file_info = open(yml_file, "r")
info = file_info.read()
file_info.close()
# extract the version info
ver = re.search("^version: \"([0-9]+).([0-9]+).([0-9]+)\"", info)
#print("yml:", ver.group(1), ver.group(2), ver.group(3))
# return version info as a tuple (major, minor, patch)
return (ver.group(1), ver.group(2), ver.group(3))
def get_coprocessor_version() -> (int, int, int):
# read the coprocessor file
try:
file_info = open(coprocessor_version_file, "r")
except:
print("Coprocessor file open error: default to 0.0.0")
return (0, 0, 0)
info = file_info.read()
file_info.close()
# extract the version info
major_re = re.search("_VERSION_MAJOR_1 ([0-9]+)", info)
minor_re = re.search("_VERSION_MINOR_1 ([0-9]+)", info)
patch_re = re.search("_VERSION_PATCH_1 ([0-9]+)", info)
if ((not major_re) or (not minor_re) or (not patch_re)):
print("No coprocessor version info found: default to 0.0.0")
return (0, 0, 0)
#print("coprocessor:", major_re.group(1), minor_re.group(1), patch_re.group(1))
return (major_re.group(1), minor_re.group(1), patch_re.group(1))
def get_host_version() -> (int, int, int):
# read the host file
try:
file_info = open(host_version_file, "r")
except:
print("Host file open error: default to 0.0.0")
return (0, 0, 0)
info = file_info.read()
file_info.close()
# extract the version info
major_re = re.search("_VERSION_MAJOR_1 ([0-9]+)", info)
minor_re = re.search("_VERSION_MINOR_1 ([0-9]+)", info)
patch_re = re.search("_VERSION_PATCH_1 ([0-9]+)", info)
if ((not major_re) or (not minor_re) or (not patch_re)):
print("No host version info found: default to 0.0.0")
return (0, 0, 0)
#print("host:", major_re.group(1), minor_re.group(1), patch_re.group(1))
return (major_re.group(1), minor_re.group(1), patch_re.group(1))
# write common header using the provided file handle
def write_common_header(file_info):
year = date.today().year
file_info.write("/*\n")
if (year == start_year):
file_info.write(f" * SPDX-FileCopyrightText: {year} Espressif Systems (Shanghai) CO LTD\n")
else:
file_info.write(f" * SPDX-FileCopyrightText: {start_year}-{year} Espressif Systems (Shanghai) CO LTD\n")
file_info.write(" *\n")
file_info.write(" * SPDX-License-Identifier: Apache-2.0\n")
file_info.write(" *\n")
file_info.write(" * DO NOT MODIFY THIS FILE.\n")
file_info.write(" *\n")
file_info.write(" * tools/check_fw_versions.py generated this file.\n")
file_info.write(" *\n")
file_info.write(" * This file is autogenerated by a pre-commit hook.\n")
file_info.write(" * Version info here is populated from idf_component.yml\n");
file_info.write(" */\n")
# write footer for coprocessor file using the provided file handle
def write_coprocessor_footer(file_info):
file_info.write("\n")
file_info.write("/**\n")
file_info.write(" * Macro to convert version number into an integer\n")
file_info.write(" */\n")
file_info.write("#define ESP_HOSTED_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch))\n")
file_info.write("\n")
# write footer for host file using the provided file handle
def write_host_footer(file_info):
file_info.write("\n")
file_info.write("/**\n")
file_info.write(" * Macro to convert version number into an integer\n")
file_info.write(" */\n")
file_info.write("#define ESP_HOSTED_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch))\n")
file_info.write("\n")
def set_coprocessor_version(version: tuple) -> int:
# write the coprocessor file
file_info = open(coprocessor_version_file, "w")
write_common_header(file_info)
file_info.write("#ifndef __ESP_HOSTED_COPROCESSOR_FW_VER_H__\n")
file_info.write("#define __ESP_HOSTED_COPROCESSOR_FW_VER_H__\n")
file_info.write("\n")
ver = version[0]
file_info.write(f"#define PROJECT_VERSION_MAJOR_1 {ver}\n")
ver = version[1]
file_info.write(f"#define PROJECT_VERSION_MINOR_1 {ver}\n")
ver = version[2]
file_info.write(f"#define PROJECT_VERSION_PATCH_1 {ver}\n")
write_coprocessor_footer(file_info)
file_info.write("#endif\n")
file_info.close()
return 0
def set_host_version(version: tuple) -> int:
# write the host file
file_info = open(host_version_file, "w")
write_common_header(file_info)
file_info.write("#ifndef __ESP_HOSTED_HOST_FW_VERSION_H__\n");
file_info.write("#define __ESP_HOSTED_HOST_FW_VERSION_H__\n");
file_info.write("\n")
ver = version[0]
file_info.write(f"#define ESP_HOSTED_VERSION_MAJOR_1 {ver}\n")
ver = version[1]
file_info.write(f"#define ESP_HOSTED_VERSION_MINOR_1 {ver}\n")
ver = version[2]
file_info.write(f"#define ESP_HOSTED_VERSION_PATCH_1 {ver}\n")
write_host_footer(file_info)
file_info.write("#endif\n")
file_info.close()
return 0
def check_slave_version(yml_version: tuple) -> int:
version = get_coprocessor_version()
if (version == yml_version):
return 0
else:
return 1
def check_host_version(yml_version: tuple) -> int:
version = get_host_version()
if (version == yml_version):
return 0
else:
return 1
def check(args) -> int:
ret = 0
yml_version = get_idf_yml_version()
update = args.update
force = args.force
if (check_slave_version(yml_version)):
print(f"Co-processor version check failed. Info in {coprocessor_version_file} different from {yml_file}.")
if (update or force):
print(f"{coprocessor_version_file} updated with correct version info.")
set_coprocessor_version(yml_version)
ret = 1
elif force:
print(f"Force updating version info in {coprocessor_version_file}.")
set_coprocessor_version(yml_version)
if (check_host_version(yml_version)):
print(f"Host version check failed. Info in {host_version_file} different from {yml_file}.")
if (update or force):
set_host_version(yml_version)
print(f"{host_version_file} updated with correct version info.")
ret = 1
elif force:
print(f"Force updating version info in {host_version_file}.")
set_host_version(yml_version)
return ret
if __name__ == '__main__':
parser = argparse.ArgumentParser(description = "Check, update version headers against component version")
parser.add_argument('-u', '--update', action = 'store_true',
help = "Updates version headers if different from component version")
parser.add_argument('-f', '--force', action = 'store_true',
help = "Force update version headers")
args = parser.parse_args()
sys.exit(check(args))

View File

@@ -0,0 +1,115 @@
#!/usr/bin/env python
#
# SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
# check that RPC calls in protobuf and documentation files match
# exit with 0 if ok
# exit with 1 if fail
import os
import re
import sys
# method:
# 1. get the set of RPC calls from both the protobuf and documentation files
# 2. compare the sets
# 3. if there are differences, print the differences
protobuf_file = "common/proto/esp_hosted_rpc.proto"
doc_file = "docs/implemented_rpcs.md"
def get_set_from_document() -> set:
set_rpcs = set()
# read the protobuf file
try:
file_info = open(doc_file, "r")
except:
print("Document file open error")
return set_of_rpcs
# from this pattern in the doc_file:
# | 1 | 257 | GetMacAddress | 0.0.6 |
# it will extract GetMacAddress
# this pattern works for the list of RCP Requests and Events
pattern = re.compile("\|\s*\d+\s*\|\s*\d+\s*\|\s*(\S+)")
for line in file_info:
# get the list of rpc calls
rpc_call = pattern.search(line)
if rpc_call:
# print(rpc_call.group(1))
set_rpcs.add(rpc_call.group(1))
file_info.close()
# print(set_rpcs)
return set_rpcs
def get_set_from_protobuf() -> set:
set_rpcs = set()
# read the protobuf file
try:
file_info = open(protobuf_file, "r")
except:
print("Protobuf file open error")
return set_of_rpcs
# extract requests
# from this pattern in the protobuf_file
# Rpc_Req_GetMacAddress req_get_mac_address = 257;
# it will extract GetMacAddress
pattern_req = re.compile("\s+(Rpc_Req_)(\S+)\s+req_")
# extract events
# from this pattern in the protobuf_file
# Rpc_Event_ESPInit event_esp_init = 769;
# it will extract ESPInit
pattern_event = re.compile("\s+(Rpc_Event_)(\S+)\s+event_")
for line in file_info:
# get the list of rpc calls
rpc_call = pattern_req.search(line)
if rpc_call:
set_rpcs.add(rpc_call.group(2))
rpc_call = pattern_event.search(line)
if rpc_call:
set_rpcs.add(rpc_call.group(2))
file_info.close()
# print(set_rpcs)
return set_rpcs
def check() -> int:
ret = 1
# get the set of RPC calls in the protobuf file
protobuf_set = get_set_from_protobuf()
# get the set of RPC calls in the documentation file
document_set = get_set_from_document()
# compare the two
# if not equal
if (protobuf_set == document_set):
ret = 0
else:
# get the differences
only_in_docs = document_set.difference(protobuf_set)
only_in_protobuf = protobuf_set.difference(document_set)
if only_in_docs:
print("Error: RPCs only found in document:", only_in_docs)
if only_in_protobuf:
print("Error: RPCs only found in protobuf:", only_in_protobuf)
return ret
if __name__ == '__main__':
sys.exit(check())