I want to replace a system library by one where I made some small changes. Both libraries were compiled with the same version of cyanogenmod source. The one I copied to the sdcard worked on an earlier flash of CM.
Now I try to run the following:
$ adb shell
shell#m0:/ $ su
root#m0:/ # mount -o rw,remount /system
root#m0:/ # chmod 777 /system/lib/libwilhelm.so
root#m0:/ # cp /sdcard/libwilhelm.so /system/lib/libwilhelm.so
root#m0:/ # chmod 644 /system/lib/libwilhelm.so
root#m0:/ # mount -o ro,remount /system
root#m0:/ # reboot
However even after reboot the old libwilhelm.so is used
I know this because I log something in the not-overriden version in
frameworks/wilhelm/src/sl_entry.c:
#include <android/log.h>
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "frameworks/wilhelm/src/sl_entry.c", __VA_ARGS__))
// ...
SL_API SLresult SLAPIENTRY slCreateEngine(SLObjectItf *pEngine, SLuint32 numOptions,
const SLEngineOption *pEngineOptions, SLuint32 numInterfaces,
const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired)
{
LOGI("qqqqqqqqqqqqqqqqqqqq in slCreateEngine");
//... continue original code
This log is then different in the other library that is on the sdcard. So the logcat should display something else once I replaced the library and rebooted but it still prints the original log message.
Also the library doesn't seem to be read from another location:
root#m0:/ # find . -name "libwilhelm*"
./mnt/shell/emulated/0/libwilhelm.so
./system/lib/libwilhelm.so
find: ./proc/1897/task/2088/fd/49: No such file or directory
find: ./proc/1897/task/2088/fd/57: No such file or directory
find: ./proc/1897/task/2100/fd/42: No such file or directory
find: ./proc/2466/task/2471/fd/88: No such file or directory
find: ./proc/2466/task/2741/fd/85: No such file or directory
find: ./proc/2466/task/2741/fd/95: No such file or directory
./data/media/0/libwilhelm.so
What did I miss?
Turns out frameworks/wilhelm/src/sl_entry.c is not part of the libwilhelm.so but the libOpenSLES.so
Moreover it is safer to replace the library by an updater-script that can be executed from a recovery program like TWRP. The script could look like:
ui_print("mounting /system");
mount("ext4", "EMMC", "/dev/block/mmcblk0p9", "/system");
ui_print("/system now mounted");
ui_print("adding new shared library libOpenSLES.so");
package_extract_file("libOpenSLES.so", "/system/lib/libOpenSLES.so");
ui_print("done adding new shared library libOpenSLES.so");
ui_print("unmounting /system");
unmount("/system");
ui_print("/system now unmounted");
ui_print("finished");
Related
CMakeLists.txt
STRING( REGEX REPLACE ".*/(.*)" "\\1" CURRENT_FOLDER ${CMAKE_CURRENT_SOURCE_DIR} )
SET(TARGET ${CURRENT_FOLDER})
PROJECT (${TARGET})
add_compile_options(-static -march=armv7-a)
aux_source_directory(./src SRCS)
add_executable(${TARGET} ${SRCS})
hello.c
#include <stdio.h>
int main(void)
{
printf("hello ARM!!!");
return 0;
}
adb push '.\Desktop\hello' /data/local/tmp
adb shell chmod 777 /data/local/tmp/hello
adb shell /data/local/tmp/hello
/system/bin/sh: /data/local/tmp/hello: No such file or directory
adb shell ls -l /data/local/tmp/
-rwxrwxrwx root root 10652 2021-01-21 17:03 hello
When I compile by the following command
arm-linux-gnueabi-gcc -static -march=armv7-a hello.c -o hello
adb push '.\Desktop\hello' /data/local/tmp
adb shell chmod 777 /data/local/tmp/hello
adb shell /data/local/tmp/hello
hello ARM!!!
I found that the compile_commands.json generated by cmake is
"command": "/bin/arm-linux-gnueabi-gcc-8 -g -static -march=armv7-a -o CMakeFiles/hello.dir/src/hello.c.o -c /home/dev/workspace/ASM/Projects/hello/src/hello.c",
I don't know how to solve this problem.
CMake use two steps to generate executable. The first step it compiles the source files ( c or c++) to object file. then it links the file needed to generate the executable(s).
The compile_commands.json will contain only the commands used to compile and not to link. normally you can find the command used to link in link.txt. this file can be found in CMakeFiles/<name>.dir/link.txt.
You can also , directly run your make commad with VERBOSE=1 to see the executed command on live.
For your problem, i think there is a problem with your TARGET variable, but without more information i can not be sure.
I keep getting an error when trying to create an apk with python-for-android. When I run this:
p4a apk --debug --sdk_dir=sdk --ndk_dir=ndk --ndk_version=r16b --private mnt/c/main.py --package=helloworld --name "Hello World" --version 0.1 --bootstrap=sdl2 --requirements=python2,kivy --arch=armeabi-v7a
I get the following error:
[INFO]: Will compile for the following archs: armeabi-v7a
[INFO]: Found Android API target in $ANDROIDAPI
[ERROR]: Could not find `android` or `sdkmanager` binaries in Android SDK. Exiting.
Traceback (most recent call last):
File "/usr/local/bin/p4a", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python2.7/dist-packages/pythonforandroid/toolchain.py", line 975, in main
ToolchainCL()
File "/usr/local/lib/python2.7/dist-packages/pythonforandroid/toolchain.py", line 512, in __init__
getattr(self, args.subparser_name.replace('-', '_'))(args)
File "/usr/local/lib/python2.7/dist-packages/pythonforandroid/toolchain.py", line 144, in wrapper_func
user_ndk_ver=self.ndk_version)
File "/usr/local/lib/python2.7/dist-packages/pythonforandroid/build.py", line 238, in prepare_build_environment
apis = [s for s in targets if re.match(r'^ *API level: ', s)]
UnboundLocalError: local variable 'targets' referenced before assignment
I am using Ubuntu 16.04. Here is my .bashrc file (scroll to bottom to see my additions):
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color) color_prompt=yes;;
esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u#\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u#\h:\w\$ '
fi
unset color_prompt force_color_prompt
# If this is an xterm set the title to user#host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u#\h: \w\a\]$PS1"
;;
*)
;;
esac
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''
s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
export ANDROIDSDK="~/sdk"
export ANDROIDNDK="~/ndk"
export ANDROIDAPI="19"
export ANDROIDNDKVER="r16b"
Note I downloaded the ndk from (https://developer.android.com/ndk/downloads/index.html) and the sdk from (https://developer.android.com/studio/index.html). I also installed platform tools and build-tools with sdkmanager. I am a complete beginner to python-for-android, so any help is greatly appreciated.
Error is pretty straightforward, you have a problem with SDK:
[ERROR]: Could not find android or sdkmanager binaries in
Android SDK. Exiting.
I'm not sure about how to make things right with Studio, but link to SDK that works:
https://dl.google.com/android/android-sdk_r24.4.1-linux.tgz
I am trying to load a simple Systemtap module on my GT-i9300
I get the error
Error inserting module '/sdcard/systemtap/modules/monitor_fopen.ko':
Unknown symbol in module
Steps that I took:
1. Get root on the device
I did this by installing this Rom
2. Build custom kernel
# ====================================================
# Add toolchain
user#ubuntu1210:~/Programs$ git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7
user#ubuntu1210:~$ sudo gedit .bashrc
# Toolchain
export PATH=${PATH}:~/Programs/arm-linux-androideabi-4.7/bin
# Reboot ubuntu
# ====================================================
# ====================================================
# Download and extract to ~/android/kernel :
# https://github.com/SlimRoms/kernel_samsung_smdk4412.git
user#ubuntu1210:~$ cd android/kernel/kernel_samsung_smdk4412/
# ====================================================
# ====================================================
# Set configuration for compiling
user#ubuntu1210:~/android/kernel/kernel_samsung_smdk4412$ make clean -j4 ARCH=arm SUBARCH=arm CROSS_COMPILE=arm-linux-androideabi-
user#ubuntu1210:~/android/kernel/kernel_samsung_smdk4412$ make ARCH=arm SUBARCH=arm CROSS_COMPILE=arm-linux-androideabi- slim_i9300_defconfig
user#ubuntu1210:~/android/kernel/kernel_samsung_smdk4412$ gedit .config
# Enable config parameters:
CONFIG_DEBUG_INFO, CONFIG_KPROBES, CONFIG_RELAY, CONFIG_DEBUG_FS, CONFIG_MODULES, CONFIG_MODULE_UNLOAD
# ====================================================
# Build Kernel
user#ubuntu1210:~/android/kernel/kernel_samsung_smdk4412$ make -j4 ARCH=arm SUBARCH=arm CROSS_COMPILE=arm-linux-androideabi-
3. Flash built zImage to device
# Download and extract bootimg_tools.zip from
# http://forum.xda-developers.com/showpost.php?p=44670032&postcount=12
#
# Download correct ROM .zip file and extract boot.img to the same folder as bootimg_tools
user#ubuntu1210:~/bootimg_tools$ perl split_bootimg.pl boot.img
user#ubuntu1210:~/bootimg_tools$ perl unpack_ramdisk boot.img-ramdisk.gz ramdisk
user#ubuntu1210:~/bootimg_tools$ perl repack_ramdisk ramdisk boot.img-ramdisk.cpio.gz
user#ubuntu1210:~/bootimg_tools$ cp /home/user/kernel_samsung_smdk4412/arch/arm/boot/zImage boot.img-kernel
user#ubuntu1210:~/bootimg_tools$ ./mkbootimg --kernel boot.img-kernel --ramdisk boot.img-ramdisk.cpio.gz --cmdline 'console=null androidboot.hardware=qcom user_debug=31 zcache' --base 0x80200000 --pagesize 2048 -o boot.img
# Download and install heimdall
# https://bitbucket.org/benjamin_dobell/heimdall/downloads
user#ubuntu1210:~/bootimg_tools$ adb reboot bootloader
user#ubuntu1210:~/bootimg_tools$ sudo heimdall flash --BOOT boot.img --verbose
4. Install systemtap on PC
user#ubuntu1210:~$ mkdir systemtap
user#ubuntu1210:~$ cd systemtap/
user#ubuntu1210:~/systemtap$ git clone https://github.com/flipreverse/systemtap-android.git
user#ubuntu1210:~/systemtap$ cd systemtap-android/
user#ubuntu1210:~/systemtap/systemtap-android$ git submodule init
user#ubuntu1210:~/systemtap/systemtap-android$ git submodule update
user#ubuntu1210:~/systemtap/systemtap-android$ sh build.sh
5. Create an .stp file
user#ubuntu1210:~$ cd /home/user/systemtap/systemtap-android/scripts/
user#ubuntu1210:~$ vi monitor_fopen.stp
#! /usr/bin/stap
probe begin
{
printf("start monitoring");
}
probe end
{
printf("end monitoring");
}
6. Build .ko file out of .stp file using compiled Kernel
user#ubuntu1210:~$ /home/user/systemtap/systemtap-android/installed/bin/stap
-p 4 -v
-a arm
-B CROSS_COMPILE=/home/user/Programs/arm-linux-androideabi-4.7/bin/arm-linux-androideabi-
-r /home/user/android/kernel/kernel_samsung_smdk4412/
-j /home/user/systemtap/systemtap-android/installed/share/systemtap/tapset/
-R /home/user/systemtap/systemtap-android/installed/share/systemtap/runtime/
-t -g -m monitor_fopen /home/user/systemtap/systemtap-android/scripts/monitor_fopen.stp
7. Install Systemtap Android App on the device that runs the custom Kernel
https://github.com/flipreverse/systemtap-android-app
8. Start the app and give the app root access
Superuser.apk should ask you whether Systemtap can have root access
9. Push the .ko file from step 6 to the sdcard
user#ubuntu1210:~$ adb push monitor_fopen.ko /sdcard/systemtap/modules/monitor_fopen.ko
10. Load the module
user#ubuntu1210:~$ adb shell
shell#android:/ $ su
root#android:/ # cd /data/data/com.systemtap.android
root#android:/data/data/com.systemtap.android # sh start_stap.sh
modulename=monitor_fopen
moduledir=/sdcard/systemtap/modules
outputname=monitor_fopen_2014.mm.dd_sss
outputdir=/sdcard/systemtap/stap_output
logdir=/sdcard/systemtap/stap_log
rundir=/sdcard/systemtap/stap_run
stapdir=/data/data/com.systemtap.android
:q!
11. Read result from loading the module
user#ubuntu1210:~$ adb shell
shell#android:/ $ cd sdcard/systemtap/stap_log/
shell#android:/sdcard/systemtap/stap_log $ cat monitor_fopen_2014.mm.dd_sss.txt
Loaded kernel module: monitor_fopen.ko
Output file: monitor_fopen_2014.mm.dd_sss.*
Error inserting module '/sdcard/systemtap/modules/monitor_fopen.ko': Unknown symbol in module
I have no idea in what step I went wrong. Does anyone have a clue?
thanks to #adelphus, he remembered me to use dmesg and I found the error:
Android: Unknown symbol _GLOBAL_OFFSET_TABLE_
With the help of this site I edited the Makefile of the kernel to
CFLAGS_MODULE = -fno-pic
Redoing all the other steps in my OP then worked.
Below is my .bashrc file
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
$export=$PATH:./home/ssrp/workspace/android-sdk-linux/platform-tools
$export PATH=$PATH:./home/ssrp/workspace/android-sdk-linux/tools
$export JAVA_HOME=./usr/lib/jvm/java-6-openjdk
$export NDK=./home/ssrp/workspace/android-ndk-r9
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color) color_prompt=yes;;
esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
The NDK and SDK folders are located as they are in the path in the .bashrc file, But it gives me the following output when I opened the terminal;
bash: =/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:./home/ssrp/workspace/android-sdk-linux/platform-tools: No such file or directory
bash: PATH=/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:./home/ssrp/workspace/android-sdk-linux/tools: No such file or directory
bash: JAVA_HOME=./usr/lib/jvm/java-6-openjdk: No such file or directory
bash: NDK=./home/ssrp/workspace/android-ndk-r9: No such file or directory
ssrp#ssrp-PC:~$
What could I be doing wrong here, could anyone specify?
For JAVA_HOME remove the first dot in the path. For NDK and PATH remove ./home/ssrp and put ~ instead. it should look like this:
$export PATH=$PATH:~/workspace/android-sdk-linux/tools:~/workspace/android-sdk-linux/platform-tools
$export JAVA_HOME=/usr/lib/jvm/java-6-openjdk
$export NDK=~/workspace/android-ndk-r9
I just built my goldfish android kernel. I wrote a hello world program and compiled using arm-linux-gnueabi-gcc. I used adb push to put the executable in /data/local of the emulated kernel. I was able to ssh into the emulated kernel using adb shell. When I cd into /data/local and ls the directory, I'm able to see the a.out which I had put using adb push. When I do #./a.out, I get the error ./a.out: not found.
Can some one help me on this.
I added the -static option during compilation worked. arm-linux-gnueabi-gcc -static
I guess it's a missing library problem. I have met this problem before, my fix is below:
root#evab:~# ./a.out
-sh: ./a.out: not found
root#evab:~# ls /lib /root
/lib:
libc.so.6
/root:
a.out
root#evab:~#
Then check which shared library is needed by the application:
leo#leo-VirtualBox:/opt/nfs/root$ arm-linux-readelf a.out -a |grep lib
[Requesting program interpreter: /lib/ld-linux.so.3]
0x00000001 (NEEDED) Shared library: [libc.so.6]
... ...
By the output, we can confirm that the ld-linux.so.3 is missing, so copy ld-linux.so.3 to target filesystem /lib directory:
root#evab:~# ./a.out
test
root#evab:~# ls /lib /root
/lib:
ld-linux.so.3 libc.so.6
/root:
a.out
root#evab:~#