diff options
author | Ameya Thakur <ameyat@codeaurora.org> | 2016-05-03 17:57:23 -0700 |
---|---|---|
committer | Ameya Thakur <ameyat@codeaurora.org> | 2016-05-03 18:39:37 -0700 |
commit | cc1b52c5837f783af4b0fa5e4cc91c61f80ce59c (patch) | |
tree | cdb017eb35306e66448b23f09d6b887611aebf5c | |
parent | 369d68330bab4ee7ed80f94722e481adb1dd218a (diff) |
bootcontrol: Update a check in set_active_boot_slot
set_active_boot_slot used to call into get_current_slot and assumed it
would get the currently active slot.
get_current_slot has been updated to return the slot number from which
we currently booted instead of it's earlier implementation which was to
return the active slot.
We now have a new function to return the current active slot which
set_active_boot_slot calls.
Change-Id: I191bb7c7f49ff75b972efb4a65e9bc9872c6e3d8
-rw-r--r-- | boot_control.c | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/boot_control.c b/boot_control.c index 6fa066d..d5e2e4b 100644 --- a/boot_control.c +++ b/boot_control.c @@ -294,6 +294,38 @@ error: return 0; } +static unsigned get_current_active_slot(struct boot_control_module *module) +{ + uint32_t num_slots = 0; + char bootPartition[MAX_GPT_NAME_SIZE + 1]; + unsigned i = 0; + if (!module) { + ALOGE("%s: Invalid argument", __func__); + goto error; + } + num_slots = get_number_slots(module); + if (num_slots <= 1) { + //Slot 0 is the only slot around. + return 0; + } + //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; + } +error: + //The HAL spec requires that we return a number between + //0 to num_slots - 1. Since something went wrong here we + //are just going to return the default slot. + return 0; +} + int mark_boot_successful(struct boot_control_module *module) { unsigned cur_slot = 0; @@ -358,7 +390,7 @@ int set_active_boot_slot(struct boot_control_module *module, unsigned slot) __func__); goto error; } - current_slot = get_current_slot(module); + current_slot = get_current_active_slot(module); if (current_slot == slot) { //Nothing to do here. Just return return 0; |