Skip to content

Commit

Permalink
scripts: serie_update: fetch submodules
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ajarmouni-st committed Dec 7, 2023
1 parent 89ef0a3 commit 93ed06d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
8 changes: 4 additions & 4 deletions scripts/ble_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ def build_patch_from_current_zephyr_version(

temp_source_lib_path = Path(temp_source_path / "lib")

# reset the STM32Cube repo to this current version
# Checkout the current Zephyr version of the STM32Cube repo
os_cmd(
("git", "reset", "--hard", version),
("git", "checkout", "-f", "--recurse-submodules", version),
cwd=src_repo_path,
)

Expand Down Expand Up @@ -218,9 +218,9 @@ def update(
build_patch_from_current_zephyr_version(
src_repo_path, temp_source_path, dest_lib_path, current_version
)
# reset the STM32Cube repo to this update version
# Checkout the latest version of the STM32Cube repo
os_cmd(
("git", "reset", "--hard", update_version),
("git", "checkout", "-f", "--recurse-submodules", update_version),
cwd=src_repo_path,
)
copy_hci_files(src_repo_path, dest_lib_path)
Expand Down
35 changes: 25 additions & 10 deletions scripts/serie_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(

# ##### 3 root directories to work with ########
# 1: STM32Cube repo Default $HOME/STM32Cube_repo
# 2 : zephyr stm32 path : ex: .../zephyr_project/module/hal/stm32
# 2: zephyr stm32 path : ex: .../zephyr_project/module/hal/stm32
# 3: Temporary directory to construct the update
# (within STM32Cube repo dir)
self.stm32cube_repo_path = stm32cube_repo_path
Expand All @@ -105,7 +105,7 @@ 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
)
Expand Down Expand Up @@ -192,14 +192,26 @@ def clone_cube_repo(self):
# if already exists, then just clean and fetch
self.os_cmd(("git", "clean", "-fdx"), cwd=self.stm32cube_serie_path)
self.os_cmd(("git", "fetch"), cwd=self.stm32cube_serie_path)
# this is useful when HAL/CMSIS Device drivers submodules are not
# already present locally, otherwise "git fetch" is sufficient
self.os_cmd(("git", "submodule", "update", "--init"),
cwd=self.stm32cube_serie_path)
branch = self.major_branch()
# "Using --recurse-submodules will update the content of all active
# submodules according to the commit recorded in the superproject.
# If local modifications in a submodule would be overwritten the
# checkout will fail unless -f is used."
# https://git-scm.com/docs/git-checkout
self.os_cmd(
("git", "reset", "--hard", branch),
("git", "checkout", "-f", "--recurse-submodules", branch),
cwd=self.stm32cube_serie_path,
)
else:
# HAL & CMSIS Device drivers are now included as git submodules in
# upstream STM32Cube GitHub repositories
# So to get them too, --recursive or --recurse-submodules is needed
self.os_cmd(
("git", "clone", repo_name),
("git", "clone", "--recursive", repo_name),
cwd=self.stm32cube_repo_path,
)
branch = self.major_branch()
Expand Down Expand Up @@ -260,6 +272,7 @@ def extract_source(self):
# 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
/ "Drivers"
Expand Down Expand Up @@ -290,6 +303,7 @@ 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
/ "Drivers"
Expand Down Expand Up @@ -320,9 +334,9 @@ 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
# Checkout the current Zephyr version of the STM32Cube repo
self.os_cmd(
("git", "reset", "--hard", self.current_version),
("git", "checkout", "-f", "--recurse-submodules", self.current_version),
cwd=self.stm32cube_serie_path,
)

Expand Down Expand Up @@ -565,9 +579,9 @@ 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
# Checkout the latest version of the upstream STM32Cube repo
self.os_cmd(
("git", "reset", "--hard", self.version_update),
("git", "checkout", "-f", "--recurse-submodules", self.version_update),
cwd=self.stm32cube_serie_path,
)

Expand Down Expand Up @@ -693,7 +707,8 @@ def reject(self):

def cleanup_stm32cube_repo(self):
"""clean the STM32Cube repo"""
self.os_cmd(("git", "reset", "--hard", "HEAD"), cwd=self.stm32cube_serie_path)
self.os_cmd(("git", "checkout", "-f", "--recurse-submodules", "HEAD"),
cwd=self.stm32cube_serie_path)

def clean_files(self):
"""Clean repo file if required"""
Expand All @@ -709,7 +724,7 @@ def clean_files(self):
)
else:
self.os_cmd(
("git", "reset", "--hard", "HEAD"),
("git", "checkout", "-f", "--recurse-submodules", "HEAD"),
cwd=self.stm32cube_serie_path,
)

Expand Down

0 comments on commit 93ed06d

Please sign in to comment.