Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 52 additions & 0 deletions merge_firmware_image.py
Original file line number Diff line number Diff line change
@@ -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()
182 changes: 182 additions & 0 deletions publish_m5burner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
# -*- 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=<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=<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, 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]))


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)

# 公开端点的第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] 全流程完成:固件已发布并公开')


if __name__ == '__main__':
main()
Loading