mirror of
https://github.com/dikeckaan/mu300-linux.git
synced 2026-12-05 08:02:40 +00:00
Fix U30 Air LED reconciliation and bundle Chinese UI and updated diff tools
This commit is contained in:
1 parent
8cd3d82401
commit
dbd6bf1e2f
13 files changed
+275
-25
No files matched your search
@@ -0,0 +1,10 @@
|
||||
# MU300 系列更新说明(2026-10-26)
|
||||
|
||||
适用 MU300、F50、V50、U30 Air;提供 7.2.8 和 6.18.54 两种内核包。
|
||||
|
||||
- **内置中文界面**:补齐 LuCI 基础界面、防火墙和软件包管理的简体中文包,保留原有自动识别及用户手动选择的语言。
|
||||
- **U30 Air 灯控修复**:到期熄灯覆盖两颗 Wi-Fi 灯,避免状态记录缺失时漏灭;修正电池颜色更新被其他事件或并发回调提前确认的问题。保留原有充电呼吸、满电常亮和拔插倒计时,不增加轮询频率。
|
||||
- **Diff Studio 随包提供**:根目录包含 Windows、Apple Silicon 和 Python 入口,共用安装器后端;可另行导出仅包含工具的独立包。
|
||||
- **跨平台补丁导出修复**:Windows 生成的补丁包保留 Mac 更新程序、后端及动态库的执行权限。
|
||||
|
||||
本轮用户态修复复用已有配套内核与模块,更新工具按源码指纹重新构建。灯控已通过离线和隔离运行时回归,尚未进行本轮 U30 Air 实物灯效验证。
|
||||
@@ -96,3 +96,14 @@ python3 tools/build-release.py add-diff --workspace /home/kano/openwrt-build --p
|
||||
ZIP 流式处理,不解压完整 rootfs。新工具纳入原 desktop manifest 和 CRC/SHA256 校验,
|
||||
每个发布包仍只有一份 boot、一份 rootfs 和各平台一份后端;最终通过才发布新目录。
|
||||
旧包不覆盖,失败现场按既有 clean-staging 规则处理。
|
||||
|
||||
仅导出独立 Diff Studio(两个平台后端各一份,无 boot/rootfs/ADB):
|
||||
|
||||
```sh
|
||||
python3 tools/build-release.py run --workspace /home/kano/openwrt-build --label diff-standalone -- \
|
||||
python3 tools/package-diff-studio.py --from-release /absolute/path/to/verified-release.zip \
|
||||
--output-zip /absolute/repo/release/diff-studio/OpenWrt-Diff-Studio.zip
|
||||
```
|
||||
|
||||
工具文件逐项按发布包内 `diff-tool.json` 核验,保留 Mac App 签名内容和可执行权限,
|
||||
不解压固件、不重新编译;输出 ZIP 与 SHA256,已有目标不覆盖。
|
||||
@@ -0,0 +1,25 @@
|
||||
# U30 Air 熄灯遗漏与电池颜色更新(2026-10-26)
|
||||
|
||||
## 已确认的代码缺陷
|
||||
|
||||
- `mu300-led` 在任意命令退出时重新读取电池状态写入调度提示。若先在 49% 显示蓝灯,电量变为 50% 后执行 Wi-Fi 灯事件,提示会变成白灯,实际电池灯仍是蓝色。守护进程可能将未显示的新颜色当成已处理,跳过后续更新。
|
||||
- 灯效子进程退出时,`mu300-sysd` 记录的是此刻的输入。输入在子进程工作期间发生变化时,可能把新输入提前确认。旧的跳过条件没有核对控制器实际处理的电池快照。
|
||||
- 超时熄灯仅遍历 `/run/mu300/led/` 中已有的非隐藏状态文件。若灯已亮但文件缺失,两个 Wi-Fi LDO 不会收到关闭命令;倒计时文件被删除后,后续 tick 还会提前退出。
|
||||
|
||||
以上使用私有 sysfs、时钟和状态目录复现,不能据此确定所有用户机器的残灯都来自同一原因。
|
||||
|
||||
## 修正
|
||||
|
||||
- 电池处理函数记录自己处理的快照;Wi-Fi、网络等事件只发布这份已处理记录,不再把新读数冒充已更新颜色。
|
||||
- 守护进程只有在电池输入与控制器处理记录一致时才允许省略 tick,避免完成回调吞掉状态变化。
|
||||
- U30 Air 的到期熄灯明确覆盖全部物理灯组,包括 2.4 GHz 和 5 GHz 两颗 Wi-Fi 灯;没有状态文件或倒计时已经消费,也能执行关闭。
|
||||
- 无效电量统一标记 unavailable,保留原有等待有效电量的行为。
|
||||
|
||||
不增加周期性轮询、不改变现有 30/90 秒安全核对节奏、充电呼吸曲线、满电常亮、低电颜色规则、拔线后的倒计时或用户灯组开关。F50/V50 的板级熄灯路径保持原实现。状态快照是运行期文件,不写持久化配置、NV 或电池寄存器。
|
||||
|
||||
## 验证与交付边界
|
||||
|
||||
- 新增两个 shell 回归,先在旧实现复现失败,再验证修正后的颜色快照与遗漏灯组关闭。
|
||||
- 灯控、网络灯、网页灯设置和 V50 测试 29 项通过;原物理灯与 sysd 启动链测试 13 项通过。shell 场景覆盖本机可用的 dash、bash、BusyBox ash。
|
||||
- 新增实际 ucode/uloop/socket 并发回归:首轮处理蓝色期间电量变为白色,收到电源事件后必须处理白色,稳定后不重复派生灯控进程。
|
||||
- 当前连接设备只读识别为 F50,未向它部署 U30 Air 修复。尚未进行 U30 Air 实物插拔、待机和观察灯色验证;未编译或重打固件包。
|
||||
@@ -3,9 +3,33 @@ import os
|
||||
from pathlib import Path
|
||||
import json
|
||||
import hashlib
|
||||
import stat
|
||||
import zipfile
|
||||
|
||||
|
||||
def write_runtime(archive, path, name):
|
||||
"""Retain Mac executable bits even when exporting from Windows/NTFS."""
|
||||
info = zipfile.ZipInfo.from_file(path, name)
|
||||
mode = stat.S_IMODE(path.stat().st_mode)
|
||||
app = name.split('/', 1)[0].endswith('.app')
|
||||
mac = app or name.startswith('tools/macos/')
|
||||
with path.open('rb') as stream:
|
||||
magic = stream.read(4) if mac else b''
|
||||
if (app and '/Contents/MacOS/' in name
|
||||
or name == 'tools/macos/backend/openwrt-backend'
|
||||
or mac and magic in (b'\xcf\xfa\xed\xfe', b'\xce\xfa\xed\xfe',
|
||||
b'\xfe\xed\xfa\xcf', b'\xfe\xed\xfa\xce',
|
||||
b'\xca\xfe\xba\xbe', b'\xbe\xba\xfe\xca')):
|
||||
mode = 0o755
|
||||
info.create_system = 3
|
||||
info.external_attr = (stat.S_IFREG | mode) << 16
|
||||
info.compress_type = zipfile.ZIP_DEFLATED
|
||||
stream.seek(0)
|
||||
with archive.open(info, 'w', force_zip64=True) as output:
|
||||
for block in iter(lambda: stream.read(1 << 20), b''):
|
||||
output.write(block)
|
||||
|
||||
|
||||
def export_bundle(patch, output, runtime):
|
||||
"""Use the generator's own fingerprinted runtime, including offline exports."""
|
||||
runtime = Path(runtime)
|
||||
@@ -40,7 +64,7 @@ def export_bundle(patch, output, runtime):
|
||||
dest = name
|
||||
else:
|
||||
continue
|
||||
z.write(runtime / name, dest)
|
||||
write_runtime(z, runtime / name, dest)
|
||||
z.writestr('README.md', '# OpenWrt differential OTA\n\n'
|
||||
'Web: import update.ota in System > System patches.\n'
|
||||
'Desktop: extract the complete folder and open OpenWrt-Updater.exe / .app.\n'
|
||||
|
||||
@@ -164,7 +164,9 @@ apk_retry update >/dev/null
|
||||
# i2c-tools, gpiod-tools: mu300-usb (the charger of the U30 Air) and mu300-nfc (its NFC tag)
|
||||
apk_retry add --allow-untrusted /in/wifi-sae/*.apk >/dev/null
|
||||
# The cipher capability helper needs the section omitted by reduced iw builds.
|
||||
apk_retry add iwinfo wireless-regdb iw-full bash ip-full coreutils-stty openssl-util curl ca-bundle msmtp luci-base rpcd-mod-ucode ucode ucode-mod-fs ucode-mod-ubus ucode-mod-uci ucode-mod-uloop ucode-mod-nl80211 ucode-mod-rtnl ucode-mod-socket \
|
||||
apk_retry add iwinfo wireless-regdb iw-full bash ip-full coreutils-stty openssl-util curl ca-bundle msmtp luci-base \
|
||||
luci-i18n-base-zh-cn luci-i18n-firewall-zh-cn luci-i18n-package-manager-zh-cn \
|
||||
rpcd-mod-ucode ucode ucode-mod-fs ucode-mod-ubus ucode-mod-uci ucode-mod-uloop ucode-mod-nl80211 ucode-mod-rtnl ucode-mod-socket \
|
||||
i2c-tools gpiod-tools flock ttyd luci-app-ttyd luci-i18n-ttyd-zh-cn luci-i18n-ttyd-tr python3 >/dev/null
|
||||
apk_retry add --allow-untrusted /in/block-mount-mu300.apk >/dev/null
|
||||
apk_retry add --allow-untrusted /in/luci-theme-aurora.apk >/dev/null
|
||||
@@ -255,8 +257,8 @@ if [ -d /in/luci-plugin ]; then
|
||||
chroot "$R" /usr/bin/ucode -e "import * as dash from \"mu300.dash\"; import * as rates from \"mu300.rates\"; import * as placement from \"mu300.service-cpus\";"
|
||||
mkdir -p $R/usr/lib/lua/luci/i18n
|
||||
cp -a /in/luci-plugin/lmo/. $R/usr/lib/lua/luci/i18n/
|
||||
# The source-tree install does not run the package postinst. Register only
|
||||
# Turkish; registering zh_cn changes auto-locale for Chinese browsers.
|
||||
# Official Chinese language packages register zh_cn. The dashboard uses
|
||||
# Chinese source strings; source-tree staging still needs Turkish registration.
|
||||
uci -c $R/etc/config -q get luci.languages.tr >/dev/null || uci -c $R/etc/config set luci.languages.tr="Türkçe"
|
||||
uci -c $R/etc/config commit luci
|
||||
fi
|
||||
|
||||
@@ -99,23 +99,17 @@ awake() {
|
||||
}
|
||||
# A deadline hint for sysd. Keep all board colours and physical writes here.
|
||||
tick_hint() {
|
||||
local now due until cap status color mode marker=-
|
||||
local now due until marker=-
|
||||
now=$(uptime_s); due=$((now + 600))
|
||||
until=$(rd "$STATE/.awake-until")
|
||||
case $until in ''|*[!0-9]*) ;; *)
|
||||
[ "$KEEP_LIT" = 1 ] || [ "$TIMEOUT" = 0 ] || [ "$until" -le "$now" ] || due=$until ;;
|
||||
esac
|
||||
if [ "$DEVICE" = u30air ]; then
|
||||
local root=${MU300_POWER_SUPPLY_DIR:-$R/sys/class/power_supply}
|
||||
cap=$(rd "$root/sc27xx-fgu/capacity"); status=$(rd "$root/sc27xx-fgu/status")
|
||||
[ "$KEEP_LIT" != 0 ] || status=Discharging
|
||||
case $cap in ''|*[!0-9]*) marker=unavailable ;; *)
|
||||
color=white; [ "$cap" -ge 50 ] || color=blue
|
||||
[ "$status" != Full ] || color=white
|
||||
mode=steady
|
||||
if [ "$status" = Charging ]; then mode=breathe; [ "$cap" -ge 10 ] || color=red; fi
|
||||
marker=$color:$mode:$KEEP_LIT ;;
|
||||
esac
|
||||
# Only battery() knows which snapshot was actually applied. A Wi-Fi
|
||||
# event or a capacity change during writes must not acknowledge a new
|
||||
# battery colour before its channels have been reconciled.
|
||||
marker=$(rd "$STATE/.battery-applied") || marker=unavailable
|
||||
fi
|
||||
mkdir -p "$STATE" || return 0
|
||||
(umask 077; printf 'due %s\nbattery %s\n' "$due" "$marker" > "$STATE/.tick-hint.new") &&
|
||||
@@ -211,10 +205,10 @@ nap() { sleep "$1" 2>/dev/null || sleep 1; } # (a busybox without fractional s
|
||||
|
||||
battery() {
|
||||
[ "$DEVICE" = u30air ] || return 0
|
||||
local root=${MU300_POWER_SUPPLY_DIR:-$R/sys/class/power_supply} cap status color channel value previous_power
|
||||
local root=${MU300_POWER_SUPPLY_DIR:-$R/sys/class/power_supply} cap status color channel value previous_power marker mode
|
||||
cap=$(rd "$root/sc27xx-fgu/capacity")
|
||||
case $cap in ''|*[!0-9]*) return 0 ;; esac
|
||||
[ "$cap" -le 100 ] || return 0
|
||||
case $cap in ''|*[!0-9]*) echo unavailable > "$STATE/.battery-applied"; return 0 ;; esac
|
||||
[ "$cap" -le 100 ] || { echo unavailable > "$STATE/.battery-applied"; return 0; }
|
||||
status=$(rd "$root/sc27xx-fgu/status")
|
||||
# Charger online changes before the fuel-gauge status sometimes does.
|
||||
# A stale "Charging"/"Full" must not keep the charging indication alive.
|
||||
@@ -239,6 +233,10 @@ battery() {
|
||||
value=0; [ "$channel" != "$color" ] || value=1
|
||||
if siren_running; then echo "$value" > "$STATE/$channel"; else set_led "$channel" "$value"; fi
|
||||
done
|
||||
marker=white; [ "$color" != sc27xx:blue ] || marker=blue
|
||||
[ "$color" != sc27xx:red ] || marker=red
|
||||
mode=steady; [ "$status" != Charging ] || mode=breathe
|
||||
printf '%s:%s:%s\n' "$marker" "$mode" "$KEEP_LIT" > "$STATE/.battery-applied"
|
||||
if [ "$KEEP_LIT" = 1 ] && [ "$previous_power" != 1 ] && ! siren_running; then show_all; fi
|
||||
}
|
||||
|
||||
@@ -304,9 +302,20 @@ case "$1 ${2:-}" in
|
||||
[ "$1" != tick ] || battery
|
||||
[ "$TIMEOUT" = 0 ] && exit 0
|
||||
if { [ "$1" = tick ] || [ "${2:-}" = --if-due ]; } && awake; then exit 0; fi
|
||||
[ -e "$STATE/.awake-until" ] || { [ "$1" != tick ] && [ "${2:-}" != --if-due ]; } || exit 0
|
||||
if [ "$DEVICE" != u30air ]; then
|
||||
[ -e "$STATE/.awake-until" ] || { [ "$1" != tick ] && [ "${2:-}" != --if-due ]; } || exit 0
|
||||
fi
|
||||
rm -f "$STATE/.awake-until"
|
||||
for f in "$STATE"/*; do [ -f "$f" ] && write "${f##*/}" 0; done ;;
|
||||
if [ "$DEVICE" = u30air ]; then
|
||||
# Physical lamps can predate this process's desired-state files
|
||||
# (boot handoff, a late driver or an interrupted refresh). Darken
|
||||
# the entire board, including BOTH Wi-Fi LDOs, on every due tick.
|
||||
for lamp in "$DATA" "$DATA5G" "$NODATA" "$WIFI5" "$WIFI24" $SIREN; do
|
||||
write "$lamp" 0
|
||||
done
|
||||
else
|
||||
for f in "$STATE"/*; do [ -f "$f" ] && write "${f##*/}" 0; done
|
||||
fi ;;
|
||||
"alarm on")
|
||||
rm -f "$BOOT_STATE"
|
||||
siren_running && exit 0
|
||||
|
||||
@@ -305,7 +305,7 @@ function led_observe() {
|
||||
let color=+cap>=50?'white':'blue', mode='steady';
|
||||
if(st=='Full')color='white';
|
||||
if(st=='Charging') {mode='breathe';if(+cap<10)color='red';}
|
||||
battery=digits(cap)?color+':'+mode+':'+(on=='1'?'1':'0'):'unavailable';
|
||||
battery=digits(cap) && +cap<=100?color+':'+mode+':'+(on=='1'?'1':'0'):'unavailable';
|
||||
}
|
||||
return [battery,rd(LEDDIR+'/.awake-until'),rd(LEDDIR+'/.boot-chase'),
|
||||
rd(LEDDIR+'/.battery-breathe'),rd(R+'/run/mu300/led-siren.pid')];
|
||||
@@ -315,7 +315,9 @@ function led_look() {
|
||||
if (led_ticking) { led_again = true; return; }
|
||||
led_hint_load();
|
||||
let observed=led_observe();
|
||||
if(led_hint && now()<led_hint.due && sprintf('%J',observed)==led_seen) {led_arm();return;}
|
||||
// The child may finish while capacity/power changes. Its hint records
|
||||
// the applied snapshot, so never mark newer, unapplied input as handled.
|
||||
if(led_hint && observed[0]==led_hint.battery && now()<led_hint.due && sprintf('%J',observed)==led_seen) {led_arm();return;}
|
||||
led_ticking = true;
|
||||
spawn(['mu300-led','tick'], () => {
|
||||
led_ticking = false;
|
||||
|
||||
@@ -96,5 +96,50 @@ Path(os.environ['SLACK_RESULT']).write_text(Path('/proc/self/timerslack_ns').rea
|
||||
self.assertEqual(p.returncode,0,p.stderr)
|
||||
self.assertNotEqual(int((self.base/'slack').read_text()),500000000)
|
||||
|
||||
def test_color_change_during_tick_is_not_acknowledged_by_completion(self):
|
||||
psy=self.root/'sys/class/power_supply'
|
||||
(psy/'sc27xx-fgu').mkdir(parents=True)
|
||||
(psy/'bq256xx-charger').mkdir()
|
||||
(psy/'sc27xx-fgu/capacity').write_text('49\n')
|
||||
(psy/'sc27xx-fgu/status').write_text('Discharging\n')
|
||||
(psy/'bq256xx-charger/online').write_text('0\n')
|
||||
helper=self.stub('keys','''#!/usr/bin/python3
|
||||
import ctypes,os,time
|
||||
from pathlib import Path
|
||||
ctypes.CDLL(None).prctl(1,15)
|
||||
p=Path(os.environ['MU300_SYSROOT'])/'calls'
|
||||
while not p.exists():time.sleep(.02)
|
||||
time.sleep(.1)
|
||||
print('uevent power_supply',flush=True)
|
||||
time.sleep(60)
|
||||
''')
|
||||
self.stub('mu300-led','''#!/usr/bin/python3
|
||||
import os,time
|
||||
from pathlib import Path
|
||||
root=Path(os.environ['MU300_SYSROOT']);p=root/'run/mu300/led';p.mkdir(exist_ok=True)
|
||||
cap=root/'sys/class/power_supply/sc27xx-fgu/capacity'
|
||||
color='white' if int(cap.read_text())>=50 else 'blue'
|
||||
now=int(float(Path('/proc/uptime').read_text().split()[0]))
|
||||
(p/'.tick-hint').write_text('due '+str(now+600)+'\\nbattery '+color+':steady:0\\n')
|
||||
calls=root/'calls'
|
||||
first=not calls.exists()
|
||||
with calls.open('a') as f:f.write(color+'\\n')
|
||||
if first:cap.write_text('50\\n')
|
||||
''')
|
||||
env=dict(self.env,MU300_KEYS_BIN=str(helper),MU300_SYSD_PARTS='led',MU300_SYSD_LOG=str(self.base/'sysd.log'))
|
||||
daemon=subprocess.Popen(['ucode',str(SYSD)],env=env,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
||||
try:
|
||||
deadline=time.monotonic()+10 # Production's first LED check is at five seconds.
|
||||
while time.monotonic()<deadline:
|
||||
if (self.root/'calls').exists() and len((self.root/'calls').read_text().splitlines())>=2:break
|
||||
time.sleep(.05)
|
||||
self.assertEqual((self.root/'calls').read_text().splitlines(),['blue','white'])
|
||||
time.sleep(.7)
|
||||
self.assertEqual((self.root/'calls').read_text().splitlines(),['blue','white'])
|
||||
finally:
|
||||
daemon.send_signal(signal.SIGTERM);_,err=daemon.communicate(timeout=5)
|
||||
if (self.base/'sysd.log').exists():print((self.base/'sysd.log').read_text())
|
||||
if err:print(err.decode())
|
||||
|
||||
|
||||
if __name__=='__main__':unittest.main()
|
||||
@@ -36,6 +36,38 @@ esac""")
|
||||
def led(self, shell, *args, **extra):
|
||||
return self.script(shell, BIN/'mu300-led', *args, **dict(self.extra, **extra))
|
||||
|
||||
def test_wifi_event_cannot_acknowledge_an_unapplied_battery_color(self):
|
||||
for shell in self.each_shell():
|
||||
state=self.root/'run/mu300/led'
|
||||
(self.battery/'capacity').write_text('49\n')
|
||||
self.apply(shell,'battery')
|
||||
self.assertEqual(self.value('sc27xx:blue'),'255')
|
||||
(self.battery/'capacity').write_text('50\n')
|
||||
self.apply(shell,'wifi-on')
|
||||
self.assertEqual(self.value('sc27xx:blue'),'255')
|
||||
self.assertIn('battery blue:breathe:1\n',(state/'.tick-hint').read_text())
|
||||
self.assertEqual(self.led(shell,'tick').returncode,0)
|
||||
self.assertEqual(self.value('sc27xx:green'),'255')
|
||||
self.assertIn('battery white:breathe:1\n',(state/'.tick-hint').read_text())
|
||||
|
||||
def test_sleep_clears_physical_wifi_without_a_desired_state_record(self):
|
||||
for shell in self.each_shell():
|
||||
(self.battery/'status').write_text('Discharging\n')
|
||||
self.assertEqual(self.led(shell,'wake',TEST_TIMEOUT='60').returncode,0)
|
||||
state=self.root/'run/mu300/led'
|
||||
for lamp in ('zte-ldo1','zte-ldo2'):
|
||||
(state/lamp).unlink(missing_ok=True)
|
||||
(self.lamps/lamp/'brightness').write_text('1\n')
|
||||
(self.root/'proc/uptime').write_text('161.00 0.00\n')
|
||||
self.assertEqual(self.led(shell,'tick',TEST_TIMEOUT='60').returncode,0)
|
||||
self.assertEqual(self.value('zte-ldo1'),'0')
|
||||
self.assertEqual(self.value('zte-ldo2'),'0')
|
||||
# A late hardware residue must also be cleared after the lease was consumed.
|
||||
(self.lamps/'zte-ldo1'/'brightness').write_text('1\n')
|
||||
self.assertEqual(self.led(shell,'tick',TEST_TIMEOUT='60').returncode,0)
|
||||
self.assertEqual(self.value('zte-ldo1'),'0')
|
||||
(self.root/'proc/uptime').write_text('100.00 0.00\n')
|
||||
|
||||
def test_tick_hint_tracks_timeout_charge_bucket_and_unplug(self):
|
||||
for shell in self.each_shell():
|
||||
state=self.root/'run/mu300/led'
|
||||
|
||||
@@ -157,6 +157,7 @@ for f in ./lib/netifd/proto/mu300cell.sh ./lib/netifd/proto/mu300cell-v6.sh \
|
||||
./etc/hotplug.d/net/90-unisoc-usb-host \
|
||||
./etc/hotplug.d/iface/90-unisoc-usb-host \
|
||||
./usr/lib/lua/luci/i18n/mu300.en.lmo ./usr/lib/lua/luci/i18n/mu300.tr.lmo \
|
||||
./usr/lib/lua/luci/i18n/base.zh-cn.lmo ./usr/lib/lua/luci/i18n/firewall.zh-cn.lmo ./usr/lib/lua/luci/i18n/package-manager.zh-cn.lmo \
|
||||
./etc/init.d/unisoc-modem-ui ./etc/rc.d/S95unisoc-modem-ui \
|
||||
./www/luci-static/aurora/main.css \
|
||||
./www/luci-static/resources/view/aurora/studio.js \
|
||||
|
||||
@@ -117,7 +117,8 @@ for f in ./opt/mu300/bin/mu300-at ./opt/mu300/bin/mobile-data \
|
||||
./usr/libexec/unisoc-modem/data-sim ./www/luci-static/resources/view/mu300/sim.js \
|
||||
./www/luci-static/resources/view/mu300/device.js ./usr/libexec/unisoc-modem/device-usb \
|
||||
./etc/hotplug.d/net/90-unisoc-usb-host ./etc/hotplug.d/iface/90-unisoc-usb-host \
|
||||
./etc/init.d/unisoc-modem-ui ./usr/lib/lua/luci/i18n/mu300.en.lmo ./usr/lib/lua/luci/i18n/mu300.tr.lmo; do
|
||||
./etc/init.d/unisoc-modem-ui ./usr/lib/lua/luci/i18n/mu300.en.lmo ./usr/lib/lua/luci/i18n/mu300.tr.lmo \
|
||||
./usr/lib/lua/luci/i18n/base.zh-cn.lmo ./usr/lib/lua/luci/i18n/firewall.zh-cn.lmo ./usr/lib/lua/luci/i18n/package-manager.zh-cn.lmo; do
|
||||
tar -tzf "$D/mu300-openwrt-rootfs.tar.gz" "$f" >/dev/null || {
|
||||
echo "release OpenWrt rootfs missing $f" >&2; exit 1;
|
||||
}
|
||||
|
||||
@@ -7,10 +7,12 @@ Only Diff Studio's files enter diff-tool.json; no firmware/ADB/installer payload
|
||||
is included when the tool subsequently exports a patch updater.
|
||||
"""
|
||||
import hashlib
|
||||
import copy
|
||||
import json
|
||||
from pathlib import Path
|
||||
from pathlib import Path, PurePosixPath
|
||||
import shutil
|
||||
import sys
|
||||
import zipfile
|
||||
|
||||
TOP=Path(__file__).resolve().parents[1]
|
||||
SUPPORT=('__init__.py','ota_engine.py','ota_package.py','release_index.py','ota_desktop.py',
|
||||
@@ -25,6 +27,49 @@ def digest(path):
|
||||
return h.hexdigest()
|
||||
|
||||
|
||||
def export_standalone(release, output):
|
||||
"""Export only the verified tool files, retaining signed app contents/modes."""
|
||||
output=Path(output)
|
||||
if output.exists():
|
||||
raise ValueError('Select a new output ZIP; existing packages are not overwritten')
|
||||
with zipfile.ZipFile(release) as source:
|
||||
if len(source.namelist())!=len(set(source.namelist())):
|
||||
raise ValueError('Duplicate archive entries')
|
||||
manifest=json.loads(source.read('diff-tool.json'))
|
||||
files=manifest.get('files',{})
|
||||
required={'OpenWrt-Diff-Studio.exe','OpenWrt-Diff-Studio.py',
|
||||
'OpenWrt-Diff-Studio.app/Contents/MacOS/openwrt-installer',
|
||||
'tools/backend/openwrt-backend.exe','tools/macos/backend/openwrt-backend'}
|
||||
if manifest.get('protocol')!=1 or not required.issubset(files):
|
||||
raise ValueError('Release does not contain a complete Diff Studio')
|
||||
for name,wanted in files.items():
|
||||
path=PurePosixPath(name)
|
||||
if (path.is_absolute() or '..' in path.parts or '\\' in name or
|
||||
(name not in required and not name.startswith(('backend/','tools/backend/',
|
||||
'tools/macos/backend/','OpenWrt-Diff-Studio.app/')))):
|
||||
raise ValueError('Unexpected Diff Studio file: '+name)
|
||||
with source.open(name) as stream:
|
||||
hashed=hashlib.sha256()
|
||||
for block in iter(lambda:stream.read(1<<20),b''):hashed.update(block)
|
||||
if hashed.hexdigest()!=wanted:
|
||||
raise ValueError('Diff Studio checksum mismatch: '+name)
|
||||
guide=source.read('docs/DIFF-STUDIO.md').decode('utf-8')
|
||||
output.parent.mkdir(parents=True,exist_ok=True)
|
||||
with zipfile.ZipFile(output,'x',compression=zipfile.ZIP_DEFLATED) as target:
|
||||
for name in sorted(files):
|
||||
with source.open(name) as src, target.open(copy.copy(source.getinfo(name)),'w',force_zip64=True) as dst:
|
||||
shutil.copyfileobj(src,dst,1<<20)
|
||||
target.writestr('diff-tool.json',source.read('diff-tool.json'))
|
||||
target.writestr('START-HERE.md',guide.replace('完整解压固件 ZIP','完整解压本工具 ZIP'))
|
||||
with zipfile.ZipFile(output) as result:
|
||||
if result.testzip():
|
||||
raise ValueError('Standalone ZIP verification failed')
|
||||
checksum=digest(output)
|
||||
Path(str(output)+'.sha256').write_text(checksum+' '+output.name+'\n',encoding='utf-8')
|
||||
print(str(output)+'\nSHA256 '+checksum)
|
||||
return manifest
|
||||
|
||||
|
||||
def attach(package):
|
||||
package=Path(package)
|
||||
sys.path.insert(0,str(TOP/'installer'))
|
||||
@@ -78,9 +123,18 @@ def attach(package):
|
||||
if __name__=='__main__':
|
||||
import argparse
|
||||
parser=argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--package',type=Path,required=True)
|
||||
parser.add_argument('--package',type=Path)
|
||||
parser.add_argument('--prepare',action='store_true')
|
||||
parser.add_argument('--from-release',type=Path)
|
||||
parser.add_argument('--output-zip',type=Path)
|
||||
args=parser.parse_args()
|
||||
if args.from_release or args.output_zip:
|
||||
if not args.from_release or not args.output_zip or args.package or args.prepare:
|
||||
parser.error('Use --from-release and --output-zip together without --package/--prepare')
|
||||
export_standalone(args.from_release,args.output_zip)
|
||||
sys.exit(0)
|
||||
if not args.package:
|
||||
parser.error('Supply --package or --from-release/--output-zip')
|
||||
args.package.mkdir(parents=True,exist_ok=True)
|
||||
if args.prepare:
|
||||
import runpy
|
||||
|
||||
@@ -52,6 +52,24 @@ class DiffPackaging(unittest.TestCase):
|
||||
self.assertFalse(any('Installer' in n or n.startswith('files/') or 'adb' in n for n in names))
|
||||
self.assertEqual(names.count('update.ota'),1)
|
||||
|
||||
def test_export_restores_mac_execute_bits_from_windows_style_modes(self):
|
||||
manifest=tool['attach'](self.root)
|
||||
executable='OpenWrt-Diff-Studio.app/Contents/MacOS/openwrt-installer'
|
||||
backend='tools/macos/backend/openwrt-backend'
|
||||
library='tools/macos/backend/_internal/libpython-test.dylib'
|
||||
path=self.root/library;path.parent.mkdir(parents=True,exist_ok=True)
|
||||
path.write_bytes(b'\xcf\xfa\xed\xfe library fixture')
|
||||
manifest['files'][library]=hashlib.sha256(path.read_bytes()).hexdigest()
|
||||
(self.root/'diff-tool.json').write_text(json.dumps(manifest))
|
||||
for name in (executable,backend,library):(self.root/name).chmod(0o644)
|
||||
patch=self.root.parent/'test.ota';patch.write_bytes(b'opaque fixture')
|
||||
target=self.root.parent/'patch.zip';export_bundle(patch,target,self.root)
|
||||
with zipfile.ZipFile(target) as z:
|
||||
for name in (executable.replace('Diff-Studio','Updater'),backend,library):
|
||||
self.assertEqual((z.getinfo(name).external_attr>>16)&0o777,0o755)
|
||||
self.assertEqual(z.read(executable.replace('Diff-Studio','Updater')),(self.root/executable).read_bytes())
|
||||
self.assertFalse((z.getinfo('OpenWrt-Updater.app/Contents/Info.plist').external_attr>>16)&0o111)
|
||||
|
||||
def test_stale_native_and_duplicate_attachment_refused(self):
|
||||
(self.root/'tools/backend/openwrt-backend.exe').write_bytes(b'tampered')
|
||||
with self.assertRaisesRegex(ValueError,'native input mismatch'):tool['attach'](self.root)
|
||||
@@ -60,5 +78,21 @@ class DiffPackaging(unittest.TestCase):
|
||||
tool['attach'](self.root)
|
||||
with self.assertRaisesRegex(ValueError,'already exists'):tool['attach'](self.root)
|
||||
|
||||
def test_standalone_export_contains_complete_tool_without_firmware(self):
|
||||
manifest=tool['attach'](self.root)
|
||||
release=self.root.parent/'release.zip';output=self.root.parent/'standalone.zip'
|
||||
with zipfile.ZipFile(release,'w') as z:
|
||||
for path in self.root.rglob('*'):
|
||||
if path.is_file():z.write(path,path.relative_to(self.root).as_posix())
|
||||
tool['export_standalone'](release,output)
|
||||
with zipfile.ZipFile(output) as z:
|
||||
self.assertEqual(set(z.namelist()),set(manifest['files'])|{'diff-tool.json','START-HERE.md'})
|
||||
for name,wanted in manifest['files'].items():
|
||||
self.assertEqual(hashlib.sha256(z.read(name)).hexdigest(),wanted)
|
||||
self.assertFalse(any('Installer' in name or 'adb' in name or name.startswith('files/') for name in z.namelist()))
|
||||
self.assertTrue(Path(str(output)+'.sha256').is_file())
|
||||
with self.assertRaisesRegex(ValueError,'existing packages'):
|
||||
tool['export_standalone'](release,output)
|
||||
|
||||
|
||||
if __name__=='__main__':unittest.main()
|
||||
Reference in new issue
Block a user