{"id":13423222,"url":"https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials","last_synced_at":"2025-03-15T15:30:51.989Z","repository":{"id":37447538,"uuid":"127553476","full_name":"rust-embedded/rust-raspberrypi-OS-tutorials","owner":"rust-embedded","description":":books: Learn to write an embedded OS in Rust :crab:","archived":false,"fork":false,"pushed_at":"2024-02-10T03:24:45.000Z","size":21234,"stargazers_count":13622,"open_issues_count":17,"forks_count":790,"subscribers_count":238,"default_branch":"master","last_synced_at":"2024-10-29T14:55:49.616Z","etag":null,"topics":["aarch64","arm64","armv8","bare-metal","embedded-rust","kernel","operating-system","os","raspberry","raspberry-pi","raspberry-pi-3","raspberry-pi-4","rpi3","rpi4","rust","tutorial"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rust-embedded.png","metadata":{"files":{"readme":"README.CN.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":["https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials/blob/master/SPONSORING.md"]}},"created_at":"2018-03-31T17:08:56.000Z","updated_at":"2024-10-29T06:18:28.000Z","dependencies_parsed_at":"2023-01-31T16:01:18.961Z","dependency_job_id":"3ae329ef-de7b-4714-a2f3-efe8eaf693ff","html_url":"https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials","commit_stats":null,"previous_names":["rust-embedded/rust-raspi3-os-tutorials"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-embedded%2Frust-raspberrypi-OS-tutorials","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-embedded%2Frust-raspberrypi-OS-tutorials/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-embedded%2Frust-raspberrypi-OS-tutorials/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-embedded%2Frust-raspberrypi-OS-tutorials/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rust-embedded","download_url":"https://codeload.github.com/rust-embedded/rust-raspberrypi-OS-tutorials/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243112146,"owners_count":20238185,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aarch64","arm64","armv8","bare-metal","embedded-rust","kernel","operating-system","os","raspberry","raspberry-pi","raspberry-pi-3","raspberry-pi-4","rpi3","rpi4","rust","tutorial"],"created_at":"2024-07-31T00:00:25.332Z","updated_at":"2025-03-15T15:30:50.830Z","avatar_url":"https://github.com/rust-embedded.png","language":"Rust","readme":"# Rust 开发树莓派操作系统教程\n\n![](https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials/workflows/BSP-RPi3/badge.svg) ![](https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials/workflows/BSP-RPi4/badge.svg) ![](https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials/workflows/Unit-Tests/badge.svg) ![](https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials/workflows/Integration-Tests/badge.svg) ![](https://img.shields.io/badge/License-MIT%20OR%20Apache--2.0-blue)\n\n\u003cbr/\u003e\n\n\u003cimg src=\"doc/header.jpg\" height=\"379\"\u003e \u003cimg src=\"doc/minipush_demo_frontpage.gif\" height=\"379\"\u003e\n\n## ℹ️ 介绍\n\n该系列教程适用于 ARM64 位[ARMv8-A 架构]的业余操作系统开发者。该教程会从零开始，一步步地指导你如何开发一个[功能健全的]\n嵌入式操作系统的内核。包含了实现一般操作系统的任务，例如开发串口控制台，设置虚拟内存和处理硬件异常。\n同时利用 Rust 的特性来提供系统的安全和速度。\n\n祝你玩得开心！\n\n_带上我最诚挚的问候,\u003cbr\u003eAndre ([@andre-richter])_\n\n[armv8-a 架构]: https://developer.arm.com/products/architecture/cpu-architecture/a-profile/docs\n[功能健全的]: https://en.wikipedia.org/wiki/Monolithic_kernel\n[@andre-richter]: https://github.com/andre-richter\n\n## 📑 教程结构\n\n- 每篇教程都包含一个独立可引导的二进制内核文件。\n- 每篇新的教程都在之前的基础上扩展。\n- 每篇教程的指南里面都有一个简短的章节来总结新增的代码和功能，也会展示源代码的区别，方便检查和同步。\n- 部分教程中有除了`tl;dr`章节外还有非常详细、具体的介绍。长期计划是所有的教程都会有详细的文字说明。但是目前只有那些我认为教程的`tl;dr`和`diff`还不够详细的章节会详细说明。\n- 教程中所用的代码可以在**树莓派 3 和 4**上运行。\n  - 教程的第一到五章是基础内容，只能运行在`QEMU`上。\n  - 到了[第六章]时(06_drivers_gpio_uart)，你可以在树莓派上加载和运行内核并通过`UART`来观察输出结果。\n- 虽然这些教程是以树莓派 3 和 4 为试验对象，但代码是模块化的，所以应该容易移植到其他 CPU 架构的开发板上。\n  - 我希望会有人有机会去实现**RISC-V**架构的代码。\n- 我推荐使用[Visual Studio Code],配置[Rust Analyzer]插件开发代码。\n- 除了文本教程之外，也可以用`make doc`命令利用网页的优势来浏览代码。\n\n### `make doc` 的输出\n\n![make doc](doc/make_doc.png)\n\n[Visual Studio Code]: https://code.visualstudio.com\n[Rust Analyzer]: https://rust-analyzer.github.io\n\n## 🛠 系统要求\n\n本教程主要是面向**Linux**发行版的。理论上，文中大部分内容在其他类Unix系统诸如**macOS**也能正常工作，但请注意，只是理论上。\n\n### 🚀 tl;dr 版本\n\n1. [安装 Docker][install_docker]。\n2. **(仅限Linux)** 确保您的用户帐户在 [docker group] 中。\n3. 准备Rust工具链。其中大部分将在首次使用时通过[rust-toolchain.toml](rust-toolchain.toml)文件进行处理。我们要做的是：\n   1. 如果你已经安装了一个版本的Rust:\n      ```bash\n      cargo install cargo-binutils rustfilt\n      ```\n\n   1. 如果你想要全新安装:\n      ```bash\n      curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh\n\n      source $HOME/.cargo/env\n      cargo install cargo-binutils rustfilt\n      ```\n\n4. 如果你使用 `Visual Studio Code`，我强烈推荐你安装[Rust Analyzer 扩展]。\n5. **(仅限macOS)** 安装一些`Ruby` gems。\n\n这是作者最后一次在`macOS Monterey`上用`Ruby 3.0.2`版本进行测试。如果您正在使用`rbenv`，那么相应的`.ruby-version`文件已经就位。\n如果你从未听说过`rbenv`，请尝试使用[这个指南](https://stackoverflow.com/a/68118750)。\n\n在存储库根文件夹中运行此操作：\n\n```bash\nbundle config set --local path '.vendor/bundle'\nbundle config set --local without 'development'\nbundle install\n```\n\n[docker group]: https://docs.docker.com/engine/install/linux-postinstall/\n[Rust Analyzer 扩展]: https://marketplace.visualstudio.com/items?itemName=matklad.rust-analyzer\n\n\n## 🧰 长期版本: 消除工具链烦恼\n\n这个系列的教程会着重关注用户体验的友好性。因此，我尽量消除嵌入式开发中的最大痛点：`Toolchain hassle`。\n\nRust内置的交叉编译支持在这方面帮了我们大忙。我们只需要使用`rustup`安装目标工具链就可以在`x86`宿主机上交叉编译支持树莓派的目标文件。然而，除了Rust编译器，我们还需要更多的工具。例如：\nRust本身在这方面已经起到了很大的作用，因为它内置了对交叉编译的支持。从`x86`宿主机到树莓派的`AArch64`架构的交叉编译所需的一切都将由`rustup`自动安装。然而，除了Rust编译器，我们还将使用更多的工具。例如：\n\n- 用于在我们的宿主系统上模拟我们内核运行环境的`QEMU`。\n- 一个叫`Minipush`的自制工具，可以通过`UART`将内核加载到树莓派上。\n- 用于调式目标文件的`OpenOCD`和`GDB`。\n\n在你的宿主机上安装/编译正确版本的上述工具很可能会遇到很多麻烦。举个例子，你的发行版也许并不会提供我们需要的最新版本的软件包。又或者你在编译这些工具时会遇到一些很难处理的依赖问题。\n\n这也是为什么我们要尽可能使用[Docker][install_docker]的原因。我们提供了一个已经预装了所有需要的工具及依赖的容器，当需要的时候它就会被自动拉取。如果你想要了解更多有关Docker和这个容器的细节，请查看本仓库下的[docker](docker) 文件夹。\n\n[install_docker]: https://docs.docker.com/get-docker/\n\n## 📟 USB 串行输出\n\n由于教程中开发的内核是在真实的硬件上运行的，因此强烈建议您使用 USB 串行调试线来进行试验。连接调试线后，树莓派需要通过额外电源供电。\n\n- 您可以在[\\[1\\]] [\\[2\\]]中或者[淘宝]上找到USB转串口线，但许多其他线材也可以工作。理想情况下，您的线材应基于`CP2102`芯片。\n- 您将其连接到`GND`和GPIO引脚`14/15`，如下所示。\n- [教程5](05_drivers_gpio_uart/README.CN.md)是这个设备第一次需要使用的地方。查看它了解如何准备SD卡以从中启动自制内核的说明。\n- 从[教程6](06_uart_chainloader/README.CN.md)开始，在树莓派上启动内核变得非常舒适。在本教程中开发了一个所谓的`chainloader`，。\n  这将是您暂时需要在SD卡上手动复制的最后一个文件。这将使您能够在通过`UART`按需引导期间加载教程内核。\n\n![UART wiring diagram](doc/wiring.png)\n\n[\\[1\\]]: https://www.amazon.de/dp/B0757FQ5CX/ref=cm_sw_r_tw_dp_U_x_ozGRDbVTJAG4Q\n[\\[2\\]]: https://www.adafruit.com/product/954\n[淘宝]: https://www.taobao.com/\n\n## 🙌 致谢\n\n这个教程最初是由[Zoltan Baldaszti](https://github.com/bztsrc)的[项目](https://github.com/bztsrc/raspi3-tutorial)衍生出来的，感谢它给我开了一个头。\n\n## License\n\nLicensed under either of\n\n- Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n\n### 贡献\n\n除非您明确声明，否则有意提交给您的任何贡献（包括 Apache-2.0 许可中定义的）均应按上述双重许可，且无任何附加条款或条件。\n","funding_links":["https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials/blob/master/SPONSORING.md"],"categories":["Books, blogs and training materials","Rust","Language-Specific Tools","Rust 程序设计","Embedded Development","Install script","C/C++生态圈Dev\u0026Ops工具与服务","Operating Systems"],"sub_categories":["Community Chat Rooms","Rust","网络服务_其他","Operating Systems Development"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frust-embedded%2Frust-raspberrypi-OS-tutorials","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frust-embedded%2Frust-raspberrypi-OS-tutorials","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frust-embedded%2Frust-raspberrypi-OS-tutorials/lists"}