diff --git a/firmware/targets/f7/furi_hal/furi_hal_version.c b/firmware/targets/f7/furi_hal/furi_hal_version.c index 0d87c8073..ab635be54 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_version.c +++ b/firmware/targets/f7/furi_hal/furi_hal_version.c @@ -106,6 +106,10 @@ static void furi_hal_version_set_name(const char* name) { // BLE Mac address uint32_t udn = LL_FLASH_GetUDN(); + if(version_get_custom_name(NULL) != NULL) { + udn = (uint32_t)*version_get_custom_name(NULL); + } + uint32_t company_id = LL_FLASH_GetSTCompanyID(); uint32_t device_id = LL_FLASH_GetDeviceID(); furi_hal_version.ble_mac[0] = (uint8_t)(udn & 0x000000FF); @@ -129,7 +133,11 @@ static void furi_hal_version_load_otp_v0() { furi_hal_version.board_body = otp->board_body; furi_hal_version.board_connect = otp->board_connect; - furi_hal_version_set_name(otp->name); + if(version_get_custom_name(NULL) != NULL) { + furi_hal_version_set_name(version_get_custom_name(NULL)); + } else { + furi_hal_version_set_name(otp->name); + } } static void furi_hal_version_load_otp_v1() { @@ -143,7 +151,11 @@ static void furi_hal_version_load_otp_v1() { furi_hal_version.board_color = otp->board_color; furi_hal_version.board_region = otp->board_region; - furi_hal_version_set_name(otp->name); + if(version_get_custom_name(NULL) != NULL) { + furi_hal_version_set_name(version_get_custom_name(NULL)); + } else { + furi_hal_version_set_name(otp->name); + } } static void furi_hal_version_load_otp_v2() { @@ -163,7 +175,11 @@ static void furi_hal_version_load_otp_v2() { if(otp->board_color != 0xFF) { furi_hal_version.board_color = otp->board_color; furi_hal_version.board_region = otp->board_region; - furi_hal_version_set_name(otp->name); + if(version_get_custom_name(NULL) != NULL) { + furi_hal_version_set_name(version_get_custom_name(NULL)); + } else { + furi_hal_version_set_name(otp->name); + } } else { furi_hal_version.board_color = 0; furi_hal_version.board_region = 0; @@ -301,5 +317,8 @@ size_t furi_hal_version_uid_size() { } const uint8_t* furi_hal_version_uid() { + if(version_get_custom_name(NULL) != NULL) { + return (const uint8_t*)((uint32_t)*version_get_custom_name(NULL)); + } return (const uint8_t*)UID64_BASE; } diff --git a/lib/toolbox/version.c b/lib/toolbox/version.c index c6c10b410..ae4ef2e3f 100644 --- a/lib/toolbox/version.c +++ b/lib/toolbox/version.c @@ -8,6 +8,7 @@ struct Version { const char* git_branch; const char* git_branch_num; const char* build_date; + const char* custom_flipper_name; const char* version; const uint8_t target; const bool build_is_dirty; @@ -19,6 +20,11 @@ static const Version version = { .git_branch = GIT_BRANCH, .git_branch_num = GIT_BRANCH_NUM, .build_date = BUILD_DATE, +#ifdef FURI_CUSTOM_FLIPPER_NAME + .custom_flipper_name = FURI_CUSTOM_FLIPPER_NAME, +#else + .custom_flipper_name = NULL, +#endif .version = VERSION #ifdef FURI_RAM_EXEC " (RAM)" @@ -52,6 +58,10 @@ const char* version_get_version(const Version* v) { return v ? v->version : version.version; } +const char* version_get_custom_name(const Version* v) { + return v ? v->custom_flipper_name : version.custom_flipper_name; +} + uint8_t version_get_target(const Version* v) { return v ? v->target : version.target; } diff --git a/lib/toolbox/version.h b/lib/toolbox/version.h index 652ff3fea..ed54631b3 100644 --- a/lib/toolbox/version.h +++ b/lib/toolbox/version.h @@ -2,6 +2,7 @@ #include #include +#include #ifdef __cplusplus extern "C" { @@ -64,6 +65,15 @@ const char* version_get_builddate(const Version* v); */ const char* version_get_version(const Version* v); +/** Get custom flipper name if set in ENV + * + * @param v pointer to Version data. NULL for currently running + * software. + * + * @return custom name or NULL + */ +const char* version_get_custom_name(const Version* v); + /** Get hardware target this firmware was built for * * @param v pointer to Version data. NULL for currently running diff --git a/scripts/sconsdist.py b/scripts/sconsdist.py index 1e95ee2f2..2520f130a 100644 --- a/scripts/sconsdist.py +++ b/scripts/sconsdist.py @@ -2,7 +2,7 @@ from flipper.app import App from os.path import join, exists -from os import makedirs +from os import makedirs, environ from update import Main as UpdateMain import shutil @@ -134,6 +134,15 @@ class Main(App): self.logger.info( f"Use this directory to self-update your Flipper:\n\t{bundle_dir}" ) + log_custom_fz_name = ( + environ.get("CUSTOM_FLIPPER_NAME", None) + or "" + ) + if (log_custom_fz_name != ""): + self.logger.info( + f"Flipper Custom Name is set:\n\tName: {log_custom_fz_name} : length - {len(log_custom_fz_name)} chars" + ) + return UpdateMain(no_exit=True)(bundle_args) return 0 diff --git a/scripts/version.py b/scripts/version.py index 8abb5bbd2..5f34f1b1f 100644 --- a/scripts/version.py +++ b/scripts/version.py @@ -37,13 +37,28 @@ class GitVersion: or "unknown" ) - return { - "GIT_COMMIT": commit, - "GIT_BRANCH": branch, - "GIT_BRANCH_NUM": branch_num, - "VERSION": version, - "BUILD_DIRTY": dirty and 1 or 0, - } + custom_fz_name = ( + os.environ.get("CUSTOM_FLIPPER_NAME", None) + or "" + ) + + if (custom_fz_name != "") and (len(custom_fz_name) <= 8): + return { + "GIT_COMMIT": commit, + "GIT_BRANCH": branch, + "GIT_BRANCH_NUM": branch_num, + "FURI_CUSTOM_FLIPPER_NAME": custom_fz_name, + "VERSION": version, + "BUILD_DIRTY": dirty and 1 or 0, + } + else: + return { + "GIT_COMMIT": commit, + "GIT_BRANCH": branch, + "GIT_BRANCH_NUM": branch_num, + "VERSION": version, + "BUILD_DIRTY": dirty and 1 or 0, + } def _exec_git(self, args): cmd = ["git"] diff --git a/site_scons/commandline.scons b/site_scons/commandline.scons index 4c96268b6..bb9a04d4f 100644 --- a/site_scons/commandline.scons +++ b/site_scons/commandline.scons @@ -76,6 +76,12 @@ vars.Add( default="local", ) +vars.Add( + "CUSTOM_FLIPPER_NAME", + help="Replaces OTP flipper name with custom string of 8 chars", + default="", +) + vars.Add( "UPDATE_VERSION_STRING", help="Version string for updater package", diff --git a/site_scons/environ.scons b/site_scons/environ.scons index 99d4cc0b5..f1668ab16 100644 --- a/site_scons/environ.scons +++ b/site_scons/environ.scons @@ -12,7 +12,7 @@ forward_os_env = { "PATH": os.environ["PATH"], } # Proxying CI environment to child processes & scripts -for env_value_name in ("WORKFLOW_BRANCH_OR_TAG", "DIST_SUFFIX", "HOME", "APPDATA"): +for env_value_name in ("WORKFLOW_BRANCH_OR_TAG", "DIST_SUFFIX", "CUSTOM_FLIPPER_NAME", "HOME", "APPDATA"): if environ_value := os.environ.get(env_value_name, None): forward_os_env[env_value_name] = environ_value