前言:根据前文的信息 KataOS 和 CantripOS,我就计划和LY一起合作翻译 CantripOS 截止2023年3月共8篇文档,此为第1篇。repo 是一个构建在 Git 之上的工具。repo 可以帮助管理许多 Git 存储库,上传到版本控制系统,并自动化部分开发工作流程。repo 并不是要取代 Git,只是为了让 Git 更容易使用。repo 命令是一个可执行的 Python 脚本,可以将其放在路径中的任何位置。
CantripOS 包括一个多平台构建框架。该框架利用了make、cmake和cargo。要开始使用,请按照以下步骤操作:
1.使用repo工具从GitHub克隆Sparrow项目。我们假设它位于名为"sparrow"的顶级目录下。
2.下载、构建并引导系统到Cantrip shell提示符。目前唯一可用的目标平台是"rpi3"(适用于在qemu模拟器上运行的raspi3b机器)。
mkdir sparrow
cd sparrow
repo init -u https://github.com/AmbiML/sparrow-manifest -m sparrow-manifest.xml
repo sync -j$(nproc)
export PLATFORM=rpi3
source build/setup.sh
m simulate-debug
请注意,如果您的repo工具过时,您可能需要在init请求中提供-b main参数,因为旧版本的repo只检查主分支。
前提条件
请注意,首先确认您已经在系统上安装了下列前提条件,在添加到了您的shell搜索路径中:
- 适用于目标体系结构的GCC(或clang)
- Rust;任何nightly版本>=nightly-2021-11-05都可以使用。build/setup.sh脚本中设置了默认版本;如果您使用的版本不同,请编辑shell脚本或在每个工作的shell中导出CANTRIP_RUST_VERSION。请注意,我们使用了各种仅限于nightly版本的功能,这些功能不受Rust稳定版本的支持(例如,覆盖默认的TLS模型)。
- python tempita模块。
- seL4期望的任何模拟器都适用于您的目标体系结构;例如,对于aarch64,这是qemu-system-aarch64。
因为Sparrow是一个CAmkES项目,您还需要安装 CAmkES依赖。
首次设置
Sparrow 使用 repo 来下载和组合 Sparrow git 存储库以及类似 seL4 的依赖项目/存储库等。
$ repo init -u https://github.com/AmbiML/sparrow-manifest -m sparrow-manifest.xml
Downloading Repo source from https://gerrit.googlesource.com/git-repo
repo has been initialized in <your-directory>/sparrow/
If this is not the directory in which you want to initialize repo, please run:
rm -r <your-directory>/sparrow//.repo
and try again.
$ repo sync -j12
Fetching: 100% (23/23), done in 9.909s
Garbage collecting: 100% (23/23), done in 0.218s
Checking out: 100% (23/23), done in 0.874s
repo sync has finished successfully.
$ export PLATFORM=rpi3
$ export CANTRIP_RUST_VERSION=nightly
$ source build/setup.sh
========================================
ROOTDIR=/<your-directory>/sparrow
OUT=/<your-directory>/sparrow/out
PLATFORM=rpi3
========================================
Type 'm [target]' to build.
Targets available are:
...
cantrip cantrip-build-debug-prepare cantrip-build-release-prepare cantrip-builtins
cantrip-builtins-debug cantrip-builtins-release cantrip-bundle-debug cantrip-bundle-release
cantrip-clean cantrip-clean-headers cantrip-clippy cantrip-component-headers
...
$ m simulate
...
info: component 'rust-std' for target 'aarch64-unknown-none' is up to date
loading initial cache file <your-directory>/sparrow/cantrip/projects/camkes/settings.cmake
-- Set platform details from PLATFORM=rpi3
-- KernelPlatform: bcm2837
-- KernelARMPlatform: rpi3
-- Setting from flags KernelSel4Arch: aarch64
-- Found seL4: <your-directory>/sparrow/kernel
-- The C compiler identification is GNU 11.2.1
...
[291/291] Generating images/capdl-loader-image-arm-bcm2837
...
qemu-system-aarch64 -machine raspi3b -nographic -serial null -serial mon:stdio -m size=1024M -s \
-kernel /<your-directory>/sparrow/out/cantrip/aarch64-unknown-elf/debug/capdl-loader-image \
--mem-path /<your-directory>/sparrow/out/cantrip/aarch64-unknown-elf/debug/cantrip.mem
ELF-loader started on CPU: ARM Ltd. Cortex-A53 r0p4
paddr=[8bd000..fed0ff]
No DTB passed in from boot loader.
Looking for DTB in CPIO archive...found at 9b3ef8.
Loaded DTB from 9b3ef8.
paddr=[23c000..23ffff]
ELF-loading image 'kernel' to 0
paddr=[0..23bfff]
vaddr=[ffffff8000000000..ffffff800023bfff]
virt_entry=ffffff8000000000
ELF-loading image 'capdl-loader' to 240000
paddr=[240000..4c0fff]
vaddr=[400000..680fff]
virt_entry=4009e8
Enabling MMU and paging
Jumping to kernel-image entry point...
Warning: gpt_cntfrq 62500000, expected 19200000
Bootstrapping kernel
Booting all finished, dropped to user space
cantrip_os_rootserver::Bootinfo: (1969, 131072) empty slots 1 nodes (15, 83) untyped 131072 cnode slots
cantrip_os_rootserver::Model: 1821 objects 1 irqs 0 untypeds 2 asids
cantrip_os_rootserver::capDL spec: 0.39 Mbytes
cantrip_os_rootserver::CAmkES components: 5.85 Mbytes
cantrip_os_rootserver::Rootserver executable: 1.07 Mbytes
<<seL4(CPU 0) [decodeARMFrameInvocation/2137 T0xffffff80004c7400 "rootserver" @44373c]: ARMPageMap: Attempting to remap a frame that does not belong to the passed address space>>
...
<<seL4(CPU 0) [decodeCNodeInvocation/107 T0xffffff80009a3400 "rootserver" @4268a0]: CNode Copy/Mint/Move/Mutate: Source slot invalid or empty.>>
...
CANTRIP> builtins
autostart.repl 336
hello.app 1084
keyval.app 32276
logtest.app 26948
panic.app 25688
timer.app 33060
CANTRIP> install hello.app
cantrip_memory_manager::Global memory: 0 allocated 130543360 free, reserved: 2273280 kernel 1359872 user
Collected 1084 bytes of data, crc32 5b847193
Application "hello" installed
CANTRIP> start hello
Bundle "hello" started.
CANTRIP> install keyval.app
I am a C app!
Done, sleeping in WFI loop
Collected 32276 bytes of data, crc32 bcf05273
Application "keyval" installed
CANTRIP> start keyval
Bundle "keyval" started.
...
CANTRIP> mstats
48 bytes in-use, 130543312 bytes free, 720512 bytes requested, 1359872 overhead
2 objs in-use, 196 objs requested
CANTRIP> EOF
命令 m simulate
可以重复运行。 如果需要重置设置,只需删除构建树并重新运行 m simulate
即可; 例如:
$ cd sparrow
$ m clean
$ m simulate
构建系统:基础
所需的设置过程:
$ export PLATFORM=rpi3
$ export CANTRIP_RUST_VERSION=nightly # force use of "nightly" channel
$ source build/setup.sh
这定义了与 CantriPOS 一起运行的各种 shell 函数或别名。 特别是 m 命令是构建和运行模拟的主要机制。 默认的目标命令是 simulate 所以它们是等价的:
$ m simulate
$ m # 默认目标也是 simulate
与上面情况类似,另一个有用的目标是 m simulate-debug,它构建系统的调试版本并启动模拟器。 在这种情况下,模拟器(依赖于平台)支持在单独的窗口/终端中将 GDB 与 scripts/kgdb.sh 连接起来。 有关将 GDB 与 seL4 结合使用的更多信息,后面的文档会继续补充。
根据您所使用的 shell, 支持 Tab 自动补全:
$ m <TAB>
cargo_test_debugconsole_zmodem cantrip-gen-headers
cargo_test_cantrip keyval_debug
cargo_test_cantrip_os_common_logger keyval_release
cargo_test_cantrip_os_common_slot_allocator logtest_debug
cargo_test_cantrip_proc_interface logtest_release
cargo_test_cantrip_proc_manager matcha_tock_clean
clean matcha_tock_debug
collate_cantrip_rust_toolchain matcha_tock_release
collate_matcha_rust_toolchain minisel_debug
collate_rust_toolchains minisel_release
elfconvert multihart_boot_rom
fibonacci_debug multihart_boot_rom_clean
fibonacci_release panic_debug
flatbuffers panic_release
flatbuffers-clean prereqs
...
hmm
命令可以显示帮助信息,例如:
$ hmm sel4test
sel4test: (defined in build/platforms/sparrow/sim_sel4test.mk)
C-based libsel4 syscall api wrappers. The result is run under Renode.
构建系统:多平台支持
构建系统支持多个目标平台。 但目前只有两个平台——sparrow 和 rpi3——所以这不那么令人兴奋。 当前平台保存在您的 shell 环境中,因此在默认设置后您将看到:
$ source build/setup.sh
$ printenv PLATFORM
sparrow
但这也意味着您需要在您使用该软件的每个 shell 中获取 build/setup.sh
的源代码。
要切换当前平台,请使用 set-platform shell
函数:
$ source build/setup.sh
$ printenv PLATFORM
sparrow
另外还有一个 list-platforms shell
函数,您可以使用 set-platform
命令代替制表符补全。
构建系统:清理构建包
大多数时候运行 m simulate
或 m simulate-debug
就够了:make dependencies 将只完成必要的操作。 有时有必要删除构建包(例如,因为依赖关系不正确或依赖关系过于保守导致构建步骤过多)。 若要有许多目标可以选择性地清除不需要的包,只需要使用下列命令:
$ m cantrip-clean
将会为当前平台删除所有的构建包:
$ m clean
则会为所有平台删除所有的构建包。
Fuchsia 中文社区译者补充说明:build artifacts 是指源代码通过编译生成的中间或最终结果,例如目标代码、库文件、可执行文件等。在编译过程中,编译器将源代码转换为目标代码或其他可执行文件,并将其输出到一个或多个文件中,这些文件就是build artifacts。
Build artifacts通常是编译系统生成的临时文件,它们是构建过程的产物,包括中间文件、对象文件、库文件、可执行文件等。这些文件可能会被后续的构建流程使用,例如链接器会使用中间文件或对象文件生成可执行文件或库文件。
本篇文档的原始地址在:这里
下一篇文档将介绍 CantripOS 的软件组织结构