Featured image of post Build U-boot for QEMU

Build U-boot for QEMU

Note for Build U-boot and Run with QEMU

Install Dependencies

1
2
3
4
sudo apt install \
bc build-essential git libncurses5-dev \
lzop perl libssl-dev bison flex \
swig libyaml-dev pkg-config python3-dev

Clone U-boot Source

1
2
3
4
git clone https://github.com/u-boot/u-boot.git
cd u-boot
make distclean
make qemu_arm64_defconfig && make -j8
  • make distclean This cleans the repository by removing any previous build artifacts, generated configuration files, or object files. It ensures you have a completely fresh start, especially useful if you built U-Boot for a different target earlier.
  • make qemu_arm64_defconfig This sets the default configuration for building U-Boot specifically for a QEMU ARM64 (AArch64) virtual environment. Defconfigs are baseline config files that initialize a bunch of standard options for a given architecture or board in U-Boot.
  • make -j8 Builds U-Boot with 8 parallel jobs, leveraging multiple cores to speed up compilation. The output of this step will typically produce u-boot.bin and other binaries needed to run U-Boot (like u-boot.elf or u-boot.map).

Run U-boot with QEMU

1
2
3
4
5
6
qemu-system-aarch64 \                                   
-M virt \
-cpu cortex-a57 \
-m 1024 \
-nographic \
-bios u-boot.bin
  • -M virt: Specifies the QEMU “virt” machine model, a generic machine typically used for virtualizing ARM systems.
  • -cpu cortex-a57: Defines the virtual CPU core type. Cortex-A57 is a common 64-bit ARM core.
  • -m 1024: Allocates 1024 MB of memory (i.e., 1 GB) to the virtual machine.
  • -nographic: Disables graphical output and directs all console I/O to the terminal.
  • -bios u-boot.bin: Instructs QEMU to use the u-boot.bin file as the “BIOS” or firmware image. Essentially, QEMU treats this binary as the initial code that runs at system reset, simulating the environment where U-Boot is the first piece of software to execute.

Output

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
U-Boot 2025.04-rc1-00020-g021baf7b08cc (Jan 30 2025 - 14:41:56 +0000)

DRAM:  1 GiB
Core:  51 devices, 14 uclasses, devicetree: board
Flash: 64 MiB
Loading Environment from Flash... *** Warning - bad CRC, using default environment

In:    serial,usbkbd
Out:   serial,vidconsole
Err:   serial,vidconsole
No USB controllers found
Net:   eth0: virtio-net#32

starting USB...
No USB controllers found
Hit any key to stop autoboot:  0
Scanning for bootflows in all bootdevs
Seq  Method       State   Uclass    Part  Name                      Filename
---  -----------  ------  --------  ----  ------------------------  ----------------
Scanning global bootmeth 'efi_mgr':
Cannot persist EFI variables without system partition
Missing TPMv2 device for EFI_TCG_PROTOCOL
Missing RNG device for EFI_RNG_PROTOCOL
Scanning bootdev 'fw-cfg@9020000.bootdev':
fatal: no kernel available
No USB controllers found
scanning bus for devices...
Scanning bootdev 'virtio-net#32.bootdev':
BOOTP broadcast 1
DHCP client bound to address 10.0.2.15 (13 ms)
*** Warning: no boot file name; using '0A00020F.img'
Using virtio-net#32 device
TFTP from server 10.0.2.2; our IP address is 10.0.2.15
Filename '0A00020F.img'.
Load address: 0x40400000
Loading: *
TFTP error: 'Access violation' (2)
Not retrying...
No more bootdevs
---  -----------  ------  --------  ----  ------------------------  ----------------
(0 bootflows, 0 valid)
=>
comments powered by Disqus