Snap for 4654740 from 5cf62279a7965e6ffce68bda9bcf1a346239ff54 to oc-wear-dr-kingyo-release

Change-Id: Ic135f4ca59d9d2ac37cc885628f92925f426445a
diff --git a/board/samsung/koi/koi.c b/board/samsung/koi/koi.c
index 977d167..4ba7c15 100644
--- a/board/samsung/koi/koi.c
+++ b/board/samsung/koi/koi.c
@@ -714,6 +714,32 @@
 	do_gpt(NULL, 0, 5, argv);
 }
 
+/*
+ * Check if "boot-recovery" is present at the first 32byte
+ * of misc partition.
+ */
+static int check_recovery_in_misc(void)
+{
+	unsigned long start, count;
+	unsigned char pid;
+	int dev_num = 0;
+	char startstr[20];
+	char arg[50];
+
+	get_boot_part_info(dev_num, 5, &start, &count, &pid);
+	if (pid != 0x83 && pid != 0xee)
+		return 0;
+
+	strcpy(arg, "mmc read 0 0x48000000 ");
+	sprintf(startstr, "0x%x ", start);
+	strcat(arg, startstr);
+	strcat(arg, "0x1");
+	run_command(arg, 0);
+	if (strncmp("boot-recovery", (char *)0x48000000, 13) == 0)
+		return 1;
+	return 0;
+}
+
 int board_late_init(void)
 {
 	struct exynos4_power *pmu = (struct exynos4_power *)EXYNOS4_POWER_BASE;
@@ -881,6 +907,9 @@
 		/* power-on write protect info partition */
 		run_command("mmc_wp 0x72c000 1 1", 0);
 	}
+	if (check_recovery_in_misc())
+		mode = CONFIG_FACTORY_RESET_MODE;
+
 	rw_img_hdr(mode==CONFIG_FACTORY_RESET_MODE ? 1:0, "read");
 	get_bootarg_from_img_hdr(tmp_buf);
 	setenv("bootargs", tmp_buf);
diff --git a/include/configs/koi.h b/include/configs/koi.h
index 1f294f8..779fa74 100644
--- a/include/configs/koi.h
+++ b/include/configs/koi.h
@@ -492,7 +492,7 @@
 #define CONFIG_INTEGRATED_IMG
 
 /* version-bootloader */
-#define VERSION_BOOTLOADER "KOI015"
+#define VERSION_BOOTLOADER "KOI016"
 
 #define CONFIG_AUTO_FW_WRITE