[U-Boot] Code style questions (weak functions, cpu/ v's lib_arch/)

Graeme Russ graeme.russ at gmail.com
Tue Nov 18 23:35:04 CET 2008


Further to my question regarding weak functions versus conditional compile,
I have a couple of other 'style' questions:

1) I have seen two varying applications of __attribute__ ((weak)) - The
most common being of the form:

  function(args) __attribute__((weak,alias("__function")));

  __function(args)
  {
    /* Default functionality */
  };

The other is rare (occurs only 5 times in my slightly older code base)

  __attribute__((weak))
  function(args)
  {
    /* Default functionality */
  };

Is there any real difference between the two? Is there a reason for the
second one?

2) What defines if code belongs in cpu/<cpu_type> versus lib_<cpu_type>?
Reset vector and bootstrap code is fairly obvious, but I notice that
serial port functionality seems to be exclusively located in
cpu/<cpu_type>, interrupt handling seems to be a bit of a mix depending on
the particular cpu, lib_nios2\cache.S and lib_ppc\cache.c (to me) in an
odd location.

The reason I ask is that as part of my restructure of i386 / sc520, I want to
make sure the right code ends up in the right place. A couple of examples:
- Standard i386 interrupt handling uses 8259 PICs - This is an architectural
  thing, a not a hard and fast i386 cpu implementation. The sc520 has a more
  advanced on-chip PIC allowing up to 22 interrupts and dynamic routine of
  interrupt sources to interrupt priorities.
- The sc520 has a some very nice on-chip timers, i386 requires external
  timers and/or calibrated delay loops

So I am thinking to leave all _very_ i386 CPU specific code (reset vector,
bootstrap, real-to-protected mode switch, IDT, etc) in cpu/i386/ and create
a new cpu/i386/sc520/ folder for _very_ sc520 specific code (memory mapped
configuration register control, memory sizing). These two folders will
basically have all the low level assembler code.

I was then going to move timer control, PIC setup, and serial I/O into
lib_i386/ (and possible creating a sub folder lib_i386/sc520/ to hold the
sc520 specific timer, PIC setup, SSI functions.

Are there any hard and fast rules I should be using to increase the chances
of these changes making it into mainline more smoothly?

Regards,

Graeme


More information about the U-Boot mailing list