From: Volodymyr Babchuk Date: Mon, 11 Mar 2024 21:33:45 +0000 (+0000) Subject: qcom: board: validate fdt before trying to use it X-Git-Url: http://git.dujemihanovic.xyz/login.html?a=commitdiff_plain;h=86eb5d834d220893b5dc262c5aea7f933e275a4f;p=u-boot.git qcom: board: validate fdt before trying to use it There are cases when previous bootloader stage leaves some seemingly valid value in r0, which in fact does not point to valid FDT blob. This behavior was encountered when trying to boot U-Boot as "hyp" loader on SA8155P-ADP. To be sure that we really got the pointer to a device tree we need to validate it with fdt_check_header() function. Note: This approach is not 100% fool-proof, as get_prev_bl_fdt_addr() theoretically can return a pointer to a region that is not physically mapped and we will get data abort exception when fdt_check_header() will try to access it. But at this early boot stage we don't know where RAM is anyways so there is little we can do. Signed-off-by: Volodymyr Babchuk Reviewed-by: Sumit Garg Reviewed-by: Caleb Connolly Signed-off-by: Caleb Connolly --- diff --git a/arch/arm/mach-snapdragon/board.c b/arch/arm/mach-snapdragon/board.c index f12f5791a1..6f762fc948 100644 --- a/arch/arm/mach-snapdragon/board.c +++ b/arch/arm/mach-snapdragon/board.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -93,7 +94,9 @@ void *board_fdt_blob_setup(int *err) * try and use the FDT built into U-Boot if there is one... * This avoids having a hard dependency on the previous stage bootloader */ - if (IS_ENABLED(CONFIG_OF_SEPARATE) && (!fdt || fdt != ALIGN(fdt, SZ_4K))) { + + if (IS_ENABLED(CONFIG_OF_SEPARATE) && (!fdt || fdt != ALIGN(fdt, SZ_4K) || + fdt_check_header((void *)fdt))) { debug("%s: Using built in FDT, bootloader gave us %#llx\n", __func__, fdt); return (void *)gd->fdt_blob; }