From 0301c044ea220df72f44ae2b9dca6fc73d5149f9 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Fri, 30 Mar 2018 16:28:57 -0700 Subject: init Signed-off-by: Joel Fernandes --- README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..11c58f5 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +Project to give a rich Android development environment for end-users to use over adb. + +This will work only on rooted android devices that are running fairly recent Android (O or greater). -- cgit v1.2.3 From fcc4e6b5b3c42f48d1f864f98520f02cb46a2290 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Fri, 30 Mar 2018 16:56:20 -0700 Subject: Add utils Signed-off-by: Joel Fernandes --- src/utils/android | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100755 src/utils/android diff --git a/src/utils/android b/src/utils/android new file mode 100755 index 0000000..f5e7511 --- /dev/null +++ b/src/utils/android @@ -0,0 +1,12 @@ +#!/bin/bash -x +# Utilities to interact with android more easily + +cmd_exists() { + which $1 > /dev/null + return $? +} + +do_adb_root() { + adb root + return $? +} -- cgit v1.2.3 From 6c1ca314a3cc846a9c2c6fa2dbf8fe4cbdc9e742 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Fri, 30 Mar 2018 17:13:15 -0700 Subject: Update Signed-off-by: Joel Fernandes --- src/androdeb | 42 ++++++++++++++++++++++++++++++++++++++++++ src/utils/android | 2 ++ 2 files changed, 44 insertions(+) create mode 100755 src/androdeb diff --git a/src/androdeb b/src/androdeb new file mode 100755 index 0000000..5df8a2e --- /dev/null +++ b/src/androdeb @@ -0,0 +1,42 @@ +#!/bin/bash -e +set -x + +script_full_path=$( cd "$(dirname "$0")" ; pwd -P ) + +source $script_full_path/utils/android + +# Set default vars +DISTRO=buster + +# Parse command line parameters +POSITIONAL=() +while [[ $# -gt 0 ]] +do +key="$1" + +case $key in + -k|--kernelsrc) + KERNEL_PATH="$2" + shift || true # past argument + shift || true # past value + ;; + -t|--tempdir) + TMPDIR="$2" + shift || true # past argument + shift || true # past value + ;; + *) # unknown option + POSITIONAL+=("$1") # save it in an array for later + shift || true # past argument + ;; +esac +done + +set -- "${POSITIONAL[@]}" # restore positional parameters + +# Where do we want to store temporary files +if [[ -z ${TMPDIR+x} ]] || [[ ! -d "${TMPDIR}" ]]; then + TMPDIR=`mktemp` +fi + + diff --git a/src/utils/android b/src/utils/android index f5e7511..0cac1fa 100755 --- a/src/utils/android +++ b/src/utils/android @@ -1,6 +1,8 @@ #!/bin/bash -x # Utilities to interact with android more easily +script_full_path=$( cd "$(dirname "$0")" ; pwd -P ) + cmd_exists() { which $1 > /dev/null return $? -- cgit v1.2.3 From 83676b1dc68405ae82b3394611c14bdeb6606b97 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Fri, 30 Mar 2018 23:33:47 -0700 Subject: Update Signed-off-by: Joel Fernandes --- src/androdeb | 68 ++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 16 deletions(-) diff --git a/src/androdeb b/src/androdeb index 5df8a2e..560c06a 100755 --- a/src/androdeb +++ b/src/androdeb @@ -1,42 +1,78 @@ #!/bin/bash -e -set -x script_full_path=$( cd "$(dirname "$0")" ; pwd -P ) source $script_full_path/utils/android +usage() { + echo "androdeb" + echo " prepare Prepare the device (when running for the first time)" + echo " shell Enter the androdeb shell environment and get to work!" + echo "" + echo " --tracers Enable tracing packages (perf and trace-cmd)" + echo " --compilers Enable compilers on the FS (gcc and clang)" + echo " --editors Enable vim, emacs and git packages" + echo " --scheduler scheduler testing tools (only rt-app for now)" + echo " --bcc Build and install BCC from source" + echo " --fullbuild Enable all of the above tools" + echo "" + echo " --kernelsrc path-to-kernel-sources (can be used for bcc)" + echo " --tempdir use a specific temporary directory" + echo " --distro Debian distro to base on (default is buster)" + exit 1 +} + # Set default vars DISTRO=buster +PACKAGES="" # Parse command line parameters +PKG=0; if [ $# -lt 1 ]; then usage; fi POSITIONAL=() while [[ $# -gt 0 ]] do key="$1" case $key in - -k|--kernelsrc) - KERNEL_PATH="$2" - shift || true # past argument - shift || true # past value - ;; - -t|--tempdir) - TMPDIR="$2" - shift || true # past argument - shift || true # past value - ;; + prepare) + PREP=1; shift || true; ;; + shell) + SHELL=1; shift || true; ;; + --tracers) + TRACERS=1; PKG=1; shift || true; ;; + --compilers) + COMPILERS=1; PKG=1 shift || true; ;; + --editors) + EDITORS=1; PKG=1 shift || true; ;; + --scheduler) + SCHEDULER=1; PKG=1 shift || true; ;; + --fullbuild) + FULLBUILD=1; PKG=1 shift || true; ;; + --bcc) + BCC=1; PKG=1 shift || true; ;; + --kernelsrc) + KERNELSRC="$2"; shift || true; shift || true; ;; + --tempdir) + TMPDIR="$2"; shift || true; shift || true; ;; *) # unknown option - POSITIONAL+=("$1") # save it in an array for later - shift || true # past argument + echo "Unknown option ($1)"; usage ;; esac done set -- "${POSITIONAL[@]}" # restore positional parameters +if [[ ! -z ${PREP+x} ]] && [[ $PKG -eq 0 ]]; then; + echo "Need to specifify something to prepare"; usage; fi + +########################################################## +# PREPARE +########################################################## # Where do we want to store temporary files if [[ -z ${TMPDIR+x} ]] || [[ ! -d "${TMPDIR}" ]]; then - TMPDIR=`mktemp` -fi - + TMPDIR=`mktemp`; fi +echo $KERNELSRC +echo $BCC +echo $COMPILERS +echo $TRACERS -- cgit v1.2.3 From 5b4be9ce53af13fdf720d10198de2ac9faad3cd6 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Fri, 30 Mar 2018 23:58:27 -0700 Subject: Update Signed-off-by: Joel Fernandes --- src/androdeb | 64 +++++++++++++++++--------------------------------- src/packages/compilers | 4 ++++ src/packages/editors | 4 ++++ src/packages/scheduler | 3 +++ src/packages/tracers | 5 ++++ 5 files changed, 37 insertions(+), 43 deletions(-) create mode 100644 src/packages/compilers create mode 100644 src/packages/editors create mode 100644 src/packages/scheduler create mode 100644 src/packages/tracers diff --git a/src/androdeb b/src/androdeb index 560c06a..4c7ff54 100755 --- a/src/androdeb +++ b/src/androdeb @@ -1,14 +1,13 @@ #!/bin/bash -e +spath=$( cd "$(dirname "$0")" ; pwd -P ) -script_full_path=$( cd "$(dirname "$0")" ; pwd -P ) - -source $script_full_path/utils/android +source $spath/utils/android usage() { echo "androdeb" - echo " prepare Prepare the device (when running for the first time)" echo " shell Enter the androdeb shell environment and get to work!" echo "" + echo " prepare Prepare the device (when running for the first time)" echo " --tracers Enable tracing packages (perf and trace-cmd)" echo " --compilers Enable compilers on the FS (gcc and clang)" echo " --editors Enable vim, emacs and git packages" @@ -23,47 +22,29 @@ usage() { } # Set default vars -DISTRO=buster -PACKAGES="" +DISTRO=buster; PACKAGES="" # Parse command line parameters -PKG=0; if [ $# -lt 1 ]; then usage; fi -POSITIONAL=() -while [[ $# -gt 0 ]] -do -key="$1" - +if [ $# -lt 1 ]; then usage; fi; POSITIONAL=() +while [[ $# -gt 0 ]]; do; key="$1" case $key in - prepare) - PREP=1; shift || true; ;; - shell) - SHELL=1; shift || true; ;; - --tracers) - TRACERS=1; PKG=1; shift || true; ;; - --compilers) - COMPILERS=1; PKG=1 shift || true; ;; - --editors) - EDITORS=1; PKG=1 shift || true; ;; - --scheduler) - SCHEDULER=1; PKG=1 shift || true; ;; - --fullbuild) - FULLBUILD=1; PKG=1 shift || true; ;; - --bcc) - BCC=1; PKG=1 shift || true; ;; - --kernelsrc) - KERNELSRC="$2"; shift || true; shift || true; ;; - --tempdir) - TMPDIR="$2"; shift || true; shift || true; ;; - *) # unknown option - echo "Unknown option ($1)"; usage - ;; + prepare) PREP=1; shift || true; ;; + shell) SHELL=1; shift || true; ;; + --tracers) TRACERS=1; source $spath/packages/tracers; shift || true; ;; + --compilers) COMPILERS=1; source $spath/packages/compilers; shift || true; ;; + --editors) EDITORS=1; source $spath/packages/editors; shift || true; ;; + --scheduler) SCHEDULER=1; source $spath/packages/scheduler; shift || true; ;; + --fullbuild) FULLBUILD=1; for f in $(ls $spath/packages); do source packages/$f; done; shift || true; ;; + --bcc) BCC=1; shift || true; ;; + --kernelsrc) KERNELSRC="$2"; shift || true; shift || true; ;; + --tempdir) TMPDIR="$2"; shift || true; shift || true; ;; + *) echo "Unknown option ($1)"; usage; ;; esac done -set -- "${POSITIONAL[@]}" # restore positional parameters - -if [[ ! -z ${PREP+x} ]] && [[ $PKG -eq 0 ]]; then; - echo "Need to specifify something to prepare"; usage; fi +if [[ ! -z ${PREP+x} ]] && [[ "x$PACKAGES" == "x" ]]; then + echo "Need to specifify something to prepare"; usage; +fi ########################################################## # PREPARE @@ -72,7 +53,4 @@ if [[ ! -z ${PREP+x} ]] && [[ $PKG -eq 0 ]]; then; if [[ -z ${TMPDIR+x} ]] || [[ ! -d "${TMPDIR}" ]]; then TMPDIR=`mktemp`; fi -echo $KERNELSRC -echo $BCC -echo $COMPILERS -echo $TRACERS +echo $PACKAGES diff --git a/src/packages/compilers b/src/packages/compilers new file mode 100644 index 0000000..d2d764a --- /dev/null +++ b/src/packages/compilers @@ -0,0 +1,4 @@ +PACKAGES+="\ +clang-6.0 +gcc +" diff --git a/src/packages/editors b/src/packages/editors new file mode 100644 index 0000000..9860e90 --- /dev/null +++ b/src/packages/editors @@ -0,0 +1,4 @@ +PACKAGES+="\ +emacs +vim +" diff --git a/src/packages/scheduler b/src/packages/scheduler new file mode 100644 index 0000000..5d70217 --- /dev/null +++ b/src/packages/scheduler @@ -0,0 +1,3 @@ +PACKAGES+="\ +rt-app +" diff --git a/src/packages/tracers b/src/packages/tracers new file mode 100644 index 0000000..4dee51a --- /dev/null +++ b/src/packages/tracers @@ -0,0 +1,5 @@ +PACKAGES+="\ +perf +trace-cmd +strace +" -- cgit v1.2.3 From 4fb97ea102e4a0fe0446540c1833abeb113d3224 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sat, 31 Mar 2018 11:15:19 -0700 Subject: Update Signed-off-by: Joel Fernandes --- src/.gitignore | 1 + src/addons/bashrc | 4 ++++ src/addons/device-unpack.sh | 6 ++++++ src/addons/run-chroot | 12 ++++++++++++ src/addons/run-chroot-command | 8 ++++++++ src/androdeb | 38 +++++++++++++++++++++++++++----------- src/packages/bcc | 23 +++++++++++++++++++++++ src/packages/compilers | 5 +++++ src/packages/editors | 3 ++- src/packages/scheduler | 1 + src/packages/tracers | 2 +- src/utils/android | 26 +++++++++++++++++++++++++- 12 files changed, 115 insertions(+), 14 deletions(-) create mode 100644 src/.gitignore create mode 100644 src/addons/bashrc create mode 100755 src/addons/device-unpack.sh create mode 100755 src/addons/run-chroot create mode 100755 src/addons/run-chroot-command create mode 100644 src/packages/bcc diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 0000000..15c6bf7 --- /dev/null +++ b/src/.gitignore @@ -0,0 +1 @@ +tmpdir diff --git a/src/addons/bashrc b/src/addons/bashrc new file mode 100644 index 0000000..2b48d5c --- /dev/null +++ b/src/addons/bashrc @@ -0,0 +1,4 @@ +# Create a more sane trace development environment! + +export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/share/bcc/tools/ +export TMPDIR=/tmp/ diff --git a/src/addons/device-unpack.sh b/src/addons/device-unpack.sh new file mode 100755 index 0000000..3339f43 --- /dev/null +++ b/src/addons/device-unpack.sh @@ -0,0 +1,6 @@ +#!/system/bin/sh + +cd /data/ +rm -rf debian +tar -xf debian.tar.gz +rm debian.tar.gz diff --git a/src/addons/run-chroot b/src/addons/run-chroot new file mode 100755 index 0000000..ea2f662 --- /dev/null +++ b/src/addons/run-chroot @@ -0,0 +1,12 @@ +#!/system/bin/sh + +cd /data/ +mount -t proc /proc debian/proc/ > /dev/null +mount --rbind /dev debian/dev/ > /dev/null +mount --rbind /sys debian/sys/ > /dev/null +mount --rbind /sys/kernel/debug/ debian/sys/kernel/debug/ > /dev/null +mount --rbind /sys/kernel/debug/tracing/ debian/sys/kernel/debug/tracing/ +if [ -d /system/ ]; then + mount --bind /system debian/system/ +fi +chroot debian/ /bin/bash --rcfile /bashrc diff --git a/src/addons/run-chroot-command b/src/addons/run-chroot-command new file mode 100755 index 0000000..9a99836 --- /dev/null +++ b/src/addons/run-chroot-command @@ -0,0 +1,8 @@ +#!/system/bin/sh + +# Directly execute a command within the chroot of an Android device + +CHROOT_PATH=$1 +CMD=$2 + +chroot $CHROOT_PATH /bin/bash -i -c $CMD diff --git a/src/androdeb b/src/androdeb index 4c7ff54..9921d7f 100755 --- a/src/androdeb +++ b/src/androdeb @@ -1,8 +1,11 @@ #!/bin/bash -e spath=$( cd "$(dirname "$0")" ; pwd -P ) +curdir=$( pwd -P ) source $spath/utils/android +if [[ $EUID -ne 0 ]]; then echo "This tool must be run as root"; exit 3; fi + usage() { echo "androdeb" echo " shell Enter the androdeb shell environment and get to work!" @@ -22,20 +25,20 @@ usage() { } # Set default vars -DISTRO=buster; PACKAGES="" +DISTRO=buster; PACKAGES=""; ARCH=arm64 # Parse command line parameters if [ $# -lt 1 ]; then usage; fi; POSITIONAL=() -while [[ $# -gt 0 ]]; do; key="$1" +while [[ $# -gt 0 ]]; do key="$1"; case $key in prepare) PREP=1; shift || true; ;; shell) SHELL=1; shift || true; ;; - --tracers) TRACERS=1; source $spath/packages/tracers; shift || true; ;; - --compilers) COMPILERS=1; source $spath/packages/compilers; shift || true; ;; - --editors) EDITORS=1; source $spath/packages/editors; shift || true; ;; - --scheduler) SCHEDULER=1; source $spath/packages/scheduler; shift || true; ;; - --fullbuild) FULLBUILD=1; for f in $(ls $spath/packages); do source packages/$f; done; shift || true; ;; - --bcc) BCC=1; shift || true; ;; + --tracers) source $spath/packages/tracers; shift || true; ;; + --compilers) source $spath/packages/compilers; shift || true; ;; + --editors) source $spath/packages/editors; shift || true; ;; + --scheduler) source $spath/packages/scheduler; shift || true; ;; + --fullbuild) for f in $(ls $spath/packages); do source packages/$f; done; shift || true; ;; + --bcc) source $spath/packages/bcc; BCC=1; shift || true; ;; --kernelsrc) KERNELSRC="$2"; shift || true; shift || true; ;; --tempdir) TMPDIR="$2"; shift || true; shift || true; ;; *) echo "Unknown option ($1)"; usage; ;; @@ -50,7 +53,20 @@ fi # PREPARE ########################################################## # Where do we want to store temporary files -if [[ -z ${TMPDIR+x} ]] || [[ ! -d "${TMPDIR}" ]]; then - TMPDIR=`mktemp`; fi +MKTEMP=0; if [[ -z ${TMPDIR+x} ]] || [[ ! -d "${TMPDIR}" ]]; then + TMPDIR=`mktemp -d`; MKTEMP=1; fi + +OUT_TMP=$TMPDIR/debian; rm -rf $OUT_TMP; mkdir -p $OUT_TMP + +echo "Full package list: $PACKAGES" +echo "Using temporary directory: $OUT_TMP" + +time qemu-debootstrap --arch arm64 --include=$(make_csv "$PACKAGES") \ + --variant=minbase $DISTRO $OUT_TMP http://deb.debian.org/debian/ + +cp $spath/addons/bashrc $OUT_TMP/.bashrc + +# rm -rf $OUT_TMP; if [ $MKTEMP -eq 1 ]; then rm -rf $TMPDIR; fi -echo $PACKAGES +# Use --foreign and --variant=minbase to build minimal deb first stage +# Use fakeroot tar to build tar with root files diff --git a/src/packages/bcc b/src/packages/bcc new file mode 100644 index 0000000..8988cd5 --- /dev/null +++ b/src/packages/bcc @@ -0,0 +1,23 @@ +PACKAGES+="\ +llvm-6.0-dev +libclang-6.0-dev +libelf-dev +libfl-dev +libunwind-dev +libdw-dev +git +gcc +libtool +autoconf +make +cmake +iperf +arping +ethtool +flex +bison +python +clang-6.0 +python-netaddr +python-pyroute2 +" diff --git a/src/packages/compilers b/src/packages/compilers index d2d764a..f380dd3 100644 --- a/src/packages/compilers +++ b/src/packages/compilers @@ -1,4 +1,9 @@ PACKAGES+="\ +git clang-6.0 gcc +libtool +autoconf +make +cmake " diff --git a/src/packages/editors b/src/packages/editors index 9860e90..99865fa 100644 --- a/src/packages/editors +++ b/src/packages/editors @@ -1,4 +1,5 @@ PACKAGES+="\ -emacs vim +nano +git " diff --git a/src/packages/scheduler b/src/packages/scheduler index 5d70217..a5df38c 100644 --- a/src/packages/scheduler +++ b/src/packages/scheduler @@ -1,3 +1,4 @@ PACKAGES+="\ +git rt-app " diff --git a/src/packages/tracers b/src/packages/tracers index 4dee51a..38c1d43 100644 --- a/src/packages/tracers +++ b/src/packages/tracers @@ -1,5 +1,5 @@ PACKAGES+="\ -perf +linux-perf trace-cmd strace " diff --git a/src/utils/android b/src/utils/android index 0cac1fa..b08c662 100755 --- a/src/utils/android +++ b/src/utils/android @@ -1,7 +1,31 @@ #!/bin/bash -x # Utilities to interact with android more easily -script_full_path=$( cd "$(dirname "$0")" ; pwd -P ) +make_csv() { + out="" + in=$1 + for p in $in; do + if [ "x$out" == "x" ]; then + out=$p + else + out="$out,$p" + fi + done + echo $out +} + +make_spaces() { + out="" + in=$1 + for p in $in; do + if [ "x$out" == "x" ]; then + out=$p + else + out="$out $p" + fi + done + echo $out +} cmd_exists() { which $1 > /dev/null -- cgit v1.2.3 From b61d27dea8210da1dd0befda470e132f6615aa67 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sat, 31 Mar 2018 11:59:45 -0700 Subject: Update Signed-off-by: Joel Fernandes --- src/androdeb | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/androdeb b/src/androdeb index 9921d7f..aae074a 100755 --- a/src/androdeb +++ b/src/androdeb @@ -25,7 +25,7 @@ usage() { } # Set default vars -DISTRO=buster; PACKAGES=""; ARCH=arm64 +DISTRO=buster; PACKAGES="bash"; ARCH=arm64 # Parse command line parameters if [ $# -lt 1 ]; then usage; fi; POSITIONAL=() @@ -50,7 +50,7 @@ if [[ ! -z ${PREP+x} ]] && [[ "x$PACKAGES" == "x" ]]; then fi ########################################################## -# PREPARE +# PREPARE # ########################################################## # Where do we want to store temporary files MKTEMP=0; if [[ -z ${TMPDIR+x} ]] || [[ ! -d "${TMPDIR}" ]]; then @@ -64,8 +64,31 @@ echo "Using temporary directory: $OUT_TMP" time qemu-debootstrap --arch arm64 --include=$(make_csv "$PACKAGES") \ --variant=minbase $DISTRO $OUT_TMP http://deb.debian.org/debian/ +# Some reason debootstrap leaves these founded +umount $OUT_TMP/proc/sys/fs/binfmt_misc +umount $OUT_TMP/proc + +# Make bash the default shell +chroot $OUT_TMP rm /bin/sh || true +chroot $OUT_TMP ln -s /bin/bash /bin/sh || true cp $spath/addons/bashrc $OUT_TMP/.bashrc +# Cleanup +rm -rf $OUT_TMP/lib/udev/* +rm -rf $OUT_TMP/var/lib/apt/lists/* +rm -rf $OUT_TMP/var/cache/apt/archives/*deb +rm -rf $OUT_TMP/usr/share/locale/* +rm -rf $OUT_TMP/usr/lib/share/locale/* +rm -rf $OUT_TMP/usr/share/doc/* +rm -rf $OUT_TMP/usr/lib/share/doc/* +rm -rf $OUT_TMP/usr/share/ieee-data/* +rm -rf $OUT_TMP/usr/lib/share/ieee-data/* +rm -rf $OUT_TMP/usr/share/man/* +rm -rf $OUT_TMP/usr/lib/share/man/* + +echo "Compressing new filesystem to prepare to push to Android /data/androdeb/" +tar -zcf $OUT_TMP/deb.tar.gz -C $OUT_TMP debian + # rm -rf $OUT_TMP; if [ $MKTEMP -eq 1 ]; then rm -rf $TMPDIR; fi # Use --foreign and --variant=minbase to build minimal deb first stage -- cgit v1.2.3 From a0cb0c77c780a45bf698df8494eec7ceeec2240c Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sat, 31 Mar 2018 13:02:23 -0700 Subject: Update Signed-off-by: Joel Fernandes --- src/addons/device-startup | 8 ++++++++ src/addons/device-teardown | 4 ++++ src/addons/device-unpack | 34 ++++++++++++++++++++++++++++++++++ src/addons/device-unpack.sh | 6 ------ 4 files changed, 46 insertions(+), 6 deletions(-) create mode 100755 src/addons/device-startup create mode 100755 src/addons/device-teardown create mode 100755 src/addons/device-unpack delete mode 100755 src/addons/device-unpack.sh diff --git a/src/addons/device-startup b/src/addons/device-startup new file mode 100755 index 0000000..8489159 --- /dev/null +++ b/src/addons/device-startup @@ -0,0 +1,8 @@ +#!/system/bin/sh +# This script looks for /data/androdeb/deb.tar.gz and unpacks it +# into debian, also tries to shut down any open chroots and clean up. + +cd /data/ +rm -rf debian +tar -xf debian.tar.gz +rm debian.tar.gz diff --git a/src/addons/device-teardown b/src/addons/device-teardown new file mode 100755 index 0000000..e5fd049 --- /dev/null +++ b/src/addons/device-teardown @@ -0,0 +1,4 @@ +#!/system/bin/sh + +spath=$( cd "$(dirname "$0")" ; pwd -P ) + diff --git a/src/addons/device-unpack b/src/addons/device-unpack new file mode 100755 index 0000000..7c43e09 --- /dev/null +++ b/src/addons/device-unpack @@ -0,0 +1,34 @@ +#!/system/bin/sh +function die() { + exit_code=$1 + msg=$2 + echo "ERROR: $msg (code $exit_code)" + exit $exit_code +} + +set -e + +# Script to do unpack of rootfs, ensures proper tear down +# of existing environment. Expects debian rootfs in +# /data/deb.tar.gz which it will delete after successful +# unpack of rootfs. + +spath=$( cd "$(dirname "$0")" ; pwd -P ) + +if [ ! -f /data/deb.tar.gz ]; then + echo "Debian rootfs tar doesn't existing at /data/deb.tar.gz" + echo "Run androdeb with device connected first" + exit 1 +fi + +if [ -d /data/androdeb/debian ]; then + echo "androdeb environment already exists, doing a tear down" + # TODO: run env tear down script first + rm -rf /data/androdeb/debian +fi + + +mkdir -p /data/androdeb/ +tar -zxf /data/deb.tar.gz -C /data/androdeb/ || die 2 "Couldn't unpack due to tar -x errors" + +echo "Unpack of rootfs successful! Go forth and hack." diff --git a/src/addons/device-unpack.sh b/src/addons/device-unpack.sh deleted file mode 100755 index 3339f43..0000000 --- a/src/addons/device-unpack.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/system/bin/sh - -cd /data/ -rm -rf debian -tar -xf debian.tar.gz -rm debian.tar.gz -- cgit v1.2.3 From 4dd60862c1983419676905f8b94e58047731d186 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sat, 31 Mar 2018 13:27:16 -0700 Subject: Update Signed-off-by: Joel Fernandes --- src/addons/device-unpack | 2 ++ src/androdeb | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/addons/device-unpack b/src/addons/device-unpack index 7c43e09..089988c 100755 --- a/src/addons/device-unpack +++ b/src/addons/device-unpack @@ -1,4 +1,5 @@ #!/system/bin/sh + function die() { exit_code=$1 msg=$2 @@ -30,5 +31,6 @@ fi mkdir -p /data/androdeb/ tar -zxf /data/deb.tar.gz -C /data/androdeb/ || die 2 "Couldn't unpack due to tar -x errors" +rm /data/deb.tar.gz echo "Unpack of rootfs successful! Go forth and hack." diff --git a/src/androdeb b/src/androdeb index aae074a..1a7c5c5 100755 --- a/src/androdeb +++ b/src/androdeb @@ -25,7 +25,7 @@ usage() { } # Set default vars -DISTRO=buster; PACKAGES="bash"; ARCH=arm64 +DISTRO=buster; PACKAGES=$'bash\n'; ARCH=arm64 # Parse command line parameters if [ $# -lt 1 ]; then usage; fi; POSITIONAL=() @@ -87,7 +87,13 @@ rm -rf $OUT_TMP/usr/share/man/* rm -rf $OUT_TMP/usr/lib/share/man/* echo "Compressing new filesystem to prepare to push to Android /data/androdeb/" -tar -zcf $OUT_TMP/deb.tar.gz -C $OUT_TMP debian +tar -zcf $TMPDIR/deb.tar.gz -C $TMPDIR debian + +# Push tar to device and start unpack +adb shell mkdir -p /data/androdeb/ +adb push $TMPDIR/deb.tar.gz /data/androdeb/ +adb push $spath/addons/device-* /data/androdeb/ +adb shell /data/androdeb/device-unpack # rm -rf $OUT_TMP; if [ $MKTEMP -eq 1 ]; then rm -rf $TMPDIR; fi -- cgit v1.2.3 From 0bd688653729cd83077d2c8af54d8f9d16fd0606 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sat, 31 Mar 2018 16:03:00 -0700 Subject: Update Signed-off-by: Joel Fernandes --- src/addons/device-startup | 8 -------- src/addons/device-teardown | 4 ---- src/addons/device-umount-all | 16 ++++++++++++++++ src/addons/run-chroot | 17 +++++++++++------ src/androdeb | 2 +- 5 files changed, 28 insertions(+), 19 deletions(-) delete mode 100755 src/addons/device-startup delete mode 100755 src/addons/device-teardown create mode 100755 src/addons/device-umount-all diff --git a/src/addons/device-startup b/src/addons/device-startup deleted file mode 100755 index 8489159..0000000 --- a/src/addons/device-startup +++ /dev/null @@ -1,8 +0,0 @@ -#!/system/bin/sh -# This script looks for /data/androdeb/deb.tar.gz and unpacks it -# into debian, also tries to shut down any open chroots and clean up. - -cd /data/ -rm -rf debian -tar -xf debian.tar.gz -rm debian.tar.gz diff --git a/src/addons/device-teardown b/src/addons/device-teardown deleted file mode 100755 index e5fd049..0000000 --- a/src/addons/device-teardown +++ /dev/null @@ -1,4 +0,0 @@ -#!/system/bin/sh - -spath=$( cd "$(dirname "$0")" ; pwd -P ) - diff --git a/src/addons/device-umount-all b/src/addons/device-umount-all new file mode 100755 index 0000000..981250c --- /dev/null +++ b/src/addons/device-umount-all @@ -0,0 +1,16 @@ +#!/bin/sh + +if [ "$1x" == "--debugx" ]; then + set -x +fi + +umount_all() { + mpoints=$(mount|cut -d ' ' -f3|grep debian) + for m in $mpoints; + do umount $m 2>&1 > /dev/null + done +} + +for i in $(seq 0 10); do + umount_all 2>&1 > /dev/null +done diff --git a/src/addons/run-chroot b/src/addons/run-chroot index ea2f662..a886851 100755 --- a/src/addons/run-chroot +++ b/src/addons/run-chroot @@ -1,11 +1,16 @@ #!/system/bin/sh +spath=$( cd "$(dirname "$0")" ; pwd -P ) -cd /data/ -mount -t proc /proc debian/proc/ > /dev/null -mount --rbind /dev debian/dev/ > /dev/null -mount --rbind /sys debian/sys/ > /dev/null -mount --rbind /sys/kernel/debug/ debian/sys/kernel/debug/ > /dev/null -mount --rbind /sys/kernel/debug/tracing/ debian/sys/kernel/debug/tracing/ +cd $spath + +# tear everything down +./device-umount-all + +mount --bind /proc debian/proc/ > /dev/null +mount --bind /dev debian/dev/ > /dev/null +mount --bind /sys debian/sys/ > /dev/null +mount --bind /sys/kernel/debug/ debian/sys/kernel/debug/ > /dev/null +mount --bind /sys/kernel/debug/tracing/ debian/sys/kernel/debug/tracing/ if [ -d /system/ ]; then mount --bind /system debian/system/ fi diff --git a/src/androdeb b/src/androdeb index 1a7c5c5..f6e9b4b 100755 --- a/src/androdeb +++ b/src/androdeb @@ -62,7 +62,7 @@ echo "Full package list: $PACKAGES" echo "Using temporary directory: $OUT_TMP" time qemu-debootstrap --arch arm64 --include=$(make_csv "$PACKAGES") \ - --variant=minbase $DISTRO $OUT_TMP http://deb.debian.org/debian/ + $DISTRO $OUT_TMP http://deb.debian.org/debian/ # Some reason debootstrap leaves these founded umount $OUT_TMP/proc/sys/fs/binfmt_misc -- cgit v1.2.3 From 394e7ec8be103dbb8d81f9080681f336cebae988 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sat, 31 Mar 2018 16:51:09 -0700 Subject: Update Signed-off-by: Joel Fernandes --- src/addons/device-unpack | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/addons/device-unpack b/src/addons/device-unpack index 089988c..a660997 100755 --- a/src/addons/device-unpack +++ b/src/addons/device-unpack @@ -24,7 +24,7 @@ fi if [ -d /data/androdeb/debian ]; then echo "androdeb environment already exists, doing a tear down" - # TODO: run env tear down script first + /data/androdeb/device-umount-all rm -rf /data/androdeb/debian fi -- cgit v1.2.3 From 8957a1476c13cd902f522dbffab737e24159dce4 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sat, 31 Mar 2018 16:58:45 -0700 Subject: Update Signed-off-by: Joel Fernandes --- src/addons/device-umount-all | 2 +- src/addons/run-chroot | 3 +++ src/androdeb | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/addons/device-umount-all b/src/addons/device-umount-all index 981250c..f68aac7 100755 --- a/src/addons/device-umount-all +++ b/src/addons/device-umount-all @@ -11,6 +11,6 @@ umount_all() { done } -for i in $(seq 0 10); do +for i in $(seq 0 6); do umount_all 2>&1 > /dev/null done diff --git a/src/addons/run-chroot b/src/addons/run-chroot index a886851..94f8b8a 100755 --- a/src/addons/run-chroot +++ b/src/addons/run-chroot @@ -15,3 +15,6 @@ if [ -d /system/ ]; then mount --bind /system debian/system/ fi chroot debian/ /bin/bash --rcfile /bashrc + +# tear everything down +./device-umount-all diff --git a/src/androdeb b/src/androdeb index f6e9b4b..8f6f849 100755 --- a/src/androdeb +++ b/src/androdeb @@ -73,6 +73,10 @@ chroot $OUT_TMP rm /bin/sh || true chroot $OUT_TMP ln -s /bin/bash /bin/sh || true cp $spath/addons/bashrc $OUT_TMP/.bashrc +# For mounting android partitions +mkdir $OUT_TMP/system +mkdir $OUT_TMP/vendor + # Cleanup rm -rf $OUT_TMP/lib/udev/* rm -rf $OUT_TMP/var/lib/apt/lists/* -- cgit v1.2.3 From cc94c19a95b75ff86388cee75048fa6ee525a188 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sat, 31 Mar 2018 17:09:26 -0700 Subject: Update Signed-off-by: Joel Fernandes --- src/addons/bashrc | 8 ++++++-- src/addons/device-unpack | 5 ++--- src/addons/run-chroot | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/addons/bashrc b/src/addons/bashrc index 2b48d5c..95890be 100644 --- a/src/addons/bashrc +++ b/src/addons/bashrc @@ -1,4 +1,8 @@ -# Create a more sane trace development environment! - export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/share/bcc/tools/ export TMPDIR=/tmp/ + +echo "########################################################" +echo "# Welcome to androdeb environment running on Android #" +echo "# With great power comes great responibility! #" +echo "# For questions: joel@linuxinternals.org #" +echo "########################################################" diff --git a/src/addons/device-unpack b/src/addons/device-unpack index a660997..b1eb5f2 100755 --- a/src/addons/device-unpack +++ b/src/addons/device-unpack @@ -16,7 +16,7 @@ set -e spath=$( cd "$(dirname "$0")" ; pwd -P ) -if [ ! -f /data/deb.tar.gz ]; then +if [ ! -f /data/androdeb/deb.tar.gz ]; then echo "Debian rootfs tar doesn't existing at /data/deb.tar.gz" echo "Run androdeb with device connected first" exit 1 @@ -29,8 +29,7 @@ if [ -d /data/androdeb/debian ]; then fi -mkdir -p /data/androdeb/ -tar -zxf /data/deb.tar.gz -C /data/androdeb/ || die 2 "Couldn't unpack due to tar -x errors" +tar -zxf /data/androdeb/deb.tar.gz -C /data/androdeb/ || die 2 "Couldn't unpack due to tar -x errors" rm /data/deb.tar.gz echo "Unpack of rootfs successful! Go forth and hack." diff --git a/src/addons/run-chroot b/src/addons/run-chroot index 94f8b8a..5804a99 100755 --- a/src/addons/run-chroot +++ b/src/addons/run-chroot @@ -14,7 +14,7 @@ mount --bind /sys/kernel/debug/tracing/ debian/sys/kernel/debug/tracing/ if [ -d /system/ ]; then mount --bind /system debian/system/ fi -chroot debian/ /bin/bash --rcfile /bashrc +chroot debian/ /bin/bash # tear everything down ./device-umount-all -- cgit v1.2.3 From 59d5eb537496e4cd95ff973e7989ff334e070f44 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sat, 31 Mar 2018 17:18:52 -0700 Subject: Update Signed-off-by: Joel Fernandes --- src/addons/bashrc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/addons/bashrc b/src/addons/bashrc index 95890be..8d4ca3d 100644 --- a/src/addons/bashrc +++ b/src/addons/bashrc @@ -1,8 +1,10 @@ export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/share/bcc/tools/ export TMPDIR=/tmp/ +echo "" echo "########################################################" echo "# Welcome to androdeb environment running on Android #" echo "# With great power comes great responibility! #" echo "# For questions: joel@linuxinternals.org #" echo "########################################################" +echo "" -- cgit v1.2.3 From 96a7bb759125f9ba61c1ac33cff8d15d129ed456 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sat, 31 Mar 2018 17:24:20 -0700 Subject: Update Signed-off-by: Joel Fernandes --- src/addons/run | 20 ++++++++++++++++++++ src/addons/run-chroot | 20 -------------------- src/addons/run-chroot-command | 8 -------- src/addons/run-command | 8 ++++++++ 4 files changed, 28 insertions(+), 28 deletions(-) create mode 100755 src/addons/run delete mode 100755 src/addons/run-chroot delete mode 100755 src/addons/run-chroot-command create mode 100755 src/addons/run-command diff --git a/src/addons/run b/src/addons/run new file mode 100755 index 0000000..5804a99 --- /dev/null +++ b/src/addons/run @@ -0,0 +1,20 @@ +#!/system/bin/sh +spath=$( cd "$(dirname "$0")" ; pwd -P ) + +cd $spath + +# tear everything down +./device-umount-all + +mount --bind /proc debian/proc/ > /dev/null +mount --bind /dev debian/dev/ > /dev/null +mount --bind /sys debian/sys/ > /dev/null +mount --bind /sys/kernel/debug/ debian/sys/kernel/debug/ > /dev/null +mount --bind /sys/kernel/debug/tracing/ debian/sys/kernel/debug/tracing/ +if [ -d /system/ ]; then + mount --bind /system debian/system/ +fi +chroot debian/ /bin/bash + +# tear everything down +./device-umount-all diff --git a/src/addons/run-chroot b/src/addons/run-chroot deleted file mode 100755 index 5804a99..0000000 --- a/src/addons/run-chroot +++ /dev/null @@ -1,20 +0,0 @@ -#!/system/bin/sh -spath=$( cd "$(dirname "$0")" ; pwd -P ) - -cd $spath - -# tear everything down -./device-umount-all - -mount --bind /proc debian/proc/ > /dev/null -mount --bind /dev debian/dev/ > /dev/null -mount --bind /sys debian/sys/ > /dev/null -mount --bind /sys/kernel/debug/ debian/sys/kernel/debug/ > /dev/null -mount --bind /sys/kernel/debug/tracing/ debian/sys/kernel/debug/tracing/ -if [ -d /system/ ]; then - mount --bind /system debian/system/ -fi -chroot debian/ /bin/bash - -# tear everything down -./device-umount-all diff --git a/src/addons/run-chroot-command b/src/addons/run-chroot-command deleted file mode 100755 index 9a99836..0000000 --- a/src/addons/run-chroot-command +++ /dev/null @@ -1,8 +0,0 @@ -#!/system/bin/sh - -# Directly execute a command within the chroot of an Android device - -CHROOT_PATH=$1 -CMD=$2 - -chroot $CHROOT_PATH /bin/bash -i -c $CMD diff --git a/src/addons/run-command b/src/addons/run-command new file mode 100755 index 0000000..9a99836 --- /dev/null +++ b/src/addons/run-command @@ -0,0 +1,8 @@ +#!/system/bin/sh + +# Directly execute a command within the chroot of an Android device + +CHROOT_PATH=$1 +CMD=$2 + +chroot $CHROOT_PATH /bin/bash -i -c $CMD -- cgit v1.2.3 From e2a0466c52c24632a9dedb4903281c6b01e18716 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sat, 31 Mar 2018 19:33:23 -0700 Subject: Update Signed-off-by: Joel Fernandes --- src/addons/bashrc | 2 +- src/androdeb | 37 +++++++++++++++++++++++++------------ 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/addons/bashrc b/src/addons/bashrc index 8d4ca3d..02fdeae 100644 --- a/src/addons/bashrc +++ b/src/addons/bashrc @@ -4,7 +4,7 @@ export TMPDIR=/tmp/ echo "" echo "########################################################" echo "# Welcome to androdeb environment running on Android #" -echo "# With great power comes great responibility! #" +echo "# With great power comes great responsibility! #" echo "# For questions: joel@linuxinternals.org #" echo "########################################################" echo "" diff --git a/src/androdeb b/src/androdeb index 8f6f849..c96c933 100755 --- a/src/androdeb +++ b/src/androdeb @@ -4,8 +4,6 @@ curdir=$( pwd -P ) source $spath/utils/android -if [[ $EUID -ne 0 ]]; then echo "This tool must be run as root"; exit 3; fi - usage() { echo "androdeb" echo " shell Enter the androdeb shell environment and get to work!" @@ -25,14 +23,14 @@ usage() { } # Set default vars -DISTRO=buster; PACKAGES=$'bash\n'; ARCH=arm64 +DISTRO=buster; PACKAGES=""; ARCH=arm64 # Parse command line parameters if [ $# -lt 1 ]; then usage; fi; POSITIONAL=() while [[ $# -gt 0 ]]; do key="$1"; case $key in prepare) PREP=1; shift || true; ;; - shell) SHELL=1; shift || true; ;; + shell) ASHELL=1; shift || true; ;; --tracers) source $spath/packages/tracers; shift || true; ;; --compilers) source $spath/packages/compilers; shift || true; ;; --editors) source $spath/packages/editors; shift || true; ;; @@ -40,7 +38,7 @@ case $key in --fullbuild) for f in $(ls $spath/packages); do source packages/$f; done; shift || true; ;; --bcc) source $spath/packages/bcc; BCC=1; shift || true; ;; --kernelsrc) KERNELSRC="$2"; shift || true; shift || true; ;; - --tempdir) TMPDIR="$2"; shift || true; shift || true; ;; + --tempdir) TDIR="$2"; shift || true; shift || true; ;; *) echo "Unknown option ($1)"; usage; ;; esac done @@ -48,15 +46,30 @@ done if [[ ! -z ${PREP+x} ]] && [[ "x$PACKAGES" == "x" ]]; then echo "Need to specifify something to prepare"; usage; fi +PACKAGES+=$'bash\n' + +########################################################## +# SHELL +########################################################## +if [[ ! -z ${ASHELL+x} ]]; then + echo "For a better shell experience, run the following commands:" + echo " adb shell" + echo " /data/androdeb/run" + adb shell -x /data/androdeb/run + exit 0 +fi ########################################################## -# PREPARE # +# PREPARE ########################################################## +if [[ $EUID -ne 0 ]]; then echo "For prepare, this tool must run as root"; +echo "Try ./sudo androdeb prepare "; exit 3; fi + # Where do we want to store temporary files -MKTEMP=0; if [[ -z ${TMPDIR+x} ]] || [[ ! -d "${TMPDIR}" ]]; then - TMPDIR=`mktemp -d`; MKTEMP=1; fi +MKTEMP=0; if [[ -z ${TDIR+x} ]] || [[ ! -d "${TDIR}" ]]; then + TDIR=`mktemp -d`; MKTEMP=1; fi -OUT_TMP=$TMPDIR/debian; rm -rf $OUT_TMP; mkdir -p $OUT_TMP +OUT_TMP=$TDIR/debian; rm -rf $OUT_TMP; mkdir -p $OUT_TMP echo "Full package list: $PACKAGES" echo "Using temporary directory: $OUT_TMP" @@ -91,15 +104,15 @@ rm -rf $OUT_TMP/usr/share/man/* rm -rf $OUT_TMP/usr/lib/share/man/* echo "Compressing new filesystem to prepare to push to Android /data/androdeb/" -tar -zcf $TMPDIR/deb.tar.gz -C $TMPDIR debian +tar -zcf $TDIR/deb.tar.gz -C $TDIR debian # Push tar to device and start unpack adb shell mkdir -p /data/androdeb/ -adb push $TMPDIR/deb.tar.gz /data/androdeb/ +adb push $TDIR/deb.tar.gz /data/androdeb/ adb push $spath/addons/device-* /data/androdeb/ adb shell /data/androdeb/device-unpack -# rm -rf $OUT_TMP; if [ $MKTEMP -eq 1 ]; then rm -rf $TMPDIR; fi +# rm -rf $OUT_TMP; if [ $MKTEMP -eq 1 ]; then rm -rf $TDIR; fi # Use --foreign and --variant=minbase to build minimal deb first stage # Use fakeroot tar to build tar with root files -- cgit v1.2.3 From c9646819169a189cd9c8af3ba8e046667e424c73 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sat, 31 Mar 2018 19:45:46 -0700 Subject: Update Signed-off-by: Joel Fernandes --- src/addons/bashrc | 2 ++ src/addons/device-unpack | 7 ------- src/androdeb | 6 +++++- src/utils/android | 7 +++++++ 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/addons/bashrc b/src/addons/bashrc index 02fdeae..f6d8aa4 100644 --- a/src/addons/bashrc +++ b/src/addons/bashrc @@ -6,5 +6,7 @@ echo "########################################################" echo "# Welcome to androdeb environment running on Android #" echo "# With great power comes great responsibility! #" echo "# For questions: joel@linuxinternals.org #" +echo " #" +echo " Try running vim, gcc, clang, bcc, git, make etc. #" echo "########################################################" echo "" diff --git a/src/addons/device-unpack b/src/addons/device-unpack index b1eb5f2..40863ea 100755 --- a/src/addons/device-unpack +++ b/src/addons/device-unpack @@ -1,12 +1,5 @@ #!/system/bin/sh -function die() { - exit_code=$1 - msg=$2 - echo "ERROR: $msg (code $exit_code)" - exit $exit_code -} - set -e # Script to do unpack of rootfs, ensures proper tear down diff --git a/src/androdeb b/src/androdeb index c96c933..3638cfb 100755 --- a/src/androdeb +++ b/src/androdeb @@ -1,7 +1,6 @@ #!/bin/bash -e spath=$( cd "$(dirname "$0")" ; pwd -P ) curdir=$( pwd -P ) - source $spath/utils/android usage() { @@ -52,6 +51,11 @@ PACKAGES+=$'bash\n' # SHELL ########################################################## if [[ ! -z ${ASHELL+x} ]]; then + set +e; adb shell ls /data/androdeb/debian/.bashrc > /dev/null 2>&1 + if [ $? -ne 0 ]; then + die 2 "Device doesn't have an androdeb environment, run \"./androdeb prepare\" first"; + fi; set -e + echo "For a better shell experience, run the following commands:" echo " adb shell" echo " /data/androdeb/run" diff --git a/src/utils/android b/src/utils/android index b08c662..1581730 100755 --- a/src/utils/android +++ b/src/utils/android @@ -36,3 +36,10 @@ do_adb_root() { adb root return $? } + +die() { + exit_code=$1 + msg=$2 + echo "ERROR: $msg (code $exit_code)" + exit $exit_code +} -- cgit v1.2.3 From 77e53796bde27d7b7fbe8f6bb469a638e5cde591 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sat, 31 Mar 2018 20:03:42 -0700 Subject: Update Signed-off-by: Joel Fernandes --- src/addons/bashrc | 4 ++++ src/androdeb | 13 +++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/addons/bashrc b/src/addons/bashrc index f6d8aa4..995f3c4 100644 --- a/src/addons/bashrc +++ b/src/addons/bashrc @@ -8,5 +8,9 @@ echo "# With great power comes great responsibility! #" echo "# For questions: joel@linuxinternals.org #" echo " #" echo " Try running vim, gcc, clang, bcc, git, make etc. #" +echo " or apt-get install something. #" +echo " #" +echo " Note: For apt-get to work, you need to disable #" +echo " CONFIG_ANDROID_PARANOID_NETWORK and rebuild kernel. #" echo "########################################################" echo "" diff --git a/src/androdeb b/src/androdeb index 3638cfb..a6195d3 100755 --- a/src/androdeb +++ b/src/androdeb @@ -35,7 +35,7 @@ case $key in --editors) source $spath/packages/editors; shift || true; ;; --scheduler) source $spath/packages/scheduler; shift || true; ;; --fullbuild) for f in $(ls $spath/packages); do source packages/$f; done; shift || true; ;; - --bcc) source $spath/packages/bcc; BCC=1; shift || true; ;; + --bcc) source $spath/packages/bcc; INSTALL_BCC=1; shift || true; ;; --kernelsrc) KERNELSRC="$2"; shift || true; shift || true; ;; --tempdir) TDIR="$2"; shift || true; shift || true; ;; *) echo "Unknown option ($1)"; usage; ;; @@ -45,7 +45,10 @@ done if [[ ! -z ${PREP+x} ]] && [[ "x$PACKAGES" == "x" ]]; then echo "Need to specifify something to prepare"; usage; fi -PACKAGES+=$'bash\n' +PACKAGES+="\ +bash +ca-certifcates +" ########################################################## # SHELL @@ -107,6 +110,12 @@ rm -rf $OUT_TMP/usr/lib/share/ieee-data/* rm -rf $OUT_TMP/usr/share/man/* rm -rf $OUT_TMP/usr/lib/share/man/* +# Clone BCC if needed +if [[ ! -z ${INSTALL_BCC+x} ]]; then +git clone https://github.com/iovisor/bcc.git $TDIR/debian/bcc-master +cp $spath/bcc/build-bcc.sh $TDIR/debian/bcc-master/ +fi + echo "Compressing new filesystem to prepare to push to Android /data/androdeb/" tar -zcf $TDIR/deb.tar.gz -C $TDIR debian -- cgit v1.2.3 From 04112d0be83d83e371c8000cf7b638db5853ddf8 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sat, 31 Mar 2018 20:04:03 -0700 Subject: Update Signed-off-by: Joel Fernandes --- src/bcc/build-bcc.sh | 8 ++++++++ src/bcc/build-kernel-headers-tar.sh | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100755 src/bcc/build-bcc.sh create mode 100755 src/bcc/build-kernel-headers-tar.sh diff --git a/src/bcc/build-bcc.sh b/src/bcc/build-bcc.sh new file mode 100755 index 0000000..3118896 --- /dev/null +++ b/src/bcc/build-bcc.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +rm -rf build && mkdir -p build && cd build +cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_C_COMPILER=clang-6.0 -DCMAKE_CXX_COMPILER=clang++-6.0 +make -j4 +make install + +# rm -rf /bcc-master diff --git a/src/bcc/build-kernel-headers-tar.sh b/src/bcc/build-kernel-headers-tar.sh new file mode 100755 index 0000000..84e9c39 --- /dev/null +++ b/src/bcc/build-kernel-headers-tar.sh @@ -0,0 +1,23 @@ +#!/bin/bash -x +script_full_path=$( cd "$(dirname "$0")" ; pwd -P ) + +if [ $# -ne 1 ]; then + echo "illegal number of parameters, usage: ./build-kernel-headers-tar.sh KERNEL_PATH" + exit 1 +fi + +KERNEL_PATH=$1 +KERNEL_PATH="$(dirname $(readlink -e $KERNEL_PATH))/$(basename $KERNEL_PATH)" +if [ ! -d "$KERNEL_PATH" ]; then + echo "Kernel directory couldn't be found" + exit 3 +fi + +kdir=$(basename $KERNEL_PATH) + +cd $KERNEL_PATH/.. +find $kdir/arch -name include -type d -print | xargs -n1 -i: find : -type f > /tmp/kernel-headers.h +find $kdir/include >> /tmp/kernel-headers.h + +cat /tmp/kernel-headers.h | tar -zcf $KERNEL_PATH/../$kdir.tar.gz -T - +rm /tmp/kernel-headers.h -- cgit v1.2.3 From e9476a4159c01f67364ee9f436b15d13c9eb2fdb Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sat, 31 Mar 2018 20:04:32 -0700 Subject: Update Signed-off-by: Joel Fernandes --- addons/bashrc | 16 +++++ addons/device-umount-all | 16 +++++ addons/device-unpack | 28 ++++++++ addons/run | 20 ++++++ addons/run-command | 8 +++ androdeb | 131 ++++++++++++++++++++++++++++++++++++ bcc/build-bcc.sh | 8 +++ bcc/build-kernel-headers-tar.sh | 23 +++++++ packages/bcc | 23 +++++++ packages/compilers | 9 +++ packages/editors | 5 ++ packages/scheduler | 4 ++ packages/tracers | 5 ++ src/addons/bashrc | 16 ----- src/addons/device-umount-all | 16 ----- src/addons/device-unpack | 28 -------- src/addons/run | 20 ------ src/addons/run-command | 8 --- src/androdeb | 131 ------------------------------------ src/bcc/build-bcc.sh | 8 --- src/bcc/build-kernel-headers-tar.sh | 23 ------- src/packages/bcc | 23 ------- src/packages/compilers | 9 --- src/packages/editors | 5 -- src/packages/scheduler | 4 -- src/packages/tracers | 5 -- src/utils/android | 45 ------------- utils/android | 45 +++++++++++++ 28 files changed, 341 insertions(+), 341 deletions(-) create mode 100644 addons/bashrc create mode 100755 addons/device-umount-all create mode 100755 addons/device-unpack create mode 100755 addons/run create mode 100755 addons/run-command create mode 100755 androdeb create mode 100755 bcc/build-bcc.sh create mode 100755 bcc/build-kernel-headers-tar.sh create mode 100644 packages/bcc create mode 100644 packages/compilers create mode 100644 packages/editors create mode 100644 packages/scheduler create mode 100644 packages/tracers delete mode 100644 src/addons/bashrc delete mode 100755 src/addons/device-umount-all delete mode 100755 src/addons/device-unpack delete mode 100755 src/addons/run delete mode 100755 src/addons/run-command delete mode 100755 src/androdeb delete mode 100755 src/bcc/build-bcc.sh delete mode 100755 src/bcc/build-kernel-headers-tar.sh delete mode 100644 src/packages/bcc delete mode 100644 src/packages/compilers delete mode 100644 src/packages/editors delete mode 100644 src/packages/scheduler delete mode 100644 src/packages/tracers delete mode 100755 src/utils/android create mode 100755 utils/android diff --git a/addons/bashrc b/addons/bashrc new file mode 100644 index 0000000..995f3c4 --- /dev/null +++ b/addons/bashrc @@ -0,0 +1,16 @@ +export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/share/bcc/tools/ +export TMPDIR=/tmp/ + +echo "" +echo "########################################################" +echo "# Welcome to androdeb environment running on Android #" +echo "# With great power comes great responsibility! #" +echo "# For questions: joel@linuxinternals.org #" +echo " #" +echo " Try running vim, gcc, clang, bcc, git, make etc. #" +echo " or apt-get install something. #" +echo " #" +echo " Note: For apt-get to work, you need to disable #" +echo " CONFIG_ANDROID_PARANOID_NETWORK and rebuild kernel. #" +echo "########################################################" +echo "" diff --git a/addons/device-umount-all b/addons/device-umount-all new file mode 100755 index 0000000..f68aac7 --- /dev/null +++ b/addons/device-umount-all @@ -0,0 +1,16 @@ +#!/bin/sh + +if [ "$1x" == "--debugx" ]; then + set -x +fi + +umount_all() { + mpoints=$(mount|cut -d ' ' -f3|grep debian) + for m in $mpoints; + do umount $m 2>&1 > /dev/null + done +} + +for i in $(seq 0 6); do + umount_all 2>&1 > /dev/null +done diff --git a/addons/device-unpack b/addons/device-unpack new file mode 100755 index 0000000..40863ea --- /dev/null +++ b/addons/device-unpack @@ -0,0 +1,28 @@ +#!/system/bin/sh + +set -e + +# Script to do unpack of rootfs, ensures proper tear down +# of existing environment. Expects debian rootfs in +# /data/deb.tar.gz which it will delete after successful +# unpack of rootfs. + +spath=$( cd "$(dirname "$0")" ; pwd -P ) + +if [ ! -f /data/androdeb/deb.tar.gz ]; then + echo "Debian rootfs tar doesn't existing at /data/deb.tar.gz" + echo "Run androdeb with device connected first" + exit 1 +fi + +if [ -d /data/androdeb/debian ]; then + echo "androdeb environment already exists, doing a tear down" + /data/androdeb/device-umount-all + rm -rf /data/androdeb/debian +fi + + +tar -zxf /data/androdeb/deb.tar.gz -C /data/androdeb/ || die 2 "Couldn't unpack due to tar -x errors" +rm /data/deb.tar.gz + +echo "Unpack of rootfs successful! Go forth and hack." diff --git a/addons/run b/addons/run new file mode 100755 index 0000000..5804a99 --- /dev/null +++ b/addons/run @@ -0,0 +1,20 @@ +#!/system/bin/sh +spath=$( cd "$(dirname "$0")" ; pwd -P ) + +cd $spath + +# tear everything down +./device-umount-all + +mount --bind /proc debian/proc/ > /dev/null +mount --bind /dev debian/dev/ > /dev/null +mount --bind /sys debian/sys/ > /dev/null +mount --bind /sys/kernel/debug/ debian/sys/kernel/debug/ > /dev/null +mount --bind /sys/kernel/debug/tracing/ debian/sys/kernel/debug/tracing/ +if [ -d /system/ ]; then + mount --bind /system debian/system/ +fi +chroot debian/ /bin/bash + +# tear everything down +./device-umount-all diff --git a/addons/run-command b/addons/run-command new file mode 100755 index 0000000..9a99836 --- /dev/null +++ b/addons/run-command @@ -0,0 +1,8 @@ +#!/system/bin/sh + +# Directly execute a command within the chroot of an Android device + +CHROOT_PATH=$1 +CMD=$2 + +chroot $CHROOT_PATH /bin/bash -i -c $CMD diff --git a/androdeb b/androdeb new file mode 100755 index 0000000..a6195d3 --- /dev/null +++ b/androdeb @@ -0,0 +1,131 @@ +#!/bin/bash -e +spath=$( cd "$(dirname "$0")" ; pwd -P ) +curdir=$( pwd -P ) +source $spath/utils/android + +usage() { + echo "androdeb" + echo " shell Enter the androdeb shell environment and get to work!" + echo "" + echo " prepare Prepare the device (when running for the first time)" + echo " --tracers Enable tracing packages (perf and trace-cmd)" + echo " --compilers Enable compilers on the FS (gcc and clang)" + echo " --editors Enable vim, emacs and git packages" + echo " --scheduler scheduler testing tools (only rt-app for now)" + echo " --bcc Build and install BCC from source" + echo " --fullbuild Enable all of the above tools" + echo "" + echo " --kernelsrc path-to-kernel-sources (can be used for bcc)" + echo " --tempdir use a specific temporary directory" + echo " --distro Debian distro to base on (default is buster)" + exit 1 +} + +# Set default vars +DISTRO=buster; PACKAGES=""; ARCH=arm64 + +# Parse command line parameters +if [ $# -lt 1 ]; then usage; fi; POSITIONAL=() +while [[ $# -gt 0 ]]; do key="$1"; +case $key in + prepare) PREP=1; shift || true; ;; + shell) ASHELL=1; shift || true; ;; + --tracers) source $spath/packages/tracers; shift || true; ;; + --compilers) source $spath/packages/compilers; shift || true; ;; + --editors) source $spath/packages/editors; shift || true; ;; + --scheduler) source $spath/packages/scheduler; shift || true; ;; + --fullbuild) for f in $(ls $spath/packages); do source packages/$f; done; shift || true; ;; + --bcc) source $spath/packages/bcc; INSTALL_BCC=1; shift || true; ;; + --kernelsrc) KERNELSRC="$2"; shift || true; shift || true; ;; + --tempdir) TDIR="$2"; shift || true; shift || true; ;; + *) echo "Unknown option ($1)"; usage; ;; +esac +done + +if [[ ! -z ${PREP+x} ]] && [[ "x$PACKAGES" == "x" ]]; then + echo "Need to specifify something to prepare"; usage; +fi +PACKAGES+="\ +bash +ca-certifcates +" + +########################################################## +# SHELL +########################################################## +if [[ ! -z ${ASHELL+x} ]]; then + set +e; adb shell ls /data/androdeb/debian/.bashrc > /dev/null 2>&1 + if [ $? -ne 0 ]; then + die 2 "Device doesn't have an androdeb environment, run \"./androdeb prepare\" first"; + fi; set -e + + echo "For a better shell experience, run the following commands:" + echo " adb shell" + echo " /data/androdeb/run" + adb shell -x /data/androdeb/run + exit 0 +fi + +########################################################## +# PREPARE +########################################################## +if [[ $EUID -ne 0 ]]; then echo "For prepare, this tool must run as root"; +echo "Try ./sudo androdeb prepare "; exit 3; fi + +# Where do we want to store temporary files +MKTEMP=0; if [[ -z ${TDIR+x} ]] || [[ ! -d "${TDIR}" ]]; then + TDIR=`mktemp -d`; MKTEMP=1; fi + +OUT_TMP=$TDIR/debian; rm -rf $OUT_TMP; mkdir -p $OUT_TMP + +echo "Full package list: $PACKAGES" +echo "Using temporary directory: $OUT_TMP" + +time qemu-debootstrap --arch arm64 --include=$(make_csv "$PACKAGES") \ + $DISTRO $OUT_TMP http://deb.debian.org/debian/ + +# Some reason debootstrap leaves these founded +umount $OUT_TMP/proc/sys/fs/binfmt_misc +umount $OUT_TMP/proc + +# Make bash the default shell +chroot $OUT_TMP rm /bin/sh || true +chroot $OUT_TMP ln -s /bin/bash /bin/sh || true +cp $spath/addons/bashrc $OUT_TMP/.bashrc + +# For mounting android partitions +mkdir $OUT_TMP/system +mkdir $OUT_TMP/vendor + +# Cleanup +rm -rf $OUT_TMP/lib/udev/* +rm -rf $OUT_TMP/var/lib/apt/lists/* +rm -rf $OUT_TMP/var/cache/apt/archives/*deb +rm -rf $OUT_TMP/usr/share/locale/* +rm -rf $OUT_TMP/usr/lib/share/locale/* +rm -rf $OUT_TMP/usr/share/doc/* +rm -rf $OUT_TMP/usr/lib/share/doc/* +rm -rf $OUT_TMP/usr/share/ieee-data/* +rm -rf $OUT_TMP/usr/lib/share/ieee-data/* +rm -rf $OUT_TMP/usr/share/man/* +rm -rf $OUT_TMP/usr/lib/share/man/* + +# Clone BCC if needed +if [[ ! -z ${INSTALL_BCC+x} ]]; then +git clone https://github.com/iovisor/bcc.git $TDIR/debian/bcc-master +cp $spath/bcc/build-bcc.sh $TDIR/debian/bcc-master/ +fi + +echo "Compressing new filesystem to prepare to push to Android /data/androdeb/" +tar -zcf $TDIR/deb.tar.gz -C $TDIR debian + +# Push tar to device and start unpack +adb shell mkdir -p /data/androdeb/ +adb push $TDIR/deb.tar.gz /data/androdeb/ +adb push $spath/addons/device-* /data/androdeb/ +adb shell /data/androdeb/device-unpack + +# rm -rf $OUT_TMP; if [ $MKTEMP -eq 1 ]; then rm -rf $TDIR; fi + +# Use --foreign and --variant=minbase to build minimal deb first stage +# Use fakeroot tar to build tar with root files diff --git a/bcc/build-bcc.sh b/bcc/build-bcc.sh new file mode 100755 index 0000000..3118896 --- /dev/null +++ b/bcc/build-bcc.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +rm -rf build && mkdir -p build && cd build +cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_C_COMPILER=clang-6.0 -DCMAKE_CXX_COMPILER=clang++-6.0 +make -j4 +make install + +# rm -rf /bcc-master diff --git a/bcc/build-kernel-headers-tar.sh b/bcc/build-kernel-headers-tar.sh new file mode 100755 index 0000000..84e9c39 --- /dev/null +++ b/bcc/build-kernel-headers-tar.sh @@ -0,0 +1,23 @@ +#!/bin/bash -x +script_full_path=$( cd "$(dirname "$0")" ; pwd -P ) + +if [ $# -ne 1 ]; then + echo "illegal number of parameters, usage: ./build-kernel-headers-tar.sh KERNEL_PATH" + exit 1 +fi + +KERNEL_PATH=$1 +KERNEL_PATH="$(dirname $(readlink -e $KERNEL_PATH))/$(basename $KERNEL_PATH)" +if [ ! -d "$KERNEL_PATH" ]; then + echo "Kernel directory couldn't be found" + exit 3 +fi + +kdir=$(basename $KERNEL_PATH) + +cd $KERNEL_PATH/.. +find $kdir/arch -name include -type d -print | xargs -n1 -i: find : -type f > /tmp/kernel-headers.h +find $kdir/include >> /tmp/kernel-headers.h + +cat /tmp/kernel-headers.h | tar -zcf $KERNEL_PATH/../$kdir.tar.gz -T - +rm /tmp/kernel-headers.h diff --git a/packages/bcc b/packages/bcc new file mode 100644 index 0000000..8988cd5 --- /dev/null +++ b/packages/bcc @@ -0,0 +1,23 @@ +PACKAGES+="\ +llvm-6.0-dev +libclang-6.0-dev +libelf-dev +libfl-dev +libunwind-dev +libdw-dev +git +gcc +libtool +autoconf +make +cmake +iperf +arping +ethtool +flex +bison +python +clang-6.0 +python-netaddr +python-pyroute2 +" diff --git a/packages/compilers b/packages/compilers new file mode 100644 index 0000000..f380dd3 --- /dev/null +++ b/packages/compilers @@ -0,0 +1,9 @@ +PACKAGES+="\ +git +clang-6.0 +gcc +libtool +autoconf +make +cmake +" diff --git a/packages/editors b/packages/editors new file mode 100644 index 0000000..99865fa --- /dev/null +++ b/packages/editors @@ -0,0 +1,5 @@ +PACKAGES+="\ +vim +nano +git +" diff --git a/packages/scheduler b/packages/scheduler new file mode 100644 index 0000000..a5df38c --- /dev/null +++ b/packages/scheduler @@ -0,0 +1,4 @@ +PACKAGES+="\ +git +rt-app +" diff --git a/packages/tracers b/packages/tracers new file mode 100644 index 0000000..38c1d43 --- /dev/null +++ b/packages/tracers @@ -0,0 +1,5 @@ +PACKAGES+="\ +linux-perf +trace-cmd +strace +" diff --git a/src/addons/bashrc b/src/addons/bashrc deleted file mode 100644 index 995f3c4..0000000 --- a/src/addons/bashrc +++ /dev/null @@ -1,16 +0,0 @@ -export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/share/bcc/tools/ -export TMPDIR=/tmp/ - -echo "" -echo "########################################################" -echo "# Welcome to androdeb environment running on Android #" -echo "# With great power comes great responsibility! #" -echo "# For questions: joel@linuxinternals.org #" -echo " #" -echo " Try running vim, gcc, clang, bcc, git, make etc. #" -echo " or apt-get install something. #" -echo " #" -echo " Note: For apt-get to work, you need to disable #" -echo " CONFIG_ANDROID_PARANOID_NETWORK and rebuild kernel. #" -echo "########################################################" -echo "" diff --git a/src/addons/device-umount-all b/src/addons/device-umount-all deleted file mode 100755 index f68aac7..0000000 --- a/src/addons/device-umount-all +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh - -if [ "$1x" == "--debugx" ]; then - set -x -fi - -umount_all() { - mpoints=$(mount|cut -d ' ' -f3|grep debian) - for m in $mpoints; - do umount $m 2>&1 > /dev/null - done -} - -for i in $(seq 0 6); do - umount_all 2>&1 > /dev/null -done diff --git a/src/addons/device-unpack b/src/addons/device-unpack deleted file mode 100755 index 40863ea..0000000 --- a/src/addons/device-unpack +++ /dev/null @@ -1,28 +0,0 @@ -#!/system/bin/sh - -set -e - -# Script to do unpack of rootfs, ensures proper tear down -# of existing environment. Expects debian rootfs in -# /data/deb.tar.gz which it will delete after successful -# unpack of rootfs. - -spath=$( cd "$(dirname "$0")" ; pwd -P ) - -if [ ! -f /data/androdeb/deb.tar.gz ]; then - echo "Debian rootfs tar doesn't existing at /data/deb.tar.gz" - echo "Run androdeb with device connected first" - exit 1 -fi - -if [ -d /data/androdeb/debian ]; then - echo "androdeb environment already exists, doing a tear down" - /data/androdeb/device-umount-all - rm -rf /data/androdeb/debian -fi - - -tar -zxf /data/androdeb/deb.tar.gz -C /data/androdeb/ || die 2 "Couldn't unpack due to tar -x errors" -rm /data/deb.tar.gz - -echo "Unpack of rootfs successful! Go forth and hack." diff --git a/src/addons/run b/src/addons/run deleted file mode 100755 index 5804a99..0000000 --- a/src/addons/run +++ /dev/null @@ -1,20 +0,0 @@ -#!/system/bin/sh -spath=$( cd "$(dirname "$0")" ; pwd -P ) - -cd $spath - -# tear everything down -./device-umount-all - -mount --bind /proc debian/proc/ > /dev/null -mount --bind /dev debian/dev/ > /dev/null -mount --bind /sys debian/sys/ > /dev/null -mount --bind /sys/kernel/debug/ debian/sys/kernel/debug/ > /dev/null -mount --bind /sys/kernel/debug/tracing/ debian/sys/kernel/debug/tracing/ -if [ -d /system/ ]; then - mount --bind /system debian/system/ -fi -chroot debian/ /bin/bash - -# tear everything down -./device-umount-all diff --git a/src/addons/run-command b/src/addons/run-command deleted file mode 100755 index 9a99836..0000000 --- a/src/addons/run-command +++ /dev/null @@ -1,8 +0,0 @@ -#!/system/bin/sh - -# Directly execute a command within the chroot of an Android device - -CHROOT_PATH=$1 -CMD=$2 - -chroot $CHROOT_PATH /bin/bash -i -c $CMD diff --git a/src/androdeb b/src/androdeb deleted file mode 100755 index a6195d3..0000000 --- a/src/androdeb +++ /dev/null @@ -1,131 +0,0 @@ -#!/bin/bash -e -spath=$( cd "$(dirname "$0")" ; pwd -P ) -curdir=$( pwd -P ) -source $spath/utils/android - -usage() { - echo "androdeb" - echo " shell Enter the androdeb shell environment and get to work!" - echo "" - echo " prepare Prepare the device (when running for the first time)" - echo " --tracers Enable tracing packages (perf and trace-cmd)" - echo " --compilers Enable compilers on the FS (gcc and clang)" - echo " --editors Enable vim, emacs and git packages" - echo " --scheduler scheduler testing tools (only rt-app for now)" - echo " --bcc Build and install BCC from source" - echo " --fullbuild Enable all of the above tools" - echo "" - echo " --kernelsrc path-to-kernel-sources (can be used for bcc)" - echo " --tempdir use a specific temporary directory" - echo " --distro Debian distro to base on (default is buster)" - exit 1 -} - -# Set default vars -DISTRO=buster; PACKAGES=""; ARCH=arm64 - -# Parse command line parameters -if [ $# -lt 1 ]; then usage; fi; POSITIONAL=() -while [[ $# -gt 0 ]]; do key="$1"; -case $key in - prepare) PREP=1; shift || true; ;; - shell) ASHELL=1; shift || true; ;; - --tracers) source $spath/packages/tracers; shift || true; ;; - --compilers) source $spath/packages/compilers; shift || true; ;; - --editors) source $spath/packages/editors; shift || true; ;; - --scheduler) source $spath/packages/scheduler; shift || true; ;; - --fullbuild) for f in $(ls $spath/packages); do source packages/$f; done; shift || true; ;; - --bcc) source $spath/packages/bcc; INSTALL_BCC=1; shift || true; ;; - --kernelsrc) KERNELSRC="$2"; shift || true; shift || true; ;; - --tempdir) TDIR="$2"; shift || true; shift || true; ;; - *) echo "Unknown option ($1)"; usage; ;; -esac -done - -if [[ ! -z ${PREP+x} ]] && [[ "x$PACKAGES" == "x" ]]; then - echo "Need to specifify something to prepare"; usage; -fi -PACKAGES+="\ -bash -ca-certifcates -" - -########################################################## -# SHELL -########################################################## -if [[ ! -z ${ASHELL+x} ]]; then - set +e; adb shell ls /data/androdeb/debian/.bashrc > /dev/null 2>&1 - if [ $? -ne 0 ]; then - die 2 "Device doesn't have an androdeb environment, run \"./androdeb prepare\" first"; - fi; set -e - - echo "For a better shell experience, run the following commands:" - echo " adb shell" - echo " /data/androdeb/run" - adb shell -x /data/androdeb/run - exit 0 -fi - -########################################################## -# PREPARE -########################################################## -if [[ $EUID -ne 0 ]]; then echo "For prepare, this tool must run as root"; -echo "Try ./sudo androdeb prepare "; exit 3; fi - -# Where do we want to store temporary files -MKTEMP=0; if [[ -z ${TDIR+x} ]] || [[ ! -d "${TDIR}" ]]; then - TDIR=`mktemp -d`; MKTEMP=1; fi - -OUT_TMP=$TDIR/debian; rm -rf $OUT_TMP; mkdir -p $OUT_TMP - -echo "Full package list: $PACKAGES" -echo "Using temporary directory: $OUT_TMP" - -time qemu-debootstrap --arch arm64 --include=$(make_csv "$PACKAGES") \ - $DISTRO $OUT_TMP http://deb.debian.org/debian/ - -# Some reason debootstrap leaves these founded -umount $OUT_TMP/proc/sys/fs/binfmt_misc -umount $OUT_TMP/proc - -# Make bash the default shell -chroot $OUT_TMP rm /bin/sh || true -chroot $OUT_TMP ln -s /bin/bash /bin/sh || true -cp $spath/addons/bashrc $OUT_TMP/.bashrc - -# For mounting android partitions -mkdir $OUT_TMP/system -mkdir $OUT_TMP/vendor - -# Cleanup -rm -rf $OUT_TMP/lib/udev/* -rm -rf $OUT_TMP/var/lib/apt/lists/* -rm -rf $OUT_TMP/var/cache/apt/archives/*deb -rm -rf $OUT_TMP/usr/share/locale/* -rm -rf $OUT_TMP/usr/lib/share/locale/* -rm -rf $OUT_TMP/usr/share/doc/* -rm -rf $OUT_TMP/usr/lib/share/doc/* -rm -rf $OUT_TMP/usr/share/ieee-data/* -rm -rf $OUT_TMP/usr/lib/share/ieee-data/* -rm -rf $OUT_TMP/usr/share/man/* -rm -rf $OUT_TMP/usr/lib/share/man/* - -# Clone BCC if needed -if [[ ! -z ${INSTALL_BCC+x} ]]; then -git clone https://github.com/iovisor/bcc.git $TDIR/debian/bcc-master -cp $spath/bcc/build-bcc.sh $TDIR/debian/bcc-master/ -fi - -echo "Compressing new filesystem to prepare to push to Android /data/androdeb/" -tar -zcf $TDIR/deb.tar.gz -C $TDIR debian - -# Push tar to device and start unpack -adb shell mkdir -p /data/androdeb/ -adb push $TDIR/deb.tar.gz /data/androdeb/ -adb push $spath/addons/device-* /data/androdeb/ -adb shell /data/androdeb/device-unpack - -# rm -rf $OUT_TMP; if [ $MKTEMP -eq 1 ]; then rm -rf $TDIR; fi - -# Use --foreign and --variant=minbase to build minimal deb first stage -# Use fakeroot tar to build tar with root files diff --git a/src/bcc/build-bcc.sh b/src/bcc/build-bcc.sh deleted file mode 100755 index 3118896..0000000 --- a/src/bcc/build-bcc.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -rm -rf build && mkdir -p build && cd build -cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_C_COMPILER=clang-6.0 -DCMAKE_CXX_COMPILER=clang++-6.0 -make -j4 -make install - -# rm -rf /bcc-master diff --git a/src/bcc/build-kernel-headers-tar.sh b/src/bcc/build-kernel-headers-tar.sh deleted file mode 100755 index 84e9c39..0000000 --- a/src/bcc/build-kernel-headers-tar.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash -x -script_full_path=$( cd "$(dirname "$0")" ; pwd -P ) - -if [ $# -ne 1 ]; then - echo "illegal number of parameters, usage: ./build-kernel-headers-tar.sh KERNEL_PATH" - exit 1 -fi - -KERNEL_PATH=$1 -KERNEL_PATH="$(dirname $(readlink -e $KERNEL_PATH))/$(basename $KERNEL_PATH)" -if [ ! -d "$KERNEL_PATH" ]; then - echo "Kernel directory couldn't be found" - exit 3 -fi - -kdir=$(basename $KERNEL_PATH) - -cd $KERNEL_PATH/.. -find $kdir/arch -name include -type d -print | xargs -n1 -i: find : -type f > /tmp/kernel-headers.h -find $kdir/include >> /tmp/kernel-headers.h - -cat /tmp/kernel-headers.h | tar -zcf $KERNEL_PATH/../$kdir.tar.gz -T - -rm /tmp/kernel-headers.h diff --git a/src/packages/bcc b/src/packages/bcc deleted file mode 100644 index 8988cd5..0000000 --- a/src/packages/bcc +++ /dev/null @@ -1,23 +0,0 @@ -PACKAGES+="\ -llvm-6.0-dev -libclang-6.0-dev -libelf-dev -libfl-dev -libunwind-dev -libdw-dev -git -gcc -libtool -autoconf -make -cmake -iperf -arping -ethtool -flex -bison -python -clang-6.0 -python-netaddr -python-pyroute2 -" diff --git a/src/packages/compilers b/src/packages/compilers deleted file mode 100644 index f380dd3..0000000 --- a/src/packages/compilers +++ /dev/null @@ -1,9 +0,0 @@ -PACKAGES+="\ -git -clang-6.0 -gcc -libtool -autoconf -make -cmake -" diff --git a/src/packages/editors b/src/packages/editors deleted file mode 100644 index 99865fa..0000000 --- a/src/packages/editors +++ /dev/null @@ -1,5 +0,0 @@ -PACKAGES+="\ -vim -nano -git -" diff --git a/src/packages/scheduler b/src/packages/scheduler deleted file mode 100644 index a5df38c..0000000 --- a/src/packages/scheduler +++ /dev/null @@ -1,4 +0,0 @@ -PACKAGES+="\ -git -rt-app -" diff --git a/src/packages/tracers b/src/packages/tracers deleted file mode 100644 index 38c1d43..0000000 --- a/src/packages/tracers +++ /dev/null @@ -1,5 +0,0 @@ -PACKAGES+="\ -linux-perf -trace-cmd -strace -" diff --git a/src/utils/android b/src/utils/android deleted file mode 100755 index 1581730..0000000 --- a/src/utils/android +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash -x -# Utilities to interact with android more easily - -make_csv() { - out="" - in=$1 - for p in $in; do - if [ "x$out" == "x" ]; then - out=$p - else - out="$out,$p" - fi - done - echo $out -} - -make_spaces() { - out="" - in=$1 - for p in $in; do - if [ "x$out" == "x" ]; then - out=$p - else - out="$out $p" - fi - done - echo $out -} - -cmd_exists() { - which $1 > /dev/null - return $? -} - -do_adb_root() { - adb root - return $? -} - -die() { - exit_code=$1 - msg=$2 - echo "ERROR: $msg (code $exit_code)" - exit $exit_code -} diff --git a/utils/android b/utils/android new file mode 100755 index 0000000..1581730 --- /dev/null +++ b/utils/android @@ -0,0 +1,45 @@ +#!/bin/bash -x +# Utilities to interact with android more easily + +make_csv() { + out="" + in=$1 + for p in $in; do + if [ "x$out" == "x" ]; then + out=$p + else + out="$out,$p" + fi + done + echo $out +} + +make_spaces() { + out="" + in=$1 + for p in $in; do + if [ "x$out" == "x" ]; then + out=$p + else + out="$out $p" + fi + done + echo $out +} + +cmd_exists() { + which $1 > /dev/null + return $? +} + +do_adb_root() { + adb root + return $? +} + +die() { + exit_code=$1 + msg=$2 + echo "ERROR: $msg (code $exit_code)" + exit $exit_code +} -- cgit v1.2.3 From 8e08fc087a42f685904a4218a778c96ce7f72e64 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sat, 31 Mar 2018 20:05:15 -0700 Subject: Update Signed-off-by: Joel Fernandes --- src/.gitignore | 1 - 1 file changed, 1 deletion(-) delete mode 100644 src/.gitignore diff --git a/src/.gitignore b/src/.gitignore deleted file mode 100644 index 15c6bf7..0000000 --- a/src/.gitignore +++ /dev/null @@ -1 +0,0 @@ -tmpdir -- cgit v1.2.3 From 6f1c70f2cd6a8dab6a33c3c97d5421e30737fba6 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sat, 31 Mar 2018 20:26:26 -0700 Subject: Update Signed-off-by: Joel Fernandes --- addons/run-command | 8 ++++---- androdeb | 10 +++++++++- bcc/build-bcc.sh | 4 ++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/addons/run-command b/addons/run-command index 9a99836..7ad6bc1 100755 --- a/addons/run-command +++ b/addons/run-command @@ -1,8 +1,8 @@ #!/system/bin/sh +spath=$( cd "$(dirname "$0")" ; pwd -P ) +cd $spath # Directly execute a command within the chroot of an Android device +CMD=$1 -CHROOT_PATH=$1 -CMD=$2 - -chroot $CHROOT_PATH /bin/bash -i -c $CMD +chroot debian /bin/bash -i -c $CMD diff --git a/androdeb b/androdeb index a6195d3..45f006f 100755 --- a/androdeb +++ b/androdeb @@ -42,6 +42,10 @@ case $key in esac done +do_adb_root || die 3 "adb root failed, make sure: +- device is connected, and there's only one device (TODO: add multi device support) +- device is userdebug." + if [[ ! -z ${PREP+x} ]] && [[ "x$PACKAGES" == "x" ]]; then echo "Need to specifify something to prepare"; usage; fi @@ -125,7 +129,11 @@ adb push $TDIR/deb.tar.gz /data/androdeb/ adb push $spath/addons/device-* /data/androdeb/ adb shell /data/androdeb/device-unpack -# rm -rf $OUT_TMP; if [ $MKTEMP -eq 1 ]; then rm -rf $TDIR; fi +# Build BCC and install bcc on device if needed +if [[ ! -z ${INSTALL_BCC+x} ]]; then +adb shell /data/androdeb/run-command /bcc-master/build-bcc.sh +fi +# rm -rf $OUT_TMP; if [ $MKTEMP -eq 1 ]; then rm -rf $TDIR; fi # Use --foreign and --variant=minbase to build minimal deb first stage # Use fakeroot tar to build tar with root files diff --git a/bcc/build-bcc.sh b/bcc/build-bcc.sh index 3118896..8fb8d78 100755 --- a/bcc/build-bcc.sh +++ b/bcc/build-bcc.sh @@ -1,4 +1,8 @@ #!/bin/bash +# This script should run within a bcc checkout + +spath=$( cd "$(dirname "$0")" ; pwd -P ) +cd $spath rm -rf build && mkdir -p build && cd build cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_C_COMPILER=clang-6.0 -DCMAKE_CXX_COMPILER=clang++-6.0 -- cgit v1.2.3 From 5572bd24128ced8c53b3d12f429da64a29d5e0bd Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sat, 31 Mar 2018 20:31:21 -0700 Subject: Update Signed-off-by: Joel Fernandes --- addons/bashrc | 4 +++- androdeb | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/addons/bashrc b/addons/bashrc index 995f3c4..1fd7bf2 100644 --- a/addons/bashrc +++ b/addons/bashrc @@ -1,13 +1,15 @@ export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/share/bcc/tools/ export TMPDIR=/tmp/ +echo 0 > /proc/sys/kernel/kptr_restrict + echo "" echo "########################################################" echo "# Welcome to androdeb environment running on Android #" echo "# With great power comes great responsibility! #" echo "# For questions: joel@linuxinternals.org #" echo " #" -echo " Try running vim, gcc, clang, bcc, git, make etc. #" +echo " Try running vim, gcc, clang, bcc, git, make, perf etc #" echo " or apt-get install something. #" echo " #" echo " Note: For apt-get to work, you need to disable #" diff --git a/androdeb b/androdeb index 45f006f..781e002 100755 --- a/androdeb +++ b/androdeb @@ -12,10 +12,12 @@ usage() { echo " --compilers Enable compilers on the FS (gcc and clang)" echo " --editors Enable vim, emacs and git packages" echo " --scheduler scheduler testing tools (only rt-app for now)" + echo " --fullbuild Enable all of the above tools (no BCC)" + echo "" echo " --bcc Build and install BCC from source" - echo " --fullbuild Enable all of the above tools" + echo " --kernelsrc Extract kernel headers for BCC from here" + echo " (use if BCC couldn't find headers on device)" echo "" - echo " --kernelsrc path-to-kernel-sources (can be used for bcc)" echo " --tempdir use a specific temporary directory" echo " --distro Debian distro to base on (default is buster)" exit 1 @@ -34,7 +36,7 @@ case $key in --compilers) source $spath/packages/compilers; shift || true; ;; --editors) source $spath/packages/editors; shift || true; ;; --scheduler) source $spath/packages/scheduler; shift || true; ;; - --fullbuild) for f in $(ls $spath/packages); do source packages/$f; done; shift || true; ;; + --fullbuild) for f in $(ls $spath/packages|grep -v bcc); do source packages/$f; done; shift || true; ;; --bcc) source $spath/packages/bcc; INSTALL_BCC=1; shift || true; ;; --kernelsrc) KERNELSRC="$2"; shift || true; shift || true; ;; --tempdir) TDIR="$2"; shift || true; shift || true; ;; -- cgit v1.2.3 From 72656c5b3fcc370beb8168453dc7a470c67c12b7 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sat, 31 Mar 2018 20:35:33 -0700 Subject: Update Signed-off-by: Joel Fernandes --- androdeb | 21 +++++++++++++++------ bcc/build-kernel-headers-tar.sh | 23 ----------------------- bcc/build-kheaders-targz.sh | 37 +++++++++++++++++++++++++++++++++++++ utils/android | 4 ++-- 4 files changed, 54 insertions(+), 31 deletions(-) delete mode 100755 bcc/build-kernel-headers-tar.sh create mode 100755 bcc/build-kheaders-targz.sh diff --git a/androdeb b/androdeb index 781e002..84c4e7f 100755 --- a/androdeb +++ b/androdeb @@ -44,18 +44,19 @@ case $key in esac done -do_adb_root || die 3 "adb root failed, make sure: -- device is connected, and there's only one device (TODO: add multi device support) -- device is userdebug." - if [[ ! -z ${PREP+x} ]] && [[ "x$PACKAGES" == "x" ]]; then echo "Need to specifify something to prepare"; usage; fi + PACKAGES+="\ bash ca-certifcates " +do_adb_root || die 3 "adb root failed, make sure: +- device is connected, and there's only one device (TODO: add multi device support) +- device is userdebug." + ########################################################## # SHELL ########################################################## @@ -75,8 +76,14 @@ fi ########################################################## # PREPARE ########################################################## -if [[ $EUID -ne 0 ]]; then echo "For prepare, this tool must run as root"; -echo "Try ./sudo androdeb prepare "; exit 3; fi +# Prepare is the last command checked +if [[ ! -z ${PREPARE+x} ]]; then usage; fi + +if [[ $EUID -ne 0 ]]; then die 6 "For prepare, this tool must run as root. Try: ./sudo androdeb prepare "; fi + +if [[ ! -z ${INSTALL_BCC} ]] && [[ -z ${KERNELSRC} ]]; then die 4 "--kernelsrc must be provided with --bcc"; fi + +if [[ ! -z ${KERNELSRC} ]] && [[ ! -d ${KERNELSRC} ]]; then die 5 "Kernel source directory doesn't exist"; fi # Where do we want to store temporary files MKTEMP=0; if [[ -z ${TDIR+x} ]] || [[ ! -d "${TDIR}" ]]; then @@ -131,6 +138,8 @@ adb push $TDIR/deb.tar.gz /data/androdeb/ adb push $spath/addons/device-* /data/androdeb/ adb shell /data/androdeb/device-unpack +build-kheaders-targz.sh + # Build BCC and install bcc on device if needed if [[ ! -z ${INSTALL_BCC+x} ]]; then adb shell /data/androdeb/run-command /bcc-master/build-bcc.sh diff --git a/bcc/build-kernel-headers-tar.sh b/bcc/build-kernel-headers-tar.sh deleted file mode 100755 index 84e9c39..0000000 --- a/bcc/build-kernel-headers-tar.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash -x -script_full_path=$( cd "$(dirname "$0")" ; pwd -P ) - -if [ $# -ne 1 ]; then - echo "illegal number of parameters, usage: ./build-kernel-headers-tar.sh KERNEL_PATH" - exit 1 -fi - -KERNEL_PATH=$1 -KERNEL_PATH="$(dirname $(readlink -e $KERNEL_PATH))/$(basename $KERNEL_PATH)" -if [ ! -d "$KERNEL_PATH" ]; then - echo "Kernel directory couldn't be found" - exit 3 -fi - -kdir=$(basename $KERNEL_PATH) - -cd $KERNEL_PATH/.. -find $kdir/arch -name include -type d -print | xargs -n1 -i: find : -type f > /tmp/kernel-headers.h -find $kdir/include >> /tmp/kernel-headers.h - -cat /tmp/kernel-headers.h | tar -zcf $KERNEL_PATH/../$kdir.tar.gz -T - -rm /tmp/kernel-headers.h diff --git a/bcc/build-kheaders-targz.sh b/bcc/build-kheaders-targz.sh new file mode 100755 index 0000000..a7db3db --- /dev/null +++ b/bcc/build-kheaders-targz.sh @@ -0,0 +1,37 @@ +#!/bin/bash +script_full_path=$( cd "$(dirname "$0")" ; pwd -P ) + +if [ $# -ne 2 ]; then + echo "illegal number of parameters, usage: ./build KERNEL_PATH out.tar.gz" + exit 1 +fi + +# Please provide absolute paths +KERNEL_PATH=$1 +OUT_TAR=$2 + +KERNEL_PATH="$(dirname $(readlink -e $KERNEL_PATH))/$(basename $KERNEL_PATH)" +if [ ! -d "$KERNEL_PATH" ]; then + echo "Kernel directory couldn't be found" + exit 3 +fi + +kdir=$(basename $KERNEL_PATH) + +cd $KERNEL_PATH/.. +find $kdir/arch -name include -type d -print | xargs -n1 -i: find : -type f > /tmp/kernel-headers.h +find $kdir/include >> /tmp/kernel-headers.h + +grep "include/generated/autoconf.h" /tmp/kernel-headers.h > /dev/null 2>&1 +retgrep=$? +if [ $retgrep -ne 0 ]; then + echo "" + echo "The kernel sources at ${KERNEL_PATH} you pointed to aren't configured and built." + echo "Please atleast run in your kernel sources:" + echo $'make defconfig\nmake' + echo $'\nNote: You dont need to do the full build since headers are generated early on.\n' + exit $retgrep +fi + +cat /tmp/kernel-headers.h | tar -zcf $OUT_TAR -T - +# rm /tmp/kernel-headers.h diff --git a/utils/android b/utils/android index 1581730..0dbff7d 100755 --- a/utils/android +++ b/utils/android @@ -33,13 +33,13 @@ cmd_exists() { } do_adb_root() { - adb root + adb root > /dev/null 2>&1 return $? } die() { exit_code=$1 msg=$2 - echo "ERROR: $msg (code $exit_code)" + echo "ERROR: $msg" exit $exit_code } -- cgit v1.2.3 From 25f7915a6fbb5b545cf260a064cb7407b6add96f Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sat, 31 Mar 2018 21:18:40 -0700 Subject: Update Signed-off-by: Joel Fernandes --- androdeb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/androdeb b/androdeb index 84c4e7f..0bd3a25 100755 --- a/androdeb +++ b/androdeb @@ -89,10 +89,15 @@ if [[ ! -z ${KERNELSRC} ]] && [[ ! -d ${KERNELSRC} ]]; then die 5 "Kernel source MKTEMP=0; if [[ -z ${TDIR+x} ]] || [[ ! -d "${TDIR}" ]]; then TDIR=`mktemp -d`; MKTEMP=1; fi +# Package kernel headers +if [[ ! -z ${INSTALL_BCC} ]] && [[ ! -z ${KERNELSRC} ]]; then +TDIR_ABS=$( cd "$TDIR" ; pwd -P ) +$spath/bcc/build-kheaders-targz.sh ${KERNELSRC} $TDIR_ABS/kh.tgz || die 6 "Failed to package kernel headers"; fi + OUT_TMP=$TDIR/debian; rm -rf $OUT_TMP; mkdir -p $OUT_TMP echo "Full package list: $PACKAGES" -echo "Using temporary directory: $OUT_TMP" +echo "Using temporary directory: $TDIR" time qemu-debootstrap --arch arm64 --include=$(make_csv "$PACKAGES") \ $DISTRO $OUT_TMP http://deb.debian.org/debian/ @@ -138,8 +143,6 @@ adb push $TDIR/deb.tar.gz /data/androdeb/ adb push $spath/addons/device-* /data/androdeb/ adb shell /data/androdeb/device-unpack -build-kheaders-targz.sh - # Build BCC and install bcc on device if needed if [[ ! -z ${INSTALL_BCC+x} ]]; then adb shell /data/androdeb/run-command /bcc-master/build-bcc.sh -- cgit v1.2.3 From e381ac7ea51a6addfd694ea38235b42bfcfc94dc Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sat, 31 Mar 2018 21:46:36 -0700 Subject: Update Signed-off-by: Joel Fernandes --- addons/bashrc | 2 ++ addons/device-unpack | 2 +- androdeb | 20 +++++++++++++------- bcc/build-kheaders-targz.sh | 10 +++++----- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/addons/bashrc b/addons/bashrc index 1fd7bf2..93f6819 100644 --- a/addons/bashrc +++ b/addons/bashrc @@ -16,3 +16,5 @@ echo " Note: For apt-get to work, you need to disable #" echo " CONFIG_ANDROID_PARANOID_NETWORK and rebuild kernel. #" echo "########################################################" echo "" + +if [ -d /kernel-headers/ ]; then export BCC_KERNEL_SOURCE=/kernel-headers/; fi diff --git a/addons/device-unpack b/addons/device-unpack index 40863ea..1dcb578 100755 --- a/addons/device-unpack +++ b/addons/device-unpack @@ -23,6 +23,6 @@ fi tar -zxf /data/androdeb/deb.tar.gz -C /data/androdeb/ || die 2 "Couldn't unpack due to tar -x errors" -rm /data/deb.tar.gz +rm /data/androdeb/deb.tar.gz echo "Unpack of rootfs successful! Go forth and hack." diff --git a/androdeb b/androdeb index 0bd3a25..0fd274d 100755 --- a/androdeb +++ b/androdeb @@ -50,7 +50,7 @@ fi PACKAGES+="\ bash -ca-certifcates +ca-certificates " do_adb_root || die 3 "adb root failed, make sure: @@ -60,7 +60,7 @@ do_adb_root || die 3 "adb root failed, make sure: ########################################################## # SHELL ########################################################## -if [[ ! -z ${ASHELL+x} ]]; then +if [ ! -z ${ASHELL+x} ]; then set +e; adb shell ls /data/androdeb/debian/.bashrc > /dev/null 2>&1 if [ $? -ne 0 ]; then die 2 "Device doesn't have an androdeb environment, run \"./androdeb prepare\" first"; @@ -81,20 +81,25 @@ if [[ ! -z ${PREPARE+x} ]]; then usage; fi if [[ $EUID -ne 0 ]]; then die 6 "For prepare, this tool must run as root. Try: ./sudo androdeb prepare "; fi -if [[ ! -z ${INSTALL_BCC} ]] && [[ -z ${KERNELSRC} ]]; then die 4 "--kernelsrc must be provided with --bcc"; fi +if [[ ! -z ${INSTALL_BCC+x} ]] && [[ -z ${KERNELSRC+x} ]]; then die 4 "--kernelsrc must be provided with --bcc"; fi -if [[ ! -z ${KERNELSRC} ]] && [[ ! -d ${KERNELSRC} ]]; then die 5 "Kernel source directory doesn't exist"; fi +if [[ ! -z ${KERNELSRC+x} ]] && [[ ! -d ${KERNELSRC} ]]; then die 5 "Kernel source directory provided doesn't exist"; fi # Where do we want to store temporary files MKTEMP=0; if [[ -z ${TDIR+x} ]] || [[ ! -d "${TDIR}" ]]; then TDIR=`mktemp -d`; MKTEMP=1; fi +rm -rf $TDIR/* +TDIR_ABS=$( cd "$TDIR" ; pwd -P ) # Package kernel headers if [[ ! -z ${INSTALL_BCC} ]] && [[ ! -z ${KERNELSRC} ]]; then -TDIR_ABS=$( cd "$TDIR" ; pwd -P ) $spath/bcc/build-kheaders-targz.sh ${KERNELSRC} $TDIR_ABS/kh.tgz || die 6 "Failed to package kernel headers"; fi OUT_TMP=$TDIR/debian; rm -rf $OUT_TMP; mkdir -p $OUT_TMP +if [ -f $TDIR_ABS/kh.tgz ]; then + mkdir $OUT_TMP/kernel-headers + tar -xvf $TDIR_ABS/kh.tgz -C $OUT_TMP/kernel-headers/ +fi echo "Full package list: $PACKAGES" echo "Using temporary directory: $TDIR" @@ -140,7 +145,7 @@ tar -zcf $TDIR/deb.tar.gz -C $TDIR debian # Push tar to device and start unpack adb shell mkdir -p /data/androdeb/ adb push $TDIR/deb.tar.gz /data/androdeb/ -adb push $spath/addons/device-* /data/androdeb/ +adb push $spath/addons/* /data/androdeb/ adb shell /data/androdeb/device-unpack # Build BCC and install bcc on device if needed @@ -148,6 +153,7 @@ if [[ ! -z ${INSTALL_BCC+x} ]]; then adb shell /data/androdeb/run-command /bcc-master/build-bcc.sh fi -# rm -rf $OUT_TMP; if [ $MKTEMP -eq 1 ]; then rm -rf $TDIR; fi +rm -rf $TDIR/*; if [ $MKTEMP -eq 1 ]; then rm -rf $TDIR; fi + # Use --foreign and --variant=minbase to build minimal deb first stage # Use fakeroot tar to build tar with root files diff --git a/bcc/build-kheaders-targz.sh b/bcc/build-kheaders-targz.sh index a7db3db..105fb6d 100755 --- a/bcc/build-kheaders-targz.sh +++ b/bcc/build-kheaders-targz.sh @@ -16,11 +16,11 @@ if [ ! -d "$KERNEL_PATH" ]; then exit 3 fi -kdir=$(basename $KERNEL_PATH) +# kdir=$(basename $KERNEL_PATH) -cd $KERNEL_PATH/.. -find $kdir/arch -name include -type d -print | xargs -n1 -i: find : -type f > /tmp/kernel-headers.h -find $kdir/include >> /tmp/kernel-headers.h +cd $KERNEL_PATH +find arch -name include -type d -print | xargs -n1 -i: find : -type f > /tmp/kernel-headers.h +find include >> /tmp/kernel-headers.h grep "include/generated/autoconf.h" /tmp/kernel-headers.h > /dev/null 2>&1 retgrep=$? @@ -34,4 +34,4 @@ if [ $retgrep -ne 0 ]; then fi cat /tmp/kernel-headers.h | tar -zcf $OUT_TAR -T - -# rm /tmp/kernel-headers.h +rm /tmp/kernel-headers.h -- cgit v1.2.3 From cfd32ac27f378402ad1927a01e3d55ec497e6d98 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sat, 31 Mar 2018 22:16:59 -0700 Subject: add todo Signed-off-by: Joel Fernandes --- TODO | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 TODO diff --git a/TODO b/TODO new file mode 100644 index 0000000..d56b218 --- /dev/null +++ b/TODO @@ -0,0 +1,2 @@ +- check for space on both host and target +- check if host deps are installed (Qemu etc) -- cgit v1.2.3 From a53e69caaf16ce270e9cfa50decb96f478f5fa4d Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sat, 31 Mar 2018 22:58:02 -0700 Subject: Update Signed-off-by: Joel Fernandes --- bcc/build-bcc.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bcc/build-bcc.sh b/bcc/build-bcc.sh index 8fb8d78..a3ddc83 100755 --- a/bcc/build-bcc.sh +++ b/bcc/build-bcc.sh @@ -8,5 +8,5 @@ rm -rf build && mkdir -p build && cd build cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_C_COMPILER=clang-6.0 -DCMAKE_CXX_COMPILER=clang++-6.0 make -j4 make install - -# rm -rf /bcc-master +cd .. +rm -rf build -- cgit v1.2.3 From 4795bd5667a812bd7f8139f1c2e1702022cd35bf Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sat, 31 Mar 2018 23:34:10 -0700 Subject: Update Signed-off-by: Joel Fernandes --- androdeb | 1 + 1 file changed, 1 insertion(+) diff --git a/androdeb b/androdeb index 0fd274d..ea8a2dd 100755 --- a/androdeb +++ b/androdeb @@ -19,6 +19,7 @@ usage() { echo " (use if BCC couldn't find headers on device)" echo "" echo " --tempdir use a specific temporary directory" + echo " --outdir incase artifacts are to be stored on the host (not usual)" echo " --distro Debian distro to base on (default is buster)" exit 1 } -- cgit v1.2.3 From 9205776d0c6830a87af9012636794c3266460e52 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sat, 31 Mar 2018 23:38:43 -0700 Subject: Update Signed-off-by: Joel Fernandes --- addons/build-debian-tar | 19 +++++++++++++++++++ addons/run-command | 2 +- androdeb | 3 +++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100755 addons/build-debian-tar diff --git a/addons/build-debian-tar b/addons/build-debian-tar new file mode 100755 index 0000000..3e159bf --- /dev/null +++ b/addons/build-debian-tar @@ -0,0 +1,19 @@ +#!/bin/sh +set -e +# Build a tarball out of a android environment which I can then +# upload to places for people who want to expedite the install + +# This script runs on the device + +spath=$( cd "$(dirname "$0")" ; pwd -P ) +cd $spath + +./device-umount-all + +if [ ! -d debian ]; then echo "Error: environment to tar doesn't exist"; exit 1; fi + +rm -rf debian-tar; cp -r debian debian-tar; +rm -rf debian/debian-tar/; mv debian-tar debian/ +./run-command "tar -zcf deb.tgz -C debian-tar/ --exclude='./kernel-headers' ." +mv debian/deb.tgz . +rm -rf debian/debian-tar diff --git a/addons/run-command b/addons/run-command index 7ad6bc1..c58a002 100755 --- a/addons/run-command +++ b/addons/run-command @@ -5,4 +5,4 @@ cd $spath # Directly execute a command within the chroot of an Android device CMD=$1 -chroot debian /bin/bash -i -c $CMD +chroot debian /bin/bash -i -c "$CMD" diff --git a/androdeb b/androdeb index ea8a2dd..ff2cb50 100755 --- a/androdeb +++ b/androdeb @@ -41,6 +41,7 @@ case $key in --bcc) source $spath/packages/bcc; INSTALL_BCC=1; shift || true; ;; --kernelsrc) KERNELSRC="$2"; shift || true; shift || true; ;; --tempdir) TDIR="$2"; shift || true; shift || true; ;; + --outdir) ODIR="$2"; shift || true; shift || true; ;; *) echo "Unknown option ($1)"; usage; ;; esac done @@ -49,6 +50,8 @@ if [[ ! -z ${PREP+x} ]] && [[ "x$PACKAGES" == "x" ]]; then echo "Need to specifify something to prepare"; usage; fi +if [[ ! -z ${ODIR+x} ]] && [[ ! -d $ODIR ]]; then die 7 "Out dir specified doesn't exist"; fi + PACKAGES+="\ bash ca-certificates -- cgit v1.2.3 From 97958e121cdf8011468d7c7175f3fb6638ad9437 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sat, 31 Mar 2018 23:51:44 -0700 Subject: Update Signed-off-by: Joel Fernandes --- androdeb | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/androdeb b/androdeb index ff2cb50..1868e2b 100755 --- a/androdeb +++ b/androdeb @@ -18,8 +18,8 @@ usage() { echo " --kernelsrc Extract kernel headers for BCC from here" echo " (use if BCC couldn't find headers on device)" echo "" - echo " --tempdir use a specific temporary directory" - echo " --outdir incase artifacts are to be stored on the host (not usual)" + echo " --tempdir Use a specific temporary directory for build operation" + echo " --buildtar Local directory to store tarball of androdeb env from device" echo " --distro Debian distro to base on (default is buster)" exit 1 } @@ -41,16 +41,15 @@ case $key in --bcc) source $spath/packages/bcc; INSTALL_BCC=1; shift || true; ;; --kernelsrc) KERNELSRC="$2"; shift || true; shift || true; ;; --tempdir) TDIR="$2"; shift || true; shift || true; ;; - --outdir) ODIR="$2"; shift || true; shift || true; ;; + --buildtar) TARDIR="$2"; shift || true; shift || true; ;; *) echo "Unknown option ($1)"; usage; ;; esac done if [[ ! -z ${PREP+x} ]] && [[ "x$PACKAGES" == "x" ]]; then - echo "Need to specifify something to prepare"; usage; -fi + echo "Need to specifify something to prepare"; usage; fi -if [[ ! -z ${ODIR+x} ]] && [[ ! -d $ODIR ]]; then die 7 "Out dir specified doesn't exist"; fi +if [[ ! -z ${TARDIR+x} ]] && [[ ! -d $TARDIR ]]; then die 7 "Tar dir specified doesn't exist"; fi PACKAGES+="\ bash @@ -140,8 +139,7 @@ rm -rf $OUT_TMP/usr/lib/share/man/* # Clone BCC if needed if [[ ! -z ${INSTALL_BCC+x} ]]; then git clone https://github.com/iovisor/bcc.git $TDIR/debian/bcc-master -cp $spath/bcc/build-bcc.sh $TDIR/debian/bcc-master/ -fi +cp $spath/bcc/build-bcc.sh $TDIR/debian/bcc-master/; fi echo "Compressing new filesystem to prepare to push to Android /data/androdeb/" tar -zcf $TDIR/deb.tar.gz -C $TDIR debian @@ -154,10 +152,15 @@ adb shell /data/androdeb/device-unpack # Build BCC and install bcc on device if needed if [[ ! -z ${INSTALL_BCC+x} ]]; then -adb shell /data/androdeb/run-command /bcc-master/build-bcc.sh -fi +adb shell /data/androdeb/run-command /bcc-master/build-bcc.sh; fi rm -rf $TDIR/*; if [ $MKTEMP -eq 1 ]; then rm -rf $TDIR; fi +# Extract a tar of the built, compiled and installed androdeb env +if [[ ! -z ${TARDIR+x} ]]; then + echo "Creating and pulling tarball of androdeb env from device" + adb shell /data/androdeb/build-debian-tar + adb pull /data/androdeb/deb.tgz $TARDIR/; fi + # Use --foreign and --variant=minbase to build minimal deb first stage # Use fakeroot tar to build tar with root files -- cgit v1.2.3 From e828d03c45ab584b4ec13f224aa7e5370a5f5297 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sat, 31 Mar 2018 23:57:35 -0700 Subject: Update Signed-off-by: Joel Fernandes --- androdeb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/androdeb b/androdeb index 1868e2b..b41b224 100755 --- a/androdeb +++ b/androdeb @@ -31,7 +31,7 @@ DISTRO=buster; PACKAGES=""; ARCH=arm64 if [ $# -lt 1 ]; then usage; fi; POSITIONAL=() while [[ $# -gt 0 ]]; do key="$1"; case $key in - prepare) PREP=1; shift || true; ;; + prepare) PREPARE=1; shift || true; ;; shell) ASHELL=1; shift || true; ;; --tracers) source $spath/packages/tracers; shift || true; ;; --compilers) source $spath/packages/compilers; shift || true; ;; @@ -80,7 +80,7 @@ fi # PREPARE ########################################################## # Prepare is the last command checked -if [[ ! -z ${PREPARE+x} ]]; then usage; fi +if [[ -z ${PREPARE+x} ]]; then usage; fi if [[ $EUID -ne 0 ]]; then die 6 "For prepare, this tool must run as root. Try: ./sudo androdeb prepare "; fi -- cgit v1.2.3 From a6a75980a01de2df137394da3f46550417759a65 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 00:07:20 -0700 Subject: Update Signed-off-by: Joel Fernandes --- addons/bashrc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/bashrc b/addons/bashrc index 93f6819..96f7720 100644 --- a/addons/bashrc +++ b/addons/bashrc @@ -1,8 +1,6 @@ export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/share/bcc/tools/ export TMPDIR=/tmp/ -echo 0 > /proc/sys/kernel/kptr_restrict - echo "" echo "########################################################" echo "# Welcome to androdeb environment running on Android #" @@ -17,4 +15,7 @@ echo " CONFIG_ANDROID_PARANOID_NETWORK and rebuild kernel. #" echo "########################################################" echo "" +psk=/proc/sys/kernel/kptr_restrict +if [ -f $psk ]; then echo 0 > $psk; fi + if [ -d /kernel-headers/ ]; then export BCC_KERNEL_SOURCE=/kernel-headers/; fi -- cgit v1.2.3 From db939c9d6f5bc0832445c9edcb72a92abe54f0e2 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 00:19:18 -0700 Subject: Update Signed-off-by: Joel Fernandes --- TODO | 2 ++ androdeb | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/TODO b/TODO index d56b218..c51dab7 100644 --- a/TODO +++ b/TODO @@ -1,2 +1,4 @@ - check for space on both host and target - check if host deps are installed (Qemu etc) +- make possible to use external tgz (from web or local fs) +- update headers on device if using external tgz diff --git a/androdeb b/androdeb index b41b224..98ff3d1 100755 --- a/androdeb +++ b/androdeb @@ -160,7 +160,8 @@ rm -rf $TDIR/*; if [ $MKTEMP -eq 1 ]; then rm -rf $TDIR; fi if [[ ! -z ${TARDIR+x} ]]; then echo "Creating and pulling tarball of androdeb env from device" adb shell /data/androdeb/build-debian-tar - adb pull /data/androdeb/deb.tgz $TARDIR/; fi + adb pull /data/androdeb/deb.tgz $TARDIR/ + adb shell rm /data/androdeb/deb.tgz; fi # Use --foreign and --variant=minbase to build minimal deb first stage # Use fakeroot tar to build tar with root files -- cgit v1.2.3 From cf1ceb3e14283834029c489d0aeeaac45505f7b8 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 10:10:15 -0700 Subject: Update Signed-off-by: Joel Fernandes --- androdeb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/androdeb b/androdeb index 98ff3d1..cd23618 100755 --- a/androdeb +++ b/androdeb @@ -69,10 +69,7 @@ if [ ! -z ${ASHELL+x} ]; then die 2 "Device doesn't have an androdeb environment, run \"./androdeb prepare\" first"; fi; set -e - echo "For a better shell experience, run the following commands:" - echo " adb shell" - echo " /data/androdeb/run" - adb shell -x /data/androdeb/run + adb shell -t /data/androdeb/run exit 0 fi -- cgit v1.2.3 From 9f00bf4269beac280dfc41165c0f7c20cca55a4c Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 10:36:33 -0700 Subject: Update Signed-off-by: Joel Fernandes --- androdeb | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/androdeb b/androdeb index cd23618..2ed2485 100755 --- a/androdeb +++ b/androdeb @@ -12,14 +12,16 @@ usage() { echo " --compilers Enable compilers on the FS (gcc and clang)" echo " --editors Enable vim, emacs and git packages" echo " --scheduler scheduler testing tools (only rt-app for now)" + echo "" echo " --fullbuild Enable all of the above tools (no BCC)" + echo " --archive Use archive for root fs (overrides all other prepare options)" echo "" echo " --bcc Build and install BCC from source" echo " --kernelsrc Extract kernel headers for BCC from here" echo " (use if BCC couldn't find headers on device)" echo "" echo " --tempdir Use a specific temporary directory for build operation" - echo " --buildtar Local directory to store tarball of androdeb env from device" + echo " --buildtar Local directory to store tarball of androdeb env from device" echo " --distro Debian distro to base on (default is buster)" exit 1 } @@ -33,6 +35,7 @@ while [[ $# -gt 0 ]]; do key="$1"; case $key in prepare) PREPARE=1; shift || true; ;; shell) ASHELL=1; shift || true; ;; + --archive) TARF=$2; shift || true; shift || true; ;; --tracers) source $spath/packages/tracers; shift || true; ;; --compilers) source $spath/packages/compilers; shift || true; ;; --editors) source $spath/packages/editors; shift || true; ;; @@ -46,8 +49,8 @@ case $key in esac done -if [[ ! -z ${PREP+x} ]] && [[ "x$PACKAGES" == "x" ]]; then - echo "Need to specifify something to prepare"; usage; fi +if [ ! -z "$PREPARE" ] && [ -z "$TARF" ] && [ "x$PACKAGES" == "x" ]; then + echo "Need to specifify something to prepare."; usage; fi if [[ ! -z ${TARDIR+x} ]] && [[ ! -d $TARDIR ]]; then die 7 "Tar dir specified doesn't exist"; fi @@ -77,10 +80,14 @@ fi # PREPARE ########################################################## # Prepare is the last command checked -if [[ -z ${PREPARE+x} ]]; then usage; fi +if [ -z "$PREPARE" ]; then usage; fi if [[ $EUID -ne 0 ]]; then die 6 "For prepare, this tool must run as root. Try: ./sudo androdeb prepare "; fi +if [ ! -z "$TARF" ]; then + if [ ! -f ${TARF} ]; then die 7 "archive provided doesn't exist"; fi +fi + if [[ ! -z ${INSTALL_BCC+x} ]] && [[ -z ${KERNELSRC+x} ]]; then die 4 "--kernelsrc must be provided with --bcc"; fi if [[ ! -z ${KERNELSRC+x} ]] && [[ ! -d ${KERNELSRC} ]]; then die 5 "Kernel source directory provided doesn't exist"; fi @@ -101,6 +108,14 @@ if [ -f $TDIR_ABS/kh.tgz ]; then tar -xvf $TDIR_ABS/kh.tgz -C $OUT_TMP/kernel-headers/ fi +if [ ! -z "$TARF" ]; then + echo "Using archive at $TARF for filesystem preparation" + adb shell mkdir -p /data/androdeb/ + adb push $TARF /data/androdeb/ + adb push $spath/addons/* /data/androdeb/ + adb shell /data/androdeb/device-unpack +else + echo "Full package list: $PACKAGES" echo "Using temporary directory: $TDIR" @@ -151,6 +166,9 @@ adb shell /data/androdeb/device-unpack if [[ ! -z ${INSTALL_BCC+x} ]]; then adb shell /data/androdeb/run-command /bcc-master/build-bcc.sh; fi + +fi # !TARF + rm -rf $TDIR/*; if [ $MKTEMP -eq 1 ]; then rm -rf $TDIR; fi # Extract a tar of the built, compiled and installed androdeb env -- cgit v1.2.3 From 7c6203847c3b62c4952eea9ca897e8971ada5550 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 10:38:18 -0700 Subject: Update Signed-off-by: Joel Fernandes --- addons/build-debian-tar | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/build-debian-tar b/addons/build-debian-tar index 3e159bf..515c142 100755 --- a/addons/build-debian-tar +++ b/addons/build-debian-tar @@ -13,7 +13,7 @@ cd $spath if [ ! -d debian ]; then echo "Error: environment to tar doesn't exist"; exit 1; fi rm -rf debian-tar; cp -r debian debian-tar; -rm -rf debian/debian-tar/; mv debian-tar debian/ -./run-command "tar -zcf deb.tgz -C debian-tar/ --exclude='./kernel-headers' ." +rm -rf debian/debian; mv debian-tar debian/debian +./run-command "tar -zcf deb.tgz --exclude='./kernel-headers' debian" mv debian/deb.tgz . rm -rf debian/debian-tar -- cgit v1.2.3 From bb6337d8fb72ecb2f420f1d4f8bc824a4a3d50f8 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 11:03:16 -0700 Subject: Update Signed-off-by: Joel Fernandes --- androdeb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/androdeb b/androdeb index 2ed2485..1cb5423 100755 --- a/androdeb +++ b/androdeb @@ -111,7 +111,7 @@ fi if [ ! -z "$TARF" ]; then echo "Using archive at $TARF for filesystem preparation" adb shell mkdir -p /data/androdeb/ - adb push $TARF /data/androdeb/ + adb push $TARF /data/androdeb/deb.tar.gz adb push $spath/addons/* /data/androdeb/ adb shell /data/androdeb/device-unpack else -- cgit v1.2.3 From 482302521ca3fcbcac64d25801ed2a66c8c44e6c Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 11:05:48 -0700 Subject: Update Signed-off-by: Joel Fernandes --- addons/build-debian-tar | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/build-debian-tar b/addons/build-debian-tar index 515c142..a5b9bbd 100755 --- a/addons/build-debian-tar +++ b/addons/build-debian-tar @@ -14,6 +14,6 @@ if [ ! -d debian ]; then echo "Error: environment to tar doesn't exist"; exit 1; rm -rf debian-tar; cp -r debian debian-tar; rm -rf debian/debian; mv debian-tar debian/debian -./run-command "tar -zcf deb.tgz --exclude='./kernel-headers' debian" +./run-command "tar -zcf deb.tgz --exclude='debian/kernel-headers' debian" mv debian/deb.tgz . rm -rf debian/debian-tar -- cgit v1.2.3 From 87831dc794b586ae7ea18448c35abf73491e00af Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 11:08:02 -0700 Subject: Update Signed-off-by: Joel Fernandes --- TODO | 1 + 1 file changed, 1 insertion(+) diff --git a/TODO b/TODO index c51dab7..c7bac62 100644 --- a/TODO +++ b/TODO @@ -2,3 +2,4 @@ - check if host deps are installed (Qemu etc) - make possible to use external tgz (from web or local fs) - update headers on device if using external tgz +- get perf to work -- cgit v1.2.3 From b51a039f2f4dc26bfb2b35fb939cbec7ea881e1e Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 11:08:50 -0700 Subject: Update Signed-off-by: Joel Fernandes --- TODO | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TODO b/TODO index c7bac62..257bcf8 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,5 @@ - check for space on both host and target - check if host deps are installed (Qemu etc) - make possible to use external tgz (from web or local fs) -- update headers on device if using external tgz +- make update headers indep of bcc, but bcc dependent on it - get perf to work -- cgit v1.2.3 From df70d45fedc5fc064d90e9a69f0271e868c7bc90 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 13:05:41 -0700 Subject: Update Signed-off-by: Joel Fernandes --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 11c58f5..89cdefc 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ Project to give a rich Android development environment for end-users to use over adb. -This will work only on rooted android devices that are running fairly recent Android (O or greater). +This will work only on rooted android devices that are running fairly recent Android (N or later). -- cgit v1.2.3 From a67be0bb5cad54538e93c015a6994f9ac6e34785 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 13:40:34 -0700 Subject: Update Signed-off-by: Joel Fernandes --- androdeb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/androdeb b/androdeb index 1cb5423..1775aa9 100755 --- a/androdeb +++ b/androdeb @@ -1,4 +1,6 @@ #!/bin/bash -e +VERSION=0.9 + spath=$( cd "$(dirname "$0")" ; pwd -P ) curdir=$( pwd -P ) source $spath/utils/android @@ -14,6 +16,8 @@ usage() { echo " --scheduler scheduler testing tools (only rt-app for now)" echo "" echo " --fullbuild Enable all of the above tools (no BCC)" + echo "" + echo " --download Download full FS archive from web (overrides all tools specified)" echo " --archive Use archive for root fs (overrides all other prepare options)" echo "" echo " --bcc Build and install BCC from source" @@ -41,6 +45,7 @@ case $key in --editors) source $spath/packages/editors; shift || true; ;; --scheduler) source $spath/packages/scheduler; shift || true; ;; --fullbuild) for f in $(ls $spath/packages|grep -v bcc); do source packages/$f; done; shift || true; ;; + --download) DOWNLOAD=1; shift || true; ;; --bcc) source $spath/packages/bcc; INSTALL_BCC=1; shift || true; ;; --kernelsrc) KERNELSRC="$2"; shift || true; shift || true; ;; --tempdir) TDIR="$2"; shift || true; shift || true; ;; @@ -49,11 +54,12 @@ case $key in esac done -if [ ! -z "$PREPARE" ] && [ -z "$TARF" ] && [ "x$PACKAGES" == "x" ]; then - echo "Need to specifify something to prepare."; usage; fi +if [ ! -z "$PREPARE" ] && [ -z "$DOWNLOAD" ] && [ -z "$TARF" ] && [ "x$PACKAGES" == "x" ]; then + echo "Need to specifify something to prepare, or try: ./andrdeb prepare --download"; usage; fi if [[ ! -z ${TARDIR+x} ]] && [[ ! -d $TARDIR ]]; then die 7 "Tar dir specified doesn't exist"; fi +# Default packages PACKAGES+="\ bash ca-certificates @@ -84,7 +90,7 @@ if [ -z "$PREPARE" ]; then usage; fi if [[ $EUID -ne 0 ]]; then die 6 "For prepare, this tool must run as root. Try: ./sudo androdeb prepare "; fi -if [ ! -z "$TARF" ]; then +if [ ! -z "$TARF" ] && [ -z "$DOWNLOAD" ]; then if [ ! -f ${TARF} ]; then die 7 "archive provided doesn't exist"; fi fi @@ -98,6 +104,10 @@ MKTEMP=0; if [[ -z ${TDIR+x} ]] || [[ ! -d "${TDIR}" ]]; then rm -rf $TDIR/* TDIR_ABS=$( cd "$TDIR" ; pwd -P ) +if [ ! -z "$DOWNLOAD" ]; then + curl -L https://github.com/joelagnel/androdeb/releases/download/$VERSION/androdeb-fs.tgz --output $TDIR_ABS/androdeb-fs.tgz; + TARF=$TDIR_ABS/androdeb-fs.tgz; fi + # Package kernel headers if [[ ! -z ${INSTALL_BCC} ]] && [[ ! -z ${KERNELSRC} ]]; then $spath/bcc/build-kheaders-targz.sh ${KERNELSRC} $TDIR_ABS/kh.tgz || die 6 "Failed to package kernel headers"; fi -- cgit v1.2.3 From ca8fb557ec062ce21e87faf1286ce77ad174256c Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 13:48:16 -0700 Subject: Update Signed-off-by: Joel Fernandes --- androdeb | 32 ++++++-------------------------- utils/banners | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 26 deletions(-) create mode 100755 utils/banners diff --git a/androdeb b/androdeb index 1775aa9..69282f0 100755 --- a/androdeb +++ b/androdeb @@ -1,34 +1,10 @@ #!/bin/bash -e -VERSION=0.9 +VERSION=v0.9 spath=$( cd "$(dirname "$0")" ; pwd -P ) curdir=$( pwd -P ) source $spath/utils/android - -usage() { - echo "androdeb" - echo " shell Enter the androdeb shell environment and get to work!" - echo "" - echo " prepare Prepare the device (when running for the first time)" - echo " --tracers Enable tracing packages (perf and trace-cmd)" - echo " --compilers Enable compilers on the FS (gcc and clang)" - echo " --editors Enable vim, emacs and git packages" - echo " --scheduler scheduler testing tools (only rt-app for now)" - echo "" - echo " --fullbuild Enable all of the above tools (no BCC)" - echo "" - echo " --download Download full FS archive from web (overrides all tools specified)" - echo " --archive Use archive for root fs (overrides all other prepare options)" - echo "" - echo " --bcc Build and install BCC from source" - echo " --kernelsrc Extract kernel headers for BCC from here" - echo " (use if BCC couldn't find headers on device)" - echo "" - echo " --tempdir Use a specific temporary directory for build operation" - echo " --buildtar Local directory to store tarball of androdeb env from device" - echo " --distro Debian distro to base on (default is buster)" - exit 1 -} +source $spath/utils/banners # Set default vars DISTRO=buster; PACKAGES=""; ARCH=arm64 @@ -50,6 +26,7 @@ case $key in --kernelsrc) KERNELSRC="$2"; shift || true; shift || true; ;; --tempdir) TDIR="$2"; shift || true; shift || true; ;; --buildtar) TARDIR="$2"; shift || true; shift || true; ;; + --debug) set -x; shift || true; ;; *) echo "Unknown option ($1)"; usage; ;; esac done @@ -98,6 +75,8 @@ if [[ ! -z ${INSTALL_BCC+x} ]] && [[ -z ${KERNELSRC+x} ]]; then die 4 "--kernels if [[ ! -z ${KERNELSRC+x} ]] && [[ ! -d ${KERNELSRC} ]]; then die 5 "Kernel source directory provided doesn't exist"; fi +print_prepare_banner + # Where do we want to store temporary files MKTEMP=0; if [[ -z ${TDIR+x} ]] || [[ ! -d "${TDIR}" ]]; then TDIR=`mktemp -d`; MKTEMP=1; fi @@ -105,6 +84,7 @@ rm -rf $TDIR/* TDIR_ABS=$( cd "$TDIR" ; pwd -P ) if [ ! -z "$DOWNLOAD" ]; then + echo "Downloading Androdeb from the web..."; echo "" curl -L https://github.com/joelagnel/androdeb/releases/download/$VERSION/androdeb-fs.tgz --output $TDIR_ABS/androdeb-fs.tgz; TARF=$TDIR_ABS/androdeb-fs.tgz; fi diff --git a/utils/banners b/utils/banners new file mode 100755 index 0000000..3bad2a9 --- /dev/null +++ b/utils/banners @@ -0,0 +1,33 @@ +#!/bin/bash -x + +print_prepare_banner() { + echo "Preparing device..." + echo "" + +usage() { + echo "androdeb" + echo " shell Enter the androdeb shell environment and get to work!" + echo "" + echo " prepare Prepare the device (when running for the first time)" + echo " --tracers Enable tracing packages (perf and trace-cmd)" + echo " --compilers Enable compilers on the FS (gcc and clang)" + echo " --editors Enable vim, emacs and git packages" + echo " --scheduler scheduler testing tools (only rt-app for now)" + echo "" + echo " --fullbuild Enable all of the above tools (no BCC)" + echo "" + echo " --download Download full FS archive from web (overrides all tools specified)" + echo " --archive Use archive for root fs (overrides all other prepare options)" + echo "" + echo " --bcc Build and install BCC from source" + echo " --kernelsrc Extract kernel headers for BCC from here" + echo " (use if BCC couldn't find headers on device)" + echo "" + echo " --tempdir Use a specific temporary directory for build operation" + echo " --buildtar Local directory to store tarball of androdeb env from device" + echo " --distro Debian distro to base on (default is buster)" + echo " --debug" + exit 1 +} + + -- cgit v1.2.3 From a34c884df0b67b214a7875ae57b5917511e73ae0 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 13:48:47 -0700 Subject: Update Signed-off-by: Joel Fernandes --- addons/build-debian-tar | 4 ++-- androdeb | 2 +- utils/banners | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/addons/build-debian-tar b/addons/build-debian-tar index a5b9bbd..ce7a753 100755 --- a/addons/build-debian-tar +++ b/addons/build-debian-tar @@ -14,6 +14,6 @@ if [ ! -d debian ]; then echo "Error: environment to tar doesn't exist"; exit 1; rm -rf debian-tar; cp -r debian debian-tar; rm -rf debian/debian; mv debian-tar debian/debian -./run-command "tar -zcf deb.tgz --exclude='debian/kernel-headers' debian" -mv debian/deb.tgz . +./run-command "tar -zcf androdeb-fs.tgz --exclude='debian/kernel-headers' debian" +mv debian/androdeb-fs.tgz . rm -rf debian/debian-tar diff --git a/androdeb b/androdeb index 69282f0..5fc1edf 100755 --- a/androdeb +++ b/androdeb @@ -165,7 +165,7 @@ rm -rf $TDIR/*; if [ $MKTEMP -eq 1 ]; then rm -rf $TDIR; fi if [[ ! -z ${TARDIR+x} ]]; then echo "Creating and pulling tarball of androdeb env from device" adb shell /data/androdeb/build-debian-tar - adb pull /data/androdeb/deb.tgz $TARDIR/ + adb pull /data/androdeb/androdeb-fs.tgz $TARDIR/ adb shell rm /data/androdeb/deb.tgz; fi # Use --foreign and --variant=minbase to build minimal deb first stage diff --git a/utils/banners b/utils/banners index 3bad2a9..fcdc1da 100755 --- a/utils/banners +++ b/utils/banners @@ -3,6 +3,7 @@ print_prepare_banner() { echo "Preparing device..." echo "" +} usage() { echo "androdeb" -- cgit v1.2.3 From 0b662e7873e08d5bc4caef65056e0c12d2876d12 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 13:54:30 -0700 Subject: Update Signed-off-by: Joel Fernandes --- TODO | 2 +- packages/tracers | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/TODO b/TODO index 257bcf8..7de7a1d 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,5 @@ - check for space on both host and target - check if host deps are installed (Qemu etc) -- make possible to use external tgz (from web or local fs) - make update headers indep of bcc, but bcc dependent on it +- build tar independent of prepare - get perf to work diff --git a/packages/tracers b/packages/tracers index 38c1d43..3486640 100644 --- a/packages/tracers +++ b/packages/tracers @@ -1,5 +1,7 @@ PACKAGES+="\ linux-perf +linux-perf-4.9 +linux-perf-4.15 trace-cmd strace " -- cgit v1.2.3 From bfba005f1c4db5d611506644c451a468fe04b2e3 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 13:56:17 -0700 Subject: Update Signed-off-by: Joel Fernandes --- TODO | 1 + 1 file changed, 1 insertion(+) diff --git a/TODO b/TODO index 7de7a1d..487cbec 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,6 @@ - check for space on both host and target - check if host deps are installed (Qemu etc) - make update headers indep of bcc, but bcc dependent on it +- make fullbuild also select bcc - build tar independent of prepare - get perf to work -- cgit v1.2.3 From 55eef6868ed2324f4d3c5723b2417234c231186a Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 14:02:37 -0700 Subject: Update Signed-off-by: Joel Fernandes --- README.md | 4 +++- addons/bashrc | 21 ++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 89cdefc..4c42ba0 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ Project to give a rich Android development environment for end-users to use over adb. -This will work only on rooted android devices that are running fairly recent Android (N or later). +Notes: +* This will work only on rooted android devices that are running fairly recent Android (N or later). +* This project is pre-alpha and work in progress! diff --git a/addons/bashrc b/addons/bashrc index 96f7720..c9cf3f4 100644 --- a/addons/bashrc +++ b/addons/bashrc @@ -2,17 +2,16 @@ export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/sh export TMPDIR=/tmp/ echo "" -echo "########################################################" -echo "# Welcome to androdeb environment running on Android #" -echo "# With great power comes great responsibility! #" -echo "# For questions: joel@linuxinternals.org #" -echo " #" -echo " Try running vim, gcc, clang, bcc, git, make, perf etc #" -echo " or apt-get install something. #" -echo " #" -echo " Note: For apt-get to work, you need to disable #" -echo " CONFIG_ANDROID_PARANOID_NETWORK and rebuild kernel. #" -echo "########################################################" +echo "##########################################################" +echo "# Welcome to androdeb environment running on Android! #" +echo "# Questions to: Joel Fernandes #" +echo " #" +echo " Try running vim, gcc, clang, bcc, git, make, perf etc #" +echo " or apt-get install something. #" +echo " #" +echo " Note: For apt-get to work, you need to disable #" +echo " CONFIG_ANDROID_PARANOID_NETWORK and rebuild kernel. #" +echo "##########################################################" echo "" psk=/proc/sys/kernel/kptr_restrict -- cgit v1.2.3 From de8e752b5b37f4b12c70117b978ff53aaba7fdb4 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 14:11:13 -0700 Subject: Update Signed-off-by: Joel Fernandes --- packages/tracers | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/tracers b/packages/tracers index 3486640..321c071 100644 --- a/packages/tracers +++ b/packages/tracers @@ -1,6 +1,5 @@ PACKAGES+="\ linux-perf -linux-perf-4.9 linux-perf-4.15 trace-cmd strace -- cgit v1.2.3 From 46c642d525996fc5efc50cd2abe3d3d3fda9f2de Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 15:08:52 -0700 Subject: Update Signed-off-by: Joel Fernandes --- androdeb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/androdeb b/androdeb index 5fc1edf..2e9f4db 100755 --- a/androdeb +++ b/androdeb @@ -166,7 +166,7 @@ if [[ ! -z ${TARDIR+x} ]]; then echo "Creating and pulling tarball of androdeb env from device" adb shell /data/androdeb/build-debian-tar adb pull /data/androdeb/androdeb-fs.tgz $TARDIR/ - adb shell rm /data/androdeb/deb.tgz; fi + adb shell rm /data/androdeb/androdeb-fs.tgz; fi # Use --foreign and --variant=minbase to build minimal deb first stage # Use fakeroot tar to build tar with root files -- cgit v1.2.3 From 417bb1821768114546b4b6e63c3bdaf70e3727da Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 15:08:52 -0700 Subject: Update Signed-off-by: Joel Fernandes --- addons/run | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/addons/run b/addons/run index 5804a99..6a083fa 100755 --- a/addons/run +++ b/addons/run @@ -11,9 +11,8 @@ mount --bind /dev debian/dev/ > /dev/null mount --bind /sys debian/sys/ > /dev/null mount --bind /sys/kernel/debug/ debian/sys/kernel/debug/ > /dev/null mount --bind /sys/kernel/debug/tracing/ debian/sys/kernel/debug/tracing/ -if [ -d /system/ ]; then - mount --bind /system debian/system/ -fi +if [ -d /system/ ]; then; mount --bind /system debian/system/; fi +if [ -d /vendor/ ]; then; mount --bind /vendor debian/vendor/; fi chroot debian/ /bin/bash # tear everything down -- cgit v1.2.3 From 0b735b5c94c6980e90b93cc9f6a9ec7dfdb48673 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 15:33:57 -0700 Subject: Update Signed-off-by: Joel Fernandes --- androdeb | 6 +++--- utils/banners | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/androdeb b/androdeb index 2e9f4db..ce8d02a 100755 --- a/androdeb +++ b/androdeb @@ -112,9 +112,9 @@ echo "Using temporary directory: $TDIR" time qemu-debootstrap --arch arm64 --include=$(make_csv "$PACKAGES") \ $DISTRO $OUT_TMP http://deb.debian.org/debian/ -# Some reason debootstrap leaves these founded -umount $OUT_TMP/proc/sys/fs/binfmt_misc -umount $OUT_TMP/proc +# Some reason debootstrap leaves these mounted +umount $OUT_TMP/proc/sys/fs/binfmt_misc || true +umount $OUT_TMP/proc || true # Make bash the default shell chroot $OUT_TMP rm /bin/sh || true diff --git a/utils/banners b/utils/banners index fcdc1da..9a5ad56 100755 --- a/utils/banners +++ b/utils/banners @@ -17,17 +17,17 @@ usage() { echo "" echo " --fullbuild Enable all of the above tools (no BCC)" echo "" - echo " --download Download full FS archive from web (overrides all tools specified)" + echo " --download Download full FS archive from web (overrides all tools specified)" echo " --archive Use archive for root fs (overrides all other prepare options)" echo "" echo " --bcc Build and install BCC from source" echo " --kernelsrc Extract kernel headers for BCC from here" - echo " (use if BCC couldn't find headers on device)" + echo " (use if BCC couldn't find headers on device)" echo "" echo " --tempdir Use a specific temporary directory for build operation" echo " --buildtar Local directory to store tarball of androdeb env from device" echo " --distro Debian distro to base on (default is buster)" - echo " --debug" + echo " --debug" exit 1 } -- cgit v1.2.3 From f0c5409e3a24dd0713aab721271d6ed080d8c420 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 19:05:10 -0700 Subject: androdeb: Reorganize a bit, make headers update possible post install Signed-off-by: Joel Fernandes --- TODO | 1 + androdeb | 63 +++++++++++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/TODO b/TODO index 487cbec..0b3366e 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,6 @@ - check for space on both host and target - check if host deps are installed (Qemu etc) + - make update headers indep of bcc, but bcc dependent on it - make fullbuild also select bcc - build tar independent of prepare diff --git a/androdeb b/androdeb index ce8d02a..b23cfcc 100755 --- a/androdeb +++ b/androdeb @@ -7,7 +7,13 @@ source $spath/utils/android source $spath/utils/banners # Set default vars -DISTRO=buster; PACKAGES=""; ARCH=arm64 +DISTRO=buster; ARCH=arm64 + +# Default packages +DEFAULT_PACKAGES+="\ +bash +ca-certificates +" # Parse command line parameters if [ $# -lt 1 ]; then usage; fi; POSITIONAL=() @@ -31,17 +37,11 @@ case $key in esac done -if [ ! -z "$PREPARE" ] && [ -z "$DOWNLOAD" ] && [ -z "$TARF" ] && [ "x$PACKAGES" == "x" ]; then +if [ ! -z "$PREPARE" ] && [ -z "$DOWNLOAD" ] && [ -z "$TARF" ] && [ -z "$PACKAGES" ] && [ -z "$KERNELSRC" ]; then echo "Need to specifify something to prepare, or try: ./andrdeb prepare --download"; usage; fi if [[ ! -z ${TARDIR+x} ]] && [[ ! -d $TARDIR ]]; then die 7 "Tar dir specified doesn't exist"; fi -# Default packages -PACKAGES+="\ -bash -ca-certificates -" - do_adb_root || die 3 "adb root failed, make sure: - device is connected, and there's only one device (TODO: add multi device support) - device is userdebug." @@ -62,14 +62,29 @@ fi ########################################################## # PREPARE ########################################################## + +function do_cleanup() { + rm -rf $TDIR/*; if [ $MKTEMP -eq 1 ]; then rm -rf $TDIR; fi +} + +function push_unpack_headers() { + adb shell ls /data/androdeb/debian > /dev/null 2>&1 + if [ $? -ne 0 ]; then die 8 "Existing androdev env not found to update kernel headers into."; fi + + adb shell rm -rf /data/androdeb/debian/kernel-headers/ + adb shell mkdir /data/androdeb/debian/kernel-headers/ + adb push $TDIR_ABS/kh.tgz /data/androdeb/ + echo "Storing kernel headers into androdeb /kernel-headers/" + adb shell tar -xvf /data/androdeb/kh.tgz -C /data/androdeb/debian/kernel-headers/ > /dev/null + adb shell rm /data/androdeb/kh.tgz +} + # Prepare is the last command checked if [ -z "$PREPARE" ]; then usage; fi if [[ $EUID -ne 0 ]]; then die 6 "For prepare, this tool must run as root. Try: ./sudo androdeb prepare "; fi -if [ ! -z "$TARF" ] && [ -z "$DOWNLOAD" ]; then - if [ ! -f ${TARF} ]; then die 7 "archive provided doesn't exist"; fi -fi +if [ ! -z "$TARF" ] && [ ! -f $TARF ] && [ -z "$DOWNLOAD" ]; then die 7 "archive provided doesn't exist"; fi if [[ ! -z ${INSTALL_BCC+x} ]] && [[ -z ${KERNELSRC+x} ]]; then die 4 "--kernelsrc must be provided with --bcc"; fi @@ -88,24 +103,35 @@ if [ ! -z "$DOWNLOAD" ]; then curl -L https://github.com/joelagnel/androdeb/releases/download/$VERSION/androdeb-fs.tgz --output $TDIR_ABS/androdeb-fs.tgz; TARF=$TDIR_ABS/androdeb-fs.tgz; fi +OUT_TMP=$TDIR/debian; rm -rf $OUT_TMP; mkdir -p $OUT_TMP + # Package kernel headers -if [[ ! -z ${INSTALL_BCC} ]] && [[ ! -z ${KERNELSRC} ]]; then -$spath/bcc/build-kheaders-targz.sh ${KERNELSRC} $TDIR_ABS/kh.tgz || die 6 "Failed to package kernel headers"; fi +if [ ! -z "$KERNELSRC" ]; then + $spath/bcc/build-kheaders-targz.sh ${KERNELSRC} $TDIR_ABS/kh.tgz || + die 6 "Failed to package kernel headers" + # Is header update the only thing left to do? + if [[ -z "$PACKAGES" ]] && [[ -z "$TARF" ]]; then + push_unpack_headers; do_cleanup; exit 0; fi -OUT_TMP=$TDIR/debian; rm -rf $OUT_TMP; mkdir -p $OUT_TMP -if [ -f $TDIR_ABS/kh.tgz ]; then mkdir $OUT_TMP/kernel-headers tar -xvf $TDIR_ABS/kh.tgz -C $OUT_TMP/kernel-headers/ fi +# Build FS from existing tar, very simple. if [ ! -z "$TARF" ]; then echo "Using archive at $TARF for filesystem preparation" adb shell mkdir -p /data/androdeb/ adb push $TARF /data/androdeb/deb.tar.gz adb push $spath/addons/* /data/androdeb/ adb shell /data/androdeb/device-unpack -else + if [ ! -z "$KERNELSRC" ]; then push_unpack_headers; fi + + do_cleanup + exit 0 +fi + +PACKAGES+="$DEFAULT_PACKAGES" echo "Full package list: $PACKAGES" echo "Using temporary directory: $TDIR" @@ -156,10 +182,7 @@ adb shell /data/androdeb/device-unpack if [[ ! -z ${INSTALL_BCC+x} ]]; then adb shell /data/androdeb/run-command /bcc-master/build-bcc.sh; fi - -fi # !TARF - -rm -rf $TDIR/*; if [ $MKTEMP -eq 1 ]; then rm -rf $TDIR; fi +do_cleanup # Extract a tar of the built, compiled and installed androdeb env if [[ ! -z ${TARDIR+x} ]]; then -- cgit v1.2.3 From 7206511d3bdf3781f119f9fbaecebcabcd94f0d7 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 20:02:53 -0700 Subject: Update Signed-off-by: Joel Fernandes --- addons/device-unpack | 2 +- addons/run | 4 ++-- androdeb | 24 ++++++++++++++---------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/addons/device-unpack b/addons/device-unpack index 1dcb578..14ba258 100755 --- a/addons/device-unpack +++ b/addons/device-unpack @@ -25,4 +25,4 @@ fi tar -zxf /data/androdeb/deb.tar.gz -C /data/androdeb/ || die 2 "Couldn't unpack due to tar -x errors" rm /data/androdeb/deb.tar.gz -echo "Unpack of rootfs successful! Go forth and hack." +echo "Unpack of rootfs successful!" diff --git a/addons/run b/addons/run index 6a083fa..faee212 100755 --- a/addons/run +++ b/addons/run @@ -11,8 +11,8 @@ mount --bind /dev debian/dev/ > /dev/null mount --bind /sys debian/sys/ > /dev/null mount --bind /sys/kernel/debug/ debian/sys/kernel/debug/ > /dev/null mount --bind /sys/kernel/debug/tracing/ debian/sys/kernel/debug/tracing/ -if [ -d /system/ ]; then; mount --bind /system debian/system/; fi -if [ -d /vendor/ ]; then; mount --bind /vendor debian/vendor/; fi +if [ -d /system/ ]; then mount --bind /system debian/system/; fi +if [ -d /vendor/ ]; then mount --bind /vendor debian/vendor/; fi chroot debian/ /bin/bash # tear everything down diff --git a/androdeb b/androdeb index b23cfcc..e90843a 100755 --- a/androdeb +++ b/androdeb @@ -79,6 +79,10 @@ function push_unpack_headers() { adb shell rm /data/androdeb/kh.tgz } +function all_done_banner() { + echo "All done! Run \"androdeb shell\" to enter environment" +} + # Prepare is the last command checked if [ -z "$PREPARE" ]; then usage; fi @@ -86,9 +90,10 @@ if [[ $EUID -ne 0 ]]; then die 6 "For prepare, this tool must run as root. Try: if [ ! -z "$TARF" ] && [ ! -f $TARF ] && [ -z "$DOWNLOAD" ]; then die 7 "archive provided doesn't exist"; fi -if [[ ! -z ${INSTALL_BCC+x} ]] && [[ -z ${KERNELSRC+x} ]]; then die 4 "--kernelsrc must be provided with --bcc"; fi +if [ ! -z "$INSTALL_BCC" ] && [ -z "$KERNELSRC" ] && [ -z "$TARDIR" ]; + then die 4 "--kernelsrc must be provided with --bcc (unless --buildtar is provided)."; fi -if [[ ! -z ${KERNELSRC+x} ]] && [[ ! -d ${KERNELSRC} ]]; then die 5 "Kernel source directory provided doesn't exist"; fi +if [ ! -z "$KERNELSRC" ] && [ ! -d $KERNELSRC ]; then die 5 "Kernel source directory provided doesn't exist"; fi print_prepare_banner @@ -107,14 +112,15 @@ OUT_TMP=$TDIR/debian; rm -rf $OUT_TMP; mkdir -p $OUT_TMP # Package kernel headers if [ ! -z "$KERNELSRC" ]; then - $spath/bcc/build-kheaders-targz.sh ${KERNELSRC} $TDIR_ABS/kh.tgz || - die 6 "Failed to package kernel headers" + echo "Building and updating kernel headers from kernel source dir ($KERNELSRC)" + $spath/bcc/build-kheaders-targz.sh ${KERNELSRC} $TDIR_ABS/kh.tgz > /dev/null + # Is header update the only thing left to do? if [[ -z "$PACKAGES" ]] && [[ -z "$TARF" ]]; then - push_unpack_headers; do_cleanup; exit 0; fi + push_unpack_headers; do_cleanup; all_done_banner; exit 0; fi mkdir $OUT_TMP/kernel-headers - tar -xvf $TDIR_ABS/kh.tgz -C $OUT_TMP/kernel-headers/ + tar -xvf $TDIR_ABS/kh.tgz -C $OUT_TMP/kernel-headers/ > /dev/null fi # Build FS from existing tar, very simple. @@ -127,8 +133,7 @@ if [ ! -z "$TARF" ]; then if [ ! -z "$KERNELSRC" ]; then push_unpack_headers; fi - do_cleanup - exit 0 + do_cleanup; all_done_banner; exit 0 fi PACKAGES+="$DEFAULT_PACKAGES" @@ -191,5 +196,4 @@ if [[ ! -z ${TARDIR+x} ]]; then adb pull /data/androdeb/androdeb-fs.tgz $TARDIR/ adb shell rm /data/androdeb/androdeb-fs.tgz; fi -# Use --foreign and --variant=minbase to build minimal deb first stage -# Use fakeroot tar to build tar with root files +all_done_banner -- cgit v1.2.3 From 100c46823d7b67987359b221ee51c7b4834aca57 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 20:09:57 -0700 Subject: Make BCC install independent of kernel headers. There are too many cases where BCC can end up on an FS without kernel headers (for instance if an archive was provided, but headers weren't). For this reason don't enforce this dependency. Signed-off-by: Joel Fernandes --- androdeb | 7 ++----- packages/bcc | 2 ++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/androdeb b/androdeb index e90843a..06e9732 100755 --- a/androdeb +++ b/androdeb @@ -26,9 +26,9 @@ case $key in --compilers) source $spath/packages/compilers; shift || true; ;; --editors) source $spath/packages/editors; shift || true; ;; --scheduler) source $spath/packages/scheduler; shift || true; ;; - --fullbuild) for f in $(ls $spath/packages|grep -v bcc); do source packages/$f; done; shift || true; ;; + --fullbuild) for f in $(ls $spath/packages); do source packages/$f; done; shift || true; ;; --download) DOWNLOAD=1; shift || true; ;; - --bcc) source $spath/packages/bcc; INSTALL_BCC=1; shift || true; ;; + --bcc) source $spath/packages/bcc; shift || true; ;; --kernelsrc) KERNELSRC="$2"; shift || true; shift || true; ;; --tempdir) TDIR="$2"; shift || true; shift || true; ;; --buildtar) TARDIR="$2"; shift || true; shift || true; ;; @@ -90,9 +90,6 @@ if [[ $EUID -ne 0 ]]; then die 6 "For prepare, this tool must run as root. Try: if [ ! -z "$TARF" ] && [ ! -f $TARF ] && [ -z "$DOWNLOAD" ]; then die 7 "archive provided doesn't exist"; fi -if [ ! -z "$INSTALL_BCC" ] && [ -z "$KERNELSRC" ] && [ -z "$TARDIR" ]; - then die 4 "--kernelsrc must be provided with --bcc (unless --buildtar is provided)."; fi - if [ ! -z "$KERNELSRC" ] && [ ! -d $KERNELSRC ]; then die 5 "Kernel source directory provided doesn't exist"; fi print_prepare_banner diff --git a/packages/bcc b/packages/bcc index 8988cd5..d0a9c7c 100644 --- a/packages/bcc +++ b/packages/bcc @@ -21,3 +21,5 @@ clang-6.0 python-netaddr python-pyroute2 " + +INSTALL_BCC=1 -- cgit v1.2.3 From 92bbf76ff281458ebbde100488f70fa8890bc6cc Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 20:12:19 -0700 Subject: Dont print package list Signed-off-by: Joel Fernandes --- androdeb | 1 - 1 file changed, 1 deletion(-) diff --git a/androdeb b/androdeb index 06e9732..0d4cc79 100755 --- a/androdeb +++ b/androdeb @@ -134,7 +134,6 @@ if [ ! -z "$TARF" ]; then fi PACKAGES+="$DEFAULT_PACKAGES" -echo "Full package list: $PACKAGES" echo "Using temporary directory: $TDIR" time qemu-debootstrap --arch arm64 --include=$(make_csv "$PACKAGES") \ -- cgit v1.2.3 From 63981700338cc89fd6967cb21bc6af43c9b7e2fa Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 20:30:55 -0700 Subject: Update Signed-off-by: Joel Fernandes --- README.md | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4c42ba0..381171e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,36 @@ Project to give a rich Android development environment for end-users to use over adb. +androdeb aims to provide a powerful Linux environment where one can run popular +and mainstream Linux tracing, compiling, editing and other development tools. + +Usecases +-------- +(1) Powerful development environment with all tools ready to go (editors, +compilers, tracers, perl/python etc) for your on-device development. + +(2) No more cross-compiler needed: Because it comes with gcc and clang, one can +build target packages natively without needing to do any cross compilation. We even +ship git, and have support to run apt-get to get any missing development packages. + +(3) Using these one can run popular tools such as BCC that are difficult to run +in an Android environment due to lack of packages, dependencies and cross-compilation +needed for their operation. + +(4) No more crippled tools: Its often a theme to build a static binary with +features disabled, because you couldn't cross-compile the feature's dependencies. One +classic example is perf. However, thanks to androdeb, we can build perf natively +on device without having to cripple it. + +Requirements for running +------------------------ +Target: +An ARM64 android N or later device which has "adb root" supported. Typically +this is a build in a userdebug configuration. Device should have atleast 2 GB +free space in the data partition. + +Host: +A machine running recent Ubuntu or Debian, with 4GB of memory and 4GB free space. +Host needs qemu-debootstrap package installed. Run `apt-get install qemu-debootstrap`. + Notes: -* This will work only on rooted android devices that are running fairly recent Android (N or later). * This project is pre-alpha and work in progress! -- cgit v1.2.3 From 536edfc69d78427e0a392274fa5b14636793148f Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 20:31:07 -0700 Subject: Update Signed-off-by: Joel Fernandes --- androdeb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/androdeb b/androdeb index 0d4cc79..f061776 100755 --- a/androdeb +++ b/androdeb @@ -1,5 +1,5 @@ #!/bin/bash -e -VERSION=v0.9 +VERSION=v0.95 spath=$( cd "$(dirname "$0")" ; pwd -P ) curdir=$( pwd -P ) -- cgit v1.2.3 From 9bb0c84980d54f492783cb1699ce1714e3a5d7d8 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 20:38:35 -0700 Subject: Update Signed-off-by: Joel Fernandes --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index 381171e..22c9199 100644 --- a/README.md +++ b/README.md @@ -32,5 +32,24 @@ Host: A machine running recent Ubuntu or Debian, with 4GB of memory and 4GB free space. Host needs qemu-debootstrap package installed. Run `apt-get install qemu-debootstrap`. +Quick Start Instructions +------------------------ +* Clone androdeb repository: +``` +git clone https://github.com/joelagnel/androdeb.git +cd androdeb +``` + +* Fastest way of installing androdeb onto your device: +``` +# First make sure device is connected to system (only single device supported) +./androdeb prepare --download +``` + +* Run androdeb shell +``` +./androdeb shell +``` + Notes: * This project is pre-alpha and work in progress! -- cgit v1.2.3 From 93b7f2ebbf614a3f5c4930404fef3e0ac05971ec Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 20:58:20 -0700 Subject: Update Signed-off-by: Joel Fernandes --- README.md | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 22c9199..a6ba5e1 100644 --- a/README.md +++ b/README.md @@ -43,13 +43,64 @@ cd androdeb * Fastest way of installing androdeb onto your device: ``` # First make sure device is connected to system (only single device supported) -./androdeb prepare --download +sudo ./androdeb prepare --download ``` -* Run androdeb shell +* Now run androdeb shell: ``` ./androdeb shell ``` +More advanced usage instructions +-------------------------------- +* Install kernel headers in addition to preparing androdeb device: +``` +./androdeb prepare --download --kernelsrc /path/to/kernel-source +``` + +* Update kernel headers onto an existing install: +If you need to put kernel sources for an existing install, run: +``` +./androdeb prepare --kernelsrc /path/to/kernel-source +``` +Note: The kernel sources should have been built (atleast build should have started). + +* Build and prepare device with a custom rootfs locally: +The androdeb fs will be prepared locally by downloading packages as needed: +``` +./androdeb prepare --fullbuild +``` +This is unlike `--download` where the androdeb rootfs is itself pulled from the web. + +* Add kernel headers to device in addition to building locally: +``` +./androdeb prepare --fullbuild --kernelsrc /path/to/kernel-source/ +``` + +* Instead of `--fullbuild`, customize what you install: +``` +./androdeb prepare --editors --compilers +``` + +* Install only BCC: +``` +./androdeb prepare --bcc --kernelsrc /path/to/kernel-source/ +``` +Note: BCC is built while being installed. Also --kernelsrc is +recommended for tools to function unless device has them +already. + +* Extract the FS from the device, after its prepared: +``` +./androdeb prepare --fullbuild --buildtar /path/ +``` +After device is prepared, it will extract the root fs from it +and store it as a tar archive at `/path/androdeb-fs.tgz`. This +can be used later. + +* Use a previously prepared androdeb rootfs tar from local: +``` +./androdeb prepare --archive /path/androdeb-fs.tgz +``` Notes: * This project is pre-alpha and work in progress! -- cgit v1.2.3 From 1a0e259d6f65354bf07d5ddb95a98c06f6e83bf1 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 21:00:51 -0700 Subject: Update Signed-off-by: Joel Fernandes --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a6ba5e1..32c89e0 100644 --- a/README.md +++ b/README.md @@ -52,19 +52,21 @@ sudo ./androdeb prepare --download ``` More advanced usage instructions -------------------------------- -* Install kernel headers in addition to preparing androdeb device: +### Install kernel headers in addition to preparing androdeb device: ``` ./androdeb prepare --download --kernelsrc /path/to/kernel-source ``` -* Update kernel headers onto an existing install: +### Update kernel headers onto an existing install: + If you need to put kernel sources for an existing install, run: ``` ./androdeb prepare --kernelsrc /path/to/kernel-source ``` Note: The kernel sources should have been built (atleast build should have started). -* Build and prepare device with a custom rootfs locally: +### Build and prepare device with a custom rootfs locally: + The androdeb fs will be prepared locally by downloading packages as needed: ``` ./androdeb prepare --fullbuild -- cgit v1.2.3 From da816a8a516259f7679f9b6d05a0d7b9d38a17f5 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 21:02:11 -0700 Subject: Update Signed-off-by: Joel Fernandes --- README.md | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 32c89e0..79064c6 100644 --- a/README.md +++ b/README.md @@ -73,17 +73,17 @@ The androdeb fs will be prepared locally by downloading packages as needed: ``` This is unlike `--download` where the androdeb rootfs is itself pulled from the web. -* Add kernel headers to device in addition to building locally: +### Add kernel headers to device in addition to building locally: ``` ./androdeb prepare --fullbuild --kernelsrc /path/to/kernel-source/ ``` -* Instead of `--fullbuild`, customize what you install: +### Instead of `--fullbuild`, customize what you install: ``` ./androdeb prepare --editors --compilers ``` -* Install only BCC: +### Install only BCC: ``` ./androdeb prepare --bcc --kernelsrc /path/to/kernel-source/ ``` @@ -91,7 +91,7 @@ Note: BCC is built while being installed. Also --kernelsrc is recommended for tools to function unless device has them already. -* Extract the FS from the device, after its prepared: +### Extract the FS from the device, after its prepared: ``` ./androdeb prepare --fullbuild --buildtar /path/ ``` @@ -99,10 +99,7 @@ After device is prepared, it will extract the root fs from it and store it as a tar archive at `/path/androdeb-fs.tgz`. This can be used later. -* Use a previously prepared androdeb rootfs tar from local: +### Use a previously prepared androdeb rootfs tar from local: ``` ./androdeb prepare --archive /path/androdeb-fs.tgz ``` - -Notes: -* This project is pre-alpha and work in progress! -- cgit v1.2.3 From afea46d91568f201e250ee99700e733dad725b99 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 21:08:23 -0700 Subject: Update Signed-off-by: Joel Fernandes --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 79064c6..47ae83e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ -Project to give a rich Android development environment for end-users to use over adb. +androdeb: a rich Android development environment for users +========================================================== -androdeb aims to provide a powerful Linux environment where one can run popular +**androdeb aims** to provide a powerful Linux environment where one can run popular and mainstream Linux tracing, compiling, editing and other development tools. Usecases @@ -10,7 +11,8 @@ compilers, tracers, perl/python etc) for your on-device development. (2) No more cross-compiler needed: Because it comes with gcc and clang, one can build target packages natively without needing to do any cross compilation. We even -ship git, and have support to run apt-get to get any missing development packages. +ship git, and have support to run apt-get to get any missing development packages +from the web. (3) Using these one can run popular tools such as BCC that are difficult to run in an Android environment due to lack of packages, dependencies and cross-compilation -- cgit v1.2.3 From 9d2c0e23a3b4e92d76f8472511d8fa77e9b85c2b Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 21:10:47 -0700 Subject: Update Signed-off-by: Joel Fernandes --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 47ae83e..bc2afb8 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,10 @@ -androdeb: a rich Android development environment for users -========================================================== +androdeb: Android development environment for power users +--------------------------------------------------------- -**androdeb aims** to provide a powerful Linux environment where one can run popular -and mainstream Linux tracing, compiling, editing and other development tools. +**androdeb** aims to provide a powerful Linux shell environment where one can +run popular and mainstream Linux tracing, compiling, editing and other +development tools. All the commands typically available on a modern Linux +system are supported in androdeb. Usecases -------- -- cgit v1.2.3 From 6ba5a490c6e7425a8cf59e29b507dcfb8bb3e32d Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 21:12:10 -0700 Subject: Update Signed-off-by: Joel Fernandes --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bc2afb8..6c1c9ef 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,8 @@ androdeb: Android development environment for power users **androdeb** aims to provide a powerful Linux shell environment where one can run popular and mainstream Linux tracing, compiling, editing and other -development tools. All the commands typically available on a modern Linux -system are supported in androdeb. +development tools on an Android system. All the commands typically available on +a modern Linux system are supported in androdeb. Usecases -------- -- cgit v1.2.3 From 8ff0b5fb632cf852bd1d67f1dbac125beae774df Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 21:13:03 -0700 Subject: Update Signed-off-by: Joel Fernandes --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6c1c9ef..f1c164c 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,10 @@ a modern Linux system are supported in androdeb. Usecases -------- -(1) Powerful development environment with all tools ready to go (editors, +1. Powerful development environment with all tools ready to go (editors, compilers, tracers, perl/python etc) for your on-device development. -(2) No more cross-compiler needed: Because it comes with gcc and clang, one can +2. No more cross-compiler needed: Because it comes with gcc and clang, one can build target packages natively without needing to do any cross compilation. We even ship git, and have support to run apt-get to get any missing development packages from the web. -- cgit v1.2.3 From 1fdb31889a93b9ba2a9ede8c85c01293fb92c413 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 21:13:27 -0700 Subject: Update Signed-off-by: Joel Fernandes --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f1c164c..df922e1 100644 --- a/README.md +++ b/README.md @@ -16,11 +16,11 @@ build target packages natively without needing to do any cross compilation. We e ship git, and have support to run apt-get to get any missing development packages from the web. -(3) Using these one can run popular tools such as BCC that are difficult to run +3. Using these one can run popular tools such as BCC that are difficult to run in an Android environment due to lack of packages, dependencies and cross-compilation needed for their operation. -(4) No more crippled tools: Its often a theme to build a static binary with +4. No more crippled tools: Its often a theme to build a static binary with features disabled, because you couldn't cross-compile the feature's dependencies. One classic example is perf. However, thanks to androdeb, we can build perf natively on device without having to cripple it. -- cgit v1.2.3 From bc32b49b2edb1197686f7c0a0ccdfd5ef7c9617b Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 21:15:24 -0700 Subject: Update Signed-off-by: Joel Fernandes --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index df922e1..df3e5df 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ More advanced usage instructions ./androdeb prepare --download --kernelsrc /path/to/kernel-source ``` -### Update kernel headers onto an existing install: +### Update kernel headers onto an already prepared device: If you need to put kernel sources for an existing install, run: ``` @@ -91,7 +91,7 @@ This is unlike `--download` where the androdeb rootfs is itself pulled from the ``` ./androdeb prepare --bcc --kernelsrc /path/to/kernel-source/ ``` -Note: BCC is built while being installed. Also --kernelsrc is +Note: BCC is built while being installed. Also `--kernelsrc` is recommended for tools to function unless device has them already. -- cgit v1.2.3 From 652141b6003c1eb14b8a5a3b1ed88b3b4e550f74 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 21:15:48 -0700 Subject: Update Signed-off-by: Joel Fernandes --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index df3e5df..38a7445 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -androdeb: Android development environment for power users ---------------------------------------------------------- +androdeb +-------- **androdeb** aims to provide a powerful Linux shell environment where one can run popular and mainstream Linux tracing, compiling, editing and other -- cgit v1.2.3 From efe6c4cefdee76e0137923e1e501796a1c376d82 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 21:24:02 -0700 Subject: Update Signed-off-by: Joel Fernandes --- LICENSE | 339 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ TODO | 5 - addons/bashrc | 2 +- androdeb | 3 + 4 files changed, 343 insertions(+), 6 deletions(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d159169 --- /dev/null +++ b/LICENSE @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/TODO b/TODO index 0b3366e..d56b218 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,2 @@ - check for space on both host and target - check if host deps are installed (Qemu etc) - -- make update headers indep of bcc, but bcc dependent on it -- make fullbuild also select bcc -- build tar independent of prepare -- get perf to work diff --git a/addons/bashrc b/addons/bashrc index c9cf3f4..c814ecf 100644 --- a/addons/bashrc +++ b/addons/bashrc @@ -4,7 +4,7 @@ export TMPDIR=/tmp/ echo "" echo "##########################################################" echo "# Welcome to androdeb environment running on Android! #" -echo "# Questions to: Joel Fernandes #" +echo "# Questions to: Joel Fernandes #" echo " #" echo " Try running vim, gcc, clang, bcc, git, make, perf etc #" echo " or apt-get install something. #" diff --git a/androdeb b/androdeb index f061776..8b665f4 100755 --- a/androdeb +++ b/androdeb @@ -1,4 +1,7 @@ #!/bin/bash -e +# +# (c) Joel Fernandes + VERSION=v0.95 spath=$( cd "$(dirname "$0")" ; pwd -P ) -- cgit v1.2.3 From 993bb460f1672ee3ff35555c4991b499533a6bdd Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Apr 2018 22:01:48 -0700 Subject: Update Signed-off-by: Joel Fernandes --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 38a7445..02b8963 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ androdeb -------- -**androdeb** aims to provide a powerful Linux shell environment where one can +**androdeb** provides a powerful Linux shell environment where one can run popular and mainstream Linux tracing, compiling, editing and other -development tools on an Android system. All the commands typically available on -a modern Linux system are supported in androdeb. +development tools on an existing Android device. All the commands typically +available on a modern Linux system are supported in androdeb. Usecases -------- -- cgit v1.2.3 From 72514d96aff343a2b35cf8e2530c7bd0f52bcc38 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Mon, 2 Apr 2018 09:21:20 -0700 Subject: Update Signed-off-by: Joel Fernandes --- TODO | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TODO b/TODO index d56b218..d48bb5a 100644 --- a/TODO +++ b/TODO @@ -1,2 +1,4 @@ - check for space on both host and target - check if host deps are installed (Qemu etc) +- add an adb remove command to remove an env explicitly +- Improve suggestions for missing adb -- cgit v1.2.3 From 01f526ee1e875c18a1be8ef1e83d638d0ee753fd Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Mon, 2 Apr 2018 09:58:54 -0700 Subject: Update Signed-off-by: Joel Fernandes --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 02b8963..b9c0143 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ free space in the data partition. Host: A machine running recent Ubuntu or Debian, with 4GB of memory and 4GB free space. -Host needs qemu-debootstrap package installed. Run `apt-get install qemu-debootstrap`. +Host needs qemu-debootstrap package installed. Run `apt-get install qemu-user-static`. Quick Start Instructions ------------------------ -- cgit v1.2.3 From 25976503226d32856bee07022faedccd24473263 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Mon, 2 Apr 2018 09:59:48 -0700 Subject: Update Signed-off-by: Joel Fernandes --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b9c0143..bf7c1ec 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,8 @@ free space in the data partition. Host: A machine running recent Ubuntu or Debian, with 4GB of memory and 4GB free space. -Host needs qemu-debootstrap package installed. Run `apt-get install qemu-user-static`. +Host needs qemu-debootstrap tool. To install this, run `apt-get install qemu-user-static`. +Other distributions may work but they are not tested. Quick Start Instructions ------------------------ -- cgit v1.2.3 From 71c15501e6895bdc2e09528eb124f1dc4b59af66 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Mon, 2 Apr 2018 10:00:38 -0700 Subject: Update Signed-off-by: Joel Fernandes --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bf7c1ec..cd74349 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ free space in the data partition. Host: A machine running recent Ubuntu or Debian, with 4GB of memory and 4GB free space. -Host needs qemu-debootstrap tool. To install this, run `apt-get install qemu-user-static`. +Host needs qemu-debootstrap. To install it, run `sudo apt-get install qemu-user-static`. Other distributions may work but they are not tested. Quick Start Instructions -- cgit v1.2.3 From ea5d8ba0d34b445224871e9f6c33792c85a18236 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Mon, 2 Apr 2018 10:02:26 -0700 Subject: Update Signed-off-by: Joel Fernandes --- TODO | 1 + 1 file changed, 1 insertion(+) diff --git a/TODO b/TODO index d48bb5a..ec18264 100644 --- a/TODO +++ b/TODO @@ -2,3 +2,4 @@ - check if host deps are installed (Qemu etc) - add an adb remove command to remove an env explicitly - Improve suggestions for missing adb +- make commands that don't need root run as non-root -- cgit v1.2.3 From 2a4c77d52e6710408e3ad6d79b55d50208172c2e Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Mon, 2 Apr 2018 10:15:50 -0700 Subject: Update Signed-off-by: Joel Fernandes --- README.md | 3 ++- TODO | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cd74349..81cd6d2 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,8 @@ free space in the data partition. Host: A machine running recent Ubuntu or Debian, with 4GB of memory and 4GB free space. -Host needs qemu-debootstrap. To install it, run `sudo apt-get install qemu-user-static`. +Host needs debootstrap and qemu-debootstrap packages. +To install it, run `sudo apt-get install qemu-user-static deboostrap`. Other distributions may work but they are not tested. Quick Start Instructions diff --git a/TODO b/TODO index ec18264..4e2ea42 100644 --- a/TODO +++ b/TODO @@ -3,3 +3,4 @@ - add an adb remove command to remove an env explicitly - Improve suggestions for missing adb - make commands that don't need root run as non-root +- fix debootstrap install instructions -- cgit v1.2.3 From 50ea7cacc2505992dfa766184e6a37169dbf361b Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Mon, 2 Apr 2018 21:58:02 -0700 Subject: Add more mountpoints Signed-off-by: Joel Fernandes --- addons/run | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/addons/run b/addons/run index faee212..103bba3 100755 --- a/addons/run +++ b/addons/run @@ -11,8 +11,28 @@ mount --bind /dev debian/dev/ > /dev/null mount --bind /sys debian/sys/ > /dev/null mount --bind /sys/kernel/debug/ debian/sys/kernel/debug/ > /dev/null mount --bind /sys/kernel/debug/tracing/ debian/sys/kernel/debug/tracing/ -if [ -d /system/ ]; then mount --bind /system debian/system/; fi -if [ -d /vendor/ ]; then mount --bind /vendor debian/vendor/; fi + +# Mount Android partitions +if [ -d /d/ ]; then + mkdir -p debian/d/ + mount --bind /d debian/d/ +fi + +if [ -d /data/ ]; then + mkdir -p debian/data/ + mount --bind /system debian/data/ +fi + +if [ -d /system/ ]; then + mkdir -p debian/system/ + mount --bind /system debian/system/ +fi + +if [ -d /vendor/ ]; then + mkdir -p debian/vendor/ + mount --bind /vendor debian/vendor/ +fi + chroot debian/ /bin/bash # tear everything down -- cgit v1.2.3 From 96f2486bdb35003ed8a0f783adc3e33af6b88756 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Mon, 2 Apr 2018 21:58:29 -0700 Subject: Update Signed-off-by: Joel Fernandes --- TODO | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TODO b/TODO index 4e2ea42..b9a892c 100644 --- a/TODO +++ b/TODO @@ -3,4 +3,4 @@ - add an adb remove command to remove an env explicitly - Improve suggestions for missing adb - make commands that don't need root run as non-root -- fix debootstrap install instructions +- adb multi device support -- cgit v1.2.3 From af07ec7d9bf9c33508d1882b0165e1f990f8b9f7 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Mon, 2 Apr 2018 22:01:19 -0700 Subject: Update Signed-off-by: Joel Fernandes --- TODO | 1 - androdeb | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index b9a892c..349184e 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,5 @@ - check for space on both host and target - check if host deps are installed (Qemu etc) - add an adb remove command to remove an env explicitly -- Improve suggestions for missing adb - make commands that don't need root run as non-root - adb multi device support diff --git a/androdeb b/androdeb index 8b665f4..1e10f06 100755 --- a/androdeb +++ b/androdeb @@ -46,8 +46,12 @@ if [ ! -z "$PREPARE" ] && [ -z "$DOWNLOAD" ] && [ -z "$TARF" ] && [ -z "$PACKAGE if [[ ! -z ${TARDIR+x} ]] && [[ ! -d $TARDIR ]]; then die 7 "Tar dir specified doesn't exist"; fi do_adb_root || die 3 "adb root failed, make sure: +- adb is available (try to run adb manually and see if it works) - device is connected, and there's only one device (TODO: add multi device support) -- device is userdebug." +- device is userdebug. + +Note: adb can be typically obtained using the android-adb-tools or the adb +packages on your distro, or by installing the Android SDK." ########################################################## # SHELL -- cgit v1.2.3 From e15a7b043221971dcdd68897a07ef4d08871de2a Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Mon, 2 Apr 2018 22:03:47 -0700 Subject: Make tool run as non-root for the most part Signed-off-by: Joel Fernandes --- androdeb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/androdeb b/androdeb index 1e10f06..be68056 100755 --- a/androdeb +++ b/androdeb @@ -93,8 +93,6 @@ function all_done_banner() { # Prepare is the last command checked if [ -z "$PREPARE" ]; then usage; fi -if [[ $EUID -ne 0 ]]; then die 6 "For prepare, this tool must run as root. Try: ./sudo androdeb prepare "; fi - if [ ! -z "$TARF" ] && [ ! -f $TARF ] && [ -z "$DOWNLOAD" ]; then die 7 "archive provided doesn't exist"; fi if [ ! -z "$KERNELSRC" ] && [ ! -d $KERNELSRC ]; then die 5 "Kernel source directory provided doesn't exist"; fi @@ -143,7 +141,8 @@ fi PACKAGES+="$DEFAULT_PACKAGES" echo "Using temporary directory: $TDIR" -time qemu-debootstrap --arch arm64 --include=$(make_csv "$PACKAGES") \ +if [[ $EUID -ne 0 ]]; then echo "The next stage needs root. You may be accessed for root password."; fi +sudo qemu-debootstrap --arch arm64 --include=$(make_csv "$PACKAGES") \ $DISTRO $OUT_TMP http://deb.debian.org/debian/ # Some reason debootstrap leaves these mounted -- cgit v1.2.3 From 02939a36a78e96fc8d60a957c1a8269e2b00b656 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Mon, 2 Apr 2018 22:18:10 -0700 Subject: Add multidevice support Signed-off-by: Joel Fernandes --- TODO | 2 -- androdeb | 47 ++++++++++++++++++++++++----------------------- utils/banners | 3 +++ 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/TODO b/TODO index 349184e..15f0843 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,3 @@ - check for space on both host and target - check if host deps are installed (Qemu etc) - add an adb remove command to remove an env explicitly -- make commands that don't need root run as non-root -- adb multi device support diff --git a/androdeb b/androdeb index be68056..d2fa562 100755 --- a/androdeb +++ b/androdeb @@ -11,6 +11,7 @@ source $spath/utils/banners # Set default vars DISTRO=buster; ARCH=arm64 +ADB="adb" # Default packages DEFAULT_PACKAGES+="\ @@ -35,6 +36,7 @@ case $key in --kernelsrc) KERNELSRC="$2"; shift || true; shift || true; ;; --tempdir) TDIR="$2"; shift || true; shift || true; ;; --buildtar) TARDIR="$2"; shift || true; shift || true; ;; + --device|-s) ADB="$ADB -s $2"; shift || true; shift || true; ;; --debug) set -x; shift || true; ;; *) echo "Unknown option ($1)"; usage; ;; esac @@ -46,9 +48,8 @@ if [ ! -z "$PREPARE" ] && [ -z "$DOWNLOAD" ] && [ -z "$TARF" ] && [ -z "$PACKAGE if [[ ! -z ${TARDIR+x} ]] && [[ ! -d $TARDIR ]]; then die 7 "Tar dir specified doesn't exist"; fi do_adb_root || die 3 "adb root failed, make sure: -- adb is available (try to run adb manually and see if it works) -- device is connected, and there's only one device (TODO: add multi device support) -- device is userdebug. +- If multiple devices connected, provide --device (or -s ) +- Try to run \"adb root\" manually and see if it works. Typically this needs a userdebug build. Note: adb can be typically obtained using the android-adb-tools or the adb packages on your distro, or by installing the Android SDK." @@ -57,12 +58,12 @@ packages on your distro, or by installing the Android SDK." # SHELL ########################################################## if [ ! -z ${ASHELL+x} ]; then - set +e; adb shell ls /data/androdeb/debian/.bashrc > /dev/null 2>&1 + set +e; $ADB shell ls /data/androdeb/debian/.bashrc > /dev/null 2>&1 if [ $? -ne 0 ]; then die 2 "Device doesn't have an androdeb environment, run \"./androdeb prepare\" first"; fi; set -e - adb shell -t /data/androdeb/run + $ADB shell -t /data/androdeb/run exit 0 fi @@ -75,15 +76,15 @@ function do_cleanup() { } function push_unpack_headers() { - adb shell ls /data/androdeb/debian > /dev/null 2>&1 + $ADB shell ls /data/androdeb/debian > /dev/null 2>&1 if [ $? -ne 0 ]; then die 8 "Existing androdev env not found to update kernel headers into."; fi - adb shell rm -rf /data/androdeb/debian/kernel-headers/ - adb shell mkdir /data/androdeb/debian/kernel-headers/ - adb push $TDIR_ABS/kh.tgz /data/androdeb/ + $ADB shell rm -rf /data/androdeb/debian/kernel-headers/ + $ADB shell mkdir /data/androdeb/debian/kernel-headers/ + $ADB push $TDIR_ABS/kh.tgz /data/androdeb/ echo "Storing kernel headers into androdeb /kernel-headers/" - adb shell tar -xvf /data/androdeb/kh.tgz -C /data/androdeb/debian/kernel-headers/ > /dev/null - adb shell rm /data/androdeb/kh.tgz + $ADB shell tar -xvf /data/androdeb/kh.tgz -C /data/androdeb/debian/kernel-headers/ > /dev/null + $ADB shell rm /data/androdeb/kh.tgz } function all_done_banner() { @@ -128,10 +129,10 @@ fi # Build FS from existing tar, very simple. if [ ! -z "$TARF" ]; then echo "Using archive at $TARF for filesystem preparation" - adb shell mkdir -p /data/androdeb/ - adb push $TARF /data/androdeb/deb.tar.gz - adb push $spath/addons/* /data/androdeb/ - adb shell /data/androdeb/device-unpack + $ADB shell mkdir -p /data/androdeb/ + $ADB push $TARF /data/androdeb/deb.tar.gz + $ADB push $spath/addons/* /data/androdeb/ + $ADB shell /data/androdeb/device-unpack if [ ! -z "$KERNELSRC" ]; then push_unpack_headers; fi @@ -180,22 +181,22 @@ echo "Compressing new filesystem to prepare to push to Android /data/androdeb/" tar -zcf $TDIR/deb.tar.gz -C $TDIR debian # Push tar to device and start unpack -adb shell mkdir -p /data/androdeb/ -adb push $TDIR/deb.tar.gz /data/androdeb/ -adb push $spath/addons/* /data/androdeb/ -adb shell /data/androdeb/device-unpack +$ADB shell mkdir -p /data/androdeb/ +$ADB push $TDIR/deb.tar.gz /data/androdeb/ +$ADB push $spath/addons/* /data/androdeb/ +$ADB shell /data/androdeb/device-unpack # Build BCC and install bcc on device if needed if [[ ! -z ${INSTALL_BCC+x} ]]; then -adb shell /data/androdeb/run-command /bcc-master/build-bcc.sh; fi +$ADB shell /data/androdeb/run-command /bcc-master/build-bcc.sh; fi do_cleanup # Extract a tar of the built, compiled and installed androdeb env if [[ ! -z ${TARDIR+x} ]]; then echo "Creating and pulling tarball of androdeb env from device" - adb shell /data/androdeb/build-debian-tar - adb pull /data/androdeb/androdeb-fs.tgz $TARDIR/ - adb shell rm /data/androdeb/androdeb-fs.tgz; fi + $ADB shell /data/androdeb/build-debian-tar + $ADB pull /data/androdeb/androdeb-fs.tgz $TARDIR/ + $ADB shell rm /data/androdeb/androdeb-fs.tgz; fi all_done_banner diff --git a/utils/banners b/utils/banners index 9a5ad56..11d764e 100755 --- a/utils/banners +++ b/utils/banners @@ -27,6 +27,9 @@ usage() { echo " --tempdir Use a specific temporary directory for build operation" echo " --buildtar Local directory to store tarball of androdeb env from device" echo " --distro Debian distro to base on (default is buster)" + echo " --device Serial number of adb device." + echo " -s Serial number of adb device." + echo "" echo " --debug" exit 1 } -- cgit v1.2.3 From b4c80a6ebd6fc3503ad68b87cd24bad3b7b8db65 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Mon, 2 Apr 2018 22:37:22 -0700 Subject: Fix multidev support and add remove command Signed-off-by: Joel Fernandes --- androdeb | 13 +++++++++---- utils/android | 10 +++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/androdeb b/androdeb index d2fa562..1ca680c 100755 --- a/androdeb +++ b/androdeb @@ -25,6 +25,7 @@ while [[ $# -gt 0 ]]; do key="$1"; case $key in prepare) PREPARE=1; shift || true; ;; shell) ASHELL=1; shift || true; ;; + remove) REMOVE=1; shift || true; ;; --archive) TARF=$2; shift || true; shift || true; ;; --tracers) source $spath/packages/tracers; shift || true; ;; --compilers) source $spath/packages/compilers; shift || true; ;; @@ -47,13 +48,18 @@ if [ ! -z "$PREPARE" ] && [ -z "$DOWNLOAD" ] && [ -z "$TARF" ] && [ -z "$PACKAGE if [[ ! -z ${TARDIR+x} ]] && [[ ! -d $TARDIR ]]; then die 7 "Tar dir specified doesn't exist"; fi -do_adb_root || die 3 "adb root failed, make sure: +do_adb_root "$ADB" || die 3 "adb root failed, make sure: - If multiple devices connected, provide --device (or -s ) - Try to run \"adb root\" manually and see if it works. Typically this needs a userdebug build. Note: adb can be typically obtained using the android-adb-tools or the adb packages on your distro, or by installing the Android SDK." +if [ ! -z "$REMOVE" ]; then + die_if_no_androdeb "Nothing to remove." + $ADB shell /data/androdeb/device-umount-all; + $ADB shell rm -rf /data/androdeb; exit 0; fi + ########################################################## # SHELL ########################################################## @@ -76,8 +82,7 @@ function do_cleanup() { } function push_unpack_headers() { - $ADB shell ls /data/androdeb/debian > /dev/null 2>&1 - if [ $? -ne 0 ]; then die 8 "Existing androdev env not found to update kernel headers into."; fi + die_if_no_androdeb "Couldn't update headers." $ADB shell rm -rf /data/androdeb/debian/kernel-headers/ $ADB shell mkdir /data/androdeb/debian/kernel-headers/ @@ -142,7 +147,7 @@ fi PACKAGES+="$DEFAULT_PACKAGES" echo "Using temporary directory: $TDIR" -if [[ $EUID -ne 0 ]]; then echo "The next stage needs root. You may be accessed for root password."; fi +if [[ $EUID -ne 0 ]]; then echo ""; echo "Please enter your root password for next stage:"; fi sudo qemu-debootstrap --arch arm64 --include=$(make_csv "$PACKAGES") \ $DISTRO $OUT_TMP http://deb.debian.org/debian/ diff --git a/utils/android b/utils/android index 0dbff7d..7ad11be 100755 --- a/utils/android +++ b/utils/android @@ -33,7 +33,8 @@ cmd_exists() { } do_adb_root() { - adb root > /dev/null 2>&1 + ADB="$1" + $ADB root > /dev/null 2>&1 return $? } @@ -43,3 +44,10 @@ die() { echo "ERROR: $msg" exit $exit_code } + +die_if_no_androdeb() { + set +e + $ADB shell ls /data/androdeb/debian > /dev/null 2>&1 + if [ $? -ne 0 ]; then die 8 "Existing androdeb env not found on device. $1"; fi + set -e +} -- cgit v1.2.3 From 286cb10c37a7a22b9c3d9e00db6a42eb38e45015 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Mon, 2 Apr 2018 23:07:39 -0700 Subject: Make whole tool as run only by root Signed-off-by: Joel Fernandes --- androdeb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/androdeb b/androdeb index 1ca680c..6440786 100755 --- a/androdeb +++ b/androdeb @@ -99,6 +99,8 @@ function all_done_banner() { # Prepare is the last command checked if [ -z "$PREPARE" ]; then usage; fi +if [[ $EUID -ne 0 ]]; then die 6 "For prepare, this tool must run as root. Try: ./sudo androdeb prepare "; fi + if [ ! -z "$TARF" ] && [ ! -f $TARF ] && [ -z "$DOWNLOAD" ]; then die 7 "archive provided doesn't exist"; fi if [ ! -z "$KERNELSRC" ] && [ ! -d $KERNELSRC ]; then die 5 "Kernel source directory provided doesn't exist"; fi @@ -147,8 +149,7 @@ fi PACKAGES+="$DEFAULT_PACKAGES" echo "Using temporary directory: $TDIR" -if [[ $EUID -ne 0 ]]; then echo ""; echo "Please enter your root password for next stage:"; fi -sudo qemu-debootstrap --arch arm64 --include=$(make_csv "$PACKAGES") \ +time qemu-debootstrap --arch arm64 --include=$(make_csv "$PACKAGES") \ $DISTRO $OUT_TMP http://deb.debian.org/debian/ # Some reason debootstrap leaves these mounted -- cgit v1.2.3 From e561d8239662f227bff26133902331b071bcc6b0 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Mon, 2 Apr 2018 23:10:12 -0700 Subject: Update Signed-off-by: Joel Fernandes --- androdeb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/androdeb b/androdeb index 6440786..c0a483e 100755 --- a/androdeb +++ b/androdeb @@ -52,7 +52,7 @@ do_adb_root "$ADB" || die 3 "adb root failed, make sure: - If multiple devices connected, provide --device (or -s ) - Try to run \"adb root\" manually and see if it works. Typically this needs a userdebug build. -Note: adb can be typically obtained using the android-adb-tools or the adb +Note: adb can be typically obtained using the android-tools-adb or the adb packages on your distro, or by installing the Android SDK." if [ ! -z "$REMOVE" ]; then -- cgit v1.2.3 From 961b69bc418276dca891471dd882f41e71ef640a Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Mon, 2 Apr 2018 23:14:36 -0700 Subject: Update Signed-off-by: Joel Fernandes --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 81cd6d2..3b4fc7a 100644 --- a/README.md +++ b/README.md @@ -52,10 +52,19 @@ cd androdeb sudo ./androdeb prepare --download ``` -* Now run androdeb shell: +* Now run androdeb shell to enter your new environment!: ``` ./androdeb shell ``` + +* Once done, hit `CTRL + D` and you will exit out of the shell. +To remove androdeb from the device, run: +``` +./androdeb remove +``` +If you have multiple devices connected, please add `-s `. +Serial numbers of all devices connected can be obtained by `adb devices`. + More advanced usage instructions -------------------------------- ### Install kernel headers in addition to preparing androdeb device: -- cgit v1.2.3 From 170dfeb0a535343205ef859afc2af11b52596b0c Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Mon, 2 Apr 2018 23:15:19 -0700 Subject: Update Signed-off-by: Joel Fernandes --- TODO | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TODO b/TODO index 15f0843..94fe33b 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,3 @@ - check for space on both host and target - check if host deps are installed (Qemu etc) -- add an adb remove command to remove an env explicitly +- add version number to bashrc -- cgit v1.2.3 From d2f1352e2d508da83fa724e70f8a1c4eb417ed6e Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Mon, 2 Apr 2018 23:34:41 -0700 Subject: Update Signed-off-by: Joel Fernandes --- addons/run | 5 ++--- androdeb | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/addons/run b/addons/run index 103bba3..8e52ad7 100755 --- a/addons/run +++ b/addons/run @@ -14,13 +14,12 @@ mount --bind /sys/kernel/debug/tracing/ debian/sys/kernel/debug/tracing/ # Mount Android partitions if [ -d /d/ ]; then - mkdir -p debian/d/ - mount --bind /d debian/d/ + ln -s /sys/kernel/debug debian/d fi if [ -d /data/ ]; then mkdir -p debian/data/ - mount --bind /system debian/data/ + mount --bind /data debian/data/ fi if [ -d /system/ ]; then diff --git a/androdeb b/androdeb index c0a483e..60a7da4 100755 --- a/androdeb +++ b/androdeb @@ -2,7 +2,7 @@ # # (c) Joel Fernandes -VERSION=v0.95 +VERSION=v0.96 spath=$( cd "$(dirname "$0")" ; pwd -P ) curdir=$( pwd -P ) -- cgit v1.2.3 From bd00820ba1fb6236ce261ee8492d6258ea01098f Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Mon, 2 Apr 2018 23:45:16 -0700 Subject: Update Signed-off-by: Joel Fernandes --- addons/run | 2 +- androdeb | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/addons/run b/addons/run index 8e52ad7..725b306 100755 --- a/addons/run +++ b/addons/run @@ -14,7 +14,7 @@ mount --bind /sys/kernel/debug/tracing/ debian/sys/kernel/debug/tracing/ # Mount Android partitions if [ -d /d/ ]; then - ln -s /sys/kernel/debug debian/d + if [ ! -d debian/d ]; then ln -s /sys/kernel/debug debian/d; fi fi if [ -d /data/ ]; then diff --git a/androdeb b/androdeb index 60a7da4..c95d6bf 100755 --- a/androdeb +++ b/androdeb @@ -161,10 +161,6 @@ chroot $OUT_TMP rm /bin/sh || true chroot $OUT_TMP ln -s /bin/bash /bin/sh || true cp $spath/addons/bashrc $OUT_TMP/.bashrc -# For mounting android partitions -mkdir $OUT_TMP/system -mkdir $OUT_TMP/vendor - # Cleanup rm -rf $OUT_TMP/lib/udev/* rm -rf $OUT_TMP/var/lib/apt/lists/* -- cgit v1.2.3 From 3be0220430b8233b0a572d4ad9279c4dc4ad0172 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Mon, 2 Apr 2018 23:50:22 -0700 Subject: Update Signed-off-by: Joel Fernandes --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3b4fc7a..52d435e 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ cd androdeb * Fastest way of installing androdeb onto your device: ``` -# First make sure device is connected to system (only single device supported) +# First make sure device is connected to system sudo ./androdeb prepare --download ``` -- cgit v1.2.3 From 464193ec1bf2a8a4b44a897f543a97e8888c6c95 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Mon, 2 Apr 2018 23:54:49 -0700 Subject: Make it possible to symlink androdeb Signed-off-by: Joel Fernandes --- androdeb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/androdeb b/androdeb index c95d6bf..fdc7722 100755 --- a/androdeb +++ b/androdeb @@ -4,7 +4,8 @@ VERSION=v0.96 -spath=$( cd "$(dirname "$0")" ; pwd -P ) +spath="$(dirname "$(readlink -f "$0")")" +# spath=$( cd "$(dirname "$0")" ; pwd -P ) curdir=$( pwd -P ) source $spath/utils/android source $spath/utils/banners -- cgit v1.2.3 From e573e6cd017c533a65c326b721e124aa0977ee17 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Mon, 2 Apr 2018 23:59:12 -0700 Subject: Update Signed-off-by: Joel Fernandes --- README.md | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 52d435e..ba67855 100644 --- a/README.md +++ b/README.md @@ -44,23 +44,24 @@ Quick Start Instructions ``` git clone https://github.com/joelagnel/androdeb.git cd androdeb +sudo ln -s ./androdeb /usr/bin/androdeb ``` * Fastest way of installing androdeb onto your device: ``` # First make sure device is connected to system -sudo ./androdeb prepare --download +sudo androdeb prepare --download ``` * Now run androdeb shell to enter your new environment!: ``` -./androdeb shell +androdeb shell ``` * Once done, hit `CTRL + D` and you will exit out of the shell. To remove androdeb from the device, run: ``` -./androdeb remove +androdeb remove ``` If you have multiple devices connected, please add `-s `. Serial numbers of all devices connected can be obtained by `adb devices`. @@ -69,14 +70,14 @@ More advanced usage instructions -------------------------------- ### Install kernel headers in addition to preparing androdeb device: ``` -./androdeb prepare --download --kernelsrc /path/to/kernel-source +androdeb prepare --download --kernelsrc /path/to/kernel-source ``` ### Update kernel headers onto an already prepared device: If you need to put kernel sources for an existing install, run: ``` -./androdeb prepare --kernelsrc /path/to/kernel-source +androdeb prepare --kernelsrc /path/to/kernel-source ``` Note: The kernel sources should have been built (atleast build should have started). @@ -84,23 +85,23 @@ Note: The kernel sources should have been built (atleast build should have start The androdeb fs will be prepared locally by downloading packages as needed: ``` -./androdeb prepare --fullbuild +androdeb prepare --fullbuild ``` This is unlike `--download` where the androdeb rootfs is itself pulled from the web. ### Add kernel headers to device in addition to building locally: ``` -./androdeb prepare --fullbuild --kernelsrc /path/to/kernel-source/ +androdeb prepare --fullbuild --kernelsrc /path/to/kernel-source/ ``` ### Instead of `--fullbuild`, customize what you install: ``` -./androdeb prepare --editors --compilers +androdeb prepare --editors --compilers ``` ### Install only BCC: ``` -./androdeb prepare --bcc --kernelsrc /path/to/kernel-source/ +androdeb prepare --bcc --kernelsrc /path/to/kernel-source/ ``` Note: BCC is built while being installed. Also `--kernelsrc` is recommended for tools to function unless device has them @@ -108,7 +109,7 @@ already. ### Extract the FS from the device, after its prepared: ``` -./androdeb prepare --fullbuild --buildtar /path/ +androdeb prepare --fullbuild --buildtar /path/ ``` After device is prepared, it will extract the root fs from it and store it as a tar archive at `/path/androdeb-fs.tgz`. This @@ -116,5 +117,5 @@ can be used later. ### Use a previously prepared androdeb rootfs tar from local: ``` -./androdeb prepare --archive /path/androdeb-fs.tgz +androdeb prepare --archive /path/androdeb-fs.tgz ``` -- cgit v1.2.3 From 6c4de6c6aa744dbc1dd122c5a9a4995d90145c87 Mon Sep 17 00:00:00 2001 From: ErickReyesR Date: Tue, 3 Apr 2018 11:27:53 -0700 Subject: Update README.md Fix typo in required packages (deboostrap -> debootstrap) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ba67855..19ea27f 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ free space in the data partition. Host: A machine running recent Ubuntu or Debian, with 4GB of memory and 4GB free space. Host needs debootstrap and qemu-debootstrap packages. -To install it, run `sudo apt-get install qemu-user-static deboostrap`. +To install it, run `sudo apt-get install qemu-user-static debootstrap`. Other distributions may work but they are not tested. Quick Start Instructions -- cgit v1.2.3 From 7dd36e668d43ceb2957a44a9192ace6abe614d39 Mon Sep 17 00:00:00 2001 From: Joel Date: Tue, 3 Apr 2018 12:35:23 -0700 Subject: Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ba67855..19ea27f 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ free space in the data partition. Host: A machine running recent Ubuntu or Debian, with 4GB of memory and 4GB free space. Host needs debootstrap and qemu-debootstrap packages. -To install it, run `sudo apt-get install qemu-user-static deboostrap`. +To install it, run `sudo apt-get install qemu-user-static debootstrap`. Other distributions may work but they are not tested. Quick Start Instructions -- cgit v1.2.3 From 34863fe90a786da6b5a50da749668b11aeaf8e17 Mon Sep 17 00:00:00 2001 From: Erick Reyes Date: Tue, 3 Apr 2018 17:01:06 -0700 Subject: build-kheaders: Fix redirection of error messages When the kernel source was not built in-tree, the script was failing silently. This patch exposes the error to the user. --- bcc/build-kheaders-targz.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/bcc/build-kheaders-targz.sh b/bcc/build-kheaders-targz.sh index 105fb6d..06eed93 100755 --- a/bcc/build-kheaders-targz.sh +++ b/bcc/build-kheaders-targz.sh @@ -25,11 +25,13 @@ find include >> /tmp/kernel-headers.h grep "include/generated/autoconf.h" /tmp/kernel-headers.h > /dev/null 2>&1 retgrep=$? if [ $retgrep -ne 0 ]; then - echo "" - echo "The kernel sources at ${KERNEL_PATH} you pointed to aren't configured and built." - echo "Please atleast run in your kernel sources:" - echo $'make defconfig\nmake' - echo $'\nNote: You dont need to do the full build since headers are generated early on.\n' + >&2 echo "" + >&2 echo "The kernel sources at ${KERNEL_PATH} you pointed to aren't configured and built." + >&2 echo "Please atleast run in your kernel sources:" + >&2 echo $'make defconfig\nmake' + >&2 echo $'\nNote: You dont need to do the full build since headers are generated early on.\n' + >&2 echo "Note: Please build your kernel in tree (build and source should be in same directory)" + >&2 echo "" exit $retgrep fi -- cgit v1.2.3 From 139fa98233fa1513d88001f15481b4e957680690 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Wed, 4 Apr 2018 04:26:22 -0700 Subject: Add rust and golang Signed-off-by: Joel Fernandes --- addons/bashrc | 4 ++-- androdeb | 2 +- packages/compilers | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/addons/bashrc b/addons/bashrc index c814ecf..16cb209 100644 --- a/addons/bashrc +++ b/addons/bashrc @@ -6,8 +6,8 @@ echo "##########################################################" echo "# Welcome to androdeb environment running on Android! #" echo "# Questions to: Joel Fernandes #" echo " #" -echo " Try running vim, gcc, clang, bcc, git, make, perf etc #" -echo " or apt-get install something. #" +echo " Try vim, gcc, rust, go, git, make, perf, trace, filetop #" +echo " trace-cmd etc. or apt-get install something. #" echo " #" echo " Note: For apt-get to work, you need to disable #" echo " CONFIG_ANDROID_PARANOID_NETWORK and rebuild kernel. #" diff --git a/androdeb b/androdeb index fdc7722..1eb6411 100755 --- a/androdeb +++ b/androdeb @@ -2,7 +2,7 @@ # # (c) Joel Fernandes -VERSION=v0.96 +VERSION=v0.97 spath="$(dirname "$(readlink -f "$0")")" # spath=$( cd "$(dirname "$0")" ; pwd -P ) diff --git a/packages/compilers b/packages/compilers index f380dd3..9d9a614 100644 --- a/packages/compilers +++ b/packages/compilers @@ -2,6 +2,8 @@ PACKAGES+="\ git clang-6.0 gcc +rustc +golang libtool autoconf make -- cgit v1.2.3 From dec5adf51b5f811c3ebf511f92c31e53f1075728 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Wed, 4 Apr 2018 11:22:29 -0700 Subject: add nodejs Signed-off-by: Joel Fernandes --- packages/compilers | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/compilers b/packages/compilers index 9d9a614..e24a6b9 100644 --- a/packages/compilers +++ b/packages/compilers @@ -4,6 +4,7 @@ clang-6.0 gcc rustc golang +nodejs libtool autoconf make -- cgit v1.2.3 From 301e455978e218f8878901aeec8288f1e932401a Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Thu, 5 Apr 2018 22:46:19 -0700 Subject: Make it possible to run mostly without sudo Signed-off-by: Joel Fernandes --- androdeb | 35 ++--------------------------------- buildstrap | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 33 deletions(-) create mode 100755 buildstrap diff --git a/androdeb b/androdeb index 1eb6411..474e61f 100755 --- a/androdeb +++ b/androdeb @@ -100,8 +100,6 @@ function all_done_banner() { # Prepare is the last command checked if [ -z "$PREPARE" ]; then usage; fi -if [[ $EUID -ne 0 ]]; then die 6 "For prepare, this tool must run as root. Try: ./sudo androdeb prepare "; fi - if [ ! -z "$TARF" ] && [ ! -f $TARF ] && [ -z "$DOWNLOAD" ]; then die 7 "archive provided doesn't exist"; fi if [ ! -z "$KERNELSRC" ] && [ ! -d $KERNELSRC ]; then die 5 "Kernel source directory provided doesn't exist"; fi @@ -150,38 +148,9 @@ fi PACKAGES+="$DEFAULT_PACKAGES" echo "Using temporary directory: $TDIR" -time qemu-debootstrap --arch arm64 --include=$(make_csv "$PACKAGES") \ - $DISTRO $OUT_TMP http://deb.debian.org/debian/ - -# Some reason debootstrap leaves these mounted -umount $OUT_TMP/proc/sys/fs/binfmt_misc || true -umount $OUT_TMP/proc || true - -# Make bash the default shell -chroot $OUT_TMP rm /bin/sh || true -chroot $OUT_TMP ln -s /bin/bash /bin/sh || true -cp $spath/addons/bashrc $OUT_TMP/.bashrc - -# Cleanup -rm -rf $OUT_TMP/lib/udev/* -rm -rf $OUT_TMP/var/lib/apt/lists/* -rm -rf $OUT_TMP/var/cache/apt/archives/*deb -rm -rf $OUT_TMP/usr/share/locale/* -rm -rf $OUT_TMP/usr/lib/share/locale/* -rm -rf $OUT_TMP/usr/share/doc/* -rm -rf $OUT_TMP/usr/lib/share/doc/* -rm -rf $OUT_TMP/usr/share/ieee-data/* -rm -rf $OUT_TMP/usr/lib/share/ieee-data/* -rm -rf $OUT_TMP/usr/share/man/* -rm -rf $OUT_TMP/usr/lib/share/man/* - -# Clone BCC if needed -if [[ ! -z ${INSTALL_BCC+x} ]]; then -git clone https://github.com/iovisor/bcc.git $TDIR/debian/bcc-master -cp $spath/bcc/build-bcc.sh $TDIR/debian/bcc-master/; fi +if [[ $EUID -ne 0 ]]; then echo "The next stage runs as sudo, please enter password if asked."; fi -echo "Compressing new filesystem to prepare to push to Android /data/androdeb/" -tar -zcf $TDIR/deb.tar.gz -C $TDIR debian +sudo $spath/buildstrap $ARCH $DISTRO $TDIR $OUT_TMP "$(make_csv "$PACKAGES")" # Push tar to device and start unpack $ADB shell mkdir -p /data/androdeb/ diff --git a/buildstrap b/buildstrap new file mode 100755 index 0000000..6e92553 --- /dev/null +++ b/buildstrap @@ -0,0 +1,44 @@ +#!/bin/bash + +ARCH=$1 +DISTRO=$2 +TDIR=$3 +OUT_TMP=$4 +PACKAGES=$5 + +time qemu-debootstrap --arch $ARCH --include=$(make_csv "$PACKAGES") \ + $DISTRO $OUT_TMP http://deb.debian.org/debian/ + +# Some reason debootstrap leaves these mounted +umount $OUT_TMP/proc/sys/fs/binfmt_misc || true +umount $OUT_TMP/proc || true + +# Make bash the default shell +chroot $OUT_TMP rm /bin/sh || true +chroot $OUT_TMP ln -s /bin/bash /bin/sh || true +cp $spath/addons/bashrc $OUT_TMP/.bashrc + +# Cleanup +rm -rf $OUT_TMP/lib/udev/* +rm -rf $OUT_TMP/var/lib/apt/lists/* +rm -rf $OUT_TMP/var/cache/apt/archives/*deb +rm -rf $OUT_TMP/usr/share/locale/* +rm -rf $OUT_TMP/usr/lib/share/locale/* +rm -rf $OUT_TMP/usr/share/doc/* +rm -rf $OUT_TMP/usr/lib/share/doc/* +rm -rf $OUT_TMP/usr/share/ieee-data/* +rm -rf $OUT_TMP/usr/lib/share/ieee-data/* +rm -rf $OUT_TMP/usr/share/man/* +rm -rf $OUT_TMP/usr/lib/share/man/* + +# Clone BCC if needed +if [[ ! -z ${INSTALL_BCC+x} ]]; then +git clone https://github.com/iovisor/bcc.git $TDIR/debian/bcc-master +cp $spath/bcc/build-bcc.sh $TDIR/debian/bcc-master/; fi + +echo "Compressing new filesystem to prepare to push to Android /data/androdeb/" +tar -zcf $TDIR/deb.tar.gz -C $TDIR debian + +chmod -R 0777 $TDIR/ + +chmod 0777 $TDIR/deb.tar.gz -- cgit v1.2.3 From 93149afa78aaec955ed54e3c20b69ab4c2c9923b Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Thu, 5 Apr 2018 22:46:48 -0700 Subject: Revert "add nodejs" This reverts commit dec5adf51b5f811c3ebf511f92c31e53f1075728. --- packages/compilers | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/compilers b/packages/compilers index e24a6b9..9d9a614 100644 --- a/packages/compilers +++ b/packages/compilers @@ -4,7 +4,6 @@ clang-6.0 gcc rustc golang -nodejs libtool autoconf make -- cgit v1.2.3 From ae5f5cd16f244446f932834f5a984c672bad19b5 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Thu, 5 Apr 2018 22:46:50 -0700 Subject: Revert "Add rust and golang" This reverts commit 139fa98233fa1513d88001f15481b4e957680690. --- addons/bashrc | 4 ++-- androdeb | 2 +- packages/compilers | 2 -- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/addons/bashrc b/addons/bashrc index 16cb209..c814ecf 100644 --- a/addons/bashrc +++ b/addons/bashrc @@ -6,8 +6,8 @@ echo "##########################################################" echo "# Welcome to androdeb environment running on Android! #" echo "# Questions to: Joel Fernandes #" echo " #" -echo " Try vim, gcc, rust, go, git, make, perf, trace, filetop #" -echo " trace-cmd etc. or apt-get install something. #" +echo " Try running vim, gcc, clang, bcc, git, make, perf etc #" +echo " or apt-get install something. #" echo " #" echo " Note: For apt-get to work, you need to disable #" echo " CONFIG_ANDROID_PARANOID_NETWORK and rebuild kernel. #" diff --git a/androdeb b/androdeb index 474e61f..90cf1c8 100755 --- a/androdeb +++ b/androdeb @@ -2,7 +2,7 @@ # # (c) Joel Fernandes -VERSION=v0.97 +VERSION=v0.96 spath="$(dirname "$(readlink -f "$0")")" # spath=$( cd "$(dirname "$0")" ; pwd -P ) diff --git a/packages/compilers b/packages/compilers index 9d9a614..f380dd3 100644 --- a/packages/compilers +++ b/packages/compilers @@ -2,8 +2,6 @@ PACKAGES+="\ git clang-6.0 gcc -rustc -golang libtool autoconf make -- cgit v1.2.3 From 2b3b4d1f5b6bed62344affee6364236dfdb366a9 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Thu, 5 Apr 2018 22:47:00 -0700 Subject: Bump version Signed-off-by: Joel Fernandes --- androdeb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/androdeb b/androdeb index 90cf1c8..474e61f 100755 --- a/androdeb +++ b/androdeb @@ -2,7 +2,7 @@ # # (c) Joel Fernandes -VERSION=v0.96 +VERSION=v0.97 spath="$(dirname "$(readlink -f "$0")")" # spath=$( cd "$(dirname "$0")" ; pwd -P ) -- cgit v1.2.3 From 1637115d0ed615bec864283fa39fe72df1d07e35 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Thu, 5 Apr 2018 22:50:36 -0700 Subject: add new pull command to update git Signed-off-by: Joel Fernandes --- androdeb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/androdeb b/androdeb index 474e61f..c2adcba 100755 --- a/androdeb +++ b/androdeb @@ -27,6 +27,7 @@ case $key in prepare) PREPARE=1; shift || true; ;; shell) ASHELL=1; shift || true; ;; remove) REMOVE=1; shift || true; ;; + pull) PULL=1; shift || true; ;; --archive) TARF=$2; shift || true; shift || true; ;; --tracers) source $spath/packages/tracers; shift || true; ;; --compilers) source $spath/packages/compilers; shift || true; ;; @@ -44,6 +45,14 @@ case $key in esac done +if [ ! -z "$PULL" ]; then + echo "Updating androdeb by git pull" + cd $spath + git pull + echo "Done." + exit 0 +fi + if [ ! -z "$PREPARE" ] && [ -z "$DOWNLOAD" ] && [ -z "$TARF" ] && [ -z "$PACKAGES" ] && [ -z "$KERNELSRC" ]; then echo "Need to specifify something to prepare, or try: ./andrdeb prepare --download"; usage; fi -- cgit v1.2.3 From ab5f9284fe1d70470e53c42ff2e4aa3ba6fbfc22 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Thu, 5 Apr 2018 22:53:23 -0700 Subject: Add a buildtar command to do a full build and tar to PWD Signed-off-by: Joel Fernandes --- androdeb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/androdeb b/androdeb index c2adcba..0ea880b 100755 --- a/androdeb +++ b/androdeb @@ -20,6 +20,10 @@ bash ca-certificates " +config_full_build() { + for f in $(ls $spath/packages); do source packages/$f; done; +} + # Parse command line parameters if [ $# -lt 1 ]; then usage; fi; POSITIONAL=() while [[ $# -gt 0 ]]; do key="$1"; @@ -28,12 +32,13 @@ case $key in shell) ASHELL=1; shift || true; ;; remove) REMOVE=1; shift || true; ;; pull) PULL=1; shift || true; ;; + buildtar) PREPARE=1; TARDIR="./"; config_full_build; shift || true; ;; --archive) TARF=$2; shift || true; shift || true; ;; --tracers) source $spath/packages/tracers; shift || true; ;; --compilers) source $spath/packages/compilers; shift || true; ;; --editors) source $spath/packages/editors; shift || true; ;; --scheduler) source $spath/packages/scheduler; shift || true; ;; - --fullbuild) for f in $(ls $spath/packages); do source packages/$f; done; shift || true; ;; + --fullbuild) config_full_build; shift || true; ;; --download) DOWNLOAD=1; shift || true; ;; --bcc) source $spath/packages/bcc; shift || true; ;; --kernelsrc) KERNELSRC="$2"; shift || true; shift || true; ;; -- cgit v1.2.3 From 9d767b4f4bed5116e5d1797faf46741f6dc68bfb Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Thu, 5 Apr 2018 22:55:24 -0700 Subject: Fix buildstrap issue Signed-off-by: Joel Fernandes --- androdeb | 2 +- buildstrap | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/androdeb b/androdeb index 0ea880b..c856b2a 100755 --- a/androdeb +++ b/androdeb @@ -164,7 +164,7 @@ echo "Using temporary directory: $TDIR" if [[ $EUID -ne 0 ]]; then echo "The next stage runs as sudo, please enter password if asked."; fi -sudo $spath/buildstrap $ARCH $DISTRO $TDIR $OUT_TMP "$(make_csv "$PACKAGES")" +sudo $spath/buildstrap $ARCH $DISTRO $TDIR $OUT_TMP "$(make_csv "$PACKAGES")" $INSTALL_BCC # Push tar to device and start unpack $ADB shell mkdir -p /data/androdeb/ diff --git a/buildstrap b/buildstrap index 6e92553..881dcbc 100755 --- a/buildstrap +++ b/buildstrap @@ -1,10 +1,15 @@ #!/bin/bash +spath="$(dirname "$(readlink -f "$0")")" +source $spath/utils/android +source $spath/utils/banners + ARCH=$1 DISTRO=$2 TDIR=$3 OUT_TMP=$4 PACKAGES=$5 +INSTALL_BCC=$6 time qemu-debootstrap --arch $ARCH --include=$(make_csv "$PACKAGES") \ $DISTRO $OUT_TMP http://deb.debian.org/debian/ -- cgit v1.2.3 From 1d032fc66b2fbe4d46e16adb3d336da83db0d492 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Thu, 5 Apr 2018 23:23:44 -0700 Subject: Update docs Signed-off-by: Joel Fernandes --- README.md | 7 ++++++- utils/banners | 6 ++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 19ea27f..3dbc035 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ sudo ln -s ./androdeb /usr/bin/androdeb * Fastest way of installing androdeb onto your device: ``` # First make sure device is connected to system -sudo androdeb prepare --download +androdeb prepare --download ``` * Now run androdeb shell to enter your new environment!: @@ -66,6 +66,11 @@ androdeb remove If you have multiple devices connected, please add `-s `. Serial numbers of all devices connected can be obtained by `adb devices`. +* To update the androdeb you cloned on your host, run: +``` +androdeb pull +``` + More advanced usage instructions -------------------------------- ### Install kernel headers in addition to preparing androdeb device: diff --git a/utils/banners b/utils/banners index 11d764e..467fac3 100755 --- a/utils/banners +++ b/utils/banners @@ -8,6 +8,8 @@ print_prepare_banner() { usage() { echo "androdeb" echo " shell Enter the androdeb shell environment and get to work!" + echo " remove Remove androdeb from the device" + echo " pull Git pull androdeb to update it on your host" echo "" echo " prepare Prepare the device (when running for the first time)" echo " --tracers Enable tracing packages (perf and trace-cmd)" @@ -27,8 +29,8 @@ usage() { echo " --tempdir Use a specific temporary directory for build operation" echo " --buildtar Local directory to store tarball of androdeb env from device" echo " --distro Debian distro to base on (default is buster)" - echo " --device Serial number of adb device." - echo " -s Serial number of adb device." + echo " --device Serial number of adb device." + echo " -s Serial number of adb device." echo "" echo " --debug" exit 1 -- cgit v1.2.3 From 3d063428ab979e334129c8dee01d6f5a4aed719b Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Thu, 5 Apr 2018 23:33:44 -0700 Subject: Bump version Signed-off-by: Joel Fernandes --- androdeb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/androdeb b/androdeb index c856b2a..1852d38 100755 --- a/androdeb +++ b/androdeb @@ -2,7 +2,7 @@ # # (c) Joel Fernandes -VERSION=v0.97 +VERSION=v0.98 spath="$(dirname "$(readlink -f "$0")")" # spath=$( cd "$(dirname "$0")" ; pwd -P ) -- cgit v1.2.3 From 1ed30d73e38dfeb9433510510a43cb78efa7f54a Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Fri, 18 May 2018 14:08:20 -0700 Subject: Add support for unpacking a custom built kernel header tar gz This can be used as: androdeb prepare --download --kernel-headers-targz /tmp/kernel-headers.tar.gz Signed-off-by: Joel Fernandes --- androdeb | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/androdeb b/androdeb index 1852d38..d070378 100755 --- a/androdeb +++ b/androdeb @@ -1,6 +1,6 @@ #!/bin/bash -e # -# (c) Joel Fernandes +# (c) Joel Fernandes VERSION=v0.98 @@ -42,6 +42,7 @@ case $key in --download) DOWNLOAD=1; shift || true; ;; --bcc) source $spath/packages/bcc; shift || true; ;; --kernelsrc) KERNELSRC="$2"; shift || true; shift || true; ;; + --kernel-headers-targz) KERNELHDRS=$2; shift || true; shift || true; ;; --tempdir) TDIR="$2"; shift || true; shift || true; ;; --buildtar) TARDIR="$2"; shift || true; shift || true; ;; --device|-s) ADB="$ADB -s $2"; shift || true; shift || true; ;; @@ -58,7 +59,7 @@ if [ ! -z "$PULL" ]; then exit 0 fi -if [ ! -z "$PREPARE" ] && [ -z "$DOWNLOAD" ] && [ -z "$TARF" ] && [ -z "$PACKAGES" ] && [ -z "$KERNELSRC" ]; then +if [ ! -z "$PREPARE" ] && [ -z "$DOWNLOAD" ] && [ -z "$TARF" ] && [ -z "$PACKAGES" ] && [ -z "$KERNELSRC" ] && [ -z "$KERNELHDRS" ]; then echo "Need to specifify something to prepare, or try: ./andrdeb prepare --download"; usage; fi if [[ ! -z ${TARDIR+x} ]] && [[ ! -d $TARDIR ]]; then die 7 "Tar dir specified doesn't exist"; fi @@ -107,6 +108,18 @@ function push_unpack_headers() { $ADB shell rm /data/androdeb/kh.tgz } +function push_unpack_tarred_headers() { + die_if_no_androdeb "Couldn't update headers." + + $ADB shell rm -rf /data/androdeb/debian/kernel-headers/ + $ADB shell mkdir /data/androdeb/debian/kernel-headers/ + $ADB push $1 /data/androdeb/ + echo "Storing kernel headers into androdeb root directory" + $ADB shell tar -xvf /data/androdeb/$(basename $1) -C /data/androdeb/debian/ > /dev/null + + $ADB shell rm /data/androdeb/$(basename $1) +} + function all_done_banner() { echo "All done! Run \"androdeb shell\" to enter environment" } @@ -114,9 +127,11 @@ function all_done_banner() { # Prepare is the last command checked if [ -z "$PREPARE" ]; then usage; fi -if [ ! -z "$TARF" ] && [ ! -f $TARF ] && [ -z "$DOWNLOAD" ]; then die 7 "archive provided doesn't exist"; fi +if [ ! -z "$TARF" ] && [ ! -f $TARF ] && [ -z "$DOWNLOAD" ]; then die 5 "archive provided doesn't exist"; fi + +if [ ! -z "$KERNELSRC" ] && [ ! -d $KERNELSRC ]; then die 6 "Kernel source directory provided doesn't exist"; fi -if [ ! -z "$KERNELSRC" ] && [ ! -d $KERNELSRC ]; then die 5 "Kernel source directory provided doesn't exist"; fi +if [ ! -z "$KERNELHDRS" ] && [ ! -f $KERNELHDRS ]; then die 7 "Kernel headers tar.gz doesn't exist"; fi print_prepare_banner @@ -133,6 +148,17 @@ if [ ! -z "$DOWNLOAD" ]; then OUT_TMP=$TDIR/debian; rm -rf $OUT_TMP; mkdir -p $OUT_TMP +# Unpack the supplied kernel headers tar.gz directly into androdeb root +if [ ! -z "$KERNELHDRS" ]; then + echo "Building updating kernel headers from supplied tar.gz ($KERNELHDRS)" + + # Is header tar gz update the only thing left to do? + if [[ -z "$PACKAGES" ]] && [[ -z "$TARF" ]] && [[ -z "$KERNELSRC" ]] ; then + push_unpack_tarred_headers $KERNELHDRS; do_cleanup; all_done_banner; exit 0; fi + + tar -xvf $KERNELHDRS -C $OUT_TMP/ > /dev/null +fi + # Package kernel headers if [ ! -z "$KERNELSRC" ]; then echo "Building and updating kernel headers from kernel source dir ($KERNELSRC)" @@ -154,6 +180,7 @@ if [ ! -z "$TARF" ]; then $ADB push $spath/addons/* /data/androdeb/ $ADB shell /data/androdeb/device-unpack + if [ ! -z "$KERNELHDRS" ]; then push_unpack_tarred_headers $KERNELHDRS; fi if [ ! -z "$KERNELSRC" ]; then push_unpack_headers; fi do_cleanup; all_done_banner; exit 0 -- cgit v1.2.3 From 8c9de04396baf952bb5564fe893f6ee597cf9ff7 Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Sat, 26 May 2018 19:35:24 -0700 Subject: Fix: not all arches carry same kernel-version for perf Signed-off-by: Joel Fernandes (Google) --- packages/tracers | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/tracers b/packages/tracers index 321c071..38c1d43 100644 --- a/packages/tracers +++ b/packages/tracers @@ -1,6 +1,5 @@ PACKAGES+="\ linux-perf -linux-perf-4.15 trace-cmd strace " -- cgit v1.2.3 From d7f21f10b0e0bc8cbf77565b58f97a9f4afa5458 Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Sun, 27 May 2018 20:19:51 -0700 Subject: Allow --fullbuild run from any directory Signed-off-by: Joel Fernandes (Google) --- androdeb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/androdeb b/androdeb index d070378..89a6b3f 100755 --- a/androdeb +++ b/androdeb @@ -21,7 +21,7 @@ ca-certificates " config_full_build() { - for f in $(ls $spath/packages); do source packages/$f; done; + for f in $(ls $spath/packages); do source $spath/packages/$f; done; } # Parse command line parameters -- cgit v1.2.3 From 08d1a07e1acf12e75449fb72313be866bd308792 Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Mon, 28 May 2018 13:29:03 -0700 Subject: Add option to override default arch with --arch option Signed-off-by: Joel Fernandes (Google) --- androdeb | 1 + utils/banners | 1 + 2 files changed, 2 insertions(+) diff --git a/androdeb b/androdeb index 89a6b3f..9645f81 100755 --- a/androdeb +++ b/androdeb @@ -33,6 +33,7 @@ case $key in remove) REMOVE=1; shift || true; ;; pull) PULL=1; shift || true; ;; buildtar) PREPARE=1; TARDIR="./"; config_full_build; shift || true; ;; + --arch) ARCH=$2; shift || true; shift || true; ;; --archive) TARF=$2; shift || true; shift || true; ;; --tracers) source $spath/packages/tracers; shift || true; ;; --compilers) source $spath/packages/compilers; shift || true; ;; diff --git a/utils/banners b/utils/banners index 467fac3..14ae5dc 100755 --- a/utils/banners +++ b/utils/banners @@ -33,6 +33,7 @@ usage() { echo " -s Serial number of adb device." echo "" echo " --debug" + echo " --arch Specify an ARCH to build for (default arm64)" exit 1 } -- cgit v1.2.3 From 9c3ae936242dd7fe330e814a8d039fb2e7ec6ced Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Mon, 28 May 2018 14:34:48 -0700 Subject: Add support to build an ext4 image from a filesystem This is suitable for passing to Qemu with -hda which makes it appear as a disk to a Qemu instance. Once it appears, one can chroot into it. Note: - Device need not be connected, this option is only used to prepare a standalone image. - BCC isn't built but is just cloned into the image. - Other options such as --buildtar are ignored. Signed-off-by: Joel Fernandes (Google) --- README.md | 7 +++++++ androdeb | 30 ++++++++++++++++++++++++++---- buildimage | 11 +++++++++++ buildstrap | 8 ++++++-- utils/banners | 1 + 5 files changed, 51 insertions(+), 6 deletions(-) create mode 100755 buildimage diff --git a/README.md b/README.md index 3dbc035..d7d3e85 100644 --- a/README.md +++ b/README.md @@ -124,3 +124,10 @@ can be used later. ``` androdeb prepare --archive /path/androdeb-fs.tgz ``` + +### Build a standalone raw EXT4 image out of the FS: +``` +androdeb prepare --buildimage /path/to/image.img +``` +This can then be passed to Qemu as -hda. Note: This option doesn't need a +device connected. diff --git a/androdeb b/androdeb index 9645f81..eca1de0 100755 --- a/androdeb +++ b/androdeb @@ -47,6 +47,7 @@ case $key in --tempdir) TDIR="$2"; shift || true; shift || true; ;; --buildtar) TARDIR="$2"; shift || true; shift || true; ;; --device|-s) ADB="$ADB -s $2"; shift || true; shift || true; ;; + --build-image) BUILD_IMAGE=$2; shift || true; shift || true; ;; --debug) set -x; shift || true; ;; *) echo "Unknown option ($1)"; usage; ;; esac @@ -60,17 +61,26 @@ if [ ! -z "$PULL" ]; then exit 0 fi -if [ ! -z "$PREPARE" ] && [ -z "$DOWNLOAD" ] && [ -z "$TARF" ] && [ -z "$PACKAGES" ] && [ -z "$KERNELSRC" ] && [ -z "$KERNELHDRS" ]; then +if [ -z "$PACKAGES" ]; then + echo "No packages specified, so I'm going to do a --fullbuild" + config_full_build +fi + +if [ ! -z "$PREPARE" ] && [ -z "$DOWNLOAD" ] && [ -z "$TARF" ] && + [ -z "$KERNELSRC" ] && [ -z "$KERNELHDRS" ] && + [ -z "$BUILD_IMAGE" ]; then echo "Need to specifify something to prepare, or try: ./andrdeb prepare --download"; usage; fi if [[ ! -z ${TARDIR+x} ]] && [[ ! -d $TARDIR ]]; then die 7 "Tar dir specified doesn't exist"; fi +if [ -z "$BUILD_IMAGE" ]; then do_adb_root "$ADB" || die 3 "adb root failed, make sure: - If multiple devices connected, provide --device (or -s ) - Try to run \"adb root\" manually and see if it works. Typically this needs a userdebug build. Note: adb can be typically obtained using the android-tools-adb or the adb packages on your distro, or by installing the Android SDK." +fi if [ ! -z "$REMOVE" ]; then die_if_no_androdeb "Nothing to remove." @@ -154,7 +164,7 @@ if [ ! -z "$KERNELHDRS" ]; then echo "Building updating kernel headers from supplied tar.gz ($KERNELHDRS)" # Is header tar gz update the only thing left to do? - if [[ -z "$PACKAGES" ]] && [[ -z "$TARF" ]] && [[ -z "$KERNELSRC" ]] ; then + if [[ -z "$PACKAGES" ]] && [[ -z "$TARF" ]] && [[ -z "$BUILD_IMAGE" ]] && [[ -z "$KERNELSRC" ]] ; then push_unpack_tarred_headers $KERNELHDRS; do_cleanup; all_done_banner; exit 0; fi tar -xvf $KERNELHDRS -C $OUT_TMP/ > /dev/null @@ -166,7 +176,7 @@ if [ ! -z "$KERNELSRC" ]; then $spath/bcc/build-kheaders-targz.sh ${KERNELSRC} $TDIR_ABS/kh.tgz > /dev/null # Is header update the only thing left to do? - if [[ -z "$PACKAGES" ]] && [[ -z "$TARF" ]]; then + if [[ -z "$PACKAGES" ]] && [[ -z "$BUILD_IMAGE" ]] && [[ -z "$TARF" ]]; then push_unpack_headers; do_cleanup; all_done_banner; exit 0; fi mkdir $OUT_TMP/kernel-headers @@ -192,7 +202,19 @@ echo "Using temporary directory: $TDIR" if [[ $EUID -ne 0 ]]; then echo "The next stage runs as sudo, please enter password if asked."; fi -sudo $spath/buildstrap $ARCH $DISTRO $TDIR $OUT_TMP "$(make_csv "$PACKAGES")" $INSTALL_BCC +SKIP_COMPRESS=0; if [ ! -z "$BUILD_IMAGE" ]; then SKIP_COMPRESS=1; fi + +sudo $spath/buildstrap $ARCH $DISTRO $TDIR $OUT_TMP "$(make_csv "$PACKAGES")" $INSTALL_BCC $SKIP_COMPRESS + +# If we only wanted to prepare a rootfs and don't have +# a device connected, then just echo that and skip cleanup +if [ ! -z "$BUILD_IMAGE" ]; then + echo "For --build-image, only the image is built" + echo "Note that BCC will not be built on the image, you've to do it yourself" + sudo $spath/buildimage $OUT_TMP $(dirname $BUILD_IMAGE)/$(basename $BUILD_IMAGE) + sudo chmod a+rw $(dirname $BUILD_IMAGE)/$(basename $BUILD_IMAGE) + do_cleanup; echo "Your .img has been built! Enjoy!"; exit 0 +fi # Push tar to device and start unpack $ADB shell mkdir -p /data/androdeb/ diff --git a/buildimage b/buildimage new file mode 100755 index 0000000..ccdc65d --- /dev/null +++ b/buildimage @@ -0,0 +1,11 @@ +#!/bin/bash +set -e + +# Given a path, make an ext4 image out of it, store it in $2 +dd if=/dev/zero of=$2 bs=4k count=$((256 * 1024 * 2)) +mkfs.ext4 $2 + +OUT=`mktemp -d` +mount -o loop $2 $OUT/ +rsync -ra $1/ $OUT/ +umount $OUT/ diff --git a/buildstrap b/buildstrap index 881dcbc..e6b7679 100755 --- a/buildstrap +++ b/buildstrap @@ -10,6 +10,7 @@ TDIR=$3 OUT_TMP=$4 PACKAGES=$5 INSTALL_BCC=$6 +SKIP_COMPRESS=$7 time qemu-debootstrap --arch $ARCH --include=$(make_csv "$PACKAGES") \ $DISTRO $OUT_TMP http://deb.debian.org/debian/ @@ -41,9 +42,12 @@ if [[ ! -z ${INSTALL_BCC+x} ]]; then git clone https://github.com/iovisor/bcc.git $TDIR/debian/bcc-master cp $spath/bcc/build-bcc.sh $TDIR/debian/bcc-master/; fi +# Should be really do this? +chmod -R 0777 $TDIR/ + +if [ $SKIP_COMPRESS -eq 1 ]; then exit 0; fi + echo "Compressing new filesystem to prepare to push to Android /data/androdeb/" tar -zcf $TDIR/deb.tar.gz -C $TDIR debian -chmod -R 0777 $TDIR/ - chmod 0777 $TDIR/deb.tar.gz diff --git a/utils/banners b/utils/banners index 14ae5dc..342e48a 100755 --- a/utils/banners +++ b/utils/banners @@ -21,6 +21,7 @@ usage() { echo "" echo " --download Download full FS archive from web (overrides all tools specified)" echo " --archive Use archive for root fs (overrides all other prepare options)" + echo " --build-image Build an ext4 .img with the base image and BCC (useful for Qemu)" echo "" echo " --bcc Build and install BCC from source" echo " --kernelsrc Extract kernel headers for BCC from here" -- cgit v1.2.3 From fa32e59e703c49f2109d0d333cba4fc2e0e8c2eb Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Tue, 29 May 2018 11:49:20 -0700 Subject: Update BCC/androdeb docs Signed-off-by: Joel Fernandes (Google) --- BCC.md | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 19 +++++++++-- 2 files changed, 125 insertions(+), 3 deletions(-) create mode 100644 BCC.md diff --git a/BCC.md b/BCC.md new file mode 100644 index 0000000..f6f78a7 --- /dev/null +++ b/BCC.md @@ -0,0 +1,109 @@ +BCC (BPF compiler collection) for Android +========================================= + +Introduction +------------ +BCC is a compiler and a toolkit, containing powerful kernel tracing tools that +trace at the lowest levels, including adding hooks to functions in kernel space +and user space to deeply understand system behavior while being low in +overhead. [Here's a presentation with +Overview](http://www.joelfernandes.org/resources/bcc-ospm.pdf) and visit [BCC +project page](https://github.com/iovisor/bcc) for official BCC documentation. + +Quick Start +----------- +androdeb is the primary vehicle for running BCC on Android. It supports +preparing the target Android device with necessary kernel headers, cloning and +building BCC on device, and other setup. + +For setting up BCC on your Android device, you need the target device's kernel +source and the sources should be built atleast once in-tree. Once it is built, +run the following command pointing androdeb to the kernel sources which will +have it extract headers from there and push them to the device. +``` +androdeb prepare --download --bcc --kernelsrc /path/to/kernel-source/ +``` +This downloads and installs a pre-built androdeb filesystem containing a recent +version of BCC onto the android device, extracts kernel headers from the source +tree pointed to and does other setup. Note that `--download` option will work +only if the target architecture is ARM64. For other architectures, see the +[Other Architectures +section](https://github.com/joelagnel/androdeb/blob/master/BCC.md#other-architectures-other-than-arm64) + +Now to run BCC, just start an androdeb shell: `androdeb shell`. This uses adb +as the backend to start a shell into your androdeb environment. Try running +`opensnoop` or any of the other BCC tracers to confirm that the setup worked +correctly. + +If building your own kernel, following are the kernel requirements: + +You need kernel 4.9 or newer. Anything less needs backports. Your kernel needs +to be built with the following config options at the minimum: +``` +CONFIG_KPROBES=y +CONFIG_KPROBE_EVENT=y +CONFIG_BPF_SYSCALL=y +``` +Optionally, +``` +CONFIG_UPROBES=y +CONFIG_UPROBE_EVENT=y +``` +Additionally, for the criticalsection BCC tracer to work, you need: +``` +CONFIG_DEBUG_PREEMPT=y +CONFIG_PREEMPTIRQ_EVENTS=y +``` + +Build BCC during androdeb install (Optional) +-------------------------------------------- +If you would like the latest BCC installation on your Android device, we +recommend dropping the `--download` option from the androdeb command above. +This will make androdeb clone and build the latest version for of BCC for the +target architecture. Note that this is much slower that `--download`. +``` +androdeb prepare --bcc --kernelsrc /path/to/kernel-source/ +``` + +Other Architectures (other than ARM64) +----------------------- +By default androdeb assumes the target Android device is based on ARM64 +processor architecture. For other architectures, use the --arch option. For +example for x86_64 architecture, run: +``` +androdeb prepare --arch amd64 --bcc --kernelsrc /path/to/kernel-source/ +``` +Note: The --download option ignores the --arch flag. This is because we only +provide pre-built filesystems for ARM64 at the moment. + +Common Issues +------------- +* Issue 1: Headers are missing on the target device. + +Symptom: This will usually result in an error like the following: +``` +root@localhost:/# criticalstat + +In file included from :2 +In file included from /virtual/include/bcc/bpf.h:12: +In file included from include/linux/types.h:5: +include/uapi/linux/types.h:4:10: fatal error: 'asm/types.h' file not found + +#include + + ^~~~~~~~~~~~~ +1 error generated. +Traceback (most recent call last): + + File "./criticalstat.py", line 138, in + b = BPF(text=bpf_text) + File "/usr/lib/python2.7/dist-packages/bcc/__init__.py", line 297, in __init__ + raise Exception("Failed to compile BPF text:\n%s" % text) +Exception: Failed to compile BPF text: + +#include +#include +#include + +extern char _stext[]; +``` diff --git a/README.md b/README.md index d7d3e85..6c330e8 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,10 @@ ship git, and have support to run apt-get to get any missing development package from the web. 3. Using these one can run popular tools such as BCC that are difficult to run -in an Android environment due to lack of packages, dependencies and cross-compilation -needed for their operation. +in an Android environment due to lack of packages, dependencies and +cross-compilation needed for their operation. [Check BCC on Android using +androdeb](https://github.com/joelagnel/androdeb/blob/master/BCC.md) for more +information on that. 4. No more crippled tools: Its often a theme to build a static binary with features disabled, because you couldn't cross-compile the feature's dependencies. One @@ -30,7 +32,8 @@ Requirements for running Target: An ARM64 android N or later device which has "adb root" supported. Typically this is a build in a userdebug configuration. Device should have atleast 2 GB -free space in the data partition. +free space in the data partition. If you would like to use other architectures, +see the [Other Architectures](https://github.com/joelagnel/androdeb/blob/master/README.md#how-to-use-androdeb-for-other-architectures-other-than-arm64) section. Host: A machine running recent Ubuntu or Debian, with 4GB of memory and 4GB free space. @@ -131,3 +134,13 @@ androdeb prepare --buildimage /path/to/image.img ``` This can then be passed to Qemu as -hda. Note: This option doesn't need a device connected. + +### How to use androdeb for other Architectures (other than ARM64) +By default androdeb assumes the target Android device is based on ARM64 +processor architecture. For other architectures, use the --arch option. For +example for x86_64 architecture, run: +``` +androdeb prepare --arch amd64 --bcc --kernelsrc /path/to/kernel-source/ +``` +Note: The --download option ignores the --arch flag. This is because we only +provide pre-built filesystems for ARM64 at the moment. -- cgit v1.2.3 From 448a174f823fbdbfc58194f5a5ce446bf4b2f5ed Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Tue, 29 May 2018 12:23:18 -0700 Subject: androdeb: Remove 'buildtar' and prepare checks. - buildtar is not needed, since we have "prepare --buildtar" already - prepare can be specified without any options since all packages will be installed if prepare wasn't specified anything. So IOW, its perfectly legal to do: "androdeb prepare" Signed-off-by: Joel Fernandes (Google) --- androdeb | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/androdeb b/androdeb index eca1de0..12a4e64 100755 --- a/androdeb +++ b/androdeb @@ -28,11 +28,10 @@ config_full_build() { if [ $# -lt 1 ]; then usage; fi; POSITIONAL=() while [[ $# -gt 0 ]]; do key="$1"; case $key in - prepare) PREPARE=1; shift || true; ;; + prepare) PREPARE=1; shift || true; ;; shell) ASHELL=1; shift || true; ;; remove) REMOVE=1; shift || true; ;; pull) PULL=1; shift || true; ;; - buildtar) PREPARE=1; TARDIR="./"; config_full_build; shift || true; ;; --arch) ARCH=$2; shift || true; shift || true; ;; --archive) TARF=$2; shift || true; shift || true; ;; --tracers) source $spath/packages/tracers; shift || true; ;; @@ -62,15 +61,10 @@ if [ ! -z "$PULL" ]; then fi if [ -z "$PACKAGES" ]; then - echo "No packages specified, so I'm going to do a --fullbuild" + echo "No packages specified, so I'm going to build/install all packages (--fullbuild)" config_full_build fi -if [ ! -z "$PREPARE" ] && [ -z "$DOWNLOAD" ] && [ -z "$TARF" ] && - [ -z "$KERNELSRC" ] && [ -z "$KERNELHDRS" ] && - [ -z "$BUILD_IMAGE" ]; then - echo "Need to specifify something to prepare, or try: ./andrdeb prepare --download"; usage; fi - if [[ ! -z ${TARDIR+x} ]] && [[ ! -d $TARDIR ]]; then die 7 "Tar dir specified doesn't exist"; fi if [ -z "$BUILD_IMAGE" ]; then -- cgit v1.2.3 From 4b216fdd8f869492798e47c0d301ba25426940cf Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Tue, 29 May 2018 12:33:27 -0700 Subject: Allow packages to specify extra files to install Signed-off-by: Joel Fernandes (Google) --- androdeb | 6 ++++-- buildstrap | 10 ++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/androdeb b/androdeb index 12a4e64..c2b0dc3 100755 --- a/androdeb +++ b/androdeb @@ -2,7 +2,7 @@ # # (c) Joel Fernandes -VERSION=v0.98 +VERSION=v0.99 spath="$(dirname "$(readlink -f "$0")")" # spath=$( cd "$(dirname "$0")" ; pwd -P ) @@ -19,6 +19,7 @@ DEFAULT_PACKAGES+="\ bash ca-certificates " +EXTRA_FILES="none" config_full_build() { for f in $(ls $spath/packages); do source $spath/packages/$f; done; @@ -198,7 +199,8 @@ if [[ $EUID -ne 0 ]]; then echo "The next stage runs as sudo, please enter passw SKIP_COMPRESS=0; if [ ! -z "$BUILD_IMAGE" ]; then SKIP_COMPRESS=1; fi -sudo $spath/buildstrap $ARCH $DISTRO $TDIR $OUT_TMP "$(make_csv "$PACKAGES")" $INSTALL_BCC $SKIP_COMPRESS +sudo $spath/buildstrap $ARCH $DISTRO $TDIR $OUT_TMP "$(make_csv "$PACKAGES")" "$(make_csv "$EXTRA_FILES")"\ + $INSTALL_BCC $SKIP_COMPRESS # If we only wanted to prepare a rootfs and don't have # a device connected, then just echo that and skip cleanup diff --git a/buildstrap b/buildstrap index e6b7679..6f740e3 100755 --- a/buildstrap +++ b/buildstrap @@ -9,8 +9,9 @@ DISTRO=$2 TDIR=$3 OUT_TMP=$4 PACKAGES=$5 -INSTALL_BCC=$6 -SKIP_COMPRESS=$7 +EXTRA_FILES=$6 +INSTALL_BCC=$7 +SKIP_COMPRESS=$8 time qemu-debootstrap --arch $ARCH --include=$(make_csv "$PACKAGES") \ $DISTRO $OUT_TMP http://deb.debian.org/debian/ @@ -24,6 +25,11 @@ chroot $OUT_TMP rm /bin/sh || true chroot $OUT_TMP ln -s /bin/bash /bin/sh || true cp $spath/addons/bashrc $OUT_TMP/.bashrc +for f in $EXTRA_FILES; do + if [ $f == "none" ]; then continue; fi + cp $f $OUT_TMP/ +done + # Cleanup rm -rf $OUT_TMP/lib/udev/* rm -rf $OUT_TMP/var/lib/apt/lists/* -- cgit v1.2.3 From ab376b8ea9285454720d08eb6618aa1c3968cb17 Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Tue, 29 May 2018 12:34:03 -0700 Subject: bcc: Package criticalstat into the FS Signed-off-by: Joel Fernandes (Google) --- bcc/criticalstat.py | 297 ++++++++++++++++++++++++++++++++++++++++++++++++++++ packages/bcc | 4 + 2 files changed, 301 insertions(+) create mode 100755 bcc/criticalstat.py diff --git a/bcc/criticalstat.py b/bcc/criticalstat.py new file mode 100755 index 0000000..87afe28 --- /dev/null +++ b/bcc/criticalstat.py @@ -0,0 +1,297 @@ +#!/usr/bin/python +# +# By Joel Fernandes +# + +from __future__ import print_function +from bcc import BPF +import argparse +import ctypes as ct +import sys + +examples="" + +parser = argparse.ArgumentParser( + description="Trace long critical sections", + formatter_class=argparse.RawDescriptionHelpFormatter, + epilog=examples) + +parser.add_argument("-p", "--preemptoff", action="store_true", + help="Find long sections where preemption was off") + +parser.add_argument("-i", "--irqoff", action="store_true", + help="Find long sections where IRQ was off") + +parser.add_argument("-d", "--duration", default=100, + help="Duration in uS (microseconds) below which we filter") + +args = parser.parse_args() + +preemptoff = False +irqoff = False + +if args.irqoff: + preemptoff = False + irqoff = True +elif args.preemptoff: + preemptoff = True + irqoff = False + +bpf_text = """ +#include +#include +#include + +extern char _stext[]; + +enum addr_offs { + start_caller_off, + start_parent_off, + end_caller_off, + end_parent_off +}; + +struct start_data { + u32 addr_offs[2]; + u64 ts; + int idle_skip; + int active; +}; + +struct data_t { + u64 time; + u64 stack_id; + u32 cpu; + u64 id; + u32 addrs[4]; /* indexed by addr_offs */ + char comm[TASK_COMM_LEN]; +}; + +BPF_STACK_TRACE(stack_traces, 1024); +BPF_PERCPU_ARRAY(sts, struct start_data, 1); +BPF_PERCPU_ARRAY(isidle, u64, 1); +BPF_PERF_OUTPUT(events); + +TRACEPOINT_PROBE(power, cpu_idle) +{ + int idx = 0; + u64 val; + struct start_data *stdp, std; + + stdp = sts.lookup(&idx); + bpf_probe_read(&std, sizeof(struct start_data), stdp); + + // Mark active sections as that they should be skipped + + // Handle the case CSenter, Ienter, CSexit, Iexit + // Handle the case CSenter, Ienter, Iexit, CSexit + if (std.active) { + std.idle_skip = 1; + sts.update(&idx, &std); + } + + // Mark CPU as actively within idle or not. + if (args->state < 100) { + bpf_trace_printk(\"Setting idle\\n\"); + val = 1; + isidle.update(&idx, &val); + } else { + bpf_trace_printk(\"Resetting idle\\n\"); + val = 0; + isidle.update(&idx, &val); + } + return 0; +} + +static int in_idle(void) +{ + u64 *idlep, idle; + int idx = 0; + + // Skip event if we're in idle loop + idlep = isidle.lookup(&idx); + bpf_probe_read(&idle, sizeof(u64), idlep); + + // Skip if we're in idle loop + if (idle) + return 1; + else + return 0; +} + +static void reset_state(void) +{ + int idx = 0; + struct start_data s = {}; + + sts.update(&idx, &s); +} + +TRACEPOINT_PROBE(preemptirq, TYPE_disable) +{ + int idx = 0; + struct start_data s; + + // Handle the case Ienter, CSenter, CSexit, Iexit + // Handle the case Ienter, CSenter, Iexit, CSexit + if (in_idle()) { + bpf_trace_printk(\"disable: In idle, resetting\\n\"); + reset_state(); + return 0; + } + + u64 ts = bpf_ktime_get_ns(); + + bpf_trace_printk(\"Entered new section, setting time to %lu\\n\", (unsigned long)ts); + s.idle_skip = 0; + s.addr_offs[start_caller_off] = args->caller_offs; + s.addr_offs[start_parent_off] = args->parent_offs; + s.ts = ts; + s.active = 1; + bpf_trace_printk(\"Finished storing\\n\", (unsigned long)ts); + + sts.update(&idx, &s); + return 0; +} + +TRACEPOINT_PROBE(preemptirq, TYPE_enable) +{ + int idx = 0; + u64 start_ts, end_ts, diff; + struct start_data *stdp, std; + + // Handle the case CSenter, Ienter, CSexit, Iexit + // Handle the case Ienter, CSenter, CSexit, Iexit + if (in_idle()) { + bpf_trace_printk(\"enable: In idle, resetting\\n\"); + reset_state(); + return 0; + } + + bpf_trace_printk(\"enable: start lookup\\n\"); + + stdp = sts.lookup(&idx); + bpf_trace_printk(\"enable: start read\\n\"); + bpf_probe_read(&std, sizeof(struct start_data), stdp); + + // Handle the case Ienter, Csenter, Iexit, Csexit + if (!std.active) { + reset_state(); + return 0; + } + + // Handle the case CSenter, Ienter, Iexit, CSexit + if (std.idle_skip) { + reset_state(); + return 0; + } + + bpf_trace_printk(\"enable: start gettime\\n\"); + end_ts = bpf_ktime_get_ns(); + start_ts = std.ts; + + if (start_ts > end_ts) { + bpf_trace_printk("ERROR: start < end\\n"); + reset_state(); + return 0; + } + + diff = end_ts - start_ts; + bpf_trace_printk(\"Exited section, diff is %lu\\n\", (unsigned long)diff); + + if (diff < DURATION) { + reset_state(); + return 0; + } + + u64 id = bpf_get_current_pid_tgid(); + struct data_t data = {}; + + if (bpf_get_current_comm(&data.comm, sizeof(data.comm)) == 0) { + data.addrs[start_caller_off] = std.addr_offs[start_caller_off]; + data.addrs[start_parent_off] = std.addr_offs[start_parent_off]; + data.addrs[end_caller_off] = args->caller_offs; + data.addrs[end_parent_off] = args->parent_offs; + + data.id = id; + data.stack_id = stack_traces.get_stackid(args, BPF_F_REUSE_STACKID); + data.time = diff; + data.cpu = bpf_get_smp_processor_id(); + bpf_trace_printk(\"Large diff found: %lu\\n\", (unsigned long)diff); + events.perf_submit(args, &data, sizeof(data)); + } else { + bpf_trace_printk("ERROR: Couldn't get process name\\n"); + } + + reset_state(); + return 0; +} +""" +bpf_text = bpf_text.replace('DURATION', '{}'.format(int(args.duration) * 1000)) + +if preemptoff: + bpf_text = bpf_text.replace('TYPE', 'preempt') +else: + bpf_text = bpf_text.replace('TYPE', 'irq') + +b = BPF(text=bpf_text) + +TASK_COMM_LEN = 16 # linux/sched.h + +class Data(ct.Structure): + _fields_ = [ + ("time", ct.c_ulonglong), + ("stack_id", ct.c_ulonglong), + ("cpu", ct.c_int), + ("id", ct.c_ulonglong), + ("addrs", ct.c_int * 4), + ("comm", ct.c_char * TASK_COMM_LEN), + ] + +def get_syms(kstack): + syms = [] + + for addr in kstack: + s = b.ksym(addr, show_offset=True) + syms.append(s) + + return syms + +# process event +def print_event(cpu, data, size): + try: + global b + event = ct.cast(data, ct.POINTER(Data)).contents + stack_traces = b['stack_traces'] + stext = b.ksymname('_stext') + + if event.stack_id < 0: + print("Empty kernel stack received\n") + return + + kstack = stack_traces.walk(event.stack_id) + + syms = get_syms(kstack) + if not syms: + return + + print("===================================") + print("TASK: %s (pid %5d tid %5d) Total Time: %-9.3fus\n\n" % (event.comm.decode(), \ + (event.id >> 32), (event.id & 0xffffffff), float(event.time) / 1000), end="") + print("Section start: {} -> {}".format(b.ksym(stext + event.addrs[0]), b.ksym(stext + event.addrs[1]))) + print("Section end: {} -> {}".format(b.ksym(stext + event.addrs[2]), b.ksym(stext + event.addrs[3]))) + for s in syms: + print(" ", end="") + print("%s" % s) + print("===================================") + print("") + except: + sys.exit(0) + +b["events"].open_perf_buffer(print_event, page_cnt=256) + +print("Finding critical section with {} disabled for > {}us".format(('preempt' if preemptoff else 'IRQ'), args.duration)) + +while 1: + b.perf_buffer_poll(); + diff --git a/packages/bcc b/packages/bcc index d0a9c7c..20a8ef3 100644 --- a/packages/bcc +++ b/packages/bcc @@ -22,4 +22,8 @@ python-netaddr python-pyroute2 " +EXTRA_FILES+="\ +bcc/criticalstat.py +" + INSTALL_BCC=1 -- cgit v1.2.3 From 9922a0cff3db5b9cccf80dd30bf5cd5ef1d6d214 Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Tue, 29 May 2018 15:20:20 -0700 Subject: Dont show No packages message for shell mode Signed-off-by: Joel Fernandes (Google) --- androdeb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/androdeb b/androdeb index c2b0dc3..1750b82 100755 --- a/androdeb +++ b/androdeb @@ -61,7 +61,7 @@ if [ ! -z "$PULL" ]; then exit 0 fi -if [ -z "$PACKAGES" ]; then +if [ -z "$ASHELL" ] && [ -z "$PACKAGES" ]; then echo "No packages specified, so I'm going to build/install all packages (--fullbuild)" config_full_build fi -- cgit v1.2.3 From 4f7110820bd09a502e8f88e4ff967493d26939d1 Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Tue, 29 May 2018 16:23:15 -0700 Subject: Fix passing of packages and files to buildstrap Signed-off-by: Joel Fernandes (Google) --- androdeb | 12 ++++++------ buildstrap | 4 ++-- packages/bcc | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/androdeb b/androdeb index 1750b82..d5c3552 100755 --- a/androdeb +++ b/androdeb @@ -15,10 +15,9 @@ DISTRO=buster; ARCH=arm64 ADB="adb" # Default packages -DEFAULT_PACKAGES+="\ -bash -ca-certificates -" +DEFAULT_PACKAGES+="bash +ca-certificates" + EXTRA_FILES="none" config_full_build() { @@ -199,8 +198,9 @@ if [[ $EUID -ne 0 ]]; then echo "The next stage runs as sudo, please enter passw SKIP_COMPRESS=0; if [ ! -z "$BUILD_IMAGE" ]; then SKIP_COMPRESS=1; fi -sudo $spath/buildstrap $ARCH $DISTRO $TDIR $OUT_TMP "$(make_csv "$PACKAGES")" "$(make_csv "$EXTRA_FILES")"\ - $INSTALL_BCC $SKIP_COMPRESS +sudo $spath/buildstrap $ARCH $DISTRO $TDIR $OUT_TMP \ + "$(make_csv "$PACKAGES")"\ + "$(echo "$EXTRA_FILES" | base64)" $INSTALL_BCC $SKIP_COMPRESS # If we only wanted to prepare a rootfs and don't have # a device connected, then just echo that and skip cleanup diff --git a/buildstrap b/buildstrap index 6f740e3..da09f01 100755 --- a/buildstrap +++ b/buildstrap @@ -9,11 +9,11 @@ DISTRO=$2 TDIR=$3 OUT_TMP=$4 PACKAGES=$5 -EXTRA_FILES=$6 +EXTRA_FILES=$(echo $6 | base64 -d) INSTALL_BCC=$7 SKIP_COMPRESS=$8 -time qemu-debootstrap --arch $ARCH --include=$(make_csv "$PACKAGES") \ +time qemu-debootstrap --arch $ARCH --include=$PACKAGES \ $DISTRO $OUT_TMP http://deb.debian.org/debian/ # Some reason debootstrap leaves these mounted diff --git a/packages/bcc b/packages/bcc index 20a8ef3..5640f74 100644 --- a/packages/bcc +++ b/packages/bcc @@ -1,4 +1,4 @@ -PACKAGES+="\ +PACKAGES+=" llvm-6.0-dev libclang-6.0-dev libelf-dev @@ -22,7 +22,7 @@ python-netaddr python-pyroute2 " -EXTRA_FILES+="\ +EXTRA_FILES+=" bcc/criticalstat.py " -- cgit v1.2.3 From 57b3fd2acfbf32a5b641fa7b0c0be93cc58beb6e Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Tue, 29 May 2018 16:27:03 -0700 Subject: Handle passing of extra file list to buildstrap Previously we use base64, but it doesn't really work. For now just do a silly temp file write and delete. Signed-off-by: Joel Fernandes (Google) --- androdeb | 5 ++++- buildstrap | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/androdeb b/androdeb index d5c3552..d2190d9 100755 --- a/androdeb +++ b/androdeb @@ -198,9 +198,12 @@ if [[ $EUID -ne 0 ]]; then echo "The next stage runs as sudo, please enter passw SKIP_COMPRESS=0; if [ ! -z "$BUILD_IMAGE" ]; then SKIP_COMPRESS=1; fi +ex_files=$(mktemp); echo $EXTRA_FILES > $ex_files + sudo $spath/buildstrap $ARCH $DISTRO $TDIR $OUT_TMP \ "$(make_csv "$PACKAGES")"\ - "$(echo "$EXTRA_FILES" | base64)" $INSTALL_BCC $SKIP_COMPRESS + $ex_files $INSTALL_BCC $SKIP_COMPRESS +rm $ex_files # If we only wanted to prepare a rootfs and don't have # a device connected, then just echo that and skip cleanup diff --git a/buildstrap b/buildstrap index da09f01..5fed520 100755 --- a/buildstrap +++ b/buildstrap @@ -9,7 +9,7 @@ DISTRO=$2 TDIR=$3 OUT_TMP=$4 PACKAGES=$5 -EXTRA_FILES=$(echo $6 | base64 -d) +EXTRA_FILES="$(cat $6)" INSTALL_BCC=$7 SKIP_COMPRESS=$8 -- cgit v1.2.3 From 342be3101f1d68be7207831e178b25790a3247d1 Mon Sep 17 00:00:00 2001 From: ErickReyesR Date: Tue, 29 May 2018 17:19:01 -0700 Subject: criticalstat.py: check for required trace events --- bcc/criticalstat.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/bcc/criticalstat.py b/bcc/criticalstat.py index 87afe28..5052fdb 100755 --- a/bcc/criticalstat.py +++ b/bcc/criticalstat.py @@ -8,6 +8,8 @@ from bcc import BPF import argparse import ctypes as ct import sys +import subprocess +import os.path examples="" @@ -36,6 +38,23 @@ if args.irqoff: elif args.preemptoff: preemptoff = True irqoff = False + +debugfs_path = subprocess.Popen("cat /proc/mounts | grep -w debugfs | awk '{print $2}'", + shell=True, stdout=subprocess.PIPE).stdout.read().split("\n")[0] + +if debugfs_path == "": + print("ERROR: Unable to find debugfs mount point"); + sys.exit(0); + +trace_path = debugfs_path + "/tracing/events/preemptirq/"; + +if (not os.path.exists(trace_path + "irq_disable") or + not os.path.exists(trace_path + "irq_enable") or + not os.path.exists(trace_path + "preempt_disable") or + not os.path.exists(trace_path + "preempt_enable")): + print("ERROR: required tracing events are not available\n" + + "Make sure the kernel is built with CONFIG_DEBUG_PREEMPT and CONFIG_PREEMPTIRQ_EVENTS enabled") + sys.exit(0) bpf_text = """ #include -- cgit v1.2.3 From 39e7f3953edd30d1397efc2f6b848445c7c38ea3 Mon Sep 17 00:00:00 2001 From: ErickReyesR Date: Tue, 29 May 2018 19:29:31 -0700 Subject: criticalstat.py: trim long lines --- bcc/criticalstat.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bcc/criticalstat.py b/bcc/criticalstat.py index 5052fdb..7bc65b1 100755 --- a/bcc/criticalstat.py +++ b/bcc/criticalstat.py @@ -39,8 +39,10 @@ elif args.preemptoff: preemptoff = True irqoff = False -debugfs_path = subprocess.Popen("cat /proc/mounts | grep -w debugfs | awk '{print $2}'", - shell=True, stdout=subprocess.PIPE).stdout.read().split("\n")[0] +debugfs_path = subprocess.Popen ("cat /proc/mounts | grep -w debugfs" + + " | awk '{print $2}'", + shell=True, + stdout=subprocess.PIPE).stdout.read().split("\n")[0] if debugfs_path == "": print("ERROR: Unable to find debugfs mount point"); @@ -53,7 +55,8 @@ if (not os.path.exists(trace_path + "irq_disable") or not os.path.exists(trace_path + "preempt_disable") or not os.path.exists(trace_path + "preempt_enable")): print("ERROR: required tracing events are not available\n" + - "Make sure the kernel is built with CONFIG_DEBUG_PREEMPT and CONFIG_PREEMPTIRQ_EVENTS enabled") + "Make sure the kernel is built with CONFIG_DEBUG_PREEMPT " + + "and CONFIG_PREEMPTIRQ_EVENTS enabled") sys.exit(0) bpf_text = """ -- cgit v1.2.3 From ed92a99face26fbaf4460f4a96c5a31befce2abc Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Tue, 29 May 2018 20:08:51 -0700 Subject: Update docs Signed-off-by: Joel Fernandes (Google) --- BCC.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/BCC.md b/BCC.md index f6f78a7..6adc058 100644 --- a/BCC.md +++ b/BCC.md @@ -6,15 +6,18 @@ Introduction BCC is a compiler and a toolkit, containing powerful kernel tracing tools that trace at the lowest levels, including adding hooks to functions in kernel space and user space to deeply understand system behavior while being low in -overhead. [Here's a presentation with -Overview](http://www.joelfernandes.org/resources/bcc-ospm.pdf) and visit [BCC -project page](https://github.com/iovisor/bcc) for official BCC documentation. +overhead. [Here's a presentation with an +overview](http://www.joelfernandes.org/resources/bcc-ospm.pdf) and visit [BCC's +project page](https://github.com/iovisor/bcc) for the official BCC +documentation. Quick Start ----------- androdeb is the primary vehicle for running BCC on Android. It supports preparing the target Android device with necessary kernel headers, cloning and -building BCC on device, and other setup. +building BCC on device, and other setup. Take a look a quick look at [androdeb +README](https://github.com/joelagnel/androdeb/blob/master/README.md) so that +you're familiar with what it is. For setting up BCC on your Android device, you need the target device's kernel source and the sources should be built atleast once in-tree. Once it is built, -- cgit v1.2.3 From 586fd636339f5a647307cb478fd990e8952ad6bf Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Tue, 29 May 2018 20:20:00 -0700 Subject: Update BCC docs with more common issues examples Signed-off-by: Joel Fernandes (Google) --- BCC.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/BCC.md b/BCC.md index 6adc058..7428b74 100644 --- a/BCC.md +++ b/BCC.md @@ -81,6 +81,8 @@ provide pre-built filesystems for ARM64 at the moment. Common Issues ------------- +Here are some common issues you may face when running different BCC tools. + * Issue 1: Headers are missing on the target device. Symptom: This will usually result in an error like the following: @@ -110,3 +112,43 @@ Exception: Failed to compile BPF text: extern char _stext[]; ``` + +* Issue 2: `CONFIG_KPROBES` isn't enabled. + +Symptom: This will result in an error like the following: +``` +Traceback (most recent call last): + File "/usr/share/bcc/tools/cachetop", line 263, in + curses.wrapper(handle_loop, args) + File "/usr/lib/python2.7/curses/wrapper.py", line 43, in wrapper + return func(stdscr, *args, **kwds) + File "/usr/share/bcc/tools/cachetop", line 172, in handle_loop + b.attach_kprobe(event="add_to_page_cache_lru", fn_name="do_count") + File "/usr/lib/python2.7/dist-packages/bcc/__init__.py", line 543, in +attach_kprobe + fn = self.load_func(fn_name, BPF.KPROBE) + File "/usr/lib/python2.7/dist-packages/bcc/__init__.py", line 355, in +load_func + (func_name, errstr)) +Exception: Failed to load BPF program do_count: Invalid argument +``` + +* Issue 3: `CONFIG_BPF_SYSCALL` isn't enabled. + +Symptom: This will result in an error like the following: +``` +Traceback (most recent call last): + File "/usr/share/bcc/tools/cachetop", line 263, in + curses.wrapper(handle_loop, args) + File "/usr/lib/python2.7/curses/wrapper.py", line 43, in wrapper + return func(stdscr, *args, **kwds) + File "/usr/share/bcc/tools/cachetop", line 172, in handle_loop + b.attach_kprobe(event="add_to_page_cache_lru", fn_name="do_count") + File "/usr/lib/python2.7/dist-packages/bcc/__init__.py", line 543, in +attach_kprobe + fn = self.load_func(fn_name, BPF.KPROBE) + File "/usr/lib/python2.7/dist-packages/bcc/__init__.py", line 355, in +load_func + (func_name, errstr)) +Exception: Failed to load BPF program do_count: Invalid argument +``` -- cgit v1.2.3 From 9013703436d2c837182db7e3124a2d41d12752b4 Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Tue, 29 May 2018 20:22:32 -0700 Subject: Update BCC docs common issues example 3 Signed-off-by: Joel Fernandes (Google) --- BCC.md | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/BCC.md b/BCC.md index 7428b74..fc8080c 100644 --- a/BCC.md +++ b/BCC.md @@ -135,20 +135,44 @@ Exception: Failed to load BPF program do_count: Invalid argument * Issue 3: `CONFIG_BPF_SYSCALL` isn't enabled. -Symptom: This will result in an error like the following: +Symptom: This may result in a compilation error like the following: ``` +root@localhost:/# cachetop Traceback (most recent call last): File "/usr/share/bcc/tools/cachetop", line 263, in curses.wrapper(handle_loop, args) File "/usr/lib/python2.7/curses/wrapper.py", line 43, in wrapper return func(stdscr, *args, **kwds) - File "/usr/share/bcc/tools/cachetop", line 172, in handle_loop - b.attach_kprobe(event="add_to_page_cache_lru", fn_name="do_count") - File "/usr/lib/python2.7/dist-packages/bcc/__init__.py", line 543, in -attach_kprobe - fn = self.load_func(fn_name, BPF.KPROBE) - File "/usr/lib/python2.7/dist-packages/bcc/__init__.py", line 355, in -load_func - (func_name, errstr)) -Exception: Failed to load BPF program do_count: Invalid argument + File "/usr/share/bcc/tools/cachetop", line 171, in handle_loop + b = BPF(text=bpf_text) + File "/usr/lib/python2.7/dist-packages/bcc/__init__.py", line 297, in __init__ + raise Exception("Failed to compile BPF text:\n%s" % text) +Exception: Failed to compile BPF text: + + + #include + struct key_t { + u64 ip; + u32 pid; + u32 uid; + char comm[16]; + }; + + BPF_HASH(counts, struct key_t); + + int do_count(struct pt_regs *ctx) { + struct key_t key = {}; + u64 zero = 0 , *val; + u64 pid = bpf_get_current_pid_tgid(); + u32 uid = bpf_get_current_uid_gid(); + + key.ip = PT_REGS_IP(ctx); + key.pid = pid & 0xFFFFFFFF; + key.uid = uid & 0xFFFFFFFF; + bpf_get_current_comm(&(key.comm), 16); + + val = counts.lookup_or_init(&key, &zero); // update counter + (*val)++; + return 0; + } ``` -- cgit v1.2.3 From 172270466084fe396814cd263d4699eb8fdf21fc Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Wed, 30 May 2018 17:14:22 -0700 Subject: Fix spacing in usage() Signed-off-by: Joel Fernandes (Google) --- utils/banners | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/banners b/utils/banners index 342e48a..ff82d1b 100755 --- a/utils/banners +++ b/utils/banners @@ -21,7 +21,7 @@ usage() { echo "" echo " --download Download full FS archive from web (overrides all tools specified)" echo " --archive Use archive for root fs (overrides all other prepare options)" - echo " --build-image Build an ext4 .img with the base image and BCC (useful for Qemu)" + echo " --build-image Build an ext4 .img with the base image and BCC (useful for Qemu)" echo "" echo " --bcc Build and install BCC from source" echo " --kernelsrc Extract kernel headers for BCC from here" -- cgit v1.2.3 From 1171d2dc928f5e888b19453a72c5bc980460ac95 Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Wed, 30 May 2018 17:22:09 -0700 Subject: Skip full install if only kernel header install needed Signed-off-by: Joel Fernandes (Google) --- README.md | 2 +- androdeb | 7 +++++-- utils/banners | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6c330e8..d84cbc4 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ androdeb prepare --download --kernelsrc /path/to/kernel-source If you need to put kernel sources for an existing install, run: ``` -androdeb prepare --kernelsrc /path/to/kernel-source +androdeb prepare --kernelsrc /path/to/kernel-source --skip-install ``` Note: The kernel sources should have been built (atleast build should have started). diff --git a/androdeb b/androdeb index d2190d9..2692561 100755 --- a/androdeb +++ b/androdeb @@ -42,6 +42,7 @@ case $key in --download) DOWNLOAD=1; shift || true; ;; --bcc) source $spath/packages/bcc; shift || true; ;; --kernelsrc) KERNELSRC="$2"; shift || true; shift || true; ;; + --skip-install) SKIP_INSTALL=1; shift || true; ;; --kernel-headers-targz) KERNELHDRS=$2; shift || true; shift || true; ;; --tempdir) TDIR="$2"; shift || true; shift || true; ;; --buildtar) TARDIR="$2"; shift || true; shift || true; ;; @@ -158,7 +159,8 @@ if [ ! -z "$KERNELHDRS" ]; then echo "Building updating kernel headers from supplied tar.gz ($KERNELHDRS)" # Is header tar gz update the only thing left to do? - if [[ -z "$PACKAGES" ]] && [[ -z "$TARF" ]] && [[ -z "$BUILD_IMAGE" ]] && [[ -z "$KERNELSRC" ]] ; then + if [[ ! -z "$SKIP_INSTALL" ]]; then + echo "Skipping install" push_unpack_tarred_headers $KERNELHDRS; do_cleanup; all_done_banner; exit 0; fi tar -xvf $KERNELHDRS -C $OUT_TMP/ > /dev/null @@ -170,7 +172,8 @@ if [ ! -z "$KERNELSRC" ]; then $spath/bcc/build-kheaders-targz.sh ${KERNELSRC} $TDIR_ABS/kh.tgz > /dev/null # Is header update the only thing left to do? - if [[ -z "$PACKAGES" ]] && [[ -z "$BUILD_IMAGE" ]] && [[ -z "$TARF" ]]; then + if [[ ! -z "$SKIP_INSTALL" ]]; then + echo "Skipping install" push_unpack_headers; do_cleanup; all_done_banner; exit 0; fi mkdir $OUT_TMP/kernel-headers diff --git a/utils/banners b/utils/banners index ff82d1b..69e6dec 100755 --- a/utils/banners +++ b/utils/banners @@ -25,7 +25,7 @@ usage() { echo "" echo " --bcc Build and install BCC from source" echo " --kernelsrc Extract kernel headers for BCC from here" - echo " (use if BCC couldn't find headers on device)" + echo " --skip-install Pass this along if only header install is needed" echo "" echo " --tempdir Use a specific temporary directory for build operation" echo " --buildtar Local directory to store tarball of androdeb env from device" -- cgit v1.2.3 From 361e24af74b35d490c35ba67987276b5bf602e55 Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Mon, 4 Jun 2018 13:42:16 -0700 Subject: Update criticalstat with comments from iovisor/bcc/pull/1794/ Signed-off-by: Joel Fernandes (Google) --- bcc/criticalstat.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/bcc/criticalstat.py b/bcc/criticalstat.py index 7bc65b1..6337bdf 100755 --- a/bcc/criticalstat.py +++ b/bcc/criticalstat.py @@ -61,16 +61,13 @@ if (not os.path.exists(trace_path + "irq_disable") or bpf_text = """ #include -#include #include -extern char _stext[]; - enum addr_offs { - start_caller_off, - start_parent_off, - end_caller_off, - end_parent_off + START_CALLER_OFF, + START_PARENT_OFF, + END_CALLER_OFF, + END_PARENT_OFF }; struct start_data { @@ -166,8 +163,8 @@ TRACEPOINT_PROBE(preemptirq, TYPE_disable) bpf_trace_printk(\"Entered new section, setting time to %lu\\n\", (unsigned long)ts); s.idle_skip = 0; - s.addr_offs[start_caller_off] = args->caller_offs; - s.addr_offs[start_parent_off] = args->parent_offs; + s.addr_offs[START_CALLER_OFF] = args->caller_offs; + s.addr_offs[START_PARENT_OFF] = args->parent_offs; s.ts = ts; s.active = 1; bpf_trace_printk(\"Finished storing\\n\", (unsigned long)ts); @@ -230,10 +227,10 @@ TRACEPOINT_PROBE(preemptirq, TYPE_enable) struct data_t data = {}; if (bpf_get_current_comm(&data.comm, sizeof(data.comm)) == 0) { - data.addrs[start_caller_off] = std.addr_offs[start_caller_off]; - data.addrs[start_parent_off] = std.addr_offs[start_parent_off]; - data.addrs[end_caller_off] = args->caller_offs; - data.addrs[end_parent_off] = args->parent_offs; + data.addrs[START_CALLER_OFF] = std.addr_offs[START_CALLER_OFF]; + data.addrs[START_PARENT_OFF] = std.addr_offs[START_PARENT_OFF]; + data.addrs[END_CALLER_OFF] = args->caller_offs; + data.addrs[END_PARENT_OFF] = args->parent_offs; data.id = id; data.stack_id = stack_traces.get_stackid(args, BPF_F_REUSE_STACKID); -- cgit v1.2.3 From 273334bbccae4ced13b6d01c51cc2be55788f39b Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Mon, 4 Jun 2018 15:17:31 -0700 Subject: criticalstat: Updated Signed-off-by: Joel Fernandes (Google) --- bcc/criticalstat.py | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/bcc/criticalstat.py b/bcc/criticalstat.py index 6337bdf..261bd3e 100755 --- a/bcc/criticalstat.py +++ b/bcc/criticalstat.py @@ -1,7 +1,7 @@ #!/usr/bin/python # # By Joel Fernandes -# +# (c) Google LLC. from __future__ import print_function from bcc import BPF @@ -86,7 +86,7 @@ struct data_t { char comm[TASK_COMM_LEN]; }; -BPF_STACK_TRACE(stack_traces, 1024); +BPF_STACK_TRACE(stack_traces, 16384); BPF_PERCPU_ARRAY(sts, struct start_data, 1); BPF_PERCPU_ARRAY(isidle, u64, 1); BPF_PERF_OUTPUT(events); @@ -124,18 +124,14 @@ TRACEPOINT_PROBE(power, cpu_idle) static int in_idle(void) { - u64 *idlep, idle; + u64 *idlep; int idx = 0; // Skip event if we're in idle loop idlep = isidle.lookup(&idx); - bpf_probe_read(&idle, sizeof(u64), idlep); - - // Skip if we're in idle loop - if (idle) + if (idlep && *idlep) return 1; - else - return 0; + return 0; } static void reset_state(void) @@ -233,7 +229,7 @@ TRACEPOINT_PROBE(preemptirq, TYPE_enable) data.addrs[END_PARENT_OFF] = args->parent_offs; data.id = id; - data.stack_id = stack_traces.get_stackid(args, BPF_F_REUSE_STACKID); + data.stack_id = stack_traces.get_stackid(args, 0); data.time = diff; data.cpu = bpf_get_smp_processor_id(); bpf_trace_printk(\"Large diff found: %lu\\n\", (unsigned long)diff); @@ -288,20 +284,23 @@ def print_event(cpu, data, size): print("Empty kernel stack received\n") return - kstack = stack_traces.walk(event.stack_id) - - syms = get_syms(kstack) - if not syms: - return - print("===================================") print("TASK: %s (pid %5d tid %5d) Total Time: %-9.3fus\n\n" % (event.comm.decode(), \ (event.id >> 32), (event.id & 0xffffffff), float(event.time) / 1000), end="") print("Section start: {} -> {}".format(b.ksym(stext + event.addrs[0]), b.ksym(stext + event.addrs[1]))) print("Section end: {} -> {}".format(b.ksym(stext + event.addrs[2]), b.ksym(stext + event.addrs[3]))) - for s in syms: - print(" ", end="") - print("%s" % s) + + if event.stack_id < 16384: + kstack = stack_traces.walk(event.stack_id) + syms = get_syms(kstack) + if not syms: + return + + for s in syms: + print(" ", end="") + print("%s" % s) + else: + print("NO STACK FOUND DUE TO COLLISION") print("===================================") print("") except: @@ -313,4 +312,3 @@ print("Finding critical section with {} disabled for > {}us".format(('preempt' i while 1: b.perf_buffer_poll(); - -- cgit v1.2.3 From a30d2f9e4156db22c8499826edf2ba6e41925214 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Wed, 6 Jun 2018 17:45:19 -0700 Subject: bcc: Update criticalstat Signed-off-by: Joel Fernandes --- bcc/criticalstat.py | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/bcc/criticalstat.py b/bcc/criticalstat.py index 261bd3e..9a91a0e 100755 --- a/bcc/criticalstat.py +++ b/bcc/criticalstat.py @@ -91,6 +91,23 @@ BPF_PERCPU_ARRAY(sts, struct start_data, 1); BPF_PERCPU_ARRAY(isidle, u64, 1); BPF_PERF_OUTPUT(events); +/* + * In the below code we install tracepoint probes on preempt or + * IRQ disable/enable critical sections and idle events, the cases + * are combinations of 4 different states. + * The states are defined as: + * CSenter: A critical section has been entered. Either due to + * preempt disable or irq disable. + * CSexit: A critical section has been exited. Either due to + * preempt enable or irq enable. + * Ienter: The CPU has entered an idle state. + * Iexit: The CPU has exited an idle state. + * + * The scenario we are trying to detect is if there is an overlap + * between Critical sections and idle entry/exit. If there are any + * such cases, we avoid recording those critical sections since they + * are not worth while to record and just add noise. + */ TRACEPOINT_PROBE(power, cpu_idle) { int idx = 0; @@ -111,11 +128,9 @@ TRACEPOINT_PROBE(power, cpu_idle) // Mark CPU as actively within idle or not. if (args->state < 100) { - bpf_trace_printk(\"Setting idle\\n\"); val = 1; isidle.update(&idx, &val); } else { - bpf_trace_printk(\"Resetting idle\\n\"); val = 0; isidle.update(&idx, &val); } @@ -150,20 +165,17 @@ TRACEPOINT_PROBE(preemptirq, TYPE_disable) // Handle the case Ienter, CSenter, CSexit, Iexit // Handle the case Ienter, CSenter, Iexit, CSexit if (in_idle()) { - bpf_trace_printk(\"disable: In idle, resetting\\n\"); reset_state(); return 0; } u64 ts = bpf_ktime_get_ns(); - bpf_trace_printk(\"Entered new section, setting time to %lu\\n\", (unsigned long)ts); s.idle_skip = 0; s.addr_offs[START_CALLER_OFF] = args->caller_offs; s.addr_offs[START_PARENT_OFF] = args->parent_offs; s.ts = ts; s.active = 1; - bpf_trace_printk(\"Finished storing\\n\", (unsigned long)ts); sts.update(&idx, &s); return 0; @@ -178,15 +190,12 @@ TRACEPOINT_PROBE(preemptirq, TYPE_enable) // Handle the case CSenter, Ienter, CSexit, Iexit // Handle the case Ienter, CSenter, CSexit, Iexit if (in_idle()) { - bpf_trace_printk(\"enable: In idle, resetting\\n\"); reset_state(); return 0; } - bpf_trace_printk(\"enable: start lookup\\n\"); stdp = sts.lookup(&idx); - bpf_trace_printk(\"enable: start read\\n\"); bpf_probe_read(&std, sizeof(struct start_data), stdp); // Handle the case Ienter, Csenter, Iexit, Csexit @@ -201,18 +210,15 @@ TRACEPOINT_PROBE(preemptirq, TYPE_enable) return 0; } - bpf_trace_printk(\"enable: start gettime\\n\"); end_ts = bpf_ktime_get_ns(); start_ts = std.ts; if (start_ts > end_ts) { - bpf_trace_printk("ERROR: start < end\\n"); reset_state(); return 0; } diff = end_ts - start_ts; - bpf_trace_printk(\"Exited section, diff is %lu\\n\", (unsigned long)diff); if (diff < DURATION) { reset_state(); @@ -232,10 +238,7 @@ TRACEPOINT_PROBE(preemptirq, TYPE_enable) data.stack_id = stack_traces.get_stackid(args, 0); data.time = diff; data.cpu = bpf_get_smp_processor_id(); - bpf_trace_printk(\"Large diff found: %lu\\n\", (unsigned long)diff); events.perf_submit(args, &data, sizeof(data)); - } else { - bpf_trace_printk("ERROR: Couldn't get process name\\n"); } reset_state(); -- cgit v1.2.3 From 5dfc6a736d21ea75fdbe8a42be562506601455b1 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Tue, 19 Jun 2018 19:44:03 -0700 Subject: Remove criticalstat, its merged into bcc now Signed-off-by: Joel Fernandes --- bcc/criticalstat.py | 317 ---------------------------------------------------- packages/bcc | 4 - 2 files changed, 321 deletions(-) delete mode 100755 bcc/criticalstat.py diff --git a/bcc/criticalstat.py b/bcc/criticalstat.py deleted file mode 100755 index 9a91a0e..0000000 --- a/bcc/criticalstat.py +++ /dev/null @@ -1,317 +0,0 @@ -#!/usr/bin/python -# -# By Joel Fernandes -# (c) Google LLC. - -from __future__ import print_function -from bcc import BPF -import argparse -import ctypes as ct -import sys -import subprocess -import os.path - -examples="" - -parser = argparse.ArgumentParser( - description="Trace long critical sections", - formatter_class=argparse.RawDescriptionHelpFormatter, - epilog=examples) - -parser.add_argument("-p", "--preemptoff", action="store_true", - help="Find long sections where preemption was off") - -parser.add_argument("-i", "--irqoff", action="store_true", - help="Find long sections where IRQ was off") - -parser.add_argument("-d", "--duration", default=100, - help="Duration in uS (microseconds) below which we filter") - -args = parser.parse_args() - -preemptoff = False -irqoff = False - -if args.irqoff: - preemptoff = False - irqoff = True -elif args.preemptoff: - preemptoff = True - irqoff = False - -debugfs_path = subprocess.Popen ("cat /proc/mounts | grep -w debugfs" + - " | awk '{print $2}'", - shell=True, - stdout=subprocess.PIPE).stdout.read().split("\n")[0] - -if debugfs_path == "": - print("ERROR: Unable to find debugfs mount point"); - sys.exit(0); - -trace_path = debugfs_path + "/tracing/events/preemptirq/"; - -if (not os.path.exists(trace_path + "irq_disable") or - not os.path.exists(trace_path + "irq_enable") or - not os.path.exists(trace_path + "preempt_disable") or - not os.path.exists(trace_path + "preempt_enable")): - print("ERROR: required tracing events are not available\n" + - "Make sure the kernel is built with CONFIG_DEBUG_PREEMPT " + - "and CONFIG_PREEMPTIRQ_EVENTS enabled") - sys.exit(0) - -bpf_text = """ -#include -#include - -enum addr_offs { - START_CALLER_OFF, - START_PARENT_OFF, - END_CALLER_OFF, - END_PARENT_OFF -}; - -struct start_data { - u32 addr_offs[2]; - u64 ts; - int idle_skip; - int active; -}; - -struct data_t { - u64 time; - u64 stack_id; - u32 cpu; - u64 id; - u32 addrs[4]; /* indexed by addr_offs */ - char comm[TASK_COMM_LEN]; -}; - -BPF_STACK_TRACE(stack_traces, 16384); -BPF_PERCPU_ARRAY(sts, struct start_data, 1); -BPF_PERCPU_ARRAY(isidle, u64, 1); -BPF_PERF_OUTPUT(events); - -/* - * In the below code we install tracepoint probes on preempt or - * IRQ disable/enable critical sections and idle events, the cases - * are combinations of 4 different states. - * The states are defined as: - * CSenter: A critical section has been entered. Either due to - * preempt disable or irq disable. - * CSexit: A critical section has been exited. Either due to - * preempt enable or irq enable. - * Ienter: The CPU has entered an idle state. - * Iexit: The CPU has exited an idle state. - * - * The scenario we are trying to detect is if there is an overlap - * between Critical sections and idle entry/exit. If there are any - * such cases, we avoid recording those critical sections since they - * are not worth while to record and just add noise. - */ -TRACEPOINT_PROBE(power, cpu_idle) -{ - int idx = 0; - u64 val; - struct start_data *stdp, std; - - stdp = sts.lookup(&idx); - bpf_probe_read(&std, sizeof(struct start_data), stdp); - - // Mark active sections as that they should be skipped - - // Handle the case CSenter, Ienter, CSexit, Iexit - // Handle the case CSenter, Ienter, Iexit, CSexit - if (std.active) { - std.idle_skip = 1; - sts.update(&idx, &std); - } - - // Mark CPU as actively within idle or not. - if (args->state < 100) { - val = 1; - isidle.update(&idx, &val); - } else { - val = 0; - isidle.update(&idx, &val); - } - return 0; -} - -static int in_idle(void) -{ - u64 *idlep; - int idx = 0; - - // Skip event if we're in idle loop - idlep = isidle.lookup(&idx); - if (idlep && *idlep) - return 1; - return 0; -} - -static void reset_state(void) -{ - int idx = 0; - struct start_data s = {}; - - sts.update(&idx, &s); -} - -TRACEPOINT_PROBE(preemptirq, TYPE_disable) -{ - int idx = 0; - struct start_data s; - - // Handle the case Ienter, CSenter, CSexit, Iexit - // Handle the case Ienter, CSenter, Iexit, CSexit - if (in_idle()) { - reset_state(); - return 0; - } - - u64 ts = bpf_ktime_get_ns(); - - s.idle_skip = 0; - s.addr_offs[START_CALLER_OFF] = args->caller_offs; - s.addr_offs[START_PARENT_OFF] = args->parent_offs; - s.ts = ts; - s.active = 1; - - sts.update(&idx, &s); - return 0; -} - -TRACEPOINT_PROBE(preemptirq, TYPE_enable) -{ - int idx = 0; - u64 start_ts, end_ts, diff; - struct start_data *stdp, std; - - // Handle the case CSenter, Ienter, CSexit, Iexit - // Handle the case Ienter, CSenter, CSexit, Iexit - if (in_idle()) { - reset_state(); - return 0; - } - - - stdp = sts.lookup(&idx); - bpf_probe_read(&std, sizeof(struct start_data), stdp); - - // Handle the case Ienter, Csenter, Iexit, Csexit - if (!std.active) { - reset_state(); - return 0; - } - - // Handle the case CSenter, Ienter, Iexit, CSexit - if (std.idle_skip) { - reset_state(); - return 0; - } - - end_ts = bpf_ktime_get_ns(); - start_ts = std.ts; - - if (start_ts > end_ts) { - reset_state(); - return 0; - } - - diff = end_ts - start_ts; - - if (diff < DURATION) { - reset_state(); - return 0; - } - - u64 id = bpf_get_current_pid_tgid(); - struct data_t data = {}; - - if (bpf_get_current_comm(&data.comm, sizeof(data.comm)) == 0) { - data.addrs[START_CALLER_OFF] = std.addr_offs[START_CALLER_OFF]; - data.addrs[START_PARENT_OFF] = std.addr_offs[START_PARENT_OFF]; - data.addrs[END_CALLER_OFF] = args->caller_offs; - data.addrs[END_PARENT_OFF] = args->parent_offs; - - data.id = id; - data.stack_id = stack_traces.get_stackid(args, 0); - data.time = diff; - data.cpu = bpf_get_smp_processor_id(); - events.perf_submit(args, &data, sizeof(data)); - } - - reset_state(); - return 0; -} -""" -bpf_text = bpf_text.replace('DURATION', '{}'.format(int(args.duration) * 1000)) - -if preemptoff: - bpf_text = bpf_text.replace('TYPE', 'preempt') -else: - bpf_text = bpf_text.replace('TYPE', 'irq') - -b = BPF(text=bpf_text) - -TASK_COMM_LEN = 16 # linux/sched.h - -class Data(ct.Structure): - _fields_ = [ - ("time", ct.c_ulonglong), - ("stack_id", ct.c_ulonglong), - ("cpu", ct.c_int), - ("id", ct.c_ulonglong), - ("addrs", ct.c_int * 4), - ("comm", ct.c_char * TASK_COMM_LEN), - ] - -def get_syms(kstack): - syms = [] - - for addr in kstack: - s = b.ksym(addr, show_offset=True) - syms.append(s) - - return syms - -# process event -def print_event(cpu, data, size): - try: - global b - event = ct.cast(data, ct.POINTER(Data)).contents - stack_traces = b['stack_traces'] - stext = b.ksymname('_stext') - - if event.stack_id < 0: - print("Empty kernel stack received\n") - return - - print("===================================") - print("TASK: %s (pid %5d tid %5d) Total Time: %-9.3fus\n\n" % (event.comm.decode(), \ - (event.id >> 32), (event.id & 0xffffffff), float(event.time) / 1000), end="") - print("Section start: {} -> {}".format(b.ksym(stext + event.addrs[0]), b.ksym(stext + event.addrs[1]))) - print("Section end: {} -> {}".format(b.ksym(stext + event.addrs[2]), b.ksym(stext + event.addrs[3]))) - - if event.stack_id < 16384: - kstack = stack_traces.walk(event.stack_id) - syms = get_syms(kstack) - if not syms: - return - - for s in syms: - print(" ", end="") - print("%s" % s) - else: - print("NO STACK FOUND DUE TO COLLISION") - print("===================================") - print("") - except: - sys.exit(0) - -b["events"].open_perf_buffer(print_event, page_cnt=256) - -print("Finding critical section with {} disabled for > {}us".format(('preempt' if preemptoff else 'IRQ'), args.duration)) - -while 1: - b.perf_buffer_poll(); diff --git a/packages/bcc b/packages/bcc index 5640f74..1d91354 100644 --- a/packages/bcc +++ b/packages/bcc @@ -22,8 +22,4 @@ python-netaddr python-pyroute2 " -EXTRA_FILES+=" -bcc/criticalstat.py -" - INSTALL_BCC=1 -- cgit v1.2.3 From abf99c6aec7c09efd99dc2dc2f68b24194a76e2d Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Tue, 19 Jun 2018 19:44:19 -0700 Subject: Add an android version of perf's futex-contention script This is temporarily added here, its not used by androdeb yet. This will be made a part of androdeb's perf and then once its ready, it can be submitted to the Linux kernel upstream and deleted from here. TODO: - Add max to statistic print - Add support to detect wakers - Turn into a new perf script that's android specific (?) - Add a flag for android locking selection - Add support for pthread lock contention Signed-off-by: Joel Fernandes --- bcc/misc/futex-contention.py | 63 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 bcc/misc/futex-contention.py diff --git a/bcc/misc/futex-contention.py b/bcc/misc/futex-contention.py new file mode 100644 index 0000000..5c96780 --- /dev/null +++ b/bcc/misc/futex-contention.py @@ -0,0 +1,63 @@ +# futex contention +# (c) 2010, Arnaldo Carvalho de Melo +# Licensed under the terms of the GNU GPL License version 2 +# +# Translation of: +# +# http://sourceware.org/systemtap/wiki/WSFutexContention +# +# to perf python scripting. +# +# Measures futex contention + +import os, sys +sys.path.append(os.environ['PERF_EXEC_PATH'] + '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') +from Util import * + +process_names = {} +thread_thislock = {} +thread_blocktime = {} + +lock_waits = {} # long-lived stats on (tid,lock) blockage elapsed time +process_names = {} # long-lived pid-to-execname mapping + +def android_lock(callchain): + for c in callchain: + if 'sym' in c and 'name' in c['sym']: + name = c['sym']['name'] + else: + continue + + if 'art::Monitor::Lock' in name: + return True + return False + +def syscalls__sys_enter_futex(event, ctxt, cpu, s, ns, tid, comm, callchain, + nr, uaddr, op, val, utime, uaddr2, val3): + + cmd = op & FUTEX_CMD_MASK + if cmd != FUTEX_WAIT or android_lock(callchain) == False: + return # we don't care about originators of WAKE events + # or futex uses that aren't android locks. + + process_names[tid] = comm + thread_thislock[tid] = uaddr + thread_blocktime[tid] = nsecs(s, ns) + +def syscalls__sys_exit_futex(event, ctxt, cpu, s, ns, tid, comm, callchain, + nr, ret): + if thread_blocktime.has_key(tid): + elapsed = nsecs(s, ns) - thread_blocktime[tid] + add_stats(lock_waits, (tid, thread_thislock[tid]), elapsed) + del thread_blocktime[tid] + del thread_thislock[tid] + +def trace_begin(): + print "Press control+C to stop and show the summary" + +def trace_end(): + for (tid, lock) in lock_waits: + min, max, avg, count = lock_waits[tid, lock] + print "%s[%d] lock %x contended %d times, %d avg ns" % \ + (process_names[tid], tid, lock, count, avg) + -- cgit v1.2.3 From 9f870352362bb4d8c6fbcc2dfc44453ae0416104 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Tue, 19 Jun 2018 19:51:36 -0700 Subject: update todo Signed-off-by: Joel Fernandes --- TODO | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index 94fe33b..2efc767 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,5 @@ -- check for space on both host and target -- check if host deps are installed (Qemu etc) -- add version number to bashrc +TODO: + - update androdeb with latest bcc (which will include criticalstat) + - symlink whichever perf is installed to /usr/bin/perf + - patch perf with the new futex contention script + (probably it can just be dropped into a path) -- cgit v1.2.3 From e25caea93c7f2494795ff311629e556cdc723de4 Mon Sep 17 00:00:00 2001 From: Erick Reyes Date: Tue, 19 Jun 2018 15:42:59 -0700 Subject: androdeb: add androdeb pull command There was already "androdeb pull" command, which did a git pull. This was renamed to "androdeb git-pull". The new command makes it easier to retrieve files from the androdeb filesystem. The same options as "adb pull" are supported. Signed-off-by: Erick Reyes --- androdeb | 25 +++++++++++++++++++++++-- utils/banners | 3 ++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/androdeb b/androdeb index 2692561..3102cd9 100755 --- a/androdeb +++ b/androdeb @@ -31,7 +31,8 @@ case $key in prepare) PREPARE=1; shift || true; ;; shell) ASHELL=1; shift || true; ;; remove) REMOVE=1; shift || true; ;; - pull) PULL=1; shift || true; ;; + git-pull) GIT_PULL=1; shift || true; ;; + pull) PULL=1; shift || true; break ;; --arch) ARCH=$2; shift || true; shift || true; ;; --archive) TARF=$2; shift || true; shift || true; ;; --tracers) source $spath/packages/tracers; shift || true; ;; @@ -53,7 +54,7 @@ case $key in esac done -if [ ! -z "$PULL" ]; then +if [ ! -z "$GIT_PULL" ]; then echo "Updating androdeb by git pull" cd $spath git pull @@ -61,6 +62,26 @@ if [ ! -z "$PULL" ]; then exit 0 fi +if [ ! -z "$PULL" ]; then + if [ $1 == "-a" ]; then + PRESERVE="-a" + echo "Preserving filestamps and mode" + shift || true + fi + file_count=$# + if [ $file_count -gt 1 ]; then + file_count=$((file_count - 1)) + fi + i=0 + while [ $i -lt $file_count ]; do + files["$i"]=/data/androdeb/debian/$1 + shift || true + i=$((i + 1)) + done + $ADB pull $PRESERVE "${files[@]}" "$@" + exit 0 +fi + if [ -z "$ASHELL" ] && [ -z "$PACKAGES" ]; then echo "No packages specified, so I'm going to build/install all packages (--fullbuild)" config_full_build diff --git a/utils/banners b/utils/banners index 69e6dec..e4b65a8 100755 --- a/utils/banners +++ b/utils/banners @@ -9,7 +9,8 @@ usage() { echo "androdeb" echo " shell Enter the androdeb shell environment and get to work!" echo " remove Remove androdeb from the device" - echo " pull Git pull androdeb to update it on your host" + echo " git-pull Git pull androdeb to update it on your host" + echo " pull Retrieve files from the androdeb filesystem in the device" echo "" echo " prepare Prepare the device (when running for the first time)" echo " --tracers Enable tracing packages (perf and trace-cmd)" -- cgit v1.2.3 From 7c8b10846470725740021e465e23d6a0a0beac58 Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Mon, 25 Jun 2018 12:29:10 -0700 Subject: Fix remove issue Signed-off-by: Joel Fernandes (Google) --- androdeb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/androdeb b/androdeb index 3102cd9..801d9a2 100755 --- a/androdeb +++ b/androdeb @@ -100,7 +100,7 @@ fi if [ ! -z "$REMOVE" ]; then die_if_no_androdeb "Nothing to remove." - $ADB shell /data/androdeb/device-umount-all; + $ADB shell /data/androdeb/device-umount-all || true; $ADB shell rm -rf /data/androdeb; exit 0; fi ########################################################## -- cgit v1.2.3 From fbdab9e75606d67f65346692a5eaafe7e801a49e Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Mon, 25 Jun 2018 13:27:58 -0700 Subject: addons: fix paths to shell Signed-off-by: Joel Fernandes (Google) --- addons/build-debian-tar | 2 +- addons/device-umount-all | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/build-debian-tar b/addons/build-debian-tar index ce7a753..2c58c37 100755 --- a/addons/build-debian-tar +++ b/addons/build-debian-tar @@ -1,4 +1,4 @@ -#!/bin/sh +#!/system/bin/sh set -e # Build a tarball out of a android environment which I can then # upload to places for people who want to expedite the install diff --git a/addons/device-umount-all b/addons/device-umount-all index f68aac7..fe3b092 100755 --- a/addons/device-umount-all +++ b/addons/device-umount-all @@ -1,4 +1,4 @@ -#!/bin/sh +#!/system/bin/sh if [ "$1x" == "--debugx" ]; then set -x -- cgit v1.2.3 From d9d099bfc97a0242ea9017422a7c1ea908c6445e Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Mon, 25 Jun 2018 13:28:27 -0700 Subject: update Signed-off-by: Joel Fernandes (Google) --- androdeb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/androdeb b/androdeb index 801d9a2..9af869f 100755 --- a/androdeb +++ b/androdeb @@ -2,7 +2,7 @@ # # (c) Joel Fernandes -VERSION=v0.99 +VERSION=v0.99a spath="$(dirname "$(readlink -f "$0")")" # spath=$( cd "$(dirname "$0")" ; pwd -P ) -- cgit v1.2.3 From 9e670aac7abda916c414b9d06d63f0c2e0b29f4a Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Mon, 25 Jun 2018 13:39:34 -0700 Subject: v0.99b release Main addition is criticalstat. Signed-off-by: Joel Fernandes (Google) --- androdeb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/androdeb b/androdeb index 9af869f..a52f641 100755 --- a/androdeb +++ b/androdeb @@ -2,7 +2,7 @@ # # (c) Joel Fernandes -VERSION=v0.99a +VERSION=v0.99b spath="$(dirname "$(readlink -f "$0")")" # spath=$( cd "$(dirname "$0")" ; pwd -P ) @@ -170,7 +170,9 @@ TDIR_ABS=$( cd "$TDIR" ; pwd -P ) if [ ! -z "$DOWNLOAD" ]; then echo "Downloading Androdeb from the web..."; echo "" - curl -L https://github.com/joelagnel/androdeb/releases/download/$VERSION/androdeb-fs.tgz --output $TDIR_ABS/androdeb-fs.tgz; + # Github dropped tar gz support! ##?#??#! Now we've to zip everything. + curl -L https://github.com/joelagnel/androdeb/releases/download/$VERSION/androdeb-fs.tgz.zip --output $TDIR_ABS/androdeb-fs.tgz.zip; + unzip -e $TDIR_ABS/androdeb-fs.tgz.zip -d $TDIR_ABS/ TARF=$TDIR_ABS/androdeb-fs.tgz; fi OUT_TMP=$TDIR/debian; rm -rf $OUT_TMP; mkdir -p $OUT_TMP -- cgit v1.2.3 From 3a11fb1e7b4c3fc3073b9736bc8e635764409b19 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Mon, 25 Jun 2018 23:10:42 -0700 Subject: add temporary perf scripts Signed-off-by: Joel Fernandes --- bcc/misc/android-futex-contention-record | 2 + bcc/misc/android-futex-contention-report | 4 ++ bcc/misc/android-futex-contention.py | 115 +++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 bcc/misc/android-futex-contention-record create mode 100644 bcc/misc/android-futex-contention-report create mode 100644 bcc/misc/android-futex-contention.py diff --git a/bcc/misc/android-futex-contention-record b/bcc/misc/android-futex-contention-record new file mode 100644 index 0000000..a12ff79 --- /dev/null +++ b/bcc/misc/android-futex-contention-record @@ -0,0 +1,2 @@ +#!/bin/bash +perf record -a -g -e syscalls:sys_enter_futex -e syscalls:sys_exit_futex -e sched:sched_waking $@ diff --git a/bcc/misc/android-futex-contention-report b/bcc/misc/android-futex-contention-report new file mode 100644 index 0000000..7a8c122 --- /dev/null +++ b/bcc/misc/android-futex-contention-report @@ -0,0 +1,4 @@ +#!/bin/bash +# description: futext contention measurement + +perf script $@ -s "$PERF_EXEC_PATH"/scripts/python/android-futex-contention.py diff --git a/bcc/misc/android-futex-contention.py b/bcc/misc/android-futex-contention.py new file mode 100644 index 0000000..b3fab37 --- /dev/null +++ b/bcc/misc/android-futex-contention.py @@ -0,0 +1,115 @@ +# futex contention +# (c) 2010, Arnaldo Carvalho de Melo +# Licensed under the terms of the GNU GPL License version 2 +# +# Translation of: +# +# http://sourceware.org/systemtap/wiki/WSFutexContention +# +# to perf python scripting. +# +# Measures futex contention + +import os, sys +sys.path.append(os.environ['PERF_EXEC_PATH'] + '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') +from Util import * + +process_names = {} +thread_thislock = {} +thread_blocktime = {} + +lock_waits = {} # long-lived stats on (tid,lock) blockage elapsed time +waker_wakee = {} # maps the futex waker to wakee +max_waits = {} # Details about a maximum contention like owner, owner chain +process_names = {} # long-lived pid-to-execname mapping + +def android_lock(callchain): + for c in callchain: + if 'sym' in c and 'name' in c['sym']: + name = c['sym']['name'] + else: + continue + + if 'art::Monitor::Lock' in name: + return True + return False + +def print_callchain(callchain): + for c in callchain: + if 'sym' in c and 'name' in c['sym']: + name = c['sym']['name'] + else: + continue + + print(" %s" % (name)) + +def sched__sched_waking(event_name, context, common_cpu, + common_secs, common_nsecs, common_pid, common_comm, + common_callchain, comm, pid, prio, success, + target_cpu): + waker_wakee[pid] = [common_pid, common_callchain] + +def syscalls__sys_enter_futex(event, ctxt, cpu, s, ns, tid, comm, callchain, + nr, uaddr, op, val, utime, uaddr2, val3): + + cmd = op & FUTEX_CMD_MASK + if cmd != FUTEX_WAIT or android_lock(callchain) == False: + return # we don't care about originators of WAKE events + # or futex uses that aren't android locks. + + process_names[tid] = comm + thread_thislock[tid] = uaddr + thread_blocktime[tid] = nsecs(s, ns) + +def syscalls__sys_exit_futex(event, ctxt, cpu, s, ns, tid, comm, callchain, + nr, ret): + + waker_pid = -1 + waker_chain = "[no call chain]" + + if thread_blocktime.has_key(tid): + # Gather stats about the contention (sum, min, max) + elapsed = nsecs(s, ns) - thread_blocktime[tid] + add_stats(lock_waits, (tid, thread_thislock[tid]), elapsed) + + # Track details about the maximum contention seen + # including owner and its callchain + if (tid, thread_thislock[tid]) in waker_wakee: + prev_wait = waker_wakee[(tid, thread_thislock[tid])][0] + else: + prev_wait = 0 + + if elapsed > prev_wait: + if tid in waker_wakee: + waker_pid = waker_wakee[tid][0] + waker_chain = waker_wakee[tid][1] + + max_waits[(tid, thread_thislock[tid])] = [elapsed, waker_pid, waker_chain, callchain] + + del thread_blocktime[tid] + del thread_thislock[tid] + +def trace_begin(): + print "Press control+C to stop and show the summary" + +def trace_end(): + for (tid, lock) in lock_waits: + print("\n==============================================================\n") + min, max, avg, count = lock_waits[tid, lock] + print "%s[%d] lock %x contended %d times, %d avg ns, %d max ns" % \ + (process_names[tid], tid, lock, count, avg, max) + print "" + + if not (tid, lock) in max_waits: + print"Max contention info not available" + continue + + print "Callstack of suffering task:" + print_callchain(max_waits[tid, lock][3]) + print "" + + waker_pid = max_waits[tid, lock][1] + waker_name = process_names[waker_pid] if waker_pid in process_names else "nameless-owner" + print "Owner %s caused this contention of %d. Owner's Call stack below:" % (waker_name, max_waits[tid, lock][0]) + print_callchain(max_waits[tid, lock][2]) + -- cgit v1.2.3 From 25f97a07a7ec713e2e19a72b40aa9e9683a2640c Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Mon, 25 Jun 2018 23:16:01 -0700 Subject: fixup! add temporary perf scripts Signed-off-by: Joel Fernandes --- bcc/misc/android-futex-contention.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bcc/misc/android-futex-contention.py b/bcc/misc/android-futex-contention.py index b3fab37..5ef3841 100644 --- a/bcc/misc/android-futex-contention.py +++ b/bcc/misc/android-futex-contention.py @@ -74,8 +74,8 @@ def syscalls__sys_exit_futex(event, ctxt, cpu, s, ns, tid, comm, callchain, # Track details about the maximum contention seen # including owner and its callchain - if (tid, thread_thislock[tid]) in waker_wakee: - prev_wait = waker_wakee[(tid, thread_thislock[tid])][0] + if (tid, thread_thislock[tid]) in max_waits: + prev_wait = max_waits[(tid, thread_thislock[tid])][0] else: prev_wait = 0 @@ -110,6 +110,6 @@ def trace_end(): waker_pid = max_waits[tid, lock][1] waker_name = process_names[waker_pid] if waker_pid in process_names else "nameless-owner" - print "Owner %s caused this contention of %d. Owner's Call stack below:" % (waker_name, max_waits[tid, lock][0]) + print "Owner %s caused this contention of %d ns. Owner's Call stack below:" % (waker_name, max_waits[tid, lock][0]) print_callchain(max_waits[tid, lock][2]) -- cgit v1.2.3 From 5104a6c01607fb97c09cafffebf023b9758a62ba Mon Sep 17 00:00:00 2001 From: Erick Reyes Date: Wed, 27 Jun 2018 15:31:58 -0700 Subject: androdeb: add push command Similar to the previously added 'pull' command, this one adds a shorthand to copy files to the device Signed-off-by: Erick Reyes --- androdeb | 34 ++++++++++++++++++++++++++++++---- utils/banners | 3 ++- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/androdeb b/androdeb index 3102cd9..80ade36 100755 --- a/androdeb +++ b/androdeb @@ -33,6 +33,7 @@ case $key in remove) REMOVE=1; shift || true; ;; git-pull) GIT_PULL=1; shift || true; ;; pull) PULL=1; shift || true; break ;; + push) PUSH=1; shift || true; break ;; --arch) ARCH=$2; shift || true; shift || true; ;; --archive) TARF=$2; shift || true; shift || true; ;; --tracers) source $spath/packages/tracers; shift || true; ;; @@ -62,16 +63,24 @@ if [ ! -z "$GIT_PULL" ]; then exit 0 fi +# Helper function to count number of source arguments in a list +# when more than one argument is supplied, it is assumed the last argument +# is a destination +function count_sources() { + local source_count=$# + if [ $source_count -gt 1 ]; then + source_count=$((source_count - 1)) + fi + echo "$source_count" +} + if [ ! -z "$PULL" ]; then if [ $1 == "-a" ]; then PRESERVE="-a" echo "Preserving filestamps and mode" shift || true fi - file_count=$# - if [ $file_count -gt 1 ]; then - file_count=$((file_count - 1)) - fi + file_count=`count_sources $@` i=0 while [ $i -lt $file_count ]; do files["$i"]=/data/androdeb/debian/$1 @@ -82,6 +91,23 @@ if [ ! -z "$PULL" ]; then exit 0 fi +if [ ! -z "$PUSH" ]; then + if [ $1 == "--sync" ]; then + sync=$1 + shift || true + fi + file_count=`count_sources $@` + i=0 + while [ $i -lt $file_count ]; do + files["$i"]=$1 + shift || true + i=$((i + 1)) + done + dest=/data/androdeb/debian/$1 + $ADB push $sync "${files[@]}" $dest + exit 0 +fi + if [ -z "$ASHELL" ] && [ -z "$PACKAGES" ]; then echo "No packages specified, so I'm going to build/install all packages (--fullbuild)" config_full_build diff --git a/utils/banners b/utils/banners index e4b65a8..1127a65 100755 --- a/utils/banners +++ b/utils/banners @@ -10,7 +10,8 @@ usage() { echo " shell Enter the androdeb shell environment and get to work!" echo " remove Remove androdeb from the device" echo " git-pull Git pull androdeb to update it on your host" - echo " pull Retrieve files from the androdeb filesystem in the device" + echo " pull Copy files from the androdeb filesystem in the device" + echo " push Copy files to the androdeb filesystem in the device" echo "" echo " prepare Prepare the device (when running for the first time)" echo " --tracers Enable tracing packages (perf and trace-cmd)" -- cgit v1.2.3 From 3de5dfbc816862ed5d34386fc88e26684a9d21c8 Mon Sep 17 00:00:00 2001 From: Erick Reyes Date: Thu, 28 Jun 2018 16:15:41 -0700 Subject: androdeb: fix issues with androdeb push command push command had an incorrect '--sync' parameter, this was a misunderstanding of the adb command usage, removed moved the helper function count_sources to utils/android Signed-off-by: Erick Reyes --- androdeb | 15 --------------- utils/android | 11 +++++++++++ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/androdeb b/androdeb index 80ade36..5900341 100755 --- a/androdeb +++ b/androdeb @@ -63,17 +63,6 @@ if [ ! -z "$GIT_PULL" ]; then exit 0 fi -# Helper function to count number of source arguments in a list -# when more than one argument is supplied, it is assumed the last argument -# is a destination -function count_sources() { - local source_count=$# - if [ $source_count -gt 1 ]; then - source_count=$((source_count - 1)) - fi - echo "$source_count" -} - if [ ! -z "$PULL" ]; then if [ $1 == "-a" ]; then PRESERVE="-a" @@ -92,10 +81,6 @@ if [ ! -z "$PULL" ]; then fi if [ ! -z "$PUSH" ]; then - if [ $1 == "--sync" ]; then - sync=$1 - shift || true - fi file_count=`count_sources $@` i=0 while [ $i -lt $file_count ]; do diff --git a/utils/android b/utils/android index 7ad11be..d7db55f 100755 --- a/utils/android +++ b/utils/android @@ -51,3 +51,14 @@ die_if_no_androdeb() { if [ $? -ne 0 ]; then die 8 "Existing androdeb env not found on device. $1"; fi set -e } + +# Helper function to count number of source arguments in a list +# when more than one argument is supplied, it is assumed the last argument +# is a destination +count_sources() { + local source_count=$# + if [ $source_count -gt 1 ]; then + source_count=$((source_count - 1)) + fi + echo "$source_count" +} \ No newline at end of file -- cgit v1.2.3 From d90662d255cb53efadaf10d3064eea0ebc6f36e9 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 1 Jul 2018 13:01:42 -0700 Subject: Set permissions for debugfs mounts Mounting debugfs can change the mode permissions of all mounted instances to 0700 apparently. Reset the mode in case that happens. Signed-off-by: Joel Fernandes --- addons/run | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/addons/run b/addons/run index 725b306..7910d28 100755 --- a/addons/run +++ b/addons/run @@ -9,9 +9,17 @@ cd $spath mount --bind /proc debian/proc/ > /dev/null mount --bind /dev debian/dev/ > /dev/null mount --bind /sys debian/sys/ > /dev/null + mount --bind /sys/kernel/debug/ debian/sys/kernel/debug/ > /dev/null mount --bind /sys/kernel/debug/tracing/ debian/sys/kernel/debug/tracing/ +# Fix up weirdness with debugfs permission changing because of +# above mounts. +chmod 0777 /sys/kernel/debug > /dev/null +chmod 0777 debian/sys/kernel/debug > /dev/null +chmod 0777 /sys/kernel/debug/tracing > /dev/null +chmod 0777 debian/sys/kernel/debug/tracing > /dev/null + # Mount Android partitions if [ -d /d/ ]; then if [ ! -d debian/d ]; then ln -s /sys/kernel/debug debian/d; fi -- cgit v1.2.3 From 3e4f3618cec481b4b842f79aff4c259d374862cd Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Mon, 2 Jul 2018 19:18:04 -0700 Subject: run: prevent teardown if chroot is already mounted Intention is to speed up the run stage. Signed-off-by: Joel Fernandes (Google) --- addons/run | 74 ++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 38 insertions(+), 36 deletions(-) diff --git a/addons/run b/addons/run index 7910d28..ebab04b 100755 --- a/addons/run +++ b/addons/run @@ -3,42 +3,44 @@ spath=$( cd "$(dirname "$0")" ; pwd -P ) cd $spath -# tear everything down -./device-umount-all - -mount --bind /proc debian/proc/ > /dev/null -mount --bind /dev debian/dev/ > /dev/null -mount --bind /sys debian/sys/ > /dev/null - -mount --bind /sys/kernel/debug/ debian/sys/kernel/debug/ > /dev/null -mount --bind /sys/kernel/debug/tracing/ debian/sys/kernel/debug/tracing/ - -# Fix up weirdness with debugfs permission changing because of -# above mounts. -chmod 0777 /sys/kernel/debug > /dev/null -chmod 0777 debian/sys/kernel/debug > /dev/null -chmod 0777 /sys/kernel/debug/tracing > /dev/null -chmod 0777 debian/sys/kernel/debug/tracing > /dev/null - -# Mount Android partitions -if [ -d /d/ ]; then - if [ ! -d debian/d ]; then ln -s /sys/kernel/debug debian/d; fi -fi - -if [ -d /data/ ]; then - mkdir -p debian/data/ - mount --bind /data debian/data/ -fi - -if [ -d /system/ ]; then - mkdir -p debian/system/ - mount --bind /system debian/system/ -fi - -if [ -d /vendor/ ]; then - mkdir -p debian/vendor/ - mount --bind /vendor debian/vendor/ -fi +do_mounts() +{ + mount --bind /proc debian/proc/ > /dev/null + mount --bind /dev debian/dev/ > /dev/null + mount --bind /sys debian/sys/ > /dev/null + mount --bind /sys/kernel/debug/ debian/sys/kernel/debug/ > /dev/null + mount --bind /sys/kernel/debug/tracing/ debian/sys/kernel/debug/tracing/ + + # Fix up weirdness with debugfs permission changing because of + # above mounts. + chmod 0777 /sys/kernel/debug > /dev/null + chmod 0777 debian/sys/kernel/debug > /dev/null + chmod 0777 /sys/kernel/debug/tracing > /dev/null + chmod 0777 debian/sys/kernel/debug/tracing > /dev/null + + # Mount Android partitions + if [ -d /d/ ]; then + if [ ! -d debian/d ]; then ln -s /sys/kernel/debug debian/d; fi + fi + + if [ -d /data/ ]; then + mkdir -p debian/data/ + mount --bind /data debian/data/ + fi + + if [ -d /system/ ]; then + mkdir -p debian/system/ + mount --bind /system debian/system/ + fi + + if [ -d /vendor/ ]; then + mkdir -p debian/vendor/ + mount --bind /vendor debian/vendor/ + fi +} + +mount | grep debian +if [ $? -ne 0 ]; then do_mounts; fi chroot debian/ /bin/bash -- cgit v1.2.3 From 2ae36afb400925340227976d189d89e57c04bc01 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Mon, 2 Jul 2018 19:30:15 -0700 Subject: run: redirect mount output Signed-off-by: Joel Fernandes --- addons/run | 3 --- 1 file changed, 3 deletions(-) diff --git a/addons/run b/addons/run index ebab04b..772a7c4 100755 --- a/addons/run +++ b/addons/run @@ -43,6 +43,3 @@ mount | grep debian if [ $? -ne 0 ]; then do_mounts; fi chroot debian/ /bin/bash - -# tear everything down -./device-umount-all -- cgit v1.2.3 From ccb993f08c722cdd55c9c28958d6c1044efc7685 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Mon, 2 Jul 2018 19:59:04 -0700 Subject: Add support to run commands over shell and return output This makes it possible to do: androdeb shell ls -la Signed-off-by: Joel Fernandes --- addons/run-command | 2 +- androdeb | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/addons/run-command b/addons/run-command index c58a002..01c182c 100755 --- a/addons/run-command +++ b/addons/run-command @@ -3,6 +3,6 @@ spath=$( cd "$(dirname "$0")" ; pwd -P ) cd $spath # Directly execute a command within the chroot of an Android device -CMD=$1 +CMD="$*" chroot debian /bin/bash -i -c "$CMD" diff --git a/androdeb b/androdeb index f4e613d..eb08876 100755 --- a/androdeb +++ b/androdeb @@ -27,6 +27,17 @@ config_full_build() { # Parse command line parameters if [ $# -lt 1 ]; then usage; fi; POSITIONAL=() while [[ $# -gt 0 ]]; do key="$1"; + +# If its shell mode, any future args become shell's args +if [ "x$ASHELL" == "x1" ]; then + if [ -z "$SHELL_ARGS" ]; then + SHELL_ARGS=$key + else + SHELL_ARGS="$SHELL_ARGS $key" + fi + shift || true; continue +fi + case $key in prepare) PREPARE=1; shift || true; ;; shell) ASHELL=1; shift || true; ;; @@ -123,7 +134,16 @@ if [ ! -z ${ASHELL+x} ]; then die 2 "Device doesn't have an androdeb environment, run \"./androdeb prepare\" first"; fi; set -e - $ADB shell -t /data/androdeb/run + if [ ! -z ${SHELL_ARGS+x} ]; then + # Explanation of quotes: + # Outer quote is so that androdeb's bash passes the SHELL_ARGS as a single + # argument to $ADB shell. Inner quotes is so that run-command can receive all + # the args even though they may be separated by spaces. \m/ + $ADB shell -t /data/androdeb/run-command "\"$SHELL_ARGS\"" + else + $ADB shell -t /data/androdeb/run + fi + exit 0 fi -- cgit v1.2.3 From 47689a7c85876a0182a43deadfc3a6ee4463e357 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Mon, 2 Jul 2018 20:02:56 -0700 Subject: bashrc: split bashrc into verbose and nonverbose Signed-off-by: Joel Fernandes --- addons/bashrc | 9 +++------ addons/bashrc.common | 7 +++++++ addons/bashrc.silent | 1 + 3 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 addons/bashrc.common create mode 100644 addons/bashrc.silent diff --git a/addons/bashrc b/addons/bashrc index c814ecf..8c25c22 100644 --- a/addons/bashrc +++ b/addons/bashrc @@ -1,10 +1,10 @@ -export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/share/bcc/tools/ -export TMPDIR=/tmp/ +# The bannered bashrc +source .bashrc.common echo "" echo "##########################################################" echo "# Welcome to androdeb environment running on Android! #" -echo "# Questions to: Joel Fernandes #" +echo "# Questions to: Joel Fernandes #" echo " #" echo " Try running vim, gcc, clang, bcc, git, make, perf etc #" echo " or apt-get install something. #" @@ -14,7 +14,4 @@ echo " CONFIG_ANDROID_PARANOID_NETWORK and rebuild kernel. #" echo "##########################################################" echo "" -psk=/proc/sys/kernel/kptr_restrict -if [ -f $psk ]; then echo 0 > $psk; fi -if [ -d /kernel-headers/ ]; then export BCC_KERNEL_SOURCE=/kernel-headers/; fi diff --git a/addons/bashrc.common b/addons/bashrc.common new file mode 100644 index 0000000..dab8ab1 --- /dev/null +++ b/addons/bashrc.common @@ -0,0 +1,7 @@ +export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/share/bcc/tools/ +export TMPDIR=/tmp/ + +psk=/proc/sys/kernel/kptr_restrict +if [ -f $psk ]; then echo 0 > $psk; fi + +if [ -d /kernel-headers/ ]; then export BCC_KERNEL_SOURCE=/kernel-headers/; fi diff --git a/addons/bashrc.silent b/addons/bashrc.silent new file mode 100644 index 0000000..c49f02e --- /dev/null +++ b/addons/bashrc.silent @@ -0,0 +1 @@ +source .bashrc.common -- cgit v1.2.3 From fa4b8cdef88c73ccfcda9f79d44b8c4d79e2530c Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Mon, 2 Jul 2018 20:08:07 -0700 Subject: androdeb: Silence banner from run-command Signed-off-by: Joel Fernandes --- addons/run-command | 2 +- buildstrap | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/run-command b/addons/run-command index 01c182c..eed84f9 100755 --- a/addons/run-command +++ b/addons/run-command @@ -5,4 +5,4 @@ cd $spath # Directly execute a command within the chroot of an Android device CMD="$*" -chroot debian /bin/bash -i -c "$CMD" +chroot debian /bin/bash --rcfile '.bashrc.silent' -i -c "$CMD" diff --git a/buildstrap b/buildstrap index 5fed520..451d7f5 100755 --- a/buildstrap +++ b/buildstrap @@ -24,6 +24,8 @@ umount $OUT_TMP/proc || true chroot $OUT_TMP rm /bin/sh || true chroot $OUT_TMP ln -s /bin/bash /bin/sh || true cp $spath/addons/bashrc $OUT_TMP/.bashrc +cp $spath/addons/bashrc.common $OUT_TMP/.bashrc.common +cp $spath/addons/bashrc.silent $OUT_TMP/.bashrc.silent for f in $EXTRA_FILES; do if [ $f == "none" ]; then continue; fi -- cgit v1.2.3 From 69dabcef0fe53d0815e3975ebf9504eec38d0660 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Mon, 2 Jul 2018 20:45:16 -0700 Subject: Update to new release Signed-off-by: Joel Fernandes --- androdeb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/androdeb b/androdeb index eb08876..3bf4d94 100755 --- a/androdeb +++ b/androdeb @@ -2,7 +2,7 @@ # # (c) Joel Fernandes -VERSION=v0.99b +VERSION=v0.99c spath="$(dirname "$(readlink -f "$0")")" # spath=$( cd "$(dirname "$0")" ; pwd -P ) -- cgit v1.2.3 From 9649a26278eda9e73ef27aaa039c61e5dd3e64a2 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Mon, 2 Jul 2018 20:49:41 -0700 Subject: androdeb: silence false error report on remove Signed-off-by: Joel Fernandes --- androdeb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/androdeb b/androdeb index 3bf4d94..15f90a5 100755 --- a/androdeb +++ b/androdeb @@ -104,7 +104,7 @@ if [ ! -z "$PUSH" ]; then exit 0 fi -if [ -z "$ASHELL" ] && [ -z "$PACKAGES" ]; then +if [ -z "$ASHELL" ] && [ -z "$REMOVE" ] && [ -z "$PACKAGES" ]; then echo "No packages specified, so I'm going to build/install all packages (--fullbuild)" config_full_build fi -- cgit v1.2.3 From 848b98e646c5bf1a675956b4ec35f6ad7226e0c5 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Mon, 2 Jul 2018 20:54:54 -0700 Subject: run: silence output from mount Signed-off-by: Joel Fernandes --- addons/run | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/run b/addons/run index 772a7c4..a5bdaf3 100755 --- a/addons/run +++ b/addons/run @@ -39,7 +39,7 @@ do_mounts() fi } -mount | grep debian +mount | grep debian > /dev/null if [ $? -ne 0 ]; then do_mounts; fi chroot debian/ /bin/bash -- cgit v1.2.3 From b9f28aed889f3b31f238d87ed70b6506f1e8035a Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Mon, 2 Jul 2018 21:28:57 -0700 Subject: Update to new release Signed-off-by: Joel Fernandes --- androdeb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/androdeb b/androdeb index 15f90a5..aa536ed 100755 --- a/androdeb +++ b/androdeb @@ -2,7 +2,7 @@ # # (c) Joel Fernandes -VERSION=v0.99c +VERSION=v0.99d spath="$(dirname "$(readlink -f "$0")")" # spath=$( cd "$(dirname "$0")" ; pwd -P ) -- cgit v1.2.3 From 638578fe59af404a48d135003fff12a28f2a7d7d Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 8 Jul 2018 10:50:55 -0700 Subject: shell: Make shell interactive mode work Signed-off-by: Joel Fernandes --- addons/run | 40 +--------------------------------------- addons/run-command | 2 ++ addons/run.common | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 39 deletions(-) create mode 100644 addons/run.common diff --git a/addons/run b/addons/run index a5bdaf3..9738504 100755 --- a/addons/run +++ b/addons/run @@ -1,45 +1,7 @@ #!/system/bin/sh spath=$( cd "$(dirname "$0")" ; pwd -P ) - cd $spath -do_mounts() -{ - mount --bind /proc debian/proc/ > /dev/null - mount --bind /dev debian/dev/ > /dev/null - mount --bind /sys debian/sys/ > /dev/null - mount --bind /sys/kernel/debug/ debian/sys/kernel/debug/ > /dev/null - mount --bind /sys/kernel/debug/tracing/ debian/sys/kernel/debug/tracing/ - - # Fix up weirdness with debugfs permission changing because of - # above mounts. - chmod 0777 /sys/kernel/debug > /dev/null - chmod 0777 debian/sys/kernel/debug > /dev/null - chmod 0777 /sys/kernel/debug/tracing > /dev/null - chmod 0777 debian/sys/kernel/debug/tracing > /dev/null - - # Mount Android partitions - if [ -d /d/ ]; then - if [ ! -d debian/d ]; then ln -s /sys/kernel/debug debian/d; fi - fi - - if [ -d /data/ ]; then - mkdir -p debian/data/ - mount --bind /data debian/data/ - fi - - if [ -d /system/ ]; then - mkdir -p debian/system/ - mount --bind /system debian/system/ - fi - - if [ -d /vendor/ ]; then - mkdir -p debian/vendor/ - mount --bind /vendor debian/vendor/ - fi -} - -mount | grep debian > /dev/null -if [ $? -ne 0 ]; then do_mounts; fi +source run.common chroot debian/ /bin/bash diff --git a/addons/run-command b/addons/run-command index eed84f9..6d5a8ca 100755 --- a/addons/run-command +++ b/addons/run-command @@ -2,6 +2,8 @@ spath=$( cd "$(dirname "$0")" ; pwd -P ) cd $spath +source run.common + # Directly execute a command within the chroot of an Android device CMD="$*" diff --git a/addons/run.common b/addons/run.common new file mode 100644 index 0000000..1ef22aa --- /dev/null +++ b/addons/run.common @@ -0,0 +1,38 @@ +do_mounts() +{ + mount --bind /proc debian/proc/ > /dev/null + mount --bind /dev debian/dev/ > /dev/null + mount --bind /sys debian/sys/ > /dev/null + mount --bind /sys/kernel/debug/ debian/sys/kernel/debug/ > /dev/null + mount --bind /sys/kernel/debug/tracing/ debian/sys/kernel/debug/tracing/ + + # Fix up weirdness with debugfs permission changing because of + # above mounts. + chmod 0777 /sys/kernel/debug > /dev/null + chmod 0777 debian/sys/kernel/debug > /dev/null + chmod 0777 /sys/kernel/debug/tracing > /dev/null + chmod 0777 debian/sys/kernel/debug/tracing > /dev/null + + # Mount Android partitions + if [ -d /d/ ]; then + if [ ! -d debian/d ]; then ln -s /sys/kernel/debug debian/d; fi + fi + + if [ -d /data/ ]; then + mkdir -p debian/data/ + mount --bind /data debian/data/ + fi + + if [ -d /system/ ]; then + mkdir -p debian/system/ + mount --bind /system debian/system/ + fi + + if [ -d /vendor/ ]; then + mkdir -p debian/vendor/ + mount --bind /vendor debian/vendor/ + fi +} + +mount | grep debian > /dev/null +if [ $? -ne 0 ]; then do_mounts; fi -- cgit v1.2.3 From cb152a113e953e93b11485c0cc70f066fbc80fbd Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 8 Jul 2018 10:57:12 -0700 Subject: shell: show banner only once Signed-off-by: Joel Fernandes --- addons/bashrc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/addons/bashrc b/addons/bashrc index 8c25c22..14b9253 100644 --- a/addons/bashrc +++ b/addons/bashrc @@ -1,6 +1,8 @@ # The bannered bashrc source .bashrc.common +if [ ! -f .banner.shown ]; then + echo "" echo "##########################################################" echo "# Welcome to androdeb environment running on Android! #" @@ -14,4 +16,6 @@ echo " CONFIG_ANDROID_PARANOID_NETWORK and rebuild kernel. #" echo "##########################################################" echo "" +touch .banner.shown +fi -- cgit v1.2.3 From c6bb496f5582e3e308d0d66849cdb62543f53067 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 8 Jul 2018 11:00:32 -0700 Subject: update README Signed-off-by: Joel Fernandes --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index d84cbc4..aa90051 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,11 @@ Serial numbers of all devices connected can be obtained by `adb devices`. androdeb pull ``` +To update an existing androdeb clone on your host, run: +``` +androdeb git-pull +``` + More advanced usage instructions -------------------------------- ### Install kernel headers in addition to preparing androdeb device: -- cgit v1.2.3 From 73a213021eb731f06567fbf6c598ef17a3a0be13 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 8 Jul 2018 14:04:31 -0700 Subject: Fix apt-get issue on Android Signed-off-by: Joel Fernandes --- buildstrap | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/buildstrap b/buildstrap index 451d7f5..bb744bb 100755 --- a/buildstrap +++ b/buildstrap @@ -45,6 +45,15 @@ rm -rf $OUT_TMP/usr/lib/share/ieee-data/* rm -rf $OUT_TMP/usr/share/man/* rm -rf $OUT_TMP/usr/lib/share/man/* +# Fix apt-get issue: Android requires _apt user to be in the +# AID_INET group which is also android specific. +grep -ri _apt:x:100:65534 $OUT_TMP/etc/passwd +if [ $? -ne 0 ]; then + echo "ERROR: _apt user cannot be added to AID_INET group" +else + sed -i -e 's/_apt:x:100:65534/_apt:x:100:3003/' /etc/passwd +fi + # Clone BCC if needed if [[ ! -z ${INSTALL_BCC+x} ]]; then git clone https://github.com/iovisor/bcc.git $TDIR/debian/bcc-master -- cgit v1.2.3 From 511d95da04a58a9e6594f380ce20d9b9de5c3d85 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 8 Jul 2018 14:08:53 -0700 Subject: bashrc: remove apt-get message from banner Signed-off-by: Joel Fernandes --- addons/bashrc | 3 --- 1 file changed, 3 deletions(-) diff --git a/addons/bashrc b/addons/bashrc index 14b9253..815ca70 100644 --- a/addons/bashrc +++ b/addons/bashrc @@ -10,9 +10,6 @@ echo "# Questions to: Joel Fernandes #" echo " #" echo " Try running vim, gcc, clang, bcc, git, make, perf etc #" echo " or apt-get install something. #" -echo " #" -echo " Note: For apt-get to work, you need to disable #" -echo " CONFIG_ANDROID_PARANOID_NETWORK and rebuild kernel. #" echo "##########################################################" echo "" -- cgit v1.2.3 From 5201ffbf0a53703970b2e65a3cac43dc915e803b Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 8 Jul 2018 15:37:19 -0700 Subject: Fix apt-get issue properly Signed-off-by: Joel Fernandes --- buildstrap | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/buildstrap b/buildstrap index bb744bb..90c100a 100755 --- a/buildstrap +++ b/buildstrap @@ -47,11 +47,11 @@ rm -rf $OUT_TMP/usr/lib/share/man/* # Fix apt-get issue: Android requires _apt user to be in the # AID_INET group which is also android specific. -grep -ri _apt:x:100:65534 $OUT_TMP/etc/passwd +grep -ri _apt:x:100:65534 $OUT_TMP/etc/passwd > /dev/null 2>&1 if [ $? -ne 0 ]; then echo "ERROR: _apt user cannot be added to AID_INET group" else - sed -i -e 's/_apt:x:100:65534/_apt:x:100:3003/' /etc/passwd + sed -i -e 's/_apt:x:100:65534/_apt:x:100:3003/' $OUT_TMP/etc/passwd fi # Clone BCC if needed -- cgit v1.2.3 From 7a193e2569b6be0537216ce6cb63f456e1347f1f Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 8 Jul 2018 15:18:06 -0700 Subject: add dns entries Signed-off-by: Joel Fernandes --- buildstrap | 3 +++ 1 file changed, 3 insertions(+) diff --git a/buildstrap b/buildstrap index 90c100a..02dde43 100755 --- a/buildstrap +++ b/buildstrap @@ -54,6 +54,9 @@ else sed -i -e 's/_apt:x:100:65534/_apt:x:100:3003/' $OUT_TMP/etc/passwd fi +# Add a default DNS server +echo "nameserver 4.2.2.2" > $OUT_TMP/etc/resolv.conf + # Clone BCC if needed if [[ ! -z ${INSTALL_BCC+x} ]]; then git clone https://github.com/iovisor/bcc.git $TDIR/debian/bcc-master -- cgit v1.2.3 From 5ac823f14ad9a41ecc78a1ee1d587a7e4cc5a335 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 8 Jul 2018 14:04:31 -0700 Subject: Release v0.99e Signed-off-by: Joel Fernandes --- androdeb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/androdeb b/androdeb index aa536ed..4287926 100755 --- a/androdeb +++ b/androdeb @@ -2,7 +2,7 @@ # # (c) Joel Fernandes -VERSION=v0.99d +VERSION=v0.99e spath="$(dirname "$(readlink -f "$0")")" # spath=$( cd "$(dirname "$0")" ; pwd -P ) -- cgit v1.2.3 From 4e19ccde5cbffcf521a712cb1dd692bb4691fe5e Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 8 Jul 2018 17:23:07 -0700 Subject: utils: rename android to support Signed-off-by: Joel Fernandes --- androdeb | 2 +- buildstrap | 2 +- utils/android | 64 ----------------------------------------------------------- utils/support | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 66 deletions(-) delete mode 100755 utils/android create mode 100755 utils/support diff --git a/androdeb b/androdeb index 4287926..1a0914c 100755 --- a/androdeb +++ b/androdeb @@ -7,7 +7,7 @@ VERSION=v0.99e spath="$(dirname "$(readlink -f "$0")")" # spath=$( cd "$(dirname "$0")" ; pwd -P ) curdir=$( pwd -P ) -source $spath/utils/android +source $spath/utils/support source $spath/utils/banners # Set default vars diff --git a/buildstrap b/buildstrap index 02dde43..83c807e 100755 --- a/buildstrap +++ b/buildstrap @@ -1,7 +1,7 @@ #!/bin/bash spath="$(dirname "$(readlink -f "$0")")" -source $spath/utils/android +source $spath/utils/support source $spath/utils/banners ARCH=$1 diff --git a/utils/android b/utils/android deleted file mode 100755 index d7db55f..0000000 --- a/utils/android +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/bash -x -# Utilities to interact with android more easily - -make_csv() { - out="" - in=$1 - for p in $in; do - if [ "x$out" == "x" ]; then - out=$p - else - out="$out,$p" - fi - done - echo $out -} - -make_spaces() { - out="" - in=$1 - for p in $in; do - if [ "x$out" == "x" ]; then - out=$p - else - out="$out $p" - fi - done - echo $out -} - -cmd_exists() { - which $1 > /dev/null - return $? -} - -do_adb_root() { - ADB="$1" - $ADB root > /dev/null 2>&1 - return $? -} - -die() { - exit_code=$1 - msg=$2 - echo "ERROR: $msg" - exit $exit_code -} - -die_if_no_androdeb() { - set +e - $ADB shell ls /data/androdeb/debian > /dev/null 2>&1 - if [ $? -ne 0 ]; then die 8 "Existing androdeb env not found on device. $1"; fi - set -e -} - -# Helper function to count number of source arguments in a list -# when more than one argument is supplied, it is assumed the last argument -# is a destination -count_sources() { - local source_count=$# - if [ $source_count -gt 1 ]; then - source_count=$((source_count - 1)) - fi - echo "$source_count" -} \ No newline at end of file diff --git a/utils/support b/utils/support new file mode 100755 index 0000000..d7db55f --- /dev/null +++ b/utils/support @@ -0,0 +1,64 @@ +#!/bin/bash -x +# Utilities to interact with android more easily + +make_csv() { + out="" + in=$1 + for p in $in; do + if [ "x$out" == "x" ]; then + out=$p + else + out="$out,$p" + fi + done + echo $out +} + +make_spaces() { + out="" + in=$1 + for p in $in; do + if [ "x$out" == "x" ]; then + out=$p + else + out="$out $p" + fi + done + echo $out +} + +cmd_exists() { + which $1 > /dev/null + return $? +} + +do_adb_root() { + ADB="$1" + $ADB root > /dev/null 2>&1 + return $? +} + +die() { + exit_code=$1 + msg=$2 + echo "ERROR: $msg" + exit $exit_code +} + +die_if_no_androdeb() { + set +e + $ADB shell ls /data/androdeb/debian > /dev/null 2>&1 + if [ $? -ne 0 ]; then die 8 "Existing androdeb env not found on device. $1"; fi + set -e +} + +# Helper function to count number of source arguments in a list +# when more than one argument is supplied, it is assumed the last argument +# is a destination +count_sources() { + local source_count=$# + if [ $source_count -gt 1 ]; then + source_count=$((source_count - 1)) + fi + echo "$source_count" +} \ No newline at end of file -- cgit v1.2.3 From cc09dd9acce39de75bdbc152f3d2704914d3c332 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 8 Jul 2018 17:33:59 -0700 Subject: utils: add logging utilities borrowed from wltests Signed-off-by: Joel Fernandes --- utils/support | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 110 insertions(+), 1 deletion(-) diff --git a/utils/support b/utils/support index d7db55f..a856858 100755 --- a/utils/support +++ b/utils/support @@ -61,4 +61,113 @@ count_sources() { source_count=$((source_count - 1)) fi echo "$source_count" -} \ No newline at end of file +} + +# Borrowed from project LISA. +################################################################################ +# Logging functions +################################################################################ +c_error() { + NOW=$(date +"%H:%m:%S") + # If there is only one parameter, let's assume it's just the message + if [ $# -gt 1 ]; then + local parent_lineno="$1" + local message="$2" + echo -e "${red}$NOW - ERROR: on or near line ${parent_lineno}: ${message}${nocol}" + return + fi + + local message="$1" + echo -e "${red}$NOW - ERROR : ${message}${nocol}" +} + +c_warning() { + NOW=$(date +"%H:%m:%S") + # If there is only one parameter, let's assume it's just the message + if [ $# -gt 1 ]; then + local parent_lineno="$1" + local message="$2" + echo -e "${yellow}$NOW - WARNING: on or near line ${parent_lineno}: ${message}${nocol}" + return + fi + local message="$1" + echo -e "${yellow}$NOW - WARNING : ${message}${nocol}" +} + +c_info() { + NOW=$(date +"%H:%m:%S") + # If there is only one parameter, let's assume it's just the message + if [ $# -gt 1 ]; then + local parent_lineno="$1" + local message="$2" + echo -e "${blue}$NOW - INFO: on or near line ${parent_lineno}: ${message}${nocol}" + return + fi + local message="$1" + echo -e "${blue}$NOW - INFO : ${message}${nocol}" +} + +d_notify() { + MESSAGE=$1 + ICON=$2 + # Let's try to send a desktop notification, + # silently fails if there is not support. + notify-send \ + --icon=$ICON \ + --urgency=critical \ + --expire-time=1500 \ + "Test Series" \ + "$MESSAGE" \ + 2>/dev/null +} + +my_tput() { + if [ "${TERM-dumb}" == dumb ]; then + return + fi + tput $* +} + +box_out() +{ + local s=("$@") b w + for l in "${s[@]}"; do + ((w<${#l})) && { b="$l"; w="${#l}"; } + done + my_tput setaf 3 + echo -e "|-${b//?/-}-|" + for l in "${s[@]}"; do + printf '| %s%*s%s |\n' "$(my_tput setaf 4)" "-$w" "$l" "$(my_tput setaf 3)" + # echo "|-${b//?/-}-|" + done + echo "|-${b//?/-}-|" + my_tput sgr 0 +} + + +################################################################################ +# Colors +################################################################################ + +if [ -t 1 ]; then + ncolors=$(my_tput colors) + if [ -n "${ncolors}" ] && [ ${ncolors} -ge 8 ]; then + nocol='\e[0m' # No Color + white='\e[1;37m' + black='\e[0;30m' + blue='\e[0;34m' + lblue='\e[1;34m' + green='\e[0;32m' + lgreen='\e[1;32m' + cyan='\e[0;36m' + lcyan='\e[1;36m' + red='\e[0;31m' + lred='\e[1;31m' + purple='\e[0;35m' + lpurple='\e[1;35m' + brown='\e[0;33m' + yellow='\e[1;33m' + grey='\e[0;30m' + lgrey='\e[0;37m' + fi +fi -- cgit v1.2.3 From 112243b6bb7ee3e12d2dc26a7c639514f2cd9ccf Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 8 Jul 2018 17:42:48 -0700 Subject: Improve logging Signed-off-by: Joel Fernandes --- androdeb | 40 +++++++++++++++++------------------ buildstrap | 4 ++-- utils/banners | 67 ++++++++++++++++++++++++++++++----------------------------- utils/support | 2 +- 4 files changed, 57 insertions(+), 56 deletions(-) diff --git a/androdeb b/androdeb index 1a0914c..e16a389 100755 --- a/androdeb +++ b/androdeb @@ -62,22 +62,22 @@ case $key in --device|-s) ADB="$ADB -s $2"; shift || true; shift || true; ;; --build-image) BUILD_IMAGE=$2; shift || true; shift || true; ;; --debug) set -x; shift || true; ;; - *) echo "Unknown option ($1)"; usage; ;; + *) c_error "Unknown option ($1)"; usage; ;; esac done if [ ! -z "$GIT_PULL" ]; then - echo "Updating androdeb by git pull" + c_info "Updating androdeb by git pull" cd $spath git pull - echo "Done." + c_info "Done." exit 0 fi if [ ! -z "$PULL" ]; then if [ $1 == "-a" ]; then PRESERVE="-a" - echo "Preserving filestamps and mode" + c_info "Preserving filestamps and mode" shift || true fi file_count=`count_sources $@` @@ -105,7 +105,7 @@ if [ ! -z "$PUSH" ]; then fi if [ -z "$ASHELL" ] && [ -z "$REMOVE" ] && [ -z "$PACKAGES" ]; then - echo "No packages specified, so I'm going to build/install all packages (--fullbuild)" + c_info "No packages specified, so I'm going to build/install all packages (--fullbuild)" config_full_build fi @@ -161,7 +161,7 @@ function push_unpack_headers() { $ADB shell rm -rf /data/androdeb/debian/kernel-headers/ $ADB shell mkdir /data/androdeb/debian/kernel-headers/ $ADB push $TDIR_ABS/kh.tgz /data/androdeb/ - echo "Storing kernel headers into androdeb /kernel-headers/" + c_info "Storing kernel headers into androdeb /kernel-headers/" $ADB shell tar -xvf /data/androdeb/kh.tgz -C /data/androdeb/debian/kernel-headers/ > /dev/null $ADB shell rm /data/androdeb/kh.tgz } @@ -172,14 +172,14 @@ function push_unpack_tarred_headers() { $ADB shell rm -rf /data/androdeb/debian/kernel-headers/ $ADB shell mkdir /data/androdeb/debian/kernel-headers/ $ADB push $1 /data/androdeb/ - echo "Storing kernel headers into androdeb root directory" + c_info "Storing kernel headers into androdeb root directory" $ADB shell tar -xvf /data/androdeb/$(basename $1) -C /data/androdeb/debian/ > /dev/null $ADB shell rm /data/androdeb/$(basename $1) } function all_done_banner() { - echo "All done! Run \"androdeb shell\" to enter environment" + c_info "All done! Run \"androdeb shell\" to enter environment" } # Prepare is the last command checked @@ -200,7 +200,7 @@ rm -rf $TDIR/* TDIR_ABS=$( cd "$TDIR" ; pwd -P ) if [ ! -z "$DOWNLOAD" ]; then - echo "Downloading Androdeb from the web..."; echo "" + c_info "Downloading Androdeb from the web..."; c_info "" # Github dropped tar gz support! ##?#??#! Now we've to zip everything. curl -L https://github.com/joelagnel/androdeb/releases/download/$VERSION/androdeb-fs.tgz.zip --output $TDIR_ABS/androdeb-fs.tgz.zip; unzip -e $TDIR_ABS/androdeb-fs.tgz.zip -d $TDIR_ABS/ @@ -210,11 +210,11 @@ OUT_TMP=$TDIR/debian; rm -rf $OUT_TMP; mkdir -p $OUT_TMP # Unpack the supplied kernel headers tar.gz directly into androdeb root if [ ! -z "$KERNELHDRS" ]; then - echo "Building updating kernel headers from supplied tar.gz ($KERNELHDRS)" + c_info "Building updating kernel headers from supplied tar.gz ($KERNELHDRS)" # Is header tar gz update the only thing left to do? if [[ ! -z "$SKIP_INSTALL" ]]; then - echo "Skipping install" + c_info "Skipping install" push_unpack_tarred_headers $KERNELHDRS; do_cleanup; all_done_banner; exit 0; fi tar -xvf $KERNELHDRS -C $OUT_TMP/ > /dev/null @@ -222,12 +222,12 @@ fi # Package kernel headers if [ ! -z "$KERNELSRC" ]; then - echo "Building and updating kernel headers from kernel source dir ($KERNELSRC)" + c_info "Building and updating kernel headers from kernel source dir ($KERNELSRC)" $spath/bcc/build-kheaders-targz.sh ${KERNELSRC} $TDIR_ABS/kh.tgz > /dev/null # Is header update the only thing left to do? if [[ ! -z "$SKIP_INSTALL" ]]; then - echo "Skipping install" + c_info "Skipping install" push_unpack_headers; do_cleanup; all_done_banner; exit 0; fi mkdir $OUT_TMP/kernel-headers @@ -236,7 +236,7 @@ fi # Build FS from existing tar, very simple. if [ ! -z "$TARF" ]; then - echo "Using archive at $TARF for filesystem preparation" + c_info "Using archive at $TARF for filesystem preparation" $ADB shell mkdir -p /data/androdeb/ $ADB push $TARF /data/androdeb/deb.tar.gz $ADB push $spath/addons/* /data/androdeb/ @@ -249,9 +249,9 @@ if [ ! -z "$TARF" ]; then fi PACKAGES+="$DEFAULT_PACKAGES" -echo "Using temporary directory: $TDIR" +c_info "Using temporary directory: $TDIR" -if [[ $EUID -ne 0 ]]; then echo "The next stage runs as sudo, please enter password if asked."; fi +if [[ $EUID -ne 0 ]]; then c_info "The next stage runs as sudo, please enter password if asked."; fi SKIP_COMPRESS=0; if [ ! -z "$BUILD_IMAGE" ]; then SKIP_COMPRESS=1; fi @@ -265,11 +265,11 @@ rm $ex_files # If we only wanted to prepare a rootfs and don't have # a device connected, then just echo that and skip cleanup if [ ! -z "$BUILD_IMAGE" ]; then - echo "For --build-image, only the image is built" - echo "Note that BCC will not be built on the image, you've to do it yourself" + c_info "For --build-image, only the image is built" + c_info "Note that BCC will not be built on the image, you've to do it yourself" sudo $spath/buildimage $OUT_TMP $(dirname $BUILD_IMAGE)/$(basename $BUILD_IMAGE) sudo chmod a+rw $(dirname $BUILD_IMAGE)/$(basename $BUILD_IMAGE) - do_cleanup; echo "Your .img has been built! Enjoy!"; exit 0 + do_cleanup; c_info "Your .img has been built! Enjoy!"; exit 0 fi # Push tar to device and start unpack @@ -286,7 +286,7 @@ do_cleanup # Extract a tar of the built, compiled and installed androdeb env if [[ ! -z ${TARDIR+x} ]]; then - echo "Creating and pulling tarball of androdeb env from device" + c_info "Creating and pulling tarball of androdeb env from device" $ADB shell /data/androdeb/build-debian-tar $ADB pull /data/androdeb/androdeb-fs.tgz $TARDIR/ $ADB shell rm /data/androdeb/androdeb-fs.tgz; fi diff --git a/buildstrap b/buildstrap index 83c807e..50def86 100755 --- a/buildstrap +++ b/buildstrap @@ -49,7 +49,7 @@ rm -rf $OUT_TMP/usr/lib/share/man/* # AID_INET group which is also android specific. grep -ri _apt:x:100:65534 $OUT_TMP/etc/passwd > /dev/null 2>&1 if [ $? -ne 0 ]; then - echo "ERROR: _apt user cannot be added to AID_INET group" + c_warning "_apt user cannot be added to AID_INET group" else sed -i -e 's/_apt:x:100:65534/_apt:x:100:3003/' $OUT_TMP/etc/passwd fi @@ -67,7 +67,7 @@ chmod -R 0777 $TDIR/ if [ $SKIP_COMPRESS -eq 1 ]; then exit 0; fi -echo "Compressing new filesystem to prepare to push to Android /data/androdeb/" +c_info "Compressing new filesystem to prepare to push to Android /data/androdeb/" tar -zcf $TDIR/deb.tar.gz -C $TDIR debian chmod 0777 $TDIR/deb.tar.gz diff --git a/utils/banners b/utils/banners index 1127a65..f873fdb 100755 --- a/utils/banners +++ b/utils/banners @@ -1,42 +1,43 @@ #!/bin/bash -x print_prepare_banner() { - echo "Preparing device..." - echo "" + c_info "Preparing device..." + c_info "" } usage() { - echo "androdeb" - echo " shell Enter the androdeb shell environment and get to work!" - echo " remove Remove androdeb from the device" - echo " git-pull Git pull androdeb to update it on your host" - echo " pull Copy files from the androdeb filesystem in the device" - echo " push Copy files to the androdeb filesystem in the device" - echo "" - echo " prepare Prepare the device (when running for the first time)" - echo " --tracers Enable tracing packages (perf and trace-cmd)" - echo " --compilers Enable compilers on the FS (gcc and clang)" - echo " --editors Enable vim, emacs and git packages" - echo " --scheduler scheduler testing tools (only rt-app for now)" - echo "" - echo " --fullbuild Enable all of the above tools (no BCC)" - echo "" - echo " --download Download full FS archive from web (overrides all tools specified)" - echo " --archive Use archive for root fs (overrides all other prepare options)" - echo " --build-image Build an ext4 .img with the base image and BCC (useful for Qemu)" - echo "" - echo " --bcc Build and install BCC from source" - echo " --kernelsrc Extract kernel headers for BCC from here" - echo " --skip-install Pass this along if only header install is needed" - echo "" - echo " --tempdir Use a specific temporary directory for build operation" - echo " --buildtar Local directory to store tarball of androdeb env from device" - echo " --distro Debian distro to base on (default is buster)" - echo " --device Serial number of adb device." - echo " -s Serial number of adb device." - echo "" - echo " --debug" - echo " --arch Specify an ARCH to build for (default arm64)" + c_info "USAGE:" + c_info "androdeb" + c_info " shell Enter the androdeb shell environment and get to work!" + c_info " remove Remove androdeb from the device" + c_info " git-pull Git pull androdeb to update it on your host" + c_info " pull Copy files from the androdeb filesystem in the device" + c_info " push Copy files to the androdeb filesystem in the device" + c_info "" + c_info " prepare Prepare the device (when running for the first time)" + c_info " --tracers Enable tracing packages (perf and trace-cmd)" + c_info " --compilers Enable compilers on the FS (gcc and clang)" + c_info " --editors Enable vim, emacs and git packages" + c_info " --scheduler scheduler testing tools (only rt-app for now)" + c_info "" + c_info " --fullbuild Enable all of the above tools (no BCC)" + c_info "" + c_info " --download Download full FS archive from web (overrides all tools specified)" + c_info " --archive Use archive for root fs (overrides all other prepare options)" + c_info " --build-image Build an ext4 .img with the base image and BCC (useful for Qemu)" + c_info "" + c_info " --bcc Build and install BCC from source" + c_info " --kernelsrc Extract kernel headers for BCC from here" + c_info " --skip-install Pass this along if only header install is needed" + c_info "" + c_info " --tempdir Use a specific temporary directory for build operation" + c_info " --buildtar Local directory to store tarball of androdeb env from device" + c_info " --distro Debian distro to base on (default is buster)" + c_info " --device Serial number of adb device." + c_info " -s Serial number of adb device." + c_info "" + c_info " --debug" + c_info " --arch Specify an ARCH to build for (default arm64)" exit 1 } diff --git a/utils/support b/utils/support index a856858..84494e1 100755 --- a/utils/support +++ b/utils/support @@ -41,7 +41,7 @@ do_adb_root() { die() { exit_code=$1 msg=$2 - echo "ERROR: $msg" + c_error "$msg" exit $exit_code } -- cgit v1.2.3 From f95f2b2786625427abb64fd5b7013910d956f289 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 8 Jul 2018 17:54:47 -0700 Subject: androdeb: make adb push quieter Signed-off-by: Joel Fernandes --- androdeb | 21 +++++++++++++++------ utils/support | 2 ++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/androdeb b/androdeb index e16a389..5afdd40 100755 --- a/androdeb +++ b/androdeb @@ -158,10 +158,10 @@ function do_cleanup() { function push_unpack_headers() { die_if_no_androdeb "Couldn't update headers." + c_info "Storing kernel headers into androdeb /kernel-headers/" $ADB shell rm -rf /data/androdeb/debian/kernel-headers/ $ADB shell mkdir /data/androdeb/debian/kernel-headers/ - $ADB push $TDIR_ABS/kh.tgz /data/androdeb/ - c_info "Storing kernel headers into androdeb /kernel-headers/" + run_quiet $ADB push $TDIR_ABS/kh.tgz /data/androdeb/ $ADB shell tar -xvf /data/androdeb/kh.tgz -C /data/androdeb/debian/kernel-headers/ > /dev/null $ADB shell rm /data/androdeb/kh.tgz } @@ -171,7 +171,10 @@ function push_unpack_tarred_headers() { $ADB shell rm -rf /data/androdeb/debian/kernel-headers/ $ADB shell mkdir /data/androdeb/debian/kernel-headers/ - $ADB push $1 /data/androdeb/ + + c_info "Pushing headers tar onto device" + run_quiet $ADB push $1 /data/androdeb/ + c_info "Storing kernel headers into androdeb root directory" $ADB shell tar -xvf /data/androdeb/$(basename $1) -C /data/androdeb/debian/ > /dev/null @@ -238,9 +241,15 @@ fi if [ ! -z "$TARF" ]; then c_info "Using archive at $TARF for filesystem preparation" $ADB shell mkdir -p /data/androdeb/ - $ADB push $TARF /data/androdeb/deb.tar.gz - $ADB push $spath/addons/* /data/androdeb/ - $ADB shell /data/androdeb/device-unpack + + c_info "Pushing filesystem to device.." + run_quiet $ADB push $TARF /data/androdeb/deb.tar.gz + + c_info "Pushing addons to device.." + run_quiet $ADB push $spath/addons/* /data/androdeb/ + + c_info "Unpacking filesystem in device.." + run_quiet $ADB shell /data/androdeb/device-unpack if [ ! -z "$KERNELHDRS" ]; then push_unpack_tarred_headers $KERNELHDRS; fi if [ ! -z "$KERNELSRC" ]; then push_unpack_headers; fi diff --git a/utils/support b/utils/support index 84494e1..ad72e05 100755 --- a/utils/support +++ b/utils/support @@ -1,6 +1,8 @@ #!/bin/bash -x # Utilities to interact with android more easily +function run_quiet() { eval "$* >/dev/null 2>&1"; } + make_csv() { out="" in=$1 -- cgit v1.2.3 From ba7214ef3f5fc32ad31f682b410fb6d78b1c0df6 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 8 Jul 2018 18:15:49 -0700 Subject: build-image: make message independent of BCC Signed-off-by: Joel Fernandes --- androdeb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/androdeb b/androdeb index 5afdd40..1d64252 100755 --- a/androdeb +++ b/androdeb @@ -274,11 +274,13 @@ rm $ex_files # If we only wanted to prepare a rootfs and don't have # a device connected, then just echo that and skip cleanup if [ ! -z "$BUILD_IMAGE" ]; then - c_info "For --build-image, only the image is built" - c_info "Note that BCC will not be built on the image, you've to do it yourself" + c_info "For --build-image, only the image is built." + c_info "any builds that need to happen on device may be cloned but not built." sudo $spath/buildimage $OUT_TMP $(dirname $BUILD_IMAGE)/$(basename $BUILD_IMAGE) sudo chmod a+rw $(dirname $BUILD_IMAGE)/$(basename $BUILD_IMAGE) - do_cleanup; c_info "Your .img has been built! Enjoy!"; exit 0 + + do_cleanup + c_info "Your .img has been built! Enjoy!"; exit 0 fi # Push tar to device and start unpack -- cgit v1.2.3 From c26696d47d2f4c832a6ba198a43818cdd75b7475 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 8 Jul 2018 18:28:12 -0700 Subject: androdeb: Improve adb-root failure message Signed-off-by: Joel Fernandes --- androdeb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/androdeb b/androdeb index 1d64252..a489835 100755 --- a/androdeb +++ b/androdeb @@ -112,12 +112,17 @@ fi if [[ ! -z ${TARDIR+x} ]] && [[ ! -d $TARDIR ]]; then die 7 "Tar dir specified doesn't exist"; fi if [ -z "$BUILD_IMAGE" ]; then -do_adb_root "$ADB" || die 3 "adb root failed, make sure: -- If multiple devices connected, provide --device (or -s ) -- Try to run \"adb root\" manually and see if it works. Typically this needs a userdebug build. + do_adb_root "$ADB" -Note: adb can be typically obtained using the android-tools-adb or the adb -packages on your distro, or by installing the Android SDK." + if [ $? -ne 0 ]; then + c_error "adb root failed, make sure:" + c_error " * If multiple devices connected, provide --device (or -s )" + c_error " * Try to run \"adb root\" manually and see if it works. Typically this needs a userdebug build." + c_error "" + c_error "Note: adb can be typically obtained using the android-tools-adb or the adb" + c_error "packages on your distro, or by installing the Android SDK." + die 3 "Exiting." + fi fi if [ ! -z "$REMOVE" ]; then -- cgit v1.2.3 From fdc5200894f324498861cb889093f11b5ce43a00 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 8 Jul 2018 18:49:20 -0700 Subject: build-image: Make device skipping more generic Currently, build-image skips device preparation stages and doesn't even need a device connected, unlike other options. Make it more generic so that in the future other options can also use such functionality. Also results in a cleanup. Signed-off-by: Joel Fernandes --- androdeb | 15 ++++++++------- buildstrap | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/androdeb b/androdeb index a489835..127c74a 100755 --- a/androdeb +++ b/androdeb @@ -13,6 +13,7 @@ source $spath/utils/banners # Set default vars DISTRO=buster; ARCH=arm64 ADB="adb" +SKIP_DEVICE=0 # Skip device preparation # Default packages DEFAULT_PACKAGES+="bash @@ -60,7 +61,7 @@ case $key in --tempdir) TDIR="$2"; shift || true; shift || true; ;; --buildtar) TARDIR="$2"; shift || true; shift || true; ;; --device|-s) ADB="$ADB -s $2"; shift || true; shift || true; ;; - --build-image) BUILD_IMAGE=$2; shift || true; shift || true; ;; + --build-image) BI=1; BUILD_IMAGEF=$2; SKIP_DEVICE=1; shift || true; shift || true; ;; --debug) set -x; shift || true; ;; *) c_error "Unknown option ($1)"; usage; ;; esac @@ -111,7 +112,7 @@ fi if [[ ! -z ${TARDIR+x} ]] && [[ ! -d $TARDIR ]]; then die 7 "Tar dir specified doesn't exist"; fi -if [ -z "$BUILD_IMAGE" ]; then +if [ -z $BI ]; then do_adb_root "$ADB" if [ $? -ne 0 ]; then @@ -123,6 +124,8 @@ if [ -z "$BUILD_IMAGE" ]; then c_error "packages on your distro, or by installing the Android SDK." die 3 "Exiting." fi +else + [ ! -z $BUILD_IMAGEF ] || die 8 "--build-image passed but no image file provided" fi if [ ! -z "$REMOVE" ]; then @@ -267,19 +270,17 @@ c_info "Using temporary directory: $TDIR" if [[ $EUID -ne 0 ]]; then c_info "The next stage runs as sudo, please enter password if asked."; fi -SKIP_COMPRESS=0; if [ ! -z "$BUILD_IMAGE" ]; then SKIP_COMPRESS=1; fi - ex_files=$(mktemp); echo $EXTRA_FILES > $ex_files sudo $spath/buildstrap $ARCH $DISTRO $TDIR $OUT_TMP \ "$(make_csv "$PACKAGES")"\ - $ex_files $INSTALL_BCC $SKIP_COMPRESS + $ex_files $INSTALL_BCC $SKIP_DEVICE rm $ex_files # If we only wanted to prepare a rootfs and don't have # a device connected, then just echo that and skip cleanup -if [ ! -z "$BUILD_IMAGE" ]; then - c_info "For --build-image, only the image is built." +if [ $SKIP_DEVICE -eq 1 ]; then + c_info "Device preparation is being skipped for the selected options" c_info "any builds that need to happen on device may be cloned but not built." sudo $spath/buildimage $OUT_TMP $(dirname $BUILD_IMAGE)/$(basename $BUILD_IMAGE) sudo chmod a+rw $(dirname $BUILD_IMAGE)/$(basename $BUILD_IMAGE) diff --git a/buildstrap b/buildstrap index 50def86..5eca01f 100755 --- a/buildstrap +++ b/buildstrap @@ -11,7 +11,7 @@ OUT_TMP=$4 PACKAGES=$5 EXTRA_FILES="$(cat $6)" INSTALL_BCC=$7 -SKIP_COMPRESS=$8 +SKIP_DEVICE=$8 # Skip any device-specific stages time qemu-debootstrap --arch $ARCH --include=$PACKAGES \ $DISTRO $OUT_TMP http://deb.debian.org/debian/ @@ -65,7 +65,7 @@ cp $spath/bcc/build-bcc.sh $TDIR/debian/bcc-master/; fi # Should be really do this? chmod -R 0777 $TDIR/ -if [ $SKIP_COMPRESS -eq 1 ]; then exit 0; fi +if [ $SKIP_DEVICE -eq 1 ]; then exit 0; fi c_info "Compressing new filesystem to prepare to push to Android /data/androdeb/" tar -zcf $TDIR/deb.tar.gz -C $TDIR debian -- cgit v1.2.3 From ffcbfe401de05d1ba30adadd9357fd55f98b1f67 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 8 Jul 2018 19:08:02 -0700 Subject: bcc: INSTALL_BCC needs to always be defined Signed-off-by: Joel Fernandes --- androdeb | 6 ++++-- buildstrap | 9 +++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/androdeb b/androdeb index 127c74a..da9a493 100755 --- a/androdeb +++ b/androdeb @@ -14,6 +14,7 @@ source $spath/utils/banners DISTRO=buster; ARCH=arm64 ADB="adb" SKIP_DEVICE=0 # Skip device preparation +INSTALL_BCC=0 # Decide if BCC is to be installed # Default packages DEFAULT_PACKAGES+="bash @@ -296,8 +297,9 @@ $ADB push $spath/addons/* /data/androdeb/ $ADB shell /data/androdeb/device-unpack # Build BCC and install bcc on device if needed -if [[ ! -z ${INSTALL_BCC+x} ]]; then -$ADB shell /data/androdeb/run-command /bcc-master/build-bcc.sh; fi +if [ $INSTALL_BCC -eq 0 ]; then + $ADB shell /data/androdeb/run-command /bcc-master/build-bcc.sh; +fi do_cleanup diff --git a/buildstrap b/buildstrap index 5eca01f..d4ae1fd 100755 --- a/buildstrap +++ b/buildstrap @@ -58,14 +58,15 @@ fi echo "nameserver 4.2.2.2" > $OUT_TMP/etc/resolv.conf # Clone BCC if needed -if [[ ! -z ${INSTALL_BCC+x} ]]; then -git clone https://github.com/iovisor/bcc.git $TDIR/debian/bcc-master -cp $spath/bcc/build-bcc.sh $TDIR/debian/bcc-master/; fi +if [ $INSTALL_BCC -eq 1 ]; then + git clone https://github.com/iovisor/bcc.git $TDIR/debian/bcc-master + cp $spath/bcc/build-bcc.sh $TDIR/debian/bcc-master/; +fi # Should be really do this? chmod -R 0777 $TDIR/ -if [ $SKIP_DEVICE -eq 1 ]; then exit 0; fi +[ $SKIP_DEVICE -eq 0 ] || exit 0 c_info "Compressing new filesystem to prepare to push to Android /data/androdeb/" tar -zcf $TDIR/deb.tar.gz -C $TDIR debian -- cgit v1.2.3 From 47ef21587e58b7901072866eaa274fedc818550d Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 8 Jul 2018 19:13:51 -0700 Subject: build-image: Fix issues with new variable names Signed-off-by: Joel Fernandes --- androdeb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/androdeb b/androdeb index da9a493..d3c6c57 100755 --- a/androdeb +++ b/androdeb @@ -283,8 +283,11 @@ rm $ex_files if [ $SKIP_DEVICE -eq 1 ]; then c_info "Device preparation is being skipped for the selected options" c_info "any builds that need to happen on device may be cloned but not built." - sudo $spath/buildimage $OUT_TMP $(dirname $BUILD_IMAGE)/$(basename $BUILD_IMAGE) - sudo chmod a+rw $(dirname $BUILD_IMAGE)/$(basename $BUILD_IMAGE) + + if [ ! -z $BI ]; then + sudo $spath/buildimage $OUT_TMP $(dirname $BUILD_IMAGEF)/$(basename $BUILD_IMAGEF) + sudo chmod a+rw $(dirname $BUILD_IMAGEF)/$(basename $BUILD_IMAGEF) + fi do_cleanup c_info "Your .img has been built! Enjoy!"; exit 0 -- cgit v1.2.3 From 07529acb2d5b531861e37e89c53ebfc27172d8fe Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 8 Jul 2018 19:24:35 -0700 Subject: androdeb: add a version box Signed-off-by: Joel Fernandes --- androdeb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/androdeb b/androdeb index d3c6c57..7596787 100755 --- a/androdeb +++ b/androdeb @@ -10,6 +10,8 @@ curdir=$( pwd -P ) source $spath/utils/support source $spath/utils/banners +box_out "androdeb: $VERSION" + # Set default vars DISTRO=buster; ARCH=arm64 ADB="adb" -- cgit v1.2.3 From 9a38e60370d6ec0cf770b824ed1f8cb306e70d7d Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 8 Jul 2018 19:26:32 -0700 Subject: fixup! build-image: Fix issues with new variable names --- androdeb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/androdeb b/androdeb index 7596787..ae8e0f3 100755 --- a/androdeb +++ b/androdeb @@ -289,10 +289,11 @@ if [ $SKIP_DEVICE -eq 1 ]; then if [ ! -z $BI ]; then sudo $spath/buildimage $OUT_TMP $(dirname $BUILD_IMAGEF)/$(basename $BUILD_IMAGEF) sudo chmod a+rw $(dirname $BUILD_IMAGEF)/$(basename $BUILD_IMAGEF) + c_info "Your .img has been built! Enjoy!" fi do_cleanup - c_info "Your .img has been built! Enjoy!"; exit 0 + exit 0 fi # Push tar to device and start unpack -- cgit v1.2.3 From dd102af6911b183c202ba368d24f62bed6df8b53 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 8 Jul 2018 19:38:42 -0700 Subject: shell: dont print box for shell Signed-off-by: Joel Fernandes --- androdeb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/androdeb b/androdeb index ae8e0f3..79fcd66 100755 --- a/androdeb +++ b/androdeb @@ -10,8 +10,6 @@ curdir=$( pwd -P ) source $spath/utils/support source $spath/utils/banners -box_out "androdeb: $VERSION" - # Set default vars DISTRO=buster; ARCH=arm64 ADB="adb" @@ -70,6 +68,8 @@ case $key in esac done +[ -z $ASHELL ] && box_out "androdeb: $VERSION" + if [ ! -z "$GIT_PULL" ]; then c_info "Updating androdeb by git pull" cd $spath @@ -116,6 +116,7 @@ fi if [[ ! -z ${TARDIR+x} ]] && [[ ! -d $TARDIR ]]; then die 7 "Tar dir specified doesn't exist"; fi if [ -z $BI ]; then + [ -z $ASHELL ] && c_info "Looking for device.." do_adb_root "$ADB" if [ $? -ne 0 ]; then -- cgit v1.2.3 From 087ff8b506bafc826319eff89ef314b7145447ea Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 8 Jul 2018 22:45:43 -0700 Subject: bcc: support kernel version override Signed-off-by: Joel Fernandes --- addons/bashrc.common | 22 ++++++- addons/get_kvers.sh | 12 ++++ ...OT-MERGE-Remove-version-override-warnings.patch | 26 ++++++++ ...ang-Allow-user-to-override-kernel-version.patch | 74 ++++++++++++++++++++++ buildstrap | 6 ++ 5 files changed, 139 insertions(+), 1 deletion(-) create mode 100755 addons/get_kvers.sh create mode 100644 bcc/misc/0001-DONOT-MERGE-Remove-version-override-warnings.patch create mode 100644 bcc/misc/0001-clang-Allow-user-to-override-kernel-version.patch diff --git a/addons/bashrc.common b/addons/bashrc.common index dab8ab1..75cae9e 100644 --- a/addons/bashrc.common +++ b/addons/bashrc.common @@ -4,4 +4,24 @@ export TMPDIR=/tmp/ psk=/proc/sys/kernel/kptr_restrict if [ -f $psk ]; then echo 0 > $psk; fi -if [ -d /kernel-headers/ ]; then export BCC_KERNEL_SOURCE=/kernel-headers/; fi +override_vers=1 +this_vers=$(/get_kvers.sh) +if [ -d /kernel-headers/ ]; then + export BCC_KERNEL_SOURCE=/kernel-headers/; + + h_vers=0 + vers_line=$(grep LINUX_VERSION_CODE /kernel-headers/include/generated/uapi/linux/version.h) + if [ "x$vers_line" != "x" ]; then + h_vers=$(echo $vers_line | cut -d ' ' -f3) + fi + + if [ $this_vers -eq $h_vers ]; then + override_vers=0 + fi +fi + +# Override kernel version if we haven't found headers with them. +# Needed for BCC to work on slightly mismatched kernels. +if [ $override_vers -eq 1 ]; then + export LINUX_VERSION_CODE_OVERRIDE=$this_vers +fi diff --git a/addons/get_kvers.sh b/addons/get_kvers.sh new file mode 100755 index 0000000..3a7a6fe --- /dev/null +++ b/addons/get_kvers.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +kvers=$(uname -r) + +MAJOR=$(echo $kvers | awk -F. '{ print $1 }') +MINOR=$(echo $kvers | awk -F. '{ print $2 }') +SUBVR=$(echo $kvers | awk -F. '{ print $3 }' | awk -F- '{ print $1 }') + +maj_num=$(($MAJOR * 65536)) +min_num=$(($MINOR * 256)) + +echo $(($maj_num + $min_num + $SUBVR)) diff --git a/bcc/misc/0001-DONOT-MERGE-Remove-version-override-warnings.patch b/bcc/misc/0001-DONOT-MERGE-Remove-version-override-warnings.patch new file mode 100644 index 0000000..7ed6dc7 --- /dev/null +++ b/bcc/misc/0001-DONOT-MERGE-Remove-version-override-warnings.patch @@ -0,0 +1,26 @@ +From 2d4a9cd04dbfa20f460b8147d03936aa97768158 Mon Sep 17 00:00:00 2001 +From: Joel Fernandes +Date: Sun, 8 Jul 2018 23:07:19 -0700 +Subject: [PATCH] DONOT MERGE: Remove version override warnings + +Signed-off-by: Joel Fernandes +--- + src/cc/frontends/clang/loader.cc | 2 -- + 1 file changed, 2 deletions(-) + +diff --git a/src/cc/frontends/clang/loader.cc b/src/cc/frontends/clang/loader.cc +index 81e429032551..53250f426547 100755 +--- a/src/cc/frontends/clang/loader.cc ++++ b/src/cc/frontends/clang/loader.cc +@@ -179,8 +179,6 @@ int ClangLoader::parse(unique_ptr *mod, TableStorage &ts, + if (version_override) { + vmacro = "-DLINUX_VERSION_CODE_OVERRIDE=" + string(version_override); + +- std::cout << "WARNING: Linux version for eBPF program is being overridden with: " << version_override << "\n"; +- std::cout << "WARNING: Due to this, the results of the program may be unpredictable\n"; + flags_cstr_rem.push_back(vmacro.c_str()); + } + +-- +2.18.0.203.gfac676dfb9-goog + diff --git a/bcc/misc/0001-clang-Allow-user-to-override-kernel-version.patch b/bcc/misc/0001-clang-Allow-user-to-override-kernel-version.patch new file mode 100644 index 0000000..13bd369 --- /dev/null +++ b/bcc/misc/0001-clang-Allow-user-to-override-kernel-version.patch @@ -0,0 +1,74 @@ +From aab6e5f524e783fda038c53b04a7a06531797bfd Mon Sep 17 00:00:00 2001 +From: Joel Fernandes +Date: Sun, 8 Jul 2018 22:55:29 -0700 +Subject: [PATCH] clang: Allow user to override kernel version + +BCC currently requires exactly matching headers. Sometimes this is quite +inconvenient especially if the kernel version is only very slightly +different such as updates in a stable kernel. This patch gives the user +the flexibility to override the the LINUX_VERSION_CODE provided in the +linux kernel headers, so that the eBPF program may load. We also print a +message when this is done, so that the user is warned about the override +happening and that results may be unpredictable. + +Signed-off-by: Joel Fernandes +--- + src/cc/export/helpers.h | 4 ++++ + src/cc/frontends/clang/loader.cc | 11 +++++++++++ + 2 files changed, 15 insertions(+) + mode change 100644 => 100755 src/cc/export/helpers.h + mode change 100644 => 100755 src/cc/frontends/clang/loader.cc + +diff --git a/src/cc/export/helpers.h b/src/cc/export/helpers.h +old mode 100644 +new mode 100755 +index a05a9f740603..e4af0bcdd1f5 +--- a/src/cc/export/helpers.h ++++ b/src/cc/export/helpers.h +@@ -224,7 +224,11 @@ struct _name##_table_t _name = { .max_entries = (_max_entries) } + + char _license[4] SEC("license") = "GPL"; + ++#ifdef LINUX_VERSION_CODE_OVERRIDE ++unsigned _version SEC("version") = LINUX_VERSION_CODE_OVERRIDE; ++#else + unsigned _version SEC("version") = LINUX_VERSION_CODE; ++#endif + + /* helper functions called from eBPF programs written in C */ + static void *(*bpf_map_lookup_elem)(void *map, void *key) = +diff --git a/src/cc/frontends/clang/loader.cc b/src/cc/frontends/clang/loader.cc +old mode 100644 +new mode 100755 +index 72c5843ec808..81e429032551 +--- a/src/cc/frontends/clang/loader.cc ++++ b/src/cc/frontends/clang/loader.cc +@@ -112,7 +112,9 @@ int ClangLoader::parse(unique_ptr *mod, TableStorage &ts, + uname(&un); + string kdir, kpath; + const char *kpath_env = ::getenv("BCC_KERNEL_SOURCE"); ++ const char *version_override = ::getenv("LINUX_VERSION_CODE_OVERRIDE"); + bool has_kpath_source = false; ++ string vmacro; + + if (kpath_env) { + kpath = string(kpath_env); +@@ -173,6 +175,15 @@ int ClangLoader::parse(unique_ptr *mod, TableStorage &ts, + flags_cstr.push_back(it->c_str()); + + vector flags_cstr_rem; ++ ++ if (version_override) { ++ vmacro = "-DLINUX_VERSION_CODE_OVERRIDE=" + string(version_override); ++ ++ std::cout << "WARNING: Linux version for eBPF program is being overridden with: " << version_override << "\n"; ++ std::cout << "WARNING: Due to this, the results of the program may be unpredictable\n"; ++ flags_cstr_rem.push_back(vmacro.c_str()); ++ } ++ + flags_cstr_rem.push_back("-include"); + flags_cstr_rem.push_back("/virtual/include/bcc/helpers.h"); + flags_cstr_rem.push_back("-isystem"); +-- +2.18.0.203.gfac676dfb9-goog + diff --git a/buildstrap b/buildstrap index d4ae1fd..61b16bf 100755 --- a/buildstrap +++ b/buildstrap @@ -26,6 +26,7 @@ chroot $OUT_TMP ln -s /bin/bash /bin/sh || true cp $spath/addons/bashrc $OUT_TMP/.bashrc cp $spath/addons/bashrc.common $OUT_TMP/.bashrc.common cp $spath/addons/bashrc.silent $OUT_TMP/.bashrc.silent +cp $spath/addons/get_kvers.sh $OUT_TMP/ for f in $EXTRA_FILES; do if [ $f == "none" ]; then continue; fi @@ -61,6 +62,11 @@ echo "nameserver 4.2.2.2" > $OUT_TMP/etc/resolv.conf if [ $INSTALL_BCC -eq 1 ]; then git clone https://github.com/iovisor/bcc.git $TDIR/debian/bcc-master cp $spath/bcc/build-bcc.sh $TDIR/debian/bcc-master/; + + pushd $TDIR/debian/bcc-master + git apply $spath/bcc/misc/0001-clang-Allow-user-to-override-kernel-version.patch + git apply $spath/bcc/misc/0001-DONOT-MERGE-Remove-version-override-warnings.patch + popd fi # Should be really do this? -- cgit v1.2.3 From ddd2803ddb8b86c6ddb87fc1c6acfdfa818de694 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 8 Jul 2018 23:13:17 -0700 Subject: androdeb: make --build-tar path optional Default it to script directory Signed-off-by: Joel Fernandes --- androdeb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/androdeb b/androdeb index 79fcd66..25c5173 100755 --- a/androdeb +++ b/androdeb @@ -60,7 +60,7 @@ case $key in --skip-install) SKIP_INSTALL=1; shift || true; ;; --kernel-headers-targz) KERNELHDRS=$2; shift || true; shift || true; ;; --tempdir) TDIR="$2"; shift || true; shift || true; ;; - --buildtar) TARDIR="$2"; shift || true; shift || true; ;; + --buildtar) BTAR=1; TARDIR="$2"; shift || true; shift || true; ;; --device|-s) ADB="$ADB -s $2"; shift || true; shift || true; ;; --build-image) BI=1; BUILD_IMAGEF=$2; SKIP_DEVICE=1; shift || true; shift || true; ;; --debug) set -x; shift || true; ;; @@ -70,6 +70,10 @@ done [ -z $ASHELL ] && box_out "androdeb: $VERSION" +if [ ! -z $BTAR ] && [ -z $TARDIR ]; then + TARDIR=$spath +fi + if [ ! -z "$GIT_PULL" ]; then c_info "Updating androdeb by git pull" cd $spath -- cgit v1.2.3 From 241160e30a0a548ffff0426015f698a45d506a76 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 8 Jul 2018 23:36:11 -0700 Subject: bcc: fix build process Signed-off-by: Joel Fernandes --- androdeb | 2 +- buildstrap | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/androdeb b/androdeb index 25c5173..e30d047 100755 --- a/androdeb +++ b/androdeb @@ -308,7 +308,7 @@ $ADB push $spath/addons/* /data/androdeb/ $ADB shell /data/androdeb/device-unpack # Build BCC and install bcc on device if needed -if [ $INSTALL_BCC -eq 0 ]; then +if [ $INSTALL_BCC -eq 1 ]; then $ADB shell /data/androdeb/run-command /bcc-master/build-bcc.sh; fi diff --git a/buildstrap b/buildstrap index 61b16bf..d14173a 100755 --- a/buildstrap +++ b/buildstrap @@ -64,8 +64,8 @@ if [ $INSTALL_BCC -eq 1 ]; then cp $spath/bcc/build-bcc.sh $TDIR/debian/bcc-master/; pushd $TDIR/debian/bcc-master - git apply $spath/bcc/misc/0001-clang-Allow-user-to-override-kernel-version.patch - git apply $spath/bcc/misc/0001-DONOT-MERGE-Remove-version-override-warnings.patch + git am $spath/bcc/misc/0001-clang-Allow-user-to-override-kernel-version.patch + git am $spath/bcc/misc/0001-DONOT-MERGE-Remove-version-override-warnings.patch popd fi -- cgit v1.2.3 From 7880b49027de8d450dbdd30abd3acaa2c2e2d366 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Tue, 10 Jul 2018 09:13:09 -0700 Subject: androdeb: fix incorrect home directory variable The following command fails on androdeb. The output looks like: curl https://sh.rustup.rs -sSf | sh info: downloading installer error: $HOME differs from euid-obtained home directory: you may be using sudo error: if this is what you want, restart the installation with `-y' This is because home directory wasn't set. Signed-off-by: Joel Fernandes --- addons/bashrc | 4 ++++ addons/bashrc.silent | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/addons/bashrc b/addons/bashrc index 815ca70..30c1388 100644 --- a/addons/bashrc +++ b/addons/bashrc @@ -16,3 +16,7 @@ echo "" touch .banner.shown fi + +homedir=$( getent passwd "$USER" | cut -d: -f6 ) +export HOME=$homedir +cd $HOME diff --git a/addons/bashrc.silent b/addons/bashrc.silent index c49f02e..95f23f0 100644 --- a/addons/bashrc.silent +++ b/addons/bashrc.silent @@ -1 +1,5 @@ source .bashrc.common + +homedir=$( getent passwd "$USER" | cut -d: -f6 ) +export HOME=$homedir +cd $HOME -- cgit v1.2.3 From 60f64b2a3f6630d61e303d143e082fb902a3c51a Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Tue, 10 Jul 2018 09:33:13 -0700 Subject: bcc: use patch to apply patches Signed-off-by: Joel Fernandes --- buildstrap | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/buildstrap b/buildstrap index d14173a..b046d20 100755 --- a/buildstrap +++ b/buildstrap @@ -64,8 +64,8 @@ if [ $INSTALL_BCC -eq 1 ]; then cp $spath/bcc/build-bcc.sh $TDIR/debian/bcc-master/; pushd $TDIR/debian/bcc-master - git am $spath/bcc/misc/0001-clang-Allow-user-to-override-kernel-version.patch - git am $spath/bcc/misc/0001-DONOT-MERGE-Remove-version-override-warnings.patch + patch -p1 < $spath/bcc/misc/0001-clang-Allow-user-to-override-kernel-version.patch + patch -p1 < $spath/bcc/misc/0001-DONOT-MERGE-Remove-version-override-warnings.patch popd fi -- cgit v1.2.3 From a35c4db31b89b903cf3a424d156c9d668ab66fa3 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Tue, 10 Jul 2018 09:34:29 -0700 Subject: bash: dont cd into homedir Doing this is more complicated, since several command expect running from /. Also users may be depending on that. Just prevent cd for now. Signed-off-by: Joel Fernandes --- addons/bashrc | 1 - addons/bashrc.silent | 1 - 2 files changed, 2 deletions(-) diff --git a/addons/bashrc b/addons/bashrc index 30c1388..675572d 100644 --- a/addons/bashrc +++ b/addons/bashrc @@ -19,4 +19,3 @@ fi homedir=$( getent passwd "$USER" | cut -d: -f6 ) export HOME=$homedir -cd $HOME diff --git a/addons/bashrc.silent b/addons/bashrc.silent index 95f23f0..1e52500 100644 --- a/addons/bashrc.silent +++ b/addons/bashrc.silent @@ -2,4 +2,3 @@ source .bashrc.common homedir=$( getent passwd "$USER" | cut -d: -f6 ) export HOME=$homedir -cd $HOME -- cgit v1.2.3 From d54c266a0617f32fb5e8b3abf90b2835d15f437a Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Tue, 10 Jul 2018 10:45:32 -0700 Subject: Release v0.99f Signed-off-by: Joel Fernandes --- androdeb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/androdeb b/androdeb index e30d047..d538e16 100755 --- a/androdeb +++ b/androdeb @@ -2,7 +2,7 @@ # # (c) Joel Fernandes -VERSION=v0.99e +VERSION=v0.99f spath="$(dirname "$(readlink -f "$0")")" # spath=$( cd "$(dirname "$0")" ; pwd -P ) -- cgit v1.2.3 From c755196348e9f843e449e67c0c5008df8e3df081 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Tue, 10 Jul 2018 14:12:19 -0700 Subject: Update androdeb command naming to adeb Signed-off-by: Joel Fernandes --- BCC.md | 12 ++++++------ README.md | 46 +++++++++++++++++++++++++--------------------- adeb | 6 ++++++ androdeb | 2 +- utils/banners | 2 +- 5 files changed, 39 insertions(+), 29 deletions(-) create mode 100755 adeb diff --git a/BCC.md b/BCC.md index fc8080c..9042361 100644 --- a/BCC.md +++ b/BCC.md @@ -24,7 +24,7 @@ source and the sources should be built atleast once in-tree. Once it is built, run the following command pointing androdeb to the kernel sources which will have it extract headers from there and push them to the device. ``` -androdeb prepare --download --bcc --kernelsrc /path/to/kernel-source/ +adeb prepare --download --bcc --kernelsrc /path/to/kernel-source/ ``` This downloads and installs a pre-built androdeb filesystem containing a recent version of BCC onto the android device, extracts kernel headers from the source @@ -33,7 +33,7 @@ only if the target architecture is ARM64. For other architectures, see the [Other Architectures section](https://github.com/joelagnel/androdeb/blob/master/BCC.md#other-architectures-other-than-arm64) -Now to run BCC, just start an androdeb shell: `androdeb shell`. This uses adb +Now to run BCC, just start an adeb shell: `adeb shell`. This uses adb as the backend to start a shell into your androdeb environment. Try running `opensnoop` or any of the other BCC tracers to confirm that the setup worked correctly. @@ -61,11 +61,11 @@ CONFIG_PREEMPTIRQ_EVENTS=y Build BCC during androdeb install (Optional) -------------------------------------------- If you would like the latest BCC installation on your Android device, we -recommend dropping the `--download` option from the androdeb command above. -This will make androdeb clone and build the latest version for of BCC for the +recommend dropping the `--download` option from the adeb command above. +This will make androdeb clone and build the latest version of BCC for the target architecture. Note that this is much slower that `--download`. ``` -androdeb prepare --bcc --kernelsrc /path/to/kernel-source/ +adeb prepare --bcc --kernelsrc /path/to/kernel-source/ ``` Other Architectures (other than ARM64) @@ -74,7 +74,7 @@ By default androdeb assumes the target Android device is based on ARM64 processor architecture. For other architectures, use the --arch option. For example for x86_64 architecture, run: ``` -androdeb prepare --arch amd64 --bcc --kernelsrc /path/to/kernel-source/ +adeb prepare --arch amd64 --bcc --kernelsrc /path/to/kernel-source/ ``` Note: The --download option ignores the --arch flag. This is because we only provide pre-built filesystems for ARM64 at the moment. diff --git a/README.md b/README.md index aa90051..09a5223 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ androdeb -------- -**androdeb** provides a powerful Linux shell environment where one can -run popular and mainstream Linux tracing, compiling, editing and other -development tools on an existing Android device. All the commands typically -available on a modern Linux system are supported in androdeb. +**androdeb** (also known as **adeb**) provides a powerful Linux shell +environment where one can run popular and mainstream Linux tracing, compiling, +editing and other development tools on an existing Android device. All the +commands typically available on a modern Linux system are supported in +androdeb. Usecases -------- @@ -47,50 +48,53 @@ Quick Start Instructions ``` git clone https://github.com/joelagnel/androdeb.git cd androdeb + +# Add some short cuts: +sudo ln -s ./adeb /usr/bin/adeb sudo ln -s ./androdeb /usr/bin/androdeb ``` -* Fastest way of installing androdeb onto your device: +* Fastest way of installing adeb onto your device: ``` # First make sure device is connected to system -androdeb prepare --download +adeb prepare --download ``` -* Now run androdeb shell to enter your new environment!: +* Now run adeb shell to enter your new environment!: ``` -androdeb shell +adeb shell ``` * Once done, hit `CTRL + D` and you will exit out of the shell. To remove androdeb from the device, run: ``` -androdeb remove +adeb remove ``` If you have multiple devices connected, please add `-s `. Serial numbers of all devices connected can be obtained by `adb devices`. * To update the androdeb you cloned on your host, run: ``` -androdeb pull +adeb pull ``` To update an existing androdeb clone on your host, run: ``` -androdeb git-pull +adeb git-pull ``` More advanced usage instructions -------------------------------- ### Install kernel headers in addition to preparing androdeb device: ``` -androdeb prepare --download --kernelsrc /path/to/kernel-source +adeb prepare --download --kernelsrc /path/to/kernel-source ``` ### Update kernel headers onto an already prepared device: If you need to put kernel sources for an existing install, run: ``` -androdeb prepare --kernelsrc /path/to/kernel-source --skip-install +adeb prepare --kernelsrc /path/to/kernel-source --skip-install ``` Note: The kernel sources should have been built (atleast build should have started). @@ -98,23 +102,23 @@ Note: The kernel sources should have been built (atleast build should have start The androdeb fs will be prepared locally by downloading packages as needed: ``` -androdeb prepare --fullbuild +adeb prepare --fullbuild ``` This is unlike `--download` where the androdeb rootfs is itself pulled from the web. ### Add kernel headers to device in addition to building locally: ``` -androdeb prepare --fullbuild --kernelsrc /path/to/kernel-source/ +adeb prepare --fullbuild --kernelsrc /path/to/kernel-source/ ``` ### Instead of `--fullbuild`, customize what you install: ``` -androdeb prepare --editors --compilers +adeb prepare --editors --compilers ``` ### Install only BCC: ``` -androdeb prepare --bcc --kernelsrc /path/to/kernel-source/ +adeb prepare --bcc --kernelsrc /path/to/kernel-source/ ``` Note: BCC is built while being installed. Also `--kernelsrc` is recommended for tools to function unless device has them @@ -122,7 +126,7 @@ already. ### Extract the FS from the device, after its prepared: ``` -androdeb prepare --fullbuild --buildtar /path/ +adeb prepare --fullbuild --buildtar /path/ ``` After device is prepared, it will extract the root fs from it and store it as a tar archive at `/path/androdeb-fs.tgz`. This @@ -130,12 +134,12 @@ can be used later. ### Use a previously prepared androdeb rootfs tar from local: ``` -androdeb prepare --archive /path/androdeb-fs.tgz +adeb prepare --archive /path/androdeb-fs.tgz ``` ### Build a standalone raw EXT4 image out of the FS: ``` -androdeb prepare --buildimage /path/to/image.img +adeb prepare --buildimage /path/to/image.img ``` This can then be passed to Qemu as -hda. Note: This option doesn't need a device connected. @@ -145,7 +149,7 @@ By default androdeb assumes the target Android device is based on ARM64 processor architecture. For other architectures, use the --arch option. For example for x86_64 architecture, run: ``` -androdeb prepare --arch amd64 --bcc --kernelsrc /path/to/kernel-source/ +adeb prepare --arch amd64 --bcc --kernelsrc /path/to/kernel-source/ ``` Note: The --download option ignores the --arch flag. This is because we only provide pre-built filesystems for ARM64 at the moment. diff --git a/adeb b/adeb new file mode 100755 index 0000000..a651772 --- /dev/null +++ b/adeb @@ -0,0 +1,6 @@ +#!/bin/bash -e +# +# (c) Joel Fernandes + +spath="$(dirname "$(readlink -f "$0")")" +source $spath/androdeb diff --git a/androdeb b/androdeb index d538e16..5d9a2ce 100755 --- a/androdeb +++ b/androdeb @@ -68,7 +68,7 @@ case $key in esac done -[ -z $ASHELL ] && box_out "androdeb: $VERSION" +[ -z $ASHELL ] && box_out "adeb: $VERSION" if [ ! -z $BTAR ] && [ -z $TARDIR ]; then TARDIR=$spath diff --git a/utils/banners b/utils/banners index f873fdb..491d324 100755 --- a/utils/banners +++ b/utils/banners @@ -7,7 +7,7 @@ print_prepare_banner() { usage() { c_info "USAGE:" - c_info "androdeb" + c_info "adeb" c_info " shell Enter the androdeb shell environment and get to work!" c_info " remove Remove androdeb from the device" c_info " git-pull Git pull androdeb to update it on your host" -- cgit v1.2.3 From aefebd105950638d0330fb801c5dd610e83628cf Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Tue, 10 Jul 2018 14:17:19 -0700 Subject: readme: fix symlink instructions Signed-off-by: Joel Fernandes --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 09a5223..293669b 100644 --- a/README.md +++ b/README.md @@ -50,8 +50,8 @@ git clone https://github.com/joelagnel/androdeb.git cd androdeb # Add some short cuts: -sudo ln -s ./adeb /usr/bin/adeb -sudo ln -s ./androdeb /usr/bin/androdeb +sudo ln -s $(pwd)/adeb /usr/bin/adeb +sudo ln -s $(pwd)/androdeb /usr/bin/androdeb ``` * Fastest way of installing adeb onto your device: -- cgit v1.2.3 From 773bd58dd8169a358f90419ef6b91efca6fbd521 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Tue, 10 Jul 2018 19:20:39 -0700 Subject: lockstat: add initial Signed-off-by: Joel Fernandes --- bcc/misc/lockstat.py | 249 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 249 insertions(+) create mode 100755 bcc/misc/lockstat.py diff --git a/bcc/misc/lockstat.py b/bcc/misc/lockstat.py new file mode 100755 index 0000000..fb1edbe --- /dev/null +++ b/bcc/misc/lockstat.py @@ -0,0 +1,249 @@ +#!/usr/bin/env bcc-py +# +# lockstat Trace and display lock contention stats +# +# USAGE: lockstat + +# Licensed under the Apache License, Version 2.0 (the "License") +# 28-Jul-2017 Gisle Dankel Created this. + +from bcc import BPF +from ctypes import c_int +from time import sleep +from datetime import datetime +import argparse +import subprocess +import os + +class Lock(object): + def __init__(self): + self.contention_count = 0 + self.elapsed_blocked = 0 + self.thread_count = 0 + + def update(self, count, block_time): + self.contention_count += count + self.elapsed_blocked += block_time + self.thread_count += 1 + +def run_command_get_pid(command): + p = subprocess.Popen(command.split()) + return p.pid + + + +examples = """ +EXAMPLES: + +./lockstat + Trace calls to sys_futex and display contented locks every 5 seconds + for all processes running on the system +./lockstat -p + Trace only for the specified pid and display contended locks + every 5 seconds +./lockstat -p -t + Trace for a specified pid and print a message on each entry and exit to + sys_futex until interrupted or killed +./lockstat -p 10 + Trace the specified pid and show a message every 10 seconds +./lockstat -c 1 30 + Run the specified command and display contended locks every 1 second + for a total of 30 times +""" + +description = """ +Trace kernel futex events. +These often occur because of lock contention, e.g. involving a pthread_mutex. +This script resemblers the following SystemTap example: +https://sourceware.org/systemtap/SystemTap_Beginners_Guide/futexcontentionsect.html +""" + +parser = argparse.ArgumentParser(description=description, + formatter_class=argparse.RawDescriptionHelpFormatter, + epilog=examples) +parser.add_argument("-p", "--pid", type=int, default=-1, + help="the PID to trace; if not specified, trace all") +parser.add_argument("-t", "--trace", action="store_true", + help="print trace messages for each futex enter/exit") +parser.add_argument("interval", nargs="?", default=5, type=int, + help="interval in seconds to print summary") +parser.add_argument("count", nargs="?", type=int, + help="number of times to print the report before exiting") +parser.add_argument("-c", "--command", + help="execute and trace the specified command") + +args = parser.parse_args() + +pid = args.pid +command = args.command +interval = args.interval +num_prints = args.count +trace_all = args.trace + +if command is not None: + print("Executing '%s' and tracing the resulting process." % command) + pid = run_command_get_pid(command) + +bpf_source = """ +#include +#include +#include +#include + +struct comm_t { + char name[TASK_COMM_LEN]; +}; + +struct lock_key_t { + u64 uaddr; + u32 pid; + u32 tgid; +}; + +struct lock_info_t { + u64 elapsed_blocked; + u64 contention_count; +}; + + +BPF_HASH(pid_lock, u32, u64); +BPF_HASH(pid_blocktime, u32, u64); +BPF_HASH(tgid_comm, u32, struct comm_t); +BPF_HASH(lock_stats, struct lock_key_t, struct lock_info_t, 1000000); + +static inline int update_stats(u32 pid, u32 tgid, u64 uaddr, u64 block_time) { + struct lock_key_t key = {}; + struct lock_info_t zero = {}; + struct lock_info_t *info; + + key.pid = pid; + key.tgid = tgid; + key.uaddr = uaddr; + info = lock_stats.lookup_or_init(&key, &zero); + info->elapsed_blocked += block_time; + info->contention_count++; + + if (0 == tgid_comm.lookup(&tgid)) { + struct comm_t comm; + bpf_get_current_comm(&comm.name, sizeof(comm.name)); + tgid_comm.update(&tgid, &comm); + } + return 0; +} + +// FIXME: Should attach to sys_enter_futex and sys_exit_futex tracepoints here, +// but that does not currently work +int sys_futex_enter(struct pt_regs *ctx, u32 *uaddr, int op, u32 val, + struct timespec *utime, u32 *uaddr2, u32 val3) { + int cmd = op & FUTEX_CMD_MASK; + if (cmd != FUTEX_WAIT) + return 0; + + u64 pid_tgid = bpf_get_current_pid_tgid(); + u32 pid = pid_tgid; + u32 tgid = pid_tgid >> 32; + + if (!(THREAD_FILTER)) + return 0; + + u64 timestamp = bpf_ktime_get_ns(); + u64 uaddr64 = (u64) uaddr; + pid_lock.update(&pid, &uaddr64); + pid_blocktime.update(&pid, ×tamp); + + if (SHOULD_PRINT) + bpf_trace_printk("enter sys_futex, pid = %u, uaddr = %x, " + "cmd = %u\\n", pid, uaddr64, cmd); + return 0; +} + +int sys_futex_exit(struct pt_regs *ctx) { + u64 pid_tgid = bpf_get_current_pid_tgid(); + u32 pid = pid_tgid; + u32 tgid = pid_tgid >> 32; + if (!(THREAD_FILTER)) + return 0; + + u64 *blocktime = pid_blocktime.lookup(&pid); + u64 *uaddr = pid_lock.lookup(&pid); + u64 timestamp = bpf_ktime_get_ns(); + u64 elapsed; + + if (blocktime == 0 || uaddr == 0) + return 0; // not FUTEX_WAIT, or (less likely) missed futex_enter + + elapsed = timestamp - *blocktime; + update_stats(pid, tgid, *uaddr, elapsed); + pid_lock.delete(&pid); + pid_blocktime.delete(&pid); + + if (SHOULD_PRINT) { + bpf_trace_printk("exit sys_futex, uaddr = %x, elapsed = %uns\\n", + uaddr == 0 ? 0 : *uaddr, elapsed); + } + return 0; +} + +""" + +bpf_source = bpf_source.replace("SHOULD_PRINT", "1" if trace_all else "0") + +thread_filter = '1' +if pid != -1: + print("Tracing pid %d, Ctrl+C to quit." % pid) + # 'tgid' in kernel space is what people thin of as 'pid' in userspace + thread_filter = "tgid == %d" % pid +else: + print("Tracing all processes, Ctrl+C to quit.") + +bpf_source = bpf_source.replace("THREAD_FILTER", thread_filter) + +bpf_program = BPF(text=bpf_source) +bpf_program.attach_kprobe(event="SyS_futex", fn_name="sys_futex_enter") +bpf_program.attach_kretprobe(event="SyS_futex", fn_name="sys_futex_exit") + +def create_tgid_stats(): + stats = bpf_program["lock_stats"] + res = {} + for key, val in stats.items(): + if not key.tgid in res: + res[key.tgid] = {} + if not key.uaddr in res[key.tgid]: + res[key.tgid][key.uaddr] = Lock() + lock = res[key.tgid][key.uaddr] + lock.update(val.contention_count, val.elapsed_blocked) + return res + +def print_comm_stats(stats): + comms = bpf_program["tgid_comm"] + print("\n%s:" % (datetime.now().strftime("%H:%M:%S"))) + for tgid, locks in stats.items(): + comm = comms[c_int(tgid)].name + print("\n %s (%d):" % (comm, tgid)) + sorted_locks = sorted(locks.items(), + key=lambda x: x[1].elapsed_blocked, + reverse=True) + for addr, stats in sorted_locks: + print(" %x: %dms (%d contentions involving %d threads, avg %dus)" % + (addr, stats.elapsed_blocked / 1000000, + stats.contention_count, stats.thread_count, + stats.elapsed_blocked / stats.contention_count / 1000)) + +count_so_far = 0 +while True: + if trace_all: + print(bpf_program.trace_fields()) + else: + try: + sleep(interval) + except KeyboardInterrupt: + exit() + print_comm_stats(create_tgid_stats()) + count_so_far += 1 + bpf_program['tgid_comm'].clear() + bpf_program['lock_stats'].clear() + bpf_program['pid_lock'].clear() + bpf_program['pid_blocktime'].clear() + + if num_prints is not None and count_so_far >= num_prints: + exit() -- cgit v1.2.3 From bb0952ac237e867c1b562caa040d9306759523ac Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Tue, 10 Jul 2018 19:21:28 -0700 Subject: lockstat: Filter for only Android monitor locks Signed-off-by: Joel Fernandes --- bcc/misc/lockstat.py | 67 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 59 insertions(+), 8 deletions(-) mode change 100755 => 100644 bcc/misc/lockstat.py diff --git a/bcc/misc/lockstat.py b/bcc/misc/lockstat.py old mode 100755 new mode 100644 index fb1edbe..fa3edda --- a/bcc/misc/lockstat.py +++ b/bcc/misc/lockstat.py @@ -1,4 +1,4 @@ -#!/usr/bin/env bcc-py +#!/usr/bin/python # # lockstat Trace and display lock contention stats # @@ -15,23 +15,24 @@ import argparse import subprocess import os +# One Lock object per TGID and uaddr. class Lock(object): def __init__(self): self.contention_count = 0 self.elapsed_blocked = 0 self.thread_count = 0 + self.last_stack_syms = [] - def update(self, count, block_time): + def update(self, count, block_time, last_stack_syms): self.contention_count += count self.elapsed_blocked += block_time self.thread_count += 1 + self.last_stack_syms = last_stack_syms def run_command_get_pid(command): p = subprocess.Popen(command.split()) return p.pid - - examples = """ EXAMPLES: @@ -103,15 +104,16 @@ struct lock_key_t { struct lock_info_t { u64 elapsed_blocked; u64 contention_count; + u64 sid; }; - BPF_HASH(pid_lock, u32, u64); BPF_HASH(pid_blocktime, u32, u64); BPF_HASH(tgid_comm, u32, struct comm_t); BPF_HASH(lock_stats, struct lock_key_t, struct lock_info_t, 1000000); +BPF_STACK_TRACE(stack_traces, 16384); -static inline int update_stats(u32 pid, u32 tgid, u64 uaddr, u64 block_time) { +static inline int update_stats(u32 pid, u32 tgid, u64 uaddr, u64 block_time, u64 sid) { struct lock_key_t key = {}; struct lock_info_t zero = {}; struct lock_info_t *info; @@ -122,6 +124,7 @@ static inline int update_stats(u32 pid, u32 tgid, u64 uaddr, u64 block_time) { info = lock_stats.lookup_or_init(&key, &zero); info->elapsed_blocked += block_time; info->contention_count++; + info->sid = sid; if (0 == tgid_comm.lookup(&tgid)) { struct comm_t comm; @@ -168,12 +171,15 @@ int sys_futex_exit(struct pt_regs *ctx) { u64 *uaddr = pid_lock.lookup(&pid); u64 timestamp = bpf_ktime_get_ns(); u64 elapsed; + u64 sid; if (blocktime == 0 || uaddr == 0) return 0; // not FUTEX_WAIT, or (less likely) missed futex_enter elapsed = timestamp - *blocktime; - update_stats(pid, tgid, *uaddr, elapsed); + + sid = stack_traces.get_stackid(ctx, BPF_F_USER_STACK); + update_stats(pid, tgid, *uaddr, elapsed, sid); pid_lock.delete(&pid); pid_blocktime.delete(&pid); @@ -202,19 +208,58 @@ bpf_program = BPF(text=bpf_source) bpf_program.attach_kprobe(event="SyS_futex", fn_name="sys_futex_enter") bpf_program.attach_kretprobe(event="SyS_futex", fn_name="sys_futex_exit") +def get_syms(stack, pid): + global bpf_program + syms = [] + for addr in stack: + s = bpf_program.sym(addr, pid, show_offset=True) + syms.append(s) + return syms + +def print_syms(syms): + print("=========") + for f in syms: + print(f) + print("=========") + +def is_android_monitor_lock(syms): + for s in syms: + if 'art::Monitor::Lock' in s: + return True + return False + +def disp_stack(stack, pid): + for addr in stack: + s = bpf_program.sym(addr, pid, show_offset=True) + def create_tgid_stats(): + global bpf_program stats = bpf_program["lock_stats"] res = {} + stack_traces = bpf_program['stack_traces'] for key, val in stats.items(): + # Only display Android monitor locks + if val.sid >= 0: + ust = stack_traces.walk(val.sid) + syms = get_syms(ust, key.pid) + if not is_android_monitor_lock(syms): + continue + else: + continue + if not key.tgid in res: res[key.tgid] = {} if not key.uaddr in res[key.tgid]: res[key.tgid][key.uaddr] = Lock() + lock = res[key.tgid][key.uaddr] - lock.update(val.contention_count, val.elapsed_blocked) + lock.update(val.contention_count, val.elapsed_blocked, syms) return res def print_comm_stats(stats): + if stats == {}: + return + comms = bpf_program["tgid_comm"] print("\n%s:" % (datetime.now().strftime("%H:%M:%S"))) for tgid, locks in stats.items(): @@ -229,6 +274,12 @@ def print_comm_stats(stats): stats.contention_count, stats.thread_count, stats.elapsed_blocked / stats.contention_count / 1000)) + # No use of displaying lock stacks since we're only + # filtering for Android monitor locks. + # + # print("Last stack for this lock:") + # print_syms(stats.last_stack_syms) + count_so_far = 0 while True: if trace_all: -- cgit v1.2.3 From 7196a4e6a795143fa6553ee8563460cf80f8d8ae Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Tue, 10 Jul 2018 21:25:13 -0700 Subject: run: mount devpts for ssh to work Signed-off-by: Joel Fernandes --- addons/run.common | 3 +++ 1 file changed, 3 insertions(+) diff --git a/addons/run.common b/addons/run.common index 1ef22aa..e5189b9 100644 --- a/addons/run.common +++ b/addons/run.common @@ -1,7 +1,10 @@ do_mounts() { mount --bind /proc debian/proc/ > /dev/null + mount --bind /dev debian/dev/ > /dev/null + mount --bind /dev/pts debian/dev/pts > /dev/null + mount --bind /sys debian/sys/ > /dev/null mount --bind /sys/kernel/debug/ debian/sys/kernel/debug/ > /dev/null mount --bind /sys/kernel/debug/tracing/ debian/sys/kernel/debug/tracing/ -- cgit v1.2.3 From 6975db2ce21f88db0dca0a659fb13b774281a60c Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Wed, 11 Jul 2018 20:53:16 -0700 Subject: androdeb: reduce number of options A big rewrite to simplify the options. Now providing a "minimal" FS for a basic install with just apt, networking tools, etc. And a "full" FS with BCC included. Signed-off-by: Joel Fernandes --- BCC.md | 8 +++++++- README.md | 36 +++++++++++++++++++--------------- androdeb | 63 +++++++++++++++++++++++++++++++++++------------------------ buildstrap | 3 ++- utils/banners | 47 +++++++++++++++++++++++++++++--------------- 5 files changed, 97 insertions(+), 60 deletions(-) diff --git a/BCC.md b/BCC.md index 9042361..8995747 100644 --- a/BCC.md +++ b/BCC.md @@ -65,8 +65,14 @@ recommend dropping the `--download` option from the adeb command above. This will make androdeb clone and build the latest version of BCC for the target architecture. Note that this is much slower that `--download`. ``` -adeb prepare --bcc --kernelsrc /path/to/kernel-source/ +adeb prepare --build --bcc --kernelsrc /path/to/kernel-source/ ``` +Note that the full androdeb install already contains recent BCC: +``` +adeb prepare --full +``` +This downloads and installs a prebuilt FS and is faster than building locally +using `--build`. Other Architectures (other than ARM64) ----------------------- diff --git a/README.md b/README.md index 293669b..a4b7d1a 100644 --- a/README.md +++ b/README.md @@ -54,10 +54,15 @@ sudo ln -s $(pwd)/adeb /usr/bin/adeb sudo ln -s $(pwd)/androdeb /usr/bin/androdeb ``` -* Fastest way of installing adeb onto your device: +* Installing adeb onto your device: ``` # First make sure device is connected to system -adeb prepare --download +# Then run, for the base image: +adeb prepare +``` +# The previous command only downloads and installs the base image. +# Instead if you want to download and install the full image, do: +adeb prepare --full ``` * Now run adeb shell to enter your new environment!: @@ -87,7 +92,7 @@ More advanced usage instructions -------------------------------- ### Install kernel headers in addition to preparing androdeb device: ``` -adeb prepare --download --kernelsrc /path/to/kernel-source +adeb prepare --kernelsrc /path/to/kernel-source ``` ### Update kernel headers onto an already prepared device: @@ -102,31 +107,30 @@ Note: The kernel sources should have been built (atleast build should have start The androdeb fs will be prepared locally by downloading packages as needed: ``` -adeb prepare --fullbuild +adeb prepare --build ``` -This is unlike `--download` where the androdeb rootfs is itself pulled from the web. +This is unlike the default behavior, where the androdeb rootfs is itself pulled from the web. -### Add kernel headers to device in addition to building locally: +If you wish to do a full build (that is locally prepare a rootfs with all packages, including bcc, then do): ``` -adeb prepare --fullbuild --kernelsrc /path/to/kernel-source/ +adeb prepare --full --build ``` -### Instead of `--fullbuild`, customize what you install: +### Add kernel headers to device in addition to building locally: ``` -adeb prepare --editors --compilers +adeb prepare --build --kernelsrc /path/to/kernel-source/ ``` -### Install only BCC: +### Build/install a base image with BCC: ``` -adeb prepare --bcc --kernelsrc /path/to/kernel-source/ +adeb prepare --build --bcc --kernelsrc /path/to/kernel-source/ ``` -Note: BCC is built while being installed. Also `--kernelsrc` is -recommended for tools to function unless device has them -already. +Note: BCC is built from source. Also `--kernelsrc` is recommended for tools to +function unless device has them already. ### Extract the FS from the device, after its prepared: ``` -adeb prepare --fullbuild --buildtar /path/ +adeb prepare --buildtar /path/ ``` After device is prepared, it will extract the root fs from it and store it as a tar archive at `/path/androdeb-fs.tgz`. This @@ -149,7 +153,7 @@ By default androdeb assumes the target Android device is based on ARM64 processor architecture. For other architectures, use the --arch option. For example for x86_64 architecture, run: ``` -adeb prepare --arch amd64 --bcc --kernelsrc /path/to/kernel-source/ +adeb prepare --build --arch amd64 --bcc --kernelsrc /path/to/kernel-source/ ``` Note: The --download option ignores the --arch flag. This is because we only provide pre-built filesystems for ARM64 at the moment. diff --git a/androdeb b/androdeb index 5d9a2ce..6ecfa54 100755 --- a/androdeb +++ b/androdeb @@ -13,12 +13,14 @@ source $spath/utils/banners # Set default vars DISTRO=buster; ARCH=arm64 ADB="adb" +FULL=0 # Default to a minimal install +DOWNLOAD=1 # Default to downloading from web SKIP_DEVICE=0 # Skip device preparation INSTALL_BCC=0 # Decide if BCC is to be installed # Default packages -DEFAULT_PACKAGES+="bash -ca-certificates" +PACKAGES="" +DEFAULT_PACKAGES="bash ca-certificates apt net-tools iputils-ping procps vim" EXTRA_FILES="none" @@ -41,26 +43,22 @@ if [ "x$ASHELL" == "x1" ]; then fi case $key in - prepare) PREPARE=1; shift || true; ;; shell) ASHELL=1; shift || true; ;; remove) REMOVE=1; shift || true; ;; git-pull) GIT_PULL=1; shift || true; ;; pull) PULL=1; shift || true; break ;; push) PUSH=1; shift || true; break ;; + prepare) PREPARE=1; shift || true; ;; + --full) FULL=1; config_full_build; shift || true; ;; --arch) ARCH=$2; shift || true; shift || true; ;; --archive) TARF=$2; shift || true; shift || true; ;; - --tracers) source $spath/packages/tracers; shift || true; ;; - --compilers) source $spath/packages/compilers; shift || true; ;; - --editors) source $spath/packages/editors; shift || true; ;; - --scheduler) source $spath/packages/scheduler; shift || true; ;; - --fullbuild) config_full_build; shift || true; ;; - --download) DOWNLOAD=1; shift || true; ;; --bcc) source $spath/packages/bcc; shift || true; ;; --kernelsrc) KERNELSRC="$2"; shift || true; shift || true; ;; --skip-install) SKIP_INSTALL=1; shift || true; ;; --kernel-headers-targz) KERNELHDRS=$2; shift || true; shift || true; ;; --tempdir) TDIR="$2"; shift || true; shift || true; ;; - --buildtar) BTAR=1; TARDIR="$2"; shift || true; shift || true; ;; + --build) DOWNLOAD=0; shift || true; ;; + --buildtar) BTAR=1; DOWNLOAD=0; TARDIR="$2"; shift || true; shift || true; ;; --device|-s) ADB="$ADB -s $2"; shift || true; shift || true; ;; --build-image) BI=1; BUILD_IMAGEF=$2; SKIP_DEVICE=1; shift || true; shift || true; ;; --debug) set -x; shift || true; ;; @@ -70,6 +68,14 @@ done [ -z $ASHELL ] && box_out "adeb: $VERSION" +if [ $FULL -eq 1 ]; then + FNAME=androdeb-fs.tgz.zip + FNAME_UZ=androdeb-fs.tgz +else + FNAME=androdeb-fs-minimal.tgz.zip + FNAME_UZ=androdeb-fs-minimal.tgz +fi + if [ ! -z $BTAR ] && [ -z $TARDIR ]; then TARDIR=$spath fi @@ -112,11 +118,6 @@ if [ ! -z "$PUSH" ]; then exit 0 fi -if [ -z "$ASHELL" ] && [ -z "$REMOVE" ] && [ -z "$PACKAGES" ]; then - c_info "No packages specified, so I'm going to build/install all packages (--fullbuild)" - config_full_build -fi - if [[ ! -z ${TARDIR+x} ]] && [[ ! -d $TARDIR ]]; then die 7 "Tar dir specified doesn't exist"; fi if [ -z $BI ]; then @@ -198,7 +199,7 @@ function push_unpack_tarred_headers() { } function all_done_banner() { - c_info "All done! Run \"androdeb shell\" to enter environment" + c_info "All done! Run \"adeb shell\" to enter environment" } # Prepare is the last command checked @@ -218,12 +219,14 @@ MKTEMP=0; if [[ -z ${TDIR+x} ]] || [[ ! -d "${TDIR}" ]]; then rm -rf $TDIR/* TDIR_ABS=$( cd "$TDIR" ; pwd -P ) -if [ ! -z "$DOWNLOAD" ]; then +if [ $DOWNLOAD -eq 1 ]; then c_info "Downloading Androdeb from the web..."; c_info "" + # Github dropped tar gz support! ##?#??#! Now we've to zip everything. - curl -L https://github.com/joelagnel/androdeb/releases/download/$VERSION/androdeb-fs.tgz.zip --output $TDIR_ABS/androdeb-fs.tgz.zip; - unzip -e $TDIR_ABS/androdeb-fs.tgz.zip -d $TDIR_ABS/ - TARF=$TDIR_ABS/androdeb-fs.tgz; fi + curl -L https://github.com/joelagnel/androdeb/releases/download/$VERSION/$FNAME --output $TDIR_ABS/$FNAME + unzip -e $TDIR_ABS/$FNAME -d $TDIR_ABS/ + TARF=$TDIR_ABS/$FNAME_UZ +fi OUT_TMP=$TDIR/debian; rm -rf $OUT_TMP; mkdir -p $OUT_TMP @@ -312,13 +315,21 @@ if [ $INSTALL_BCC -eq 1 ]; then $ADB shell /data/androdeb/run-command /bcc-master/build-bcc.sh; fi -do_cleanup - # Extract a tar of the built, compiled and installed androdeb env if [[ ! -z ${TARDIR+x} ]]; then - c_info "Creating and pulling tarball of androdeb env from device" - $ADB shell /data/androdeb/build-debian-tar - $ADB pull /data/androdeb/androdeb-fs.tgz $TARDIR/ - $ADB shell rm /data/androdeb/androdeb-fs.tgz; fi + c_info "Creating tarball" + pushd $TARDIR + if [ $INSTALL_BCC -eq 0 ]; then + mv $TDIR/deb.tar.gz $FNAME_UZ + else + $ADB shell /data/androdeb/build-debian-tar + $ADB pull /data/androdeb/androdeb-fs.tgz $FNAME_UZ + $ADB shell rm /data/androdeb/androdeb-fs.tgz; + fi + zip -r $FNAME $FNAME_UZ + popd +fi + +do_cleanup all_done_banner diff --git a/buildstrap b/buildstrap index b046d20..0aaa635 100755 --- a/buildstrap +++ b/buildstrap @@ -12,8 +12,9 @@ PACKAGES=$5 EXTRA_FILES="$(cat $6)" INSTALL_BCC=$7 SKIP_DEVICE=$8 # Skip any device-specific stages +VARIANT="--variant=minbase" -time qemu-debootstrap --arch $ARCH --include=$PACKAGES \ +time qemu-debootstrap --arch $ARCH --include=$PACKAGES $VARIANT \ $DISTRO $OUT_TMP http://deb.debian.org/debian/ # Some reason debootstrap leaves these mounted diff --git a/utils/banners b/utils/banners index 491d324..5f975bc 100755 --- a/utils/banners +++ b/utils/banners @@ -2,6 +2,11 @@ print_prepare_banner() { c_info "Preparing device..." + if [ $FULL -eq 1 ]; then + c_info "Doing a full install." + else + c_info "Doing a base install." + fi c_info "" } @@ -15,29 +20,39 @@ usage() { c_info " push Copy files to the androdeb filesystem in the device" c_info "" c_info " prepare Prepare the device (when running for the first time)" - c_info " --tracers Enable tracing packages (perf and trace-cmd)" - c_info " --compilers Enable compilers on the FS (gcc and clang)" - c_info " --editors Enable vim, emacs and git packages" - c_info " --scheduler scheduler testing tools (only rt-app for now)" + c_info " By default, this will download and install a base image." + c_info " ** Folowing are the prepare options **" + c_info " --full Pass this to prepare to download and install the full image which" + c_info " contains compilers, editors, tracers etc." c_info "" - c_info " --fullbuild Enable all of the above tools (no BCC)" + c_info " --build Instead of download, build and install the image onto the device" c_info "" - c_info " --download Download full FS archive from web (overrides all tools specified)" - c_info " --archive Use archive for root fs (overrides all other prepare options)" - c_info " --build-image Build an ext4 .img with the base image and BCC (useful for Qemu)" + c_info " --archive Use archive for root fs (overrides all other prepare options)" c_info "" - c_info " --bcc Build and install BCC from source" - c_info " --kernelsrc Extract kernel headers for BCC from here" - c_info " --skip-install Pass this along if only header install is needed" + c_info " --buildtar While preparing, also build a tar.gz.zip file of the filesystem," + c_info " this is how images that are downloaded by prepare are built" c_info "" - c_info " --tempdir Use a specific temporary directory for build operation" - c_info " --buildtar Local directory to store tarball of androdeb env from device" - c_info " --distro Debian distro to base on (default is buster)" + c_info " --build-image Build an ext4 .img with the base image and BCC (useful for Qemu)" + c_info "" + c_info " ** Folowing are misc build options **" + c_info " --tempdir Use a specific temporary directory for build operation" + c_info " --arch Specify an ARCH to build for (default arm64)" + c_info " --distro Debian distro to base on (default is buster)" + c_info "" + c_info " ** Folowing are the options for BCC **" + c_info " --bcc Build and install BCC onto the device, from source" + c_info " BCC is already included in 'prepare --full'" + c_info "" + c_info " --kernelsrc Extract kernel headers for BCC from this directory" + c_info "" + c_info " --skip-install Pass this to --kernelsrc if you wish to only extra/install kernel headers" + c_info " and would like to exit after that (skips build/install of everything else)" + c_info "" + c_info " ** Folowing are device specific options ** " c_info " --device Serial number of adb device." c_info " -s Serial number of adb device." c_info "" - c_info " --debug" - c_info " --arch Specify an ARCH to build for (default arm64)" + c_info " --debug Debug all execution." exit 1 } -- cgit v1.2.3 From b97601fb8c1c4ef5b777d80120621955db3ddaeb Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Wed, 11 Jul 2018 20:56:39 -0700 Subject: update README Signed-off-by: Joel Fernandes --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a4b7d1a..cb1dc5c 100644 --- a/README.md +++ b/README.md @@ -60,8 +60,9 @@ sudo ln -s $(pwd)/androdeb /usr/bin/androdeb # Then run, for the base image: adeb prepare ``` -# The previous command only downloads and installs the base image. -# Instead if you want to download and install the full image, do: +The previous command only downloads and installs the base image. +Instead if you want to download and install the full image, do: +``` adeb prepare --full ``` -- cgit v1.2.3 From 161819971d783b805a07a0766acaec1711c58e2d Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Wed, 11 Jul 2018 20:59:08 -0700 Subject: update README Signed-off-by: Joel Fernandes --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cb1dc5c..e750874 100644 --- a/README.md +++ b/README.md @@ -55,9 +55,9 @@ sudo ln -s $(pwd)/androdeb /usr/bin/androdeb ``` * Installing adeb onto your device: +First make sure device is connected to system +Then run, for the base image: ``` -# First make sure device is connected to system -# Then run, for the base image: adeb prepare ``` The previous command only downloads and installs the base image. @@ -144,7 +144,7 @@ adeb prepare --archive /path/androdeb-fs.tgz ### Build a standalone raw EXT4 image out of the FS: ``` -adeb prepare --buildimage /path/to/image.img +adeb prepare --build-image /path/to/image.img ``` This can then be passed to Qemu as -hda. Note: This option doesn't need a device connected. -- cgit v1.2.3 From dc8805f3c89822a41b94c141237fd364f8052a90 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Wed, 11 Jul 2018 21:01:55 -0700 Subject: update README Signed-off-by: Joel Fernandes --- BCC.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BCC.md b/BCC.md index 8995747..b6fdf81 100644 --- a/BCC.md +++ b/BCC.md @@ -24,7 +24,7 @@ source and the sources should be built atleast once in-tree. Once it is built, run the following command pointing androdeb to the kernel sources which will have it extract headers from there and push them to the device. ``` -adeb prepare --download --bcc --kernelsrc /path/to/kernel-source/ +adeb prepare --build --bcc --kernelsrc /path/to/kernel-source/ ``` This downloads and installs a pre-built androdeb filesystem containing a recent version of BCC onto the android device, extracts kernel headers from the source -- cgit v1.2.3 From 0dee97368d7493ebdd87c261d45450c666489118 Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Mon, 16 Jul 2018 18:45:30 -0700 Subject: License as Apache 2.0 Signed-off-by: Joel Fernandes (Google) --- LICENSE | 541 ++++++++++++++++++++++++---------------------------------------- 1 file changed, 202 insertions(+), 339 deletions(-) diff --git a/LICENSE b/LICENSE index d159169..d645695 100644 --- a/LICENSE +++ b/LICENSE @@ -1,339 +1,202 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. -- cgit v1.2.3 From ac628747a3ade454f5abc19630d987ad21ab3590 Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Mon, 16 Jul 2018 18:55:40 -0700 Subject: Rename certain places to adeb Signed-off-by: Joel Fernandes (Google) --- BCC.md | 22 +++++++++++----------- README.md | 41 ++++++++++++++++++++--------------------- androdeb | 2 +- 3 files changed, 32 insertions(+), 33 deletions(-) diff --git a/BCC.md b/BCC.md index b6fdf81..9df3b29 100644 --- a/BCC.md +++ b/BCC.md @@ -13,28 +13,28 @@ documentation. Quick Start ----------- -androdeb is the primary vehicle for running BCC on Android. It supports +adeb is the primary vehicle for running BCC on Android. It supports preparing the target Android device with necessary kernel headers, cloning and -building BCC on device, and other setup. Take a look a quick look at [androdeb -README](https://github.com/joelagnel/androdeb/blob/master/README.md) so that +building BCC on device, and other setup. Take a look a quick look at [adeb +README](https://github.com/joelagnel/adeb/blob/master/README.md) so that you're familiar with what it is. For setting up BCC on your Android device, you need the target device's kernel source and the sources should be built atleast once in-tree. Once it is built, -run the following command pointing androdeb to the kernel sources which will +run the following command pointing adeb to the kernel sources which will have it extract headers from there and push them to the device. ``` adeb prepare --build --bcc --kernelsrc /path/to/kernel-source/ ``` -This downloads and installs a pre-built androdeb filesystem containing a recent +This downloads and installs a pre-built adeb filesystem containing a recent version of BCC onto the android device, extracts kernel headers from the source tree pointed to and does other setup. Note that `--download` option will work only if the target architecture is ARM64. For other architectures, see the [Other Architectures -section](https://github.com/joelagnel/androdeb/blob/master/BCC.md#other-architectures-other-than-arm64) +section](https://github.com/joelagnel/adeb/blob/master/BCC.md#other-architectures-other-than-arm64) Now to run BCC, just start an adeb shell: `adeb shell`. This uses adb -as the backend to start a shell into your androdeb environment. Try running +as the backend to start a shell into your adeb environment. Try running `opensnoop` or any of the other BCC tracers to confirm that the setup worked correctly. @@ -58,16 +58,16 @@ CONFIG_DEBUG_PREEMPT=y CONFIG_PREEMPTIRQ_EVENTS=y ``` -Build BCC during androdeb install (Optional) +Build BCC during adeb install (Optional) -------------------------------------------- If you would like the latest BCC installation on your Android device, we recommend dropping the `--download` option from the adeb command above. -This will make androdeb clone and build the latest version of BCC for the +This will make adeb clone and build the latest version of BCC for the target architecture. Note that this is much slower that `--download`. ``` adeb prepare --build --bcc --kernelsrc /path/to/kernel-source/ ``` -Note that the full androdeb install already contains recent BCC: +Note that the full adeb install already contains recent BCC: ``` adeb prepare --full ``` @@ -76,7 +76,7 @@ using `--build`. Other Architectures (other than ARM64) ----------------------- -By default androdeb assumes the target Android device is based on ARM64 +By default adeb assumes the target Android device is based on ARM64 processor architecture. For other architectures, use the --arch option. For example for x86_64 architecture, run: ``` diff --git a/README.md b/README.md index e750874..9f326e2 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -androdeb +adeb -------- -**androdeb** (also known as **adeb**) provides a powerful Linux shell +**adeb** (also known as **androdeb**) provides a powerful Linux shell environment where one can run popular and mainstream Linux tracing, compiling, editing and other development tools on an existing Android device. All the commands typically available on a modern Linux system are supported in -androdeb. +adeb. Usecases -------- @@ -20,12 +20,12 @@ from the web. 3. Using these one can run popular tools such as BCC that are difficult to run in an Android environment due to lack of packages, dependencies and cross-compilation needed for their operation. [Check BCC on Android using -androdeb](https://github.com/joelagnel/androdeb/blob/master/BCC.md) for more +adeb](https://github.com/joelagnel/adeb/blob/master/BCC.md) for more information on that. 4. No more crippled tools: Its often a theme to build a static binary with features disabled, because you couldn't cross-compile the feature's dependencies. One -classic example is perf. However, thanks to androdeb, we can build perf natively +classic example is perf. However, thanks to adeb, we can build perf natively on device without having to cripple it. Requirements for running @@ -34,7 +34,7 @@ Target: An ARM64 android N or later device which has "adb root" supported. Typically this is a build in a userdebug configuration. Device should have atleast 2 GB free space in the data partition. If you would like to use other architectures, -see the [Other Architectures](https://github.com/joelagnel/androdeb/blob/master/README.md#how-to-use-androdeb-for-other-architectures-other-than-arm64) section. +see the [Other Architectures](https://github.com/joelagnel/adeb/blob/master/README.md#how-to-use-adeb-for-other-architectures-other-than-arm64) section. Host: A machine running recent Ubuntu or Debian, with 4GB of memory and 4GB free space. @@ -44,14 +44,13 @@ Other distributions may work but they are not tested. Quick Start Instructions ------------------------ -* Clone androdeb repository: +* Clone adeb repository: ``` -git clone https://github.com/joelagnel/androdeb.git -cd androdeb +git clone https://github.com/joelagnel/adeb.git +cd adeb # Add some short cuts: sudo ln -s $(pwd)/adeb /usr/bin/adeb -sudo ln -s $(pwd)/androdeb /usr/bin/androdeb ``` * Installing adeb onto your device: @@ -72,26 +71,26 @@ adeb shell ``` * Once done, hit `CTRL + D` and you will exit out of the shell. -To remove androdeb from the device, run: +To remove adeb from the device, run: ``` adeb remove ``` If you have multiple devices connected, please add `-s `. Serial numbers of all devices connected can be obtained by `adb devices`. -* To update the androdeb you cloned on your host, run: +* To update the adeb you cloned on your host, run: ``` adeb pull ``` -To update an existing androdeb clone on your host, run: +To update an existing adeb clone on your host, run: ``` adeb git-pull ``` More advanced usage instructions -------------------------------- -### Install kernel headers in addition to preparing androdeb device: +### Install kernel headers in addition to preparing adeb device: ``` adeb prepare --kernelsrc /path/to/kernel-source ``` @@ -106,11 +105,11 @@ Note: The kernel sources should have been built (atleast build should have start ### Build and prepare device with a custom rootfs locally: -The androdeb fs will be prepared locally by downloading packages as needed: +The adeb fs will be prepared locally by downloading packages as needed: ``` adeb prepare --build ``` -This is unlike the default behavior, where the androdeb rootfs is itself pulled from the web. +This is unlike the default behavior, where the adeb rootfs is itself pulled from the web. If you wish to do a full build (that is locally prepare a rootfs with all packages, including bcc, then do): ``` @@ -134,12 +133,12 @@ function unless device has them already. adeb prepare --buildtar /path/ ``` After device is prepared, it will extract the root fs from it -and store it as a tar archive at `/path/androdeb-fs.tgz`. This +and store it as a tar archive at `/path/adeb-fs.tgz`. This can be used later. -### Use a previously prepared androdeb rootfs tar from local: +### Use a previously prepared adeb rootfs tar from local: ``` -adeb prepare --archive /path/androdeb-fs.tgz +adeb prepare --archive /path/adeb-fs.tgz ``` ### Build a standalone raw EXT4 image out of the FS: @@ -149,8 +148,8 @@ adeb prepare --build-image /path/to/image.img This can then be passed to Qemu as -hda. Note: This option doesn't need a device connected. -### How to use androdeb for other Architectures (other than ARM64) -By default androdeb assumes the target Android device is based on ARM64 +### How to use adeb for other Architectures (other than ARM64) +By default adeb assumes the target Android device is based on ARM64 processor architecture. For other architectures, use the --arch option. For example for x86_64 architecture, run: ``` diff --git a/androdeb b/androdeb index 6ecfa54..3fcf2dc 100755 --- a/androdeb +++ b/androdeb @@ -223,7 +223,7 @@ if [ $DOWNLOAD -eq 1 ]; then c_info "Downloading Androdeb from the web..."; c_info "" # Github dropped tar gz support! ##?#??#! Now we've to zip everything. - curl -L https://github.com/joelagnel/androdeb/releases/download/$VERSION/$FNAME --output $TDIR_ABS/$FNAME + curl -L https://github.com/joelagnel/adeb/releases/download/$VERSION/$FNAME --output $TDIR_ABS/$FNAME unzip -e $TDIR_ABS/$FNAME -d $TDIR_ABS/ TARF=$TDIR_ABS/$FNAME_UZ fi -- cgit v1.2.3 From 9488c2c6666f8ed1923ba1f62a83ed2e2ddfbcc9 Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Fri, 20 Jul 2018 16:44:26 -0700 Subject: run: bind mount bpf Signed-off-by: Joel Fernandes (Google) --- addons/run.common | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/run.common b/addons/run.common index e5189b9..5c45308 100644 --- a/addons/run.common +++ b/addons/run.common @@ -6,6 +6,7 @@ do_mounts() mount --bind /dev/pts debian/dev/pts > /dev/null mount --bind /sys debian/sys/ > /dev/null + mount --bind /sys/fs/bpf/ debian/sys/fs/bpf/ > /dev/null mount --bind /sys/kernel/debug/ debian/sys/kernel/debug/ > /dev/null mount --bind /sys/kernel/debug/tracing/ debian/sys/kernel/debug/tracing/ -- cgit v1.2.3 From 9ed573a1c76643606082ed0a70d61d663731b9ce Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Wed, 25 Jul 2018 16:07:55 -0700 Subject: Fix adb root error reporting Signed-off-by: Joel Fernandes (Google) --- androdeb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/androdeb b/androdeb index 3fcf2dc..240fb5f 100755 --- a/androdeb +++ b/androdeb @@ -122,6 +122,7 @@ if [[ ! -z ${TARDIR+x} ]] && [[ ! -d $TARDIR ]]; then die 7 "Tar dir specified d if [ -z $BI ]; then [ -z $ASHELL ] && c_info "Looking for device.." + set +e do_adb_root "$ADB" if [ $? -ne 0 ]; then @@ -133,6 +134,7 @@ if [ -z $BI ]; then c_error "packages on your distro, or by installing the Android SDK." die 3 "Exiting." fi + set -e else [ ! -z $BUILD_IMAGEF ] || die 8 "--build-image passed but no image file provided" fi -- cgit v1.2.3 From 387c895c1803006bc6fa7b303c65ee53f8526d63 Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Wed, 25 Jul 2018 16:27:49 -0700 Subject: Disable downloads for archive mode installs Signed-off-by: Joel Fernandes (Google) --- androdeb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/androdeb b/androdeb index 240fb5f..9c7d4a5 100755 --- a/androdeb +++ b/androdeb @@ -51,7 +51,7 @@ case $key in prepare) PREPARE=1; shift || true; ;; --full) FULL=1; config_full_build; shift || true; ;; --arch) ARCH=$2; shift || true; shift || true; ;; - --archive) TARF=$2; shift || true; shift || true; ;; + --archive) DOWNLOAD=0; TARF=$2; shift || true; shift || true; ;; --bcc) source $spath/packages/bcc; shift || true; ;; --kernelsrc) KERNELSRC="$2"; shift || true; shift || true; ;; --skip-install) SKIP_INSTALL=1; shift || true; ;; -- cgit v1.2.3 From db9005f3443de61396189c3803b40f80b79fd2a1 Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Wed, 25 Jul 2018 16:44:12 -0700 Subject: Disable automatic downloads Signed-off-by: Joel Fernandes (Google) --- README.md | 7 +++++++ androdeb | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9f326e2..d4e5655 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,13 @@ cd adeb # Add some short cuts: sudo ln -s $(pwd)/adeb /usr/bin/adeb + +# For cached image downloads which result in a huge speed-up, +# You could set the ADEB_REPO_URL environment variable in your +# bashrc file. +# Disclaimer: Google is not liable for the below URL and this +# is just an example. +export ADEB_REPO_URL="github.com/joelagnel/" ``` * Installing adeb onto your device: diff --git a/androdeb b/androdeb index 9c7d4a5..9d343aa 100755 --- a/androdeb +++ b/androdeb @@ -225,8 +225,18 @@ if [ $DOWNLOAD -eq 1 ]; then c_info "Downloading Androdeb from the web..."; c_info "" # Github dropped tar gz support! ##?#??#! Now we've to zip everything. - curl -L https://github.com/joelagnel/adeb/releases/download/$VERSION/$FNAME --output $TDIR_ABS/$FNAME - unzip -e $TDIR_ABS/$FNAME -d $TDIR_ABS/ + if [ -z $ADEB_REPO_URL ]; then + c_warning "Automatic download is disabled. To enable it, please set the \$ADEB_REPO_URL" + c_warning "environment variable as recommended in the setup instructions in the README.md" + do_cleanup + exit 0 + fi + + curl -L https://$ADEB_REPO_URL/adeb/releases/download/$VERSION/$FNAME --output $TDIR_ABS/$FNAME || + die 9 "Failed to download adeb release." + + unzip -e $TDIR_ABS/$FNAME -d $TDIR_ABS/ || + die 10 "Failed to download adeb release. Double check the ADEB_REPO_URL value." TARF=$TDIR_ABS/$FNAME_UZ fi -- cgit v1.2.3 From a1dd6a85e08e4236760cf2e07598708eb01fb054 Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Wed, 25 Jul 2018 16:47:53 -0700 Subject: Remove github URL from README Signed-off-by: Joel Fernandes (Google) --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index d4e5655..31a57bf 100644 --- a/README.md +++ b/README.md @@ -44,9 +44,8 @@ Other distributions may work but they are not tested. Quick Start Instructions ------------------------ -* Clone adeb repository: +* First clone this repository into adb and cd into it. ``` -git clone https://github.com/joelagnel/adeb.git cd adeb # Add some short cuts: -- cgit v1.2.3 From 619493ccc34afab8965225e5f2338e0e564a9949 Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Wed, 25 Jul 2018 17:08:16 -0700 Subject: add notice Signed-off-by: Joel Fernandes (Google) --- NOTICE | 202 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 NOTICE diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/NOTICE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. -- cgit v1.2.3 From 1052fa71e78d25e09996aeeed03a9a24f2f317b2 Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Wed, 25 Jul 2018 17:08:54 -0700 Subject: add module license Signed-off-by: Joel Fernandes (Google) --- MODULE_LICENSE_APACHE2 | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 MODULE_LICENSE_APACHE2 diff --git a/MODULE_LICENSE_APACHE2 b/MODULE_LICENSE_APACHE2 new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3 From 4ae2a7ca1d08d43e48656f77e388c5b4b2b2974e Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Wed, 25 Jul 2018 17:11:28 -0700 Subject: add metadata Signed-off-by: Joel Fernandes (Google) --- METADATA | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 METADATA diff --git a/METADATA b/METADATA new file mode 100644 index 0000000..90881ff --- /dev/null +++ b/METADATA @@ -0,0 +1,19 @@ +name: "adeb" +description: "adeb (also known as androdeb) provides a powerful Linux shell +environment where one can run popular and mainstream Linux tracing, compiling, +editing and other development tools on an existing Android device. All the +commands typically available on a modern Linux system are supported in adeb." + +third_party { + url { + type: HOMEPAGE + value: "https://github.com/joelagnel/adeb/README.md" + } + url { + type: GIT + value: "https://github.com/joelagnel/adeb.git" + } + version: "v0.99f" + last_upgrade_date { year: 2018 month: 7 day: 25 } + license_type: NOTICE +} -- cgit v1.2.3 From 76e8464685e7e3c5f581bae7f693bdb07ca3babf Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Fri, 27 Jul 2018 20:04:30 -0700 Subject: readme: start a trouble shooting section Signed-off-by: Joel Fernandes (Google) --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 31a57bf..ec81bef 100644 --- a/README.md +++ b/README.md @@ -163,3 +163,8 @@ adeb prepare --build --arch amd64 --bcc --kernelsrc /path/to/kernel-source/ ``` Note: The --download option ignores the --arch flag. This is because we only provide pre-built filesystems for ARM64 at the moment. + +Common Trouble shooting +----------------- +1. Installing g++ with `apt-get install g++` fails. +A. Solution: Run `adeb shell apt-get update` after the `adeb prepare` stage. -- cgit v1.2.3 From 02db2fd65166fb0d5be0fed6b9dcd378dd85b8ff Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Fri, 27 Jul 2018 20:05:17 -0700 Subject: fixup! readme: start a trouble shooting section Signed-off-by: Joel Fernandes (Google) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ec81bef..a324111 100644 --- a/README.md +++ b/README.md @@ -167,4 +167,5 @@ provide pre-built filesystems for ARM64 at the moment. Common Trouble shooting ----------------- 1. Installing g++ with `apt-get install g++` fails. + A. Solution: Run `adeb shell apt-get update` after the `adeb prepare` stage. -- cgit v1.2.3 From 82574e1159e0ff9da765984e4c4289d348d19849 Mon Sep 17 00:00:00 2001 From: ErickReyesR Date: Tue, 31 Jul 2018 00:25:18 -0600 Subject: readme: remove obsolete command description Fixup: adeb pull command was changed in 925a9f5 but the readme file still had the description for the old version of the command. --- README.md | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/README.md b/README.md index a324111..a1aafc2 100644 --- a/README.md +++ b/README.md @@ -84,12 +84,7 @@ adeb remove If you have multiple devices connected, please add `-s `. Serial numbers of all devices connected can be obtained by `adb devices`. -* To update the adeb you cloned on your host, run: -``` -adeb pull -``` - -To update an existing adeb clone on your host, run: +* To update an existing adeb clone on your host, run: ``` adeb git-pull ``` -- cgit v1.2.3 From 511b11e86469697935bc8a799e9f79d56a1cbbbf Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Tue, 31 Jul 2018 16:39:48 -0700 Subject: add README.version Signed-off-by: Joel Fernandes (Google) --- README.version | 1 + 1 file changed, 1 insertion(+) create mode 100644 README.version diff --git a/README.version b/README.version new file mode 100644 index 0000000..598516d --- /dev/null +++ b/README.version @@ -0,0 +1 @@ +https://github.com/joelagnel/adeb/ -- cgit v1.2.3 From de9be0524085b2d52e701765d751ace295d969ae Mon Sep 17 00:00:00 2001 From: Erick Reyes Date: Thu, 2 Aug 2018 20:08:28 -0700 Subject: adeb: add prebuilt headers from Android common kernel One of the biggest hurdles for new users is the need for kernel source code / headers. This is an attempt to provide a working solution (albeit not optimal) by installing prebuilt headers generated by compiling the Android common kernel for arm64 and x86_64 architectures. The headers were obtained form the public repository: https://android.googlesource.com/kernel/common/ Supported versions are 4.9 and 4.14 Signed-off-by: Erick Reyes --- androdeb | 46 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/androdeb b/androdeb index 9d343aa..42a86ec 100755 --- a/androdeb +++ b/androdeb @@ -42,6 +42,8 @@ if [ "x$ASHELL" == "x1" ]; then shift || true; continue fi +KERNEL_HEADERS_NEEDED=0 + case $key in shell) ASHELL=1; shift || true; ;; remove) REMOVE=1; shift || true; ;; @@ -52,7 +54,7 @@ case $key in --full) FULL=1; config_full_build; shift || true; ;; --arch) ARCH=$2; shift || true; shift || true; ;; --archive) DOWNLOAD=0; TARF=$2; shift || true; shift || true; ;; - --bcc) source $spath/packages/bcc; shift || true; ;; + --bcc) source $spath/packages/bcc; KERNEL_HEADERS_NEEDED=1; shift || true; ;; --kernelsrc) KERNELSRC="$2"; shift || true; shift || true; ;; --skip-install) SKIP_INSTALL=1; shift || true; ;; --kernel-headers-targz) KERNELHDRS=$2; shift || true; shift || true; ;; @@ -71,6 +73,7 @@ done if [ $FULL -eq 1 ]; then FNAME=androdeb-fs.tgz.zip FNAME_UZ=androdeb-fs.tgz + KERNEL_HEADERS_NEEDED=1 else FNAME=androdeb-fs-minimal.tgz.zip FNAME_UZ=androdeb-fs-minimal.tgz @@ -204,6 +207,35 @@ function all_done_banner() { c_info "All done! Run \"adeb shell\" to enter environment" } +function check_repo_url () { + if [ -z $ADEB_REPO_URL ]; then + c_warning "Automatic download is disabled. To enable it, please set the \$ADEB_REPO_URL" + c_warning "environment variable as recommended in the setup instructions in the README.md" + do_cleanup + exit 0 + fi +} + +function download_headers() { + KERNEL_MAJOR=`$ADB shell uname -r | cut -d - -f 1 | cut -d . -f 1` + KERNEL_MINOR=`$ADB shell uname -r | cut -d - -f 1 | cut -d . -f 2` + KERNEL_VERSION="$KERNEL_MAJOR.$KERNEL_MINOR" + case $KERNEL_VERSION in + 4.9) PREBUILT_HEADERS_FILE=headers-$ARCH-4.9.114.tar.gz.zip ;; + 4.14) PREBUILT_HEADERS_FILE=headers-$ARCH-4.14.59.tar.gz.zip ;; + *) die 11 "Unsuported kernel version ($KERNEL_VERSION)" ;; + esac + + check_repo_url + + curl -L https://$ADEB_REPO_URL/adeb/releases/download/$VERSION/$PREBUILT_HEADERS_FILE --output $TDIR_ABS/$PREBUILT_HEADERS_FILE || + die 9 "Failed to download kernel headers" + + unzip -e $TDIR_ABS/$PREBUILT_HEADERS_FILE -d $TDIR_ABS/ || + die 10 "Failed to download kernel headers. Double check the ADEB_REPO_URL value." + KERNELHDRS=$TDIR_ABS/`echo "$PREBUILT_HEADERS_FILE" | sed "s/.zip//"` +} + # Prepare is the last command checked if [ -z "$PREPARE" ]; then usage; fi @@ -225,12 +257,7 @@ if [ $DOWNLOAD -eq 1 ]; then c_info "Downloading Androdeb from the web..."; c_info "" # Github dropped tar gz support! ##?#??#! Now we've to zip everything. - if [ -z $ADEB_REPO_URL ]; then - c_warning "Automatic download is disabled. To enable it, please set the \$ADEB_REPO_URL" - c_warning "environment variable as recommended in the setup instructions in the README.md" - do_cleanup - exit 0 - fi + check_repo_url curl -L https://$ADEB_REPO_URL/adeb/releases/download/$VERSION/$FNAME --output $TDIR_ABS/$FNAME || die 9 "Failed to download adeb release." @@ -240,6 +267,11 @@ if [ $DOWNLOAD -eq 1 ]; then TARF=$TDIR_ABS/$FNAME_UZ fi +if [ ! -z "$KERNEL_HEADERS_NEEDED" ] && [ -z "$KERNELSRC" ] && [ -z "$KERNELHDRS"]; then + c_info "Kernel headers are needed but none were provided. Downloading pre-built headers" + download_headers +fi + OUT_TMP=$TDIR/debian; rm -rf $OUT_TMP; mkdir -p $OUT_TMP # Unpack the supplied kernel headers tar.gz directly into androdeb root -- cgit v1.2.3 From 97f031b846ae159db919c211b0c94f86c75aebcb Mon Sep 17 00:00:00 2001 From: Joel Date: Sun, 5 Aug 2018 05:51:54 -0700 Subject: Update README.version --- README.version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.version b/README.version index 598516d..3b30f4a 100644 --- a/README.version +++ b/README.version @@ -1 +1 @@ -https://github.com/joelagnel/adeb/ +URL: https://github.com/joelagnel/adeb/ -- cgit v1.2.3 From 540df09d9e69d9e59963c619e0683e6f2852e965 Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Thu, 16 Aug 2018 13:25:30 -0700 Subject: Remove merged BCC patches Signed-off-by: Joel Fernandes (Google) --- addons/bashrc.common | 2 +- ...OT-MERGE-Remove-version-override-warnings.patch | 26 -------- ...ang-Allow-user-to-override-kernel-version.patch | 74 ---------------------- 3 files changed, 1 insertion(+), 101 deletions(-) delete mode 100644 bcc/misc/0001-DONOT-MERGE-Remove-version-override-warnings.patch delete mode 100644 bcc/misc/0001-clang-Allow-user-to-override-kernel-version.patch diff --git a/addons/bashrc.common b/addons/bashrc.common index 75cae9e..f357b6f 100644 --- a/addons/bashrc.common +++ b/addons/bashrc.common @@ -23,5 +23,5 @@ fi # Override kernel version if we haven't found headers with them. # Needed for BCC to work on slightly mismatched kernels. if [ $override_vers -eq 1 ]; then - export LINUX_VERSION_CODE_OVERRIDE=$this_vers + export BCC_LINUX_VERSION_CODE=$this_vers fi diff --git a/bcc/misc/0001-DONOT-MERGE-Remove-version-override-warnings.patch b/bcc/misc/0001-DONOT-MERGE-Remove-version-override-warnings.patch deleted file mode 100644 index 7ed6dc7..0000000 --- a/bcc/misc/0001-DONOT-MERGE-Remove-version-override-warnings.patch +++ /dev/null @@ -1,26 +0,0 @@ -From 2d4a9cd04dbfa20f460b8147d03936aa97768158 Mon Sep 17 00:00:00 2001 -From: Joel Fernandes -Date: Sun, 8 Jul 2018 23:07:19 -0700 -Subject: [PATCH] DONOT MERGE: Remove version override warnings - -Signed-off-by: Joel Fernandes ---- - src/cc/frontends/clang/loader.cc | 2 -- - 1 file changed, 2 deletions(-) - -diff --git a/src/cc/frontends/clang/loader.cc b/src/cc/frontends/clang/loader.cc -index 81e429032551..53250f426547 100755 ---- a/src/cc/frontends/clang/loader.cc -+++ b/src/cc/frontends/clang/loader.cc -@@ -179,8 +179,6 @@ int ClangLoader::parse(unique_ptr *mod, TableStorage &ts, - if (version_override) { - vmacro = "-DLINUX_VERSION_CODE_OVERRIDE=" + string(version_override); - -- std::cout << "WARNING: Linux version for eBPF program is being overridden with: " << version_override << "\n"; -- std::cout << "WARNING: Due to this, the results of the program may be unpredictable\n"; - flags_cstr_rem.push_back(vmacro.c_str()); - } - --- -2.18.0.203.gfac676dfb9-goog - diff --git a/bcc/misc/0001-clang-Allow-user-to-override-kernel-version.patch b/bcc/misc/0001-clang-Allow-user-to-override-kernel-version.patch deleted file mode 100644 index 13bd369..0000000 --- a/bcc/misc/0001-clang-Allow-user-to-override-kernel-version.patch +++ /dev/null @@ -1,74 +0,0 @@ -From aab6e5f524e783fda038c53b04a7a06531797bfd Mon Sep 17 00:00:00 2001 -From: Joel Fernandes -Date: Sun, 8 Jul 2018 22:55:29 -0700 -Subject: [PATCH] clang: Allow user to override kernel version - -BCC currently requires exactly matching headers. Sometimes this is quite -inconvenient especially if the kernel version is only very slightly -different such as updates in a stable kernel. This patch gives the user -the flexibility to override the the LINUX_VERSION_CODE provided in the -linux kernel headers, so that the eBPF program may load. We also print a -message when this is done, so that the user is warned about the override -happening and that results may be unpredictable. - -Signed-off-by: Joel Fernandes ---- - src/cc/export/helpers.h | 4 ++++ - src/cc/frontends/clang/loader.cc | 11 +++++++++++ - 2 files changed, 15 insertions(+) - mode change 100644 => 100755 src/cc/export/helpers.h - mode change 100644 => 100755 src/cc/frontends/clang/loader.cc - -diff --git a/src/cc/export/helpers.h b/src/cc/export/helpers.h -old mode 100644 -new mode 100755 -index a05a9f740603..e4af0bcdd1f5 ---- a/src/cc/export/helpers.h -+++ b/src/cc/export/helpers.h -@@ -224,7 +224,11 @@ struct _name##_table_t _name = { .max_entries = (_max_entries) } - - char _license[4] SEC("license") = "GPL"; - -+#ifdef LINUX_VERSION_CODE_OVERRIDE -+unsigned _version SEC("version") = LINUX_VERSION_CODE_OVERRIDE; -+#else - unsigned _version SEC("version") = LINUX_VERSION_CODE; -+#endif - - /* helper functions called from eBPF programs written in C */ - static void *(*bpf_map_lookup_elem)(void *map, void *key) = -diff --git a/src/cc/frontends/clang/loader.cc b/src/cc/frontends/clang/loader.cc -old mode 100644 -new mode 100755 -index 72c5843ec808..81e429032551 ---- a/src/cc/frontends/clang/loader.cc -+++ b/src/cc/frontends/clang/loader.cc -@@ -112,7 +112,9 @@ int ClangLoader::parse(unique_ptr *mod, TableStorage &ts, - uname(&un); - string kdir, kpath; - const char *kpath_env = ::getenv("BCC_KERNEL_SOURCE"); -+ const char *version_override = ::getenv("LINUX_VERSION_CODE_OVERRIDE"); - bool has_kpath_source = false; -+ string vmacro; - - if (kpath_env) { - kpath = string(kpath_env); -@@ -173,6 +175,15 @@ int ClangLoader::parse(unique_ptr *mod, TableStorage &ts, - flags_cstr.push_back(it->c_str()); - - vector flags_cstr_rem; -+ -+ if (version_override) { -+ vmacro = "-DLINUX_VERSION_CODE_OVERRIDE=" + string(version_override); -+ -+ std::cout << "WARNING: Linux version for eBPF program is being overridden with: " << version_override << "\n"; -+ std::cout << "WARNING: Due to this, the results of the program may be unpredictable\n"; -+ flags_cstr_rem.push_back(vmacro.c_str()); -+ } -+ - flags_cstr_rem.push_back("-include"); - flags_cstr_rem.push_back("/virtual/include/bcc/helpers.h"); - flags_cstr_rem.push_back("-isystem"); --- -2.18.0.203.gfac676dfb9-goog - -- cgit v1.2.3 From f44ca959377cedbd1e59f00a9c23be81366521dc Mon Sep 17 00:00:00 2001 From: Liu Changcheng Date: Thu, 2 Aug 2018 14:38:58 +0800 Subject: use tsing debian mirror in China It's too slow to use debian offical website to create filesystem. tsinghua mirror is a good local debian pkgs Signed-off-by: Liu Changcheng Signed-off-by: Joel Fernandes (Google) --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a1aafc2..a81a89d 100644 --- a/README.md +++ b/README.md @@ -163,4 +163,10 @@ Common Trouble shooting ----------------- 1. Installing g++ with `apt-get install g++` fails. -A. Solution: Run `adeb shell apt-get update` after the `adeb prepare` stage. +Solution: Run `adeb shell apt-get update` after the `adeb prepare` stage. + +2. It's too slow to use debootstrap to create debian fs + +Solution: Use a local mirror, for example in China you could use +https://mirror.tuna.tsinghua.edu.cn/debian/ instead of debian official website +http://deb.debian.org/debian/ -- cgit v1.2.3 From dd195c0b38771ce1ac02d08486d09f11fd9adafc Mon Sep 17 00:00:00 2001 From: Erick Reyes Date: Thu, 16 Aug 2018 14:50:47 -0700 Subject: androdeb: update to 0.99g release Changed pre-built headers naming scheme to address review comments (make it flexible for future versions) Changed the ADEB_REPO_URL setting to make it easier to use alternate repositories Signed-off-by: Erick Reyes --- README.md | 2 +- androdeb | 18 +++++++----------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index a81a89d..b4200d9 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ sudo ln -s $(pwd)/adeb /usr/bin/adeb # bashrc file. # Disclaimer: Google is not liable for the below URL and this # is just an example. -export ADEB_REPO_URL="github.com/joelagnel/" +export ADEB_REPO_URL="github.com/joelagnel/adeb/" ``` * Installing adeb onto your device: diff --git a/androdeb b/androdeb index 42a86ec..031f2b6 100755 --- a/androdeb +++ b/androdeb @@ -2,7 +2,7 @@ # # (c) Joel Fernandes -VERSION=v0.99f +VERSION=v0.99g spath="$(dirname "$(readlink -f "$0")")" # spath=$( cd "$(dirname "$0")" ; pwd -P ) @@ -220,19 +220,15 @@ function download_headers() { KERNEL_MAJOR=`$ADB shell uname -r | cut -d - -f 1 | cut -d . -f 1` KERNEL_MINOR=`$ADB shell uname -r | cut -d - -f 1 | cut -d . -f 2` KERNEL_VERSION="$KERNEL_MAJOR.$KERNEL_MINOR" - case $KERNEL_VERSION in - 4.9) PREBUILT_HEADERS_FILE=headers-$ARCH-4.9.114.tar.gz.zip ;; - 4.14) PREBUILT_HEADERS_FILE=headers-$ARCH-4.14.59.tar.gz.zip ;; - *) die 11 "Unsuported kernel version ($KERNEL_VERSION)" ;; - esac + PREBUILT_HEADERS_FILE=headers-$ARCH-$KERNEL_VERSION.tar.gz.zip check_repo_url - curl -L https://$ADEB_REPO_URL/adeb/releases/download/$VERSION/$PREBUILT_HEADERS_FILE --output $TDIR_ABS/$PREBUILT_HEADERS_FILE || - die 9 "Failed to download kernel headers" + curl -L https://$ADEB_REPO_URL/releases/download/$VERSION/$PREBUILT_HEADERS_FILE --output $TDIR_ABS/$PREBUILT_HEADERS_FILE || + die 9 "Failed to download kernel headers. Please check your internet connection and repository URL" unzip -e $TDIR_ABS/$PREBUILT_HEADERS_FILE -d $TDIR_ABS/ || - die 10 "Failed to download kernel headers. Double check the ADEB_REPO_URL value." + die 10 "Failed to download kernel headers. Kernel $KERNEL_VERSION for $ARCH may not be supported or ADEB_REPO_URL is incorrect." KERNELHDRS=$TDIR_ABS/`echo "$PREBUILT_HEADERS_FILE" | sed "s/.zip//"` } @@ -259,7 +255,7 @@ if [ $DOWNLOAD -eq 1 ]; then # Github dropped tar gz support! ##?#??#! Now we've to zip everything. check_repo_url - curl -L https://$ADEB_REPO_URL/adeb/releases/download/$VERSION/$FNAME --output $TDIR_ABS/$FNAME || + curl -L https://$ADEB_REPO_URL/releases/download/$VERSION/$FNAME --output $TDIR_ABS/$FNAME || die 9 "Failed to download adeb release." unzip -e $TDIR_ABS/$FNAME -d $TDIR_ABS/ || @@ -267,7 +263,7 @@ if [ $DOWNLOAD -eq 1 ]; then TARF=$TDIR_ABS/$FNAME_UZ fi -if [ ! -z "$KERNEL_HEADERS_NEEDED" ] && [ -z "$KERNELSRC" ] && [ -z "$KERNELHDRS"]; then +if [ ! -z "$KERNEL_HEADERS_NEEDED" ] && [ -z "$KERNELSRC" ] && [ -z "$KERNELHDRS" ]; then c_info "Kernel headers are needed but none were provided. Downloading pre-built headers" download_headers fi -- cgit v1.2.3 From 240ce0744e86a1226111fff50382b62957ea3d3e Mon Sep 17 00:00:00 2001 From: Erick Reyes Date: Thu, 16 Aug 2018 14:54:51 -0700 Subject: buildstrap: removed obsolete dependency buildstrap was referencing BCC patch files no longer needed. The changes were merged upstream Signed-off-by: Erick Reyes --- buildstrap | 2 -- 1 file changed, 2 deletions(-) diff --git a/buildstrap b/buildstrap index 0aaa635..8f78fb8 100755 --- a/buildstrap +++ b/buildstrap @@ -65,8 +65,6 @@ if [ $INSTALL_BCC -eq 1 ]; then cp $spath/bcc/build-bcc.sh $TDIR/debian/bcc-master/; pushd $TDIR/debian/bcc-master - patch -p1 < $spath/bcc/misc/0001-clang-Allow-user-to-override-kernel-version.patch - patch -p1 < $spath/bcc/misc/0001-DONOT-MERGE-Remove-version-override-warnings.patch popd fi -- cgit v1.2.3 From 104ab647a5f77ba15f3673a969fa4f677a2d4a4d Mon Sep 17 00:00:00 2001 From: Erick Reyes Date: Thu, 16 Aug 2018 14:55:40 -0700 Subject: kernel headers sanity check Print out an error if the user is trying to use kernel headers for a different major version Signed-off-by: Erick Reyes --- addons/bashrc.common | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/addons/bashrc.common b/addons/bashrc.common index f357b6f..14e09d3 100644 --- a/addons/bashrc.common +++ b/addons/bashrc.common @@ -17,6 +17,16 @@ if [ -d /kernel-headers/ ]; then if [ $this_vers -eq $h_vers ]; then override_vers=0 + else + this_major=$(($this_vers / (256 * 256))) + this_minor=$(($this_vers / 256 % 256)) + h_major=$(($h_vers / (256 * 256))) + h_minor=$(($h_vers / 256 % 256)) + if [ $this_major -ne $h_major ] || [ $this_minor -ne $h_minor ]; then + echo "Error: kernel version does not match installed headers ($this_major.$this_minor <> $h_major.$h_minor)" + echo "BCC will not work" + override_vers=0 + fi fi fi -- cgit v1.2.3 From eb6bc737662da03b3c35dcc74e49176e37928cfc Mon Sep 17 00:00:00 2001 From: Erick Reyes Date: Thu, 16 Aug 2018 15:39:48 -0700 Subject: androdeb: add automatic ADEB_REPO_URL detection for git repositories When the ADEB_REPO_URL variable is not set, attempt to use the git fetch URL from where adeb is running. This makes the most common use case simpler. Signed-off-by: Erick Reyes --- README.md | 7 ++++--- androdeb | 31 +++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index b4200d9..23ae44d 100644 --- a/README.md +++ b/README.md @@ -51,9 +51,10 @@ cd adeb # Add some short cuts: sudo ln -s $(pwd)/adeb /usr/bin/adeb -# For cached image downloads which result in a huge speed-up, -# You could set the ADEB_REPO_URL environment variable in your -# bashrc file. +# Cached image downloads result in a huge speed-up. These are automatic if you +# cloned the repository using git. However, if you downloaded the repository +# as a zip file (or you want to host images elsewere), you could set the +# ADEB_REPO_URL environment variable in your bashrc file. # Disclaimer: Google is not liable for the below URL and this # is just an example. export ADEB_REPO_URL="github.com/joelagnel/adeb/" diff --git a/androdeb b/androdeb index 031f2b6..9c8fa4b 100755 --- a/androdeb +++ b/androdeb @@ -207,13 +207,32 @@ function all_done_banner() { c_info "All done! Run \"adeb shell\" to enter environment" } +function detect_repo_url() { + GIT_REMOTE=`cd $spath && git branch -vv | grep "\*" | sed -e "s/.*\[//" | cut -d "/" -f 1` + if [ -z $GIT_REMOTE ]; then + c_warning "Not running from a git repository, unable to determine URL" + return 0 + fi + ADEB_REPO_URL=`cd $spath && git remote show $GIT_REMOTE | grep "Fetch URL" | sed -e "s/.*Fetch URL://" \ + -e "s/.*@//" \ + -e "s/https:\/\///" \ + -e "s/:/\//" \ + -e "s/\.git$//"`"/" + c_info "Detected URL: $ADEB_REPO_URL" +} + function check_repo_url () { - if [ -z $ADEB_REPO_URL ]; then - c_warning "Automatic download is disabled. To enable it, please set the \$ADEB_REPO_URL" - c_warning "environment variable as recommended in the setup instructions in the README.md" - do_cleanup - exit 0 - fi + if [ -z $ADEB_REPO_URL ]; then + c_info "No repository URL provided in enviromnent. Attempting to auto-detect it" + detect_repo_url + fi + + if [ -z $ADEB_REPO_URL ]; then + c_warning "Automatic download is disabled. To enable it, please set the \$ADEB_REPO_URL" + c_warning "environment variable as recommended in the setup instructions in the README.md" + do_cleanup + exit 0 + fi } function download_headers() { -- cgit v1.2.3 From ed2d299be33c778b6253cb1bc61fb060bb224785 Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Fri, 17 Aug 2018 12:10:56 -0700 Subject: androdeb: update release to keep BCC working due to bashrc changes Signed-off-by: Joel Fernandes (Google) --- androdeb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/androdeb b/androdeb index 9d343aa..261d3c6 100755 --- a/androdeb +++ b/androdeb @@ -2,7 +2,7 @@ # # (c) Joel Fernandes -VERSION=v0.99f +VERSION=v0.99g spath="$(dirname "$(readlink -f "$0")")" # spath=$( cd "$(dirname "$0")" ; pwd -P ) -- cgit v1.2.3 From 90e01eab55fdcfd95a56e65673dc7316e9c4eeb1 Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Fri, 17 Aug 2018 12:11:27 -0700 Subject: buildstrap: Remove BCC patches that are not longer applied/used Signed-off-by: Joel Fernandes (Google) --- buildstrap | 5 ----- 1 file changed, 5 deletions(-) diff --git a/buildstrap b/buildstrap index 0aaa635..b33b71e 100755 --- a/buildstrap +++ b/buildstrap @@ -63,11 +63,6 @@ echo "nameserver 4.2.2.2" > $OUT_TMP/etc/resolv.conf if [ $INSTALL_BCC -eq 1 ]; then git clone https://github.com/iovisor/bcc.git $TDIR/debian/bcc-master cp $spath/bcc/build-bcc.sh $TDIR/debian/bcc-master/; - - pushd $TDIR/debian/bcc-master - patch -p1 < $spath/bcc/misc/0001-clang-Allow-user-to-override-kernel-version.patch - patch -p1 < $spath/bcc/misc/0001-DONOT-MERGE-Remove-version-override-warnings.patch - popd fi # Should be really do this? -- cgit v1.2.3 From 60ab9285e5bfeff92a113983ec157f16051f92ba Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Fri, 17 Aug 2018 12:11:52 -0700 Subject: androdeb: Make --bcc imply --full since only the full FS has BCC Signed-off-by: Joel Fernandes (Google) --- androdeb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/androdeb b/androdeb index 261d3c6..15f7b54 100755 --- a/androdeb +++ b/androdeb @@ -52,7 +52,7 @@ case $key in --full) FULL=1; config_full_build; shift || true; ;; --arch) ARCH=$2; shift || true; shift || true; ;; --archive) DOWNLOAD=0; TARF=$2; shift || true; shift || true; ;; - --bcc) source $spath/packages/bcc; shift || true; ;; + --bcc) FULL=1; source $spath/packages/bcc; shift || true; ;; --kernelsrc) KERNELSRC="$2"; shift || true; shift || true; ;; --skip-install) SKIP_INSTALL=1; shift || true; ;; --kernel-headers-targz) KERNELHDRS=$2; shift || true; shift || true; ;; -- cgit v1.2.3 From ab56927bf163cbd728b06161dd335da608369c6e Mon Sep 17 00:00:00 2001 From: Erick Reyes Date: Fri, 17 Aug 2018 16:02:00 -0700 Subject: androdeb: make repository URL detection more robust The previous logic to detect the git repository URL was prone to failure when git version changed. Changed it to rely on git config and use the first remote found Signed-off-by: Erick Reyes --- androdeb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/androdeb b/androdeb index 9456d60..ee898fb 100755 --- a/androdeb +++ b/androdeb @@ -205,12 +205,7 @@ function all_done_banner() { } function detect_repo_url() { - GIT_REMOTE=`cd $spath && git branch -vv | grep "\*" | sed -e "s/.*\[//" | cut -d "/" -f 1` - if [ -z $GIT_REMOTE ]; then - c_warning "Not running from a git repository, unable to determine URL" - return 0 - fi - ADEB_REPO_URL=`cd $spath && git remote show $GIT_REMOTE | grep "Fetch URL" | sed -e "s/.*Fetch URL://" \ + ADEB_REPO_URL=`cd $spath && git config -l | grep -m1 remote | grep url | sed -e "s/.*url=//" \ -e "s/.*@//" \ -e "s/https:\/\///" \ -e "s/:/\//" \ -- cgit v1.2.3 From 2a89d5bdefc11aea3d2f992bd06b459ab62675d2 Mon Sep 17 00:00:00 2001 From: Erick Reyes Date: Mon, 20 Aug 2018 18:42:35 -0700 Subject: Add utility script to build kernel headers tar/zip file Signed-off-by: Erick Reyes --- utils/packheaders.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 utils/packheaders.sh diff --git a/utils/packheaders.sh b/utils/packheaders.sh new file mode 100755 index 0000000..d10b81b --- /dev/null +++ b/utils/packheaders.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Utility to build kernel headers tar/zip file +# must be run from the top level of a kernel source directory +# and supplied an output file name + +MKTEMP=0; if [[ -z ${TDIR+x} ]] || [[ ! -d "${TDIR}" ]]; then + TDIR=`mktemp -d`; MKTEMP=1; fi +rm -rf $TDIR/* +TDIR_ABS=$( cd "$TDIR" ; pwd -P ) + + +if [ $# -ne 1 ]; then + echo "usage: makeheaders.sh " + exit 0 +fi + +mkdir -p $TDIR_ABS/kernel-headers + +find arch -name include -type d -print | xargs -n1 -i: find : -type f -exec cp --parents {} $TDIR_ABS/kernel-headers/ \; +find include -exec cp --parents {} $TDIR_ABS/kernel-headers/ 2> /dev/null \; +tar -zcf $1 --directory=$TDIR_ABS kernel-headers + +zip -r $1.zip $1 +rm -rf $TDIR/*; if [ $MKTEMP -eq 1 ]; then rm -rf $TDIR; fi -- cgit v1.2.3 From 1787a464045a75de8cc6d2b5bc080962b2c22815 Mon Sep 17 00:00:00 2001 From: Erick Reyes Date: Fri, 31 Aug 2018 10:33:52 -0700 Subject: addons/get_kvers.sh: fix issue with CONFIG_LOCALVERSION_AUTO disabled Modified kernels with CONFIG_LOCALVERSION_AUTO disabled produce a short version string with the form "..+". This case was not handled correctly by the version parser. Signed-off-by: Erick Reyes --- addons/get_kvers.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/get_kvers.sh b/addons/get_kvers.sh index 3a7a6fe..3d18e32 100755 --- a/addons/get_kvers.sh +++ b/addons/get_kvers.sh @@ -4,7 +4,7 @@ kvers=$(uname -r) MAJOR=$(echo $kvers | awk -F. '{ print $1 }') MINOR=$(echo $kvers | awk -F. '{ print $2 }') -SUBVR=$(echo $kvers | awk -F. '{ print $3 }' | awk -F- '{ print $1 }') +SUBVR=$(echo $kvers | awk -F. '{ print $3 }' | awk -F- '{ print $1 }' | sed 's/[^0-9]*//g') maj_num=$(($MAJOR * 65536)) min_num=$(($MINOR * 256)) -- cgit v1.2.3 From f081ad747f5f4b94b4f92999bcf7f23f8d252d9e Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Mon, 8 Oct 2018 14:53:41 -0700 Subject: Update BCC documentation Signed-off-by: Joel Fernandes (Google) --- BCC.md | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/BCC.md b/BCC.md index 9df3b29..01b5a22 100644 --- a/BCC.md +++ b/BCC.md @@ -19,18 +19,24 @@ building BCC on device, and other setup. Take a look a quick look at [adeb README](https://github.com/joelagnel/adeb/blob/master/README.md) so that you're familiar with what it is. -For setting up BCC on your Android device, you need the target device's kernel -source and the sources should be built atleast once in-tree. Once it is built, -run the following command pointing adeb to the kernel sources which will -have it extract headers from there and push them to the device. +To download a prebuilt filesystem with BCC already built/installed for an ARM64 +device, you can just run: ``` -adeb prepare --build --bcc --kernelsrc /path/to/kernel-source/ +adeb prepare --full +``` + +This downloads the FS and also downloads prebuilt kernel headers after +detecting your device's kernel version. Running BCC this way may cause a warning +at startup since the headers may not be an *exact* match for your kernel's +sublevel (only version and patchlevel are matched), however it works well in +our testing and could be used, as long as you can tolerate the warning. + +If you would like to setup your own kernel headers and prevent the warning, +you can point adeb to the kernel sources which will extract headers from there: ``` -This downloads and installs a pre-built adeb filesystem containing a recent -version of BCC onto the android device, extracts kernel headers from the source -tree pointed to and does other setup. Note that `--download` option will work -only if the target architecture is ARM64. For other architectures, see the -[Other Architectures +adeb prepare --full --kernelsrc /path/to/kernel-source/ +``` +For targets other than ARM64, see the [Other Architectures section](https://github.com/joelagnel/adeb/blob/master/BCC.md#other-architectures-other-than-arm64) Now to run BCC, just start an adeb shell: `adeb shell`. This uses adb @@ -60,19 +66,13 @@ CONFIG_PREEMPTIRQ_EVENTS=y Build BCC during adeb install (Optional) -------------------------------------------- -If you would like the latest BCC installation on your Android device, we -recommend dropping the `--download` option from the adeb command above. -This will make adeb clone and build the latest version of BCC for the -target architecture. Note that this is much slower that `--download`. +If you would like the latest upstream BCC built and installed on your Android +device, you can run: ``` adeb prepare --build --bcc --kernelsrc /path/to/kernel-source/ ``` -Note that the full adeb install already contains recent BCC: -``` -adeb prepare --full -``` -This downloads and installs a prebuilt FS and is faster than building locally -using `--build`. +NOTE: This is a slow process and can take a long time. Since it not only builds +BCC but also installs all non-BCC debian packages onto the filesystem and configures them. Other Architectures (other than ARM64) ----------------------- @@ -80,10 +80,12 @@ By default adeb assumes the target Android device is based on ARM64 processor architecture. For other architectures, use the --arch option. For example for x86_64 architecture, run: ``` -adeb prepare --arch amd64 --bcc --kernelsrc /path/to/kernel-source/ +adeb prepare --arch amd64 --build --bcc --kernelsrc /path/to/kernel-source/ ``` Note: The --download option ignores the --arch flag. This is because we only provide pre-built filesystems for ARM64 at the moment. +Note: If you pass --arch, you have to pass --build, because prebuilt +filesystems are not available for non-arm64 devices. Common Issues ------------- -- cgit v1.2.3 From 0b3639d1f84de7ccae59cd88ad8a4cd3507dfc19 Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Mon, 8 Oct 2018 15:01:23 -0700 Subject: Update banner to be more accurate Signed-off-by: Joel Fernandes (Google) --- addons/bashrc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/bashrc b/addons/bashrc index 675572d..5ca6461 100644 --- a/addons/bashrc +++ b/addons/bashrc @@ -8,8 +8,8 @@ echo "##########################################################" echo "# Welcome to androdeb environment running on Android! #" echo "# Questions to: Joel Fernandes #" echo " #" -echo " Try running vim, gcc, clang, bcc, git, make, perf etc #" -echo " or apt-get install something. #" +echo " Try running vim, gcc, clang, git, make, perf, filetop #" +echo " ..etc or apt-get install something. #" echo "##########################################################" echo "" -- cgit v1.2.3 From 5e40e89ded2289b953274d4f44a7ca094377ebd2 Mon Sep 17 00:00:00 2001 From: "Joel Fernandes (Google)" Date: Sun, 14 Oct 2018 13:14:34 -0700 Subject: Fix Qemu image building The --build-image flag can be used to build images for Qemu. The download_headers function breaks this because it needs to query the kernel version from the device, which is not possible with "--build-image" since there may be no adb-connected device. Just prevent the download_headers from triggering on Qemu images for now. Signed-off-by: Joel Fernandes (Google) --- androdeb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/androdeb b/androdeb index ee898fb..3600a5b 100755 --- a/androdeb +++ b/androdeb @@ -60,7 +60,7 @@ case $key in --build) DOWNLOAD=0; shift || true; ;; --buildtar) BTAR=1; DOWNLOAD=0; TARDIR="$2"; shift || true; shift || true; ;; --device|-s) ADB="$ADB -s $2"; shift || true; shift || true; ;; - --build-image) BI=1; BUILD_IMAGEF=$2; SKIP_DEVICE=1; shift || true; shift || true; ;; + --build-image) BI=1; BUILD_IMAGEF=$2; SKIP_DEVICE=1; DOWNLOAD=0; shift || true; shift || true; ;; --debug) set -x; shift || true; ;; *) c_error "Unknown option ($1)"; usage; ;; esac @@ -274,7 +274,7 @@ if [ $DOWNLOAD -eq 1 ]; then TARF=$TDIR_ABS/$FNAME_UZ fi -if [ ! -z "$FULL" ] && [ -z "$KERNELSRC" ] && [ -z "$KERNELHDRS" ]; then +if [ ! -z "$FULL" ] && [ -z "$KERNELSRC" ] && [ -z "$KERNELHDRS" ] && [ -z "$BI" ]; then c_info "Kernel headers are needed but none were provided. Downloading pre-built headers" download_headers fi -- cgit v1.2.3