]> git.baikalelectronics.ru Git - arm-tf.git/commitdiff
feat(hikey960): read serial number from UFS
authorArthur Cassegrain <arthur.cassegrain@trustonic.com>
Fri, 26 Nov 2021 15:39:12 +0000 (16:39 +0100)
committerLukas Hanel <lukas.hanel@trustonic.com>
Wed, 2 Nov 2022 14:35:03 +0000 (15:35 +0100)
Serial number is written into UFS by fastboot
Pass BL2 params to BL31 (serial number)

Change-Id: I9a490db07ca10088da69191a2f2c1621d44a278c
Signed-off-by: vallau01 <valentin.laurent@trustonic.com>
Signed-off-by: Lukas Hanel <lukas.hanel@trustonic.com>
plat/hisilicon/hikey960/hikey960_bl2_setup.c
plat/hisilicon/hikey960/hikey960_bl31_setup.c
plat/hisilicon/hikey960/hikey960_io_storage.c
plat/hisilicon/hikey960/hikey960_private.h

index c1c2a8c59dedd51f044dd413eaea4089a4a6b344..733485385fb2f87d427fb7ac6c3361c6dd41f842 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2017-2022, ARM Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -31,6 +31,9 @@
 
 #define BL2_RW_BASE            (BL_CODE_END)
 
+/* BL2 platform parameters passed to BL31 */
+static plat_params_from_bl2_t plat_params_from_bl2;
+
 static meminfo_t bl2_el3_tzram_layout;
 static console_t console;
 extern int load_lpm3(void);
@@ -217,6 +220,11 @@ int hikey960_bl2_handle_post_image_load(unsigned int image_id)
        assert(bl_mem_params);
 
        switch (image_id) {
+       case BL31_IMAGE_ID:
+               /* Pass BL2 platform parameter to BL31 */
+               bl_mem_params->ep_info.args.arg1 = (uint64_t) &plat_params_from_bl2;
+               break;
+
 #ifdef __aarch64__
        case BL32_IMAGE_ID:
 #ifdef SPD_opteed
@@ -307,6 +315,8 @@ void bl2_el3_plat_arch_setup(void)
 
 void bl2_platform_setup(void)
 {
+       int ret;
+
        /* disable WDT0 */
        if (mmio_read_32(WDT0_REG_BASE + WDT_LOCK_OFFSET) == WDT_LOCKED) {
                mmio_write_32(WDT0_REG_BASE + WDT_LOCK_OFFSET, WDT_UNLOCK);
@@ -322,4 +332,13 @@ void bl2_platform_setup(void)
        hikey960_gpio_init();
        hikey960_init_ufs();
        hikey960_io_setup();
+
+       /* Read serial number from storage */
+       plat_params_from_bl2.fastboot_serno = 0;
+       ret = hikey960_load_serialno(&plat_params_from_bl2.fastboot_serno);
+       if (ret != 0) {
+               ERROR("BL2: could not read serial number\n");
+       }
+       INFO("BL2: fastboot_serno %lx\n", plat_params_from_bl2.fastboot_serno);
+       flush_dcache_range((uintptr_t)&plat_params_from_bl2, sizeof(plat_params_from_bl2_t));
 }
index 49918ef877d0376dc25391302daa9ffa2709c7e4..0debe1ee647b6078ef6e5ae9be669438dbe23f25 100644 (file)
@@ -33,6 +33,9 @@ static entry_point_info_t bl32_ep_info;
 static entry_point_info_t bl33_ep_info;
 static console_t console;
 
+/* fastboot serial number consumed by Kinibi SPD/LP for gpd.tee.deviceID. */
+uint64_t fastboot_serno;
+
 /******************************************************************************
  * On a GICv2 system, the Group 1 secure interrupts are treated as Group 0
  * interrupts.
@@ -73,6 +76,7 @@ void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
 {
        unsigned int id, uart_base;
        void *from_bl2;
+       plat_params_from_bl2_t *plat_params_from_bl2 = (plat_params_from_bl2_t *) arg1;
 
        from_bl2 = (void *) arg0;
 
@@ -91,6 +95,10 @@ void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
        cci_init(CCI400_REG_BASE, cci_map, ARRAY_SIZE(cci_map));
        cci_enable_snoop_dvm_reqs(MPIDR_AFFLVL1_VAL(read_mpidr_el1()));
 
+       /* Fastboot serial number passed from BL2 as a platform parameter */
+       fastboot_serno = plat_params_from_bl2->fastboot_serno;
+       INFO("BL31: fastboot_serno %lx\n", fastboot_serno);
+
        /*
         * Check params passed from BL2 should not be NULL,
         */
index 883085bd8533e79ebe1f1004de93e1ef05109e06..475e41676930971b89caa7fb2331337d8f942d81 100644 (file)
@@ -23,6 +23,9 @@
 #include <lib/semihosting.h>
 #include <tools_share/firmware_image_package.h>
 
+#include "hikey960_def.h"
+#include "hikey960_private.h"
+
 struct plat_io_policy {
        uintptr_t *dev_handle;
        uintptr_t image_spec;
@@ -45,6 +48,12 @@ static const io_block_spec_t ufs_gpt_spec = {
                          (PLAT_PARTITION_MAX_ENTRIES / 4 + 2),
 };
 
+/* Fastboot serial number stored within first UFS device blocks */
+static const io_block_spec_t ufs_fastboot_spec = {
+       .offset         = UFS_BASE,
+       .length         = 1 << 20,
+};
+
 static const io_block_dev_spec_t ufs_dev_spec = {
        /* It's used as temp buffer in block driver. */
        .buffer         = {
@@ -256,6 +265,54 @@ static int check_fip(const uintptr_t spec)
        return result;
 }
 
+int hikey960_load_serialno(uint64_t *serno)
+{
+       int result;
+       size_t len = 0;
+       uintptr_t local_handle;
+       uint64_t buf[HIKEY960_SERIAL_NUMBER_SIZE / sizeof(uint64_t)];
+
+       if (serno == NULL) {
+               return -1;
+       }
+
+       result = io_dev_init(ufs_dev_handle, (uintptr_t)NULL);
+       if (result != 0) {
+               return result;
+       }
+
+       result = io_open(ufs_dev_handle,
+               (uintptr_t)&ufs_fastboot_spec, &local_handle);
+       if (result != 0) {
+               return result;
+       }
+
+       result = io_seek(local_handle, IO_SEEK_SET,
+               HIKEY960_SERIAL_NUMBER_LBA * UFS_BLOCK_SIZE);
+       if (result != 0) {
+               goto closing;
+       }
+
+       result = io_read(local_handle, (uintptr_t)buf,
+               HIKEY960_SERIAL_NUMBER_SIZE, &len);
+       if (result != 0) {
+               goto closing;
+       }
+
+       if (len != HIKEY960_SERIAL_NUMBER_SIZE) {
+               result = -1;
+               goto closing;
+       }
+
+       /* UEFI fastboot app stores a 16 bytes blob       */
+       /* We extract only relevant 8 bytes serial number */
+       *serno = buf[1];
+
+closing:
+       io_close(local_handle);
+       return result;
+}
+
 void hikey960_io_setup(void)
 {
        int result;
index 54bf501341083573850cba91e77ffec9f78c1943..742725c6923f7b7910153cefc38a46555059da12 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2017-2022, ARM Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -9,6 +9,10 @@
 
 #include <common/bl_common.h>
 
+/* Fastboot serial number */
+#define HIKEY960_SERIAL_NUMBER_LBA     (UFS_BASE + 20)
+#define HIKEY960_SERIAL_NUMBER_SIZE    16
+
 /*
  * Function and variable prototypes
  */
@@ -27,6 +31,7 @@ void hikey960_init_mmu_el3(unsigned long total_base,
 void hikey960_io_setup(void);
 int hikey960_read_boardid(unsigned int *id);
 int hikey960_set_fip_addr(unsigned int image_id, const char *name);
+int hikey960_load_serialno(uint64_t *serno);
 void hikey960_clk_init(void);
 void hikey960_pmu_init(void);
 void hikey960_regulator_enable(void);
@@ -39,4 +44,12 @@ void clr_retention_ticks(unsigned int val);
 void clr_ex(void);
 void nop(void);
 
+/*******************************************************************************
+ * Struct for parameters received from BL2
+ ******************************************************************************/
+typedef struct plat_params_from_bl2 {
+       /* Fastboot serial number gathered from UFS */
+       uint64_t fastboot_serno;
+} plat_params_from_bl2_t;
+
 #endif /* HIKEY960_PRIVATE_H */