]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
rockchip: board: Add board_rng_seed() for all Rockchip devices
authorChris Morgan <macromorgan@hotmail.com>
Tue, 2 Jan 2024 15:46:52 +0000 (09:46 -0600)
committerKever Yang <kever.yang@rock-chips.com>
Fri, 19 Jan 2024 02:57:36 +0000 (10:57 +0800)
Allow all rockchip devices to use the hardware RNG to seed Linux
RNG.

Signed-off-by: Chris Morgan <macromorgan@hotmail.com>
Reviewed-by: Kever Yang <kever.yang@rock-chips.com>
arch/arm/mach-rockchip/board.c
board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c

index 38a2a4b95ec0e2183d621ac56f0a0f4acf7dca26..c1cfe0ea1d25605f70a3dddc2881b54c4ccb0364 100644 (file)
@@ -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 <rng.h>
+
+/* 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
index 3d0c6146233059f53f8ef7b57a1784f8da4bcb88..3ff2e9493f9898794d6c4b3d8c5f325c53d5471c 100644 (file)
@@ -16,7 +16,6 @@
 #include <mmc.h>
 #include <panel.h>
 #include <pwm.h>
-#include <rng.h>
 #include <stdlib.h>
 #include <video_bridge.h>
 
@@ -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.