summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeevan Shriram <jshriram@codeaurora.org>2020-01-20 17:34:53 -0800
committerAmit Pundir <amit.pundir@linaro.org>2022-12-21 00:33:22 +0530
commitf14190ac72772c39a9d04bacbe1d58914717bf1f (patch)
tree9e1b5fbedb209717c2d12c3eec08ab7dbdd7c166
parentf16bebd3b647964d2adae008485e7c55f850cad9 (diff)
QcomModulePkg: Add support for Virtual A/B
For Virtual A/B OTA feature, change to * add intial support for feature. * parse misc partition for virtual a/b merge status. * publish snapshot merge status in fastboot variables. Change-Id: I9eff78c4f4727a500cece1f1ef5922ff366528c5
-rw-r--r--AndroidBoot.mk7
-rw-r--r--QcomModulePkg/Include/Library/BootLinux.h1
-rw-r--r--QcomModulePkg/Include/Library/Recovery.h41
-rw-r--r--QcomModulePkg/Library/BootLib/BootLinux.c12
-rw-r--r--QcomModulePkg/Library/BootLib/Recovery.c69
-rw-r--r--QcomModulePkg/Library/FastbootLib/FastbootCmds.c25
-rw-r--r--QcomModulePkg/QcomModulePkg.dsc3
-rw-r--r--makefile1
8 files changed, 154 insertions, 5 deletions
diff --git a/AndroidBoot.mk b/AndroidBoot.mk
index 0f34d1c2df..b8378a47fa 100644
--- a/AndroidBoot.mk
+++ b/AndroidBoot.mk
@@ -86,6 +86,12 @@ else
DYNAMIC_PARTITION_SUPPORT := DYNAMIC_PARTITION_SUPPORT=0
endif
+ifeq ($(PRODUCT_VIRTUAL_AB_OTA),true)
+ VIRTUAL_AB_OTA := VIRTUAL_AB_OTA=1
+else
+ VIRTUAL_AB_OTA := VIRTUAL_AB_OTA=0
+endif
+
ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
BUILD_USES_RECOVERY_AS_BOOT := BUILD_USES_RECOVERY_AS_BOOT=1
else
@@ -138,6 +144,7 @@ $(TARGET_ABL): $(LOCAL_ABL_SRC_FILE) | $(ABL_OUT) $(INSTALLED_KEYSTOREIMAGE_TARG
$(DISABLE_PARALLEL_DOWNLOAD_FLASH) \
$(AB_RETRYCOUNT_DISABLE) \
$(DYNAMIC_PARTITION_SUPPORT) \
+ $(VIRTUAL_AB_OTA) \
$(BUILD_USES_RECOVERY_AS_BOOT) \
CLANG_BIN=$(CLANG_BIN) \
CLANG_PREFIX=$(CLANG35_PREFIX)\
diff --git a/QcomModulePkg/Include/Library/BootLinux.h b/QcomModulePkg/Include/Library/BootLinux.h
index 38d0503f5a..2d887993b4 100644
--- a/QcomModulePkg/Include/Library/BootLinux.h
+++ b/QcomModulePkg/Include/Library/BootLinux.h
@@ -222,6 +222,7 @@ VOID ResetBootDevImage (VOID);
BOOLEAN IsBootDevImage (VOID);
BOOLEAN IsABRetryCountDisabled (VOID);
BOOLEAN IsDynamicPartitionSupport (VOID);
+BOOLEAN IsVirtualAbOtaSupported (VOID);
UINT64 SetandGetLoadAddr (BootParamlist *BootParamlistPtr, AddrType Type);
BOOLEAN IsNANDSquashFsSupport (VOID);
#endif
diff --git a/QcomModulePkg/Include/Library/Recovery.h b/QcomModulePkg/Include/Library/Recovery.h
index b1305b92e3..b0b9c7ff86 100644
--- a/QcomModulePkg/Include/Library/Recovery.h
+++ b/QcomModulePkg/Include/Library/Recovery.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2016,2019 The Linux Foundation. All rights reserved.
+/* Copyright (c) 2016, 2019-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
@@ -43,10 +43,49 @@ struct RecoveryMessage {
CHAR8 recovery[1024];
};
+#define MISC_VIRTUAL_AB_MESSAGE_VERSION 2
+#define MISC_VIRTUAL_AB_MAGIC_HEADER 0x56740AB0
+
+/** MISC Partition usage as per AOSP implementation.
+ * 0 - 2K For bootloader_message
+ * 2K - 16K Used by Vendor's bootloader (the 2K - 4K range may be
+ * optionally used as bootloader_message_ab struct)
+ * 16K - 32K Used by uncrypt and recovery to store wipe_package
+ * for A/B devices
+ * 32K - 64K System space, used for miscellanious AOSP features.
+ **/
+#define MISC_VIRTUALAB_OFFSET (32 * 1024)
+
+static CHAR8 *VabSnapshotMergeStatus[] = {
+ "none",
+ "unknown",
+ "snapshotted",
+ "merging",
+ "cancelled"
+};
+
+typedef enum UINT8 {
+ NONE_MERGE_STATUS,
+ UNKNOWN_MERGE_STATUS,
+ SNAPSHOTTED,
+ MERGING,
+ CANCELLED
+} VirtualAbMergeStatus;
+
+typedef struct {
+ UINT8 Version;
+ UINT32 Magic;
+ UINT8 MergeStatus; // IBootControl 1.1, MergeStatus enum.
+ UINT8 SourceStatus; // Slot number when merge_status was written.
+ UINT8 Reserved[57];
+} __attribute__ ((packed)) MiscVirtualABMessage;
+
EFI_STATUS
RecoveryInit (BOOLEAN *BootIntoRecovery);
EFI_STATUS
GetFfbmCommand (CHAR8 *FfbmMode, UINT32 Sz);
EFI_STATUS
WriteRecoveryMessage (CHAR8 *Command);
+VirtualAbMergeStatus
+GetSnapshotMergeStatus (VOID);
#endif
diff --git a/QcomModulePkg/Library/BootLib/BootLinux.c b/QcomModulePkg/Library/BootLib/BootLinux.c
index 5919b99ac6..114dcd543c 100644
--- a/QcomModulePkg/Library/BootLib/BootLinux.c
+++ b/QcomModulePkg/Library/BootLib/BootLinux.c
@@ -1854,6 +1854,18 @@ BOOLEAN IsDynamicPartitionSupport (VOID)
}
#endif
+#if VIRTUAL_AB_OTA
+BOOLEAN IsVirtualAbOtaSupported (VOID)
+{
+ return TRUE;
+}
+#else
+BOOLEAN IsVirtualAbOtaSupported (VOID)
+{
+ return FALSE;
+}
+#endif
+
#if NAND_SQUASHFS_SUPPORT
BOOLEAN IsNANDSquashFsSupport (VOID)
{
diff --git a/QcomModulePkg/Library/BootLib/Recovery.c b/QcomModulePkg/Library/BootLib/Recovery.c
index c10e479b21..6e5c1a98a5 100644
--- a/QcomModulePkg/Library/BootLib/Recovery.c
+++ b/QcomModulePkg/Library/BootLib/Recovery.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2016-2019, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2016-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
@@ -31,8 +31,11 @@
#include <Library/LinuxLoaderLib.h>
#include <Library/BootLinux.h>
+STATIC MiscVirtualABMessage *VirtualAbMsg = NULL;
+
STATIC EFI_STATUS
-ReadFromPartition (EFI_GUID *Ptype, VOID **Msg, UINT32 Size)
+ReadFromPartitionOffset (EFI_GUID *Ptype, VOID **Msg,
+ UINT32 Size, UINT32 Offset)
{
EFI_STATUS Status;
EFI_BLOCK_IO_PROTOCOL *BlkIo = NULL;
@@ -85,7 +88,15 @@ ReadFromPartition (EFI_GUID *Ptype, VOID **Msg, UINT32 Size)
return EFI_OUT_OF_RESOURCES;
}
- Status = BlkIo->ReadBlocks (BlkIo, BlkIo->Media->MediaId, 0, MsgSize, *Msg);
+ if (Offset % BlkIo->Media->BlockSize) {
+ DEBUG (
+ (EFI_D_ERROR, "Error offset:%u passed is not multiple of blocksz:%u\n",
+ Offset, BlkIo->Media->BlockSize));
+ return EFI_INVALID_PARAMETER;
+ }
+ Status = BlkIo->ReadBlocks (BlkIo, BlkIo->Media->MediaId,
+ (Offset / BlkIo->Media->BlockSize),
+ MsgSize, *Msg);
if (Status != EFI_SUCCESS) {
FreePool (*Msg);
*Msg = NULL;
@@ -95,6 +106,58 @@ ReadFromPartition (EFI_GUID *Ptype, VOID **Msg, UINT32 Size)
return Status;
}
+VirtualAbMergeStatus
+GetSnapshotMergeStatus (VOID)
+{
+ VirtualAbMergeStatus MergeStatus = NONE_MERGE_STATUS;
+ EFI_STATUS Status;
+ EFI_GUID Ptype = gEfiMiscPartitionGuid;
+ MemCardType CardType = UNKNOWN;
+ UINT32 PageSize;
+
+ if (VirtualAbMsg == NULL) {
+
+ CardType = CheckRootDeviceType ();
+ if (CardType == NAND) {
+ return MergeStatus;
+ }
+
+ GetPageSize (&PageSize);
+
+ Status = ReadFromPartitionOffset (&Ptype, (VOID **)&VirtualAbMsg, PageSize,
+ MISC_VIRTUALAB_OFFSET);
+ if (Status != EFI_SUCCESS) {
+ DEBUG ((EFI_D_ERROR,
+ "Error reading virtualab msg from misc partition: %r\n", Status));
+ return MergeStatus;
+ }
+
+ if (VirtualAbMsg->Magic != MISC_VIRTUAL_AB_MAGIC_HEADER ||
+ VirtualAbMsg->Version != MISC_VIRTUAL_AB_MESSAGE_VERSION) {
+ DEBUG ((EFI_D_ERROR,
+ "Error read virtualab msg version:%u magic:%u not valid\n",
+ VirtualAbMsg->Version, VirtualAbMsg->Magic));
+ FreePool (VirtualAbMsg);
+ VirtualAbMsg = NULL;
+ } else {
+ DEBUG ((EFI_D_VERBOSE, "read virtualab MergeStatus:%x\n",
+ VirtualAbMsg->MergeStatus));
+ }
+ }
+
+ if (VirtualAbMsg) {
+ MergeStatus = VirtualAbMsg->MergeStatus;
+ }
+
+ return MergeStatus;
+}
+
+STATIC EFI_STATUS
+ReadFromPartition (EFI_GUID *Ptype, VOID **Msg, UINT32 Size)
+{
+ return (ReadFromPartitionOffset (Ptype, Msg, Size, 0));
+}
+
EFI_STATUS
WriteRecoveryMessage (CHAR8 *Command)
{
diff --git a/QcomModulePkg/Library/FastbootLib/FastbootCmds.c b/QcomModulePkg/Library/FastbootLib/FastbootCmds.c
index 54a4609fbb..8dc6d4d956 100644
--- a/QcomModulePkg/Library/FastbootLib/FastbootCmds.c
+++ b/QcomModulePkg/Library/FastbootLib/FastbootCmds.c
@@ -18,7 +18,7 @@ found at
* Copyright (c) 2009, Google Inc.
* All rights reserved.
*
- * Copyright (c) 2015 - 2019, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2015 - 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
@@ -116,6 +116,7 @@ STATIC CHAR8 StrSocVersion[MAX_RSP_SIZE];
STATIC CHAR8 LogicalBlkSizeStr[MAX_RSP_SIZE];
STATIC CHAR8 EraseBlkSizeStr[MAX_RSP_SIZE];
STATIC CHAR8 MaxDownloadSizeStr[MAX_RSP_SIZE];
+STATIC CHAR8 SnapshotMergeState[MAX_RSP_SIZE];
struct GetVarSlotInfo {
CHAR8 SlotSuffix[MAX_SLOT_SUFFIX_SZ];
@@ -3306,6 +3307,7 @@ FastbootCommandSetup (IN VOID *Base, IN UINT64 Size)
UINT32 PartitionCount = 0;
BOOLEAN MultiSlotBoot = PartitionHasMultiSlot ((CONST CHAR16 *)L"boot");
MemCardType Type = UNKNOWN;
+ VirtualAbMergeStatus SnapshotMergeStatus;
mDataBuffer = Base;
mNumDataBytes = Size;
@@ -3380,6 +3382,27 @@ FastbootCommandSetup (IN VOID *Base, IN UINT64 Size)
FastbootPublishVar ("is-userspace", "no");
}
+ if (IsVirtualAbOtaSupported ()) {
+ SnapshotMergeStatus = GetSnapshotMergeStatus ();
+
+ switch (SnapshotMergeStatus) {
+ case SNAPSHOTTED:
+ SnapshotMergeStatus = SNAPSHOTTED;
+ break;
+ case MERGING:
+ SnapshotMergeStatus = MERGING;
+ break;
+ default:
+ SnapshotMergeStatus = NONE_MERGE_STATUS;
+ break;
+ }
+
+ AsciiSPrint (SnapshotMergeState,
+ AsciiStrLen (VabSnapshotMergeStatus[SnapshotMergeStatus]) + 1,
+ "%a", VabSnapshotMergeStatus[SnapshotMergeStatus]);
+ FastbootPublishVar ("snapshot-update-state", SnapshotMergeState);
+ }
+
AsciiSPrint (FullProduct, sizeof (FullProduct), "%a", PRODUCT_NAME);
FastbootPublishVar ("product", FullProduct);
FastbootPublishVar ("serialno", StrSerialNum);
diff --git a/QcomModulePkg/QcomModulePkg.dsc b/QcomModulePkg/QcomModulePkg.dsc
index 59757c9320..389fa88a03 100644
--- a/QcomModulePkg/QcomModulePkg.dsc
+++ b/QcomModulePkg/QcomModulePkg.dsc
@@ -128,6 +128,9 @@
!if $(DYNAMIC_PARTITION_SUPPORT)
GCC:*_*_*_CC_FLAGS = -DDYNAMIC_PARTITION_SUPPORT
!endif
+ !if $(VIRTUAL_AB_OTA)
+ GCC:*_*_*_CC_FLAGS = -DVIRTUAL_AB_OTA
+ !endif
!if $(BUILD_USES_RECOVERY_AS_BOOT)
GCC:*_*_*_CC_FLAGS = -DBUILD_USES_RECOVERY_AS_BOOT
!endif
diff --git a/makefile b/makefile
index 323787f325..f07d82a726 100644
--- a/makefile
+++ b/makefile
@@ -146,6 +146,7 @@ ABL_FV_IMG: EDK_TOOLS_BIN
-D DISABLE_PARALLEL_DOWNLOAD_FLASH=$(DISABLE_PARALLEL_DOWNLOAD_FLASH) \
-D ENABLE_LE_VARIANT=$(ENABLE_LE_VARIANT) \
-D DYNAMIC_PARTITION_SUPPORT=$(DYNAMIC_PARTITION_SUPPORT) \
+ -D VIRTUAL_AB_OTA=$(VIRTUAL_AB_OTA) \
-D BUILD_USES_RECOVERY_AS_BOOT=$(BUILD_USES_RECOVERY_AS_BOOT) \
-D INIT_BIN=$(INIT_BIN) \
-D UBSAN_UEFI_GCC_FLAG_UNDEFINED=$(UBSAN_GCC_FLAG_UNDEFINED) \