Bootloader LK低电禁止开机,并显示提示图片

需求:
5%以下电量需要开机时候,弹出友好界面提醒:“电量不足,请充电半小时后再开机”

Bootloader低电禁止开机,并显示提示图片

bootloader流程分析:
https://blog.csdn.net/chenzhen1080/article/details/96635968

原理:电量充足时默认显示splash.img的图片,电量低时,显示“电量不足”的图片。

遇到的问题:
1.修改LK的splash.h图像失真
https://blog.csdn.net/u012728256/article/details/70045965
图片资源请查看附件

格式要求是png, 色深8bit, 且不带alpha(透明色)通道的,之后使用如下命令生成的splash.h文件就显示正常。

convert logo.png -recolor "0 0 1,0 1 0,1 0 0" logo_new.png   //将图片重新着色BRG转C成rgb
convert -depth 8 logo_new.png rgb:logo_raw.raw    //将png格式转成raw图片格式
xxd -c16 -i logo_raw.raw > splash.h  //生成对于的splash.h头文件的数组

2.bootloader无法获取电量百分比
bootloader只能获取到电压,所以只能估算5%的时候的电压了
3.用photoshop生成的.raw文件,之后调用 xxd -c16 -i logo_raw.raw > splash.h生成.h文件显示出的图片显示蓝色。
不知道原因
4.aboot.c有如下代码:

normal_boot:
	if (!boot_into_fastboot)
	{
		if (target_is_emmc_boot())
		{
			if(emmc_recovery_init())
				dprintf(ALWAYS,"error in emmc_recovery_init\n");
			if(target_use_signed_kernel())
			{
......

调试过程中,一直纠结为啥没有执行goto normal_boot语句,却能进入kernel,原来如果没有强制跳转语句,则normal_boot被忽略!代码继续往下执行。
完整patch如下:

diff --git a/bootable/bootloader/lk/dev/fbcon/fbcon.c b/bootable/bootloader/lk/dev/fbcon/fbcon.c
old mode 100644
new mode 100755
index 3ac42f4..08aad09
--- a/bootable/bootloader/lk/dev/fbcon/fbcon.c
+++ b/bootable/bootloader/lk/dev/fbcon/fbcon.c
@@ -538,3 +538,11 @@ void display_image_on_screen(void)
 	display_default_image_on_screen();
 #endif
 }
+
+#if LOW_BATTERY_WARNING
+void display_batt_low_logo() {
+	display_default_image_on_screen();
+};
+#endif
+
+
diff --git a/bootable/bootloader/lk/include/platform.h b/bootable/bootloader/lk/include/platform.h
old mode 100644
new mode 100755
index 91ff133..bb18166
--- a/bootable/bootloader/lk/include/platform.h
+++ b/bootable/bootloader/lk/include/platform.h
@@ -49,6 +49,9 @@ addr_t get_bs_info_addr(void);
 void display_init(void);
 void display_shutdown(void);
 void display_image_on_screen(void);
+#if LOW_BATTERY_WARNING
+void display_batt_low_logo(void);
+#endif
 void display_fbcon_message(char *str);
 
 unsigned board_machtype(void);
diff --git a/bootable/bootloader/lk/include/target.h b/bootable/bootloader/lk/include/target.h
old mode 100644
new mode 100755
index b482b2d..b9de77f
--- a/bootable/bootloader/lk/include/target.h
+++ b/bootable/bootloader/lk/include/target.h
@@ -52,6 +52,9 @@ int target_is_emmc_boot(void);
 unsigned* target_atag_mem(unsigned* ptr);
 void target_battery_charging_enable(unsigned enable, unsigned disconnect);
 unsigned target_pause_for_battery_charge(void);
+#if LOW_BATTERY_WARNING
+bool is_user_press_power_key(void);
+#endif
 unsigned target_baseband(void);
 void target_serialno(unsigned char *buf);
 void target_fastboot_init(void);
diff --git a/bootable/bootloader/lk/makefile b/bootable/bootloader/lk/makefile
old mode 100644
new mode 100755
index ea33eb6..b125f03
--- a/bootable/bootloader/lk/makefile
+++ b/bootable/bootloader/lk/makefile
@@ -93,6 +93,8 @@ GENERATED := $(CONFIGHEADER)
 # anything added to DEFINES will be put into $(BUILDDIR)/config.h
 DEFINES := LK=1				
 
+DEFINES += LOW_BATTERY_WARNING=0
+
 # Anything added to SRCDEPS will become a dependency of every source file in the system.
 # Useful for header files that may be included by one or more source files.
 SRCDEPS := $(CONFIGHEADER)
diff --git a/bootable/bootloader/lk/platform/msm_shared/display.c b/bootable/bootloader/lk/platform/msm_shared/display.c
old mode 100644
new mode 100755
index 3bf5621..a1c19b1
--- a/bootable/bootloader/lk/platform/msm_shared/display.c
+++ b/bootable/bootloader/lk/platform/msm_shared/display.c
@@ -39,6 +39,10 @@
 #ifdef DISPLAY_TYPE_MDSS
 #include <target/display.h>
 #endif
+#if LOW_BATTERY_WARNING
+#include <platform/timer.h>
+#define POWERON_VOL_THRESH 3600000
+#endif
 
 static struct msm_fb_panel_data *panel;
 
@@ -269,6 +273,10 @@ msm_display_on_out:
 int msm_display_init(struct msm_fb_panel_data *pdata)
 {
 	int ret = NO_ERROR;
+#if LOW_BATTERY_WARNING
+	int low_battery = 0;
+#endif
+	
 
 	panel = pdata;
 	if (!panel) {
@@ -330,7 +338,19 @@ int msm_display_init(struct msm_fb_panel_data *pdata)
 		goto msm_display_init_out;
 
 	fbcon_setup(&(panel->fb));
+#if LOW_BATTERY_WARNING
+	uint32_t volt = target_get_battery_voltage();
+	if(volt < POWERON_VOL_THRESH){
+		dprintf(INFO, "Tim_B display the low battery png.volt=%d\n",volt);
+        display_batt_low_logo();
+		low_battery = 1;
+	}else{
+	    display_image_on_screen();
+		low_battery = 0;
+    }
+#else
 	display_image_on_screen();
+#endif
 
 	if (panel->dsi2HDMI_config)
 		ret = panel->dsi2HDMI_config(&(panel->panel_info));
@@ -358,6 +378,12 @@ int msm_display_init(struct msm_fb_panel_data *pdata)
 		goto msm_display_init_out;
 
 msm_display_init_out:
+#if LOW_BATTERY_WARNING
+	if(low_battery && is_user_press_power_key()){
+			mdelay(2000);
+			shutdown_device();
+	}
+#endif
 	return ret;
 }
 
diff --git a/bootable/bootloader/lk/platform/msm_shared/include/splash.h b/bootable/bootloader/lk/platform/msm_shared/include/splash.h
old mode 100644
new mode 100755
index badb8d0..f993d80
--- a/bootable/bootloader/lk/platform/msm_shared/include/splash.h
+++ b/bootable/bootloader/lk/platform/msm_shared/include/splash.h
@@ -3544,12 +3544,3183 @@ static char imageBuffer[] = {
 
 #else
 
+#if LOW_BATTERY_WARNING
+#define SPLASH_IMAGE_WIDTH     482
+#define SPLASH_IMAGE_HEIGHT    35
+#else
 #define SPLASH_IMAGE_WIDTH     113
 #define SPLASH_IMAGE_HEIGHT    124
+#endif
 
 /* This image is 228x113 raw Image resembling QuIC logo*/
 
 static char imageBuffer_rgb888[] = {
 //注意修改的图片数据删除了,请对比参考原文件
 }
diff --git a/bootable/bootloader/lk/target/msm8952/init.c b/bootable/bootloader/lk/target/msm8952/init.c
old mode 100644
new mode 100755
index 462ceca..34bd900
--- a/bootable/bootloader/lk/target/msm8952/init.c
+++ b/bootable/bootloader/lk/target/msm8952/init.c
@@ -470,6 +470,27 @@ uint32_t is_user_force_reset(void)
 
 #define SMBCHG_USB_RT_STS 0x21310
 #define USBIN_UV_RT_STS BIT(0)
+#if LOW_BATTERY_WARNING
+bool is_user_press_power_key(void)
+{
+/*
+	#define HARD_RST                1
+	#define DC_CHG                  8
+	#define USB_CHG                 16
+	#define PON1                    32
+	#define CBLPWR_N                64
+	#define KPDPWR_N                128*/
+
+	uint8_t pon_reason = pm8x41_get_pon_reason();
+	uint8_t is_cold_boot = pm8x41_get_is_cold_boot();
+	bool powerKeyPressed = pon_reason & KPDPWR_N; //power key is pressed
+	bool notHardReset = !(pon_reason & HARD_RST); //hard set
+	dprintf(INFO, "%s : Tim_B pon_reason is:0x%x,powerKeyPressed=%d,notHardReset=%d\n", __func__,
+		pon_reason,powerKeyPressed,notHardReset);
+	return is_cold_boot && powerKeyPressed;
+}
+#endif
+
 unsigned target_pause_for_battery_charge(void)
 {
 	uint8_t pon_reason = pm8x41_get_pon_reason();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值