allow setting custom flipper name

serial & ble mac generated from custom name (if set), CI support added too
This commit is contained in:
MX 2022-08-14 05:34:54 +03:00
parent 4dab3a83a3
commit a896aa4113
No known key found for this signature in database
GPG key ID: 6C4C311DFD4B4AB5
7 changed files with 81 additions and 12 deletions

View file

@ -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;
}

View file

@ -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;
}

View file

@ -2,6 +2,7 @@
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#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

View file

@ -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

View file

@ -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"]

View file

@ -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",

View file

@ -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