[Linux Device Driver] 组合按键

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。

  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值