Skip to content

Commit

Permalink
Merge pull request #2942 from ostreedev/android-bootloader-parsing
Browse files Browse the repository at this point in the history
bootloader: fold all Android Bootloader specific logic into prepare-root
  • Loading branch information
ericcurtin committed Jul 20, 2023
2 parents a035c2e + c89baae commit 4c0e5b1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
23 changes: 0 additions & 23 deletions src/switchroot/ostree-mount-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,29 +119,6 @@ read_proc_cmdline_key (const char *key)
return ret;
}

static inline char *
get_aboot_root_slot (const char *slot_suffix)
{
if (strcmp (slot_suffix, "_a") == 0)
return strdup ("/ostree/root.a");
else if (strcmp (slot_suffix, "_b") == 0)
return strdup ("/ostree/root.b");

errx (EXIT_FAILURE, "androidboot.slot_suffix invalid: %s", slot_suffix);

return NULL;
}

static inline char *
get_ostree_target (void)
{
autofree char *slot_suffix = read_proc_cmdline_key ("androidboot.slot_suffix");
if (slot_suffix)
return get_aboot_root_slot (slot_suffix);

return read_proc_cmdline_key ("ostree");
}

/* This is an API for other projects to determine whether or not the
* currently running system is ostree-controlled.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/switchroot/ostree-prepare-root-static.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ resolve_deploy_path (const char *root_mountpoint)
char destpath[PATH_MAX];
struct stat stbuf;
char *deploy_path;
autofree char *ostree_target = get_ostree_target ();
autofree char *ostree_cmdline = read_proc_cmdline_key ("ostree");

if (snprintf (destpath, sizeof (destpath), "%s/%s", root_mountpoint, ostree_target) < 0)
if (snprintf (destpath, sizeof (destpath), "%s/%s", root_mountpoint, ostree_cmdline) < 0)
err (EXIT_FAILURE, "failed to assemble ostree target path");
if (lstat (destpath, &stbuf) < 0)
err (EXIT_FAILURE, "Couldn't find specified OSTree root '%s'", destpath);
Expand Down
25 changes: 24 additions & 1 deletion src/switchroot/ostree-prepare-root.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,29 @@ sysroot_is_configured_ro (const char *sysroot)
return g_key_file_get_boolean (repo_config, "sysroot", "readonly", NULL);
}

static inline char *
get_aboot_root_slot (const char *slot_suffix)
{
if (strcmp (slot_suffix, "_a") == 0)
return strdup ("/ostree/root.a");
else if (strcmp (slot_suffix, "_b") == 0)
return strdup ("/ostree/root.b");

errx (EXIT_FAILURE, "androidboot.slot_suffix invalid: %s", slot_suffix);

return NULL;
}

static inline char *
get_ostree_target (void)
{
autofree char *slot_suffix = read_proc_cmdline_key ("androidboot.slot_suffix");
if (slot_suffix)
return get_aboot_root_slot (slot_suffix);

return read_proc_cmdline_key ("ostree");
}

static char *
resolve_deploy_path (const char *root_mountpoint)
{
Expand All @@ -114,7 +137,7 @@ resolve_deploy_path (const char *root_mountpoint)
char *deploy_path;
autofree char *ostree_target = get_ostree_target ();
if (!ostree_target)
errx (EXIT_FAILURE, "No ostree= cmdline");
errx (EXIT_FAILURE, "No ostree target");

if (snprintf (destpath, sizeof (destpath), "%s/%s", root_mountpoint, ostree_target) < 0)
err (EXIT_FAILURE, "failed to assemble ostree target path");
Expand Down
6 changes: 3 additions & 3 deletions src/switchroot/ostree-system-generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ main (int argc, char *argv[])
* exit so that we don't error, but at the same time work where switchroot
* is PID 1 (and so hasn't created /run/ostree-booted).
*/
autofree char *ostree_target = get_ostree_target ();
if (!ostree_target)
autofree char *ostree_cmdline = read_proc_cmdline_key ("ostree");
if (!ostree_cmdline)
exit (EXIT_SUCCESS);

/* See comments in ostree-prepare-root.c for this.
Expand All @@ -77,7 +77,7 @@ main (int argc, char *argv[])

{
g_autoptr (GError) local_error = NULL;
if (!ostree_cmd__private__ ()->ostree_system_generator (ostree_target, arg_dest, NULL,
if (!ostree_cmd__private__ ()->ostree_system_generator (ostree_cmdline, arg_dest, NULL,
arg_dest_late, &local_error))
errx (EXIT_FAILURE, "%s", local_error->message);
}
Expand Down

0 comments on commit 4c0e5b1

Please sign in to comment.