diff options
author | Ameya Thakur <ameyat@codeaurora.org> | 2016-05-02 16:21:13 -0700 |
---|---|---|
committer | Ameya Thakur <ameyat@codeaurora.org> | 2016-05-03 13:37:13 -0700 |
commit | 369d68330bab4ee7ed80f94722e481adb1dd218a (patch) | |
tree | 5153297b9e047e73485ba4ccee902f1da836399c | |
parent | c14fff0a37a3b14e051444337980968e99ed1826 (diff) |
bootctrl: Fix implementation of get_current_slot
get_current_slot will now return the slot on which the system was
booted rather than the current active slot.
Change-Id: I2aa64400a45ae23796cd073fc92f5732cdd7391e
-rw-r--r-- | Android.mk | 2 | ||||
-rw-r--r-- | boot_control.c | 21 |
2 files changed, 14 insertions, 9 deletions
@@ -3,7 +3,7 @@ include $(CLEAR_VARS) LOCAL_C_INCLUDES += hardware/libhardware/include LOCAL_C_INCLUDES += $(TARGET_OUT_HEADERS)/gpt-utils/inc LOCAL_CFLAGS += -Wall -Werror -LOCAL_SHARED_LIBRARIES += liblog librecovery_updater_msm +LOCAL_SHARED_LIBRARIES += liblog librecovery_updater_msm libcutils LOCAL_SRC_FILES := boot_control.c LOCAL_MODULE_RELATIVE_PATH := hw LOCAL_MODULE := bootctrl.$(TARGET_BOARD_PLATFORM) diff --git a/boot_control.c b/boot_control.c index 58edf5e..6fa066d 100644 --- a/boot_control.c +++ b/boot_control.c @@ -38,11 +38,13 @@ #include <sys/stat.h> #include <fcntl.h> #include <limits.h> +#include <cutils/properties.h> #include "gpt-utils.h" #define BOOTDEV_DIR "/dev/block/bootdevice/by-name" #define BOOT_IMG_PTN_NAME "boot" #define LUN_NAME_END_LOC 14 +#define BOOT_SLOT_PROP "ro.boot.slot_suffix" const char *slot_suffix_arr[] = { AB_SLOT_A_SUFFIX, @@ -260,7 +262,7 @@ error: unsigned get_current_slot(struct boot_control_module *module) { uint32_t num_slots = 0; - char bootPartition[MAX_GPT_NAME_SIZE + 1]; + char bootSlotProp[PROPERTY_VALUE_MAX] = {'\0'}; unsigned i = 0; if (!module) { ALOGE("%s: Invalid argument", __func__); @@ -271,16 +273,19 @@ unsigned get_current_slot(struct boot_control_module *module) //Slot 0 is the only slot around. return 0; } + property_get(BOOT_SLOT_PROP, bootSlotProp, "N/A"); + if (!strncmp(bootSlotProp, "N/A", strlen("N/A"))) { + ALOGE("%s: Unable to read boot slot property", + __func__); + goto error; + } //Iterate through a list of partitons named as boot+suffix //and see which one is currently active. for (i = 0; slot_suffix_arr[i] != NULL ; i++) { - memset(bootPartition, '\0', sizeof(bootPartition)); - snprintf(bootPartition, sizeof(bootPartition) - 1, - "boot%s", - slot_suffix_arr[i]); - if (get_partition_attribute(bootPartition, - ATTR_SLOT_ACTIVE) == 1) - return i; + if (!strncmp(bootSlotProp, + slot_suffix_arr[i], + strlen(slot_suffix_arr[i]))) + return i; } error: //The HAL spec requires that we return a number between |