0. 背景
本文我已分享过同事,现在也分享给大家。
平台: SM6350、android 10、kernel version:msm-4.19
1. 代码
开机组合键需实现3个功能:
1. Power + Volume Up进入recovery模式
2. Power + Volume Down进入Fastboot模式
3. Power + Volume Up + Volume Down进入edl模式
2. 为啥这样改
这个是根据打印的log,然后改的,可能有的平台代码默认是好的。
代码路径:
bootable/bootloader/edk2/QcomModulePkg/Application/LinuxLoader/LinuxLoader.c
音量+ 和power键一起按,keyPressed 返回值是5(get getcode=5),串口log如下;
VB: Non-secure device: Security State: (0xF7F)
VB: RWDeviceState: Succeed using devinfo!
get getcode=5
grep -nr "SCAN_HOME" ./bootable/
检索SCAN_HOME的值是5,回到之前的修改,这样改会正确进入recovery模式。BootIntoRecovery = TRUE;
音量- 和power键一起按,keyPressed 返回值是8(get getcode=8),串口log如下:
VB: Non-secure device: Security State: (0xF7F)
VB: RWDeviceState: Succeed using devinfo!
get getcode=8
Total DDR Size: 0x00000000FDA00000
Fastboot=1, Recovery:0
grep -nr "SCAN_SCAN_DELETE" ./bootable/
SCAN_SCAN_DELETE这个定义的值就是8。
顺便看下三个键进入强制下载(音量+、音量-、power键一起按)的log。
UEFI Total : 1051 ms
POST Time [ 2499] OS Loader
Loader Build Info: Oct 15 2020 21:03:37
VB: Non-secure device: Security State: (0xF7F)
VB: RWDeviceState: Succeed using devinfo!
get getcode=23
Start EBS [ 2549]
get getcode=23,SCAN_ESC定义的值就是23。
3. 拓展
我比较关心音量+ 和power键一起按,怎么就对应SCAN_HOME了,SCAN_SCAN_DELETE
还有SCAN_ESC是如何对应的。于是我去modem那边检索看看。
bitra-la-1-0_amss_standard_oem$ grep -nr "SCAN_DELETE" ./
终端返回结果如下:
vim ./BOOT.XF.3.3/boot_images/ShellPkg/Application/Shell/FileHandleWrappers.c +607
我先看了下第一个文件,淦,没看到啥,里面有些command的东西不知道干啥的…,然后想到这个不是几个按键吗,于是看看这个文件:ButtonsLib.c
vim ./BOOT.XF.3.3/boot_images/QcomPkg/SocPkg/BitraPkg/Library/ButtonsLib/ButtonsLib.c
这个代码里面翻看了下,发现了power key、volume up、volume down这些东西,这个代码的意思是检查某个按键被按下(ButtonPressed),然后把值存到pButtonArray数组里面。
然后检查 看看谁调用了这个函数:PollButtonArray
grep -nr "PollButtonArray" ./
从console返回的信息来看,只找到一个地方, 于是打开看看。
vim ./BOOT.XF.3.3/boot_images/QcomPkg/Drivers/ButtonsDxe/ButtonsDxe.c +361
这段代码的大概意思是处理按键事件(调用PollButtonArray函数)。然后通过
ConvertEfiKeyCode函数作了某种转换,把值存到了key buffer里面。
我们继续查找下ConvertEfiKeyCode函数原型,看它搞啥鬼。
grep -nr "ConvertEfiKeyCode" ./BOOT.XF.3.3/boot_images/
./BOOT.XF.3.3/boot_images/QcomPkg/Include/Library/KeypadLib.h
./BOOT.XF.3.3/boot_images/QcomPkg/Include/Library/ButtonsLib.h
Vim ./BOOT.XF.3.3/boot_images/QcomPkg/SocPkg/BitraPkg/Library/ButtonsLib/ButtonsLib.c +146/
进入这里发现核心代码就在里面。
EFI_STATUS ConvertEfiKeyCode (
KEY_TYPE *pKeysPressed,
UINT8 numOfKeysPressed,
KEY_TYPE *pKeysReleased,
UINT8 numOfKeysReleased,
UINT8 sizeOfPressedReleasedArray,
EFI_INPUT_KEY *pEfiKeys,
UINT8 *pNumOfEfiKeys
)
{
EFI_STATUS retVal = EFI_NOT_FOUND;
EFI_INPUT_KEY EfiKey;
EfiKey.ScanCode = SCAN_NULL;
EfiKey.UnicodeChar = 0;
*pNumOfEfiKeys = 0;
isHomeKeyDetected = FALSE;
BOOLEAN bCameraKeyIsPressed;
BOOLEAN bVolUpKeyIsPressed;
BOOLEAN bVolDownKeyIsPressed;
BOOLEAN bCameraKeyIsReleased;
BOOLEAN bHomeKeyIsPressed;
BOOLEAN bPwrKeyPressed;
if( isEfiKeyDetected == FALSE )
{
bCameraKeyIsPressed = FoundAKey(pKeysPressed, sizeOfPressedReleasedArray, CAMERA);
bVolUpKeyIsPressed = FoundAKey(pKeysPressed, sizeOfPressedReleasedArray, VOL_UP);
bVolDownKeyIsPressed = FoundAKey(pKeysPressed, sizeOfPressedReleasedArray, VOL_DOWN);
bCameraKeyIsReleased = FoundAKey(pKeysReleased,sizeOfPressedReleasedArray, CAMERA);
bHomeKeyIsPressed = FoundAKey(pKeysPressed, sizeOfPressedReleasedArray, HOME);
bPwrKeyPressed = FoundAKey(pKeysPressed, sizeOfPressedReleasedArray, PWR);
// assume EFI key found
isEfiKeyDetected = TRUE;
if( bVolUpKeyIsPressed && bVolDownKeyIsPressed )
{
// combo key found
EfiKey.ScanCode = SCAN_ESC;
}
else if( bCameraKeyIsPressed && bVolUpKeyIsPressed )
{
// combo key found
EfiKey.ScanCode = SCAN_HOME;
}
else if( bCameraKeyIsPressed && bVolDownKeyIsPressed )
{
// combo key found
EfiKey.ScanCode = SCAN_DELETE;
}
else if( bVolUpKeyIsPressed )
{
if( bPwrKeyPressed )
{
// combo key found
EfiKey.ScanCode = SCAN_HOME;
}
else
{
// single key found
EfiKey.ScanCode = SCAN_UP;
}
}
else if( bVolDownKeyIsPressed )
{
if( bPwrKeyPressed )
{
// combo key found
EfiKey.ScanCode = SCAN_DELETE;
}
else
......
回到我们最开始的patch与要求:
Volume Down + Power是SCAN_DELETE,所以进入fastboot;
Volume Up + Power是SCAN_HOME,所以进入recovery;
Volume Up和Volume Down一起按的时候是SCAN_ESC,所以进入强制下载edl。