1 From ed4ae7386257aa66455e330234e513d098a36f84 Mon Sep 17 00:00:00 2001
2 From: Alex Shumsky <alexthreed@gmail.com>
3 Date: Wed, 16 Oct 2024 13:02:03 +0300
4 Subject: [PATCH] rockchip: board: Increase rng-seed size to make it sufficient
7 Increase rng-seed size to make Linux happy and initialize rng pool instantly.
8 Linux 5.19+ requires 32 bytes of entropy to initialize random pool, but u-boot
9 currently provides only 8 bytes.
10 Linux 5.18 and probably some versions before it used to require 64 bytes.
11 Bump min value to 64 bytes to be on a safe side.
13 Boot with 8 byte rng-seed (Linux 6.11):
15 [ 12.089286] random: crng init done
16 Boot with 32 byte rng-seed (Linux 6.11):
18 [ 0.000000] random: crng init done
20 Linux source references:
21 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/char/random.c?h=v5.19#n551
22 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/char/random.c?h=v5.18#n236
24 Signed-off-by: Alex Shumsky <alexthreed@gmail.com>
25 Fixes: d2048bafae40 ("rockchip: board: Add board_rng_seed() for all Rockchip devices")
26 Reviewed-by: Dragan Simic <dsimic@manjaro.org>
27 Reviewed-by: Marek Vasut <marex@denx.de>
28 Reviewed-by: Quentin Schulz <quentin.schulz@cherry.de>
29 Reviewed-by: Kever Yang <kever.yang@rock-chips.com>
31 arch/arm/mach-rockchip/board.c | 11 ++++++++++-
32 common/Kconfig | 3 +++
33 doc/usage/environment.rst | 5 +++++
34 include/fdt_support.h | 3 ++-
35 4 files changed, 20 insertions(+), 2 deletions(-)
37 --- a/arch/arm/mach-rockchip/board.c
38 +++ b/arch/arm/mach-rockchip/board.c
39 @@ -480,9 +480,18 @@ __weak int misc_init_r(void)
40 __weak int board_rng_seed(struct abuf *buf)
44 + ulong len = env_get_ulong("rng_seed_size", 10, 64);
49 + * rng_seed_size should be at least 32 bytes for Linux 5.19+,
50 + * or 64 for older Linux kernel versions
52 + log_warning("Value for rng_seed_size (%lu) too low, Linux kernel RNG may fail to initialize early\n",
58 printf("Out of memory\n");
61 @@ -927,6 +927,9 @@ config BOARD_RNG_SEED
62 new seed for use on subsequent boots, and whether or not the
63 kernel should account any entropy from the given seed.
65 + Default seed size (64 bytes) can be overridden by a decimal
66 + environment variable rng_seed_size.
71 --- a/doc/usage/environment.rst
72 +++ b/doc/usage/environment.rst
73 @@ -323,6 +323,11 @@ netretry
74 Useful on scripts which control the retry operation
78 + Size of random value added to device-tree node /chosen/rng-seed.
79 + This variable is given as a decimal number.
80 + If unset, 64 bytes is used as the default.
83 If set then Linux will be told to boot silently, by
84 adding 'console=' to its command line. If "yes" it will be
85 --- a/include/fdt_support.h
86 +++ b/include/fdt_support.h
87 @@ -202,7 +202,8 @@ int ft_board_setup(void *blob, struct bd
89 * This function is called if CONFIG_BOARD_RNG_SEED is set, and must
90 * be provided by the board. It should return, via @buf, some suitable
91 - * seed value to pass to the kernel.
92 + * seed value to pass to the kernel. Seed size could be set in a decimal
93 + * environment variable rng_seed_size and it defaults to 64 bytes.
95 * @param buf A struct abuf for returning the seed and its size.
96 * @return 0 if ok, negative on error.