diff mbox

[U-Boot] make hang() a weak function

Message ID 1366107249-24547-1-git-send-email-andreas.devel@googlemail.com
State Rejected
Delegated to: Wolfgang Denk
Headers show

Commit Message

Andreas Bießmann April 16, 2013, 10:14 a.m. UTC
This patch also does some minor coding style cleanups.

Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>

---
 arch/arm/lib/board.c            |    3 ++-
 arch/avr32/lib/board.c          |    3 ++-
 arch/blackfin/lib/board.c       |    3 ++-
 arch/m68k/lib/board.c           |    3 ++-
 arch/microblaze/lib/board.c     |    5 +++--
 arch/mips/lib/board.c           |    3 ++-
 arch/nds32/lib/board.c          |    3 ++-
 arch/nios2/lib/board.c          |    5 +++--
 arch/openrisc/lib/board.c       |    3 ++-
 arch/powerpc/lib/board.c        |    4 ++--
 arch/sandbox/lib/board.c        |    3 ++-
 arch/sh/lib/board.c             |    3 ++-
 arch/sparc/lib/board.c          |    3 ++-
 arch/x86/lib/board.c            |    3 ++-
 common/board_f.c                |    3 ++-
 common/spl/spl.c                |    3 ++-
 drivers/mtd/nand/mxc_nand_spl.c |    3 ++-
 17 files changed, 36 insertions(+), 20 deletions(-)

Comments

Stefan Roese April 16, 2013, 10:29 a.m. UTC | #1
Hi Andreas,

On 16.04.2013 12:14, Andreas Bießmann wrote:
> This patch also does some minor coding style cleanups.
> 
> Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>
> 
> ---
>  arch/arm/lib/board.c            |    3 ++-
>  arch/avr32/lib/board.c          |    3 ++-
>  arch/blackfin/lib/board.c       |    3 ++-
>  arch/m68k/lib/board.c           |    3 ++-
>  arch/microblaze/lib/board.c     |    5 +++--
>  arch/mips/lib/board.c           |    3 ++-
>  arch/nds32/lib/board.c          |    3 ++-
>  arch/nios2/lib/board.c          |    5 +++--
>  arch/openrisc/lib/board.c       |    3 ++-
>  arch/powerpc/lib/board.c        |    4 ++--
>  arch/sandbox/lib/board.c        |    3 ++-
>  arch/sh/lib/board.c             |    3 ++-
>  arch/sparc/lib/board.c          |    3 ++-
>  arch/x86/lib/board.c            |    3 ++-
>  common/board_f.c                |    3 ++-
>  common/spl/spl.c                |    3 ++-
>  drivers/mtd/nand/mxc_nand_spl.c |    3 ++-
>  17 files changed, 36 insertions(+), 20 deletions(-)
> 
> diff --git a/arch/arm/lib/board.c b/arch/arm/lib/board.c
> index 0521178..4a00e16 100644
> --- a/arch/arm/lib/board.c
> +++ b/arch/arm/lib/board.c
> @@ -707,8 +707,9 @@ void board_init_r(gd_t *id, ulong dest_addr)
>  	/* NOTREACHED - no way out of command loop except booting */
>  }
>  
> -void hang(void)
> +void __hang(void)
>  {
>  	puts("### ERROR ### Please RESET the board ###\n");
>  	for (;;);
>  }
> +void hang(void) __attribute__((weak, alias("__hang")));

Please include "linux/compiler.h" and use:

void __weak hang(void)
{
	puts("### ERROR ### Please RESET the board ###\n");
	for (;;);
}

instead. No __attribute__ needed and easier to read.

Thanks,
Stefan
Graeme Russ April 16, 2013, 11:10 a.m. UTC | #2
Hi Andreas,


On Tue, Apr 16, 2013 at 8:14 PM, Andreas Bießmann <
andreas.devel@googlemail.com> wrote:

> This patch also does some minor coding style cleanups.
>
>
Coding style cleanups belong in a separate patch - Rules are rules ;)

Regards,

Graeme
Albert ARIBAUD April 16, 2013, 11:36 a.m. UTC | #3
Hi Andreas,

On Tue, 16 Apr 2013 12:14:09 +0200, Andreas Bießmann
<andreas.devel@googlemail.com> wrote:

> This patch also does some minor coding style cleanups.
> 
> Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>
> 
> ---
>  arch/arm/lib/board.c            |    3 ++-
>  arch/avr32/lib/board.c          |    3 ++-
>  arch/blackfin/lib/board.c       |    3 ++-
>  arch/m68k/lib/board.c           |    3 ++-
>  arch/microblaze/lib/board.c     |    5 +++--
>  arch/mips/lib/board.c           |    3 ++-
>  arch/nds32/lib/board.c          |    3 ++-
>  arch/nios2/lib/board.c          |    5 +++--
>  arch/openrisc/lib/board.c       |    3 ++-
>  arch/powerpc/lib/board.c        |    4 ++--
>  arch/sandbox/lib/board.c        |    3 ++-
>  arch/sh/lib/board.c             |    3 ++-
>  arch/sparc/lib/board.c          |    3 ++-
>  arch/x86/lib/board.c            |    3 ++-
>  common/board_f.c                |    3 ++-
>  common/spl/spl.c                |    3 ++-
>  drivers/mtd/nand/mxc_nand_spl.c |    3 ++-
>  17 files changed, 36 insertions(+), 20 deletions(-)
> 
> diff --git a/arch/arm/lib/board.c b/arch/arm/lib/board.c
> index 0521178..4a00e16 100644
> --- a/arch/arm/lib/board.c
> +++ b/arch/arm/lib/board.c
> @@ -707,8 +707,9 @@ void board_init_r(gd_t *id, ulong dest_addr)
>  	/* NOTREACHED - no way out of command loop except booting */
>  }
>  
> -void hang(void)
> +void __hang(void)
>  {
>  	puts("### ERROR ### Please RESET the board ###\n");
>  	for (;;);
>  }
> +void hang(void) __attribute__((weak, alias("__hang")));
> diff --git a/arch/avr32/lib/board.c b/arch/avr32/lib/board.c
> index 57e07df..7e3380a 100644
> --- a/arch/avr32/lib/board.c
> +++ b/arch/avr32/lib/board.c
> @@ -120,10 +120,11 @@ static int display_banner (void)
>  	return 0;
>  }
>  
> -void hang(void)
> +void __hang(void)
>  {
>  	for (;;) ;
>  }
> +void hang(void) __attribute__((weak, alias("__hang")));
>  
>  static int display_dram_config (void)
>  {
> diff --git a/arch/blackfin/lib/board.c b/arch/blackfin/lib/board.c
> index 75b6c46..7769962 100644
> --- a/arch/blackfin/lib/board.c
> +++ b/arch/blackfin/lib/board.c
> @@ -433,7 +433,7 @@ void board_init_r(gd_t * id, ulong dest_addr)
>  		main_loop();
>  }
>  
> -void hang(void)
> +void __hang(void)
>  {
>  #ifdef CONFIG_STATUS_LED
>  	status_led_set(STATUS_LED_BOOT, STATUS_LED_OFF);
> @@ -446,3 +446,4 @@ void hang(void)
>  		 */
>  		asm("emuexcpt;");
>  }
> +void hang(void) __attribute__((weak, alias("__hang"));
> diff --git a/arch/m68k/lib/board.c b/arch/m68k/lib/board.c
> index adaccfe..93aeafb 100644
> --- a/arch/m68k/lib/board.c
> +++ b/arch/m68k/lib/board.c
> @@ -665,8 +665,9 @@ void board_init_r (gd_t *id, ulong dest_addr)
>  }
>  
>  
> -void hang(void)
> +void __hang(void)
>  {
>  	puts ("### ERROR ### Please RESET the board ###\n");
>  	for (;;);
>  }
> +void hang(void) __attribute__((weak, alias("__hang")));
> diff --git a/arch/microblaze/lib/board.c b/arch/microblaze/lib/board.c
> index a7c2f76..e661704 100644
> --- a/arch/microblaze/lib/board.c
> +++ b/arch/microblaze/lib/board.c
> @@ -195,8 +195,9 @@ void board_init_f(ulong not_used)
>  	}
>  }
>  
> -void hang (void)
> +void __hang(void)
>  {
> -	puts ("### ERROR ### Please RESET the board ###\n");
> +	puts("### ERROR ### Please RESET the board ###\n");
>  	for (;;) ;
>  }
> +void hang(void) __attribute__((weak, alias("__hang")));
> diff --git a/arch/mips/lib/board.c b/arch/mips/lib/board.c
> index f19f198..ad18440 100644
> --- a/arch/mips/lib/board.c
> +++ b/arch/mips/lib/board.c
> @@ -345,9 +345,10 @@ void board_init_r(gd_t *id, ulong dest_addr)
>  	/* NOTREACHED - no way out of command loop except booting */
>  }
>  
> -void hang(void)
> +void __hang(void)
>  {
>  	puts("### ERROR ### Please RESET the board ###\n");
>  	for (;;)
>  		;
>  }
> +void hang(void) __attribute__((weak, alias("__hang")));
> diff --git a/arch/nds32/lib/board.c b/arch/nds32/lib/board.c
> index a7d27fc..2433d8a 100644
> --- a/arch/nds32/lib/board.c
> +++ b/arch/nds32/lib/board.c
> @@ -405,9 +405,10 @@ void board_init_r(gd_t *id, ulong dest_addr)
>  	/* NOTREACHED - no way out of command loop except booting */
>  }
>  
> -void hang(void)
> +void __hang(void)
>  {
>  	puts("### ERROR ### Please RESET the board ###\n");
>  	for (;;)
>  		;
>  }
> +void hang(void) __attribute__((weak, alias("__hang")));
> diff --git a/arch/nios2/lib/board.c b/arch/nios2/lib/board.c
> index 1e495d4..517a3a1 100644
> --- a/arch/nios2/lib/board.c
> +++ b/arch/nios2/lib/board.c
> @@ -168,9 +168,10 @@ void board_init (void)
>  
>  /***********************************************************************/
>  
> -void hang (void)
> +void __hang(void)
>  {
> -	disable_interrupts ();
> +	disable_interrupts();
>  	puts("### ERROR ### Please reset board ###\n");
>  	for (;;);
>  }
> +void hang(void) __attribute__((weak, alias("__hang")));
> diff --git a/arch/openrisc/lib/board.c b/arch/openrisc/lib/board.c
> index 85aa189..c5437db 100644
> --- a/arch/openrisc/lib/board.c
> +++ b/arch/openrisc/lib/board.c
> @@ -158,7 +158,7 @@ void board_init(void)
>  
>  /***********************************************************************/
>  
> -void hang(void)
> +void __hang(void)
>  {
>  	disable_interrupts();
>  	puts("### ERROR ### Please reset board ###\n");
> @@ -166,3 +166,4 @@ void hang(void)
>  	for (;;)
>  		;
>  }
> +void hang(void) __attribute__((weak, alias("__hang")));
> diff --git a/arch/powerpc/lib/board.c b/arch/powerpc/lib/board.c
> index 422b4a3..24bb948 100644
> --- a/arch/powerpc/lib/board.c
> +++ b/arch/powerpc/lib/board.c
> @@ -1050,14 +1050,14 @@ void board_init_r(gd_t *id, ulong dest_addr)
>  	/* NOTREACHED - no way out of command loop except booting */
>  }
>  
> -void hang(void)
> +void __hang(void)
>  {
>  	puts("### ERROR ### Please RESET the board ###\n");
>  	bootstage_error(BOOTSTAGE_ID_NEED_RESET);
>  	for (;;)
>  		;
>  }
> -
> +void hang(void) __attribute__((weak, alias("__hang")));
>  
>  #if 0	/* We could use plain global data, but the resulting code is bigger */
>  /*
> diff --git a/arch/sandbox/lib/board.c b/arch/sandbox/lib/board.c
> index 3752fab..fe10e6c 100644
> --- a/arch/sandbox/lib/board.c
> +++ b/arch/sandbox/lib/board.c
> @@ -277,9 +277,10 @@ void board_init_r(gd_t *id, ulong dest_addr)
>  	/* NOTREACHED - no way out of command loop except booting */
>  }
>  
> -void hang(void)
> +void __hang(void)
>  {
>  	puts("### ERROR ### Please RESET the board ###\n");
>  	for (;;)
>  		;
>  }
> +void hang(void) __attribute__((weak, alias("__hang")));
> diff --git a/arch/sh/lib/board.c b/arch/sh/lib/board.c
> index 6e43acf..60be847 100644
> --- a/arch/sh/lib/board.c
> +++ b/arch/sh/lib/board.c
> @@ -203,9 +203,10 @@ void sh_generic_init(void)
>  
>  /***********************************************************************/
>  
> -void hang(void)
> +void __hang(void)
>  {
>  	puts("Board ERROR\n");
>  	for (;;)
>  		;
>  }
> +void hang(void) __attribute__((weak, alias("__hang")));
> diff --git a/arch/sparc/lib/board.c b/arch/sparc/lib/board.c
> index 79fb4c8..ddd735c 100644
> --- a/arch/sparc/lib/board.c
> +++ b/arch/sparc/lib/board.c
> @@ -411,7 +411,7 @@ void board_init_f(ulong bootflag)
>  
>  }
>  
> -void hang(void)
> +void __hang(void)
>  {
>  	puts("### ERROR ### Please RESET the board ###\n");
>  #ifdef CONFIG_SHOW_BOOT_PROGRESS
> @@ -419,5 +419,6 @@ void hang(void)
>  #endif
>  	for (;;) ;
>  }
> +void hang(void) __attribute__((weak, alias("__hang")));
>  
>  /************************************************************************/
> diff --git a/arch/x86/lib/board.c b/arch/x86/lib/board.c
> index f372898..960f323 100644
> --- a/arch/x86/lib/board.c
> +++ b/arch/x86/lib/board.c
> @@ -265,9 +265,10 @@ void board_init_r(gd_t *id, ulong dest_addr)
>  	/* NOTREACHED - no way out of command loop except booting */
>  }
>  
> -void hang(void)
> +void __hang(void)
>  {
>  	puts("### ERROR ### Please RESET the board ###\n");
>  	for (;;)
>  		;
>  }
> +void hang(void) __attribute__((weak, alias("__hang")));
> diff --git a/common/board_f.c b/common/board_f.c
> index 7698891..d811067 100644
> --- a/common/board_f.c
> +++ b/common/board_f.c
> @@ -1005,8 +1005,9 @@ void board_init_f_r(void)
>  }
>  #endif /* CONFIG_X86 */
>  
> -void hang(void)
> +void __hang(void)
>  {
>  	puts("### ERROR ### Please RESET the board ###\n");
>  	for (;;);
>  }
> +void hang(void) __attribute__((weak, alias("__hang")));
> diff --git a/common/spl/spl.c b/common/spl/spl.c
> index 6715e0d..322b7b8 100644
> --- a/common/spl/spl.c
> +++ b/common/spl/spl.c
> @@ -48,12 +48,13 @@ struct spl_image_info spl_image;
>  /* Define board data structure */
>  static bd_t bdata __attribute__ ((section(".data")));
>  
> -inline void hang(void)
> +inline void __hang(void)
>  {
>  	puts("### ERROR ### Please RESET the board ###\n");
>  	for (;;)
>  		;
>  }
> +void hang(void) __attribute__((weak, alias("__hang")));
>  
>  /*
>   * Default function to determine if u-boot or the OS should
> diff --git a/drivers/mtd/nand/mxc_nand_spl.c b/drivers/mtd/nand/mxc_nand_spl.c
> index 09f23c3..9738045 100644
> --- a/drivers/mtd/nand/mxc_nand_spl.c
> +++ b/drivers/mtd/nand/mxc_nand_spl.c
> @@ -359,8 +359,9 @@ void nand_boot(void)
>  /*
>   * Called in case of an exception.
>   */
> -void hang(void)
> +void __hang(void)
>  {
>  	/* Loop forever */
>  	while (1) ;
>  }
> +void hang(void) __attribute__((weak, alias("__hang")));

Apart from Stefan's comments: considered standalone, doesn't this patch
have zero effect? I suspect you intend to use this in a later patch,
and if so, I would suggest grouping these in a series so that the
subsequent patch(es) explain this one.

Amicalement,
Andreas Bießmann April 16, 2013, 11:45 a.m. UTC | #4
Hi Albert,

On 04/16/2013 01:36 PM, Albert ARIBAUD wrote:
> Hi Andreas,
> 
> On Tue, 16 Apr 2013 12:14:09 +0200, Andreas Bießmann
> <andreas.devel@googlemail.com> wrote:
> 
>> This patch also does some minor coding style cleanups.
>>
>> Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>
>>
>> ---
>>  arch/arm/lib/board.c            |    3 ++-
>>  arch/avr32/lib/board.c          |    3 ++-
>>  arch/blackfin/lib/board.c       |    3 ++-
>>  arch/m68k/lib/board.c           |    3 ++-
>>  arch/microblaze/lib/board.c     |    5 +++--
>>  arch/mips/lib/board.c           |    3 ++-
>>  arch/nds32/lib/board.c          |    3 ++-
>>  arch/nios2/lib/board.c          |    5 +++--
>>  arch/openrisc/lib/board.c       |    3 ++-
>>  arch/powerpc/lib/board.c        |    4 ++--
>>  arch/sandbox/lib/board.c        |    3 ++-
>>  arch/sh/lib/board.c             |    3 ++-
>>  arch/sparc/lib/board.c          |    3 ++-
>>  arch/x86/lib/board.c            |    3 ++-
>>  common/board_f.c                |    3 ++-
>>  common/spl/spl.c                |    3 ++-
>>  drivers/mtd/nand/mxc_nand_spl.c |    3 ++-
>>  17 files changed, 36 insertions(+), 20 deletions(-)

<snip>

> 
> Apart from Stefan's comments: considered standalone, doesn't this patch
> have zero effect? I suspect you intend to use this in a later patch,
> and if so, I would suggest grouping these in a series so that the
> subsequent patch(es) explain this one.

I would like to use a specialized hang() for a not mainlined board, thus
there will no more patches using this currently.

Best regards

Andreas Bießmann
Wolfgang Denk April 16, 2013, 12:22 p.m. UTC | #5
Dear "Andreas Bießmann",

In message <516D39CF.9020907@gmail.com> you wrote:
> 
> > Apart from Stefan's comments: considered standalone, doesn't this patch
> > have zero effect? I suspect you intend to use this in a later patch,
> > and if so, I would suggest grouping these in a series so that the
> > subsequent patch(es) explain this one.
> 
> I would like to use a specialized hang() for a not mainlined board, thus
> there will no more patches using this currently.

So it is dead code in mainline, and we will not add it.


Best regards,

Wolfgang Denk
Andreas Bießmann April 16, 2013, 12:58 p.m. UTC | #6
Dear Wolfgang Denk,

On 04/16/2013 02:22 PM, Wolfgang Denk wrote:
> Dear "Andreas Bießmann",
> 
> In message <516D39CF.9020907@gmail.com> you wrote:
>>
>>> Apart from Stefan's comments: considered standalone, doesn't this patch
>>> have zero effect? I suspect you intend to use this in a later patch,
>>> and if so, I would suggest grouping these in a series so that the
>>> subsequent patch(es) explain this one.
>>
>> I would like to use a specialized hang() for a not mainlined board, thus
>> there will no more patches using this currently.
> 
> So it is dead code in mainline, and we will not add it.

Well, I don't think it is dead code cause the hang() is called in some ways.
This patch opens just the possibility to specialize the hang() by for
example a specific board. Maybe this could also be used for specific
hang() for different arches when we get closer to the common board files.
It is correct that we do not need this patch now and I can handle it
here in my own tree.

Best regards

Andreas Bießmann
Wolfgang Denk April 16, 2013, 1:05 p.m. UTC | #7
Dear Andreas,

In message <516D4B00.9030102@gmail.com> you wrote:
>
> > So it is dead code in mainline, and we will not add it.
> 
> Well, I don't think it is dead code cause the hang() is called in some ways.
> This patch opens just the possibility to specialize the hang() by for
> example a specific board. Maybe this could also be used for specific
> hang() for different arches when we get closer to the common board files.

I think it is dead code, and not needed nor useful in mainline.  I
cannot even see how it would be useful for you.  hang() is defined to
"hang" the CPU, i. e. to make sure the system will remain in the
current state.  To me this naturally translates into an infinite loop,
the implementation of which is completely hardware and architecture
independent.

Note that hang() is not supposed to do anything else, it just hangs
the system.  If you have a debugger attached, you will be able to do a
simple stack backtrace and see exactly where you are hanging, and why.

If you think you need to have specialized code, you are doing
something wrong.

> It is correct that we do not need this patch now and I can handle it
> here in my own tree.

Good.

Best regards,

Wolfgang Denk
Andreas Bießmann April 16, 2013, 1:32 p.m. UTC | #8
Dear Wolfgang,

On 04/16/2013 03:05 PM, Wolfgang Denk wrote:
> Dear Andreas,
> 
> In message <516D4B00.9030102@gmail.com> you wrote:
>>
>>> So it is dead code in mainline, and we will not add it.
>>
>> Well, I don't think it is dead code cause the hang() is called in some ways.
>> This patch opens just the possibility to specialize the hang() by for
>> example a specific board. Maybe this could also be used for specific
>> hang() for different arches when we get closer to the common board files.
> 
> I think it is dead code, and not needed nor useful in mainline.  I
> cannot even see how it would be useful for you.  hang() is defined to
> "hang" the CPU, i. e. to make sure the system will remain in the
> current state.  To me this naturally translates into an infinite loop,
> the implementation of which is completely hardware and architecture
> independent.

Yes it is independent (or should at least). But there are still slightly
different versions:

---8<---
arch/blackfin/lib/board.c:void hang(void)
arch/blackfin/lib/board.c-{
arch/blackfin/lib/board.c-#ifdef CONFIG_STATUS_LED
arch/blackfin/lib/board.c-      status_led_set(STATUS_LED_BOOT,
STATUS_LED_OFF);
arch/blackfin/lib/board.c-      status_led_set(STATUS_LED_CRASH,
STATUS_LED_BLINKING);
--->8---

---8<---
arch/arm/lib/board.c:void __hang(void)
arch/arm/lib/board.c-{
arch/arm/lib/board.c-   puts("### ERROR ### Please RESET the board ###\n");
arch/arm/lib/board.c-   for (;;);
arch/arm/lib/board.c-}
--->8---

---8<---
arch/powerpc/lib/board.c:void __hang(void)
arch/powerpc/lib/board.c-{
arch/powerpc/lib/board.c-       puts("### ERROR ### Please RESET the
board ###\n");
arch/powerpc/lib/board.c-       bootstage_error(BOOTSTAGE_ID_NEED_RESET);
arch/powerpc/lib/board.c-       for (;;)
--->8---

> Note that hang() is not supposed to do anything else, it just hangs
> the system.  If you have a debugger attached, you will be able to do a
> simple stack backtrace and see exactly where you are hanging, and why.

Well, for this specific board I plan to panic() on wrong hardware
detection (which will in turn call hang()). My requirements say that I
have to visualize this state then, I thought it would be a good idea to
blink some lights in the endless loop in hang() for this specific board.

> If you think you need to have specialized code, you are doing
> something wrong.

Really? How would you solve this requirement?

Best regards

Andreas Bießmann
Graeme Russ April 16, 2013, 1:35 p.m. UTC | #9
Hi Andreas,


On Tue, Apr 16, 2013 at 11:32 PM, Andreas Bießmann <
andreas.devel@googlemail.com> wrote:
>
> Dear Wolfgang,
>
> On 04/16/2013 03:05 PM, Wolfgang Denk wrote:
> > Dear Andreas,
> >
> > In message <516D4B00.9030102@gmail.com> you wrote:
> >>
> >>> So it is dead code in mainline, and we will not add it.
> >>
> >> Well, I don't think it is dead code cause the hang() is called in some
ways.
> >> This patch opens just the possibility to specialize the hang() by for
> >> example a specific board. Maybe this could also be used for specific
> >> hang() for different arches when we get closer to the common board
files.
> >
> > I think it is dead code, and not needed nor useful in mainline.  I
> > cannot even see how it would be useful for you.  hang() is defined to
> > "hang" the CPU, i. e. to make sure the system will remain in the
> > current state.  To me this naturally translates into an infinite loop,
> > the implementation of which is completely hardware and architecture
> > independent.
>
> Yes it is independent (or should at least). But there are still slightly
> different versions:
>
> ---8<---
> arch/blackfin/lib/board.c:void hang(void)
> arch/blackfin/lib/board.c-{
> arch/blackfin/lib/board.c-#ifdef CONFIG_STATUS_LED
> arch/blackfin/lib/board.c-      status_led_set(STATUS_LED_BOOT,
> STATUS_LED_OFF);
> arch/blackfin/lib/board.c-      status_led_set(STATUS_LED_CRASH,
> STATUS_LED_BLINKING);
> --->8---
>
> ---8<---
> arch/arm/lib/board.c:void __hang(void)
> arch/arm/lib/board.c-{
> arch/arm/lib/board.c-   puts("### ERROR ### Please RESET the board
###\n");
> arch/arm/lib/board.c-   for (;;);
> arch/arm/lib/board.c-}
> --->8---
>
> ---8<---
> arch/powerpc/lib/board.c:void __hang(void)
> arch/powerpc/lib/board.c-{
> arch/powerpc/lib/board.c-       puts("### ERROR ### Please RESET the
> board ###\n");
> arch/powerpc/lib/board.c-       bootstage_error(BOOTSTAGE_ID_NEED_RESET);
> arch/powerpc/lib/board.c-       for (;;)
> --->8---

I think that ultimately there should only be a single hang() function

> > Note that hang() is not supposed to do anything else, it just hangs
> > the system.  If you have a debugger attached, you will be able to do a
> > simple stack backtrace and see exactly where you are hanging, and why.
>
> Well, for this specific board I plan to panic() on wrong hardware
> detection (which will in turn call hang()). My requirements say that I
> have to visualize this state then, I thought it would be a good idea to
> blink some lights in the endless loop in hang() for this specific board.
>
> > If you think you need to have specialized code, you are doing
> > something wrong.
>
> Really? How would you solve this requirement?

Doesn't it make  sense to use panic()?

Regards,

Graeme
Andreas Bießmann April 16, 2013, 2:15 p.m. UTC | #10
Hi Graeme,

On 04/16/2013 03:35 PM, Graeme Russ wrote:
> Hi Andreas,
> 
> On Tue, Apr 16, 2013 at 11:32 PM, Andreas Bießmann
> <andreas.devel@googlemail.com <mailto:andreas.devel@googlemail.com>> wrote:
>>
>> Dear Wolfgang,
>>
>> On 04/16/2013 03:05 PM, Wolfgang Denk wrote:
>> > Dear Andreas,
>> >
>> > In message <516D4B00.9030102@gmail.com
> <mailto:516D4B00.9030102@gmail.com>> you wrote:

<snip>

> I think that ultimately there should only be a single hang() function

Ok.

>> > Note that hang() is not supposed to do anything else, it just hangs
>> > the system.  If you have a debugger attached, you will be able to do a
>> > simple stack backtrace and see exactly where you are hanging, and why.
>>
>> Well, for this specific board I plan to panic() on wrong hardware
>> detection (which will in turn call hang()). My requirements say that I
>> have to visualize this state then, I thought it would be a good idea to
>> blink some lights in the endless loop in hang() for this specific board.
>>
>> > If you think you need to have specialized code, you are doing
>> > something wrong.
>>
>> Really? How would you solve this requirement?
> 
> Doesn't it make  sense to use panic()?

In my opinion it makes sense to panic(). In my special case I also need
to hang() when panic(). The next question is then how to visualize the
(end-)user of that device that we hang().

Best regards

Andreas Bießmann
Wolfgang Denk April 16, 2013, 2:17 p.m. UTC | #11
Dear Andreas,

In message <516D52EE.1040402@gmail.com> you wrote:
> 
> Yes it is independent (or should at least). But there are still slightly
> different versions:

Yes, I know :-(

> ---8<---
> arch/powerpc/lib/board.c:void __hang(void)
> arch/powerpc/lib/board.c-{
> arch/powerpc/lib/board.c-       puts("### ERROR ### Please RESET the
> board ###\n");
> arch/powerpc/lib/board.c-       bootstage_error(BOOTSTAGE_ID_NEED_RESET);
> arch/powerpc/lib/board.c-       for (;;)
> --->8---

This is probably what the generic code should look like.

> > Note that hang() is not supposed to do anything else, it just hangs
> > the system.  If you have a debugger attached, you will be able to do a
> > simple stack backtrace and see exactly where you are hanging, and why.
> 
> Well, for this specific board I plan to panic() on wrong hardware
> detection (which will in turn call hang()). My requirements say that I
> have to visualize this state then, I thought it would be a good idea to
> blink some lights in the endless loop in hang() for this specific board.
> 
> > If you think you need to have specialized code, you are doing
> > something wrong.
> 
> Really? How would you solve this requirement?

Turn on the blinking in panic(), before calling hang().  This requires
that you have some way to blink a LED when the CPU is hanging in an
endlss loop, though.

In general, panic() and hang() are for fatal errors where no way of
recovery is possible and where you cannot make any assumptions about
remaining (or even allowed) functionality. The puts() and
bootstage_*() calls above are already stretching the design pretty
far.  We should not add more functionality here.

Best regards,

Wolfgang Denk
Graeme Russ April 16, 2013, 2:20 p.m. UTC | #12
Hi Andreas,


On Wed, Apr 17, 2013 at 12:15 AM, Andreas Bießmann <
andreas.devel@googlemail.com> wrote:
>
> Hi Graeme,
>
> On 04/16/2013 03:35 PM, Graeme Russ wrote:
> > Hi Andreas,
> >
> > On Tue, Apr 16, 2013 at 11:32 PM, Andreas Bießmann
> > <andreas.devel@googlemail.com <mailto:andreas.devel@googlemail.com>>
wrote:
> >>
> >> Dear Wolfgang,
> >>
> >> On 04/16/2013 03:05 PM, Wolfgang Denk wrote:
> >> > Dear Andreas,
> >> >
> >> > In message <516D4B00.9030102@gmail.com
> > <mailto:516D4B00.9030102@gmail.com>> you wrote:
>
> <snip>
>
> > I think that ultimately there should only be a single hang() function
>
> Ok.
>
> >> > Note that hang() is not supposed to do anything else, it just hangs
> >> > the system.  If you have a debugger attached, you will be able to do
a
> >> > simple stack backtrace and see exactly where you are hanging, and
why.
> >>
> >> Well, for this specific board I plan to panic() on wrong hardware
> >> detection (which will in turn call hang()). My requirements say that I
> >> have to visualize this state then, I thought it would be a good idea to
> >> blink some lights in the endless loop in hang() for this specific
board.
> >>
> >> > If you think you need to have specialized code, you are doing
> >> > something wrong.
> >>
> >> Really? How would you solve this requirement?
> >
> > Doesn't it make  sense to use panic()?
>
> In my opinion it makes sense to panic(). In my special case I also need
> to hang() when panic(). The next question is then how to visualize the
> (end-)user of that device that we hang().

In panic()?

My thought would be along the lines of:
 - Detect something fatal
 - Call panic()
 - Do something to alert the user - puts(), start a LED blinking, etc.
 - Stay in panic() if you need CPU cycles to  keep alerting the user (LED
blinking for example)
 - Call hang() if you've done everything you can

Regards,

Graeme
Wolfgang Denk April 16, 2013, 2:23 p.m. UTC | #13
Dear Andreas,

In message <516D5D0A.20403@gmail.com> you wrote:
> 
> In my opinion it makes sense to panic(). In my special case I also need
> to hang() when panic(). The next question is then how to visualize the
> (end-)user of that device that we hang().

The intention behind hang() is to stop doing anything, i. e. to idle
the board.  Nothing else.

We can argue if this is always a good thing to do.  For example, in
some situations it may be possible to switch off the board instead.
Or, as in your case, to run some code to visualize the state.

I fully agree that these are perfectly reasonable use cases for fatal
error handling in U-Boot.  But then, these are not functions to be
implemented in the context of hang().  Hang is a synonym for "place
the CPU into an infinite loop and stop doing anything else".

If you call hang() you agree to hang the system.

If you want to do something else, then please do not call hang(), but
some other function.

Best regards,

Wolfgang Denk
Andreas Bießmann April 16, 2013, 2:40 p.m. UTC | #14
Dear Wolfgang,

On 04/16/2013 04:23 PM, Wolfgang Denk wrote:
> Dear Andreas,
> 
> In message <516D5D0A.20403@gmail.com> you wrote:
>>
>> In my opinion it makes sense to panic(). In my special case I also need
>> to hang() when panic(). The next question is then how to visualize the
>> (end-)user of that device that we hang().
> 
> The intention behind hang() is to stop doing anything, i. e. to idle
> the board.  Nothing else.
> 
> We can argue if this is always a good thing to do.  For example, in
> some situations it may be possible to switch off the board instead.
> Or, as in your case, to run some code to visualize the state.
> 
> I fully agree that these are perfectly reasonable use cases for fatal
> error handling in U-Boot.  But then, these are not functions to be
> implemented in the context of hang().  Hang is a synonym for "place
> the CPU into an infinite loop and stop doing anything else".
> 
> If you call hang() you agree to hang the system.

I got your point.

> If you want to do something else, then please do not call hang(), but
> some other function.

I will find a solution for my very specific state of the device.

But how about other places in u-boot hang()ing the device? How can we
tell the user that state without a terminal? If one plugs a uart cable
he might see some cause of the hang() but this is not acceptable for
some groups of users.
Is it wise to completely stop a device without showing the state to the
user?
This question is a bit hypothetical cause we should eliminate the root
causes for hang()s before going to market. However I would like to hear
your thoughts about that.

Best regards

Andreas Bießmann
Wolfgang Denk April 16, 2013, 3:14 p.m. UTC | #15
Dear Andreas,

In message <516D62E1.7090306@gmail.com> you wrote:
>
> But how about other places in u-boot hang()ing the device? How can we
> tell the user that state without a terminal? If one plugs a uart cable
> he might see some cause of the hang() but this is not acceptable for
> some groups of users.
> Is it wise to completely stop a device without showing the state to the
> user?

If you want to tell the user, this should be done _before_ calling
hang() - if you decide to hang() your board.  Keep in mind that you
don't have to define CONFIG_PANIC_HANG.

Also, as done in arch/powerpc/lib/board.c we usually print an error
message on the console device, and we can call bootstage_error(),
which could initialte such actions.

> This question is a bit hypothetical cause we should eliminate the root
> causes for hang()s before going to market. However I would like to hear
> your thoughts about that.

You cannot eliminate all causes that will lead a board to run into
hang().  There may be simply broken hardware, for example...

Best regards,

Wolfgang Denk
Andreas Bießmann April 16, 2013, 3:34 p.m. UTC | #16
Dear Wolfgang,

On 04/16/2013 05:14 PM, Wolfgang Denk wrote:
> Dear Andreas,
> 
> In message <516D62E1.7090306@gmail.com> you wrote:
>>
>> But how about other places in u-boot hang()ing the device? How can we
>> tell the user that state without a terminal? If one plugs a uart cable
>> he might see some cause of the hang() but this is not acceptable for
>> some groups of users.
>> Is it wise to completely stop a device without showing the state to the
>> user?
> 
> If you want to tell the user, this should be done _before_ calling
> hang() - if you decide to hang() your board.  

Well, that is my point. We have about 40 places where we may hang() a
arm device:

---8<---
abiessmann@punisher % git grep "hang(" drivers/ arch/arm/ | wc -l
40
--->8---

You say (or at least I understand you so), that I have to hack all these
places with some application specific stuff to inform the user of the
device that we will stop processing now. Why don't we add an interface
to easily change the behavior of hang application specific.

> Keep in mind that you
> don't have to define CONFIG_PANIC_HANG.

Thats true, but in some cases we just want to hang on panic.

> Also, as done in arch/powerpc/lib/board.c we usually print an error
> message on the console device, and we can call bootstage_error(),
> which could initialte such actions.

Ahhh ... I got it. So this is the interface I want! All we need is
bootstage_error() in all hang() variants and thats it.

>> This question is a bit hypothetical cause we should eliminate the root
>> causes for hang()s before going to market. However I would like to hear
>> your thoughts about that.
> 
> You cannot eliminate all causes that will lead a board to run into
> hang().  There may be simply broken hardware, for example...

Thats true.

Best regards

Andreas Bießmann
Wolfgang Denk April 16, 2013, 4 p.m. UTC | #17
Dear Andreas,

In message <516D6F71.8090304@gmail.com> you wrote:
> 
> You say (or at least I understand you so), that I have to hack all these
> places with some application specific stuff to inform the user of the
> device that we will stop processing now. Why don't we add an interface
> to easily change the behavior of hang application specific.

Because hang() is a trivial function that does just what the name
says.  If you don't want this, then don't use this.  If you need
additional functionality, then use a function that provides such.

> > Keep in mind that you
> > don't have to define CONFIG_PANIC_HANG.
> 
> Thats true, but in some cases we just want to hang on panic.

Indeed.  Normally this is the most useful thing to do.

> > Also, as done in arch/powerpc/lib/board.c we usually print an error
> > message on the console device, and we can call bootstage_error(),
> > which could initialte such actions.
> 
> Ahhh ... I got it. So this is the interface I want! All we need is
> bootstage_error() in all hang() variants and thats it.

As you have to touch all these places anyway, please rather move
hang() out of all architecture specific code and place it in the
global lib/.

Best regards,

Wolfgang Denk
Andreas Bießmann April 16, 2013, 4:14 p.m. UTC | #18
Dear Wolfgang,

On 16.04.13 18:00, Wolfgang Denk wrote:
> Dear Andreas,
> 
> In message <516D6F71.8090304@gmail.com> you wrote:

>>> Also, as done in arch/powerpc/lib/board.c we usually print an error
>>> message on the console device, and we can call bootstage_error(),
>>> which could initialte such actions.
>>
>> Ahhh ... I got it. So this is the interface I want! All we need is
>> bootstage_error() in all hang() variants and thats it.
> 
> As you have to touch all these places anyway, please rather move
> hang() out of all architecture specific code and place it in the
> global lib/.

will do.

Best regards

Andreas Bießmann
Andreas Bießmann April 17, 2013, 11:02 a.m. UTC | #19
This series started with intention to make a hung board visualize the
(end-)user that it does hang(). The first approach was to make all the
different hang() functions weak and provide board specific versions to
implement the 'visualization' there.
After some discussion it turned out, that there is still an interface to
visualize such states to the user: the 'bootstage' stuff.

BTW:
This is my first try sending a series with patman. All I can say is:
patman is really cool ;)

The 'microblaze: fix style in board.c' is an leftover from the first approach.

The 'nios2: fix style in board.c' is an leftover from the first approach.

The 'lib: consolidate hang()' is build tested on arm and avr32. It may
produces errors on other arches like ppc cause the previous SPL inlined hang()
function was also removed.  We need to discuss if we always pull in the
libgeneric unconditional into SPL or provide a second hang() for those boards
which do not link against libgeneric in SPL.

Changes in v2:
 * delete all hang() and provide generic lib/hang.c

Andreas Bießmann (5):
  microblaze: fix style in board.c
  nios2: fix style in board.c.
  mx31pdk: add CONFIG_SPL_LIBGENERIC_SUPPORT
  tx25: add CONFIG_SPL_LIBGENERIC_SUPPORT
  lib: consolidate hang()

 arch/arm/cpu/arm926ejs/mxs/spl_boot.c |    8 +----
 arch/arm/cpu/arm926ejs/spear/spl.c    |    7 ----
 arch/arm/lib/board.c                  |    7 +---
 arch/avr32/lib/board.c                |    6 +---
 arch/blackfin/lib/board.c             |   15 +-------
 arch/m68k/lib/board.c                 |    7 ----
 arch/microblaze/lib/board.c           |   63 +++++++++++++++------------------
 arch/mips/lib/board.c                 |    8 +----
 arch/nds32/lib/board.c                |    8 +----
 arch/nios2/lib/board.c                |   47 ++++++++++--------------
 arch/openrisc/lib/board.c             |   13 +------
 arch/powerpc/lib/board.c              |   10 +-----
 arch/sandbox/lib/board.c              |    8 +----
 arch/sh/lib/board.c                   |   10 +-----
 arch/sparc/lib/board.c                |   10 +-----
 arch/x86/lib/board.c                  |    8 +----
 common/board_f.c                      |    6 ----
 common/spl/spl.c                      |    7 ----
 drivers/mtd/nand/mxc_nand_spl.c       |   10 +-----
 include/configs/mx31pdk.h             |    1 +
 include/configs/tx25.h                |    1 +
 lib/Makefile                          |    1 +
 lib/hang.c                            |   47 ++++++++++++++++++++++++
 23 files changed, 109 insertions(+), 199 deletions(-)
 create mode 100644 lib/hang.c
Wolfgang Denk April 18, 2013, 7:40 p.m. UTC | #20
Dear Andreas,

In message <1366196568-23008-1-git-send-email-andreas.devel@googlemail.com> you wrote:
>
> Andreas Bießmann (5):
>   microblaze: fix style in board.c
>   nios2: fix style in board.c.
>   mx31pdk: add CONFIG_SPL_LIBGENERIC_SUPPORT
>   tx25: add CONFIG_SPL_LIBGENERIC_SUPPORT
>   lib: consolidate hang()

Compile-tested for Power architecture.  No new warnings / errors
found.

Tested-by: Wolfgang Denk <wd@denx.de>
Acked-by: Wolfgang Denk <wd@denx.de>

Best regards,

Wolfgang Denk
Andreas Bießmann April 19, 2013, 8:48 a.m. UTC | #21
This series started with intention to make a hung board visualize the
(end-)user that it does hang(). The first approach was to make all the
different hang() functions weak and provide board specific versions to
implement the 'visualization' there.
After some discussion it turned out, that there is still an interface to
visualize such states to the user: the 'bootstage' stuff.

BTW:
This is my first try sending a series with patman. All I can say is:
patman is really cool ;)

The 'microblaze: fix style in board.c' is an leftover from the first approach.

The 'nios2: fix style in board.c' is an leftover from the first approach.

The 'lib: consolidate hang()' is build tested on arm and avr32. It may
produces errors on other arches like ppc cause the previous SPL inlined hang()
function was also removed.  We need to discuss if we always pull in the
libgeneric unconditional into SPL or provide a second hang() for those boards
which do not link against libgeneric in SPL.

Since v2 got a complete (compile-)test on powerpc by Wolfgang I think we can
stick with the current solution.  v3 includes some minor changes mentioned in
the changelog of respective patches.

Changes in v3:
 * shorten error string for 'no FDT'
 * remove unnecessarily added linux/compiler.h
 * fix typo in new hang() docu
 * use simplified macro for SPL_LIBCOMMON_SUPPORT as suggested by Benoît

Changes in v2:
 * delete all hang() and provide generic lib/hang.c

Andreas Bießmann (5):
  microblaze: fix style in board.c
  nios2: fix style in board.c.
  mx31pdk: add CONFIG_SPL_LIBGENERIC_SUPPORT
  tx25: add CONFIG_SPL_LIBGENERIC_SUPPORT
  lib: consolidate hang()

 arch/arm/cpu/arm926ejs/mxs/spl_boot.c |    7 ----
 arch/arm/cpu/arm926ejs/spear/spl.c    |    7 ----
 arch/arm/lib/board.c                  |    6 ----
 arch/avr32/lib/board.c                |    5 ---
 arch/blackfin/lib/board.c             |   14 --------
 arch/m68k/lib/board.c                 |    7 ----
 arch/microblaze/lib/board.c           |   62 ++++++++++++++-------------------
 arch/mips/lib/board.c                 |    7 ----
 arch/nds32/lib/board.c                |    7 ----
 arch/nios2/lib/board.c                |   46 +++++++++---------------
 arch/openrisc/lib/board.c             |   12 -------
 arch/powerpc/lib/board.c              |    9 -----
 arch/sandbox/lib/board.c              |    7 ----
 arch/sh/lib/board.c                   |    9 -----
 arch/sparc/lib/board.c                |    9 -----
 arch/x86/lib/board.c                  |    7 ----
 common/board_f.c                      |    6 ----
 common/spl/spl.c                      |    7 ----
 drivers/mtd/nand/mxc_nand_spl.c       |    9 -----
 include/configs/mx31pdk.h             |    1 +
 include/configs/tx25.h                |    1 +
 lib/Makefile                          |    1 +
 lib/hang.c                            |   46 ++++++++++++++++++++++++
 23 files changed, 93 insertions(+), 199 deletions(-)
 create mode 100644 lib/hang.c
Simon Glass April 25, 2013, 9:44 p.m. UTC | #22
Hi Andreas,

On Fri, Apr 19, 2013 at 1:48 AM, Andreas Bießmann
<andreas.devel@googlemail.com> wrote:
> This series started with intention to make a hung board visualize the
> (end-)user that it does hang(). The first approach was to make all the
> different hang() functions weak and provide board specific versions to
> implement the 'visualization' there.
> After some discussion it turned out, that there is still an interface to
> visualize such states to the user: the 'bootstage' stuff.
>
> BTW:
> This is my first try sending a series with patman. All I can say is:
> patman is really cool ;)
>
> The 'microblaze: fix style in board.c' is an leftover from the first approach.
>
> The 'nios2: fix style in board.c' is an leftover from the first approach.
>
> The 'lib: consolidate hang()' is build tested on arm and avr32. It may
> produces errors on other arches like ppc cause the previous SPL inlined hang()
> function was also removed.  We need to discuss if we always pull in the
> libgeneric unconditional into SPL or provide a second hang() for those boards
> which do not link against libgeneric in SPL.
>
> Since v2 got a complete (compile-)test on powerpc by Wolfgang I think we can
> stick with the current solution.  v3 includes some minor changes mentioned in
> the changelog of respective patches.

This series tested on snow with CONFIG_SYS_GENERIC_BOARD enabled. No
warnings or problems noted and hang() still works.

Tested-by: Simon Glass <sjg@chromium.org>
Acked-by: Simon Glass <sjg@chromium.org>

>
> Changes in v3:
>  * shorten error string for 'no FDT'
>  * remove unnecessarily added linux/compiler.h
>  * fix typo in new hang() docu
>  * use simplified macro for SPL_LIBCOMMON_SUPPORT as suggested by Benoît
>
> Changes in v2:
>  * delete all hang() and provide generic lib/hang.c
>
> Andreas Bießmann (5):
>   microblaze: fix style in board.c
>   nios2: fix style in board.c.
>   mx31pdk: add CONFIG_SPL_LIBGENERIC_SUPPORT
>   tx25: add CONFIG_SPL_LIBGENERIC_SUPPORT
>   lib: consolidate hang()
>
Tom Rini May 2, 2013, 4:06 p.m. UTC | #23
On Fri, Apr 19, 2013 at 10:48:45AM +0200, Andreas Bie??mann wrote:

> This series started with intention to make a hung board visualize the
> (end-)user that it does hang(). The first approach was to make all the
> different hang() functions weak and provide board specific versions to
> implement the 'visualization' there.
> After some discussion it turned out, that there is still an interface to
> visualize such states to the user: the 'bootstage' stuff.

With a change to 5/5, applied to u-boot/master, thanks!
diff mbox

Patch

diff --git a/arch/arm/lib/board.c b/arch/arm/lib/board.c
index 0521178..4a00e16 100644
--- a/arch/arm/lib/board.c
+++ b/arch/arm/lib/board.c
@@ -707,8 +707,9 @@  void board_init_r(gd_t *id, ulong dest_addr)
 	/* NOTREACHED - no way out of command loop except booting */
 }
 
-void hang(void)
+void __hang(void)
 {
 	puts("### ERROR ### Please RESET the board ###\n");
 	for (;;);
 }
+void hang(void) __attribute__((weak, alias("__hang")));
diff --git a/arch/avr32/lib/board.c b/arch/avr32/lib/board.c
index 57e07df..7e3380a 100644
--- a/arch/avr32/lib/board.c
+++ b/arch/avr32/lib/board.c
@@ -120,10 +120,11 @@  static int display_banner (void)
 	return 0;
 }
 
-void hang(void)
+void __hang(void)
 {
 	for (;;) ;
 }
+void hang(void) __attribute__((weak, alias("__hang")));
 
 static int display_dram_config (void)
 {
diff --git a/arch/blackfin/lib/board.c b/arch/blackfin/lib/board.c
index 75b6c46..7769962 100644
--- a/arch/blackfin/lib/board.c
+++ b/arch/blackfin/lib/board.c
@@ -433,7 +433,7 @@  void board_init_r(gd_t * id, ulong dest_addr)
 		main_loop();
 }
 
-void hang(void)
+void __hang(void)
 {
 #ifdef CONFIG_STATUS_LED
 	status_led_set(STATUS_LED_BOOT, STATUS_LED_OFF);
@@ -446,3 +446,4 @@  void hang(void)
 		 */
 		asm("emuexcpt;");
 }
+void hang(void) __attribute__((weak, alias("__hang"));
diff --git a/arch/m68k/lib/board.c b/arch/m68k/lib/board.c
index adaccfe..93aeafb 100644
--- a/arch/m68k/lib/board.c
+++ b/arch/m68k/lib/board.c
@@ -665,8 +665,9 @@  void board_init_r (gd_t *id, ulong dest_addr)
 }
 
 
-void hang(void)
+void __hang(void)
 {
 	puts ("### ERROR ### Please RESET the board ###\n");
 	for (;;);
 }
+void hang(void) __attribute__((weak, alias("__hang")));
diff --git a/arch/microblaze/lib/board.c b/arch/microblaze/lib/board.c
index a7c2f76..e661704 100644
--- a/arch/microblaze/lib/board.c
+++ b/arch/microblaze/lib/board.c
@@ -195,8 +195,9 @@  void board_init_f(ulong not_used)
 	}
 }
 
-void hang (void)
+void __hang(void)
 {
-	puts ("### ERROR ### Please RESET the board ###\n");
+	puts("### ERROR ### Please RESET the board ###\n");
 	for (;;) ;
 }
+void hang(void) __attribute__((weak, alias("__hang")));
diff --git a/arch/mips/lib/board.c b/arch/mips/lib/board.c
index f19f198..ad18440 100644
--- a/arch/mips/lib/board.c
+++ b/arch/mips/lib/board.c
@@ -345,9 +345,10 @@  void board_init_r(gd_t *id, ulong dest_addr)
 	/* NOTREACHED - no way out of command loop except booting */
 }
 
-void hang(void)
+void __hang(void)
 {
 	puts("### ERROR ### Please RESET the board ###\n");
 	for (;;)
 		;
 }
+void hang(void) __attribute__((weak, alias("__hang")));
diff --git a/arch/nds32/lib/board.c b/arch/nds32/lib/board.c
index a7d27fc..2433d8a 100644
--- a/arch/nds32/lib/board.c
+++ b/arch/nds32/lib/board.c
@@ -405,9 +405,10 @@  void board_init_r(gd_t *id, ulong dest_addr)
 	/* NOTREACHED - no way out of command loop except booting */
 }
 
-void hang(void)
+void __hang(void)
 {
 	puts("### ERROR ### Please RESET the board ###\n");
 	for (;;)
 		;
 }
+void hang(void) __attribute__((weak, alias("__hang")));
diff --git a/arch/nios2/lib/board.c b/arch/nios2/lib/board.c
index 1e495d4..517a3a1 100644
--- a/arch/nios2/lib/board.c
+++ b/arch/nios2/lib/board.c
@@ -168,9 +168,10 @@  void board_init (void)
 
 /***********************************************************************/
 
-void hang (void)
+void __hang(void)
 {
-	disable_interrupts ();
+	disable_interrupts();
 	puts("### ERROR ### Please reset board ###\n");
 	for (;;);
 }
+void hang(void) __attribute__((weak, alias("__hang")));
diff --git a/arch/openrisc/lib/board.c b/arch/openrisc/lib/board.c
index 85aa189..c5437db 100644
--- a/arch/openrisc/lib/board.c
+++ b/arch/openrisc/lib/board.c
@@ -158,7 +158,7 @@  void board_init(void)
 
 /***********************************************************************/
 
-void hang(void)
+void __hang(void)
 {
 	disable_interrupts();
 	puts("### ERROR ### Please reset board ###\n");
@@ -166,3 +166,4 @@  void hang(void)
 	for (;;)
 		;
 }
+void hang(void) __attribute__((weak, alias("__hang")));
diff --git a/arch/powerpc/lib/board.c b/arch/powerpc/lib/board.c
index 422b4a3..24bb948 100644
--- a/arch/powerpc/lib/board.c
+++ b/arch/powerpc/lib/board.c
@@ -1050,14 +1050,14 @@  void board_init_r(gd_t *id, ulong dest_addr)
 	/* NOTREACHED - no way out of command loop except booting */
 }
 
-void hang(void)
+void __hang(void)
 {
 	puts("### ERROR ### Please RESET the board ###\n");
 	bootstage_error(BOOTSTAGE_ID_NEED_RESET);
 	for (;;)
 		;
 }
-
+void hang(void) __attribute__((weak, alias("__hang")));
 
 #if 0	/* We could use plain global data, but the resulting code is bigger */
 /*
diff --git a/arch/sandbox/lib/board.c b/arch/sandbox/lib/board.c
index 3752fab..fe10e6c 100644
--- a/arch/sandbox/lib/board.c
+++ b/arch/sandbox/lib/board.c
@@ -277,9 +277,10 @@  void board_init_r(gd_t *id, ulong dest_addr)
 	/* NOTREACHED - no way out of command loop except booting */
 }
 
-void hang(void)
+void __hang(void)
 {
 	puts("### ERROR ### Please RESET the board ###\n");
 	for (;;)
 		;
 }
+void hang(void) __attribute__((weak, alias("__hang")));
diff --git a/arch/sh/lib/board.c b/arch/sh/lib/board.c
index 6e43acf..60be847 100644
--- a/arch/sh/lib/board.c
+++ b/arch/sh/lib/board.c
@@ -203,9 +203,10 @@  void sh_generic_init(void)
 
 /***********************************************************************/
 
-void hang(void)
+void __hang(void)
 {
 	puts("Board ERROR\n");
 	for (;;)
 		;
 }
+void hang(void) __attribute__((weak, alias("__hang")));
diff --git a/arch/sparc/lib/board.c b/arch/sparc/lib/board.c
index 79fb4c8..ddd735c 100644
--- a/arch/sparc/lib/board.c
+++ b/arch/sparc/lib/board.c
@@ -411,7 +411,7 @@  void board_init_f(ulong bootflag)
 
 }
 
-void hang(void)
+void __hang(void)
 {
 	puts("### ERROR ### Please RESET the board ###\n");
 #ifdef CONFIG_SHOW_BOOT_PROGRESS
@@ -419,5 +419,6 @@  void hang(void)
 #endif
 	for (;;) ;
 }
+void hang(void) __attribute__((weak, alias("__hang")));
 
 /************************************************************************/
diff --git a/arch/x86/lib/board.c b/arch/x86/lib/board.c
index f372898..960f323 100644
--- a/arch/x86/lib/board.c
+++ b/arch/x86/lib/board.c
@@ -265,9 +265,10 @@  void board_init_r(gd_t *id, ulong dest_addr)
 	/* NOTREACHED - no way out of command loop except booting */
 }
 
-void hang(void)
+void __hang(void)
 {
 	puts("### ERROR ### Please RESET the board ###\n");
 	for (;;)
 		;
 }
+void hang(void) __attribute__((weak, alias("__hang")));
diff --git a/common/board_f.c b/common/board_f.c
index 7698891..d811067 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -1005,8 +1005,9 @@  void board_init_f_r(void)
 }
 #endif /* CONFIG_X86 */
 
-void hang(void)
+void __hang(void)
 {
 	puts("### ERROR ### Please RESET the board ###\n");
 	for (;;);
 }
+void hang(void) __attribute__((weak, alias("__hang")));
diff --git a/common/spl/spl.c b/common/spl/spl.c
index 6715e0d..322b7b8 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -48,12 +48,13 @@  struct spl_image_info spl_image;
 /* Define board data structure */
 static bd_t bdata __attribute__ ((section(".data")));
 
-inline void hang(void)
+inline void __hang(void)
 {
 	puts("### ERROR ### Please RESET the board ###\n");
 	for (;;)
 		;
 }
+void hang(void) __attribute__((weak, alias("__hang")));
 
 /*
  * Default function to determine if u-boot or the OS should
diff --git a/drivers/mtd/nand/mxc_nand_spl.c b/drivers/mtd/nand/mxc_nand_spl.c
index 09f23c3..9738045 100644
--- a/drivers/mtd/nand/mxc_nand_spl.c
+++ b/drivers/mtd/nand/mxc_nand_spl.c
@@ -359,8 +359,9 @@  void nand_boot(void)
 /*
  * Called in case of an exception.
  */
-void hang(void)
+void __hang(void)
 {
 	/* Loop forever */
 	while (1) ;
 }
+void hang(void) __attribute__((weak, alias("__hang")));