From 7261efebe1fc767c68b36d2271142e58c1140560 Mon Sep 17 00:00:00 2001 From: DrDavidDa Date: Wed, 2 Sep 2026 14:39:27 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20M5Burner=E5=85=A8=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8F=91=E5=B8=83=E6=B5=81=E6=B0=B4=E7=BA=BF(=E9=80=86?= =?UTF-8?q?=E5=90=91=E5=AE=98=E6=96=B9=E5=AE=A2=E6=88=B7=E7=AB=AFAPI)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - publish_m5burner.py: 登录uiflow2→multipart上传→设公开→取ShareCode 全流程自动化 - merge_firmware_image.py: 离线合成16MB整片镜像(bootloader+partitions+app+voice_data@0xC10000) - NVS/otadata不写入(首启自动格式化), 镜像内零个人配置, 泄露扫描通过 - 凭据走本地m5_credentials.txt(.gitignore已排除) Co-Authored-By: Claude --- .gitignore | 5 ++ merge_firmware_image.py | 52 +++++++++++++ publish_m5burner.py | 168 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 225 insertions(+) create mode 100644 merge_firmware_image.py create mode 100644 publish_m5burner.py diff --git a/.gitignore b/.gitignore index 2233542..10ba59b 100644 --- a/.gitignore +++ b/.gitignore @@ -9,9 +9,14 @@ sf_api_key.txt zhipu_token.txt wifi_extra.txt +m5_credentials.txt *.token *_key.txt +# ===== M5Burner 发布镜像(16MB 构建产物不入库)===== +build_voice_data.bin +m5burner_image.bin + # ===== 开发诊断/测试脚本(本地保留,不进仓库)===== diag*.py test_*.py diff --git a/merge_firmware_image.py b/merge_firmware_image.py new file mode 100644 index 0000000..7bc6451 --- /dev/null +++ b/merge_firmware_image.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# 合成 M5Burner 用的 16MB 整片 flash 镜像(与 M5Burner「导出固件」产物等价) +# 布局 (tts_16MB.csv): +# 0x0 bootloader.bin (pio build 产物) +# 0x8000 partitions.bin (pio build 产物) +# 0x10000 firmware.bin (pio build 产物 app0) +# 0xC10000 voice_data (build_voice_data.bin,从设备实读的 TTS 模型) +# NVS/otadata 不写入(空→首次启动自动格式化),确保无任何个人配置泄露。 +# 用法: python merge_firmware_image.py +import subprocess, os, sys + +HERE = os.path.dirname(os.path.abspath(__file__)) +BUILD = os.path.join(HERE, '.pio', 'build', 'm5stack-papercolor') +VOICE = os.path.join(HERE, 'build_voice_data.bin') +OUT = os.path.join(HERE, 'm5burner_image.bin') +FLASH_SIZE = 16 * 1024 * 1024 + + +def check(path, label): + if not os.path.exists(path): + print('[FAIL] 缺少 %s: %s' % (label, path)) + sys.exit(1) + + +def main(): + bootloader = os.path.join(BUILD, 'bootloader.bin') + partitions = os.path.join(BUILD, 'partitions.bin') + firmware = os.path.join(BUILD, 'firmware.bin') + for p, l in [(bootloader, 'bootloader'), (partitions, 'partitions'), + (firmware, 'firmware(先 pio run -j 1)'), (VOICE, 'voice_data(先从设备读取)')]: + check(p, l) + + # 先铺 0xFF 底板,再按偏移写入各段 + img = bytearray([0xFF]) * FLASH_SIZE + + def put(path, offset): + data = open(path, 'rb').read() + assert offset + len(data) <= FLASH_SIZE, '%s 越界' % path + img[offset:offset + len(data)] = data + print('[OK] %-14s %8d B @ 0x%06X' % (os.path.basename(path), len(data), offset)) + + put(bootloader, 0x0) + put(partitions, 0x8000) + put(firmware, 0x10000) + put(VOICE, 0xC10000) + + open(OUT, 'wb').write(bytes(img)) + print('[DONE] %s (%.1f MB)' % (OUT, os.path.getsize(OUT) / 1048576)) + + +if __name__ == '__main__': + main() diff --git a/publish_m5burner.py b/publish_m5burner.py new file mode 100644 index 0000000..d8759fd --- /dev/null +++ b/publish_m5burner.py @@ -0,0 +1,168 @@ +# -*- coding: utf-8 -*- +# 一键发布固件到 M5Burner(全自动:登录→上传→公开→Share Code) +# 逆向自 M5Burner v3 客户端(packages/view main.js + app.asar packages/auth.js): +# 登录: POST https://uiflow2.m5stack.com/api/v1/account/login {email,password} +# → Set-Cookie m5_auth_token=(即 ssoToken)+ body.data.username +# 发布: POST http://m5burner-api.m5stack.com/api/admin/firmware +# multipart: name/description/category/author/version/github/cover/firmware +# header: m5_auth_token= +# 公开: PUT {API}/api/admin/firmware/{fid}/publish/{version}/1 +# 分享码: POST {API}/api/admin/firmware/share/{fid}/{version} +# 用法: +# 1. 在 m5_credentials.txt 写两行:第1行邮箱 第2行密码(已被 .gitignore 排除) +# 2. python publish_m5burner.py +# 镜像合成(如尚未生成): +# python merge_firmware_image.py +import requests, sys, os, json + +UIFLOW_HOST = 'https://uiflow2.m5stack.com' +API = 'http://m5burner-api.m5stack.com' +HERE = os.path.dirname(os.path.abspath(__file__)) +IMAGE = os.path.join(HERE, 'm5burner_image.bin') +COVER = os.path.join(HERE, 'docs', 'images', 'standby.jpg') +CREDS = os.path.join(HERE, 'm5_credentials.txt') + +NAME = 'eInk Desk Terminal' +VERSION = 'v1.0.0' +CATEGORY = 'paper' # M5Burner 官方 PaperColor 类别 +GITHUB = 'https://github.com/DrDavidDa/eInk-Desk-Terminal' +DESCRIPTION = ('Full-featured eInk desk study terminal for M5Stack PaperColor ' + '(ESP32-S3 + 4" Spectra 6 full-color E-Ink). 7 pages: lunar calendar ' + '+ weather, tech news RSS, Anki-style flash cards with spaced repetition, ' + 'Zhipu CodingPlan quota dashboard, voice memo with offline Chinese TTS, ' + 'environment dashboard, QR viewer. Offline Chinese TTS + global voice ' + 'assistant "Xiaocai" (long-press C). Ultra-low-power standby ~2mA. ' + 'First boot: write WiFi config to SD /config.ini (see GitHub README).') + + +def read_creds(): + if not os.path.exists(CREDS): + print('[FAIL] 缺少 %s(第1行邮箱,第2行密码)' % CREDS) + sys.exit(1) + lines = [l.strip() for l in open(CREDS, encoding='utf-8').read().splitlines() if l.strip()] + if len(lines) < 2: + print('[FAIL] m5_credentials.txt 需两行:邮箱 / 密码') + sys.exit(1) + return lines[0], lines[1] + + +def login(email, password): + r = requests.post(UIFLOW_HOST + '/api/v1/account/login', + json={'email': email, 'password': password}, timeout=30) + if r.status_code != 200: + print('[FAIL] 登录 HTTP %d: %s' % (r.status_code, r.text[:200])) + sys.exit(1) + token = r.cookies.get('m5_auth_token') + if not token: + for c in r.headers.get('set-cookie', '').split(';'): + if 'm5_auth_token=' in c: + token = c.split('m5_auth_token=')[1].strip() + break + if not token: + print('[FAIL] 登录成功但未返回 m5_auth_token:', r.text[:300]) + sys.exit(1) + username = '' + try: + username = r.json()['data']['username'] + except Exception: + pass + print('[OK] 登录成功 user=%s token=%s...%s' % (username, token[:8], token[-6:])) + return token, username + + +def publish(token, username): + if not os.path.exists(IMAGE): + print('[FAIL] 缺少镜像 %s,先运行 python merge_firmware_image.py' % IMAGE) + sys.exit(1) + data = { + 'name': NAME, + 'description': DESCRIPTION, + 'category': CATEGORY, + 'author': username or 'DrDavidDa', + 'version': VERSION, + 'github': GITHUB, + } + files = { + 'cover': ('cover.jpg', open(COVER, 'rb').read(), 'image/jpeg'), + 'firmware': ('firmware.bin', open(IMAGE, 'rb').read(), 'application/octet-stream'), + } + print('[..] 上传 16MB 镜像到 %s ...' % API) + r = requests.post(API + '/api/admin/firmware', data=data, files=files, + headers={'m5_auth_token': token}, timeout=600) + print('[..] HTTP %d' % r.status_code) + try: + print(json.dumps(r.json(), ensure_ascii=False)[:800]) + return r.json() + except Exception: + print(r.text[:800]) + return None + + +def get_own(token): + r = requests.get(API + '/api/admin/firmware', + headers={'m5_auth_token': token}, timeout=30) + try: + data = r.json() + except Exception: + print(r.text[:500]) + return None + # 兼容裸列表 / {data:[...]} / {data:{list:[...]}} 三种包法 + if isinstance(data, list): + return data + if isinstance(data, dict): + inner = data.get('data', data) + if isinstance(inner, list): + return inner + if isinstance(inner, dict) and isinstance(inner.get('list'), list): + return inner['list'] + return data + + +def set_public(token, fid, version): + r = requests.put(API + '/api/admin/firmware/%s/publish/%s/1' % (fid, version), + json={}, headers={'m5_auth_token': token}, timeout=30) + print('[%s] 公开 HTTP %d %s' % ('OK' if r.status_code == 200 else '??', r.status_code, r.text[:200])) + + +def share_code(token, fid, version): + r = requests.post(API + '/api/admin/firmware/share/%s/%s' % (fid, version), + json={}, headers={'m5_auth_token': token}, timeout=30) + print('[%s] ShareCode HTTP %d: %s' % ('OK' if r.status_code == 200 else '??', r.status_code, r.text[:300])) + return r.text + + +def main(): + email, password = read_creds() + token, username = login(email, password) + + # 已存在则跳过重复上传(按名称在"我的固件"里查) + own = get_own(token) + fid = None + if isinstance(own, list): + for item in own: + if item.get('name') == NAME: + fid = item.get('fid') or item.get('_id') + print('[OK] 固件已存在 fid=%s(跳过上传)' % fid) + break + else: + print('[??] 我的固件响应结构未知:', str(own)[:400]) + if not fid: + resp = publish(token, username) + own = get_own(token) + if isinstance(own, list): + for item in own: + if item.get('name') == NAME: + fid = item.get('fid') or item.get('_id') + print('[OK] 上传成功 fid=%s versions=%s' % (fid, item.get('versions'))) + break + if not fid: + print('[FAIL] 上传后在"我的固件"中未找到,手动核对响应:', str(resp)[:400]) + sys.exit(1) + + set_public(token, fid, VERSION) + share_code(token, fid, VERSION) + print('[DONE] 全流程完成:固件已发布并公开') + + +if __name__ == '__main__': + main() From a7f77464bb6bf31cfb2109de23fc3229aee1ff1c Mon Sep 17 00:00:00 2001 From: DrDavidDa Date: Wed, 2 Sep 2026 14:54:52 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20M5Burner=E6=AD=A3=E5=BC=8F=E4=B8=8A?= =?UTF-8?q?=E6=9E=B6=20+=20README=E6=96=B0=E5=A2=9E=E4=B8=80=E9=94=AE?= =?UTF-8?q?=E7=83=A7=E5=BD=95=E5=85=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - set_public 参数修正为版本内部文件名(逆向UI源码确认) - README 快速开始新增 M5Burner 一键烧录(搜索 eInk Desk Terminal / ShareCode) - 已上架 M5Burner 官方 paper 类别, 作者 DrDavid, 分享码 h7QZeGjpDZQ6e8vv Co-Authored-By: Claude --- README.md | 8 ++++++++ publish_m5burner.py | 22 ++++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2bd370f..3b89b28 100644 --- a/README.md +++ b/README.md @@ -195,6 +195,14 @@ flowchart LR | microSD 卡 | 存考点卡片、语音待办、二维码图 | | USB-C 数据线 | 烧录 + 串口(建议优质线材) | +### 方式 A:M5Burner 一键烧录(零环境,推荐) + +1. 下载 [M5Burner](https://m5stack.com/pages/m5burner) → 右上角登录 M5Stack 社区账号 +2. 左下角 **USER CUSTOM** → 搜索 **eInk Desk Terminal**(类别 paper · 作者 DrDavid)→ Burn +3. 或点 **Share Burn** 输入分享码:`h7QZeGjpDZQ6e8vv` + +> 首次使用需向设备 SD 卡写入 `/config.ini`(WiFi + token),见下方「配置」。 + ### 1. 环境 ```bash diff --git a/publish_m5burner.py b/publish_m5burner.py index d8759fd..a01b00c 100644 --- a/publish_m5burner.py +++ b/publish_m5burner.py @@ -118,8 +118,9 @@ def get_own(token): return data -def set_public(token, fid, version): - r = requests.put(API + '/api/admin/firmware/%s/publish/%s/1' % (fid, version), +def set_public(token, fid, file_hash): + # 注意:端点第2参数是 versionInfo.file(内部文件名hash.bin),不是版本字符串(逆向 UI 源码确认) + r = requests.put(API + '/api/admin/firmware/%s/publish/%s/1' % (fid, file_hash), json={}, headers={'m5_auth_token': token}, timeout=30) print('[%s] 公开 HTTP %d %s' % ('OK' if r.status_code == 200 else '??', r.status_code, r.text[:200])) @@ -159,8 +160,21 @@ def main(): print('[FAIL] 上传后在"我的固件"中未找到,手动核对响应:', str(resp)[:400]) sys.exit(1) - set_public(token, fid, VERSION) - share_code(token, fid, VERSION) + # 公开端点的第2参数是内部文件名(fid+file 定位具体版本),从"我的固件"里取最新版本 + own = get_own(token) + file_hash = None + if isinstance(own, list): + for item in own: + if (item.get('fid') or item.get('_id')) == fid: + vers = item.get('versions') or [] + if vers: + file_hash = vers[-1].get('file') + break + if not file_hash: + print('[FAIL] 未取到版本内部文件名') + sys.exit(1) + set_public(token, fid, file_hash) + share_code(token, fid, file_hash) print('[DONE] 全流程完成:固件已发布并公开')