Case Analysis of SWT Restart

Keywords: Android git Mobile

Strongly Recommend Articles: Welcome to Collection
Android dry goods sharing

Read for five minutes, ten o'clock a day, and study with you for life. Here's Android, a programmer.

This article mainly introduces some knowledge points in Android development. By reading this article, you will gain the following contents:

I. High Temperature Triggered Kernel Exception Restart Problem
II. Solutions
III. Solutions to Increase Battery Temperature

I. High Temperature Triggered Kernel Exception Restart Problem

The default temperature of mobile phone battery above 60 degrees will trigger the security mechanism of mobile phone, allowing mobile housekeeper to restart.

The part of Log that caused the cell phone to restart by abnormal temperature is as follows:

II. Solutions

This problem needs to drive colleagues to modify an address in the underlying battery.c file so that it will not be restarted unless it is written dead. Or increase the battery temperature parameters.

III. Solutions to Increase Battery Temperature

The scheme to increase the temperature of the battery is as follows:

1. Modify mtk_battery_table.h

/alps/kernel-4.4/drivers/misc/mediatek/include/mt-plat/mt6739/include/mach/mtk_battery_table.h

  * ============================================================

  */

+//#define SPROCOMM_NTC //wang add

+#ifdef SPROCOMM_NTC

+#define NTC_COMP_RES 42

+#endif

+

 /* Qmax for battery  */

 #define Q_MAX_L_CURRENT 0

 #define Q_MAX_H_CURRENT 10000

@@ [-111,7](http://192.168.11.104/gitweb/?p=alps-mp-o1.mp1-V1.git;a=blob;f=alps/kernel-4.4/drivers/misc/mediatek/include/mt-plat/mt6739/include/mach/mtk_battery_table.h;h=7cb7b5e7e735a1907b941a6df5755c582ffca0ac;hb=7cb7b5e7e735a1907b941a6df5755c582ffca0ac#l111) [+116,8](http://192.168.11.104/gitweb/?p=alps-mp-o1.mp1-V1.git;a=blob;f=alps/kernel-4.4/drivers/misc/mediatek/include/mt-plat/mt6739/include/mach/mtk_battery_table.h;h=76ef73904571e7abf677cf9b73783b52131c467a;hb=76ef73904571e7abf677cf9b73783b52131c467a#l116) @@ int g_QMAX_SYS_VOL_T4[TOTAL_BATTERY_NUMBER] = {36000, 36010, 36020, 36030};

 #define BIF_NTC_R 16000

 #if (BAT_NTC_10 == 1)

-struct FUELGAUGE_TEMPERATURE Fg_Temperature_Table[21] = {

+#define NTC_NUM 25 //wang add 20180528

+struct FUELGAUGE_TEMPERATURE Fg_Temperature_Table[NTC_NUM] = {

                {-40, 195652},

                {-35, 148171},

                {-30, 113347},

@@ [-132,12](http://192.168.11.104/gitweb/?p=alps-mp-o1.mp1-V1.git;a=blob;f=alps/kernel-4.4/drivers/misc/mediatek/include/mt-plat/mt6739/include/mach/mtk_battery_table.h;h=7cb7b5e7e735a1907b941a6df5755c582ffca0ac;hb=7cb7b5e7e735a1907b941a6df5755c582ffca0ac#l132) [+138,17](http://192.168.11.104/gitweb/?p=alps-mp-o1.mp1-V1.git;a=blob;f=alps/kernel-4.4/drivers/misc/mediatek/include/mt-plat/mt6739/include/mach/mtk_battery_table.h;h=76ef73904571e7abf677cf9b73783b52131c467a;hb=76ef73904571e7abf677cf9b73783b52131c467a#l138) @@ struct FUELGAUGE_TEMPERATURE Fg_Temperature_Table[21] = {

                {45, 4917},

                {50, 4161},

                {55, 3535},

-               {60, 3014}

+               {60, 3014},

+               {65, 2586},

+               {70, 2228},

+               {75, 1925},

+               {80, 1669}

 };

 #endif

 #if (BAT_NTC_47 == 1)

-struct FUELGAUGE_TEMPERATURE Fg_Temperature_Table[21] = {

+#define NTC_NUM 21 //wang add 20180528

+struct FUELGAUGE_TEMPERATURE Fg_Temperature_Table[NTC_NUM] = {

                {-40, 1747920},

                {-35, 1245428},

                {-30, 898485},
2. Modify mtk_ts_battery.c

/alps/kernel-4.4/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_battery.c

@@ [-134,7](http://192.168.11.104/gitweb/?p=alps-mp-o1.mp1-V1.git;a=blob;f=alps/kernel-4.4/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_battery.c;h=f807c7272f610a9e61307eaebe0057ee0f157490;hb=f807c7272f610a9e61307eaebe0057ee0f157490#l134) [+134,7](http://192.168.11.104/gitweb/?p=alps-mp-o1.mp1-V1.git;a=blob;f=alps/kernel-4.4/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_battery.c;h=e201c1fc84ba09e04f8d53a5ca11993848df1feb;hb=e201c1fc84ba09e04f8d53a5ca11993848df1feb#l134) @@ static int bat_temp = 21234;

 /* static int battery_write_flag=0; */

-#define mtktsbattery_TEMP_CRIT 60000   /* 60.000 degree Celsius */

+#define mtktsbattery_TEMP_CRIT 80000   /* 60.000 degree Celsius */ //wang add 20180528

 #define mtktsbattery_dprintk(fmt, args...)   \

 do {                                    \

@@ [-455,8](http://192.168.11.104/gitweb/?p=alps-mp-o1.mp1-V1.git;a=blob;f=alps/kernel-4.4/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_battery.c;h=f807c7272f610a9e61307eaebe0057ee0f157490;hb=f807c7272f610a9e61307eaebe0057ee0f157490#l455) [+455,8](http://192.168.11.104/gitweb/?p=alps-mp-o1.mp1-V1.git;a=blob;f=alps/kernel-4.4/drivers/misc/mediatek/thermal/common/thermal_zones/mtk_ts_battery.c;h=e201c1fc84ba09e04f8d53a5ca11993848df1feb;hb=e201c1fc84ba09e04f8d53a5ca11993848df1feb#l455) @@ static int tsbat_sysrst_set_cur_state(struct thermal_cooling_device *cdev, unsig

                pr_debug("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");

                pr_debug("*****************************************");

                pr_debug("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");

-

-               *(unsigned int *)0x0 = 0xdead;  /* To trigger data abort to reset the system for thermal protection. */

+               //wang add 20180528

+               //*(unsigned int *)0x0 = 0xdead;        /* To trigger data abort to reset the system for thermal protection. */

        }

        return 0;

 }
3. Modify mtk_battery.c

alps/kernel-4.4/drivers/power/mediatek/battery/mtk_battery.c

@@ [-2041,15](http://192.168.11.104/gitweb/?p=alps-mp-o1.mp1-V1.git;a=blob;f=alps/kernel-4.4/drivers/power/mediatek/battery/mtk_battery.c;h=424147210393fd33fb205b40414683f5549b3cc2;hb=424147210393fd33fb205b40414683f5549b3cc2#l2041) [+2041,15](http://192.168.11.104/gitweb/?p=alps-mp-o1.mp1-V1.git;a=blob;f=alps/kernel-4.4/drivers/power/mediatek/battery/mtk_battery.c;h=97a739dc0bbddd02b32c85c1c99da6006e81e746;hb=97a739dc0bbddd02b32c85c1c99da6006e81e746#l2041) @@ unsigned int TempConverBattThermistor(int temp)

        int i;

        unsigned int TBatt_R_Value = 0xffff;

-       if (temp >= Fg_Temperature_Table[20].BatteryTemp) {

-               TBatt_R_Value = Fg_Temperature_Table[20].TemperatureR;

+       if (temp >= Fg_Temperature_Table[NTC_NUM - 1].BatteryTemp) {

+               TBatt_R_Value = Fg_Temperature_Table[NTC_NUM - 1].TemperatureR;

        } else if (temp <= Fg_Temperature_Table[0].BatteryTemp) {

                TBatt_R_Value = Fg_Temperature_Table[0].TemperatureR;

        } else {

                RES1 = Fg_Temperature_Table[0].TemperatureR;

                TMP1 = Fg_Temperature_Table[0].BatteryTemp;

-               for (i = 0; i <= 20; i++) {

+               for (i = 0; i < NTC_NUM; i++) {

                        if (temp <= Fg_Temperature_Table[i].BatteryTemp) {

                                RES2 = Fg_Temperature_Table[i].TemperatureR;

                                TMP2 = Fg_Temperature_Table[i].BatteryTemp;

@@ [-2078,13](http://192.168.11.104/gitweb/?p=alps-mp-o1.mp1-V1.git;a=blob;f=alps/kernel-4.4/drivers/power/mediatek/battery/mtk_battery.c;h=424147210393fd33fb205b40414683f5549b3cc2;hb=424147210393fd33fb205b40414683f5549b3cc2#l2078) [+2078,13](http://192.168.11.104/gitweb/?p=alps-mp-o1.mp1-V1.git;a=blob;f=alps/kernel-4.4/drivers/power/mediatek/battery/mtk_battery.c;h=97a739dc0bbddd02b32c85c1c99da6006e81e746;hb=97a739dc0bbddd02b32c85c1c99da6006e81e746#l2078) @@ int BattThermistorConverTemp(int Res)

        if (Res >= Fg_Temperature_Table[0].TemperatureR) {

                TBatt_Value = -40;

-       } else if (Res <= Fg_Temperature_Table[20].TemperatureR) {

-               TBatt_Value = 60;

+       } else if (Res <= Fg_Temperature_Table[NTC_NUM - 1].TemperatureR) {

+               TBatt_Value = 80;

        } else {

                RES1 = Fg_Temperature_Table[0].TemperatureR;

                TMP1 = Fg_Temperature_Table[0].BatteryTemp;

-               for (i = 0; i <= 20; i++) {

+               for (i = 0; i < (NTC_NUM - 1); i++) {

                        if (Res >= Fg_Temperature_Table[i].TemperatureR) {

                                RES2 = Fg_Temperature_Table[i].TemperatureR;

                                TMP2 = Fg_Temperature_Table[i].BatteryTemp;

@@ [-2098,7](http://192.168.11.104/gitweb/?p=alps-mp-o1.mp1-V1.git;a=blob;f=alps/kernel-4.4/drivers/power/mediatek/battery/mtk_battery.c;h=424147210393fd33fb205b40414683f5549b3cc2;hb=424147210393fd33fb205b40414683f5549b3cc2#l2098) [+2098,7](http://192.168.11.104/gitweb/?p=alps-mp-o1.mp1-V1.git;a=blob;f=alps/kernel-4.4/drivers/power/mediatek/battery/mtk_battery.c;h=97a739dc0bbddd02b32c85c1c99da6006e81e746;hb=97a739dc0bbddd02b32c85c1c99da6006e81e746#l2098) @@ int BattThermistorConverTemp(int Res)

                TBatt_Value = (((Res - RES2) * TMP1) + ((RES1 - Res) * TMP2)) / (RES1 - RES2);

        }

-       bm_trace("[BattThermistorConverTemp] %d %d %d %d %d %d\n", RES1, RES2, Res, TMP1, TMP2, TBatt_Value);

+       bm_trace("[BattThermistorConverTemp] %d %d %d %d %d %d, wwwwwNTC_NUM = %d\n", RES1, RES2, Res, TMP1, TMP2, TBatt_Value, NTC_NUM);

        return TBatt_Value;

 }

@@ [-2334,8](http://192.168.11.104/gitweb/?p=alps-mp-o1.mp1-V1.git;a=blob;f=alps/kernel-4.4/drivers/power/mediatek/battery/mtk_battery.c;h=424147210393fd33fb205b40414683f5549b3cc2;hb=424147210393fd33fb205b40414683f5549b3cc2#l2334) [+2334,8](http://192.168.11.104/gitweb/?p=alps-mp-o1.mp1-V1.git;a=blob;f=alps/kernel-4.4/drivers/power/mediatek/battery/mtk_battery.c;h=97a739dc0bbddd02b32c85c1c99da6006e81e746;hb=97a739dc0bbddd02b32c85c1c99da6006e81e746#l2334) @@ int force_get_tbat(bool update)

        bat_temperature_val = force_get_tbat_internal(update);

-       while (counts < 5 && bat_temperature_val >= 60) {

-               bm_err("[force_get_tbat]over60 count=%d, bat_temp=%d\n", counts, bat_temperature_val);

+       while (counts < 5 && bat_temperature_val >= 80) {//wang submit 20180524

+               bm_err("[force_get_tbat]over80 count=%d, bat_temp=%d\n", counts, bat_temperature_val);

                bat_temperature_val = force_get_tbat_internal(true);

                counts++;

        }
4. Modify mtk_battery_internal.h

alps/kernel-4.4/drivers/power/mediatek/battery/mtk_battery_internal.h

@@ [-34,7](http://192.168.11.104/gitweb/?p=alps-mp-o1.mp1-V1.git;a=blob;f=alps/kernel-4.4/drivers/power/mediatek/battery/mtk_battery_internal.h;h=6c2293cbfad5a14e479c095779d82e88d1032bcb;hb=6c2293cbfad5a14e479c095779d82e88d1032bcb#l34) [+34,7](http://192.168.11.104/gitweb/?p=alps-mp-o1.mp1-V1.git;a=blob;f=alps/kernel-4.4/drivers/power/mediatek/battery/mtk_battery_internal.h;h=304fc84470f8bdfdece2439cc5376b15c0b4dfba;hb=304fc84470f8bdfdece2439cc5376b15c0b4dfba#l34) @@

 #define SHUTDOWN_TIME 40

 #define AVGVBAT_ARRAY_SIZE 30

 #define INIT_VOLTAGE 3450

-#define BATTERY_SHUTDOWN_TEMPERATURE 60

+#define BATTERY_SHUTDOWN_TEMPERATURE 80

 /* ============================================================ */

 /* typedef and Struct*/

So far, this article is over. If there are any mistakes, you are welcome to make suggestions and corrections. At the same time look forward to your attention, thank you for reading, thank you!

Posted by DarkArchon on Mon, 30 Sep 2019 08:35:09 -0700