diff --git a/.github/actions/import-toolchain/action.yml b/.github/actions/import-toolchain/action.yml deleted file mode 100644 index 466e2d404..000000000 --- a/.github/actions/import-toolchain/action.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: import-toolchain - -runs: - using: composite - steps: - - uses: actions/checkout@v3 - with: - submodules: 'recursive' - - - name: Cache DragonOS GCC - id: cache-dragonos-gcc - uses: actions/cache@v3 - env: - cache-name: cache-dragonos-gcc - with: - path: | - ~/opt - ~/.bashrc - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('tools/build_gcc_toolchain.sh') }} - - - name: Cache build tools - id: cache-build-tools - uses: actions/cache@v3 - env: - cache-name: cache-build-tools - dadk_version: 0.1.11 - with: - path: | - ~/.cargo - ~/.rustup - ~/.bashrc - ~/opt - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.dadk_version }}-${{ hashFiles('.github/workflows/cache-toolchain.yml') }}-${{ hashFiles('tools/install_musl_gcc.sh') }} - - - uses: ./.github/actions/install-apt-packages - diff --git a/.github/actions/install-apt-packages/action.yml b/.github/actions/install-apt-packages/action.yml deleted file mode 100644 index de85fe83f..000000000 --- a/.github/actions/install-apt-packages/action.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: install-apt-packages - -runs: - using: composite - steps: - - - uses: awalsh128/cache-apt-pkgs-action@latest - with: - packages: llvm-dev libclang-dev clang gcc-multilib libssl-dev pkg-config - version: ${{ hashFiles('.github/actions/install-apt-packages/action.yml') }} - - - uses: awalsh128/cache-apt-pkgs-action@latest - with: - packages: gcc-riscv64-unknown-elf gcc-riscv64-linux-gnu gdb-multiarch - version: ${{ hashFiles('.github/actions/install-apt-packages/action.yml') }} - \ No newline at end of file diff --git a/.github/workflows/cache-toolchain.yml b/.github/workflows/cache-toolchain.yml deleted file mode 100644 index 94519c834..000000000 --- a/.github/workflows/cache-toolchain.yml +++ /dev/null @@ -1,94 +0,0 @@ -name: Cache toolchain - -on: workflow_call - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Cache DragonOS GCC - id: cache-dragonos-gcc - uses: actions/cache@v3 - env: - cache-name: cache-dragonos-gcc - with: - path: | - ~/opt - ~/.bashrc - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('tools/build_gcc_toolchain.sh') }} - - - if: ${{ steps.cache-dragonos-gcc.outputs.cache-hit != 'true' }} - name: build dragonos-gcc - continue-on-error: true - run: | - bash tools/build_gcc_toolchain.sh -f - - - uses: ./.github/actions/install-apt-packages - - - name: Cache build tools - id: cache-build-tools - uses: actions/cache@v3 - env: - cache-name: cache-build-tools - dadk_version: 0.1.11 - with: - path: | - ~/.cargo - ~/.rustup - ~/.bashrc - ~/opt - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.dadk_version }}-${{ hashFiles('.github/workflows/cache-toolchain.yml') }}-${{ hashFiles('tools/install_musl_gcc.sh') }} - - - if: ${{ steps.cache-build-tools.outputs.cache-hit != 'true' }} - name: Install toolchain - continue-on-error: false - run: | - USE_GITHUB=1 bash tools/install_musl_gcc.sh - - cargo install cargo-binutils - rustup toolchain install nightly-x86_64-unknown-linux-gnu - rustup toolchain install nightly-2024-07-23-x86_64-unknown-linux-gnu - rustup toolchain install nightly-2023-08-15-x86_64-unknown-linux-gnu - rustup component add rust-src --toolchain nightly-2024-07-23-x86_64-unknown-linux-gnu - rustup component add rust-src --toolchain nightly-2023-08-15-x86_64-unknown-linux-gnu - rustup target add x86_64-unknown-none --toolchain nightly-2024-07-23-x86_64-unknown-linux-gnu - rustup target add x86_64-unknown-none --toolchain nightly-2023-08-15-x86_64-unknown-linux-gnu - - rustup toolchain install nightly-2024-07-23-riscv64gc-unknown-linux-gnu --force-non-host - rustup toolchain install nightly-2023-08-15-riscv64gc-unknown-linux-gnu --force-non-host - rustup target add riscv64gc-unknown-none-elf --toolchain nightly-2024-07-23-riscv64gc-unknown-linux-gnu - rustup target add riscv64imac-unknown-none-elf --toolchain nightly-2024-07-23-riscv64gc-unknown-linux-gnu - rustup target add riscv64gc-unknown-none-elf --toolchain nightly-2023-08-15-riscv64gc-unknown-linux-gnu - rustup target add riscv64imac-unknown-none-elf --toolchain nightly-2023-08-15-riscv64gc-unknown-linux-gnu - - rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu - rustup component add rust-src - rustup component add llvm-tools-preview - - rustup component add rustfmt - rustup component add rustfmt --toolchain nightly-x86_64-unknown-linux-gnu - rustup component add rustfmt --toolchain nightly-2024-07-23-x86_64-unknown-linux-gnu - rustup component add rustfmt --toolchain nightly-2023-08-15-x86_64-unknown-linux-gnu - rustup component add rustfmt --toolchain nightly-2024-07-23-riscv64gc-unknown-linux-gnu - rustup component add rustfmt --toolchain nightly-2023-08-15-riscv64gc-unknown-linux-gnu - - rustup default nightly-2024-07-23 - - cargo install dadk --version 0.1.11 - - - userapp_musl_toolchain="nightly-2023-08-15-x86_64-unknown-linux-gnu" - - rustup toolchain install ${userapp_musl_toolchain} - rustup component add --toolchain ${userapp_musl_toolchain} rust-src - rustup target add --toolchain ${userapp_musl_toolchain} x86_64-unknown-linux-musl - - rustup target add x86_64-unknown-linux-musl --toolchain nightly-2024-07-23-x86_64-unknown-linux-gnu - rustup component add rust-src --toolchain nightly-2024-07-23-x86_64-unknown-linux-gnu - - - diff --git a/.github/workflows/makefile.yml b/.github/workflows/makefile.yml index c785dee80..58a86ce4d 100644 --- a/.github/workflows/makefile.yml +++ b/.github/workflows/makefile.yml @@ -7,28 +7,26 @@ on: branches: [ "master", "feat-*", "fix-*"] jobs: - # ensure the toolchain is cached - ensure-toolchain: - uses: ./.github/workflows/cache-toolchain.yml format-check: name: Format check ${{ matrix.arch }} runs-on: ubuntu-latest - needs: [ensure-toolchain] continue-on-error: true + container: dragonos/dragonos-dev:v1.3 strategy: matrix: arch: [x86_64, riscv64] steps: + - run: echo "Running in dragonos/dragonos-dev:v1.3" - uses: actions/checkout@v3 - - uses: ./.github/actions/import-toolchain - - name: Format check env: ARCH: ${{ matrix.arch }} + HOME: /root + shell: bash -ileo pipefail {0} run: | printf "\n" >> kernel/src/include/bindings/bindings.rs FMT_CHECK=1 make fmt @@ -36,38 +34,38 @@ jobs: kernel-static-test: name: Kernel static test ${{ matrix.arch }} runs-on: ubuntu-latest - needs: [ensure-toolchain] continue-on-error: true + container: dragonos/dragonos-dev:v1.3 strategy: matrix: arch: [x86_64, riscv64] steps: - - uses: actions/checkout@v3 + - run: echo "Running in dragonos/dragonos-dev:v1.3" - - uses: ./.github/actions/import-toolchain + - uses: actions/checkout@v3 - name: Run kernel static test shell: bash -ileo pipefail {0} env: ARCH: ${{ matrix.arch }} - run: bash -c "source ~/.cargo/env && cd kernel && make test" - + HOME: /root + run: bash -c "source /root/.cargo/env && cd kernel && make test" + build-x86_64: runs-on: ubuntu-latest - needs: [ensure-toolchain] + container: dragonos/dragonos-dev:v1.3 steps: - - uses: actions/checkout@v3 + - run: echo "Running in dragonos/dragonos-dev:v1.3" - - uses: ./.github/actions/import-toolchain - - + - uses: actions/checkout@v3 - name: build the DragonOS env: ARCH: x86_64 + HOME: /root shell: bash -ileo pipefail {0} run: | @@ -77,23 +75,23 @@ jobs: make -j $(nproc) - build-riscv64: runs-on: ubuntu-latest - needs: [ensure-toolchain] + container: dragonos/dragonos-dev:v1.3 steps: + - run: echo "Running in dragonos/dragonos-dev:v1.3" + - uses: actions/checkout@v3 with: submodules: 'recursive' - - uses: ./.github/actions/import-toolchain - - name: build the DragonOS shell: bash -ileo pipefail {0} env: ARCH: riscv64 + HOME: /root run: source ~/.bashrc && source ~/.cargo/env && make kernel -j $(nproc) diff --git a/.github/workflows/publish-dragonos-docker-image.yml b/.github/workflows/publish-dragonos-docker-image.yml new file mode 100644 index 000000000..b20ae61af --- /dev/null +++ b/.github/workflows/publish-dragonos-docker-image.yml @@ -0,0 +1,37 @@ +name: Publish Docker images + +on: + workflow_dispatch: + push: + paths: + - tools/BUILD_CONTAINER_VERSION + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - uses: actions/checkout@v4 + + - name: Fetch versions in the repo + id: fetch-versions + run: | + BUILD_CONTAINER_VERSION=$(cat tools/BUILD_CONTAINER_VERSION) + echo "build_container_version=$BUILD_CONTAINER_VERSION" >> "$GITHUB_OUTPUT" + + - name: Build and push docker image + uses: docker/build-push-action@v4 + with: + context: . + file: ./tools/Dockerfile + platforms: linux/amd64 + push: true + tags: dragonos/dragonos-dev:${{ steps.fetch-versions.outputs.build_container_version }} diff --git a/.vscode/settings.json b/.vscode/settings.json index fb915c105..4560338a7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,7 +9,6 @@ "glib.h": "c", "asm.h": "c", "memory.h": "c", - "multiboot2.h": "c", "kprint.h": "c", "ptrace.h": "c", "mouse.h": "c", @@ -77,7 +76,6 @@ "cstdbool": "c", "typeinfo": "c", "unistd.h": "c", - "syscall_num.h": "c", "stdint.h": "c", "syscall.h": "c", "fcntl.h": "c", @@ -121,9 +119,7 @@ "dirent.h": "c", "cmd_help.h": "c", "wait.h": "c", - "__libc__.h": "c", "ctype.h": "c", - "mmio.h": "c", "stdint-gcc.h": "c", "acpi.h": "c", "assert.h": "c", diff --git a/build-scripts/kernel_build/src/cfiles/arch/mod.rs b/build-scripts/kernel_build/src/cfiles/arch/mod.rs index a856f8465..4f52d74e4 100644 --- a/build-scripts/kernel_build/src/cfiles/arch/mod.rs +++ b/build-scripts/kernel_build/src/cfiles/arch/mod.rs @@ -1,4 +1,4 @@ -use std::path::PathBuf; +use std::{collections::HashSet, path::PathBuf}; use cc::Build; @@ -13,9 +13,9 @@ pub(super) trait CFilesArch { /// 设置架构相关的宏定义 fn setup_defines(&self, c: &mut Build); /// 设置架构相关的全局包含目录 - fn setup_global_include_dir(&self, c: &mut Build); + fn setup_global_include_dir(&self, c: &mut HashSet); /// 设置需要编译的架构相关的文件 - fn setup_files(&self, c: &mut Build, files: &mut Vec); + fn setup_files(&self, c: &mut Build, files: &mut HashSet); /// 设置架构相关的全局编译标志 fn setup_global_flags(&self, c: &mut Build); diff --git a/build-scripts/kernel_build/src/cfiles/arch/riscv64.rs b/build-scripts/kernel_build/src/cfiles/arch/riscv64.rs index 1f0565c83..655af27e1 100644 --- a/build-scripts/kernel_build/src/cfiles/arch/riscv64.rs +++ b/build-scripts/kernel_build/src/cfiles/arch/riscv64.rs @@ -1,4 +1,4 @@ -use std::path::PathBuf; +use std::{collections::HashSet, path::PathBuf}; use crate::{constant::ARCH_DIR_RISCV64, utils::FileUtils}; @@ -12,17 +12,18 @@ impl CFilesArch for RiscV64CFilesArch { c.define("__riscv", None); } - fn setup_global_include_dir(&self, c: &mut cc::Build) { - c.include("src/arch/riscv64/include"); + fn setup_global_include_dir(&self, include_dirs: &mut HashSet) { + include_dirs.insert("src/arch/riscv64/include".into()); } - fn setup_files(&self, _c: &mut cc::Build, files: &mut Vec) { - files.push(PathBuf::from("src/arch/riscv64/asm/head.S")); - files.append(&mut FileUtils::list_all_files( - &arch_path("asm"), - Some("c"), - true, - )); + fn setup_files(&self, _c: &mut cc::Build, files: &mut HashSet) { + files.insert(PathBuf::from("src/arch/riscv64/asm/head.S")); + + FileUtils::list_all_files(&arch_path("asm"), Some("c"), true) + .into_iter() + .for_each(|f| { + files.insert(f); + }); } fn setup_global_flags(&self, c: &mut cc::Build) { diff --git a/build-scripts/kernel_build/src/cfiles/arch/x86_64.rs b/build-scripts/kernel_build/src/cfiles/arch/x86_64.rs index e473a8a9c..8ab7ae2c7 100644 --- a/build-scripts/kernel_build/src/cfiles/arch/x86_64.rs +++ b/build-scripts/kernel_build/src/cfiles/arch/x86_64.rs @@ -1,4 +1,4 @@ -use std::path::PathBuf; +use std::{collections::HashSet, path::PathBuf}; use cc::Build; @@ -13,38 +13,24 @@ impl CFilesArch for X86_64CFilesArch { c.define("__x86_64__", None); } - fn setup_global_include_dir(&self, c: &mut cc::Build) { - c.include("src/arch/x86_64/include"); + fn setup_global_include_dir(&self, include_dirs: &mut HashSet) { + include_dirs.insert("src/arch/x86_64/include".into()); } - fn setup_files(&self, _c: &mut Build, files: &mut Vec) { - // 获取`kernel/src/arch/x86_64/driver/apic`下的所有C文件 - files.append(&mut FileUtils::list_all_files( - &arch_path("driver/apic"), - Some("c"), - true, - )); - - files.append(&mut FileUtils::list_all_files( - &arch_path("init"), - Some("c"), - true, - )); - files.append(&mut FileUtils::list_all_files( - &arch_path("asm"), - Some("c"), - true, - )); - files.append(&mut FileUtils::list_all_files( - &arch_path("interrupt"), - Some("c"), - true, - )); + fn setup_files(&self, _c: &mut Build, files: &mut HashSet) { + const DIRS: [&str; 4] = ["driver/apic", "init", "asm", "interrupt"]; + DIRS.iter().for_each(|dir| { + FileUtils::list_all_files(&arch_path(dir), Some("c"), true) + .into_iter() + .for_each(|f| { + files.insert(f); + }); + }); // setup asm files - files.push(PathBuf::from("src/arch/x86_64/asm/head.S")); - files.push(PathBuf::from("src/arch/x86_64/asm/entry.S")); - files.push(PathBuf::from("src/arch/x86_64/asm/apu_boot.S")); + files.insert(PathBuf::from("src/arch/x86_64/asm/head.S")); + files.insert(PathBuf::from("src/arch/x86_64/asm/entry.S")); + files.insert(PathBuf::from("src/arch/x86_64/asm/apu_boot.S")); } fn setup_global_flags(&self, c: &mut Build) { diff --git a/build-scripts/kernel_build/src/cfiles/common.rs b/build-scripts/kernel_build/src/cfiles/common.rs new file mode 100644 index 000000000..3488e731c --- /dev/null +++ b/build-scripts/kernel_build/src/cfiles/common.rs @@ -0,0 +1,21 @@ +use std::{collections::HashSet, path::PathBuf}; + +use crate::utils::FileUtils; + +pub(super) fn setup_common_files(files: &mut HashSet) { + const DIRS: [&str; 3] = ["src/common", "src/debug/traceback", "src/libs"]; + DIRS.iter().for_each(|dir| { + FileUtils::list_all_files(&dir.into(), Some("c"), true) + .into_iter() + .for_each(|f| { + files.insert(f); + }); + }); +} + +pub(super) fn setup_common_include_dir(include_dirs: &mut HashSet) { + const DIRS: [&str; 3] = ["src/include", "src/common", "src"]; + DIRS.iter().for_each(|dir| { + include_dirs.insert(dir.into()); + }); +} diff --git a/build-scripts/kernel_build/src/cfiles/mod.rs b/build-scripts/kernel_build/src/cfiles/mod.rs index de3efbc5f..90173d661 100644 --- a/build-scripts/kernel_build/src/cfiles/mod.rs +++ b/build-scripts/kernel_build/src/cfiles/mod.rs @@ -1,4 +1,4 @@ -use std::path::PathBuf; +use std::{collections::HashSet, path::PathBuf}; use cc::Build; @@ -7,6 +7,7 @@ use crate::utils::cargo_handler::CargoHandler; use self::arch::current_cfiles_arch; mod arch; +mod common; /// 构建项目的c文件 pub struct CFilesBuilder; @@ -46,19 +47,29 @@ impl CFilesBuilder { } fn setup_global_include_dir(c: &mut Build) { - c.include("src/include"); - c.include("src"); + let mut include_dirs = HashSet::new(); + c.include("."); - current_cfiles_arch().setup_global_include_dir(c); + common::setup_common_include_dir(&mut include_dirs); + + current_cfiles_arch().setup_global_include_dir(&mut include_dirs); + + let include_dirs: Vec = include_dirs.into_iter().collect(); + Self::set_rerun_if_files_changed(&include_dirs); + + include_dirs.into_iter().for_each(|dir| { + c.include(dir); + }); } /// 设置需要编译的文件 fn setup_files(c: &mut Build) { - let mut files: Vec = Vec::new(); - + let mut files: HashSet = HashSet::new(); current_cfiles_arch().setup_files(c, &mut files); - + common::setup_common_files(&mut files); + // 去重 + let files: Vec = files.into_iter().collect(); Self::set_rerun_if_files_changed(&files); c.files(files.as_slice()); } diff --git a/kernel/env.mk b/kernel/env.mk index 7f3f3f605..871f6e7d4 100644 --- a/kernel/env.mk +++ b/kernel/env.mk @@ -2,30 +2,17 @@ include ../env.mk # 设置编译器 ifeq ($(ARCH), x86_64) - -# 如果 x86_64时,DragonOS_GCC 为空,那么设置为默认值 -export DragonOS_GCC?=$(HOME)/opt/dragonos-gcc/gcc-x86_64-unknown-none/bin - -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 AR=$(DragonOS_GCC)/x86_64-elf-ar -export OBJCOPY=$(DragonOS_GCC)/x86_64-elf-objcopy - +CCPREFIX=x86_64-linux-gnu- else ifeq ($(ARCH), riscv64) - -export CC=riscv64-unknown-elf-gcc -# binutils版本需要>=2.38 -# 而ubuntu的unknown-elf的版本比较旧,所以使用了riscv64-linux-gnu-ld -export LD=riscv64-linux-gnu-ld -export AS=riscv64-unknown-elf-as -export NM=riscv64-unknown-elf-nm -export AR=riscv64-unknown-elf-ar -export OBJCOPY=riscv64-unknown-elf-objcopy - +CCPREFIX=riscv64-linux-gnu- endif +export CC=$(CCPREFIX)gcc +export LD=$(CCPREFIX)ld +export AS=$(CCPREFIX)as +export NM=$(CCPREFIX)nm +export AR=$(CCPREFIX)ar +export OBJCOPY=$(CCPREFIX)objcopy export DEBUG=DEBUG diff --git a/kernel/src/Makefile b/kernel/src/Makefile index 3ee688cc7..7476a48bf 100644 --- a/kernel/src/Makefile +++ b/kernel/src/Makefile @@ -36,7 +36,7 @@ export ASFLAGS := --64 LD_LIST := "" -kernel_subdirs := common driver debug syscall libs +kernel_subdirs := debug kernel_rust: diff --git a/kernel/src/arch/x86_64/sched.rs b/kernel/src/arch/x86_64/sched.rs index 68f4da6de..78497754e 100644 --- a/kernel/src/arch/x86_64/sched.rs +++ b/kernel/src/arch/x86_64/sched.rs @@ -4,17 +4,6 @@ use crate::{exception::InterruptArch, sched::SchedArch, smp::core::smp_get_proce use super::{driver::apic::apic_timer::apic_timer_init, CurrentIrqArch}; -// /// @brief 若内核代码不处在中断上下文中,那么将可以使用本函数,发起一个sys_sched系统调用,然后运行调度器。 -// /// 由于只能在中断上下文中进行进程切换,因此需要发起一个系统调用SYS_SCHED。 -// #[no_mangle] -// pub extern "C" fn sched() { -// let _guard = unsafe { CurrentIrqArch::save_and_disable_irq() }; -// __schedule(SchedMode::SM_NONE); -// // unsafe { -// // enter_syscall_int(SYS_SCHED as u64, 0, 0, 0, 0, 0, 0); -// // } -// } - static mut BSP_INIT_OK: bool = false; pub struct X86_64SchedArch; diff --git a/kernel/src/common/Makefile b/kernel/src/common/Makefile deleted file mode 100644 index a7ce01f4b..000000000 --- a/kernel/src/common/Makefile +++ /dev/null @@ -1,14 +0,0 @@ - -CFLAGS += -I . - -kernel_common_subdirs:= math - -ECHO: - @echo "$@" - -$(kernel_common_subdirs): ECHO - - $(MAKE) -C $@ all CFLAGS="$(CFLAGS)" ASFLAGS="$(ASFLAGS)" - -all: $(kernel_common_subdirs) - diff --git a/kernel/src/common/boot_info.h b/kernel/src/common/boot_info.h deleted file mode 100644 index e9108068a..000000000 --- a/kernel/src/common/boot_info.h +++ /dev/null @@ -1,23 +0,0 @@ - -/** - * @file boot_info.h - * @brief 启动信息接口 - */ - -#pragma once -#include "glib.h" - -/** - * @brief 启动信息接口 - * 由引导传递的机器信息处理 - * 如 grub2 传递的 multiboot2 结构 - * 注意这部分是通过内存传递的,在重新保存之前不能被覆盖 - * 架构专有的数据在 dtb.h 或 multiboot2.h - * 实现在 dtb.cpp 或 multiboot2.cpp - */ - /// 声明,定义在具体的实现中 - /// 地址 - extern uintptr_t boot_info_addr; - /// 长度 - extern unsigned int boot_info_size; - diff --git a/kernel/src/common/glib.h b/kernel/src/common/glib.h index 411413e38..1725cbd68 100644 --- a/kernel/src/common/glib.h +++ b/kernel/src/common/glib.h @@ -6,11 +6,11 @@ #pragma once // 引入对bool类型的支持 -#include #include -#include #include #include +#include +#include #include @@ -22,13 +22,11 @@ * * 方法:使用ptr减去结构体内的偏移,得到结构体变量的基地址 */ -#define container_of(ptr, type, member) \ - ({ \ - typeof(((type *)0)->member) *p = (ptr); \ - (type *)((unsigned long)p - (unsigned long)&(((type *)0)->member)); \ - }) - - +#define container_of(ptr, type, member) \ + ({ \ + typeof(((type *)0)->member) *p = (ptr); \ + (type *)((unsigned long)p - (unsigned long)&(((type *)0)->member)); \ + }) #define ABS(x) ((x) > 0 ? (x) : -(x)) // 绝对值 // 最大最小值 @@ -39,10 +37,7 @@ #define MASK_HIGH_32bit(x) (x & (0x00000000ffffffffUL)) // 四舍五入成整数 -ul round(double x) -{ - return (ul)(x + 0.5); -} +ul round(double x) { return (ul)(x + 0.5); } /** * @brief 地址按照align进行对齐 @@ -51,18 +46,6 @@ ul round(double x) * @param _align * @return ul 对齐后的地址 */ -static __always_inline ul ALIGN(const ul addr, const ul _align) -{ - return (ul)((addr + _align - 1) & (~(_align - 1))); +static __always_inline ul ALIGN(const ul addr, const ul _align) { + return (ul)((addr + _align - 1) & (~(_align - 1))); } - - -/** - * @brief 将数据从src搬运到dst,并能正确处理地址重叠的问题 - * - * @param dst 目标地址指针 - * @param src 源地址指针 - * @param size 大小 - * @return void* 指向目标地址的指针 - */ -void *c_memmove(void *dst, const void *src, uint64_t size); \ No newline at end of file diff --git a/kernel/src/common/math/Makefile b/kernel/src/common/math/Makefile deleted file mode 100644 index f85134716..000000000 --- a/kernel/src/common/math/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -SRC = $(wildcard *.c) -OBJ = $(SRC:.c=.o) -CFLAGS += -I . - -.PHONY: all - -all: $(OBJ) - -%.o: %.c - $(CC) $(CFLAGS) -c $< -o $@ \ No newline at end of file diff --git a/kernel/src/common/string.h b/kernel/src/common/string.h index a918aea5f..81201624f 100644 --- a/kernel/src/common/string.h +++ b/kernel/src/common/string.h @@ -1,62 +1,13 @@ #pragma once #include "glib.h" -/** - * @brief 拷贝整个字符串 - * - * @param dst 目标地址 - * @param src 源地址 - * @return char* 目标字符串 - */ -char *strcpy(char *dst, const char *src); -//计算字符串的长度(经过测试,该版本比采用repne/scasb汇编的运行速度快16.8%左右) -static inline int strlen(const char *s) -{ - if (s == NULL) - return 0; - register int __res = 0; - while (s[__res] != '\0') - { - ++__res; - } - return __res; +// 计算字符串的长度(经过测试,该版本比采用repne/scasb汇编的运行速度快16.8%左右) +static inline int strlen(const char *s) { + if (s == NULL) + return 0; + register int __res = 0; + while (s[__res] != '\0') { + ++__res; + } + return __res; } - -/** - * @brief 测量字符串的长度 - * - * @param src 字符串 - * @param maxlen 最大长度 - * @return long - */ -long strnlen(const char *src, unsigned long maxlen); - -/* - 比较字符串 FirstPart and SecondPart - FirstPart = SecondPart => 0 - FirstPart > SecondPart => 1 - FirstPart < SecondPart => -1 -*/ - -int strcmp(const char *FirstPart, const char *SecondPart); - -char *strncpy(char *restrict d, const char *restrict s, size_t n); - -long strncpy_from_user(char *dst, const char *src, unsigned long size); - -/** - * @brief 测量来自用户空间的字符串的长度,会检验地址空间是否属于用户空间 - * @param src - * @param maxlen - * @return long - */ -long strnlen_user(const char *src, unsigned long maxlen); - -/** - * @brief 拼接两个字符串(将src接到dest末尾) - * - * @param dest 目标串 - * @param src 源串 - * @return char* - */ -char *strcat(char *dest, const char *src); \ No newline at end of file diff --git a/kernel/src/common/unistd.h b/kernel/src/common/unistd.h deleted file mode 100644 index 29483d3ae..000000000 --- a/kernel/src/common/unistd.h +++ /dev/null @@ -1,22 +0,0 @@ -/** - * @file unistd.h - * @author fslongjin (longjin@RinGoTek.cn) - * @brief - * @version 0.1 - * @date 2022-04-22 - * - * @copyright Copyright (c) 2022 - * - */ -#pragma once - -#include -#include - -/** - * @brief 交换n字节 - * @param src 源地址 - * @param dest 目的地址 - * @param nbytes 交换字节数 - */ -void swab(void *restrict src, void *restrict dest, ssize_t nbytes); \ No newline at end of file diff --git a/kernel/src/debug/Makefile b/kernel/src/debug/Makefile index 809b2b147..a145970d4 100644 --- a/kernel/src/debug/Makefile +++ b/kernel/src/debug/Makefile @@ -1,5 +1,6 @@ -all: traceback.o +all: + @echo "" CFLAGS += -I . diff --git a/kernel/src/driver/Makefile b/kernel/src/driver/Makefile deleted file mode 100644 index 8cc629113..000000000 --- a/kernel/src/driver/Makefile +++ /dev/null @@ -1,17 +0,0 @@ - -CFLAGS += -I . - -kernel_driver_subdirs:= - -ECHO: - @echo "$@" - -$(kernel_driver_subdirs): ECHO - - $(MAKE) -C $@ all CFLAGS="$(CFLAGS)" ASFLAGS="$(ASFLAGS)" - -all: $(kernel_driver_subdirs) - - -clean: - echo "Done." diff --git a/kernel/src/libs/Makefile b/kernel/src/libs/Makefile deleted file mode 100644 index c6544118f..000000000 --- a/kernel/src/libs/Makefile +++ /dev/null @@ -1,19 +0,0 @@ - -CFLAGS += -I . - -kernel_lib_subdirs:= - -kernel_lib_objs:= $(shell find ./*.c) - -ECHO: - @echo "$@" - -$(kernel_lib_subdirs): ECHO - $(MAKE) -C $@ all CFLAGS="$(CFLAGS)" ASFLAGS="$(ASFLAGS)" - -$(kernel_lib_objs): ECHO - $(CC) $(CFLAGS) -c $@ -o $@.o - -all: $(kernel_lib_objs) $(kernel_lib_subdirs) - @echo $(kernel_lib_objs) - diff --git a/kernel/src/libs/glib.c b/kernel/src/libs/glib.c deleted file mode 100644 index 42dedf27e..000000000 --- a/kernel/src/libs/glib.c +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include - - -/** - * @brief 将数据从src搬运到dst,并能正确处理地址重叠的问题 - * - * @param dst 目标地址指针 - * @param src 源地址指针 - * @param size 大小 - * @return void* 指向目标地址的指针 - */ -void *c_memmove(void *dst, const void *src, uint64_t size) -{ - const char *_src = src; - char *_dst = dst; - - if (!size) - return dst; - - // 当源地址大于目标地址时,使用memcpy来完成 - if (dst <= src) - return memcpy(dst, src, size); - - // 当源地址小于目标地址时,为防止重叠覆盖,因此从后往前拷贝 - _src += size; - _dst += size; - - // 逐字节拷贝 - while (size--) - *--_dst = *--_src; - - return dst; -} \ No newline at end of file diff --git a/kernel/src/libs/string.c b/kernel/src/libs/string.c deleted file mode 100644 index e5971503f..000000000 --- a/kernel/src/libs/string.c +++ /dev/null @@ -1,101 +0,0 @@ -#include -#include - -/** - * @brief 拷贝整个字符串 - * - * @param dst 目标地址 - * @param src 源地址 - * @return char* 目标字符串 - */ -char *strcpy(char *dst, const char *src) -{ - while (*src) - { - *(dst++) = *(src++); - } - *dst = 0; - - return dst; -} - -long strnlen(const char *src, unsigned long maxlen) -{ - - if (src == NULL) - return 0; - register int __res = 0; - while (src[__res] != '\0' && __res < maxlen) - { - ++__res; - } - return __res; -} - -/* - 比较字符串 FirstPart and SecondPart - FirstPart = SecondPart => 0 - FirstPart > SecondPart => 1 - FirstPart < SecondPart => -1 -*/ -int strcmp(const char *l, const char *r) -{ - for (; *l == *r && *l; l++, r++) - ; - return *(unsigned char *)l - *(unsigned char *)r; -} - -char *__stpncpy(char *restrict d, const char *restrict s, size_t n) -{ - - for (; n && (*d = *s); n--, s++, d++) - ; -tail: - memset(d, 0, n); - return d; -} - -char *strncpy(char *restrict d, const char *restrict s, size_t n) -{ - __stpncpy(d, s, n); - return d; -} - -long strncpy_from_user(char *dst, const char *src, unsigned long size) -{ - if (!verify_area((uint64_t)src, size)) - return 0; - - strncpy(dst, src, size); - return size; -} - -/** - * @brief 测量来自用户空间的字符串的长度,会检验地址空间是否属于用户空间 - * @param src - * @param maxlen - * @return long - */ -long strnlen_user(const char *src, unsigned long maxlen) -{ - - unsigned long size = strlen(src); - // 地址不合法 - if (!verify_area((uint64_t)src, size)) - return 0; - - return size <= maxlen ? size : maxlen; -} - -/** - * @brief 拼接两个字符串(将src接到dest末尾) - * - * @param dest 目标串 - * @param src 源串 - * @return char* - */ -char *strcat(char *dest, const char *src) -{ - strcpy(dest + strlen(dest), src); - return dest; -} \ No newline at end of file diff --git a/kernel/src/libs/unistd.c b/kernel/src/libs/unistd.c deleted file mode 100644 index 1e36bfede..000000000 --- a/kernel/src/libs/unistd.c +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include - - -void swab(void *restrict src, void *restrict dest, ssize_t nbytes) -{ - unsigned char buf[32]; - char *_src = src; - char *_dest = dest; - uint32_t transfer; - for (; nbytes > 0; nbytes -= transfer) - { - transfer = (nbytes > 32) ? 32 : nbytes; - memcpy(buf, _src, transfer); - memcpy(_src, _dest, transfer); - memcpy(_dest, buf, transfer); - _src += transfer; - _dest += transfer; - } -} \ No newline at end of file diff --git a/kernel/src/process/process.h b/kernel/src/process/process.h index d30e8833b..9695316d3 100644 --- a/kernel/src/process/process.h +++ b/kernel/src/process/process.h @@ -12,7 +12,6 @@ #include "ptrace.h" #include #include -#include /** * @brief 进程退出时执行的函数 @@ -32,6 +31,6 @@ extern uint32_t rs_current_pcb_cpuid(); extern uint32_t rs_current_pcb_pid(); extern uint32_t rs_current_pcb_preempt_count(); extern uint32_t rs_current_pcb_flags(); -extern int64_t rs_current_pcb_thread_rbp(); +extern uint64_t rs_current_pcb_thread_rbp(); #define PF_NEED_SCHED (1UL << 1) diff --git a/kernel/src/syscall/Makefile b/kernel/src/syscall/Makefile deleted file mode 100644 index ae15a094a..000000000 --- a/kernel/src/syscall/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -SRC = $(wildcard *.c) -OBJ = $(SRC:.c=.o) -CFLAGS += -I . - -.PHONY: all - -all: $(OBJ) - -%.o: %.c - $(CC) $(CFLAGS) -c $< -o $@ diff --git a/kernel/src/syscall/syscall.c b/kernel/src/syscall/syscall.c deleted file mode 100644 index 3bd1d7fff..000000000 --- a/kernel/src/syscall/syscall.c +++ /dev/null @@ -1,54 +0,0 @@ -#include "syscall.h" -#include -#include -#include -#include -#include -#include - -#if ARCH(I386) || ARCH(X86_64) -// 导出系统调用入口函数,定义在entry.S中 -extern void syscall_int(void); - -/** - * @brief 通过中断进入系统调用 - * - * @param syscall_id - * @param arg0 - * @param arg1 - * @param arg2 - * @param arg3 - * @param arg4 - * @param arg5 - * @param arg6 - * @param arg7 - * @return long - */ - -long enter_syscall_int(ul syscall_id, ul arg0, ul arg1, ul arg2, ul arg3, - ul arg4, ul arg5) { - long err_code; - __asm__ __volatile__("movq %2, %%rdi \n\t" - "movq %3, %%rsi \n\t" - "movq %4, %%rdx \n\t" - "movq %5, %%r10 \n\t" - "movq %6, %%r8 \n\t" - "movq %7, %%r9 \n\t" - "int $0x80 \n\t" - : "=a"(err_code) - : "a"(syscall_id), "m"(arg0), "m"(arg1), "m"(arg2), - "m"(arg3), "m"(arg4), "m"(arg5) - : "memory", "r8", "r9", "r10", "rdi", "rsi", "rdx"); - - return err_code; -} - -#else -long enter_syscall_int(ul syscall_id, ul arg0, ul arg1, ul arg2, ul arg3, - ul arg4, ul arg5) { - while (1) { - /* code */ - } -} - -#endif diff --git a/kernel/src/syscall/syscall.h b/kernel/src/syscall/syscall.h deleted file mode 100644 index 0d1aeda26..000000000 --- a/kernel/src/syscall/syscall.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -/** - * @brief 初始化系统调用模块 - * - */ -extern int syscall_init(); - -/** - * @brief 用户态系统调用入口函数 - * 从用户态进入系统调用 - * @param syscall_id 系统调用id - * @return long 错误码 - */ -long enter_syscall_int(ul syscall_id, ul arg0, ul arg1, ul arg2, ul arg3, ul arg4, ul arg5); - diff --git a/kernel/src/syscall/syscall_num.h b/kernel/src/syscall/syscall_num.h deleted file mode 100644 index 07dabe383..000000000 --- a/kernel/src/syscall/syscall_num.h +++ /dev/null @@ -1,102 +0,0 @@ -#pragma once -/** - * 请注意!!!由于系统调用模块已经使用Rust重构,当修改系统调用号时,需要同时修改syscall_num.h和syscall/mod.rs中的系统调用号 - * 并且以syscall/mod.rs中的为准!!! - * - * TODO:在完成系统的重构后,删除syscall_num.h - * - */ - -// 定义系统调用号 -#define SYS_READ 0 -#define SYS_WRITE 1 -#define SYS_OPEN 2 -#define SYS_CLOSE 3 - -#define SYS_FSTAT 5 -#define SYS_LSEEK 8 -#define SYS_MMAP 9 -#define SYS_MPROTECT 10 -#define SYS_MUNMAP 11 -#define SYS_BRK 12 -#define SYS_SIGACTION 13 - -#define SYS_RT_SIGRETURN 15 -#define SYS_IOCTL 16 - -#define SYS_DUP 32 -#define SYS_DUP2 33 - -#define SYS_NANOSLEEP 35 -#define SYS_ALARM 37 -#define SYS_GETPID 39 - -#define SYS_SOCKET 41 -#define SYS_CONNECT 42 -#define SYS_ACCEPT 43 -#define SYS_SENDTO 44 -#define SYS_RECVFROM 45 - -#define SYS_RECVMSG 47 -#define SYS_SHUTDOWN 48 -#define SYS_BIND 49 -#define SYS_LISTEN 50 -#define SYS_GETSOCKNAME 51 -#define SYS_GETPEERNAME 52 - -#define SYS_SETSOCKOPT 54 -#define SYS_GETSOCKOPT 55 -#define SYS_CLONE 56 -#define SYS_FORK 57 -#define SYS_VFORK 58 -#define SYS_EXECVE 59 -#define SYS_EXIT 60 -#define SYS_WAIT4 61 -#define SYS_KILL 62 -#define SYS_UNAME 63 - -#define SYS_FCNTL 72 - -#define SYS_FTRUNCATE 77 -#define SYS_GET_DENTS 78 - -#define SYS_GETCWD 79 - -#define SYS_CHDIR 80 - -#define SYS_MKDIR 83 -#define SYS_RMDIR 84 - -#define SYS_LINK 86 - -#define SYS_GETTIMEOFDAY 96 - -#define SYS_ARCH_PRCTL 158 - -#define SYS_MOUNT 165 -#define SYS_REBOOT 169 - -#define SYS_GETPPID 110 -#define SYS_GETPGID 121 - -#define SYS_MKNOD 133 - -#define SYS_FUTEX 202 - -#define SYS_SET_TID_ADDR 218 - -#define SYS_UNLINK_AT 263 - -#define SYS_LINKAT 265 - -#define SYS_PIPE 293 - -#define SYS_WRITEV 20 - -// 与linux不一致的调用,在linux基础上累加 -#define SYS_PUT_STRING 100000 -#define SYS_SBRK 100001 -/// todo: 该系统调用与Linux不一致,将来需要删除该系统调用!!! -/// 删的时候记得改C版本的libc -#define SYS_CLOCK 100002 -#define SYS_SCHED 100003 diff --git a/tools/BUILD_CONTAINER_VERSION b/tools/BUILD_CONTAINER_VERSION new file mode 100644 index 000000000..26e5d1951 --- /dev/null +++ b/tools/BUILD_CONTAINER_VERSION @@ -0,0 +1 @@ +v1.3 \ No newline at end of file diff --git a/tools/Dockerfile b/tools/Dockerfile index 8031bfe53..c6d644c96 100644 --- a/tools/Dockerfile +++ b/tools/Dockerfile @@ -1,53 +1,27 @@ -FROM debian:bullseye +FROM ubuntu:jammy + +# 设置环境变量 +ENV TZ=Asia/Shanghai +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone # 设置工作目录 -WORKDIR /build-image +WORKDIR /tmp # 将本地的脚本复制到工作目录 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 +# 设置sudo免密码 +RUN apt update && \ + apt install -y ca-certificates curl gnupg wget sudo apt-utils && \ + bash bootstrap.sh --default && \ + sudo cp /tmp/docker-entrypoint.sh /root/entrypoint.sh && \ + sudo chmod a+rwx /root/entrypoint.sh && \ + sudo apt autoremove -q -y && \ + sudo apt clean -q -y && \ + sudo rm -rf /tmp/* -# 清除缓存 -WORKDIR / -RUN apt-get autoremove -q -y && \ - apt-get clean -q -y && \ - rm -rf /build-image +WORKDIR /root -ENV DragonOS_GCC=/root/opt/dragonos-gcc/gcc-x86_64-unknown-none/bin/ +ENTRYPOINT [ "/root/entrypoint.sh" ] # 设置容器启动后执行的命令 CMD ["/bin/bash"] diff --git a/tools/bootstrap.sh b/tools/bootstrap.sh index d3d583f87..aee206b9b 100644 --- a/tools/bootstrap.sh +++ b/tools/bootstrap.sh @@ -19,8 +19,11 @@ source "$HOME/.$CURRENT_SHELL"rc 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 +DEFAULT_INSTALL="false" + +export RUSTUP_DIST_SERVER=${RUSTUP_DIST_SERVER:-https://rsproxy.cn} +export RUSTUP_UPDATE_ROOT=${RUSTUP_UPDATE_ROOT:-https://rsproxy.cn/rustup} +export RUST_VERSION="${RUST_VERSION:-nightly-2024-07-23}" banner() { @@ -62,7 +65,7 @@ install_ubuntu_debian_pkg() lsb-release \ llvm-dev libclang-dev clang gcc-multilib \ gcc build-essential fdisk dosfstools dnsmasq bridge-utils iptables libssl-dev pkg-config \ - sphinx + sphinx make git # 必须分开安装,否则会出现错误 sudo "$1" install -y \ gcc-riscv64-unknown-elf gcc-riscv64-linux-gnu gdb-multiarch @@ -73,7 +76,7 @@ install_ubuntu_debian_pkg() sudo apt install -y python3 python3-pip fi - if [ -z "$(which docker)" ] && [ -n ${dockerInstall} ]; then + if [ -z "$(which docker)" ] && [ "${dockerInstall}" = "true" ]; then echo "正在安装docker..." sudo apt install -y docker.io docker-compose sudo groupadd docker @@ -190,97 +193,70 @@ rustInstall() { fi # If rustup is not installed we should offer to install it for them if [ -z "$(which rustup)" ]; then - echo "您没有安装rustup," - echo "我们强烈建议使用rustup, 是否要立即安装?" - echo "*WARNING* 这将会发起这样的一个命令 'curl | sh' " - printf "(y/N): " - read rustup - if echo "$rustup" | grep -iq "^y" ;then - #install rustup - curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain nightly - # You have to add the rustup variables to the $PATH - echo "export PATH=\"\$HOME/.cargo/bin:\$PATH\"" >> ~/.bashrc - # source the variables so that we can execute rustup commands in the current shell - source ~/.cargo/env - source "$HOME/.cargo/env" - else - echo "Rustup will not be installed!" - fi + echo "正在安装Rust..." + #install rustup + curl https://sh.rustup.rs -sSf --retry 5 --retry-delay 5 | sh -s -- --default-toolchain ${RUST_VERSION} -y + # You have to add the rustup variables to the $PATH + echo "export PATH=\"\$HOME/.cargo/bin:\$PATH\"" >> ~/.bashrc + # source the variables so that we can execute rustup commands in the current shell + source ~/.cargo/env + source "$HOME/.cargo/env" fi # if [ -z "$(which rustc)" ]; then echo "Rust 还未被安装" echo "请再次运行脚本,接受rustup安装" echo "或通过以下方式手动安装rustc(不推荐):" - echo "curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain nightly" + echo "curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain $RUST_VERSION -y" exit else - echo "是否为Rust换源为国内镜像源?(Tuna)" - echo "如果您在国内,我们推荐您这样做,以提升网络速度。" - echo "*WARNING* 这将会替换原有的镜像源设置。" - printf "(y/N): " - read change_src - if echo "$change_src" | grep -iq "^y" ;then - touch ~/.cargo/config - bash change_rust_src.sh + local change_rust_src="" + if [ "$DEFAULT_INSTALL" = "true" ]; then + change_rust_src="true" else - echo "取消换源,您原有的配置不会被改变。" + echo "是否为Rust换源为国内镜像源?(Tuna)" + echo "如果您在国内,我们推荐您这样做,以提升网络速度。" + echo "*WARNING* 这将会替换原有的镜像源设置。" + printf "(y/N): " + read change_src + if echo "$change_src" | grep -iq "^y" ;then + change_rust_src="true" + else + echo "取消换源,您原有的配置不会被改变。" + fi fi + if [ "$change_rust_src" = "true" ]; then + echo "正在为rust换源" + bash change_rust_src.sh --sparse + fi + echo "正在安装DragonOS所需的rust组件...首次安装需要一些时间来更新索引,请耐心等待..." cargo install cargo-binutils rustup toolchain install nightly-2023-08-15-x86_64-unknown-linux-gnu - rustup toolchain install nightly-2024-07-23-x86_64-unknown-linux-gnu - rustup component add rust-src --toolchain nightly-2024-07-23-x86_64-unknown-linux-gnu + rustup toolchain install $RUST_VERSION-x86_64-unknown-linux-gnu + rustup component add rust-src --toolchain $RUST_VERSION-x86_64-unknown-linux-gnu rustup component add rust-src --toolchain nightly-2023-08-15-x86_64-unknown-linux-gnu - rustup target add x86_64-unknown-none --toolchain nightly-2024-07-23-x86_64-unknown-linux-gnu + rustup target add x86_64-unknown-none --toolchain $RUST_VERSION-x86_64-unknown-linux-gnu rustup target add x86_64-unknown-none --toolchain nightly-2023-08-15-x86_64-unknown-linux-gnu rustup target add x86_64-unknown-linux-musl --toolchain nightly-2023-08-15-x86_64-unknown-linux-gnu - rustup target add x86_64-unknown-linux-musl --toolchain nightly-2024-07-23-x86_64-unknown-linux-gnu + rustup target add x86_64-unknown-linux-musl --toolchain $RUST_VERSION-x86_64-unknown-linux-gnu - rustup toolchain install nightly-2024-07-23-riscv64gc-unknown-linux-gnu --force-non-host + rustup toolchain install $RUST_VERSION-riscv64gc-unknown-linux-gnu --force-non-host rustup toolchain install nightly-2023-08-15-riscv64gc-unknown-linux-gnu --force-non-host - rustup target add riscv64gc-unknown-none-elf --toolchain nightly-2024-07-23-riscv64gc-unknown-linux-gnu - rustup target add riscv64imac-unknown-none-elf --toolchain nightly-2024-07-23-riscv64gc-unknown-linux-gnu + rustup target add riscv64gc-unknown-none-elf --toolchain $RUST_VERSION-riscv64gc-unknown-linux-gnu + rustup target add riscv64imac-unknown-none-elf --toolchain $RUST_VERSION-riscv64gc-unknown-linux-gnu rustup target add riscv64gc-unknown-none-elf --toolchain nightly-2023-08-15-riscv64gc-unknown-linux-gnu rustup target add riscv64imac-unknown-none-elf --toolchain nightly-2023-08-15-riscv64gc-unknown-linux-gnu rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu rustup component add rust-src rustup component add llvm-tools-preview - rustup default nightly-2024-07-23 + rustup default $RUST_VERSION echo "Rust已经成功的在您的计算机上安装!请运行 source ~/.cargo/env 以使rust在当前窗口生效!" fi } -#################################################################################### -# 初始化DragonOS的musl交叉编译工具链 -# 主要是把musl交叉编译工具链的rcrt1.o替换为crt1.o (因为rust的rcrt1.o会使用动态链接的解释器,但是DragonOS目前尚未把它加载进来) -# -# 为DragonOS开发应用的时候,请使用 `cargo +nightly-2023-08-15-x86_64-unknown-linux-gnu build --target x86_64-unknown-linux-musl` 来编译 -# 这样编译出来的应用将能二进制兼容DragonOS -#################################################################################### -initialize_userland_musl_toolchain() -{ - fork_toolchain_from="nightly-2023-08-15-x86_64-unknown-linux-gnu" - custom_toolchain="nightly-2023-08-15-x86_64-unknown-linux_dragonos-gnu" - custom_toolchain_dir="$(dirname $(rustc --print sysroot))/${custom_toolchain}" - # 如果目录为空 - if [ ! -d "${custom_toolchain_dir}" ]; then - echo "Custom toolchain does not exist, creating..." - rustup toolchain install ${fork_toolchain_from} - rustup component add --toolchain ${fork_toolchain_from} rust-src - rustup target add --toolchain ${fork_toolchain_from} x86_64-unknown-linux-musl - cp -r $(dirname $(rustc --print sysroot))/${fork_toolchain_from} ${custom_toolchain_dir} - self_contained_dir=${custom_toolchain_dir}/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained - cp -f ${self_contained_dir}/crt1.o ${self_contained_dir}/rcrt1.o - else - echo "Custom toolchain already exists." - fi - -} - - install_python_pkg() { echo "正在安装python依赖项..." @@ -300,6 +276,10 @@ while true; do "--no-docker") dockerInstall="" ;; + "--default") + DEFAULT_INSTALL="true" + dockerInstall="" + ;; "--help") echo "--no-docker(not install docker): 该参数表示执行该脚本的过程中不单独安装docker." exit 0 @@ -349,9 +329,6 @@ fi # 安装rust rustInstall - -# 初始化DragonOS的musl交叉编译工具链 -initialize_userland_musl_toolchain install_python_pkg # 安装dadk @@ -359,10 +336,6 @@ cargo install dadk || exit 1 bashpath=$(cd `dirname $0`; pwd) -# 创建磁盘镜像 -bash ${bashpath}/create_hdd_image.sh -# 编译安装GCC交叉编译工具链 -bash ${bashpath}/build_gcc_toolchain.sh -cs -kb -kg || (echo "GCC交叉编译工具链安装失败" && exit 1) # 编译安装musl交叉编译工具链 bash ${bashpath}/install_musl_gcc.sh || (echo "musl交叉编译工具链安装失败" && exit 1) # 编译安装grub @@ -370,7 +343,8 @@ bash ${bashpath}/grub_auto_install.sh || (echo "grub安装失败" && exit 1) # 解决kvm权限问题 USR=$USER -sudo adduser $USR kvm +sudo groupadd kvm || echo "kvm组已存在" +sudo usermod -aG kvm $USR sudo chown $USR /dev/kvm congratulations diff --git a/tools/change_rust_src.sh b/tools/change_rust_src.sh index c62270e08..5d3ac7f23 100644 --- a/tools/change_rust_src.sh +++ b/tools/change_rust_src.sh @@ -1,6 +1,13 @@ echo "正在为rust换源" -echo "bash change_rust_src.sh --sparse以使用稀疏索引" + sparse="false" + +CONFIG_FILE=~/.cargo/config.toml +# 创建父目录 +if [ ! -d ~/.cargo ]; then + mkdir -p ~/.cargo +fi + while true; do if [ -z "$1" ]; then break; @@ -13,21 +20,32 @@ while true; do esac shift 1 done + + if [ -z ${sparse} ]; then - echo -e "[source.crates-io] \n \ -registry = \"https://github.com/rust-lang/crates.io-index\" \n \ -\n \ -replace-with = 'tuna' \n \ -[source.tuna] \n \ -registry = \"sparse+https://mirrors.tuna.tsinghua.edu.cn/crates.io-index/\" \n \ -" > ~/.cargo/config.toml +echo -e "[source.crates-io] \n \ +replace-with = 'rsproxy-sparse' \n \ +[source.rsproxy] \n \ +registry = \"https://rsproxy.cn/crates.io-index\" \n \ +[source.rsproxy-sparse] \n \ +registry = \"sparse+https://rsproxy.cn/index/\" \n \ +[registries.rsproxy] \n \ +index = \"https://rsproxy.cn/crates.io-index\" \n \ +[net] \n \ +git-fetch-with-cli = true \n \ +" > $CONFIG_FILE else - echo -e "[source.crates-io] \n \ -registry = \"https://github.com/rust-lang/crates.io-index\" \n \ -\n \ -replace-with = 'tuna' \n \ -[source.tuna] \n \ -registry = \"https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git\" \n \ -" > ~/.cargo/config.toml +echo "TIPS: bash change_rust_src.sh --sparse以使用稀疏索引" +echo -e "[source.crates-io] \n \ +replace-with = 'rsproxy' \n \ +[source.rsproxy] \n \ +registry = \"https://rsproxy.cn/crates.io-index\" \n \ +[source.rsproxy-sparse] \n \ +registry = \"sparse+https://rsproxy.cn/index/\" \n \ +[registries.rsproxy] \n \ +index = \"https://rsproxy.cn/crates.io-index\" \n \ +[net] \n \ +git-fetch-with-cli = true \n \ +" > $CONFIG_FILE fi diff --git a/tools/docker-entrypoint.sh b/tools/docker-entrypoint.sh new file mode 100644 index 000000000..5fc44481d --- /dev/null +++ b/tools/docker-entrypoint.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +exec "$@" diff --git a/tools/install_musl_gcc.sh b/tools/install_musl_gcc.sh index bcf1862aa..1809f3e71 100644 --- a/tools/install_musl_gcc.sh +++ b/tools/install_musl_gcc.sh @@ -33,6 +33,8 @@ fi INSTALL_POS="$HOME/opt/" +mkdir -p $INSTALL_POS + get_shell_rc_file() { if [ -n "$ZSH_VERSION" ]; then