#!/bin/sh
# Run an Android (bionic) program that uses the Mali GPU (OpenCL/GLES/Vulkan) inside the vendor chroot.
# usage: android-gpu-run /system/bin/cltest [args]   (path inside /opt/mu300/android)
set -e
A=/opt/mu300/android
[ -e /dev/mali0 ] || { modprobe sprd_gpu_cooling; modprobe mali_kbase; }
for n in $(seq 1 60); do mountpoint -q $A/dev && break; sleep 1; done
# OpenWrt's procd preloads /lib/libsetlbf.so into services; the bionic linker in the chroot cannot load it
unset LD_PRELOAD
export LD_LIBRARY_PATH=/apex/com.android.runtime/lib64/bionic:/system/lib64:/vendor/lib64:/vendor/lib64/egl:/vendor/lib64/hw:/apex/com.android.vndk.v33/lib64
exec chroot $A "$@"
