Add an helper to revoke an i.MX SRK key. At the moment the helper supprts i.MX8M devices only, but adding support for other SoCs can be done easily by providing the .revoke_key() hook. Signed-off-by: Marco Felsch <m.felsch@xxxxxxxxxxxxxx> --- drivers/hab/hab.c | 45 ++++++++++++++++++++++++++++++++ include/hab.h | 6 +++++ include/mach/imx/ocotp-fusemap.h | 1 + 3 files changed, 52 insertions(+) diff --git a/drivers/hab/hab.c b/drivers/hab/hab.c index 28a091841a69..e21a3c3acf81 100644 --- a/drivers/hab/hab.c +++ b/drivers/hab/hab.c @@ -231,6 +231,27 @@ static int imx8m_hab_device_locked_down_ocotp(void) return v; } +static int imx8m_hab_revoke_key_ocotp(unsigned key_idx) +{ + int ret; + + /* Prohibit revocation of last possible key */ + if (key_idx >= 4) + return -EINVAL; + + ret = imx_ocotp_srk_revoke_locked(); + if (ret < 0) + return ret; + + /* Return -EINVAL in case the SRK_REVOKE write is locked */ + if (ret == 1) + return -EINVAL; + + ret = imx_ocotp_write_field(MX8M_OCOTP_SRK_REVOKE, BIT(key_idx)); + + return ret; +} + struct imx_hab_ops { int (*write_srk_hash)(const u8 *srk, unsigned flags); int (*read_srk_hash)(u8 *srk); @@ -238,6 +259,7 @@ struct imx_hab_ops { int (*lockdown_device)(unsigned flags); int (*device_locked_down)(void); int (*print_status)(void); + int (*revoke_key)(unsigned key_idx); }; static struct imx_hab_ops imx_hab_ops_iim = { @@ -265,6 +287,7 @@ static struct imx_hab_ops imx8m_hab_ops_ocotp = { .device_locked_down = imx8m_hab_device_locked_down_ocotp, .permanent_write_enable = imx_hab_permanent_write_enable_ocotp, .print_status = imx8m_hab_print_status, + .revoke_key = imx8m_hab_revoke_key_ocotp, }; static int imx_ahab_write_srk_hash(const u8 *__newsrk, unsigned flags) @@ -536,3 +559,25 @@ static int init_imx_hab_print_status(void) return 0; } postmmu_initcall(init_imx_hab_print_status); + +int imx_hab_revoke_key(unsigned key_idx, unsigned flags) +{ + struct imx_hab_ops *ops = imx_get_hab_ops(); + int ret; + + if (!ops || !ops->revoke_key) + return -ENOSYS; + + if (flags & IMX_SRK_REVOKE_KEY_PERMANENT) { + ret = ops->permanent_write_enable(1); + if (ret) + return ret; + } + + ret = ops->revoke_key(key_idx); + + if (flags & IMX_SRK_REVOKE_KEY_PERMANENT) + ops->permanent_write_enable(0); + + return ret; +} diff --git a/include/hab.h b/include/hab.h index 2cef3841d149..fd32bff15ef8 100644 --- a/include/hab.h +++ b/include/hab.h @@ -42,6 +42,11 @@ static inline int habv4_get_state(void) * fuses so that the key hash can not be modified. */ #define IMX_SRK_HASH_WRITE_LOCK BIT(2) +/* + * Revoke the SRK key permanently, without the flag only shadow registers are + * written. + */ +#define IMX_SRK_REVOKE_KEY_PERMANENT BIT(3) bool imx_hab_srk_hash_valid(const void *buf); int imx_hab_write_srk_hash(const void *buf, unsigned flags); @@ -51,5 +56,6 @@ int imx_hab_read_srk_hash(void *buf); int imx_hab_lockdown_device(unsigned flags); int imx_hab_device_locked_down(void); int imx_hab_print_status(void); +int imx_hab_revoke_key(unsigned key_idx, unsigned flags); #endif /* __HABV4_H */ diff --git a/include/mach/imx/ocotp-fusemap.h b/include/mach/imx/ocotp-fusemap.h index c4f94e61e8f8..e6fa96b40ba9 100644 --- a/include/mach/imx/ocotp-fusemap.h +++ b/include/mach/imx/ocotp-fusemap.h @@ -57,5 +57,6 @@ #define MX8M_OCOTP_SRK_LOCK (OCOTP_WORD(0x400) | OCOTP_BIT(9) | OCOTP_WIDTH(1)) #define MX8M_OCOTP_SEC_CONFIG_1 (OCOTP_WORD(0x470) | OCOTP_BIT(25) | OCOTP_WIDTH(1)) #define MX8MQ_OCOTP_DIR_BT_DIS (OCOTP_WORD(0x470) | OCOTP_BIT(27) | OCOTP_WIDTH(1)) +#define MX8M_OCOTP_SRK_REVOKE (OCOTP_WORD(0x670) | OCOTP_BIT(0) | OCOTP_WIDTH(4)) #endif /* __MACH_IMX_OCOTP_FUSEMAP_H */ -- 2.39.2