Skip to contentSkip to conversation

fdt: Avoid early panic() when there is no FDT present

PATCH In review Simon Glass 4 participants 9 messages Mar 28, 2012 – Mar 29, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 fdt: Avoid early panic() when there is no FDT present

CONFIG_OF_CONTROL requires a valid device tree. However, we cannot call panic() before the console is set up since the message does not appear, and we get a silent failure.

Remove the panic from fdtdec_check_fdt() and provide a new function to prepare the fdt for use. This will be called after the console is ready.

---
 include/fdtdec.h |   17 +++++++++++++++--
 lib/fdtdec.c     |   24 +++++++++++++++++++-----
 2 files changed, 34 insertions(+), 7 deletions(-)
include/fdtdec.h +15 -2
index 766e0bd..d45acbe 100644
@@ -157,8 +157,21 @@ s32 fdtdec_get_int(const void *blob, int node, const char *prop_name,
 int fdtdec_get_is_enabled(const void *blob, int node);
 
 /**
- * Checks whether we have a valid fdt available to control U-Boot, and panic
- * if not.
+ * Make sure we have a valid fdt available to control U-Boot.
+ *
+ * If not, a message is printed to the console if the console is ready.
+ *
+ * @return 0 if all ok, -1 if not
+ */
+int fdtdec_prepare_fdt(void);
+
+/**
+ * Checks that we have a valid fdt available to control U-Boot.
+
+ * However, if not then for the moment nothing is done, since this function
+ * is called too early to panic().
+ *
+ * @returns 0
  */
 int fdtdec_check_fdt(void);
 
lib/fdtdec.c +19 -5
index 9241d13..0fb6d17 100644
@@ -276,17 +276,31 @@ int fdtdec_add_aliases_for_id(const void *blob, const char *name,
 	return num_found;
 }
 
+int fdtdec_check_fdt(void)
+{
+	/*
+	 * We must have an FDT, but we cannot panic() yet since the console
+	 * is not ready. So for now, just assert(). Boards which need an early
+	 * FDT (prior to console ready) will need to make their own
+	 * arrangements and do their own checks.
+	 */
+	assert(!fdtdec_prepare_fdt());
+	return 0;
+}
+
 /*
  * This function is a little odd in that it accesses global data. At some
  * point if the architecture board.c files merge this will make more sense.
  * Even now, it is common code.
  */
-int fdtdec_check_fdt(void)
+int fdtdec_prepare_fdt(void)
 {
-	/* We must have an fdt */
-	if (((uintptr_t)gd->fdt_blob & 3) || fdt_check_header(gd->fdt_blob))
-		panic("No valid fdt found - please append one to U-Boot\n"
-			"binary or define CONFIG_OF_EMBED\n");
+	if (((uintptr_t)gd->fdt_blob & 3) || fdt_check_header(gd->fdt_blob)) {
+		printf("No valid FDT found - please append one to U-Boot "
+			"binary, use u-boot-dtb.bin or define "
+			"CONFIG_OF_EMBED\n");
+		return -1;
+	}
 	return 0;
 }
 
Signature · 1 line
1.7.7.3
#1 lore raw

PATCH 2/2 arm: Check for valid FDT after console is up

When using CONFIG_OF_CONTROL, add a check that we have a valid FDT and panic() if not. This must be done after the console is ready.

---
 arch/arm/lib/board.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
arch/arm/lib/board.c +8 -0
index 81293c3..ab88e9c 100644
@@ -291,6 +291,14 @@ void board_init_f(ulong bootflag)
 		}
 	}
 
+#ifdef CONFIG_OF_CONTROL
+	/* For now, put this check after the console is ready */
+	if (fdtdec_prepare_fdt()) {
+		panic("** CONFIG_OF_CONTROL defined but no FDT - please see "
+			"doc/README.fdt-control");
+	}
+#endif
+
 	debug("monitor len: %08lX\n", gd->mon_len);
 	/*
 	 * Ram is setup, size stored in gd !!
Signature · 1 line
1.7.7.3
#2 lore raw

PATCH 2/2 arm: Check for valid FDT after console is up

Simon,

Quoted 11 lines

-----Original Message-----
From: Simon Glass [mailto:sjg at chromium.org]
Sent: Wednesday, March 28, 2012 1:08 PM
To: U-Boot Mailing List
Cc: Tom Warren; Stephen Warren; Albert Aribaud; Simon Glass
Subject: [PATCH 2/2] arm: Check for valid FDT after console is up

When using CONFIG_OF_CONTROL, add a check that we have a valid FDT and panic() if not. This must be done after the console is ready.

This works (u-boot.bin gives an error message and then resets). If you're happy with the constant reset loop and not a hang, I'm OK with it, too.

Quoted 25 lines
---
 arch/arm/lib/board.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
arch/arm/lib/board.c index renamed from arch/arm/lib/board.c +0 -0

81293c3..ab88e9c 100644

arch/arm/lib/board.c +8 -1
@@ -291,6 +291,14 @@ void board_init_f(ulong bootflag)
 		}
 	}
 
+#ifdef CONFIG_OF_CONTROL
+	/* For now, put this check after the console is ready */
+	if (fdtdec_prepare_fdt()) {
+		panic("** CONFIG_OF_CONTROL defined but no FDT - please see "
+			"doc/README.fdt-control");
+	}
+#endif
+
 	debug("monitor len: %08lX\n", gd->mon_len);
 	/*
 	 * Ram is setup, size stored in gd !!
--

1.7.7.3

Signature · 1 line
nvpublic
#3 lore raw

PATCH 2/2 arm: Check for valid FDT after console is up

+Wolfgang

Hi Tom,

Quoted 12 lines · Tom Warren

Simon,

Quoted 10 lines

-----Original Message-----
From: Simon Glass [mailto:sjg at chromium.org]
Sent: Wednesday, March 28, 2012 1:08 PM
To: U-Boot Mailing List
Cc: Tom Warren; Stephen Warren; Albert Aribaud; Simon Glass
Subject: [PATCH 2/2] arm: Check for valid FDT after console is up

When using CONFIG_OF_CONTROL, add a check that we have a valid FDT and panic() if not. This must be done after the console is ready.

Quoted 6 lines
Quoted 1 line

This works (u-boot.bin gives an error message and then resets). If you're happy with the constant reset loop and not a hang, I'm OK with it, too.

Thanks. You can define CONFIG_PANIC_HANG for that behaviour.

I would like to get these applied for the upcoming release, since the recent revert of the pre-console putc() has left us otherwise completely without a solution to this problem.

Regards,
Simon

Quoted 28 lines
Quoted 22 lines

---
?arch/arm/lib/board.c | ? ?8 ++++++++
?1 files changed, 8 insertions(+), 0 deletions(-)

arch/arm/lib/board.c index renamed from arch/arm/lib/board.c +0 -0

81293c3..ab88e9c 100644

arch/arm/lib/board.c +8 -0
@@ -291,6 +291,14 @@ void board_init_f(ulong bootflag)
 ? ? ? ? ? ? ? }
 ? ? ? }
 
+#ifdef CONFIG_OF_CONTROL
+ ? ? /* For now, put this check after the console is ready */
+ ? ? if (fdtdec_prepare_fdt()) {
+ ? ? ? ? ? ? panic("** CONFIG_OF_CONTROL defined but no FDT - please see "
+ ? ? ? ? ? ? ? ? ? ? "doc/README.fdt-control");
+ ? ? }
+#endif
+
 ? ? ? debug("monitor len: %08lX\n", gd->mon_len);
Quoted 4 lines

? ? ? /*
? ? ? ?* Ram is setup, size stored in gd !!
--
1.7.7.3

--
nvpublic

#4 lore raw

PATCH 2/2 arm: Check for valid FDT after console is up

In reply to Simon Glass
Quoted 4 lines · Simon Glass

When using CONFIG_OF_CONTROL, add a check that we have a valid FDT and panic() if not. This must be done after the console is ready.

Excellent. The behavior after this series is exactly what I was looking for.

One query on this patch though: Is there a need for arch/arm/lib/board.c:init_sequence[] to still include the call to fdtdec_check_fdt()? After all, if the console doesn't come from FDT, then the panic() call this patch adds will show the message so there's no need to check it earlier, and if the console does come from FDT, there's little point executing that early assert() since the message goes nowhere - presumably the code that extracts the console from FDT would perform this panic if required. So, I would have just moved the call to the existing fdtdec_check_fdt() myself, rather than splitting it into two.

Still, as far as I'm concerned, this comment can be addressed in a later cleanup patch. So, the series:

#5 lore raw

PATCH 2/2 arm: Check for valid FDT after console is up

Hi Stephen,

Quoted 7 lines · Stephen Warren
Quoted 4 lines · Simon Glass

When using CONFIG_OF_CONTROL, add a check that we have a valid FDT and panic() if not. This must be done after the console is ready.

Excellent. The behavior after this series is exactly what I was looking for.

Thanks, I'm pleased. The behavior was never in question, only the means to make it work.

Quoted 11 lines

One query on this patch though: Is there a need for arch/arm/lib/board.c:init_sequence[] to still include the call to fdtdec_check_fdt()? After all, if the console doesn't come from FDT, then the panic() call this patch adds will show the message so there's no need to check it earlier, and if the console does come from FDT, there's little point executing that early assert() since the message goes nowhere - presumably the code that extracts the console from FDT would perform this panic if required. So, I would have just moved the call to the existing fdtdec_check_fdt() myself, rather than splitting it into two.

I did certainly look at this, but I know we are going to hit this problem again. As you say the console-from-FDT code will currently have to do its own check, and I'm not entirely comfortable with that - it would be nice it the fdtdec_check_fdt() could actually do something useful. But I'm going to wait until another sub-arch has FDT support (and I have put up my fdt_serial series) before worrying about it further.

Quoted 6 lines

Still, as far as I'm concerned, this comment can be addressed in a later cleanup patch. So, the series:

Great!

Regards,
Simon

Tested-by Acked-by on v1 1/2
#6 lore raw
In reply to Simon Glass

Simon,

Quoted 8 lines

-----Original Message-----
From: Simon Glass [mailto:[email protected]]
Sent: Wednesday, March 28, 2012 1:08 PM
To: U-Boot Mailing List
Cc: Tom Warren; Stephen Warren; Albert Aribaud; Simon Glass; Jerry Van Baren; Devicetree Discuss
Subject: [PATCH 1/2] fdt: Avoid early panic() when there is no FDT present

Quoted 8 lines

CONFIG_OF_CONTROL requires a valid device tree. However, we cannot call panic() before the console is set up since the message does not appear, and we get a silent failure.

Remove the panic from fdtdec_check_fdt() and provide a new function to prepare the fdt for use. This will be called after the console is ready.

Quoted 80 lines
---
 include/fdtdec.h |   17 +++++++++++++++--
 lib/fdtdec.c     |   24 +++++++++++++++++++-----
 2 files changed, 34 insertions(+), 7 deletions(-)
include/fdtdec.h index 766e0bd..d45acbe renamed from include/fdtdec.h +0 -0

100644

include/fdtdec.h +0 -1
@@ -157,8 +157,21 @@ s32 fdtdec_get_int(const void *blob, int node, const
 char *prop_name,  int fdtdec_get_is_enabled(const void *blob, int node);
 
 /**
- * Checks whether we have a valid fdt available to control U-Boot, and

panic
- * if not.
+ * Make sure we have a valid fdt available to control U-Boot.
+ *
+ * If not, a message is printed to the console if the console is ready.
+ *
+ * @return 0 if all ok, -1 if not
+ */

include/fdtdec.h +10 -0
+int fdtdec_prepare_fdt(void);
+
+/**
+ * Checks that we have a valid fdt available to control U-Boot.
+
+ * However, if not then for the moment nothing is done, since this
+ function
+ * is called too early to panic().
+ *
+ * @returns 0
  */
 int fdtdec_check_fdt(void);
lib/fdtdec.c +5 -0
@@ -276,17 +276,31 @@ int fdtdec_add_aliases_for_id(const void *blob, const
 char *name,
 	return num_found;
 }
 
+int fdtdec_check_fdt(void)
+{
+	/*
+	 * We must have an FDT, but we cannot panic() yet since the console
+	 * is not ready. So for now, just assert(). Boards which need an

early

lib/fdtdec.c +9 -5
+	 * FDT (prior to console ready) will need to make their own
+	 * arrangements and do their own checks.
+	 */
+	assert(!fdtdec_prepare_fdt());
+	return 0;
+}
+
 /*
  * This function is a little odd in that it accesses global data. At some
  * point if the architecture board.c files merge this will make more sense.
  * Even now, it is common code.
  */
-int fdtdec_check_fdt(void)
+int fdtdec_prepare_fdt(void)
 {
-	/* We must have an fdt */
-	if (((uintptr_t)gd->fdt_blob & 3) || fdt_check_header(gd->fdt_blob))
-		panic("No valid fdt found - please append one to U-Boot\n"
-			"binary or define CONFIG_OF_EMBED\n");
+	if (((uintptr_t)gd->fdt_blob & 3) || fdt_check_header(gd->fdt_blob))

{

lib/fdtdec.c +5 -1
+		printf("No valid FDT found - please append one to U-Boot "
+			"binary, use u-boot-dtb.bin or define "
+			"CONFIG_OF_EMBED\n");
+		return -1;
+	}
 	return 0;
 }
 
--

1.7.7.3

Signature · 1 line
nvpublic
#7 lore raw
In reply to Simon Glass

Dear Simon Glass,

Quoted 3 lines · In message <[email protected]> you wrote:

CONFIG_OF_CONTROL requires a valid device tree. However, we cannot call panic() before the console is set up since the message does not appear, and we get a silent failure.

...

include/fdtdec.h s32 fdtdec_get_int(const void *blob, int node, const char *prop_name, · line 174

Quoted 9 lines
include/fdtdec.h +9 -0
+int fdtdec_prepare_fdt(void);
+
+/**
+ * Checks that we have a valid fdt available to control U-Boot.
+
+ * However, if not then for the moment nothing is done, since this function
+ * is called too early to panic().
+ *
+ * @returns 0

If the function always returns 0, then it makes no sense to return any value at all. Please make it void, then.

lib/fdtdec.c int fdtdec_add_aliases_for_id(const void *blob, const char *name, · line 289

Quoted 11 lines
lib/fdtdec.c +11 -0
+int fdtdec_check_fdt(void)
+{
+	/*
+	 * We must have an FDT, but we cannot panic() yet since the console
+	 * is not ready. So for now, just assert(). Boards which need an early
+	 * FDT (prior to console ready) will need to make their own
+	 * arrangements and do their own checks.
+	 */
+	assert(!fdtdec_prepare_fdt());
+	return 0;
+}

Ditto - make that "void fdtdec_check_fdt(void)".

Quoted 1 line

+int fdtdec_prepare_fdt(void)

...

Quoted 2 lines

return 0;
}

Ditto - make that "void fdtdec_prepare_fdt(void)".

I have to admit that I do not understand how this patch will help you anything. You write "we cannot panic()", but "just assert()".

If the assertion fails, it will call __assert_fail() - which in turn will just call panic(). So you are out of the frying pan into the fire.

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: [email protected]
Life. Don't talk to me about life.      - Marvin the Paranoid Android
#8 lore raw

Hi Wolfgang,

Quoted 7 lines · Wolfgang Denk

Dear Simon Glass,

Quoted 3 lines · In message <[email protected]> you wrote:

CONFIG_OF_CONTROL requires a valid device tree. However, we cannot call panic() before the console is set up since the message does not appear, and we get a silent failure.

...

Quoted 12 lines

include/fdtdec.h s32 fdtdec_get_int(const void *blob, int node, const char *prop_name, · line 174

Quoted 9 lines
include/fdtdec.h +9 -0
+int fdtdec_prepare_fdt(void);
+
+/**
+ * Checks that we have a valid fdt available to control U-Boot.
+
+ * However, if not then for the moment nothing is done, since this function
+ * is called too early to panic().
+ *
+ * @returns 0

If the function always returns 0, then it makes no sense to return any value at all.  Please make it void, then.

fdtdec_check_fdt() is used in the ARM init sequence, so I need to follow that signature and return a value. In fact I must return 0 or the board will hang.

Quoted 15 lines

lib/fdtdec.c int fdtdec_add_aliases_for_id(const void *blob, const char *name, · line 289

Quoted 12 lines
lib/fdtdec.c +11 -0
+int fdtdec_check_fdt(void)
+{
+     /*
+      * We must have an FDT, but we cannot panic() yet since the console
+      * is not ready. So for now, just assert(). Boards which need an early
+      * FDT (prior to console ready) will need to make their own
+      * arrangements and do their own checks.
+      */
+     assert(!fdtdec_prepare_fdt());
+     return 0;
+}

Ditto - make that "void fdtdec_check_fdt(void)".

Quoted 6 lines
Quoted 1 line

+int fdtdec_prepare_fdt(void)

...

Quoted 2 lines

      return 0;
 }

Ditto - make that "void fdtdec_prepare_fdt(void)".

This fdtdec_prepare_fdt() is intended to provide a way to find out if there is a valid fdt. The 'return 0' that you have shown is only if it succeeds - it does actually return -1 on failure. I want a function which just checks this, and returns the result (rather than dying if it fails, which the behaviour that in principle I would like in the init sequence).

Quoted 8 lines

I have to admit that I do not understand how this patch will help you anything.  You write "we cannot panic()", but "just assert()".

If the assertion fails, it will call __assert_fail() - which in turn will just call panic().  So you are out of the frying pan into the fire.

Yes, but only if DEBUG is turned on in fdtdec. Otherwise we just continue and panic later when we can report the error.

Regards,
Simon

Quoted 10 lines

Best regards,

Wolfgang Denk

--
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: [email protected] Life. Don't talk to me about life.      - Marvin the Paranoid Android