[U-Boot] [PATCH 0/2] RFC: make U-boot fully PIC

Joakim Tjernlund Joakim.Tjernlund at transmode.se
Thu Oct 29 17:13:42 CET 2009


U-boot must be linked to the correct startup address in
flash so that global data acceses work before relocation to
RAM.

This patch demonstrates the changes needed in common
code needed to run from any link address.
With these changes and a few asm insn in start.S
I can link my u-boot to address 0 and still boot linux.

I am posting this for comment only and what I want to know
if this change to common code is accepable or not.
if so, I will send a formal patch for 83xx

The size cost is about 500 text bytes:
   text	   data	    bss	    dec	    hex	filename
 229544	  14876	  27608	 272028	  4269c	u-boot
 230008	  14872	  27608	 272488	  42868	u-boot.link_off

link_off looks like this currently:
	.globl link_off /* const void * link_off(const void * ptr) */
link_off:
	/* Adds GOT offset to ptr, might be useful for true PIC too */
	/* Would be great if this could be inline C __asm__ instead */
	/* Hand coded as we cannot clobber r14 when called from C */
	mflr	r4
	bl	1f
	.text	2
0:	.long	.LCTOC1-1f
	.text
1:	mflr	r6
	lwz	r0,0b-1b(r6)
	add	r6,r0,r6
	mtlr	r4
	la	r4,.L__GOT2_TABLE_(r6) /* addi	r4,r6,.L__GOT2_TABLE_ */
	lwz	r5,.L__GOT2_TABLE_(r6)
	sub	r4,r5,r4 /* r4 - r5 */
	sub	r3,r3,r4 /* r4 - r3 */
	blr

WD, what do you think?

Joakim Tjernlund (2):
  Use LINK_OFF to access global data
  Use LINK_OFF in enviroment too

 common/cmd_nvedit.c           |    2 +
 common/console.c              |   12 ++++++--
 common/env_common.c           |    2 +-
 common/env_flash.c            |   65 ++++++++++++++++++++++++----------------
 cpu/mpc83xx/cpu.c             |   10 +++---
 cpu/mpc83xx/cpu_init.c        |   26 +++++++++-------
 cpu/mpc83xx/speed.c           |   28 +++++++-----------
 drivers/serial/serial.c       |   21 +++++++------
 include/common.h              |    1 -
 include/linux/ctype.h         |    6 ++--
 lib_generic/crc32.c           |    7 ++++-
 lib_generic/ctype.c           |    2 +-
 lib_generic/display_options.c |    5 ++-
 lib_generic/vsprintf.c        |    9 ++++--
 lib_ppc/board.c               |    5 ++-
 tools/updater/ctype.c         |    2 +-
 16 files changed, 115 insertions(+), 88 deletions(-)



More information about the U-Boot mailing list