#card10 #ccc #l0dable #cc-camp19 #cc-camp2019

nightly sys no-std card10-sys

为 card10 l0dables 提供不安全的 C 绑定

2 个稳定版本

1.10.0 2019年9月8日
1.9.0 2019年9月3日

#236 in 无标准库


用于 2 crates

MIT/Apache

19MB
197K SLoC

C 161K SLoC // 0.2% comments SWIG 9K SLoC // 0.2% comments M4 8K SLoC // 0.3% comments Shell 7.5K SLoC // 0.2% comments Visual Studio Project 5K SLoC GNU Style Assembly 2K SLoC // 0.2% comments Bitbake 1.5K SLoC // 0.3% comments Assembly 772 SLoC // 0.1% comments Arduino C++ 766 SLoC // 0.4% comments Automake 762 SLoC // 0.1% comments Python 170 SLoC // 0.4% comments Visual Studio Solution 140 SLoC Rust 132 SLoC // 0.0% comments Perl 97 SLoC // 0.2% comments INI 52 SLoC GDB Script 42 SLoC

包含 (静态库,3MB) libarm_cortexM3l_math.a,(静态库,3MB) libarm_cortexM4l_math.a,(静态库,3MB) libarm_cortexM4lf_math.a,(自动工具混淆代码,1MB) configure,(模糊 autoconf 代码,59KB) configure.ac

Rust 对 card10 CCCamp19 徽章的支持

准备你的 card10

解锁不再是必需的!

从固件 v1.9 开始,运行 ELF 可执行文件需要包含以下内容的 /card10.cfg

execute_elf=true

预构建的二进制文件

得益于 Gitlab 的 CI 系统和 NixOS,我们为您构建了 .elf 文件,可以直接放入 card10 徽章的 apps/ 目录。

对于本仓库中的每个提交,我们还会构建包含所需配置和示例二进制文件的完整固件镜像。

https://git.card10.badge.events.ccc.de/astro/rust-card10/-/jobs

先决条件

您需要 Rust 夜间版本和一个可编译 card10 固件(包括匹配的 libc)的工作环境。

  1. 有关如何设置 rust 的说明,请参阅 https://rustup.rs

    请确保您已安装最新的 rust 夜间工具链,并添加 thumbv7em-none-eabi 目标。

    rustup toolchain install nightly
    rustup update
    rustup target add thumbv7em-none-eabi --toolchain nightly
    
  2. 有关如何设置 card10 固件的说明,请查看 https://firmware.card10.badge.events.ccc.de/how-to-build.html 中的依赖性章节。

  3. 此外,您可能还需要 llvm 和 libc i386 开发头文件的软件包。

  4. 使用 --recursive 克隆此仓库以获取子模块,否则之后更新它们

    git submodule update --init --recursive
    

构建和运行 Rust 可加载程序

设置

如果您想创建自己的基于 Rust 的可加载程序 crate,则需要做一些准备工作

  • 设置新的 crate 仓库。

  • card10-l0dable = "^0.1" 添加为新crate的依赖项。

  • 修改你 Cargo.toml 文件中默认的 cargo 发布配置。

    [profile.release]
    opt-level = "s"
    panic = "abort"
    
  • $PROJECT/.cargo/config 中创建(或更新)thumbv7em-none-eabi 目标配置,并使用以下rustflags

    [target.thumbv7em-none-eabi]
    rustflags = [
      "-C", "linker=arm-none-eabi-gcc",
      "-C", "link-args=-Tl0dable.ld -n -pie -fPIC",
      "-C", "relocation-model=pic",
    ]
    
    [build]
    target = "thumbv7em-none-eabi"
    
  • 确保你的crate被标记为 non_std 项目,并且让 card10-l0dable 了解你的自定义main函数。这需要在你的 main.rs 文件中进行以下更新。

    #![no_std]
    #![no_main]
    
    use card10_l0dable::main;
    
    main!(main);
    fn main() {}
    

编译

使用nightly工具链并定义正确的目标来编译项目。

cargo +nightly build --release --target thumbv7em-none-eabi

转移到card10

然后,将目标目录 target/thumbv7em-none-eabi/release/example 中的结果可执行文件复制到你的徽章的 apps 目录。

注意:需要将可执行文件重命名为添加 elf 扩展名(例如,将 example 重命名为 example.elf)。

Crates

Crate 文档 描述
card10-sys docs.rs 为l0dables提供不安全的C绑定
card10-alloc docs.rs 为l0dables提供alloc::*支持
card10-l0dable docs.rs 构建l0dables的高层crate
example l0dable示例
rkanoid Arkanoid克隆
draw-image 将静态图像绘制到显示屏的示例

杂项

如何更新固件绑定

  1. card10-sys/firmware 子模块更新到最新的固件状态。

  2. 按照上述方法重新构建固件。

  3. 从项目根目录运行以下脚本

    python card10-sys/firmware/epicardium/api/genapi.py -H card10-sys/firmware/epicardium/epicardium.h -c card10-sys/vendor/client.c -s card10-sys/vendor/server.c
    
  4. 重新构建你的应用 :)


lib.rs:

此文件与card10 EPIC API客户端C代码链接。

依赖项