Aliens

打开edk2 fastboot在user版本下刷写分区的功能

March 1, 2022

在Android 10中测试有效

在user版本中, 使用fastboot flash boot boot.img会提示’Unknown command', 这是因为在user版本中, 关闭了fastboot flash的命令.

edk2版本的fastboot对应的源码路径为QcomModulePkg/Library/FastbootLib, flash 等命令在FastbootCmds.c中的cmd_list这个数组定义.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
struct FastbootCmdDesc cmd_list[] = {
      /* By Default enable list is empty */
      {"", NULL},
/*CAUTION(High): Enabling these commands will allow changing the partitions
 *like system,userdata,cachec etc...
 */
#ifdef ENABLE_UPDATE_PARTITIONS_CMDS
      {"flash:", CmdFlash},
      {"erase:", CmdErase},
      {"set_active", CmdSetActive},
      {"flashing get_unlock_ability", CmdFlashingGetUnlockAbility},
      {"flashing unlock", CmdFlashingUnlock},
      {"flashing lock", CmdFlashingLock},
#endif
/*
 *CAUTION(CRITICAL): Enabling these commands will allow changes to bootimage.
 */
#ifdef ENABLE_DEVICE_CRITICAL_LOCK_UNLOCK_CMDS
      {"flashing unlock_critical", CmdFlashingUnLockCritical},
      {"flashing lock_critical", CmdFlashingLockCritical},
#endif
/*
 *CAUTION(CRITICAL): Enabling this command will allow boot with different
 *bootimage.
 */
#ifdef ENABLE_BOOT_CMD
      {"boot", CmdBoot},
#endif

可以看出, 这些命令被ENABLE_UPDATE_PARTITIONS_CMDS, ENABLE_DEVICE_CRITICAL_LOCK_UNLOCK_CMDS, ENABLE_BOOT_CMD控制, 如果需要强行使用这些命令, 那么有两种方法:

a. 在FastbootCmds.c开头define这些宏 b. 在编译脚本中使用-D参数打开这些宏

我选择的是方案b, 搜索整个工程, 发现在QcomModulePkg.dsc中定义了这些宏

1
2
3
4
5
!if $(USER_BUILD_VARIANT) == 0
    GCC:*_*_*_CC_FLAGS = -DENABLE_UPDATE_PARTITIONS_CMDS -DENABLE_BOOT_CMD -DENABLE_DEVICE_CRITICAL_LOCK_UNLOCK_CMDS
!else
    GCC:*_*_*_CC_FLAGS = 
!endif

很显然, userdebug时才会定义这些宏, user版本不会, 故作如下修改

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
diff --git a/QcomModulePkg/QcomModulePkg.dsc b/QcomModulePkg/QcomModulePkg.dsc
index 99f990c52..0b37499f5 100644
--- a/QcomModulePkg/QcomModulePkg.dsc
+++ b/QcomModulePkg/QcomModulePkg.dsc
@@ -114,7 +114,7 @@
   !if $(USER_BUILD_VARIANT) == 0
       GCC:*_*_*_CC_FLAGS = -DENABLE_UPDATE_PARTITIONS_CMDS -DENABLE_BOOT_CMD -DENABLE_DEVICE_CRITICAL_LOCK_UNLOCK_CMDS
   !else
-      GCC:*_*_*_CC_FLAGS = -DUSER_BUILD_VARIANT
+      GCC:*_*_*_CC_FLAGS = -DENABLE_UPDATE_PARTITIONS_CMDS -DENABLE_BOOT_CMD -DENABLE_DEVICE_CRITICAL_LOCK_UNLOCK_CMDS
   !endif
   !if $(ENABLE_LE_VARIANT) == 1
       GCC:*_*_*_CC_FLAGS = -DENABLE_LE_VARIANT

参考: https://blog.csdn.net/super_AI_x/article/details/97791564