Skip to contentSkip to conversation

i.MX6 High Assurance Boot (HAB) support

PATCH New nitin.garg at freescale.com 4 participants 13 messages Aug 31, 2014 – Sep 4, 2014 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i.MX6 High Assurance Boot (HAB) support

From: Nitin Garg <[email protected]>

Add hab_auth_img u-boot command which can be used for HAB authentication of images.

Nitin Garg (1):
Support i.MX6 High Assurance Boot (HAB) authentication of images

 arch/arm/cpu/armv7/mx6/clock.c            |   40 ++++++-
 arch/arm/cpu/armv7/mx6/hab.c              |  180 ++++++++++++++++++++++++++++-
 arch/arm/cpu/armv7/mx6/soc.c              |   15 +++
 arch/arm/include/asm/arch-mx6/clock.h     |    6 +
 arch/arm/include/asm/arch-mx6/sys_proto.h |    4 +-
 5 files changed, 242 insertions(+), 3 deletions(-)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/1 Support i.MX6 High Assurance Boot (HAB) authentication of images

From: Nitin Garg <[email protected]>

Add hab_auth_img u-boot command which can be used for HAB authentication of images.

---
 arch/arm/cpu/armv7/mx6/clock.c            |   40 ++++++-
 arch/arm/cpu/armv7/mx6/hab.c              |  180 ++++++++++++++++++++++++++++-
 arch/arm/cpu/armv7/mx6/soc.c              |   15 +++
 arch/arm/include/asm/arch-mx6/clock.h     |    6 +
 arch/arm/include/asm/arch-mx6/sys_proto.h |    4 +-
 5 files changed, 242 insertions(+), 3 deletions(-)
arch/arm/cpu/armv7/mx6/clock.c +39 -1
index 820b8d5..62de8c9 100644
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2011 Freescale Semiconductor, Inc.
+ * Copyright (C) 2010-2014 Freescale Semiconductor, Inc.
  *
  * SPDX-License-Identifier:	GPL-2.0+
  */
@@ -543,6 +543,44 @@ int enable_pcie_clock(void)
 			       BM_ANADIG_PLL_ENET_ENABLE_PCIE);
 }
 
+#ifdef CONFIG_SECURE_BOOT
+void hab_caam_clock_enable(void)
+{
+	struct mxc_ccm_reg *ccm_regs = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
+	u32 reg = 0;
+
+	/*CG4 ~ CG6, enable CAAM clocks*/
+	reg = readl(&ccm_regs->CCGR0);
+	reg |= (MXC_CCM_CCGR0_CAAM_WRAPPER_IPG_MASK |
+			MXC_CCM_CCGR0_CAAM_WRAPPER_ACLK_MASK |
+			MXC_CCM_CCGR0_CAAM_SECURE_MEM_MASK);
+	writel(reg, &ccm_regs->CCGR0);
+
+	/* Enable EMI slow clk */
+	reg = readl(&ccm_regs->CCGR6);
+	reg |= MXC_CCM_CCGR6_EMI_SLOW_MASK;
+	writel(reg, &ccm_regs->CCGR6);
+}
+
+void hab_caam_clock_disable(void)
+{
+	struct mxc_ccm_reg *ccm_regs = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
+	u32 reg = 0;
+
+	/*CG4 ~ CG6, disable CAAM clocks*/
+	reg = readl(&ccm_regs->CCGR0);
+	reg &= ~(MXC_CCM_CCGR0_CAAM_WRAPPER_IPG_MASK |
+			MXC_CCM_CCGR0_CAAM_WRAPPER_ACLK_MASK |
+			MXC_CCM_CCGR0_CAAM_SECURE_MEM_MASK);
+	writel(reg, &ccm_regs->CCGR0);
+
+	/* Disable EMI slow clk */
+	reg = readl(&ccm_regs->CCGR6);
+	reg &= ~MXC_CCM_CCGR6_EMI_SLOW_MASK;
+	writel(reg, &ccm_regs->CCGR6);
+}
+#endif
+
 unsigned int mxc_get_clock(enum mxc_clock clk)
 {
 	switch (clk) {
arch/arm/cpu/armv7/mx6/hab.c +179 -1

212 lines not on this page · raw message

arch/arm/cpu/armv7/mx6/soc.c +15 -0
index 8aacdaf..4cb46a8 100644
@@ -408,10 +408,25 @@ int board_postclk_init(void)
 #ifndef CONFIG_SYS_DCACHE_OFF
 void enable_caches(void)
 {
+#if defined(CONFIG_SYS_ARM_CACHE_WRITETHROUGH)
+	enum dcache_option option = DCACHE_WRITETHROUGH;
+#else
+	enum dcache_option option = DCACHE_WRITEBACK;
+#endif
+
 	/* Avoid random hang when download by usb */
 	invalidate_dcache_all();
+
 	/* Enable D-cache. I-cache is already enabled in start.S */
 	dcache_enable();
+
+	/* Enable caching on OCRAM and ROM */
+	mmu_set_region_dcache_behaviour(ROMCP_ARB_BASE_ADDR,
+					ROMCP_ARB_END_ADDR,
+					option);
+	mmu_set_region_dcache_behaviour(IRAM_BASE_ADDR,
+					IRAM_SIZE,
+					option);
 }
 #endif
 
arch/arm/include/asm/arch-mx6/clock.h +6 -0
index 339c789..b7c36e5 100644
@@ -2,6 +2,8 @@
  * (C) Copyright 2009
  * Stefano Babic, DENX Software Engineering, sbabic at denx.de.
  *
+ * (C) Copyright 2014 Freescale Semiconductor, Inc.
+ *
  * SPDX-License-Identifier:	GPL-2.0+
  */
 
@@ -60,4 +62,8 @@ int enable_i2c_clk(unsigned char enable, unsigned i2c_num);
 int enable_spi_clk(unsigned char enable, unsigned spi_num);
 void enable_ipu_clock(void);
 int enable_fec_anatop_clock(enum enet_freq freq);
+#ifdef CONFIG_SECURE_BOOT
+void hab_caam_clock_enable(void);
+void hab_caam_clock_disable(void);
+#endif
 #endif /* __ASM_ARCH_CLOCK_H */
arch/arm/include/asm/arch-mx6/sys_proto.h +3 -1
index 306d699..2bbb86e 100644
@@ -2,6 +2,8 @@
  * (C) Copyright 2009
  * Stefano Babic, DENX Software Engineering, [email protected].
  *
+ * (C) Copyright 2014 Freescale Semiconductor, Inc.
+ *
  * SPDX-License-Identifier:	GPL-2.0+
  */
 
@@ -11,7 +13,7 @@
 #include <asm/imx-common/regs-common.h>
 #include "../arch-imx/cpu.h"
 
-#define soc_rev() (get_cpu_rev() & 0xFF)
+#define soc_rev() ((int)(get_cpu_rev() & 0xFF))
 #define is_soc_rev(rev)        (soc_rev() - rev)
 
 u32 get_nr_cpus(void);
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH 1/1 Support i.MX6 High Assurance Boot (HAB) authentication of images

Hello Nitin,

Quoted 6 lines · On Sun, Aug 31, 2014 at 5:16 PM, <[email protected]> wrote:

From: Nitin Garg <[email protected]>

Add hab_auth_img u-boot command which can be used for HAB authentication of images.

As the other patch I commented, this commit log also needs some rework to comply to the guidelines. I would also welcome a more detailed description about what this adds on top of previous HAB code.

...

Quoted 4 lines
arch/arm/include/asm/arch-mx6/sys_proto.h +0 -0
index 306d699..2bbb86e 100644

...

arch/arm/include/asm/arch-mx6/sys_proto.h line 16

Quoted 6 lines
arch/arm/include/asm/arch-mx6/sys_proto.h +1 -1
@@ -11,7 +13,7 @@
 #include <asm/imx-common/regs-common.h>
 #include "../arch-imx/cpu.h"
 
-#define soc_rev() (get_cpu_rev() & 0xFF)
+#define soc_rev() ((int)(get_cpu_rev() & 0xFF))

This seems unrelated change, isn't it?

Signature · 3 lines
Otavio Salvador                             O.S. Systems
http://www.ossystems.com.br        http://code.ossystems.com.br
Mobile: +55 (53) 9981-7854            Mobile: +1 (347) 903-9750
author
#3 lore raw

PATCH 1/1 Support i.MX6 High Assurance Boot (HAB) authentication of images

Quoted 5 lines · Otavio Salvador

Hello Nitin,

Quoted 2 lines · On Sun, Aug 31, 2014 at 5:16 PM, <[email protected]> wrote:

From: Nitin Garg <[email protected]>

Quoted 9 lines
Quoted 4 lines

Add hab_auth_img u-boot command which can be used for HAB authentication of images.

As the other patch I commented, this commit log also needs some rework to comply to the guidelines. I would also welcome a more detailed description about what this adds on top of previous HAB code.

I will improve the commit log and add detailed description.

Quoted 6 lines

...

Quoted 4 lines
arch/arm/include/asm/arch-mx6/sys_proto.h +0 -0
index 306d699..2bbb86e 100644

...

Quoted 9 lines

arch/arm/include/asm/arch-mx6/sys_proto.h line 16

Quoted 6 lines
arch/arm/include/asm/arch-mx6/sys_proto.h +1 -1
@@ -11,7 +13,7 @@
 #include <asm/imx-common/regs-common.h>
 #include "../arch-imx/cpu.h"
 
-#define soc_rev() (get_cpu_rev() & 0xFF)
+#define soc_rev() ((int)(get_cpu_rev() & 0xFF))

This seems unrelated change, isn't it?

Since get_cpu_rev returns unsigned int, this was causing a mix of unsigned int and int across binary operators.

e.g:
if(soc_rev() >= CHIP_REV_1_5)

#4 lore raw

PATCH 1/1 Support i.MX6 High Assurance Boot (HAB) authentication of images

Hello Nitin,

Quoted 15 lines · Nitin Garg
Quoted 5 lines · Otavio Salvador
Quoted 4 lines
arch/arm/include/asm/arch-mx6/sys_proto.h +0 -0
index 306d699..2bbb86e 100644

...

Quoted 9 lines

arch/arm/include/asm/arch-mx6/sys_proto.h line 16

Quoted 6 lines
arch/arm/include/asm/arch-mx6/sys_proto.h +1 -1
@@ -11,7 +13,7 @@
 #include <asm/imx-common/regs-common.h>
 #include "../arch-imx/cpu.h"
 
-#define soc_rev() (get_cpu_rev() & 0xFF)
+#define soc_rev() ((int)(get_cpu_rev() & 0xFF))

This seems unrelated change, isn't it?

Quoted 5 lines

Since get_cpu_rev returns unsigned int, this was causing a mix of unsigned int and int across binary operators.

e.g:
if(soc_rev() >= CHIP_REV_1_5)

In this case, please split this change.

Shouldn't this to be fixed in the get_cpu_rev?

Cheers,

Signature · 3 lines
Otavio Salvador                             O.S. Systems
http://www.ossystems.com.br        http://code.ossystems.com.br
Mobile: +55 (53) 9981-7854            Mobile: +1 (347) 903-9750
author
#5 lore raw

PATCH 1/1 Support i.MX6 High Assurance Boot (HAB) authentication of images

Quoted 21 lines · Otavio Salvador

Hello Nitin,

Quoted 18 lines · Nitin Garg
Quoted 5 lines · Otavio Salvador
Quoted 4 lines
arch/arm/include/asm/arch-mx6/sys_proto.h +0 -0
index 306d699..2bbb86e 100644

...

Quoted 9 lines

arch/arm/include/asm/arch-mx6/sys_proto.h line 16

Quoted 6 lines
arch/arm/include/asm/arch-mx6/sys_proto.h +1 -1
@@ -11,7 +13,7 @@
 #include <asm/imx-common/regs-common.h>
 #include "../arch-imx/cpu.h"
 
-#define soc_rev() (get_cpu_rev() & 0xFF)
+#define soc_rev() ((int)(get_cpu_rev() & 0xFF))

This seems unrelated change, isn't it?

Since get_cpu_rev returns unsigned int, this was causing a mix of unsigned int and int across binary operators.

Quoted 9 lines
Quoted 2 lines

e.g:
if(soc_rev() >= CHIP_REV_1_5)

In this case, please split this change.

Shouldn't this to be fixed in the get_cpu_rev?

Cheers,

But get_cpu_rev is correct, it returns unsigned int. The problem happens in hab code where there are comparisons between int and unsigned int, hence I think it should not be split. Pls advice.

#6 lore raw

PATCH 1/1 Support i.MX6 High Assurance Boot (HAB) authentication of images

Quoted 27 lines · Nitin Garg
Quoted 26 lines · Otavio Salvador

Hello Nitin,

Quoted 15 lines · Nitin Garg
Quoted 5 lines · Otavio Salvador
Quoted 4 lines
arch/arm/include/asm/arch-mx6/sys_proto.h +0 -0
index 306d699..2bbb86e 100644

...

Quoted 9 lines

arch/arm/include/asm/arch-mx6/sys_proto.h line 16

Quoted 6 lines
arch/arm/include/asm/arch-mx6/sys_proto.h +1 -1
@@ -11,7 +13,7 @@
 #include <asm/imx-common/regs-common.h>
 #include "../arch-imx/cpu.h"
 
-#define soc_rev() (get_cpu_rev() & 0xFF)
+#define soc_rev() ((int)(get_cpu_rev() & 0xFF))

This seems unrelated change, isn't it?

Quoted 5 lines

Since get_cpu_rev returns unsigned int, this was causing a mix of unsigned int and int across binary operators.

e.g:
if(soc_rev() >= CHIP_REV_1_5)

In this case, please split this change.

Quoted 8 lines
Quoted 4 lines

Shouldn't this to be fixed in the get_cpu_rev?

Cheers,

But get_cpu_rev is correct, it returns unsigned int. The problem happens in hab code where there are comparisons between int and unsigned int, hence I think it should not be split. Pls advice.

Well, this is not up to me however in this case wouldn't be better to fix the HAB code?

Signature · 3 lines
Otavio Salvador                             O.S. Systems
http://www.ossystems.com.br        http://code.ossystems.com.br
Mobile: +55 (53) 9981-7854            Mobile: +1 (347) 903-9750
#7 lore raw

PATCH 1/1 Support i.MX6 High Assurance Boot (HAB) authentication of images

In reply to Nitin Garg
Quoted 3 lines · Nitin Garg

But get_cpu_rev is correct, it returns unsigned int. The problem happens in hab code where there are comparisons between int and unsigned int, hence

Where exactly in the hab code does the problem happen?

author
#8 lore raw

PATCH 1/1 Support i.MX6 High Assurance Boot (HAB) authentication of images

Quoted 8 lines · Fabio Estevam
Quoted 3 lines · Nitin Garg

But get_cpu_rev is correct, it returns unsigned int. The problem happens in hab code where there are comparisons between int and unsigned int, hence

Where exactly in the hab code does the problem happen?

In the macros of HAB, like:
hab_rvt_report_event_p

The compiler generates bhi instead of bgt.

#9 lore raw

PATCH 1/1 Support i.MX6 High Assurance Boot (HAB) authentication of images

Quoted 7 lines · Nitin Garg
Quoted 6 lines · Fabio Estevam
Quoted 3 lines · Nitin Garg

But get_cpu_rev is correct, it returns unsigned int. The problem happens in hab code where there are comparisons between int and unsigned int, hence

Quoted 6 lines
Quoted 2 lines

Where exactly in the hab code does the problem happen?

In the macros of HAB, like:
hab_rvt_report_event_p

The compiler generates bhi instead of bgt.

However looking at the code I didn't see any negative CHIP_REV:

#define CHIP_REV_1_0                 0x10
#define CHIP_REV_1_2                 0x12
#define CHIP_REV_1_5                 0x15

So I am not sure we have a failure case in the U-Boot code now.

I think I am missing something though ...

Signature · 3 lines
Otavio Salvador                             O.S. Systems
http://www.ossystems.com.br        http://code.ossystems.com.br
Mobile: +55 (53) 9981-7854            Mobile: +1 (347) 903-9750
#10 lore raw

PATCH 1/1 Support i.MX6 High Assurance Boot (HAB) authentication of images

In reply to Nitin Garg
Quoted 4 lines · Nitin Garg

In the macros of HAB, like:
hab_rvt_report_event_p

The compiler generates bhi instead of bgt.

hab_rvt_report_event_p exists prior to this patch. Is the issue present in current code then?

If so, it should be handled on a separate patch.

author
#11 lore raw

PATCH 1/1 Support i.MX6 High Assurance Boot (HAB) authentication of images

Quoted 5 lines · Fabio Estevam
Quoted 3 lines · Nitin Garg

In the macros of HAB, like:
hab_rvt_report_event_p

Quoted 7 lines
Quoted 1 line

The compiler generates bhi instead of bgt.

hab_rvt_report_event_p exists prior to this patch. Is the issue present in current code then?

If so, it should be handled on a separate patch.

I will remove the typecast as its not essential (I stepped through the code today and its fine).

#12 lore raw

PATCH 1/1 Support i.MX6 High Assurance Boot (HAB) authentication of images

In reply to nitin.garg at freescale.com

Dear nitin.garg at freescale.com,

arch/arm/cpu/armv7/mx6/clock.c int enable_pcie_clock(void) · line 557

Quoted 6 lines · In message <[email protected]> you…
arch/arm/cpu/armv7/mx6/clock.c +5 -0
+	reg = readl(&ccm_regs->CCGR0);
+	reg |= (MXC_CCM_CCGR0_CAAM_WRAPPER_IPG_MASK |
+			MXC_CCM_CCGR0_CAAM_WRAPPER_ACLK_MASK |
+			MXC_CCM_CCGR0_CAAM_SECURE_MEM_MASK);
+	writel(reg, &ccm_regs->CCGR0);

Is there any specific reason for not using setbits_le32() instead?

arch/arm/cpu/armv7/mx6/clock.c int enable_pcie_clock(void) · line 562

Quoted 4 lines
arch/arm/cpu/armv7/mx6/clock.c +4 -0
+	/* Enable EMI slow clk */
+	reg = readl(&ccm_regs->CCGR6);
+	reg |= MXC_CCM_CCGR6_EMI_SLOW_MASK;
+	writel(reg, &ccm_regs->CCGR6);

Ditto?

arch/arm/cpu/armv7/mx6/clock.c int enable_pcie_clock(void) · line 575

Quoted 5 lines
arch/arm/cpu/armv7/mx6/clock.c +5 -0
+	reg = readl(&ccm_regs->CCGR0);
+	reg &= ~(MXC_CCM_CCGR0_CAAM_WRAPPER_IPG_MASK |
+			MXC_CCM_CCGR0_CAAM_WRAPPER_ACLK_MASK |
+			MXC_CCM_CCGR0_CAAM_SECURE_MEM_MASK);
+	writel(reg, &ccm_regs->CCGR0);

Why not using clrbits_le32() instead?

arch/arm/cpu/armv7/mx6/clock.c int enable_pcie_clock(void) · line 580

Quoted 4 lines
arch/arm/cpu/armv7/mx6/clock.c +4 -0
+	/* Disable EMI slow clk */
+	reg = readl(&ccm_regs->CCGR6);
+	reg &= ~MXC_CCM_CCGR6_EMI_SLOW_MASK;
+	writel(reg, &ccm_regs->CCGR6);

Ditto?

arch/arm/cpu/armv7/mx6/hab.c line 15

Quoted 3 lines
arch/arm/cpu/armv7/mx6/hab.c +3 -0
+/* enable HAB (High Assurance Boot) debug */
+/* #define DEBUG_AUTHENTICATE_IMAGE */
+

Please do not add dead code.

Quoted 12 lines
arch/arm/cpu/armv7/mx6/hab.c +12 -0
+#ifdef DEBUG_AUTHENTICATE_IMAGE
+void dump_mem(uint32_t addr, int size)
+{
+	int i;
+
+	for (i = 0; i < size; i += 4) {
+		if (i != 0) {
+			if (i % 16 == 0)
+				printf("\n");
+			else
+				printf(" ");
+		}

arch/arm/cpu/armv7/mx6/hab.c int get_hab_status(void) · line 207

Quoted 10 lines
arch/arm/cpu/armv7/mx6/hab.c +10 -0
+
+		printf("0x%08x", *(uint32_t *)addr);
+		addr += 4;
+	}
+
+	printf("\n");
+
+	return;
+}
+#endif

Is this really needed? Do we not already have such code, like print_buffer() ?

arch/arm/include/asm/arch-mx6/clock.h int enable_i2c_clk(unsigned char enable, unsigned i2c_num); · line 68

Quoted 8 lines
arch/arm/include/asm/arch-mx6/clock.h +4 -0
@@ -60,4 +62,8 @@ int enable_i2c_clk(unsigned char enable, unsigned i2c_num);
 int enable_spi_clk(unsigned char enable, unsigned spi_num);
 void enable_ipu_clock(void);
 int enable_fec_anatop_clock(enum enet_freq freq);
+#ifdef CONFIG_SECURE_BOOT
+void hab_caam_clock_enable(void);
+void hab_caam_clock_disable(void);
+#endif

You can drop the #ifdef for prototypes.

Quoted 12 lines
arch/arm/include/asm/arch-mx6/sys_proto.h +2 -0
@@ -2,6 +2,8 @@
  * (C) Copyright 2009
  * Stefano Babic, DENX Software Engineering, sbabic at denx.de.
  *
+ * (C) Copyright 2014 Freescale Semiconductor, Inc.
+ *
  * SPDX-License-Identifier:	GPL-2.0+
  */
 

arch/arm/include/asm/arch-mx6/sys_proto.h line 16

Quoted 5 lines
arch/arm/include/asm/arch-mx6/sys_proto.h +1 -1
@@ -11,7 +13,7 @@
 #include <asm/imx-common/regs-common.h>
 #include "../arch-imx/cpu.h"
 
-#define soc_rev() (get_cpu_rev() & 0xFF)
+#define soc_rev() ((int)(get_cpu_rev() & 0xFF))

Claiming copyright for adding a single cast is a bit excessive, isn't it?

Best regards,

Wolfgang Denk

Signature · 7 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Your csh still thinks true is false. Write to your vendor  today  and
tell them that next year Configure ought to "rm /bin/csh" unless they
fix  their blasted shell. :-)
                 - Larry Wall in Configure from the perl distribution