devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fdt: Extend warnings on error paths
@ 2025-04-23  9:10 Bartosz Szczepanek
  2025-04-23 20:23 ` Rob Herring
  0 siblings, 1 reply; 2+ messages in thread
From: Bartosz Szczepanek @ 2025-04-23  9:10 UTC (permalink / raw)
  To: Rob Herring, Saravana Kannan
  Cc: nh-open-source, Bartosz Szczepanek, devicetree, linux-kernel

Print out adress and size if elfcorehdr is overlapped. Be more verbose
about what went wrong in case early_init_dt_verify fails. Other than
improving logging, no functional change is intended in this commit.

Signed-off-by: Bartosz Szczepanek <bsz@amazon.de>
---
 drivers/of/fdt.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index aedd0e2dcd89..c9b5e056b713 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -469,21 +469,22 @@ static u32 of_fdt_crc32;
  * described in the device tree. This region contains all the
  * information about primary kernel's core image and is used by a dump
  * capture kernel to access the system memory on primary kernel.
  */
 static void __init fdt_reserve_elfcorehdr(void)
 {
 	if (!IS_ENABLED(CONFIG_CRASH_DUMP) || !elfcorehdr_size)
 		return;
 
 	if (memblock_is_region_reserved(elfcorehdr_addr, elfcorehdr_size)) {
-		pr_warn("elfcorehdr is overlapped\n");
+		pr_warn("elfcorehdr is overlapped (addr=0x%llx, size=%llu)\n",
+			elfcorehdr_addr, elfcorehdr_size);
 		return;
 	}
 
 	memblock_reserve(elfcorehdr_addr, elfcorehdr_size);
 
 	pr_info("Reserving %llu KiB of memory at 0x%llx for elfcorehdr\n",
 		elfcorehdr_size >> 10, elfcorehdr_addr);
 }
 
 /**
@@ -1128,26 +1129,33 @@ void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
 	memblock_add(base, size);
 }
 
 static void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
 {
 	return memblock_alloc_or_panic(size, align);
 }
 
 bool __init early_init_dt_verify(void *dt_virt, phys_addr_t dt_phys)
 {
-	if (!dt_virt)
+	int rc;
+
+	if (!dt_virt) {
+		pr_warn("FDT wasn't correctly mapped");
 		return false;
+	}
 
 	/* check device tree validity */
-	if (fdt_check_header(dt_virt))
+	rc = fdt_check_header(dt_virt);
+	if (rc) {
+		pr_warn("FDT header is invalid: status=%d", rc);
 		return false;
+	}
 
 	/* Setup flat device-tree pointer */
 	initial_boot_params = dt_virt;
 	initial_boot_params_pa = dt_phys;
 	of_fdt_crc32 = crc32_be(~0, initial_boot_params,
 				fdt_totalsize(initial_boot_params));
 
 	/* Initialize {size,address}-cells info */
 	early_init_dt_scan_root();
 
-- 
2.47.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] fdt: Extend warnings on error paths
  2025-04-23  9:10 [PATCH] fdt: Extend warnings on error paths Bartosz Szczepanek
@ 2025-04-23 20:23 ` Rob Herring
  0 siblings, 0 replies; 2+ messages in thread
From: Rob Herring @ 2025-04-23 20:23 UTC (permalink / raw)
  To: Bartosz Szczepanek
  Cc: Saravana Kannan, nh-open-source, devicetree, linux-kernel

On Wed, Apr 23, 2025 at 09:10:17AM +0000, Bartosz Szczepanek wrote:
> Print out adress and size if elfcorehdr is overlapped. Be more verbose
> about what went wrong in case early_init_dt_verify fails. Other than
> improving logging, no functional change is intended in this commit.
> 
> Signed-off-by: Bartosz Szczepanek <bsz@amazon.de>
> ---
>  drivers/of/fdt.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> index aedd0e2dcd89..c9b5e056b713 100644
> --- a/drivers/of/fdt.c
> +++ b/drivers/of/fdt.c
> @@ -469,21 +469,22 @@ static u32 of_fdt_crc32;
>   * described in the device tree. This region contains all the
>   * information about primary kernel's core image and is used by a dump
>   * capture kernel to access the system memory on primary kernel.
>   */
>  static void __init fdt_reserve_elfcorehdr(void)
>  {
>  	if (!IS_ENABLED(CONFIG_CRASH_DUMP) || !elfcorehdr_size)
>  		return;
>  
>  	if (memblock_is_region_reserved(elfcorehdr_addr, elfcorehdr_size)) {
> -		pr_warn("elfcorehdr is overlapped\n");
> +		pr_warn("elfcorehdr is overlapped (addr=0x%llx, size=%llu)\n",
> +			elfcorehdr_addr, elfcorehdr_size);
>  		return;
>  	}
>  
>  	memblock_reserve(elfcorehdr_addr, elfcorehdr_size);
>  
>  	pr_info("Reserving %llu KiB of memory at 0x%llx for elfcorehdr\n",
>  		elfcorehdr_size >> 10, elfcorehdr_addr);
>  }
>  
>  /**
> @@ -1128,26 +1129,33 @@ void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
>  	memblock_add(base, size);
>  }
>  
>  static void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
>  {
>  	return memblock_alloc_or_panic(size, align);
>  }
>  
>  bool __init early_init_dt_verify(void *dt_virt, phys_addr_t dt_phys)
>  {
> -	if (!dt_virt)
> +	int rc;
> +
> +	if (!dt_virt) {
> +		pr_warn("FDT wasn't correctly mapped");

You need a '\n' here. Technically, it doesn't, but IIRC it won't get 
flushed out immediately without. Of course, this runs too early to see 
the message typically.

It's possible some arch has a fallback if this function fails and 
doesn't want the warning, but we can apply and see.

>  		return false;
> +	}
>  
>  	/* check device tree validity */
> -	if (fdt_check_header(dt_virt))
> +	rc = fdt_check_header(dt_virt);
> +	if (rc) {
> +		pr_warn("FDT header is invalid: status=%d", rc);
>  		return false;
> +	}
>  
>  	/* Setup flat device-tree pointer */
>  	initial_boot_params = dt_virt;
>  	initial_boot_params_pa = dt_phys;
>  	of_fdt_crc32 = crc32_be(~0, initial_boot_params,
>  				fdt_totalsize(initial_boot_params));
>  
>  	/* Initialize {size,address}-cells info */
>  	early_init_dt_scan_root();

Normal context is 3 lines. Please send patches that way.

Rob

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-04-23 20:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-23  9:10 [PATCH] fdt: Extend warnings on error paths Bartosz Szczepanek
2025-04-23 20:23 ` Rob Herring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).