From patchwork Thu Jul 14 16:27:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 648297 X-Patchwork-Delegate: yorksun@freescale.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3rqsJX0BDMz9s1h for ; Thu, 14 Jul 2016 20:24:42 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7876B4B99D; Thu, 14 Jul 2016 12:24:37 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6tCcT6wMZJh4; Thu, 14 Jul 2016 12:24:37 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id ED6204B979; Thu, 14 Jul 2016 12:24:36 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0A8F74B979 for ; Thu, 14 Jul 2016 12:24:33 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rogNi2sL5ptZ for ; Thu, 14 Jul 2016 12:24:32 +0200 (CEST) X-Greylist: delayed 922 seconds by postgrey-1.34 at theia; Thu, 14 Jul 2016 12:24:28 CEST X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from NAM03-DM3-obe.outbound.protection.outlook.com (mail-dm3nam03on0045.outbound.protection.outlook.com [104.47.41.45]) by theia.denx.de (Postfix) with ESMTPS id 28DE94B811 for ; Thu, 14 Jul 2016 12:24:28 +0200 (CEST) Received: from BN3PR0301CA0009.namprd03.prod.outlook.com (10.160.180.147) by BN3PR03MB2401.namprd03.prod.outlook.com (10.166.75.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.528.16; Thu, 14 Jul 2016 10:09:16 +0000 Received: from BN1AFFO11FD027.protection.gbl (2a01:111:f400:7c10::127) by BN3PR0301CA0009.outlook.office365.com (2a01:111:e400:4000::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.539.14 via Frontend Transport; Thu, 14 Jul 2016 10:09:16 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none; nxp.com; dmarc=fail action=none header.from=nxp.com; nxp.com; dkim=none (message not signed) header.d=none; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BN1AFFO11FD027.mail.protection.outlook.com (10.58.52.87) with Microsoft SMTP Server (TLS) id 15.1.523.9 via Frontend Transport; Thu, 14 Jul 2016 10:09:16 +0000 Received: from localhost.localdomain.ap.freescale.net ([10.232.14.164]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id u6EA8woC019249; Thu, 14 Jul 2016 03:09:12 -0700 From: Sumit Garg To: Date: Thu, 14 Jul 2016 12:27:51 -0400 Message-ID: <1468513673-5406-2-git-send-email-sumit.garg@nxp.com> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1468513673-5406-1-git-send-email-sumit.garg@nxp.com> References: <1468513673-5406-1-git-send-email-sumit.garg@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131129645562920458; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(7916002)(2980300002)(1109001)(1110001)(339900001)(189002)(199003)(87936001)(2351001)(586003)(229853001)(19580395003)(81166006)(19580405001)(77096005)(2950100001)(36756003)(33646002)(8936002)(7846002)(81156014)(50226002)(305945005)(356003)(48376002)(106466001)(189998001)(105606002)(2906002)(50466002)(97736004)(104016004)(86362001)(50986999)(8666005)(6806005)(92566002)(575784001)(47776003)(5003940100001)(11100500001)(15975445007)(110136002)(85426001)(4326007)(8676002)(68736007)(76176999)(7059030)(4720700001); DIR:OUT; SFP:1101; SCL:1; SRVR:BN3PR03MB2401; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD027; 1:1zvIKpmG2wBEYTW9ZDeK8+umxjaxTTOiDYcVFTIzRWaQA/WXn4Z9faqZOi6wv6sA8vzqrfnwOABgqqbBiaQDPjrOm0stunkKlJwWqrznXofZ1mxmepgCZbU2qyiTBjA8uCmnhTo+mGYGHRfmogHA3kPn3Ll0GXGOYd9gPn7r+BpK+U/upqZnIE8ysHOozZmvlERtlF8sZXxPYt+z4uK9u9IyiGjaeHtxI/FHH69j5vgxlMDR7NbMS7VCosvM8095Z/frUagqPjmnCTh5TjEH4yCvmZnILb17L1qCS3AR71U6K1q2l2TTXjgK0sIAut604BdY6ZZLp50Auw+GMg6oq8i13E23KhMdvgfmVSJ4m+vP7zwCL/ViP0UGCS5hIKdFt2bvS/BrbbJwNZwyyGVLtHei314PfOBCrd6QYLd3IgKg0dB0cpPX5MxOLLpOZCSpwfo+eOKt71aF+z6zlR8QKqwv/g8yl+vKM7vkjR7507tRi4V01jR+y/lg2b/TQs8YOpdkBDfYfPnqxoefvNxZd2Bn6VvjI3/OealqXJfN8XGQlV3y9XlPGA+B3Hw4rKD3EGITOfIei8GmGWPyeSYGMAQG9pR5Orf+AYn/Fgsm08Gxt4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+XLo1ALuiOKE5QXjAx0ilY5q1l9TE= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN3PR03MB2401; X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB2401; 31:cDDJE5D31f/i9aemhWlhGuTHxFiNCLOFnXBCj10bKJXlxDhbt605d9uLs9AtVBQH2v3jZTZ3phS3LWJkjPw19VzPcS8uoHk1pODwtBB082KGJuzy++vR+0n/JKHy50kC2c2pwW6bjNCKhAj3rUvckKTyMJUjuIb/37G5rzbOOTTkYnzsqrrDpvzBxLVkada/WI7mDme8UvbmaDSDjl6/uw==; 4:A40gISh0K+CnE8c2tDq7moKGSNmFww7QYHLTfHpvmuOHLCNtUieOX70REB0kQEhXvPxozsN9dlFGnpOQqQoQ6HaxdIOnn0xF+U/MmqmUN6EfahBuMf5IU0qunAwN0AF6iYiniHOwa9BZlA7r+NVnYI4yuBvg+pJtChFnm3XsjmDiOQtc43petOk9jjfeSRO+CTeoT7/FiIsiLcKrG6aFFM+2ONitKQ2n80XUxCoob/vAoPzGE/3+Bu7gcsGWTKf+hYpUOXtUwGNJIBT7IYUODiBGGrFMP6b0bUhICVsxa6iHOmYCNbbWSEUimogzQlBzVhBh5nDm0lWb5c0QMYnbXAT3quOaEGNO/nAV/wwbbEVKYurR2AQRuCf73z3YVeb/1SZPNmhSnHJMQUWa3WxB6QhHadSbQMYPcZo7+sp8rtoVwHMEOXlGoE5ON+AGIaK0m/RjwkUNjeHCHpenrlyKKECK+zGGdTvvl9ogX/3qeHERBAg1NyvhVB7mbdFhjJo4w/dAF3Yti6JCTbOuuWGjWQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13023025)(13024025)(13015025)(13018025)(13017025)(5005006)(8121501046)(10201501046)(3002001)(6055026); SRVR:BN3PR03MB2401; BCL:0; PCL:0; RULEID:(400006); SRVR:BN3PR03MB2401; X-Forefront-PRVS: 00032065B2 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN3PR03MB2401; 23:b8rAm6eH/g0mhAwbHw/EgtfiOYPBh18ERJoHET//O?= =?us-ascii?Q?PTVQXwDPJrCybPrTeqFchrzj2w36zTkEjoLIQlX/UVY6Zkx4PGPphiMDgeg3?= =?us-ascii?Q?OrVIv0zdJf1dU5OdZbGk4eOXS+zK17dHaigwFPg0hTtyz0+HBUkORW/UsvfM?= =?us-ascii?Q?YnGrzeP7Txj1iGO0pE5Gne9HuyfbcfBO9LB1yEx7DDvRx5xTcUXfoLFVSP+3?= =?us-ascii?Q?MD2Rke6wz9Jgf6OzaR3Roba0k1y+IIHdnmPNkfzZg9Q+AjKf3Tbego9C7cFG?= =?us-ascii?Q?p3BflRe5wBt0brtcKtsOykf42OB0iFFmsGS67GNch8FtdWR+bkl0lrO4VVzB?= =?us-ascii?Q?mjhEYeIvkn/Rcggi2RAWegNNj+ffEroBJ0SnBCPUKleXEWkkDqgsAHRQWNr6?= =?us-ascii?Q?NsdRS8T4X2263KIvPQaA23OavvBLtVntZJec9y8QrM1ogygDcYBopzP/s5fC?= =?us-ascii?Q?LLBSlZweGq3JllI7oaZgSNYtfDxQv2yHGd6AHr3uInSu+xtBgnlU+6iIj+Bn?= =?us-ascii?Q?024pjPwcy+n+LXYnZ4wKqlaQpTFVBZxZ5JkZskqsLwJayA7gkkGNRL1sywEK?= =?us-ascii?Q?XUaipa9ol7gzrJlg/2d7TOZwHisGG1J5atpTYE+ZZB0jKFIVWqRSSc413X1X?= =?us-ascii?Q?8pMdHn+bPGflov/2KuQQ98Ej/6aMJ7Rg03SgOD7yJ5G/wKCrYMP/RaNqBWlL?= =?us-ascii?Q?h2Hfoncbq87r+EwhCGslYQvvVgax8wNaSMrhMc+fnexrAsPR0FB8QKCiEbU/?= =?us-ascii?Q?s5tagqssqVxcc+3mMLcGEXdh8H6/IkrCp4uyWqwBPU7439I6cAWY2sZylTv2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d78rEf3o+Ewl/5iK13thLEMH0wAwqkdxcgbdo7RB6byBT06JGws7GuiEyZrpW622y4QrVmK5ImpUWQVjRC4OJ4QVSNxK/TcSbfk=; 7:k7kITcH9VTK2GfXpr6ainNh7H1Se31ROh/6xTf6EvvlXZX+liLKJzZg5y6mFqjVqcIIhCz20EpcpR9Tri6C8xWfXEcWPa4ykXWFdGyJWHTnhSYiP0HOIIVFIhB6i5Pn5pmgW7Wn29jM1A2T9xO8SWbzTHVYX2xfHRP8KBMuhApT634RKbxecD8SjL1JEZMCK4Y2EPCIT7uS2M4TLdnNpr8zPqzQusW24AN0LHYH+aj6UOvZlEDSsfUNJOWDyLkPC SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2016 10:09:16.1048 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN3PR03MB2401 Cc: trini@konsulko.com, sjg@google.com, ruchika.gupta@nxp.com Subject: [U-Boot] [PATCH 1/3] powerpc/mpc85xx: SECURE BOOT- Enable chain of trust in SPL X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" As part of Chain of Trust for Secure boot, the SPL U-Boot will validate the next level U-boot image. Add a new function spl_validate_uboot to perform the validation. Enable hardware crypto operations in SPL using SEC block. In case of Secure Boot, PAMU is not bypassed. For allowing SEC block access to CPC configured as SRAM, configure PAMU. Reviewed-by: Ruchika Gupta Signed-off-by: Aneesh Bansal Signed-off-by: Sumit Garg Reviewed-by: Simon Glass --- Changes PATCH v5->PATCH v6: Incorporated review comments regarding comment style. Changes PATCH v4->PATCH v5: Check for def CONFIG_SPL_DM and ndef CONFIG_SPL_FRAMEWORK instead of def CONFIG_DM macro to include call to dm_init_and_scan(). As dm_init_and_scan() is called as part of common SPL framework, so no need to call it again but in case of powerpc platforms which currently do not use common SPL framework, so need to include this function call here. Changes PATCH v3->PATCH v4: Generic changes in lib, drivers, common Makefiles removed from this patchset. Rebased this patchset on top of patch [1], so this patchset is dependent on patch [1]. Changes PATCH v2->PATCH v3: Patches rebased Changes PATCH->PATCH v2: Patches rebased [1]https://patchwork.ozlabs.org/patch/627664/ arch/powerpc/cpu/mpc8xxx/fsl_pamu.c | 8 +++++ arch/powerpc/cpu/mpc8xxx/pamu_table.c | 8 +++++ arch/powerpc/include/asm/fsl_secure_boot.h | 31 +++++++++++++++- board/freescale/common/fsl_chain_of_trust.c | 56 +++++++++++++++++++++++++++++ drivers/crypto/fsl/jr.c | 17 +++++++++ drivers/mtd/nand/fsl_ifc_spl.c | 24 +++++++++++++ include/fsl_validate.h | 7 ++++ 7 files changed, 150 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/cpu/mpc8xxx/fsl_pamu.c b/arch/powerpc/cpu/mpc8xxx/fsl_pamu.c index 9421f1e..ede8e66 100644 --- a/arch/powerpc/cpu/mpc8xxx/fsl_pamu.c +++ b/arch/powerpc/cpu/mpc8xxx/fsl_pamu.c @@ -239,15 +239,23 @@ int pamu_init(void) spaact_size = sizeof(struct paace) * NUM_SPAACT_ENTRIES; /* Allocate space for Primary PAACT Table */ +#if (defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_PPAACT_ADDR)) + ppaact = (void *)CONFIG_SPL_PPAACT_ADDR; +#else ppaact = memalign(PAMU_TABLE_ALIGNMENT, ppaact_size); if (!ppaact) return -1; +#endif memset(ppaact, 0, ppaact_size); /* Allocate space for Secondary PAACT Table */ +#if (defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_SPAACT_ADDR)) + sec = (void *)CONFIG_SPL_SPAACT_ADDR; +#else sec = memalign(PAMU_TABLE_ALIGNMENT, spaact_size); if (!sec) return -1; +#endif memset(sec, 0, spaact_size); ppaact_phys = virt_to_phys((void *)ppaact); diff --git a/arch/powerpc/cpu/mpc8xxx/pamu_table.c b/arch/powerpc/cpu/mpc8xxx/pamu_table.c index 26c5ea4..a8e6f51 100644 --- a/arch/powerpc/cpu/mpc8xxx/pamu_table.c +++ b/arch/powerpc/cpu/mpc8xxx/pamu_table.c @@ -28,6 +28,14 @@ void construct_pamu_addr_table(struct pamu_addr_tbl *tbl, int *num_entries) i++; #endif +#if (defined(CONFIG_SPL_BUILD) && (CONFIG_SYS_INIT_L3_VADDR)) + tbl->start_addr[i] = + (uint64_t)virt_to_phys((void *)CONFIG_SYS_INIT_L3_VADDR); + tbl->size[i] = 256 * 1024; /* 256K CPC flash */ + tbl->end_addr[i] = tbl->start_addr[i] + tbl->size[i] - 1; + + i++; +#endif debug("PAMU address\t\t\tsize\n"); for (j = 0; j < i ; j++) debug("%llx \t\t\t%llx\n", tbl->start_addr[j], tbl->size[j]); diff --git a/arch/powerpc/include/asm/fsl_secure_boot.h b/arch/powerpc/include/asm/fsl_secure_boot.h index 826f9c9..9420021 100644 --- a/arch/powerpc/include/asm/fsl_secure_boot.h +++ b/arch/powerpc/include/asm/fsl_secure_boot.h @@ -72,6 +72,32 @@ #ifdef CONFIG_CHAIN_OF_TRUST +#ifdef CONFIG_SPL_BUILD +#define CONFIG_SPL_DM 1 +#define CONFIG_SPL_CRYPTO_SUPPORT +#define CONFIG_SPL_HASH_SUPPORT +#define CONFIG_SPL_RSA +#define CONFIG_SPL_DRIVERS_MISC_SUPPORT +/* + * PPAACT and SPAACT table for PAMU must be placed on DDR after DDR init + * due to space crunch on CPC and thus malloc will not work. + */ +#define CONFIG_SPL_PPAACT_ADDR 0x2e000000 +#define CONFIG_SPL_SPAACT_ADDR 0x2f000000 +#define CONFIG_SPL_JR0_LIODN_S 454 +#define CONFIG_SPL_JR0_LIODN_NS 458 +/* + * Define the key hash for U-Boot here if public/private key pair used to + * sign U-boot are different from the SRK hash put in the fuse + * Example of defining KEY_HASH is + * #define CONFIG_SPL_UBOOT_KEY_HASH \ + * "41066b564c6ffcef40ccbc1e0a5d0d519604000c785d97bbefd25e4d288d1c8b" + * else leave it defined as NULL + */ + +#define CONFIG_SPL_UBOOT_KEY_HASH NULL +#endif /* ifdef CONFIG_SPL_BUILD */ + #define CONFIG_CMD_ESBC_VALIDATE #define CONFIG_CMD_BLOB #define CONFIG_FSL_SEC_MON @@ -82,7 +108,9 @@ #define CONFIG_FSL_CAAM #endif -/* fsl_setenv_chain_of_trust() must be called from +#ifndef CONFIG_SPL_BUILD +/* + * fsl_setenv_chain_of_trust() must be called from * board_late_init() */ #ifndef CONFIG_BOARD_LATE_INIT @@ -119,5 +147,6 @@ #endif /* #ifdef CONFIG_BOOTSCRIPT_COPY_RAM */ #include +#endif /* #ifndef CONFIG_SPL_BUILD */ #endif /* #ifdef CONFIG_CHAIN_OF_TRUST */ #endif diff --git a/board/freescale/common/fsl_chain_of_trust.c b/board/freescale/common/fsl_chain_of_trust.c index ecfcc82..290536d 100644 --- a/board/freescale/common/fsl_chain_of_trust.c +++ b/board/freescale/common/fsl_chain_of_trust.c @@ -6,7 +6,17 @@ #include #include +#include #include +#include + +#ifdef CONFIG_ADDR_MAP +#include +#endif + +#ifdef CONFIG_FSL_CORENET +#include +#endif #ifdef CONFIG_LS102XA #include @@ -52,6 +62,7 @@ int fsl_check_boot_mode_secure(void) return 0; } +#ifndef CONFIG_SPL_BUILD int fsl_setenv_chain_of_trust(void) { /* Check Boot Mode @@ -68,3 +79,48 @@ int fsl_setenv_chain_of_trust(void) setenv("bootcmd", CONFIG_CHAIN_BOOT_CMD); return 0; } +#endif + +#ifdef CONFIG_SPL_BUILD +void spl_validate_uboot(uint32_t hdr_addr, uintptr_t img_addr) +{ + int res; + + /* + * Check Boot Mode + * If Boot Mode is Non-Secure, skip validation + */ + if (fsl_check_boot_mode_secure() == 0) + return; + + printf("SPL: Validating U-Boot image\n"); + +#ifdef CONFIG_ADDR_MAP + init_addr_map(); +#endif + +#ifdef CONFIG_FSL_CORENET + if (pamu_init() < 0) + fsl_secboot_handle_error(ERROR_ESBC_PAMU_INIT); +#endif + +#ifdef CONFIG_FSL_CAAM + if (sec_init() < 0) + fsl_secboot_handle_error(ERROR_ESBC_SEC_INIT); +#endif + +/* + * dm_init_and_scan() is called as part of common SPL framework, so no + * need to call it again but in case of powerpc platforms which currently + * do not use common SPL framework, so need to call this function here. + */ +#if defined(CONFIG_SPL_DM) && (!defined(CONFIG_SPL_FRAMEWORK)) + dm_init_and_scan(false); +#endif + res = fsl_secboot_validate(hdr_addr, CONFIG_SPL_UBOOT_KEY_HASH, + &img_addr); + + if (res == 0) + printf("SPL: Validation of U-boot successful\n"); +} +#endif /* ifdef CONFIG_SPL_BUILD */ diff --git a/drivers/crypto/fsl/jr.c b/drivers/crypto/fsl/jr.c index 510fa4e..4a8cc32 100644 --- a/drivers/crypto/fsl/jr.c +++ b/drivers/crypto/fsl/jr.c @@ -599,10 +599,27 @@ int sec_init_idx(uint8_t sec_idx) sec_out32(&sec->mcfgr, mcr); #ifdef CONFIG_FSL_CORENET +#ifdef CONFIG_SPL_BUILD + /* + * For SPL Build, Set the Liodns in SEC JR0 for + * creating PAMU entries corresponding to these. + * For normal build, these are set in set_liodns(). + */ + liodn_ns = CONFIG_SPL_JR0_LIODN_NS & JRNSLIODN_MASK; + liodn_s = CONFIG_SPL_JR0_LIODN_S & JRSLIODN_MASK; + + liodnr = sec_in32(&sec->jrliodnr[0].ls) & + ~(JRNSLIODN_MASK | JRSLIODN_MASK); + liodnr = liodnr | + (liodn_ns << JRNSLIODN_SHIFT) | + (liodn_s << JRSLIODN_SHIFT); + sec_out32(&sec->jrliodnr[0].ls, liodnr); +#else liodnr = sec_in32(&sec->jrliodnr[0].ls); liodn_ns = (liodnr & JRNSLIODN_MASK) >> JRNSLIODN_SHIFT; liodn_s = (liodnr & JRSLIODN_MASK) >> JRSLIODN_SHIFT; #endif +#endif ret = jr_init(sec_idx); if (ret < 0) { diff --git a/drivers/mtd/nand/fsl_ifc_spl.c b/drivers/mtd/nand/fsl_ifc_spl.c index cbeb74a..4e49a4e 100644 --- a/drivers/mtd/nand/fsl_ifc_spl.c +++ b/drivers/mtd/nand/fsl_ifc_spl.c @@ -11,6 +11,9 @@ #include #include #include +#ifdef CONFIG_CHAIN_OF_TRUST +#include +#endif static inline int is_blank(uchar *addr, int page_size) { @@ -268,6 +271,27 @@ void nand_boot(void) */ flush_cache(CONFIG_SYS_NAND_U_BOOT_DST, CONFIG_SYS_NAND_U_BOOT_SIZE); #endif + +#ifdef CONFIG_CHAIN_OF_TRUST + /* + * U-Boot header is appended at end of U-boot image, so + * calculate U-boot header address using U-boot header size. + */ +#define CONFIG_U_BOOT_HDR_ADDR \ + ((CONFIG_SYS_NAND_U_BOOT_START + \ + CONFIG_SYS_NAND_U_BOOT_SIZE) - \ + CONFIG_U_BOOT_HDR_SIZE) + spl_validate_uboot(CONFIG_U_BOOT_HDR_ADDR, + CONFIG_SYS_NAND_U_BOOT_START); + /* + * In case of failure in validation, spl_validate_uboot would + * not return back in case of Production environment with ITS=1. + * Thus U-Boot will not start. + * In Development environment (ITS=0 and SB_EN=1), the function + * may return back in case of non-fatal failures. + */ +#endif + uboot = (void *)CONFIG_SYS_NAND_U_BOOT_START; uboot(); } diff --git a/include/fsl_validate.h b/include/fsl_validate.h index a71e1ce..c350938 100644 --- a/include/fsl_validate.h +++ b/include/fsl_validate.h @@ -254,4 +254,11 @@ int fsl_secboot_blob_decap(cmd_tbl_t *cmdtp, int flag, int argc, int fsl_check_boot_mode_secure(void); int fsl_setenv_chain_of_trust(void); + +/* + * This function is used to validate the main U-boot binary from + * SPL just before passing control to it using QorIQ Trust + * Architecture header (appended to U-boot image). + */ +void spl_validate_uboot(uint32_t hdr_addr, uintptr_t img_addr); #endif