diff --git a/applications/cli/cli_commands.c b/applications/cli/cli_commands.c index 2e4d6b90c..aed635132 100644 --- a/applications/cli/cli_commands.c +++ b/applications/cli/cli_commands.c @@ -102,7 +102,10 @@ void cli_command_hw_info(Cli* cli, string_t args, void* context) { api_hal_version_get_hw_connect()); time_t time = api_hal_version_get_hw_timestamp(); printf("%-20s %s\r", "Production date:", ctime(&time)); - printf("%-20s %s", "Name:", api_hal_version_get_name_ptr()); + const char* name = api_hal_version_get_name_ptr(); + if(name) { + printf("%-20s %s", "Name:", name); + } } void cli_command_vibro(Cli* cli, string_t args, void* context) { diff --git a/firmware/targets/api-hal-include/api-hal-version.h b/firmware/targets/api-hal-include/api-hal-version.h index 19e1c3f32..0f2f7097c 100644 --- a/firmware/targets/api-hal-include/api-hal-version.h +++ b/firmware/targets/api-hal-include/api-hal-version.h @@ -9,6 +9,9 @@ extern "C" { #endif +/** Init flipper version */ +void api_hal_version_init(); + /** Check target firmware version */ bool api_hal_version_do_i_belong_here(); diff --git a/firmware/targets/f5/api-hal/api-hal-version.c b/firmware/targets/f5/api-hal/api-hal-version.c index 19fdbc3d1..6818fe300 100644 --- a/firmware/targets/f5/api-hal/api-hal-version.c +++ b/firmware/targets/f5/api-hal/api-hal-version.c @@ -11,6 +11,14 @@ typedef struct { char name[8]; } ApiHalVersionOTP; +// Initialiazed from OTP, used to guarantee zero terminated C string +static char flipper_name[9]; + +void api_hal_version_init() { + char* name = ((ApiHalVersionOTP*)OTP_AREA_BASE)->name; + strlcpy(flipper_name, name, 9); +} + bool api_hal_version_do_i_belong_here() { return api_hal_version_get_hw_target() == 5; } @@ -36,8 +44,7 @@ const uint32_t api_hal_version_get_hw_timestamp() { } const char * api_hal_version_get_name_ptr() { - char * name = ((ApiHalVersionOTP*)OTP_AREA_BASE)->name; - return *name == 0xFFU ? NULL : name; + return *flipper_name == 0xFFU ? NULL : flipper_name; } const struct Version* api_hal_version_get_fw_version(void) { diff --git a/firmware/targets/f5/api-hal/api-hal.c b/firmware/targets/f5/api-hal/api-hal.c index cf01b7fe1..222a41e56 100644 --- a/firmware/targets/f5/api-hal/api-hal.c +++ b/firmware/targets/f5/api-hal/api-hal.c @@ -1,6 +1,8 @@ #include void api_hal_init() { + api_hal_version_init(); + FURI_LOG_I("FURI_HAL", "VERSION OK"); api_hal_delay_init(); FURI_LOG_I("FURI_HAL", "DELAY OK"); api_hal_os_init(); diff --git a/firmware/targets/f6/api-hal/api-hal-version.c b/firmware/targets/f6/api-hal/api-hal-version.c index 19fdbc3d1..6818fe300 100644 --- a/firmware/targets/f6/api-hal/api-hal-version.c +++ b/firmware/targets/f6/api-hal/api-hal-version.c @@ -11,6 +11,14 @@ typedef struct { char name[8]; } ApiHalVersionOTP; +// Initialiazed from OTP, used to guarantee zero terminated C string +static char flipper_name[9]; + +void api_hal_version_init() { + char* name = ((ApiHalVersionOTP*)OTP_AREA_BASE)->name; + strlcpy(flipper_name, name, 9); +} + bool api_hal_version_do_i_belong_here() { return api_hal_version_get_hw_target() == 5; } @@ -36,8 +44,7 @@ const uint32_t api_hal_version_get_hw_timestamp() { } const char * api_hal_version_get_name_ptr() { - char * name = ((ApiHalVersionOTP*)OTP_AREA_BASE)->name; - return *name == 0xFFU ? NULL : name; + return *flipper_name == 0xFFU ? NULL : flipper_name; } const struct Version* api_hal_version_get_fw_version(void) { diff --git a/firmware/targets/f6/api-hal/api-hal.c b/firmware/targets/f6/api-hal/api-hal.c index cf01b7fe1..222a41e56 100644 --- a/firmware/targets/f6/api-hal/api-hal.c +++ b/firmware/targets/f6/api-hal/api-hal.c @@ -1,6 +1,8 @@ #include void api_hal_init() { + api_hal_version_init(); + FURI_LOG_I("FURI_HAL", "VERSION OK"); api_hal_delay_init(); FURI_LOG_I("FURI_HAL", "DELAY OK"); api_hal_os_init();