我不明白加载 U-Boot 时 RAM 中发生了什么。我正在开发 Xilinx Zynq ZC702 评估套件,并尝试使用 U-Boot 在其上加载 Linux 内核。于是我使用 Xilinx 工具 Vivado 和 SDK 生成了一个 BOOT.bin 文件,一步步写在 SD 卡上:
- 使用 Vivado 创建一个硬件项目,
- 使用 SDK 生成 FSBL 和 FPGA 比特流,
- 创建一个包含 FSBL + 比特流 + U-Boot 的引导映像(我从 xilinx Git 存储库下载了 U-Boot 源)。
简而言之,我遵循了赛灵思用户指南中描述的所有步骤。
但是现在,在加载内核之前,我想了解发生了什么,但我做不到。根据文档,U-Boot 如果从闪存加载,会将自身复制到 RAM 中,并从那里执行自身,但是在哪里?
我在网上搜索,发现 U-Boot 提取自身的地址是由CONFIG_SYS_TEXT_BASE在include/configs/zynq-common.h中定义的,似乎是 0x400_0000。
但在另一个网站上我看到我们可以在调试模式下打印重定位地址,所以我修改了文件common/board_r.c并重写了函数“ init_announce ”来打印“ gd->relocaddr ”字段。这次似乎 U-Boot 使用了偏移地址 0x3FF3_7000。
当我使用 U-Boot 命令“md”检查内存时,我看到使用了两个偏移量,并且在两个位置都看到了一种幻数“be00_00ea”:
Xilinx First Stage Boot Loader
Release 2014.4 Feb 8 2016-14:53:56
Devcfg driver initialized
Silicon Version 3.1
Boot mode is SD
SD: rc= 0
SD Init Done
Flash Base Address: 0xE0100000
Reboot status register: 0x60400000
Multiboot Register: 0x0000C000
Image Start Address: 0x00000000
Partition Header Offset:0x00000C80
Partition Count: 3
Partition Number: 1
Header Dump
Image Word Len: 0x000F6EC0
Data Word Len: 0x000F6EC0
Partition Word Len:0x000F6EC0
Load Addr: 0x00000000
Exec Addr: 0x00000000
Partition Start: 0x000065D0
Partition Attr: 0x00000020
Partition Checksum Offset: 0x00000000
Section Count: 0x00000001
Checksum: 0xFFD14B7E
Bitstream
In FsblHookBeforeBitstreamDload function
PCAP:StatusReg = 0x40000A30
PCAP:device ready
PCAP:Clear done
Level Shifter Value = 0xA
Devcfg Status register = 0x40000A30
PCAP:Fabric is Initialized done
PCAP register dump:
PCAP CTRL 0xF8007000: 0x4C00E07F
PCAP LOCK 0xF8007004: 0x0000001A
PCAP CONFIG 0xF8007008: 0x00000508
PCAP ISR 0xF800700C: 0x0802000B
PCAP IMR 0xF8007010: 0xFFFFFFFF
PCAP STATUS 0xF8007014: 0x00000A30
PCAP DMA SRC ADDR 0xF8007018: 0x00100001
PCAP DMA DEST ADDR 0xF800701C: 0xFFFFFFFF
PCAP DMA SRC LEN 0xF8007020: 0x000F6EC0
PCAP DMA DEST LEN 0xF8007024: 0x000F6EC0
PCAP ROM SHADOW CTRL 0xF8007028: 0xFFFFFFFF
PCAP MBOOT 0xF800702C: 0x0000C000
PCAP SW ID 0xF8007030: 0x00000000
PCAP UNLOCK 0xF8007034: 0x757BDF0D
PCAP MCTRL 0xF8007080: 0x30800100
DMA Done !
FPGA Done !
In FsblHookAfterBitstreamDload function
Partition Number: 2
Header Dump
Image Word Len: 0x0001BA12
Data Word Len: 0x0001BA12
Partition Word Len:0x0001BA12
Load Addr: 0x04000000
Exec Addr: 0x04000000
Partition Start: 0x000FD490
Partition Attr: 0x00000010
Partition Checksum Offset: 0x00000000
Section Count: 0x00000001
Checksum: 0xF7EAFAC8
Application
Handoff Address: 0x04000000
In FsblHookBeforeHandoff function
SUCCESSFUL_HANDOFF
FSBL Status = 0x1
U-Boot 2015.07 (Feb 11 2016 - 10:24:28 +0100)
Model: Zynq ZC702 Development Board
I2C: ready
DRAM: ECC disabled 1 GiB
MMC: zynq_sdhci: 0
SF: Detected N25Q128A with page size 256 Bytes, erase size 64 KiB, total 16 MiB
In: serial
Out: serial
Err: serial
Model: Zynq ZC702 Development Board
Net: Gem.e000b000
Hit any key to stop autoboot: 0
zynq-uboot> md 0x4000000
04000000: ea0000be e59ff014 e59ff014 e59ff014 ................
04000010: e59ff014 e59ff014 e59ff014 e59ff014 ................
04000020: 04000060 040000c0 04000120 04000180 `....... .......
04000030: 040001e0 04000240 040002a0 deadbeef ....@...........
04000040: 0badc0de e320f000 e320f000 e320f000 ...... ... ... .
04000050: e320f000 e320f000 e320f000 e320f000 .. ... ... ... .
04000060: e51fd028 e58de000 e14fe000 e58de004 (.........O.....
04000070: e3a0d013 e169f00d e1a0e00f e1b0f00e ......i.........
04000080: e24dd048 e88d1fff e51f2050 e892000c H.M.....P ......
04000090: e28d0048 e28d5034 e1a0100e e885000f H...4P..........
040000a0: e1a0000d eb0005dc e320f000 e320f000 .......... ... .
040000b0: e320f000 e320f000 e320f000 e320f000 .. ... ... ... .
040000c0: e51fd088 e58de000 e14fe000 e58de004 ..........O.....
040000d0: e3a0d013 e169f00d e1a0e00f e1b0f00e ......i.........
040000e0: e24dd048 e88d1fff e51f20b0 e892000c H.M...... ......
040000f0: e28d0048 e28d5034 e1a0100e e885000f H...4P..........
zynq-uboot> md 0x3ff37000
3ff37000: ea0000be e59ff014 e59ff014 e59ff014 ................
3ff37010: e59ff014 e59ff014 e59ff014 e59ff014 ................
3ff37020: 3ff37060 3ff370c0 3ff37120 3ff37180 `p.?.p.? q.?.q.?
3ff37030: 3ff371e0 3ff37240 3ff372a0 deadbeef .q.?@r.?.r.?....
3ff37040: 3f312628 e320f000 e320f000 e320f000 (&1?.. ... ... .
3ff37050: e320f000 e320f000 e320f000 e320f000 .. ... ... ... .
3ff37060: e51fd028 e58de000 e14fe000 e58de004 (.........O.....
3ff37070: e3a0d013 e169f00d e1a0e00f e1b0f00e ......i.........
3ff37080: e24dd048 e88d1fff e51f2050 e892000c H.M.....P ......
3ff37090: e28d0048 e28d5034 e1a0100e e885000f H...4P..........
3ff370a0: e1a0000d eb0005dc e320f000 e320f000 .......... ... .
3ff370b0: e320f000 e320f000 e320f000 e320f000 .. ... ... ... .
3ff370c0: e51fd088 e58de000 e14fe000 e58de004 ..........O.....
3ff370d0: e3a0d013 e169f00d e1a0e00f e1b0f00e ......i.........
3ff370e0: e24dd048 e88d1fff e51f20b0 e892000c H.M...... ......
3ff370f0: e28d0048 e28d5034 e1a0100e e885000f H...4P..........
zynq-uboot>
为什么 U-Boot 需要这两个偏移量?U-Boot 的真正内存占用是多少?更一般地说,我可以将内核放在哪里以确保它不会覆盖某些内容?