From 68faa12a656024c42d2ba11255e92d4b22ed8da9 Mon Sep 17 00:00:00 2001 From: Abderrahmane Jarmouni Date: Wed, 22 Nov 2023 18:10:35 +0100 Subject: [PATCH] scripts: serie_update: fetch submodules STM32Cube HAL & CMSIS Device drivers are now included as git submodules in the upstream STM32Cube repos. So we need a new logic to fetch them & integrate the changes. Signed-off-by: Abderrahmane Jarmouni --- scripts/serie_update.py | 106 ++++++++++++++++++++++++-------- scripts/update_stm32_package.py | 2 +- 2 files changed, 83 insertions(+), 25 deletions(-) diff --git a/scripts/serie_update.py b/scripts/serie_update.py index a832aa474..e344d3b88 100644 --- a/scripts/serie_update.py +++ b/scripts/serie_update.py @@ -85,15 +85,25 @@ def __init__( self.debug = debug self.module_patch = f"module_{self.stm32_serie}.patch" - # ##### 3 root directories to work with ######## + # ##### 5 root directories to work with ######## # 1: STM32Cube repo Default $HOME/STM32Cube_repo - # 2 : zephyr stm32 path : ex: .../zephyr_project/module/hal/stm32 - # 3: Temporary directory to construct the update - # (within STM32Cube repo dir) + # 2: STM32Cube repo Current $HOME/STM32Cube_repo_curr + # 3: STM32Cube repo Latest $HOME/STM32Cube_repo_latest + # 4: zephyr stm32 path : ex: .../zephyr_project/module/hal/stm32 + # 5: Temporary directory to construct the update + # (within STM32Cube repo dir) self.stm32cube_repo_path = stm32cube_repo_path if not self.stm32cube_repo_path.exists(): self.stm32cube_repo_path.mkdir() + self.stm32cube_repo_curr_path = Path(str(stm32cube_repo_path) + "_curr") + if not self.stm32cube_repo_curr_path.exists(): + self.stm32cube_repo_curr_path.mkdir() + + self.stm32cube_repo_latest_path = Path(str(stm32cube_repo_path) + "_latest") + if not self.stm32cube_repo_latest_path.exists(): + self.stm32cube_repo_latest_path.mkdir() + self.zephyr_hal_stm32_path = REPO_ROOT if not self.zephyr_hal_stm32_path.exists(): raise FileNotFoundError("Error: cannot find zephyr project") @@ -105,10 +115,16 @@ def __init__( ) self.stm32cube_temp.mkdir() - # subdir specific to a stm32 serie + # subdir specific to an stm32 serie self.stm32cube_serie_path = self.stm32cube_repo_path / Path( "STM32Cube" + self.serie ) + self.stm32cube_serie_curr_path = self.stm32cube_repo_curr_path / Path( + "STM32Cube" + self.serie + ) + self.stm32cube_serie_latest_path = self.stm32cube_repo_latest_path / Path( + "STM32Cube" + self.serie + ) self.zephyr_module_serie_path = ( self.zephyr_hal_stm32_path / "stm32cube" / self.stm32_seriexx ) @@ -253,15 +269,16 @@ def get_zephyr_current_version(self): f"Error: cannot find version {previous_version} in STM32Cube_repo" ) - def extract_source(self): + def extract_source(self, stm32cube_serie_path): """Extract sources and includes files from STM32Cube repo and copy them in temporary directory """ # for CMSIS files temp_cmsis_soc_path = self.stm32cube_temp_serie / "soc" Path.mkdir(temp_cmsis_soc_path, parents=True) + stm32cube_cmsis_include_path = ( - self.stm32cube_serie_path + stm32cube_serie_path / "Drivers" / "CMSIS" / "Device" @@ -273,7 +290,7 @@ def extract_source(self): shutil.copytree(stm32cube_cmsis_include_path, temp_cmsis_soc_path) stm32cube_cmsis_templates_path = ( - self.stm32cube_serie_path + stm32cube_serie_path / "Drivers" / "CMSIS" / "Device" @@ -290,8 +307,9 @@ def extract_source(self): # for hal and ll drivers temp_drivers_include_path = self.stm32cube_temp_serie / "drivers" / "include" temp_drivers_include_path.parent.mkdir(parents=True) + stm32cube_driver_inc = ( - self.stm32cube_serie_path + stm32cube_serie_path / "Drivers" / Path(self.stm32_seriexx_upper + "_HAL_Driver") / "Inc" @@ -308,7 +326,7 @@ def extract_source(self): temp_drivers_src_path = self.stm32cube_temp_serie / "drivers" / "src" temp_drivers_src_path.mkdir() stm32cube_drivers_src_path = ( - self.stm32cube_serie_path + stm32cube_serie_path / "Drivers" / Path(self.stm32_seriexx_upper + "_HAL_Driver") / "Src" @@ -320,16 +338,30 @@ def build_from_current_cube_version(self): """Build a commit in temporary dir with STM32Cube version corresponding to zephyr current hal version """ - # reset the STM32Cube repo to this current version + # clone the current version of the upstream STM32Cube repo + repo_name = STM32_CUBE_REPO_BASE + self.serie + ".git" + logging.info( + "%s", + "Cloning " + self.current_version + " of repo " + + repo_name + + " in " + + str(self.stm32cube_serie_curr_path), + ) + if self.stm32cube_serie_curr_path.exists(): + # clean-up the module + shutil.rmtree( + str(self.stm32cube_serie_curr_path), + onerror=common_utils.remove_readonly + ) self.os_cmd( - ("git", "reset", "--hard", self.current_version), - cwd=self.stm32cube_serie_path, + ("git", "clone", "-b", self.current_version, + "--recurse-submodules", repo_name), cwd=self.stm32cube_repo_curr_path, ) # build the zephyr module from the stm32cube - self.extract_source() + self.extract_source(self.stm32cube_serie_curr_path) logging.info( - "%s", "Building module from STM32Cube_repo " + self.current_version + "%s", "Building module from STM32Cube_repo_curr " + self.current_version ) if not self.stm32cube_temp_serie.parent.exists(): @@ -444,7 +476,7 @@ def update_readme(self, make_version, make_commit): def copy_release_note(self): """Copy release_note.html file from STM32Cube to zephyr""" - release_note_src = self.stm32cube_serie_path / "Release_Notes.html" + release_note_src = self.stm32cube_serie_latest_path / "Release_Notes.html" release_note_dst = self.zephyr_module_serie_path / "release_note.html" if release_note_dst.exists(): release_note_dst.unlink() @@ -565,15 +597,31 @@ def build_from_version_update(self): """Build a commit in temporary dir with STM32Cube version corresponding to zephyr latest hal version """ - # reset the STM32Cube repo to this latest version + + # clone the update version of the upstream STM32Cube repo + repo_name = STM32_CUBE_REPO_BASE + self.serie + ".git" + logging.info( + "%s", + "Cloning " + self.version_update + " of repo " + + repo_name + + " in " + + str(self.stm32cube_serie_latest_path), + ) + if self.stm32cube_serie_latest_path.exists(): + # clean-up the module + shutil.rmtree( + str(self.stm32cube_serie_latest_path), + onerror=common_utils.remove_readonly + ) self.os_cmd( - ("git", "reset", "--hard", self.version_update), - cwd=self.stm32cube_serie_path, + ("git", "clone", "-b", self.version_update, + "--recurse-submodules", repo_name), + cwd=self.stm32cube_repo_latest_path, ) # Get the commit id of this latest version self.update_commit = subprocess.check_output( - ("git", "rev-parse", "HEAD"), cwd=self.stm32cube_serie_path + ("git", "rev-parse", "HEAD"), cwd=self.stm32cube_serie_latest_path ).decode("utf-8") # clear previous version content before populating with latest version @@ -582,12 +630,14 @@ def build_from_version_update(self): ) # populate temporary directory with latest version - self.extract_source() + self.extract_source(self.stm32cube_serie_latest_path) # Commit files except log or patch files self.os_cmd(("git", "add", "*"), cwd=self.stm32cube_serie_path) - self.os_cmd(("git", "reset", "--", "*.patch"), cwd=self.stm32cube_serie_path) - self.os_cmd(("git", "reset", "--", "*.log"), cwd=self.stm32cube_serie_path) + self.os_cmd(("git", "reset", "--", "*.patch"), + cwd=self.stm32cube_serie_path) + self.os_cmd(("git", "reset", "--", "*.log"), + cwd=self.stm32cube_serie_path) self.os_cmd( ("git", "commit", "-am", '"module' + self.version_update + '"'), cwd=self.stm32cube_temp_serie, @@ -701,12 +751,20 @@ def clean_files(self): os.chdir(os.getenv("HOME")) shutil.rmtree(str(self.stm32cube_temp), onerror=common_utils.remove_readonly) - # remove STM32Cube repo only if required + # remove STM32Cube repos only if required if not self.noclean: self.cleanup_stm32cube_repo() shutil.rmtree( str(self.stm32cube_repo_path), onerror=common_utils.remove_readonly ) + shutil.rmtree( + str(self.stm32cube_repo_curr_path), + onerror=common_utils.remove_readonly + ) + shutil.rmtree( + str(self.stm32cube_repo_latest_path), + onerror=common_utils.remove_readonly + ) else: self.os_cmd( ("git", "reset", "--hard", "HEAD"), diff --git a/scripts/update_stm32_package.py b/scripts/update_stm32_package.py index 5a1ec5c6b..3fe83a1cc 100644 --- a/scripts/update_stm32_package.py +++ b/scripts/update_stm32_package.py @@ -107,7 +107,7 @@ def update_cubes(): if not args.noclean: print( - f"Do you want to clean downloaded repo {str(repo_path)} at the end of updates?" + f"Do you want to clean downloaded repos {str(repo_path)} at the end of updates?" ) res = input("(Enter y/n) ").lower() while res not in ("y", "n"):