[PATCH v2 1/2] xilinx: board: Update the kaslr-seed property
Venkatesh Yadav Abbarapu
venkatesh.abbarapu at amd.com
Tue Jan 16 05:50:22 CET 2024
Create a ft_board_setup() api that gets called as part
of bootm/booti before jumping to kernel. In this
ft_board_setup() callback that will inspect the DTB
and insert the device tree blob with the "kaslr-seed" property.
Signed-off-by: Michal Simek <michal.simek at amd.com>
Signed-off-by: Venkatesh Yadav Abbarapu <venkatesh.abbarapu at amd.com>
---
board/xilinx/common/board.c | 50 +++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
diff --git a/board/xilinx/common/board.c b/board/xilinx/common/board.c
index 12a877c715..2796d45351 100644
--- a/board/xilinx/common/board.c
+++ b/board/xilinx/common/board.c
@@ -25,6 +25,7 @@
#include <i2c_eeprom.h>
#include <net.h>
#include <generated/dt.h>
+#include <rng.h>
#include <slre.h>
#include <soc.h>
#include <linux/ctype.h>
@@ -682,3 +683,52 @@ phys_addr_t board_get_usable_ram_top(phys_size_t total_size)
return reg + size;
}
#endif
+
+#ifdef CONFIG_OF_BOARD_SETUP
+#define MAX_RAND_SIZE 8
+int ft_board_setup(void *blob, struct bd_info *bd)
+{
+ size_t n = MAX_RAND_SIZE;
+ struct udevice *dev;
+ u8 buf[MAX_RAND_SIZE];
+ int nodeoffset;
+ int ret;
+
+ if (uclass_get_device(UCLASS_RNG, 0, &dev) || !dev) {
+ debug("No RNG device\n");
+ return -EINVAL;
+ }
+
+ if (dm_rng_read(dev, buf, n)) {
+ debug("Reading RNG failed\n");
+ return -EINVAL;
+ }
+
+ if (!blob) {
+ debug("No FDT memory address configured. Please configure\n"
+ "the FDT address via \"fdt addr <address>\" command.\n"
+ "Aborting!\n");
+ return -EINVAL;
+ }
+
+ ret = fdt_check_header(blob);
+ if (ret < 0) {
+ debug("fdt_chosen: %s\n", fdt_strerror(ret));
+ return -EINVAL;
+ }
+
+ nodeoffset = fdt_find_or_add_subnode(blob, 0, "chosen");
+ if (nodeoffset < 0) {
+ debug("Reading chosen node failed\n");
+ return -EINVAL;
+ }
+
+ ret = fdt_setprop(blob, nodeoffset, "kaslr-seed", buf, sizeof(buf));
+ if (ret < 0) {
+ debug("Unable to set kaslr-seed on chosen node: %s\n", fdt_strerror(ret));
+ return -EINVAL;
+ }
+
+ return ret;
+}
+#endif
--
2.25.1
More information about the U-Boot
mailing list