Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 20 May 2012 10:47:04 -0700
From:      Tim Kientzle <kientzle@freebsd.org>
To:        freebsd-current FreeBSD <freebsd-current@freebsd.org>, arm@freebsd.org
Subject:   Customizing ubldr build...
Message-ID:  <E84EA543-11A9-4EA6-9313-6908F485C569@freebsd.org>

next in thread | raw e-mail | index | archive | help
In order to fully automate building SD images for Beaglebone,
I'm trying to come up with a clean way to tailor the ubldr build.

I think I've come up with a good way to do this and would appreciate any =
feedback.

First, here's the (somewhat simplified) script that builds and installs =
ubldr (this
is going into the beaglebsd.sh script I've been working on):

 cd /usr/src
 buildenv=3D`make TARGET_ARCH=3Darm TARGET_CPUTYPE=3Darm buildenvvars`
 cd sys/boot
 eval $buildenv make obj
 eval $buildenv make UBLDR_LOADADDR=3D0x80100000 all
 cd arm/uboot
 eval $buildenv make DESTDIR=3D${DESTDIR}  BINDIR=3D  NO_MAN=3Dtrue =
install

The key issue is the physical load address, which differs among boards.
My idea is to allow specifying this at build time through a make
variable UBLDR_LOADADDR.

The Makefile for sys/boot/arm/uboot passes this down into a
dynamically-built loader script.  Here's a summary of the changes
I'm proposing to sys/boot/arm/uboot/Makefile:

+UBLDR_LOADADDR?=3D	0x1000000
=20
 LDFLAGS=3D	-nostdlib -static
+LDFLAGS+=3D	-T ldscript.generated
 LDFLAGS+=3D	-T ${.CURDIR}/ldscript.${MACHINE_CPUARCH}
=20
+${PROG}: ldscript.generated
+
+ldscript.generated::
+	echo "UBLDR_LOADADDR =3D ${UBLDR_LOADADDR};" > =
ldscript.generated

And now the standard loader script can simply use the symbol instead of
a hard-coded value:

 Index: ldscript.arm
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
 --- ldscript.arm	(revision 235597)
 +++ ldscript.arm	(working copy)
 @@ -5,7 +5,7 @@
  SECTIONS
  {
    /* Read-only sections, merged into text segment: */
 -  . =3D 0x1000000 + SIZEOF_HEADERS;
 +  . =3D UBLDR_LOADADDR + SIZEOF_HEADERS;
    .interp     : { *(.interp) 	}
    .hash          : { *(.hash)		}
    .dynsym        : { *(.dynsym)		}

This seems to work pretty well for me, except for one odd point:
the make dependencies cause ubldr to get relinked on every build.
(This can be fixed in the usual way.)

If anyone sees a better way to handle this, I'd much appreciate the =
input.

Cheers,

Tim




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E84EA543-11A9-4EA6-9313-6908F485C569>