title: Understand U-Boot memory footprint
body: <p>I don't understand what is happening in RAM when loading U-Boot. I'm working on a Xilinx Zynq ZC702 evaluation kit and I'm trying to load a Linux kernel on it using U-Boot. So I used the Xilinx tool Vivado and the SDK to generate a BOOT.bin file that is written on an SD card step by step:</p>
  
  <ul>
  <li>Create an HW project using Vivado,</li>
  <li>Generate FSBL and FPGA bitstream using the SDK,</li>
  <li>Create a boot image containing the FSBL + bitstream + U-Boot (I downloaded the U-Boot sources from the xilinx Git repository).</li>
  </ul>
  
  <p>In short, I followed all the steps described on <a href="http://www.wiki.xilinx.com/Getting+Started" rel="noreferrer">Xilinx User Guide</a>.</p>
  
  <p>But now, before loading the kernel, I wanted to understand what was happening but I can't. According to the documentation, U-Boot, if loaded from flash, copies itself into RAM, and executes itself from there, but where ?</p>
  
  <p>I searched on the web and I found that the address where U-Boot extracts itself is defined in <em>include/configs/zynq-common.h</em> by <strong><em>CONFIG_SYS_TEXT_BASE</em></strong>, which appear to be 0x400_0000.</p>
  
  <p>But on an other website I saw that we can print the relocation address in debug mode, so I modified the file <em>common/board_r.c</em> and overwrote the function "<em>initr_announce</em>" to print the "<em>gd->relocaddr</em>" field. This time it appear that U-Boot uses the offset address 0x3FF3_7000.</p>
  
  <p>When I use U-Boot command "md" to inspect the memory I see that the two offsets are used, and I see a sort of magic number "be00_00ea" at both locations :</p>
  
  <pre><code>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&gt; 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&gt; 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    (&amp;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&gt; 
  </code></pre>
  
  <p>Why U-Boot need those two offsets ? And what is the real memory footprint of U-Boot ? And more generally where can I put my kernel to be sure that it will not overwrite something ?</p>