]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
arm: mx6: implement refcounting for the ocotp clock and use 'fuse_read()' rather...
authorLothar Waßmann <LW@KARO-electronics.de>
Thu, 9 May 2019 13:47:12 +0000 (15:47 +0200)
committerLothar Waßmann <LW@KARO-electronics.de>
Thu, 9 May 2019 13:47:12 +0000 (15:47 +0200)
arch/arm/cpu/armv7/mx6/clock.c
arch/arm/cpu/armv7/mx6/hab.c

index c3c9c5e6512ba13ebacd96181056e915db9e14da..4f2a4b97b72ac724d1107162d113ffcd901b46ef 100644 (file)
@@ -138,6 +138,16 @@ static inline int wait_pll_lock(u32 *reg)
 void enable_ocotp_clk(unsigned char enable)
 {
        u32 reg;
+       static int enabled __attribute__((section(".data")));
+
+       if (enabled < 0) {
+               printf("ERROR: unbalanced enable/disable ocotp_clk\n");
+               hang();
+       }
+       if (enable && enabled++)
+               return;
+       if (!enable && --enabled)
+               return;
 
        reg = __raw_readl(&imx_ccm->CCGR2);
        if (enable)
index aaf0d33a42da92fe625e9f015df06ef3ecb64798..83b1e26a100167ddf70b31963bf7315c9bb828f9 100644 (file)
@@ -5,6 +5,7 @@
  */
 
 #include <common.h>
+#include <fuse.h>
 #include <asm/io.h>
 #include <asm/system.h>
 #include <asm/arch/clock.h>
@@ -175,13 +176,14 @@ uint8_t hab_engines[ARRAY_SIZE(eng_str)] = {
 
 bool is_hab_enabled(void)
 {
-       struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
-       struct fuse_bank *bank = &ocotp->bank[0];
-       struct fuse_bank0_regs *fuse =
-               (struct fuse_bank0_regs *)bank->fuse_regs;
-       uint32_t reg = readl(&fuse->cfg5);
+       uint32_t reg;
        static int first = 1;
 
+       if (fuse_read(0, 6, &reg)) {
+               printf("Failed to read SECURE_BOOT fuse\n");
+               return 0;
+       }
+
        if (first) {
                debug("rvt_base=%p\n", hab_rvt_base());
                debug("hab_rvt_entry=%p\n", hab_rvt_entry_p);
@@ -253,8 +255,10 @@ int get_hab_status(void)
                puts("Secure boot disabled\n");
 
        /* Check HAB status */
+       enable_ocotp_clk(1);
        config = state = 0; /* ROM code assumes short enums! */
        ret = hab_rvt_report_status(&config, &state);
+       enable_ocotp_clk(0);
        printf("HAB Configuration: 0x%02x, HAB State: 0x%02x\n",
                config, state);
        if (ret != HAB_SUCCESS) {
@@ -284,6 +288,7 @@ static inline enum hab_status hab_init(void)
 {
        enum hab_status ret;
 
+       enable_ocotp_clk(1);
        if (!is_hab_enabled()) {
                puts("hab fuse not enabled\n");
                return HAB_FAILURE;
@@ -310,6 +315,7 @@ static inline enum hab_status hab_exit(void)
                printf("hab exit function failed: %02x\n", ret);
 
        hab_caam_clock_enable(0);
+       enable_ocotp_clk(0);
 
        return ret;
 }