[U-Boot] [RFC][PATCH] Code Clean-up (weak functions)

Shinya Kuribayashi shinya.kuribayashi at necel.com
Thu Dec 25 01:56:37 CET 2008


Remy Bohmer wrote:
> Create a default fallback routine that can be used if there is no
> strong implementation:
> -------------------------------------------------------------------------------------------
> __attribute__((weak)) unsigned long long printk_clock(void)
> {
>         return sched_clock();
> }
> -------------------------------------------------------------------------------------------
> and here is an example of the strong implementation (from the ARM architecture):
> -------------------------------------------------------------------------------------------
> unsigned long long printk_clock(void)
> {
>         return (unsigned long long)(jiffies - INITIAL_JIFFIES) *
>                         (1000000000 / HZ);
> }
> -------------------------------------------------------------------------------------------
> 
> If the strong implementation is available, the weak is simply
> discarded during linking, if the strong is omitted, the weak is used
> as fallback. This is a clean, lean and mean example without
> complex/superfluous aliases or checks for NULL pointers.
> It should not get any harder than this...

+1.  I like this one, and U-Boot/MIPS _machine_restart() is implemented
in the same manner.

-- 
Shinya Kuribayashi
NEC Electronics


More information about the U-Boot mailing list