mirror of
https://github.com/dikeckaan/mu300-linux.git
synced 2026-12-05 08:02:40 +00:00
mu300-update keeps the vendor files when it runs from OpenWrt: busybox's cp -an skipped the image's existing directories
Busybox cp -n skips a directory that exists without looking into it, so `cp -an old/v/. new/v/` copied nothing into the image's own opt/mu300/android and lib/firmware. An update run from OpenWrt (v2026.10.10-rc1 on F50 #1) left every system without the Android userspace and the WCN firmware: no modem, no mobile data, no hotspot, no VPN. copy_missing copies what the old system has and the new one lacks, never replaces the image's files, never writes below a link of the new system, and a failed copy stops the update before anything is switched. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DqKKtBQZCfxYnHuBCuDqqn
This commit is contained in:
1 parent
c527f87e0b
commit
f7df326eb0
2 files changed
+75
-1
No files matched your search
@@ -136,6 +136,24 @@ bundle_has_sd() { bundle_has "$1" "$2" sdcard; }
|
||||
# bundle_fits_slot BUNDLE LIST: can its init run from the slot Linux is on? One from before linux-slot knows only b:
|
||||
# on a it would restore the block that boots Linux, marked successful, and log into Android's boot partition.
|
||||
bundle_fits_slot() { [ "$(linux_slot)" = b ] || bundle_has "$1" "$2" linux-slot; }
|
||||
# copy_missing FROM TO: copy what FROM has and TO lacks, never replacing anything of TO. Not `cp -an FROM/. TO/`:
|
||||
# busybox cp -n skips a directory that exists without looking into it, so an update run from OpenWrt copied none of
|
||||
# the vendor files into the image's own opt/mu300/android and lib/firmware (no modem, no Wi-Fi after the reboot).
|
||||
# Nothing is written below a link of TO (find lists a directory before what is in it).
|
||||
copy_missing() {
|
||||
( cd "$1" && find . ! -name . ) | {
|
||||
skip=
|
||||
while IFS= read -r p; do
|
||||
case $p in "$skip"/*) continue ;; esac
|
||||
if [ -e "$2/$p" ] || [ -L "$2/$p" ]; then
|
||||
{ [ -d "$2/$p" ] && [ ! -L "$2/$p" ]; } || skip=$p
|
||||
continue
|
||||
fi
|
||||
cp -a "$1/$p" "$2/$p" || exit 1
|
||||
skip=$p
|
||||
done
|
||||
}
|
||||
}
|
||||
# the directory the running system booted from (it stays in use under any name until the reboot)
|
||||
is_root() { [ -d "$1" ] && [ / -ef "$1" ]; }
|
||||
# the directory this system booted from; /etc/openwrt_release alone cannot tell the two OpenWrt systems apart
|
||||
@@ -320,7 +338,7 @@ apply_one() { # apply_one OS TAG
|
||||
for v in $(vendor_list "$os"); do
|
||||
[ -d "$old/$v" ] || continue
|
||||
mkdir -p "$new/$v"
|
||||
cp -an "$old/$v/." "$new/$v/" 2>/dev/null || true
|
||||
copy_missing "$old/$v" "$new/$v" || { rm -rf "$new"; die "$os: copying the vendor files failed, nothing was changed"; }
|
||||
done
|
||||
# services enabled by hand (the links point into the system, so test with -L)
|
||||
if [ "$os" = ubuntu ]; then
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
release it takes, the kernel choice, the byte helpers it edits boot image headers with, and whether a kernel bundle
|
||||
may go onto this device."""
|
||||
import io
|
||||
import os
|
||||
import shutil
|
||||
import struct
|
||||
import subprocess
|
||||
@@ -428,6 +429,61 @@ class FromStock(UpdateBase):
|
||||
self.assertNotEqual(r.returncode, 0)
|
||||
self.assertIn('persistent log area', r.stderr)
|
||||
|
||||
def test_apply_keeps_the_vendor_files_the_image_has_a_directory_for(self):
|
||||
# the images ship opt/mu300/android/system/bin/cltest and a few firmware files, so the vendor directories
|
||||
# exist in the new system; busybox's `cp -an old/. new/` then skips them as existing and copies nothing (an
|
||||
# update run from OpenWrt left every system without the Android userspace: no modem, no Wi-Fi)
|
||||
img = self.tmp / 'img'
|
||||
for f, data in [('sbin/init', b'#!/bin/sh\n'), ('opt/mu300/android/system/bin/cltest', b'image'),
|
||||
('lib/firmware/regulatory.db', b'image'), ('etc/mu300/image-version', b'v2\n')]:
|
||||
(img / f).parent.mkdir(parents=True, exist_ok=True)
|
||||
(img / f).write_bytes(data)
|
||||
(img / 'sbin/init').chmod(0o755)
|
||||
old = self.disk / 'openwrt'
|
||||
for f, data in [('sbin/init', b'#!/bin/sh\n'), ('opt/mu300/android/system/bin/cltest', b'old'),
|
||||
('opt/mu300/android/system/bin/cp_diskserver', b'vendor'),
|
||||
('opt/mu300/android/vendor/lib/libril.so', b'vendor'),
|
||||
('opt/mu300/android/dev-properties/property_info', b'props'),
|
||||
('lib/firmware/wcnmodem.bin', b'fw'), ('lib/firmware/regulatory.db', b'old'),
|
||||
('lib/modules/5.4.254/x.ko', b'ko'), ('etc/mu300/vpn.conf', b'mine')]:
|
||||
(old / f).parent.mkdir(parents=True, exist_ok=True)
|
||||
(old / f).write_bytes(data)
|
||||
(old / 'opt/mu300/android/system/lib').symlink_to('../vendor/lib')
|
||||
stage = self.disk / '.mu300-update'
|
||||
for shell in self.each_shell():
|
||||
for d in ('openwrt.old', 'openwrt.new'):
|
||||
shutil.rmtree(self.disk / d, ignore_errors=True)
|
||||
stage.mkdir(exist_ok=True)
|
||||
subprocess.run(['tar', '-czf', str(stage / 'mu300-openwrt-rootfs.tar.gz'), '-C', str(img), '.'], check=True)
|
||||
r = self.up(shell, 'is_root() { false; }; apply_one openwrt v2')
|
||||
self.assertEqual(r.returncode, 0, r.stderr)
|
||||
new = self.disk / 'openwrt'
|
||||
self.assertEqual((new / 'opt/mu300/android/system/bin/cp_diskserver').read_bytes(), b'vendor')
|
||||
self.assertEqual((new / 'opt/mu300/android/vendor/lib/libril.so').read_bytes(), b'vendor')
|
||||
self.assertEqual((new / 'opt/mu300/android/dev-properties/property_info').read_bytes(), b'props')
|
||||
self.assertEqual(os.readlink(new / 'opt/mu300/android/system/lib'), '../vendor/lib')
|
||||
self.assertEqual((new / 'lib/firmware/wcnmodem.bin').read_bytes(), b'fw')
|
||||
self.assertEqual((new / 'lib/modules/5.4.254/x.ko').read_bytes(), b'ko')
|
||||
# what the image has stays the image's
|
||||
self.assertEqual((new / 'opt/mu300/android/system/bin/cltest').read_bytes(), b'image')
|
||||
self.assertEqual((new / 'lib/firmware/regulatory.db').read_bytes(), b'image')
|
||||
self.assertEqual((new / 'etc/mu300/vpn.conf').read_bytes(), b'mine')
|
||||
# the next shell updates from this one (disk/openwrt again)
|
||||
|
||||
def test_copy_missing_never_writes_through_a_link_of_the_target(self):
|
||||
a, b, outside = self.tmp / 'a', self.tmp / 'b', self.tmp / 'outside'
|
||||
(a / 'd/x').mkdir(parents=True)
|
||||
(a / 'd/x/f').write_text('a')
|
||||
(a / 'name with space').write_text('s')
|
||||
b.mkdir(); outside.mkdir()
|
||||
(b / 'd').symlink_to(outside)
|
||||
for shell in self.each_shell():
|
||||
r = self.up(shell, f'copy_missing "{a}" "{b}"')
|
||||
self.assertEqual(r.returncode, 0, r.stderr)
|
||||
self.assertEqual(list(outside.iterdir()), [])
|
||||
self.assertEqual((b / 'name with space').read_text(), 's')
|
||||
(b / 'name with space').unlink()
|
||||
|
||||
def test_modules_into_every_system(self):
|
||||
b = self.tmp / 'bundle'
|
||||
(b / 'modules').mkdir(parents=True)
|
||||
|
||||
Reference in new issue
Block a user