fix: recognize SM8975 and mark Adreno 850 support experimental (#1249)

* fix: recognize SM8975 and mark Adreno 850 support experimental

* fix: retain A850 experimental status with spoofed Vulkan names
This commit is contained in:
Danbro007 authored and GitHub committed 2026-10-22 10:19:23 -04:00
1 parent 0577a22459
commit d2abaef2a3
15 files changed
+522 -41

No files matched your search

+133
View File
@@ -0,0 +1,133 @@
#!/usr/bin/env python3
"""Package pinned local community A850 drivers; never download or execute drivers."""
import argparse
import hashlib
import io
import json
import os
from pathlib import Path
import stat
import struct
import tempfile
import zipfile
ANDROID_SHA256 = '0cf849d068c875f6c469380ca1f74da1f757575bce53d4ef9c1f6d38677cbe8b'
LINUX_SHA256 = '40fc59506620001531b9bdd1c9152e104c6fb1f4c07773c4743b9d70deb87eec'
LIBRARY = 'libvulkan_freedreno.so'
VERSION = '20261012-a850exp1'
SOURCE = 'https://github.com/Droid-Deck/DroidDeck/issues/342'
README = f'''# Adreno 850 community experimental
Manual opt-in experiment for DroidDeck; not native Adreno 850 support.
Source: community attachments to {SOURCE}
Android original: AdrenoTools-A850-experimental.zip, SHA256 {ANDROID_SHA256}
Linux original: A850-experimental.zip, SHA256 {LINUX_SHA256}
These community binaries are patched to treat Adreno 850 as Adreno 840.
They have not been validated on the target phone by this project. They may
black-screen, hang, glitch, or fail to boot. They do not establish native 850
support. Import and select this bundle manually; global auto selection is
unchanged. Use sysmem mode as advised in the original Linux metadata.
Both original meta.json files, libraries, and Linux ICD JSON are preserved
byte-for-byte. No drivers are downloaded, executed, or rebuilt by this tool.
'''
NOTICE = f'''Community experimental binaries, distributed without a compatibility guarantee.
Original author attribution and release descriptions are in android/meta.json
and linux/meta.json. The412Banner is the original driver author; the community
attachment describes an experimental binary patch. Source: {SOURCE}
This wrapper makes no new license grant for the enclosed third-party binaries.
'''
def validate_elf(data, platform):
if (len(data) < 64 or data[:6] != b'\x7fELF\x02\x01'
or struct.unpack_from('<H', data, 18)[0] != 183):
raise ValueError(f'{platform}: expected ELF64 little-endian AArch64 library')
if platform == 'linux' and b'libc.so.6\x00' not in data:
raise ValueError('linux: expected glibc library')
if platform == 'android' and b'libc.so.6\x00' in data:
raise ValueError('android: glibc library is not an AdrenoTools driver')
def read_driver(path, platform, expected_hash):
original = Path(path).read_bytes()
if hashlib.sha256(original).hexdigest() != expected_hash:
raise ValueError(f'{platform}: SHA256 mismatch; only the pinned issue #342 attachment is accepted')
allowed = {'meta.json', LIBRARY}
if platform == 'linux':
allowed.add('freedreno_icd.aarch64.json')
with zipfile.ZipFile(io.BytesIO(original)) as archive:
entries = archive.infolist()
names = [entry.filename for entry in entries]
if len(names) != len(set(names)) or set(names) != allowed:
raise ValueError(f'{platform}: expected only {sorted(allowed)}; unsafe, extra or missing entries')
for entry in entries:
mode = entry.external_attr >> 16
if entry.is_dir() or stat.S_IFMT(mode) not in (0, stat.S_IFREG) or entry.flag_bits & 1:
raise ValueError(f'{platform}: entry must be an unencrypted regular file')
files = {name: archive.read(name) for name in names}
meta = json.loads(files['meta.json'])
if not isinstance(meta, dict):
raise ValueError(f'{platform}: meta.json must be an object')
if platform == 'android' and meta.get('libraryName') != LIBRARY:
raise ValueError('android: incorrect meta.json libraryName')
if platform == 'linux':
if meta.get('libc') != 'glibc' or meta.get('kind') != 'linux-vulkan-icd':
raise ValueError('linux: incorrect meta.json libc/kind')
icd = json.loads(files['freedreno_icd.aarch64.json'])
if (not isinstance(icd, dict) or not isinstance(icd.get('ICD'), dict)
or icd['ICD'].get('library_path') != './' + LIBRARY):
raise ValueError('linux: incorrect ICD library_path')
validate_elf(files[LIBRARY], platform)
return files
def prepare_bundle(android, linux, output):
android, linux, output = map(Path, (android, linux, output))
for source in (android, linux):
if source.resolve() == output.resolve() or (output.exists() and source.samefile(output)):
raise ValueError('output must differ from both input archives')
files = {}
for platform, source, digest in (('android', android, ANDROID_SHA256), ('linux', linux, LINUX_SHA256)):
files.update({f'{platform}/{name}': data for name, data in read_driver(source, platform, digest).items()})
manifest = {'package': 'Adreno 850 community experimental', 'version': VERSION, 'tag': VERSION,
'drivers': {'android': {'path': 'android'}, 'linux': {'path': 'linux'}}}
files['manifest.json'] = (json.dumps(manifest, indent=2, sort_keys=True) + '\n').encode()
files['README.md'] = README.encode()
files['NOTICE'] = NOTICE.encode()
temporary = None
try:
with tempfile.NamedTemporaryFile(dir=output.parent, prefix='.' + output.name + '.', delete=False) as target:
temporary = Path(target.name)
with zipfile.ZipFile(target, 'w', compression=zipfile.ZIP_STORED) as archive:
for name, data in sorted(files.items()):
info = zipfile.ZipInfo(name, date_time=(1980, 1, 1, 0, 0, 0))
info.create_system = 3
info.external_attr = (stat.S_IFREG | 0o644) << 16
archive.writestr(info, data)
target.flush()
os.fsync(target.fileno())
os.replace(temporary, output)
finally:
if temporary is not None:
temporary.unlink(missing_ok=True)
return output
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--android', type=Path, required=True, help='Original AdrenoTools-A850-experimental.zip')
parser.add_argument('--linux', type=Path, required=True, help='Original A850-experimental.zip')
parser.add_argument('--output', type=Path, required=True, help='Destination DroidDeck DriverBundle zip')
args = parser.parse_args()
try:
result = prepare_bundle(args.android, args.linux, args.output)
except (OSError, ValueError, zipfile.BadZipFile, RuntimeError) as error:
parser.exit(1, f'error: {error}\n')
print(f'Created {result} (manual opt-in; experimental, no target-phone validation)')
if __name__ == '__main__':
main()
+164
View File
@@ -0,0 +1,164 @@
import hashlib
import importlib.util
import json
from pathlib import Path
import struct
import stat
import tempfile
import unittest
from unittest import mock
import zipfile
spec = importlib.util.spec_from_file_location(
'prepare_a850_driver_bundle', Path(__file__).resolve().parents[1] / 'prepare_a850_driver_bundle.py')
prepare = importlib.util.module_from_spec(spec)
spec.loader.exec_module(prepare)
class A850BundleTest(unittest.TestCase):
def setUp(self):
self.temp = tempfile.TemporaryDirectory()
self.addCleanup(self.temp.cleanup)
self.root = Path(self.temp.name)
self.android = self.root / 'android.zip'
self.linux = self.root / 'linux.zip'
self.output = self.root / 'bundle.zip'
self.android_files = self.files('android')
self.linux_files = self.files('linux')
self.write(self.android, self.android_files)
self.write(self.linux, self.linux_files)
def files(self, platform):
elf = bytearray(64)
elf[:6] = b'\x7fELF\x02\x01'
struct.pack_into('<H', elf, 18, 183)
elf += b'libc.so.6\x00' if platform == 'linux' else b'libc.so\x00'
meta = ({'libc': 'glibc', 'kind': 'linux-vulkan-icd'} if platform == 'linux'
else {'libraryName': prepare.LIBRARY})
files = {'meta.json': json.dumps(meta).encode(), prepare.LIBRARY: bytes(elf)}
if platform == 'linux':
files['freedreno_icd.aarch64.json'] = json.dumps({'ICD': {'library_path': './' + prepare.LIBRARY}}).encode()
return files
def write(self, path, files):
with zipfile.ZipFile(path, 'w') as archive:
for name, data in files.items():
archive.writestr(name, data)
def pinned_fixture(self):
return mock.patch.multiple(prepare,
ANDROID_SHA256=hashlib.sha256(self.android.read_bytes()).hexdigest(),
LINUX_SHA256=hashlib.sha256(self.linux.read_bytes()).hexdigest())
def test_manifest_roundtrip_preserves_both_original_halves_and_is_deterministic(self):
with self.pinned_fixture():
prepare.prepare_bundle(self.android, self.linux, self.output)
first = self.output.read_bytes()
prepare.prepare_bundle(self.android, self.linux, self.output)
self.assertEqual(first, self.output.read_bytes())
with zipfile.ZipFile(self.output) as archive:
manifest = json.loads(archive.read('manifest.json'))
self.assertEqual('Adreno 850 community experimental', manifest['package'])
self.assertEqual('20261012-a850exp1', manifest['version'])
self.assertEqual(manifest['version'], manifest['tag'])
for platform, originals in (('android', self.android_files), ('linux', self.linux_files)):
directory = manifest['drivers'][platform]['path']
self.assertEqual(platform, directory)
for name, data in originals.items():
self.assertEqual(data, archive.read(directory + '/' + name))
self.assertIn(b'not native Adreno 850 support', archive.read('README.md'))
self.assertIn(b'issues/342', archive.read('NOTICE'))
def test_hash_mismatch_refuses_and_preserves_old_output(self):
self.output.write_bytes(b'previous bundle')
with self.assertRaisesRegex(ValueError, 'SHA256 mismatch'):
prepare.prepare_bundle(self.android, self.linux, self.output)
self.assertEqual(b'previous bundle', self.output.read_bytes())
def test_unsafe_extra_and_missing_entries_refused_before_output_write(self):
for entry in ('../escape', '/absolute', 'sub/../meta.json', 'sub\\meta.json', 'extra.so', None):
with self.subTest(entry=entry):
files = self.android_files.copy()
if entry is None:
files.pop(prepare.LIBRARY)
else:
files[entry] = b'unexpected'
self.write(self.android, files)
self.output.write_bytes(b'old')
with self.pinned_fixture(), self.assertRaisesRegex(ValueError, 'unsafe, extra or missing'):
prepare.prepare_bundle(self.android, self.linux, self.output)
self.assertEqual(b'old', self.output.read_bytes())
def test_bad_linux_half_does_not_replace_output(self):
self.linux_files['meta.json'] = b'{"libc":"bionic","kind":"linux-vulkan-icd"}'
self.write(self.linux, self.linux_files)
self.output.write_bytes(b'old')
with self.pinned_fixture(), self.assertRaisesRegex(ValueError, 'libc/kind'):
prepare.prepare_bundle(self.android, self.linux, self.output)
self.assertEqual(b'old', self.output.read_bytes())
def test_bad_android_library_name_refused(self):
self.android_files['meta.json'] = b'{"libraryName":"../evil.so"}'
self.write(self.android, self.android_files)
with self.pinned_fixture(), self.assertRaisesRegex(ValueError, 'libraryName'):
prepare.prepare_bundle(self.android, self.linux, self.output)
def test_wrong_elf_class_endian_architecture_and_libc_refused(self):
original = self.linux_files[prepare.LIBRARY]
for offset, replacement in ((4, 1), (5, 2), (18, 62)):
elf = bytearray(original)
elf[offset] = replacement
with self.subTest(offset=offset), self.assertRaisesRegex(ValueError, 'ELF64'):
prepare.validate_elf(elf, 'linux')
with self.assertRaisesRegex(ValueError, 'glibc'):
prepare.validate_elf(self.android_files[prepare.LIBRARY], 'linux')
with self.assertRaisesRegex(ValueError, 'AdrenoTools'):
prepare.validate_elf(original, 'android')
def test_output_cannot_overwrite_either_input_or_alias(self):
for source in (self.android, self.linux):
with self.subTest(source=source), self.assertRaisesRegex(ValueError, 'differ'):
prepare.prepare_bundle(self.android, self.linux, source)
alias = self.root / 'alias.zip'
alias.symlink_to(self.android)
with self.assertRaisesRegex(ValueError, 'differ'):
prepare.prepare_bundle(self.android, self.linux, alias)
def test_duplicate_and_symlink_entries_refused(self):
for duplicate in (True, False):
with self.subTest(duplicate=duplicate):
with zipfile.ZipFile(self.android, 'w') as archive:
for name, data in self.android_files.items():
info = zipfile.ZipInfo(name)
if not duplicate and name == prepare.LIBRARY:
info.create_system = 3
info.external_attr = (stat.S_IFLNK | 0o777) << 16
archive.writestr(info, data)
if duplicate:
import warnings
with warnings.catch_warnings():
warnings.simplefilter('ignore', UserWarning)
archive.writestr('meta.json', b'{}')
with self.pinned_fixture(), self.assertRaises(ValueError):
prepare.prepare_bundle(self.android, self.linux, self.output)
self.assertFalse(self.output.exists())
def test_malformed_icd_refused(self):
for icd in ({'ICD': []}, {'ICD': {'library_path': '../evil.so'}}):
with self.subTest(icd=icd):
self.linux_files['freedreno_icd.aarch64.json'] = json.dumps(icd).encode()
self.write(self.linux, self.linux_files)
with self.pinned_fixture(), self.assertRaisesRegex(ValueError, 'ICD library_path'):
prepare.prepare_bundle(self.android, self.linux, self.output)
def test_failed_replace_cleans_temporary_and_preserves_previous_output(self):
self.output.write_bytes(b'old')
with self.pinned_fixture(), mock.patch.object(prepare.os, 'replace', side_effect=OSError('fixture failure')):
with self.assertRaisesRegex(OSError, 'fixture failure'):
prepare.prepare_bundle(self.android, self.linux, self.output)
self.assertEqual(b'old', self.output.read_bytes())
self.assertEqual([], list(self.root.glob('.bundle.zip.*')))
if __name__ == '__main__':
unittest.main()