Skip to contentSkip to conversation

imx: hab: Keep CAAM clock enabled after authenticating additional images

PATCH New Breno Lima 3 participants 11 messages Feb 20, 2018 – Feb 22, 2018

Subsystems (3)
lore
Share & tools
lore

Breno Lima

author
#0 lore raw

PATCH 1/5 imx: hab: Keep CAAM clock enabled after authenticating additional images

From: Breno Lima <[email protected]>

Currently it is not possible to run CMD_DEK on i.MX SPL targets:

=> dek_blob 0x12000000 0x12001000 128

The system hangs after running dek_blob because the CAAM clock is being disabled by the HAB code. There is no need to disable CAAM clock after authenticating additional boot images, thus keep CAAM clock enabled to address this issue.

---
 arch/arm/mach-imx/hab.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
arch/arm/mach-imx/hab.c +3 -4
index 5f19777..1e6b31d 100644
@@ -507,13 +507,13 @@ int imx_hab_authenticate_image(uint32_t ddr_start, uint32_t image_size,
 
 	/* Verify IVT header bugging out on error */
 	if (verify_ivt_header(ivt_hdr))
-		goto hab_caam_clock_disable;
+		goto hab_authentication_exit;
 
 	/* Verify IVT body */
 	if (ivt->self != ivt_addr) {
 		printf("ivt->self 0x%08x pointer is 0x%08x\n",
 		       ivt->self, ivt_addr);
-		goto hab_caam_clock_disable;
+		goto hab_authentication_exit;
 	}
 
 	start = ddr_start;
@@ -591,8 +591,7 @@ hab_exit_failure_print_status:
 	get_hab_status();
 #endif
 
-hab_caam_clock_disable:
-	hab_caam_clock_enable(0);
+hab_authentication_exit:
 
 	if (load_addr != 0)
 		result = 0;
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH 2/5 imx: hab: Ensure the IVT DCD pointer is Null prior to calling HAB authenticate function.

From: Utkarsh Gupta <[email protected]>

DCD commands should only be present in the initial boot image loaded by the SoC ROM. DCD should not be present in images that will be verified by software using HAB RVT authentication APIs. Newer versions of HAB will generate an error if a DCD pointer is present in an image being authenticated by calling the HAB RVT API. Older versions of HAB will process and run DCD if it is present, and this could lead to an incorrect authentication boot flow.

It is highly recommended this check is in place to ensure additional HAB verified images do not include a DCD table.

---
 arch/arm/mach-imx/hab.c | 6 ++++++
 1 file changed, 6 insertions(+)
arch/arm/mach-imx/hab.c +6 -0
index 1e6b31d..ba6b31d 100644
@@ -516,6 +516,12 @@ int imx_hab_authenticate_image(uint32_t ddr_start, uint32_t image_size,
 		goto hab_authentication_exit;
 	}
 
+	/* Verify if IVT DCD pointer is NULL */
+	if (ivt->dcd) {
+		puts("Error: DCD pointer must be NULL\n");
+		goto hab_authentication_exit;
+	}
+
 	start = ddr_start;
 	bytes = image_size;
 
Signature · 1 line
2.7.4
reviewer
#2 lore raw

PATCH 2/5 imx: hab: Ensure the IVT DCD pointer is Null prior to calling HAB authenticate function.

Quoted 10 lines · Breno Lima

From: Utkarsh Gupta <[email protected]>

DCD commands should only be present in the initial boot image loaded by the SoC ROM. DCD should not be present in images that will be verified by software using HAB RVT authentication APIs. Newer versions of HAB will generate an error if a DCD pointer is present in an image being authenticated by calling the HAB RVT API. Older versions of HAB will process and run DCD if it is present, and this could lead to an incorrect authentication boot flow.

Quoted 5 lines

It is highly recommended this check is in place to ensure additional HAB verified images do not include a DCD table.

author
#3 lore raw

PATCH 3/5 imx: hab: Check if CSF is valid before authenticating image

In reply to Breno Lima

From: Utkarsh Gupta <[email protected]>

For proper authentication the HAB code must check if the CSF is valid. Users must call the csf_is_valid() function to parse the CSF prior to authenticating any additional images. The function will return a failure if any of the following invalid conditions are met:

- CSF pointer is NULL
- CSF Header does not exist
- CSF does not lie within the image bounds
- CSF command length zero

---
 arch/arm/include/asm/mach-imx/hab.h |  8 ++++
 arch/arm/mach-imx/hab.c             | 81 +++++++++++++++++++++++++++++++++++++
 2 files changed, 89 insertions(+)
arch/arm/include/asm/mach-imx/hab.h +8 -0
index a0cb19d..bb73203 100644
@@ -38,6 +38,12 @@ struct ivt {
 	uint32_t reserved2;	/* Reserved should be zero */
 };
 
+struct __packed hab_hdr {
+	u8 tag;              /* Tag field */
+	u8 len[2];           /* Length field in bytes (big-endian) */
+	u8 par;              /* Parameters field */
+};
+
 /* -------- start of HAB API updates ------------*/
 /* The following are taken from HAB4 SIS */
 
@@ -182,6 +188,8 @@ typedef void hapi_clock_init_t(void);
 #define HAB_CID_ROM 0 /**< ROM Caller ID */
 #define HAB_CID_UBOOT 1 /**< UBOOT Caller ID*/
 
+#define HAB_CMD_HDR          0xD4  /* CSF Header */
+
 #define IVT_SIZE			0x20
 #define CSF_PAD_SIZE			0x2000
 
arch/arm/mach-imx/hab.c +81 -0

93 lines not on this page · raw message

Signature · 1 line
2.7.4
reviewer
#4 lore raw

PATCH 3/5 imx: hab: Check if CSF is valid before authenticating image

Quoted 7 lines · Breno Lima

From: Utkarsh Gupta <[email protected]>

For proper authentication the HAB code must check if the CSF is valid. Users must call the csf_is_valid() function to parse the CSF prior to authenticating any additional images. The function will return a failure if any of the following invalid conditions are met:

Quoted 7 lines

- CSF pointer is NULL
- CSF Header does not exist
- CSF does not lie within the image bounds
- CSF command length zero

author
#5 lore raw

PATCH 4/5 imx: hab: Check if CSF contains deprecated commands

In reply to Breno Lima

From: Utkarsh Gupta <[email protected]>

Write, Check and Set MID commands have been deprecated from the Code Signing Tool (CST) v2.3.3 and will not be implemented in newer versions of HAB, hence the following features are no longer available:

- Write Data
- Clear Mask
- Set Mask
- Check All Clear
- Check All Set
- Check Any Clear
- Check Any Set
- Set MID

The inappropriate use of Write Data command may lead to an incorrect authentication boot flow. Since no specific application has been identified that requires the use of any of these features, it is highly recommended to add this check.

---
 arch/arm/include/asm/mach-imx/hab.h |  4 ++++
 arch/arm/mach-imx/hab.c             | 20 ++++++++++++++++++++
 2 files changed, 24 insertions(+)
arch/arm/include/asm/mach-imx/hab.h +4 -0
index bb73203..93475a6 100644
@@ -189,6 +189,10 @@ typedef void hapi_clock_init_t(void);
 #define HAB_CID_UBOOT 1 /**< UBOOT Caller ID*/
 
 #define HAB_CMD_HDR          0xD4  /* CSF Header */
+#define HAB_CMD_WRT_DAT      0xCC  /* Write Data command tag */
+#define HAB_CMD_CHK_DAT      0xCF  /* Check Data command tag */
+#define HAB_CMD_SET          0xB1  /* Set command tag */
+#define HAB_PAR_MID          0x01  /* MID parameter value */
 
 #define IVT_SIZE			0x20
 #define CSF_PAD_SIZE			0x2000
arch/arm/mach-imx/hab.c +20 -0
index 7f66965..79e8bf6 100644
@@ -518,6 +518,26 @@ static bool csf_is_valid(struct ivt *ivt, ulong start_addr, size_t bytes)
 	}
 
 	do {
+		struct hab_hdr *cmd;
+
+		cmd = (struct hab_hdr *)&csf_hdr[offset];
+
+		switch (cmd->tag) {
+		case (HAB_CMD_WRT_DAT):
+			puts("Error: Deprecated write command found\n");
+			return false;
+		case (HAB_CMD_CHK_DAT):
+			puts("Error: Deprecated check command found\n");
+			return false;
+		case (HAB_CMD_SET):
+			if (cmd->par == HAB_PAR_MID) {
+				puts("Error: Deprecated Set MID command found\n");
+				return false;
+			}
+		default:
+			break;
+		}
+
 		cmd_hdr_len = get_csf_cmd_hdr_len(&csf_hdr[offset]);
 		if (!cmd_hdr_len) {
 			puts("Error: Invalid command length\n");
Signature · 1 line
2.7.4
reviewer
#6 lore raw

PATCH 4/5 imx: hab: Check if CSF contains deprecated commands

Quoted 15 lines · Breno Lima

From: Utkarsh Gupta <[email protected]>

Write, Check and Set MID commands have been deprecated from the Code Signing Tool (CST) v2.3.3 and will not be implemented in newer versions of HAB, hence the following features are no longer available:

- Write Data
- Clear Mask
- Set Mask
- Check All Clear
- Check All Set
- Check Any Clear
- Check Any Set
- Set MID

Quoted 7 lines

The inappropriate use of Write Data command may lead to an incorrect authentication boot flow. Since no specific application has been identified that requires the use of any of these features, it is highly recommended to add this check.

author
#7 lore raw

PATCH 5/5 arm: imx: hab: Define HAB_RVT_BASE according to the processor version

In reply to Breno Lima

From: Breno Lima <[email protected]>

Currently the following devices are using a different definition for ROM Vector Table addresses:

- i.MX6DQP = All rev
- i.MX6DQ >= rev 1.5
- i.MX6SDL >= rev 1.2

There is no need to create a new RVT macros since the only update were the RVT base address. Remove HAB_RVT_*_NEW macros and define a new RVT base address.

More details about RVT base address can be found on processors Reference Manual and in the following documents:

EB803: i.MX 6Dual/6Quad Applications Processor Silicon Revision 1.2 to 1.3 Comparison

EB804: i.MX 6Solo/6DualLite Application Processor Silicon Revision 1.1 to 1.2/1.3 Comparison

---
 arch/arm/include/asm/mach-imx/hab.h |  15 ++---
 arch/arm/mach-imx/hab.c             | 106 +++---------------------------------
 2 files changed, 17 insertions(+), 104 deletions(-)
arch/arm/include/asm/mach-imx/hab.h +8 -7
index 93475a6..561de9c 100644
@@ -168,7 +168,14 @@ typedef void hapi_clock_init_t(void);
 #ifdef CONFIG_ROM_UNIFIED_SECTIONS
 #define HAB_RVT_BASE			0x00000100
 #else
-#define HAB_RVT_BASE			0x00000094
+#define HAB_RVT_BASE_NEW		0x00000098
+#define HAB_RVT_BASE_OLD		0x00000094
+#define HAB_RVT_BASE ((is_mx6dqp()) ?					\
+			HAB_RVT_BASE_NEW :				\
+			(is_mx6dq() && (soc_rev() >= CHIP_REV_1_5)) ?	\
+			HAB_RVT_BASE_NEW :				\
+			(is_mx6sdl() && (soc_rev() >= CHIP_REV_1_2)) ?	\
+			HAB_RVT_BASE_NEW : HAB_RVT_BASE_OLD)
 #endif
 
 #define HAB_RVT_ENTRY			(*(uint32_t *)(HAB_RVT_BASE + 0x04))
@@ -179,12 +186,6 @@ typedef void hapi_clock_init_t(void);
 #define HAB_RVT_REPORT_STATUS		(*(uint32_t *)(HAB_RVT_BASE + 0x24))
 #define HAB_RVT_FAILSAFE		(*(uint32_t *)(HAB_RVT_BASE + 0x28))
 
-#define HAB_RVT_REPORT_EVENT_NEW               (*(uint32_t *)0x000000B8)
-#define HAB_RVT_REPORT_STATUS_NEW              (*(uint32_t *)0x000000BC)
-#define HAB_RVT_AUTHENTICATE_IMAGE_NEW         (*(uint32_t *)0x000000A8)
-#define HAB_RVT_ENTRY_NEW                      (*(uint32_t *)0x0000009C)
-#define HAB_RVT_EXIT_NEW                       (*(uint32_t *)0x000000A0)
-
 #define HAB_CID_ROM 0 /**< ROM Caller ID */
 #define HAB_CID_UBOOT 1 /**< UBOOT Caller ID*/
 
arch/arm/mach-imx/hab.c +9 -97

130 lines not on this page · raw message

Signature · 1 line
2.7.4
reviewer
#8 lore raw

PATCH 5/5 arm: imx: hab: Define HAB_RVT_BASE according to the processor version

Quoted 16 lines · Breno Lima

From: Breno Lima <[email protected]>

Currently the following devices are using a different definition for ROM Vector Table addresses:

- i.MX6DQP = All rev
- i.MX6DQ >= rev 1.5
- i.MX6SDL >= rev 1.2

There is no need to create a new RVT macros since the only update were the RVT base address. Remove HAB_RVT_*_NEW macros and define a new RVT base address.

More details about RVT base address can be found on processors Reference Manual and in the following documents:

Quoted 7 lines

EB803: i.MX 6Dual/6Quad Applications Processor Silicon Revision 1.2 to 1.3 Comparison

EB804: i.MX 6Solo/6DualLite Application Processor Silicon Revision 1.1 to 1.2/1.3 Comparison

reviewer
#9 lore raw

PATCH 1/5 imx: hab: Keep CAAM clock enabled after authenticating additional images

In reply to Breno Lima
Quoted 4 lines · Breno Lima

From: Breno Lima <[email protected]>

Currently it is not possible to run CMD_DEK on i.MX SPL targets:

Quoted 8 lines

=> dek_blob 0x12000000 0x12001000 128

The system hangs after running dek_blob because the CAAM clock is being disabled by the HAB code. There is no need to disable CAAM clock after authenticating additional boot images, thus keep CAAM clock enabled to address this issue.

#10 lore raw

PATCH 1/5 imx: hab: Keep CAAM clock enabled after authenticating additional images

Quoted 7 lines · Fabio Estevam
Quoted 6 lines · Breno Lima

From: Breno Lima <[email protected]>

Currently it is not possible to run CMD_DEK on i.MX SPL targets:

=> dek_blob 0x12000000 0x12001000 128

Quoted 9 lines
Quoted 6 lines

The system hangs after running dek_blob because the CAAM clock is being disabled by the HAB code. There is no need to disable CAAM clock after authenticating additional boot images, thus keep CAAM clock enabled to address this issue.

Series contains fixes, I pick it up for the release.

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================