Repository navigation
sof-remote-server: Add Android (AOSP/NDK Bionic + TinyALSA) build support - #4
Conversation
lgirdwood
left a comment
There was a problem hiding this comment.
lets make sure we update the readme with build instructions and support
There was a problem hiding this comment.
🟡 Changes recommended
The boot service exposes unauthenticated root command execution when started, and unresolved Android build failures, SELinux startup requirements, and audio correctness defects remain.
6 open issues
Android CMake build still links CLI against unavailable pthread library · New ARM64 ABI spelling mismatch leaves Soong CRT object paths empty · New Unauthenticated root command server listens on all interfaces · New FLOAT_LE requests use S16 format without converting sample buffers · New Fallback mixer lookup assumes kernel control IDs are contiguous · New Missing SELinux policy prevents service startup on enforcing builds · New
What changed in this PR
Adds Android build and deployment support for the SOF remote telemetry server and CLI, adapting the existing Linux audio backends for Bionic and AOSP libraries.
Changes:
- Adds Soong targets, an Android init service, and standalone cross-build and ADB deployment commands.
- Adds compatibility handling for ALSA-free builds and differing TinyALSA/Tinycompress APIs.
- Adds Android firmware/debugfs paths, startup logging, and quick-start documentation.
| File | Description |
|---|---|
sof-remote-server/sof_remote_server.rc |
Defines boot startup on debuggable Android builds. |
sof-remote-server/sof_remote_server.c |
Adds Android defaults, startup logging, and discovery paths. |
sof-remote-server/Makefile |
Adds Android cross-compilation and ADB deployment. |
sof-remote-server/dapm_inspector.c |
Adds Android firmware and debugfs fallbacks. |
sof-remote-server/CMakeLists.txt |
Enables Android server builds and conditional linking. |
sof-remote-server/audio_backend_tinyalsa.c |
Adapts PCM and mixer operations for AOSP TinyALSA. |
sof-remote-server/audio_backend_compress.c |
Handles differing timestamp function signatures. |
sof-remote-server/audio_backend_alsa.c |
Supports builds without ALSA by forwarding to TinyALSA. |
sof-remote-server/Android.bp |
Defines vendor server and CLI Soong targets. |
README.md |
Documents Android build and deployment commands. |
Makefile |
Exposes Android targets and excludes artifacts from RPM sources. |
.gitignore |
Ignores Android build output directories. |
Review effort: Balanced
| set(TINYCOMPR_OBJ2 "${SOF_WORK_DIR}/tinycompress/src/lib/.libs/libtinycompress_la-compress_hw.o" CACHE FILEPATH "Path to tinycompress compress_hw.o") | ||
|
|
||
| if(ASOUND_LIB) | ||
| if(ASOUND_LIB OR ANDROID) |
There was a problem hiding this comment.
Fixed in commit eb31073 (sof-remote-server/CMakeLists.txt): sof-remote now links only m when if(ANDROID) (omitting pthread, which is integrated into Bionic libc) and keeps pthread m for non-Android builds. Also added project(sof_remote_server LANGUAGES C) so standalone CMake Android configures do not probe for a C++ compiler.
Verified via cmake -DCMAKE_SYSTEM_NAME=Android -DCMAKE_C_COMPILER=... -DCMAKE_C_COMPILER_TARGET=x86_64-linux-android34 linking sof-remote with -lm (and no -lpthread).
| ANDROID_CRTBEGIN ?= $(dir $(firstword $(wildcard $(AOSP_DIR)/out/soong/.intermediates/bionic/libc/crtbegin_dynamic/android_$(ANDROID_ABI)*/crtbegin_dynamic.o))) | ||
| ANDROID_CRTEND ?= $(dir $(firstword $(wildcard $(AOSP_DIR)/out/soong/.intermediates/bionic/libc/crtend_android/android_$(ANDROID_ABI)*/crtend_android.o))) |
There was a problem hiding this comment.
Fixed in commit eb31073 (sof-remote-server/Makefile): added ANDROID_SOONG_ARCH mapping (arm64-v8a/aarch64 -> arm64, armeabi-v7a -> arm, x86 -> x86, x86_64 -> x86_64) and updated ANDROID_CRTBEGIN/ANDROID_CRTEND globs to use android_$(ANDROID_SOONG_ARCH)*.
| on property:sys.boot_completed=1 && property:ro.debuggable=1 | ||
| start vendor.sof_remote_server |
There was a problem hiding this comment.
Fixed in commit eb31073 (sof-remote-server/sof_remote_server.c, sof-remote-server/sof_remote_server.rc):
sof_remote_servernow accepts-b <addr>(defaulting to127.0.0.1on Android and0.0.0.0on Linux) and-E/-S(disablinghost:shellpopen()execution by default on Android with-EACCES, requiring explicit-Eto opt in).sof_remote_server.rcnow launches with-b 127.0.0.1 -p 9998and is strictly opt-in (on property:persist.vendor.sof.remote_server.enable=1 && property:ro.debuggable=1).
Verified runtime loopback binding (ss -ltn) and -S/-E host: shell enforcement via sof-remote.
| #ifdef HAVE_TINYALSA_V2 | ||
| case SOF_PCM_FMT_FLOAT_LE: return PCM_FORMAT_FLOAT_LE; | ||
| #endif |
There was a problem hiding this comment.
Fixed in commit eb31073 (sof-remote-server/audio_backend_tinyalsa.c): changed sof_to_tinyalsa_format(uint32_t fmt_id, enum pcm_format *out_fmt) to return -ENOTSUP for unsupported formats (including SOF_PCM_FMT_FLOAT_LE when !HAVE_TINYALSA_V2 and unknown format IDs), and checked the return value before pcm_open() in both tinyalsa_pcm_play_frames() and tinyalsa_pcm_capture_frames().
Verified with a C unit test compiled against AOSP external/tinyalsa headers (!HAVE_TINYALSA_V2).
| (void)ctl; | ||
| return fallback_idx; |
There was a problem hiding this comment.
Fixed in commit eb31073 (sof-remote-server/audio_backend_tinyalsa.c): added tiny_elem_id_table_load() querying SNDRV_CTL_IOCTL_ELEM_LIST on /dev/snd/controlC%u so tinyalsa_kctl_list(), fill_tinyalsa_kctl_info(), and find_tiny_ctl() use the exact kernel struct snd_ctl_elem_id fields (numid, iface, device, subdevice, index) instead of fabricating idx + 1. When neither SNDRV_CTL_IOCTL_ELEM_LIST nor TinyALSA v2 IDs are available, kinfo->numid stays 0 and explicit-numid lookup fails cleanly rather than guessing i + 1.
Verified against local /dev/snd/controlC0 via unit test (tinyalsa_kctl_list matching SNDRV_CTL_IOCTL_ELEM_LIST).
| # SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) | ||
| # Android init service for SOF Remote Telemetry & Debug Server | ||
|
|
||
| service vendor.sof_remote_server /vendor/bin/sof_remote_server -p 9998 |
There was a problem hiding this comment.
Fixed in commit eb31073: added reference SELinux vendor policy files under sof-remote-server/sepolicy/ (file_contexts, property.te, property_contexts, and sof_remote_server.te wrapped in userdebug_or_eng(...)) and documented BOARD_VENDOR_SEPOLICY_DIRS integration in sof-remote-server/README.md.
|
@lgirdwood Updated documentation and addressed all PR #4 review comments in commit eb31073:
|


Summary
Adds Android (AOSP Soong and standalone NDK/AOSP Clang cross-compilation) build and deployment support for
sof-remote-server(sof_remote_serverandsof-remote):AOSP Soong Integration & Init Service:
sof-remote-server/Android.bpdefiningcc_binarytargets forsof_remote_serverandsof-remote(vendor: true, linkinglibtinyalsa,libtinycompress, andliblog).sof-remote-server/sof_remote_server.rcto startvendor.sof_remote_serveron boot whenro.debuggable=1.Standalone NDK / AOSP Cross-Compilation (
make android&make android-push):androidandandroid-pushtargets tosof-remote-server/Makefile, top-levelMakefile, andsof-remote-server/CMakeLists.txt.ANDROID_NDK_HOMEor an AOSP checkout (AOSP_DIR) and embedstinyalsaandtinycompressdirectly intobuild-android-<abi>/sof_remote_serverso it only depends on NDK system libraries (libc.so,libm.so,libdl.so,liblog.so) when pushed viaadb.Bionic & AOSP
external/tinyalsa/external/tinycompressAdaptations:audio_backend_alsa.c: Makesalsa-liboptional (HAVE_ALSA) and forwardsalsa_*calls totinyalsa_*when built withoutalsa-lib(-DNO_ALSA/__ANDROID__).audio_backend_tinyalsa.c: Supports both upstream TinyALSA v2 (<tinyalsa/pcm.h>,pcm_writei/pcm_readi) and AOSPexternal/tinyalsa(<tinyalsa/asoundlib.h>,pcm_write/pcm_read).audio_backend_compress.c: Uses C11_Generic(compr_get_tstamp_compat) to support both AOSP (unsigned long *) and upstream (unsigned int *)compress_get_tstampsignatures.sof_remote_server.c&dapm_inspector.c: Adds Androidlogcatlogging, defaultsg_tone_apitoSOF_AUDIO_API_TINYALSAon Android, and adds/vendor/firmwareand/ddebugfs fallback paths.Test Plan
make android(x86_64-linux-android34Bionic PIE binaries) andmake all(native Linuxx86_64binaries).readelf -donbuild-android-x86_64/sof_remote_server(NEEDED: liblog.so, libdl.so, libm.so, libc.so).