aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/Kconfig14
-rw-r--r--common/fdt_support.c13
-rw-r--r--include/fdt_support.h13
3 files changed, 40 insertions, 0 deletions
diff --git a/common/Kconfig b/common/Kconfig
index e7914ca..ebee856 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -768,6 +768,20 @@ config TPL_STACKPROTECTOR
bool "Stack Protector buffer overflow detection for TPL"
depends on STACKPROTECTOR && TPL
+config BOARD_RNG_SEED
+ bool "Provide /chosen/rng-seed property to the linux kernel"
+ help
+ Selecting this option requires the board to define a
+ board_rng_seed() function, which should return a buffer
+ which will be used to populate the /chosen/rng-seed property
+ in the device tree for the OS being booted.
+
+ It is up to the board code (and more generally the whole
+ BSP) where and how to store (or generate) such a seed, how
+ to ensure a given seed is only used once, how to create a
+ new seed for use on subsequent boots, and whether or not the
+ kernel should account any entropy from the given seed.
+
endmenu
menu "Update support"
diff --git a/common/fdt_support.c b/common/fdt_support.c
index 8c18af2..baf7fb7 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -7,6 +7,7 @@
*/
#include <common.h>
+#include <abuf.h>
#include <env.h>
#include <log.h>
#include <mapmem.h>
@@ -279,6 +280,7 @@ __weak char *board_fdt_chosen_bootargs(void)
int fdt_chosen(void *fdt)
{
+ struct abuf buf = {};
int nodeoffset;
int err;
char *str; /* used to set string properties */
@@ -294,6 +296,17 @@ int fdt_chosen(void *fdt)
if (nodeoffset < 0)
return nodeoffset;
+ if (IS_ENABLED(CONFIG_BOARD_RNG_SEED) && !board_rng_seed(&buf)) {
+ err = fdt_setprop(fdt, nodeoffset, "rng-seed",
+ abuf_data(&buf), abuf_size(&buf));
+ abuf_uninit(&buf);
+ if (err < 0) {
+ printf("WARNING: could not set rng-seed %s.\n",
+ fdt_strerror(err));
+ return err;
+ }
+ }
+
str = board_fdt_chosen_bootargs();
if (str) {
diff --git a/include/fdt_support.h b/include/fdt_support.h
index ac76939..b838071 100644
--- a/include/fdt_support.h
+++ b/include/fdt_support.h
@@ -11,6 +11,7 @@
#include <asm/u-boot.h>
#include <linux/libfdt.h>
+#include <abuf.h>
/**
* arch_fixup_fdt() - Write arch-specific information to fdt
@@ -187,6 +188,18 @@ int fdt_find_or_add_subnode(void *fdt, int parentoffset, const char *name);
int ft_board_setup(void *blob, struct bd_info *bd);
/**
+ * board_rng_seed() - Provide a seed to be passed via /chosen/rng-seed
+ *
+ * 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.
+ *
+ * @param buf A struct abuf for returning the seed and its size.
+ * @return 0 if ok, negative on error.
+ */
+int board_rng_seed(struct abuf *buf);
+
+/**
* board_fdt_chosen_bootargs() - Arbitrarily amend fdt kernel command line
*
* This is used for late modification of kernel command line arguments just