Hello Baochip
本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。
Hello Baochip
Baochip is the latest open/trustable hardware venture by living legend Andrew “bunnie” Huang (wikipedia.org). Here’s the official website: https://www.baochip.com/ But I recommend bunnie’s write-ups on his blog as an introduction: Baochip-1x: A Mostly-Open, 22nm SoC for High Assurance Applications (bunniestudios.com) BIO: The Bao I/O Coprocessor (bunniestudios.com)
Baochip 是传奇人物 Andrew “bunnie” Huang(wikipedia.org)推出的最新开放/可信硬件项目。官方网站为:https://www.baochip.com/,但我建议阅读 bunnie 在其博客上的文章作为入门:Baochip-1x: A Mostly-Open, 22nm SoC for High Assurance Applications (bunniestudios.com) 以及 BIO: The Bao I/O Coprocessor (bunniestudios.com)。
What makes the Baochip1x special is that it is an SoC (system on chip) with: A RISC-V core An MMU (memory management unit, allows for hardware support of virtual memory, a feature normally reserved for “real” computers) I/O coprocessor (BIO) Hardware support for a bunch of security-focused features such as a TRNG (true random number generator), AES encryption, and a ton of cryptographic hashes It is intentionally inspectable with inexpensive infra-red cameras so you can visibly verify the structure of the chip yourself! (See Infra-Red, In Situ (IRIS) Inspection of Silicon (bunniestudios.com) It was made specifically to be able to run Xous, a microkernel OS written in Rust originally written for bunnie’s Precursor device. See Xous 0.10.0 - Introducing Baochip-1x Support (crowdsupply.com). More about Xous here: https://betrusted.io/xous-book/
Baochip1x 的特别之处在于它是一款 SoC(片上系统),具备:一个 RISC-V 内核、一个 MMU(内存管理单元,允许硬件支持虚拟内存,这是通常仅限于“真正”计算机的功能)、一个 I/O 协处理器(BIO),以及对一系列安全功能(如真随机数生成器 TRNG、AES 加密和大量加密哈希)的硬件支持。它被设计为可以使用廉价的红外摄像机进行检查,因此您可以亲自直观地验证芯片结构!(参见 Infra-Red, In Situ (IRIS) Inspection of Silicon (bunniestudios.com))。它专为运行 Xous 而设计,这是一款最初为 bunnie 的 Precursor 设备编写的 Rust 微内核操作系统。参见 Xous 0.10.0 - Introducing Baochip-1x Support (crowdsupply.com)。关于 Xous 的更多信息请见:https://betrusted.io/xous-book/
I’m mostly here because I think bunnie is great and I’m interested in RISC-V as a platform. (I’ve been a fan of bunnie since his On MicroSD Problems (bunniestudios.com) investigation and write-up, but especially after I read his book The Hardware Hacker: Adventures in Making and Breaking Hardware in 2019.)
我在这里主要是因为我认为 bunnie 很棒,并且我对 RISC-V 平台很感兴趣。(自从读了他的 On MicroSD Problems (bunniestudios.com) 调查报告后,我就一直是 bunnie 的粉丝,尤其是在 2019 年读了他的书《The Hardware Hacker: Adventures in Making and Breaking Hardware》之后。)
The Dabao evaluation board My Dabao board with the Baochip1x arrived today from Crowd Supply. Here’s a crummy image of the chip itself, so tiny and so shiny!: It’s shiny because there’s no package, that’s the actual silicon polished to a perfect mirror finish. Let’s connect to it! I found this pair of READMEs in the Xous repo most helpful: https://github.com/betrusted-io/xous-core/blob/dev/README-baochip.md “Regardless of the board, the bao1x chip comes from the factory programmed with boot0 and boot1 stages. The code for these can be found in bao1x-boot/.” “boot1 contains a USB driver, serial-over-USB driver, and serial driver capable of accepting code updates in the form of .u2f files or serial commands. It also contains a small command terminal for managing configurations, keys, and device lifecycle state.”
Dabao 评估板:我从 Crowd Supply 订购的带有 Baochip1x 的 Dabao 板今天到了。这是一张芯片本身的模糊照片,它非常小且闪亮!它之所以闪亮是因为没有封装,那是经过完美镜面抛光的真实硅片。让我们连接它吧!我在 Xous 仓库中发现这两个 README 文件非常有帮助:https://github.com/betrusted-io/xous-core/blob/dev/README-baochip.md “无论使用哪种板子,bao1x 芯片出厂时都已预编程了 boot0 和 boot1 阶段。这些代码可以在 bao1x-boot/ 中找到。” “boot1 包含一个 USB 驱动程序、USB 串口驱动程序以及能够接受 .u2f 文件或串口命令形式代码更新的串口驱动程序。它还包含一个用于管理配置、密钥和设备生命周期状态的小型命令终端。”
https://github.com/betrusted-io/xous-core/blob/dev/README-consoles.md “Baochip relies primarily upon a “virtual serial console”, which is a USB CDC-ACM device. In short, when you plug a Baochip into your computer, you will get something similar to either a COM port (on windows) or a tty node (on Linux).” Sure enough, I plugged it into my Linux PC and there it is: $ sudo dmesg … [41412.220396] usb 3-4: Product: Baochip-1x [41412.220400] usb 3-4: Manufacturer: Baochip [41412.220404] usb 3-4: SerialNumber: YH1DTN [41412.307486] usb-storage 3-4:1.2: USB Mass Storage device detected [41412.307677] scsi host9: usb-storage 3-4:1.2 [41412.307824] usbcore: registered new interface driver usb-storage [41412.308600] cdc_acm 3-4:1.0: ttyACM0: USB ACM device …
https://github.com/betrusted-io/xous-core/blob/dev/README-consoles.md “Baochip 主要依赖于‘虚拟串口控制台’,即 USB CDC-ACM 设备。简而言之,当您将 Baochip 插入计算机时,您将获得类似于 Windows 上的 COM 端口或 Linux 上的 tty 节点的东西。” 果然,我把它插到我的 Linux PC 上,它就在那里:$ sudo dmesg … [41412.220396] usb 3-4: Product: Baochip-1x [41412.220400] usb 3-4: Manufacturer: Baochip [41412.220404] usb 3-4: SerialNumber: YH1DTN [41412.307486] usb-storage 3-4:1.2: USB Mass Storage device detected [41412.307677] scsi host9: usb-storage 3-4:1.2 [41412.307824] usbcore: registered new interface driver usb-storage [41412.308600] cdc_acm 3-4:1.0: ttyACM0: USB ACM device …
Using GNU screen is how I’m used to speaking to serial devices and that’s what the README recommended as well. Depending on your distro’s setup, it may be easiest to simply run screen as root. Without root: $ screen /dev/ttyACM0 1000000 [screen is terminating] With root: $ sudo screen /dev/ttyACM0 1000000 (terminal goes blank - we’re connected!)
使用 GNU screen 是我与串口设备通信的习惯方式,这也是 README 推荐的方法。根据您的发行版设置,最简单的方法可能是直接以 root 身份运行 screen。不使用 root:$ screen /dev/ttyACM0 1000000 [screen is terminating];使用 root:$ sudo screen /dev/ttyACM0 1000000(终端变为空白 - 我们已连接!)
The boot1 REPL (which we can think of here as nothing more than a simple command-line interface) presents a completely blank terminal with no prompt. Hit Enter or trying typing a command and you’ll see a reply if everything’s working: Command not recognized: Commands include: altboot, audit, boot, boardtype, bootwait, echo, idmode, ifr, localecho, lockdown, paranoid, reset, self_destruct, skipping, uf2 The easiest commmand to use is echo: echo Hello World! Hello World!
boot1 REPL(在这里我们可以将其视为一个简单的命令行界面)呈现出一个完全空白且没有提示符的终端。按下回车键或尝试输入命令,如果一切正常,您将看到回复:Command not recognized: Commands include: altboot, audit, boot, boardtype, bootwait, echo, idmode, ifr, localecho, lockdown, paranoid, reset, self_destruct, skipping, uf2。最简单的命令是 echo:echo Hello World! Hello World!
Some of the others are mysterious or scary like paranoid or even self_destruct. Since the source for both boot stages are in the Xous repo, I cloned it and searched for the REPL commands. Sure enough, I found them in: xous-core/bao1x-boot/boot1/src/repl.rs. Here’s the echo command: “echo” => { for word in args { crate::print!(”{} ”, word); } crate::println!(""); } And self_destruct is not a joke: “self_destruct” => { if !matches!(args.as_slice(), [s] if s == “void_my_warrantee”) { return Err(Error::help( “Usage: ‘self_destruct void_my_warrantee’. This PERMANENTLY wipes the chip and bricks it. No returns or exchanges are allowed after executing this command.”, )); } let mut rram = bao1x_hal::rram::Reram::new(); unsafe { rram.self_destruct() } // … and all was null and void! }
其他一些命令则显得神秘或可怕,比如 paranoid 甚至 self_destruct。由于两个引导阶段的源代码都在 Xous 仓库中,我克隆了它并搜索了 REPL 命令。果然,我在 xous-core/bao1x-boot/boot1/src/repl.rs 中找到了它们。这是 echo 命令:“echo” => { for word in args { crate::print!(”{} ”, word); } crate::println!(""); } 而 self_destruct 并非玩笑:“self_destruct” => { if !matches!(args.as_slice(), [s] if s == “void_my_warrantee”) { return Err(Error::help( “Usage: ‘self_destruct void_my_warrantee’. This PERMANENTLY wipes the chip and bricks it. No returns or exchanges are allowed after executing this command.”, )); } let mut rram = bao1x_hal::rram::Reram::new(); unsafe { rram.self_destruct() } // … and all was null and void! }
I didn’t see any easter eggs and echo is the only real command one would “play” with. Exit from the screen session with the screen prefix command CTRL+A followed by the \ key. Where to go from here? I’m just happy this thing exists and that I could talk with it right away. I think this is my first interactions with a computer running a RISC-V architecture? It looks like the Xous ecosystem is very well planned, with a focus on having a toolchain that doesn’t rely on a ton of fragile C tooling setup.
我没有看到任何彩蛋,echo 是唯一一个人们会“玩”的真正命令。使用 screen 前缀命令 CTRL+A 后跟 \ 键退出 screen 会话。接下来该做什么?我很高兴这个东西存在,并且我能立即与它对话。我想这是我第一次与运行 RISC-V 架构的计算机交互?看起来 Xous 生态系统规划得非常好,重点在于拥有一个不依赖于大量脆弱 C 工具链设置的工具链。
I thought this was particularly insightful (from bunnie’s blog post about the BIO coprocessor linked above): ”…one of the key benefits of the Xous ecosystem being pure Rust is that we don’t have to maintain any tooling. We’d like to keep it so that the only tool required to build a Xous image is stable Rust. The moment a C compiler is introduced into the build process, we have to wade through a hodge-podge of distribution-specific C toolchains, greatly increasing developer friction and maintenance burden.” As an aside, here’s an interesting tidbit for Zig fans: “Our solution to this problem, at least for now, is to borrow the Zig ecosystem’s clang C compiler. … As a side-effect, this also paves an on-ramp for Zig developers to write BIO code.” But I really thin
我认为这一点特别有见地(来自上面链接的关于 BIO 协处理器的 bunnie 博客文章):“……Xous 生态系统纯粹使用 Rust 的主要好处之一是我们不必维护任何工具。我们希望保持构建 Xous 镜像所需的唯一工具就是稳定版 Rust。一旦在构建过程中引入 C 编译器,我们就必须处理各种特定于发行版的 C 工具链,这大大增加了开发者的摩擦和维护负担。” 顺便提一下,对于 Zig 粉丝来说,这里有一个有趣的小知识:“我们目前解决这个问题的方法是借用 Zig 生态系统的 clang C 编译器。……作为一个副作用,这也为 Zig 开发者编写 BIO 代码铺平了道路。” 但我真的认为