Skip to content

Commit

Permalink
[Ubuntu Touch] Initial release of Ubports recovery
Browse files Browse the repository at this point in the history
Change-Id: I9c58576663885e504f7a0b8cfbbe98a30811bfa0
  • Loading branch information
Vince1171 committed Jun 27, 2019
1 parent d488704 commit c2f1f96
Show file tree
Hide file tree
Showing 14 changed files with 1,195 additions and 7 deletions.
47 changes: 46 additions & 1 deletion Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ LOCAL_STATIC_LIBRARIES := \
libext2_uuid \
libfec \
libfec_rs \
libsquashfs_utils
libsquashfs_utils \
libcrecovery

LOCAL_HAL_STATIC_LIBRARIES := libhealthd
LOCAL_WHOLE_STATIC_LIBRARIES += libcutils
Expand Down Expand Up @@ -152,6 +153,7 @@ LOCAL_REQUIRED_MODULES := recovery-persist recovery-refresh
endif

LOCAL_C_INCLUDES += system/extras/ext4_utils
LOCAL_C_INCLUDES += external/lz4/lib
LOCAL_C_INCLUDES += external/boringssl/include

ifeq ($(ONE_SHOT_MAKEFILE),)
Expand Down Expand Up @@ -253,19 +255,61 @@ include $(BUILD_EXECUTABLE)
include $(CLEAR_VARS)
LOCAL_MODULE := libmake_ext4fs_static
LOCAL_MODULE_TAGS := optional
LOCAL_C_INCLUDES += external/lz4/lib
LOCAL_CFLAGS := -Dmain=make_ext4fs_main
LOCAL_SRC_FILES := \
../../system/extras/ext4_utils/make_ext4fs_main.c \
../../system/core/libcutils/canned_fs_config.c
LOCAL_STATIC_LIBRARIES += libselinux
include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := system-image-upgrader
LOCAL_MODULE_TAGS := optional eng debug
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
LOCAL_SRC_FILES := $(LOCAL_MODULE)
include $(BUILD_PREBUILT)

include $(CLEAR_VARS)
LOCAL_MODULE := replace-system
LOCAL_MODULE_TAGS := optional eng debug
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
LOCAL_SRC_FILES := $(LOCAL_MODULE)
include $(BUILD_PREBUILT)

include $(CLEAR_VARS)
LOCAL_MODULE := install-system
LOCAL_MODULE_TAGS := optional eng debug
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
LOCAL_SRC_FILES := $(LOCAL_MODULE)
include $(BUILD_PREBUILT)

include $(CLEAR_VARS)
LOCAL_MODULE := archive-master.tar.xz
LOCAL_MODULE_TAGS := optional eng debug
LOCAL_MODULE_CLASS := RECOVERY_ETC
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/etc/system-image
LOCAL_SRC_FILES := archive-master.tar.xz
include $(BUILD_PREBUILT)

include $(CLEAR_VARS)
LOCAL_MODULE := archive-master.tar.xz.asc
LOCAL_MODULE_TAGS := optional eng debug
LOCAL_MODULE_CLASS := RECOVERY_ETC
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/etc/system-image
LOCAL_SRC_FILES := archive-master.tar.xz.asc
include $(BUILD_PREBUILT)

# Minizip static library
include $(CLEAR_VARS)
LOCAL_MODULE := libminizip_static
LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS := -Dmain=minizip_main -D__ANDROID__ -DIOAPI_NO_64 -Wno-unknown-attributes
LOCAL_C_INCLUDES := external/zlib
LOCAL_C_INCLUDES += external/lz4/lib
LOCAL_SRC_FILES := \
../../external/zlib/src/contrib/minizip/ioapi.c \
../../external/zlib/src/contrib/minizip/minizip.c \
Expand Down Expand Up @@ -329,6 +373,7 @@ include $(BUILD_STATIC_LIBRARY)

include \
$(LOCAL_PATH)/applypatch/Android.mk \
$(LOCAL_PATH)/libcrecovery/Android.mk \
$(LOCAL_PATH)/bootloader_message/Android.mk \
$(LOCAL_PATH)/edify/Android.mk \
$(LOCAL_PATH)/minui/Android.mk \
Expand Down
Binary file added archive-master.tar.xz
Binary file not shown.
11 changes: 11 additions & 0 deletions archive-master.tar.xz.asc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQEcBAABAgAGBQJVNU16AAoJEBowx9ZYXp6Bkg4IAJ8xmvYzIe22P/7cR5uALUVb
ysOXugvGdXNAn9J867EPnbJ+oAWSJiDgB8i20Wx+c2JKRGQ8XHmDZQL+43ANZzu5
LMY/7N56LD8UXrB9vmyQhTsyodKeSBF24yJnH3M8upoSrrbuP3VpoGIMa38Udz7b
UDbMkGYJmV8tyoGE377CceNv++vKP49W0j0WK1QakIOHnDbmMSRA0AXve4kUf2LJ
XkVNeUYJ4lpAl0BNSl7J4NOtJFzD+eSjh1yBZTmPzwqvSfkJWft9XnxfP2/r1oy3
pWkYLHNgdPIR/NPKPtc06MZ+YmQqoTrtVHhO2jFve8MkmhNqNx2sFwcWKZODkUU=
=08bM
-----END PGP SIGNATURE-----
45 changes: 43 additions & 2 deletions device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,25 +100,66 @@ static const menu ADVANCED_MENU = {
ADVANCED_MENU_ENTRIES
};

static const char* MAIN_MENU_NAMES[] = {
static const char* ANDROID_MENU_NAMES[] = {
"Reboot system now",
"Apply update",
"Factory reset",
"Advanced",
nullptr
};
static const menu_entry MAIN_MENU_ENTRIES[] = {
static const menu_entry ANDROID_MENU_ENTRIES[] = {
{ ACTION_INVOKE, { .action = Device::REBOOT } },
{ ACTION_INVOKE, { .action = Device::APPLY_UPDATE } },
{ ACTION_SUBMENU, { .submenu = &WIPE_MENU } },
{ ACTION_SUBMENU, { .submenu = &ADVANCED_MENU } },
{ ACTION_NONE, { .action = Device::NO_ACTION } }
};
static const menu ANDROID_MENU = {
ANDROID_MENU_NAMES,
ANDROID_MENU_ENTRIES
};

static const char* UBUNTU_MENU_NAMES[] = {
"Reboot system now",
"Replace ubuntu android system",
"Install ubuntu zip",
"Install ubuntu preinstalled",
"Wipe data/factory reset",
nullptr
};
static const menu_entry UBUNTU_MENU_ENTRIES[] = {
{ ACTION_INVOKE, { .action = Device::REBOOT } },
{ ACTION_INVOKE, { .action = Device::REPLACE_SYSTEM } },
{ ACTION_INVOKE, { .action = Device::INSTALL_UBUNTU_ZIP } },
{ ACTION_INVOKE, { .action = Device::INSTALL_UBUNTU_ROOTSTOCK } },
{ ACTION_INVOKE, { .action = Device::WIPE_DATA_UBUNTU } },
{ ACTION_NONE, { .action = Device::NO_ACTION } }
};

static const menu UBUNTU_MENU = {
UBUNTU_MENU_NAMES,
UBUNTU_MENU_ENTRIES
};

static const char* MAIN_MENU_NAMES[] = {
"Reboot system now",
"Ubuntu actions",
"Android actions",
nullptr
};
static const menu_entry MAIN_MENU_ENTRIES[] = {
{ ACTION_INVOKE, { .action = Device::REBOOT } },
{ ACTION_SUBMENU, { .submenu = &UBUNTU_MENU } },
{ ACTION_SUBMENU, { .submenu = &ANDROID_MENU } },
{ ACTION_NONE, { .action = Device::NO_ACTION } }
};

static const menu MAIN_MENU = {
MAIN_MENU_NAMES,
MAIN_MENU_ENTRIES
};


Device::Device(RecoveryUI* ui) :
ui_(ui) {
menu_stack.push(&MAIN_MENU);
Expand Down
4 changes: 4 additions & 0 deletions device.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ class Device : public VoldWatcher {
MOUNT_SYSTEM,
RUN_GRAPHICS_TEST,
WIPE_SYSTEM,
WIPE_DATA_UBUNTU,
REPLACE_SYSTEM,
INSTALL_UBUNTU_ZIP,
INSTALL_UBUNTU_ROOTSTOCK,
};

// Return the list of menu items (an array of strings,
Expand Down
83 changes: 83 additions & 0 deletions install-system
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/sbin/sh

TARPATH=$(realpath $2)
SYSIMG=$(realpath $3)


prepare_ubuntu_system()
{
mount /data
rm -f /data/system.img
rm -rf /data/ubuntu
for data in system android; do
rm -rf /data/$data-data
done
dd if=/dev/zero of=/data/system.img seek=500K bs=4096 count=0 >/dev/null 2>&1
mkfs.ext2 -F /data/system.img >/dev/null 2>&1
mkdir -p /data/ubuntu
mount -o loop /data/system.img /data/ubuntu/
}

cleanup()
{
umount /data/ubuntu/ 2>/dev/null && rm -rf /data/ubuntu 2>/dev/null
rm -r /data/zip
}

usage()
{
echo "usage: $(basename $0) <method>\n
methods: zip, pre"
exit 1
}

TARBALL=$(basename $TARPATH)
THIS_DIR=$(dirname $0)

if [ $1 == "zip" ]; then
mkdir /data/zip
unzip $TARPATH -d /data/zip
TARBALL = /data/zip/ubuntu.tar.gz
SYSIMG = /data/zip/system.img
fi

if [ -z "$TARBALL" ]; then
echo "need valid rootfs tarball path"
usage
fi

echo -n "preparing system-image on device ... "
prepare_ubuntu_system
echo "[done]"

echo -n "unpacking rootfs tarball to system-image ... "
echo "$TARPATH"
zcat $TARPATH | tar xf - -C /data/ubuntu
cd /data/ubuntu
mkdir -p /data/ubuntu/android/firmware
mkdir -p /data/ubuntu/android/persist
mkdir -p /data/ubuntu/userdata
[ -e /data/ubuntu/SWAP.swap ] && mv /data/ubuntu/SWAP.swap /data/SWAP.img
for link in cache data factory firmware persist system; do
cd /data/ubuntu && ln -s /android/$link $link
done
cd /data/ubuntu/lib && ln -s /system/lib/modules modules
cd /data/ubuntu && ln -s /android/system/vendor vendor
[ -e /data/ubuntu/etc/mtab ] && rm /data/ubuntu/etc/mtab
cd /data/ubuntu/etc && ln -s /proc/mounts mtab

echo "[done]"

echo -n "adding android system image to installation ... "
cd "$(dirname "$0")"
ANDROID_DIR="/data/ubuntu/var/lib/lxc/android/"
cp $SYSIMG $ANDROID_DIR
echo "[done]"

echo -n "enabling Mir ... "
touch /data/ubuntu/home/phablet/.display-mir
echo "[done]"

echo -n "cleaning up on device ... "
cleanup
echo "[done]"
8 changes: 8 additions & 0 deletions libcrecovery/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_SRC_FILES := system.c popen.c
LOCAL_MODULE := libcrecovery
LOCAL_MODULE_TAGS := optional
include $(BUILD_STATIC_LIBRARY)

10 changes: 10 additions & 0 deletions libcrecovery/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef LIBCRECOVERY_COMMON_H
#define LIBCRECOVERY_COMMON_H

#include <stdio.h>

int __system(const char *command);
FILE * __popen(const char *program, const char *type);
int __pclose(FILE *iop);

#endif
2 changes: 2 additions & 0 deletions libcrecovery/defines.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#undef _PATH_BSHELL
#define _PATH_BSHELL "/sbin/sh"
Loading

0 comments on commit c2f1f96

Please sign in to comment.