From a0ae3c321517a1279751130d0d8a264e558f55dd Mon Sep 17 00:00:00 2001 From: Ye Li Date: Mon, 16 Apr 2018 01:01:29 -0700 Subject: [PATCH] MLK-16441 imx8qm/qxp: print commit hash for SCFW, SECO, IMX-MKIMAGE and ATF Since we have many software running on QM/QXP, it is better to print their commit ids in u-boot to know their versions. This patch enables the CONFIG_ARCH_MISC_INIT. In arch_misc_init to gets the commit ids for SCFW and ATF via their APIs and get the commit for imx-mkimage at the end of u-boot.bin loading address. Once the commit ids are acquired, show them in console like: BuildInfo: - SCFW e2e62ca4, SECO-FW c121d4a4, IMX-MKIMAGE fe2ff1e9, ATF 8673a8e - U-Boot 2018.03-imx_v2018.03+g557a2e5 and set them to environment variables like: commit_atf=8673a8e commit_mkimage=fe2ff1e9 commit_scfw=e2e62ca4 commit_secofw=c121d4a4 If old software are running which does not support provide commit it, the patch use 0 instead. Signed-off-by: Ye Li Reviewed-by: Peng Fan (cherry picked from commit 5b443e3e26178e6df7cf76d98724a45871fcfaf1) --- arch/arm/include/asm/arch-imx8/sci/rpc.h | 27 ++++++++- arch/arm/include/asm/arch-imx8/sci/sci.h | 4 ++ arch/arm/mach-imx/imx8/cpu.c | 72 ++++++++++++++++++++++++ drivers/misc/imx8/scu_api.c | 27 +++++++++ 4 files changed, 129 insertions(+), 1 deletion(-) diff --git a/arch/arm/include/asm/arch-imx8/sci/rpc.h b/arch/arm/include/asm/arch-imx8/sci/rpc.h index 746c2fa24d..c429bd038b 100644 --- a/arch/arm/include/asm/arch-imx8/sci/rpc.h +++ b/arch/arm/include/asm/arch-imx8/sci/rpc.h @@ -32,7 +32,9 @@ #define SC_RPC_SVC_PAD 6U #define SC_RPC_SVC_MISC 7U #define SC_RPC_SVC_IRQ 8U -#define SC_RPC_SVC_ABORT 9U +#define SC_RPC_SVC_SECO 9U +#define SC_RPC_SVC_ABORT 10U + /* Types */ @@ -155,4 +157,27 @@ struct sc_rpc_msg_s { #define RM_FUNC_IS_PAD_OWNED 25U #define RM_FUNC_DUMP 27U +/* SECO RPC */ +#define SECO_FUNC_UNKNOWN 0 /*!< Unknown function */ +#define SECO_FUNC_IMAGE_LOAD 1U /*!< Index for seco_image_load() RPC call */ +#define SECO_FUNC_AUTHENTICATE 2U /*!< Index for seco_authenticate() RPC call */ +#define SECO_FUNC_FORWARD_LIFECYCLE 3U /*!< Index for seco_forward_lifecycle() RPC call */ +#define SECO_FUNC_RETURN_LIFECYCLE 4U /*!< Index for seco_return_lifecycle() RPC call */ +#define SECO_FUNC_COMMIT 5U /*!< Index for seco_commit() RPC call */ +#define SECO_FUNC_ATTEST_MODE 6U /*!< Index for seco_attest_mode() RPC call */ +#define SECO_FUNC_ATTEST 7U /*!< Index for seco_attest() RPC call */ +#define SECO_FUNC_GET_ATTEST_PKEY 8U /*!< Index for seco_get_attest_pkey() RPC call */ +#define SECO_FUNC_GET_ATTEST_SIGN 9U /*!< Index for seco_get_attest_sign() RPC call */ +#define SECO_FUNC_ATTEST_VERIFY 10U /*!< Index for seco_attest_verify() RPC call */ +#define SECO_FUNC_GEN_KEY_BLOB 11U /*!< Index for seco_gen_key_blob() RPC call */ +#define SECO_FUNC_LOAD_KEY 12U /*!< Index for seco_load_key() RPC call */ +#define SECO_FUNC_GET_MP_KEY 13U /*!< Index for seco_get_mp_key() RPC call */ +#define SECO_FUNC_UPDATE_MPMR 14U /*!< Index for seco_update_mpmr() RPC call */ +#define SECO_FUNC_GET_MP_SIGN 15U /*!< Index for seco_get_mp_sign() RPC call */ +#define SECO_FUNC_BUILD_INFO 16U /*!< Index for seco_build_info() RPC call */ +#define SECO_FUNC_CHIP_INFO 17U /*!< Index for seco_chip_info() RPC call */ +#define SECO_FUNC_ENABLE_DEBUG 18U /*!< Index for seco_enable_debug() RPC call */ +#define SECO_FUNC_GET_EVENT 19U /*!< Index for seco_get_event() RPC call */ +#define SECO_FUNC_FUSE_WRITE 20U /*!< Index for seco_fuse_write() RPC call */ + #endif /* SC_RPC_H */ diff --git a/arch/arm/include/asm/arch-imx8/sci/sci.h b/arch/arm/include/asm/arch-imx8/sci/sci.h index 7f26f01dad..6c450aaf97 100644 --- a/arch/arm/include/asm/arch-imx8/sci/sci.h +++ b/arch/arm/include/asm/arch-imx8/sci/sci.h @@ -94,4 +94,8 @@ int sc_pad_set(sc_ipc_t ipc, sc_pad_t pad, u32 val); int sc_rm_set_master_sid(sc_ipc_t ipc, sc_rsrc_t resource, sc_rm_sid_t sid); +/* SECO API */ +void sc_seco_build_info(sc_ipc_t ipc, uint32_t *version, + uint32_t *commit); + #endif diff --git a/arch/arm/mach-imx/imx8/cpu.c b/arch/arm/mach-imx/imx8/cpu.c index b472e8306f..ea212451ba 100644 --- a/arch/arm/mach-imx/imx8/cpu.c +++ b/arch/arm/mach-imx/imx8/cpu.c @@ -23,6 +23,7 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -338,6 +339,77 @@ void arch_preboot_os(void) #endif } +#if defined(CONFIG_ARCH_MISC_INIT) +#define FSL_SIP_BUILDINFO 0xC2000003 +#define FSL_SIP_BUILDINFO_GET_COMMITHASH 0x00 +extern uint32_t _end_ofs; + +static void set_buildinfo_to_env(uint32_t scfw, uint32_t secofw, char *mkimage, char *atf) +{ + if (!mkimage || !atf) + return; + + env_set("commit_mkimage", mkimage); + env_set("commit_atf", atf); + env_set_hex("commit_scfw", (ulong)scfw); + env_set_hex("commit_secofw", (ulong)secofw); +} + +static void acquire_buildinfo(void) +{ + uint32_t sc_build = 0, sc_commit = 0; + uint32_t seco_build = 0, seco_commit = 0; + char *mkimage_commit, *temp; + uint64_t atf_commit = 0; + + /* Get SCFW build and commit id */ + sc_misc_build_info(-1, &sc_build, &sc_commit); + if (sc_build == 0) { + debug("SCFW does not support build info\n"); + sc_commit = 0; /* Display 0 when the build info is not supported*/ + } + + /* Get SECO FW build and commit id */ + sc_seco_build_info(-1, &seco_build, &seco_commit); + if (seco_build == 0) { + debug("SECO FW does not support build info\n"); + seco_commit = 0; /* Display 0 when the build info is not supported*/ + } + + /* Get imx-mkimage commit id. + * The imx-mkimage puts the commit hash behind the end of u-boot.bin + */ + mkimage_commit = (char *)(ulong)(CONFIG_SYS_TEXT_BASE + _end_ofs + fdt_totalsize(gd->fdt_blob)); + temp = mkimage_commit + 8; + *temp = '\0'; + + if (strlen(mkimage_commit) == 0) { + debug("IMX-MKIMAGE does not support build info\n"); + mkimage_commit = "0"; /* Display 0 */ + } + + /* Get ARM Trusted Firmware commit id */ + atf_commit = call_imx_sip(FSL_SIP_BUILDINFO, FSL_SIP_BUILDINFO_GET_COMMITHASH, 0, 0, 0); + if (atf_commit == 0xffffffff) { + debug("ATF does not support build info\n"); + atf_commit = 0x30; /* Display 0, 0 ascii is 0x30 */ + } + + /* Set all to env */ + set_buildinfo_to_env(sc_commit, seco_commit, mkimage_commit, (char *)&atf_commit); + + printf("\n BuildInfo: \n - SCFW %08x, SECO-FW %08x, IMX-MKIMAGE %s, ATF %s\n - %s \n\n", + sc_commit, seco_commit, mkimage_commit, (char *)&atf_commit, U_BOOT_VERSION); +} + +int arch_misc_init(void) +{ + acquire_buildinfo(); + + return 0; +} +#endif + int print_bootinfo(void) { enum boot_device bt_dev = get_boot_device(); diff --git a/drivers/misc/imx8/scu_api.c b/drivers/misc/imx8/scu_api.c index 57a61c40d2..76a1d3a154 100644 --- a/drivers/misc/imx8/scu_api.c +++ b/drivers/misc/imx8/scu_api.c @@ -442,3 +442,30 @@ int sc_pm_get_resource_power_mode(sc_ipc_t ipc, sc_rsrc_t resource, return ret; } + +void sc_seco_build_info(sc_ipc_t ipc, uint32_t *version, + uint32_t *commit) +{ + struct udevice *dev = gd->arch.scu_dev; + struct sc_rpc_msg_s msg; + int size = sizeof(struct sc_rpc_msg_s); + + RPC_VER(&msg) = SC_RPC_VERSION; + RPC_SVC(&msg) = (u8)(SC_RPC_SVC_SECO); + RPC_FUNC(&msg) = (u8)(SECO_FUNC_BUILD_INFO); + RPC_SIZE(&msg) = 1U; + + misc_call(dev, SC_FALSE, &msg, size, &msg, size); + + if (version != NULL) + { + *version = RPC_U32(&msg, 0U); + } + + if (commit != NULL) + { + *commit = RPC_U32(&msg, 4U); + } + + return; +} -- 2.17.1