From c31c1f23c2dc6eef3fd3ec6d1275770b927d8520 Mon Sep 17 00:00:00 2001 From: Adam Dobrowolski Date: Wed, 6 Oct 2021 15:29:59 +0200 Subject: [PATCH] [EGD-7753] Predefined upadter and bootloader versions in cmake So that we would be able to select proper Uptader and Bootloader as well as modify them in configuration on demand --- CMakeLists.txt | 5 -- cmake/modules/AddVersionJson.cmake | 4 +- cmake/modules/ConfigureVersionJson.cmake | 4 -- cmake/modules/DownloadAsset.cmake | 19 ++++++ cmake/modules/FetchBootloader.cmake | 23 -------- cmake/modules/FetchPureUpdater.cmake | 20 ------- config/version.json.cmake_template | 4 +- .../BellHybrid/BinaryAssetsVersions.cmake | 9 +++ products/BellHybrid/CMakeLists.txt | 5 ++ products/PurePhone/BinaryAssetsVersions.cmake | 9 +++ products/PurePhone/CMakeLists.txt | 5 ++ tools/README.md | 2 +- tools/download_asset.py | 59 ++++++++++++------- 13 files changed, 91 insertions(+), 77 deletions(-) create mode 100644 cmake/modules/DownloadAsset.cmake delete mode 100644 cmake/modules/FetchBootloader.cmake delete mode 100644 cmake/modules/FetchPureUpdater.cmake create mode 100644 products/BellHybrid/BinaryAssetsVersions.cmake create mode 100644 products/PurePhone/BinaryAssetsVersions.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ae0db168064d9596c542583885cfccf13bc3896..0bee17c74e91d8074a2caf623e89476f0f1677ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,8 +23,6 @@ include(SerialPort) include(CopyGdbInit) include(Utils) include(ModuleUtils) -include(FetchBootloader) -include(FetchPureUpdater) include(DiskImage) include(AddPackage) @@ -168,7 +166,4 @@ add_library(version-header INTERFACE) target_include_directories(version-header INTERFACE $) add_dependencies(version-header version) -fetch_ecoboot() -fetch_updater() - add_subdirectory(products) diff --git a/cmake/modules/AddVersionJson.cmake b/cmake/modules/AddVersionJson.cmake index 055771e79feff40a25b298b0da995a2514adc153..0ffb9b556da6788ae7e0687e37f71962596f7f1a 100644 --- a/cmake/modules/AddVersionJson.cmake +++ b/cmake/modules/AddVersionJson.cmake @@ -6,17 +6,17 @@ function(add_version_json SOURCE_TARGET) -DDST_FILE=${CMAKE_BINARY_DIR}/${SOURCE_TARGET}-version.json -DBOOTLOADER_FILENAME=ecoboot.bin -DBOOTLOADER_FILE=${CMAKE_BINARY_DIR}/ecoboot.bin - -DBOOTLOADER_VERSION_FILE=${CMAKE_BINARY_DIR}/ecoboot.version -DBOOT_FILENAME=boot.bin -DBOOT_FILE=$ -DBOOT_VERSION=${PROJECT_VERSION} -DUPDATER_FILENAME=updater.bin -DUPDATER_FILE=${CMAKE_BINARY_DIR}/updater.bin - -DUPDATER_VERSION_FILE=${CMAKE_BINARY_DIR}/PureUpdater.version -DOS_VERSION_MAJOR=${OS_VERSION_MAJOR} -DOS_VERSION_MINOR=${OS_VERSION_MINOR} -DOS_VERSION_PATCH=${OS_VERSION_PATCH} -DOS_VERSION_LABEL=${OS_VERSION_LABEL} + -DECOBOOT_BIN_VERSION=${ECOBOOT_BIN_VERSION} + -DUPDATER_BIN_VERSION=${UPDATER_BIN_VERSION} -B ${CMAKE_BINARY_DIR} -P ${CMAKE_SOURCE_DIR}/cmake/modules/ConfigureVersionJson.cmake DEPENDS ecoboot.bin-target diff --git a/cmake/modules/ConfigureVersionJson.cmake b/cmake/modules/ConfigureVersionJson.cmake index ad65b9598defef2d06d2fb12938956501f61ffe1..3d153559ef543d4af766969316f0d0ff51502cfc 100644 --- a/cmake/modules/ConfigureVersionJson.cmake +++ b/cmake/modules/ConfigureVersionJson.cmake @@ -1,12 +1,8 @@ list(APPEND CMAKE_MODULE_PATH "${SRC_DIR}/cmake/modules") include(Version) -file(READ ${BOOTLOADER_VERSION_FILE} BOOTLOADER_VERSION) file(MD5 ${BOOTLOADER_FILE} BOOTLOADER_MD5SUM) file(MD5 ${BOOT_FILE} BOOT_MD5SUM) - -file(READ ${UPDATER_VERSION_FILE} UPDATER_VERSION) -string(STRIP ${UPDATER_VERSION} UPDATER_VERSION) file(MD5 ${UPDATER_FILE} UPDATER_MD5SUM) message("Configuring version.json file") diff --git a/cmake/modules/DownloadAsset.cmake b/cmake/modules/DownloadAsset.cmake new file mode 100644 index 0000000000000000000000000000000000000000..35bdf37e11d6bb0d33480c36b2c5c63ca16d121b --- /dev/null +++ b/cmake/modules/DownloadAsset.cmake @@ -0,0 +1,19 @@ +function(download_asset asset_name_in asset_name_out asset_repo asset_version) + add_custom_command(OUTPUT ${asset_repo} + COMMAND ${CMAKE_SOURCE_DIR}/tools/download_asset.py + "$<$:-t$ENV{ASSETS_TOKEN}>" + --workdir ${CMAKE_BINARY_DIR} + --repository ${asset_repo} + download + --product ${PRODUCT} + --version ${asset_version} + --assetRepoName ${asset_name_in} + --assetOutName ${asset_name_out} + COMMENT "Downloading updater.bin" + ) + + add_custom_target(${asset_name_out}-target DEPENDS ${asset_repo}) + + multicomp_install(PROGRAMS ${CMAKE_BINARY_DIR}/${asset_repo} DESTINATION "./" + COMPONENTS Standalone Update) +endfunction() diff --git a/cmake/modules/FetchBootloader.cmake b/cmake/modules/FetchBootloader.cmake deleted file mode 100644 index 1f8902bb00e239a9d65073c730203f3c09a18e72..0000000000000000000000000000000000000000 --- a/cmake/modules/FetchBootloader.cmake +++ /dev/null @@ -1,23 +0,0 @@ -function(fetch_ecoboot) - set(ECOBOOT_ASSET_NAME ecoboot.bin) - if(${BOARD} STREQUAL "puretx" AND ${BOARD_REVISION} LESS_EQUAL 6) - set(ECOBOOT_ASSET_NAME ecoboot_T6.bin) - endif() - - add_custom_command(OUTPUT ecoboot.bin - COMMAND ${CMAKE_SOURCE_DIR}/tools/download_asset.py - "$<$:-l$ENV{ASSETS_LOGIN}>" - "$<$:-t$ENV{ASSETS_TOKEN}>" - -w ${CMAKE_BINARY_DIR} - ecoboot download - -n ${ECOBOOT_ASSET_NAME} - -o ecoboot.bin - COMMENT "Downloading ecoboot.bin" - BYPRODUCTS ecoboot.version - ) - - add_custom_target(ecoboot.bin-target DEPENDS ecoboot.bin) - - multicomp_install(PROGRAMS ${CMAKE_BINARY_DIR}/ecoboot.bin DESTINATION "./" - COMPONENTS Standalone Update) -endfunction() diff --git a/cmake/modules/FetchPureUpdater.cmake b/cmake/modules/FetchPureUpdater.cmake deleted file mode 100644 index 134b9d5c2f83d500fa8e00d24de3ee1b7b1bf9d4..0000000000000000000000000000000000000000 --- a/cmake/modules/FetchPureUpdater.cmake +++ /dev/null @@ -1,20 +0,0 @@ -function(fetch_updater) - set(UPDATER_ASSET_NAME PureUpdater_RT.bin) - - add_custom_command(OUTPUT updater.bin - COMMAND ${CMAKE_SOURCE_DIR}/tools/download_asset.py - "$<$:-l$ENV{ASSETS_LOGIN}>" - "$<$:-t$ENV{ASSETS_TOKEN}>" - -w ${CMAKE_BINARY_DIR} - PureUpdater download - -n ${UPDATER_ASSET_NAME} - -o updater.bin - COMMENT "Downloading updater.bin" - BYPRODUCTS PureUpdater.version - ) - - add_custom_target(updater.bin-target DEPENDS updater.bin) - - multicomp_install(PROGRAMS ${CMAKE_BINARY_DIR}/updater.bin DESTINATION "./" - COMPONENTS Standalone Update) -endfunction() diff --git a/config/version.json.cmake_template b/config/version.json.cmake_template index cbeadf4e1d71f2387673ca4534d65574e097b601..cf52b08c6e7f6748663c98fedd10856ef07f0c6f 100644 --- a/config/version.json.cmake_template +++ b/config/version.json.cmake_template @@ -10,7 +10,7 @@ }, "bootloader": { - "version": "@BOOTLOADER_VERSION@", + "version": "@ECOBOOT_BIN_VERSION@", "filename": "@BOOTLOADER_FILENAME@", "md5sum": "@BOOTLOADER_MD5SUM@" }, @@ -22,7 +22,7 @@ }, "updater": { - "version": "@UPDATER_VERSION@", + "version": "@UPDATER_BIN_VERSION@", "filename": "@UPDATER_FILENAME@", "md5sum": "@UPDATER_MD5SUM@" } diff --git a/products/BellHybrid/BinaryAssetsVersions.cmake b/products/BellHybrid/BinaryAssetsVersions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..405e5cb4c036c7b26c9e68693ea1bc48b043cbec --- /dev/null +++ b/products/BellHybrid/BinaryAssetsVersions.cmake @@ -0,0 +1,9 @@ +# This file sets versions of downloaded binaries for release packaging purposes + +if( NOT DEFINED ECOBOOT_BIN_VERSION) + set(ECOBOOT_BIN_VERSION 1.0.17 CACHE STRING "bootloader binary version to download from bootloader release page") +endif() + +if (NOT DEFINED UPDATER_BIN_VERSION) + set(UPDATER_BIN_VERSION 1.1.2 CACHE STRING "updater binary version to download from updater release page") +endif() diff --git a/products/BellHybrid/CMakeLists.txt b/products/BellHybrid/CMakeLists.txt index 48f76c9d64c8d6dab855ebd90058ac788051e082..8027d7b4861cb1683851ef27298a860ca033f4f4 100644 --- a/products/BellHybrid/CMakeLists.txt +++ b/products/BellHybrid/CMakeLists.txt @@ -82,6 +82,11 @@ add_image( include(AddHexTarget) add_hex_target(BellHybrid) +include(BinaryAssetsVersions.cmake) +include(DownloadAsset) +download_asset(PureUpdater_RT.bin updater.bin PureUpdater ${UPDATER_BIN_VERSION}) +download_asset(ecoboot.bin ecoboot.bin ecoboot ${ECOBOOT_BIN_VERSION}) + include(AddVersionJson) add_version_json(BellHybrid) diff --git a/products/PurePhone/BinaryAssetsVersions.cmake b/products/PurePhone/BinaryAssetsVersions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..405e5cb4c036c7b26c9e68693ea1bc48b043cbec --- /dev/null +++ b/products/PurePhone/BinaryAssetsVersions.cmake @@ -0,0 +1,9 @@ +# This file sets versions of downloaded binaries for release packaging purposes + +if( NOT DEFINED ECOBOOT_BIN_VERSION) + set(ECOBOOT_BIN_VERSION 1.0.17 CACHE STRING "bootloader binary version to download from bootloader release page") +endif() + +if (NOT DEFINED UPDATER_BIN_VERSION) + set(UPDATER_BIN_VERSION 1.1.2 CACHE STRING "updater binary version to download from updater release page") +endif() diff --git a/products/PurePhone/CMakeLists.txt b/products/PurePhone/CMakeLists.txt index ec3a305369de6f6c1fa51a76ac447670c2d29388..a76c58ea3958847f41c4a1d7689ba3ccb82217b0 100644 --- a/products/PurePhone/CMakeLists.txt +++ b/products/PurePhone/CMakeLists.txt @@ -99,6 +99,11 @@ add_image( include(AddHexTarget) add_hex_target(PurePhone) +include(BinaryAssetsVersions.cmake) +include(DownloadAsset) +download_asset(PureUpdater_RT.bin updater.bin PureUpdater ${UPDATER_BIN_VERSION}) +download_asset(ecoboot.bin ecoboot.bin ecoboot ${ECOBOOT_BIN_VERSION}) + include(AddVersionJson) add_version_json(PurePhone) diff --git a/tools/README.md b/tools/README.md index f0dec9964e2d8d850aef632a34d00d7e59ccd36b..701c9db4ffa2e19b958553a43a7589da484072e6 100644 --- a/tools/README.md +++ b/tools/README.md @@ -42,7 +42,7 @@ curl -o /dev/null -H "Authorization: token $(git config user.apitoken)" "https:/ 2. Check if you can list releases on repository: ``` -python3 ./tools/download_asset.py -w ./ PureUpdater list 21s[cbe063dc6] +python3 ./tools/download_asset.py -w ./ --repository PureUpdater list 21s[cbe063dc6] ``` **if not** Then fix your token, or request access to PureUpdater diff --git a/tools/download_asset.py b/tools/download_asset.py index a2584bd8d03cab21339c0af87690775749b65be4..3673acd6bfefecaa2bde0c131e2a036bc02d7070 100755 --- a/tools/download_asset.py +++ b/tools/download_asset.py @@ -83,11 +83,12 @@ class Getter(object): def getReleases(self, args): '''List only releases''' + print(f"{sys._getframe().f_code.co_name}") self.args = args self.getGHLogin(args) self.getApiToken(args) request = self.genRestPrefix() + "releases" - print ("Request:", request) + print (f"Request: {request}") headers = {'accept': 'application/vnd.github.v3+json'} page = 0 itemsOnPage = 100 @@ -121,29 +122,46 @@ class Getter(object): for release in self.releases: print(release['tag_name'], release['name'], release['published_at'], release['prerelease'], sep=" | ") + def getProductByName(self, repository: str, product: str, version: str) -> str: + ''' + We have naming convetion of releases: + "$Product $Version" + where: + - product is product built i.e. ecoboot + - version - is semantic version we use + ''' + if "bell" in product.lower(): + product = "bell" + elif "pure" in product.lower(): + product = "pure" + else: + print("we require short version in this script - either pure or bell") + sys.exit(2) + + return f"{repository} {version}-{product}" + def downloadRelease(self, args): - print(sys._getframe().f_code.co_name) + print(f"{sys._getframe().f_code.co_name} from: {args.repository}") self.getReleases(args) - print("tag:", args.tag) - print("asset:", args.assetRepoName) + release_requested = self.getProductByName(args.repository, args.product, args.version) release = None - if args.tag is None: - release = self.releases[0] - else: - for rel in self.releases: - if rel['tag_name'] == args.tag: - release = rel - break + for rel in self.releases: + # warning just taken first from partial match, should be done differently + if release_requested in rel['name']: + release = rel + break if release is None: - print("No release with tag:", args.tag) - print("release:", release['tag_name']) + raise RuntimeError(f"Can't get release by release name: {release_requested} with args: {args}") + print(f"Trying to download release from {args.repository} under name: {release_requested}") assets = release['assets'] + found = False for asset in assets: if asset['name'] == args.assetRepoName: self.downloadAsset(asset, args.assetOutName) - with open(args.workdir + '/' + args.repository + '.version', 'w+') as versionfile: - versionfile.write(release['tag_name']) + found = True + if not found: + raise(RuntimeError(f"asset not found {args.assetRepoName} and cant be saved as {args.assetOutName}")) def downloadAsset(self, asset, outName): self.createWorkdir() @@ -182,7 +200,7 @@ def main(): getter = Getter() parser = argparse.ArgumentParser(description="Download ecooboot") - parser.add_argument('-w', '--workdir', help="Directory where package is build", default="update") + parser.add_argument('--workdir', help="Directory where package is build", default="update") parser.add_argument('-t', '--token', help="GitHub security token " "by default read from `git config user.apitoken` " @@ -197,7 +215,7 @@ def main(): "`git config -add user.githublogin `", required=(getter.ghLogin is None)) - parser.add_argument('repository', help="repository name from which assets will be downloaded") + parser.add_argument('--repository', help="repository name from which assets will be downloaded") parser.set_defaults(func=getter.run) subparsers = parser.add_subparsers(title="commands", @@ -209,9 +227,10 @@ def main(): getReleases_args = subparsers.add_parser('download', aliases=['dw'], description="Download Release based on tag or the latest") getReleases_args.set_defaults(func=getter.downloadRelease) - getReleases_args.add_argument('tag', help="Download release with selected tag", nargs='?') - getReleases_args.add_argument('-n', '--assetRepoName', help="Asset name in repository", required=True) - getReleases_args.add_argument('-o', '--assetOutName', help="Asset output name", required=True) + getReleases_args.add_argument('--assetRepoName', help="Asset name in repository", required=True) + getReleases_args.add_argument('--assetOutName', help="Asset output name", required=True) + getReleases_args.add_argument('--version', help="Asset version", required=True) + getReleases_args.add_argument('--product', help="Asset product", required=True) args = parser.parse_args() getter.repo = args.repository