MLK-16441 imx8qm/qxp: print commit hash for SCFW, SECO, IMX-MKIMAGE and ATF
authorYe Li <ye.li@nxp.com>
Thu, 12 Mar 2020 02:40:19 +0000 (19:40 -0700)
committerYe Li <ye.li@nxp.com>
Thu, 29 Apr 2021 07:56:19 +0000 (00:56 -0700)
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 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 <ye.li@nxp.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
(cherry picked from commit 5b443e3e26178e6df7cf76d98724a45871fcfaf1)
(cherry picked from commit cfe5dc4a4a2fc342859ddd19f5ce01b9c43c2d8b)

arch/arm/mach-imx/imx8/misc.c

index de19955..a6895f3 100644 (file)
@@ -3,8 +3,14 @@
 #include <log.h>
 #include <asm/arch/sci/sci.h>
 #include <asm/mach-imx/sys_proto.h>
+#include <asm/global_data.h>
 #include <imx_sip.h>
+#include <env.h>
 #include <linux/arm-smccc.h>
+#include <generated/version_autogenerated.h>
+#include <linux/libfdt.h>
+
+DECLARE_GLOBAL_DATA_PTR;
 
 int sc_pm_setup_uart(sc_rsrc_t uart_rsrc, sc_pm_clock_rate_t clk_rate)
 {
@@ -29,11 +35,25 @@ int sc_pm_setup_uart(sc_rsrc_t uart_rsrc, sc_pm_clock_rate_t clk_rate)
        return 0;
 }
 
+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);
+}
+
 void build_info(void)
 {
        struct arm_smccc_res res;
        u32 seco_build = 0, seco_commit = 0;
        u32 sc_build = 0, sc_commit = 0;
+       char *mkimage_commit, *temp;
        ulong atf_commit = 0;
 
        /* Get SCFW build and commit id */
@@ -51,6 +71,19 @@ void build_info(void)
                seco_commit = 0;
        }
 
+       /* 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 */
        arm_smccc_smc(IMX_SIP_BUILDINFO, IMX_SIP_BUILDINFO_GET_COMMITHASH,
                      0, 0, 0, 0, 0, 0, &res);
@@ -60,6 +93,9 @@ void build_info(void)
                atf_commit = 0x30; /* Display 0 */
        }
 
-       printf("Build: SCFW %08x, SECO-FW %08x, ATF %s\n",
-              sc_commit, seco_commit, (char *)&atf_commit);
+       /* 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);
 }