Skip to content

Commit

Permalink
src/update_handler: adapt MBR/GPT boot partition switch terminology
Browse files Browse the repository at this point in the history
In dbd8f2d ('docs/advanced: clarify how boot-mbr-switch works') and
27c0bdf ('docs/advanced: update boot-gpt-switch explanation to
"first/second half" wording') the documentation for MBR/GPT boot partition
switching was clarified and made more precise.

However, the log output for these functions was not adapted and is thus
misleading/wrong.

This is fixed here to reflect that we do not switch between different
partitions but switch the location of the boot partition between the
first and the second half of a defined region.

Also, adapt the variable name 'inactive_part' to 'inactive_half' for
this.

Signed-off-by: Enrico Jorns <[email protected]>
  • Loading branch information
ejoerns committed Aug 20, 2021
1 parent 38787da commit a376ff6
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/update_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -1410,7 +1410,7 @@ static gboolean img_to_fs_handler(RaucImage *image, RaucSlot *dest_slot, const g
static gboolean img_to_boot_mbr_switch_handler(RaucImage *image, RaucSlot *dest_slot, const gchar *hook_name, GError **error)
{
gboolean res = FALSE;
int out_fd = -1, inactive_part;
int out_fd = -1, inactive_half;
g_autoptr(GUnixOutputStream) outstream = NULL;
GError *ierror = NULL;
struct boot_switch_partition dest_partition;
Expand All @@ -1425,12 +1425,12 @@ static gboolean img_to_boot_mbr_switch_handler(RaucImage *image, RaucSlot *dest_
}

if (dest_partition.start == dest_slot->region_start)
inactive_part = 0;
inactive_half = 0;
else
inactive_part = 1;
inactive_half = 1;

g_message("Found inactive boot partition %d (pos. %"G_GUINT64_FORMAT "B, size %"G_GUINT64_FORMAT "B)",
inactive_part, dest_partition.start, dest_partition.size);
g_message("Found inactive (%s) half of boot partition region (pos. %"G_GUINT64_FORMAT "B, size %"G_GUINT64_FORMAT "B)",
inactive_half == 0 ? "first" : "second", dest_partition.start, dest_partition.size);

if (dest_partition.size < (guint64)image->checksum.size) {
g_set_error(error, R_UPDATE_ERROR, R_UPDATE_ERROR_FAILED,
Expand All @@ -1441,7 +1441,7 @@ static gboolean img_to_boot_mbr_switch_handler(RaucImage *image, RaucSlot *dest_
}

g_hash_table_insert(vars, g_strdup("RAUC_BOOT_PARTITION_ACTIVATING"),
g_strdup_printf("%d", inactive_part));
g_strdup_printf("%d", inactive_half));
g_hash_table_insert(vars, g_strdup("RAUC_BOOT_PARTITION_START"),
g_strdup_printf("%"G_GUINT64_FORMAT, dest_partition.start));
g_hash_table_insert(vars, g_strdup("RAUC_BOOT_PARTITION_SIZE"),
Expand All @@ -1457,17 +1457,17 @@ static gboolean img_to_boot_mbr_switch_handler(RaucImage *image, RaucSlot *dest_
}
}

g_message("Clearing inactive boot partition %d on %s", inactive_part,
g_message("Clearing inactive (%s) half of boot partition region on %s", inactive_half == 0 ? "first" : "second",
dest_slot->device);

res = clear_boot_switch_partition(dest_slot->device, &dest_partition, &ierror);
if (!res) {
g_propagate_prefixed_error(error, ierror,
"Failed to clear inactive partition: ");
"Failed to clear inactive region: ");
goto out;
}

g_message("Opening inactive boot partition %d on %s", inactive_part,
g_message("Opening inactive (%s) half of boot partition region on %s", inactive_half == 0 ? "first" : "second",
dest_slot->device);

out_fd = open(dest_slot->device, O_WRONLY);
Expand Down Expand Up @@ -1496,8 +1496,8 @@ static gboolean img_to_boot_mbr_switch_handler(RaucImage *image, RaucSlot *dest_
goto out;
}

g_message("Copying image to inactive boot partition %d on %s",
inactive_part, dest_slot->device);
g_message("Copying image to inactive (%s) half of boot partition region on %s",
inactive_half == 0 ? "first" : "second", dest_slot->device);

res = copy_raw_image(image, outstream, &ierror);
if (!res) {
Expand All @@ -1515,7 +1515,7 @@ static gboolean img_to_boot_mbr_switch_handler(RaucImage *image, RaucSlot *dest_
}
}

g_message("Setting MBR to switch boot partition");
g_message("Setting %s half of boot partition region active in MBR", inactive_half == 0 ? "first" : "second");

res = r_mbr_switch_set_boot_partition(dest_slot->device, &dest_partition, &ierror);
if (!res) {
Expand All @@ -1534,7 +1534,7 @@ G_GNUC_UNUSED
static gboolean img_to_boot_gpt_switch_handler(RaucImage *image, RaucSlot *dest_slot, const gchar *hook_name, GError **error)
{
gboolean res = FALSE;
int out_fd = -1, inactive_part;
int out_fd = -1, inactive_half;
g_autoptr(GUnixOutputStream) outstream = NULL;
GError *ierror = NULL;
struct boot_switch_partition dest_partition;
Expand All @@ -1549,12 +1549,12 @@ static gboolean img_to_boot_gpt_switch_handler(RaucImage *image, RaucSlot *dest_
}

if (dest_partition.start == dest_slot->region_start)
inactive_part = 0;
inactive_half = 0;
else
inactive_part = 1;
inactive_half = 1;

g_message("Found inactive boot partition %d (pos. %"G_GUINT64_FORMAT "B, size %"G_GUINT64_FORMAT "B)",
inactive_part, dest_partition.start, dest_partition.size);
g_message("Found inactive (%s) half of boot partition region (pos. %"G_GUINT64_FORMAT "B, size %"G_GUINT64_FORMAT "B)",
inactive_half == 0 ? "first" : "second", dest_partition.start, dest_partition.size);

if (dest_partition.size < (guint64)image->checksum.size) {
g_set_error(error, R_UPDATE_ERROR, R_UPDATE_ERROR_FAILED,
Expand All @@ -1565,7 +1565,7 @@ static gboolean img_to_boot_gpt_switch_handler(RaucImage *image, RaucSlot *dest_
}

g_hash_table_insert(vars, g_strdup("RAUC_BOOT_PARTITION_ACTIVATING"),
g_strdup_printf("%d", inactive_part));
g_strdup_printf("%d", inactive_half));
g_hash_table_insert(vars, g_strdup("RAUC_BOOT_PARTITION_START"),
g_strdup_printf("%"G_GUINT64_FORMAT, dest_partition.start));
g_hash_table_insert(vars, g_strdup("RAUC_BOOT_PARTITION_SIZE"),
Expand All @@ -1581,7 +1581,7 @@ static gboolean img_to_boot_gpt_switch_handler(RaucImage *image, RaucSlot *dest_
}
}

g_message("Clearing inactive boot partition %d on %s", inactive_part,
g_message("Clearing inactive (%s) half of boot partition region on %s", inactive_half == 0 ? "first" : "second",
dest_slot->device);

res = clear_boot_switch_partition(dest_slot->device, &dest_partition, &ierror);
Expand All @@ -1591,7 +1591,7 @@ static gboolean img_to_boot_gpt_switch_handler(RaucImage *image, RaucSlot *dest_
goto out;
}

g_message("Opening inactive boot partition %d on %s", inactive_part,
g_message("Opening inactive (%s) half of boot partition region on %s", inactive_half == 0 ? "first" : "second",
dest_slot->device);

out_fd = open(dest_slot->device, O_WRONLY);
Expand Down Expand Up @@ -1620,8 +1620,8 @@ static gboolean img_to_boot_gpt_switch_handler(RaucImage *image, RaucSlot *dest_
goto out;
}

g_message("Copying image to inactive boot partition %d on %s",
inactive_part, dest_slot->device);
g_message("Copying image to inactive (%s) half of boot partition region on %s",
inactive_half == 0 ? "first" : "second", dest_slot->device);

res = copy_raw_image(image, outstream, &ierror);
if (!res) {
Expand All @@ -1639,7 +1639,7 @@ static gboolean img_to_boot_gpt_switch_handler(RaucImage *image, RaucSlot *dest_
}
}

g_message("Setting GPT to switch boot partition");
g_message("Setting %s half of boot partition region active in GPT", inactive_half == 0 ? "first" : "second");

res = r_gpt_switch_set_boot_partition(dest_slot->device, &dest_partition, &ierror);
if (!res) {
Expand Down

0 comments on commit a376ff6

Please sign in to comment.