imx: deal with the RNG self test of the i.MX6 boot ROM
Subsystems (4)
v2 cover imx: deal with the RNG self test of the i.MX6 boot ROM
The boot ROM of a few i.MX6 revisions runs its RNG self test incorrectly, which leaves a HAB warning behind on every boot and says nothing about the state of the RNG.
The first patch runs the test correctly, before anything else uses the RNG. The second one makes hab_status name the leftover event, so that the warning stops sending people looking for a fault in their own image.
Azure build is (now really) fine:
https://dev.azure.com/hs0298/hs/_build/results?buildId=215&view=results
Changes in v2:
- Dropped Gaurav Jain <[email protected]> from Cc. The address bounced on v1 with "550 5.4.1 Recipient address rejected: Access denied". His Signed-off-by stays, it records where the code comes from.
- Disabled the option in imx6dl_mamoj_defconfig. Enabling it by default grew that board's SPL past its size limit, 241 bytes over in CI. Enabling LTO is no option, as it is already enabled.
- Added the MX6DL_MAMOJ board maintainers to Cc.
Simone CIANNI <[email protected]> is left out, that address bounces the same way with "550 5.4.1 Recipient address rejected: Access denied".
Heiko Schocher (2):
crypto: fsl: run the CAAM RNG self test on affected i.MX6 chips
imx: hab: name the event left behind by the boot ROM RNG self test
arch/arm/include/asm/arch-imx/cpu.h | 2 + arch/arm/mach-imx/hab.c | 16 +++ configs/imx6dl_mamoj_defconfig | 1 + drivers/crypto/fsl/Kconfig | 22 ++++ drivers/crypto/fsl/Makefile | 1 + drivers/crypto/fsl/jr.c | 3 + drivers/crypto/fsl/jr.h | 1 + drivers/crypto/fsl/rng_self_test.c | 157 ++++++++++++++++++++++++++++ 8 files changed, 203 insertions(+) create mode 100644 drivers/crypto/fsl/rng_self_test.c
---
base-commit: 75df64103873fac09642860cedadaffb8cf6b2c7
branch: hab-rng-v2
Signature · 1 line
2.55.0
PATCH v2 1/2 crypto: fsl: run the CAAM RNG self test on affected i.MX6 chips
The boot ROM of a few i.MX6 revisions runs the RNG self test incorrectly. It leaves a HAB event behind on every boot:
STS = HAB_WARNING (0x69) RSN = HAB_ENG_FAIL (0x30)
CTX = HAB_CTX_ENTRY (0xE1) ENG = HAB_ENG_CAAM (0x1D)NXP recommends to run a rng self test before any RNG related crypto implementations are done.
Affected are i.MX6Solo, i.MX6DL and i.MX6SX revision 1.4, i.MX6Q revision 1.6 and i.MX6QP revision 1.1, and no other revision of those chips. Both chip and revision are read at runtime and have to match.
Run this test on affected chips and stop if test fails.
Turning the option on by default grows the SPL, which puts imx6dl_mamoj over its size limit, so switch it off in that board's defconfig.
Part of the code is taken from u-boot-imx NXP tree, from the commit linked below, and adapted to mainline.
---
Rework against NXP base:
- adapt the chip detection
- checkpatch cleanup
- Kconfig symbol renamed and set a default
It may be worth discussing whether triggering a panic() and bringing the entire system to a halt is appropriate in this case.
Changes in v2:
- Dropped Gaurav Jain <[email protected]> from Cc. The address bounced on v1 with "550 5.4.1 Recipient address rejected: Access denied". His Signed-off-by stays, it records where the code comes from.
- Disabled the option in imx6dl_mamoj_defconfig. Enabling it by default grew that board's SPL past its size limit, 241 bytes over in CI. Enabling LTO is no option, as it is already enabled.
- Added the MX6DL_MAMOJ board maintainers to Cc.
Simone CIANNI <[email protected]> is left out, that address bounces the same way with "550 5.4.1 Recipient address rejected: Access denied".
arch/arm/include/asm/arch-imx/cpu.h | 2 + configs/imx6dl_mamoj_defconfig | 1 + drivers/crypto/fsl/Kconfig | 22 ++++ drivers/crypto/fsl/Makefile | 1 + drivers/crypto/fsl/jr.c | 3 + drivers/crypto/fsl/jr.h | 1 + drivers/crypto/fsl/rng_self_test.c | 157 ++++++++++++++++++++++++++++ 7 files changed, 187 insertions(+) create mode 100644 drivers/crypto/fsl/rng_self_test.c
arch/arm/include/asm/arch-imx/cpu.h +2 -0
@@ -95,7 +95,9 @@#define CHIP_REV_1_1 0x11#define CHIP_REV_1_2 0x12#define CHIP_REV_1_3 0x13 +#define CHIP_REV_1_4 0x14#define CHIP_REV_1_5 0x15 +#define CHIP_REV_1_6 0x16#define CHIP_REV_2_0 0x20#define CHIP_REV_2_1 0x21#define CHIP_REV_2_2 0x22
configs/imx6dl_mamoj_defconfig +1 -0
@@ -41,6 +41,7 @@ CONFIG_ENV_IS_IN_MMC=y CONFIG_ENV_RELOC_GD_ENV_ADDR=y CONFIG_ENV_MMC_DEVICE_INDEX=2 CONFIG_BOUNCE_BUFFER=y +# CONFIG_FSL_CAAM_RNG_SELF_TEST is not set CONFIG_DFU_MMC=y CONFIG_USB_FUNCTION_FASTBOOT=y CONFIG_FASTBOOT_BUF_ADDR=0x12000000
drivers/crypto/fsl/Kconfig +22 -0
@@ -100,4 +100,26 @@ config FSL_DCP_RNG and a Pseudo-Random Number Generator (PRNG) to achieve a true randomness and cryptographic strength. +config FSL_CAAM_RNG_SELF_TEST + bool "Run the CAAM RNG self test on affected i.MX6 chips" + depends on FSL_CAAM + default y if MX6S || MX6DL || MX6Q || MX6QDL || MX6SX + help + The boot ROM of a few i.MX6 revisions runs the RNG self test + incorrectly and leaves a HAB warning behind, which reads + + STS = HAB_WARNING (0x69) RSN = HAB_ENG_FAIL (0x30) + CTX = HAB_CTX_ENTRY (0xE1) ENG = HAB_ENG_CAAM (0x1D) + + The warning itself is harmless and this option does not make it + go away. What it does is run the self test correctly, before + anything else uses the RNG, so that a genuinely broken RNG is + found rather than assumed to be the known warning. The board is + stopped if the test fails. + + Affected are i.MX6Solo, i.MX6DL and i.MX6SX revision 1.4, i.MX6Q + revision 1.6 and i.MX6QP revision 1.1, and no other revision of + those chips. Chip and revision are read at runtime, so a build + covering several of them behaves correctly on each. + endif
drivers/crypto/fsl/Makefile +1 -0
@@ -9,3 +9,4 @@ obj-$(CONFIG_RSA_FREESCALE_EXP) += fsl_rsa.o obj-$(CONFIG_$(PHASE_)FSL_CAAM_RNG) += rng.o obj-$(CONFIG_FSL_DCP_RNG) += dcp_rng.o obj-$(CONFIG_FSL_MFGPROT) += fsl_mfgprot.o +obj-$(CONFIG_FSL_CAAM_RNG_SELF_TEST) += rng_self_test.o
drivers/crypto/fsl/jr.c +3 -0
@@ -804,6 +804,9 @@ init:pamu_enable ();#endif +if (IS_ENABLED (CONFIG_FSL_CAAM_RNG_SELF_TEST )) +rng_self_test (); +if (get_rng_vid (caam->sec) >=4 ) {if (rng_init (sec_idx, caam->sec) <0 ) {printf ("SEC%u: RNG instantiation failed\n" , sec_idx);
drivers/crypto/fsl/jr.h +1 -0
@@ -132,4 +132,5 @@ struct caam_regs {void caam_jr_strstatus (u32 status);int run_descriptor_jr (uint32_t *desc); +void rng_self_test (void );#endif
drivers/crypto/fsl/rng_self_test.c new file +157 -0
157 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH v2 2/2 imx: hab: name the event left behind by the boot ROM RNG self test
In reply to Heiko SchocherThe boot ROM of a few i.MX6 revisions runs its RNG self test incorrectly and logs an event for it on every boot. An event that reads HAB_ENG_FAIL on the CAAM and nothing further sends the reader looking for a fault in their own image, which is not where it is.
Print from where that event comes.
---
(no changes since v1)
arch/arm/mach-imx/hab.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
arch/arm/mach-imx/hab.c +16 -0
@@ -421,6 +421,19 @@ static inline u32 get_idx(u8 *list, u8 tgt, u32 size)return idx; } +/* +* The boot ROM of a few i.MX6 revisions runs the RNG self test +* incorrectly and leaves this event behind on every boot. Say so, so +* that the reader does not go looking for a fault that is not there. +*/ +static bool is_rng_self_test_event (struct record *rec) +{ +return rec->contents[0 ] ==HAB_WARNING && + rec->contents[1 ] ==HAB_ENG_FAIL && + rec->contents[2 ] ==HAB_CTX_ENTRY && + rec->contents[3 ] ==HAB_ENG_CAAM ; +} +static void process_event_record (uint8_t *event_data,size_t bytes) {struct record *rec = (struct record *)event_data;
@@ -433,6 +446,9 @@ static void process_event_record(uint8_t *event_data, size_t bytes) ARRAY_SIZE(hab_contexts))]);printf ("%s" , eng_str[get_idx (hab_engines, rec->contents[3 ],ARRAY_SIZE (hab_engines))]); + +if (is_rng_self_test_event (rec)) +puts ("\nknown to come from the RNG self test of the boot ROM, harmless\n" ); }static void display_event (uint8_t *event_data,size_t bytes)
Signature · 1 line
2.55.0