Skip to content

Commit

Permalink
Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
Jani Monoses committed Nov 28, 2014
0 parents commit ce24b7d
Show file tree
Hide file tree
Showing 6 changed files with 544 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# A set of scripts useful when adapting an Android source tree to work for Ubuntu phones.

Short description of the contents

+ docker-buildenv: Docker setup of a build environment for Ubuntu phone Android trees.
+ kernel: Script that sets the required values for kernel config options in a given config file
+ build: scripts to create a device tarball from Android build images, and a script to replace the
Android system.img on a phone without reflashing it entirely
14 changes: 14 additions & 0 deletions build/device-tarball.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#Example configuration for make-device-tarball
#
#Device name (e.g mako)
DEVICE=devname
#Source name destination name pairs for the partition images to be flashed
PARTITIONS="
recovery.img:recovery.img
boot.img:boot.img
lk.bin:uboot.img
"
#Optional path from where to copy files in the tarball's system/ dir
#ROOTFSDIR=ubuntu/tools/system
#Add unique git id and timestamp to the resulting tarball name
DEVICE_BUILD_ID=true
94 changes: 94 additions & 0 deletions build/make-device-tarball
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/bin/bash
# Make a device tarball from the Android build image and optionally
# files for the Ubuntu root filesystem


CONFFILE=${1:-ubuntu/tools/mktarball.conf}

[ -f "$CONFFILE" ] || {
echo "Config file $CONFFILE not found"
exit 1
}

. $CONFFILE

[ -n "$DEVICE" ] || {
echo "Variable DEVICE not set in config file"
exit 1
}


: ${PRODUCTDIR:=${PWD}/out/target/product/$DEVICE}

[ -f $PRODUCTDIR/system.img ] || {
echo "$PRODUCTDIR does not seem to contain the required Android img files"
exit 1
}

TMPDEVICEDIR=$(mktemp -d)
DEVICETARBALL=${PRODUCTDIR}/device_$DEVICE.tar.xz
LXCPATH=${TMPDEVICEDIR}/system/var/lib/lxc/android

# Ensure cleanup of temporary directory
function onExit() {
rm -Rf $TMPDEVICEDIR
}

trap onExit EXIT

mkdir -p ${LXCPATH}

if file $PRODUCTDIR/system.img | grep ": data" >/dev/null; then
echo "Copying system.img into a proper EXT4 filesystem"
simg2img $PRODUCTDIR/system.img tmp.img >/dev/null
resize2fs -M tmp.img >/dev/null 2>&1
mv tmp.img $LXCPATH/system.img
else
echo "Copying system.img which is already an EXT4 filesystem"
cp $PRODUCTDIR/system.img /$LXCPATH
fi

# Optionally copy partition images
if [ -n "$PARTITIONS" ]; then
PDIR=${TMPDEVICEDIR}/partitions
mkdir -p $PDIR

for pair in $PARTITIONS;do
IFS=':' read src dest <<< $pair
echo "Copying partition $dest"
cp ${PRODUCTDIR}/$src $PDIR/$dest
done
fi

# Optionally copy files over the root filesystem
if [ -d "$ROOTFSDIR" ]; then
echo "Copying files over the root filesystem"
cp -a $ROOTFSDIR/*/* ${TMPDEVICEDIR}/system/
fi

# Optionally generate a build ID based on the latest git commit
if [ "$DEVICE_BUILD_ID" == "true" ]; then
git describe --tags --dirty --always >> ${TMPDEVICEDIR}/system/etc/device-build
fi

echo "Creating the tarball"

if which pxz >/dev/null; then
XZ=pxz
echo "Using parallel XZ compression"
else
echo "Using single threaded XZ compression, you may want to install pxz"
XZ=xz
fi

pushd $TMPDEVICEDIR >/dev/null
tar --use-compress-program=$XZ -cf $DEVICETARBALL $(find . -type f) --owner=0 --group=0
popd >/dev/null

# Optionally create ASCII armored detached GPG signature for the tarball
# KEYPATH should hold the signing keys.
if [ -d "$KEYPATH" ]; then
echo "Creating GPG signature for the device tarball"
gpg --yes --homedir $KEYPATH -sba $DEVICETARBALL
fi

60 changes: 60 additions & 0 deletions build/replace-android-system
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash

# Wait until the adb shell is unavailable, meaning the device is rebooting
wait_for_reboot() {
while test -n "$(adb shell echo '1' 2>/dev/null)"
do
echo -n ".";
sleep 3;
done
echo
}

#Wait until we get a working adb shell, meaning the device is in normal or recovery mode
wait_for_device() {
while test -z "$(adb shell echo '1' 2>/dev/null)"
do
echo -n ".";
sleep 3;
done
echo
}

SYSTEM_IMAGE=$1

if [ ! -f "$SYSTEM_IMAGE" ]; then
echo "Usage: $0 system.img"
exit
fi

echo "Rebooting to recovery"
adb reboot recovery
wait_for_device

echo "Mounting system partition"
adb shell "mkdir /a; if [ -e emmc@android ]; then mount emmc@android /a; else mount /data; mount /data/system.img /a; fi"

if file $SYSTEM_IMAGE | grep ": data" >/dev/null; then
echo "Converting from sparse ext4 image to mountable ext4 image"
simg2img $SYSTEM_IMAGE tmp.img >/dev/null
resize2fs -M tmp.img >/dev/null 2>&1
mv tmp.img $SYSTEM_IMAGE
fi

echo Pushing android system image...
adb push $SYSTEM_IMAGE /a/var/lib/lxc/android/system.img >/dev/null 2>&1 &

SIZE=$(stat -t $SYSTEM_IMAGE |awk '{print $2}')
S=0
while test $S -lt $SIZE
do
sleep 1
S=$(adb shell stat -t /a/var/lib/lxc/android/system.img | awk '{print $2}')
printf "%0.2d%%\r" $[100*$S/$SIZE]
done

echo "Done, rebooting to Ubuntu"

adb reboot

# vim: expandtab: ts=4: sw=4
32 changes: 32 additions & 0 deletions docker-buildenv/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Set up an Ubuntu based environment suitable for building the Ubuntu Touch Android tree in
# If you have squid-deb-proxy installed on your host, it will get used in the container
# Build it and run it with your home dir bindmounted then run the build from your tree
# docker build --rm -t yourimagename .
# docker run -it -v /home/yourname/any/path:/home/developer yourimagename

FROM ubuntu:13.10

MAINTAINER Jani Monoses <[email protected]>

RUN /sbin/ip route | awk '/default/ { print "Acquire::http::Proxy \"http://"$3":8000\";" }' > /etc/apt/apt.conf.d/30proxy

# Allow installing i386 debs required by some of the AOSP prebuilt tools

RUN dpkg --add-architecture i386

RUN apt-get update

RUN DEBIAN_FRONTEND='noninteractive' apt-get install -y cpp-4.8 ccache gcc-4.8 g++-4.8 git gnupg flex bison gperf build-essential \
zip bzr curl libc6-dev libncurses5-dev:i386 x11proto-core-dev \
libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 \
libgl1-mesa-dev g++-multilib mingw32 ubuntu-dev-tools tofrodos \
python-markdown libxml2-utils xsltproc zlib1g-dev:i386 schedtool bsdiff bash-completion vim

# Add default user
RUN adduser --disabled-password --quiet --gecos Developer developer

USER developer
ENV HOME /home/developer
WORKDIR /home/developer

CMD ["/bin/bash"]
Loading

0 comments on commit ce24b7d

Please sign in to comment.