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.si...@amd.com>
Signed-off-by: Venkatesh Yadav Abbarapu <venkatesh.abbar...@amd.com>
---
 board/xilinx/common/board.c | 59 +++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/board/xilinx/common/board.c b/board/xilinx/common/board.c
index 12a877c715..985a3825e6 100644
--- a/board/xilinx/common/board.c
+++ b/board/xilinx/common/board.c
@@ -682,3 +682,62 @@ phys_addr_t board_get_usable_ram_top(phys_size_t 
total_size)
        return reg + size;
 }
 #endif
+
+#ifdef CONFIG_OF_BOARD_SETUP
+int ft_board_setup(void *blob, struct bd_info *bd)
+{
+       size_t n = 0x8;
+       struct udevice *dev;
+       u64 *buf;
+       int nodeoffset;
+       int ret;
+
+       if (uclass_get_device(UCLASS_RNG, 0, &dev) || !dev) {
+               debug("No RNG device\n");
+               return 0;
+       }
+
+       buf = malloc(n);
+       if (!buf) {
+               debug("Out of memory\n");
+               return 0;
+       }
+
+       if (dm_rng_read(dev, buf, n)) {
+               debug("Reading RNG failed\n");
+               ret = 0;
+               goto end;
+       }
+
+       if (!blob) {
+               debug("No FDT memory address configured. Please configure\n"
+                     "the FDT address via \"fdt addr <address>\" command.\n"
+                     "Aborting!\n");
+               ret = 0;
+               goto end;
+       }
+
+       ret = fdt_check_header(blob);
+       if (ret < 0) {
+               printf("fdt_chosen: %s\n", fdt_strerror(ret));
+               goto end;
+       }
+
+       nodeoffset = fdt_find_or_add_subnode(blob, 0, "chosen");
+       if (nodeoffset < 0) {
+               printf("Reading chosen node failed\n");
+               ret = -EINVAL;
+               goto end;
+       }
+
+       ret = fdt_setprop(blob, nodeoffset, "kaslr-seed", buf, sizeof(buf));
+       if (ret < 0) {
+               printf("Unable to set kaslr-seed on chosen node: %s\n", 
fdt_strerror(ret));
+               goto end;
+       }
+end:
+       free(buf);
+
+       return ret;
+}
+#endif
-- 
2.25.1

Reply via email to