Skip to content

Commit

Permalink
scripts: ble_library: wba lib update
Browse files Browse the repository at this point in the history
automatize the update of stm32wba BLE library

Signed-off-by: Abderrahmane Jarmouni <[email protected]>
  • Loading branch information
ajarmouni-st committed Jan 10, 2024
1 parent 2292590 commit 6b31ad9
Show file tree
Hide file tree
Showing 2 changed files with 163 additions and 32 deletions.
175 changes: 146 additions & 29 deletions scripts/ble_library.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
"""
SPDX-License-Identifier: Apache-2.0
Copyright (c) 2021 STMicroelectronics.
Copyright (c) 2023 STMicroelectronics.
This script updates ble library
"""

Expand All @@ -13,9 +13,7 @@
import logging
from common_utils import common_utils

include_dir = ["stm32wb/hci"]

file_list = [
file_list_wb = [
"Middlewares/ST/STM32_WPAN/ble/core/ble_bufsize.h",
"Middlewares/ST/STM32_WPAN/interface/patterns/ble_thread/hw.h",
"Middlewares/ST/STM32_WPAN/interface/patterns/ble_thread/shci/shci.c",
Expand All @@ -41,6 +39,87 @@
+ "tl_dbg_conf.h",
]

file_list_wba = {
"auto": ["Middlewares/ST/STM32_WPAN/ble/stack/include/auto/ble_types.h",
],
"reg_files": ["Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/inc/_40nm_reg_files/"
+ "DWC_ble154combo.h",
],
"ll": ["Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/inc/bsp.h",
"Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/inc/common_types.h",
"Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/inc/event_manager.h",
"Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/inc/evnt_schdlr_gnrc_if.h",
"Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/inc/hci.h",
"Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/inc/ll_intf.h",
"Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/inc/mem_intf.h",
"Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/inc/os_wrapper.h",
"Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/inc/power_table.h",
"Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/config/ble_full/ll_fw_config.h",
],
"hci": ["Middlewares/ST/STM32_WPAN/ble/stack/include/ble_bufsize.h",
"Middlewares/ST/STM32_WPAN/ble/stack/include/ble_const.h",
"Middlewares/ST/STM32_WPAN/ble/stack/include/ble_defs.h",
"Middlewares/ST/STM32_WPAN/ble/stack/include/ble_std.h",
"Middlewares/ST/STM32_WPAN/ble/stack/include/bleplat.h",
"Middlewares/ST/STM32_WPAN/ble/stack/include/blestack.h",
"Middlewares/ST/STM32_WPAN/link_layer/ll_sys/inc/linklayer_plat.h",
"Middlewares/ST/STM32_WPAN/link_layer/ll_sys/inc/ll_sys.h",
"Middlewares/ST/STM32_WPAN/link_layer/ll_sys/src/ll_sys_cs.c",
"Middlewares/ST/STM32_WPAN/link_layer/ll_sys/src/ll_sys_dp_slp.c",
"Middlewares/ST/STM32_WPAN/link_layer/ll_sys/src/ll_sys_intf.c",
"Middlewares/ST/STM32_WPAN/link_layer/ll_sys/src/ll_sys_startup.c",
"Middlewares/ST/STM32_WPAN/link_layer/ll_sys/inc/ll_sys_startup.h",
"Middlewares/ST/STM32_WPAN/stm32_wpan_common.h",
"Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/Core/Inc/app_common.h",
"Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/Core/Inc/app_conf.h",
"Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/Core/Inc/app_entry.h",
"Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/Core/Inc/utilities_conf.h",
"Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/Core/Inc/main.h",
"Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/System/Modules/Flash/rf_timing_synchro.c",
"Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/System/Modules/Flash/rf_timing_synchro.h",
"Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/System/Modules/Flash/flash_driver.c",
"Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/System/Modules/Flash/flash_driver.h",
"Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/System/Modules/Flash/flash_manager.c",
"Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/System/Modules/Flash/flash_manager.h",
"Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/System/Modules/RTDebug/"
+ "debug_signals.h",
"Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/System/Modules/RTDebug/"
+ "RTDebug.c",
"Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/System/Modules/RTDebug/"
+ "RTDebug.h",
"Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/System/Modules/RTDebug/"
+ "local_debug_tables.h",
"Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/System/Modules/scm.c",
"Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/System/Modules/scm.h",
"Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/System/Modules/stm_list.c",
"Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/System/Modules/stm_list.h",
"Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/System/Modules/"
+ "utilities_common.h",
"Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/System/Interfaces/hw.h",
"Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/System/Interfaces/hw_aes.c",
"Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/System/Interfaces/hw_if.h",
"Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/System/Interfaces/hw_pka.c",
"Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/System/Interfaces/"
+ "pka_p256.c",
"Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/System/Config/Log/"
+ "log_module.c",
"Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/System/Config/Log/"
+ "log_module.h",
"Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/System/Config/Debug_GPIO/"
+ "app_debug.h",
"Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/System/Config/Debug_GPIO/"
+ "debug_config.h",
"Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/STM32_WPAN/Target/"
+ "power_table.c",
"Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/STM32_WPAN/Target/bpka.c",
"Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/STM32_WPAN/Target/bpka.h",
"Utilities/trace/adv_trace/stm32_adv_trace.h",
"Utilities/misc/stm32_mem.h",
"Utilities/tim_serv/stm32_timer.h",
"Utilities/misc/stm32_tiny_vsnprintf.h",
],
}


def os_cmd(cmd, cwd=None, shell=False):
"""Execute a command with subprocess.check_call()
Expand All @@ -63,32 +142,61 @@ def os_cmd(cmd, cwd=None, shell=False):
)


def copy_hci_files(src_repo_path, dest_lib_path):
def copy_hci_files(src_repo_path, dest_lib_path, stm32_serie):
"""Copy sources files from Cube Firmware to zephyr"""
# remove existing *.c and *.h files
hci_path = Path(dest_lib_path / "stm32wb" / "hci")
hci_path = Path(dest_lib_path / "hci")
if hci_path.exists():
for item in os.listdir(hci_path):
if item.endswith(".c") or item.endswith(".h"):
os.remove(hci_path / item)

for file in file_list:
file_path = Path(src_repo_path / file)
file_name = file_path.name
if file_path.exists:
# copy each file to destination
if not Path(dest_lib_path / "stm32wb" / "hci" / file_name).parent.exists():
Path(dest_lib_path / "stm32wb" / "hci" / file_name).parent.mkdir(
parents=True
)
shutil.copy(file_path, Path(dest_lib_path / "stm32wb" / "hci" / file_name))
else:
logging.error(f"File : {file_path} not found")
logging.error("Abort")
sys.exit()

if stm32_serie == "stm32wb":
if not hci_path.exists():
hci_path.mkdir(parents=True)

def update_ble_lib_readme(lib_path, make_version, make_commit):
for file in file_list_wb:
file_path = Path(src_repo_path / file)
file_name = file_path.name
if file_path.exists():
# copy each file to destination
shutil.copy(file_path, Path(hci_path / file_name))
else:
logging.error(f"File : {file_path} not found")
logging.error("Abort")
sys.exit()

elif stm32_serie == "stm32wba":
# remove existing *.c and *.h files
auto_path = Path(hci_path / "auto")
ll_path = Path(hci_path / "ll")
reg_files_path = Path(ll_path / "_40nm_reg_files")
dir_paths = {"hci": hci_path, "auto": auto_path, "ll": ll_path,
"reg_files": reg_files_path}

for dir_path in [auto_path, ll_path, reg_files_path]:
if dir_path.exists():
for item in os.listdir(dir_path):
if item.endswith(".c") or item.endswith(".h"):
os.remove(dir_path / item)

for dir_name in file_list_wba:
if not dir_paths[dir_name].exists():
dir_paths[dir_name].mkdir(parents=True)

for file in file_list_wba[dir_name]:
file_path = Path(src_repo_path / file)
file_name = file_path.name
if file_path.exists():
# copy each file to destination
shutil.copy(file_path, Path(dir_paths[dir_name]))
else:
logging.error(f"File : {file_path} not found")
logging.error("Abort")
sys.exit()


def update_ble_lib_readme(lib_path, make_version, make_commit, stm32_serie):
"""Update README file
Args:
Expand All @@ -97,7 +205,7 @@ def update_ble_lib_readme(lib_path, make_version, make_commit):
make_commit: Commit corresponding to latest STM32Cube version.
"""

readme_path = Path(lib_path / "stm32wb" / "hci" / "README")
readme_path = Path(lib_path / "hci" / "README")

with readme_path.open(mode="r") as readme_prev:
lines = (x for x in readme_prev.read().splitlines())
Expand Down Expand Up @@ -130,11 +238,11 @@ def update_ble_lib_readme(lib_path, make_version, make_commit):


def build_patch_from_current_zephyr_version(
src_repo_path, temp_source_path, zephyr_lib_path, version
src_repo_path, temp_source_path, zephyr_lib_path, version, stm32_serie
):
""" Rebuild zephyr patch compare to cube files (current zephyr version) """

temp_source_lib_path = Path(temp_source_path / "lib")
temp_source_lib_path = Path(temp_source_path / "lib" / stm32_serie)

# Checkout the current Zephyr version of the STM32Cube repo
os_cmd(
Expand All @@ -149,6 +257,7 @@ def build_patch_from_current_zephyr_version(
copy_hci_files(
src_repo_path,
temp_source_lib_path,
stm32_serie,
)
os_cmd(("git", "init"), cwd=temp_source_path)
os_cmd(
Expand Down Expand Up @@ -179,7 +288,8 @@ def build_patch_from_current_zephyr_version(
for file in temp_source_lib_path.glob("*"):
if file.is_file():
file.unlink()
Path(temp_source_lib_path / "stm32wb" / "hci" / "README").unlink()
if Path(temp_source_lib_path / "hci" / "README").exists():
Path(temp_source_lib_path / "hci" / "README").unlink()

# commit this current zephyr library file
os_cmd(("git", "add", "*"), cwd=temp_source_path)
Expand Down Expand Up @@ -212,20 +322,27 @@ def update(
current_version,
update_version,
commit,
stm32_serie
):
"""Update ble library"""
logging.info(" ... Updating ble library ...")
if not dest_lib_path.exists():
dest_lib_path.mkdir(parents=True)

build_patch_from_current_zephyr_version(
src_repo_path, temp_source_path, dest_lib_path, current_version
src_repo_path, temp_source_path, dest_lib_path, current_version,
stm32_serie
)
# Checkout the latest version of the STM32Cube repo
os_cmd(
("git", "checkout", "-f", "--recurse-submodules", update_version),
cwd=src_repo_path,
)
copy_hci_files(src_repo_path, dest_lib_path)
copy_hci_files(src_repo_path, dest_lib_path, stm32_serie)
common_utils.apply_patch(dest_lib_path / "ble_zephyr.patch", dest_lib_path)
update_ble_lib_readme(dest_lib_path, update_version, commit)
if Path(dest_lib_path / "hci" / "README").exists():
update_ble_lib_readme(
dest_lib_path, update_version, commit, stm32_serie)


if __name__ == "__main__":
Expand Down
20 changes: 17 additions & 3 deletions scripts/serie_update.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
"""
SPDX-License-Identifier: Apache-2.0
Copyright (c) 2019 STMicroelectronics.
Copyright (c) 2023 STMicroelectronics.
This script define Stm32SerieUpdate class
to be used by update_stm32_package.py
"""
Expand Down Expand Up @@ -779,14 +779,28 @@ def update_stm32_hal_serie(self):
if self.stm32_serie == "stm32wb":
ble_library.update(
self.stm32cube_serie_path,
Path(self.zephyr_hal_stm32_path / "lib"),
Path(self.zephyr_hal_stm32_path / "lib" / "stm32wb"),
self.stm32cube_temp,
self.current_version,
self.version_update,
self.update_commit,
self.stm32_serie
)
self.merge_commit(lib=True)

# 9) clean
# 9) In case of stm32wba, update hci library
elif self.stm32_serie == "stm32wba":
ble_library.update(
self.stm32cube_serie_path,
Path(self.zephyr_hal_stm32_path / "lib" / "stm32wba"),
self.stm32cube_temp,
self.current_version,
self.version_update,
self.update_commit,
self.stm32_serie
)
self.merge_commit(lib=True)

# 10) clean
self.clean_files()
logging.info("%s", f"Done {self.stm32_serie}\n")

0 comments on commit 6b31ad9

Please sign in to comment.