diff --git a/device/cheetah/MODEM-CLIENT.md b/device/cheetah/MODEM-CLIENT.md index 8561bb114..665890420 100644 --- a/device/cheetah/MODEM-CLIENT.md +++ b/device/cheetah/MODEM-CLIENT.md @@ -52,8 +52,13 @@ Two packages: Units (`systemd/`), none enabled by the package: - `omamobile-sitd.service`: `Type=notify`, `Requires=`/`After=omamobile-modem.service`, - `ExecStart=omamobile-sitd --bringup`, `Restart=no` (a second start-up on - the same CP is not supported: reboot), `TimeoutStartSec=15min`. + `ExecStart=omamobile-sitd --bringup`, `Restart=no` (it never restarts on + its own), `TimeoutStartSec=15min`. A second start-up on the same CP after + a clean stop clears the earlier start's bearer records whose setup was + confirmed (a reservation with no confirmed outcome stays, and the start + refuses), withdraws the old IMS PDN with DelPdnInfo, and sets up again. + On the 9a this brought data back (2026-11-02); IMS after the withdrawal + hasn't run yet. After a failed start-up, reboot. - `omamobile-sit-data.service`: after the RIL is ready; `omamobile-sit data on|off` starts and stops it. - `/usr/lib/NetworkManager/conf.d/90-omamobile-rmnet.conf`: `rmnet*` unmanaged. diff --git a/device/cheetah/MODEM-PLAN.md b/device/cheetah/MODEM-PLAN.md index 608b9caa4..a788a3f51 100644 --- a/device/cheetah/MODEM-PLAN.md +++ b/device/cheetah/MODEM-PLAN.md @@ -1516,7 +1516,7 @@ tools/phone-ssh 'omamobile-sit status; systemctl is-active omamobile-sitd' # pass: "network: home LTE ..."; "IMS voice: yes, SMS: yes, data bearer: up"; active # stop: the unit fails (journal names the step: SIM timeout, registration deadline, "data call # did not become active" with its status, IMS deadline). Record the step and status, then reboot -# before another try (a second start-up on the same CP isn't supported; about one start in twenty +# before another try (a second start-up after a failed one isn't qualified; about one start in twenty # crashed the CP during registration on this phone model: the watcher records it) # rollback: `omamobile-sit radio off` (AT+CFUN=0: deregisters; turning it on again may stall # registration until a reboot), then `systemctl stop omamobile-sitd`; or reboot @@ -2510,8 +2510,9 @@ a status. About one fresh CP start in twenty crashed during registration on this phone model (section 4): a crash is recorded, and a reboot recovers it. -**A second start-up on the same CP is not supported**: after any failed -step, reboot before the next try. Every reboot with the modem up powers +**A second start-up after a failed step isn't qualified**: reboot before +the next try. (After a clean stop, a second start-up sets up again: +MODEM-CLIENT, the sitd unit.) Every reboot with the modem up powers it off: one recovered UFS error-handler pass, expected (M2.6, not yet attributed to an edge; M4.1j/M4.1k proved the reboot itself clean). diff --git a/device/tegu/CALL-AUDIO-TUNING.md b/device/tegu/CALL-AUDIO-TUNING.md new file mode 100644 index 000000000..a9b3c1c5f --- /dev/null +++ b/device/tegu/CALL-AUDIO-TUNING.md @@ -0,0 +1,186 @@ + +# Pixel 9a: call tuning and the first earpiece route + +Status, 2026-11-03: **implemented and tested offline, no phone trial**. +Branch `tegu-call-audio-aec-earpiece` builds on `sitd-tegu-call-audio` +(`d826388`); omamobile-modem-sit 0.3.13. AEC is off by default and call +audio still defaults to `card = none`. The earpiece mode below is a +conservative top-speaker route, not a reproduction of every stock codec +profile setting. This note records the remaining distinction explicitly. + +## Sources and the tuning transport + +Read the owner's saved 9a audio HAL, its AoC utility library, mixer paths, +platform configuration and factory-image `/vendor/etc/aoc` files as data. +No vendor program was run or copied into the repository. Compare the +functional interface with our GPL kernel at +[`253ddb231a89792ea845549c55fb0f04536c9317`](https://github.com/derekross/linux-omarchy-mobile/tree/253ddb231a89792ea845549c55fb0f04536c9317): +`drivers/soc/google/aoc/aoc-interface-gs201.h`, `aoc_char_dev.c`, +`alsa/aoc_alsa_ctl.c`, `alsa/aoc_alsa_hw.c`, and +`sound/soc/codecs/tas2781-{i2c,fmwlib}.c` / `include/sound/tas2x20-tlv.h`. +The kernel worktree is `~/android/mainline/wt-call-test`. + +Stock uses the `fmapmg3hybrid` telephony tuner. Its APMg3 adapter wraps +an unchanged protobuf with this **12-byte little-endian envelope**: + +| Offset | Type | Meaning used by the adapter | +| --- | --- | --- | +| 0 | u16 | 2 (envelope tag; its semantic name is not established here) | +| 2 | u16 | Total envelope plus protobuf length | +| 4 | u32 | 19 for uplink tuning, 20 for downlink tuning | +| 8 | u32 | Protobuf length | +| 12 | bytes | Original protobuf | + +Both operations use AoC address **block 19, component 24, address type 0**. +In `AocTuningCommands::SetParameterBulk`, type 0 selects +**`audio_output_tuning`**, not `audio_input_tuning`: block/component names +do not select the character channel. Write the envelope padded to a full +**16384-byte block** to `/dev/acd-audio_bulk_tx`, then send a **22-byte** +CMD_AUDIO_OUTPUT_SET_PARAMETER_BULK (ID 210 / `0x00d2`) record on +`/dev/acd-audio_output_tuning`: + +| Bytes | Field | +| --- | --- | +| 0, 1 | CMD type 0, counter | +| 2–3 | u16 length 22 | +| 4–5, 6–7 | u16 command ID 210, signed i16 reply initially 0 | +| 8, 9 | u8 block 19, component 24 | +| 10–13, 14–17 | u32 TX offset 0, TX address 0 | +| 18–21 | u32 envelope length, not the padding length | + +Stock's utility has a separate type-1 family using `audio_input_tuning`, +`audio_input_bulk_tx/rx`, ID 234 and a 5120-byte staging buffer. That is +not the APMg3 upload described above. Stock opens the output bulk RX service +as part of its generic descriptor set; this write-only implementation +needs no bulk RX read. The tuning reply comes back on the tuning service. + +`aoc_tuning.py` implements only the two uplink/downlink operations, with +bounded nonblocking writes, one-second readiness/acknowledgement deadlines, +exact record lengths, command/counter matching and a zero reply required. +It never resumes a short record, retries an unknown command, maps SRAM or +opens the CP/AoC shared voice window. `aoc_char_dev` makes the service +opens exclusive. An uncertain write/reply leaves the private RAM marker +`/run/omamobile-sit/aoc-voice-tuning-uncertain`; later tuning attempts refuse. +The unit already preserves its runtime directory. Do not delete the marker +to retry on the same AoC session. + +**Echo reference is a separate ALSA step.** +`VoiceCall::EchoReferencePath::Set` selects **FT AEC Reference Source = +SPEAKER** for the speaker and handset paths. Our kernel's setter caches +that choice; `aoc_audio_modem_mic_input()` uses it as the reference input +when constructing MODEM_INPUT_START_2. Set it before EP4 capture starts. +Its saved value is restored after the PCMs stop. There is no additional SIT +request. The existing EP4/EP5 preparation starts the modem voice path. + +`SendCommonCommand` is not the AEC protobuf transport. Its observed caller +here toggles **microphone compensation** with input-family command 355/356, +using an eight-byte CMD_HDR. Sending those would enable a different feature; +the implementation does not send them. The complete stock hybrid tuner's +band, volume and processing-mode policy is outside this first loader. +Actual echo cancellation still needs a far-end listening test. + +## Files and lifecycle + +`tools/extract-vendor-firmware -d tegu` now copies these six owner files +unchanged into **`usr/lib/firmware/updates/omamobile/tegu/aoc/`** in its +output tree, included in `vendor-firmware.sha256`: + +| Route | Uplink on | Uplink cleanup | Downlink | +| --- | --- | --- | --- | +| Speakerphone | `uplink_speaker_aec_on_config.pb` | `uplink_speaker_aec_off_config.pb` | `downlink_speaker_config.pb` | +| Earpiece | `uplink_handset_aec_on_config.pb` | `uplink_handset_aec_off_config.pb` | `downlink_handset_config.pb` | + +The source is `/vendor/etc/aoc/` in the owner's own 9a image. Do not use +another device's protobufs. HAC, wired, Bluetooth, dock and external-speaker +configs are unnecessary for these two routes. Missing any of these six +fails extraction. The loader requires the selected route's on, off and +downlink files before any upload. Files are not shipped in the package. + +With `[audio] tegu_aec = yes`, the route first saves the mixer state and +verifies sink mute, sets the echo reference, uploads uplink-on and downlink, +and starts capture/playback once with the existing voice parameters. It +then applies and reads back the amplifier attenuation before unmuting. +Hang-up mutes, stops both PCMs, sends the same route's uplink-off package, +closes the tuning services and restores the mixers. **This turns AEC off; +it does not claim to restore an unknown previous protobuf**, and leaves the +selected downlink tuning resident in the inactive telephony component. + +A missing or refused tuning setup refuses audio while call signalling +continues. Unknown setup or failed cleanup leaves the sink muted; the CP +is never stopped or reset. Tests cover cleanup, stale/mismatched/negative +acknowledgements, short writes and an unknown outcome blocking another call. + +## Earpiece mapping and the limit of the stock comparison + +The stock GPL TAS parser is +[Google amplifiers `33976d763bc0ace11603e7ecb207fc2b6e3f2608`](https://android.googlesource.com/kernel/google-modules/amplifiers/+/33976d763bc0ace11603e7ecb207fc2b6e3f2608/tas25xx/src/tas25xx-regbin-parser.c). +It builds playback-volume controls from the image's KCNTR table; values +are table indices, not decibels. A bounded private inspection of the owner's +table, following that parser, established: + +| Stock setting | Mainline mapping / implementation | +| --- | --- | +| PLAYBACK_VOLUME_LEFT = 55 | Its coefficient matches **tas2x20 DVC index 220 (unity)**, not index 55. Use a lower first-test level: **Top Speaker Digital Volume = 160 (-30 dB)** | +| Top amplifier only | **Bottom Speaker Digital Volume = 0**, read back before unmuting. This is the table's minimum (-110 dB), not power-off or a hardware mute | +| CODEC PROFILE = voice | Mainline exposes per-amplifier **Speaker Profile Id**, not the vendor enum. The examined native RCA's index **4** is `case05-voice-handset`, but that case contains only one power-state write. It lacks profile 0's full initialization. Selecting 4 on a fresh, uninitialized amplifier is not a complete voice route | +| EM LEFT/RIGHT = OFF | Mainline has **no EM mixer control**. The stock driver writes bits 7:6 of register 0:0:3. The examined full native profile 0 writes EM off; no userspace register write or invented control is added | +| AoC Modem Sink Channel Bitmap | **Read-only**: its SOC_SINGLE_EXT has a get handler and NULL put. It reports a sink's active channel bitmap; it is not a writable TDM-slot selector in this kernel | + +For the first usable top-only mode, retain the existing **full profile 0** +on both amplifiers, load handset AEC/downlink tuning, and attenuate/mute as +above. Refuse earpiece audio if the selected amplifier profiles are not 0, +or AEC was not enabled. This keeps startup on the already working native +initialization instead of treating a profile label as sufficient evidence. +Only the top is intended to be audible; the bottom still powers up. +Exact stock voice-profile and per-amplifier EM control remain a separate +firmware/kernel task if needed after this route is qualified. Gains have +not been acoustically qualified at the ear. + +Configuration (changes apply on the next **fresh CP** session): + +```ini +[audio] +card = none +tegu_aec = no +tegu_route = speaker +``` + +The attended trial chooses `card = auto`, `tegu_aec = yes`, then `speaker` +or `earpiece`. The earpiece mode does not affect the 7 Pro's CS35L41 route; +there is no mid-call route switch in this change. Do not enable it globally. + +## Verification and the attended gate + +Laptop checks, risk **low**, with synthetic service records and an ext4 +fixture containing fictional data only: + +```sh +tests/packages omamobile-modem-sit +tests/extract-tegu-call-tuning +tools/pr-check d826388 +``` + +Expect: all package tests, including the existing cheetah route and sit-sim +calls/SMS, pass; six synthetic tuning files are copied byte-for-byte and +checksummed; missing cleanup tuning fails; the PR gate passes. Stop on a +failure. Rollback is the parent branch or removal of this isolated +worktree. Nothing contacts the phone or executes the saved HAL. + +Before any phone trial, the human reviews a device-specific runbook and +approves the install and fresh boot. First **read-only**, confirm the NV +backup checksums, exact daily kernel/modules, mixer control availability, +profile files and their checksums, and no active call/PCMs. Keep the modem's +sleep inhibitor and once-per-boot rule. Record the actual `uname -r` with +results; no phone kernel release is claimed for these offline checks. + +Then test **speaker AEC only first**, with live kmsg streamed to the laptop, +a watchdog and the human ready to recover. Check command replies, gain +readbacks, two-way audio and the far end's echo before trying the earpiece +on another approved fresh session. Risk **medium**: new AoC tuning and an +unqualified acoustic path. Begin the earpiece test away from the ear at the +fixed attenuation. Stop on an AoC timeout/reset, any NV/UFS error, +unexpected gain, feedback, missing bottom attenuation or unconfirmed +cleanup. Hang up and retain the mute/uncertainty state. Never retry or reset +the running CP in place. Rollback is the previous package/config on an +attended fresh boot; no automatic unit restart, warm modem restart or +manual marker deletion. Hardware results: **not run**. diff --git a/docs/TELEPHONY-APPS-PLAN.md b/docs/TELEPHONY-APPS-PLAN.md index 1e4011606..e71d65364 100644 --- a/docs/TELEPHONY-APPS-PLAN.md +++ b/docs/TELEPHONY-APPS-PLAN.md @@ -207,6 +207,9 @@ On gs201 the voice path never passes through the application processor. **The Ao Beyond the mixer paths, the working stack on this phone model sets `Voice Call Audio Enable`, `Voice Call Mic Source` 1, `Incall Sink Mute` 0, `AoC Modem Downlink ASRC Mode` 1 and a mic gain of 130 cB plus 6 dB. It opens **PCM 4 playback (EP5)** and **PCM 11 capture (EP4)** (MODEM-PLAN 6.1). Our card numbers its PCMs as stock does (AGENTS.md), so those numbers hold. `omamobile-sitd`'s `voice_audio.py` does exactly this and restores every control after the call. Our sound card already describes the back ends these paths need: `BT_RX`/`BT_TX`, `USB_RX`/`USB_TX` and `INCALL_RX`/`INCALL_TX` (`device/cheetah/overlays/aoc-sound-test.dtso`). +The 9a's opt-in AEC upload and conservative earpiece route have a separate +[offline implementation and qualification note](../device/tegu/CALL-AUDIO-TUNING.md). + ### 2.2 The work, per audio route | Route | What's needed | Depends on | Effort | diff --git a/packages/omamobile-modem-sit/etc/omamobile/modem-sit.conf b/packages/omamobile-modem-sit/etc/omamobile/modem-sit.conf index e5a1d2232..a31b8fdea 100644 --- a/packages/omamobile-modem-sit/etc/omamobile/modem-sit.conf +++ b/packages/omamobile-modem-sit/etc/omamobile/modem-sit.conf @@ -147,3 +147,13 @@ earpiece = yes # louder and clean in calls on the 7 Pro) or 0 (stock). The 9a always uses # stock's 130 cB, with no boost. mic_boost_db = 6 + +# Experimental 9a call tuning, from this phone's own factory image. +# Keep off until an attended trial; card = none still disables all audio. +# AEC uploads owner files from /usr/lib/firmware/updates/omamobile/tegu/aoc. +tegu_aec = no +# speaker: both amplifiers at -20 dB; earpiece: top at -30 dB, bottom at +# the minimum digital gain. Earpiece requires tegu_aec = yes and the full +# amplifier profile 0; the stock voice profile has no standalone native +# equivalent. Changing routes mid-call is not implemented. +tegu_route = speaker diff --git a/packages/omamobile-modem-sit/lib/aoc_tuning.py b/packages/omamobile-modem-sit/lib/aoc_tuning.py new file mode 100644 index 000000000..0115c76f6 --- /dev/null +++ b/packages/omamobile-modem-sit/lib/aoc_tuning.py @@ -0,0 +1,121 @@ +# SPDX-License-Identifier: MIT +"""Bounded AoC telephony tuning upload, using the owner's tegu protobufs. + +Only the APMg3 telephony component on audio_output_tuning is addressed. +The GPL AoC interface defines CMD_HDR / SET_PARAMETER_BULK; the route +adapter adds an envelope with tag 2 around each unchanged protobuf. No +vendor executable, shared memory mapping, or arbitrary command API. +""" +import os +from pathlib import Path +import select +import struct + +from paths import RUN + +ROOT = Path('/usr/lib/firmware/updates/omamobile/tegu/aoc') +BULK_SIZE = 16384 +HEADER = struct.Struct(', ..."). PROTECTION = Path(os.environ.get('OMAMOBILE_SPK_STATUS', '/run/omamobile/speaker-protection')) STAGES = ('media', 'c8') @@ -50,6 +52,7 @@ # tas2x20_dvc_table in include/sound/tas2x20-tlv.h: index 220 is unity, # index 180 is -20 dB. Use the index, not the control's misleading dB TLV. TEGU_GAIN = '180' +TEGU_EARPIECE_GAIN = '160' # -30 dB; stock index 55 maps to unity (220) TEGU_GAINS = ('Top Speaker Digital Volume', 'Bottom Speaker Digital Volume') TEGU_ROUTE = ( ('Incall Sink Mute', '1'), @@ -106,7 +109,7 @@ class VoiceAudio: # without earpiece mode (no service installed, or [audio] earpiece = no) earpiece_cmd = None - def __init__(self, *, mic_boost_db=6, card=None, earpiece=True): + def __init__(self, *, mic_boost_db=6, card=None, earpiece=True, tegu_route='speaker', tegu_aec=False): if mic_boost_db not in (0, 6): raise ValueError('unsupported voice microphone boost') self.mic_boost_db = mic_boost_db @@ -118,6 +121,11 @@ def __init__(self, *, mic_boost_db=6, card=None, earpiece=True): # The protection service's earpiece mode is the 7 Pro's CS35L41 # route; the 9a's TAS2572 route sets its own gains. self.earpiece_cmd = None + if tegu_route not in ('speaker', 'earpiece'): + raise ValueError('unsupported tegu call route') + self.tegu_route = tegu_route + self.tegu_aec = tegu_aec + self.tuning = None self.saved = [] self.pcms = [] self.alsa = C.CDLL('libasound.so.2') @@ -267,14 +275,40 @@ def tegu_enter(self): return self # Read everything before changing anything. Mute is first so its # original value is restored last, after closing the voice PCMs. - names = [name for name, _ in TEGU_ROUTE] + list(TEGU_GAINS) - saved = [(name, self.mixer_value(name)) for name in names] + route = list(TEGU_ROUTE) + aec = getattr(self, 'tegu_aec', False) + earpiece = getattr(self, 'tegu_route', 'speaker') == 'earpiece' + if earpiece: + if not aec: + raise AudioRefused('tegu earpiece needs the handset AEC tuning enabled') + # The supplied RCA voice-handset case is only a delta, not a + # standalone initialization. Retain the full profile 0 for + # this conservative top-only route, never guess profile 4. + try: + profiles = [self.mixer_value(amp + ' Speaker Profile Id') for amp in ('Top', 'Bottom')] + except (OSError, RuntimeError, subprocess.TimeoutExpired) as error: + raise AudioRefused('tegu earpiece amplifier profile unavailable') from error + if profiles != ['0', '0']: + raise AudioRefused('tegu earpiece requires the full amplifier profile 0') + if aec: + route.insert(1, ('FT AEC Reference Source', 'SPEAKER')) + names = [name for name, _ in route] + list(TEGU_GAINS) + try: + saved = [(name, self.mixer_value(name)) for name in names] + except (OSError, RuntimeError, subprocess.TimeoutExpired) as error: + raise AudioRefused('tegu call mixer state unavailable') from error self.saved = saved try: - for name, value in TEGU_ROUTE: + for name, value in route: self.mixer('cset', name, value) if name == 'Incall Sink Mute' and self.mixer_value(name) not in ('1', 'on'): raise AudioRefused('tegu call audio refused: sink mute read-back mismatch') + if aec: + try: + self.tuning = VoiceTuning(self.tegu_route) + self.tuning.start() + except (OSError, TuningError) as error: + raise AudioRefused('tegu call audio refused: AoC tuning unavailable or unconfirmed') from error # Capture is ready before playback prepare starts the modem. for device, direction in ((11, 1), (4, 0)): pcm = C.c_void_p() @@ -285,20 +319,28 @@ def tegu_enter(self): self.check(self.alsa.snd_pcm_start(pcm), 'start') # The codec profile resets gain at playback start. These must # happen afterwards, while the modem downlink remains muted. - for name in TEGU_GAINS: - self.mixer('cset', name, TEGU_GAIN) - for name in TEGU_GAINS: + gains = ((TEGU_GAINS[1], '0'), (TEGU_GAINS[0], TEGU_EARPIECE_GAIN)) if earpiece else tuple( + (name, TEGU_GAIN) for name in TEGU_GAINS) + for name, gain in gains: + self.mixer('cset', name, gain) + for name, expected in gains: try: gain = self.mixer_value(name) except (OSError, RuntimeError, subprocess.TimeoutExpired) as error: raise AudioRefused('tegu call audio refused: TAS gain read-back unavailable') from error - if gain != TEGU_GAIN: + if gain != expected: raise AudioRefused('tegu call audio refused: TAS gain read-back mismatch') self.mixer('cset', 'Incall Sink Mute', '0') - print('AoC tegu speakerphone prepared at conservative TAS gain', flush=True) + print('AoC tegu ' + ('earpiece' if earpiece else 'speakerphone') + + ' prepared at conservative TAS gain', flush=True) return self - except BaseException: - self.__exit__(None, None, None) + except BaseException as error: + try: + self.__exit__(None, None, None) + except RuntimeError as cleanup: + if isinstance(error, AudioRefused): + raise AudioRefused('tegu call audio refused; cleanup unconfirmed, sink remains muted') from cleanup + raise raise def __exit__(self, *args): @@ -314,6 +356,13 @@ def __exit__(self, *args): if self.alsa.snd_pcm_close(pcm) < 0: failures.append('PCM close') self.pcms.clear() + if getattr(self, 'tuning', None) is not None: + try: + self.tuning.close() + except (OSError, TuningError): + failures.append('AoC tuning cleanup') + finally: + self.tuning = None for name, value in reversed(self.saved): if getattr(self, 'tegu', False) and name == 'Incall Sink Mute' and failures: continue # uncertain cleanup must leave the call sink muted diff --git a/packages/omamobile-modem-sit/systemd/omamobile-sitd.service b/packages/omamobile-modem-sit/systemd/omamobile-sitd.service index f235d22a7..54c9cc489 100644 --- a/packages/omamobile-modem-sit/systemd/omamobile-sitd.service +++ b/packages/omamobile-modem-sit/systemd/omamobile-sitd.service @@ -3,7 +3,9 @@ # bearer, IMS) and then serves calls and SMS on /run/omamobile-sit/socket. # Not enabled by the package: MODEM-PLAN.md M4 enables it after the gated # first runs. It needs the modem unit's CP ONLINE and never restarts on its -# own: a second start-up on the same CP is not supported (reboot instead). +# own. A second start-up on the same CP after a clean stop clears the earlier +# start's confirmed bearer records, withdraws its IMS PDN and sets up again +# (MODEM-CLIENT); after a failed start-up, reboot instead. [Unit] Description=Omarchy Mobile SIT RIL (S5300 calls, SMS, registration) # The device modem-policy package supplies its modem dependency as a drop-in. diff --git a/packages/omamobile-modem-sit/test/test_aoc_tuning.py b/packages/omamobile-modem-sit/test/test_aoc_tuning.py new file mode 100644 index 000000000..e7b34c18b --- /dev/null +++ b/packages/omamobile-modem-sit/test/test_aoc_tuning.py @@ -0,0 +1,172 @@ +# SPDX-License-Identifier: MIT +"""Synthetic AoC service records only; never open a device or use a blob.""" +import env # noqa: F401 +from pathlib import Path +import struct +import tempfile +import unittest +from unittest.mock import patch + +import aoc_tuning as tuning + + +class Services: + def __init__(self): + self.opened = [] + self.closed = [] + self.written = [] + self.reply = None + self.pending = False + self.timeout = False + self.short_fd = None + self.refuse = False + self.bad_reply = False + + def open(self, path, flags): + self.opened.append((path, flags)) + return 10 if path.endswith('output_tuning') else 11 + + def close(self, fd): + self.closed.append(fd) + + def select(self, read, write, errors, timeout): + if write: + return [], write, [] + return (read if (self.pending if timeout == 0 else not self.timeout) else []), [], [] + + def write(self, fd, data): + self.written.append((fd, data)) + if fd == 10: + reply = bytearray(data) + if self.refuse: + struct.pack_into('/dev/null || { echo "ok - tegu call tuning extraction # SKIP missing $tool"; exit 0; } +done +t=$(mktemp -d); trap 'rm -rf "$t"' EXIT +python3 - "$t/vendor" <<'PY' +from pathlib import Path +import sys +r = Path(sys.argv[1]) +files = { + 'build.prop': b'ro.product.vendor.device=tegu\nro.vendor.build.fingerprint=synthetic-test\n', + 'firmware/fw_bcmdhd.bin': b'4383a3-roml Version=1.2.3 (synthetic)', + 'firmware/bcmdhd.cal_4383_a3': b'NVRAMRev=synthetic\n', + 'firmware/bcmdhd_clm.blob_4383_a3': b'synthetic', + 'firmware/bcmdhd_txcap.blob_4383_a3': b'synthetic', + 'firmware/brcm/BCM.hcd': b'BCM4383A3 synthetic[test]', + 'firmware/aoc.bin': b'synthetic', + 'etc/sensors/registry/fictional.json': b'{}\n', +} +for name in ('cs40l26.wmfw', 'cs40l26-calib.wmfw'): + files['firmware/' + name] = b'WMFW' + bytes(6) + b'\x04FIRMWARE_CS40L26 BUZZ_EFFECTS2_BUZZ_LEVEL' +for name in ('cs40l26.bin', 'cs40l26-svc.bin', 'cs40l26-dvl.bin'): + files['firmware/' + name] = b'WMDR-synthetic' +for route in ('speaker', 'handset'): + for name in (f'uplink_{route}_aec_on_config.pb', f'uplink_{route}_aec_off_config.pb', + f'downlink_{route}_config.pb'): + files['etc/aoc/' + name] = b'synthetic-' + name.encode() +for name, data in files.items(): + path = r / name + path.parent.mkdir(parents=True, exist_ok=True) + path.write_bytes(data) +PY +truncate -s 16M "$t/vendor.img" +mkfs.ext4 -q -F -d "$t/vendor" "$t/vendor.img" +tools/extract-vendor-firmware -d tegu -o "$t/out" "$t/vendor.img" > "$t/log" 2>&1 || { cat "$t/log"; exit 1; } +for f in "$t/vendor/etc/aoc/"*.pb; do + cmp "$f" "$t/out/usr/lib/firmware/updates/omamobile/tegu/aoc/$(basename "$f")" +done +(cd "$t/out/usr/lib/firmware/updates" && sha256sum -c "$t/out/vendor-firmware.sha256" >/dev/null) +echo 'ok - all six tegu call tuning files copied unchanged and checksummed' +rm "$t/vendor/etc/aoc/uplink_handset_aec_off_config.pb" +mkfs.ext4 -q -F -d "$t/vendor" "$t/vendor.img" +if tools/extract-vendor-firmware -d tegu -o "$t/missing" "$t/vendor.img" > "$t/log" 2>&1; then + echo 'not ok - missing AEC-off cleanup file accepted' >&2; exit 1 +fi +grep -qF '/vendor/etc/aoc/uplink_handset_aec_off_config.pb is missing' "$t/log" +echo 'ok - missing cleanup tuning fails extraction' diff --git a/tools/extract-vendor-firmware b/tools/extract-vendor-firmware index 6ff18ab1c..44b6d3c71 100755 --- a/tools/extract-vendor-firmware +++ b/tools/extract-vendor-firmware @@ -45,6 +45,8 @@ # vendor/firmware/bcmdhd_clm.blob_4383_a3 -> brcm/brcmfmac4383-pcie..clm_blob (regulatory) # vendor/firmware/bcmdhd_txcap.blob_4383_a3 -> brcm/brcmfmac4383-pcie..txcap_blob (TX capabilities) # vendor/firmware/brcm/BCM.hcd -> brcm/BCM..hcd (btbcm) +# vendor/etc/aoc/{uplink_{speaker,handset}_aec_{on,off},downlink_{speaker,handset}}_config.pb +# -> omamobile/tegu/aoc/ (call tuning, unchanged owner files) # vendor/firmware/aoc.bin -> aoc-tegu.bin (the AoC DSP, under the 9a's own name) # vendor/etc/sensors/registry/ -> /usr/share/omamobile/sensors/registry/ # vendor/firmware/cs40l26*.{wmfw,bin} -> the same five files as cheetah's @@ -220,6 +222,12 @@ case $DEVICE_OPT in "firmware/bcmdhd_txcap.blob_4383_a3|brcm/$FW_BASE.$BOARD.txcap_blob" "firmware/brcm/BCM.hcd|brcm/BCM.$BOARD.hcd" "firmware/aoc.bin|aoc-tegu.bin" + "etc/aoc/uplink_speaker_aec_on_config.pb|omamobile/tegu/aoc/uplink_speaker_aec_on_config.pb" + "etc/aoc/uplink_speaker_aec_off_config.pb|omamobile/tegu/aoc/uplink_speaker_aec_off_config.pb" + "etc/aoc/downlink_speaker_config.pb|omamobile/tegu/aoc/downlink_speaker_config.pb" + "etc/aoc/uplink_handset_aec_on_config.pb|omamobile/tegu/aoc/uplink_handset_aec_on_config.pb" + "etc/aoc/uplink_handset_aec_off_config.pb|omamobile/tegu/aoc/uplink_handset_aec_off_config.pb" + "etc/aoc/downlink_handset_config.pb|omamobile/tegu/aoc/downlink_handset_config.pb" "firmware/cs40l26.wmfw|cs40l26.wmfw" "firmware/cs40l26.bin|cs40l26.bin" "firmware/cs40l26-svc.bin|cs40l26-svc.bin"