From 8dd52f15df34c13a3987c401ec025039c35ba930 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lothar=20Wa=C3=9Fmann?= Date: Thu, 9 May 2019 15:47:12 +0200 Subject: [PATCH] arm: mx6: implement refcounting for the ocotp clock and use 'fuse_read()' rather than 'readl()' to access the HAB fuses --- arch/arm/cpu/armv7/mx6/clock.c | 10 ++++++++++ arch/arm/cpu/armv7/mx6/hab.c | 16 +++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/arch/arm/cpu/armv7/mx6/clock.c b/arch/arm/cpu/armv7/mx6/clock.c index c3c9c5e651..4f2a4b97b7 100644 --- a/arch/arm/cpu/armv7/mx6/clock.c +++ b/arch/arm/cpu/armv7/mx6/clock.c @@ -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) diff --git a/arch/arm/cpu/armv7/mx6/hab.c b/arch/arm/cpu/armv7/mx6/hab.c index aaf0d33a42..83b1e26a10 100644 --- a/arch/arm/cpu/armv7/mx6/hab.c +++ b/arch/arm/cpu/armv7/mx6/hab.c @@ -5,6 +5,7 @@ */ #include +#include #include #include #include @@ -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, ®)) { + 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; } -- 2.39.2