[U-Boot] why u-boot relocate it self to RAM from flash?

Hi,
I can not understand why u-boot relocate it self to RAM from flash? Why is it not executing from flash? Can anybody explain.

Hi,
I can not understand why u-boot relocate it self to RAM from flash? Why is it not executing from flash? Can anybody explain.
First, flash is slow. Second, there are many data structures or variables which should be writable. So, we should copy u-boot to RAM and relocate it.
Regards

Hi,
On Tue, Dec 3, 2013 at 1:18 AM, FengHua fenghua@phytium.com.cn wrote:
Hi,
I can not understand why u-boot relocate it self to RAM from flash? Why
is
it not executing from flash? Can anybody explain.
First, flash is slow. Second, there are many data structures or variables which should be writable. So, we should copy u-boot to RAM and relocate it.
I'll expand a bit...
In theory the writeable could be relocated into RAM, but this would require the relocation address to be hard-coded. Optimally, U-Boot places itself in a memory location to provide the maximum contiguous memory space to load the operating system kernel and supporting data (RAM disks, FDTs, etc).
On most systems now, relocation is done by calculating the delta between the ROM address (TEXT_BASE) and the relocated address in RAM. The relocation code first copies the entire U-Boot image to RAM (apart from a few structures that are used only during the relocation calculation). It then scans the relocation entries (*.rel sections) to find where in the U-Boot executable all the references into the data sections. At each reference point in the executable, the relocation code modifies the reference by the relocation offset. None of this can happen if the U-Boot executable is in Flash.
The other advantage of relocating U-Boot to RAM is that it makes it possible to flash a new U-Boot image from U-Boot. If you try to do this while U-Boot is running from flash, it will crash as you are overwriting the executable code while it's executing.
Regards,
Graeme

Thank you very much for explanation both graeme and FengHua.
I think i have got best answer from you Graeme from entire web.
Thanks Tejas
On Tue, Dec 3, 2013 at 4:03 AM, Graeme Russ graeme.russ@gmail.com wrote:
Hi,
On Tue, Dec 3, 2013 at 1:18 AM, FengHua fenghua@phytium.com.cn wrote:
Hi,
I can not understand why u-boot relocate it self to RAM from flash? Why
is
it not executing from flash? Can anybody explain.
First, flash is slow. Second, there are many data structures or variables which should be writable. So, we should copy u-boot to RAM and relocate it.
I'll expand a bit...
In theory the writeable could be relocated into RAM, but this would require the relocation address to be hard-coded. Optimally, U-Boot places itself in a memory location to provide the maximum contiguous memory space to load the operating system kernel and supporting data (RAM disks, FDTs, etc).
On most systems now, relocation is done by calculating the delta between the ROM address (TEXT_BASE) and the relocated address in RAM. The relocation code first copies the entire U-Boot image to RAM (apart from a few structures that are used only during the relocation calculation). It then scans the relocation entries (*.rel sections) to find where in the U-Boot executable all the references into the data sections. At each reference point in the executable, the relocation code modifies the reference by the relocation offset. None of this can happen if the U-Boot executable is in Flash.
The other advantage of relocating U-Boot to RAM is that it makes it possible to flash a new U-Boot image from U-Boot. If you try to do this while U-Boot is running from flash, it will crash as you are overwriting the executable code while it's executing.
Regards,
Graeme

Dear tejas patel,
In message CAPWFgSA88DJF_Jm9MKTu53kpiNb7kqNcnuG6EDbA_W1MfHZO9Q@mail.gmail.com you wrote:
I can not understand why u-boot relocate it self to RAM from flash? Why is it not executing from flash? Can anybody explain.
There is a ton of reasons. One is that you cannot erase or program the flash device and execute code from it at the same time, so we would not be able to write a Linux kernel image - at least not without special flash drivers that execute from RAM. And we would not be able to update the U-Boot image in flash. etc. etc.
In the end it is much easier to run from RAM.
Best regards,
Wolfgang Denk
participants (4)
-
FengHua
-
Graeme Russ
-
tejas patel
-
Wolfgang Denk