Make TWRP compile for arm64
-Remove dosfstools for arm64 until we can make it compile
-Fix TW_USE_TOOLBOX flag to work again
-Fix symlinking and handling of sh when using mksh
-Fix legacy properties to find futex_wake function
-Fix libcrecovery to not use bsd_signal anymore
-Fix rules for building with regards to libcrecovery
-Update toolbox_recovery rules to compile tools in lollipop
-Fix a few compile errors specific to arm64
Testers report that TWRP does not boot on Nexus 9 and we fail to
get a shell for adb shell. At least it compiles without errors.
Change-Id: I286be8628defb60cc527b8a548c0bdfcb0ebb574
diff --git a/Android.mk b/Android.mk
index 13f4c84..2b7d7db 100644
--- a/Android.mk
+++ b/Android.mk
@@ -89,9 +89,9 @@
LOCAL_STATIC_LIBRARIES :=
LOCAL_SHARED_LIBRARIES :=
-LOCAL_STATIC_LIBRARIES += libcrecovery libguitwrp
+LOCAL_STATIC_LIBRARIES += libguitwrp
LOCAL_SHARED_LIBRARIES += libz libc libstlport libcutils libstdc++ libtar libblkid libminuitwrp libminadbd libmtdutils libminzip libaosprecovery
-LOCAL_SHARED_LIBRARIES += libgccdemangle
+LOCAL_SHARED_LIBRARIES += libgccdemangle libcrecovery
ifneq ($(wildcard system/core/libsparse/Android.mk),)
LOCAL_SHARED_LIBRARIES += libsparse
@@ -324,15 +324,10 @@
LOCAL_LDFLAGS += -Wl,-dynamic-linker,/sbin/linker
LOCAL_ADDITIONAL_DEPENDENCIES := \
- busybox_symlinks \
- dosfsck \
- dosfslabel \
dump_image \
erase_image \
flash_image \
fix_permissions.sh \
- fsck_msdos_symlink \
- mkdosfs \
mke2fs.conf \
mkexfatfs \
pigz \
@@ -342,6 +337,16 @@
unpigz_symlink \
updater
+ifneq ($(TARGET_ARCH), arm64)
+ LOCAL_ADDITIONAL_DEPENDENCIES += \
+ dosfsck \
+ dosfslabel \
+ fsck_msdos_symlink \
+ mkdosfs
+endif
+ifneq ($(TW_USE_TOOLBOX), true)
+ LOCAL_ADDITIONAL_DEPENDENCIES += busybox_symlinks
+endif
ifeq ($(BOARD_HAS_NO_REAL_SDCARD),)
LOCAL_ADDITIONAL_DEPENDENCIES += parted
endif
@@ -495,7 +500,6 @@
$(commands_recovery_local_path)/mtdutils/Android.mk \
$(commands_recovery_local_path)/flashutils/Android.mk \
$(commands_recovery_local_path)/pigz/Android.mk \
- $(commands_recovery_local_path)/dosfstools/Android.mk \
$(commands_recovery_local_path)/libtar/Android.mk \
$(commands_recovery_local_path)/crypto/cryptsettings/Android.mk \
$(commands_recovery_local_path)/crypto/cryptfs/Android.mk \
@@ -508,6 +512,10 @@
$(commands_recovery_local_path)/twrpTarMain/Android.mk \
$(commands_recovery_local_path)/mtp/Android.mk
+ifneq ($(TARGET_ARCH), arm64)
+ include $(commands_recovery_local_path)/dosfstools/Android.mk
+endif
+
ifeq ($(TW_INCLUDE_CRYPTO_SAMSUNG), true)
include $(commands_recovery_local_path)/crypto/libcrypt_samsung/Android.mk
endif
diff --git a/bmlutils/Android.mk b/bmlutils/Android.mk
index 7c6676b..7216775 100644
--- a/bmlutils/Android.mk
+++ b/bmlutils/Android.mk
@@ -3,6 +3,7 @@
include $(CLEAR_VARS)
BOARD_RECOVERY_DEFINES := BOARD_BML_BOOT BOARD_BML_RECOVERY
+LOCAL_STATIC_LIBRARY := libcrecovery
$(foreach board_define,$(BOARD_RECOVERY_DEFINES), \
$(if $($(board_define)), \
@@ -10,9 +11,6 @@
) \
)
-LOCAL_STATIC_LIBRARIES := libcrecovery
-LOCAL_C_INCLUDES := $(commands_recovery_local_path)/libcrecovery
-
LOCAL_SRC_FILES := bmlutils.c
LOCAL_MODULE := libbmlutils
LOCAL_MODULE_TAGS := eng
@@ -22,6 +20,7 @@
include $(CLEAR_VARS)
BOARD_RECOVERY_DEFINES := BOARD_BML_BOOT BOARD_BML_RECOVERY
+LOCAL_SHARED_LIBRARIES := libcrecovery
$(foreach board_define,$(BOARD_RECOVERY_DEFINES), \
$(if $($(board_define)), \
diff --git a/bmlutils/bmlutils.c b/bmlutils/bmlutils.c
index d59475e..4c7c49d 100644
--- a/bmlutils/bmlutils.c
+++ b/bmlutils/bmlutils.c
@@ -22,50 +22,7 @@
#include <bmlutils.h>
-#undef _PATH_BSHELL
-#define _PATH_BSHELL "/sbin/sh"
-
-int __system(const char *command)
-{
- pid_t pid;
- sig_t intsave, quitsave;
- sigset_t mask, omask;
- int pstat;
- char *argp[] = {"sh", "-c", NULL, NULL};
-
- if (!command) /* just checking... */
- return(1);
-
- argp[2] = (char *)command;
-
- sigemptyset(&mask);
- sigaddset(&mask, SIGCHLD);
- sigprocmask(SIG_BLOCK, &mask, &omask);
- switch (pid = vfork()) {
- case -1: /* error */
- sigprocmask(SIG_SETMASK, &omask, NULL);
- return(-1);
- case 0: /* child */
- sigprocmask(SIG_SETMASK, &omask, NULL);
- execve(_PATH_BSHELL, argp, environ);
- _exit(127);
- }
-
- intsave = (sig_t) bsd_signal(SIGINT, SIG_IGN);
- quitsave = (sig_t) bsd_signal(SIGQUIT, SIG_IGN);
- pid = waitpid(pid, (int *)&pstat, 0);
- sigprocmask(SIG_SETMASK, &omask, NULL);
- (void)bsd_signal(SIGINT, intsave);
- (void)bsd_signal(SIGQUIT, quitsave);
- return (pid == -1 ? -1 : pstat);
-}
-
-static struct pid {
- struct pid *next;
- FILE *fp;
- pid_t pid;
-} *pidlist;
-
+#include "../libcrecovery/common.h"
static int restore_internal(const char* bml, const char* filename)
{
diff --git a/flashutils/Android.mk b/flashutils/Android.mk
index 3209cb0..a697a09 100644
--- a/flashutils/Android.mk
+++ b/flashutils/Android.mk
@@ -83,7 +83,7 @@
LOCAL_MODULE := libflashutils
LOCAL_MODULE_TAGS := eng
LOCAL_C_INCLUDES += $(commands_recovery_local_path)
-LOCAL_SHARED_LIBRARIES := libc libmmcutils libbmlutils
+LOCAL_SHARED_LIBRARIES := libc libmmcutils libbmlutils libcrecovery
LOCAL_STATIC_LIBRARIES := libmtdutils
BOARD_RECOVERY_DEFINES := BOARD_BML_BOOT BOARD_BML_RECOVERY
diff --git a/gui/Android.mk b/gui/Android.mk
index 9cc0431..479bc76 100644
--- a/gui/Android.mk
+++ b/gui/Android.mk
@@ -130,7 +130,9 @@
$(TWRP_COMMON_XML)
$(TWRP_REMOVE_FONT)
mkdir -p $(TARGET_RECOVERY_ROOT_OUT)/sbin/
+ifneq ($(TW_USE_TOOLBOX), true)
ln -sf $(TWRP_SH_TARGET) $(TARGET_RECOVERY_ROOT_OUT)/sbin/sh
+endif
ln -sf /sbin/pigz $(TARGET_RECOVERY_ROOT_OUT)/sbin/gzip
ln -sf /sbin/unpigz $(TARGET_RECOVERY_ROOT_OUT)/sbin/gunzip
diff --git a/legacy_property_service.c b/legacy_property_service.c
index 24d3aa9..490a245 100644
--- a/legacy_property_service.c
+++ b/legacy_property_service.c
@@ -25,6 +25,8 @@
#include <limits.h>
#include <errno.h>
+#include "../../bionic/libc/private/bionic_futex.h"
+
#include <cutils/properties.h>
#include "legacy_properties.h"
@@ -181,7 +183,7 @@
memcpy(pi->value, value, valuelen + 1);
pa->toc[pa->count] =
- (namelen << 24) | (((unsigned) pi) - ((unsigned) pa));
+ (namelen << 24) | (((unsigned long) pi) - ((unsigned long) pa));
pa->count++;
pa->serial++;
diff --git a/libcrecovery/Android.mk b/libcrecovery/Android.mk
index d948dd1..8434d51 100644
--- a/libcrecovery/Android.mk
+++ b/libcrecovery/Android.mk
@@ -8,4 +8,10 @@
LOCAL_MODULE_TAGS := eng
include $(BUILD_STATIC_LIBRARY)
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := system.c popen.c
+LOCAL_MODULE := libcrecovery
+LOCAL_MODULE_TAGS := eng
+include $(BUILD_SHARED_LIBRARY)
+
endif
diff --git a/libcrecovery/system.c b/libcrecovery/system.c
index 6d78ae9..c5dd550 100644
--- a/libcrecovery/system.c
+++ b/libcrecovery/system.c
@@ -66,11 +66,11 @@
_exit(127);
}
- intsave = (sig_t) bsd_signal(SIGINT, SIG_IGN);
- quitsave = (sig_t) bsd_signal(SIGQUIT, SIG_IGN);
+ intsave = (sig_t) signal(SIGINT, SIG_IGN);
+ quitsave = (sig_t) signal(SIGQUIT, SIG_IGN);
pid = waitpid(pid, (int *)&pstat, 0);
sigprocmask(SIG_SETMASK, &omask, NULL);
- (void)bsd_signal(SIGINT, intsave);
- (void)bsd_signal(SIGQUIT, quitsave);
+ (void)signal(SIGINT, intsave);
+ (void)signal(SIGQUIT, quitsave);
return (pid == -1 ? -1 : pstat);
}
diff --git a/minui/graphics.c b/minui/graphics.c
index 948a07c..3713f61 100644
--- a/minui/graphics.c
+++ b/minui/graphics.c
@@ -175,7 +175,7 @@
fb->stride = fi.line_length/PIXEL_SIZE;
fb->format = PIXEL_FORMAT;
if (!has_overlay) {
- fb->data = (void*) (((unsigned) bits) + vi.yres * fi.line_length);
+ fb->data = (void*) (((unsigned long) bits) + vi.yres * fi.line_length);
memset(fb->data, 0, vi.yres * fi.line_length);
}
diff --git a/minuitwrp/graphics.c b/minuitwrp/graphics.c
index 9926904..d08e743 100644
--- a/minuitwrp/graphics.c
+++ b/minuitwrp/graphics.c
@@ -300,10 +300,10 @@
fb->height = vi.yres;
#ifdef BOARD_HAS_JANKY_BACKBUFFER
fb->stride = fi.line_length/2;
- fb->data = (void*) (((unsigned) bits) + vi.yres * fi.line_length);
+ fb->data = (GGLubyte*) (((unsigned long) bits) + vi.yres * fi.line_length);
#else
fb->stride = vi.xres_virtual;
- fb->data = (void*) (((unsigned) bits) + vi.yres * fb->stride * PIXEL_SIZE);
+ fb->data = (GGLubyte*) (((unsigned long) bits) + vi.yres * fb->stride * PIXEL_SIZE);
#endif
fb->format = PIXEL_FORMAT;
if (!has_overlay) {
diff --git a/prebuilt/Android.mk b/prebuilt/Android.mk
index 80c7fa4..ddfe99f 100644
--- a/prebuilt/Android.mk
+++ b/prebuilt/Android.mk
@@ -16,12 +16,16 @@
ifneq ($(TW_USE_TOOLBOX), true)
RELINK_SOURCE_FILES += $(TARGET_OUT_OPTIONAL_EXECUTABLES)/busybox
else
- RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/mksh
+ RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/sh
+ RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libcrypto.so
endif
RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/sbin/pigz
-RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/sbin/dosfsck
-RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/sbin/dosfslabel
-RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/sbin/mkdosfs
+# dosfstools does not build for arm64 right now
+ifneq ($(TARGET_ARCH), arm64)
+ RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/sbin/dosfsck
+ RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/sbin/dosfslabel
+ RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/sbin/mkdosfs
+endif
RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/e2fsck
RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/mke2fs
RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/tune2fs
@@ -31,6 +35,7 @@
RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libcutils.so
# Not available in 5.0
#RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libcorkscrew.so
+RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libcrecovery.so
RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libusbhost.so
RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libgccdemangle.so
RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libutils.so
@@ -123,9 +128,9 @@
RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libopenaes.so
endif
ifeq ($(TARGET_USERIMAGES_USE_F2FS), true)
- RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/mkfs.f2fs
+ RELINK_SOURCE_FILES += $(TARGET_ROOT_OUT_SBIN)/mkfs.f2fs
RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/fsck.f2fs
- RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/fibmap.f2fs
+ #RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/fibmap.f2fs
endif
ifneq ($(wildcard system/core/reboot/Android.mk),)
RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/reboot
diff --git a/toolbox/Android.mk b/toolbox/Android.mk
index 8a96c81..ad2e24c 100644
--- a/toolbox/Android.mk
+++ b/toolbox/Android.mk
@@ -1,7 +1,15 @@
LOCAL_PATH:= system/core/toolbox/
+
+
+common_cflags := \
+ -std=gnu99 \
+ -Werror -Wno-unused-parameter \
+ -I$(LOCAL_PATH)/upstream-netbsd/include/ \
+ -include bsd-compatibility.h
+
include $(CLEAR_VARS)
-TOOLS := \
+OUR_TOOLS := \
start \
stop \
getprop \
@@ -20,103 +28,130 @@
getsebool \
setsebool \
load_policy
- TOOLS += $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(TOOLS_FOR_SELINUX))
+ OUR_TOOLS += $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(TOOLS_FOR_SELINUX))
endif
+
ifeq ($(TW_USE_TOOLBOX), true)
- TOOLS += \
- mount \
- cat \
- ps \
- kill \
- ln \
- insmod \
- rmmod \
- lsmod \
- ifconfig \
- setconsole \
- rm \
- mkdir \
- rmdir \
- getevent \
- sendevent \
- date \
- wipe \
- sync \
- umount \
- notify \
- cmp \
- dmesg \
- route \
- hd \
- dd \
- df \
- watchprops \
- log \
- sleep \
- renice \
- printenv \
- smd \
- chmod \
- chown \
- newfs_msdos \
- netstat \
- ioctl \
- mv \
- schedtop \
- top \
- iftop \
- id \
- uptime \
- vmstat \
- nandread \
- ionice \
- touch \
- lsof \
- du \
- md5 \
- clear \
- swapon \
- swapoff \
- mkswap \
- readlink
- ifneq ($(TWHAVE_SELINUX), true)
- TOOLS += ls
- endif
+BSD_TOOLS := \
+ cat \
+ chown \
+ cp \
+ dd \
+ du \
+ grep \
+ kill \
+ ln \
+ mv \
+ printenv \
+ rm \
+ rmdir \
+ sleep \
+ sync \
+
+OUR_TOOLS += \
+ chmod \
+ clear \
+ cmp \
+ date \
+ df \
+ dmesg \
+ getevent \
+ hd \
+ id \
+ ifconfig \
+ iftop \
+ insmod \
+ ioctl \
+ ionice \
+ log \
+ lsmod \
+ lsof \
+ md5 \
+ mkdir \
+ mknod \
+ mkswap \
+ mount \
+ nandread \
+ netstat \
+ newfs_msdos \
+ nohup \
+ notify \
+ ps \
+ readlink \
+ renice \
+ rmmod \
+ route \
+ schedtop \
+ sendevent \
+ smd \
+ swapoff \
+ swapon \
+ top \
+ touch \
+ umount \
+ uptime \
+ vmstat \
+ watchprops \
+ wipe
+ ifneq ($(TWHAVE_SELINUX), true)
+ TOOLS += ls
+ endif
+ LOCAL_SHARED_LIBRARIES += libcrypto
endif
+ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
+OUR_TOOLS += r
+endif
+
+ALL_TOOLS = $(BSD_TOOLS) $(OUR_TOOLS)
+
LOCAL_SRC_FILES := \
- toolbox.c \
- $(patsubst %,%.c,$(TOOLS))
+ upstream-netbsd/lib/libc/gen/getbsize.c \
+ upstream-netbsd/lib/libc/gen/humanize_number.c \
+ upstream-netbsd/lib/libc/stdlib/strsuftoll.c \
+ upstream-netbsd/lib/libc/string/swab.c \
+ upstream-netbsd/lib/libutil/raise_default_signal.c \
+ dynarray.c \
+ pwcache.c \
+ $(patsubst %,%.c,$(OUR_TOOLS)) \
+ toolbox.c \
-ifneq ($(wildcard system/core/toolbox/dynarray.c),)
- LOCAL_SRC_FILES += dynarray.c
-endif
+LOCAL_CFLAGS += $(common_cflags)
-# reboot.c was removed in 4.4 kitkat
-#TOOLS += reboot
+LOCAL_C_INCLUDES += external/openssl/include
-#ifeq ($(BOARD_USES_BOOTMENU),true)
-# LOCAL_SRC_FILES += ../../../external/bootmenu/libreboot/reboot.c
-#else
-# LOCAL_SRC_FILES += reboot.c
-#endif
-
-LOCAL_C_INCLUDES := bionic/libc/bionic
-
-LOCAL_SHARED_LIBRARIES := \
- libcutils \
- liblog \
- libc
+LOCAL_SHARED_LIBRARIES += libcutils
ifeq ($(TWHAVE_SELINUX), true)
- LOCAL_SHARED_LIBRARIES += libselinux
+ LOCAL_SHARED_LIBRARIES += libselinux
+ LOCAL_STATIC_LIBRARIES += \
+ libtoolbox_cat \
+ libtoolbox_chown \
+ libtoolbox_cp \
+ libtoolbox_dd \
+ libtoolbox_grep \
+ libtoolbox_kill \
+ libtoolbox_ln \
+ libtoolbox_mv \
+ libtoolbox_printenv \
+ libtoolbox_rm \
+ libtoolbox_rmdir \
+ libtoolbox_sleep \
+ libtoolbox_sync
endif
+# libusbhost is only used by lsusb, and that isn't usually included in toolbox.
+# The linker strips out all the unused library code in the normal case.
+LOCAL_STATIC_LIBRARIES := \
+ libusbhost \
+
+LOCAL_WHOLE_STATIC_LIBRARIES := $(patsubst %,libtoolbox_%,$(BSD_TOOLS))
+
LOCAL_MODULE := toolbox_recovery
LOCAL_MODULE_STEM := toolbox
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
-LOCAL_MODULE_TAGS := optional
+LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk
# Including this will define $(intermediates).
#
@@ -125,7 +160,7 @@
$(LOCAL_PATH)/toolbox.c: $(intermediates)/tools.h
TOOLS_H := $(intermediates)/tools.h
-$(TOOLS_H): PRIVATE_TOOLS := $(TOOLS)
+$(TOOLS_H): PRIVATE_TOOLS := $(ALL_TOOLS)
$(TOOLS_H): PRIVATE_CUSTOM_TOOL = echo "/* file generated automatically */" > $@ ; for t in $(PRIVATE_TOOLS) ; do echo "TOOL($$t)" >> $@ ; done
$(TOOLS_H): $(LOCAL_PATH)/Android.mk
$(TOOLS_H):
@@ -133,7 +168,7 @@
# Make #!/system/bin/toolbox launchers for each tool.
#
-SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(TOOLS))
+SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(ALL_TOOLS))
$(SYMLINKS): TOOLBOX_BINARY := $(LOCAL_MODULE_STEM)
$(SYMLINKS): $(LOCAL_INSTALLED_MODULE) $(LOCAL_PATH)/Android.mk
@echo "Symlink: $@ -> $(TOOLBOX_BINARY)"
@@ -147,3 +182,8 @@
LOCAL_ADDITIONAL_DEPENDENCIES := $(SYMLINKS)
include $(BUILD_PHONY_PACKAGE)
SYMLINKS :=
+
+# We need this so that the installed files could be picked up based on the
+# local module name
+ALL_MODULES.$(LOCAL_MODULE).INSTALLED := \
+ $(ALL_MODULES.$(LOCAL_MODULE).INSTALLED) $(SYMLINKS)
diff --git a/twrpTar.cpp b/twrpTar.cpp
index 28ac91a..b5d66d3 100644
--- a/twrpTar.cpp
+++ b/twrpTar.cpp
@@ -300,7 +300,7 @@
_exit(-1);
} else {
LOGINFO("Joined thread %i.\n", i);
- ret = (int)thread_return;
+ ret = *((int *)thread_return);
if (ret != 0) {
thread_error = 1;
LOGERR("Thread %i returned an error %i.\n", i, ret);
@@ -532,7 +532,7 @@
_exit(-1);
} else {
LOGINFO("Joined thread %i.\n", i);
- ret = (int)thread_return;
+ ret = *((int *)thread_return);
if (ret != 0) {
thread_error = 1;
LOGERR("Thread %i returned an error %i.\n", i, ret);
@@ -751,7 +751,7 @@
LOGERR("Error closing '%s' on thread %i\n", tarfn.c_str(), thread_id);
return -3;
}
- LOGINFO("Thread id %i tarList done, %i archives.\n", thread_id, archive_count, i, list_size);
+ LOGINFO("Thread id %i tarList done, %i archives.\n", thread_id, archive_count);
return 0;
}