Skip to content

Commit

Permalink
uboot-rockchip: increase rng-seed size
Browse files Browse the repository at this point in the history
Increase rng-seed size to make Linux happy and initialize rng pool instantly.
Linux 5.19+ requires 32 bytes of entropy to initialize random pool, but u-boot
currently provides only 8 bytes.

Boot with 8 byte rng-seed (Linux 6.11):
    # dmesg | grep crng
    [   12.089286] random: crng init done
Boot with 32 byte rng-seed (Linux 6.11):
    # dmesg | grep crng
    [    0.000000] random: crng init done

Signed-off-by: Tianling Shen <[email protected]>
Link: openwrt/openwrt#17352
Signed-off-by: Hauke Mehrtens <[email protected]>
  • Loading branch information
1715173329 authored and hauke committed Dec 23, 2024
1 parent 0de59fb commit 967a6a2
Showing 1 changed file with 96 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
From ed4ae7386257aa66455e330234e513d098a36f84 Mon Sep 17 00:00:00 2001
From: Alex Shumsky <[email protected]>
Date: Wed, 16 Oct 2024 13:02:03 +0300
Subject: [PATCH] rockchip: board: Increase rng-seed size to make it sufficient
for modern Linux

Increase rng-seed size to make Linux happy and initialize rng pool instantly.
Linux 5.19+ requires 32 bytes of entropy to initialize random pool, but u-boot
currently provides only 8 bytes.
Linux 5.18 and probably some versions before it used to require 64 bytes.
Bump min value to 64 bytes to be on a safe side.

Boot with 8 byte rng-seed (Linux 6.11):
# dmesg | grep crng
[ 12.089286] random: crng init done
Boot with 32 byte rng-seed (Linux 6.11):
# dmesg | grep crng
[ 0.000000] random: crng init done

Linux source references:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/char/random.c?h=v5.19#n551
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/char/random.c?h=v5.18#n236

Signed-off-by: Alex Shumsky <[email protected]>
Fixes: d2048bafae40 ("rockchip: board: Add board_rng_seed() for all Rockchip devices")
Reviewed-by: Dragan Simic <[email protected]>
Reviewed-by: Marek Vasut <[email protected]>
Reviewed-by: Quentin Schulz <[email protected]>
Reviewed-by: Kever Yang <[email protected]>
---
arch/arm/mach-rockchip/board.c | 11 ++++++++++-
common/Kconfig | 3 +++
doc/usage/environment.rst | 5 +++++
include/fdt_support.h | 3 ++-
4 files changed, 20 insertions(+), 2 deletions(-)

--- a/arch/arm/mach-rockchip/board.c
+++ b/arch/arm/mach-rockchip/board.c
@@ -480,9 +480,18 @@ __weak int misc_init_r(void)
__weak int board_rng_seed(struct abuf *buf)
{
struct udevice *dev;
- size_t len = 0x8;
+ ulong len = env_get_ulong("rng_seed_size", 10, 64);
u64 *data;

+ if (len < 64) {
+ /*
+ * rng_seed_size should be at least 32 bytes for Linux 5.19+,
+ * or 64 for older Linux kernel versions
+ */
+ log_warning("Value for rng_seed_size (%lu) too low, Linux kernel RNG may fail to initialize early\n",
+ len);
+ }
+
data = malloc(len);
if (!data) {
printf("Out of memory\n");
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -927,6 +927,9 @@ config BOARD_RNG_SEED
new seed for use on subsequent boots, and whether or not the
kernel should account any entropy from the given seed.

+ Default seed size (64 bytes) can be overridden by a decimal
+ environment variable rng_seed_size.
+
endmenu

menu "Update support"
--- a/doc/usage/environment.rst
+++ b/doc/usage/environment.rst
@@ -323,6 +323,11 @@ netretry
Useful on scripts which control the retry operation
themselves.

+rng_seed_size
+ Size of random value added to device-tree node /chosen/rng-seed.
+ This variable is given as a decimal number.
+ If unset, 64 bytes is used as the default.
+
silent_linux
If set then Linux will be told to boot silently, by
adding 'console=' to its command line. If "yes" it will be
--- a/include/fdt_support.h
+++ b/include/fdt_support.h
@@ -202,7 +202,8 @@ int ft_board_setup(void *blob, struct bd
*
* This function is called if CONFIG_BOARD_RNG_SEED is set, and must
* be provided by the board. It should return, via @buf, some suitable
- * seed value to pass to the kernel.
+ * seed value to pass to the kernel. Seed size could be set in a decimal
+ * environment variable rng_seed_size and it defaults to 64 bytes.
*
* @param buf A struct abuf for returning the seed and its size.
* @return 0 if ok, negative on error.

0 comments on commit 967a6a2

Please sign in to comment.