http://u-boot.10912.n7.nabble.com/why-u-boot-relocate-it-self-to-RAM-from-flash-td168729.html
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.
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
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: [hidden email]
http://blog.xuite.net/tzeng015/twblog/113272412-MIPS+u-boot+%E4%B8%ADcode+Relocate%E6%B5%81%E7%A8%8B%E5%88%86%E6%9E%90
注釋:
0xbf000000 是mips 24kc Flash起始的位置,也是reset
0x80000000是ar9132平台DDR的起始位置。
鏈接腳本中的0x00000000會被這個TEXT_BASE替代,可以觀察編譯時候的輸出,你會發現有一個-DTEXT_BASE=0xbf000000的選項。
Relocate的代碼在start.S中。
啟動的大致順序如下,假設代碼固化於flash起始位置。
CPU 上電
Reset(初始化cp0寄存器)
設置GOT
lowlevel_init(初始化SDRAM)
初始化cache
Relocate代碼
下面是代碼的入口
la t9, board_init_f
j t9
nop
這個board_init_f定義在lib_mips/board.c中。
這個程序為下列元素分配合適的內存空間:
[1] u-boot代碼(.text .data .bss)
[2] malloc空間 (相當於heap)
[3] Board Info
[4] Global Data
[5] Stack
這里可以看出malloc的空間位於heap中,即內存的高端,而函數中的局部變量,都在stack中的,在內存低端。
void board_init_f(ulong bootflag)
{
gd_t gd_data, *id;
bd_t *bd;
init_fnc_t **init_fnc_p
https://lxr.missinglinkelectronics.com/#uboot/doc/README.qemu-mips
uboot/doc/README.qemu-mips
http://www.linuxjournal.com/content/handy-u-boot-trick
Figure 1 shows the default boot sequence of the BeagleBone Black. This sequence is more or less applicable to most embedded systems. The x-loader and U-Boot executables are stored in the files called MLO and uboot.img, respectively. These files are stored in a FAT32 partition. The serial port outputs of the BeagleBone are shown in Listings 1–3.
http://www.denx.de/wiki/view/DULG/DebuggingUBoot
10.1.2. Debugging of U-Boot After Relocation
For debugging U-Boot after relocation we need to know the address to which U-Boot relocates itself to. When no exotic features like PRAM are used, this address usually is <MAXMEM> - CONFIG_SYS_MONITOR_LEN. In our example with 16MB RAM and CONFIG_SYS_MONITOR_LEN = 192KB this yields the address 0x1000000 - 0x30000 = 0xFD0000.
In other cases, check the source code, and apply some common sense. For example, on Power Architecture® we use "r2" to hold a pointer to the "global data" structure ("struct global_data"); this structure contains a field
unsigned long relocaddr; /* Start address of U-Boot in RAM */
which is the start addresses of U-Boot after relocation to RAM. You can easily print this value in gdb like that:
(gdb) print/x ((gd_t *)$r2)->relocaddr
With this knowledge, we can instruct gdb to forget the old symbol table and reload the symbols with our calculated offset:
(gdb) symbol-file
http://stackoverflow.com/questions/9415724/questions-about-u-boot-relocation-feature
I am using the u-boot-2011.12 on my OMAP3 target, the cross tool chain is CodeSourcery arm-none-linux-gnueabi, I compiled u-boot, downloaded it onto the target and booted it, everything went fine,but I have some questions about the u-boot relocation feature, we know that this feature is base on PIC(position independent code), position independent code is generated by setting the -fpic flag to gcc, but I don't find fpic in the compile flags. Without the PIC, how can u-boot implement the relocation feature?
http://blog.csdn.net/skyflying2012/article/details/37660265
最近在一直在做uboot的移植工作,uboot中有很多值得学习的东西,之前总结过uboot的启动流程,但uboot一个非常核心的功能没有仔细研究,就是uboot的relocation功能。
这几天研究下uboot的relocation功能,记录在此,跟大家共享。
自己辛苦编辑,转载请注明出处,谢谢!
所谓的relocation,就是重定位,uboot运行后会将自身代码拷贝到sdram的另一个位置继续运行,这个在uboot启动流程分析中说过。
但基于以前的理解,一个完整可运行的bin文件,link时指定的链接地址,load时的加载地址,运行时的运行地址,这3个地址应该是一致的
relocation后运行地址不同于加载地址 特别是链接地址,ARM的寻址会不会出现问题?
沒有留言:
張貼留言