powerpc/mpc85xx: SECURE BOOT- Enable chain of trust in SPL
Subsystems (4)
PATCH v4 1/2 powerpc/mpc85xx: SECURE BOOT- Enable chain of trust in SPL
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.
---
Changes in v2:
Patches rebased
Changes in v3:
Patches rebased
Changes in 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].
[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 | 28 ++++++++++++++++ board/freescale/common/fsl_chain_of_trust.c | 50 +++++++++++++++++++++++++++++ drivers/crypto/fsl/jr.c | 16 +++++++++ drivers/mtd/nand/fsl_ifc_spl.c | 24 ++++++++++++++ include/fsl_validate.h | 1 + 7 files changed, 135 insertions(+)
arch/powerpc/cpu/mpc8xxx/fsl_pamu.c +8 -0
@@ -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);
arch/powerpc/cpu/mpc8xxx/pamu_table.c +8 -0
@@ -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]);
arch/powerpc/include/asm/fsl_secure_boot.h +28 -0
@@ -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,6 +108,7 @@#define CONFIG_FSL_CAAM #endif +#ifndef CONFIG_SPL_BUILD /* fsl_setenv_chain_of_trust() must be called from * board_late_init() */
@@ -119,5 +146,6 @@#endif /* #ifdef CONFIG_BOOTSCRIPT_COPY_RAM */ #include <config_fsl_chain_trust.h> +#endif /* #ifndef CONFIG_SPL_BUILD */ #endif /* #ifdef CONFIG_CHAIN_OF_TRUST */ #endif
board/freescale/common/fsl_chain_of_trust.c +50 -0
66 lines not on this page · raw message
drivers/crypto/fsl/jr.c +16 -0
@@ -599,10 +599,26 @@ 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 ) {
drivers/mtd/nand/fsl_ifc_spl.c +24 -0
@@ -11,6 +11,9 @@#include <asm/io.h> #include <fsl_ifc.h> #include <linux/mtd/nand.h> +#ifdef CONFIG_CHAIN_OF_TRUST +#include <fsl_validate.h> +#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 +/* +* As 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 (); }
include/fsl_validate.h +1 -0
@@ -254,4 +254,5 @@ 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 ); +void spl_validate_uboot (uint32_t hdr_addr,uintptr_t img_addr);#endif
Signature · 1 line
1.8.1.4
PATCH v4 1/2 powerpc/mpc85xx: SECURE BOOT- Enable chain of trust in SPL
Hi Sumit,
Quoted 3 lines · Sumit Garg
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_ubootto perform the validation.
I noticed your patch series just now and I certainly don't want to derail what you are trying to do here but I wanted to see what you think about something that's pretty much related.
In order to be more flexible in how we go from SPL to U-Boot (we have a need to inject ROM-API calls for decryption in addition to authentication) I've been experimenting with a method that basically injects a generic post-process function call into spl_load_simple_fit() that the platform-specific layer can provide/override. This function will basically get invoked on the U-Boot firmware itself as well as for the selected DTB after it gets loaded, allowing to do things like custom authentication and/or decryption through plugging in for example our ROM API calls. But this should also be a starting point for someone to plug in the U-Boot RSA libraries directly in a way that doesn't require using CONFIG_SPL_DM (for memory-constrained devices).
So mostly I wanted to see if this is something that could be useful for you as well, and any comments/concerns you may have on that.
Thanks and Regards,
--
Andreas Dannenberg
Texas Instruments Inc
Quoted 288 lines
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 <[email protected]>Signed-off-by Aneesh Bansal <[email protected]>Signed-off-by Sumit Garg <[email protected]>---
Changes in v2:
Patches rebasedChanges in v3:
Patches rebasedChanges in 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].[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 | 28 ++++++++++++++++ board/freescale/common/fsl_chain_of_trust.c | 50 +++++++++++++++++++++++++++++ drivers/crypto/fsl/jr.c | 16 +++++++++ drivers/mtd/nand/fsl_ifc_spl.c | 24 ++++++++++++++ include/fsl_validate.h | 1 + 7 files changed, 135 insertions(+)arch/powerpc/cpu/mpc8xxx/fsl_pamu.c +8
-0@@ -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);arch/powerpc/cpu/mpc8xxx/pamu_table.c +8
-0@@ -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]);arch/powerpc/include/asm/fsl_secure_boot.h +28
-0@@ -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,6 +108,7 @@#define CONFIG_FSL_CAAM #endif +#ifndef CONFIG_SPL_BUILD /* fsl_setenv_chain_of_trust() must be called from * board_late_init() */ @@ -119,5 +146,6 @@#endif /* #ifdef CONFIG_BOOTSCRIPT_COPY_RAM */ #include <config_fsl_chain_trust.h> +#endif /* #ifndef CONFIG_SPL_BUILD */ #endif /* #ifdef CONFIG_CHAIN_OF_TRUST */ #endif board/freescale/common/fsl_chain_of_trust.c +50
-0@@ -6,7 +6,17 @@#include <common.h> #include <fsl_validate.h> +#include <fsl_secboot_err.h> #include <fsl_sfp.h> +#include <dm/root.h> + +#ifdef CONFIG_ADDR_MAP +#include <asm/mmu.h> +#endif + +#ifdef CONFIG_FSL_CORENET +#include <asm/fsl_pamu.h> +#endif #ifdef CONFIG_LS102XA #include <asm/arch/immap_ls102xa.h> @@ -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,42 @@ 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 + +#if defined(CONFIG_DM ) +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 drivers/crypto/fsl/jr.c +16
-0@@ -599,10 +599,26 @@ 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 ) {drivers/mtd/nand/fsl_ifc_spl.c +24
-0@@ -11,6 +11,9 @@#include <asm/io.h> #include <fsl_ifc.h> #include <linux/mtd/nand.h> +#ifdef CONFIG_CHAIN_OF_TRUST +#include <fsl_validate.h> +#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 +/* +* As 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 (); }include/fsl_validate.h +1
-0@@ -254,4 +254,5 @@ 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 ); +void spl_validate_uboot (uint32_t hdr_addr,uintptr_t img_addr);#endif Signature · 1 line
1.8.1.4
PATCH v4 1/2 powerpc/mpc85xx: SECURE BOOT- Enable chain of trust in SPL
Hi,
Quoted 219 lines · Andreas Dannenberg
Hi Sumit,
Quoted 3 lines · Sumit Garg
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_ubootto perform the validation.I noticed your patch series just now and I certainly don't want to derail what you are trying to do here but I wanted to see what you think about something that's pretty much related.
In order to be more flexible in how we go from SPL to U-Boot (we have a need to inject ROM-API calls for decryption in addition to authentication) I've been experimenting with a method that basically injects a generic post-process function call into
spl_load_simple_fit()that the platform-specific layer can provide/override. This function will basically get invoked on the U-Boot firmware itself as well as for the selected DTB after it gets loaded, allowing to do things like custom authentication and/or decryption through plugging in for example our ROM API calls. But this should also be a starting point for someone to plug in the U-Boot RSA libraries directly in a way that doesn't require usingCONFIG_SPL_DM(for memory-constrained devices).So mostly I wanted to see if this is something that could be useful for you as well, and any comments/concerns you may have on that.
Thanks and Regards,
--
Andreas Dannenberg
Texas Instruments IncQuoted 186 lines
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 <[email protected]>Signed-off-by Aneesh Bansal <[email protected]>Signed-off-by Sumit Garg <[email protected]>---
Changes in v2:
Patches rebasedChanges in v3:
Patches rebasedChanges in 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].[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 | 28 ++++++++++++++++ board/freescale/common/fsl_chain_of_trust.c | 50 +++++++++++++++++++++++++++++ drivers/crypto/fsl/jr.c | 16 +++++++++ drivers/mtd/nand/fsl_ifc_spl.c | 24 ++++++++++++++ include/fsl_validate.h | 1 + 7 files changed, 135 insertions(+)arch/powerpc/cpu/mpc8xxx/fsl_pamu.c +8
-0@@ -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);arch/powerpc/cpu/mpc8xxx/pamu_table.c +8
-0@@ -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]);arch/powerpc/include/asm/fsl_secure_boot.h +28
-0@@ -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,6 +108,7 @@#define CONFIG_FSL_CAAM #endif +#ifndef CONFIG_SPL_BUILD /* fsl_setenv_chain_of_trust() must be called from * board_late_init() */ @@ -119,5 +146,6 @@#endif /* #ifdef CONFIG_BOOTSCRIPT_COPY_RAM */ #include <config_fsl_chain_trust.h> +#endif /* #ifndef CONFIG_SPL_BUILD */ #endif /* #ifdef CONFIG_CHAIN_OF_TRUST */ #endif board/freescale/common/fsl_chain_of_trust.c +34
-0@@ -6,7 +6,17 @@#include <common.h> #include <fsl_validate.h> +#include <fsl_secboot_err.h> #include <fsl_sfp.h> +#include <dm/root.h> + +#ifdef CONFIG_ADDR_MAP +#include <asm/mmu.h> +#endif + +#ifdef CONFIG_FSL_CORENET +#include <asm/fsl_pamu.h> +#endif #ifdef CONFIG_LS102XA #include <asm/arch/immap_ls102xa.h> @@ -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,42 @@ 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
Quoted 8 lines
board/freescale/common/fsl_chain_of_trust.c int fsl_setenv_chain_of_trust(void) · line 112
Quoted 8 lines
board/freescale/common/fsl_chain_of_trust.c +8
-0+ +#ifdef CONFIG_FSL_CAAM +if (sec_init () <0 ) +fsl_secboot_handle_error (ERROR_ESBC_SEC_INIT ); +#endif + +#if defined(CONFIG_DM ) +dm_init_and_scan (false);
Eek, this is duplicating code and adding a board-specific hack. I agree that it would be better to use SPL FIT to handle this.
Quoted 87 lines
Quoted 87 lines
board/freescale/common/fsl_chain_of_trust.c +8
-0+#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 drivers/crypto/fsl/jr.c +16
-0@@ -599,10 +599,26 @@ 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 ) {drivers/mtd/nand/fsl_ifc_spl.c +24
-0@@ -11,6 +11,9 @@#include <asm/io.h> #include <fsl_ifc.h> #include <linux/mtd/nand.h> +#ifdef CONFIG_CHAIN_OF_TRUST +#include <fsl_validate.h> +#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 +/* +* As 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 (); }include/fsl_validate.h +0
-0@@ -254,4 +254,5 @@ int fsl_secboot_blob_decap(cmd_tbl_t *cmdtp, int flag, int argc,
Quoted 7 lines
Quoted 7 lines
include/fsl_validate.h +1
-1int fsl_check_boot_mode_secure (void );int fsl_setenv_chain_of_trust (void ); +void spl_validate_uboot (uint32_t hdr_addr,uintptr_t img_addr);#endif --1.8.1.4
Regards,
Simon
PATCH v4 1/2 powerpc/mpc85xx: SECURE BOOT- Enable chain of trust in SPL
Hi Andreas, Simon,
Quoted 37 lines
-----Original Message-----
From: sjg at google.com [mailto:sjg at google.com] On Behalf Of Simon Glass
Sent: Friday, June 10, 2016 6:05 AM
To: Andreas Dannenberg <[email protected]>
Cc: Sumit Garg <[email protected]>; U-Boot Mailing List <u- boot at lists.denx.de>; york sun <[email protected]>; Ruchika Gupta <[email protected]>; Prabhakar Kushwaha <[email protected]>; Teddy Reed V <[email protected]>; Aneesh Bansal <[email protected]>
Subject: Re: [PATCH v4 1/2] powerpc/mpc85xx: SECURE BOOT- Enable chain of trust in SPLHi,
Quoted 11 lines · Andreas Dannenberg
Hi Sumit,
Quoted 3 lines · Sumit Garg
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_ubootto perform the validation.I noticed your patch series just now and I certainly don't want to derail what you are trying to do here but I wanted to see what you think about something that's pretty much related.
Quoted 11 lines
In order to be more flexible in how we go from SPL to U-Boot (we have a need to inject ROM-API calls for decryption in addition to authentication) I've been experimenting with a method that basically injects a generic post-process function call into
spl_load_simple_fit()that the platform-specific layer can provide/override. This function will basically get invoked on the U-Boot firmware itself as well as for the selected DTB after it gets loaded, allowing to do things like custom authentication and/or decryption through plugging in for example our ROM API calls. But this should also be a starting point for someone to plug in the U-Boot RSA libraries directly in a way that doesn't require usingCONFIG_SPL_DM(for
Quoted 1 line
memory-constrained devices).
It?s a good idea to plug ROM API calls for decryption and authentication in U-boot firmware. I think your main concern is DM framework in SPL for memory constrained devices. But for our platforms memory constraint is not a barrier in this case, so for time being we could use CONFIG_SPL_DM. So if you come up with framework to add U-Boot RSA libraries without using DM in SPL, we could enable it on our platforms too.
Quoted 208 lines
Quoted 36 lines
So mostly I wanted to see if this is something that could be useful for you as well, and any comments/concerns you may have on that.
Thanks and Regards,
--
Andreas Dannenberg
Texas Instruments IncQuoted 25 lines
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 <[email protected]>Signed-off-by Aneesh Bansal <[email protected]>Signed-off-by Sumit Garg <[email protected]>---
Changes in v2:
Patches rebasedChanges in v3:
Patches rebasedChanges in 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].[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 | 28 ++++++++++++++++
board/freescale/common/fsl_chain_of_trust.c| 50+++++++++++++++++++++++++++++
Quoted 13 lines
Quoted 13 lines
drivers/crypto/fsl/jr.c | 16 +++++++++ drivers/mtd/nand/fsl_ifc_spl.c | 24 ++++++++++++++ include/fsl_validate.h | 1 + 7 files changed, 135 insertions(+)arch/powerpc/cpu/mpc8xxx/fsl_pamu.c +0
-0@@ -239,15 +239,23 @@ int pamu_init(void) spaact_size =sizeof (struct paace ) *NUM_SPAACT_ENTRIES ;Quoted 2 lines
arch/powerpc/cpu/mpc8xxx/fsl_pamu.c int pamu_init(void) · line 242
Quoted 2 lines
arch/powerpc/cpu/mpc8xxx/fsl_pamu.c +1
-0/* Allocate space for Primary PAACT Table */ +#if (defined(CONFIG_SPL_BUILD) &&
defined(CONFIG_SPL_PPAACT_ADDR))Quoted 9 lines
arch/powerpc/cpu/mpc8xxx/fsl_pamu.c int pamu_init(void)
Quoted 9 lines
arch/powerpc/cpu/mpc8xxx/fsl_pamu.c +3
-0+ 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))Quoted 53 lines
Quoted 53 lines
arch/powerpc/cpu/mpc8xxx/fsl_pamu.c +2
-0+ 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.cb/arch/powerpc/cpu/mpc8xxx/pamu_table.c
index 26c5ea4..a8e6f51 100644arch/powerpc/cpu/mpc8xxx/pamu_table.c +8
-0@@ -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.hb/arch/powerpc/include/asm/fsl_secure_boot.h
index 826f9c9..99eec7f 100644arch/powerpc/include/asm/fsl_secure_boot.h +14
-0@@ -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 454Quoted 8 lines
arch/powerpc/include/asm/fsl_secure_boot.h
Quoted 8 lines
arch/powerpc/include/asm/fsl_secure_boot.h +8
-0+#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"Quoted 83 lines
Quoted 83 lines
arch/powerpc/include/asm/fsl_secure_boot.h +8
-0+* 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,6 +108,7 @@#define CONFIG_FSL_CAAM #endif +#ifndef CONFIG_SPL_BUILD /* fsl_setenv_chain_of_trust() must be called from * board_late_init() */ @@ -119,5 +146,6 @@#endif /* #ifdef CONFIG_BOOTSCRIPT_COPY_RAM */ #include <config_fsl_chain_trust.h> +#endif /* #ifndef CONFIG_SPL_BUILD */ #endif /* #ifdef CONFIG_CHAIN_OF_TRUST */ #endif diff --git
a/board/freescale/common/fsl_chain_of_trust.cb/board/freescale/common/fsl_chain_of_trust.c
index ecfcc82..992babf 100644board/freescale/common/fsl_chain_of_trust.c +36
-0@@ -6,7 +6,17 @@#include <common.h> #include <fsl_validate.h> +#include <fsl_secboot_err.h> #include <fsl_sfp.h> +#include <dm/root.h> + +#ifdef CONFIG_ADDR_MAP +#include <asm/mmu.h> +#endif + +#ifdef CONFIG_FSL_CORENET +#include <asm/fsl_pamu.h> +#endif #ifdef CONFIG_LS102XA #include <asm/arch/immap_ls102xa.h> @@ -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,42 @@ 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 )
Quoted 8 lines
Quoted 5 lines
board/freescale/common/fsl_chain_of_trust.c int fsl_setenv_chain_of_trust(void) · line 112
Quoted 5 lines
board/freescale/common/fsl_chain_of_trust.c +5
-0+fsl_secboot_handle_error (ERROR_ESBC_SEC_INIT ); +#endif + +#if defined(CONFIG_DM ) +dm_init_and_scan (false);Eek, this is duplicating code and adding a board-specific hack. I agree that it would be better to use SPL FIT to handle this.
Currently our powerpc based platforms do not use generic SPL framework but uses board specific SPL framework (/board/freescale/<platform>/spl.c) and do not use DM in SPL either. So to include RSA library I called it here once rather than calling in every board specific file.
Yeah you are correct I should use CONFIG_SPL_DM here instead of CONFIG_DM.
Quoted 95 lines
Quoted 49 lines
Quoted 49 lines
board/freescale/common/fsl_chain_of_trust.c +7
-0+#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 drivers/crypto/fsl/jr.c index renamed from drivers/crypto/fsl/jr.c +0
-0510fa4e..1d4dd32 100644
drivers/crypto/fsl/jr.c +15
-0@@ -599,10 +599,26 @@ 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 ) {drivers/mtd/nand/fsl_ifc_spl.c +3
-0@@ -11,6 +11,9 @@#include <asm/io.h> #include <fsl_ifc.h> #include <linux/mtd/nand.h> +#ifdef CONFIG_CHAIN_OF_TRUST +#include <fsl_validate.h> +#endif Quoted 5 lines
drivers/mtd/nand/fsl_ifc_spl.c void nand_boot(void) · line 272
Quoted 5 lines
drivers/mtd/nand/fsl_ifc_spl.c +0
-0static 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);Quoted 22 lines
Quoted 22 lines
drivers/mtd/nand/fsl_ifc_spl.c +21
-0#endif + +#ifdef CONFIG_CHAIN_OF_TRUST +/* +* As 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 +Quoted 8 lines
include/fsl_validate.h int fsl_secboot_blob_decap(cmd_tbl_t *cmdtp, int
Quoted 8 lines
drivers/mtd/nand/fsl_ifc_spl.c +0
-0uboot = (void *)CONFIG_SYS_NAND_U_BOOT_START ;uboot (); }include/fsl_validate.h +0
-0@@ -254,4 +254,5 @@ int fsl_secboot_blob_decap(cmd_tbl_t *cmdtp, intflag, int argc,
Quoted 8 lines
Quoted 8 lines
include/fsl_validate.h +1
-1int fsl_check_boot_mode_secure (void );int fsl_setenv_chain_of_trust (void ); +void spl_validate_uboot (uint32_t hdr_addr,uintptr_t img_addr);#endif --1.8.1.4
Quoted 2 lines
Regards,
Simon
Regards,
Sumit