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

bootloader: fold all Android Bootloader specific logic into prepare-root #2942

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect though that we may end up needing to care about aboot here too. But if you don't think so, then this is definitely better.

What I was looking at was pushing all the cmdline parsing deep into the generator code instead of this binary so it can more cleanly use the internals, but it is a bigger change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup we have to be mindful of it (it works in the code as of today, but I understand there are big changes coming so we revisiting this will occur at times), stateroot being somewhat frozen in the cmdline is ok (you can theoretically change it, you just got to deliver a new Android Boot Image bundle in your update).... But with the other fields that's less ok. But I'm happy to change things as this code evolves and changes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I also agree we should try and do this kind of thing in future:

+typedef enum {
+    OTCORE_BOOT_TYPE_OSTREE,
+    OTCORE_BOOT_TYPE_ANDROID,
+} OtCoreBootType;
+
+typedef struct {
+  OtCoreBootType type;
+  char *ostree_link;
+  char android_boot_slot;  // If type == ANDROID, this will be either 'a' or 'b'
+} OtCoreBootEntry;

If the differences start to get larger than 10 lines of code. At the moment, since it's just a single if statement that's called once in the lifetime of a process, it's not worth it.... yet... at least

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