新增32位uefi启动 (#105)

* 新增32位uefi启动

* 修复小bug

* 增加grub本地编译安装

* 增加本地grub编译安装脚本

* 修正小错误

* 修复空文件夹不上传的bug
This commit is contained in:
YJwu2023 2022-12-14 16:58:49 +08:00 committed by GitHub
parent 01876902fb
commit 38b341b8aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 92 additions and 44 deletions

5
.gitignore vendored
View File

@ -1,5 +1,9 @@
/cmake-build-debug/
/bin/
tools/arch/i386/bios/grub/*
tools/arch/i386/efi/grub/*
tools/arch/x86_64/efi/grub/*
!.gitkeep
DragonOS.iso
.idea/
kernel/kernel
@ -9,7 +13,6 @@ kernel/kernel
*.s
serial_opt.txt
user/sys_api_lib
docs/_build
draft
cppcheck.xml

8
.idea/.gitignore generated vendored
View File

@ -1,8 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CLionExternalBuildManager">
<target id="05f63597-45c4-4a5c-9929-2668d1c24337" name="DragonOS" defaultType="TOOL">
<configuration id="4cc3c901-337f-4624-bd4b-ae289fc31816" name="DragonOS" />
</target>
</component>
</project>

2
.idea/dragonOS.iml generated
View File

@ -1,2 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CMake" type="CPP_MODULE" version="4" />

4
.idea/misc.xml generated
View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
</project>

8
.idea/modules.xml generated
View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/dragonOS.iml" filepath="$PROJECT_DIR$/.idea/dragonOS.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated
View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -66,11 +66,11 @@ gdb:
# 写入磁盘镜像
write_diskimage:
sudo sh -c "cd tools && bash $(ROOT_PATH)/tools/write_disk_image.sh --bios=legacy && cd .."
sudo sh -c "cd tools && bash grub_auto_install.sh && bash $(ROOT_PATH)/tools/write_disk_image.sh --bios=legacy && cd .."
# 写入磁盘镜像(uefi)
write_diskimage-uefi:
sudo sh -c "cd tools && bash $(ROOT_PATH)/tools/write_disk_image.sh --bios=uefi && cd .."
sudo sh -c "cd tools && bash grub_auto_install.sh && bash $(ROOT_PATH)/tools/write_disk_image.sh --bios=uefi && cd .."
# 不编译直接启动QEMU
qemu:
sh -c "cd tools && bash run-qemu.sh --bios=legacy && cd .."

View File

@ -0,0 +1,3 @@
# Ignore everything in this directory
*
# Except this file !.gitkeep

Binary file not shown.

View File

@ -0,0 +1,3 @@
# Ignore everything in this directory
*
# Except this file !.gitkeep

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,3 @@
# Ignore everything in this directory
*
# Except this file !.gitkeep

View File

@ -177,7 +177,7 @@ fi
# 创建磁盘镜像
bash create_hdd_image.sh
bash grub_auto_install.sh
# 解决kvm权限问题
USR=$USER
sudo adduser $USR kvm

View File

@ -0,0 +1,59 @@
#!/bin/bash
grub_dir_i386_efi=arch/i386/efi/grub
grub_dir_i386_bios=arch/i386/bios/grub
grub_dir_x86_64_efi=arch/x86_64/efi/grub
#编译核心数目
nproc=8
#检测grub是否已经安装
if [ -d ${grub_dir_i386_efi}/bin ] || [ -d ${grub_dir_i386_bios}/bin ] || [ -d ${grub_dir_x86_64_efi}/bin ] ; then
exit 0
fi
#仅支持Ubuntu/Debain下的自动安装
if ! hash 2>/dev/null apt-get; then
echo "脚本暂不支持对该系统下grub的安装请手动完成"
exit 0
fi
#下载grub2.06
echo "开始下载grub2.06"
wget https://ftp.gnu.org/gnu/grub/grub-2.06.tar.gz
echo "下载完成"
tar -xvzf grub-2.06.tar.gz
#安装对应依赖
sudo apt-get update
sudo apt-get install -y \
make \
binutils \
bison \
gcc \
gettext \
flex\
bison\
automake\
autoconf\
cd grub-2.06
echo "开始安装grub2.06"
#编译安装三个版本的grub
./configure --target=i386 --prefix=$(dirname $PWD)/${grub_dir_i386_bios}
make -j $(nporc)
make install
make clean
./configure --target=i386 --with-platform=efi --prefix=$(dirname $PWD)/${grub_dir_i386_efi}
make -j $(nporc)
make install
make clean
./configure --target=x86_64 --with-platform=efi --prefix=$(dirname $PWD)/${grub_dir_x86_64_efi}
make -j $(nporc)
make install
cd ..
#解除权限限制
sudo chmod -R 777 ${grub_dir_i386_bios}
sudo chmod -R 777 ${grub_dir_i386_efi}
sudo chmod -R 777 ${grub_dir_x86_64_efi}
rm -rf grub-2.06
rm grub-2.06.tar.gz
echo "grub2.06安装完成"

View File

@ -4,7 +4,8 @@ ARGS=`getopt -o p -l bios: -- "$@"`
eval set -- "${ARGS}"
echo "$@"
allflags=$(qemu-system-x86_64 -cpu help | awk '/flags/ {y=1; getline}; y {print}' | tr ' ' '\n' | grep -Ev "^$" | sed -r 's|^|+|' | tr '\n' ',' | sed -r "s|,$||")
ARCH="x86_64"
#ARCH="i386"
# 请根据自己的需要,在-d 后方加入所需的trace事件
# 标准的trace events
@ -40,7 +41,11 @@ if [ $flag_can_run -eq 1 ]; then
--bios)
case "$2" in
uefi) #uefi启动新增ovmf.fd固件
${QEMU} -bios arch/X86_64/OVMF.fd ${QEMU_ARGUMENT}
if [ ${ARCH} == x86_64 ] ;then
${QEMU} -bios arch/x86_64/efi/OVMF-pure-efi.fd ${QEMU_ARGUMENT}
elif [ ${ARCH} == i386 ] ;then
${QEMU} -bios arch/i386/efi/OVMF-pure-efi.fd ${QEMU_ARGUMENT}
fi
;;
legacy)
${QEMU} ${QEMU_ARGUMENT}

View File

@ -5,9 +5,11 @@
# 用法bash write_disk_image.sh --bios legacy/uefi
# 如果之前创建的disk.img是MBR分区表那么请这样运行它bash write_disk_image.sh --bios legacy
# 如果之前创建的disk.img是GPT分区表那么请这样运行它bash write_disk_image.sh --bios uefi
# 通过设置ARCH为x86_64或i386进行64/32位uefi的install但是请记住该处的ARCH应与run-qemu.sh中的一致
###############################################
ARCH="x86_64"
#ARCH="i386"
# 内核映像
root_folder=$(dirname $(pwd))
kernel="${root_folder}/bin/kernel/kernel.elf"
@ -90,9 +92,11 @@ if [ ${ARCH} == "i386" ] || [ ${ARCH} == "x86_64" ]; then
touch ${root_folder}/bin/disk_mount/boot/grub/grub.cfg
cfg_content='set timeout=15
set default=0
insmod efi_gop
menuentry "DragonOS" {
multiboot2 /boot/kernel.elf "KERNEL_ELF"
}'
# 增加insmod efi_gop防止32位uefi启动报错
echo "echo '${cfg_content}' > ${boot_folder}/grub/grub.cfg" | sh
fi
@ -103,10 +107,14 @@ case "$1" in
--bios)
case "$2" in
uefi) #uefi
grub-install --target=x86_64-efi --efi-directory=${mount_folder} --boot-directory=${boot_folder} --removable
if [ ${ARCH} == "i386" ];then
./arch/i386/efi/grub/sbin/grub-install --target=i386-efi --efi-directory=${mount_folder} --boot-directory=${boot_folder} --removable
elif [ ${ARCH} == "x86_64" ];then
./arch/x86_64/efi/grub/sbin/grub-install --target=x86_64-efi --efi-directory=${mount_folder} --boot-directory=${boot_folder} --removable
fi
;;
legacy) #传统bios
grub-install --target=i386-pc --boot-directory=${boot_folder} /dev/$LOOP_DEVICE
./arch/i386/bios/grub/sbin/grub-install --target=i386-pc --boot-directory=${boot_folder} /dev/$LOOP_DEVICE
;;
esac
;;