rng: airoha: add support for the Airoha TRNG
PATCH RESEND 1/2 rng: airoha: add support for the Airoha TRNG
Port the Linux driver for the True Random Number Generator found on Airoha EN7581/AN7581 SoCs to the U-Boot driver model.
The Linux driver waits for an interrupt to learn that the startup health test finished. U-Boot has no interrupts, so the TRNG interrupt is kept masked and RST_STARTUP_TEST_DONE is polled instead.
U-Boot can then provide /chosen/kaslr-seed, which KASLR requires.
---
Notes:
The first posting on 2026-09-20 was held by list moderation (non-member post) and never reached the list. Resent to the current list address.
drivers/rng/Kconfig | 7 ++ drivers/rng/Makefile | 1 + drivers/rng/airoha-rng.c | 136 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 144 insertions(+) create mode 100644 drivers/rng/airoha-rng.c
drivers/rng/Kconfig +7 -0
@@ -140,4 +140,11 @@ config RNG_EXYNOS case the LDFW (Loadable Firmware) has to be loaded first, as it actually implements TRNG SMC calls. +config RNG_AIROHA + bool "Airoha True Random Number Generator support" + depends on DM_RNG && ARCH_AIROHA + help + Enable support for the True Random Number Generator (TRNG) found + on Airoha EN7581/AN7581 SoCs. + endif
drivers/rng/Makefile +1 -0
@@ -20,3 +20,4 @@ obj-$(CONFIG_TPM_RNG) += tpm_rng.o obj-$(CONFIG_RNG_JH7110) += jh7110_rng.o obj-$(CONFIG_RNG_TURRIS_RWTM) += turris_rwtm_rng.o obj-$(CONFIG_RNG_EXYNOS) += exynos-trng.o +obj-$(CONFIG_RNG_AIROHA) += airoha-rng.o
drivers/rng/airoha-rng.c new file +136 -0
136 lines not on this page · raw message
base-commit: f61f50a79dab97c8a4109ee9c15b90bf6157d4e8
Signature · 1 line
2.55.0
PATCH RESEND 2/2 configs: an7581_evb: enable the Airoha TRNG
The en7581 dtsi from dts/upstream already has the TRNG node, so only the driver needs enabling. U-Boot then provides /chosen/kaslr-seed.
--- configs/an7581_evb_defconfig | 2 ++ 1 file changed, 2 insertions(+)
configs/an7581_evb_defconfig +2 -0
@@ -77,6 +77,8 @@ CONFIG_POWER_DOMAIN=y CONFIG_DM_REGULATOR=y CONFIG_DM_REGULATOR_FIXED=y CONFIG_RAM=y +CONFIG_DM_RNG=y +CONFIG_RNG_AIROHA=y CONFIG_DM_SERIAL=y CONFIG_SYS_NS16550=y CONFIG_SPI=y
Signature · 1 line
2.55.0
Am 29. September 2026 00:43:37 MESZ schrieb Vitaliy Sochnev <[email protected]>:
Quoted 27 lines
Port the Linux driver for the True Random Number Generator found on Airoha EN7581/AN7581 SoCs to the U-Boot driver model.
The Linux driver waits for an interrupt to learn that the startup health test finished. U-Boot has no interrupts, so the TRNG interrupt is kept masked and
RST_STARTUP_TEST_DONEis polled instead.U-Boot can then provide /chosen/kaslr-seed, which KASLR requires.
Signed-off-by Vitaliy Sochnev <[email protected]>---
Notes:
The first posting on 2026-09-20 was held by list moderation (non-member post) and never reached the list. Resent to the current list address.drivers/rng/Kconfig | 7 ++ drivers/rng/Makefile | 1 + drivers/rng/airoha-rng.c | 136 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 144 insertions(+)create mode 100644
drivers/rng/airoha-rng.cdrivers/rng/Kconfig +0
-0
drivers/rng/Kconfig config RNG_EXYNOS · line 145
Quoted 6 lines
drivers/rng/Kconfig +3
-0@@ -140,4 +140,11 @@ config RNG_EXYNOS case the LDFW (Loadable Firmware) has to be loaded first, as it actually implements TRNG SMC calls. +config RNG_AIROHA + bool "Airoha True Random Number Generator support" + depends on DM_RNG && ARCH_AIROHA
This DM_RNG duplicates the if condition. Please, remove the redundant constraint.
The entries once were alphabetically sorted.
Quoted 10 lines
drivers/rng/Kconfig +4
-0+ help + Enable support for the True Random Number Generator (TRNG) found + on Airoha EN7581/AN7581 SoCs. +endif
drivers/rng/Makefile +0
-0@@ -20,3 +20,4 @@ obj-$(CONFIG_TPM_RNG) += tpm_rng.o
Quoted 4 lines
obj-$(CONFIG_RNG_JH7110) += jh7110_rng.o obj-$(CONFIG_RNG_TURRIS_RWTM) += turris_rwtm_rng.o obj-$(CONFIG_RNG_EXYNOS) += exynos-trng.o +obj-$(CONFIG_RNG_AIROHA) += airoha-rng.o
Same here.
Best regards
Heinrich
Quoted 144 lines
drivers/rng/airoha-rng.c new file +136
-0@@ -0,0 +1,136 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Airoha True Random Number Generator driver +* +* Ported from the Linux driver drivers/char/hw_random/airoha-trng.c +* +* Copyright (C) 2024 Christian Marangi <[email protected]> +*/ + +#include <dm.h> +#include <rng.h> +#include <dm/device_compat.h> +#include <asm/io.h> +#include <linux/bitfield.h> +#include <linux/bitops.h> +#include <linux/iopoll.h> +#include <linux/string.h> + +#define TRNG_IP_RDY 0x800 +#define CNT_TRANS GENMASK(15, 8) +#define SAMPLE_RDY BIT(0) +#define TRNG_NS_SEK_AND_DAT_EN 0x804 +#define RNG_EN BIT(31) +#define RAW_DATA_EN BIT(16) +#define TRNG_HEALTH_TEST_SW_RST 0x808 +#define SW_RST BIT(0)/* Active High */ +#define TRNG_INTR_EN 0x818 +#define INTR_MASK BIT(16) +#define RST_STARTUP_INITR_EN BIT(0) +#define TRNG_HEALTH_TEST_STATUS 0x824 +#define RST_STARTUP_TEST_DONE BIT(18) +#define RST_STARTUP_AP_TEST_FAIL BIT(17) +#define RST_STARTUP_RC_TEST_FAIL BIT(16) +#define RAW_DATA_VALID BIT(7) +#define TRNG_RAW_DATA_OUT 0x828 + +#define TRNG_CNT_TRANS_VALID 0x80 +#define TRNG_TIMEOUT_US 100000 + +struct airoha_trng { +void __iomem *base; +}; + +static int airoha_trng_read (struct udevice *dev,void *data,size_t len) +{ +struct airoha_trng *trng =dev_get_priv (dev); +u8 *buf = data; + +while (len) { +size_t step =min (len,sizeof (u32)); +u32 status, val; +int ret; + + ret =readl_poll_timeout (trng->base +TRNG_HEALTH_TEST_STATUS , + status, status &RAW_DATA_VALID , +TRNG_TIMEOUT_US ); +if (ret) { +dev_err (dev,"Timeout waiting for TRNG RAW Data valid\n" ); +return ret; + } + + val =readl (trng->base +TRNG_RAW_DATA_OUT ); +memcpy (buf, &val, step); + + buf += step; + len -= step; + } + +return 0 ; +} + +static int airoha_trng_probe (struct udevice *dev) +{ +struct airoha_trng *trng =dev_get_priv (dev); +u32 val; +int ret; + + trng->base =dev_read_addr_ptr (dev); +if (!trng->base) +return -EINVAL ; + +/* No interrupts in U-Boot: keep the TRNG one masked and poll instead */ + val =readl (trng->base +TRNG_INTR_EN ); + val |=INTR_MASK |RST_STARTUP_INITR_EN ; +writel (val, trng->base +TRNG_INTR_EN ); + + val =readl (trng->base +TRNG_NS_SEK_AND_DAT_EN ); + val |=RAW_DATA_EN |RNG_EN ; +writel (val, trng->base +TRNG_NS_SEK_AND_DAT_EN ); + +/* Health Test runs only on the transition out of SW Reset */ +writel (SW_RST , trng->base +TRNG_HEALTH_TEST_SW_RST ); +writel (0 , trng->base +TRNG_HEALTH_TEST_SW_RST ); + + ret =readl_poll_timeout (trng->base +TRNG_HEALTH_TEST_STATUS , val, + val &RST_STARTUP_TEST_DONE ,TRNG_TIMEOUT_US ); +if (ret) { +dev_err (dev,"Timeout waiting for Health Check\n" ); +return ret; + } + +if (val & (RST_STARTUP_AP_TEST_FAIL |RST_STARTUP_RC_TEST_FAIL )) { +dev_err (dev,"Health Check fail: %s test fail\n" , + val &RST_STARTUP_AP_TEST_FAIL ?"AP" :"RC" ); +return -EIO ; + } + + ret =readl_poll_timeout (trng->base +TRNG_IP_RDY , val, + val &SAMPLE_RDY && +FIELD_GET (CNT_TRANS , val) ==TRNG_CNT_TRANS_VALID , +TRNG_TIMEOUT_US ); +if (ret) { +dev_err (dev,"Timeout waiting for IP ready\n" ); +return ret; + } + +return 0 ; +} + +static const struct dm_rng_ops airoha_trng_ops = { + .read = airoha_trng_read, +}; + +static const struct udevice_id airoha_trng_match[] = { + { .compatible ="airoha,en7581-trng" }, + { } +}; + +U_BOOT_DRIVER (airoha_trng) = { + .name ="airoha-trng" , + .id =UCLASS_RNG , + .of_match = airoha_trng_match, + .ops = &airoha_trng_ops, + .probe = airoha_trng_probe, + .priv_auto =sizeof (struct airoha_trng ), +};base-commit:
f61f50a79dab97c8a4109ee9c15b90bf6157d4e8
PATCH v2 1/2 rng: airoha: add support for the Airoha TRNG
In reply to Vitaliy SochnevPort the Linux driver for the True Random Number Generator found on Airoha EN7581/AN7581 SoCs to the U-Boot driver model.
The Linux driver waits for an interrupt to learn that the startup health test finished. U-Boot has no interrupts, so the TRNG interrupt is kept masked and RST_STARTUP_TEST_DONE is polled instead.
U-Boot can then provide /chosen/kaslr-seed, which KASLR requires.
---
Notes:
Changes in v2:
- Drop redundant DM_RNG dependency
- Sort Kconfig and Makefile entries alphabetically
drivers/rng/Kconfig | 7 ++ drivers/rng/Makefile | 1 + drivers/rng/airoha-rng.c | 136 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 144 insertions(+) create mode 100644 drivers/rng/airoha-rng.c
drivers/rng/Kconfig +7 -0
@@ -15,6 +15,13 @@ config SPL_DM_RNG if DM_RNG +config RNG_AIROHA + bool "Airoha True Random Number Generator support" + depends on ARCH_AIROHA + help + Enable support for the True Random Number Generator (TRNG) found + on Airoha EN7581/AN7581 SoCs. + config RNG_MESON bool "Amlogic Meson Random Number Generator support" depends on ARCH_MESON
drivers/rng/Makefile +1 -0
@@ -4,6 +4,7 @@ # obj-$(CONFIG_$(PHASE_)DM_RNG) += rng-uclass.o +obj-$(CONFIG_RNG_AIROHA) += airoha-rng.o obj-$(CONFIG_RNG_MESON) += meson-rng.o obj-$(CONFIG_RNG_MPFS) += mpfs_rng.o obj-$(CONFIG_RNG_SANDBOX) += sandbox_rng.o
drivers/rng/airoha-rng.c new file +136 -0
136 lines not on this page · raw message
base-commit: f61f50a79dab97c8a4109ee9c15b90bf6157d4e8
Signature · 1 line
2.55.0
PATCH v2 2/2 configs: an7581_evb: enable the Airoha TRNG
The en7581 dtsi from dts/upstream already has the TRNG node, so only the driver needs enabling.
--- configs/an7581_evb_defconfig | 2 ++ 1 file changed, 2 insertions(+)
configs/an7581_evb_defconfig +2 -0
@@ -77,6 +77,8 @@ CONFIG_POWER_DOMAIN=y CONFIG_DM_REGULATOR=y CONFIG_DM_REGULATOR_FIXED=y CONFIG_RAM=y +CONFIG_DM_RNG=y +CONFIG_RNG_AIROHA=y CONFIG_DM_SERIAL=y CONFIG_SYS_NS16550=y CONFIG_SPI=y
Signature · 1 line
2.55.0
Quoted 8 lines · Vitaliy Sochnev
Port the Linux driver for the True Random Number Generator found on Airoha EN7581/AN7581 SoCs to the U-Boot driver model.
The Linux driver waits for an interrupt to learn that the startup health test finished. U-Boot has no interrupts, so the TRNG interrupt is kept masked and
RST_STARTUP_TEST_DONEis polled instead.[...]
Applied to u-boot/main, thanks!
[1/2] rng: airoha: add support for the Airoha TRNG
commit: ce82cd191de2bd7d76213c70b339394cc0c156a1
[2/2] configs: an7581_evb: enable the Airoha TRNG
commit: 2b8358483c3ed62da6a705d8469de6b1c8d01679Signature · 1 line
Tom