mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-08 14:16: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)
|
||||
CFLAGS += -I $(shell pwd)/arch/x86_64/include
|
||||
else ifeq ($(ARCH), riscv64)
|
||||
CFLAGS += -I $(shell pwd)/arch/riscv64/include
|
||||
CFLAGS += -I $(shell pwd)/arch/riscv64/include -I $(shell pwd)/arch/riscv64/
|
||||
endif
|
||||
|
||||
export ASFLAGS := --64
|
||||
@ -70,12 +70,9 @@ __link_riscv64_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
|
||||
$(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:
|
||||
@ -89,8 +86,7 @@ __link_x86_64_kernel:
|
||||
$(MAKE) generate_kallsyms kernel_root_path="$(shell pwd)"||exit 1;\
|
||||
cd ..;\
|
||||
done
|
||||
|
||||
|
||||
|
||||
# 重新链接
|
||||
@echo "Re-Linking kernel..."
|
||||
@echo $(shell find . -name "*.o")
|
||||
@ -104,6 +100,11 @@ else
|
||||
endif
|
||||
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:
|
||||
@cargo clean
|
||||
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
|
||||
{
|
||||
//KERNEL_VMA = 0xffffffc000000000;
|
||||
KERNEL_VMA = 0;
|
||||
. = 0;
|
||||
KERNEL_VMA = 0xffffffc000000000;
|
||||
//KERNEL_VMA = 0;
|
||||
. = 0x1000000;
|
||||
|
||||
.boot.text :
|
||||
{
|
||||
KEEP(*(.multiboot_header))
|
||||
*(.bootstrap)
|
||||
KEEP(*(.bootstrap))
|
||||
*(.bootstrap.code64)
|
||||
*(.bootstrap.data)
|
||||
. = ALIGN(4096);
|
||||
|
@ -21,7 +21,7 @@ export OBJCOPY=objcopy
|
||||
|
||||
|
||||
#检测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
|
||||
fi
|
||||
#仅支持Ubuntu/Debain, Arch下的自动安装
|
||||
@ -96,20 +96,21 @@ if [ ! -d ${grub_dir_x86_64_efi}/bin ]; then
|
||||
fi
|
||||
|
||||
# 如果不存在riscv64_efi的grub,就编译安装
|
||||
if [ ! -d ${grub_dir_riscv64_efi}/bin ]; then
|
||||
echo "开始编译安装riscv64_efi版本的grub"
|
||||
# 使用which命令判断,如果不存在riscv64-linux-musl交叉编译工具链,则报错
|
||||
if [ ! -n "$(which riscv64-linux-musl-gcc)" ]; then
|
||||
echo "riscv64-linux-musl-gcc不存在,请先安装riscv64-linux-musl交叉编译工具链"
|
||||
exit 1
|
||||
fi
|
||||
# riscv64目前使用DragonStub进行启动,不需要grub
|
||||
# if [ ! -d ${grub_dir_riscv64_efi}/bin ]; then
|
||||
# echo "开始编译安装riscv64_efi版本的grub"
|
||||
# # 使用which命令判断,如果不存在riscv64-linux-musl交叉编译工具链,则报错
|
||||
# if [ ! -n "$(which riscv64-linux-musl-gcc)" ]; then
|
||||
# echo "riscv64-linux-musl-gcc不存在,请先安装riscv64-linux-musl交叉编译工具链"
|
||||
# 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
|
||||
make -j $(nproc) || exit 1
|
||||
sudo make install || exit 1
|
||||
make clean || exit 1
|
||||
sudo chmod -R 777 ${grub_dir_riscv64_efi}
|
||||
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
|
||||
# make -j $(nproc) || exit 1
|
||||
# sudo make install || exit 1
|
||||
# make clean || exit 1
|
||||
# sudo chmod -R 777 ${grub_dir_riscv64_efi}
|
||||
# fi
|
||||
|
||||
|
||||
cd ..
|
||||
|
@ -75,6 +75,7 @@ QEMU_RTC_CLOCK=""
|
||||
QEMU_SERIAL="-serial file:../serial_opt.txt"
|
||||
QEMU_DRIVE="id=disk,file=${QEMU_DISK_IMAGE},if=none"
|
||||
QEMU_ACCELARATE=""
|
||||
QEMU_ARGUMENT=""
|
||||
|
||||
# 如果qemu_accel不为空
|
||||
if [ -n "${qemu_accel}" ]; then
|
||||
@ -90,22 +91,27 @@ else
|
||||
|
||||
fi
|
||||
|
||||
if [ ${ARCH} == "riscv64" ]; then
|
||||
# 如果是riscv64架构,就不需要图形界面
|
||||
QEMU_ARGUMENT+=" --nographic "
|
||||
# 从控制台显示
|
||||
QEMU_MONITOR=""
|
||||
QEMU_SERIAL=""
|
||||
fi
|
||||
|
||||
|
||||
# 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 -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
|
||||
# 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+=" ${QEMU_SHM_OBJECT} "
|
||||
QEMU_ARGUMENT+=" ${QEMU_ACCELARATE} "
|
||||
|
||||
# 如果是riscv64架构,就不需要图形界面
|
||||
if [ ${ARCH} == "riscv64" ]; then
|
||||
QEMU_ARGUMENT+=" -nographic "
|
||||
fi
|
||||
|
||||
|
||||
# 安装riscv64的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)
|
||||
|
||||
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
|
||||
echo "下载完成"
|
||||
echo "正在解压u-boot到 '$uboot_parent_path'..."
|
||||
@ -140,7 +146,7 @@ if [ $flag_can_run -eq 1 ]; then
|
||||
BIOS_TYPE=uefi
|
||||
;;
|
||||
legacy)
|
||||
BIOS_TYPE=lagacy
|
||||
BIOS_TYPE=legacy
|
||||
;;
|
||||
esac;shift 2;;
|
||||
--display)
|
||||
|
@ -25,8 +25,15 @@ eval set -- "${ARGS}"
|
||||
#echo formatted parameters=[$@]
|
||||
echo "开始写入磁盘镜像..."
|
||||
|
||||
if [ ${ARCH} == "i386" ] || [ ${ARCH} == "x86_64" ]; then
|
||||
|
||||
INSTALL_GRUB_TO_IMAGE="1"
|
||||
|
||||
else
|
||||
INSTALL_GRUB_TO_IMAGE="0"
|
||||
fi
|
||||
|
||||
|
||||
# toolchain
|
||||
GRUB_ABS_PREFIX=/opt/dragonos-grub
|
||||
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}
|
||||
|
||||
# 检测grub文件夹是否存在
|
||||
if [ -d "${GRUB_INSTALL_PATH}" ]; then
|
||||
echo "grub已安装"
|
||||
if [ -d "${GRUB_INSTALL_PATH}" ] || [ "${INSTALL_GRUB_TO_IMAGE}" = "0" ]; then
|
||||
echo "无需安装grub"
|
||||
INSTALL_GRUB_TO_IMAGE="0"
|
||||
else
|
||||
mkdir -p ${GRUB_INSTALL_PATH}
|
||||
mkdir -p ${GRUB_INSTALL_PATH}
|
||||
cp ${kernel} ${root_folder}/bin/disk_mount/boot/
|
||||
fi
|
||||
|
||||
cp ${kernel} ${root_folder}/bin/disk_mount/boot
|
||||
# 拷贝用户程序到磁盘镜像
|
||||
mkdir -p ${root_folder}/bin/disk_mount/bin
|
||||
mkdir -p ${root_folder}/bin/disk_mount/dev
|
||||
|
Loading…
x
Reference in New Issue
Block a user