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
Conversation
@cgwalters this is incomplete but just to give you an idea of where I'm going with this. When this is complete, we will either call _ostree_bootloader_aboot_parse_bootlink or the more generic parse_bootlink function depending on how we set up this interface. |
999f177
to
2a1a042
Compare
@@ -183,6 +183,41 @@ _ostree_bootloader_aboot_post_bls_sync (OstreeBootloader *bootloader, int bootve | |||
return TRUE; | |||
} | |||
|
|||
// Parse the kernel argument ostree= | |||
static gboolean | |||
_ostree_bootloader_aboot_parse_bootlink (const char *bootlink, int *out_entry_bootversion, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmmm. Maybe.
I was thinking a bit more like this:
diff --git a/src/libostree/ostree-sysroot-private.h b/src/libostree/ostree-sysroot-private.h
index 63a29418..da17e64b 100644
--- a/src/libostree/ostree-sysroot-private.h
+++ b/src/libostree/ostree-sysroot-private.h
@@ -80,6 +80,7 @@ struct OstreeSysroot
GPtrArray *deployments;
int bootversion;
int subbootversion;
+ gboolean using_android_boot;
OstreeDeployment *booted_deployment;
OstreeDeployment *staged_deployment;
GVariant *staged_deployment_data;
And then we just do different things depending on that. It's not totally clear to me that what we need to do for aboot will practically fit into the bootloader abstraction we have right now.
I think it will be very useful to us to clean up and centralize everywhere that we're parsing the kernel cmdline. So even if using the bootloader flow was the right direction, I don't think adding another copy of the regex is right short term. Nothing would stop this code from using the existing |
The boolean is certainly simpler. What is the alternate path to parsing the directories differently in the Android Bootloader case? |
I started on this
basically:
|
Apologies, I don't 100% understand why we move the various functions into: src/switchroot/ostree-prepare-root-static.c we need them elsewhere right? If we want to avoid traversing any sort on aboot code in -static.c, we could just call "read_proc_cmdline_key ("ostree");" instead of the generic "get_ostree_target()". And call the ostree-only version of the function in the one other place it's likely required too. Like for example the "read_proc_cmdline_key (const char *key)" function which is pretty generic which we use for "ostree", "ot-composefs" and "androidboot.slot_suffix", we move this function to src/switchroot/ostree-prepare-root-static.c in the above example. But that doesn't make sense right? We use it elsewhere, even if we remove the need for an ostree= karg, we would still need it for "ot-composefs" and "androidboot.slot_suffix" (and even if we redesigned composefs to store that somewhere else in the initrd, we would still need the function for "androidboot.slot_suffix" as it's out of our control). |
2a1a042
to
e65da2f
Compare
b8c6779
to
fda9919
Compare
I did split "ostree-mount-util.h" into "ostree-mount-util-static.h" and ""ostree-mount-util.h" here though. That way -static.c includes only includes static stuff, and the other files include everything... |
fda9919
to
579a988
Compare
It's a pity this is the case "Unfortunately we can't easily use the libostree API to find the booted deployment since /boot might not have been mounted yet." ... Because if we could guarantee /boot was up, we could simply do a realpath and have the exact same parsing/regex approach for Android Bootloader and the normal approach. But I have realised since #2937 we can use the same parsing technique for both, as although the ostree= karg is not so useful for finding the sysroot to boot into. We can still use it to parse the stateroot, because the stateroot doesn't really change. |
d7c569f
to
91daac5
Compare
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.
91daac5
to
c89baae
Compare
@cgwalters I have to test this, but this solves my ostree-system-generator problem and now the Android Bootloader specific code is just in one .c file. |
So I tested this, it unblocks me (now ostree= is not aboot):
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this looks like a nice incremental improvement!
@@ -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"); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Inherently in an A/B setup we can't really handle stateroot (or at least not quite how it was designed). One option is to have a symlink This also heavily relates to #2794 which I would definitely advocate doing in general for these use cases. IOW the logic could be: if (android boot karg exists) { or so |
This sounds good to me, nice and simple |
Glancing at this osbuild has a lot of references to stateroot that would have to grow defaulting logic. |
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.