public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Madan Srinivas <madans@ti.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 2/7] arm: mach-keystone: Implements FIT post-processing call for keystone SoCs
Date: Thu, 1 Sep 2016 01:04:37 -0400	[thread overview]
Message-ID: <1472706282-6772-3-git-send-email-madans@ti.com> (raw)
In-Reply-To: <1472706282-6772-1-git-send-email-madans@ti.com>

From: Vitaly Andrianov <vitalya@ti.com>

This commit implements the board_fit_image_post_process() function for
the keystone architecture. Unlike OMAP class devices, security
functions in keystone are not handled in the ROM.
The interface to the secure functions is TI proprietary and depending
on the keystone platform, the security functions like encryption,
decryption and authentication might even be offloaded to other secure
processing elements in the SoC.
The boot monitor acts as the gateway to these secure functions and the
boot monitor for secure devices is available as part of the SECDEV
package for KS2. For more details refer doc/README.ti-secure

Signed-off-by: Vitaly Andrianov <vitalya@ti.com>
Signed-off-by: Madan Srinivas <madans@ti.com>

Cc: Lokesh Vutla <lokeshvutla@ti.com>
Cc: Dan Murphy <dmurphy@ti.com>
---

Changes in v2:
- The following changes are  made to mon.c based on review comments
	Adds NULL pointer check before calling authentication interface
	Removes an unnecessary printf
	Updates size of signed FIT blob after post processing removes header

 arch/arm/mach-keystone/mon.c | 55 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/arch/arm/mach-keystone/mon.c b/arch/arm/mach-keystone/mon.c
index 256f630..6b79077 100644
--- a/arch/arm/mach-keystone/mon.c
+++ b/arch/arm/mach-keystone/mon.c
@@ -12,10 +12,31 @@
 #include <mach/mon.h>
 asm(".arch_extension sec\n\t");
 
+#ifdef CONFIG_TI_SECURE_DEVICE
+#define KS2_HS_AUTH_FN_OFFSET	8
+#define KS2_HS_SEC_HEADER_LEN	0x60
+#define KS2_AUTH_CMD		"2"
+/**
+ * (*fn_auth)() - Invokes security functions using a
+ * proprietary TI interface. This binary and source for
+ * this is available in the secure development package or
+ * SECDEV. For details on how to access this please refer
+ * doc/README.ti-secure
+ *
+ * @first param:	no. of parameters
+ * @second param:	parameter list
+ * @return non-zero value on success, zero on error
+ */
+static unsigned int (*fn_auth)(int, char * const []);
+#endif
+
 int mon_install(u32 addr, u32 dpsc, u32 freq)
 {
 	int result;
 
+#ifdef CONFIG_TI_SECURE_DEVICE
+	fn_auth = (void *)(addr + KS2_HS_AUTH_FN_OFFSET);
+#endif
 	__asm__ __volatile__ (
 		"stmfd r13!, {lr}\n"
 		"mov r0, %1\n"
@@ -61,3 +82,37 @@ int mon_power_off(int core_id)
 		: "cc", "r0", "r1", "memory");
 	return  result;
 }
+
+#ifdef CONFIG_TI_SECURE_DEVICE
+static void k2_hs_auth(void *addr)
+{
+	char *argv1 = KS2_AUTH_CMD;
+	char argv2[32];
+	char *argv[3] = {NULL, argv1, argv2};
+	int ret = 0;
+
+	sprintf(argv2, "0x%08x", (u32)addr);
+
+	if (fn_auth)
+		ret = fn_auth(3, argv);
+
+	if (ret == 0)
+		hang();
+}
+
+void board_fit_image_post_process(void **p_image, size_t *p_size)
+{
+	void *dst = *p_image;
+	void *src = dst + KS2_HS_SEC_HEADER_LEN;
+
+	k2_hs_auth(*p_image);
+
+	/*
+	* Overwrite the image headers  after authentication
+	* and decryption. Update size to relect removal
+	* of header.
+	*/
+	*p_size -= KS2_HS_SEC_HEADER_LEN;
+	memcpy(dst, src, *p_size);
+}
+#endif
-- 
2.7.4

  parent reply	other threads:[~2016-09-01  5:04 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <madans@ti.com>
2016-08-26  6:30 ` [U-Boot] [PATCH 0/7] Adds support for secure boot on Keystone SoCs (K2E) Madan Srinivas
2016-08-26  6:30   ` [U-Boot] [PATCH 1/7] include: image.h: Fixes build warning with CONFIG_FIT_IMAGE_POST_PROCESS Madan Srinivas
2016-08-29 14:52     ` Andrew F. Davis
2016-08-26  6:30   ` [U-Boot] [PATCH 2/7] arm: mach-keystone: Implements FIT post-processing call for keystone SoCs Madan Srinivas
2016-08-29 16:22     ` Dan Murphy
2016-08-30  9:03     ` Lokesh Vutla
2016-08-26  6:30   ` [U-Boot] [PATCH 3/7] arm: omap-common: Enable support for K2 HS devices in u-boot Madan Srinivas
2016-08-29 14:56     ` Andrew F. Davis
2016-08-29 17:02     ` Dan Murphy
2016-08-26  6:30   ` [U-Boot] [PATCH 4/7] arm: omap-common: Reuse secure image name between OMAP and keystone Madan Srinivas
2016-08-29 15:10     ` Andrew F. Davis
2016-08-26  6:30   ` [U-Boot] [PATCH 5/7] arm: mach-keystone: config.mk: Adds support for secure images on K2 Madan Srinivas
2016-08-29 15:21     ` Andrew F. Davis
2016-08-26  6:30   ` [U-Boot] [PATCH 6/7] doc: Updates info on using keystone secure devices from TI Madan Srinivas
2016-08-26  6:30   ` [U-Boot] [PATCH 7/7] configs: Adds a defconfig for K2E High Security EVM Madan Srinivas
2016-08-29 15:28     ` Andrew F. Davis
2016-09-01  5:04 ` [U-Boot] [PATCH v2 0/7] Adds support for secure boot on Keystone SoCs (K2E) Madan Srinivas
2016-09-01  5:04   ` [U-Boot] [PATCH v2 1/7] include: image.h: Fixes build warning with CONFIG_FIT_IMAGE_POST_PROCESS Madan Srinivas
2016-09-06 13:34     ` Tom Rini
2016-09-06 13:34     ` Tom Rini
2016-09-01  5:04   ` Madan Srinivas [this message]
2016-09-06 13:34     ` [U-Boot] [PATCH v2 2/7] arm: mach-keystone: Implements FIT post-processing call for keystone SoCs Tom Rini
2016-09-08 15:29       ` Srinivas, Madan
2016-09-01  5:04   ` [U-Boot] [PATCH v2 3/7] arm: omap-common: adds secure image name common to OMAP and keystone Madan Srinivas
2016-09-06 13:34     ` Tom Rini
2016-09-01  5:04   ` [U-Boot] [PATCH v2 4/7] arm: omap-common: Enable support for K2 HS devices in u-boot Madan Srinivas
2016-09-06 13:34     ` Tom Rini
2016-09-01  5:04   ` [U-Boot] [PATCH v2 5/7] arm: mach-keystone: config.mk: Adds support for secure images on K2 Madan Srinivas
2016-09-02 14:35     ` Andrew F. Davis
2016-09-01  5:04   ` [U-Boot] [PATCH v2 6/7] doc: Updates info on using keystone secure devices from TI Madan Srinivas
2016-09-06 13:34     ` Tom Rini
2016-09-01  5:04   ` [U-Boot] [PATCH v2 7/7] configs: Adds a defconfig for K2E High Security EVM Madan Srinivas
2016-09-02  4:25   ` [U-Boot] [PATCH v2 0/7] Adds support for secure boot on Keystone SoCs (K2E) Lokesh Vutla
2016-09-02 16:48     ` Srinivas, Madan
2016-09-03 16:56       ` Lokesh Vutla
2016-09-03 17:23         ` Nishanth Menon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1472706282-6772-3-git-send-email-madans@ti.com \
    --to=madans@ti.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox