I'm struggling to compile the Linux kernel for usage in AOSP with KASAN & KCOV enabled. I then intend to flash it to a Pixel 2 XL (taimen) and use Syzkaller to fuzz it.
This is what I did:
1. Build unmodified kernel (works)
My reference: https://source.android.com/setup/build/building-kernels
Determine branch... android-msm-wahoo-4.4-pie-qpr2
$ repo init -u https://android.googlesource.com/kernel/manifest -b android-msm-wahoo-4.4-pie-qpr2
$ repo sync -j8 -c
$ build/build.sh -j8
Connect phone via USB
$ adb reboot bootloader
$ fastboot boot out/android-msm-wahoo-4.4/dist/Image.lz4-dtb
(Works fine)
2. Build kernel with KASAN & KCOV (fails)
To change kernel config symbols, edit POST_DEFCONFIG_CMDS in build/build.config
Copy from https://source.android.com/setup/build/building-kernels#customize-config
Modify as needed, use -d to disable, -e to enable a config option
Result:
POST_DEFCONFIG_CMDS="check_defconfig && update_debug_config"
function update_debug_config() {
${KERNEL_DIR}/scripts/config --file ${OUT_DIR}/.config \
-d CONFIG_KERNEL_LZ4 \
-e CONFIG_KASAN \
-e CONFIG_KASAN_INLINE \
-e CONFIG_KCOV \
-e CONFIG_SLUB \
-e CONFIG_SLUB_DEBUG \
--set-val FRAME_WARN 0
(cd ${OUT_DIR} && \
make O=${OUT_DIR} $archsubarch CC=${CC} CROSS_COMPILE=${CROSS_COMPILE} olddefconfig)
}
$ build/build.sh -j8
But after
CHK include/generated/compile.h
I get many undefined reference errors to various asan-symbols, e.g.
undefined reference to __asan_alloca_poison.
I did some research and read about adding -fsantitize=address and -shared-libasan (or -shared-libsan) to CFLAGS AND LDFLAGS. I did that (for which I had to hard-code it into build/build.sh, isn't there a more convenient way?), but to no avail:
I ended up with
aarch64-linux-android-ld: -f may not be used without -shared.
So I tried reading up on ld's -shared flag and adding it to LDFLAGS (more like a guess really). Resulted in
aarch64-linux-android-ld: -r and -shared may not be used together.
Really don't know where to go from here and what's going wrong in general?
Any help really appreciated!
Update: At first it seemed that using gcc instead of clang seemed to resolve the issue. The phone boots up fine, buttons work, but the touchscreen does not respond. I am looking into the reasons...
Regarding the touchscreen you need to manually copy required drivers to the AOSP folder. You can obtain fresh drivers from the kernel source code.
cd ${CONTAINER_GIT_REPO} && \
cp arch/arm64/boot/Image.lz4-dtb \$AOSP/device/google/wahoo-kernel/Image.lz4-dtb && \
cp arch/arm64/boot/dtbo.img $AOSP/device/google/wahoo-kernel/dtbo.img && \
cp drivers/input/touchscreen/stm/*.ko $AOSP/device/google/wahoo-kernel && \
cp drivers/power/*.ko $AOSP/device/google/wahoo-kernel && \
cp drivers/input/touchscreen/synaptics_dsx_htc/*.ko $AOSP/device/google/wahoo-kernel && \
cp drivers/input/touchscreen/lge/*.ko $AOSP/device/google/wahoo-kernel && \
cp drivers/input/touchscreen/lge/lgsic/*.ko $AOSP/device/google/wahoo-kernel && \
# Building final image for Pixel 2
cd \$AOSP && . build/envsetup.sh && lunch aosp_walleye-userdebug && make bootimage -j4
&& mkdir -p ${CONTAINER_GIT_REPO}/builded_images && \
cp out/target/product/walleye/*.img ${CONTAINER_GIT_REPO}/builded_images"
To obtain kernel source code:
git clone -b android-msm-wahoo-4.4-oreo-m2 --single-branch https://android.googlesource.com/kernel/msm
I have only Pixel 2 to check, but this should be applicable for both of them.
Update: You can check this repo for additional details https://gitlab.com/textor/build-pixel-2-in-docker
Maybe you can try to use the config file: ./private/msm-google/build.config.kasan
I used to use this config file and succeeded.
But the touchscreen didn't work, too.
Related
I am trying to set up a CI/CD pipeline for my android project using Jenkins and docker(I'm using docker file) and here's a sample of the Jenkinsfile
pipeline {
agent { dockerfile true }
environment {
appName = 'Yoruba Proverbs'
KEY_PASSWORD = credentials('keyPassword')
KEY_ALIAS = credentials('keyAlias')
KEYSTORE = credentials('keystore')
STORE_PASSWORD = credentials('storePassword')
}
stages {
....
}
}
The build fails at the instance when docker is trying to make a modification under the workspace directory with an operation not permitted error(FileSystemException). Here's a screenshot: build
I have tried a few different tweaks like restarting Jenkins, restarting docker, Granting docker full disk access on my laptop but no positive result
Edit:
This is the content of the Dockerfile
FROM openjdk:8
WORKDIR project/
# Install Build Essentials
RUN apt-get update \
&& apt-get install build-essential -y
# Set Environment Variables
ENV SDK_URL="https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip" \
ANDROID_HOME="/usr/local/android-sdk" \
ANDROID_VERSION=30
# Download Android SDK
RUN mkdir "$ANDROID_HOME" .android \
&& cd "$ANDROID_HOME" \
&& curl -o sdk.zip $SDK_URL \
&& unzip sdk.zip \
&& rm sdk.zip \
&& mkdir "$ANDROID_HOME/licenses" || true \
&& echo "24333f8a63b6825ea9c5514f83c2829b004d1fee" > "$ANDROID_HOME/licenses/android-sdk-license" \
&& yes | $ANDROID_HOME/tools/bin/sdkmanager --licenses
# Install Android Build Tool and Libraries
RUN $ANDROID_HOME/tools/bin/sdkmanager --update
RUN $ANDROID_HOME/tools/bin/sdkmanager "build-tools;30.0.3" \
"platforms;android-${ANDROID_VERSION}" \
"platform-tools"
CMD ["/bin/bash"]
I am trying to build a docker image for android, below is my docker file
FROM ubuntu:18.04
LABEL maintainer="Javier Santos"
ENV VERSION_SDK_TOOLS "4333796"
ENV ANDROID_HOME "/sdk"
ENV PATH "$PATH:${ANDROID_HOME}/tools"
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get -qq update
RUN apt-get install -y locales
RUN locale-gen en_US.UTF-8
ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' LC_ALL='en_US.UTF-8'
RUN apt-get install -qqy --no-install-recommends \
bzip2 \
curl \
git-core \
html2text \
openjdk-8-jdk \
libc6-i386 \
lib32stdc++6 \
lib32gcc1 \
lib32ncurses5 \
lib32z1 \
unzip \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN rm -f /etc/ssl/certs/java/cacerts; \
/var/lib/dpkg/info/ca-certificates-java.postinst configure
RUN curl -s https://dl.google.com/android/repository/sdk-tools-linux-${VERSION_SDK_TOOLS}.zip > /sdk.zip && \
unzip /sdk.zip -d /sdk && \
rm -v /sdk.zip
RUN mkdir -p $ANDROID_HOME/licenses/ \
&& echo "8933bad161af4178b1185d1a37fbf41ea5269c55\nd56f5187479451eabf01fb78af6dfcb131a6481e" > $ANDROID_HOME/licenses/android-sdk-license \
&& echo "84831b9409646a918e30573bab4c9c91346d8abd" > $ANDROID_HOME/licenses/android-sdk-preview-license
RUN yes | $ANDROID_HOME/tools/bin/sdkmanager "platforms;android-28"
ADD packages.txt /sdk
RUN mkdir -p /root/.android && \
touch /root/.android/repositories.cfg && \
${ANDROID_HOME}/tools/bin/sdkmanager --update
RUN while read -r package; do PACKAGES="${PACKAGES}${package} "; done < /sdk/packages.txt && \
${ANDROID_HOME}/tools/bin/sdkmanager ${PACKAGES}
But when I am building this, then Sending build context to Docker daemon is getting larger from 250GB and still increasing, Is this normal, or I am doing something wrong, please suggest, thanks in advance
I have taken reference from this link https://hub.docker.com/r/javiersantos/android-ci
The build context is not inside your Dockerfile, it's the path passed at the end of the build command, often a . to indicate the current directory. When building with compose it defaults to the current directory. So if this is growing, you have files in that context directory that are growing between builds.
With buildkit, this behavior changes, only sending the requested files rather than the full context. You can enable that by running export DOCKER_BUILDKIT=1 in the shell that runs the docker build command. You can also default this feature to enabled by setting the following in /etc/docker/daemon.json and then reloading the docker engine (often systemctl reload docker):
{
"features": {"buildkit": true }
}
Considering your build only adds a single file, probably the best option is to configure a .dockerignore in the root of your context (the same folder with the packages.txt file) with the following:
*
!packages.txt
The * ignores everything, and the !packages.txt reincludes that file back into the context.
I want to use "hplip" for printing from android device. Please tell me how can I build "hplip" and use in android.
Is there are any wrapper available for android?
See hplip documentation here
You can static build "hpijs" that is part of "hplib" and Ghostscript, it can run on Android.
print command like this:
gs -sDEVICE=ijs -sIjsServer=hpijs -dIjsUseOutputFD -sDeviceManufacturer="HEWLETT-PACKARD" -sDeviceModel="deskjet 5550" -r300x300 -dNOPAUSE -dSAFER -sOutputFile="/dev/usb/lp0" ruler.pdf -c quit
PS: long long ago "hpijs" is single, so you can get old version. here is a shell to build hpijs.(The comments of shell is Mother tongue, you can use Google Translate :) )
#!/bin/sh
# 说明:本脚本是交叉(ARM)编译hpijs-2.1.4
DESTDIR=${PWD}/_install
# 1.下载源码 项目地址:http://sourceforge.net/projects/hpinkjet/files/
wget http://superb-dca2.dl.sourceforge.net/project/hpinkjet/hpijs/2.1.4/hpijs-2.1.4.tar.gz &&
# 2.解压源码
tar xvzf hpijs-2.1.4.tar.gz && cd hpijs-2.1.4 &&
# 3.配置 说明:CXXFLAGS默认是"-g -O2",这里添加-static以静态编译hpijs
./configure --host=arm-linux --target=arm-linux --build=i686-linux CC=arm-linux-gcc CXX=arm-linux-g++ LD=arm-linux-ld RANLIB=arm-linux-ranlib AR=arm-linux-ar CXXFLAGS="-static -g -O2" --prefix=/ LDFLAGS=-L../jpeg-8b/.libs &&
# 4.修正语法错误 dj3320.cpp第403行和registry.cpp第249行 开头的char改为const char
sed -i '249s/\tchar\t/\tconst char\t/' registry.cpp &&
sed -i '403s/ char/ const char/' dj3320.cpp &&
# 5.编译并安装
make && make install DESTDIR=$DESTDIR
# 6.hpijs支持的打印机型号:hpijs-2.1.4/ppd查看.
# MDL MFG名字都在ppd文件中.
Hello I'm trying to build valgrind for android-arm. On Linux Mint 13 it fails with:
$ make
echo "# This is a generated file, composed of the following suppression rules:" > default.supp
echo "# " exp-sgcheck.supp xfree-3.supp xfree-4.supp glibc-2.X-drd.supp glibc-2.34567-NPTL-helgrind.supp glibc-2.X.supp >> default.supp
cat exp-sgcheck.supp xfree-3.supp xfree-4.supp glibc-2.X-drd.supp glibc-2.34567-NPTL-helgrind.supp glibc-2.X.supp >> default.supp
make all-recursive
make[1]: Entering directory `/home/matt/Desktop/valgrind/valgrind-3.8.1'
Making all in include
make[2]: Entering directory `/home/matt/Desktop/valgrind/valgrind-3.8.1/include'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/home/matt/Desktop/valgrind/valgrind-3.8.1/include'
Making all in VEX
make[2]: Entering directory `/home/matt/Desktop/valgrind/valgrind-3.8.1/VEX'
make all-am
make[3]: Entering directory `/home/matt/Desktop/valgrind/valgrind-3.8.1/VEX'
gcc -DHAVE_CONFIG_H -I. -I.. -I.. -I../include -I../VEX/pub -DVGA_arm=1 -DVGO_linux=1 -DVGP_arm_linux=1 -DVGPV_arm_linux_vanilla=1 -Ipriv -m32 -O2 -g -Wall -Wmissing-prototypes -Wshadow -Wpointer-arith -Wstrict-prototypes -Wmissing-declarations -Wno-format-zero-length -fno-strict-aliasing -fno-builtin -marm -mcpu=cortex-a8 -Wbad-function-cast -Wcast-qual -Wcast-align -fstrict-aliasing -Wno-long-long -Wno-pointer-sign -fno-stack-protector -MT libvex_arm_linux_a-main_globals.o -MD -MP -MF .deps/libvex_arm_linux_a-main_globals.Tpo -c -o libvex_arm_linux_a-main_globals.o `test -f 'priv/main_globals.c' || echo './'`priv/main_globals.c
gcc: warning: ‘-mcpu=’ is deprecated; use ‘-mtune=’ or ‘-march=’ instead
cc1: error: unrecognised command line option ‘-marm’
priv/main_globals.c:1:0: error: bad value (cortex-a8) for -mtune= switch
make[3]: *** [libvex_arm_linux_a-main_globals.o] Error 1
make[3]: Leaving directory `/home/matt/Desktop/valgrind/valgrind-3.8.1/VEX'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/home/matt/Desktop/valgrind/valgrind-3.8.1/VEX'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/matt/Desktop/valgrind/valgrind-3.8.1'
make: *** [all] Error 2
I am using ndk-r8e and valgrind 3.8.1. The configure ends with:
Maximum build arch: arm
Primary build arch: arm
Secondary build arch:
Build OS: linux
Primary build target: ARM_LINUX
Secondary build target:
Platform variant: vanilla
Primary -DVGPV string: -DVGPV_arm_linux_vanilla=1
Default supp files: exp-sgcheck.supp xfree-3.supp xfree-4.supp glibc-2.X-drd.supp glibc-2.34567-NPTL-helgrind.supp glibc-2.X.supp
What can I do to fix this? Alternatively, are there any pre-built android-arm valgrind binaries that I can use?
For building and installing Valgrind for Android use the bash script below, which I prefer to call build_valgrind.sh
To run with RUN_HELLO_JNI_THROUGH_VALGRIND=true you need two additional scripts (bootstrap_valgrind.sh, start_valgrind.sh) in the directory you run the script below from.
Running the script with the RUN_HELLO_JNI_THROUGH_VALGRIND=true flag will build the hello-jni application from the samples directory inside the Android NDK HOME, deploy it to the phone and run it through Valgrind, using either callgrind or memcheck tool, which you can specify in the start_valgrind.sh script.
The other two scripts are described here: https://stackoverflow.com/a/19235439/313113
Here's my directory structure:
|-- build_valgrind.sh (the script below)
|-- bootstrap_valgrind.sh (second script from https://stackoverflow.com/a/19235439/313113)
|-- start_valgrind.sh (first script from https://stackoverflow.com/a/19235439/313113)
|-- valgrind-3.10.0 (will be extracted by build_valgrind.sh)
`-- valgrind-3.10.0.tar.bz2 (will be downloaded by build_valgrind.sh)
I've tested that its working (memcheck and callgrind tools) on a Samsung Galaxy Nexus device with CyanogenMod 10.2.1 and Android 4.3.1 and CyanogenMod 11 20140804 snapshot, Android 4.4.4
You can see the file size of the generated output with: adb shell ls -lR "/sdcard/*grind*"
The build_valgrind.sh script:
#!/usr/bin/env bash
#set -x
function extract()
{
if [ -f "$1" ] ; then
case "$1" in
*.tar.bz2) tar xvjf "$1" ;;
*.tar.gz) tar xvzf "$1" ;;
*.bz2) bunzip2 "$1" ;;
*.rar) unrar x "$1" ;;
*.gz) gunzip "$1" ;;
*.tar) tar xvf "$1" ;;
*.tbz2) tar xvjf "$1" ;;
*.tgz) tar xvzf "$1" ;;
*.zip) unzip "$1" ;;
*.Z) uncompress "$1" ;;
*.7z) 7z x "$1" ;;
*) echo "$1 cannot be extracted via >extract<" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
RUN_HELLO_JNI_THROUGH_VALGRIND=true
VALGRIND_VERSION="3.10.0"
VALGRIND_EXTENSION=".tar.bz2"
VALGRIND_DIRECTORY="valgrind-${VALGRIND_VERSION}"
VALGRIND_TARBALL="valgrind-${VALGRIND_VERSION}${VALGRIND_EXTENSION}"
# Only download Valgrind tarball again if not already downloaded
if [[ ! -f "${VALGRIND_TARBALL}" ]]; then
wget -v -nc "http://valgrind.org/downloads/${VALGRIND_TARBALL}"
fi
# Only extract Valgrind tarball again if not already extracted
if [[ ! -d "$VALGRIND_DIRECTORY" ]]; then
extract "$VALGRIND_TARBALL"
fi
# Ensure ANDROID_NDK_HOME is set
if [[ ! -z "$ANDROID_NDK_HOME" ]]; then
export ANDROID_NDK_HOME="$HOME/Software/Android/android-ndk-r10c"
fi
# Ensure ANDOID_SDK_HOME is set
if [[ ! -z "$ANDROID_SDK_HOME" ]]; then
export ANDROID_SDK_HOME="$HOME/Software/Android/android-sdk/"
fi
if [[ ! -d "$VALGRIND_DIRECTORY" ]];
then
echo "Problem with extracting Valgrind from $VALGRIND_TARBALL into $VALGRIND_DIRECTORY!!!"
exit -1
fi
# Move to extracted directory
cd "$VALGRIND_DIRECTORY"
# ARM Toolchain
ARCH_ABI="arm-linux-androideabi-4.9"
export AR="$ANDROID_NDK_HOME/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar"
export LD="$ANDROID_NDK_HOME/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld"
export CC="$ANDROID_NDK_HOME/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc"
export CXX="$ANDROID_NDK_HOME/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++"
[[ ! -d "$ANDROID_NDK_HOME" || ! -f "$AR" || ! -f "$LD" || ! -f "$CC" || ! -f "$CXX" ]] && echo "Make sure AR, LD, CC, CXX variables are defined correctly. Ensure ANDROID_NDK_HOME is defined also" && exit -1
# Configure build
export HWKIND="nexus_s"
ANDROID_PLATFORM=android-18
export CPPFLAGS="--sysroot=$ANDROID_NDK_HOME/platforms/${ANDROID_PLATFORM}/arch-arm -DANDROID_HARDWARE_$HWKIND"
export CFLAGS="--sysroot=$ANDROID_NDK_HOME/platforms/${ANDROID_PLATFORM}/arch-arm"
# BUG: For some reason file command is unable to detect if the file does not exist with ! -f , it says it doesn't exist even when it does!!!
BUILD=false
if [[ "${VALGRIND_DIRECTORY}/Inst/data/local/Inst/bin/valgrind" = *"No such file or directory"* ]]; then
BUILD=true
fi
if [[ "$BUILD" = true ]];
then
./configure --prefix="/data/local/Inst" \
--host="armv7-unknown-linux" \
--target="armv7-unknown-linux" \
--with-tmpdir="/sdcard "
[[ $? -ne 0 ]] && echo "Can't configure!" && exit -1
# Determine the number of jobs (commands) to be run simultaneously by GNU Make
NO_CPU_CORES=$(grep -c ^processor /proc/cpuinfo)
if [ $NO_CPU_CORES -le 8 ]; then
JOBS=$(($NO_CPU_CORES+1))
else
JOBS=${NO_CPU_CORES}
fi
# Compile Valgrind
make -j "${JOBS}"
[[ $? -ne 0 ]] && echo "Can't compile!" && exit -1
# Install Valgrind locally
make -j "${JOBS}" install DESTDIR="$(pwd)/Inst"
[[ $? -ne 0 ]] && echo "Can't install!" && exit -1
fi
# Push local Valgrind installtion to the phone
if [[ $(adb shell ls -ld /data/local/Inst/bin/valgrind) = *"No such file or directory"* ]];
then
adb root
adb remount
adb shell "[ ! -d /data/local/Inst ] && mkdir /data/local/Inst"
adb push Inst /
adb shell "ls -l /data/local/Inst"
# Ensure Valgrind on the phone is running
adb shell "/data/local/Inst/bin/valgrind --version"
# Add Valgrind executable to PATH (this might fail)
adb shell "export PATH=$PATH:/data/local/Inst/bin/"
fi
if [ $RUN_HELLO_JNI_THROUGH_VALGRIND = true ]; then
PACKAGE="com.example.hellojni"
# The location of the Hello JNI sample application
HELLO_JNI_PATH="$ANDROID_NDK_HOME/samples/hello-jni"
pushd "$HELLO_JNI_PATH"
# Update build target to the desired Android SDK version
ANDROID_PROJECT_TARGET="android-18"
android update project --target "$ANDROID_PROJECT_TARGET" --path . --name hello-jni --subprojects
# Enable Android NDK build with Ant
echo '<?xml version="1.0" encoding="utf-8"?>
<project name="HelloJni" basedir="." default="debug">
<target name="-pre-build">
<exec executable="${ndk.dir}/ndk-build" failonerror="true"/>
</target>
<target name="clean" depends="android_rules.clean">
<exec executable="${ndk.dir}/ndk-build" failonerror="true">
<arg value="clean"/>
</exec>
</target>
</project>
' > "custom_rules.xml"
# Set NDK HOME for Ant (only if not already set)
if ! grep -P -q "ndk.dir=.+" "local.properties" ; then
echo -e "\nndk.dir=$ANDROID_NDK_HOME" >> "local.properties"
fi
# Fix for Java 8 warning (warning: [options] source value 1.5 is obsolete and will be removed in a future release)
echo "java.compilerargs=-Xlint:-options" >> "ant.properties"
# Workaround INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES error
adb uninstall "$PACKAGE"
# Build Hello JNI project in debug mode and install it on the device
ant clean && ant debug && ant installd
popd
cd ..
# Start HelloJNI app
adb shell am start -a android.intent.action.MAIN -n $PACKAGE/.HelloJni
# Make the script executable
chmod a+x bootstrap_valgrind.sh
# Run application through Valgrind on the phone
/usr/bin/env bash bootstrap_valgrind.sh
adb shell ls -lR "/sdcard/*grind*"
adb shell ls -lR "/storage/sdcard0/*grind*"
adb shell ls -lR "/storage/sdcard1/*grind*"
fi
exit 0
This gets valgrind to compile for me on linux. (using android-ndk-r8e and valgrind-3.8.1)
There was no need to run autogen.sh since I downloaded the tar ball from the website.
Also make sure the TOOLCHAIN= line points to a valid toolchain.
export NDK_HOME=$HOME/Downloads/android-ndk-r8e
export HWKIND=generic
export TOOLCHAIN=$NDK_HOME/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/arm-linux-androideabi
export AR=$TOOLCHAIN-ar
export LD=$TOOLCHAIN-ld
export CC=$TOOLCHAIN-gcc
CPPFLAGS="--sysroot=$NDK_HOME/platforms/android-14/arch-arm -DANDROID_HARDWARE_$HWKIND" \
CFLAGS="--sysroot=$NDK_HOME/platforms/android-14/arch-arm" \
./configure --prefix=/data/local/Inst \
--host=armv7-unknown-linux --target=armv7-unknown-linux \
--with-tmpdir=/sdcard
make
It eventually came up with a compile error saying
$NDK_HOME/platforms/android-14/arch-arm/usr/include/elf.h:58:3: error: unknown type name 'uint32_t'
It seem like someone forgot to add #include <stdint.h> somewhere. To fix this I edited $NDK_HOME/platforms/android-14/arch-arm/usr/include/elf.h and added #include <stdint.h> to the include section of this header. NOTE: This is probably not the best fix but it is the one that I came up with that fixed the compilation errors.
On mac I was able to get it to compile up until the unknown type uint32_t part by changing how the configure script checks the kernel version.
Inside the configure script search of a line kernel=`uname -r` and change it to kernel=3.9.2. (There are two kernel=`uname -r` lines replace the first one or both if you feel like it)
This stops the configure script from looking at the host kernel when deciding how it should build valgrind. (uname -r grabs the host kernel)
I believe adding the #include <stdint.h> to elf.h should work on mac to but I have not tested it.
in android tutorial one option is missed
RANLIB, after I set it - I finally compiled valgrind-3.11.0 on osx for android
#/bin/sh
echo "NKDROOT: " $NDKROOT
export ANRDOID_TOOLCHAIN="arm-linux-androideabi-4.9"
# Set up toolchain paths.
#
# For ARM
export AR=$NDKROOT/toolchains/$ANRDOID_TOOLCHAIN/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-ar
export LD=$NDKROOT/toolchains/$ANRDOID_TOOLCHAIN/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-ld
export CC=$NDKROOT/toolchains/$ANRDOID_TOOLCHAIN/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-gcc
export CXX=$NDKROOT/toolchains/$ANRDOID_TOOLCHAIN/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-g++
export RANLIB=$NDKROOT/toolchains/$ANRDOID_TOOLCHAIN/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-ranlib
echo "AR: " $AR
echo "LD: " $LD
echo "CC: " $CC
echo "CXX: " $CXX
[[ ! -d "$NDKROOT" || ! -f "$AR" || ! -f "$LD" || ! -f "$CC" || ! -f "$CXX" ]] && echo "Make sure AR, LD, CC, CXX variables are defined correctly. Ensure NDKROOT is defined also" && exit -1
./autogen.sh
#if [ $? -ne 0 ]
#then
# exit 1
#else
# echo "autogen success!"
#fi
# for ARM
ANDROID_PLATFORM=android-3
ANDROID_SYSROOT="$NDKROOT/platforms/${ANDROID_PLATFORM}/arch-arm"
echo "SYSROOT: " $ANDROID_SYSROOT
export HWKIND=generic
export CPPFLAGS="--sysroot=$ANDROID_SYSROOT -DANDROID_HARDWARE_$HWKIND"
export CFLAGS="--sysroot=$ANDROID_SYSROOT -DANDROID_HARDWARE_$HWKIND"
export LDFLAGS="--sysroot=$ANDROID_SYSROOT -DANDROID_HARDWARE_$HWKIND"
export ARFLAGS="--sysroot=$ANDROID_SYSROOT -DANDROID_HARDWARE_$HWKIND"
./configure \
--prefix=/data/local/Inst \
--host=armv7-unknown-linux --target=armv7-unknown-linux \
--with-tmpdir=/sdcard
if [ $? -ne 0 ]
then
exit 1
else
echo "configure success!"
fi
# note: on android emulator, android-14 platform was also tested and works.
# It is not clear what this platform nr really is.
make -j7
if [ $? -ne 0 ]
then
exit 1
else
echo "build success!"
fi
make -j7 install DESTDIR=`pwd`/Inst
The problem I had was that the configure script was ignoring the environment variables. To configure the make file I instead did this:
sudo ./configure --prefix=/data/local/Inst --host=armv7-unknown-linux --target=armv7-unknown-linux --with-tmpdir=/sdcard0 CPPFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm -DANDROID_HARDWARE_$HWKIND" CFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm" CC=$CC LD=$LD AR=$AR
This ensures the variables are set properly and works with Linux Mint 13. It does not work on OSX Mountain Lion however. I'd advise anyone using OSX without access to a linux installation to try using linux on a virtual machine.
I am trying to compile Frotz to run in a terminal emulator so it will execute on my Android Ice Cream Sandwich smartphone. Frotz is an open source Z-Machine interpreter for playing interactive fiction and is basically just a command-line application. I have done the following:
Downloaded Android NDK (android-ndk-r8d) and extracted it on my Windows 7 laptop. (Extracted to c:\android\android-ndk-r8d)
Downloaded and installed Cygwin, including all development packages. (So make is installed)
Using Cygwin, navigate to the folder containing the extracted Frotz makefile and source folder and try to execute make.
When I try run make, I encounter issues relating to curses.h not being found (but this issue is not the focus of this question; maybe a point for a followup question). When I do make dumb (which compiles a simplified version of Frotz), the compile succeeds and I am able to run it within Cygwin. But if I copy the compiled command-line application to the phone and try execute it, I get the following error:
not executable: magic 4D5A
I suspect the problem here is that the executable is now not compiled for the Arm architecture. The make file has the following line in it:
CC = gcc
which I have tried changing to:
CC = /cygdrive/c/android/android-ndk-r8d/toolchains/arm-linux-androideabi-4.7/prebuilt/windows/bin/arm-linux-androideabi-gcc.exe
But now when I execute make, I get the following error message:
fatal error: signal.h: No such file or directory
I am very new to C development (and Android) and struggling to figure out how to change the makefile so that it will compile correctly for Android. I will include the complete makefile below and will appreciate whatever help anyone can offer in getting this to correctly compile for Android.
The complete Frotz makefile:
# Define your C compiler. I recommend gcc if you have it.
# MacOS users should use "cc" even though it's really "gcc".
#
CC = gcc
#CC = cc
# Define your optimization flags. Most compilers understand -O and -O2,
# Standard (note: Solaris on UltraSparc using gcc 2.8.x might not like this.)
#
OPTS = -O2
# Pentium with gcc 2.7.0 or better
#OPTS = -O2 -fomit-frame-pointer -malign-functions=2 -malign-loops=2 \
#-malign-jumps=2
# Define where you want Frotz installed. Usually this is /usr/local
PREFIX = /usr/local
MAN_PREFIX = $(PREFIX)
#MAN_PREFIX = /usr/local/share
CONFIG_DIR = $(PREFIX)/etc
#CONFIG_DIR = /etc
# Define where you want Frotz to look for frotz.conf.
#
CONFIG_DIR = /usr/local/etc
#CONFIG_DIR = /etc
#CONFIG_DIR = /usr/pkg/etc
#CONFIG_DIR =
# Uncomment this if you want color support. Most, but not all curses
# libraries that work with Frotz will support color.
#
COLOR_DEFS = -DCOLOR_SUPPORT
# Uncomment this if you have an OSS soundcard driver and want classical
# Infocom sound support.
#
#SOUND_DEFS = -DOSS_SOUND
# Uncomment this too if you're running BSD of some sort and are using
# the OSS sound driver.
#
#SOUND_LIB = -lossaudio
# Define your sound device
# This should probably be a command-line/config-file option.
#
#SOUND_DEV = /dev/dsp
#SOUND_DEV = /dev/sound
#SOUND_DEV = /dev/audio
# If your vendor-supplied curses library won't work, uncomment the
# location where ncurses.h is.
#
#INCL = -I/usr/local/include
#INCL = -I/usr/pkg/include
#INCL = -I/usr/freeware/include
#INCL = -I/5usr/include
#INCL = -I/path/to/ncurses.h
# If your vendor-supplied curses library won't work, uncomment the
# location where the ncurses library is.
#
#LIB = -L/usr/local/lib
#LIB = -L/usr/pkg/lib
#LIB = -L/usr/freeware/lib
#LIB = -L/5usr/lib
#LIB = -L/path/to/libncurses.so
# One of these must always be uncommented. If your vendor-supplied
# curses library won't work, comment out the first option and uncomment
# the second.
#
CURSES = -lcurses
#CURSES = -lncurses
# Uncomment this if your need to use ncurses instead of the
# vendor-supplied curses library. This just tells the compile process
# which header to include, so don't worry if ncurses is all you have
# (like on Linux). You'll be fine.
#
#CURSES_DEF = -DUSE_NCURSES_H
# Uncomment this if you're compiling Unix Frotz on a machine that lacks
# the memmove(3) system call. If you don't know what this means, leave it
# alone.
#
#MEMMOVE_DEF = -DNO_MEMMOVE
# Uncomment this if for some wacky reason you want to compile Unix Frotz
# under Cygwin under Windoze. This sort of thing is not reccomended.
#
#EXTENSION = .exe
#####################################################
# Nothing under this line should need to be changed.
#####################################################
SRCDIR = src
VERSION = 2.43d
NAME = frotz
BINNAME = $(NAME)
DISTFILES = bugtest
DISTNAME = $(BINNAME)-$(VERSION)
distdir = $(DISTNAME)
COMMON_DIR = $(SRCDIR)/common
COMMON_TARGET = $(SRCDIR)/frotz_common.a
COMMON_OBJECT = $(COMMON_DIR)/buffer.o \
$(COMMON_DIR)/err.o \
$(COMMON_DIR)/fastmem.o \
$(COMMON_DIR)/files.o \
$(COMMON_DIR)/hotkey.o \
$(COMMON_DIR)/input.o \
$(COMMON_DIR)/main.o \
$(COMMON_DIR)/math.o \
$(COMMON_DIR)/object.o \
$(COMMON_DIR)/process.o \
$(COMMON_DIR)/quetzal.o \
$(COMMON_DIR)/random.o \
$(COMMON_DIR)/redirect.o \
$(COMMON_DIR)/screen.o \
$(COMMON_DIR)/sound.o \
$(COMMON_DIR)/stream.o \
$(COMMON_DIR)/table.o \
$(COMMON_DIR)/text.o \
$(COMMON_DIR)/variable.o
CURSES_DIR = $(SRCDIR)/curses
CURSES_TARGET = $(SRCDIR)/frotz_curses.a
CURSES_OBJECT = $(CURSES_DIR)/ux_init.o \
$(CURSES_DIR)/ux_input.o \
$(CURSES_DIR)/ux_pic.o \
$(CURSES_DIR)/ux_screen.o \
$(CURSES_DIR)/ux_text.o \
$(CURSES_DIR)/ux_audio_none.o \
$(CURSES_DIR)/ux_audio_oss.o
DUMB_DIR = $(SRCDIR)/dumb
DUMB_TARGET = $(SRCDIR)/frotz_dumb.a
DUMB_OBJECT = $(DUMB_DIR)/dumb_init.o \
$(DUMB_DIR)/dumb_input.o \
$(DUMB_DIR)/dumb_output.o \
$(DUMB_DIR)/dumb_pic.o
TARGETS = $(COMMON_TARGET) $(CURSES_TARGET)
OPT_DEFS = -DCONFIG_DIR="\"$(CONFIG_DIR)\"" $(CURSES_DEF) \
-DVERSION="\"$(VERSION)\"" -DSOUND_DEV="\"$(SOUND_DEV)\""
COMP_DEFS = $(OPT_DEFS) $(COLOR_DEFS) $(SOUND_DEFS) $(SOUNDCARD) \
$(MEMMOVE_DEF)
FLAGS = $(OPTS) $(COMP_DEFS) $(INCL)
$(NAME): $(NAME)-curses
$(NAME)-curses: soundcard.h $(COMMON_TARGET) $(CURSES_TARGET)
$(CC) -o $(BINNAME)$(EXTENSION) $(TARGETS) $(LIB) $(CURSES) \
$(SOUND_LIB)
all: $(NAME) d$(NAME)
dumb: $(NAME)-dumb
d$(NAME): $(NAME)-dumb
$(NAME)-dumb: $(COMMON_TARGET) $(DUMB_TARGET)
$(CC) -o d$(BINNAME)$(EXTENSION) $(COMMON_TARGET) \
$(DUMB_TARGET) $(LIB)
.SUFFIXES:
.SUFFIXES: .c .o .h
.c.o:
$(CC) $(FLAGS) $(CFLAGS) -o $# -c $<
# If you're going to make this target manually, you'd better know which
# config target to make first.
#
common_lib: $(COMMON_TARGET)
$(COMMON_TARGET): $(COMMON_OBJECT)
#echo
#echo "Archiving common code..."
ar rc $(COMMON_TARGET) $(COMMON_OBJECT)
ranlib $(COMMON_TARGET)
#echo
curses_lib: config_curses $(CURSES_TARGET)
$(CURSES_TARGET): $(CURSES_OBJECT)
#echo
#echo "Archiving curses interface code..."
ar rc $(CURSES_TARGET) $(CURSES_OBJECT)
ranlib $(CURSES_TARGET)
#echo
dumb_lib: $(DUMB_TARGET)
$(DUMB_TARGET): $(DUMB_OBJECT)
#echo
#echo "Archiving dumb interface code..."
ar rc $(DUMB_TARGET) $(DUMB_OBJECT)
ranlib $(DUMB_TARGET)
#echo
soundcard.h:
#if [ ! -f $(SRCDIR)/soundcard.h ] ; then \
sh $(SRCDIR)/misc/findsound.sh $(SRCDIR); \
fi
install: $(NAME)
strip $(BINNAME)$(EXTENSION)
install -d $(PREFIX)/bin
install -d $(MAN_PREFIX)/man/man6
install -c -m 755 $(BINNAME)$(EXTENSION) $(PREFIX)/bin
install -c -m 644 doc/$(NAME).6 $(MAN_PREFIX)/man/man6
uninstall:
rm -f $(PREFIX)/bin/$(NAME)
rm -f $(MAN_PREFIX)/man/man6/$(NAME).6
deinstall: uninstall
install_dumb: d$(NAME)
strip d$(BINNAME)$(EXTENSION)
install -d $(PREFIX)/bin
install -d $(MAN_PREFIX)/man/man6
install -c -m 755 d$(BINNAME)$(EXTENSION) $(PREFIX)/bin
install -c -m 644 doc/d$(NAME).6 $(MAN_PREFIX)/man/man6
uninstall_dumb:
rm -f $(PREFIX)/bin/d$(NAME)
rm -f $(MAN_PREFIX)/man/man6/d$(NAME).6
deinstall_dumb: uninstall_dumb
distro: dist
dist: distclean
mkdir $(distdir)
#for file in `ls`; do \
if test $$file != $(distdir); then \
cp -Rp $$file $(distdir)/$$file; \
fi; \
done
find $(distdir) -type l -exec rm -f {} \;
tar chof $(distdir).tar $(distdir)
gzip -f --best $(distdir).tar
rm -rf $(distdir)
#echo
#echo "$(distdir).tar.gz created"
#echo
clean:
rm -f $(SRCDIR)/*.h $(SRCDIR)/*.a
rm -f $(COMMON_DIR)/*.o $(CURSES_DIR)/*.o $(DUMB_DIR)/*.o
distclean: clean
rm -f $(BINNAME)$(EXTENSION) d$(BINNAME)$(EXTENSION)
rm -f $(BINNAME).exe $(BINNAME).bak $(BINNAME).lib
rm -f *core $(SRCDIR)/*core
-rm -rf $(distdir)
-rm -f $(distdir).tar $(distdir).tar.gz
realclean: distclean
clobber: distclean
help:
#echo
#echo "Targets:"
#echo " frotz"
#echo " dfrotz"
#echo " install"
#echo " uninstall"
#echo " clean"
#echo " distclean"
#echo
With android-ndk-r8d, you don't need cygwin: make can be found in c:\android\android-ndk-r8d\prebuilt\windows32\bin.
Anyways, to use a makefile, you should follow the instructions in c:\android\android-ndk-r8d\STANDALONE-TOOLCHAIN.html