Skip to content
Browse files

add fstab to crespo, fix backup and restore bug

  • Loading branch information...
1 parent 2a2a221 commit dea3d2ff7d70241ce2c0e5513ed3b1f6220cfb01 yanhao committed Sep 14, 2012
View
7 build/core/Makefile
@@ -277,6 +277,12 @@ INTERNAL_RAMDISK_FILES := $(filter $(TARGET_ROOT_OUT)/%, \
$(ALL_GENERATED_SOURCES) \
$(ALL_DEFAULT_INSTALLED_MODULES))
+$(INTERNAL_RECOVERY_RAMDISK_FILES): $(filter $(TARGET_RECOVERY_ROOT_OUT)/%, \
+ $(ALL_PREBUILT) \
+ $(ALL_DEFAULT_INSTALLED_MODULES))
+ @echo enter INTERNAL_RECOVERY_INSTALLED_MODULES
+
+
BUILT_RAMDISK_TARGET := $(PRODUCT_OUT)/ramdisk.img
# We just build this directly to the install location.
@@ -564,6 +570,7 @@ $(RECOVERY_INSTALL_OTA_KEYS): $(OTA_PUBLIC_KEYS) $(DUMPKEY_JAR) $(extra_keys)
$(INSTALLED_RECOVERYIMAGE_TARGET): $(MKBOOTFS) $(MKBOOTIMG) $(MINIGZIP) \
$(INSTALLED_RAMDISK_TARGET) \
$(INSTALLED_BOOTIMAGE_TARGET) \
+ $(INTERNAL_RECOVERY_RAMDISK_FILES) \
$(recovery_binary) \
$(recovery_initrc) $(recovery_kernel) \
$(INSTALLED_2NDBOOTLOADER_TARGET) \
1 external/bzip2
@@ -0,0 +1 @@
+Subproject commit 048dacdca43eed1534689ececcf2781c63e1e4ba
View
3 patch_device/crespo/device.conf
@@ -3,4 +3,7 @@ ini_set("customkeycode_down", "114");
ini_set("customkeycode_select", "116");
ini_set("customkeycode_menu", "229");
ini_set("customkeycode_back", "158");
+
+ini_set("rom_device", "Nexus S");
+ini_set("rom_date", "2012-09-14");
calibrate("2.0246", "28", "1.2555", "-3");
View
3 patch_device/crespo/root/etc/fstab
@@ -0,0 +1,3 @@
+/dev/block/platform/s3c-sdhci.0/by-name/media /sdcard vfat rw
+/dev/block/platform/s3c-sdhci.0/by-name/system /system ext4 rw
+/dev/block/platform/s3c-sdhci.0/by-name/userdata /data ext4 rw
View
47 src/Android.mk
@@ -10,6 +10,7 @@ LOCAL_SRC_FILES := \
bootloader.c \
install.c \
roots.c \
+ firmware.c \
nandroid.c \
verifier.c \
recovery.c
@@ -23,7 +24,7 @@ MYDEFINE_CFLAGS := -D_GLIBCXX_DEBUG_PEDANTIC \
-DFT2_BUILD_LIBRARY=1 \
-D_MIUI_NODEBUG=1 \
-DDARWIN_NO_CARBON
- -g -O0 -DDEBUG=1
+ # -g -O0 -DDEBUG=1
LOCAL_CFLAGS += -DRECOVERY_API_VERSION=$(RECOVERY_API_VERSION)
LOCAL_CFLAGS += $(MYDEFINE_CFLAGS)
#LOCAL_CFLAGS += -DRECOVERY_API_VERSION=$(RECOVERY_API_VERSION)
@@ -46,7 +47,7 @@ LOCAL_MODULE_TAGS := optional
#LOCAL_C_INCLUDES += $(LOCAL_PATH)/include
#LOCAL_LDLIBS += $(LOCAL_PATH)/lib
-LOCAL_STATIC_LIBRARIES += libext4_utils libz
+LOCAL_STATIC_LIBRARIES += libext4_utils libz
LOCAL_STATIC_LIBRARIES += libminzip libunz libmtdutils libmincrypt
#add static libraries
LOCAL_STATIC_LIBRARIES += libedify libcrecovery libflashutils libmmcutils libbmlutils
@@ -60,19 +61,6 @@ LOCAL_C_INCLUDES += system/extras/ext4_utils
include $(BUILD_EXECUTABLE)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := verifier_test.c verifier.c
-
-LOCAL_MODULE := verifier_test
-
-LOCAL_FORCE_STATIC_EXECUTABLE := true
-
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_STATIC_LIBRARIES := libmincrypt libcutils libstdc++ libc
-
-include $(BUILD_EXECUTABLE)
BUSYBOX_PATH := $(LOCAL_PATH)/busybox
# Now let's do recovery symlinks
@@ -86,15 +74,29 @@ $(RECOVERY_BUSYBOX_SYMLINKS): $(LOCAL_INSTALLED_MODULE)
@rm -rf $@
$(hide) ln -sf $(BUSYBOX_BINARY) $@
-copy_busybox:
+ALL_DEFAULT_INSTALLED_MODULES += $(RECOVERY_BUSYBOX_SYMLINKS)
+
+RECOVERY_BUSYBOX := $(TARGET_ROOT_OUT)/bin/busybox
+$(RECOVERY_BUSYBOX):
@cp $(BUSYBOX_PATH)/busybox $(TARGET_ROOT_OUT)/sbin/ -f
+
#@cp $(BUSYBOX_PATH)/adbd $(TARGET_ROOT_OUT)/sbin/
-ALL_DEFAULT_INSTALLED_MODULES += copy_busybox $(RECOVERY_BUSYBOX_SYMLINKS)
-copy_file_operation:
- @cp $(LOCAL_PATH)/obj/sbin/fix_permissions $(TARGET_ROOT_OUT)/sbin/ -f
- @echo "copy fix_permissions to recovery"
+ALL_DEFAULT_INSTALLED_MODULES += $(RECOVERY_BUSYBOX)
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := verifier_test.c verifier.c
+
+LOCAL_MODULE := verifier_test
+LOCAL_FORCE_STATIC_EXECUTABLE := true
+
+LOCAL_MODULE_TAGS := tests
+
+LOCAL_STATIC_LIBRARIES := libmincrypt libcutils libstdc++ libc
+
+include $(BUILD_EXECUTABLE)
#add extra library
#include bionic/libm/Android.mk
#include external/yaffs2/Android.mk
@@ -113,5 +115,8 @@ include $(commands_recovery_local_path)/mmcutils/Android.mk
include $(commands_recovery_local_path)/tools/Android.mk
include $(commands_recovery_local_path)/edify/Android.mk
include $(commands_recovery_local_path)/updater/Android.mk
-include $(commands_recovery_local_path)/applypatch/Android.mk
+#include $(commands_recovery_local_path)/applypatch/Android.mk
+
+#add some shell script
+include $(commands_recovery_local_path)/utilities/Android.mk
commands_recovery_local_path :=
View
29 src/Makefile
@@ -1,29 +0,0 @@
-LOCAL_SRC_FILES := \
- recovery_ui.c \
- mount.c \
- miui_intent.c \
- bootloader.c \
- install.c \
- roots.c \
- nandroid.c \
- verifier.c \
- recovery.c
-
-RECOVERY_API_VERSION := 3
-MYDEFINE_CFLAGS := -D_GLIBCXX_DEBUG_PEDANTIC \
- -DFT2_BUILD_LIBRARY=1 \
- -D_MIUI_NODEBUG=1 \
- -DDARWIN_NO_CARBON
-LOCAL_CFLAGS += -DRECOVERY_API_VERSION=$(RECOVERY_API_VERSION)
-
-LOCAL_C_INCLUDES += system/extras/ext4_utils
-
-LOCAL_STATIC_LIBRARIES += libext4_utils libz
-LOCAL_STATIC_LIBRARIES += libminzip libunz libmtdutils libmincrypt
-#add static libraries
-LOCAL_STATIC_LIBRARIES += libedify libcrecovery libflashutils libmmcutils libbmlutils
-LOCAL_STATIC_LIBRARIES += libmkyaffs2image libunyaffs liberase_image libdump_image libflash_image
-LOCAL_STATIC_LIBRARIES += libmiui libcutils
-LOCAL_STATIC_LIBRARIES += libstdc++ libc libm
-
-LOCAL_LIB_DI
View
6 src/applypatch/Android.mk
@@ -18,7 +18,7 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := applypatch.c bspatch.c freecache.c imgpatch.c utils.c
LOCAL_MODULE := libapplypatch
LOCAL_MODULE_TAGS := eng
-LOCAL_C_INCLUDES += external/bzip2 external/zlib bootable/recovery
+LOCAL_C_INCLUDES += external/bzip2 external/zlib src
LOCAL_STATIC_LIBRARIES += libmtdutils libmincrypt libbz libz
include $(BUILD_STATIC_LIBRARY)
@@ -27,7 +27,7 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := main.c
LOCAL_MODULE := applypatch
-LOCAL_C_INCLUDES += bootable/recovery
+LOCAL_C_INCLUDES += src
LOCAL_STATIC_LIBRARIES += libapplypatch libmtdutils libmincrypt libbz libminelf
LOCAL_SHARED_LIBRARIES += libz libcutils libstdc++ libc
@@ -39,7 +39,7 @@ LOCAL_SRC_FILES := main.c
LOCAL_MODULE := applypatch_static
LOCAL_FORCE_STATIC_EXECUTABLE := true
LOCAL_MODULE_TAGS := eng
-LOCAL_C_INCLUDES += bootable/recovery
+LOCAL_C_INCLUDES += src
LOCAL_STATIC_LIBRARIES += libapplypatch libmtdutils libmincrypt libbz libminelf
LOCAL_STATIC_LIBRARIES += libz libcutils libstdc++ libc
View
2 src/applypatch/applypatch.sh
@@ -11,7 +11,7 @@
# the tests.
EMULATOR_PORT=5580
-DATA_DIR=$ANDROID_BUILD_TOP/bootable/recovery/applypatch/testdata
+DATA_DIR=$ANDROID_BUILD_TOP/src/applypatch/testdata
# This must be the filename that applypatch uses for its copies.
CACHE_TEMP_SOURCE=/cache/saved.file
View
2 src/bmlutils/Android.mk
@@ -11,7 +11,7 @@ $(foreach board_define,$(BOARD_RECOVERY_DEFINES), \
)
LOCAL_STATIC_LIBRARIES := libcrecovery
-LOCAL_C_INCLUDES := bootable/recovery/libcrecovery
+LOCAL_C_INCLUDES := src/libcrecovery
LOCAL_SRC_FILES := bmlutils.c
LOCAL_MODULE := libbmlutils
View
131 src/firmware.c
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * 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.
+ */
+
+#include "bootloader.h"
+#include "common.h"
+#include "firmware.h"
+#include "roots.h"
+
+#include <errno.h>
+#include <string.h>
+#include <sys/reboot.h>
+
+static const char *update_type = NULL;
+static const char *update_data = NULL;
+static int update_length = 0;
+
+int remember_firmware_update(const char *type, const char *data, int length) {
+ if (update_type != NULL || update_data != NULL) {
+ LOGE("Multiple firmware images\n");
+ return -1;
+ }
+
+ update_type = type;
+ update_data = data;
+ update_length = length;
+ return 0;
+}
+
+// Return true if there is a firmware update pending.
+int firmware_update_pending() {
+ return update_data != NULL && update_length > 0;
+}
+
+/* Bootloader / Recovery Flow
+ *
+ * On every boot, the bootloader will read the bootloader_message
+ * from flash and check the command field. The bootloader should
+ * deal with the command field not having a 0 terminator correctly
+ * (so as to not crash if the block is invalid or corrupt).
+ *
+ * The bootloader will have to publish the partition that contains
+ * the bootloader_message to the linux kernel so it can update it.
+ *
+ * if command == "boot-recovery" -> boot recovery.img
+ * else if command == "update-radio" -> update radio image (below)
+ * else if command == "update-hboot" -> update hboot image (below)
+ * else -> boot boot.img (normal boot)
+ *
+ * Radio/Hboot Update Flow
+ * 1. the bootloader will attempt to load and validate the header
+ * 2. if the header is invalid, status="invalid-update", goto #8
+ * 3. display the busy image on-screen
+ * 4. if the update image is invalid, status="invalid-radio-image", goto #8
+ * 5. attempt to update the firmware (depending on the command)
+ * 6. if successful, status="okay", goto #8
+ * 7. if failed, and the old image can still boot, status="failed-update"
+ * 8. write the bootloader_message, leaving the recovery field
+ * unchanged, updating status, and setting command to
+ * "boot-recovery"
+ * 9. reboot
+ *
+ * The bootloader will not modify or erase the cache partition.
+ * It is recovery's responsibility to clean up the mess afterwards.
+ */
+
+int maybe_install_firmware_update(const char *send_intent) {
+ if (update_data == NULL || update_length == 0) return 0;
+
+ /* We destroy the cache partition to pass the update image to the
+ * bootloader, so all we can really do afterwards is wipe cache and reboot.
+ * Set up this instruction now, in case we're interrupted while writing.
+ */
+
+ struct bootloader_message boot;
+ memset(&boot, 0, sizeof(boot));
+ strlcpy(boot.command, "boot-recovery", sizeof(boot.command));
+ strlcpy(boot.recovery, "recovery\n--wipe_cache\n", sizeof(boot.command));
+ if (send_intent != NULL) {
+ strlcat(boot.recovery, "--send_intent=", sizeof(boot.recovery));
+ strlcat(boot.recovery, send_intent, sizeof(boot.recovery));
+ strlcat(boot.recovery, "\n", sizeof(boot.recovery));
+ }
+ if (set_bootloader_message(&boot)) return -1;
+
+ int width = 0, height = 0, bpp = 0;
+ char *busy_image = ui_copy_image(
+ BACKGROUND_ICON_FIRMWARE_INSTALLING, &width, &height, &bpp);
+ char *fail_image = ui_copy_image(
+ BACKGROUND_ICON_FIRMWARE_ERROR, &width, &height, &bpp);
+
+ ui_print("Writing %s image...\n", update_type);
+ if (write_update_for_bootloader(
+ update_data, update_length,
+ width, height, bpp, busy_image, fail_image)) {
+ LOGE("Can't write %s image\n(%s)\n", update_type, strerror(errno));
+ format_volume("/cache"); // Attempt to clean cache up, at least.
+ return -1;
+ }
+
+ free(busy_image);
+ free(fail_image);
+
+ /* The update image is fully written, so now we can instruct the bootloader
+ * to install it. (After doing so, it will come back here, and we will
+ * wipe the cache and reboot into the system.)
+ */
+ snprintf(boot.command, sizeof(boot.command), "update-%s", update_type);
+ if (set_bootloader_message(&boot)) {
+ format_volume("/cache");
+ return -1;
+ }
+
+ reboot(RB_AUTOBOOT);
+
+ // Can't reboot? WTF?
+ LOGE("Can't reboot\n");
+ return -1;
+}
View
35 src/firmware.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * 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.
+ */
+
+#ifndef _RECOVERY_FIRMWARE_H
+#define _RECOVERY_FIRMWARE_H
+
+/* Save a radio or bootloader update image for later installation.
+ * The type should be one of "hboot" or "radio".
+ * Takes ownership of type and data. Returns nonzero on error.
+ */
+int remember_firmware_update(const char *type, const char *data, int length);
+
+/* Returns true if a firmware update has been saved. */
+int firmware_update_pending();
+
+/* If an update was saved, reboot into the bootloader now to install it.
+ * Returns 0 if no radio image was defined, nonzero on error,
+ * doesn't return at all on success...
+ */
+int maybe_install_firmware_update(const char *send_intent);
+
+#endif
View
2 src/flashutils/Android.mk
@@ -7,7 +7,7 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := flashutils.c
LOCAL_MODULE := libflashutils
LOCAL_MODULE_TAGS := optional
-LOCAL_C_INCLUDES += bootable/recovery
+LOCAL_C_INCLUDES += src
LOCAL_STATIC_LIBRARIES := libmmcutils libmtdutils libbmlutils libcrecovery
BOARD_RECOVERY_DEFINES := BOARD_BML_BOOT BOARD_BML_RECOVERY
View
2 src/minelf/Android.mk
@@ -18,7 +18,7 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
Retouch.c
-LOCAL_C_INCLUDES += bootable/recovery
+LOCAL_C_INCLUDES += src
LOCAL_MODULE := libminelf
View
4 src/mtdutils/Android.mk
@@ -10,7 +10,7 @@ include $(BUILD_STATIC_LIBRARY)
ifeq ($(BOARD_USES_BML_OVER_MTD),true)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := bml_over_mtd.c
-LOCAL_C_INCLUDES += bootable/recovery/mtdutils
+LOCAL_C_INCLUDES += src/mtdutils
LOCAL_MODULE := libbml_over_mtd
LOCAL_MODULE_TAGS := eng
LOCAL_CFLAGS += -Dmain=bml_over_mtd_main
@@ -24,7 +24,7 @@ LOCAL_MODULE_CLASS := UTILITY_EXECUTABLES
LOCAL_MODULE_PATH := $(PRODUCT_OUT)/utilities
LOCAL_UNSTRIPPED_PATH := $(PRODUCT_OUT)/symbols/utilities
LOCAL_MODULE_STEM := bml_over_mtd
-LOCAL_C_INCLUDES += bootable/recovery/mtdutils
+LOCAL_C_INCLUDES += src/mtdutils
LOCAL_STATIC_LIBRARIES := libmtdutils libcutils libc
LOCAL_FORCE_STATIC_EXECUTABLE := true
include $(BUILD_EXECUTABLE)
View
34 src/nandroid.c
@@ -25,6 +25,7 @@
#include "common.h"
#include "libcrecovery/common.h"
#include "cutils/properties.h"
+#include "firmware.h"
#include "install.h"
#include "minzip/DirUtil.h"
#include "roots.h"
@@ -236,6 +237,8 @@ int nandroid_backup_partition(const char* backup_path, const char* root) {
// see if we need a raw backup (mtd)
char tmp[PATH_MAX];
+ sprintf(tmp, "mkdir -p %s", backup_path);
+ __system(tmp);
int ret;
if (strcmp(vol->fs_type, "mtd") == 0 ||
strcmp(vol->fs_type, "bml") == 0 ||
@@ -632,3 +635,34 @@ int nandroid_restore(const char* backup_path, int restore_boot, int restore_syst
return 0;
}
+int nandroid_usage()
+{
+ printf("Usage: nandroid backup\n");
+ printf("Usage: nandroid restore <directory>\n");
+ return 1;
+}
+
+int nandroid_main(int argc, char** argv)
+{
+ if (argc > 3 || argc < 2)
+ return nandroid_usage();
+
+ if (strcmp("backup", argv[1]) == 0)
+ {
+ if (argc != 2)
+ return nandroid_usage();
+
+ char backup_path[PATH_MAX];
+ nandroid_generate_timestamp_path(backup_path);
+ return nandroid_backup(backup_path);
+ }
+
+ if (strcmp("restore", argv[1]) == 0)
+ {
+ if (argc != 3)
+ return nandroid_usage();
+ return nandroid_restore(argv[2], 1, 1, 1, 1, 1, 0);
+ }
+
+ return nandroid_usage();
+}
View
102 src/utilities/Android.mk
@@ -0,0 +1,102 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_RECOVERY_EXECTABLES := fix_permissions
+LOCAL_RECOVERY_EXECTABLES += parted
+LOCAL_RECOVERY_EXECTABLES += sdparted
+LOCAL_RECOVERY_EXECTABLES += nandroid-md5.sh
+LOCAL_RECOVERY_EXECTABLES += killrecovery.sh
+RECOVERY_EXECTABLES := $(addprefix $(TARGET_ROOT_OUT)/sbin/, $(LOCAL_RECOVERY_EXECTABLES))
+$(RECOVERY_EXECTABLES): $(LOCAL_INSTALLED_MODULE)
+ @echo "copy $@ "
+ @mkdir -p $(dir $@)
+ @rm -rf $@
+ @cp -rf src/utilities/$(notdir $@) $(dir $@)
+
+ALL_DEFAULT_INSTALLED_MODULES += $(RECOVERY_EXECTABLES)
+
+#
+#include $(CLEAR_VARS)
+#LOCAL_MODULE := fix_permissions
+#LOCAL_MODULE_TAGS := optional
+#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 := parted
+#LOCAL_MODULE_TAGS := optional
+#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 := sdparted
+#LOCAL_MODULE_TAGS := optional
+#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 := e2fsck
+## LOCAL_MODULE_TAGS := optional
+## 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 := tune2fs
+## LOCAL_MODULE_TAGS := optional
+## 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 := mke2fs
+## LOCAL_MODULE_TAGS := optional
+## LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
+## LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
+## ifeq ($(BOARD_MKE2FS),)
+## LOCAL_SRC_FILES := $(LOCAL_MODULE)
+## else
+## LOCAL_SRC_FILES := ../../../$(BOARD_MKE2FS)
+## endif
+## include $(BUILD_PREBUILT)
+#
+#ifneq ($(TARGET_RECOVERY_FSTAB),)
+# BOARD_RECOVERY_RFS_CHECK := $(shell grep rfs $(TARGET_RECOVERY_FSTAB))
+#else
+# BOARD_RECOVERY_RFS_CHECK := $(shell grep rfs $(TARGET_DEVICE_DIR)/recovery.fstab)
+#endif
+#
+#ifneq ($(BOARD_RECOVERY_RFS_CHECK),)
+#include $(CLEAR_VARS)
+#LOCAL_MODULE := fat.format
+#LOCAL_MODULE_TAGS := optional
+#LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
+#LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
+#LOCAL_SRC_FILES := $(LOCAL_MODULE)
+#include $(BUILD_PREBUILT)
+#endif
+#
+#include $(CLEAR_VARS)
+#LOCAL_MODULE := nandroid-md5.sh
+#LOCAL_MODULE_TAGS := optional
+#LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
+#LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
+#LOCAL_SRC_FILES := nandroid-md5.sh
+#include $(BUILD_PREBUILT)
+#
+#include $(CLEAR_VARS)
+#LOCAL_MODULE := killrecovery.sh
+#LOCAL_MODULE_TAGS := optional
+#LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
+#LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
+#LOCAL_SRC_FILES := killrecovery.sh
+#include $(BUILD_PREBUILT)
+#
View
BIN src/utilities/e2fsck
Binary file not shown.
View
BIN src/utilities/fat.format
Binary file not shown.
View
484 src/utilities/fix_permissions
@@ -0,0 +1,484 @@
+#! /system/bin/sh
+#
+# Warning: if you want to run this script in cm-recovery change the above to #!/sbin/sh
+#
+# fix_permissions - fixes permissions on Android data directories after upgrade
+# shade@chemlab.org
+#
+# original concept: http://blog.elsdoerfer.name/2009/05/25/android-fix-package-uid-mismatches/
+# implementation by: Cyanogen
+# improved by: ankn, smeat, thenefield, farmatito, rikupw, Kastro
+#
+# v1.1-v1.31r3 - many improvements and concepts from XDA developers.
+# v1.34 through v2.00 - A lot of frustration [by Kastro]
+# v2.01 - Completely rewrote the script for SPEED, thanks for the input farmatito
+# /data/data depth recursion is tweaked;
+# fixed single mode;
+# functions created for modularity;
+# logging can be disabled via CLI for more speed;
+# runtime computation added to end (Runtime: mins secs);
+# progress (current # of total) added to screen;
+# fixed CLI argument parsing, now you can have more than one option!;
+# debug cli option;
+# verbosity can be disabled via CLI option for less noise;;
+# [by Kastro, (XDA: k4str0), twitter;mattcarver]
+# v2.02 - ignore com.htc.resources.apk if it exists and minor code cleanups,
+# fix help text, implement simulated run (-s) [farmatito]
+# v2.03 - fixed chown group ownership output [Kastro]
+# v2.04 - replaced /system/sd with $SD_EXT_DIRECTORY [Firerat]
+VERSION="2.04"
+
+# Defaults
+DEBUG=0 # Debug off by default
+LOGGING=1 # Logging on by default
+VERBOSE=1 # Verbose on by default
+
+# Messages
+UID_MSG="Changing user ownership for:"
+GID_MSG="Changing group ownership for:"
+PERM_MSG="Changing permissions for:"
+
+# Programs needed
+ECHO="busybox echo"
+GREP="busybox grep"
+EGREP="busybox egrep"
+CAT="busybox cat"
+CHOWN="busybox chown"
+CHMOD="busybox chmod"
+MOUNT="busybox mount"
+UMOUNT="busybox umount"
+CUT="busybox cut"
+FIND="busybox find"
+LS="busybox ls"
+TR="busybox tr"
+TEE="busybox tee"
+TEST="busybox test"
+SED="busybox sed"
+RM="busybox rm"
+WC="busybox wc"
+EXPR="busybox expr"
+DATE="busybox date"
+
+# Initialise vars
+CODEPATH=""
+UID=""
+GID=""
+PACKAGE=""
+REMOVE=0
+NOSYSTEM=0
+ONLY_ONE=""
+SIMULATE=0
+SYSREMOUNT=0
+SYSMOUNT=0
+DATAMOUNT=0
+SYSSDMOUNT=0
+FP_STARTTIME=$( $DATE +"%m-%d-%Y %H:%M:%S" )
+FP_STARTEPOCH=$( $DATE +%s )
+if $TEST "$SD_EXT_DIRECTORY" = ""; then
+ #check for mount point, /system/sd included in tests for backward compatibility
+ for MP in /sd-ext /system/sd;do
+ if $TEST -d $MP; then
+ SD_EXT_DIRECTORY=$MP
+ break
+ fi
+ done
+fi
+fp_usage()
+{
+ $ECHO "Usage $0 [OPTIONS] [APK_PATH]"
+ $ECHO " -d turn on debug"
+ $ECHO " -f fix only package APK_PATH"
+ $ECHO " -l disable logging for this run (faster)"
+ $ECHO " -r remove stale data directories"
+ $ECHO " of uninstalled packages while fixing permissions"
+ $ECHO " -s simulate only"
+ $ECHO " -u check only non-system directories"
+ $ECHO " -v disable verbosity for this run (less output)"
+ $ECHO " -V print version"
+ $ECHO " -h this help"
+}
+
+fp_parseargs()
+{
+ # Parse options
+ while $TEST $# -ne 0; do
+ case "$1" in
+ -d)
+ DEBUG=1
+ ;;
+ -f)
+ if $TEST $# -lt 2; then
+ $ECHO "$0: missing argument for option $1"
+ exit 1
+ else
+ if $TEST $( $ECHO $2 | $CUT -c1 ) != "-"; then
+ ONLY_ONE=$2
+ shift;
+ else
+ $ECHO "$0: missing argument for option $1"
+ exit 1
+ fi
+ fi
+ ;;
+ -r)
+ REMOVE=1
+ ;;
+ -s)
+ SIMULATE=1
+ ;;
+ -l)
+ if $TEST $LOGGING -eq 0; then
+ LOGGING=1
+ else
+ LOGGING=0
+ fi
+ ;;
+ -v)
+ if $TEST $VERBOSE -eq 0; then
+ VERBOSE=1
+ else
+ VERBOSE=0
+ fi
+ ;;
+ -u)
+ NOSYSTEM=1
+ ;;
+ -V)
+ $ECHO "$0 $VERSION"
+ exit 0
+ ;;
+ -h)
+ fp_usage
+ exit 0
+ ;;
+ -*)
+ $ECHO "$0: unknown option $1"
+ $ECHO
+ fp_usage
+ exit 1
+ ;;
+ esac
+ shift;
+ done
+}
+
+fp_print()
+{
+ MSG=$@
+ if $TEST $LOGGING -eq 1; then
+ $ECHO $MSG | $TEE -a $LOG_FILE
+ else
+ $ECHO $MSG
+ fi
+}
+
+fp_start()
+{
+ if $TEST $SIMULATE -eq 0 ; then
+ if $TEST $( $GREP -c " /system " "/proc/mounts" ) -ne 0; then
+ DEVICE=$( $GREP " /system " "/proc/mounts" | $CUT -d ' ' -f1 )
+ if $TEST $DEBUG -eq 1; then
+ fp_print "/system mounted on $DEVICE"
+ fi
+ if $TEST $( $GREP " /system " "/proc/mounts" | $GREP -c " ro " ) -ne 0; then
+ $MOUNT -o remount,rw $DEVICE /system
+ SYSREMOUNT=1
+ fi
+ else
+ $MOUNT /system > /dev/null 2>&1
+ SYSMOUNT=1
+ fi
+
+ if $TEST $( $GREP -c " /data " "/proc/mounts" ) -eq 0; then
+ $MOUNT /data > /dev/null 2>&1
+ DATAMOUNT=1
+ fi
+
+ if $TEST -e /dev/block/mmcblk0p2 && $TEST $( $GREP -c " $SD_EXT_DIRECTORY " "/proc/mounts" ) -eq 0; then
+ $MOUNT $SD_EXT_DIRECTORY > /dev/null 2>&1
+ SYSSDMOUNT=1
+ fi
+ fi
+ if $TEST $( $MOUNT | $GREP -c /sdcard ) -eq 0; then
+ LOG_FILE="/data/fix_permissions.log"
+ else
+ LOG_FILE="/sdcard/fix_permissions.log"
+ fi
+ if $TEST ! -e "$LOG_FILE"; then
+ > $LOG_FILE
+ fi
+
+ fp_print "$0 $VERSION started at $FP_STARTTIME"
+}
+
+fp_chown_uid()
+{
+ FP_OLDUID=$1
+ FP_UID=$2
+ FP_FILE=$3
+
+ #if user ownership doesn't equal then change them
+ if $TEST "$FP_OLDUID" != "$FP_UID"; then
+ if $TEST $VERBOSE -ne 0; then
+ fp_print "$UID_MSG $FP_FILE from '$FP_OLDUID' to '$FP_UID'"
+ fi
+ if $TEST $SIMULATE -eq 0; then
+ $CHOWN $FP_UID "$FP_FILE"
+ fi
+ fi
+}
+
+fp_chown_gid()
+{
+ FP_OLDGID=$1
+ FP_GID=$2
+ FP_FILE=$3
+
+ #if group ownership doesn't equal then change them
+ if $TEST "$FP_OLDGID" != "$FP_GID"; then
+ if $TEST $VERBOSE -ne 0; then
+ fp_print "$GID_MSG $FP_FILE from '$FP_OLDGID' to '$FP_GID'"
+ fi
+ if $TEST $SIMULATE -eq 0; then
+ $CHOWN :$FP_GID "$FP_FILE"
+ fi
+ fi
+}
+
+fp_chmod()
+{
+ FP_OLDPER=$1
+ FP_OLDPER=$( $ECHO $FP_OLDPER | cut -c2-10 )
+ FP_PERSTR=$2
+ FP_PERNUM=$3
+ FP_FILE=$4
+
+ #if the permissions are not equal
+ if $TEST "$FP_OLDPER" != "$FP_PERSTR"; then
+ if $TEST $VERBOSE -ne 0; then
+ fp_print "$PERM_MSG $FP_FILE from '$FP_OLDPER' to '$FP_PERSTR' ($FP_PERNUM)"
+ fi
+ #change the permissions
+ if $TEST $SIMULATE -eq 0; then
+ $CHMOD $FP_PERNUM "$FP_FILE"
+ fi
+ fi
+}
+
+fp_all()
+{
+ FP_NUMS=$( $CAT /data/system/packages.xml | $EGREP "^<package.*serId" | $GREP -v framework-res.apk | $GREP -v com.htc.resources.apk | $WC -l )
+ I=0
+ $CAT /data/system/packages.xml | $EGREP "^<package.*serId" | $GREP -v framework-res.apk | $GREP -v com.htc.resources.apk | while read all_line; do
+ I=$( $EXPR $I + 1 )
+ fp_package "$all_line" $I $FP_NUMS
+ done
+}
+
+fp_single()
+{
+ FP_SFOUND=$( $CAT /data/system/packages.xml | $EGREP "^<package.*serId" | $GREP -v framework-res.apk | $GREP -v com.htc.resources.apk | $GREP -i $ONLY_ONE | wc -l )
+ if $TEST $FP_SFOUND -gt 1; then
+ fp_print "Cannot perform single operation on $FP_SFOUND matched package(s)."
+ elif $TEST $FP_SFOUND = "" -o $FP_SFOUND -eq 0; then
+ fp_print "Could not find the package you specified in the packages.xml file."
+ else
+ FP_SPKG=$( $CAT /data/system/packages.xml | $EGREP "^<package.*serId" | $GREP -v framework-res.apk | $GREP -v com.htc.resources.apk | $GREP -i $ONLY_ONE )
+ fp_package "${FP_SPKG}" 1 1
+ fi
+}
+
+fp_package()
+{
+ pkgline=$1
+ curnum=$2
+ endnum=$3
+ CODEPATH=$( $ECHO $pkgline | $SED 's%.* codePath="\(.*\)".*%\1%' | $CUT -d '"' -f1 )
+ PACKAGE=$( $ECHO $pkgline | $SED 's%.* name="\(.*\)".*%\1%' | $CUT -d '"' -f1 )
+ UID=$( $ECHO $pkgline | $SED 's%.*serId="\(.*\)".*%\1%' | $CUT -d '"' -f1 )
+ GID=$UID
+ APPDIR=$( $ECHO $CODEPATH | $SED 's%^\(.*\)/.*%\1%' )
+ APK=$( $ECHO $CODEPATH | $SED 's%^.*/\(.*\..*\)$%\1%' )
+
+ #debug
+ if $TEST $DEBUG -eq 1; then
+ fp_print "CODEPATH: $CODEPATH APPDIR: $APPDIR APK:$APK UID/GID:$UID:$GID"
+ fi
+
+ #check for existence of apk
+ if $TEST -e $CODEPATH; then
+ fp_print "Processing ($curnum of $endnum): $PACKAGE..."
+
+ #lets get existing permissions of CODEPATH
+ OLD_UGD=$( $LS -ln "$CODEPATH" )
+ OLD_PER=$( $ECHO $OLD_UGD | $CUT -d ' ' -f1 )
+ OLD_UID=$( $ECHO $OLD_UGD | $CUT -d ' ' -f3 )
+ OLD_GID=$( $ECHO $OLD_UGD | $CUT -d ' ' -f4 )
+
+ #apk source dirs
+ if $TEST "$APPDIR" = "/system/app"; then
+ #skip system apps if set
+ if $TEST "$NOSYSTEM" = "1"; then
+ fp_print "***SKIPPING SYSTEM APP ($PACKAGE)!"
+ return
+ fi
+ fp_chown_uid $OLD_UID 0 "$CODEPATH"
+ fp_chown_gid $OLD_GID 0 "$CODEPATH"
+ fp_chmod $OLD_PER "rw-r--r--" 644 "$CODEPATH"
+ elif $TEST "$APPDIR" = "/data/app" || $TEST "$APPDIR" = "/sd-ext/app"; then
+ fp_chown_uid $OLD_UID 1000 "$CODEPATH"
+ fp_chown_gid $OLD_GID 1000 "$CODEPATH"
+ fp_chmod $OLD_PER "rw-r--r--" 644 "$CODEPATH"
+ elif $TEST "$APPDIR" = "/data/app-private" || $TEST "$APPDIR" = "/sd-ext/app-private"; then
+ fp_chown_uid $OLD_UID 1000 "$CODEPATH"
+ fp_chown_gid $OLD_GID $GID "$CODEPATH"
+ fp_chmod $OLD_PER "rw-r-----" 640 "$CODEPATH"
+ fi
+ else
+ fp_print "$CODEPATH does not exist ($curnum of $endnum). Reinstall..."
+ if $TEST $REMOVE -eq 1; then
+ if $TEST -d /data/data/$PACKAGE ; then
+ fp_print "Removing stale dir /data/data/$PACKAGE"
+ if $TEST $SIMULATE -eq 0 ; then
+ $RM -R /data/data/$PACKAGE
+ fi
+ fi
+ fi
+ fi
+
+ #the data/data for the package
+ if $TEST -d "/data/data/$PACKAGE"; then
+ #find all directories in /data/data/$PACKAGE
+ $FIND /data/data/$PACKAGE -type d -exec $LS -ldn {} \; | while read dataline; do
+ #get existing permissions of that directory
+ OLD_PER=$( $ECHO $dataline | $CUT -d ' ' -f1 )
+ OLD_UID=$( $ECHO $dataline | $CUT -d ' ' -f3 )
+ OLD_GID=$( $ECHO $dataline | $CUT -d ' ' -f4 )
+ FILEDIR=$( $ECHO $dataline | $CUT -d ' ' -f9 )
+ FOURDIR=$( $ECHO $FILEDIR | $CUT -d '/' -f5 )
+
+ #set defaults for iteration
+ ISLIB=0
+ REVPERM=755
+ REVPSTR="rwxr-xr-x"
+ REVUID=$UID
+ REVGID=$GID
+
+ if $TEST "$FOURDIR" = ""; then
+ #package directory, perms:755 owner:$UID:$GID
+ fp_chmod $OLD_PER "rwxr-xr-x" 755 "$FILEDIR"
+ elif $TEST "$FOURDIR" = "lib"; then
+ #lib directory, perms:755 owner:1000:1000
+ #lib files, perms:755 owner:1000:1000
+ ISLIB=1
+ REVPERM=755
+ REVPSTR="rwxr-xr-x"
+ REVUID=1000
+ REVGID=1000
+ fp_chmod $OLD_PER "rwxr-xr-x" 755 "$FILEDIR"
+ elif $TEST "$FOURDIR" = "shared_prefs"; then
+ #shared_prefs directories, perms:771 owner:$UID:$GID
+ #shared_prefs files, perms:660 owner:$UID:$GID
+ REVPERM=660
+ REVPSTR="rw-rw----"
+ fp_chmod $OLD_PER "rwxrwx--x" 771 "$FILEDIR"
+ elif $TEST "$FOURDIR" = "databases"; then
+ #databases directories, perms:771 owner:$UID:$GID
+ #databases files, perms:660 owner:$UID:$GID
+ REVPERM=660
+ REVPSTR="rw-rw----"
+ fp_chmod $OLD_PER "rwxrwx--x" 771 "$FILEDIR"
+ elif $TEST "$FOURDIR" = "cache"; then
+ #cache directories, perms:771 owner:$UID:$GID
+ #cache files, perms:600 owner:$UID:GID
+ REVPERM=600
+ REVPSTR="rw-------"
+ fp_chmod $OLD_PER "rwxrwx--x" 771 "$FILEDIR"
+ else
+ #other directories, perms:771 owner:$UID:$GID
+ REVPERM=771
+ REVPSTR="rwxrwx--x"
+ fp_chmod $OLD_PER "rwxrwx--x" 771 "$FILEDIR"
+ fi
+
+ #change ownership of directories matched
+ if $TEST "$ISLIB" = "1"; then
+ fp_chown_uid $OLD_UID 1000 "$FILEDIR"
+ fp_chown_gid $OLD_GID 1000 "$FILEDIR"
+ else
+ fp_chown_uid $OLD_UID $UID "$FILEDIR"
+ fp_chown_gid $OLD_GID $GID "$FILEDIR"
+ fi
+
+ #if any files exist in directory with improper permissions reset them
+ $FIND $FILEDIR -type f -maxdepth 1 ! -perm $REVPERM -exec $LS -ln {} \; | while read subline; do
+ OLD_PER=$( $ECHO $subline | $CUT -d ' ' -f1 )
+ SUBFILE=$( $ECHO $subline | $CUT -d ' ' -f9 )
+ fp_chmod $OLD_PER $REVPSTR $REVPERM "$SUBFILE"
+ done
+
+ #if any files exist in directory with improper user reset them
+ $FIND $FILEDIR -type f -maxdepth 1 ! -user $REVUID -exec $LS -ln {} \; | while read subline; do
+ OLD_UID=$( $ECHO $subline | $CUT -d ' ' -f3 )
+ SUBFILE=$( $ECHO $subline | $CUT -d ' ' -f9 )
+ fp_chown_uid $OLD_UID $REVUID "$SUBFILE"
+ done
+
+ #if any files exist in directory with improper group reset them
+ $FIND $FILEDIR -type f -maxdepth 1 ! -group $REVGID -exec $LS -ln {} \; | while read subline; do
+ OLD_GID=$( $ECHO $subline | $CUT -d ' ' -f4 )
+ SUBFILE=$( $ECHO $subline | $CUT -d ' ' -f9 )
+ fp_chown_gid $OLD_GID $REVGID "$SUBFILE"
+ done
+ done
+ fi
+}
+
+date_diff()
+{
+ if $TEST $# -ne 2; then
+ FP_DDM="E"
+ FP_DDS="E"
+ return
+ fi
+ FP_DDD=$( $EXPR $2 - $1 )
+ FP_DDM=$( $EXPR $FP_DDD / 60 )
+ FP_DDS=$( $EXPR $FP_DDD % 60 )
+}
+
+fp_end()
+{
+ if $TEST $SYSREMOUNT -eq 1; then
+ $MOUNT -o remount,ro $DEVICE /system > /dev/null 2>&1
+ fi
+
+ if $TEST $SYSSDMOUNT -eq 1; then
+ $UMOUNT $SD_EXT_DIRECTORY > /dev/null 2>&1
+ fi
+
+ if $TEST $SYSMOUNT -eq 1; then
+ $UMOUNT /system > /dev/null 2>&1
+ fi
+
+ if $TEST $DATAMOUNT -eq 1; then
+ $UMOUNT /data > /dev/null 2>&1
+ fi
+
+ FP_ENDTIME=$( $DATE +"%m-%d-%Y %H:%M:%S" )
+ FP_ENDEPOCH=$( $DATE +%s )
+
+ date_diff $FP_STARTEPOCH $FP_ENDEPOCH
+
+ fp_print "$0 $VERSION ended at $FP_ENDTIME (Runtime:${FP_DDM}m${FP_DDS}s)"
+}
+
+#MAIN SCRIPT
+
+fp_parseargs $@
+fp_start
+if $TEST "$ONLY_ONE" != "" -a "$ONLY_ONE" != "0" ; then
+ fp_single "$ONLY_ONE"
+else
+ fp_all
+fi
+fp_end
View
22 src/utilities/killrecovery.sh
@@ -0,0 +1,22 @@
+#!/sbin/sh
+mkdir -p /sd-ext
+rm /cache/recovery/command
+rm /cache/update.zip
+touch /tmp/.ignorebootmessage
+kill $(ps | grep /sbin/adbd)
+kill $(ps | grep /sbin/recovery)
+
+# On the Galaxy S, the recovery comes test signed, but the
+# recovery is not automatically restarted.
+if [ -f /init.smdkc110.rc ]
+then
+ /sbin/recovery &
+fi
+
+# Droid X
+if [ -f /init.mapphone_cdma.rc ]
+then
+ /sbin/recovery &
+fi
+
+exit 1
View
BIN src/utilities/mke2fs
Binary file not shown.
View
12 src/utilities/nandroid-md5.sh
@@ -0,0 +1,12 @@
+#!/sbin/sh
+cd $1
+rm -f /tmp/nandroid.md5
+md5sum * .* > /tmp/nandroid.md5
+cp /tmp/nandroid.md5 .
+# need this because wildcard seems to cause md5sum to return 1
+if [ -f nandroid.md5 ]
+then
+ return 0
+else
+ return 1
+fi
View
BIN src/utilities/parted
Binary file not shown.
View
655 src/utilities/sdparted
@@ -0,0 +1,655 @@
+#!/sbin/sh
+
+# do logging, if not excluded with -x
+LOGFILE="/data/sdparted.log"
+[ "$1" != "-x" ] && echo "$0" "$@" >> "$LOGFILE" && "$0" -x "$@" 2>&1 | tee -a "$LOGFILE" && exit
+shift
+
+ShowError() { echo ; echo " err: $1" ; echo ; exit 1 ; }
+
+ShowMessage() { echo ; echo " msg: $1" ; }
+
+ShowHelp() {
+
+cat <<DONEHELP
+
+$SCRIPTNAME v$SCRIPTREV created by $MYNAME
+
+if you use this script in your work, please give some credit. thanks.
+
+requirements: cm-recovery-v1.4
+
+usage: $SCRIPTNAME [options]
+
+
+options:
+
+ --fatsize|-fs SIZE[MG] set the size of the fat32 partition to <SIZE>.
+ default=total sdcard size - (ext + swap)
+
+ --extsize|-es SIZE[MG] set the size of the ext partition to <SIZE>.
+ default=$EXTSIZE
+
+ --swapsize|-ss SIZE[MG] set the size of the swap partition to <SIZE>.
+ if set to 0, no swap partition will be created.
+ default=$SWAPSIZE
+
+ --extfs|-efs TYPE set the filesystem of ext partition to <TYPE>.
+ valid types=ext2, ext3, ext4
+ default=$EXTFS
+
+
+ --upgradefs|-ufs TYPE upgrades existing ext partition to <TYPE>.
+ this operation will NOT wipe your sdcard and
+ cannot be used with any partition creation options.
+ valid types=ext3, ext4
+
+ --downgradefs|-dfs TYPE downgrades existing ext partition to <TYPE>.
+ this operation will NOT wipe your sdcard and
+ cannot be used with any partition creation options.
+ valid types=ext2
+
+
+ --interactive|-i interactive mode
+
+ --help|-h display this help
+
+ --printonly|-po display sdcard information
+
+ --silent|-s do not prompt user, not even initial warning.
+
+
+examples:
+ $SCRIPTNAME creates swap=$SWAPSIZE ext2=$EXTSIZE fat32=remaining free space
+ $SCRIPTNAME -efs ext4 creates swap=$SWAPSIZE ext4=$EXTSIZE fat32=remaining free space
+ $SCRIPTNAME -fs 1.5G -efs ext3 creates swap=$SWAPSIZE ext3=$EXTSIZE fat32=1536
+ $SCRIPTNAME -es 256M -ss 0 creates no swap ext2=256 fat32=remaining free space
+ $SCRIPTNAME -ufs ext4 upgrades ext partition to ext4
+
+DONEHELP
+
+}
+
+UserAbort() {
+
+ WHILEEXIT=
+
+ while [ -z "$WHILEEXIT" ]
+ do
+ echo -n "do you want to continue? (Y/n) "
+ read response
+ echo
+ [ "$response" = "Y" ] || [ "$response" = "n" ] || [ "$response" = "N" ] && WHILEEXIT="$response"
+ done
+
+ echo "$response" > /dev/null 2>&1 >>"$LOGFILE"
+
+ [ "$response" != "Y" ]
+
+}
+
+UnmountAll () {
+
+ # unmount all partitions so we can work with $SDPATH
+ # i'm assuming no more than 3 partitions
+ # maybe make a little more elegant later
+ echo -n "unmounting all partitions..."
+ umount "$FATPATH" > /dev/null 2>&1 >>"$LOGFILE"
+ umount "$EXTPATH" > /dev/null 2>&1 >>"$LOGFILE"
+ umount "$SWAPPATH" > /dev/null 2>&1 >>"$LOGFILE"
+ echo "done"
+ echo
+
+}
+
+
+CheckReqs() {
+
+ echo -n "checking script requirements..."
+ # check for valid sdcard
+ [ -e $SDPATH ] || ShowError "$SDPATH does not exist!"
+
+ # look for necessary programs
+ [ -e $CMPARTED ] || ShowError "$CMPARTED does not exist!"
+ [ -e $CMTUNE2FS ] || ShowError "$CMTUNE2FS does not exist!"
+ [ -e $CME2FSCK ] || ShowError "$CME2FSCK does not exist!"
+
+ # verify cm-v1.4
+ PARTEDREV=`"$CMPARTED" "$SDPATH" version | grep Parted | cut -d" " -f3`
+ [ "$PARTEDREV" == "1.8.8.1.179-aef3" ] || ShowError "you are not using parted v1.8.8.1.179-aef3!"
+ echo "done"
+ echo
+
+}
+
+CheckTableType() {
+
+ TABLETYPE=`"$CMPARTED" "$SDPATH" print | grep Table: | cut -d" " -f3`
+
+ [ "$TABLETYPE" == "loop" -o "$TABLETYPE" == "msdos" ] && TTISOK=1 || TTISOK=0
+ [ "$TABLETYPE" == "loop" ] && TTISLOOP=1 || TTISLOOP=0
+ [ "$TABLETYPE" == "msdos" ] && TTISMSDOS=1 || TTISMOSDOS=0
+
+}
+
+ValidateExtArg() {
+
+ FUNC_RET="nonzero"
+
+ # validating argument
+ [ "$1" != "ext2" ] && [ "$1" != "ext3" ] && [ "$1" != "ext4" ] && FUNC_RET=
+
+ [ -z "$FUNC_RET" ] && [ -z "$IMODE" ] && ShowError "$1 is not a valid filesystem."
+ [ -z "$FUNC_RET" ] && [ -n "$IMODE" ] && ShowMessage "$1 is not a valid filesystem."
+
+ # return valid argument
+ [ -n "$FUNC_RET" ] && FUNC_RET="$1"
+
+}
+
+ValidateSizeArg() {
+
+ # check for zero-length arg to protect expr length
+ [ -z "$1" ] && ShowError "zero-length argument passed to size-validator"
+
+ SIZEMB=
+ ARGLEN=`expr length $1`
+ SIZELEN=$(($ARGLEN-1))
+ SIZEARG=`expr substr $1 1 $SIZELEN`
+ SIZEUNIT=`expr substr $1 $ARGLEN 1`
+
+ # check if SIZEARG is an integer
+ if [ $SIZEARG -eq $SIZEARG 2> /dev/null ] ; then
+ # look for G
+ [ "$SIZEUNIT" == "G" ] && SIZEMB=$(($SIZEARG * 1024))
+ # look for M
+ [ "$SIZEUNIT" == "M" ] && SIZEMB=$SIZEARG
+ # no units on arg AND prevents using bogus size units
+ [ -z "$SIZEMB" ] && [ $SIZEUNIT -eq $SIZEUNIT 2> /dev/null ] && SIZEMB=$1
+ # check if SIZEARG is a floating point number, GB only
+ elif [ `expr index "$SIZEARG" .` != 0 ] && [ "$SIZEUNIT" == "G" ] ; then
+ INT=`echo "$SIZEARG" | cut -d"." -f1`
+ FRAC=`echo "$SIZEARG" | cut -d"." -f2`
+ SIGDIGITS=`expr length $FRAC`
+
+ [ -z "$INT" ] && INT=0
+ INTMB=$(($INT * 1024))
+ FRACMB=$((($FRAC * 1024) / (10**$SIGDIGITS)))
+ SIZEMB=$(($INTMB + $FRACMB))
+ # it's not a valid size
+ else
+ [ -z "$IMODE" ] && ShowError "$1 is not a valid size"
+ fi
+
+ [ -z "$SIZEMB" ] && [ -n "$IMODE" ] && ShowMessage "$1 is not a valid size"
+
+ # return valid argument in MB
+ FUNC_RET=$SIZEMB
+
+}
+
+CalculatePartitions() {
+
+ # get size of sdcard in MB & do some math
+ SDSIZEMB=`"$CMPARTED" "$SDPATH" unit MB print | grep $SDPATH | cut -d" " -f3`
+ SDSIZE=${SDSIZEMB%MB}
+ [ -n "$FATSIZE" ] || FATSIZE=$(($SDSIZE - $EXTSIZE - $SWAPSIZE))
+ EXTEND=$(($FATSIZE + $EXTSIZE))
+ SWAPEND=$(($EXTEND + $SWAPSIZE))
+
+ # check for fatsize of 0
+ [ $FATSIZE -le 0 ] && ShowError "must have a fat32 partition greater than 0MB"
+
+ # check for zero-length sdsize...
+ # indicative of parted not reporting length
+ # correctly b/c of error on sdcard
+ [ -z "$SDSIZE" ] && ShowError "zero-length argument passed to partition-calculator"
+
+ # make sure we're not being asked to do the impossible
+ [ $(($FATSIZE + $EXTSIZE + $SWAPSIZE)) -gt $SDSIZE ] && [ -z "$IMODE" ] && ShowError "sum of requested partitions is greater than sdcard size"
+
+}
+
+
+UpgradeDowngradeOnly() {
+
+ if [ -n "$UEXTFSONLY" ] ; then
+ echo
+ [ -n "$CREATEPART" ] && ShowError "cannot use upgrade option when creating partitions, use -efs instead"
+ [ -n "$DEXTFSONLY" ] && ShowError "cannot upgrade AND downgrade, it just doesn't make sense"
+ echo "you have chosen to upgrade $EXTPATH to $UEXTFSONLY."
+ echo "this action will NOT delete any data from sdcard."
+ echo
+ [ -z "$SILENTRUN" ] && UserAbort && ShowError "script canceled by user"
+ echo
+ UpgradeExt "$UEXTFSONLY"
+ ShowCardInfo
+ elif [ -n "$DEXTFSONLY" ] ; then
+ echo
+ [ -n "$CREATEPART" ] && ShowError "cannot use downgrade option when creating partitions."
+ [ -n "$UEXTFSONLY" ] && ShowError "cannot downgrade AND upgrade, it just doesn't make sense."
+ echo "you have chosen to downgrade $EXTPATH to $DEXTFSONLY."
+ echo "this action will NOT delete any data from sdcard."
+ echo
+ [ -z "$SILENTRUN" ] && UserAbort && ShowError "script canceled by user"
+ echo
+ DowngradeExt "$DEXTFSONLY"
+ ShowCardInfo
+ fi
+
+}
+
+PrepareSdCard() {
+
+ echo
+ if [ $TTISOK -eq 0 ] ; then
+ echo "partition 1 may not be aligned to cylinder boundaries."
+ echo "to continue, this must be corrected."
+ elif [ $TTISLOOP -gt 0 ] ; then
+ echo "your sdcard's partition table type is $TABLETYPE."
+ echo "to continue, partition table must be set to 'msdos'."
+ elif [ $TTISMSDOS -gt 0 ] ; then
+ # just a reminder..in a later version,
+ # i may implement resizing of partitions,
+ # so this will be unnecessary. but until then...
+ echo "to continue, all existing partitions must be removed."
+ else
+ # this is not good, and should never happen
+ # if it does, there is a serious problem
+ ShowError "sdcard failed table type check."
+ fi
+
+ echo
+ echo "this action will remove all data from your sdcard."
+ echo
+ [ -z "$SILENTRUN" ] && UserAbort && ShowError "script canceled by user"
+
+ [ $TTISOK -eq 0 ] && echo -n "correcting cylinder boundaries..."
+ [ $TTISLOOP -gt 0 ] && echo -n "setting partition table to msdos..."
+ [ $TTISMSDOS -gt 0 ] && echo -n "removing all partitions..."
+
+ "$CMPARTED" -s "$SDPATH" mklabel msdos 2>&1 >>"$LOGFILE"
+ echo "done"
+ echo
+
+}
+
+ShowActions() {
+
+ echo
+ echo "total size of sdcard=$SDSIZEMB"
+ echo
+ echo "the following actions will be performed:"
+ echo " -create $FATSIZE""MB fat32 partition"
+ [ $EXTSIZE -gt 0 ] && echo " -create $EXTSIZE""MB ext2 partition"
+ [ $SWAPSIZE -gt 0 ] && echo " -create $SWAPSIZE""MB swap partition"
+ [ "$EXTFS" != "ext2" ] && echo " -ext2 partition will be upgraded to $EXTFS"
+ echo
+ [ -z "$SILENTRUN" ] && UserAbort && ShowError "script canceled by user"
+ echo
+
+}
+
+ShowCardInfo() {
+
+ CheckTableType
+
+ echo
+ echo "retrieving current sdcard information..."
+
+ if [ $TTISOK -gt 0 ] ; then
+ echo
+ parted "$SDPATH" print
+ echo
+ echo "script log is located @ /data/sdparted.log"
+ exit 0
+ else
+ echo
+ echo "partition 1 may not be aligned to cylinder boundaries."
+ ShowError "cannot complete print operation."
+ fi
+ echo
+
+}
+
+
+PartitionSdCard() {
+
+ echo "performing selected actions..."
+ echo
+
+ if [ $FATSIZE -gt 0 ] ; then
+ echo -n "creating fat32 partition..."
+ "$CMPARTED" -s "$SDPATH" mkpartfs primary fat32 0 "$FATSIZE"MB 2>&1 >>"$LOGFILE"
+ echo "done"
+ fi
+
+ if [ $EXTSIZE -gt 0 ] ; then
+ echo -n "creating ext2 partition..."
+ "$CMPARTED" -s "$SDPATH" mkpartfs primary ext2 "$FATSIZE"MB "$EXTEND"MB 2>&1 >>"$LOGFILE"
+ "$CMTUNE2FS" -L sd-ext "$EXTPATH" 2>&1 >>"$LOGFILE"
+ echo "done"
+ fi
+
+ if [ $SWAPSIZE -gt 0 ] ; then
+ echo -n "creating swap partition..."
+ "$CMPARTED" -s "$SDPATH" mkpartfs primary linux-swap "$EXTEND"MB "$SWAPEND"MB 2>&1 >>"$LOGFILE"
+ echo "done"
+ fi
+ echo
+
+}
+
+UpgradeExt() {
+
+ # check for no upgrade
+ [ "$1" == "ext2" ] && return
+ # check for ext partition
+ [ ! -e "$EXTPATH" ] && ShowError "$EXTPATH does not exist"
+
+ # have to use -m switch for this check b/c parted incorrectly
+ # reports all ext partitions as ext2 when running print <number>
+ CHECKEXTFS=`"$CMPARTED" -m "$SDPATH" print | grep ext | cut -d":" -f5`
+ [ "$CHECKEXTFS" == "$1" ] && ShowError "$EXTPATH is already $1"
+
+ # grabbed the code bits for ext3 from upgrade_fs(credit:cyanogen)
+ # check for ext2...must upgrade to ext3 first b4 ext4
+ if [ "$1" == "ext3" -o "$1" == "ext4" ] ; then
+ echo -n "adding journaling to $EXTPATH..."
+ umount /system/sd > /dev/null 2>&1 >>"$LOGFILE"
+ "$CME2FSCK" -p "$EXTPATH" 2>&1 >>"$LOGFILE"
+ "$CMTUNE2FS" -c0 -i0 -j "$EXTPATH" 2>&1 >>"$LOGFILE"
+ echo "done"
+ fi
+
+ # and got convert to ext4 from xda-forum(credit:Denkai)
+ if [ "$1" == "ext4" ] ; then
+ echo -n "converting $EXTPATH to ext4 filesystem..."
+ umount /system/sd > /dev/null 2>&1 >>"$LOGFILE"
+ "$CMTUNE2FS" -O extents,uninit_bg,dir_index "$EXTPATH" 2>&1 >>"$LOGFILE"
+ "$CME2FSCK" -fpDC0 "$EXTPATH" 2>&1 >>"$LOGFILE"
+ echo "done"
+ fi
+ echo
+
+}
+
+DowngradeExt() {
+
+ # check for ext partition
+ [ ! -e "$EXTPATH" ] && ShowError "$EXTPATH does not exist"
+
+ # have to use print for this check b/c parted incorrectly
+ # reports all ext partitions as ext2 when running print <number>
+ CHECKEXTFS=`"$CMPARTED" -m "$SDPATH" print | grep ext | cut -d":" -f5`
+ [ "$CHECKEXTFS" == "$1" ] && ShowError "$EXTPATH is already $1"
+
+ if [ "$CHECKEXTFS" == "ext4" -o "$1" == "ext3" ] ; then
+ # interweb says downgrading from ext4 is not possible
+ # without a backup/restore procedure.
+ # if i figure it out, i'll implement it.
+ ShowError "downgrading from ext4 is not currently supported"
+ fi
+
+ if [ "$1" == "ext2" ] ; then
+ echo -n "removing journaling from $EXTPATH..."
+ umount /system/sd > /dev/null 2>&1 >>"$LOGFILE"
+ "$CMTUNE2FS" -O ^has_journal "$EXTPATH" 2>&1 >>"$LOGFILE"
+ "$CME2FSCK" -fp "$EXTPATH" 2>&1 >>"$LOGFILE"
+ echo "done"
+ fi
+ echo
+
+}
+
+
+Interactive() {
+
+cat <<DONEINSTRUCT
+
+sdparted interactive mode
+
+rules:
+1. no answer means you accept default value
+2. enter '0' for no partition
+
+DONEINSTRUCT
+
+ UserAbort && ShowError "script canceled by user"
+
+ CalculatePartitions
+
+ GetSwapSize
+
+ FATSIZE=
+
+ CalculatePartitions
+
+ GetExtSize
+
+ GetExtType
+
+ FATSIZE=
+
+ CalculatePartitions
+
+ GetFatSize
+
+}
+
+GetSwapSize() {
+
+ SWAPTEST=
+
+ while [ -z "$SWAPTEST" ]
+ do
+ echo
+ echo -n "swap partition size [default=$SWAPSIZE]: "
+ read SWAPRESP
+
+ [ -z "$SWAPRESP" ] && SWAPRESP="$SWAPSIZE"
+ echo "$SWAPRESP" > /dev/null 2>&1 >>"$LOGFILE"
+
+ ValidateSizeArg "$SWAPRESP"
+ SWAPTEST="$FUNC_RET"
+ [ -n "$SWAPTEST" ] && [ $SWAPTEST -gt $SDSIZE ] && ShowMessage "$SWAPRESP > available space($(($SDSIZE))M)." && SWAPTEST=
+ done
+
+ SWAPSIZE=$SWAPTEST
+
+}
+
+GetExtSize() {
+
+ EXTTEST=
+
+ while [ -z "$EXTTEST" ]
+ do
+ echo
+ echo -n "ext partition size [default=$EXTSIZE]: "
+ read EXTRESP
+
+ [ -z "$EXTRESP" ] && EXTRESP="$EXTSIZE"
+ echo "$EXTRESP" > /dev/null 2>&1 >>"$LOGFILE"
+
+ ValidateSizeArg "$EXTRESP"
+ EXTTEST="$FUNC_RET"
+
+ [ -n "$EXTTEST" ] && [ $EXTTEST -gt $(($SDSIZE - $SWAPSIZE)) ] && ShowMessage "$EXTRESP > available space($(($SDSIZE - $SWAPSIZE))M)." && EXTTEST=
+ done
+
+ EXTSIZE=$EXTTEST
+
+}
+
+GetExtType() {
+
+ FSTEST=
+
+ while [ -z "$FSTEST" ]
+ do
+ echo
+ echo -n "ext partition type [default=$EXTFS]: "
+ read FSRESP
+
+ [ -z "$FSRESP" ] && FSRESP="$EXTFS"
+ echo "$FSRESP" > /dev/null 2>&1 >>"$LOGFILE"
+
+ ValidateExtArg "$FSRESP"
+ FSTEST="$FUNC_RET"
+ done
+
+ EXTFS="$FSTEST"
+
+}
+
+GetFatSize() {
+
+ FATTEST=
+
+ while [ -z "$FATTEST" ]
+ do
+ echo
+ echo -n "fat partition size [default=$FATSIZE]: "
+ read FATRESP
+
+ [ -z "$FATRESP" ] && FATRESP="$FATSIZE"
+ echo "$FATRESP" > /dev/null 2>&1 >>"$LOGFILE"
+
+ ValidateSizeArg "$FATRESP"
+ FATTEST="$FUNC_RET"
+
+ [ -n "$FATTEST" ] && [ $FATTEST -gt $FATSIZE ] && ShowMessage "$FATRESP > available space($(($SDSIZE - $SWAPSIZE - $EXTSIZE))M)." && FATTEST=
+ [ -n "$FATTEST" ] && [ $FATTEST -le 0 ] && ShowMessage "must have a fat32 partition greater than 0MB" && FATTEST=
+ done
+
+ FATSIZE=$FATTEST
+
+}
+
+
+SCRIPTNAME="sdparted"
+SCRIPTREV="0.6"
+MYNAME="51dusty"
+
+IMODE=
+SILENTRUN=
+CREATEPART=
+FUNC_RET=
+
+UEXTFSONLY=
+DEXTFSONLY=
+
+TTISOK=
+TTISLOOP=
+TTISMSDOS=
+
+SDSIZE=
+SDSIZEMB=
+SDINFO=$(cat /etc/fstab | grep /sdcard | awk '{print $1}')
+if [ -L "$SDINFO" ]
+then
+ SDPATH=$(ls -l $SDINFO | awk '{print $11}')
+else
+ SDPATH=$SDINFO
+fi
+# we may now have an SDPATH, let's make sure its on mmcblkX or mmcblkXp1
+CHECK_SDPATH1=$(echo $SDPATH | grep mmcblk.$)
+CHECK_SDPATH2=$(echo $SDPATH | grep mmcblk.p1$)
+if [ -z "$CHECK_SDPATH1" ]
+then
+ if [ -z "$CHECK_SDPATH2" ]
+ then
+ echo fail1
+ unset SDPATH
+ else
+ LEN=${#SDPATH}
+ BLKLEN=$(expr $LEN - 2)
+ SDPATH=${SDPATH:0:$BLKLEN}
+ fi
+fi
+
+
+FATSIZE=
+FATTYPE="fat32"
+FATPATH=$SDPATH"p1"
+
+EXTSIZE=512
+EXTFS="ext2"
+EXTPATH=$SDPATH"p2"
+EXTEND=
+
+SWAPSIZE=32
+SWAPTYPE="linux-swap"
+SWAPPATH=$SDPATH"p3"
+SWAPEND=
+
+CMPARTED="/sbin/parted"
+CMTUNE2FS="/sbin/tune2fs"
+CME2FSCK="/sbin/e2fsck"
+
+# give the output some breathing room
+echo "$SCRIPTREV" >> "$LOGFILE"
+echo
+
+# check for arguments
+while [ $# -gt 0 ] ; do
+ case "$1" in
+
+ -h|--help) ShowHelp ; exit 0 ;;
+
+ -fs|--fatsize) shift ; ValidateSizeArg "$1" ; FATSIZE="$FUNC_RET" ; CREATEPART="$1" ;;
+ -es|--extsize) shift ; ValidateSizeArg "$1" ; EXTSIZE="$FUNC_RET" ; CREATEPART="$1" ;;
+ -ss|--swapsize) shift ; ValidateSizeArg "$1" ; SWAPSIZE="$FUNC_RET" ; CREATEPART="$1" ;;
+ -efs|--extfs) shift ; ValidateExtArg "$1" ; EXTFS="$FUNC_RET" ; CREATEPART="$1" ;;
+
+ -ufs|--upgradefs) shift ; ValidateExtArg "$1" ; UEXTFSONLY="$FUNC_RET" ;;
+ -dfs|--downgradefs) shift ; ValidateExtArg "$1" ; DEXTFSONLY="$FUNC_RET" ;;
+
+ -i|--interactive) IMODE="$1" ;;
+
+ -s|--silent) SILENTRUN="$1" ;;
+
+ -po|--printonly) ShowCardInfo ;;
+
+ *) ShowHelp ; ShowError "unknown argument '$1'" ;;
+
+ esac
+ shift
+done
+
+# can't do silent when in interactive mode
+[ -n "$IMODE" ] && SILENTRUN=
+
+# make sure sdcard exists and all needed files are here
+CheckReqs
+
+# unmount all
+UnmountAll
+
+# upgrade only? downgrade only?
+UpgradeDowngradeOnly
+
+# check table
+CheckTableType
+
+# prep card
+PrepareSdCard
+
+# check for interactive mode
+[ -n "$IMODE" ] && Interactive
+
+# do some math
+CalculatePartitions
+
+# last chance to cancel
+ShowActions
+
+# partition card
+PartitionSdCard
+
+# upgrade fs if necessary
+UpgradeExt "$EXTFS"
+
+# say goodbye and show print output
+ShowCardInfo
View
BIN src/utilities/tune2fs
Binary file not shown.
View
2 src/verifier_test.sh → src/utilities/verifier_test.sh
@@ -11,7 +11,7 @@
# the tests.
EMULATOR_PORT=5580
-DATA_DIR=$ANDROID_BUILD_TOP/bootable/recovery/testdata
+DATA_DIR=$ANDROID_BUILD_TOP/src/testdata
WORK_DIR=/data/local/tmp

0 comments on commit dea3d2f

Please sign in to comment.
Something went wrong with that request. Please try again.