Android Mediatek 增加Recovery模式下读cmdline的强制工厂重置选项

简介: Android Mediatek 增加Recovery模式下读cmdline的强制工厂重置选项

这个修改主要是在多个文件中增加了一个选项,当设备在恢复模式下并且特定的GPIO引脚被设置时,设备将进行强制的工厂重置。

修改的文件:

  1. bootable/recovery/recovery.cpp
  2. vendor/mediatek/proprietary/bootable/bootloader/lk/app/mt_boot/mt_boot.c
  3. vendor/mediatek/proprietary/bootable/bootloader/lk/platform/mt6735/platform.c
  4. vendor/mediatek/proprietary/bootable/bootloader/lk/target/XX8735/dct/dct/codegen.dws
  5. vendor/mediatek/proprietary/bootable/bootloader/preloader/custom/XX8735/dct/dct/codegen.dws

文件修改说明:

1. recovery.cpp

在这个文件中,增加了一个函数is_need_force_factory_reset(),该函数会检查/proc/cmdline中是否存在force_reset参数。如果存在,那么在恢复模式下,设备将进行强制的工厂重置。

2. mt_boot.c

在这个文件中,在恢复模式下检查了GPIO71的状态。如果GPIO71的状态为0,那么将在命令行参数中增加force_reset

3. platform.c

在这个文件中,也检查了GPIO71的状态。如果GPIO71的状态为0,那么将设备的启动模式设置为恢复模式。

4. codegen.dws

这两个二进制文件被修改,但由于它们是二进制文件,无法提供具体的修改内容(实际上是笔记忘记截图了) 就是用dct mtk专用的gpio 修改工具把gpio 改吧改吧就欧克了。


 

---
 bootable/recovery/recovery.cpp                |  28 +++++++++++++++++-
 .../bootloader/lk/app/mt_boot/mt_boot.c       |   8 ++++-
 .../bootloader/lk/platform/mt6735/platform.c  |   4 +++
 .../lk/target/XX8735/dct/dct/codegen.dws      | Bin 29887 -> 29887 bytes
 .../custom/XX8735/dct/dct/codegen.dws         | Bin 29938 -> 29887 bytes
 5 files changed, 38 insertions(+), 2 deletions(-)
 
diff --git a/bootable/recovery/recovery.cpp b/bootable/recovery/recovery.cpp
index 736423e3644..823635b1872 100755
--- a/bootable/recovery/recovery.cpp
+++ b/bootable/recovery/recovery.cpp
@@ -116,6 +116,8 @@ static const char *TEMPORARY_LOG_FILE = "/tmp/recovery.log";
 static const char *TEMPORARY_INSTALL_FILE = "/tmp/last_install";
 static const char *LAST_KMSG_FILE = "/cache/recovery/last_kmsg";
 static const char *LAST_LOG_FILE = "/cache/recovery/last_log";
+
+static const char *COMMAND_LINE="/proc/cmdline";
 // We will try to apply the update package 5 times at most in case of an I/O error or
 // bspatch | imgpatch error.
 static const int RETRY_LIMIT = 4;
@@ -137,7 +139,7 @@ static bool has_cache = false;
 static bool has_nvdata = false;
 
 RecoveryUI* ui = nullptr;
-bool modified_flash = false;
+bool modified_flash = true;
 std::string stage;
 const char* reason = nullptr;
 struct selabel_handle* sehandle;
@@ -1359,6 +1361,23 @@ static void log_failure_code(ErrorCode code, const char *update_package) {
     LOG(INFO) << log_content;
 }
 
+int is_need_force_factory_reset()
+{
+    char param[1024];
+    int fd, ret;
+    char *s=NULL;
+    
+    memset(param,0,1024);
+    fd= open("/proc/cmdline", O_RDONLY);
+    ret = read(fd, (char*)param, 1024);
+    printf("cmdline=%s\n",param);
+    s = strstr(param,"force_reset");
+    if(s!= NULL)
+        return 1;
+    else
+        return 0;
+}
+
 int main(int argc, char **argv) {
     // We don't have logcat yet under recovery; so we'll print error on screen and
     // log to stdout (which is redirected to recovery.log) as we used to do.
@@ -1422,6 +1441,11 @@ int main(int argc, char **argv) {
     int retry_count = 0;
     bool security_update = false;
 
+    if(args.size() == 1 && is_need_force_factory_reset() == 1){       
+        should_wipe_data = true;
+        should_wipe_cache=true;
+        printf("exec wipe_data \n");
+    }
     int arg;
     int option_index;
     while ((arg = getopt_long(args_to_parse.size(), args_to_parse.data(), "", OPTIONS,
@@ -1466,6 +1490,8 @@ int main(int argc, char **argv) {
         }
     }
 
+    //check_usbboot();
+
     printf("locale is [%s]\n", locale.c_str());
     printf("stage is [%s]\n", stage.c_str());
     printf("reason is [%s]\n", reason);
diff --git a/vendor/mediatek/proprietary/bootable/bootloader/lk/app/mt_boot/mt_boot.c b/vendor/mediatek/proprietary/bootable/bootloader/lk/app/mt_boot/mt_boot.c
index 55e5b07f6f2..ca1272c99cc 100755
--- a/vendor/mediatek/proprietary/bootable/bootloader/lk/app/mt_boot/mt_boot.c
+++ b/vendor/mediatek/proprietary/bootable/bootloader/lk/app/mt_boot/mt_boot.c
@@ -70,7 +70,7 @@
 #include <iothread.h>
 #include <RoT.h>
 #include <odm_mdtbo.h>          // for load_overlay_dtbo()
-
+#include <platform/mt_gpio.h>
 #include <profiling.h>
 #include <rnd.h>
 
@@ -2322,6 +2322,12 @@ int boot_linux_from_storage(void)
    }
  }
 
+ if (g_boot_mode == RECOVERY_BOOT) {
+   if(mt_get_gpio_in(GPIO71) == 0){
+     cmdline_append("force_reset");
+   }
+ }
+
  /* pass the meta_log_disable to user space logger, default is enable */
  if (is_meta_log_disable && (is_meta_log_disable() == 1)) {
    cmdline_append("androidboot.meta_log_disable=1");
diff --git a/vendor/mediatek/proprietary/bootable/bootloader/lk/platform/mt6735/platform.c b/vendor/mediatek/proprietary/bootable/bootloader/lk/platform/mt6735/platform.c
index 86b91982c49..8558d001389 100755
--- a/vendor/mediatek/proprietary/bootable/bootloader/lk/platform/mt6735/platform.c
+++ b/vendor/mediatek/proprietary/bootable/bootloader/lk/platform/mt6735/platform.c
@@ -652,6 +652,10 @@ static void lk_boot_mode_select(void)
 
  boot_mode_select();
 
+ if(mt_get_gpio_in(GPIO71) == 0){
+   g_boot_mode = RECOVERY_BOOT;
+ }
+
 #ifdef CFG_DTB_EARLY_LOADER_SUPPORT
  /* reload dtb when boot mode = recovery */
  if ((g_boot_mode == RECOVERY_BOOT) && (bldr_load_dtb("recovery") < 0))
diff --git a/vendor/mediatek/proprietary/bootable/bootloader/lk/target/XX8735/dct/dct/codegen.dws b/vendor/mediatek/proprietary/bootable/bootloader/lk/target/XX8735/dct/dct/codegen.dws
index c9abb1bee0fb5c20e775dea9edabe6a4357b2ef8..b6c155e31d9c2720249aee4a1c8a55df1e1a2866 100755
GIT binary patch
delta 34
scmV+-0Nww;=>fm#0k8ralWzn-lS>d7ldlX!lh7dqlb}o-v%VVvS@XsX2LJ#7
 
delta 49
zcmV-10M7rv=>fm#0k8ralfWMYlfD}ek{u9}AQ=dgARP#kuq-5#a3@5Q&>;kqpiCUI
Hz8e8q%^(qn
 
diff --git a/vendor/mediatek/proprietary/bootable/bootloader/preloader/custom/XX8735/dct/dct/codegen.dws b/vendor/mediatek/proprietary/bootable/bootloader/preloader/custom/XX8735/dct/dct/codegen.dws
index 1d72e4a55831802a51a1be0da022bb3c563e0eb4..17f6b28bac9fa453429ea36d21625c1fdbe82ca7 100755
GIT binary patch
delta 78
zcmezLl5zh_#tr|ZCMQU;OwMO<nCvZ}GC9CTV6uQD&*Xjqj>&q`5|i!SRVFt$2u%JV
htpR2qkP(@DK!#<qf+WY}cXkq!KZx;fo+A?$0RVCv8|VN4
 
delta 109
zcmdo0lJV0^#tr|ZCV!BznEXIclEW*+(LFxI*?TghkisNcp2-I89Fwc0H70)$<b=w(
lcp}T4bQPE!&nST`?+=lem?X<GSwWIxvVyGE<{X*e2mmY*B69!$
 
-- 
2.29.0



相关文章
|
11天前
|
Java Android开发 开发者
Android10 修改开发者选项中动画缩放默认值
Android10 修改开发者选项中动画缩放默认值
16 0
|
11天前
|
Java Android开发
Android Mediatek 禁用拨号应用的部分UI显示
Android Mediatek 禁用拨号应用的部分UI显示
14 0
|
11天前
|
Java Android开发
Android Mediatek 延迟停止启动动画和通知SurfaceFlinger(Android正在启动)
Android Mediatek 延迟停止启动动画和通知SurfaceFlinger(Android正在启动)
13 0
|
11天前
|
Linux Android开发
Android Mediatek 修改UART设备名称和默认调试属性
Android Mediatek 修改UART设备名称和默认调试属性
15 0
|
11天前
|
传感器 Android开发
Android MediaTek 添加LPS22HB压力传感器驱动
Android MediaTek 添加LPS22HB压力传感器驱动
10 0
|
11天前
|
Java Android开发
Android Mediatek 应用层重置USB设备功能
Android Mediatek 应用层重置USB设备功能
14 0
|
11天前
|
Android开发
Android Mediatek 禁用 UART 日志输出
Android Mediatek 禁用 UART 日志输出
12 0
|
11天前
|
Android开发
Android Mediatek NVRAM 加载 MAC 地址并禁用 MAC 地址更新
Android Mediatek NVRAM 加载 MAC 地址并禁用 MAC 地址更新
10 0
|
11天前
|
Java Android开发
Android Mediatek 禁用 USB 权限请求和声音提示 & 解决USB HID设备不识别问题(附带USB调试过程)
Android Mediatek 禁用 USB 权限请求和声音提示 & 解决USB HID设备不识别问题(附带USB调试过程)
15 0
|
11天前
|
Java Android开发
Android Mediatek 添加 APK 安装和下载开关
Android Mediatek 添加 APK 安装和下载开关
11 0