You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

寻求嵌入式系统(含Raspberry Pi)Secure Boot实现方案及资源

Raspberry Pi 2/3 Secure Boot 实操实现方案

一、前置准备

  • 具备Linux开发环境(推荐Ubuntu/Debian),安装依赖工具:sudo apt install openssl raspberrypi-tools device-tree-compiler
  • 树莓派2/3开发板,空白SD卡(≥8GB)
  • 重要提醒:启用Secure Boot会修改OTP一次性可编程熔丝,此操作不可逆,请确认需求后再执行

二、核心实现步骤

1. 生成签名密钥对

使用OpenSSL生成2048位RSA密钥对,私钥需妥善保管(丢失后无法签名新固件):

# 生成私钥
openssl genrsa -out rpi_secure_boot_priv.pem 2048
# 导出公钥(后续用于配置OTP熔丝)
openssl rsa -in rpi_secure_boot_priv.pem -pubout -out rpi_secure_boot_pub.pem

2. 编译签名工具

从树莓派官方工具源码仓库克隆代码,进入bootloader目录编译得到rpisigntool:

git clone --depth=1 树莓派官方工具仓库
cd tools/bootloader
make signtool

编译完成后,rpisigntool可用于签名树莓派boot阶段的核心固件。

3. 签名Boot固件

从树莓派官方渠道下载最新boot固件包,解压后对bootcode.bin、start.elf、fixup.dat这三个核心文件进行签名:

# 进入固件boot目录
cd firmware/boot

# 签名核心固件文件
../tools/bootloader/rpisigntool -v -k ../../rpi_secure_boot_priv.pem -s bootcode.bin
../tools/bootloader/rpisigntool -v -k ../../rpi_secure_boot_priv.pem -s start.elf
../tools/bootloader/rpisigntool -v -k ../../rpi_secure_boot_priv.pem -s fixup.dat

4. 配置OTP熔丝启用Secure Boot

通过树莓派的vcgencmd工具完成OTP熔丝配置,写入公钥哈希并启用Secure Boot锁:

# 计算公钥的SHA256哈希值
openssl rsa -in rpi_secure_boot_pub.pem -pubin -outform DER | sha256sum | cut -d' ' -f1 > pubkey_hash.txt

# 将哈希值分4段写入OTP熔丝(不可逆操作)
vcgencmd otp_write 0x31 $(cat pubkey_hash.txt | cut -c1-8)
vcgencmd otp_write 0x32 $(cat pubkey_hash.txt | cut -c9-16)
vcgencmd otp_write 0x33 $(cat pubkey_hash.txt | cut -c17-24)
vcgencmd otp_write 0x34 $(cat pubkey_hash.txt | cut -c25-32)

# 启用Secure Boot熔丝锁(不可逆)
vcgencmd otp_write 0x30 0x5A000000

5. 验证Secure Boot功能

将签名后的boot固件复制到SD卡的boot分区,插入树莓派启动:

  • 若固件签名与OTP中存储的公钥匹配,树莓派正常启动
  • 若使用未签名或签名不匹配的固件,树莓派会停止启动,电源灯以4次闪烁的方式报错

三、本地参考资源

  • 树莓派官方《Secure Boot Implementation Guide》:可从树莓派官方固件仓库的docs目录获取
  • Linux内核文档《Embedded Secure Boot》:位于Linux内核源码树的Documentation/security/secure-boot.rst
  • 嵌入式Linux实战手册中关于Boot链安全的章节

内容的提问来源于stack exchange,提问作者Payam30

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 05:17:24