Search code examples
u-boot

u-boot: memory allocation puzzle when booting kernel


I am using petalinux 2023.2 to run a linux with soft microblaze on a FPGA board. I had a question regarding u-boot behavior in terms of possible memory allocation. The board/design has 2GiB DDR, ranges from 0x8000_0000 to 0xffff_ffff, physically.

What the petalinux command does to boot into u-boot and then kernel via JTAG is the following (as shown with petalinux-boot --verbose option, line number is added by me):

 1 targets -set -nocase -filter {name =~ "microblaze*#0"}
 2 puts stderr "INFO: Downloading ELF file: /home/bruin/work/linux_mb/images/linux/u-boot.elf to the target."
 3 dow  "/home/bruin/work/linux_mb/images/linux/u-boot.elf"
 4 con
 5 
 6 after 1000; stop
 7 puts stderr "INFO: Loading image: /home/bruin/work/linux_mb/images/linux/linux.bin.ub at 0x80000000"
 8 dow -data  "/home/bruin/work/linux_mb/images/linux/linux.bin.ub" 0x80000000
 9 puts stderr "INFO: Loading image: /home/bruin/work/linux_mb/images/linux/system.dtb at 0x81e00000"
10 dow -data  "/home/bruin/work/linux_mb/images/linux/system.dtb" 0x81e00000
11 puts stderr "INFO: Loading image: /home/bruin/work/linux_mb/images/linux/rootfs.cpio.gz.u-boot at 0x82e00000"
12 dow -data  "/home/bruin/work/linux_mb/images/linux/rootfs.cpio.gz.u-boot" 0x82e00000
13 puts stderr "INFO: Loading image: /home/bruin/work/linux_mb/images/linux/boot.scr at 0xff200000"
14 dow -data  "/home/bruin/work/linux_mb/images/linux/boot.scr" 0xff200000
15 
16 con
17 exit

As shown above:

  • line 3~4 loads u-boot.elf to ddr and then start executing it. Where u-boot.elf been located in ddr? As shown below, it starts from 0x8010_0000.
xsct% dow u-boot.elf
Downloading Program -- /home/bruin/work/linux_mb/images/linux/u-boot.elf
        section, .text: 0x80100000 - 0x80148c7f
        section, .rodata: 0x80148c80 - 0x80156d1f
        section, .dtb.init.rodata: 0x80156d20 - 0x80159d3f
        section, .data: 0x80159d40 - 0x8015c35f
        section, .got: 0x8015c360 - 0x8015df13
        section, __u_boot_list: 0x8015df14 - 0x8015f00b
        section, .bss: 0x8015f3b4 - 0x801662c7
        section, .rela.dyn: 0x8015f00c - 0x8015f3b3
100%    0MB   0.2MB/s  00:01
Setting PC to Program Start Address 0x80100000
  • as u-boot has a default 4 seconds delay before booting kenrel, line 6 pause the execution of u-boot during this 4-seconds delay.

  • then line 8/10/12/14 download 4 data to ddr to their respective locations.

  • line 16 continues u-boot execution, which reads boot.scr to execute the command bootm 0x80000000 0x82e00000 0x81e00000 for booting into kernel.

My question is about line 7: the load address for linux.bin.ub (kernel image with u-boot header) is 0x8000_0000, the size of linux.bin.ub is around 10MiB. But u-boot.elf text is within this memory region...how is it possible?


Solution

  • But u-boot.elf text is within this memory region...how is it possible?

    During its initialization, U-Boot relocates itself to high memory in order to maximize the amount of contiguous free memory.
    See arch/microblaze/cpu/relocate.c and start.S