Merge "Remove offset pointer optimization in inftrees.c."
diff --git a/QcomModulePkg/Application/LinuxLoader/LinuxLoader.inf b/QcomModulePkg/Application/LinuxLoader/LinuxLoader.inf
index 7a1d3e7..82bf84f 100644
--- a/QcomModulePkg/Application/LinuxLoader/LinuxLoader.inf
+++ b/QcomModulePkg/Application/LinuxLoader/LinuxLoader.inf
@@ -1,5 +1,5 @@
 #/* @file
-#  Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
+#  Copyright (c) 2017-2018,2020 The Linux Foundation. All rights reserved.
 #  Portions Copyright (c) 2011-2013, ARM Limited. All rights reserved.
 #
 #  This program and the accompanying materials
@@ -46,6 +46,7 @@
 	CacheMaintenanceLib
 	Zlib
 	ArmLib
+	ArmSmcLib
 	BaseLib
 	DebugLib
 	DevicePathLib
diff --git a/QcomModulePkg/Include/Library/BootLinux.h b/QcomModulePkg/Include/Library/BootLinux.h
index 7d0423b..b62af3e 100644
--- a/QcomModulePkg/Include/Library/BootLinux.h
+++ b/QcomModulePkg/Include/Library/BootLinux.h
@@ -226,4 +226,5 @@
 UINT64 SetandGetLoadAddr (BootParamlist *BootParamlistPtr, AddrType Type);
 BOOLEAN IsNANDSquashFsSupport (VOID);
 BOOLEAN IsEnableDisplayMenuFlagSupported (VOID);
+BOOLEAN IsSystemdBootslotEnabled (VOID);
 #endif
diff --git a/QcomModulePkg/Include/Library/HypervisorMvCalls.h b/QcomModulePkg/Include/Library/HypervisorMvCalls.h
old mode 100644
new mode 100755
index 8072aec..cca751e
--- a/QcomModulePkg/Include/Library/HypervisorMvCalls.h
+++ b/QcomModulePkg/Include/Library/HypervisorMvCalls.h
@@ -25,7 +25,7 @@
  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
-
+#include <Library/ArmSmcLib.h>
 #include "BootLinux.h"
 
 #define HYP_BOOTINFO_MAGIC   0xC06B0071
@@ -61,3 +61,4 @@
 HypBootInfo *GetVmData (VOID);
 BOOLEAN IsVmEnabled (VOID);
 EFI_STATUS CheckAndSetVmData (BootParamlist *BootParamlistPtr);
+VOID DisableHypUartUsageForLogging (VOID);
diff --git a/QcomModulePkg/Include/Library/LocateDeviceTree.h b/QcomModulePkg/Include/Library/LocateDeviceTree.h
index 40f70b0..4a84a64 100644
--- a/QcomModulePkg/Include/Library/LocateDeviceTree.h
+++ b/QcomModulePkg/Include/Library/LocateDeviceTree.h
@@ -118,7 +118,8 @@
   PMIC_IDX1,
   PMIC_IDX2,
   PMIC_IDX3,
-  MAX_PMIC_IDX,
+  PMIC_IDX4,
+  MAX_PMIC_IDX = 0xF,
 } PMIC_INDEXES;
 
 typedef struct PmicIdInfo {
diff --git a/QcomModulePkg/Include/Library/PartitionTableUpdate.h b/QcomModulePkg/Include/Library/PartitionTableUpdate.h
index 861c988..ea9465d 100644
--- a/QcomModulePkg/Include/Library/PartitionTableUpdate.h
+++ b/QcomModulePkg/Include/Library/PartitionTableUpdate.h
@@ -49,6 +49,13 @@
   PARTITION_ALL,
 } UPDATE_TYPE;
 
+typedef enum {
+  PTN_ENTRIES_TO_MISC = 1,
+  PTN_ENTRIES_FROM_MISC,
+} NANDAB_UPDATE_TYPE;
+
+#define NANDAB_MAX_SLOTNAME_LEN 7
+
 #define PARTITION_ATTRIBUTES_MASK 0x1
 #define PARTITION_GUID_MASK 0x2
 
@@ -196,6 +203,22 @@
   struct BootPartsLinkedList *Next;
 };
 
+
+/*
+  CHAR8 priority     : 2;
+  CHAR8 active       : 1;
+  CHAR8 try_count    : 3;
+  CHAR8 boot_success : 1;
+  CHAR8 unbootable   : 1;
+*/
+typedef struct NandABPtnHeader {
+  CHAR8 Attributes;
+  CHAR16 SlotName[NANDAB_MAX_SLOTNAME_LEN];
+} NandABPtnHeader;
+typedef struct NandABAttr {
+  NandABPtnHeader Slots[MAX_SLOTS];
+} NandABAttr;
+
 EFI_STATUS
 UpdatePartitionTable (UINT8 *GptImage,
                       UINT32 Sz,
@@ -210,6 +233,7 @@
 PartitionHasMultiSlot (CONST CHAR16 *Pname);
 EFI_STATUS EnumeratePartitions (VOID);
 VOID UpdatePartitionEntries (VOID);
+EFI_STATUS NandABUpdatePartition (UINT32 UpdateType);
 VOID UpdatePartitionAttributes (UINT32 UpdateType);
 VOID FindPtnActiveSlot (VOID);
 EFI_STATUS
@@ -223,4 +247,5 @@
 EFI_STATUS ClearUnbootable (VOID);
 BOOLEAN IsABRetryCountUpdateRequired (VOID);
 UINT32 PartitionVerifyMibibImage (UINT8 *Image);
+UINT64 GetPartitionSize (EFI_BLOCK_IO_PROTOCOL *BlockIo);
 #endif
diff --git a/QcomModulePkg/Include/Library/Recovery.h b/QcomModulePkg/Include/Library/Recovery.h
index f45e87b..e2f1302 100644
--- a/QcomModulePkg/Include/Library/Recovery.h
+++ b/QcomModulePkg/Include/Library/Recovery.h
@@ -90,4 +90,6 @@
 GetSnapshotMergeStatus (VOID);
 EFI_STATUS
 SetSnapshotMergeStatus (VirtualAbMergeStatus MergeStatus);
+EFI_STATUS
+ReadFromPartition (EFI_GUID *Ptype, VOID **Msg, UINT32 Size);
 #endif
diff --git a/QcomModulePkg/Include/Library/UpdateCmdLine.h b/QcomModulePkg/Include/Library/UpdateCmdLine.h
index a12dba1..c3a4640 100644
--- a/QcomModulePkg/Include/Library/UpdateCmdLine.h
+++ b/QcomModulePkg/Include/Library/UpdateCmdLine.h
@@ -82,6 +82,7 @@
   CHAR8 *LEVerityCmdLine;
   CHAR8 *FstabSuffix;
   UINT32 HeaderVersion;
+  CONST CHAR8 *SystemdSlotEnv;
 } UpdateCmdLineParamList;
 
 EFI_STATUS
diff --git a/QcomModulePkg/Include/Protocol/EFIDisplayPwr.h b/QcomModulePkg/Include/Protocol/EFIDisplayPwr.h
new file mode 100644
index 0000000..84eae92
--- /dev/null
+++ b/QcomModulePkg/Include/Protocol/EFIDisplayPwr.h
@@ -0,0 +1,144 @@
+/* Copyright (c) 2020, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef __EFIDISPLAYPWR_H__
+#define __EFIDISPLAYPWR_H__
+
+/*===========================================================================
+  INCLUDE FILES
+===========================================================================*/
+
+/*===========================================================================
+  MACRO DECLARATIONS
+===========================================================================*/
+/** @ingroup efi_displayPwr_constants
+  Protocol version.
+*/
+#define EFI_DISPLAY_POWER_PROTOCOL_REVISION    0x0000000000010000
+
+/** @} */ /* end_addtogroup efi_displayPwr_constants */
+
+/*  Protocol GUID definition */
+/** @ingroup efi_displayPwr_protocol */
+#define EFI_DISPLAY_POWER_PROTOCOL_GUID  \
+    {0xf352021d, 0x9593, 0x4432, {0xbf, 0x4, 0x67, 0xb9, 0xf3, 0xb7, 0x60, 0x8}}
+
+/** @cond */
+/*===========================================================================
+  EXTERNAL VARIABLES
+===========================================================================*/
+/**
+  External reference to the Display Power Protocol GUID.
+*/
+extern EFI_GUID gEfiDisplayPowerStateProtocolGuid;
+
+/*===========================================================================
+  TYPE DEFINITIONS
+===========================================================================*/
+/**
+  Protocol declaration.
+*/
+typedef struct _EFI_DISPLAY_POWER_PROTOCOL  EFI_DISPLAY_POWER_PROTOCOL;
+/** @endcond */
+
+/** @ingroup efi_displayPwr_data_types
+  Display state.
+*/
+typedef enum /** @cond */_EFI_DISPLAY_POWER_STATE/** @endcond */ {
+  EfiDisplayPowerStateUnknown = 0,
+  /**< Indicates the power state has not yet been initialized. */
+  EfiDisplayPowerStateOff,
+  /**< Power off both the backlight and display. */
+  EfiDisplayPowerStateOn,
+  /**< Power on both the backlight and display. */
+} EFI_DISPLAY_POWER_STATE;
+/** @} */ /* end_addtogroup efi_displayPwr_data_types */
+
+/*===========================================================================
+  FUNCTION DEFINITIONS
+===========================================================================*/
+/* EFI_DISPLAY_POWER_SETDISPLAYPOWERSTATE */
+/** @ingroup efi_displayPwr_set_display_power_state
+  @par Summary
+  Modifies the power state of the display and backlight.
+
+  @param[in]  This        Pointer to the EFI_DISPLAY_POWER_PROTOCOL instance.
+  @param[in]  PowerState  Display state; see #EFI_DISPLAY_POWER_STATE for
+                          details.
+
+  @return
+  EFI_SUCCESS           -- Function returned successfully.
+  EFI_INVALID_PARAMETER -- Parameter passed is incorrect.
+  EFI_DEVICE_ERROR      -- Physical device reported an error.
+*/
+typedef
+EFI_STATUS
+(EFIAPI *EFI_DISPLAY_POWER_SETDISPLAYPOWERSTATE)(
+  IN EFI_DISPLAY_POWER_PROTOCOL             *This,
+  IN EFI_DISPLAY_POWER_STATE                PowerState
+  );
+
+/* EFI_DISPLAY_POWER_GETDISPLAYPOWERSTATE */
+/** @ingroup efi_displayPwr_get_display_power_state
+  @par Summary
+  Retrieves the current power state of the display and backlight.
+
+  @param[in]  This        Pointer to the EFI_DISPLAY_POWER_PROTOCOL instance.
+  @param[out] PowerState  Display state; see #EFI_DISPLAY_POWER_STATE for
+                          details.
+
+  @return
+  EFI_SUCCESS           -- Function returned successfully.
+  EFI_INVALID_PARAMETER -- Parameter passed is incorrect.
+  EFI_DEVICE_ERROR      -- Physical device reported an error.
+*/
+typedef
+EFI_STATUS
+(EFIAPI * EFI_DISPLAY_POWER_GETDISPLAYPOWERSTATE)(
+  IN EFI_DISPLAY_POWER_PROTOCOL             *This,
+  OUT EFI_DISPLAY_POWER_STATE               *PowerState
+  );
+
+/*===========================================================================
+  PROTOCOL INTERFACE
+===========================================================================*/
+/** @ingroup efi_displayPwr_protocol
+  @par Summary
+  This protocol allows modification and query of the display power state.
+
+  @par Parameters
+  @inputprotoparams{display_power_proto_params.tex}
+*/
+
+typedef struct _EFI_DISPLAY_POWER_PROTOCOL {
+  UINT32                                        Revision;
+  EFI_DISPLAY_POWER_SETDISPLAYPOWERSTATE        SetDisplayPowerState;
+  EFI_DISPLAY_POWER_GETDISPLAYPOWERSTATE        GetDisplayPowerState;
+} EFI_DISPLAY_POWER_PROTOCOL;
+
+#endif  /* __EFIDISPLAYPWR_H__ */
diff --git a/QcomModulePkg/Library/BootLib/BootLib.inf b/QcomModulePkg/Library/BootLib/BootLib.inf
old mode 100755
new mode 100644
index 486c2fd..9a635b8
--- a/QcomModulePkg/Library/BootLib/BootLib.inf
+++ b/QcomModulePkg/Library/BootLib/BootLib.inf
@@ -151,6 +151,7 @@
 	gEfiNandPartiGuidProtocolGuid
 	gEfiDDRGetInfoProtocolGuid
 	gEfiKernelProtocolGuid
+	gEfiDisplayPowerStateProtocolGuid
 
 [FixedPcd]
 	gArmTokenSpaceGuid.PcdSystemMemoryBase
diff --git a/QcomModulePkg/Library/BootLib/BootLinux.c b/QcomModulePkg/Library/BootLib/BootLinux.c
index b1591c3..5eea495 100644
--- a/QcomModulePkg/Library/BootLib/BootLinux.c
+++ b/QcomModulePkg/Library/BootLib/BootLinux.c
@@ -1034,6 +1034,10 @@
 
   BootStatsSetTimeStamp (BS_KERNEL_ENTRY);
 
+  if (IsVmEnabled ()) {
+    DisableHypUartUsageForLogging ();
+  }
+
   //
   // Start the Linux Kernel
   //
@@ -1553,3 +1557,15 @@
   return TRUE;
 }
 #endif
+
+#ifdef ENABLE_SYSTEMD_BOOTSLOT
+BOOLEAN IsSystemdBootslotEnabled (VOID)
+{
+  return TRUE;
+}
+#else
+BOOLEAN IsSystemdBootslotEnabled (VOID)
+{
+  return FALSE;
+}
+#endif
diff --git a/QcomModulePkg/Library/BootLib/HypervisorMvCalls.c b/QcomModulePkg/Library/BootLib/HypervisorMvCalls.c
old mode 100644
new mode 100755
index ec2fb1b..9557635
--- a/QcomModulePkg/Library/BootLib/HypervisorMvCalls.c
+++ b/QcomModulePkg/Library/BootLib/HypervisorMvCalls.c
@@ -26,11 +26,12 @@
  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-#include <Library/DebugLib.h>
 #include <Protocol/EFIScm.h>
 #include <Protocol/scm_sip_interface.h>
 #include <Library/HypervisorMvCalls.h>
 
+#define HYP_DISABLE_UART_LOGGING    0x86000000
+
 STATIC BOOLEAN VmEnabled = FALSE;
 STATIC HypBootInfo *HypInfo = NULL;
 
@@ -123,6 +124,16 @@
   return EFI_SUCCESS;
 }
 
+VOID DisableHypUartUsageForLogging (VOID)
+{
+  ARM_SMC_ARGS ArmSmcArgs;
+
+  ArmSmcArgs.Arg0 = HYP_DISABLE_UART_LOGGING;
+  ArmCallSmc (&ArmSmcArgs);
+  DEBUG ((EFI_D_VERBOSE, "returned Smc call to disable Uart logging from Hyp:"
+                         " 0x%x\n", ArmSmcArgs.Arg0));
+}
+
 EFI_STATUS
 CheckAndSetVmData (BootParamlist *BootParamlistPtr)
 {
diff --git a/QcomModulePkg/Library/BootLib/LinuxLoaderLib.c b/QcomModulePkg/Library/BootLib/LinuxLoaderLib.c
index 6dee2b5..5d77f34 100644
--- a/QcomModulePkg/Library/BootLib/LinuxLoaderLib.c
+++ b/QcomModulePkg/Library/BootLib/LinuxLoaderLib.c
@@ -826,7 +826,10 @@
   UINTN PartitionSize;
   UINTN TokenIndex;
 
-  PartitionSize = (BlockIo->Media->LastBlock + 1) * BlockIo->Media->BlockSize;
+  PartitionSize = GetPartitionSize (BlockIo);
+  if (!PartitionSize) {
+    return EFI_BAD_BUFFER_SIZE;
+  }
 
   Status = gBS->HandleProtocol (Handle, &gEfiEraseBlockProtocolGuid,
                                 (VOID **)&EraseProt);
diff --git a/QcomModulePkg/Library/BootLib/LocateDeviceTree.c b/QcomModulePkg/Library/BootLib/LocateDeviceTree.c
index 4c0e5cd..73a5b24 100644
--- a/QcomModulePkg/Library/BootLib/LocateDeviceTree.c
+++ b/QcomModulePkg/Library/BootLib/LocateDeviceTree.c
@@ -542,8 +542,8 @@
 }
 
 STATIC VOID
-ReadBestPmicMatch (CONST CHAR8 *PmicProp, UINT32 PmicEntCount,
-                    PmicIdInfo *BestPmicInfo)
+ReadBestPmicMatch (CONST CHAR8 *PmicProp, INT32 PmicMaxIdx,
+                    UINT32 PmicEntCount, PmicIdInfo *BestPmicInfo)
 {
   UINT32 PmicEntIdx;
   UINT32 Idx;
@@ -552,7 +552,7 @@
   memset (BestPmicInfo, 0, sizeof (PmicIdInfo));
   for (PmicEntIdx = 0; PmicEntIdx < PmicEntCount; PmicEntIdx++) {
     memset (&CurPmicInfo, 0, sizeof (PmicIdInfo));
-    for (Idx = 0; Idx < MAX_PMIC_IDX; Idx++) {
+    for (Idx = 0; Idx < PmicMaxIdx; Idx++) {
       CurPmicInfo.DtPmicModel[Idx] =
           fdt32_to_cpu (((struct pmic_id *)PmicProp)->pmic_version[Idx]);
 
@@ -598,25 +598,14 @@
           sizeof (struct PmicIdInfo));
     } else if (BestPmicInfo->DtMatchVal ==
           CurPmicInfo.DtMatchVal) {
-      if (BestPmicInfo->DtPmicRev[0] < CurPmicInfo.DtPmicRev[0]) {
-        gBS->CopyMem (BestPmicInfo, &CurPmicInfo,
-          sizeof (struct PmicIdInfo));
-      } else if (BestPmicInfo->DtPmicRev[1] <
-          CurPmicInfo.DtPmicRev[1]) {
-        gBS->CopyMem (BestPmicInfo, &CurPmicInfo,
-          sizeof (struct PmicIdInfo));
-      } else if (BestPmicInfo->DtPmicRev[2] <
-          CurPmicInfo.DtPmicRev[2]) {
-        gBS->CopyMem (BestPmicInfo, &CurPmicInfo,
-          sizeof (struct PmicIdInfo));
-      } else if (BestPmicInfo->DtPmicRev[3] <
-          CurPmicInfo.DtPmicRev[3]) {
-        gBS->CopyMem (BestPmicInfo, &CurPmicInfo,
-          sizeof (struct PmicIdInfo));
+      for (Idx = 0; Idx < PmicMaxIdx; Idx++) {
+        if (BestPmicInfo->DtPmicRev[Idx] < CurPmicInfo.DtPmicRev[Idx]) {
+          gBS->CopyMem (BestPmicInfo, &CurPmicInfo, sizeof (struct PmicIdInfo));
+        }
       }
     }
 
-    PmicProp += sizeof (struct pmic_id);
+    PmicProp += sizeof (UINT32) * PmicMaxIdx;
   }
 }
 
@@ -793,9 +782,13 @@
   CONST CHAR8 *PlatProp = NULL;
   CONST CHAR8 *BoardProp = NULL;
   CONST CHAR8 *PmicProp = NULL;
+  CONST CHAR8 *PmicPropSz = NULL;
   INT32 LenBoardId;
   INT32 LenPlatId;
   INT32 LenPmicId;
+  INT32 LenPmicIdSz;
+  INT32 PmicMaxIdx;
+  INT32 PmicEntSz;
   INT32 MinPlatIdLen = PLAT_ID_SIZE;
   INT32 RootOffset = 0;
   VOID *Dtb = CurDtbInfo->Dtb;
@@ -871,12 +864,33 @@
   /*Get the pmic property from Dtb then compare the dtb vs Board*/
   PmicProp =
       (CONST CHAR8 *)fdt_getprop (Dtb, RootOffset, "qcom,pmic-id", &LenPmicId);
-  if ((PmicProp) && (LenPmicId > 0) && (!(LenPmicId % PMIC_ID_SIZE))) {
-    PmicEntCount = LenPmicId / PMIC_ID_SIZE;
+
+  if ((PmicProp) &&
+      (LenPmicId > 0)) {
+    PmicPropSz =
+      (CONST CHAR8 *)fdt_getprop (Dtb, RootOffset, "qcom,pmic-id-size",
+                                   &LenPmicIdSz);
+    if ((PmicPropSz) &&
+        (LenPmicIdSz > 0)) {
+      PmicMaxIdx = (fdt32_to_cpu (*((UINT32 *)PmicPropSz)));
+    } else {
+      /* By default support four pmic, qcom,pmic-id = <a, b, c, d>*/
+      PmicMaxIdx = PMIC_IDX4;
+    }
+
+    PmicEntSz = PmicMaxIdx * sizeof (UINT32);
+    if (LenPmicId % PmicEntSz) {
+        DEBUG ((EFI_D_VERBOSE,
+                 "LenPmicId(%d) is not multiple of PmicEntSz(%d)\n",
+                 LenPmicId, PmicEntSz));
+        goto cleanup;
+    }
+
+    PmicEntCount = LenPmicId / PmicEntSz;
     /* Get the best match pmic */
-    ReadBestPmicMatch (PmicProp, PmicEntCount, &BestPmicInfo);
+    ReadBestPmicMatch (PmicProp, PmicMaxIdx, PmicEntCount, &BestPmicInfo);
     CurDtbInfo->DtMatchVal |= BestPmicInfo.DtMatchVal;
-    for (Idx = 0; Idx < MAX_PMIC_IDX; Idx++) {
+    for (Idx = 0; Idx < PmicMaxIdx; Idx++) {
       CurDtbInfo->DtPmicModel[Idx] = BestPmicInfo.DtPmicModel[Idx];
       CurDtbInfo->DtPmicRev[Idx] = BestPmicInfo.DtPmicRev[Idx];
     }
@@ -885,9 +899,7 @@
       "BestPmicInfo.DtMatchVal :%x\n", CurDtbInfo->DtMatchVal,
       BestPmicInfo.DtMatchVal));
   } else {
-    DEBUG ((EFI_D_VERBOSE, "qcom,pmic-id does not exit (or) is (%d)"
-                           " not a multiple of (%d)\n",
-            LenPmicId, PMIC_ID_SIZE));
+    DEBUG ((EFI_D_VERBOSE, "qcom,pmic-id does not exit\n"));
   }
 
 cleanup:
@@ -1037,7 +1049,11 @@
   }
 
   BlockIo = HandleInfoList[0].BlkIo;
-  DtboImgSz = (BlockIo->Media->LastBlock + 1) * BlockIo->Media->BlockSize;
+  DtboImgSz = GetPartitionSize (BlockIo);
+  if (!DtboImgSz) {
+    Status = EFI_BAD_BUFFER_SIZE;
+    goto err;
+  }
   *DtboImgBuffer = AllocateZeroPool (DtboImgSz);
   if (*DtboImgBuffer == NULL) {
     DEBUG ((EFI_D_ERROR, "Override DTB: Buffer allocation failure\n"));
diff --git a/QcomModulePkg/Library/BootLib/PartitionTableUpdate.c b/QcomModulePkg/Library/BootLib/PartitionTableUpdate.c
old mode 100644
new mode 100755
index 679df07..fd5a837
--- a/QcomModulePkg/Library/BootLib/PartitionTableUpdate.c
+++ b/QcomModulePkg/Library/BootLib/PartitionTableUpdate.c
@@ -131,6 +131,9 @@
       PtnEntries[Index].lun = i;
     }
   }
+  if (NAND == CheckRootDeviceType ()) {
+    NandABUpdatePartition (PTN_ENTRIES_FROM_MISC);
+  }
   /* Back up the ptn entries */
   gBS->CopyMem (PtnEntriesBak, PtnEntries, sizeof (PtnEntries));
 }
@@ -195,6 +198,31 @@
   return FALSE;
 }
 
+UINT64 GetPartitionSize (EFI_BLOCK_IO_PROTOCOL *BlockIo)
+{
+  UINT64 PartitionSize;
+
+  if (!BlockIo) {
+    DEBUG ((EFI_D_ERROR, "Invalid parameter, pleae check BlockIo info!!!\n"));
+    return 0;
+  }
+
+  if (CHECK_ADD64 (BlockIo->Media->LastBlock, 1)) {
+    DEBUG ((EFI_D_ERROR, "Integer overflow while adding LastBlock and 1\n"));
+    return 0;
+  }
+
+  if ((MAX_UINT64 / (BlockIo->Media->LastBlock + 1)) <
+    (UINT64)BlockIo->Media->BlockSize) {
+    DEBUG ((EFI_D_ERROR,
+     "Integer overflow while multiplying LastBlock and BlockSize\n"));
+    return 0;
+  }
+
+  PartitionSize = (BlockIo->Media->LastBlock + 1) * BlockIo->Media->BlockSize;
+  return  PartitionSize;
+}
+
 VOID UpdatePartitionAttributes (UINT32 UpdateType)
 {
   UINT32 BlkSz;
@@ -237,6 +265,12 @@
       Status = GetStorageHandle (NO_LUN, BlockIoHandle, &MaxHandles);
     } else if (!AsciiStrnCmp (BootDeviceType, "UFS", AsciiStrLen ("UFS"))) {
       Status = GetStorageHandle (Lun, BlockIoHandle, &MaxHandles);
+    } else if (!AsciiStrnCmp (BootDeviceType, "NAND", AsciiStrLen ("NAND"))) {
+      if (UpdateType & PARTITION_ATTRIBUTES_MASK) {
+         NandABUpdatePartition (PTN_ENTRIES_TO_MISC);
+         gBS->CopyMem (PtnEntriesBak, PtnEntries, sizeof (PtnEntries));
+      }
+      return;
     } else {
       DEBUG ((EFI_D_ERROR, "Unsupported  boot device type\n"));
       return;
@@ -256,7 +290,10 @@
     }
 
     BlockIo = BlockIoHandle[0].BlkIo;
-    DeviceDensity = (BlockIo->Media->LastBlock + 1) * BlockIo->Media->BlockSize;
+    DeviceDensity = GetPartitionSize (BlockIo);
+    if (!DeviceDensity) {
+      return;
+    }
     BlkSz = BlockIo->Media->BlockSize;
     PartEntriesblocks = MAX_PARTITION_ENTRIES_SZ / BlkSz;
     MaxGptPartEntrySzBytes = (GPT_HDR_BLOCKS + PartEntriesblocks) * BlkSz;
@@ -988,7 +1025,10 @@
   }
 
   BlockIo = BlockIoHandle[0].BlkIo;
-  DeviceDensity = (BlockIo->Media->LastBlock + 1) * BlockIo->Media->BlockSize;
+  DeviceDensity = GetPartitionSize (BlockIo);
+  if (!DeviceDensity) {
+    return FAILURE;
+  }
   BlkSz = BlockIo->Media->BlockSize;
 
   /* Verity that passed block has valid GPT primary header
@@ -1616,7 +1656,8 @@
   }
 
   /* Validate slot suffix and partition guids */
-  if (Status == EFI_SUCCESS) {
+  if (Status == EFI_SUCCESS &&
+      NAND != CheckRootDeviceType ()) {
     GUARD_OUT (ValidateSlotGuids (BootableSlot));
   }
   MarkPtnActive (BootableSlot->Suffix);
@@ -1792,3 +1833,67 @@
 
   return TRUE;
 }
+
+EFI_STATUS NandABUpdatePartition (UINT32 UpdateType)
+{
+  Slot Slots[] = {{L"_a"}, {L"_b"}};
+  NandABAttr *NandAttr = NULL;
+  EFI_GUID Ptype = gEfiMiscPartitionGuid;
+  EFI_STATUS Status;
+  UINT32 PageSize;
+  size_t Size1 = sizeof (PtnEntries[0].PartEntry.PartitionName);
+  size_t Size2 = sizeof (NandAttr->Slots[0].SlotName);
+
+  GetPageSize (&PageSize);
+  Status = GetNandMiscPartiGuid (&Ptype);
+  if (Status != EFI_SUCCESS) {
+    return Status;
+  }
+
+  Status = ReadFromPartition (&Ptype, (VOID **)&NandAttr, PageSize);
+  if (Status != EFI_SUCCESS) {
+    DEBUG ((EFI_D_ERROR, "Error Reading from misc partition: %r\n", Status));
+    return Status;
+  }
+
+  if (!NandAttr) {
+    DEBUG ((EFI_D_ERROR, "Error in loading Data from misc partition\n"));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  for (UINTN SlotIndex = 0; SlotIndex < ARRAY_SIZE (Slots); SlotIndex++) {
+    struct PartitionEntry *BootPartition =
+                      GetBootPartitionEntry (&Slots[SlotIndex]);
+    if (BootPartition == NULL) {
+      DEBUG ((EFI_D_ERROR, "GetActiveSlot: No boot partition "
+                    "entry for slot %s\n", Slots[SlotIndex].Suffix));
+      Status = EFI_NOT_FOUND;
+      goto Exit;
+    }
+
+    if (UpdateType == PTN_ENTRIES_TO_MISC) {
+      NandAttr->Slots[SlotIndex].Attributes =
+         (CHAR8)((BootPartition->PartEntry.Attributes >>
+                                 PART_ATT_PRIORITY_BIT)&0xff);
+      StrnCpyS (NandAttr->Slots[SlotIndex].SlotName, Size2 ,
+                    (BootPartition->PartEntry.PartitionName), Size1);
+    } else if (!StrnCmp (BootPartition->PartEntry.PartitionName,
+                       NandAttr->Slots[SlotIndex].SlotName, Size2)) {
+        BootPartition->PartEntry.Attributes =
+               (((UINT64)((NandAttr->Slots[SlotIndex].Attributes)&0xff)) <<
+                                                       PART_ATT_PRIORITY_BIT);
+    }
+  }
+
+  if (UpdateType == PTN_ENTRIES_TO_MISC) {
+    WriteToPartition (&Ptype, NandAttr, sizeof (struct NandABAttr));
+  }
+
+Exit:
+  if (NandAttr) {
+    FreePool (NandAttr);
+    NandAttr = NULL;
+  }
+
+  return Status;
+}
diff --git a/QcomModulePkg/Library/BootLib/Recovery.c b/QcomModulePkg/Library/BootLib/Recovery.c
old mode 100755
new mode 100644
index 110ab67..b61acc4
--- a/QcomModulePkg/Library/BootLib/Recovery.c
+++ b/QcomModulePkg/Library/BootLib/Recovery.c
@@ -159,8 +159,9 @@
 
   BlkIo = HandleInfoList[0].BlkIo;
   MsgSize = ROUND_TO_PAGE (Size, BlkIo->Media->BlockSize - 1);
-  PartitionSize = (BlkIo->Media->LastBlock + 1) * BlkIo->Media->BlockSize;
-  if (MsgSize > PartitionSize) {
+  PartitionSize = GetPartitionSize (BlkIo);
+  if (MsgSize > PartitionSize ||
+    !PartitionSize) {
     return EFI_OUT_OF_RESOURCES;
   }
 
@@ -235,7 +236,7 @@
   return MergeStatus;
 }
 
-STATIC EFI_STATUS
+EFI_STATUS
 ReadFromPartition (EFI_GUID *Ptype, VOID **Msg, UINT32 Size)
 {
   return (ReadFromPartitionOffset (Ptype, Msg, Size, 0));
diff --git a/QcomModulePkg/Library/BootLib/UpdateCmdLine.c b/QcomModulePkg/Library/BootLib/UpdateCmdLine.c
index fa2b0a7..4ad3870 100644
--- a/QcomModulePkg/Library/BootLib/UpdateCmdLine.c
+++ b/QcomModulePkg/Library/BootLib/UpdateCmdLine.c
@@ -57,6 +57,7 @@
 STATIC CONST CHAR8 *BatteryChgPause = " androidboot.mode=charger";
 STATIC CONST CHAR8 *MdtpActiveFlag = " mdtp";
 STATIC CONST CHAR8 *AlarmBootCmdLine = " androidboot.alarmboot=true";
+STATIC CHAR8 SystemdSlotEnv[] = " systemd.setenv=\"SLOT_SUFFIX=_a\"";
 
 /*Send slot suffix in cmdline with which we have booted*/
 STATIC CHAR8 *AndroidSlotSuffix = " androidboot.slot_suffix=";
@@ -314,7 +315,8 @@
   }
 
   /* Append slot info for A/B Variant */
-  if (Info->MultiSlotBoot) {
+  if (Info->MultiSlotBoot &&
+      NAND != CheckRootDeviceType ()) {
      StrnCatS (PartitionName, MAX_GPT_NAME_SIZE, CurSlot.Suffix,
             StrLen (CurSlot.Suffix));
   }
@@ -345,10 +347,17 @@
       // The gluebi device that is to be passed to "root=" will be the first one
       // after all "regular" mtd devices have been populated.
       UINT32 PartitionCount = 0;
+      UINT32 MtdBlkIndex = 0;
       GetPartitionCount (&PartitionCount);
+      if (Info->MultiSlotBoot &&
+         (StrnCmp ((CONST CHAR16 *)L"_b", CurSlot.Suffix,
+          StrLen (CurSlot.Suffix)) == 0))
+         MtdBlkIndex = PartitionCount;
+      else
+         MtdBlkIndex = PartitionCount - 1;
       AsciiSPrint (*SysPath, MAX_PATH_SIZE,
                    " rootfstype=squashfs root=/dev/mtdblock%d ubi.mtd=%d",
-                   (PartitionCount - 1), (Index - 1));
+                   MtdBlkIndex, (Index - 1));
     } else {
       AsciiSPrint (*SysPath, MAX_PATH_SIZE,
           " rootfstype=ubifs rootflags=bulk_read root=ubi0:rootfs ubi.mtd=%d",
@@ -468,13 +477,20 @@
   if (Param->MultiSlotBoot &&
      !IsBootDevImage ()) {
      /* Slot suffix */
-    Src = Param->AndroidSlotSuffix;
-    AsciiStrCatS (Dst, MaxCmdLineLen, Src);
-
     UnicodeStrToAsciiStr (GetCurrentSlotSuffix ().Suffix,
                           Param->SlotSuffixAscii);
-    Src = Param->SlotSuffixAscii;
-    AsciiStrCatS (Dst, MaxCmdLineLen, Src);
+    if (IsSystemdBootslotEnabled ()) {
+      INT32 StrLen = 0;
+      StrLen = AsciiStrLen (SystemdSlotEnv);
+      SystemdSlotEnv[StrLen - 2] = Param->SlotSuffixAscii[1];
+      Src = Param->SystemdSlotEnv;
+      AsciiStrCatS (Dst, MaxCmdLineLen, Src);
+    } else {
+      Src = Param->AndroidSlotSuffix;
+      AsciiStrCatS (Dst, MaxCmdLineLen, Src);
+      Src = Param->SlotSuffixAscii;
+      AsciiStrCatS (Dst, MaxCmdLineLen, Src);
+    }
   }
 
   if ((IsBuildAsSystemRootImage () &&
@@ -656,8 +672,12 @@
   MultiSlotBoot = PartitionHasMultiSlot ((CONST CHAR16 *)L"boot");
   if (MultiSlotBoot &&
      !IsBootDevImage ()) {
+    if (IsSystemdBootslotEnabled ()) {
+      CmdLineLen += AsciiStrLen (SystemdSlotEnv);
+    } else {
     /* Add additional length for slot suffix */
-    CmdLineLen += AsciiStrLen (AndroidSlotSuffix) + MAX_SLOT_SUFFIX_SZ;
+      CmdLineLen += AsciiStrLen (AndroidSlotSuffix) + MAX_SLOT_SUFFIX_SZ;
+    }
   }
 
   if ((IsBuildAsSystemRootImage () &&
@@ -743,6 +763,7 @@
   Param.DtbIdxStr = DtbIdxStr;
   Param.LEVerityCmdLine = LEVerityCmdLine;
   Param.HeaderVersion = HeaderVersion;
+  Param.SystemdSlotEnv = SystemdSlotEnv;
 
   Status = UpdateCmdLineParams (&Param, FinalCmdLine);
   if (Status != EFI_SUCCESS) {
diff --git a/QcomModulePkg/Library/BootLib/UpdateDeviceTree.c b/QcomModulePkg/Library/BootLib/UpdateDeviceTree.c
index 11b63fc..cdbd73f 100644
--- a/QcomModulePkg/Library/BootLib/UpdateDeviceTree.c
+++ b/QcomModulePkg/Library/BootLib/UpdateDeviceTree.c
@@ -39,6 +39,7 @@
 #include <Protocol/EFIChipInfoTypes.h>
 #include <Protocol/EFIDDRGetConfig.h>
 #include <Protocol/EFIRng.h>
+#include <Protocol/EFIDisplayPwr.h>
 #include <Library/PartialGoods.h>
 #include <Library/FdtRw.h>
 
@@ -144,6 +145,31 @@
   return Status;
 }
 
+STATIC VOID
+DisableDisplay (VOID)
+{
+  EFI_STATUS                     Status           = EFI_SUCCESS;
+  EFI_DISPLAY_POWER_PROTOCOL    *pDispPwrProtocol = NULL;
+
+  Status = gBS->LocateProtocol (&gEfiDisplayPowerStateProtocolGuid,
+                                NULL,
+                                (VOID **)&pDispPwrProtocol);
+
+  if ((EFI_SUCCESS != Status) ||
+      (NULL        == pDispPwrProtocol)) {
+    DEBUG ((EFI_D_ERROR,
+           "ERROR: Unable to get display power protocol,Status=%d\n", Status));
+  }
+  else {
+    Status = pDispPwrProtocol->SetDisplayPowerState (pDispPwrProtocol,
+                                                     EfiDisplayPowerStateOff);
+    if (EFI_SUCCESS != Status) {
+      DEBUG ((EFI_D_ERROR,
+             "ERROR: Fail to turn display off,Status=%d\n", Status));
+    }
+  }
+}
+
 STATIC EFI_STATUS
 UpdateSplashMemInfo (VOID *fdt)
 {
@@ -169,9 +195,19 @@
   /* Get offset of the splash memory reservation node */
   ret = FdtPathOffset (fdt, "/reserved-memory/splash_region");
   if (ret < 0) {
-    DEBUG ((EFI_D_ERROR, "ERROR: Could not get splash memory region node\n"));
+    DEBUG ((EFI_D_WARN, "Splash region not found in device tree, " \
+                        "powering down the display and controller\n"));
+
+    /*
+     * This function call leads to the following:
+     * 1) Turn off display power
+     * 2) Disable display clocks
+     * 3) Reset display TE/RST pin
+     */
+    DisableDisplay ();
     return EFI_NOT_FOUND;
   }
+
   offset = ret;
   DEBUG ((EFI_D_VERBOSE, "FB mem node name: %a\n",
           fdt_get_name (fdt, offset, NULL)));
diff --git a/QcomModulePkg/Library/FastbootLib/FastbootCmds.c b/QcomModulePkg/Library/FastbootLib/FastbootCmds.c
index 2f0426d..169c55f 100644
--- a/QcomModulePkg/Library/FastbootLib/FastbootCmds.c
+++ b/QcomModulePkg/Library/FastbootLib/FastbootCmds.c
@@ -866,9 +866,10 @@
     return EFI_VOLUME_CORRUPTED;
   }
   // Check image will fit on device
-  SparseImgData.PartitionSize =
-                              (SparseImgData.BlockIo->Media->LastBlock + 1)
-                               * SparseImgData.BlockIo->Media->BlockSize;
+  SparseImgData.PartitionSize = GetPartitionSize (SparseImgData.BlockIo);
+  if (!SparseImgData.PartitionSize) {
+    return EFI_BAD_BUFFER_SIZE;
+  }
 
   if (sz < sizeof (sparse_header_t)) {
     DEBUG ((EFI_D_ERROR, "Input image is invalid\n"));
@@ -1063,21 +1064,10 @@
     return EFI_VOLUME_CORRUPTED;
   }
 
-  if (CHECK_ADD64 (BlockIo->Media->LastBlock, 1)) {
-    DEBUG ((EFI_D_ERROR, "Integer overflow while adding LastBlock and 1\n"));
-    return EFI_INVALID_PARAMETER;
-  }
-
-  if ((MAX_UINT64 / (BlockIo->Media->LastBlock + 1)) <
-      (UINT64)BlockIo->Media->BlockSize) {
-    DEBUG ((EFI_D_ERROR,
-            "Integer overflow while multiplying LastBlock and BlockSize\n"));
-    return EFI_BAD_BUFFER_SIZE;
-  }
-
   /* Check image will fit on device */
-  PartitionSize = (BlockIo->Media->LastBlock + 1) * BlockIo->Media->BlockSize;
-  if (PartitionSize < Size) {
+  PartitionSize = GetPartitionSize (BlockIo);
+  if (PartitionSize < Size ||
+      !PartitionSize) {
     DEBUG ((EFI_D_ERROR, "Partition not big enough.\n"));
     DEBUG ((EFI_D_ERROR, "Partition Size:\t%d\nImage Size:\t%d\n",
             PartitionSize, Size));
@@ -1137,10 +1127,9 @@
   }
 
   /* Check if Image fits into partition */
-  PartitionSize =
-        ((BlockIo->Media->LastBlock + 1) * (UINT64)BlockIo->Media->BlockSize);
-
-  if (Size > PartitionSize) {
+  PartitionSize = GetPartitionSize (BlockIo);
+  if (Size > PartitionSize ||
+    !PartitionSize) {
     DEBUG ((EFI_D_ERROR, "Input Size is invalid\n"));
     return EFI_INVALID_PARAMETER;
   }
@@ -1851,8 +1840,11 @@
       goto out;
     }
 
-    PartitionSize = (BlockIo->Media->LastBlock + 1)
-                        * (BlockIo->Media->BlockSize);
+    PartitionSize = GetPartitionSize (BlockIo);
+    if (!PartitionSize) {
+      FastbootFail ("Partition error size");
+      goto out;
+    }
 
     if ((PartitionSize > MaxDownLoadSize) &&
          !IsDisableParallelDownloadFlash ()) {
@@ -3480,11 +3472,12 @@
 }
 
 STATIC EFI_STATUS
-GetPartitionSize (IN CHAR16 *PartName, OUT CHAR8 * PartSize)
+GetPartitionSizeViaName (IN CHAR16 *PartName, OUT CHAR8 * PartSize)
 {
   EFI_BLOCK_IO_PROTOCOL *BlockIo = NULL;
   EFI_HANDLE *Handle = NULL;
   EFI_STATUS Status = EFI_INVALID_PARAMETER;
+  UINT64 PartitionSize;
 
   Status = PartitionGetInfo (PartName, &BlockIo, &Handle);
   if (Status != EFI_SUCCESS) {
@@ -3496,9 +3489,12 @@
     return EFI_VOLUME_CORRUPTED;
   }
 
-  AsciiSPrint (PartSize, MAX_RSP_SIZE, " 0x%llx",
-               (UINT64) (BlockIo->Media->LastBlock + 1) *
-                   BlockIo->Media->BlockSize);
+  PartitionSize = GetPartitionSize (BlockIo);
+  if (!PartitionSize) {
+    return EFI_BAD_BUFFER_SIZE;
+  }
+
+  AsciiSPrint (PartSize, MAX_RSP_SIZE, " 0x%llx", PartitionSize);
   return EFI_SUCCESS;
 
 }
@@ -3542,7 +3538,7 @@
                             AsciiStrLen (
                               PublishedPartInfo[PtnLoopCount].part_name));
     if (!EFI_ERROR (Status)) {
-      Status = GetPartitionSize (
+      Status = GetPartitionSizeViaName (
                             PartitionNameUniCode,
                             PublishedPartInfo[PtnLoopCount].size_response);
       if (Status == EFI_SUCCESS) {
diff --git a/QcomModulePkg/Library/FastbootLib/FastbootMain.c b/QcomModulePkg/Library/FastbootLib/FastbootMain.c
index ae01672..e06cf3b 100755
--- a/QcomModulePkg/Library/FastbootLib/FastbootMain.c
+++ b/QcomModulePkg/Library/FastbootLib/FastbootMain.c
@@ -60,7 +60,7 @@
 #include "FastbootMain.h"
 #include "UsbDescriptors.h"
 
-#define USB_BUFF_SIZE 1024 * 1024 * 1
+#define USB_BUFF_SIZE USB_BUFFER_SIZE
 
 /* Global fastboot data */
 static FastbootDeviceData Fbd;
diff --git a/QcomModulePkg/Library/avb/libavb/avb_ops.c b/QcomModulePkg/Library/avb/libavb/avb_ops.c
index 2feb5dc..fd5c828 100644
--- a/QcomModulePkg/Library/avb/libavb/avb_ops.c
+++ b/QcomModulePkg/Library/avb/libavb/avb_ops.c
@@ -149,7 +149,11 @@
         }
 
 	BlockIo = InfoList[0].BlkIo;
-	PartitionSize = (BlockIo->Media->LastBlock + 1) * BlockIo->Media->BlockSize;
+    PartitionSize = GetPartitionSize (BlockIo);
+    if (!PartitionSize) {
+      Result = AVB_IO_RESULT_ERROR_RANGE_OUTSIDE_PARTITION;
+      goto out;
+    }
 
 	if (ReadOffset < 0) {
 		if ((-ReadOffset) > PartitionSize) {
@@ -589,7 +593,10 @@
 	}
 
 	BlockIo = HandleInfoList[0].BlkIo;
-	*OutSizeNumBytes = (BlockIo->Media->LastBlock + 1) * BlockIo->Media->BlockSize;
+    *OutSizeNumBytes = GetPartitionSize (BlockIo);
+    if (*OutSizeNumBytes == 0) {
+      return AVB_IO_RESULT_ERROR_RANGE_OUTSIDE_PARTITION;
+    }
 
 	return AVB_IO_RESULT_OK;
 }
diff --git a/QcomModulePkg/Library/avb/libavb/avb_slot_verify.c b/QcomModulePkg/Library/avb/libavb/avb_slot_verify.c
index 1a7dbdb..7967f00 100644
--- a/QcomModulePkg/Library/avb/libavb/avb_slot_verify.c
+++ b/QcomModulePkg/Library/avb/libavb/avb_slot_verify.c
@@ -1178,14 +1178,6 @@
   bool is_device_unlocked;
   AvbIOResult io_ret;
 
-  /* Add androidboot.vbmeta.device option. */
-  if (!cmdline_append_option(slot_data,
-                             "androidboot.vbmeta.device",
-                             "PARTUUID=$(ANDROID_VBMETA_PARTUUID)")) {
-    ret = AVB_SLOT_VERIFY_RESULT_ERROR_OOM;
-    goto out;
-  }
-
   /* Add androidboot.vbmeta.device option... except if not using a vbmeta
    * partition since it doesn't make sense in that case.
    */
diff --git a/QcomModulePkg/QcomModulePkg.dec b/QcomModulePkg/QcomModulePkg.dec
index 51d6490..b216645 100644
--- a/QcomModulePkg/QcomModulePkg.dec
+++ b/QcomModulePkg/QcomModulePkg.dec
@@ -142,6 +142,8 @@
   gEfiDDRGetInfoProtocolGuid =         { 0x1a7c0eb8, 0x5646, 0x45f7, { 0xab, 0x20, 0xea, 0xe5, 0xda, 0x46, 0x40, 0xa2 } }
   # Display Utils Protocol
   gQcomDisplayUtilsProtocolGuid =      { 0xc0dd69ac, 0x76ba, 0x11e6, { 0xab, 0x24, 0x1f, 0xc7, 0xf5, 0x57, 0x5f, 0x19 } }
+  # Display Power Protocol
+  gEfiDisplayPowerStateProtocolGuid =  { 0xf352021d, 0x9593, 0x4432, { 0xbf, 0x04, 0x67, 0xb9, 0xf3, 0xb7, 0x60, 0x08 } }
   # Multithreading Kernel protocol for UEFI
   gEfiKernelProtocolGuid =             { 0xB5062BE7, 0x170B, 0x4A32, { 0xBE, 0x21, 0x68, 0x92, 0x62, 0xFF, 0x43, 0x99 } }
 
diff --git a/QcomModulePkg/QcomModulePkg.dsc b/QcomModulePkg/QcomModulePkg.dsc
index 1509eee..b1560bd 100644
--- a/QcomModulePkg/QcomModulePkg.dsc
+++ b/QcomModulePkg/QcomModulePkg.dsc
@@ -143,6 +143,9 @@
   !if $(NAND_SQUASHFS_SUPPORT)
       GCC:*_*_*_CC_FLAGS = -DNAND_SQUASHFS_SUPPORT
   !endif
+  !if $(ENABLE_SYSTEMD_BOOTSLOT)
+      GCC:*_*_*_CC_FLAGS = -DENABLE_SYSTEMD_BOOTSLOT
+  !endif
 
 [PcdsFixedAtBuild.common]
 
diff --git a/makefile b/makefile
index 368b2b9..2ec3d7b 100644
--- a/makefile
+++ b/makefile
@@ -150,6 +150,7 @@
 	-D UBSAN_UEFI_GCC_FLAG_UNDEFINED=$(UBSAN_GCC_FLAG_UNDEFINED) \
 	-D UBSAN_UEFI_GCC_FLAG_ALIGNMENT=$(UBSAN_GCC_FLAG_ALIGNMENT) \
 	-D NAND_SQUASHFS_SUPPORT=$(NAND_SQUASHFS_SUPPORT) \
+	-D ENABLE_SYSTEMD_BOOTSLOT=$(ENABLE_SYSTEMD_BOOTSLOT) \
 	-j build_modulepkg.log $*
 
 	cp $(BUILD_ROOT)/FV/FVMAIN_COMPACT.Fv $(ABL_FV_IMG)