[U-Boot-Users] what's function of "absolute address" in these codes?

//codes from start.S of 74xx_7xx
===================================================================== START_GOT ...
. = EXC_OFF_SYS_RESET .globl _start _start: li r21, BOOTFLAG_COLD /* Normal Power-On: Boot from FLASH */ b boot_cold sync
...
boot_cold: boot_warm: /* disable everything */ ...
/* * Calculate absolute address in FLASH and jump there *------------------------------------------------------*/ lis r3, CFG_MONITOR_BASE@h ori r3, r3, CFG_MONITOR_BASE@l addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET // mtlr r3 //move contents in r3 to Link Register(LR) blr //branch to address in Link Register(LR)
in_flash: // /* let the C-code set up the rest */ /* */ /* Be careful to keep code relocatable ! */ /*------------------------------------------------------*/
========================================================================== why not use "bl in_flash" or simply comment these codes out? thank you.

xiangguo_li@hotmail.com wrote:
//codes from start.S of 74xx_7xx
===================================================================== START_GOT ...
. = EXC_OFF_SYS_RESET .globl _start _start: li r21, BOOTFLAG_COLD /* Normal Power-On: Boot from FLASH */ b boot_cold sync
...
boot_cold: boot_warm: /* disable everything */ ...
/*
- Calculate absolute address in FLASH and jump there
*------------------------------------------------------*/ lis r3, CFG_MONITOR_BASE@h mailto:CFG_MONITOR_BASE@h ori r3, r3, CFG_MONITOR_BASE@l mailto:CFG_MONITOR_BASE@l addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET // mtlr r3 //move contents in r3 to Link Register(LR) blr //branch to address in Link Register(LR)
in_flash: // /* let the C-code set up the rest */ /* */ /* Be careful to keep code relocatable ! */ /*------------------------------------------------------*/
========================================================================== why not use "bl in_flash" or simply comment these codes out? thank you.
Because the linked address of in_flash may not be where we want to have our flash and where we need to execute code. Typically on power up, flash is mapped everywhere in memory, which means there are replicated "copies" everywhere (e.g. if you have a 1MByte flash, your flash image is replicated every 1MByte). In the board configuration configuration, EXC_OFF_SYS_RESET identifies which "copy" you want to execute from (your runtime flash location, which is usually different from the start up location) and the above start up code picks the "correct copy" and jumps to it.
A little further on you will find code that does the memory map configuration which sets up the flash runtime location (making all the extra flash copies "disappear"), enables the RAM chip selects, etc. If the above start up code didn't jump to the correct "copy" of flash, the memory map initialization code would unmap flash out from under itself (your PC would be at in_flash+X rather than at EXC_OFF_SYS_RESET+in_flash+X) and your processor would crash.
HTH, gvb
participants (2)
-
Jerry Van Baren
-
xiangguo_li@hotmail.com