FastbootMenu: add ability to set active slot

Change-Id: Iac972efac622bc4ed94645161ae2120ac5003533
Signed-off-by: Alexander Martinz <amartinz@shiftphones.com>
diff --git a/QcomModulePkg/Include/Library/DrawUI.h b/QcomModulePkg/Include/Library/DrawUI.h
index 26d2610..e98229a 100644
--- a/QcomModulePkg/Include/Library/DrawUI.h
+++ b/QcomModulePkg/Include/Library/DrawUI.h
@@ -115,6 +115,8 @@
   FFBM,
   QMMI,
   NOACTION,
+  SET_ACTIVE_SLOT_A,
+  SET_ACTIVE_SLOT_B,
   OPTION_ACTION_MAX,
 } OPTION_ITEM_ACTION;
 
diff --git a/QcomModulePkg/Library/BootLib/FastbootMenu.c b/QcomModulePkg/Library/BootLib/FastbootMenu.c
index 05d5482..3164428 100644
--- a/QcomModulePkg/Library/BootLib/FastbootMenu.c
+++ b/QcomModulePkg/Library/BootLib/FastbootMenu.c
@@ -87,6 +87,20 @@
      0,
      QMMI},
 #endif
+    {{"Activate slot _a"},
+     BIG_FACTOR,
+     BGR_ORANGE,
+     BGR_BLACK,
+     OPTION_ITEM,
+     0,
+     SET_ACTIVE_SLOT_A},
+    {{"Activate slot _b"},
+     BIG_FACTOR,
+     BGR_ORANGE,
+     BGR_BLACK,
+     OPTION_ITEM,
+     0,
+     SET_ACTIVE_SLOT_B},
 };
 
 #define FASTBOOT_MSG_INDEX_HEADER                  0
diff --git a/QcomModulePkg/Library/BootLib/MenuKeysDetection.c b/QcomModulePkg/Library/BootLib/MenuKeysDetection.c
index ecc9d21..6726106 100755
--- a/QcomModulePkg/Library/BootLib/MenuKeysDetection.c
+++ b/QcomModulePkg/Library/BootLib/MenuKeysDetection.c
@@ -105,6 +105,8 @@
   EFI_STATUS Status = EFI_SUCCESS;
   EFI_GUID Ptype = gEfiMiscPartitionGuid;
   MemCardType CardType = UNKNOWN;
+  CHAR16 SuffixUnicode[MAX_SLOT_SUFFIX_SZ] = u"";
+  Slot BootSlot;
 
   /* Clear the screen */
   gST->ConOut->ClearScreen (gST->ConOut);
@@ -158,6 +160,26 @@
     }
     RebootDevice (NORMAL_MODE);
     break;
+  case SET_ACTIVE_SLOT_A:
+    AsciiStrToUnicodeStr ("_a", SuffixUnicode);
+    StrnCpyS (BootSlot.Suffix, ARRAY_SIZE (BootSlot.Suffix), SuffixUnicode,
+            StrLen (SuffixUnicode));
+    Status = SetActiveSlot (&BootSlot, TRUE);
+    if (Status != EFI_SUCCESS) {
+      DEBUG ((EFI_D_ERROR, "Failed to set the active slot to _a\n"));
+    }
+    RebootDevice (FASTBOOT_MODE);
+    break;
+  case SET_ACTIVE_SLOT_B:
+    AsciiStrToUnicodeStr ("_b", SuffixUnicode);
+    StrnCpyS (BootSlot.Suffix, ARRAY_SIZE (BootSlot.Suffix), SuffixUnicode,
+            StrLen (SuffixUnicode));
+    Status = SetActiveSlot (&BootSlot, TRUE);
+    if (Status != EFI_SUCCESS) {
+      DEBUG ((EFI_D_ERROR, "Failed to set the active slot to _b\n"));
+    }
+    RebootDevice (FASTBOOT_MODE);
+    break;
   }
 }