mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-09 07:06:47 +00:00
使用DragonStub引导riscv下的DragonOS内核 (#460)
This commit is contained in:
parent
4fda81ce81
commit
01090de77e
@ -28,7 +28,7 @@ CFLAGS = $(GLOBAL_CFLAGS) -fno-pie $(CFLAGS_UNWIND) -I $(shell pwd) -I $(shell p
|
|||||||
ifeq ($(ARCH), x86_64)
|
ifeq ($(ARCH), x86_64)
|
||||||
CFLAGS += -I $(shell pwd)/arch/x86_64/include
|
CFLAGS += -I $(shell pwd)/arch/x86_64/include
|
||||||
else ifeq ($(ARCH), riscv64)
|
else ifeq ($(ARCH), riscv64)
|
||||||
CFLAGS += -I $(shell pwd)/arch/riscv64/include
|
CFLAGS += -I $(shell pwd)/arch/riscv64/include -I $(shell pwd)/arch/riscv64/
|
||||||
endif
|
endif
|
||||||
|
|
||||||
export ASFLAGS := --64
|
export ASFLAGS := --64
|
||||||
@ -70,12 +70,9 @@ __link_riscv64_kernel:
|
|||||||
@echo "Linking kernel..."
|
@echo "Linking kernel..."
|
||||||
$(LD) -b elf64-littleriscv -z muldefs $(LDFLAGS_UNWIND) -o kernel $(shell find . -name "*.o") ../target/riscv64imac-unknown-none-elf/release/libdragonos_kernel.a -T arch/riscv64/link.ld --no-relax
|
$(LD) -b elf64-littleriscv -z muldefs $(LDFLAGS_UNWIND) -o kernel $(shell find . -name "*.o") ../target/riscv64imac-unknown-none-elf/release/libdragonos_kernel.a -T arch/riscv64/link.ld --no-relax
|
||||||
$(OBJCOPY) -I elf64-littleriscv -O elf64-littleriscv -R ".eh_frame" kernel ../../bin/kernel/kernel.elf
|
$(OBJCOPY) -I elf64-littleriscv -O elf64-littleriscv -R ".eh_frame" kernel ../../bin/kernel/kernel.elf
|
||||||
rm kernel
|
@rm kernel
|
||||||
|
$(MAKE) __dragon_stub PAYLOAD_ELF="$(shell pwd)/../../bin/kernel/kernel.elf"
|
||||||
|
|
||||||
# 构建uboot的scr文件
|
|
||||||
@echo "Generating kernel scr file..."
|
|
||||||
@mkdir -p $(ROOT_PATH)/bin/sysroot/boot/
|
|
||||||
@mkimage -A riscv -T script -d arch/riscv64/boot/bootscript.cmd $(ROOT_PATH)/bin/sysroot/boot/boot.scr
|
|
||||||
|
|
||||||
|
|
||||||
__link_x86_64_kernel:
|
__link_x86_64_kernel:
|
||||||
@ -90,7 +87,6 @@ __link_x86_64_kernel:
|
|||||||
cd ..;\
|
cd ..;\
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
# 重新链接
|
# 重新链接
|
||||||
@echo "Re-Linking kernel..."
|
@echo "Re-Linking kernel..."
|
||||||
@echo $(shell find . -name "*.o")
|
@echo $(shell find . -name "*.o")
|
||||||
@ -104,6 +100,11 @@ else
|
|||||||
endif
|
endif
|
||||||
rm kernel
|
rm kernel
|
||||||
|
|
||||||
|
__dragon_stub:
|
||||||
|
@echo "Linking dragon_stub..."
|
||||||
|
PAYLOAD_ELF=$(PAYLOAD_ELF) TARGET_SYSROOT=$(ROOT_PATH)/bin/sysroot $(MAKE) -C $(ROOT_PATH)/../DragonStub install -j $(NPROCS)
|
||||||
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@cargo clean
|
@cargo clean
|
||||||
rm -rf $(GARBAGE)
|
rm -rf $(GARBAGE)
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
load ${devtype} ${devnum}:${distro_bootpart} ${kernel_addr_r} /boot/kernel.elf
|
|
||||||
if fdt addr -q ${fdt_addr_r}; then bootelf ${kernel_addr_r} ${fdt_addr_r};else bootelf ${kernel_addr_r} ${fdtcontroladdr};fi
|
|
@ -10,14 +10,13 @@ ENTRY(_start)
|
|||||||
|
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
//KERNEL_VMA = 0xffffffc000000000;
|
KERNEL_VMA = 0xffffffc000000000;
|
||||||
KERNEL_VMA = 0;
|
//KERNEL_VMA = 0;
|
||||||
. = 0;
|
. = 0x1000000;
|
||||||
|
|
||||||
.boot.text :
|
.boot.text :
|
||||||
{
|
{
|
||||||
KEEP(*(.multiboot_header))
|
KEEP(*(.bootstrap))
|
||||||
*(.bootstrap)
|
|
||||||
*(.bootstrap.code64)
|
*(.bootstrap.code64)
|
||||||
*(.bootstrap.data)
|
*(.bootstrap.data)
|
||||||
. = ALIGN(4096);
|
. = ALIGN(4096);
|
||||||
|
@ -21,7 +21,7 @@ export OBJCOPY=objcopy
|
|||||||
|
|
||||||
|
|
||||||
#检测grub是否已经安装
|
#检测grub是否已经安装
|
||||||
if [ -d ${grub_dir_i386_efi}/bin ] && [ -d ${grub_dir_i386_legacy}/bin ] && [ -d ${grub_dir_x86_64_efi}/bin ] && [ -d ${grub_dir_riscv64_efi}/bin ] ; then
|
if [ -d ${grub_dir_i386_efi}/bin ] && [ -d ${grub_dir_i386_legacy}/bin ] && [ -d ${grub_dir_x86_64_efi}/bin ] ; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
#仅支持Ubuntu/Debain, Arch下的自动安装
|
#仅支持Ubuntu/Debain, Arch下的自动安装
|
||||||
@ -96,20 +96,21 @@ if [ ! -d ${grub_dir_x86_64_efi}/bin ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# 如果不存在riscv64_efi的grub,就编译安装
|
# 如果不存在riscv64_efi的grub,就编译安装
|
||||||
if [ ! -d ${grub_dir_riscv64_efi}/bin ]; then
|
# riscv64目前使用DragonStub进行启动,不需要grub
|
||||||
echo "开始编译安装riscv64_efi版本的grub"
|
# if [ ! -d ${grub_dir_riscv64_efi}/bin ]; then
|
||||||
# 使用which命令判断,如果不存在riscv64-linux-musl交叉编译工具链,则报错
|
# echo "开始编译安装riscv64_efi版本的grub"
|
||||||
if [ ! -n "$(which riscv64-linux-musl-gcc)" ]; then
|
# # 使用which命令判断,如果不存在riscv64-linux-musl交叉编译工具链,则报错
|
||||||
echo "riscv64-linux-musl-gcc不存在,请先安装riscv64-linux-musl交叉编译工具链"
|
# if [ ! -n "$(which riscv64-linux-musl-gcc)" ]; then
|
||||||
exit 1
|
# echo "riscv64-linux-musl-gcc不存在,请先安装riscv64-linux-musl交叉编译工具链"
|
||||||
fi
|
# exit 1
|
||||||
|
# fi
|
||||||
|
|
||||||
./configure --target=riscv64 --with-platform=efi --prefix=${grub_dir_riscv64_efi} --host=x86_64-linux-gnu --disable-werror BUILD_CC=gcc HOST_CC=x86_64-linux-gnu-gcc TARGET_CC=riscv64-linux-musl-gcc TARGET_OBJCOPY=riscv64-linux-musl-objcopy TARGET_STRIP=riscv64-linux-musl-strip TARGET_RANLIB=riscv64-linux-musl-ranlib TARGET_NM=riscv64-linux-musl-nm TARGET_LD=riscv64-linux-musl-ld
|
# ./configure --target=riscv64 --with-platform=efi --prefix=${grub_dir_riscv64_efi} --host=x86_64-linux-gnu --disable-werror BUILD_CC=gcc HOST_CC=x86_64-linux-gnu-gcc TARGET_CC=riscv64-linux-musl-gcc TARGET_OBJCOPY=riscv64-linux-musl-objcopy TARGET_STRIP=riscv64-linux-musl-strip TARGET_RANLIB=riscv64-linux-musl-ranlib TARGET_NM=riscv64-linux-musl-nm TARGET_LD=riscv64-linux-musl-ld
|
||||||
make -j $(nproc) || exit 1
|
# make -j $(nproc) || exit 1
|
||||||
sudo make install || exit 1
|
# sudo make install || exit 1
|
||||||
make clean || exit 1
|
# make clean || exit 1
|
||||||
sudo chmod -R 777 ${grub_dir_riscv64_efi}
|
# sudo chmod -R 777 ${grub_dir_riscv64_efi}
|
||||||
fi
|
# fi
|
||||||
|
|
||||||
|
|
||||||
cd ..
|
cd ..
|
||||||
|
@ -75,6 +75,7 @@ QEMU_RTC_CLOCK=""
|
|||||||
QEMU_SERIAL="-serial file:../serial_opt.txt"
|
QEMU_SERIAL="-serial file:../serial_opt.txt"
|
||||||
QEMU_DRIVE="id=disk,file=${QEMU_DISK_IMAGE},if=none"
|
QEMU_DRIVE="id=disk,file=${QEMU_DISK_IMAGE},if=none"
|
||||||
QEMU_ACCELARATE=""
|
QEMU_ACCELARATE=""
|
||||||
|
QEMU_ARGUMENT=""
|
||||||
|
|
||||||
# 如果qemu_accel不为空
|
# 如果qemu_accel不为空
|
||||||
if [ -n "${qemu_accel}" ]; then
|
if [ -n "${qemu_accel}" ]; then
|
||||||
@ -90,22 +91,27 @@ else
|
|||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ ${ARCH} == "riscv64" ]; then
|
||||||
|
# 如果是riscv64架构,就不需要图形界面
|
||||||
|
QEMU_ARGUMENT+=" --nographic "
|
||||||
|
# 从控制台显示
|
||||||
|
QEMU_MONITOR=""
|
||||||
|
QEMU_SERIAL=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# ps: 下面这条使用tap的方式,无法dhcp获取到ip,暂时不知道为什么
|
# ps: 下面这条使用tap的方式,无法dhcp获取到ip,暂时不知道为什么
|
||||||
# QEMU_DEVICES="-device ahci,id=ahci -device ide-hd,drive=disk,bus=ahci.0 -net nic,netdev=nic0 -netdev tap,id=nic0,model=virtio-net-pci,script=qemu/ifup-nat,downscript=qemu/ifdown-nat -usb -device qemu-xhci,id=xhci,p2=8,p3=4 "
|
# QEMU_DEVICES="-device ahci,id=ahci -device ide-hd,drive=disk,bus=ahci.0 -net nic,netdev=nic0 -netdev tap,id=nic0,model=virtio-net-pci,script=qemu/ifup-nat,downscript=qemu/ifdown-nat -usb -device qemu-xhci,id=xhci,p2=8,p3=4 "
|
||||||
QEMU_DEVICES="-device ahci,id=ahci -device ide-hd,drive=disk,bus=ahci.0 -netdev user,id=hostnet0,hostfwd=tcp::12580-:12580 -device virtio-net-pci,vectors=5,netdev=hostnet0,id=net0 -usb -device qemu-xhci,id=xhci,p2=8,p3=4 "
|
QEMU_DEVICES="-device ahci,id=ahci -device ide-hd,drive=disk,bus=ahci.0 -netdev user,id=hostnet0,hostfwd=tcp::12580-:12580 -device virtio-net-pci,vectors=5,netdev=hostnet0,id=net0 -usb -device qemu-xhci,id=xhci,p2=8,p3=4 "
|
||||||
# E1000E
|
# E1000E
|
||||||
# QEMU_DEVICES="-device ahci,id=ahci -device ide-hd,drive=disk,bus=ahci.0 -netdev user,id=hostnet0,hostfwd=tcp::12580-:12580 -net nic,model=e1000e,netdev=hostnet0,id=net0 -netdev user,id=hostnet1,hostfwd=tcp::12581-:12581 -device virtio-net-pci,vectors=5,netdev=hostnet1,id=net1 -usb -device qemu-xhci,id=xhci,p2=8,p3=4 "
|
# QEMU_DEVICES="-device ahci,id=ahci -device ide-hd,drive=disk,bus=ahci.0 -netdev user,id=hostnet0,hostfwd=tcp::12580-:12580 -net nic,model=e1000e,netdev=hostnet0,id=net0 -netdev user,id=hostnet1,hostfwd=tcp::12581-:12581 -device virtio-net-pci,vectors=5,netdev=hostnet1,id=net1 -usb -device qemu-xhci,id=xhci,p2=8,p3=4 "
|
||||||
QEMU_ARGUMENT="-d ${QEMU_DISK_IMAGE} -m ${QEMU_MEMORY} -smp ${QEMU_SMP} -boot order=d ${QEMU_MONITOR} -d ${qemu_trace_std} "
|
QEMU_ARGUMENT+="-d ${QEMU_DISK_IMAGE} -m ${QEMU_MEMORY} -smp ${QEMU_SMP} -boot order=d ${QEMU_MONITOR} -d ${qemu_trace_std} "
|
||||||
|
|
||||||
QEMU_ARGUMENT+="-s ${QEMU_MACHINE} ${QEMU_CPU_FEATURES} ${QEMU_RTC_CLOCK} ${QEMU_SERIAL} -drive ${QEMU_DRIVE} ${QEMU_DEVICES} "
|
QEMU_ARGUMENT+="-s ${QEMU_MACHINE} ${QEMU_CPU_FEATURES} ${QEMU_RTC_CLOCK} ${QEMU_SERIAL} -drive ${QEMU_DRIVE} ${QEMU_DEVICES} "
|
||||||
QEMU_ARGUMENT+=" ${QEMU_SHM_OBJECT} "
|
QEMU_ARGUMENT+=" ${QEMU_SHM_OBJECT} "
|
||||||
QEMU_ARGUMENT+=" ${QEMU_ACCELARATE} "
|
QEMU_ARGUMENT+=" ${QEMU_ACCELARATE} "
|
||||||
|
|
||||||
# 如果是riscv64架构,就不需要图形界面
|
|
||||||
if [ ${ARCH} == "riscv64" ]; then
|
|
||||||
QEMU_ARGUMENT+=" -nographic "
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 安装riscv64的uboot
|
# 安装riscv64的uboot
|
||||||
install_riscv_uboot()
|
install_riscv_uboot()
|
||||||
@ -118,7 +124,7 @@ install_riscv_uboot()
|
|||||||
uboot_parent_path=$(dirname ${RISCV64_UBOOT_PATH}) || (echo "获取riscv u-boot 版本 ${UBOOT_VERSION} 的父目录失败" && exit 1)
|
uboot_parent_path=$(dirname ${RISCV64_UBOOT_PATH}) || (echo "获取riscv u-boot 版本 ${UBOOT_VERSION} 的父目录失败" && exit 1)
|
||||||
|
|
||||||
if [ ! -f ${uboot_tar_name} ]; then
|
if [ ! -f ${uboot_tar_name} ]; then
|
||||||
wget https://mirrors.dragonos.org.cn/pub/third_party/u-boot/${uboot_tar_name} || echo "下载riscv u-boot 版本 ${UBOOT_VERSION} 失败" && exit 1
|
wget https://mirrors.dragonos.org.cn/pub/third_party/u-boot/${uboot_tar_name} || (echo "下载riscv u-boot 版本 ${UBOOT_VERSION} 失败" && exit 1)
|
||||||
fi
|
fi
|
||||||
echo "下载完成"
|
echo "下载完成"
|
||||||
echo "正在解压u-boot到 '$uboot_parent_path'..."
|
echo "正在解压u-boot到 '$uboot_parent_path'..."
|
||||||
@ -140,7 +146,7 @@ if [ $flag_can_run -eq 1 ]; then
|
|||||||
BIOS_TYPE=uefi
|
BIOS_TYPE=uefi
|
||||||
;;
|
;;
|
||||||
legacy)
|
legacy)
|
||||||
BIOS_TYPE=lagacy
|
BIOS_TYPE=legacy
|
||||||
;;
|
;;
|
||||||
esac;shift 2;;
|
esac;shift 2;;
|
||||||
--display)
|
--display)
|
||||||
|
@ -25,8 +25,15 @@ eval set -- "${ARGS}"
|
|||||||
#echo formatted parameters=[$@]
|
#echo formatted parameters=[$@]
|
||||||
echo "开始写入磁盘镜像..."
|
echo "开始写入磁盘镜像..."
|
||||||
|
|
||||||
|
if [ ${ARCH} == "i386" ] || [ ${ARCH} == "x86_64" ]; then
|
||||||
|
|
||||||
INSTALL_GRUB_TO_IMAGE="1"
|
INSTALL_GRUB_TO_IMAGE="1"
|
||||||
|
|
||||||
|
else
|
||||||
|
INSTALL_GRUB_TO_IMAGE="0"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# toolchain
|
# toolchain
|
||||||
GRUB_ABS_PREFIX=/opt/dragonos-grub
|
GRUB_ABS_PREFIX=/opt/dragonos-grub
|
||||||
GRUB_PATH_I386_LEGACY_INSTALL=${GRUB_ABS_PREFIX}/arch/i386/legacy/grub/sbin/grub-install
|
GRUB_PATH_I386_LEGACY_INSTALL=${GRUB_ABS_PREFIX}/arch/i386/legacy/grub/sbin/grub-install
|
||||||
@ -91,14 +98,14 @@ echo $LOOP_DEVICE
|
|||||||
# mkdir -p ${GRUB_INSTALL_PATH}
|
# mkdir -p ${GRUB_INSTALL_PATH}
|
||||||
|
|
||||||
# 检测grub文件夹是否存在
|
# 检测grub文件夹是否存在
|
||||||
if [ -d "${GRUB_INSTALL_PATH}" ]; then
|
if [ -d "${GRUB_INSTALL_PATH}" ] || [ "${INSTALL_GRUB_TO_IMAGE}" = "0" ]; then
|
||||||
echo "grub已安装"
|
echo "无需安装grub"
|
||||||
INSTALL_GRUB_TO_IMAGE="0"
|
INSTALL_GRUB_TO_IMAGE="0"
|
||||||
else
|
else
|
||||||
mkdir -p ${GRUB_INSTALL_PATH}
|
mkdir -p ${GRUB_INSTALL_PATH}
|
||||||
|
cp ${kernel} ${root_folder}/bin/disk_mount/boot/
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cp ${kernel} ${root_folder}/bin/disk_mount/boot
|
|
||||||
# 拷贝用户程序到磁盘镜像
|
# 拷贝用户程序到磁盘镜像
|
||||||
mkdir -p ${root_folder}/bin/disk_mount/bin
|
mkdir -p ${root_folder}/bin/disk_mount/bin
|
||||||
mkdir -p ${root_folder}/bin/disk_mount/dev
|
mkdir -p ${root_folder}/bin/disk_mount/dev
|
||||||
|
Loading…
x
Reference in New Issue
Block a user