Add boot slot support

Change-Id: I7eaf80e327985f53791f90fbdebad022a9650d31
This commit is contained in:
Ethan Yonker
2016-12-13 14:04:48 -06:00
parent 941a899695
commit 1b190166eb
10 changed files with 212 additions and 22 deletions
+63 -1
View File
@@ -64,12 +64,26 @@ extern "C" {
#include "gui/pages.hpp"
#endif
#ifdef AB_OTA_UPDATER
#include <hardware/hardware.h>
#include <hardware/boot_control.h>
#endif
extern bool datamedia;
TWPartitionManager::TWPartitionManager(void) {
mtp_was_enabled = false;
mtp_write_fd = -1;
stop_backup.set_value(0);
#ifdef AB_OTA_UPDATER
char slot_suffix[PROPERTY_VALUE_MAX];
property_get("ro.boot.slot_suffix", slot_suffix, "_a");
Active_Slot_Display = "";
if (strcmp(slot_suffix, "_a") == 0)
Set_Active_Slot("A");
else
Set_Active_Slot("B");
#endif
}
int TWPartitionManager::Process_Fstab(string Fstab_Filename, bool Display_Error) {
@@ -182,6 +196,9 @@ int TWPartitionManager::Process_Fstab(string Fstab_Filename, bool Display_Error)
#endif
Update_System_Details();
UnMount_Main_Partitions();
#ifdef AB_OTA_UPDATER
DataManager::SetValue("tw_active_slot", Get_Active_Slot_Display());
#endif
return true;
}
@@ -290,6 +307,8 @@ void TWPartitionManager::Output_Partition(TWPartition* Part) {
printf("Can_Flash_Img ");
if (Part->Is_Adopted_Storage)
printf("Is_Adopted_Storage ");
if (Part->SlotSelect)
printf("SlotSelect ");
printf("\n");
if (!Part->SubPartition_Of.empty())
printf(" SubPartition_Of: %s\n", Part->SubPartition_Of.c_str());
@@ -1376,8 +1395,8 @@ void TWPartitionManager::Update_System_Details(void) {
gui_msg("update_part_details=Updating partition details...");
for (iter = Partitions.begin(); iter != Partitions.end(); iter++) {
(*iter)->Update_Size(true);
if ((*iter)->Can_Be_Mounted) {
(*iter)->Update_Size(true);
if ((*iter)->Mount_Point == "/system") {
int backup_display_size = (int)((*iter)->Backup_Size / 1048576LLU);
DataManager::SetValue(TW_BACKUP_SYSTEM_SIZE, backup_display_size);
@@ -2473,3 +2492,46 @@ void TWPartitionManager::Remove_Partition_By_Path(string Path) {
}
}
}
void TWPartitionManager::Set_Active_Slot(const string& Slot) {
if (Slot != "A" && Slot != "B") {
LOGERR("Set_Active_Slot invalid slot '%s'\n", Slot.c_str());
return;
}
if (Active_Slot_Display == Slot)
return;
LOGINFO("Setting active slot %s\n", Slot.c_str());
#ifdef AB_OTA_UPDATER
if (!Active_Slot_Display.empty()) {
const hw_module_t *hw_module;
boot_control_module_t *module;
int ret;
ret = hw_get_module("bootctrl", &hw_module);
if (ret != 0) {
LOGERR("Error getting bootctrl module.\n");
} else {
module = (boot_control_module_t*) hw_module;
module->init(module);
int slot_number = 0;
if (Slot == "B")
slot_number = 1;
if (module->setActiveBootSlot(module, slot_number))
gui_msg(Msg(msg::kError, "unable_set_boot_slot=Error changing bootloader boot slot to {1}")(Slot));
}
DataManager::SetValue("tw_active_slot", Slot); // Doing this outside of this if block may result in a seg fault because the DataManager may not be ready yet
}
#else
LOGERR("Boot slot feature not present\n");
#endif
Active_Slot_Display = Slot;
if (Fstab_Processed())
Update_System_Details();
}
string TWPartitionManager::Get_Active_Slot_Suffix() {
if (Active_Slot_Display == "A")
return "_a";
return "_b";
}
string TWPartitionManager::Get_Active_Slot_Display() {
return Active_Slot_Display;
}