public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Tom Rini <trini@konsulko.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC 5/9] arm: omap5: add secure ROM signature verify API
Date: Sun, 19 Jun 2016 22:13:58 -0400	[thread overview]
Message-ID: <20160620021358.GT4353@bill-the-cat> (raw)
In-Reply-To: <CAPnjgZ0wLQ1K0K-f4T5v3rB+pwm5MBLVsPQa4=xzhfdKC1Y8TQ@mail.gmail.com>

On Thu, Jun 16, 2016 at 09:52:40PM -0600, Simon Glass wrote:
> On 15 June 2016 at 13:26, Andreas Dannenberg <dannenberg@ti.com> wrote:
> > From: Daniel Allred <d-allred@ti.com>
> >
> > Adds an API that verifies a signature attached to an image (binary
> > blob). This API is basically a entry to a secure ROM service provided by
> > the device and accessed via an SMC call, using a particular calling
> > convention.
> >
> > Signed-off-by: Daniel Allred <d-allred@ti.com>
> > Signed-off-by: Andreas Dannenberg <dannenberg@ti.com>
> > ---
> >  arch/arm/cpu/armv7/omap5/Makefile           |  1 +
> >  arch/arm/cpu/armv7/omap5/sec_fxns.c         | 70 +++++++++++++++++++++++++++++
> >  arch/arm/include/asm/arch-omap5/sys_proto.h |  4 ++
> >  3 files changed, 75 insertions(+)
> >  create mode 100644 arch/arm/cpu/armv7/omap5/sec_fxns.c
> 
> Reviewed-by: Simon Glass <sjg@chromium.org>
> 
> Please see below.
> 
> >
> > diff --git a/arch/arm/cpu/armv7/omap5/Makefile b/arch/arm/cpu/armv7/omap5/Makefile
> > index 3caba86..d373bf4 100644
> > --- a/arch/arm/cpu/armv7/omap5/Makefile
> > +++ b/arch/arm/cpu/armv7/omap5/Makefile
> > @@ -14,3 +14,4 @@ obj-y += hw_data.o
> >  obj-y  += abb.o
> >  obj-y  += fdt.o
> >  obj-$(CONFIG_IODELAY_RECALIBRATION) += dra7xx_iodelay.o
> > +obj-$(CONFIG_TI_SECURE_DEVICE) += sec_fxns.o
> > diff --git a/arch/arm/cpu/armv7/omap5/sec_fxns.c b/arch/arm/cpu/armv7/omap5/sec_fxns.c
> > new file mode 100644
> > index 0000000..766333a
> > --- /dev/null
> > +++ b/arch/arm/cpu/armv7/omap5/sec_fxns.c
> > @@ -0,0 +1,70 @@
> > +/*
> > + *
> > + * Common security functions that rely on secure ROM services
> > + *
> > + * (C) Copyright 2016
> > + * Texas Instruments, <www.ti.com>
> > + *
> > + * Daniel Allred    <d-allred@ti.com>
> > + *
> > + * SPDX-License-Identifier: GPL-2.0+
> > + */
> > +
> > +#include <common.h>
> > +#include <asm/arch/sys_proto.h>
> > +#include <asm/omap_common.h>
> > +
> > +#define SIGNATURE_LENGTH                               (0x118)
> > +
> > +/* API Index for OMAP5, DRA7xx */
> > +#define API_HAL_KM_VERIFYCERTIFICATESIGNATURE_INDEX    (0x0000000E)
> > +
> > +int secure_boot_verify_image(void **image, size_t *size)
> > +{
> > +       int result = 1;
> > +       u32 cert_addr, sig_addr;
> > +       size_t cert_size;
> > +
> > +#ifndef CONFIG_SYS_DCACHE_OFF
> > +       /* Perform cache writeback on input buffer */
> > +       flush_dcache_range(
> > +               (u32)*image,
> > +               (u32)*image + roundup(*size, ARCH_DMA_MINALIGN));
> > +#endif
> > +       cert_addr = (uint32_t)*image;
> > +       *size -= SIGNATURE_LENGTH;   /* Subtract out the signature size */
> > +       cert_size = *size;
> > +       sig_addr = cert_addr + cert_size;
> > +
> > +       /* Check if image load address is 32-bit aligned */
> > +       if (0 != (0x3 & cert_addr)) {
> > +               puts("Image is not 4-byte aligned.\n");
> > +               result = 1;
> > +               goto auth_exit;
> > +       }
> > +
> > +       /* Image size also should be multiple of 4 */
> > +       if (0 != (0x3 & cert_size)) {
> > +               puts("Image size is not 4-byte aligned.\n");
> > +               result = 1;
> > +               goto auth_exit;
> > +       }
> > +
> > +       /* Call ROM HAL API to verify certificate signature */
> > +       debug("%s: load_addr = %x, size = %x, sig_addr = %x\n", __func__,
> > +             cert_addr, cert_size, sig_addr);
> > +
> > +       result = secure_rom_call(
> > +               API_HAL_KM_VERIFYCERTIFICATESIGNATURE_INDEX, 0, 0,
> > +               4, cert_addr, cert_size, sig_addr, 0xFFFFFFFF);
> > +auth_exit:
> > +       if (result != 0) {
> > +               puts("Authentication failed!\n");
> > +               printf("Return Value = %08X\n", result);
> > +               hang();
> > +       }
> > +
> > +       printf("Authentication passed: %s\n", (char *)sig_addr);
> > +
> > +       return result;
> > +}
> > diff --git a/arch/arm/include/asm/arch-omap5/sys_proto.h b/arch/arm/include/asm/arch-omap5/sys_proto.h
> > index ab0e7fa..b175124 100644
> > --- a/arch/arm/include/asm/arch-omap5/sys_proto.h
> > +++ b/arch/arm/include/asm/arch-omap5/sys_proto.h
> > @@ -84,4 +84,8 @@ static inline u32 usec_to_32k(u32 usec)
> >  #define OMAP5_SERVICE_L2ACTLR_SET    0x104
> >  #define OMAP5_SERVICE_ACR_SET        0x107
> >
> > +#ifdef CONFIG_TI_SECURE_DEVICE
> > +int secure_boot_verify_image(void **p_image, size_t *p_size);
> 
> Function comment please.

And no ifdef/endif (here and later in the series when adding other
calls), thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160619/1f6a8fb5/attachment.sig>

  reply	other threads:[~2016-06-20  2:13 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-15 19:26 [U-Boot] [RFC 0/9] Secure Boot by Authenticating/Decrypting SPL FIT blobs Andreas Dannenberg
2016-06-15 19:26 ` [U-Boot] [RFC 1/9] spl: fit: add support for post-processing of images Andreas Dannenberg
2016-06-17  3:52   ` Simon Glass
2016-06-15 19:26 ` [U-Boot] [RFC 2/9] arm: cache: add missing dummy functions for when dcache disabled Andreas Dannenberg
2016-06-17  3:52   ` Simon Glass
2016-06-20  2:13   ` Tom Rini
2016-06-15 19:26 ` [U-Boot] [RFC 3/9] arm: omap-common: add secure smc entry Andreas Dannenberg
2016-06-17  3:52   ` Simon Glass
2016-06-15 19:26 ` [U-Boot] [RFC 4/9] arm: omap-common: add secure rom call API for secure devices Andreas Dannenberg
2016-06-17  3:52   ` Simon Glass
2016-06-17  4:18   ` Lokesh Vutla
2016-06-15 19:26 ` [U-Boot] [RFC 5/9] arm: omap5: add secure ROM signature verify API Andreas Dannenberg
2016-06-17  3:52   ` Simon Glass
2016-06-20  2:13     ` Tom Rini [this message]
2016-06-15 19:26 ` [U-Boot] [RFC 6/9] arm: omap5: add FIT image post process function Andreas Dannenberg
2016-06-17  3:52   ` Simon Glass
2016-06-17  4:26   ` Lokesh Vutla
2016-06-15 19:26 ` [U-Boot] [RFC 7/9] arm: am4x: add secure ROM signature verify API Andreas Dannenberg
2016-06-17  3:52   ` Simon Glass
2016-06-15 19:26 ` [U-Boot] [RFC 8/9] arm: am4x: add FIT image post process function Andreas Dannenberg
2016-06-17  3:52   ` Simon Glass
2016-06-17  4:27   ` Lokesh Vutla
2016-06-15 19:26 ` [U-Boot] [RFC 9/9] ti: omap-common: Update to generate secure FIT Andreas Dannenberg
2016-06-17  3:52   ` Simon Glass
2016-06-17 16:13     ` Andreas Dannenberg
2016-06-20 22:40       ` Simon Glass
2016-06-21  2:35         ` Andreas Dannenberg
2016-06-23  4:59           ` Masahiro Yamada
2016-06-23 13:23             ` Andreas Dannenberg

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=20160620021358.GT4353@bill-the-cat \
    --to=trini@konsulko.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