From 250ef119c1dc02908046113893df5eeb9ef40605 Mon Sep 17 00:00:00 2001 From: Ji Luo Date: Thu, 15 Aug 2019 11:17:00 +0800 Subject: [PATCH] MA-15321-2 Add command to get serial number Add commands to support extract serial number from device. Commands: $ fastboot oem get-serial-number $ fastboot get_staged Test: serial number upload on imx8mm. Change-Id: I5c905ab797d4fd28d76c8403914f191eaf2ef687 Signed-off-by: Ji Luo --- drivers/fastboot/fb_fsl/fb_fsl_command.c | 13 ++++++++++++- drivers/fastboot/fb_fsl/fb_fsl_common.h | 3 +++ drivers/fastboot/fb_fsl/fb_fsl_getvar.c | 9 ++++++--- include/fb_fsl.h | 1 + 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/drivers/fastboot/fb_fsl/fb_fsl_command.c b/drivers/fastboot/fb_fsl/fb_fsl_command.c index 24f51d4cbc..7b033ba32a 100755 --- a/drivers/fastboot/fb_fsl/fb_fsl_command.c +++ b/drivers/fastboot/fb_fsl/fb_fsl_command.c @@ -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)) { diff --git a/drivers/fastboot/fb_fsl/fb_fsl_common.h b/drivers/fastboot/fb_fsl/fb_fsl_common.h index 4577d9e9ae..6b957c43d5 100755 --- a/drivers/fastboot/fb_fsl/fb_fsl_common.h +++ b/drivers/fastboot/fb_fsl/fb_fsl_common.h @@ -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 diff --git a/drivers/fastboot/fb_fsl/fb_fsl_getvar.c b/drivers/fastboot/fb_fsl/fb_fsl_getvar.c index f506b54f43..8ebb0da114 100644 --- a/drivers/fastboot/fb_fsl/fb_fsl_getvar.c +++ b/drivers/fastboot/fb_fsl/fb_fsl_getvar.c @@ -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; diff --git a/include/fb_fsl.h b/include/fb_fsl.h index 4f173cee58..2d79d785f5 100644 --- a/include/fb_fsl.h +++ b/include/fb_fsl.h @@ -100,6 +100,7 @@ #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 -- 2.17.1