diff --git a/AGENTS.md b/AGENTS.md index 54d58a0..5d8ef72 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -9,10 +9,8 @@ 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 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 the protected Flash layout: the 3 MB application limit and `cardid` + at `0x356000` are mandatory template contracts. - 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`. diff --git a/AGENTS.zh_CN.md b/AGENTS.zh_CN.md index 1e2d5d1..3c068d6 100644 --- a/AGENTS.zh_CN.md +++ b/AGENTS.zh_CN.md @@ -9,9 +9,8 @@ ## 项目与安全基线 - 目标平台:ESP32-C3、8 MB Flash、无 PSRAM、ESP-IDF 5.5.3。 -- 必须保持受保护的 Flash 布局:3 MB 应用上限、`cardid@0x356000` - 与工厂所有的 `recovery@0x700000` 均为模板强制契约。模板不提供 - 任何功能键进入 Recovery 的 bootloader hook。 +- 必须保持受保护的 Flash 布局:3 MB 应用上限与 `cardid@0x356000` + 均为模板强制契约。 - 保留用户已有修改。先执行 `git status --short --branch`,不得覆盖或清理无关文件。 - 硬件事实优先级:产品规格与实测结果 → `components/bsp/include/bsp_pins.h` → BSP 头文件与实现 → 硬件指南 → README/demo。任务所需硬件细节未在这些来源中定义时,直接询问用户,不得猜测。 - 可复用板级逻辑放入 `components/bsp`;页面、状态机、动画和应用任务放入 `main`。 diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 231202f..95e3c7a 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -10,10 +10,9 @@ - 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. -- 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. +- Removed the obsolete app/test partition at `0x700000` and its related + bootloader, validation, and documentation requirements. The fixed protected + `cardid` partition and its CI checks remain unchanged. - 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 f3e682f..29c38c5 100644 --- a/docs/CHANGELOG.zh_CN.md +++ b/docs/CHANGELOG.zh_CN.md @@ -10,9 +10,8 @@ - 按功能域整理文档并采用双入口:根目录 `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` 文件与一处重复经验索引。所有交叉引用与文献链接已更新;未丢弃任何内容。 -- 保留固定的 `cardid`/Recovery 保护分区,以及 CI 对合并镜像结构、 - 分区表 MD5/范围、3 MB 应用上限和保护分区数据不入包的校验; - 移除功能键持续 5 秒进入 Recovery 的 bootloader hook。 +- 删除位于 `0x700000` 的旧 app/test 分区,以及相关的 bootloader、校验和 + 文档要求;固定的 `cardid` 保护分区及其 CI 校验保持不变。 - 规定多应用发布的 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 f3bed56..9dc9e6b 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 factory-owned Recovery regions. It does not provide a function-key bootloader entry into Recovery. +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 and fixed protected `cardid` storage. ### Capabilities outside the current contract @@ -104,7 +104,7 @@ tools/ Shared local/CI validation and firmware verification sc docs/ Project docs, changelog, engineering/contribution rules, and design references .github/ GitHub community files, PR template, issue forms, and CI workflows sdkconfig.defaults ESP32-C3, USB console, Flash, and LVGL defaults -partitions.csv App plus protected identity/Recovery layout +partitions.csv App plus protected identity layout dependencies.lock Reproducible ESP-IDF Managed Component resolution AGENTS.md Mandatory AI-agent entry point (paired with AGENTS.zh_CN.md) CLAUDE.md Claude Code pointer to AGENTS.md (paired Chinese version) diff --git a/docs/README.zh_CN.md b/docs/README.zh_CN.md index 4f74dea..8b33e62 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 区域。固件不提供任何功能键进入 Recovery 的 bootloader 入口。 +应用也可以使用 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 分区,并固定保留受保护的 `cardid` 存储区。 ### 不属于当前能力契约的事项 @@ -102,7 +102,7 @@ tools/ 本地与 CI 共用的验证及固件校验脚本 docs/ 项目说明、变更记录、工程/协作规范与设计参考 .github/ GitHub 社区文档、PR 模板、Issue Form 与 CI 工作流 sdkconfig.defaults ESP32-C3、USB console、Flash、LVGL 默认配置 -partitions.csv 应用与设备身份/Recovery 保护分区布局 +partitions.csv 应用与设备身份保护分区布局 dependencies.lock 可复现的 ESP-IDF Managed Component 解析结果 AGENTS.md AI agent 必读入口(与 AGENTS.zh_CN.md 配对) CLAUDE.md Claude Code 指向 AGENTS.md 的入口(含中文配对) diff --git a/docs/development/engineering/build-and-test.md b/docs/development/engineering/build-and-test.md index 3e34224..b6069bb 100644 --- a/docs/development/engineering/build-and-test.md +++ b/docs/development/engineering/build-and-test.md @@ -31,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 [protected Flash layout](protected-flash-layout.md): protected partition addresses, application size, partition-table MD5, and absence of protected payload data. +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): the protected `cardid` address, application size, partition-table MD5, and absence of device-specific identity data. The baseline also has a hardware-independent logic test: diff --git a/docs/development/engineering/build-and-test.zh_CN.md b/docs/development/engineering/build-and-test.zh_CN.md index 5047f40..aa3aafc 100644 --- a/docs/development/engineering/build-and-test.zh_CN.md +++ b/docs/development/engineering/build-and-test.zh_CN.md @@ -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`。门禁同时强制检查[受保护的 Flash 布局](protected-flash-layout.zh_CN.md):保护分区地址、应用大小、分区表 MD5 以及保护区数据不入包。 +固件门禁使用全新的临时构建目录,并从仓库 `sdkconfig.defaults` 生成隔离的 `sdkconfig`。它不会读取或覆盖开发者根目录的 `sdkconfig`,只把验证通过的合并镜像复制到 `build/FoloToy-AI-Passport-full.bin`。门禁同时强制检查[受保护的 Flash 布局](protected-flash-layout.zh_CN.md):受保护的 `cardid` 地址、应用大小、分区表 MD5 以及单机身份数据不入包。 当前基线含一个可独立运行的纯逻辑测试: diff --git a/docs/development/engineering/protected-flash-layout.md b/docs/development/engineering/protected-flash-layout.md index 7b9e53b..1eaf682 100644 --- a/docs/development/engineering/protected-flash-layout.md +++ b/docs/development/engineering/protected-flash-layout.md @@ -4,9 +4,8 @@ # 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. +This repository reserves the per-device identity region so derivative firmware +does not overwrite provisioned `cardid` data. ## Mandatory layout @@ -17,23 +16,14 @@ Derivative projects must preserve all of the following: `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. +- A valid partition-table MD5 marker and no partition overlap with the + protected `cardid` region. +- No device-specific `cardid` 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 +Applications may add resource partitions, but they must not overlap protected +`cardid`. 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: @@ -44,18 +34,18 @@ Run: 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. +MD5 and the protected `cardid` range, enforces the 3 MB application limit, and +rejects device-specific identity 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 +Never run `idf.py erase-flash` on a provisioned device. It destroys the +per-device identity. Prefer segmented `idf.py flash`, which does not write an +image for protected `cardid`. 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 index cad304d..fe2f8cd 100644 --- a/docs/development/engineering/protected-flash-layout.zh_CN.md +++ b/docs/development/engineering/protected-flash-layout.zh_CN.md @@ -4,9 +4,7 @@ # 受保护的 Flash 布局 -本仓库保留工厂所有的 Flash 区域,避免二创固件覆盖设备身份或 -Recovery 镜像。模板不再提供按键持续按住后进入 Recovery 的 bootloader -入口。 +本仓库保留单机身份区域,避免二创固件覆盖已写入的 `cardid` 数据。 ## 必须保持的布局 @@ -17,20 +15,12 @@ Recovery 镜像。模板不再提供按键持续按住后进入 Recovery 的 boo `build/FoloToy-AI-Passport-full.bin`。 - 位于 `0x10000` 的主应用镜像,不得超过 `0x300000` 字节。 - `cardid`:data/NVS,地址 `0x356000`,大小 `0x4000`。 -- `recovery`:app/test,地址 `0x700000`,大小 `0x100000`。 -- 有效的分区表 MD5,且所有分区不得与两个保护区重叠。 -- 社区产物不得包含任何单台设备的 `cardid` 数据,也不得携带替换 - Recovery 的数据。 +- 有效的分区表 MD5,且所有分区不得与受保护的 `cardid` 区域重叠。 +- 社区产物不得包含任何单台设备的 `cardid` 数据。 -应用可以新增资源分区,但不得覆盖保护区。必需的资源分区必须打入 +应用可以新增资源分区,但不得覆盖受保护的 `cardid`。必需的资源分区必须打入 合并产物,不得只在分区表中声明空分区。 -## Recovery 边界 - -`recovery` 分区仍为工厂镜像保留,但本模板不再包含 -`recovery_boot_hook`,也不定义任何功能键进入 Recovery 的操作。 -只保留分区布局,不代表二创镜像仍可通过小程序安装或恢复。 - ## 强制验证 执行: @@ -40,16 +30,16 @@ Recovery 镜像。模板不再提供按键持续按住后进入 Recovery 的 boo ``` 脚本会在隔离目录构建,生成合并镜像,验证 bootloader、分区表与应用的 -偏移,解析分区表并检查 MD5、保护范围和 3 MB 应用上限,同时拒绝保护 -分区数据入包。CI 执行同一门禁。该命令失败时不得发布。 +偏移,解析分区表并检查 MD5、受保护的 `cardid` 范围和 3 MB 应用上限, +同时拒绝单机身份数据入包。CI 执行同一门禁。该命令失败时不得发布。 只上传 `build/FoloToy-AI-Passport-full.bin`。名称相近的应用单镜像 `build/FoloToy-AI-Passport.bin` 不包含经完整验证的布局。 ## 开发烧录安全 -已写入设备身份的机器严禁执行 `idf.py erase-flash`,否则会同时破坏单机身份与 -工厂 Recovery 镜像。优先使用不会写保护分区镜像的分段 `idf.py flash`。 +已写入设备身份的机器严禁执行 `idf.py erase-flash`,否则会破坏单机身份。 +优先使用不会写入受保护 `cardid` 的分段 `idf.py flash`。 只有单文件的字节范围在 `cardid` 之前结束时,从 `0x0` 直接写入才安全; 若合并产物包含位于 `cardid` 之后的资源分区,就不得对已写身份的设备做 单文件直刷。 diff --git a/docs/hardware-design/AI_HARDWARE_DEVELOPMENT_GUIDE.md b/docs/hardware-design/AI_HARDWARE_DEVELOPMENT_GUIDE.md index 18a9a46..32bd40b 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 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. +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, and protected `cardid` at `0x356000`. This is not an ESP-IDF dual-slot OTA layout. 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 [protected Flash layout](../development/engineering/protected-flash-layout.md). +Do not erase a provisioned device or move/overlap protected `cardid`. +Community firmware contains no device identity 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 2a78371..8866067 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 仍保留在固定地址,但当前固件不提供任何功能键进入 Recovery 的 bootloader 入口。若实机探测结果不是 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`。这不是 ESP-IDF 双槽 OTA 布局。若实机探测结果不是 8 MB,则该设备不符合当前基线;修改项目默认值前应先确认板卡和 Flash 料号。 -不得擦除已写身份的设备,也不得移动或覆盖保护分区。社区固件既不包含单机身份, -也不携带替换 Recovery 的数据。详见[受保护的 Flash 布局](../development/engineering/protected-flash-layout.zh_CN.md)。 +不得擦除已写身份的设备,也不得移动或覆盖受保护的 `cardid`。社区固件不包含 +单机身份数据。详见[受保护的 Flash 布局](../development/engineering/protected-flash-layout.zh_CN.md)。 控制台固定为 USB Serial/JTAG,不使用 UART0 默认输出,因为其 TX GPIO21 与背光冲突。任何日志接口修改都必须同时检查引脚占用。 diff --git a/partitions.csv b/partitions.csv index d35f674..da606af 100644 --- a/partitions.csv +++ b/partitions.csv @@ -3,4 +3,3 @@ nvs, data, nvs, 0x9000, 0x6000, phy_init, data, phy, 0xf000, 0x1000, factory, app, factory, 0x10000, 0x300000, cardid, data, nvs, 0x356000, 0x4000, -recovery, app, test, 0x700000, 0x100000, diff --git a/sdkconfig.defaults b/sdkconfig.defaults index 0cd8b96..e3d392b 100644 --- a/sdkconfig.defaults +++ b/sdkconfig.defaults @@ -8,7 +8,7 @@ CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y # 固定 8MB 镜像头,关闭 detect,便于 idf.py merge-bin。 CONFIG_ESPTOOLPY_HEADER_FLASHSIZE_UPDATE=n # 3 MB 应用上限与固定保护分区保持一致。分区表保留 -# cardid@0x356000 与 recovery@0x700000,二创不得改动。 +# cardid@0x356000,二创不得移动或覆盖。 CONFIG_PARTITION_TABLE_CUSTOM=y CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" diff --git a/tests/test_verify_firmware.py b/tests/test_verify_firmware.py index e4e81af..ceee714 100644 --- a/tests/test_verify_firmware.py +++ b/tests/test_verify_firmware.py @@ -28,7 +28,6 @@ def sample_table() -> bytes: (1, 1, 0xF000, 0x1000, "phy_init"), (0, 0, 0x10000, 0x300000, "factory"), (1, 2, 0x356000, 0x4000, "cardid"), - (0, 0x20, 0x700000, 0x100000, "recovery"), ) raw = bytearray(b"\xff" * VERIFY.PARTITION_TABLE_SIZE) for index, (kind, subtype, offset, size, label) in enumerate(entries): @@ -53,8 +52,8 @@ class PartitionParserTest(unittest.TestCase): def test_parses_protected_layout_and_md5(self) -> None: partitions, found_md5 = VERIFY.parse_partition_table(sample_table()) self.assertTrue(found_md5) - self.assertEqual(partitions[-2].label, "cardid") - self.assertEqual(partitions[-1].offset, VERIFY.RECOVERY_OFFSET) + self.assertEqual(partitions[-1].label, "cardid") + self.assertEqual(partitions[-1].offset, VERIFY.CARDID_OFFSET) def test_rejects_bad_md5(self) -> None: raw = bytearray(sample_table()) @@ -64,7 +63,7 @@ class PartitionParserTest(unittest.TestCase): class ProtectedLayoutTest(unittest.TestCase): - def test_layout_verification_does_not_require_bootloader_hook(self) -> None: + def test_layout_verification_accepts_current_partition_table(self) -> None: merged = bytearray(b"\xff" * (0x10000 + 1)) merged[ VERIFY.PARTITION_TABLE_OFFSET : diff --git a/tools/verify_firmware.py b/tools/verify_firmware.py index e4cee4c..0297fb0 100755 --- a/tools/verify_firmware.py +++ b/tools/verify_firmware.py @@ -22,8 +22,6 @@ PARTITION_TABLE_SIZE = 0xC00 APP_MAX_SIZE = 0x300000 CARDID_OFFSET = 0x356000 CARDID_SIZE = 0x4000 -RECOVERY_OFFSET = 0x700000 -RECOVERY_SIZE = 0x100000 ENTRY = struct.Struct(" None: expected = { "factory": Partition(0, 0, 0x10000, APP_MAX_SIZE, "factory"), "cardid": Partition(1, 2, CARDID_OFFSET, CARDID_SIZE, "cardid"), - "recovery": Partition(0, 0x20, RECOVERY_OFFSET, RECOVERY_SIZE, "recovery"), } for label, wanted in expected.items(): if by_label.get(label) != wanted: @@ -98,8 +95,6 @@ def verify_protected_layout(merged: bytes, build_dir: Path) -> None: for item in partitions: if item.label != "cardid" and item.offset < CARDID_OFFSET + CARDID_SIZE and CARDID_OFFSET < item.end: raise ValueError(f"partition {item.label!r} overlaps protected cardid") - if item.label != "recovery" and item.offset < RECOVERY_OFFSET + RECOVERY_SIZE and RECOVERY_OFFSET < item.end: - raise ValueError(f"partition {item.label!r} overlaps permanent Recovery") app_path = build_dir / "FoloToy-AI-Passport.bin" app_size = app_path.stat().st_size @@ -109,15 +104,13 @@ def verify_protected_layout(merged: bytes, build_dir: Path) -> None: raise ValueError("merged artifact has no ESP application image at 0x10000") # A derivative may add resource partitions after cardid. The merged file is - # still acceptable only if protected regions contain padding, never a real - # device identity or a replacement Recovery payload. - for label, offset, size in ( - ("cardid", CARDID_OFFSET, CARDID_SIZE), - ("recovery", RECOVERY_OFFSET, RECOVERY_SIZE), - ): - payload = merged[offset : min(len(merged), offset + size)] - if any(byte != 0xFF for byte in payload): - raise ValueError(f"merged artifact contains forbidden {label} payload bytes") + # still acceptable only if the protected cardid region contains padding, + # never real device identity data. + payload = merged[ + CARDID_OFFSET : min(len(merged), CARDID_OFFSET + CARDID_SIZE) + ] + if any(byte != 0xFF for byte in payload): + raise ValueError("merged artifact contains forbidden cardid payload bytes") print(f"Protected firmware layout: PASS (app {app_size} / {APP_MAX_SIZE} bytes)")