Skip to content

Instantly share code, notes, and snippets.

@libcrack
Created June 1, 2024 17:28
Show Gist options
  • Save libcrack/bac23c523ee8c40b5eb69c22973fa86f to your computer and use it in GitHub Desktop.
Save libcrack/bac23c523ee8c40b5eb69c22973fa86f to your computer and use it in GitHub Desktop.
U-Boot ARM Cross-compilation for Qemu

U-Boot ARM Cross-compilation

First clone the U-Boot source code:

git clone https://github.com/ARM-software/u-boot/

Install compilation dependencies:

apt-get install --yes gcc-arm-linux-gnueabi flex cscope

Cross-compile U-Boot:

export CROSS_COMPILE=arm-linux-gnueabi-
make qemu_arm_defconfig
make cscope # This is optional
make

However, it fails to compile:

root@satan:~/software/u-boot# ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make
  CHK     include/config/uboot.release
  CHK     include/generated/version_autogenerated.h
  CHK     include/generated/timestamp_autogenerated.h
  UPD     include/generated/timestamp_autogenerated.h
  CC      lib/asm-offsets.s
  CHK     include/generated/generic-asm-offsets.h
  CC      arch/arm/lib/asm-offsets.s
  CHK     include/generated/asm-offsets.h
  HOSTLD  scripts/dtc/dtc
/usr/bin/ld: scripts/dtc/dtc-parser.tab.o:(.bss+0x10): multiple definition of `yylloc'; scripts/dtc/dtc-lexer.
lex.o:(.bss+0x0): first defined here
collect2: error: ld returned 1 exit status
make[2]: *** [scripts/Makefile.host:106: scripts/dtc/dtc] Error 1
make[1]: *** [scripts/Makefile.build:434: scripts/dtc] Error 2
make: *** [Makefile:508: scripts] Error 2

Modify scripts/dtc/dtc-lexer.lex.c:

--- scripts/dtc/dtc-lexer.lex.c.orig	2024-06-01 19:01:37.669613224 +0200
+++ scripts/dtc/dtc-lexer.lex.c	2024-06-01 19:00:29.969827811 +0200
@@ -615,7 +615,7 @@
 #include "srcpos.h"
 #include "dtc-parser.tab.h"
 
-YYLTYPE yylloc;
+extern YYLTYPE yylloc;
 extern bool treesource_error;
 
 /* CAUTION: this will stop working if we ever use yyless() or yyunput() */

Compilation successful:

root@satan:~/software/u-boot# ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make
[...]
root@satan:~/software/u-boot# ls -lah u-boot.bin
-rw-r--r-- 1 root root 453K Jun  1 19:04 u-boot.bin
root@satan:~/software/u-boot# file u-boot.bin
u-boot.bin: COM executable for DOS

Execute qemu:

qemu-system-arm -display gtk -machine virt -bios u-boot.bin
qemu-system-arm -display curses -machine virt -bios u-boot.bin
qemu-system-arm -nographic -machine virt -bios u-boot.bin

Example:

root@satan:~/software/u-boot# qemu-system-arm -nographic -machine virt -bios u-boot.bin


U-Boot 2018.09-00427-g4024652143 (Jun 01 2024 - 19:00:39 +0200)

DRAM:  128 MiB
WARNING: Caches not enabled
In:    pl011@9000000
Out:   pl011@9000000
Err:   pl011@9000000
Net:   No ethernet found.
Hit any key to stop autoboot:  0
scanning bus for devices...

Device 0: unknown device
starting USB...
No controllers found
No ethernet found.
No ethernet found.
=>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment