From 7b9e26bc684a5655bc2c375aa7b3405748c240c5 Mon Sep 17 00:00:00 2001 From: hedger Date: Fri, 26 May 2023 15:51:38 +0400 Subject: [PATCH 01/10] fbt: added hooks for build & dist environments --- firmware.scons | 4 +++ scripts/fbt_tools/fbt_fwflavor.py | 55 +++++++++++++++++++++++++++++++ scripts/ufbt/SConstruct | 5 +++ 3 files changed, 64 insertions(+) create mode 100644 scripts/fbt_tools/fbt_fwflavor.py diff --git a/firmware.scons b/firmware.scons index c46996899135..f02349a17b79 100644 --- a/firmware.scons +++ b/firmware.scons @@ -18,6 +18,7 @@ env = ENV.Clone( "fbt_apps", "pvsstudio", "fbt_hwtarget", + "fbt_fwflavor", ], COMPILATIONDB_USE_ABSPATH=False, BUILD_DIR=fw_build_meta["build_dir"], @@ -72,6 +73,8 @@ env = ENV.Clone( _APP_ICONS=None, ) +env.PreConfigureFwEnvionment() + if env["IS_BASE_FIRMWARE"]: env.Append( FIRMWARE_BUILD_CFG="firmware", @@ -271,5 +274,6 @@ if should_gen_cdb_and_link_dir(fwenv, BUILD_TARGETS): Alias(fwenv["FIRMWARE_BUILD_CFG"] + "_all", fw_artifacts) +env.PostConfigureFwEnvionment() Return("fwenv") diff --git a/scripts/fbt_tools/fbt_fwflavor.py b/scripts/fbt_tools/fbt_fwflavor.py new file mode 100644 index 000000000000..93944d80c5cf --- /dev/null +++ b/scripts/fbt_tools/fbt_fwflavor.py @@ -0,0 +1,55 @@ +""" +Use this file to introduce changes to firmware build environment +that are specific to your fork. For example, you can add new +defines that will be a part of SDK build, so applications can +use them for conditional compilation. +""" + + +def PreConfigureFwEnvionment(env): + """ + This function is called on firmware environment (incl. updater) + before any major configuration is done. + """ + # print("PreConfigureFwEnvionment") + env.Append( + CPPDEFINES=["FW_OFFICIAL"], + ) + + +def PostConfigureFwEnvionment(env): + """ + This function is called on firmware environment (incl. updater) + after all configuration is done. + """ + # print("PostConfigureFwEnvionment") + pass + + +def PreConfigureUfbtEnvionment(env): + """ + This function is called on ufbt environment at the beginning of + its configuration, before dist environment is created. + """ + # print("PreConfigureUfbtEnvionment") + pass + + +def PostConfigureUfbtEnvionment(env): + # print("PostConfigureUfbtEnvionment") + """ + This function is called on ufbt dist_env environment after all + configuration and target creation is done. + """ + pass + + +def generate(env): + env.AddMethod(PreConfigureFwEnvionment) + env.AddMethod(PostConfigureFwEnvionment) + env.AddMethod(PreConfigureUfbtEnvionment) + env.AddMethod(PostConfigureUfbtEnvionment) + + +def exists(): + return True diff --git a/scripts/ufbt/SConstruct b/scripts/ufbt/SConstruct index 4dd1fb5b9044..1faa3156f06e 100644 --- a/scripts/ufbt/SConstruct +++ b/scripts/ufbt/SConstruct @@ -98,6 +98,7 @@ env = core_env.Clone( "fbt_apps", "fbt_extapps", "fbt_assets", + "fbt_fwflavor", ("compilation_db", {"COMPILATIONDB_COMSTR": "\tCDB\t${TARGET}"}), ], FBT_FAP_DEBUG_ELF_ROOT=ufbt_build_dir, @@ -117,6 +118,8 @@ env = core_env.Clone( wrap_tempfile(env, "LINKCOM") wrap_tempfile(env, "ARCOM") +env.PreConfigureUfbtEnvionment() + # print(env.Dump()) # Dist env @@ -474,3 +477,5 @@ dist_env.PhonyTarget( "env", "@echo $( ${FBT_SCRIPT_DIR}/toolchain/fbtenv.sh $)", ) + +dist_env.PostConfigureUfbtEnvionment() From a52bb26cf3bf477f4bdd17847747cd5e26d36207 Mon Sep 17 00:00:00 2001 From: hedger Date: Fri, 26 May 2023 22:00:02 +0400 Subject: [PATCH 02/10] Moved env hooks to an optional file --- firmware.scons | 2 +- scripts/fbt_tools/fbt_envhooks.py | 62 +++++++++++++++++++++++++++++++ scripts/fbt_tools/fbt_fwflavor.py | 55 --------------------------- scripts/ufbt/SConstruct | 2 +- 4 files changed, 64 insertions(+), 57 deletions(-) create mode 100644 scripts/fbt_tools/fbt_envhooks.py delete mode 100644 scripts/fbt_tools/fbt_fwflavor.py diff --git a/firmware.scons b/firmware.scons index f02349a17b79..72d0a150371a 100644 --- a/firmware.scons +++ b/firmware.scons @@ -18,7 +18,7 @@ env = ENV.Clone( "fbt_apps", "pvsstudio", "fbt_hwtarget", - "fbt_fwflavor", + "fbt_envhooks", ], COMPILATIONDB_USE_ABSPATH=False, BUILD_DIR=fw_build_meta["build_dir"], diff --git a/scripts/fbt_tools/fbt_envhooks.py b/scripts/fbt_tools/fbt_envhooks.py new file mode 100644 index 000000000000..53e9219edee2 --- /dev/null +++ b/scripts/fbt_tools/fbt_envhooks.py @@ -0,0 +1,62 @@ +""" + +To introduce changes to firmware build environment that are specific to your fork: + + create a file "scripts/fbt/fbt_hooks.py" + +With it, you can define functions that will be called at specific points of +firmware build configuration, with environment as an argument. + +For example, you can define a function `PreConfigureFwEnvionment(env)` that +defines that will be a part of SDK build, so applications can +use them for conditional compilation. + +Here is a list of all available hooks: + + PreConfigureFwEnvionment(env): + This function is called on firmware environment (incl. updater) + before any major configuration is done. + + PostConfigureFwEnvionment(env): + This function is called on firmware environment (incl. updater) + after all configuration is done. + + PreConfigureUfbtEnvionment(env): + This function is called on ufbt environment at the beginning of + its configuration, before dist environment is created. + + PostConfigureUfbtEnvionment(env): + This function is called on ufbt dist_env environment after all + configuration and target creation is done. +""" + +try: + from fbt import fbt_hooks +except ImportError: + + class DefaultFbtHooks: + @staticmethod + def PreConfigureFwEnvionment(env): + # print("PreConfigureFwEnvionment") + env.Append( + CPPDEFINES=["FW_OFFICIAL"], + ) + + fbt_hooks = DefaultFbtHooks() + + +def generate(env): + stub_hook = lambda env: None + control_hooks = [ + "PreConfigureFwEnvionment", + "PostConfigureFwEnvionment", + "PreConfigureUfbtEnvionment", + "PostConfigureUfbtEnvionment", + ] + for hook_names in control_hooks: + hook_fn = getattr(fbt_hooks, hook_names, stub_hook) + env.AddMethod(hook_fn, hook_names) + + +def exists(): + return True diff --git a/scripts/fbt_tools/fbt_fwflavor.py b/scripts/fbt_tools/fbt_fwflavor.py deleted file mode 100644 index 93944d80c5cf..000000000000 --- a/scripts/fbt_tools/fbt_fwflavor.py +++ /dev/null @@ -1,55 +0,0 @@ -""" -Use this file to introduce changes to firmware build environment -that are specific to your fork. For example, you can add new -defines that will be a part of SDK build, so applications can -use them for conditional compilation. -""" - - -def PreConfigureFwEnvionment(env): - """ - This function is called on firmware environment (incl. updater) - before any major configuration is done. - """ - # print("PreConfigureFwEnvionment") - env.Append( - CPPDEFINES=["FW_OFFICIAL"], - ) - - -def PostConfigureFwEnvionment(env): - """ - This function is called on firmware environment (incl. updater) - after all configuration is done. - """ - # print("PostConfigureFwEnvionment") - pass - - -def PreConfigureUfbtEnvionment(env): - """ - This function is called on ufbt environment at the beginning of - its configuration, before dist environment is created. - """ - # print("PreConfigureUfbtEnvionment") - pass - - -def PostConfigureUfbtEnvionment(env): - # print("PostConfigureUfbtEnvionment") - """ - This function is called on ufbt dist_env environment after all - configuration and target creation is done. - """ - pass - - -def generate(env): - env.AddMethod(PreConfigureFwEnvionment) - env.AddMethod(PostConfigureFwEnvionment) - env.AddMethod(PreConfigureUfbtEnvionment) - env.AddMethod(PostConfigureUfbtEnvionment) - - -def exists(): - return True diff --git a/scripts/ufbt/SConstruct b/scripts/ufbt/SConstruct index 1faa3156f06e..d72de380c385 100644 --- a/scripts/ufbt/SConstruct +++ b/scripts/ufbt/SConstruct @@ -98,7 +98,7 @@ env = core_env.Clone( "fbt_apps", "fbt_extapps", "fbt_assets", - "fbt_fwflavor", + "fbt_envhooks", ("compilation_db", {"COMPILATIONDB_COMSTR": "\tCDB\t${TARGET}"}), ], FBT_FAP_DEBUG_ELF_ROOT=ufbt_build_dir, From 9006d649afeb630b0eb24e9d68fb76958aa7d74e Mon Sep 17 00:00:00 2001 From: hedger Date: Fri, 26 May 2023 22:18:43 +0400 Subject: [PATCH 03/10] Fixed var name --- scripts/fbt_tools/fbt_envhooks.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/fbt_tools/fbt_envhooks.py b/scripts/fbt_tools/fbt_envhooks.py index 53e9219edee2..91f547d5a9d2 100644 --- a/scripts/fbt_tools/fbt_envhooks.py +++ b/scripts/fbt_tools/fbt_envhooks.py @@ -53,9 +53,9 @@ def generate(env): "PreConfigureUfbtEnvionment", "PostConfigureUfbtEnvionment", ] - for hook_names in control_hooks: - hook_fn = getattr(fbt_hooks, hook_names, stub_hook) - env.AddMethod(hook_fn, hook_names) + for hook_name in control_hooks: + hook_fn = getattr(fbt_hooks, hook_name, stub_hook) + env.AddMethod(hook_fn, hook_name) def exists(): From 7dc9507b55e57284e102db7cc86a34ae125365a1 Mon Sep 17 00:00:00 2001 From: hedger Date: Fri, 26 May 2023 23:20:50 +0400 Subject: [PATCH 04/10] Added fw origin to device info --- firmware/targets/f7/furi_hal/furi_hal_info.c | 2 ++ scripts/fbt_tools/fbt_envhooks.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/firmware/targets/f7/furi_hal/furi_hal_info.c b/firmware/targets/f7/furi_hal/furi_hal_info.c index 4c034ff35217..a539bc418723 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_info.c +++ b/firmware/targets/f7/furi_hal/furi_hal_info.c @@ -173,6 +173,8 @@ void furi_hal_info_get(PropertyValueCallback out, char sep, void* context) { &property_context, "%d", 3, "firmware", "api", "major", api_version_major); property_value_out( &property_context, "%d", 3, "firmware", "api", "minor", api_version_minor); + + property_value_out(&property_context, NULL, 2, "firmware", "origin", TOSTRING(FW_ORIGIN)); } if(furi_hal_bt_is_alive()) { diff --git a/scripts/fbt_tools/fbt_envhooks.py b/scripts/fbt_tools/fbt_envhooks.py index 91f547d5a9d2..fbd26d1a784a 100644 --- a/scripts/fbt_tools/fbt_envhooks.py +++ b/scripts/fbt_tools/fbt_envhooks.py @@ -39,7 +39,7 @@ class DefaultFbtHooks: def PreConfigureFwEnvionment(env): # print("PreConfigureFwEnvionment") env.Append( - CPPDEFINES=["FW_OFFICIAL"], + CPPDEFINES=("FW_ORIGIN", "Official"), ) fbt_hooks = DefaultFbtHooks() From 1de9c5694e82b2b5ac389eafe872aa6b01596184 Mon Sep 17 00:00:00 2001 From: hedger Date: Fri, 26 May 2023 23:21:45 +0400 Subject: [PATCH 05/10] Bumped device info version --- firmware/targets/f7/furi_hal/furi_hal_info.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/targets/f7/furi_hal/furi_hal_info.c b/firmware/targets/f7/furi_hal/furi_hal_info.c index a539bc418723..a3d1e6d04e59 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_info.c +++ b/firmware/targets/f7/furi_hal/furi_hal_info.c @@ -26,7 +26,7 @@ void furi_hal_info_get(PropertyValueCallback out, char sep, void* context) { property_value_out(&property_context, NULL, 2, "format", "minor", "1"); } else { property_value_out(&property_context, NULL, 3, "device", "info", "major", "2"); - property_value_out(&property_context, NULL, 3, "device", "info", "minor", "1"); + property_value_out(&property_context, NULL, 3, "device", "info", "minor", "2"); } // Model name From 5ee9d1be7ee96fe35a2dad21d126c7b16a44075a Mon Sep 17 00:00:00 2001 From: hedger Date: Mon, 29 May 2023 18:50:35 +0400 Subject: [PATCH 06/10] fbt: added FIRMWARE_ORIGIN option. Different implementation for FW_ORIGIN_* C macro. --- fbt_options.py | 1 + firmware.scons | 7 ++++++ firmware/targets/f18/api_symbols.csv | 4 +++- firmware/targets/f7/api_symbols.csv | 4 +++- firmware/targets/f7/furi_hal/furi_hal_info.c | 18 ++++++++++++++- furi/core/core_defines.h | 5 +++++ lib/toolbox/version.c | 15 ++++++++++++- lib/toolbox/version.h | 11 ++++++++++ scripts/debug/flipperversion.py | 16 +++++++++++++- scripts/fbt_tools/fbt_envhooks.py | 23 ++++++++++++-------- scripts/fbt_tools/fbt_version.py | 4 +++- scripts/version.py | 23 ++++++++++++++++++++ site_scons/commandline.scons | 7 ++++++ 13 files changed, 123 insertions(+), 15 deletions(-) diff --git a/fbt_options.py b/fbt_options.py index d05b882a0cad..f503391933d8 100644 --- a/fbt_options.py +++ b/fbt_options.py @@ -2,6 +2,7 @@ # For more details on these options, run 'fbt -h' +FIRMWARE_ORIGIN = "Official" # Default hardware target TARGET_HW = 7 diff --git a/firmware.scons b/firmware.scons index 72d0a150371a..a91b7cdfc613 100644 --- a/firmware.scons +++ b/firmware.scons @@ -103,6 +103,13 @@ lib_targets = env.BuildModules( ], ) +# Configure firmware origin definitions +env.Append( + CPPDEFINES=[ + env.subst("FW_ORIGIN_${FIRMWARE_ORIGIN}"), + ] +) + # Now, env is fully set up with everything to build apps fwenv = env.Clone(FW_ARTIFACTS=[]) diff --git a/firmware/targets/f18/api_symbols.csv b/firmware/targets/f18/api_symbols.csv index 68248a6d2ba3..91b62052536d 100644 --- a/firmware/targets/f18/api_symbols.csv +++ b/firmware/targets/f18/api_symbols.csv @@ -1,5 +1,5 @@ entry,status,name,type,params -Version,+,27.0,, +Version,+,27.1,, Header,+,applications/services/bt/bt_service/bt.h,, Header,+,applications/services/cli/cli.h,, Header,+,applications/services/cli/cli_vcp.h,, @@ -1989,6 +1989,8 @@ Function,-,vdprintf,int,"int, const char*, __gnuc_va_list" Function,+,version_get,const Version*, Function,+,version_get_builddate,const char*,const Version* Function,+,version_get_dirty_flag,_Bool,const Version* +Function,+,version_get_firmware_origin,const char*,const Version* +Function,+,version_get_git_origin,const char*,const Version* Function,+,version_get_gitbranch,const char*,const Version* Function,+,version_get_gitbranchnum,const char*,const Version* Function,+,version_get_githash,const char*,const Version* diff --git a/firmware/targets/f7/api_symbols.csv b/firmware/targets/f7/api_symbols.csv index ccbaa531765c..0cbc47d7a4c2 100644 --- a/firmware/targets/f7/api_symbols.csv +++ b/firmware/targets/f7/api_symbols.csv @@ -1,5 +1,5 @@ entry,status,name,type,params -Version,+,27.0,, +Version,+,27.1,, Header,+,applications/services/bt/bt_service/bt.h,, Header,+,applications/services/cli/cli.h,, Header,+,applications/services/cli/cli_vcp.h,, @@ -2937,6 +2937,8 @@ Function,-,vdprintf,int,"int, const char*, __gnuc_va_list" Function,+,version_get,const Version*, Function,+,version_get_builddate,const char*,const Version* Function,+,version_get_dirty_flag,_Bool,const Version* +Function,+,version_get_firmware_origin,const char*,const Version* +Function,+,version_get_git_origin,const char*,const Version* Function,+,version_get_gitbranch,const char*,const Version* Function,+,version_get_gitbranchnum,const char*,const Version* Function,+,version_get_githash,const char*,const Version* diff --git a/firmware/targets/f7/furi_hal/furi_hal_info.c b/firmware/targets/f7/furi_hal/furi_hal_info.c index a3d1e6d04e59..47672c97a33a 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_info.c +++ b/firmware/targets/f7/furi_hal/furi_hal_info.c @@ -174,7 +174,23 @@ void furi_hal_info_get(PropertyValueCallback out, char sep, void* context) { property_value_out( &property_context, "%d", 3, "firmware", "api", "minor", api_version_minor); - property_value_out(&property_context, NULL, 2, "firmware", "origin", TOSTRING(FW_ORIGIN)); + property_value_out( + &property_context, + NULL, + 3, + "firmware", + "origin", + "fork", + version_get_firmware_origin(firmware_version)); + + property_value_out( + &property_context, + NULL, + 3, + "firmware", + "origin", + "git", + version_get_git_origin(firmware_version)); } if(furi_hal_bt_is_alive()) { diff --git a/furi/core/core_defines.h b/furi/core/core_defines.h index 830bb191c2ed..4309c20c5895 100644 --- a/furi/core/core_defines.h +++ b/furi/core/core_defines.h @@ -78,6 +78,11 @@ extern "C" { #define TOSTRING(x) STRINGIFY(x) #endif +#ifndef CONCATENATE +#define CONCATENATE(a, b) CONCATENATE_(a, b) +#define CONCATENATE_(a, b) a##b +#endif + #ifndef REVERSE_BYTES_U32 #define REVERSE_BYTES_U32(x) \ ((((x)&0x000000FF) << 24) | (((x)&0x0000FF00) << 8) | (((x)&0x00FF0000) >> 8) | \ diff --git a/lib/toolbox/version.c b/lib/toolbox/version.c index 6ba68e364d93..876695f07852 100644 --- a/lib/toolbox/version.c +++ b/lib/toolbox/version.c @@ -5,7 +5,7 @@ #define VERSION_MAGIC (0xBE40u) #define VERSION_MAJOR (0x1u) -#define VERSION_MINOR (0x0u) +#define VERSION_MINOR (0x1u) struct Version { // Header @@ -20,6 +20,9 @@ struct Version { // Payload bits and pieces const uint8_t target; const bool build_is_dirty; + // v 1.1 + const char* firmware_origin; + const char* git_origin; }; /* version of current running firmware (bootloader/flipper) */ @@ -37,6 +40,8 @@ static const Version version = { , .target = TARGET, .build_is_dirty = BUILD_DIRTY, + .firmware_origin = FIRMWARE_ORIGIN, + .git_origin = GIT_ORIGIN, }; const Version* version_get(void) { @@ -71,3 +76,11 @@ uint8_t version_get_target(const Version* v) { bool version_get_dirty_flag(const Version* v) { return v ? v->build_is_dirty : version.build_is_dirty; } + +const char* version_get_firmware_origin(const Version* v) { + return v ? v->firmware_origin : version.firmware_origin; +} + +const char* version_get_git_origin(const Version* v) { + return v ? v->git_origin : version.git_origin; +} diff --git a/lib/toolbox/version.h b/lib/toolbox/version.h index 652ff3feace8..0c04e5c75964 100644 --- a/lib/toolbox/version.h +++ b/lib/toolbox/version.h @@ -82,6 +82,17 @@ uint8_t version_get_target(const Version* v); */ bool version_get_dirty_flag(const Version* v); +/** + * Get firmware origin. "Official" for mainline firmware, fork name for forks. + * Set by FIRMWARE_ORIGIN fbt argument. +*/ +const char* version_get_firmware_origin(const Version* v); + +/** + * Get git repo origin +*/ +const char* version_get_git_origin(const Version* v); + #ifdef __cplusplus } #endif diff --git a/scripts/debug/flipperversion.py b/scripts/debug/flipperversion.py index 4ac3bd200d1e..56915c0f28e1 100644 --- a/scripts/debug/flipperversion.py +++ b/scripts/debug/flipperversion.py @@ -23,6 +23,10 @@ class VersionData: version: str target: int build_is_dirty: bool + # Since version 1.1 + firmware_origin: str = "" + git_origin: str = "" + # More fields may be added in the future extra: Optional[Dict[str, str]] = field(default_factory=dict) @@ -52,7 +56,7 @@ def load_versioned(self, major, minor): # Struct version 1.0 extra_data = int(self.version_ptr[5].cast(self._uint_type)) - return VersionData( + version_data = VersionData( git_hash=self.version_ptr[1].cast(self._cstr_type).string(), git_branch=self.version_ptr[2].cast(self._cstr_type).string(), build_date=self.version_ptr[3].cast(self._cstr_type).string(), @@ -60,6 +64,12 @@ def load_versioned(self, major, minor): target=extra_data & 0xF, build_is_dirty=bool((extra_data >> 8) & 0xF), ) + if minor >= 1: + version_data.firmware_origin = ( + self.version_ptr[6].cast(self._cstr_type).string() + ) + version_data.git_origin = self.version_ptr[7].cast(self._cstr_type).string() + return version_data def load_unversioned(self): """Parse an early version of the version struct.""" @@ -104,6 +114,10 @@ def invoke(self, arg, from_tty): print(f"\tGit commit: {v.version.git_hash}") print(f"\tDirty: {v.version.build_is_dirty}") print(f"\tHW Target: {v.version.target}") + if v.version.firmware_origin: + print(f"\tOrigin: {v.version.firmware_origin}") + if v.version.git_origin: + print(f"\tGit origin: {v.version.git_origin}") FlipperFwVersion() diff --git a/scripts/fbt_tools/fbt_envhooks.py b/scripts/fbt_tools/fbt_envhooks.py index fbd26d1a784a..0538e173c655 100644 --- a/scripts/fbt_tools/fbt_envhooks.py +++ b/scripts/fbt_tools/fbt_envhooks.py @@ -30,18 +30,14 @@ configuration and target creation is done. """ + +class DefaultFbtHooks: + pass + + try: from fbt import fbt_hooks except ImportError: - - class DefaultFbtHooks: - @staticmethod - def PreConfigureFwEnvionment(env): - # print("PreConfigureFwEnvionment") - env.Append( - CPPDEFINES=("FW_ORIGIN", "Official"), - ) - fbt_hooks = DefaultFbtHooks() @@ -53,6 +49,15 @@ def generate(env): "PreConfigureUfbtEnvionment", "PostConfigureUfbtEnvionment", ] + + if ( + isinstance(fbt_hooks, DefaultFbtHooks) + and env.subst("${FIRMWARE_ORIGIN}") != "Official" + ): + # If fbt_hooks.py is not present, but we are not building official firmware, + # create "scripts/fbt/fbt_hooks.py" to implement changes to firmware build environment. + pass + for hook_name in control_hooks: hook_fn = getattr(fbt_hooks, hook_name, stub_hook) env.AddMethod(hook_fn, hook_name) diff --git a/scripts/fbt_tools/fbt_version.py b/scripts/fbt_tools/fbt_version.py index 8469e181a32a..aead13b29fa5 100644 --- a/scripts/fbt_tools/fbt_version.py +++ b/scripts/fbt_tools/fbt_version.py @@ -19,7 +19,9 @@ def generate(env): BUILDERS={ "VersionBuilder": Builder( action=Action( - '${PYTHON3} "${VERSION_SCRIPT}" generate -t ${TARGET_HW} -o ${TARGET.dir.posix} --dir "${ROOT_DIR}"', + '${PYTHON3} "${VERSION_SCRIPT}" generate ' + "-t ${TARGET_HW} -fw-origin ${FIRMWARE_ORIGIN} " + '-o ${TARGET.dir.posix} --dir "${ROOT_DIR}"', "${VERSIONCOMSTR}", ), emitter=version_emitter, diff --git a/scripts/version.py b/scripts/version.py index 3d68b2e98d41..f00c1f531c1d 100644 --- a/scripts/version.py +++ b/scripts/version.py @@ -45,8 +45,23 @@ def get_version_info(self): "GIT_BRANCH": branch, "VERSION": version, "BUILD_DIRTY": dirty and 1 or 0, + "GIT_ORIGIN": ",".join(self._get_git_origins()), } + def _get_git_origins(self): + try: + remotes = self._exec_git("remote -v") + except subprocess.CalledProcessError: + return set() + origins = set() + for line in remotes.split("\n"): + if not line: + continue + _, destination = line.split("\t") + url, _ = destination.split(" ") + origins.add(url) + return origins + def _exec_git(self, args): cmd = ["git"] cmd.extend(args.split(" ")) @@ -74,6 +89,13 @@ def init(self): help="hardware target", required=True, ) + self.parser_generate.add_argument( + "-fw-origin", + dest="firmware_origin", + type=str, + help="firmware origin", + required=True, + ) self.parser_generate.add_argument("--dir", dest="sourcedir", required=True) self.parser_generate.set_defaults(func=self.generate) @@ -89,6 +111,7 @@ def generate(self): { "BUILD_DATE": build_date.strftime("%d-%m-%Y"), "TARGET": self.args.target, + "FIRMWARE_ORIGIN": self.args.firmware_origin, } ) diff --git a/site_scons/commandline.scons b/site_scons/commandline.scons index 2e9486627388..e31927c59427 100644 --- a/site_scons/commandline.scons +++ b/site_scons/commandline.scons @@ -236,6 +236,13 @@ vars.AddVariables( help="Don't open browser after generating error repots", default=False, ), + ( + "FIRMWARE_ORIGIN", + "Firmware origin. 'Official' if follows upstream's API structure, otherwise fork name. " + " This will also create a C define FW_ORIGIN_ so that " + " app can check what version it is being built for.", + "Official", + ), ) Return("vars") From 6baa24a5611639fe5efd171021a006172863f99b Mon Sep 17 00:00:00 2001 From: hedger Date: Mon, 29 May 2023 19:15:30 +0400 Subject: [PATCH 07/10] Fixed PVS warnings --- lib/nfc/parsers/opal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/nfc/parsers/opal.c b/lib/nfc/parsers/opal.c index b5ca37eb61d0..2a6b5d1221ac 100644 --- a/lib/nfc/parsers/opal.c +++ b/lib/nfc/parsers/opal.c @@ -143,7 +143,7 @@ bool opal_parser_parse(NfcDeviceData* dev_data) { // sign separately, because then we can handle balances of -99..-1 // cents, as the "dollars" division below would result in a positive // zero value. - o->balance = abs(o->balance); + o->balance = abs(o->balance); //-V1081 sign = "-"; } uint8_t cents = o->balance % 100; @@ -164,7 +164,7 @@ bool opal_parser_parse(NfcDeviceData* dev_data) { o->mode = 4; } - const char* mode_str = (o->mode <= 4 ? opal_modes[o->mode] : opal_modes[3]); + const char* mode_str = (o->mode <= 4 ? opal_modes[o->mode] : opal_modes[3]); //-V547 const char* usage_str = (o->usage <= 12 ? opal_usages[o->usage] : opal_usages[13]); furi_string_printf( From 18f3df5cd1fb0224cf85ee5954b45c143725a609 Mon Sep 17 00:00:00 2001 From: hedger Date: Mon, 29 May 2023 19:20:22 +0400 Subject: [PATCH 08/10] api: bumped versions --- firmware/targets/f18/api_symbols.csv | 2 +- firmware/targets/f7/api_symbols.csv | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/firmware/targets/f18/api_symbols.csv b/firmware/targets/f18/api_symbols.csv index 6d9076a3b89b..88e412bc888b 100644 --- a/firmware/targets/f18/api_symbols.csv +++ b/firmware/targets/f18/api_symbols.csv @@ -1,5 +1,5 @@ entry,status,name,type,params -Version,+,27.1,, +Version,+,27.2,, Header,+,applications/services/bt/bt_service/bt.h,, Header,+,applications/services/cli/cli.h,, Header,+,applications/services/cli/cli_vcp.h,, diff --git a/firmware/targets/f7/api_symbols.csv b/firmware/targets/f7/api_symbols.csv index fc1793d7ff23..aaf1b1f8c4e4 100644 --- a/firmware/targets/f7/api_symbols.csv +++ b/firmware/targets/f7/api_symbols.csv @@ -1,5 +1,5 @@ entry,status,name,type,params -Version,+,27.1,, +Version,+,27.2,, Header,+,applications/services/bt/bt_service/bt.h,, Header,+,applications/services/cli/cli.h,, Header,+,applications/services/cli/cli_vcp.h,, From 0d7ba08c8a0a0a7063053bf2bdacf1439b3c28bf Mon Sep 17 00:00:00 2001 From: hedger Date: Mon, 29 May 2023 20:26:44 +0400 Subject: [PATCH 09/10] fbt: added fbt_options_local.py --- .gitignore | 2 ++ documentation/fbt.md | 2 ++ fbt_options.py | 6 ++++++ 3 files changed, 10 insertions(+) diff --git a/.gitignore b/.gitignore index bf17a94e28d0..517f7ef63028 100644 --- a/.gitignore +++ b/.gitignore @@ -64,3 +64,5 @@ PVS-Studio.log *.PVS-Studio.* .gdbinit + +./fbt_options_local.py \ No newline at end of file diff --git a/documentation/fbt.md b/documentation/fbt.md index d9eb8f4aabbf..c19780ef5939 100644 --- a/documentation/fbt.md +++ b/documentation/fbt.md @@ -114,6 +114,8 @@ To run cleanup (think of `make clean`) for specified targets, add the `-c` optio Default configuration variables are set in the configuration file: `fbt_options.py`. Values set in the command line have higher precedence over the configuration file. +You can also create a file called `fbt_options_local.py` that will be evaluated when loading default options file, enabling persisent overriding of default options without modifying default configuration. + You can find out available options with `./fbt -h`. ### Firmware application set diff --git a/fbt_options.py b/fbt_options.py index f503391933d8..b6fcc70f2337 100644 --- a/fbt_options.py +++ b/fbt_options.py @@ -1,3 +1,4 @@ +from pathlib import Path import posixpath # For more details on these options, run 'fbt -h' @@ -76,3 +77,8 @@ } FIRMWARE_APP_SET = "default" + +custom_options_fn = "fbt_options_local.py" + +if Path(custom_options_fn).exists(): + exec(compile(Path(custom_options_fn).read_text(), custom_options_fn, "exec")) From ac2a56eeebb9bd6986bd567758384d09692c1243 Mon Sep 17 00:00:00 2001 From: hedger Date: Mon, 29 May 2023 20:30:43 +0400 Subject: [PATCH 10/10] gitignore: cleanup --- .gitignore | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 517f7ef63028..d60dcec3f5db 100644 --- a/.gitignore +++ b/.gitignore @@ -30,27 +30,25 @@ bindings/ .mxproject Brewfile.lock.json -# Visual Studio Code -/.vscode/ - # Kate .kateproject .kateconfig -# legendary cmake's -build -CMakeLists.txt - -# bundle output -dist - # kde .directory # SCons .sconsign.dblite + + +# Visual Studio Code +/.vscode + +# bundle output +/dist + # SCons build dir -build/ +/build # Toolchain /toolchain @@ -65,4 +63,4 @@ PVS-Studio.log .gdbinit -./fbt_options_local.py \ No newline at end of file +/fbt_options_local.py \ No newline at end of file