Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dist/
*.a
sof-remote-server/sof_remote_server
sof-remote-server/sof-remote
sof-remote-server/build-android-*/

# Virtual environments
.venv/
Expand Down
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ DEB_FILE := $(DIST_DIR)/$(PACKAGE)_$(VERSION)-$(RELEASE)_$(DEB_ARCH).deb
RPM_TOPDIR := $(abspath $(BUILD_DIR)/rpmbuild)

.PHONY: all build remote-server builder top testbench \
android android-push \
install uninstall check test ctest \
deb rpm package packages clean distclean help

Expand All @@ -75,6 +76,12 @@ build: remote-server builder top testbench
remote-server:
$(MAKE) -C sof-remote-server WORK_DIR="$(WORK_DIR)" all

android:
$(MAKE) -C sof-remote-server WORK_DIR="$(WORK_DIR)" android

android-push:
$(MAKE) -C sof-remote-server WORK_DIR="$(WORK_DIR)" android-push

builder:
$(MAKE) -C sof-builder PYTHON="$(PYTHON)" all

Expand Down Expand Up @@ -197,6 +204,7 @@ rpm:
--exclude='/dist' \
--exclude='/.git' \
--exclude='/sof-testbench/build' \
--exclude='build-android-*' \
--exclude='__pycache__' \
--exclude='*.pyc' \
--exclude='*.o' \
Expand Down Expand Up @@ -238,4 +246,6 @@ help:
@echo " make deb - Build Debian package in dist/*.deb"
@echo " make rpm - Build RPM package in dist/*.rpm"
@echo " make packages - Build both .deb and .rpm packages in dist/"
@echo " make android - Cross-compile sof_remote_server & sof-remote for Android (NDK/AOSP)"
@echo " make android-push - Build, adb push to /data/local/tmp/, and forward TCP port 9998"
@echo " make clean / distclean - Clean build artifacts"
36 changes: 32 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,44 @@ See [`sof-builder/README.md`](sof-builder/README.md) for full documentation, env

---

## Quick Start: `sof-top`
## Quick Start: `sof-top` & `sof-remote-server` (Linux & Android)

### Linux DUT Build
```bash
# Build sof_remote_server for DUTs:
make -C sof-remote-server
# Build sof_remote_server and sof-remote for Linux DUTs:
make remote-server
# or: make -C sof-remote-server

# Launch sof-top (Moving Core Graph + Moving SRAM/DRAM Memory Graph + DSP Task List):
./sof-top/sof-top --host aphid --wake
./sof-top/sof-top --host <dut-ip> --wake
```

### Android DUT Build (NDK, AOSP `make android`, CMake, or Soong)

`sof-remote-server` cross-compiles cleanly against Bionic (`NO_ALSA` + TinyALSA + TinyCompress + `liblog`):

```bash
# 1. Cross-compile with Android NDK (or set AOSP_DIR=/path/to/aosp):
make android ANDROID_NDK_HOME=/path/to/android-ndk ANDROID_ABI=arm64-v8a ANDROID_API=34
make android ANDROID_ABI=x86_64 # Default ABI

# 2. Push binaries to /data/local/tmp/ and forward TCP port 9998 over ADB:
make android-push ANDROID_ABI=arm64-v8a
adb shell /data/local/tmp/sof_remote_server -p 9998

# 3. Connect host tools (sof-top / sof-remote) over the ADB-forwarded loopback port:
./sof-top/sof-top --host 127.0.0.1 --port 9998
```

For security, Android builds bind `127.0.0.1` by default (use `-b <addr>` to override) and disable `host:` shell `popen()` execution unless `-E` is explicitly passed.

For in-tree AOSP integration:
- **Soong**: [`sof-remote-server/Android.bp`](sof-remote-server/Android.bp) builds `sof_remote_server` and `sof-remote` (`m sof_remote_server sof-remote`).
- **Init service**: [`sof-remote-server/sof_remote_server.rc`](sof-remote-server/sof_remote_server.rc) is opt-in on debuggable builds (`adb shell setprop persist.vendor.sof.remote_server.enable 1`).
- **SELinux**: Reference vendor policy files live in [`sof-remote-server/sepolicy/`](sof-remote-server/sepolicy/) (`BOARD_VENDOR_SEPOLICY_DIRS`).

See [`sof-remote-server/README.md`](sof-remote-server/README.md) for CMake Android toolchain flags and full setup details.

---

## License
Expand Down
47 changes: 47 additions & 0 deletions sof-remote-server/Android.bp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
package {
default_applicable_licenses: ["Android-Apache-2.0"],
}

cc_defaults {
name: "sof_remote_defaults",
vendor: true,
cflags: [
"-O2",
"-Wall",
"-Wextra",
"-Wno-unused-parameter",
"-DNO_ALSA",
"-DHAVE_TINYALSA",
"-DHAVE_TINYCOMPRESS",
],
}

cc_binary {
name: "sof_remote_server",
defaults: ["sof_remote_defaults"],
srcs: [
"sof_remote_server.c",
"audio_backend_alsa.c",
"audio_backend_tinyalsa.c",
"audio_backend_compress.c",
"dapm_inspector.c",
],
shared_libs: [
"libtinyalsa",
"libtinycompress",
"liblog",
],
init_rc: ["sof_remote_server.rc"],
}

cc_binary {
name: "sof-remote",
defaults: ["sof_remote_defaults"],
srcs: [
"sof_remote_cli.c",
],
shared_libs: [
"liblog",
],
}
32 changes: 21 additions & 11 deletions sof-remote-server/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
cmake_minimum_required(VERSION 3.19)
project(sof_remote_server LANGUAGES C)

add_executable(sof-remote sof_remote_cli.c)
target_include_directories(sof-remote PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(sof-remote PRIVATE pthread m)
if(ANDROID)
target_link_libraries(sof-remote PRIVATE m)
else()
target_link_libraries(sof-remote PRIVATE pthread m)
endif()
install(TARGETS sof-remote DESTINATION bin)

find_library(ASOUND_LIB NAMES asound libasound.so.2)
Expand All @@ -15,7 +20,7 @@ set(TINYCOMPR_INC "${SOF_WORK_DIR}/tinycompress/include" CACHE PATH "Path to tin
set(TINYCOMPR_OBJ1 "${SOF_WORK_DIR}/tinycompress/src/lib/.libs/libtinycompress_la-compress.o" CACHE FILEPATH "Path to tinycompress compress.o")
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)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

add_executable(sof_remote_server
sof_remote_server.c
audio_backend_alsa.c
Expand All @@ -26,10 +31,21 @@ if(ASOUND_LIB)
target_include_directories(sof_remote_server PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
)
if(EXISTS "${ALSA_INC}/alsa/asoundlib.h")
target_include_directories(sof_remote_server PRIVATE ${ALSA_INC})
if(ANDROID)
target_compile_definitions(sof_remote_server PRIVATE NO_ALSA)
target_link_libraries(sof_remote_server PRIVATE log dl m)
else()
if(EXISTS "${ALSA_INC}/alsa/asoundlib.h")
target_include_directories(sof_remote_server PRIVATE ${ALSA_INC})
endif()
target_link_libraries(sof_remote_server PRIVATE
${ASOUND_LIB}
dl
pthread
m
)
endif()
if(EXISTS "${TINYALSA_LIB}" AND EXISTS "${TINYALSA_INC}/tinyalsa/pcm.h")
if(EXISTS "${TINYALSA_LIB}" AND (EXISTS "${TINYALSA_INC}/tinyalsa/pcm.h" OR EXISTS "${TINYALSA_INC}/tinyalsa/asoundlib.h"))
target_compile_definitions(sof_remote_server PRIVATE HAVE_TINYALSA)
target_include_directories(sof_remote_server PRIVATE ${TINYALSA_INC})
target_link_libraries(sof_remote_server PRIVATE ${TINYALSA_LIB})
Expand All @@ -39,11 +55,5 @@ if(ASOUND_LIB)
target_include_directories(sof_remote_server PRIVATE ${TINYCOMPR_INC})
target_sources(sof_remote_server PRIVATE ${TINYCOMPR_OBJ1} ${TINYCOMPR_OBJ2})
endif()
target_link_libraries(sof_remote_server PRIVATE
${ASOUND_LIB}
dl
pthread
m
)
install(TARGETS sof_remote_server DESTINATION bin)
endif()
120 changes: 118 additions & 2 deletions sof-remote-server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,126 @@ SRV_OBJS := sof_remote_server.o \
audio_backend_compress.o \
dapm_inspector.o

.PHONY: all install uninstall clean
# -------------------------------------------------------------------------
# Android Cross-Compilation Support (NDK or AOSP Prebuilt Clang + Sysroot)
# Usage:
# make android [ANDROID_ABI=x86_64|arm64-v8a] [ANDROID_API=34]
# make android-push [ADB=adb]
# -------------------------------------------------------------------------
ANDROID_ABI ?= x86_64
ANDROID_API ?= 34
ANDROID_OUT_DIR ?= build-android-$(ANDROID_ABI)
ADB ?= adb
AOSP_DIR ?= $(firstword $(wildcard $(WORK_DIR)/work-extra/AOSP/wcl-desktop $(WORK_DIR)/AOSP))

ifeq ($(ANDROID_ABI),arm64-v8a)
ANDROID_TRIPLE := aarch64-linux-android
ANDROID_SOONG_ARCH := arm64
else ifeq ($(ANDROID_ABI),aarch64)
ANDROID_TRIPLE := aarch64-linux-android
ANDROID_SOONG_ARCH := arm64
else ifeq ($(ANDROID_ABI),armeabi-v7a)
ANDROID_TRIPLE := armv7a-linux-androideabi
ANDROID_SOONG_ARCH := arm
else ifeq ($(ANDROID_ABI),x86)
ANDROID_TRIPLE := i686-linux-android
ANDROID_SOONG_ARCH := x86
else
ANDROID_TRIPLE := x86_64-linux-android
ANDROID_SOONG_ARCH := x86_64
endif

ifneq ($(ANDROID_NDK_HOME),)
ANDROID_CLANG ?= $(firstword $(wildcard $(ANDROID_NDK_HOME)/toolchains/llvm/prebuilt/*/bin/clang))
ANDROID_SYSROOT ?= $(firstword $(wildcard $(ANDROID_NDK_HOME)/toolchains/llvm/prebuilt/*/sysroot))
else ifneq ($(AOSP_DIR),)
ANDROID_CLANG ?= $(lastword $(sort $(wildcard $(AOSP_DIR)/prebuilts/clang/host/linux-x86/clang-r*/bin/clang)))
ANDROID_SYSROOT ?= $(AOSP_DIR)/out/soong/ndk/sysroot
ANDROID_CRTBEGIN ?= $(dir $(firstword $(wildcard $(AOSP_DIR)/out/soong/.intermediates/bionic/libc/crtbegin_dynamic/android_$(ANDROID_SOONG_ARCH)*/crtbegin_dynamic.o)))
ANDROID_CRTEND ?= $(dir $(firstword $(wildcard $(AOSP_DIR)/out/soong/.intermediates/bionic/libc/crtend_android/android_$(ANDROID_SOONG_ARCH)*/crtend_android.o)))
endif

ANDROID_TINYALSA_DIR ?= $(firstword $(wildcard $(AOSP_DIR)/external/tinyalsa $(WORK_DIR)/tinyalsa))
ANDROID_TINYCOMPR_DIR ?= $(firstword $(wildcard $(WORK_DIR)/tinycompress $(AOSP_DIR)/external/tinycompress))

ANDROID_CRT_FLAGS := $(if $(ANDROID_CRTBEGIN),-B$(ANDROID_CRTBEGIN)) $(if $(ANDROID_CRTEND),-B$(ANDROID_CRTEND))

ANDROID_CFLAGS := --target=$(ANDROID_TRIPLE)$(ANDROID_API) \
--sysroot=$(ANDROID_SYSROOT) \
$(ANDROID_CRT_FLAGS) \
-O2 -Wall -Wextra -Wno-unused-parameter \
-Wno-unused-variable -Wno-unused-but-set-variable \
-Wno-sign-compare -Wno-macro-redefined \
-fPIE -pthread -DNO_ALSA
ANDROID_LDFLAGS := --target=$(ANDROID_TRIPLE)$(ANDROID_API) \
--sysroot=$(ANDROID_SYSROOT) \
$(ANDROID_CRT_FLAGS) \
-pie -llog -ldl -lm -lc

ANDROID_EXTRA_SRCS :=
ifneq ($(wildcard $(ANDROID_TINYALSA_DIR)/pcm.c),)
ANDROID_CFLAGS += -DHAVE_TINYALSA -I$(ANDROID_TINYALSA_DIR)/include
ANDROID_EXTRA_SRCS += $(ANDROID_TINYALSA_DIR)/pcm.c \
$(ANDROID_TINYALSA_DIR)/pcm_hw.c \
$(ANDROID_TINYALSA_DIR)/pcm_plugin.c \
$(ANDROID_TINYALSA_DIR)/mixer.c \
$(ANDROID_TINYALSA_DIR)/mixer_hw.c \
$(ANDROID_TINYALSA_DIR)/mixer_plugin.c \
$(ANDROID_TINYALSA_DIR)/snd_utils.c
else ifneq ($(wildcard $(ANDROID_TINYALSA_DIR)/src/pcm.c),)
ANDROID_CFLAGS += -DHAVE_TINYALSA -I$(ANDROID_TINYALSA_DIR)/include -I$(ANDROID_TINYALSA_DIR)/src
ANDROID_EXTRA_SRCS += $(ANDROID_TINYALSA_DIR)/src/pcm.c \
$(ANDROID_TINYALSA_DIR)/src/pcm_hw.c \
$(ANDROID_TINYALSA_DIR)/src/pcm_plugin.c \
$(ANDROID_TINYALSA_DIR)/src/mixer.c \
$(ANDROID_TINYALSA_DIR)/src/mixer_hw.c \
$(ANDROID_TINYALSA_DIR)/src/mixer_plugin.c \
$(ANDROID_TINYALSA_DIR)/src/snd_card_plugin.c \
$(ANDROID_TINYALSA_DIR)/src/limits.c
endif

ifneq ($(wildcard $(ANDROID_TINYCOMPR_DIR)/src/lib/compress.c),)
ANDROID_CFLAGS += -DHAVE_TINYCOMPRESS -I$(ANDROID_TINYCOMPR_DIR)/include
ANDROID_EXTRA_SRCS += $(ANDROID_TINYCOMPR_DIR)/src/lib/compress.c \
$(ANDROID_TINYCOMPR_DIR)/src/lib/compress_hw.c
endif

.PHONY: all android android-push install uninstall clean

all: sof_remote_server sof-remote

android:
@if [ -z "$(ANDROID_CLANG)" ] || [ ! -x "$(ANDROID_CLANG)" ]; then \
echo "ERROR: Android Clang not found. Set ANDROID_NDK_HOME or AOSP_DIR."; \
exit 1; \
fi
@if [ ! -d "$(ANDROID_SYSROOT)" ]; then \
echo "ERROR: Android sysroot not found at $(ANDROID_SYSROOT)"; \
exit 1; \
fi
mkdir -p $(ANDROID_OUT_DIR)
$(ANDROID_CLANG) $(ANDROID_CFLAGS) \
sof_remote_server.c \
audio_backend_alsa.c \
audio_backend_tinyalsa.c \
audio_backend_compress.c \
dapm_inspector.c \
$(ANDROID_EXTRA_SRCS) \
$(ANDROID_LDFLAGS) \
-o $(ANDROID_OUT_DIR)/sof_remote_server
$(ANDROID_CLANG) $(ANDROID_CFLAGS) \
sof_remote_cli.c \
$(ANDROID_LDFLAGS) \
-o $(ANDROID_OUT_DIR)/sof-remote
@echo "Built Android ($(ANDROID_TRIPLE)$(ANDROID_API)) binaries in $(ANDROID_OUT_DIR)/:"
@ls -lh $(ANDROID_OUT_DIR)/sof_remote_server $(ANDROID_OUT_DIR)/sof-remote

android-push: android
$(ADB) push $(ANDROID_OUT_DIR)/sof_remote_server $(ANDROID_OUT_DIR)/sof-remote /data/local/tmp/
$(ADB) shell chmod 0755 /data/local/tmp/sof_remote_server /data/local/tmp/sof-remote
$(ADB) forward tcp:9998 tcp:9998
@echo "Pushed to /data/local/tmp/ and forwarded localhost:9998 -> Android:9998"

audio_backend_alsa.o: audio_backend_alsa.c sof_remote_proto.h audio_backends.h
$(CC) $(CFLAGS) $(ALSA_CFLAGS) -c $< -o $@

Expand Down Expand Up @@ -84,4 +200,4 @@ uninstall:
"$(DESTDIR)$(BINDIR)/sof-remote"

clean:
rm -f *.o sof_remote_server sof-remote
rm -rf *.o sof_remote_server sof-remote build-android-*
Loading