Просмотр исходного кода

[FL-1464] Cli: merge version and hwinfo into device_info (#553)

* Cli: merge version and hwinfo and form machine/human readable key value set.
* Backport F6 changes to F5. Add readme to cli_command_device_info rountine
* Cli: return proper order to radio stack version in device_info command

Co-authored-by: SG <who.just.the.doctor@gmail.com>
あく 4 лет назад
Родитель
Сommit
5d14dce013

+ 1 - 1
applications/cli/cli.c

@@ -101,7 +101,7 @@ void cli_motd() {
     cli_print_version(api_hal_version_get_boot_version());
 
     printf("Firmware\r\n");
-    cli_print_version(api_hal_version_get_fw_version());
+    cli_print_version(api_hal_version_get_firmware_version());
 }
 
 void cli_nl() {

+ 85 - 31
applications/cli/cli_commands.c

@@ -5,6 +5,86 @@
 #include <task-control-block.h>
 #include <time.h>
 #include <notification/notification-messages.h>
+#include <shci.h>
+
+/* 
+ * Device Info Command
+ * This command is intended to be used by humans and machines
+ * Keys and values format MUST NOT BE changed
+ */
+void cli_command_device_info(Cli* cli, string_t args, void* context) {
+    // Model name
+    printf("hardware_model      : %s\r\n", api_hal_version_get_model_name());
+    printf("hardware_name       : %s\r\n", api_hal_version_get_name_ptr());
+
+    // Unique ID
+    printf("hardware_uid        : ");
+    const uint8_t* uid = api_hal_version_uid();
+    for(size_t i = 0; i < api_hal_version_uid_size(); i++) {
+        printf("%02X", uid[i]);
+    }
+    printf("\r\n");
+
+    // Board Revision
+    printf("hardware_ver        : %d\r\n", api_hal_version_get_hw_version());
+    printf("hardware_target     : %d\r\n", api_hal_version_get_hw_target());
+    printf("hardware_body       : %d\r\n", api_hal_version_get_hw_body());
+    printf("hardware_connect    : %d\r\n", api_hal_version_get_hw_connect());
+
+    // Color and Region
+    printf("hardware_color      : %d\r\n", api_hal_version_get_hw_color());
+    printf("hardware_region     : %d\r\n", api_hal_version_get_hw_region());
+
+    // Bootloader Version
+    const Version* boot_version = api_hal_version_get_boot_version();
+    if(boot_version) {
+        printf("boot_version        : %s\r\n", version_get_version(boot_version));
+        printf("boot_commit         : %s\r\n", version_get_githash(boot_version));
+        printf("boot_branch         : %s\r\n", version_get_gitbranch(boot_version));
+        printf("boot_build_date     : %s\r\n", version_get_builddate(boot_version));
+    }
+
+    // Firmware version
+    const Version* firmware_version = api_hal_version_get_firmware_version();
+    if(firmware_version) {
+        printf("firmware_version    : %s\r\n", version_get_version(firmware_version));
+        printf("firmware_commit     : %s\r\n", version_get_githash(firmware_version));
+        printf("firmware_branch     : %s\r\n", version_get_gitbranch(firmware_version));
+        printf("firmware_build_date : %s\r\n", version_get_builddate(firmware_version));
+    }
+
+    WirelessFwInfo_t pWirelessInfo;
+    if(api_hal_bt_is_alive() && SHCI_GetWirelessFwInfo(&pWirelessInfo) == SHCI_Success) {
+        printf("radio_alive         : true\r\n");
+        // FUS Info
+        printf("radio_fus_major     : %d\r\n", pWirelessInfo.FusVersionMajor);
+        printf("radio_fus_minor     : %d\r\n", pWirelessInfo.FusVersionMinor);
+        printf("radio_fus_sub       : %d\r\n", pWirelessInfo.FusVersionSub);
+        printf("radio_fus_sram2b    : %dK\r\n", pWirelessInfo.FusMemorySizeSram2B);
+        printf("radio_fus_sram2a    : %dK\r\n", pWirelessInfo.FusMemorySizeSram2A);
+        printf("radio_fus_flash     : %dK\r\n", pWirelessInfo.FusMemorySizeFlash * 4);
+        // Stack Info
+        printf("radio_stack_type    : %d\r\n", pWirelessInfo.StackType);
+        printf("radio_stack_major   : %d\r\n", pWirelessInfo.VersionMajor);
+        printf("radio_stack_minor   : %d\r\n", pWirelessInfo.VersionMinor);
+        printf("radio_stack_sub     : %d\r\n", pWirelessInfo.VersionSub);
+        printf("radio_stack_branch  : %d\r\n", pWirelessInfo.VersionBranch);
+        printf("radio_stack_release : %d\r\n", pWirelessInfo.VersionReleaseType);
+        printf("radio_stack_sram2b  : %dK\r\n", pWirelessInfo.MemorySizeSram2B);
+        printf("radio_stack_sram2a  : %dK\r\n", pWirelessInfo.MemorySizeSram2A);
+        printf("radio_stack_sram1   : %dK\r\n", pWirelessInfo.MemorySizeSram1);
+        printf("radio_stack_flash   : %dK\r\n", pWirelessInfo.MemorySizeFlash * 4);
+        // Mac address
+        printf("radio_ble_mac       : ");
+        const uint8_t* ble_mac = api_hal_version_get_ble_mac();
+        for(size_t i = 0; i < 6; i++) {
+            printf("%02X", ble_mac[i]);
+        }
+        printf("\r\n");
+    } else {
+        printf("radio_alive         : false\r\n");
+    }
+}
 
 void cli_command_help(Cli* cli, string_t args, void* context) {
     (void)args;
@@ -39,32 +119,6 @@ void cli_command_help(Cli* cli, string_t args, void* context) {
     }
 }
 
-void cli_command_version(Cli* cli, string_t args, void* context) {
-    (void)args;
-    (void)context;
-    printf("Bootloader\r\n");
-    cli_print_version(api_hal_version_get_boot_version());
-
-    printf("Firmware\r\n");
-    cli_print_version(api_hal_version_get_fw_version());
-}
-
-void cli_command_uuid(Cli* cli, string_t args, void* context) {
-    (void)args;
-    (void)context;
-    size_t uid_size = api_hal_uid_size();
-    const uint8_t* uid = api_hal_uid();
-
-    string_t byte_str;
-    string_init(byte_str);
-    string_cat_printf(byte_str, "UID:");
-    for(size_t i = 0; i < uid_size; i++) {
-        uint8_t uid_byte = uid[i];
-        string_cat_printf(byte_str, "%02X", uid_byte);
-    }
-    printf(string_get_cstr(byte_str));
-}
-
 void cli_command_date(Cli* cli, string_t args, void* context) {
     RTC_TimeTypeDef time;
     RTC_DateTypeDef date;
@@ -339,14 +393,14 @@ void cli_command_os_info(Cli* cli, string_t args, void* context) {
 }
 
 void cli_commands_init(Cli* cli) {
-    cli_add_command(cli, "help", cli_command_help, NULL);
+    cli_add_command(cli, "!", cli_command_device_info, NULL);
+    cli_add_command(cli, "device_info", cli_command_device_info, NULL);
+
     cli_add_command(cli, "?", cli_command_help, NULL);
-    cli_add_command(cli, "version", cli_command_version, NULL);
-    cli_add_command(cli, "!", cli_command_version, NULL);
-    cli_add_command(cli, "uid", cli_command_uuid, NULL);
+    cli_add_command(cli, "help", cli_command_help, NULL);
+
     cli_add_command(cli, "date", cli_command_date, NULL);
     cli_add_command(cli, "log", cli_command_log, NULL);
-    cli_add_command(cli, "hw_info", cli_command_hw_info, NULL);
     cli_add_command(cli, "vibro", cli_command_vibro, NULL);
     cli_add_command(cli, "led", cli_command_led, NULL);
     cli_add_command(cli, "gpio_set", cli_command_gpio_set, NULL);

+ 1 - 1
applications/dolphin/dolphin_views.c

@@ -131,7 +131,7 @@ void dolphin_view_idle_down_draw(Canvas* canvas, void* model) {
         canvas_draw_str(canvas, 5, 23, buffer);
 
         ver = m->screen == DolphinViewStatsBoot ? api_hal_version_get_boot_version() :
-                                                  api_hal_version_get_fw_version();
+                                                  api_hal_version_get_firmware_version();
 
         if(!ver) {
             canvas_draw_str(canvas, 5, 33, "No info");

+ 1 - 1
core/flipper.c

@@ -29,7 +29,7 @@ void flipper_init() {
     version = (const Version*)api_hal_version_get_boot_version();
     flipper_print_version("Bootloader", version);
 
-    version = (const Version*)api_hal_version_get_fw_version();
+    version = (const Version*)api_hal_version_get_firmware_version();
     flipper_print_version("Firmware", version);
 
     FURI_LOG_I("FLIPPER", "starting services");

+ 0 - 18
firmware/targets/api-hal-include/api-hal-uid.h

@@ -1,18 +0,0 @@
-#pragma once
-
-#include <stdint.h>
-#include <stddef.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/** Get platform UID size in bytes */
-size_t api_hal_uid_size();
-
-/** Get const pointer to UID */
-const uint8_t* api_hal_uid();
-
-#ifdef __cplusplus
-}
-#endif

+ 18 - 1
firmware/targets/api-hal-include/api-hal-version.h

@@ -15,6 +15,9 @@ void api_hal_version_init();
 /** Check target firmware version */
 bool api_hal_version_do_i_belong_here();
 
+/** Get model name */
+const char* api_hal_version_get_model_name();
+
 /** Get hardware version */
 const uint8_t api_hal_version_get_hw_version();
 
@@ -24,9 +27,15 @@ const uint8_t api_hal_version_get_hw_target();
 /** Get hardware body */
 const uint8_t api_hal_version_get_hw_body();
 
+/** Get hardware body color */
+const uint8_t api_hal_version_get_hw_color();
+
 /** Get hardware connect */
 const uint8_t api_hal_version_get_hw_connect();
 
+/** Get hardware region */
+const uint8_t api_hal_version_get_hw_region();
+
 /** Get hardware timestamp */
 const uint32_t api_hal_version_get_hw_timestamp();
 
@@ -39,6 +48,8 @@ const char* api_hal_version_get_device_name_ptr();
 /** Get pointer to target ble local device name */
 const char* api_hal_version_get_ble_local_device_name_ptr();
 
+const uint8_t* api_hal_version_get_ble_mac();
+
 /**
  * Get address of version structure of bootloader, stored in chip flash.
  *
@@ -51,7 +62,13 @@ const struct Version* api_hal_version_get_boot_version(void);
  *
  * @return Address of firmware version structure.
  */
-const struct Version* api_hal_version_get_fw_version(void);
+const struct Version* api_hal_version_get_firmware_version(void);
+
+/** Get platform UID size in bytes */
+size_t api_hal_version_uid_size();
+
+/** Get const pointer to UID */
+const uint8_t* api_hal_version_uid();
 
 #ifdef __cplusplus
 }

+ 0 - 1
firmware/targets/api-hal-include/api-hal.h

@@ -16,7 +16,6 @@ template <unsigned int N> struct STOP_EXTERNING_ME {};
 #include "api-hal-power.h"
 #include "api-hal-vcp.h"
 #include "api-hal-version.h"
-#include "api-hal-uid.h"
 #include "api-hal-bt.h"
 #include "api-hal-spi.h"
 #include "api-hal-flash.h"

+ 0 - 10
firmware/targets/f5/api-hal/api-hal-uuid.c

@@ -1,10 +0,0 @@
-#include <api-hal-uid.h>
-#include <stm32wbxx.h>
-
-size_t api_hal_uid_size() {
-    return 64/8;
-}
-
-const uint8_t* api_hal_uid() {
-    return (const uint8_t *)UID64_BASE;
-}

+ 38 - 2
firmware/targets/f5/api-hal/api-hal-version.c

@@ -16,12 +16,13 @@ typedef struct {
 } ApiHalVersionOTP;
 
 #define FLIPPER_ARRAY_NAME_LENGTH (FLIPPER_NAME_LENGTH + 1)
-// BLE symbol + "Flipper Zero " + name
+// BLE symbol + "Flipper " + name
 #define FLIPPER_DEVICE_NAME_LENGTH (1 + 8 + FLIPPER_ARRAY_NAME_LENGTH)
 
 // Initialiazed from OTP, used to guarantee zero terminated C string
 static char flipper_name[FLIPPER_ARRAY_NAME_LENGTH];
 static char flipper_device_name[FLIPPER_DEVICE_NAME_LENGTH];
+static uint8_t api_hal_version_ble_mac[6];
 
 void api_hal_version_init() {
     char* name = ((ApiHalVersionOTP*)OTP_AREA_BASE)->name;
@@ -41,12 +42,27 @@ void api_hal_version_init() {
     }
 
     flipper_device_name[0] = AD_TYPE_COMPLETE_LOCAL_NAME;
+
+    // BLE Mac address
+    uint32_t udn = LL_FLASH_GetUDN();
+    uint32_t company_id = LL_FLASH_GetSTCompanyID();
+    uint32_t device_id = LL_FLASH_GetDeviceID();
+    api_hal_version_ble_mac[0] = (uint8_t)(udn & 0x000000FF);
+    api_hal_version_ble_mac[1] = (uint8_t)( (udn & 0x0000FF00) >> 8 );
+    api_hal_version_ble_mac[2] = (uint8_t)( (udn & 0x00FF0000) >> 16 );
+    api_hal_version_ble_mac[3] = (uint8_t)device_id;
+    api_hal_version_ble_mac[4] = (uint8_t)(company_id & 0x000000FF);;
+    api_hal_version_ble_mac[5] = (uint8_t)( (company_id & 0x0000FF00) >> 8 );
 }
 
 bool api_hal_version_do_i_belong_here() {
     return api_hal_version_get_hw_target() == 5;
 }
 
+const char* api_hal_version_get_model_name() {
+    return "Flipper Zero";
+}
+
 const uint8_t api_hal_version_get_hw_version() {
     return ((ApiHalVersionOTP*)OTP_AREA_BASE)->version;
 }
@@ -59,10 +75,18 @@ const uint8_t api_hal_version_get_hw_body() {
     return ((ApiHalVersionOTP*)OTP_AREA_BASE)->body;
 }
 
+const uint8_t api_hal_version_get_hw_color() {
+    return 0;
+}
+
 const uint8_t api_hal_version_get_hw_connect() {
     return ((ApiHalVersionOTP*)OTP_AREA_BASE)->connect;
 }
 
+const uint8_t api_hal_version_get_hw_region() {
+    return 0;
+}
+
 const uint32_t api_hal_version_get_hw_timestamp() {
     return ((ApiHalVersionOTP*)OTP_AREA_BASE)->timestamp;
 }
@@ -79,7 +103,11 @@ const char* api_hal_version_get_ble_local_device_name_ptr() {
     return flipper_device_name;
 }
 
-const struct Version* api_hal_version_get_fw_version(void) {
+const uint8_t* api_hal_version_get_ble_mac() {
+    return api_hal_version_ble_mac;
+}
+
+const struct Version* api_hal_version_get_firmware_version(void) {
     return version_get();
 }
 
@@ -91,3 +119,11 @@ const struct Version* api_hal_version_get_boot_version(void) {
     return (const struct Version*)LL_RTC_BAK_GetRegister(RTC, LL_RTC_BKP_DR1);
 #endif
 }
+
+size_t api_hal_version_uid_size() {
+    return 64/8;
+}
+
+const uint8_t* api_hal_version_uid() {
+    return (const uint8_t *)UID64_BASE;
+}

+ 0 - 10
firmware/targets/f6/api-hal/api-hal-uuid.c

@@ -1,10 +0,0 @@
-#include <api-hal-uid.h>
-#include <stm32wbxx.h>
-
-size_t api_hal_uid_size() {
-    return 64/8;
-}
-
-const uint8_t* api_hal_uid() {
-    return (const uint8_t *)UID64_BASE;
-}

+ 37 - 1
firmware/targets/f6/api-hal/api-hal-version.c

@@ -22,6 +22,7 @@ typedef struct {
 // Initialiazed from OTP, used to guarantee zero terminated C string
 static char flipper_name[FLIPPER_ARRAY_NAME_LENGTH];
 static char flipper_device_name[FLIPPER_DEVICE_NAME_LENGTH];
+static uint8_t api_hal_version_ble_mac[6];
 
 void api_hal_version_init() {
     char* name = ((ApiHalVersionOTP*)OTP_AREA_BASE)->name;
@@ -41,12 +42,27 @@ void api_hal_version_init() {
     }
 
     flipper_device_name[0] = AD_TYPE_COMPLETE_LOCAL_NAME;
+
+    // BLE Mac address
+    uint32_t udn = LL_FLASH_GetUDN();
+    uint32_t company_id = LL_FLASH_GetSTCompanyID();
+    uint32_t device_id = LL_FLASH_GetDeviceID();
+    api_hal_version_ble_mac[0] = (uint8_t)(udn & 0x000000FF);
+    api_hal_version_ble_mac[1] = (uint8_t)( (udn & 0x0000FF00) >> 8 );
+    api_hal_version_ble_mac[2] = (uint8_t)( (udn & 0x00FF0000) >> 16 );
+    api_hal_version_ble_mac[3] = (uint8_t)device_id;
+    api_hal_version_ble_mac[4] = (uint8_t)(company_id & 0x000000FF);;
+    api_hal_version_ble_mac[5] = (uint8_t)( (company_id & 0x0000FF00) >> 8 );
 }
 
 bool api_hal_version_do_i_belong_here() {
     return api_hal_version_get_hw_target() == 6;
 }
 
+const char* api_hal_version_get_model_name() {
+    return "Flipper Zero";
+}
+
 const uint8_t api_hal_version_get_hw_version() {
     return ((ApiHalVersionOTP*)OTP_AREA_BASE)->version;
 }
@@ -59,10 +75,18 @@ const uint8_t api_hal_version_get_hw_body() {
     return ((ApiHalVersionOTP*)OTP_AREA_BASE)->body;
 }
 
+const uint8_t api_hal_version_get_hw_color() {
+    return 0;
+}
+
 const uint8_t api_hal_version_get_hw_connect() {
     return ((ApiHalVersionOTP*)OTP_AREA_BASE)->connect;
 }
 
+const uint8_t api_hal_version_get_hw_region() {
+    return 0;
+}
+
 const uint32_t api_hal_version_get_hw_timestamp() {
     return ((ApiHalVersionOTP*)OTP_AREA_BASE)->timestamp;
 }
@@ -79,7 +103,11 @@ const char* api_hal_version_get_ble_local_device_name_ptr() {
     return flipper_device_name;
 }
 
-const struct Version* api_hal_version_get_fw_version(void) {
+const uint8_t* api_hal_version_get_ble_mac() {
+    return api_hal_version_ble_mac;
+}
+
+const struct Version* api_hal_version_get_firmware_version(void) {
     return version_get();
 }
 
@@ -91,3 +119,11 @@ const struct Version* api_hal_version_get_boot_version(void) {
     return (const struct Version*)LL_RTC_BAK_GetRegister(RTC, LL_RTC_BKP_DR1);
 #endif
 }
+
+size_t api_hal_version_uid_size() {
+    return 64/8;
+}
+
+const uint8_t* api_hal_version_uid() {
+    return (const uint8_t *)UID64_BASE;
+}