prepare-root: On a non-A/B androidboot system, boot system slot a
authorEric Curtin <ecurtin@redhat.com>
Tue, 22 Aug 2023 12:04:03 +0000 (13:04 +0100)
committerEric Curtin <ecurtin@redhat.com>
Tue, 22 Aug 2023 15:43:20 +0000 (16:43 +0100)
Sometimes android bootloaders boot in a nonab way:

  https://source.android.com/docs/core/ota/nonab

In this case, "androidboot." kargs are present but not
"androidboot.slot_suffix" specifically.

In this case, rather than getting stuck in a partially booted
environment, boot system slot a.

src/switchroot/ostree-prepare-root.c

index 931672726fa34cac84170e3cc4e87f094c4375d2..155189b9c5c37efaf6a23a5da4a6769bc4a17032 100644 (file)
@@ -163,6 +163,24 @@ get_aboot_root_slot (const char *slot_suffix)
   return NULL;
 }
 
+static bool
+proc_cmdline_has_key_starting_with (const char *cmdline, const char *key)
+{
+  for (const char *iter = cmdline; iter;)
+    {
+      if (g_str_has_prefix (iter, key))
+        return true;
+
+      iter = strchr (iter, ' ');
+      if (iter == NULL)
+        return false;
+
+      iter += strspn (iter, " ");
+    }
+
+  return false;
+}
+
 static inline char *
 get_ostree_target (const char *cmdline)
 {
@@ -170,6 +188,12 @@ get_ostree_target (const char *cmdline)
   if (slot_suffix)
     return get_aboot_root_slot (slot_suffix);
 
+  /* Non-A/B androidboot:
+   * https://source.android.com/docs/core/ota/nonab
+   */
+  if (proc_cmdline_has_key_starting_with (cmdline, "androidboot."))
+    return strdup ("/ostree/root.a");
+
   return find_proc_cmdline_key (cmdline, "ostree");
 }