Patch gcc toolchain (#111)

* 添加了GCC_cross_compile——tool_chain

* - 解决环境变量路径拼接时,多了`/`的问题
- apt安装时增加-y,不需用户确认

* 解决添加环境变量的命令有误的问题

* 修正编译错误时,还会执行下一步的问题

* new: 编译完成后清理临时文件

* 更新makefile

* 调整:把grub安装在 $HOME/opt/dragonos-grub下

* new: 新增dockerfile

* 将镜像源换成中科大的(原因是清华的总是ban掉用于构建镜像的服务器的ip)

* 修改为基于debian bullseye构建

* 取消指定版本

* 修复MBR磁盘镜像未设置启动标志的bug

* 取消在docker中安装grub

* 安装grub的过程改到客户机上进行

* bootstrap.sh 添加--no-docker

* 使用新版的docker编译镜像

* 修补, 添加了一些关于gcc的check

Co-authored-by: longjin <longjin@RinGoTek.cn>
This commit is contained in:
guanjinquan 2022-12-22 21:09:12 +08:00 committed by GitHub
parent ba0d93d8b2
commit 5ed4cd4602
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 680 additions and 59 deletions

View File

@ -28,9 +28,18 @@ ifeq ($(DEBUG), DEBUG)
GLOBAL_CFLAGS += -g
endif
export CC=gcc
# ifeq ($(DragonOS_GCC), )
# $(error 尚未安装DragonOS交叉编译器, 请使用tools文件夹下的build_gcc_toolchain.sh脚本安装)
# endif
.PHONY: all
export CC=$(DragonOS_GCC)/x86_64-elf-gcc
export LD=ld
export AS=$(DragonOS_GCC)/x86_64-elf-as
export NM=$(DragonOS_GCC)/x86_64-elf-nm
export OBJCOPY=$(DragonOS_GCC)/x86_64-elf-objcopy
.PHONY: all
all: kernel user
@ -64,11 +73,11 @@ gdb:
# 写入磁盘镜像
write_diskimage:
sudo sh -c "cd tools && bash grub_auto_install.sh && bash $(ROOT_PATH)/tools/write_disk_image.sh --bios=legacy && cd .."
bash -c "cd tools && bash grub_auto_install.sh && sudo bash $(ROOT_PATH)/tools/write_disk_image.sh --bios=legacy && cd .."
# 写入磁盘镜像(uefi)
write_diskimage-uefi:
sudo sh -c "cd tools && bash grub_auto_install.sh && bash $(ROOT_PATH)/tools/write_disk_image.sh --bios=uefi && cd .."
bash -c "cd tools && bash grub_auto_install.sh && sudo bash $(ROOT_PATH)/tools/write_disk_image.sh --bios=uefi && cd .."
# 不编译直接启动QEMU
qemu:
sh -c "cd tools && bash run-qemu.sh --bios=legacy && cd .."
@ -85,6 +94,7 @@ build:
docker:
@echo "使用docker构建"
sudo bash tools/build_in_docker.sh || exit 1
$(MAKE) write_diskimage || exit 1
# uefi方式启动
run-uefi:
@ -102,4 +112,5 @@ run:
run-docker:
@echo "使用docker构建并运行"
sudo bash tools/build_in_docker.sh || exit 1
$(MAKE) write_diskimage || exit 1
$(MAKE) qemu

View File

@ -15,7 +15,7 @@
```shell
cd tools
bash bootstrap.sh
bash bootstrap.sh # 这里请不要加上sudo, 因为需要安装的开发依赖包是安装在用户环境而非全局环境
```
:::{note}
@ -26,7 +26,18 @@ bash bootstrap.sh
欢迎您为其他的系统完善构建脚本!
:::
**如果一键初始化脚本能够正常运行,并输出最终的“祝贺”界面,那么恭喜你,可以直接跳到{ref}`这里 <_get_dragonos_source_code>`进行阅读!**
**如果一键初始化脚本能够正常运行,并输出最终的“祝贺”界面(如下所示),那么恭喜你,可以直接跳到{ref}`这里 <_get_dragonos_source_code>`进行阅读!**
```shell
|-----------Congratulations!---------------|
| |
| 你成功安装了DragonOS所需的依赖项! |
| 您可以通过以下命令运行它: |
| |
| make run-docker -j 你的cpu核心数 |
| |
|------------------------------------------|
```
### 依赖清单(手动安装)
@ -184,7 +195,8 @@ make run-docker
&emsp;&emsp;在qemu虚拟机被启动后我们需要在控制台输入字母`c`,然后回车。这样,虚拟机就会开始执行。
:::{note}
首次编译时由于需要下载Rust相关的索引几百MB大小因此需要一定的时间请耐心等候
(1) 首次编译时由于需要下载Rust相关的索引几百MB大小因此需要一定的时间请耐心等候
(2) 输入命令可能需要加上sudo
:::
**关于编译命令的用法,请见:{ref}`编译命令讲解 <_build_system_command>`**

View File

@ -1,5 +1,6 @@
all:
@if [ -z $$DragonOS_GCC ]; then echo "\033[31m [错误]尚未安装DragonOS交叉编译器, 请使用tools文件夹下的build_gcc_toolchain.sh脚本安装 \033[0m"; exit 1; fi
$(MAKE) -C src all

View File

@ -23,7 +23,7 @@ kernel_subdirs := common driver process debug filesystem time arch exception mm
head.o: head.S
$(CC) -E head.S > _head.s # 预处理
as $(ASFLAGS) -o head.o _head.s
$(AS) $(ASFLAGS) -o head.o _head.s
main.o: main.c
@ -38,7 +38,7 @@ kernel_rust:
all: kernel
@echo "Linking kernel..."
ld -b elf64-x86-64 -z muldefs -o kernel head.o main.o $(shell find . -name "*.o") ../target/x86_64-unknown-none/release/libdragonos_kernel.a -T link.lds
$(LD) -b elf64-x86-64 -z muldefs -o kernel head.o main.o $(shell find . -name "*.o") ../target/x86_64-unknown-none/release/libdragonos_kernel.a -T link.lds
# 生成kallsyms
current_dir=$(pwd)
@ -55,10 +55,10 @@ all: kernel
# 重新链接
@echo "Re-Linking kernel..."
@echo $(shell find . -name "*.o")
ld -b elf64-x86-64 -z muldefs -o kernel head.o main.o $(shell find . -name "*.o") ../target/x86_64-unknown-none/release/libdragonos_kernel.a ./debug/kallsyms.o -T link.lds
$(LD) -b elf64-x86-64 -z muldefs -o kernel head.o main.o $(shell find . -name "*.o") ../target/x86_64-unknown-none/release/libdragonos_kernel.a ./debug/kallsyms.o -T link.lds
@echo "Generating kernel ELF file..."
# 生成内核文件
objcopy -I elf64-x86-64 -O elf64-x86-64 -R ".comment" -R ".eh_frame" kernel ../../bin/kernel/kernel.elf
$(OBJCOPY) -I elf64-x86-64 -O elf64-x86-64 -R ".comment" -R ".eh_frame" kernel ../../bin/kernel/kernel.elf
@echo "Kernel Build Done."
ECHO:

View File

@ -6,7 +6,7 @@ all: entry.o irq.o softirq.o trap.o
entry.o: entry.S
$(CC) -E entry.S > _entry.s
as $(ASFLAGS) -o entry.o _entry.s
$(AS) $(ASFLAGS) -o entry.o _entry.s
trap.o: trap.c
$(CC) $(CFLAGS) -c trap.c -o trap.o

View File

@ -105,14 +105,14 @@ multiboot_header:
.long CHECKSUM
// Multiboot2 Specification version 2.0.pdf
//
// (qemu, : 1440*900, : 640*480, )
.align 8
framebuffer_tag_start:
.short MULTIBOOT_HEADER_TAG_FRAMEBUFFER
.short MULTIBOOT_HEADER_TAG_OPTIONAL
.long framebuffer_tag_end - framebuffer_tag_start
.long 1440
.long 900
.long 1440 //
.long 900 //
.long 32
framebuffer_tag_end:
.align 8
@ -662,4 +662,4 @@ gdt64_pointer:
gdt64_pointer64:
.short gdt64_pointer-gdt64-1
.quad gdt64

View File

@ -13,7 +13,7 @@ $(kernel_process_objs): ECHO
procs.o: proc.S
$(CC) -E proc.S > _proc.s
as $(ASFLAGS) -o procs.o _proc.s
$(AS) $(ASFLAGS) -o procs.o _proc.s
all: procs.o $(kernel_process_objs)

53
tools/Dockerfile Normal file
View File

@ -0,0 +1,53 @@
FROM debian:bullseye
# 设置工作目录
WORKDIR /build-image
# 将本地的脚本复制到工作目录
COPY *.sh ./
# 设置用来存放rust缓存的卷
VOLUME [ "/root/.cargo/registry" ]
# 设置rust源的环境变量
ENV RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
ENV RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
RUN sed -i "s@http://\(deb\|security\).debian.org@http://mirrors.ustc.edu.cn@g" /etc/apt/sources.list && apt update && apt install -y \
ca-certificates \
curl \
gnupg \
lsb-release \
llvm-dev libclang-dev clang gcc-multilib \
gcc build-essential fdisk dosfstools qemu-kvm \
sudo wget
# 安装Rust
RUN curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain nightly -y && \
# You have to add the rustup variables to the $PATH
echo "export PATH=\"\$HOME/.cargo/bin:\$PATH\"" >> ~/.bashrc && \
bash -c "source $HOME/.cargo/env && \
# 更换cargo的索引源
touch $HOME/.cargo/config && \
bash change_rust_src.sh && \
# 安装rust的编译工具
echo "正在安装DragonOS所需的rust组件...首次安装需要一些时间来更新索引,请耐心等待..." && \
cargo install cargo-binutils && \
rustup toolchain install nightly && \
rustup default nightly && \
rustup component add rust-src && \
rustup component add llvm-tools-preview && \
rustup target add x86_64-unknown-none"
# 编译安装GCC交叉编译工具链
RUN bash build_gcc_toolchain.sh -f
# 清除缓存
WORKDIR /
RUN apt-get autoremove -q -y && \
apt-get clean -q -y && \
rm -rf /build-image
ENV DragonOS_GCC=/root/opt/dragonos-gcc/gcc-x86_64-unknown-none/bin/
# 设置容器启动后执行的命令
CMD ["/bin/bash"]

View File

@ -1,23 +1,25 @@
emulator="qemu"
defpackman="apt-get"
dockerInstall="true"
export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
banner()
{
echo "|------------------------------------------|"
echo "|------------------------------------------|"
echo "| Welcome to the DragonOS bootstrap |"
echo "|------------------------------------------|"
}
# 因为编码原因, 只有在vim打开该文件的时候对齐才是真的对齐
congratulations()
{
echo "|-----------Congratulations!---------------|"
echo "|-----------Congratulations!---------------|"
echo "| |"
echo "| 你成功安装了DragonOS所需的依赖项! |"
echo "| 您可以通过以下命令运行它: |"
echo "| 你成功安装了DragonOS所需的依赖项! |"
echo "| 您可以通过以下命令运行它: |"
echo "| |"
echo "| make run-docker -j 你的cpu核心数 |"
echo "| make run-docker -j 你的cpu核心数 |"
echo "| |"
echo "|------------------------------------------|"
}
@ -39,8 +41,8 @@ install_ubuntu_debian_pkg()
lsb-release \
llvm-dev libclang-dev clang gcc-multilib \
gcc build-essential fdisk dosfstools
if [ -z "$(which docker)" ]; then
if [ -z "$(which docker)" ] && [ -n ${dockerInstall} ]; then
echo "正在安装docker..."
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
@ -49,7 +51,9 @@ install_ubuntu_debian_pkg()
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo $1 update
sudo "$1" install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
else
elif [ -z ${dockerInstall} ]; then
echo "您传入--no-docker参数生效, 安装docker步骤被跳过."
elif [ -n "$(which docker)" ]; then
echo "您的计算机上已经安装了docker"
fi
@ -138,9 +142,32 @@ rustInstall() {
fi
}
############# 脚本开始 ##############
# 读取参数及选项,使用 -help 参数查看详细选项
while true; do
if [ -z "$1" ]; then
break;
fi
echo "repeat"
case "$1" in
"--no-docker")
dockerInstall=""
;;
"--help")
echo "--no-docker(not install docker): 该参数表示执行该脚本的过程中不单独安装docker."
exit 0
;;
*)
echo "无法识别参数$1, 请传入 --help 参数查看提供的选项."
;;
esac
shift 1
done
############ 开始执行 ###############
banner
rustInstall
banner # 开始横幅
rustInstall # 安装rust
if [ "Darwin" == "$(uname -s)" ]; then
install_osx_pkg "$emulator" || exit 1
@ -176,10 +203,14 @@ fi
# 创建磁盘镜像
bash create_hdd_image.sh
# 编译安装GCC交叉编译工具链
bash build_gcc_toolchain.sh
# 编译安装grub
bash grub_auto_install.sh
# 解决kvm权限问题
USR=$USER
sudo adduser $USR kvm
sudo chown $USR /dev/kvm
congratulations
congratulations

View File

@ -0,0 +1,184 @@
# init something here
current_path=$PATH
current_pwd=$PWD
# 不建议自行选择安装的位置, 如果要修改请自行修改 INSTALL_POS
STRUCTURE="x86_64" # 这里选择 x86_64 (64位),而不是选择 i686 架构(32位)
INSTALL_POS="$HOME/opt/dragonos-gcc"
PREFIX="$INSTALL_POS/gcc-$STRUCTURE-unknown-none"
TARGET="${STRUCTURE}-elf"
PATH="$PREFIX/bin:$PATH"
TARGET_GCC="$STRUCTURE-elf-gcc"
TARGET_LD="$STRUCTURE-elf-ld"
TARGET_AS="$STRUCTURE-elf-as"
# 获取选项
KEEP_BINUTILS=0
KEEP_GCC=0
CHANGE_SOURCE=0
FORCE=0
while true; do
if [ ! -n "$1" ]; then
break
fi
case "$1" in
"-rebuild")
echo "清除${INSTALL_POS}目录下的所有信息"
rm -rf "${INSTALL_POS}"
;;
"-kb")
KEEP_BINUTILS=1
;;
"-kg")
KEEP_GCC=1
;;
"-cs")
CHANGE_SOURCE=1
;;
"-f")
FORCE=1
;;
"-help")
echo "脚本选项如下:"
echo "-rebuild: 清除上一次安装的全部信息, 即删掉$INSTALL_POS目录下的所有内容, 然后重新构建gcc工具链."
echo "-kg(keep-gcc): 您确保${STRUCTURE}-gcc已被编译安装, 本次调用脚本不重复编译安装gcc. 如果没有安装,脚本仍然会自动安装."
echo "-kb(keep-binutils): 您确保binutils已被编译安装, 本次调用脚本不重复编译安装binutils. 如果没有安装,脚本仍然会自动安装."
echo "-cs(change source): 如果包含该选项, 使用清华源下载gcc和binutils. 否则默认官方源."
echo "-f(force): 如果包含该选项, 可以强制使用root权限安装在/root/目录下."
;;
*)
echo "不认识参数$1"
;;
esac
shift 1
done
# check: Don't install the gcc-toolchain in /root/*
if [ "${HOME:0:5}" = "/root" ] && [ $FORCE -eq 0 ]; then
echo -e "\033[35m 不要把GCC交叉编译工具链安装在/root/目录下, 或者请不要使用sudo \033[0m"
echo -e "\033[35m gcc交叉编译工具链默认安装在: /home/<your_usr_name>/opt/dragonos-gcc/ \033[0m"
echo -e "\033[35m 如果想要在/root/目录下安装(或者您的操作系统只有root用户), 请使用指令: sudo bash build_gcc_toolchain.sh -f \033[0m"
exit 0
else
# 安装开始[提示]
echo -e "\033[35m [开始安装] \033[0m"
echo -e "\033[33m gcc交叉编译工具链默认安装在: /home/<your_usr_name>/opt/dragonos-gcc/, 整个过程耗时: 5-30mins \033[0m"
sleep 0.3s
fi
# install prerequisited
# 注意texinfo和binutils的版本是否匹配
# 注意gmp/mpc/mpfr和gcc/g++的版本是否匹配
sudo apt-get install -y \
g++ \
gcc \
make \
texinfo \
libgmp3-dev \
libmpc-dev \
libmpfr-dev \
flex \
wget
# build the workspace
mkdir $HOME/opt
mkdir $INSTALL_POS
mkdir $PREFIX
cd $INSTALL_POS
# compile binutils
BIN_UTILS="binutils-2.38"
BIN_UTILS_TAR="${BIN_UTILS}.tar.gz"
if [[ ! -n "$(find $PREFIX/bin/ -name ${TARGET_LD})" && ! -n "$(find $PREFIX/bin/ -name ${TARGET_AS})" ]] || [ KEEP_BINUTILS -ne 1 ]; then
if [ KEEP_BINUTILS -eq 1 ]; then
echo -e "\033[35m 没有检测到 ${TARGET_LD} 或 没有检测到 ${TARGET_AS}, -kb参数无效 \033[0m"
echo -e "\033[35m 开始安装binutils \033[0m"
sleep 1s
fi
if [ ! -d "$BIN_UTILS" ]; then
if [ ! -f "$BIN_UTILS_TAR" ]; then
echo -e "\033[33m [提醒] 如果使用的是国外源, 下载时间可能偏久. 如果需要使用清华源, 请以输入参数-cs, 即: bash build_gcc_toolchain.sh -cs \033[0m "
if [ CHANGE_SOURCE ]; then
# 国内源
wget "https://mirrors.ustc.edu.cn/gnu/binutils/${BIN_UTILS_TAR}" -P "$INSTALL_POS"
else
# 官方网站
wget https://ftp.gnu.org/gnu/binutils/${BIN_UTILS_TAR} -P "$INSTALL_POS"
fi
fi
tar zxvf "$BIN_UTILS_TAR"
fi
# 开始编译
mkdir build-binutils
cd build-binutils
../${BIN_UTILS}/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror
make -j $(nproc) || exit 1
make install || exit 1
cd ..
fi
# compile GCC
GCC_FILE="gcc-11.3.0"
GCC_FILE_TAR="${GCC_FILE}.tar.gz"
if [ ! -n "$(find $PREFIX/bin/* -name $TARGET_GCC)" ] || [ KEEP_GCC -ne 1 ]; then
if [ KEEP_GCC -eq 1 ]; then
echo -e "\033[35m 没有检测到 $TARGET_GCC, -kg参数无效 \033[0m"
echo -e "\033[35m 开始安装binutils \033[0m"
sleep 1s
fi
if [ ! -d "$GCC_FILE" ]; then
if [ ! -f "$GCC_FILE_TAR" ]; then
echo -e "\033[33m [提醒] 如果使用的是国外源, 下载时间可能偏久. 如果需要使用清华源, 请以输入参数-cs, 即: bash build_gcc_toolchain.sh -cs \033[0m "
if [ CHANGE_SOURCE ]; then
# 国内源
wget "https://mirrors.ustc.edu.cn/gnu/gcc/${GCC_FILE}/${GCC_FILE_TAR}" -P "$INSTALL_POS"
else
# 官方网站
wget "http://ftp.gnu.org/gnu/gcc/${GCC_FILE}/${GCC_FILE_TAR}" -P "$INSTALL_POS"
fi
fi
tar zxvf "$GCC_FILE_TAR"
fi
# 开始编译安装
mkdir build-gcc
cd build-gcc
../${GCC_FILE}/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers
make all-gcc -j $(nproc) || exit 1
make all-target-libgcc -j $(nproc) || exit 1
make install-gcc -j $(nproc) || exit 1
make install-target-libgcc -j $(nproc) || exit 1
cd ..
fi
# update PATH
if [ -n "$(grep -F "export DragonOS_GCC=$PREFIX/bin/" $HOME/.bashrc)" ]; then
echo "[info] DragonOS_GCC has been in the "'$PATH'
else
echo 'export DragonOS_GCC='"$PREFIX"'/bin' >> "$HOME/.bashrc"
echo 'export PATH="$DragonOS_GCC:$PATH"' >> "$HOME/.bashrc"
echo "[info] Add DragonOS_GCC into PATH successfully."
fi
source "$HOME/.bashrc"
# final check
if [ -n "$(find $PREFIX/bin/* -name $TARGET_GCC)" ] &&
[ -n "$(find $PREFIX/bin/* -name $TARGET_LD)" ] &&
[ -n "$(find $PREFIX/bin/* -name $TARGET_AS)" ]; then
# 删除临时文件
rm -rf "$BIN_UTILS"
rm -rf "$BIN_UTILS_TAR"
rm -rf "build-binutils"
rm -rf "$GCC_FILE"
rm -rf "$GCC_FILE_TAR"
rm -rf "build-gcc"
echo -e "\033[42;37m [构建成功] Build Successfully.(请重新打开另一个Shell窗口或者重新打开你的IDE以获取新的环境变量) \033[0m"
else
echo -e "\033[31m [错误] 未找到$STRUCTURE-elf-gcc, $STRUCTURE-elf-ld和$STRUCTURE-elf-as. \033[0m"
echo -e "\033[31m [构建失败] 请尝试重新运行build_gcc_toolchain.sh, 或者查看输出,找到错误的原因. \033[0m"
fi
cd "$current_pwd"

View File

@ -1,10 +1,10 @@
docker rm -f dragonos-build || echo "No existed container"
p=`pwd`
cpu_count=$(cat /proc/cpuinfo |grep "processor"|wc -l)
docker run --rm --privileged=true --cap-add SYS_ADMIN --cap-add MKNOD -v $p:/data -v /dev:/dev -v dragonos-build-cargo:/root/.cargo/registry --name dragonos-build -i dragonos/dragonos-dev:v1.1.0-beta3 bash << EOF
docker run --rm --privileged=true --cap-add SYS_ADMIN --cap-add MKNOD -v $(pwd):/data -v /dev:/dev -v dragonos-build-cargo:/root/.cargo/registry --name dragonos-build -i dragonos/dragonos-dev:v1.2 bash << EOF
source ~/.cargo/env
source ~/.bashrc
cd /data
# Change rust src
bash tools/change_rust_src.sh
make all -j $cpu_count && make write_diskimage
make all -j $cpu_count
EOF

View File

@ -20,6 +20,7 @@ n
a
w
EOF

View File

@ -1,12 +1,20 @@
#!/bin/bash
grub_dir_i386_efi=arch/i386/efi/grub
grub_dir_i386_legacy=arch/i386/legacy/grub
grub_dir_x86_64_efi=arch/x86_64/efi/grub
ABS_PREFIX=/opt/dragonos-grub
grub_dir_i386_efi=${ABS_PREFIX}/arch/i386/efi/grub
grub_dir_i386_legacy=${ABS_PREFIX}/arch/i386/legacy/grub
grub_dir_x86_64_efi=${ABS_PREFIX}/arch/x86_64/efi/grub
mkdir -p ${grub_dir_i386_efi}
mkdir -p ${grub_dir_i386_legacy}
mkdir -p ${grub_dir_x86_64_efi}
# 防止外层声明了环境变量影响到grub的编译
export CC=gcc
export LD=ld
export AS=as
export NM=nm
export OBJCOPY=objcopy
#检测grub是否已经安装
if [ -d ${grub_dir_i386_efi}/bin ] && [ -d ${grub_dir_i386_legacy}/bin ] && [ -d ${grub_dir_x86_64_efi}/bin ] ; then
@ -19,7 +27,7 @@ if ! hash 2>/dev/null apt-get; then
fi
#下载grub2.06
if [ ! -f "grub-2.06.tar.xz" ]; then
wget https://mirrors.tuna.tsinghua.edu.cn/gnu/grub/grub-2.06.tar.xz || exit 1
wget https://mirrors.ustc.edu.cn/gnu/grub/grub-2.06.tar.xz || exit 1
fi
echo "开始下载grub2.06"
@ -42,19 +50,19 @@ sudo apt-get install -y \
cd grub-2.06
echo "开始安装grub2.06"
#编译安装三个版本的grub
./configure --target=i386 --prefix=$(dirname $PWD)/${grub_dir_i386_legacy} || exit 1
./configure --target=i386 --prefix=${grub_dir_i386_legacy} || exit 1
make -j $(nproc) || exit 1
make install || exit 1
sudo make install || exit 1
make clean || exit 1
./configure --target=i386 --with-platform=efi --prefix=$(dirname $PWD)/${grub_dir_i386_efi} || exit 1
./configure --target=i386 --with-platform=efi --prefix=${grub_dir_i386_efi} || exit 1
make -j $(nproc) || exit 1
make install || exit 1
sudo make install || exit 1
make clean || exit 1
./configure --target=x86_64 --with-platform=efi --prefix=$(dirname $PWD)/${grub_dir_x86_64_efi} || exit 1
./configure --target=x86_64 --with-platform=efi --prefix=${grub_dir_x86_64_efi} || exit 1
make -j $(nproc) || exit 1
make install || exit 1
sudo make install || exit 1
cd ..
#解除权限限制

View File

@ -22,12 +22,12 @@ echo "开始写入磁盘镜像..."
# toolchain
GRUB_ABS_PREFIX=/opt/dragonos-grub
GRUB_PATH_I386_LEGACY_INSTALL=${GRUB_ABS_PREFIX}/arch/i386/legacy/grub/sbin/grub-install
GRUB_PATH_I386_EFI_INSTALL=${GRUB_ABS_PREFIX}/arch/i386/efi/grub/sbin/grub-install
GRUB_PATH_X86_64_EFI_INSTALL=${GRUB_ABS_PREFIX}/arch/x86_64/efi/grub/sbin/grub-install
GRUB_PATH_I386_LEGACY_INSTALL=${root_folder}/tools/arch/i386/legacy/grub/sbin/grub-install
GRUB_PATH_I386_EFI_INSTALL=${root_folder}/tools/arch/i386/efi/grub/sbin/grub-install
GRUB_PATH_X86_64_EFI_INSTALL=${root_folder}/tools/arch/x86_64/efi/grub/sbin/grub-install
GRUB_PATH_I386_LEGACY_FILE=${root_folder}/tools/arch/i386/legacy/grub/bin/grub-file
GRUB_PATH_I386_LEGACY_FILE=${GRUB_ABS_PREFIX}/arch/i386/legacy/grub/bin/grub-file
# ==============检查文件是否齐全================
@ -77,6 +77,10 @@ fi
# 拷贝程序到硬盘
mkdir -p ${root_folder}/bin/disk_mount
bash mount_virt_disk.sh || exit 1
LOOP_DEVICE=$(lsblk | grep disk_mount|sed 's/.*\(loop[0-9]*\)p1.*/\1/1g'|awk 'END{print $0}')
echo $LOOP_DEVICE
mkdir -p ${boot_folder}/grub
cp ${kernel} ${root_folder}/bin/disk_mount/boot
# 拷贝用户程序到磁盘镜像
@ -96,13 +100,11 @@ cfg_content='set timeout=15
menuentry "DragonOS" {
multiboot2 /boot/kernel.elf "KERNEL_ELF"
}'
# 增加insmod efi_gop防止32位uefi启动报错
echo "echo '${cfg_content}' > ${boot_folder}/grub/grub.cfg" | sh
fi
# rm -rf ${iso_folder}
LOOP_DEVICE=$(lsblk | grep disk_mount|sed 's/.*\(loop[0-9]*\)p1.*/\1/1g'|awk 'END{print $0}')
echo $LOOP_DEVICE
case "$1" in
--bios)
case "$2" in

View File

@ -22,6 +22,7 @@ $(user_sub_dirs): ECHO sys_api_lib
app: $(user_sub_dirs)
all: app
@if [ -z $$DragonOS_GCC ]; then echo "\033[31m [错误]尚未安装DragonOS交叉编译器, 请使用tools文件夹下的build_gcc_toolchain.sh脚本安装 \033[0m"; exit 1; fi
$(shell if [ ! -e $(tmp_output_dir) ];then mkdir -p $(tmp_output_dir); fi)
$(shell if [ ! -e $(output_dir) ];then mkdir -p $(output_dir); fi)

View File

@ -8,4 +8,5 @@ $(user_apps_sub_dirs): ECHO
$(MAKE) -C $@ all CFLAGS="$(CFLAGS)" tmp_output_dir="$(tmp_output_dir)" output_dir="$(output_dir)" sys_libs_dir="$(sys_libs_dir)"
all: $(user_apps_sub_dirs)
all: $(user_apps_sub_dirs)

View File

@ -3,9 +3,9 @@ GIT_COMMIT_SHA1=$(shell git log -n 1 | head -n 1 | cut -d ' ' -f 2 | cut -c1-8)
all: about.o
ld -b elf64-x86-64 -z muldefs -o $(tmp_output_dir)/about $(shell find . -name "*.o") $(shell find $(sys_libs_dir) -name "*.o") -T about.lds
$(LD) -b elf64-x86-64 -z muldefs -o $(tmp_output_dir)/about $(shell find . -name "*.o") $(shell find $(sys_libs_dir) -name "*.o") -T about.lds
objcopy -I elf64-x86-64 -R ".eh_frame" -R ".comment" -O elf64-x86-64 $(tmp_output_dir)/about $(output_dir)/about.elf
$(OBJCOPY) -I elf64-x86-64 -R ".eh_frame" -R ".comment" -O elf64-x86-64 $(tmp_output_dir)/about $(output_dir)/about.elf
about.o: version_header about.c
$(CC) $(CFLAGS) -c about.c -o about.o

View File

@ -1,8 +1,8 @@
all: shell.o cmd.o cmd_help.o cmd_test.o
ld -b elf64-x86-64 -z muldefs -o $(tmp_output_dir)/shell $(shell find . -name "*.o") $(shell find $(sys_libs_dir) -name "*.o") -T shell.lds
$(LD) -b elf64-x86-64 -z muldefs -o $(tmp_output_dir)/shell $(shell find . -name "*.o") $(shell find $(sys_libs_dir) -name "*.o") -T shell.lds
objcopy -I elf64-x86-64 -R ".eh_frame" -R ".comment" -O elf64-x86-64 $(tmp_output_dir)/shell $(output_dir)/shell.elf
$(OBJCOPY) -I elf64-x86-64 -R ".eh_frame" -R ".comment" -O elf64-x86-64 $(tmp_output_dir)/shell $(output_dir)/shell.elf
shell.o: shell.c
$(CC) $(CFLAGS) -c shell.c -o shell.o

View File

@ -1,7 +1,7 @@
all: main.o
ld -b elf64-x86-64 -z muldefs -o $(tmp_output_dir)/test_signal $(shell find . -name "*.o") $(shell find $(sys_libs_dir) -name "*.o") -T link.lds
$(LD) -b elf64-x86-64 -z muldefs -o $(tmp_output_dir)/test_signal $(shell find . -name "*.o") $(shell find $(sys_libs_dir) -name "*.o") -T link.lds
objcopy -I elf64-x86-64 -R ".eh_frame" -R ".comment" -O elf64-x86-64 $(tmp_output_dir)/test_signal $(output_dir)/test_signal.elf
$(OBJCOPY) -I elf64-x86-64 -R ".eh_frame" -R ".comment" -O elf64-x86-64 $(tmp_output_dir)/test_signal $(output_dir)/test_signal.elf
main.o: main.c
$(CC) $(CFLAGS) -c main.c -o main.o

View File

@ -0,0 +1,316 @@
/* Copyright (C) 1997-2022 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
/*
* ISO C99: 7.18 Integer types <stdint.h>
*/
#ifndef _STDINT_H
#define _STDINT_H 1
# define __WORDSIZE 64
/* Convenience types. */
typedef unsigned char __u_char;
typedef unsigned short int __u_short;
typedef unsigned int __u_int;
typedef unsigned long int __u_long;
/* Fixed-size types, underlying types depend on word size and compiler. */
typedef signed char __int8_t;
typedef unsigned char __uint8_t;
typedef signed short int __int16_t;
typedef unsigned short int __uint16_t;
typedef signed int __int32_t;
typedef unsigned int __uint32_t;
#if __WORDSIZE == 64
typedef signed long int __int64_t;
typedef unsigned long int __uint64_t;
#else
__extension__ typedef signed long long int __int64_t;
__extension__ typedef unsigned long long int __uint64_t;
#endif
/* Smallest types with at least a given width. */
typedef __int8_t __int_least8_t;
typedef __uint8_t __uint_least8_t;
typedef __int16_t __int_least16_t;
typedef __uint16_t __uint_least16_t;
typedef __int32_t __int_least32_t;
typedef __uint32_t __uint_least32_t;
typedef __int64_t __int_least64_t;
typedef __uint64_t __uint_least64_t;
typedef __uint8_t uint8_t;
typedef __uint16_t uint16_t;
typedef __uint32_t uint32_t;
typedef __uint64_t uint64_t;
typedef __int8_t int8_t;
typedef __int16_t int16_t;
typedef __int32_t int32_t;
typedef __int64_t int64_t;
/* Small types. */
/* Signed. */
typedef __int_least8_t int_least8_t;
typedef __int_least16_t int_least16_t;
typedef __int_least32_t int_least32_t;
typedef __int_least64_t int_least64_t;
/* Unsigned. */
typedef __uint_least8_t uint_least8_t;
typedef __uint_least16_t uint_least16_t;
typedef __uint_least32_t uint_least32_t;
typedef __uint_least64_t uint_least64_t;
/* Fast types. */
/* Signed. */
typedef signed char int_fast8_t;
#if __WORDSIZE == 64
typedef long int int_fast16_t;
typedef long int int_fast32_t;
typedef long int int_fast64_t;
#else
typedef int int_fast16_t;
typedef int int_fast32_t;
__extension__
typedef long long int int_fast64_t;
#endif
/* Unsigned. */
typedef unsigned char uint_fast8_t;
#if __WORDSIZE == 64
typedef unsigned long int uint_fast16_t;
typedef unsigned long int uint_fast32_t;
typedef unsigned long int uint_fast64_t;
#else
typedef unsigned int uint_fast16_t;
typedef unsigned int uint_fast32_t;
__extension__
typedef unsigned long long int uint_fast64_t;
#endif
/* Types for `void *' pointers. */
#if __WORDSIZE == 64
# ifndef __intptr_t_defined
typedef long int intptr_t;
# define __intptr_t_defined
# endif
typedef unsigned long int uintptr_t;
#else
# ifndef __intptr_t_defined
typedef int intptr_t;
# define __intptr_t_defined
# endif
typedef unsigned int uintptr_t;
#endif
/* Largest integral types. */
#if __WORDSIZE == 64
typedef long int __intmax_t;
typedef unsigned long int __uintmax_t;
#else
__extension__ typedef long long int __intmax_t;
__extension__ typedef unsigned long long int __uintmax_t;
#endif
/* Largest integral types. */
typedef __intmax_t intmax_t;
typedef __uintmax_t uintmax_t;
# if __WORDSIZE == 64
# define __INT64_C(c) c ## L
# define __UINT64_C(c) c ## UL
# else
# define __INT64_C(c) c ## LL
# define __UINT64_C(c) c ## ULL
# endif
/* Limits of integral types. */
/* Minimum of signed integral types. */
# define INT8_MIN (-128)
# define INT16_MIN (-32767-1)
# define INT32_MIN (-2147483647-1)
# define INT64_MIN (-__INT64_C(9223372036854775807)-1)
/* Maximum of signed integral types. */
# define INT8_MAX (127)
# define INT16_MAX (32767)
# define INT32_MAX (2147483647)
# define INT64_MAX (__INT64_C(9223372036854775807))
/* Maximum of unsigned integral types. */
# define UINT8_MAX (255)
# define UINT16_MAX (65535)
# define UINT32_MAX (4294967295U)
# define UINT64_MAX (__UINT64_C(18446744073709551615))
/* Minimum of signed integral types having a minimum size. */
# define INT_LEAST8_MIN (-128)
# define INT_LEAST16_MIN (-32767-1)
# define INT_LEAST32_MIN (-2147483647-1)
# define INT_LEAST64_MIN (-__INT64_C(9223372036854775807)-1)
/* Maximum of signed integral types having a minimum size. */
# define INT_LEAST8_MAX (127)
# define INT_LEAST16_MAX (32767)
# define INT_LEAST32_MAX (2147483647)
# define INT_LEAST64_MAX (__INT64_C(9223372036854775807))
/* Maximum of unsigned integral types having a minimum size. */
# define UINT_LEAST8_MAX (255)
# define UINT_LEAST16_MAX (65535)
# define UINT_LEAST32_MAX (4294967295U)
# define UINT_LEAST64_MAX (__UINT64_C(18446744073709551615))
/* Minimum of fast signed integral types having a minimum size. */
# define INT_FAST8_MIN (-128)
# if __WORDSIZE == 64
# define INT_FAST16_MIN (-9223372036854775807L-1)
# define INT_FAST32_MIN (-9223372036854775807L-1)
# else
# define INT_FAST16_MIN (-2147483647-1)
# define INT_FAST32_MIN (-2147483647-1)
# endif
# define INT_FAST64_MIN (-__INT64_C(9223372036854775807)-1)
/* Maximum of fast signed integral types having a minimum size. */
# define INT_FAST8_MAX (127)
# if __WORDSIZE == 64
# define INT_FAST16_MAX (9223372036854775807L)
# define INT_FAST32_MAX (9223372036854775807L)
# else
# define INT_FAST16_MAX (2147483647)
# define INT_FAST32_MAX (2147483647)
# endif
# define INT_FAST64_MAX (__INT64_C(9223372036854775807))
/* Maximum of fast unsigned integral types having a minimum size. */
# define UINT_FAST8_MAX (255)
# if __WORDSIZE == 64
# define UINT_FAST16_MAX (18446744073709551615UL)
# define UINT_FAST32_MAX (18446744073709551615UL)
# else
# define UINT_FAST16_MAX (4294967295U)
# define UINT_FAST32_MAX (4294967295U)
# endif
# define UINT_FAST64_MAX (__UINT64_C(18446744073709551615))
/* Values to test for integral types holding `void *' pointer. */
# if __WORDSIZE == 64
# define INTPTR_MIN (-9223372036854775807L-1)
# define INTPTR_MAX (9223372036854775807L)
# define UINTPTR_MAX (18446744073709551615UL)
# else
# define INTPTR_MIN (-2147483647-1)
# define INTPTR_MAX (2147483647)
# define UINTPTR_MAX (4294967295U)
# endif
/* Minimum for largest signed integral type. */
# define INTMAX_MIN (-__INT64_C(9223372036854775807)-1)
/* Maximum for largest signed integral type. */
# define INTMAX_MAX (__INT64_C(9223372036854775807))
/* Maximum for largest unsigned integral type. */
# define UINTMAX_MAX (__UINT64_C(18446744073709551615))
/* Limits of other integer types. */
/* Limits of `ptrdiff_t' type. */
# if __WORDSIZE == 64
# define PTRDIFF_MIN (-9223372036854775807L-1)
# define PTRDIFF_MAX (9223372036854775807L)
# else
# if __WORDSIZE32_PTRDIFF_LONG
# define PTRDIFF_MIN (-2147483647L-1)
# define PTRDIFF_MAX (2147483647L)
# else
# define PTRDIFF_MIN (-2147483647-1)
# define PTRDIFF_MAX (2147483647)
# endif
# endif
/* Limits of `sig_atomic_t'. */
# define SIG_ATOMIC_MIN (-2147483647-1)
# define SIG_ATOMIC_MAX (2147483647)
/* Limit of `size_t' type. */
# if __WORDSIZE == 64
# define SIZE_MAX (18446744073709551615UL)
# else
# if __WORDSIZE32_SIZE_ULONG
# define SIZE_MAX (4294967295UL)
# else
# define SIZE_MAX (4294967295U)
# endif
# endif
/* Limits of `wchar_t'. */
# ifndef WCHAR_MIN
/* These constants might also be defined in <wchar.h>. */
# define WCHAR_MIN __WCHAR_MIN
# define WCHAR_MAX __WCHAR_MAX
# endif
/* Limits of `wint_t'. */
# define WINT_MIN (0u)
# define WINT_MAX (4294967295u)
/* Signed. */
# define INT8_C(c) c
# define INT16_C(c) c
# define INT32_C(c) c
# if __WORDSIZE == 64
# define INT64_C(c) c ## L
# else
# define INT64_C(c) c ## LL
# endif
/* Unsigned. */
# define UINT8_C(c) c
# define UINT16_C(c) c
# define UINT32_C(c) c ## U
# if __WORDSIZE == 64
# define UINT64_C(c) c ## UL
# else
# define UINT64_C(c) c ## ULL
# endif
/* Maximal type. */
# if __WORDSIZE == 64
# define INTMAX_C(c) c ## L
# define UINTMAX_C(c) c ## UL
# else
# define INTMAX_C(c) c ## LL
# define UINTMAX_C(c) c ## ULL
# endif
#endif /* stdint.h */

View File

@ -1,6 +1,6 @@
#pragma once
#include <stdint.h>
#include <libc/src/include/stdint.h>
#include <stdbool.h>
typedef unsigned char u_char;

View File

@ -1,5 +1,5 @@
#pragma once
#include <stdint.h>
#include <libc/src/include/stdint.h>
#include <libc/src/sys/types.h>
/**

View File

@ -1,6 +1,6 @@
#pragma once
#include <stdint.h>
#include <libc/src/include/stdint.h>
// 系统调用号
#define SYS_NOT_EXISTS 0