From: Chris Morgan Date: Tue, 2 Jan 2024 15:46:52 +0000 (-0600) Subject: rockchip: board: Add board_rng_seed() for all Rockchip devices X-Git-Url: http://git.dujemihanovic.xyz/?a=commitdiff_plain;h=d2048bafae4014fbfacb2fc860da72c1bc525354;p=u-boot.git rockchip: board: Add board_rng_seed() for all Rockchip devices Allow all rockchip devices to use the hardware RNG to seed Linux RNG. Signed-off-by: Chris Morgan Reviewed-by: Kever Yang --- diff --git a/arch/arm/mach-rockchip/board.c b/arch/arm/mach-rockchip/board.c index 38a2a4b95e..c1cfe0ea1d 100644 --- a/arch/arm/mach-rockchip/board.c +++ b/arch/arm/mach-rockchip/board.c @@ -320,3 +320,35 @@ __weak int misc_init_r(void) return ret; } #endif + +#if IS_ENABLED(CONFIG_BOARD_RNG_SEED) && IS_ENABLED(CONFIG_RNG_ROCKCHIP) +#include + +/* Use hardware rng to seed Linux random. */ +__weak int board_rng_seed(struct abuf *buf) +{ + struct udevice *dev; + size_t len = 0x8; + u64 *data; + + data = malloc(len); + if (!data) { + printf("Out of memory\n"); + return -ENOMEM; + } + + if (uclass_get_device(UCLASS_RNG, 0, &dev) || !dev) { + printf("No RNG device\n"); + return -ENODEV; + } + + if (dm_rng_read(dev, data, len)) { + printf("Reading RNG failed\n"); + return -EIO; + } + + abuf_init_set(buf, data, len); + + return 0; +} +#endif diff --git a/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c b/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c index 3d0c614623..3ff2e9493f 100644 --- a/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c +++ b/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c @@ -16,7 +16,6 @@ #include #include #include -#include #include #include @@ -133,34 +132,6 @@ void spl_board_init(void) (GPIO0_BASE + GPIO_SWPORT_DR_H)); } -/* Use hardware rng to seed Linux random. */ -int board_rng_seed(struct abuf *buf) -{ - struct udevice *dev; - size_t len = 0x8; - u64 *data; - - data = malloc(len); - if (!data) { - printf("Out of memory\n"); - return -ENOMEM; - } - - if (uclass_get_device(UCLASS_RNG, 0, &dev) || !dev) { - printf("No RNG device\n"); - return -ENODEV; - } - - if (dm_rng_read(dev, data, len)) { - printf("Reading RNG failed\n"); - return -EIO; - } - - abuf_init_set(buf, data, len); - - return 0; -} - /* * Buzz the buzzer so the user knows something is going on. Make it * optional in case PWM is disabled.