[PATCH 0/2] xilinx: Update the kaslr-seed property

Update the kaslr-seed property and enable the config CONFIG_OF_BOARD_SETUP.
Venkatesh Yadav Abbarapu (2): xilinx: board: Update the kaslr-seed property configs: zynqmp_kria: Enable CONFIG_OF_BOARD_SETUP
board/xilinx/common/board.c | 59 ++++++++++++++++++++++++++++ configs/xilinx_zynqmp_kria_defconfig | 1 + 2 files changed, 60 insertions(+)

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@amd.com Signed-off-by: Venkatesh Yadav Abbarapu venkatesh.abbarapu@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

On 1/12/24 07:10, Venkatesh Yadav Abbarapu wrote:
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@amd.com Signed-off-by: Venkatesh Yadav Abbarapu venkatesh.abbarapu@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;
this is pretty much macro not variable.
- struct udevice *dev;
- u64 *buf;
- int nodeoffset;
- int ret;
put it on the same line.
- 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;
- }
Does it really make sense to call malloc and complicate error part just for 8bytes? You can simply create array/variable on stack for it instead and it would be simpler and faster.
- 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));
this error is weird. Can you make it more understandable?
goto end;
- }
- nodeoffset = fdt_find_or_add_subnode(blob, 0, "chosen");
- if (nodeoffset < 0) {
printf("Reading chosen node failed\n");
here too. You get this error in boot and you have no idea where this is coming from.
There is going to be error printed from code like "ERROR: board-specific fdt fixup failed"
Maybe it should be enough to simply move all these messages under debug just in case and let code which calls this function to handle it.
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
M

Enable CONFIG_OF_BOARD_SETUP, so we could use ft_board_setup() to enable the kaslr-seed and pass to kernel.
Signed-off-by: Michal Simek michal.simek@amd.com Signed-off-by: Venkatesh Yadav Abbarapu venkatesh.abbarapu@amd.com --- configs/xilinx_zynqmp_kria_defconfig | 1 + 1 file changed, 1 insertion(+)
diff --git a/configs/xilinx_zynqmp_kria_defconfig b/configs/xilinx_zynqmp_kria_defconfig index a65a59c1ae..86741f1773 100644 --- a/configs/xilinx_zynqmp_kria_defconfig +++ b/configs/xilinx_zynqmp_kria_defconfig @@ -33,6 +33,7 @@ CONFIG_SPL_LOAD_FIT=y CONFIG_SPL_LOAD_FIT_ADDRESS=0x10000000 CONFIG_SYS_BOOTM_LEN=0x6400000 CONFIG_DISTRO_DEFAULTS=y +CONFIG_OF_BOARD_SETUP=y # CONFIG_ARCH_FIXUP_FDT_MEMORY is not set CONFIG_USE_PREBOOT=y CONFIG_SYS_PBSIZE=2073
participants (2)
-
Michal Simek
-
Venkatesh Yadav Abbarapu