From 650a053795d53d3f5e3054a03b3341e828f58b2c Mon Sep 17 00:00:00 2001 From: Eric Curtin Date: Tue, 22 Aug 2023 13:04:03 +0100 Subject: [PATCH] prepare-root: On a non-A/B androidboot system, boot system slot a 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 | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/switchroot/ostree-prepare-root.c b/src/switchroot/ostree-prepare-root.c index 93167272..155189b9 100644 --- a/src/switchroot/ostree-prepare-root.c +++ b/src/switchroot/ostree-prepare-root.c @@ -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"); } -- 2.30.2