Merge "recovery: updater: log to stdout in recovery mode" into mnc-dr-dev
diff --git a/recovery/updater/Android.mk b/recovery/updater/Android.mk
index 6ca26a8..556773d 100644
--- a/recovery/updater/Android.mk
+++ b/recovery/updater/Android.mk
@@ -30,7 +30,7 @@
 LOCAL_CLANG := true
 LOCAL_SRC_FILES := flash_ec.c flash_mtd.c flash_file.c flash_device.c vboot_interface.c update_fw.c debug_ec.c fwtool.c
 LOCAL_SHARED_LIBRARIES := liblog
-LOCAL_CFLAGS += -Wno-unused-parameter
+LOCAL_CFLAGS += -Wno-unused-parameter -DUSE_LOGCAT
 LOCAL_C_INCLUDES += bootable/recovery
 # For vboot_struct.h
 LOCAL_C_INCLUDES += external/vboot_reference/firmware/include
diff --git a/recovery/updater/debug_ec.c b/recovery/updater/debug_ec.c
index d470f60..8f9910c 100644
--- a/recovery/updater/debug_ec.c
+++ b/recovery/updater/debug_ec.c
@@ -17,8 +17,6 @@
 
 #define LOG_TAG "fwtool"
 
-#include <cutils/log.h>
-
 #include <errno.h>
 #include <stdint.h>
 #include <stdlib.h>
@@ -28,6 +26,7 @@
 #include "ec_commands.h"
 #include "debug_cmd.h"
 #include "flash_device.h"
+#include "update_log.h"
 
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 
diff --git a/recovery/updater/flash_device.c b/recovery/updater/flash_device.c
index 169ad91..6e08626 100644
--- a/recovery/updater/flash_device.c
+++ b/recovery/updater/flash_device.c
@@ -17,8 +17,6 @@
 
 #define LOG_TAG "fwtool"
 
-#include <cutils/log.h>
-
 #include <errno.h>
 #include <stdint.h>
 #include <stdlib.h>
@@ -27,6 +25,7 @@
 
 #include "flash_device.h"
 #include "fmap.h"
+#include "update_log.h"
 #include "vboot_interface.h"
 
 static const struct flash_device_ops *devices[] = {
diff --git a/recovery/updater/flash_ec.c b/recovery/updater/flash_ec.c
index eb36ce4..2583ed6 100644
--- a/recovery/updater/flash_ec.c
+++ b/recovery/updater/flash_ec.c
@@ -17,8 +17,6 @@
 
 #define LOG_TAG "fwtool"
 
-#include <cutils/log.h>
-
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
@@ -33,6 +31,7 @@
 
 #include "ec_commands.h"
 #include "flash_device.h"
+#include "update_log.h"
 
 #define CROS_EC_DEV_NAME "/dev/cros_ec"
 
diff --git a/recovery/updater/flash_file.c b/recovery/updater/flash_file.c
index 955a262..ee923ff 100644
--- a/recovery/updater/flash_file.c
+++ b/recovery/updater/flash_file.c
@@ -17,8 +17,6 @@
 
 #define LOG_TAG "fwtool"
 
-#include <cutils/log.h>
-
 #include <errno.h>
 #include <fcntl.h>
 #include <stdint.h>
@@ -31,6 +29,7 @@
 
 #include "edify/expr.h"
 #include "flash_device.h"
+#include "update_log.h"
 
 struct file_data {
 	int fd;
diff --git a/recovery/updater/flash_mtd.c b/recovery/updater/flash_mtd.c
index 353c560..a0a0221 100644
--- a/recovery/updater/flash_mtd.c
+++ b/recovery/updater/flash_mtd.c
@@ -17,8 +17,6 @@
 
 #define LOG_TAG "fwtool"
 
-#include <cutils/log.h>
-
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
@@ -31,6 +29,7 @@
 #include <mtd/mtd-user.h>
 
 #include "flash_device.h"
+#include "update_log.h"
 #include "vboot_interface.h"
 
 static const char * const DEFAULT_MTD_FILE = "/dev/mtd/mtd0";
diff --git a/recovery/updater/fwtool.c b/recovery/updater/fwtool.c
index fbcc816..df85bcb 100644
--- a/recovery/updater/fwtool.c
+++ b/recovery/updater/fwtool.c
@@ -17,8 +17,6 @@
 
 #define LOG_TAG "fwtool"
 
-#include <cutils/log.h>
-
 #include <errno.h>
 #include <inttypes.h>
 #include <stdint.h>
@@ -31,6 +29,7 @@
 #include "flash_device.h"
 #include "fmap.h"
 #include "update_fw.h"
+#include "update_log.h"
 #include "vboot_interface.h"
 
 static void *spi;
diff --git a/recovery/updater/recovery_updater.c b/recovery/updater/recovery_updater.c
index c308911..a95748c 100644
--- a/recovery/updater/recovery_updater.c
+++ b/recovery/updater/recovery_updater.c
@@ -29,6 +29,7 @@
 	int res;
 	Value *retval = NULL;
 
+	printf("%s: running %s.\n", __func__, name);
 	if (argc < 2) {
 		ErrorAbort(state, "syntax: %s bios.bin ec.bin", name);
 		return NULL;
@@ -46,6 +47,9 @@
 
 	FreeValue(firmware);
 	FreeValue(ec);
+
+	printf("%s: [%s] done.\n", __func__,
+		retval ? retval->data : state->errmsg);
 	return retval;
 }
 
diff --git a/recovery/updater/update_fw.c b/recovery/updater/update_fw.c
index 7c9a217..a99a100 100644
--- a/recovery/updater/update_fw.c
+++ b/recovery/updater/update_fw.c
@@ -17,8 +17,6 @@
 
 #define LOG_TAG "fwtool"
 
-#include <cutils/log.h>
-
 #include "errno.h"
 #include <stdint.h>
 #include <stdlib.h>
@@ -27,6 +25,7 @@
 
 #include "edify/expr.h"
 #include "flash_device.h"
+#include "update_log.h"
 #include "vboot_interface.h"
 
 int check_compatible_keys(struct flash_device *img, struct flash_device *spi)
diff --git a/recovery/updater/update_log.h b/recovery/updater/update_log.h
new file mode 100644
index 0000000..e2b0b3b
--- /dev/null
+++ b/recovery/updater/update_log.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2015 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_UPDATE_LOG_H_
+#define _RECOVERY_UPDATE_LOG_H_
+
+#ifdef USE_LOGCAT
+#include <cutils/log.h>
+#else
+/* when running in recovery mode, only stdout is logged properly */
+#define ALOGD(format, args...) printf("D %s: " format, LOG_TAG, ## args)
+#define ALOGI(format, args...) printf("I %s: " format, LOG_TAG, ## args)
+#define ALOGW(format, args...) printf("W %s: " format, LOG_TAG, ## args)
+#define ALOGE(format, args...) printf("E %s: " format, LOG_TAG, ## args)
+#endif
+
+#endif /* _RECOVERY_UPDATE_LOG_H_ */
diff --git a/recovery/updater/vboot_interface.c b/recovery/updater/vboot_interface.c
index 9054fb3..45a2dfc 100644
--- a/recovery/updater/vboot_interface.c
+++ b/recovery/updater/vboot_interface.c
@@ -17,8 +17,6 @@
 
 #define LOG_TAG "fwtool"
 
-#include <cutils/log.h>
-
 #include <endian.h>
 #include <errno.h>
 #include <stdint.h>
@@ -29,6 +27,7 @@
 #include "ec_commands.h"
 #include "flash_device.h"
 #include "fmap.h"
+#include "update_log.h"
 #include "vboot_struct.h"
 #include "gbb_header.h"