voidcmd_flash_mmc(constchar *arg, void *data, unsigned sz) { ... #if VERIFIED_BOOT || VERIFIED_BOOT_2 if (target_build_variant_user()) { /* if device is locked: * common partition will not allow to be flashed * critical partition will allow to flash image. */ if(!device.is_unlocked && !critical_flash_allowed(arg)) { fastboot_fail("Partition flashing is not allowed"); return; }
/* if device critical is locked: * common partition will allow to be flashed * critical partition will not allow to flash image. */ if (VB_M <= target_get_vb_version() && !device.is_unlock_critical && critical_flash_allowed(arg)) { fastboot_fail("Critical partition flashing is not allowed"); return; } } #endif
voidwrite_device_info_mmc(device_info *dev) { ... if (devinfo_present) index = partition_get_index("devinfo"); else index = partition_get_index("aboot");
ptn = partition_get_offset(index); ... if (devinfo_present) ret = mmc_write(ptn, device_info_sz, (void *)info_buf); else ret = mmc_write((ptn + size - device_info_sz), device_info_sz, (void *)info_buf);
可见,就写在devinfo分区开始处, 如果没有devinfo分区,那就放到aboot分区最后。
一般还会有个标记判断是否允许解锁,就是is_allow_unlock,这个标记写在config or frq分区:
staticchar frp_ptns[2][8] = {"config","frp"};
staticintwrite_allow_oem_unlock(bool allow_unlock) { ... index = partition_get_index(frp_ptns[0]); if (index == INVALID_PTN) { index = partition_get_index(frp_ptns[1]); if (index == INVALID_PTN) { dprintf(CRITICAL, "Neither '%s' nor '%s' partition found\n", frp_ptns[0],frp_ptns[1]); return-1; } }
/** * Sets whether the user has allowed this device to be unlocked. * * All actors involved must agree for OEM unlock to be possible. * * @param allowed Whether the device should be allowed to be unlocked. * @throws SecurityException if the user is not allowed to unlock the device. * * @see #isOemUnlockAllowedByUser() */ @RequiresPermission(android.Manifest.permission.MANAGE_USER_OEM_UNLOCK_STATE) publicvoidsetOemUnlockAllowedByUser(boolean allowed) { try { mService.setOemUnlockAllowedByUser(allowed); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } }
service frameworks/base/services/core/java/com/android/server/oemlock/OemLockService.java:
// The user has the final say so if they allow unlock, then the device allows the bootloader // to OEM unlock it. @Override publicvoidsetOemUnlockAllowedByUser(boolean allowedByUser) { if (ActivityManager.isUserAMonkey()) { // Prevent a monkey from changing this return; }
finallongtoken= Binder.clearCallingIdentity(); try { if (!isOemUnlockAllowedByAdmin()) { thrownewSecurityException("Admin does not allow OEM unlock"); }
if (!mOemLock.isOemUnlockAllowedByCarrier()) { thrownewSecurityException("Carrier does not allow OEM unlock"); }
/** * Always synchronize the OemUnlockAllowed bit to the FRP partition, which * is used to erase FRP information on a unlockable device. */ privatevoidsetPersistentDataBlockOemUnlockAllowedBit(boolean allowed) { finalPersistentDataBlockManagerInternalpdbmi = LocalServices.getService(PersistentDataBlockManagerInternal.class); // if mOemLock is PersistentDataBlockLock, then the bit should have already been set if (pdbmi != null && !(mOemLock instanceof PersistentDataBlockLock)) { Slog.i(TAG, "Update OEM Unlock bit in pst partition to " + allowed); pdbmi.forceOemUnlockEnabled(allowed); } }