Skip to content

Commit

Permalink
Add support for Virtual A/B
Browse files Browse the repository at this point in the history
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: I454972cc2be673054c50e5de6de5b3abafbdf2fd
Signed-off-by: Rahul Shahare <[email protected]>
  • Loading branch information
Rahul Shahare authored and Gerrit - the friendly Code Review server committed Apr 17, 2021
1 parent db25b52 commit e7baede
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 8 deletions.
10 changes: 8 additions & 2 deletions AndroidBoot.mk
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,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_DTBO_NOT_SUPPORTED),true)
TARGET_DTBO_NOT_SUPPORTED := TARGET_DTBO_NOT_SUPPORTED=1
else
Expand Down Expand Up @@ -141,7 +147,7 @@ $(ABOOT_CLEAN):
# ELF binary for ABOOT
TARGET_ABOOT_ELF := $(PRODUCT_OUT)/aboot.elf
$(TARGET_ABOOT_ELF): $(ABOOT_CLEAN) | $(ABOOT_OUT)
$(MAKE) -C $(LK_PATH) TOOLCHAIN_PREFIX=$(CROSS_COMPILE) BOOTLOADER_OUT=$(CROOT_DIR)/$(ABOOT_OUT) $(BOOTLOADER_PLATFORM) $(EMMC_BOOT) $(SIGNED_KERNEL) $(VERIFIED_BOOT) $(VERIFIED_BOOT_2) $(VB1_KEY_USED) $(TARGET_DTBO_NOT_SUPPORTED) $(ENABLE_DISPLAY) $(ENABLE_KASLRSEED) $(ENABLE_BOOTDEVICE_MOUNT) $(DEVICE_STATUS) $(BUILD_VARIANT) $(BOARD_NAME) $(ENABLE_VB_ATTEST) $(OSVERSION_IN_BOOTIMAGE) $(QSEECOM_SECAPP_REGION_2MB) $(TARGET_USE_SYSTEM_AS_ROOT_IMAGE) $(DYNAMIC_PARTITION_SUPPORT)
$(MAKE) -C $(LK_PATH) TOOLCHAIN_PREFIX=$(CROSS_COMPILE) BOOTLOADER_OUT=$(CROOT_DIR)/$(ABOOT_OUT) $(BOOTLOADER_PLATFORM) $(EMMC_BOOT) $(SIGNED_KERNEL) $(VERIFIED_BOOT) $(VERIFIED_BOOT_2) $(VB1_KEY_USED) $(TARGET_DTBO_NOT_SUPPORTED) $(ENABLE_DISPLAY) $(ENABLE_KASLRSEED) $(ENABLE_BOOTDEVICE_MOUNT) $(DEVICE_STATUS) $(BUILD_VARIANT) $(BOARD_NAME) $(ENABLE_VB_ATTEST) $(OSVERSION_IN_BOOTIMAGE) $(QSEECOM_SECAPP_REGION_2MB) $(TARGET_USE_SYSTEM_AS_ROOT_IMAGE) $(DYNAMIC_PARTITION_SUPPORT) $(VIRTUAL_AB_OTA)

# NAND variant output
TARGET_NAND_BOOTLOADER := $(PRODUCT_OUT)/appsboot.mbn
Expand Down Expand Up @@ -175,7 +181,7 @@ $(TARGET_NAND_BOOTLOADER): $(appsbootldr_clean) | $(NAND_BOOTLOADER_OUT)

# Top level for eMMC variant targets
$(TARGET_EMMC_BOOTLOADER): $(emmc_appsbootldr_clean) | $(EMMC_BOOTLOADER_OUT) $(INSTALLED_KEYSTOREIMAGE_TARGET)
$(MAKE) -C $(LK_PATH) TOOLCHAIN_PREFIX=$(CROSS_COMPILE) BOOTLOADER_OUT=$(CROOT_DIR)/$(EMMC_BOOTLOADER_OUT) $(BOOTLOADER_PLATFORM) EMMC_BOOT=1 $(SIGNED_KERNEL) $(VERIFIED_BOOT) $(VERIFIED_BOOT_2) $(VB1_KEY_USED) $(TARGET_DTBO_NOT_SUPPORTED) $(ENABLE_DISPLAY) $(ENABLE_KASLRSEED) $(ENABLE_BOOTDEVICE_MOUNT) $(DEVICE_STATUS) $(BUILD_VARIANT) $(BOARD_NAME) $(ENABLE_VB_ATTEST) $(OSVERSION_IN_BOOTIMAGE) $(ENABLE_BG_SUPPORT) $(QSEECOM_SECAPP_REGION_2MB) $(TARGET_USE_SYSTEM_AS_ROOT_IMAGE) $(DYNAMIC_PARTITION_SUPPORT)
$(MAKE) -C $(LK_PATH) TOOLCHAIN_PREFIX=$(CROSS_COMPILE) BOOTLOADER_OUT=$(CROOT_DIR)/$(EMMC_BOOTLOADER_OUT) $(BOOTLOADER_PLATFORM) EMMC_BOOT=1 $(SIGNED_KERNEL) $(VERIFIED_BOOT) $(VERIFIED_BOOT_2) $(VB1_KEY_USED) $(TARGET_DTBO_NOT_SUPPORTED) $(ENABLE_DISPLAY) $(ENABLE_KASLRSEED) $(ENABLE_BOOTDEVICE_MOUNT) $(DEVICE_STATUS) $(BUILD_VARIANT) $(BOARD_NAME) $(ENABLE_VB_ATTEST) $(OSVERSION_IN_BOOTIMAGE) $(ENABLE_BG_SUPPORT) $(QSEECOM_SECAPP_REGION_2MB) $(TARGET_USE_SYSTEM_AS_ROOT_IMAGE) $(DYNAMIC_PARTITION_SUPPORT) $(VIRTUAL_AB_OTA)
$(hide) rm -f $(emmc_appsbootldr_clean)

# Keep build NAND & eMMC as default for targets still using TARGET_BOOTLOADER
Expand Down
32 changes: 31 additions & 1 deletion app/aboot/aboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) 2009, Google Inc.
* All rights reserved.
*
* Copyright (c) 2009-2020, The Linux Foundation. All rights reserved.
* Copyright (c) 2009-2021, 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:
Expand Down Expand Up @@ -285,6 +285,13 @@ static const char *critical_flash_allowed_ptn[] = {
"devinfo",
"partition"};

static const char *VabSnapshotMergeStatus[] = {
"none",
"unknown",
"snapshotted",
"merging",
"cancelled"};

struct atag_ptbl_entry
{
char name[16];
Expand Down Expand Up @@ -340,6 +347,7 @@ char display_panel_buf[MAX_PANEL_BUF_SIZE];
char panel_display_mode[MAX_RSP_SIZE];
char soc_version_str[MAX_RSP_SIZE];
char block_size_string[MAX_RSP_SIZE];
static char SnapshotMergeState[MAX_RSP_SIZE];
#if PRODUCT_IOT

/* For IOT we are using custom version */
Expand Down Expand Up @@ -5013,6 +5021,7 @@ void aboot_fastboot_register_commands(void)
{
int i;
char hw_platform_buf[MAX_RSP_SIZE];
VirtualAbMergeStatus SnapshotMergeStatus;

struct fastboot_cmd_desc cmd_list[] = {
/* By default the enabled list is empty. */
Expand Down Expand Up @@ -5133,6 +5142,27 @@ void aboot_fastboot_register_commands(void)
#endif
if (target_dynamic_partition_supported())
fastboot_publish("is-userspace", "no");

if (target_virtual_ab_supported()) {
SnapshotMergeStatus = GetSnapshotMergeStatus ();

switch (SnapshotMergeStatus) {
case SNAPSHOTTED:
SnapshotMergeStatus = SNAPSHOTTED;
break;
case MERGING:
SnapshotMergeStatus = MERGING;
break;
default:
SnapshotMergeStatus = NONE_MERGE_STATUS;
break;
}

snprintf(SnapshotMergeState,
strlen(VabSnapshotMergeStatus[SnapshotMergeStatus]) + 1,
"%s", VabSnapshotMergeStatus[SnapshotMergeStatus]);
fastboot_publish("snapshot-update-state", SnapshotMergeState);
}
}

void aboot_init(const struct app_descriptor *app)
Expand Down
40 changes: 39 additions & 1 deletion app/aboot/recovery.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2010-2017,2019 The Linux Foundation. All rights reserved.
/* Copyright (c) 2010-2017,2019,2021 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
Expand Down Expand Up @@ -617,6 +617,44 @@ int write_misc(unsigned page_offset, void *buf, unsigned size)
return 0;
}

static MiscVirtualABMessage *VirtualAbMsg = NULL;

VirtualAbMergeStatus GetSnapshotMergeStatus (void)
{
VirtualAbMergeStatus MergeStatus = NONE_MERGE_STATUS;
uint32_t pagesize = get_page_size();

if (target_is_emmc_boot())
{
if (VirtualAbMsg == NULL) {
if(read_misc(MISC_VIRTUALAB_OFFSET, (void *)&VirtualAbMsg,
pagesize))
{
dprintf(CRITICAL,"Error reading virtualab msg from misc partition\n");
return MergeStatus;
}

if (VirtualAbMsg->Magic != MISC_VIRTUAL_AB_MAGIC_HEADER ||
VirtualAbMsg->Version != MISC_VIRTUAL_AB_MESSAGE_VERSION) {

dprintf(CRITICAL,"Error read virtualab msg version:%u magic:%u not valid\n",
VirtualAbMsg->Version,VirtualAbMsg->Magic);

free(VirtualAbMsg);
VirtualAbMsg = NULL;
}
else
{
dprintf(CRITICAL,"read virtualab MergeStatus:%x\n", VirtualAbMsg->MergeStatus);
}
}

if (VirtualAbMsg)
MergeStatus = VirtualAbMsg->MergeStatus;
}
return MergeStatus;
}

int get_ffbm(char *ffbm, unsigned size)
{
const char *ffbm_cmd = "ffbm-";
Expand Down
32 changes: 30 additions & 2 deletions app/aboot/recovery.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2010-2017,2019 The Linux Foundation. All rights reserved.
/* Copyright (c) 2010-2017,2019,2021 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
Expand Down Expand Up @@ -56,6 +56,34 @@ struct recovery_message {
char 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)

typedef enum VirtualAbMergeStatus{
NONE_MERGE_STATUS,
UNKNOWN_MERGE_STATUS,
SNAPSHOTTED,
MERGING,
CANCELLED
} VirtualAbMergeStatus;

typedef struct {
uint8_t Version;
uint32_t Magic;
uint8_t MergeStatus; // IBootControl 1.1, MergeStatus enum.
uint8_t SourceStatus; // Slot number when merge_status was written.
uint8_t Reserved[57];
} __attribute__ ((packed)) MiscVirtualABMessage;

struct update_header {
unsigned char MAGIC[UPDATE_MAGIC_SIZE];
Expand Down Expand Up @@ -91,7 +119,7 @@ int recovery_init (void);
* invalid.
*/
int get_ffbm(char *ffbm, unsigned size);

VirtualAbMergeStatus GetSnapshotMergeStatus(void);
extern unsigned boot_into_recovery;

#endif
3 changes: 2 additions & 1 deletion include/target.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Copyright (c) 2013-2017,2019 The Linux Foundation. All rights reserved.
* Copyright (c) 2013-2017,2019,2021 The Linux Foundation. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
Expand Down Expand Up @@ -105,6 +105,7 @@ void pmic_reset_configure(uint8_t reset_type);
bool is_display_disabled(void);
bool target_uses_system_as_root(void);
bool target_dynamic_partition_supported(void);
bool target_virtual_ab_supported(void);
struct qmp_reg *target_get_qmp_settings();
int target_get_qmp_regsize();
uint32_t target_ddr_cfg_reg();
Expand Down
14 changes: 13 additions & 1 deletion target/init.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Copyright (c) 2015-2020, The Linux Foundation. All rights reserved.
* Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
Expand Down Expand Up @@ -298,6 +298,18 @@ bool target_dynamic_partition_supported(void)
#endif
}

#if VIRTUAL_AB_OTA
bool target_virtual_ab_supported(void)
{
return true;
}
#else
bool target_virtual_ab_supported(void)
{
return false;
}
#endif

/* Default CFG register value */
uint32_t target_ddr_cfg_reg()
{
Expand Down

0 comments on commit e7baede

Please sign in to comment.