[[RFC] 01/14] Add a tool to activate barebox as a boot loader on x86 architectures

Sascha Hauer s.hauer at pengutronix.de
Fri Dec 11 10:48:21 EST 2009


On Fri, Dec 11, 2009 at 02:21:43PM +0100, Juergen Beisert wrote:
> On Freitag, 11. Dezember 2009, Sascha Hauer wrote:
> > On Thu, Dec 10, 2009 at 06:25:28PM +0100, Juergen Beisert wrote:
> > > To use barebox as a BIOS based bootloader for x86 architectures, the
> > > binary must be patched to get it bootstrapped at runtime. The 'setupmbr'
> > > tool installs the barebox-binary to the given device node or image file
> > > and patch it in accordance to the needed sector information at runtime.
> > >
> > > Signed-off by: Juergen Beisert <jbe at pengutronix.de>
> > >
> > > ---
> > >  Doxyfile                    |    3
> > >  scripts/Makefile            |    4
> > >  scripts/setupmbr/Makefile   |    4
> > >  scripts/setupmbr/arch.h     |   55 +++
> > >  scripts/setupmbr/setupmbr.c |  705
> > > ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 769
> > > insertions(+), 2 deletions(-)
> > >
> > > Index: u-boot-2.0.0-rc10/scripts/Makefile
> > > ===================================================================
> > > --- u-boot-2.0.0-rc10.orig/scripts/Makefile
> > > +++ u-boot-2.0.0-rc10/scripts/Makefile
> > > @@ -24,5 +24,7 @@ hostprogs-y += unifdef
> > >  #subdir-$(CONFIG_MODVERSIONS) += genksyms
> > >  subdir-y                     += mod
> > >
> > > +subdir-$(CONFIG_X86)             += setupmbr
> > > +
> > >  # Let clean descend into subdirs
> > > -subdir-	+= basic kconfig
> > > +subdir-	+= basic kconfig setupmbr
> > > Index: u-boot-2.0.0-rc10/scripts/setupmbr/Makefile
> > > ===================================================================
> > > --- /dev/null
> > > +++ u-boot-2.0.0-rc10/scripts/setupmbr/Makefile
> > > @@ -0,0 +1,4 @@
> > > +HOST_EXTRACFLAGS=-I$(srctree)
> > > +
> > > +hostprogs-y  := setupmbr
> > > +always       := $(hostprogs-y)
> > > Index: u-boot-2.0.0-rc10/scripts/setupmbr/arch.h
> > > ===================================================================
> > > --- /dev/null
> > > +++ u-boot-2.0.0-rc10/scripts/setupmbr/arch.h
> > > @@ -0,0 +1,55 @@
> > > +
> > > +/* we need the one from the host */
> > > +#include <endian.h>
> > > +#include <stdint.h>
> > > +
> > > +/* Byte-orders.  */
> > > +#define swap16(x)	\
> > > +({ \
> > > +   uint16_t _x = (x); \
> > > +   (uint16_t) ((_x << 8) | (_x >> 8)); \
> > > +})
> > > +
> > > +#define swap32(x)	\
> > > +({ \
> > > +   uint32_t _x = (x); \
> > > +   (uint32_t) ((_x << 24) \
> > > +                    | ((_x & (uint32_t) 0xFF00UL) << 8) \
> > > +                    | ((_x & (uint32_t) 0xFF0000UL) >> 8) \
> > > +                    | (_x >> 24)); \
> > > +})
> > > +
> > > +#define swap64(x)	\
> > > +({ \
> > > +   uint64_t _x = (x); \
> > > +   (uint64_t) ((_x << 56) \
> > > +                    | ((_x & (uint64_t) 0xFF00ULL) << 40) \
> > > +                    | ((_x & (uint64_t) 0xFF0000ULL) << 24) \
> > > +                    | ((_x & (uint64_t) 0xFF000000ULL) << 8) \
> > > +                    | ((_x & (uint64_t) 0xFF00000000ULL) >> 8) \
> > > +                    | ((_x & (uint64_t) 0xFF0000000000ULL) >> 24) \
> > > +                    | ((_x & (uint64_t) 0xFF000000000000ULL) >> 40) \
> > > +                    | (_x >> 56)); \
> > > +})
> > > +
> > > +#if __BYTE_ORDER == __BIG_ENDIAN
> > > +
> > > +/* Our target is a ia32 machine, always little endian */
> > > +
> > > +# define host2target_16(x)	swap16(x)
> > > +# define host2target_32(x)	swap32(x)
> > > +# define host2target_64(x)	swap64(x)
> > > +# define target2host_16(x)	swap16(x)
> > > +# define target2host_32(x)	swap32(x)
> > > +# define target2host_64(x)	swap64(x)
> > > +
> > > +#else
> > > +
> > > +# define host2target_16(x)	(x)
> > > +# define host2target_32(x)	(x)
> > > +# define host2target_64(x)	(x)
> > > +# define target2host_16(x)	(x)
> > > +# define target2host_32(x)	(x)
> > > +# define target2host_64(x)	(x)
> >
> > endian.h defines htole[16|32|64] which should be what you need here.
> 
> Hmmm, I found these defines in a glibc-2.10, but not in a libc-2.8 based 
> system. Seems they where added between these revisions. Can we force a 
> glibc-2.10 system, to build this tool?

glibc-2.9 also contains these. I wasn't aware of the fact that these
macros are new, I just had a look on my host system. Maybe it's best to
keep it the way you did it.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |




More information about the u-boot-v2 mailing list