Unlock device while Android booting

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Unlock device while Android booting

Unlock device while Android booting

Background

Some customers connect their imx running Android to the cloud, so reboot-bootloader and the use of fastboot oem unlock is not acceptable. This way the system is disconnected and cannot be operated remotely using adb.
This article therefore proposes to execute oem unlock before the bootloader is started when the system is first run, which can be unlocked directly.

 

Patch

diff --git a/drivers/fastboot/fb_fsl/fb_fsl_boot.c b/drivers/fastboot/fb_fsl/fb_fsl_boot.c
index 86b919775a..d60cd248ee 100644
--- a/drivers/fastboot/fb_fsl/fb_fsl_boot.c
+++ b/drivers/fastboot/fb_fsl/fb_fsl_boot.c
@@ -529,6 +529,42 @@ bool __weak is_power_key_pressed(void) {
 	return false;
 }
 
+static void wipe_all_userdata(void)
+{
+	char response[FASTBOOT_RESPONSE_LEN];
+
+	/* Erase all user data */
+	printf("Start userdata wipe process....\n");
+	/* Erase /data partition */
+	fastboot_wipe_data_partition();
+
+#if defined (CONFIG_ANDROID_SUPPORT) || defined (CONFIG_ANDROID_AUTO_SUPPORT)
+	/* Erase the misc partition. */
+	process_erase_mmc(FASTBOOT_PARTITION_MISC, response);
+#endif
+
+#ifndef CONFIG_ANDROID_AB_SUPPORT
+	/* Erase the cache partition for legacy imx6/7 */
+	process_erase_mmc(FASTBOOT_PARTITION_CACHE, response);
+#endif
+
+#if defined(AVB_RPMB) && !defined(CONFIG_IMX_TRUSTY_OS)
+	printf("Start stored_rollback_index wipe process....\n");
+	rbkidx_erase();
+	printf("Wipe stored_rollback_index completed.\n");
+#endif
+	process_erase_mmc(FASTBOOT_PARTITION_METADATA, response);
+	printf("Wipe userdata completed.\n");
+}
+void do_unlock(void)
+{
+	int status;
+	wipe_all_userdata();
+	status = fastboot_set_lock_stat(FASTBOOT_UNLOCK);
+	if (status < 0)
+		return FASTBOOT_LOCK_ERROR;
+    printf("Unlock device\n");
+}
 int do_boota(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]) {
 
 	ulong addr = 0;
@@ -563,6 +599,9 @@ int do_boota(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]) {
 		fastboot_set_lock_stat(FASTBOOT_LOCK);
 		lock_status = FASTBOOT_LOCK;
 	}
+	if (lock_status == FASTBOOT_LOCK){
+		do_unlock();
+	}
 
 	bool allow_fail = (lock_status == FASTBOOT_UNLOCK ? true : false);
 	avb_metric = get_timer(0);

 

 

 

无评分
版本历史
最后更新:
‎02-22-2022 08:17 PM
更新人: