Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bootctrl: fall back to active slot if current slot not found in cmdline #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 32 additions & 32 deletions bootctrl_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,38 +331,6 @@ int get_boot_attr(struct gpt_disk *disk, unsigned slot, enum part_attr_type attr
return get_partition_attribute(disk, bootPartition, attr);
}

static unsigned int get_current_slot_from_kernel_cmdline()
{
uint32_t num_slots = 0;
char bootSlotProp[MAX_CMDLINE_SIZE] = { '\0' };
unsigned i = 0;
num_slots = get_number_slots();
if (num_slots <= 1) {
// Slot 0 is the only slot around.
return 0;
}

get_kernel_cmdline_arg(BOOT_SLOT_PROP, bootSlotProp, "_a");
if (!strncmp(bootSlotProp, "N/A\n", strlen("N/A"))) {
fprintf(stderr, "%s: Unable to read boot slot property\n", __func__);
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++) {
if (!strncmp(bootSlotProp, slot_suffix_arr[i], strlen(slot_suffix_arr[i]))) {
// printf("%s current_slot = %d\n", __func__, i);
return i;
}
}

// 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 is_slot_bootable(unsigned slot)
{
int attr = 0;
Expand Down Expand Up @@ -560,6 +528,38 @@ unsigned get_active_boot_slot()
return 0;
}

static unsigned int get_current_slot_from_kernel_cmdline()
{
uint32_t num_slots = 0;
char bootSlotProp[MAX_CMDLINE_SIZE] = { '\0' };
unsigned i = 0;
num_slots = get_number_slots();
if (num_slots <= 1) {
// Slot 0 is the only slot around.
return 0;
}

get_kernel_cmdline_arg(BOOT_SLOT_PROP, bootSlotProp, "N/A");
if (!strncmp(bootSlotProp, "N/A\n", strlen("N/A"))) {
fprintf(stderr, "%s: Unable to read boot slot property\n", __func__);
return get_active_boot_slot();
}

// 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++) {
if (!strncmp(bootSlotProp, slot_suffix_arr[i], strlen(slot_suffix_arr[i]))) {
// printf("%s current_slot = %d\n", __func__, i);
return i;
}
}

// 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 set_active_boot_slot(unsigned slot, bool ignore_missing_bsg)
{
enum boot_chain chain = (enum boot_chain)slot;
Expand Down