public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Stefano Babic <sbabic@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 4/5] imx: hab add mx7 secure boot support
Date: Fri, 9 Oct 2015 10:52:42 +0200	[thread overview]
Message-ID: <5617805A.80305@denx.de> (raw)
In-Reply-To: <1443648649-24599-4-git-send-email-aalonso@freescale.com>

Hi Adrian,

On 30/09/2015 23:30, Adrian Alonso wrote:
> Add mx7 secure boot support, reuse existing mx6 hab
> 
> Signed-off-by: Adrian Alonso <aalonso@freescale.com>
> ---
> Changes for V2:
> - Split from original patch to track mx7 change set
>   hab: rework support for imx6/imx7
> 
>  arch/arm/imx-common/hab.c | 19 ++++++++++++++++---
>  1 file changed, 16 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/arm/imx-common/hab.c b/arch/arm/imx-common/hab.c
> index 9ee0f12..565a838 100644
> --- a/arch/arm/imx-common/hab.c
> +++ b/arch/arm/imx-common/hab.c
> @@ -261,12 +261,25 @@ uint8_t hab_engines[16] = {
>  bool is_hab_enabled(void)
>  {
>  	struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
> +	uint32_t reg;
> +#if CONFIG_MX7

Usage of SOC's runtime detection is vanished by introducing new #ifdef
section. I am aware there some registers defined for a SOC and not for
another. This is the point. We should make the access unaware for the
driver (this file).

hab.c does not yet contain any nasty #ifdef SOC_TYPE - we should have
the same in future.

> +	struct fuse_bank *bank = &ocotp->bank[1];
> +	struct fuse_bank1_regs *fuse =
> +		(struct fuse_bank1_regs *)bank->fuse_regs;
> +	reg = readl(&fuse->cfg0);
> +#elif CONFIG_MX6
>  	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);
> +	reg = readl(&fuse->cfg5);
> +#endif

There are some ways to solve it. For example (but it is not the only
solution), the offset can be set into the corresponding imx_regs as
offsetof(..) and which fuse bank can be picked up from a table here
	fuse_bank_choosen = {0 ,1 }

and then
	struct fuse_bank *bank;
 	if (is_cpu_type(MXC_CPU_MX7))
		bank = &ocotp->bank[1];
	else
		bank = &ocotp->bank[0];

or you find a better solution, of course - but do not introduce new
#ifdef. If you see, hab.c contains at the very beginning a lot of stuff
hab_rvt_report_* that makes runtime detection against compiler switches.

> +
> +	if (is_soc_type(MXC_SOC_MX7))
> +		return (reg & 0x2000000) == 0x2000000;
> +	else if (is_soc_type(MXC_SOC_MX6))
> +		return (reg & 0x2) == 0x2;

If I did not know that all i.MXes are little endian, it looks like an
endianess problem. But I suggest to add a macro for a better readiness:

#define IS_HAB_ENABLED_BIT (is_soc_type(MXC_SOC_MX7) ? 0x2000000 : 0x2)


and then you can use here simply:

	return (reg & IS_HAB_ENABLED_BIT) == IS_HAB_ENABLED_BIT

>  			 * crash.
>  			 */
>  			/* Check MMU enabled */
> -			if (get_cr() & CR_M) {
> +			if (is_soc_type(MXC_SOC_MX6) && get_cr() & CR_M) {

There is a long explanation before this code. As it depends from MMU
only, it does not explain why it is not required for MX7. Please extend
the comment and put a full explanation here.

Best regards,
Stefano Babic



-- 
=====================================================================
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
=====================================================================

  reply	other threads:[~2015-10-09  8:52 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-30 21:30 [U-Boot] [PATCH v2 1/5] imx: cpu: move common chip revision id's Adrian Alonso
2015-09-30 21:30 ` [U-Boot] [PATCH v2 2/5] imx: hab: rework support for imx6/imx7 Adrian Alonso
2015-10-09  8:27   ` Stefano Babic
2015-09-30 21:30 ` [U-Boot] [PATCH v2 3/5] imx: hab use unified rom section for mx6sx and mx6ul Adrian Alonso
2015-10-09  8:25   ` Stefano Babic
2015-09-30 21:30 ` [U-Boot] [PATCH v2 4/5] imx: hab add mx7 secure boot support Adrian Alonso
2015-10-09  8:52   ` Stefano Babic [this message]
2015-10-12 18:49     ` Alonso Adrian
2015-09-30 21:30 ` [U-Boot] [PATCH v2 5/5] mx7dsabresd: add " Adrian Alonso

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=5617805A.80305@denx.de \
    --to=sbabic@denx.de \
    --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