On Mon, 24 Jul 2023 at 19:28, Pedro Falcato <pedro.falc...@gmail.com> wrote:
>
> On Mon, Jul 24, 2023 at 6:07 PM <yashren.re...@gmail.com> wrote:
> >
> > I am developing a UEFI application which functions as a bootloader. It is 
> > required to handle loading between two Linux kernels dependending on which 
> > one failed last (A/B system).
> > Is there a way to detect if the kernel failed to load/start successfully 
> > from the UEFI shell or application?
>
> Sure, you can try and hope that it failed early enough to call
> EFI_BOOT_SERVICES.Exit(). But the amount of failure points after
> ExitBootServices() is staggeringly huge compared to before
> ExitBootServices (i.e in the efistub, when booting).
>
> >I read that there is a hand-over of control to the OS at some point and the 
> >OS calls ExitBootService but I am not sure about how to retrieve this 
> >information from the Shell? Does the return code get persisted in LastError 
> >variable?
> Seems like it, yes.
>
> > Also, do you know where in the Linux boot process the ExitBootService is 
> > called? I'm trying to figure out what actual Linux boot failures I can 
> > detect with the ExitBootService return code.
>
> 1) ExitBootServices != Exit. EFI_BOOT_SERVICES.Exit() serves as your
> exit "system call", EFI_BOOT_SERVICES.ExitBootServices() serves as the
> "remove EFI from being in my way" "system call". Please see the spec.
> 2) Probably anything that happens really early and hence is deeply
> uninteresting. But not much else AFAIK. (hopefully Ard can chime in
> here)
>
> > For instance, could I detect kernel panic?
> No.
>

ExitBootServices() shuts down the boot services, as its name suggests.
A UEFI application by definition is an application that is hosted
under the UEFI boot services, so once ExitBootServices() is called,
your app is gone.

Even if ExitBootServices() fails, it is unlikely that the UEFI
execution context is still functional, given that async event dispatch
will have been shutdown, and this affects many drivers that you may be
relying on for the console or for file storage.

The EFI stub code that runs first in the Linux kernel does very little
beyond allocating some memory and moving the kernel image and initial
ramdisk in place, and the code is almost completely arch and platform
agnostic. So it seems unlikely that any of the issues that are trying
to diagnose would occur here.

After ExitBootServices(), the OS is completetly in control of the
hardware, and along with it, any of the diagnostic facilities that the
machine might have. I don't know what LastError is, but unless it is a
non-volatile EFI variable, I don't think you will be able to rely on
it either.


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#107227): https://edk2.groups.io/g/devel/message/107227
Mute This Topic: https://groups.io/mt/100333279/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to