From 67d358cf4ea53d83e320e9c4ab0ebd5e398f4b60 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 10 Jun 2011 20:26:44 +0200 Subject: [PATCH 1/4] Add a new 'Show log' extended function. Could also be used to report last lines from log on error. Signed-off-by: Tanguy Pruvot Change-Id: I3d9e51f4e81e48f20120e2449ccde651efae8d07 --- common.h | 1 + extendedcommands.c | 12 ++++++++++-- ui.c | 30 ++++++++++++++++++++++++++++-- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/common.h b/common.h index 77cf143..b83055e 100644 --- a/common.h +++ b/common.h @@ -33,6 +33,7 @@ void ui_clear_key_queue(); // The screen is small, and users may need to report these messages to support, // so keep the output short and not too cryptic. void ui_print(const char *fmt, ...) __attribute__((format(printf, 1, 2))); +void ui_printlogtail(int nb_lines); void ui_reset_text_col(); void ui_set_show_text(int value); diff --git a/extendedcommands.c b/extendedcommands.c index c2a0e18..ae41f06 100644 --- a/extendedcommands.c +++ b/extendedcommands.c @@ -876,6 +876,7 @@ void show_advanced_menu() "Wipe Battery Stats", "Report Error", "Key Test", + "Show log", #ifndef BOARD_HAS_SMALL_RECOVERY "Partition SD Card", "Fix Permissions", @@ -894,8 +895,10 @@ void show_advanced_menu() switch (chosen_item) { case 0: + { reboot_wrapper("recovery"); break; + } case 1: { if (0 != ensure_path_mounted("/data")) @@ -936,6 +939,11 @@ void show_advanced_menu() break; } case 5: + { + ui_printlogtail(12); + break; + } + case 6: { static char* ext_sizes[] = { "128M", "256M", @@ -978,7 +986,7 @@ void show_advanced_menu() ui_print("An error occured while partitioning your SD Card. Please see /tmp/recovery.log for more details.\n"); break; } - case 6: + case 7: { ensure_path_mounted("/system"); ensure_path_mounted("/data"); @@ -987,7 +995,7 @@ void show_advanced_menu() ui_print("Done!\n"); break; } - case 7: + case 8: { static char* ext_sizes[] = { "128M", "256M", diff --git a/ui.c b/ui.c index 133f4da..d953562 100644 --- a/ui.c +++ b/ui.c @@ -29,6 +29,8 @@ #include "minui/minui.h" #include "recovery_ui.h" +extern int __system(const char *command); + #ifdef BOARD_HAS_NO_SELECT_BUTTON static int gShowBackButton = 1; #else @@ -58,6 +60,7 @@ static gr_surface gProgressBarIndeterminate[PROGRESSBAR_INDETERMINATE_STATES]; static gr_surface gProgressBarEmpty; static gr_surface gProgressBarFill; static int ui_has_initialized = 0; +static int ui_log_stdout = 1; static const struct { gr_surface* surface; const char *name; } BITMAPS[] = { { &gBackgroundIcon[BACKGROUND_ICON_INSTALLING], "icon_installing" }, @@ -98,7 +101,7 @@ static int show_text = 0; static char menu[MENU_MAX_ROWS][MENU_MAX_COLS]; static int show_menu = 0; static int menu_top = 0, menu_items = 0, menu_sel = 0; -static int menu_show_start = 0; // this is line which menu display is starting at +static int menu_show_start = 0; // this is line which menu display is starting at // Key event input queue static pthread_mutex_t key_queue_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -460,7 +463,8 @@ void ui_print(const char *fmt, ...) vsnprintf(buf, 256, fmt, ap); va_end(ap); - fputs(buf, stdout); + if (ui_log_stdout) + fputs(buf, stdout); // This can get called before ui_init(), so be careful. pthread_mutex_lock(&gUpdateMutex); @@ -481,6 +485,28 @@ void ui_print(const char *fmt, ...) pthread_mutex_unlock(&gUpdateMutex); } +void ui_printlogtail(int nb_lines) { + char * log_data; + char tmp[PATH_MAX]; + FILE * f; + int line=0; + //don't log output to recovery.log + ui_log_stdout=0; + sprintf(tmp, "tail -n %d /tmp/recovery.log > /tmp/tail.log", nb_lines); + __system(tmp); + f = fopen("/tmp/tail.log", "rb"); + if (f != NULL) { + while (line < nb_lines) { + log_data = fgets(tmp, PATH_MAX, f); + if (log_data == NULL) break; + ui_print("%s", tmp); + line++; + } + fclose(f); + } + ui_log_stdout=1; +} + void ui_reset_text_col() { pthread_mutex_lock(&gUpdateMutex); From 0b06fc06969120762c921dbcb726a15f6e2d0c94 Mon Sep 17 00:00:00 2001 From: Ricardo Cerqueira Date: Thu, 7 Jul 2011 01:09:52 +0100 Subject: [PATCH 2/4] recovery: Ignore wipe command from bootloaders that always send it Change-Id: Ia93e1aae4d07ff609a252ae60850c739b02f2969 --- Android.mk | 2 +- recovery.c | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Android.mk b/Android.mk index 4d72ade..519b8ca 100644 --- a/Android.mk +++ b/Android.mk @@ -31,7 +31,7 @@ LOCAL_CFLAGS += -DRECOVERY_VERSION="$(RECOVERY_VERSION)" RECOVERY_API_VERSION := 2 LOCAL_CFLAGS += -DRECOVERY_API_VERSION=$(RECOVERY_API_VERSION) -BOARD_RECOVERY_DEFINES := BOARD_HAS_NO_SELECT_BUTTON BOARD_HAS_SMALL_RECOVERY BOARD_LDPI_RECOVERY BOARD_UMS_LUNFILE +BOARD_RECOVERY_DEFINES := BOARD_HAS_NO_SELECT_BUTTON BOARD_HAS_SMALL_RECOVERY BOARD_LDPI_RECOVERY BOARD_UMS_LUNFILE BOARD_RECOVERY_ALWAYS_WIPES $(foreach board_define,$(BOARD_RECOVERY_DEFINES), \ $(if $($(board_define)), \ diff --git a/recovery.c b/recovery.c index 52d3879..89fb214 100644 --- a/recovery.c +++ b/recovery.c @@ -826,7 +826,11 @@ main(int argc, char **argv) { case 'p': previous_runs = atoi(optarg); break; case 's': send_intent = optarg; break; case 'u': update_package = optarg; break; - case 'w': wipe_data = wipe_cache = 1; break; + case 'w': +#ifndef BOARD_RECOVERY_ALWAYS_WIPES + wipe_data = wipe_cache = 1; +#endif + break; case 'c': wipe_cache = 1; break; case 'e': encrypted_fs_mode = optarg; toggle_secure_fs = 1; break; case 't': ui_show_text(1); break; From 50732e3c67454e174f008ba5443b21070f360a56 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Thu, 7 Jul 2011 12:44:05 -0700 Subject: [PATCH 3/4] backup and restore of /sdcard/Android (see getExternalFilesDir) Change-Id: I6306464cdce4e3b48e0d109284e5606f65a84ee2 --- Android.mk | 2 +- edifyscripting.c | 4 ++++ nandroid.c | 13 +++++++++++++ recovery.c | 3 ++- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Android.mk b/Android.mk index 519b8ca..d65f650 100644 --- a/Android.mk +++ b/Android.mk @@ -26,7 +26,7 @@ LOCAL_MODULE := recovery LOCAL_FORCE_STATIC_EXECUTABLE := true -RECOVERY_VERSION := ClockworkMod Recovery v4.0.0.5 +RECOVERY_VERSION := ClockworkMod Recovery v4.0.0.8 LOCAL_CFLAGS += -DRECOVERY_VERSION="$(RECOVERY_VERSION)" RECOVERY_API_VERSION := 2 LOCAL_CFLAGS += -DRECOVERY_API_VERSION=$(RECOVERY_API_VERSION) diff --git a/edifyscripting.c b/edifyscripting.c index 89554d7..1634a9e 100644 --- a/edifyscripting.c +++ b/edifyscripting.c @@ -145,6 +145,10 @@ Value* FormatFn(const char* name, State* state, int argc, Expr* argv[]) { free(path); return StringValue(strdup("")); } + if (0 != format_volume("/sdcard/Android")) { + free(path); + return StringValue(strdup("")); + } } done: diff --git a/nandroid.c b/nandroid.c index af97e86..8bb82f1 100644 --- a/nandroid.c +++ b/nandroid.c @@ -277,6 +277,16 @@ int nandroid_backup(const char* backup_path) return ret; } + if (0 != stat("/sdcard/Android", &s)) + { + ui_print("No /sdcard/Android found. Skipping backup of application files on external storage.\n"); + } + else + { + if (0 != (ret = nandroid_backup_partition_extended(backup_path, "/sdcard/Android", 0))) + return ret; + } + if (0 != (ret = nandroid_backup_partition_extended(backup_path, "/cache", 0))) return ret; @@ -514,6 +524,9 @@ int nandroid_restore(const char* backup_path, int restore_boot, int restore_syst if (restore_data && 0 != (ret = nandroid_restore_partition_extended(backup_path, "/sdcard/.android_secure", 0))) return ret; + if (restore_data && 0 != (ret = nandroid_restore_partition_extended(backup_path, "/sdcard/Android", 0))) + return ret; + if (restore_cache && 0 != (ret = nandroid_restore_partition_extended(backup_path, "/cache", 0))) return ret; diff --git a/recovery.c b/recovery.c index 89fb214..e69a461 100644 --- a/recovery.c +++ b/recovery.c @@ -686,6 +686,7 @@ wipe_data(int confirm) { } erase_volume("/sd-ext"); erase_volume("/sdcard/.android_secure"); + erase_volume("/sdcard/Android"); ui_print("Data wipe complete.\n"); } @@ -826,7 +827,7 @@ main(int argc, char **argv) { case 'p': previous_runs = atoi(optarg); break; case 's': send_intent = optarg; break; case 'u': update_package = optarg; break; - case 'w': + case 'w': #ifndef BOARD_RECOVERY_ALWAYS_WIPES wipe_data = wipe_cache = 1; #endif From a75c067df4a08df6e734aba607c941eef7f261e0 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Thu, 7 Jul 2011 12:55:02 -0700 Subject: [PATCH 4/4] Support overriding of the bml partition used for boot and recovery. This is not ideal, because that means that there are different flash_image binaries for different samsung phones. But as far as I know, there is no way to find out which bml device is boot or recovery. Change-Id: I5e3b83dd9267a275def003182c1bd5d2cf585896 --- bmlutils/Android.mk | 10 +++++++++- bmlutils/bmlutils.c | 15 +++++++++++---- flashutils/Android.mk | 9 +++++++++ flashutils/flashutils.c | 10 +++++++++- 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/bmlutils/Android.mk b/bmlutils/Android.mk index e95cb5f..6d9ab83 100644 --- a/bmlutils/Android.mk +++ b/bmlutils/Android.mk @@ -1,7 +1,15 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) -LOCAL_CFLAGS += -DBOARD_BOOT_DEVICE=\"$(BOARD_BOOT_DEVICE)\" + +BOARD_RECOVERY_DEFINES := BOARD_BML_BOOT BOARD_BML_RECOVERY + +$(foreach board_define,$(BOARD_RECOVERY_DEFINES), \ + $(if $($(board_define)), \ + $(eval LOCAL_CFLAGS += -D$(board_define)=\"$($(board_define))\") \ + ) \ + ) + LOCAL_SRC_FILES := bmlutils.c LOCAL_MODULE := libbmlutils LOCAL_MODULE_TAGS := eng diff --git a/bmlutils/bmlutils.c b/bmlutils/bmlutils.c index 9ef04b4..db80501 100644 --- a/bmlutils/bmlutils.c +++ b/bmlutils/bmlutils.c @@ -23,6 +23,13 @@ extern int __system(const char *command); #define BML_UNLOCK_ALL 0x8A29 ///< unlock all partition RO -> RW +#ifndef BOARD_BML_BOOT +#define BOARD_BML_BOOT "/dev/block/bml7" +#endif + +#ifndef BOARD_BML_RECOVERY +#define BOARD_BML_RECOVERY "/dev/block/bml8" +#endif static int restore_internal(const char* bml, const char* filename) { @@ -66,13 +73,13 @@ int cmd_bml_restore_raw_partition(const char *partition, const char *filename) // always restore boot, regardless of whether recovery or boot is flashed. // this is because boot and recovery are the same on some samsung phones. // unless of course, recoveryonly is explictly chosen (bml8) - ret = restore_internal("/dev/block/bml7", filename); + ret = restore_internal(BOARD_BML_BOOT, filename); if (ret != 0) return ret; } if (strcmp(partition, "recovery") == 0 || strcmp(partition, "recoveryonly") == 0) - ret = restore_internal("/dev/block/bml8", filename); + ret = restore_internal(BOARD_BML_RECOVERY, filename); return ret; } @@ -80,9 +87,9 @@ int cmd_bml_backup_raw_partition(const char *partition, const char *out_file) { char* bml; if (strcmp("boot", partition) == 0) - bml = "/dev/block/bml7"; + bml = BOARD_BML_BOOT; else if (strcmp("recovery", partition) == 0) - bml = "/dev/block/bml8"; + bml = BOARD_BML_RECOVERY; else { printf("Invalid partition.\n"); return -1; diff --git a/flashutils/Android.mk b/flashutils/Android.mk index d513275..aa4c7d3 100644 --- a/flashutils/Android.mk +++ b/flashutils/Android.mk @@ -9,6 +9,15 @@ LOCAL_MODULE := libflashutils LOCAL_MODULE_TAGS := eng LOCAL_C_INCLUDES += bootable/recovery LOCAL_STATIC_LIBRARIES := libmmcutils libmtdutils libbmlutils libcrecovery + +BOARD_RECOVERY_DEFINES := BOARD_BML_BOOT BOARD_BML_RECOVERY + +$(foreach board_define,$(BOARD_RECOVERY_DEFINES), \ + $(if $($(board_define)), \ + $(eval LOCAL_CFLAGS += -D$(board_define)=\"$($(board_define))\") \ + ) \ + ) + include $(BUILD_STATIC_LIBRARY) include $(CLEAR_VARS) diff --git a/flashutils/flashutils.c b/flashutils/flashutils.c index 958476c..de45e87 100644 --- a/flashutils/flashutils.c +++ b/flashutils/flashutils.c @@ -6,12 +6,20 @@ #include "flashutils/flashutils.h" +#ifndef BOARD_BML_BOOT +#define BOARD_BML_BOOT "/dev/block/bml7" +#endif + +#ifndef BOARD_BML_RECOVERY +#define BOARD_BML_RECOVERY "/dev/block/bml8" +#endif + int the_flash_type = UNKNOWN; int device_flash_type() { if (the_flash_type == UNKNOWN) { - if (access("/dev/block/bml7", F_OK) == 0) { + if (access(BOARD_BML_BOOT, F_OK) == 0) { the_flash_type = BML; } else if (access("/proc/emmc", F_OK) == 0) { the_flash_type = MMC;