[FL-1355] Fix flipper name C string (#485)
* api-hal-version: guarantee zero terminated flipper name * cli_commands: fix hw_info command
This commit is contained in:
		
							parent
							
								
									f1e9a12eb0
								
							
						
					
					
						commit
						356476b7f8
					
				| @ -102,7 +102,10 @@ void cli_command_hw_info(Cli* cli, string_t args, void* context) { | |||||||
|         api_hal_version_get_hw_connect()); |         api_hal_version_get_hw_connect()); | ||||||
|     time_t time = api_hal_version_get_hw_timestamp(); |     time_t time = api_hal_version_get_hw_timestamp(); | ||||||
|     printf("%-20s %s\r", "Production date:", ctime(&time)); |     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) { | void cli_command_vibro(Cli* cli, string_t args, void* context) { | ||||||
|  | |||||||
| @ -9,6 +9,9 @@ | |||||||
| extern "C" { | extern "C" { | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
|  | /** Init flipper version */ | ||||||
|  | void api_hal_version_init(); | ||||||
|  | 
 | ||||||
| /** Check target firmware version */ | /** Check target firmware version */ | ||||||
| bool api_hal_version_do_i_belong_here(); | bool api_hal_version_do_i_belong_here(); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -11,6 +11,14 @@ typedef struct { | |||||||
|     char name[8]; |     char name[8]; | ||||||
| } ApiHalVersionOTP; | } 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() { | bool api_hal_version_do_i_belong_here() { | ||||||
|     return api_hal_version_get_hw_target() == 5; |     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() { | const char * api_hal_version_get_name_ptr() { | ||||||
|     char * name = ((ApiHalVersionOTP*)OTP_AREA_BASE)->name; |     return *flipper_name == 0xFFU ? NULL : flipper_name; | ||||||
|     return *name == 0xFFU ? NULL : name;  |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| const struct Version* api_hal_version_get_fw_version(void) { | const struct Version* api_hal_version_get_fw_version(void) { | ||||||
|  | |||||||
| @ -1,6 +1,8 @@ | |||||||
| #include <api-hal.h> | #include <api-hal.h> | ||||||
| 
 | 
 | ||||||
| void api_hal_init() { | void api_hal_init() { | ||||||
|  |     api_hal_version_init(); | ||||||
|  |     FURI_LOG_I("FURI_HAL", "VERSION OK"); | ||||||
|     api_hal_delay_init(); |     api_hal_delay_init(); | ||||||
|     FURI_LOG_I("FURI_HAL", "DELAY OK"); |     FURI_LOG_I("FURI_HAL", "DELAY OK"); | ||||||
|     api_hal_os_init(); |     api_hal_os_init(); | ||||||
|  | |||||||
| @ -11,6 +11,14 @@ typedef struct { | |||||||
|     char name[8]; |     char name[8]; | ||||||
| } ApiHalVersionOTP; | } 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() { | bool api_hal_version_do_i_belong_here() { | ||||||
|     return api_hal_version_get_hw_target() == 5; |     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() { | const char * api_hal_version_get_name_ptr() { | ||||||
|     char * name = ((ApiHalVersionOTP*)OTP_AREA_BASE)->name; |     return *flipper_name == 0xFFU ? NULL : flipper_name; | ||||||
|     return *name == 0xFFU ? NULL : name;  |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| const struct Version* api_hal_version_get_fw_version(void) { | const struct Version* api_hal_version_get_fw_version(void) { | ||||||
|  | |||||||
| @ -1,6 +1,8 @@ | |||||||
| #include <api-hal.h> | #include <api-hal.h> | ||||||
| 
 | 
 | ||||||
| void api_hal_init() { | void api_hal_init() { | ||||||
|  |     api_hal_version_init(); | ||||||
|  |     FURI_LOG_I("FURI_HAL", "VERSION OK"); | ||||||
|     api_hal_delay_init(); |     api_hal_delay_init(); | ||||||
|     FURI_LOG_I("FURI_HAL", "DELAY OK"); |     FURI_LOG_I("FURI_HAL", "DELAY OK"); | ||||||
|     api_hal_os_init(); |     api_hal_os_init(); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 gornekich
						gornekich