介绍
阅读u-boot源代码中的README。可以发现u-boot可以在qemu环境下运行。这有助于在没有真正硬件的情况下进行u-boot相关实验。
步骤
下载源码
git的配置不再赘述
git clone https://github.com/u-boot/u-boot.git
编译
对于mac m1系列的芯片架构为AArch64,因此需要将CROSS_COMPILE替换为正确的交叉编译器:
安装交叉编译器
brew tap messense/macos-cross-toolchains
brew install aarch64-unknown-linux-gnu
编译源码
export CROSS_COMPILE=aarch64-linux-gnu-
make qemu_arm64_defconfig
make
解决报错
(1)Makefile:40: *** missing separator. Stop.
注释掉报错的行即可,如图:
(2)fatal error: openssl/evp.h file not found.
首先确保环境中安装有openssl,任然是brew安装
brew install openssl
如任然报错可将环境中的openssl文件拷贝一份至uboot目录下(目标路径根据个人路径修改)
cp -R /opt/homebrew/Cellar/openssl@3/3.2.0/include/openssl /u-boot/include
运行
安装qemu(可以brew安装的就尽量不用源码编啦,省的一些版本问题)
brew install qemu
根据提示缺少啥安啥就好了,一般需要:
brew install ninja pkgconfig glib pixman
最后终于可以正常运行了
qemu-system-aarch64 -machine virt -cpu cortex-a57 -bios u-boot.bin
如果提示 Could not initialize SDL(No available video device) - exiting
可以增加参数 -curses
看看效果: