bootloader: fold all Android Bootloader specific logic into prepare-root
authorEric Curtin <ecurtin@redhat.com>
Thu, 20 Jul 2023 10:32:30 +0000 (11:32 +0100)
committerEric Curtin <ecurtin@redhat.com>
Thu, 20 Jul 2023 11:31:01 +0000 (12:31 +0100)
Now that we use androidboot.slot_suffix karg to determine whether we
boot into /ostree/root.a or /ostree/root.b, we can use ostree= karg
simply for parsing the stateroot, although we will still boot into
what's pointed to by /ostree/root.a or /ostree/root.b.

src/switchroot/ostree-mount-util.h
src/switchroot/ostree-prepare-root-static.c
src/switchroot/ostree-prepare-root.c
src/switchroot/ostree-system-generator.c

index b79ccfd7d4e49f53b098e27b2ea1e6e1eba060ee..10e63f98c4089e993d53733351a4a0e68106f30f 100644 (file)
@@ -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.
  */
index 06181c570e62de12e98b24d236419ae529e59ff0..cd36070df0684c668e8ab5f3594d473df6e42ccd 100644 (file)
@@ -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);
index d0b58cc509d9a242e29aeb33cdcd8807b4c8857f..0f84ed1c3b15d18e886d9f366d0ce55503a5d120 100644 (file)
@@ -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)
 {
@@ -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");
index ecae432a1e7f9a77e2adf9b22614ff6f3d1423e7..d10919043f4c5cb17396bd2d377f399995fb35e3 100644 (file)
@@ -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.
@@ -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);
   }