From 6e482f887da9868a3cdd26b8395990a44504d40b Mon Sep 17 00:00:00 2001 From: cjiio Date: Fri, 4 Sep 2026 11:02:00 +0800 Subject: [PATCH] fix(bootloader): remove recovery key hook --- AGENTS.md | 9 +-- AGENTS.zh_CN.md | 8 +-- CMakeLists.txt | 8 --- .../recovery_boot_hook/CMakeLists.txt | 5 -- .../recovery_boot_hook/recovery_boot_hook.c | 31 -------- docs/CHANGELOG.md | 8 +-- docs/CHANGELOG.zh_CN.md | 6 +- docs/README.md | 2 +- docs/README.zh_CN.md | 2 +- docs/development/README.md | 2 +- docs/development/README.zh_CN.md | 2 +- docs/development/ci/CI-build-and-release.md | 2 +- .../ci/CI-build-and-release.zh_CN.md | 2 +- .../engineering/ble-recovery-compatibility.md | 70 ------------------- .../ble-recovery-compatibility.zh_CN.md | 59 ---------------- .../development/engineering/build-and-test.md | 11 ++- .../engineering/build-and-test.zh_CN.md | 8 +-- .../engineering/protected-flash-layout.md | 61 ++++++++++++++++ .../protected-flash-layout.zh_CN.md | 55 +++++++++++++++ .../release/publish-to-community.md | 4 +- .../release/publish-to-community.zh_CN.md | 4 +- .../AI_HARDWARE_DEVELOPMENT_GUIDE.md | 4 +- .../AI_HARDWARE_DEVELOPMENT_GUIDE.zh_CN.md | 4 +- docs/hardware-design/specifications.md | 2 +- docs/hardware-design/specifications.zh_CN.md | 2 +- sdkconfig.defaults | 13 +--- tests/test_verify_firmware.py | 18 ++++- tools/verify_firmware.py | 15 ++-- 28 files changed, 181 insertions(+), 236 deletions(-) delete mode 100644 bootloader_components/recovery_boot_hook/CMakeLists.txt delete mode 100644 bootloader_components/recovery_boot_hook/recovery_boot_hook.c delete mode 100644 docs/development/engineering/ble-recovery-compatibility.md delete mode 100644 docs/development/engineering/ble-recovery-compatibility.zh_CN.md create mode 100644 docs/development/engineering/protected-flash-layout.md create mode 100644 docs/development/engineering/protected-flash-layout.zh_CN.md diff --git a/AGENTS.md b/AGENTS.md index 8a6e3a0..54d58a0 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -9,9 +9,10 @@ This file is the only mandatory entry point for AI-assisted work in this reposit ## Project and safety baseline - Target: ESP32-C3, 8 MB Flash, no PSRAM, ESP-IDF 5.5.3. -- Preserve mini-program BLE install compatibility: the 3 MB application limit, - `cardid` at `0x356000`, permanent Recovery at `0x700000`, and the five-second - UP-key bootloader hook are mandatory template contracts. +- Preserve the protected Flash layout: the 3 MB application limit, `cardid` at + `0x356000`, and factory-owned Recovery at `0x700000` are mandatory template + contracts. The template intentionally provides no function-key bootloader + hook for entering Recovery. - Preserve existing user changes. Start with `git status --short --branch`; never overwrite or clean unrelated files. - Hardware facts follow this priority: product specifications and measured results → `components/bsp/include/bsp_pins.h` → BSP headers and implementation → hardware guide → README/demo code. If a task requires a hardware detail not defined by these sources, ask the user instead of guessing. - Reusable board logic belongs in `components/bsp`; pages, state machines, animations, and application tasks belong in `main`. @@ -30,7 +31,7 @@ This file is the only mandatory entry point for AI-assisted work in this reposit | Environment bootstrap or missing toolchain | `docs/development/engineering/environment-setup.md` | | BSP, pins, buses, display, audio, battery | `docs/hardware-design/AI_HARDWARE_DEVELOPMENT_GUIDE.md`, `components/bsp/include/bsp_pins.h` | | Demo or menu | `main/demo.h`, `main/main.c`, the nearest `main/demo_*.c` implementation | -| Build, test, dependencies, partitions | `docs/development/engineering/build-and-test.md`, `docs/development/engineering/ble-recovery-compatibility.md`, `sdkconfig.defaults`, `partitions.csv` | +| Build, test, dependencies, partitions | `docs/development/engineering/build-and-test.md`, `docs/development/engineering/protected-flash-layout.md`, `sdkconfig.defaults`, `partitions.csv` | | CI or release | the matching file in `docs/development/ci/CI-*.md` and `.github/workflows/` | | Project completion | `docs/development/release/project-completion.md` (then the `issue-suggestions` or `experience-pr` skill) | | Documentation | `docs/contribution/doc-conventions.md`, `docs/README.md` | diff --git a/AGENTS.zh_CN.md b/AGENTS.zh_CN.md index 4011f53..1e2d5d1 100644 --- a/AGENTS.zh_CN.md +++ b/AGENTS.zh_CN.md @@ -9,9 +9,9 @@ ## 项目与安全基线 - 目标平台:ESP32-C3、8 MB Flash、无 PSRAM、ESP-IDF 5.5.3。 -- 必须保持小程序 BLE 安装兼容:3 MB 应用上限、`cardid@0x356000`、 - 永久 `recovery@0x700000` 以及上键持续 5 秒进入 Recovery 的 bootloader hook - 均为模板强制契约。 +- 必须保持受保护的 Flash 布局:3 MB 应用上限、`cardid@0x356000` + 与工厂所有的 `recovery@0x700000` 均为模板强制契约。模板不提供 + 任何功能键进入 Recovery 的 bootloader hook。 - 保留用户已有修改。先执行 `git status --short --branch`,不得覆盖或清理无关文件。 - 硬件事实优先级:产品规格与实测结果 → `components/bsp/include/bsp_pins.h` → BSP 头文件与实现 → 硬件指南 → README/demo。任务所需硬件细节未在这些来源中定义时,直接询问用户,不得猜测。 - 可复用板级逻辑放入 `components/bsp`;页面、状态机、动画和应用任务放入 `main`。 @@ -30,7 +30,7 @@ | 环境引导或缺少工具链 | `docs/development/engineering/environment-setup.zh_CN.md` | | BSP、引脚、总线、显示、音频、电池 | `docs/hardware-design/AI_HARDWARE_DEVELOPMENT_GUIDE.zh_CN.md`、`components/bsp/include/bsp_pins.h` | | Demo 或菜单 | `main/demo.h`、`main/main.c`、最近的 `main/demo_*.c` 实现 | -| 构建、测试、依赖、分区 | `docs/development/engineering/build-and-test.zh_CN.md`、`docs/development/engineering/ble-recovery-compatibility.zh_CN.md`、`sdkconfig.defaults`、`partitions.csv` | +| 构建、测试、依赖、分区 | `docs/development/engineering/build-and-test.zh_CN.md`、`docs/development/engineering/protected-flash-layout.zh_CN.md`、`sdkconfig.defaults`、`partitions.csv` | | CI 或发布 | `docs/development/ci/CI-*.zh_CN.md` 中的对应文件与 `.github/workflows/` | | 项目开发完成 | `docs/development/release/project-completion.zh_CN.md`(再进入 `issue-suggestions` 或 `experience-pr` skill) | | 文档 | `docs/contribution/doc-conventions.zh_CN.md`、`docs/README.zh_CN.md` | diff --git a/CMakeLists.txt b/CMakeLists.txt index 63a15ad..d803bce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,4 @@ cmake_minimum_required(VERSION 3.16) include($ENV{IDF_PATH}/tools/cmake/project.cmake) -# Community firmware replaces the bootloader when installed over USB. Keep the -# factory Recovery entry gesture in every derivative build so USB development -# does not strand the device outside the mini-program BLE install path. -idf_build_set_property( - BOOTLOADER_EXTRA_COMPONENT_DIRS - "${CMAKE_CURRENT_LIST_DIR}/bootloader_components/" - APPEND) - project(FoloToy-AI-Passport) diff --git a/bootloader_components/recovery_boot_hook/CMakeLists.txt b/bootloader_components/recovery_boot_hook/CMakeLists.txt deleted file mode 100644 index f23a6a5..0000000 --- a/bootloader_components/recovery_boot_hook/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -idf_component_register( - SRCS "recovery_boot_hook.c" - PRIV_REQUIRES bootloader_support - PRIV_INCLUDE_DIRS "$ENV{IDF_PATH}/components/bootloader_support/private_include" -) diff --git a/bootloader_components/recovery_boot_hook/recovery_boot_hook.c b/bootloader_components/recovery_boot_hook/recovery_boot_hook.c deleted file mode 100644 index 01ecdbe..0000000 --- a/bootloader_components/recovery_boot_hook/recovery_boot_hook.c +++ /dev/null @@ -1,31 +0,0 @@ -// Bootloader hook shared by every AI Passport community firmware derivative. -// Holding the UP-key ADC GPIO low for five seconds boots the factory-installed -// permanent Recovery image. This project never owns or writes that image. -#include "bootloader_common.h" -#include "bootloader_config.h" -#include "bootloader_utility.h" -#include "esp_log.h" - -#define RECOVERY_BUTTON_GPIO 0 -#define RECOVERY_HOLD_SECONDS 5 -#define RECOVERY_OFFSET 0x700000 -#define RECOVERY_SIZE 0x100000 - -void bootloader_hooks_include(void) -{ -} - -void bootloader_after_init(void) -{ - if (bootloader_common_check_long_hold_gpio( - RECOVERY_BUTTON_GPIO, RECOVERY_HOLD_SECONDS) != GPIO_LONG_HOLD) { - return; - } - - ESP_LOGI("recovery_boot", "UP held: booting permanent recovery at 0x%x", - RECOVERY_OFFSET); - bootloader_state_t state = { 0 }; - state.factory.offset = RECOVERY_OFFSET; - state.factory.size = RECOVERY_SIZE; - bootloader_utility_load_boot_image(&state, FACTORY_INDEX); -} diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index f9ca474..231202f 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -10,10 +10,10 @@ - Reorganized the documentation by function area with a dual entry point: the root `AGENTS.md` is now a thin router (hard constraints + task routing only) and the detailed AI workflow lives in `docs/development/ai-guide.md`; `agent-guide.md` was folded in. `docs/development/` gained a second level (`engineering/`, `ci/`, `release/`), and the `plays/` application archive and `experiences/` moved into a `docs/reference/` area with a dedicated README. Removed `docs/software-design/` (empty scaffold); folded the three `assets/{fonts,images,music}/README` leaves into the `assets/` README; flattened the six `project-completion` sub-documents into a single file; and unified each directory to a single README, eliminating every `INDEX` file and a duplicated experience index. All cross-references and bibliographic links were updated; no content was dropped. -- Made mini-program BLE install compatibility a template-level invariant: fixed - protected `cardid`/Recovery partitions, retained the five-second UP-key - Recovery boot hook, and added CI validation for merged-image structure, - partition MD5/ranges, the 3 MB app limit, and protected payload exclusion. +- Kept the fixed protected `cardid`/Recovery partitions and CI validation for + merged-image structure, partition MD5/ranges, the 3 MB app limit, and + protected payload exclusion, while removing the five-second function-key + Recovery boot hook. - Documented a release-title convention for multi-app releases: name tags as `v-` (e.g. `v0.1.0-voice-keychain`) so the release title carries the version and the app, and confirm the title after the release is published so a release list is scannable by app. - Added a post-release follow-up workflow: an `issue-suggestions` skill for filing user feedback as issues against the upstream project, an `experience-pr` skill for submitting reusable development experience as a documentation PR, a `docs/experiences/` directory for per-entry experience files, and supporting `project-completion`, `file-issues`, and experience-index documents. - Simplified the tracked repository root: moved GitHub-recognized community documents into `.github/`, moved the changelog into `docs/`, updated every reference, and added a root-document allowlist to repository checks. diff --git a/docs/CHANGELOG.zh_CN.md b/docs/CHANGELOG.zh_CN.md index aabe11d..f3e682f 100644 --- a/docs/CHANGELOG.zh_CN.md +++ b/docs/CHANGELOG.zh_CN.md @@ -10,9 +10,9 @@ - 按功能域整理文档并采用双入口:根目录 `AGENTS.md` 变为薄路由(只保留硬约束与任务路由),详细的 AI 开发工作流下沉到 `docs/development/ai-guide.md`,`agent-guide.md` 并入其中。为 `docs/development/` 增加二级分区(`engineering/`、`ci/`、`release/`),把 `plays/` 应用档案与 `experiences/` 移入带专属 README 的 `docs/reference/` 参考区;删除 `docs/software-design/`(空脚手架);把 `assets/{fonts,images,music}/README` 三个叶子 README 并入 `assets/` README;把 `project-completion` 的六个子文档压平为单文件;并把每个目录统一为单一 README,消除所有 `INDEX` 文件与一处重复经验索引。所有交叉引用与文献链接已更新;未丢弃任何内容。 -- 将小程序 BLE 安装兼容提升为二创模板强制契约:固定保护 `cardid`/Recovery 分区, - 保留上键持续 5 秒进入 Recovery 的 bootloader hook,并在 CI 强制校验合并镜像结构、 - 分区表 MD5/范围、3 MB 应用上限和保护分区数据不入包。 +- 保留固定的 `cardid`/Recovery 保护分区,以及 CI 对合并镜像结构、 + 分区表 MD5/范围、3 MB 应用上限和保护分区数据不入包的校验; + 移除功能键持续 5 秒进入 Recovery 的 bootloader hook。 - 规定多应用发布的 Release 标题约定:tag 按 `v<版本>-<应用名>`(如 `v0.1.0-voice-keychain`)命名,让 Release 标题同时带版本与应用名;发布成功后核对标题,保证一眼扫 Release 列表就能区分是哪个应用。 - 新增发布后收尾流程:`issue-suggestions` skill 用于把用户反馈作为 issue 提交到上游项目;`experience-pr` skill 用于把可复用的开发经验作为文档 PR 提交;新增 `docs/experiences/` 目录保存单条经验文件;并配套 `project-completion`、`file-issues` 与经验索引文档。 - 精简仓库根目录:将 GitHub 可识别的社区治理文档迁入 `.github/`,将变更记录迁入 `docs/`,同步全部引用,并在仓库检查中加入根目录文档白名单。 diff --git a/docs/README.md b/docs/README.md index bec94c7..e6b2de5 100644 --- a/docs/README.md +++ b/docs/README.md @@ -30,7 +30,7 @@ The table below describes the application capabilities implemented by the curren All pins, addresses, panel parameters, and button voltage windows are defined only in [`components/bsp/include/bsp_pins.h`](../components/bsp/include/bsp_pins.h). Application code must not duplicate these constants. See the [AI Hardware Development Guide](hardware-design/AI_HARDWARE_DEVELOPMENT_GUIDE.md) for the complete pin map, panel initialization, ADC thresholds, I2C addressing rules, audio clocks, and memory details. -Applications may also use ESP-IDF timers, FreeRTOS tasks, and internal Flash/NVS; the Pomodoro branch contains an NVS example. Wi-Fi and Bluetooth LE remain ESP-IDF application services rather than BSP APIs: their menu pages initialize each stack only while open and release it on exit. `demo/claude-buddy-port` remains a fuller BLE application architecture reference, not a substitute for measuring the current board's antenna, RF performance, power consumption, and coexistence behavior. The current product and firmware baseline uses 8 MB Flash with a 3 MB factory-app partition plus fixed protected identity and permanent-Recovery regions so derivative firmware stays installable through the mini-program. +Applications may also use ESP-IDF timers, FreeRTOS tasks, and internal Flash/NVS; the Pomodoro branch contains an NVS example. Wi-Fi and Bluetooth LE remain ESP-IDF application services rather than BSP APIs: their menu pages initialize each stack only while open and release it on exit. `demo/claude-buddy-port` remains a fuller BLE application architecture reference, not a substitute for measuring the current board's antenna, RF performance, power consumption, and coexistence behavior. The current product and firmware baseline uses 8 MB Flash with a 3 MB factory-app partition plus fixed protected identity and factory-owned Recovery regions. It does not provide a function-key bootloader entry into Recovery. ### Capabilities outside the current contract diff --git a/docs/README.zh_CN.md b/docs/README.zh_CN.md index dd33a95..4f74dea 100644 --- a/docs/README.zh_CN.md +++ b/docs/README.zh_CN.md @@ -30,7 +30,7 @@ FoloToy AI Passport 是一个开放式可穿戴 AI 硬件,本仓库是这款 A 所有引脚、地址、面板参数和按键电压窗口只在 [`components/bsp/include/bsp_pins.h`](../components/bsp/include/bsp_pins.h) 定义。应用代码不得复制这些常量。完整引脚表、面板初始化、ADC 阈值、I2C 地址规则、音频时钟和内存说明见 [AI 硬件开发指南](hardware-design/AI_HARDWARE_DEVELOPMENT_GUIDE.zh_CN.md)。 -应用也可以使用 ESP-IDF 提供的定时器、FreeRTOS 任务和内部 Flash/NVS;番茄钟分支提供了 NVS 示例。Wi-Fi 和 Bluetooth LE 仍是 ESP-IDF 应用服务而非 BSP API:其菜单页面仅在打开时初始化对应协议栈、退出时释放。`demo/claude-buddy-port` 仍是更完整的 BLE 应用架构参考,不能替代对当前板卡天线、射频表现、功耗和共存行为的实测。当前产品与固件基线使用 8 MB Flash,包含 3 MB factory-app 分区,并固定保留设备身份与永久 Recovery 区域,使二创固件仍可通过小程序安装。 +应用也可以使用 ESP-IDF 提供的定时器、FreeRTOS 任务和内部 Flash/NVS;番茄钟分支提供了 NVS 示例。Wi-Fi 和 Bluetooth LE 仍是 ESP-IDF 应用服务而非 BSP API:其菜单页面仅在打开时初始化对应协议栈、退出时释放。`demo/claude-buddy-port` 仍是更完整的 BLE 应用架构参考,不能替代对当前板卡天线、射频表现、功耗和共存行为的实测。当前产品与固件基线使用 8 MB Flash,包含 3 MB factory-app 分区,并固定保留设备身份与工厂 Recovery 区域。固件不提供任何功能键进入 Recovery 的 bootloader 入口。 ### 不属于当前能力契约的事项 diff --git a/docs/development/README.md b/docs/development/README.md index 0898211..a46d04a 100644 --- a/docs/development/README.md +++ b/docs/development/README.md @@ -14,7 +14,7 @@ This directory contains AI Passport engineering rules and reusable workflows, gr - [environment-setup.md](engineering/environment-setup.md): clean-machine bootstrap for AI agents, including international and mainland China download routes. - [build-and-test.md](engineering/build-and-test.md): ESP-IDF build and validation. -- [ble-recovery-compatibility.md](engineering/ble-recovery-compatibility.md): mandatory mini-program BLE install artifact, partition, and bootloader contract. +- [protected-flash-layout.md](engineering/protected-flash-layout.md): mandatory merged-artifact and protected-partition layout. - [coding-conventions.md](engineering/coding-conventions.md): source-code and resource conventions. ## CI diff --git a/docs/development/README.zh_CN.md b/docs/development/README.zh_CN.md index b585fb4..446d651 100644 --- a/docs/development/README.zh_CN.md +++ b/docs/development/README.zh_CN.md @@ -23,7 +23,7 @@ - [environment-setup.zh_CN.md](engineering/environment-setup.zh_CN.md):AI 在全新机器上的环境引导,包含国际与中国大陆下载线路。 - [build-and-test.zh_CN.md](engineering/build-and-test.zh_CN.md):构建与验证(ESP-IDF 命令、逻辑测试、改动验证要求)。 -- [ble-recovery-compatibility.zh_CN.md](engineering/ble-recovery-compatibility.zh_CN.md):小程序 BLE 安装所需的产物、分区与 bootloader 强制契约。 +- [protected-flash-layout.zh_CN.md](engineering/protected-flash-layout.zh_CN.md):合并产物与保护分区的强制布局。 - [coding-conventions.zh_CN.md](engineering/coding-conventions.zh_CN.md):代码约定(语言风格、复用、注释、测试同步、资源约束等)。 ## CI(ci) diff --git a/docs/development/ci/CI-build-and-release.md b/docs/development/ci/CI-build-and-release.md index a4dbb9f..50c25ea 100644 --- a/docs/development/ci/CI-build-and-release.md +++ b/docs/development/ci/CI-build-and-release.md @@ -6,7 +6,7 @@ `.github/workflows/build-firmware.yml` builds and publishes firmware for tags and supports manual dispatch. Ordinary branch pushes do not trigger it. Keep this page synchronized with the workflow. -The build job restores ccache, runs `./tools/validate.sh --firmware` with ESP-IDF 5.5.3 for ESP32-C3, verifies the bootloader at `0x0`, partition table at `0x8000`, application at `0x10000`, 8 MB Flash arguments, and the complete mini-program BLE compatibility contract, then uploads `FoloToy-AI-Passport-full.bin`. A separate least-privilege release job publishes that artifact only for a tag. +The build job restores ccache, runs `./tools/validate.sh --firmware` with ESP-IDF 5.5.3 for ESP32-C3, verifies the bootloader at `0x0`, partition table at `0x8000`, application at `0x10000`, 8 MB Flash arguments, and the protected Flash layout, then uploads `FoloToy-AI-Passport-full.bin`. A separate least-privilege release job publishes that artifact only for a tag. All Actions are pinned to full commit SHAs. The build job has `contents: read`; only the tag release job receives `contents: write`. diff --git a/docs/development/ci/CI-build-and-release.zh_CN.md b/docs/development/ci/CI-build-and-release.zh_CN.md index 952d0fb..6ca9697 100644 --- a/docs/development/ci/CI-build-and-release.zh_CN.md +++ b/docs/development/ci/CI-build-and-release.zh_CN.md @@ -19,7 +19,7 @@ 1. **ccache 缓存恢复**:使用 `actions/cache` 缓存编译中间产物(`.ccache`),二次编译大幅提速。缓存 key 含 ref 与 commit SHA;缓存保留时间以仓库的 GitHub Actions 设置为准。 2. **编译与验证**(ESP-IDF 5.5.3 / esp32c3):运行与本地相同的 `./tools/validate.sh --firmware`。脚本使用 `sdkconfig.defaults` 和 `partitions.csv` 构建固件,再执行 `idf.py merge-bin`。 -3. **验证完整固件**:脚本逐字节确认 bootloader、partition-table 和 app 位于 `0x0`、`0x8000` 和 `0x10000`,确认 `flash_args` 使用 8 MB Flash,并完整检查小程序 BLE 兼容契约,最后输出 `build/FoloToy-AI-Passport-full.bin`。 +3. **验证完整固件**:脚本逐字节确认 bootloader、partition-table 和 app 位于 `0x0`、`0x8000` 和 `0x10000`,确认 `flash_args` 使用 8 MB Flash,并完整检查受保护的 Flash 布局,最后输出 `build/FoloToy-AI-Passport-full.bin`。 4. **上传 artifact**:每次成功构建都上传 `FoloToy-AI-Passport-full.bin`。普通分支只有从该分支手动运行 `workflow_dispatch` 才会构建;普通 push 不触发。 5. **发布 tag**:tag 构建完成后,独立 release job 下载上述 artifact,并创建 GitHub Release。 diff --git a/docs/development/engineering/ble-recovery-compatibility.md b/docs/development/engineering/ble-recovery-compatibility.md deleted file mode 100644 index 911b9ff..0000000 --- a/docs/development/engineering/ble-recovery-compatibility.md +++ /dev/null @@ -1,70 +0,0 @@ -

- 简体中文 · English -

- -# Mini-Program BLE Firmware Compatibility - -This repository is a derivative-firmware template. Every application built from -it must remain installable by the AI Passport mini-program through the permanent -Recovery already provisioned by the official factory firmware. - -## How installation works - -The application does not implement the BLE flashing service. The user holds UP -while powering on for five seconds; the custom bootloader then starts the -factory-installed Recovery at `0x700000`. Recovery exposes the FFF0–FFF4 BLE -service, verifies the device, receives the application and resource sections, -protects device identity, commits a compatible partition table, and starts the -new application. - -The community artifact is therefore an input to Recovery, not a replacement for -Recovery. A device whose permanent Recovery was erased must first be restored -with the official USB recovery flow. - -## Mandatory contract - -Derivative projects must preserve all of the following: - -- ESP32-C3, 8 MB Flash, ESP-IDF 5.5.3. -- A merged ESP image starting at `0x0`, produced as - `build/FoloToy-AI-Passport-full.bin`. -- One main application image at `0x10000`, no larger than `0x300000` bytes. -- `cardid`: data/NVS at `0x356000`, size `0x4000`. -- `recovery`: app/test at `0x700000`, size `0x100000`. -- The bootloader hook under `bootloader_components/recovery_boot_hook/`, which - enters Recovery after the UP key is held for five seconds. -- A valid partition-table MD5 marker and no partition overlap with either - protected region. -- No device-specific `cardid` payload and no replacement Recovery payload in a - community artifact. - -Applications may add resource partitions, but the partitions must not overlap -the protected regions. Required resource partitions must be included in the -merged artifact rather than declared empty. - -## Enforced validation - -Run: - -```bash -./tools/validate.sh --firmware -``` - -The check builds in an isolated directory, creates the merged image, verifies -the bootloader/table/application offsets, parses the partition table, checks its -MD5 and protected ranges, enforces the 3 MB application limit, rejects protected -payload bytes, and confirms the Recovery boot hook is linked. CI runs the same -gate. Do not publish an artifact when this command fails. - -Upload only `build/FoloToy-AI-Passport-full.bin`; the similarly named app-only -`build/FoloToy-AI-Passport.bin` cannot pass mini-program compatibility checks. - -## Flashing safety during development - -Never run `idf.py erase-flash` on a provisioned device. It destroys both the -per-device identity and permanent Recovery. Prefer mini-program installation or -the segmented `idf.py flash` development command, which does not write an image -for the protected partitions. A raw single-file write from `0x0` is safe only -when its byte range ends before `cardid`; a merged artifact containing later -resource partitions spans the gap and must not be raw-flashed to a provisioned -device. diff --git a/docs/development/engineering/ble-recovery-compatibility.zh_CN.md b/docs/development/engineering/ble-recovery-compatibility.zh_CN.md deleted file mode 100644 index f6bfcae..0000000 --- a/docs/development/engineering/ble-recovery-compatibility.zh_CN.md +++ /dev/null @@ -1,59 +0,0 @@ -

- 简体中文 · English -

- -# 小程序 BLE 固件兼容规范 - -本仓库是二创固件模板。任何基于它开发的应用,都必须保持可由 AI Passport -小程序通过官方默认固件预装的永久 Recovery 安装。 - -## 安装原理 - -玩法应用本身不实现 BLE 刷机服务。用户关机后按住上键开机 5 秒,自定义 -bootloader 跳转到 `0x700000` 的工厂预装 Recovery。Recovery 提供 FFF0–FFF4 -BLE 服务,验证设备后接收应用与资源分区,保护设备身份,写入兼容分区表, -最后启动新应用。 - -因此,社区固件是 Recovery 的安装输入,不是 Recovery 的替代品。如果设备的永久 -Recovery 已被擦除,必须先走官网 USB 恢复流程。 - -## 必须保持的契约 - -二创项目必须同时保留: - -- ESP32-C3、8 MB Flash、ESP-IDF 5.5.3。 -- 从 `0x0` 开始的合并 ESP 镜像,固定产物为 - `build/FoloToy-AI-Passport-full.bin`。 -- 位于 `0x10000` 的主应用镜像,不得超过 `0x300000` 字节。 -- `cardid`:data/NVS,地址 `0x356000`,大小 `0x4000`。 -- `recovery`:app/test,地址 `0x700000`,大小 `0x100000`。 -- `bootloader_components/recovery_boot_hook/` 下的 bootloader hook,上键持续 - 5 秒后进入 Recovery。 -- 有效的分区表 MD5,且所有分区不得与两个保护区重叠。 -- 社区产物不得包含任何单台设备的 `cardid` 数据,也不得携带替换 Recovery - 的数据。 - -应用可以新增资源分区,但不得覆盖保护区。必需资源分区必须打入合并产物, -不得只在分区表声明一个空分区。 - -## 强制验证 - -执行: - -```bash -./tools/validate.sh --firmware -``` - -脚本会在隔离目录构建,生成合并镜像,验证 bootloader、分区表与应用的偏移, -解析分区表并检查 MD5、保护范围和 3 MB 应用上限,拒绝保护分区数据,同时 -确认 Recovery boot hook 已链接。CI 执行同一门禁。该命令失败时不得发布。 - -只上传 `build/FoloToy-AI-Passport-full.bin`。名称相近的应用单镜像 -`build/FoloToy-AI-Passport.bin` 无法通过小程序兼容检测。 - -## 开发烧录安全 - -已写入设备身份的机器严禁执行 `idf.py erase-flash`,否则会同时破坏单机身份与永久 -Recovery。优先使用小程序安装,或使用不会写保护分区镜像的分段 `idf.py flash`。 -只有单文件的字节范围在 `cardid` 之前结束时,从 `0x0` 直接写入才是安全的; -若合并产物包含位于 `cardid` 之后的资源分区,就不得对已写身份的设备做单文件直刷。 diff --git a/docs/development/engineering/build-and-test.md b/docs/development/engineering/build-and-test.md index 9ffbe2a..3e34224 100644 --- a/docs/development/engineering/build-and-test.md +++ b/docs/development/engineering/build-and-test.md @@ -10,8 +10,7 @@ the [environment bootstrap](environment-setup.md) first. > Prefer `./tools/validate.sh --firmware` for firmware builds and flash its > verified `build/FoloToy-AI-Passport-full.bin` at offset `0x0` only when the > target is blank or the merged byte range ends before protected `cardid`. -> On a provisioned device, prefer mini-program install or segmented -> `idf.py flash`. Treat +> On a provisioned device, use segmented `idf.py flash`. Treat > `idf.py build` and `idf.py flash` as incremental development commands, not the > default delivery path. @@ -32,7 +31,7 @@ regenerated. The tracked `dependencies.lock` pins Managed Component resolution. After changing an `idf_component.yml`, regenerate the lock with ESP-IDF 5.5.3, review version changes, and commit it with the manifest. An ordinary build must not leave an unexplained lock-file diff. -Firmware validation uses a fresh temporary build directory and an isolated `sdkconfig` generated from the tracked defaults. It does not consume or overwrite a developer's root `sdkconfig`, and it copies only the verified merged image to `build/FoloToy-AI-Passport-full.bin`. The gate also enforces the [mini-program BLE compatibility contract](ble-recovery-compatibility.md): protected partition addresses, application size, partition-table MD5, absence of protected payload data, and the Recovery bootloader hook. +Firmware validation uses a fresh temporary build directory and an isolated `sdkconfig` generated from the tracked defaults. It does not consume or overwrite a developer's root `sdkconfig`, and it copies only the verified merged image to `build/FoloToy-AI-Passport-full.bin`. The gate also enforces the [protected Flash layout](protected-flash-layout.md): protected partition addresses, application size, partition-table MD5, and absence of protected payload data. The baseline also has a hardware-independent logic test: @@ -47,7 +46,7 @@ Use the unified validation entry point: ```bash ./tools/validate.sh --static # repository checks, workflows, links, secrets, host tests -./tools/validate.sh --firmware # build, merge-bin, offsets, and BLE compatibility +./tools/validate.sh --firmware # build, merge-bin, offsets, and protected layout ./tools/validate.sh # complete gate; requires an activated ESP-IDF environment ``` @@ -56,5 +55,5 @@ CI calls the same script. Fix the shared script or environment if local and CI b Hardware-affecting changes must also run the applicable on-device checklist in the hardware guide. Report compilation separately from physical-device validation. Never upload the app-only `build/FoloToy-AI-Passport.bin` to the community. Only -the validated `build/FoloToy-AI-Passport-full.bin` contains the structure the -mini-program can inspect and transform safely. +the validated `build/FoloToy-AI-Passport-full.bin` contains the complete checked +firmware layout. diff --git a/docs/development/engineering/build-and-test.zh_CN.md b/docs/development/engineering/build-and-test.zh_CN.md index ad1eec1..5047f40 100644 --- a/docs/development/engineering/build-and-test.zh_CN.md +++ b/docs/development/engineering/build-and-test.zh_CN.md @@ -9,7 +9,7 @@ > 固件编译优先运行 `./tools/validate.sh --firmware`,烧录优先把验证通过的 > `build/FoloToy-AI-Passport-full.bin` 写入空白设备;对已有身份的设备,只有合并文件 -> 在保护区 `cardid` 之前结束时才可从 `0x0` 直刷,其余情况优先用小程序或分段 +> 在保护区 `cardid` 之前结束时才可从 `0x0` 直刷,其余情况使用分段 > `idf.py flash`。`idf.py build` 和 > `idf.py flash` 只作为增量开发命令,不作为默认交付方式。 @@ -29,7 +29,7 @@ target 或已跟踪 defaults 时,先保留有意的本地设置,再运行 仓库提交 `dependencies.lock` 以固定 ESP-IDF Managed Components 的解析结果。修改 `idf_component.yml` 后必须使用 ESP-IDF 5.5.3 重新生成锁文件、review 版本变化并与 manifest 一起提交;普通构建不应产生未提交的锁文件差异。 -固件门禁使用全新的临时构建目录,并从仓库 `sdkconfig.defaults` 生成隔离的 `sdkconfig`。它不会读取或覆盖开发者根目录的 `sdkconfig`,只把验证通过的合并镜像复制到 `build/FoloToy-AI-Passport-full.bin`。门禁同时强制检查[小程序 BLE 兼容契约](ble-recovery-compatibility.zh_CN.md):保护分区地址、应用大小、分区表 MD5、保护区数据不入包,以及 Recovery bootloader hook。 +固件门禁使用全新的临时构建目录,并从仓库 `sdkconfig.defaults` 生成隔离的 `sdkconfig`。它不会读取或覆盖开发者根目录的 `sdkconfig`,只把验证通过的合并镜像复制到 `build/FoloToy-AI-Passport-full.bin`。门禁同时强制检查[受保护的 Flash 布局](protected-flash-layout.zh_CN.md):保护分区地址、应用大小、分区表 MD5 以及保护区数据不入包。 当前基线含一个可独立运行的纯逻辑测试: @@ -44,7 +44,7 @@ cc -std=c11 -Wall -Wextra -Werror -Imain \ ```bash ./tools/validate.sh --static # 仓库一致性、workflow、文档链接、敏感信息、host tests -./tools/validate.sh --firmware # ESP-IDF build、merge-bin、偏移与 BLE 兼容校验 +./tools/validate.sh --firmware # ESP-IDF build、merge-bin、偏移与保护布局校验 ./tools/validate.sh # 完整验证 ``` @@ -53,4 +53,4 @@ cc -std=c11 -Wall -Wextra -Werror -Imain \ 涉及物理外设的改动必须在真机运行硬件指南验收清单,并把“编译通过”与“硬件验证通过”分开记录。 社区只能上传验证通过的 `build/FoloToy-AI-Passport-full.bin`,不得上传应用单镜像 -`build/FoloToy-AI-Passport.bin`,后者没有小程序可安全解析与转换的完整结构。 +`build/FoloToy-AI-Passport.bin`,后者不包含完整且经校验的固件布局。 diff --git a/docs/development/engineering/protected-flash-layout.md b/docs/development/engineering/protected-flash-layout.md new file mode 100644 index 0000000..7b9e53b --- /dev/null +++ b/docs/development/engineering/protected-flash-layout.md @@ -0,0 +1,61 @@ +

+ 简体中文 · English +

+ +# Protected Flash Layout + +This repository reserves factory-owned Flash regions so derivative firmware +does not overwrite device identity or the Recovery image. The template does +not provide a button-held bootloader entry into Recovery. + +## Mandatory layout + +Derivative projects must preserve all of the following: + +- ESP32-C3, 8 MB Flash, ESP-IDF 5.5.3. +- A merged ESP image starting at `0x0`, produced as + `build/FoloToy-AI-Passport-full.bin`. +- One main application image at `0x10000`, no larger than `0x300000` bytes. +- `cardid`: data/NVS at `0x356000`, size `0x4000`. +- `recovery`: app/test at `0x700000`, size `0x100000`. +- A valid partition-table MD5 marker and no partition overlap with either + protected region. +- No device-specific `cardid` payload and no replacement Recovery payload in a + community artifact. + +Applications may add resource partitions, but they must not overlap the +protected regions. Required resource partitions must be included in the merged +artifact rather than declared empty. + +## Recovery boundary + +The `recovery` partition remains reserved for the factory-owned image, but this +template contains no `recovery_boot_hook` and defines no function-key gesture +for entering it. Preserving the partition layout alone is not a claim that a +derivative image can be installed or recovered through the mini-program. + +## Enforced validation + +Run: + +```bash +./tools/validate.sh --firmware +``` + +The check builds in an isolated directory, creates the merged image, verifies +the bootloader/table/application offsets, parses the partition table, checks its +MD5 and protected ranges, enforces the 3 MB application limit, and rejects +protected payload bytes. CI runs the same gate. Do not publish an artifact when +this command fails. + +Upload only `build/FoloToy-AI-Passport-full.bin`; the similarly named app-only +`build/FoloToy-AI-Passport.bin` does not contain the complete validated layout. + +## Flashing safety during development + +Never run `idf.py erase-flash` on a provisioned device. It destroys both the +per-device identity and factory-owned Recovery image. Prefer segmented +`idf.py flash`, which does not write an image for the protected partitions. A +raw single-file write from `0x0` is safe only when its byte range ends before +`cardid`; a merged artifact containing later resource partitions spans the gap +and must not be raw-flashed to a provisioned device. diff --git a/docs/development/engineering/protected-flash-layout.zh_CN.md b/docs/development/engineering/protected-flash-layout.zh_CN.md new file mode 100644 index 0000000..cad304d --- /dev/null +++ b/docs/development/engineering/protected-flash-layout.zh_CN.md @@ -0,0 +1,55 @@ +

+ 简体中文 · English +

+ +# 受保护的 Flash 布局 + +本仓库保留工厂所有的 Flash 区域,避免二创固件覆盖设备身份或 +Recovery 镜像。模板不再提供按键持续按住后进入 Recovery 的 bootloader +入口。 + +## 必须保持的布局 + +二创项目必须同时保留: + +- ESP32-C3、8 MB Flash、ESP-IDF 5.5.3。 +- 从 `0x0` 开始的合并 ESP 镜像,固定产物为 + `build/FoloToy-AI-Passport-full.bin`。 +- 位于 `0x10000` 的主应用镜像,不得超过 `0x300000` 字节。 +- `cardid`:data/NVS,地址 `0x356000`,大小 `0x4000`。 +- `recovery`:app/test,地址 `0x700000`,大小 `0x100000`。 +- 有效的分区表 MD5,且所有分区不得与两个保护区重叠。 +- 社区产物不得包含任何单台设备的 `cardid` 数据,也不得携带替换 + Recovery 的数据。 + +应用可以新增资源分区,但不得覆盖保护区。必需的资源分区必须打入 +合并产物,不得只在分区表中声明空分区。 + +## Recovery 边界 + +`recovery` 分区仍为工厂镜像保留,但本模板不再包含 +`recovery_boot_hook`,也不定义任何功能键进入 Recovery 的操作。 +只保留分区布局,不代表二创镜像仍可通过小程序安装或恢复。 + +## 强制验证 + +执行: + +```bash +./tools/validate.sh --firmware +``` + +脚本会在隔离目录构建,生成合并镜像,验证 bootloader、分区表与应用的 +偏移,解析分区表并检查 MD5、保护范围和 3 MB 应用上限,同时拒绝保护 +分区数据入包。CI 执行同一门禁。该命令失败时不得发布。 + +只上传 `build/FoloToy-AI-Passport-full.bin`。名称相近的应用单镜像 +`build/FoloToy-AI-Passport.bin` 不包含经完整验证的布局。 + +## 开发烧录安全 + +已写入设备身份的机器严禁执行 `idf.py erase-flash`,否则会同时破坏单机身份与 +工厂 Recovery 镜像。优先使用不会写保护分区镜像的分段 `idf.py flash`。 +只有单文件的字节范围在 `cardid` 之前结束时,从 `0x0` 直接写入才安全; +若合并产物包含位于 `cardid` 之后的资源分区,就不得对已写身份的设备做 +单文件直刷。 diff --git a/docs/development/release/publish-to-community.md b/docs/development/release/publish-to-community.md index c6e5600..bf91a5f 100644 --- a/docs/development/release/publish-to-community.md +++ b/docs/development/release/publish-to-community.md @@ -29,7 +29,7 @@ The skill's `SKILL.md` defines the exact workflow: inspect the project, prepare - **Firmware**: the single merged ESP image `build/FoloToy-AI-Passport-full.bin`. It must pass `./tools/validate.sh --firmware`, including the - [mini-program BLE compatibility contract](../engineering/ble-recovery-compatibility.md). + [protected Flash layout](../engineering/protected-flash-layout.md). Never substitute the app-only `.bin` produced by `idf.py build`. - **Cover**: a representative JPEG / PNG / WebP image (<= 10 MiB). - **Source**: the public HTTPS Git page for the firmware repository — GitHub, Gitee, GitLab, Codeberg, or another publicly reachable HTTPS Git repository page. A fork owner publishes from their fork's source page, resolved from `git remote -v`. @@ -40,7 +40,7 @@ The skill's `SKILL.md` defines the exact workflow: inspect the project, prepare - Validation, drafting, and preview that is not confirmed by the author does **not** authorize upload. - Authorization credentials are never requested, received, or stored by the assistant. The creator registers or signs in on the official site and approves the displayed code; the assistant never handles their password. - Never retry a rejected upload automatically. Report the server response and resolve the cause with the creator first. -- Do not weaken, bypass, or remove the BLE compatibility gate merely to make a +- Do not weaken, bypass, or remove the protected-layout gate merely to make a community submission pass. Fix the image layout or build packaging instead. ## How the assistant installs the skill diff --git a/docs/development/release/publish-to-community.zh_CN.md b/docs/development/release/publish-to-community.zh_CN.md index 2ef7e6d..3c6b8ba 100644 --- a/docs/development/release/publish-to-community.zh_CN.md +++ b/docs/development/release/publish-to-community.zh_CN.md @@ -32,7 +32,7 @@ skill 的 `SKILL.md` 定义了精确流程:检查项目、准备中英文标 ## 你需要提供给助手的东西 - **固件**:固定使用单个合并镜像 `build/FoloToy-AI-Passport-full.bin`, - 且必须通过 `./tools/validate.sh --firmware` 与[小程序 BLE 兼容契约](../engineering/ble-recovery-compatibility.zh_CN.md)。 + 且必须通过 `./tools/validate.sh --firmware` 与[受保护的 Flash 布局](../engineering/protected-flash-layout.zh_CN.md)。 不得用 `idf.py build` 生成的应用单镜像替代。 - **封面**:一张代表产品的 JPEG / PNG / WebP 图(≤ 10 MiB)。 - **源码**:固件仓库的公开 HTTPS Git 项目页——GitHub、Gitee、GitLab、Codeberg 或其它公开可达的 HTTPS Git 仓库页。fork 所有者从其 fork 的来源页发布,从 `git remote -v` 解析。 @@ -43,7 +43,7 @@ skill 的 `SKILL.md` 定义了精确流程:检查项目、准备中英文标 - 未经作者确认的验证、起草与预览**不授权上传**。 - 助手绝不索取、接收或存储授权凭证。由创作者在官方站点注册或登录并批准显示的代码;助手不接触其密码。 - 不自动重试被拒的上传。先把服务端响应展示给创作者,查清原因再处理。 -- 不得为了让社区提交通过而弱化、绕过或删除 BLE 兼容门禁;应修复镜像布局或打包流程。 +- 不得为了让社区提交通过而弱化、绕过或删除保护布局门禁;应修复镜像布局或打包流程。 ## 助手如何安装该 skill diff --git a/docs/hardware-design/AI_HARDWARE_DEVELOPMENT_GUIDE.md b/docs/hardware-design/AI_HARDWARE_DEVELOPMENT_GUIDE.md index 57ce773..18a9a46 100644 --- a/docs/hardware-design/AI_HARDWARE_DEVELOPMENT_GUIDE.md +++ b/docs/hardware-design/AI_HARDWARE_DEVELOPMENT_GUIDE.md @@ -167,11 +167,11 @@ Accurate production SOC requires the cell parameters, CW2017 datasheet/vendor pr ## 10. Flash, console, and memory -The current product and firmware baseline uses 8 MB Flash. `sdkconfig.defaults` fixes the image to 8 MB and disables automatic flash-size header rewriting. `partitions.csv` defines 24 KB NVS, 4 KB PHY data, one 3 MB factory application, protected `cardid` at `0x356000`, and permanent Recovery at `0x700000`. This is not an ESP-IDF dual-slot OTA layout: the factory-installed Recovery performs BLE installation and must remain at its fixed address. The bootloader enters it when UP/GPIO0 is held for five seconds. A detected non-8-MB device does not match this baseline; identify the board and flash part before changing the project default. +The current product and firmware baseline uses 8 MB Flash. `sdkconfig.defaults` fixes the image to 8 MB and disables automatic flash-size header rewriting. `partitions.csv` defines 24 KB NVS, 4 KB PHY data, one 3 MB factory application, protected `cardid` at `0x356000`, and factory-owned Recovery at `0x700000`. This is not an ESP-IDF dual-slot OTA layout. Recovery remains reserved at its fixed address, but this firmware provides no function-key bootloader entry into it. A detected non-8-MB device does not match this baseline; identify the board and flash part before changing the project default. Do not erase a provisioned device or move/overlap the protected partitions. Community firmware contains neither device identity nor a replacement Recovery -payload. See the [BLE compatibility contract](../development/engineering/ble-recovery-compatibility.md). +payload. See the [protected Flash layout](../development/engineering/protected-flash-layout.md). The console is USB Serial/JTAG. Do not switch to the UART0 default output without resolving its GPIO21 conflict with the backlight. diff --git a/docs/hardware-design/AI_HARDWARE_DEVELOPMENT_GUIDE.zh_CN.md b/docs/hardware-design/AI_HARDWARE_DEVELOPMENT_GUIDE.zh_CN.md index be8bc7d..2a78371 100644 --- a/docs/hardware-design/AI_HARDWARE_DEVELOPMENT_GUIDE.zh_CN.md +++ b/docs/hardware-design/AI_HARDWARE_DEVELOPMENT_GUIDE.zh_CN.md @@ -226,10 +226,10 @@ SOC 准确度取决于电芯与 profile 的匹配程度。本驱动给出的是 ## 10. Flash、控制台和资源预算 -当前产品与固件基线使用 8 MB Flash。`sdkconfig.defaults` 固定使用 8 MB Flash 镜像配置,并关闭 `CONFIG_ESPTOOLPY_HEADER_FLASHSIZE_UPDATE`(不按探测容量回写镜像头,便于 `idf.py merge-bin`);`partitions.csv` 提供 24 KB NVS、4 KB PHY data、3 MB factory app、位于 `0x356000` 的保护 `cardid`,以及位于 `0x700000` 的永久 Recovery。这不是 ESP-IDF 双槽 OTA 布局;工厂预装 Recovery 负责 BLE 安装,且必须保持固定地址。开机持续按住上键/GPIO0 5 秒时,bootloader 会进入 Recovery。若实机探测结果不是 8 MB,则该设备不符合当前基线;修改项目默认值前应先确认板卡和 Flash 料号。 +当前产品与固件基线使用 8 MB Flash。`sdkconfig.defaults` 固定使用 8 MB Flash 镜像配置,并关闭 `CONFIG_ESPTOOLPY_HEADER_FLASHSIZE_UPDATE`(不按探测容量回写镜像头,便于 `idf.py merge-bin`);`partitions.csv` 提供 24 KB NVS、4 KB PHY data、3 MB factory app、位于 `0x356000` 的保护 `cardid`,以及位于 `0x700000` 的工厂 Recovery。这不是 ESP-IDF 双槽 OTA 布局。Recovery 仍保留在固定地址,但当前固件不提供任何功能键进入 Recovery 的 bootloader 入口。若实机探测结果不是 8 MB,则该设备不符合当前基线;修改项目默认值前应先确认板卡和 Flash 料号。 不得擦除已写身份的设备,也不得移动或覆盖保护分区。社区固件既不包含单机身份, -也不携带替换 Recovery 的数据。详见 [BLE 兼容契约](../development/engineering/ble-recovery-compatibility.zh_CN.md)。 +也不携带替换 Recovery 的数据。详见[受保护的 Flash 布局](../development/engineering/protected-flash-layout.zh_CN.md)。 控制台固定为 USB Serial/JTAG,不使用 UART0 默认输出,因为其 TX GPIO21 与背光冲突。任何日志接口修改都必须同时检查引脚占用。 diff --git a/docs/hardware-design/specifications.md b/docs/hardware-design/specifications.md index 8169866..e0e5ce7 100644 --- a/docs/hardware-design/specifications.md +++ b/docs/hardware-design/specifications.md @@ -21,4 +21,4 @@ This page defines the user-facing product specifications. Firmware pin assignmen | Audio | Built-in microphone and speaker with ES8311 codec | | Charging | USB Type-C 2.0, 5 V input | | Battery | Built-in 520 mAh rechargeable lithium battery with CW2017 fuel gauge | -| Other | Device-specific QR fallback with recovery-firmware entry | +| Other | Device-specific QR fallback | diff --git a/docs/hardware-design/specifications.zh_CN.md b/docs/hardware-design/specifications.zh_CN.md index 93d2464..ba1c066 100644 --- a/docs/hardware-design/specifications.zh_CN.md +++ b/docs/hardware-design/specifications.zh_CN.md @@ -21,4 +21,4 @@ | 音频 | 内置麦克风和扬声器,使用 ES8311 codec | | 充电 | USB Type-C 2.0,5 V 输入 | | 电池 | 内置 520 mAh 可充电锂电池,使用 CW2017 电量计 | -| 其他 | 专属二维码 fallback,含恢复固件入口 | +| 其他 | 专属二维码 fallback | diff --git a/sdkconfig.defaults b/sdkconfig.defaults index b74e1d6..0cd8b96 100644 --- a/sdkconfig.defaults +++ b/sdkconfig.defaults @@ -7,21 +7,12 @@ CONFIG_IDF_TARGET="esp32c3" CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y # 固定 8MB 镜像头,关闭 detect,便于 idf.py merge-bin。 CONFIG_ESPTOOLPY_HEADER_FLASHSIZE_UPDATE=n -# 3 MB 应用上限与小程序 BLE Recovery 安装器保持一致。分区表 -# 还固定保留 cardid@0x356000 与 recovery@0x700000,二创不得改动。 +# 3 MB 应用上限与固定保护分区保持一致。分区表保留 +# cardid@0x356000 与 recovery@0x700000,二创不得改动。 CONFIG_PARTITION_TABLE_CUSTOM=y CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" -# 开机持续按住上键(GPIO0)5 秒,由自定义 bootloader 跳转到工厂 -# 预装的 0x700000 Recovery。这些选项为 bootloader 提供长按检测配置。 -CONFIG_BOOTLOADER_FACTORY_RESET=y -CONFIG_BOOTLOADER_NUM_PIN_FACTORY_RESET=0 -CONFIG_BOOTLOADER_FACTORY_RESET_PIN_LOW=y -CONFIG_BOOTLOADER_OTA_DATA_ERASE=y -CONFIG_BOOTLOADER_DATA_FACTORY_RESET="" -CONFIG_BOOTLOADER_HOLD_TIME_GPIO=5 - # --- 控制台:USB-Serial-JTAG(C3 原生 USB,GPIO18/19)--- # 不用 UART0:其默认 TX=GPIO21 与本板背光引脚冲突。 CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y diff --git a/tests/test_verify_firmware.py b/tests/test_verify_firmware.py index 077003d..e4e81af 100644 --- a/tests/test_verify_firmware.py +++ b/tests/test_verify_firmware.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -"""Host tests for the mini-program firmware compatibility parser.""" +"""Host tests for the protected firmware-layout parser.""" from __future__ import annotations @@ -7,6 +7,7 @@ import hashlib import importlib.util import struct import sys +import tempfile import unittest from pathlib import Path @@ -62,5 +63,20 @@ class PartitionParserTest(unittest.TestCase): VERIFY.parse_partition_table(bytes(raw)) +class ProtectedLayoutTest(unittest.TestCase): + def test_layout_verification_does_not_require_bootloader_hook(self) -> None: + merged = bytearray(b"\xff" * (0x10000 + 1)) + merged[ + VERIFY.PARTITION_TABLE_OFFSET : + VERIFY.PARTITION_TABLE_OFFSET + VERIFY.PARTITION_TABLE_SIZE + ] = sample_table() + merged[0x10000] = 0xE9 + + with tempfile.TemporaryDirectory() as directory: + build_dir = Path(directory) + (build_dir / "FoloToy-AI-Passport.bin").write_bytes(b"\xe9") + VERIFY.verify_protected_layout(bytes(merged), build_dir) + + if __name__ == "__main__": unittest.main() diff --git a/tools/verify_firmware.py b/tools/verify_firmware.py index 082b741..e4cee4c 100755 --- a/tools/verify_firmware.py +++ b/tools/verify_firmware.py @@ -25,7 +25,6 @@ CARDID_SIZE = 0x4000 RECOVERY_OFFSET = 0x700000 RECOVERY_SIZE = 0x100000 ENTRY = struct.Struct(" tuple[list[Partition], bool]: return partitions, found_md5 -def verify_recovery_contract(merged: bytes, build_dir: Path) -> None: - """Enforce the artifact/layout contract used by mini-program BLE install.""" +def verify_protected_layout(merged: bytes, build_dir: Path) -> None: + """Enforce the protected partition and merged-artifact layout.""" table = merged[ PARTITION_TABLE_OFFSET : PARTITION_TABLE_OFFSET + PARTITION_TABLE_SIZE ] @@ -105,7 +104,7 @@ def verify_recovery_contract(merged: bytes, build_dir: Path) -> None: app_path = build_dir / "FoloToy-AI-Passport.bin" app_size = app_path.stat().st_size if app_size > APP_MAX_SIZE: - raise ValueError(f"application is {app_size} bytes; BLE limit is {APP_MAX_SIZE}") + raise ValueError(f"application is {app_size} bytes; limit is {APP_MAX_SIZE}") if len(merged) <= 0x10000 or merged[0x10000] != 0xE9: raise ValueError("merged artifact has no ESP application image at 0x10000") @@ -120,11 +119,7 @@ def verify_recovery_contract(merged: bytes, build_dir: Path) -> None: if any(byte != 0xFF for byte in payload): raise ValueError(f"merged artifact contains forbidden {label} payload bytes") - bootloader = (build_dir / "bootloader" / "bootloader.bin").read_bytes() - if RECOVERY_BOOT_MARKER not in bootloader: - raise ValueError("bootloader is missing the 5-second UP Recovery hook") - - print(f"Mini-program BLE contract: PASS (app {app_size} / {APP_MAX_SIZE} bytes)") + print(f"Protected firmware layout: PASS (app {app_size} / {APP_MAX_SIZE} bytes)") def main() -> int: @@ -158,7 +153,7 @@ def main() -> int: return 1 try: - verify_recovery_contract(merged, build_dir) + verify_protected_layout(merged, build_dir) except (OSError, UnicodeDecodeError, ValueError) as error: print(f"ERROR: {error}", file=sys.stderr) return 1