一、EDKII windows 环境搭建

1. 下载UEFI开源代码

cmd进入C盘根目录,git clone https://github.com/tianocore/edk2.git edkii && cd edkii && git submodule update --init
(太慢的话,使用gitee, git clone https://gitee.com/xiaopangzi313/edk2.git)

2. 安装ASL编译器

下载 iasl-win-20190405.zip,然后解压至C:\asl

3. 安装NASM编译器

下载 nasm-2.14.02-win64.zip,解压nasm-2.14.02-win64.zip到C:\nasm

4. 安装VS2013或者VS2015(过程略)

5. 修改启动脚本edksetup.bat

进入edk2目录,在edksetup.bat最后一行添加
build -a IA32,X64 -p OvmfPkg\OvmfPkgX64.dsc -D DEBUG_ON_SERIAL_PORT

6. 编译 OVMF.FD 固件文件

在edk2目录执行edksetup.bat,

运行结果如下,

为了运行方便,可以将edksetup.bat放入右键菜单,编写以下文本保存为EDK2_Build.reg 并双击运行,

Windows Registry Editor Version 5.00[HKEY_CLASSES_ROOT\Directory\shell\EDK2_Build]
@="EDK2_Build"
"Icon"="cmd.exe"[HKEY_CLASSES_ROOT\Directory\shell\EDK2_Build\command]
@="cmd.exe /s /k pushd \"%V\" && edksetup.bat"[HKEY_CLASSES_ROOT\Directory\Background\shell\EDK2_Build]
@="EDK2_Build"
"Icon"="cmd.exe"[HKEY_CLASSES_ROOT\Directory\Background\shell\EDK2_Build\command]
@="cmd.exe /s /k pushd \"%V\"  && edksetup.bat"

即可以使用右键菜单运行编译脚本,

查看生成的固件文件,dir C:\edkii\Build\OvmfX64\DEBUG_VS2013x86\FV\*.fd

7. 安装QEMU(X64)虚拟机

下载QEMU并安装,链接:https://pan.baidu.com/s/1aQ7wmQ6bUOInUs94PmAFHA 提取码:csdn
–来自百度网盘超级会员V1的分享
在C盘创建QEMU并进入,拷贝OVMF.FD到当前目录,创建启动脚本setup-qemu-x64.bat
C:\qemu>echo "C:\Program Files\qemu\qemu-system-x86_64.exe" -bios "OVMF.fd" -M "pc" -m 256 -cpu "qemu64" -boot order=dc -serial stdio >> setup-qemu-x64.bat
运行脚本 setup-qemu-x64.bat

效果如下,

图中,左侧为Console串口输出,右侧为QEMUshell界面。

二、EDKII Linux(Centos7) 环境搭建

1. 设置软件源

# 备份当前repo文件
cp  /etc/yum.repos.d/CentOS-Base.repo  /etc/yum.repos.d/CentOS-Base.repo.back
# 下载ali cloud centos 源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# 安装扩展仓库
wget -O /etc/yum.repos.d/epel-7.repo wget http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all
yum makecache

2. 安装编译器、模拟器环境

·yum -y install gcc gcc-c++ git python3 nasm iasl libuuid-devel qemu
#安装GUI
yum groupinstall "GNOME Desktop" "Graphical Administration Tools"
ln -sf /lib/systemd/system/runlevel5.target /etc/systemd/system/default.target

3. 下载UEFI开源代码

git clone https://github.com/tianocore/edk2.git edkii(如果太慢可以sync到自己的gitee账户,如我的gitee, git clone https://gitee.com/xiaopangzi313/edk2.git)

4. 编译UEFI开源代码

# 编译basetoolsmake -C /root/edk2/BaseTools/Source/C
# 编译 Ovmf.fd./OvmfPkg/build.sh -D DEBUG_ON_SERIAL_PORT

5. 使用QEMU加载Ovmf.fd

  • qemu-system-x86_64 -bios ./Build/OvmfX64/DEBUG_GCC48/FV/OVMF.fd

    PS:
    VMware/Vbox console操作不方便,可以尝试使用虚拟串口方式。

    • 虚拟机设置->硬件>添加->串行端口->使用命名管道->输入\\.\pipe\com_1
    • Centos 下配置grub:
      1. sed 's/quiet/console=ttyS1,9600 loglevel=8/' -i /etc/default/grub
      2. grub2-mkconfig -o /boot/grub2/grub.cfg
      3. grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
      4. reboot
    • Putty 配置,serial line设置为\\.\pipe\com_1,speed设置为9600
      效果如下:

三、UEFI OVMF 固件 boot Linux

1. 编译Busybox

#安装相关依赖库以及tool
yum -y  install gcc  gcc-c++
yum install -y ncurses ncurses-devel
yum install -y elfutils-libelf-devel openssl-devel dwarves make flex bison
yum install -y glibc-static#创建工作目录
CSDN=/root/csdn
TOP_BUILD=$CSDN/build
mkdidr -p $(TOP_BUILD)
cd $CSDN#下载解压busybox源码
wget  https://busybox.net/downloads/busybox-1.26.2.tar.bz2  --no-check-certificate
tar xjf busybox-1.26.2.tar.bz2

#生成.config
cd $CSDN/busybox-1.26.2
mkdir -pv $TOP_BUILD/obj/busybox-x86
make O=$TOP_BUILD/obj/busybox-x86 defconfigmake O=$TOP_BUILD/obj/busybox-x86 menuconfig
sed -i "s/.*CONFIG_STATIC.*/CONFIG_STATIC=y/" .config
(或者Busybox Settings  ---> Build BusyBox as a static binary (no shared libs).)cd $TOP_BUILD/obj/busybox-x86
make -j2
make install

编译完成如下:

测试下busybox:

2. 制作initramfs

#创建假的文件系统目录
mkdir -pv $TOP_BUILD/initramfs/x86-busybox
cd $TOP_BUILD/initramfs/x86-busybox
mkdir -pv {bin,dev/tty0,sbin,etc,proc,sys/kernel/debug,usr/{bin,sbin},lib,lib64,mnt/root,root}#copy 编译生成的busybox
cp -av $TOP_BUILD/obj/busybox-x86/_install/*  $TOP_BUILD/initramfs/x86-busybox
cp -av /dev/{null,console,tty,sda1} $TOP_BUILD/initramfs/x86-busybox/dev/#创建init文件
cat > $TOP_BUILD/initramfs/x86-busybox/init < EOF
#!/bin/sh
mount -t proc none /proc
mount -t sysfs none /sys
#mount -t debugfs none /sys/kernel/debug
mdev -s
echo -e "\nBoot took $(cut -d' ' -f1 /proc/uptime) seconds\n"
#exec /bin/sh
exec /sbin/init
EOF
chmod +x $TOP_BUILD/initramfs/x86-busybox/init#创建 ./etc/passwd与 ./etc/group
echo "root::0:0:root:/:/bin/sh" > ./etc/passwd
touch  ./etc/group #创建 ./etc/inittab
cat > ./etc/inittab << EOF
::sysinit:/etc/rc.d/rcS
::respawn:/sbin/getty -n -l /bin/sh ttyS0 115200
::respawn:/bin/cttyhack /bin/sh
::shutdown:/bin/umount -a -r
::shutdown:/sbin/swapoff -a
::restart:/sbin/init
EOF#创建 . ./etc/fstab
cat > ./etc/fstab << EOF
proc     /proc    proc     defaults 0 0
sys      /sys     sysfs    defaults 0 0
none     /dev     devtmpfs defaults 0 0
tmpfs    /dev/shm tmpfs    defaults 0 0
none     /dev/pts devpts   defaults 0 0
EOF#创建 . ./etc/hostname
echo "busybox_csdn" >  ./etc/hostname#创建  ./etc/rc.d/rcS
mkdir -p ./etc/rc.d/ && touch ./etc/rc.d/rcSecho '#!/bin/sh
/bin/hostname -F /etc/hostname
/bin/mount /proc               # We need to do this before remounting root
/bin/mount /sys
/bin/mount -o remount,rw /     # Remount read-write
/bin/mount /dev
/bin/mkdir /dev/shm
/bin/mkdir /dev/pts
/bin/mount -a                  # Mount all filesystems in fstab, except those marked with 'noauto'
/sbin/ifconfig lo 127.0.0.1    # Setup loopback interface for network (if you have networking in your kernel)
#/sbin/inetd                    # If you want inetd to run
#/sbin/telnetd                  # If you want standalone telnetd to run -- incompatible with inetd it seems
' > ./etc/rc.d/rcS
chmod +x ./etc/rc.d/rcS#创建 tty设备文件
mknod ./dev/tty1 c 4 1
mknod ./dev/tty2 c 4 2
mknod ./dev/tty3 c 4 3
mknod ./dev/tty4 c 4 4
ls -l ./dev/tty[0-9]

#打包initramfs
cd $TOP_BUILD/initramfs/x86-busybox
find . -print0 | cpio --null -ov --format=newc     | gzip -9 > $TOP_BUILD/obj/initramfs-busybox-x86.cpio.gz

3. 制作支持EFI的 Linux 硬盘镜像

# 安装相关的toolyum install -y dosfstoolsyum install -y  grub2-efi-x64-modules.noarchyum install -y  efibootmgr
# 插入 USB 到PC同时保证被Vmware能识别(或者直接宿主linux)

#对U盘前500MB清零dd if=/dev/zero of=/dev/sdb  bs=1M count=512;    #对U盘(/dev/sdb)进行分区
gdisk /dev/sdb
GPT fdisk (gdisk) version 0.8.10Partition table scan:MBR: protectiveBSD: not presentAPM: not presentGPT: presentFound valid GPT with protective MBR; using GPT.Command (? for help): p
Disk /dev/sdb: 60062500 sectors, 28.6 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 2280F128-40B9-44EF-8972-59E8AA2C1DD3
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 60062466
Partitions will be aligned on 2048-sector boundaries
Total free space is 60062433 sectors (28.6 GiB)Number  Start (sector)    End (sector)  Size       Code  NameCommand (? for help): n
Partition number (1-128, default 1):
First sector (34-60062466, default = 2048) or {+-}size{KMGTP}:
Last sector (2048-60062466, default = 60062466) or {+-}size{KMGTP}: 110MiB
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): EF00
Changed type of partition to 'EFI System'Command (? for help): p
Disk /dev/sdb: 60062500 sectors, 28.6 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 2280F128-40B9-44EF-8972-59E8AA2C1DD3
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 60062466
Partitions will be aligned on 2048-sector boundaries
Total free space is 59839200 sectors (28.5 GiB)Number  Start (sector)    End (sector)  Size       Code  Name1            2048          225280   109.0 MiB   EF00  EFI SystemCommand (? for help): n
Partition number (2-128, default 2):
First sector (34-60062466, default = 227328) or {+-}size{KMGTP}:
Last sector (227328-60062466, default = 60062466) or {+-}size{KMGTP}: 400MiB
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 8300
Changed type of partition to 'Linux filesystem'Command (? for help): p
Disk /dev/sdb: 60062500 sectors, 28.6 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 2280F128-40B9-44EF-8972-59E8AA2C1DD3
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 60062466
Partitions will be aligned on 2048-sector boundaries
Total free space is 59247327 sectors (28.3 GiB)Number  Start (sector)    End (sector)  Size       Code  Name1            2048          225280   109.0 MiB   EF00  EFI System2          227328          819200   289.0 MiB   8300  Linux filesystemCommand (? for help): wFinal checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdb.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.
[root@localhost ~]#

#对U盘(/dev/sdb)进行格式化
fdisk -l  /dev/sdb
mkfs.vfat  -F 32 -s 2 /dev/sdb1
mkfs.ext3 /dev/sdb2
#对U盘安装bootloader这里用grub tool,也可以使用LILO
mount /dev/sdb2 /mnt/
mkdir -p /mnt/boot/efi
mkdir -p /mnt/boot/grub
mount /dev/sdb1  /mnt/boot/efi
grub2-install --root-directory=/mnt/   --target=x86_64-efi   /dev/sdb

#创建EFI/BOOT/bootx64.efi,确保UEFI可以boot
mkdir -p  /mnt/boot/efi/EFI/BOOT
cp  /mnt/boot/efi/EFI/centos/grubx64.efi  /mnt/boot/efi/EFI/BOOT/bootx64.efi# copy 本机的kernel 镜像(也可以自己编译)
cp  /boot/vmlinuz-3.10.0-514.el7.x86_64  /mnt/#copy上面编译的busybox initramfs
cp   /root/csdn/build/obj/initramfs-busybox-x86.cpio.gz  /mnt/

# 获取主分区的UUID用来填充grub.cfg
lsblk -f

# 制作启动菜单
echo 'menuentry 'csdn-kernel-3.10.0-514.el7.x86_64' --class gnu-linux --class gnu --class os {insmod gzioinsmod part_gptsearch --no-floppy --fs-uuid --set e619cba7-494d-4e0a-976d-e5d6ca196dbcecho 'Loading csdn kernel 3.10.0 ...'linux  /vmlinuz-3.10.0-514.el7.x86_64  rw init=/bin/sh console=ttyS0,9600n8 console=tty0 consoleblank=0 earlyprintk=ttyS0,9600 kgdboc=kbd,ttyS0 loglevel=7echo   'Loading initial ramdisk busybox  ...'initrd /initramfs-busybox-x86.cpio.gz
}'  > /mnt/boot/efi/EFI/centos/grub.cfg
#卸载U盘
umount /dev/sdb1
umount /dev/sdb2# 导出U盘为HardDisk image
dd if=/dev/sdb bs=512 count=819200 of=./csdn_busybox.img

4. 使用OVMF 固件启动 Linux 硬盘镜像

1.`Windows 端启动

chcp 65001 && "C:\Program Files\qemu\qemu-system-x86_64.exe" -bios "OVMF.fd" -M "pc" -m 256 -cpu "qemu64" -boot order=dc -serial stdio -hda "csdn_busybox.img"
press F2 -> uefi shell

退出shell,进入setup, 再进入boot entry


`

2.`Linux端启动

qemu-system-x86_64 -bios ./Build/OvmfX64/DEBUG_GCC48/FV/OVMF.fd -serial stdio -hda /root/csdn_busybox.img

5. 使用OVMF 固件启动 win10硬盘镜像

cmd 中执行如下命令qemu-system-x86_64.exe -bios "OVMF.fd" -M "pc" -m 4096 -cpu "qemu64" -hda E:\iso\win10_xxx.raw -serial stdio (注意:win10 镜像可以通过vmware以及vbox制作)

6. 使用OVMF 固件启动 FWTS硬盘镜像

cmd 中执行如下命令chcp 65001 && "C:\Program Files\qemu\qemu-system-x86_64.exe" -bios "OVMF.fd" -M "pc" -m 4096 -cpu "qemu64" -boot order=dc -serial stdio -hda fwts-live-22.03.00-x86_64.img -usbdevice disk:HDD_BOOT.img (注意:fwts镜像可以从 https://fwts.ubuntu.com/fwts-live/ 下载)

小结:

本章完成了UEFI 开源固件OVMF的编译环境搭建以及使用OVMF 启动UEFI shell / Linux OS (busybox + fwts)/ windows . 后续再会添加OVMF启动ReactOS.

PS:
本文使用的Qemu安装包,OVMF固件以及busybox可以从以下链接下载
qemu+ovmf+busybox

UEFI 基础教程 (一) - 基于QEMU搭建UEFI开发环境(win/linux)相关推荐

  1. 【kratos入门实战教程】1-kratos项目搭建和开发环境配置

    1.系列目录 [kratos入门实战教程]0-商城项目介绍 [kratos入门实战教程]1-kratos项目搭建和开发环境配置 [kratos入门实战教程]2-实现注册登陆业务 2.概览 经过上一篇的 ...

  2. Docker最全教程之使用Docker搭建Java开发环境(十八)

    前言 Java是一门面向对象的优秀编程语言,市场占有率极高,但是在容器化实践过程中,发现官方支持并不友好,同时与其他编程语言的基础镜像相比(具体见各语言镜像比较),确实是非常臃肿. 本篇仅作探索,希望 ...

  3. Docker最全教程之使用Docker搭建Java开发环境

    前言 Java是一门面向对象的优秀编程语言,市场占有率极高,但是在容器化实践过程中,发现官方支持并不友好,同时与其他编程语言的基础镜像相比(具体见各语言镜像比较),确实是非常臃肿. Java [Jav ...

  4. 乐鑫Esp32学习之旅② 巧用eclipes编辑器,官方教程在Windows下搭建esp32开发环境,打印 “Hello World”。

    本系列博客学习由非官方人员 半颗心脏 潜心所力所写,仅仅做个人技术交流分享,不做任何商业用途.如有不对之处,请留言,本人及时更改. 1. 爬坑学习新旅程,虚拟机搭建esp32开发环境,打印 " ...

  5. mac搭建python开发环境_Mac中基于Homebrew搭建python开发环境

    转移到mac上了.这里是在lion中搭建python开发环境的简单记录.这份记录不是一份step by step.而是事后写的记录,可能有记忆遗漏.如果有错误,请指正. 1.安装homebrew的准备 ...

  6. 使用 qemu 搭建内核开发环境

    本文主要介绍在 MacOS 上使用 qemu 搭建 Linux Kernel 的开发环境.(在开始之前需要注意的是,本文中的 Linux 开发环境是一个远程服务器,而 qemu 被安装在本地的 Mac ...

  7. 基于WSL搭建ESP8266开发环境

    目的 本文档用于记录 ESP8266 基于 WSL 的开发环境搭建.本人在最早接触 ESP8266 时使用的环境搭建方法是在 windows 下使用 MINGW32,这个环境下的编译非常慢,体验非常不 ...

  8. 在Ubuntu下使用QEMU搭建arm开发环境(一)搭建基本开发环境

    马上就要开学了,开学后就会开始arm+Linux的学习,因为马上就要去学校了,就没有买板子,打算去了学校再买,但是想学习的心是迫切的(O(∩_∩)O哈哈~),在网上浏览的时候发现了QEMU这个&quo ...

  9. pythonweb搭建教程_基于Centos搭建Python Web 环境搭建教程

    CentOS 7.2 64 位操作系统 安装 setuptools 工具 安装 因为之后我们需要安装 Django ,而 Django 需要用这个工具,所以我们需要先安装 setuptools 工具. ...

最新文章

  1. ubuntu18.04上安装TensorFlow2.0
  2. Golang学习之GOROOT、PATH、GOPATH及go get
  3. [工具]-C语言中字符串的形式打印16进制数据
  4. Spring-JdbcTemplate(注入到spring容器)-02
  5. hive启动mapreduce任务后,被killed
  6. [react] 在react中什么是合成事件?有什么用?
  7. mysql mode_MYSQL中的sql_mode模式
  8. 防火墙设置导致服务器站点打开,服务器、网站、环境配置全正常网站打不开原来是系统防火墙造成的...
  9. php无嵌套遍历多维数组,不递归怎么遍历多维数组(维数不定)
  10. grid列的值格式化
  11. windows mobile 服务自动停止_打印服务print Splooer自动停止怎么办?
  12. 微信开发者工具中导入错误 提示请选择含app.json/project.config.json的目录(纪录篇)
  13. mysql变量赋值加冒号_C语言变量声明加冒号的用法(占位符)
  14. 2019款享域视频_钱都花哪了?单日投放最高2443款,复盘2019年买量最烧钱的100款手游...
  15. 手机桌面没有计算机图标,手机桌面图标不见了,更改桌面图标的大小-
  16. 【数据库/数据挖掘/内容检索】 2019年-中国计算机学会推荐国际学术会议和期刊目录(五)
  17. 值班 查看及重启系统
  18. JZOJ_2499_东风谷早苗 (Standard IO)
  19. 初始vue脚手架的项目文件中mian.js文件
  20. static关键字的用法

热门文章

  1. 是配置在计算机硬件上的最基本的系统软件,试题库
  2. 快手小说怎么引流?门槛太低,是个人就能做
  3. “幽灵刹车”困扰特斯拉
  4. VS2015无法新建项目错误及解决方法:无法打开“……/VC?VCWizards/default.vcxproj”因为此版本的应用程序不支持其项目类型(.vcxproj)
  5. pip 按照requirements.txt安装到对应的package名称的文件中
  6. themeleaf基本语法
  7. python绝技:运用python成为顶级黑客
  8. C程序设计(谭浩强第五版)总结
  9. C++20 标准正式发布
  10. 怎么把一张暗的照片调亮_PS怎么把一张暗的图调亮,就局部