MA-15321-2 Add command to get serial number
authorJi Luo <ji.luo@nxp.com>
Thu, 15 Aug 2019 03:17:00 +0000 (11:17 +0800)
committerJi Luo <ji.luo@nxp.com>
Thu, 13 May 2021 01:49:17 +0000 (09:49 +0800)
Add commands to support extract serial number from device.
Commands:
    $ fastboot oem get-serial-number
    $ fastboot get_staged <path-to-serial-number>

Test: serial number upload on imx8mm.

Change-Id: I5c905ab797d4fd28d76c8403914f191eaf2ef687
Signed-off-by: Ji Luo <ji.luo@nxp.com>
(cherry picked from commit 250ef119c1dc02908046113893df5eeb9ef40605)

drivers/fastboot/fb_fsl/fb_fsl_command.c
drivers/fastboot/fb_fsl/fb_fsl_common.h
drivers/fastboot/fb_fsl/fb_fsl_getvar.c
include/fb_fsl.h

index 210c505..988e677 100644 (file)
@@ -62,7 +62,6 @@ static u32 fastboot_bytes_received;
  */
 static u32 fastboot_bytes_expected;
 
-
 /* Write the bcb with fastboot bootloader commands */
 static void enable_fastboot_command(void)
 {
@@ -586,6 +585,18 @@ static void flashing(char *cmd, char *response)
                        printf("mppubk generated!\n");
                        strcpy(response, "OKAY");
                }
+       }  else if (endswith(cmd, FASTBOOT_GET_SERIAL_NUMBER)) {
+               char *serial = get_serial();
+
+               if (!serial)
+                       strcpy(response, "FAILSerial number not support!");
+               else {
+                       /* Serial number will not exceed 16 bytes.*/
+                       strncpy(fastboot_buf_addr, serial, 16);
+                       fastboot_bytes_received = 16;
+                       printf("Serial number generated!\n");
+                       strcpy(response, "OKAY");
+               }
        }
 #ifndef CONFIG_AVB_ATX
        else if (endswith(cmd, FASTBOOT_SET_RPMB_KEY)) {
index 4577d9e..6b957c4 100644 (file)
@@ -44,7 +44,10 @@ extern AvbAtxOps fsl_avb_atx_ops;
 extern AvbOps fsl_avb_ops;
 #endif
 
+#define IMX_SERIAL_LEN 32
+
 int get_block_size(void);
 void process_erase_mmc(const char *cmdbuf, char *response);
+char *get_serial(void);
 
 #endif // FB_FSL_COMMON_H
index 24e94b8..77bd996 100644 (file)
@@ -113,13 +113,16 @@ static bool is_slotvar(char *cmd)
        return false;
 }
 
-static char *get_serial(void)
+static char serial[IMX_SERIAL_LEN];
+
+char *get_serial(void)
 {
 #ifdef CONFIG_SERIAL_TAG
        struct tag_serialnr serialnr;
-       static char serial[32];
+       memset(serial, 0, IMX_SERIAL_LEN);
+
        get_board_serial(&serialnr);
-       sprintf(serial, "%08x%08x", serialnr.high,      serialnr.low);
+       sprintf(serial, "%08x%08x", serialnr.high, serialnr.low);
        return serial;
 #else
        return NULL;
index fdcb036..b0dc3c0 100644 (file)
 #define FASTBOOT_APPEND_RSA_ATTESTATION_CERT_ENC  "append-rsa-atte-cert-enc"
 #define FASTBOOT_APPEND_EC_ATTESTATION_CERT_ENC  "append-ec-atte-cert-enc"
 #define FASTBOOT_GET_MPPUBK  "get-mppubk"
+#define FASTBOOT_GET_SERIAL_NUMBER  "get-serial-number"
 #endif
 
 #ifdef CONFIG_ANDROID_THINGS_SUPPORT