* [edk2-devel] Detecting Linux boot failure from UEFI shell (BootServices)
@ 2023-07-24 6:41 yashren.reddi
2023-07-24 17:28 ` Pedro Falcato
0 siblings, 1 reply; 3+ messages in thread
From: yashren.reddi @ 2023-07-24 6:41 UTC (permalink / raw)
To: devel
[-- Attachment #1: Type: text/plain, Size: 1559 bytes --]
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? I read that there is a hand-over of control to the OS at some point and the OS calls ExitBootService ( https://uefi.org/specs/UEFI/2.9_A/07_Services_Boot_Services.html#efi-boot-services-exit )
but I am not sure about how to retrieve this information from the Shell? Does the return code get persisted in LastError variable? 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. For instance, could I detect kernel panic?
Currently, I have a catch all approach, where I persist a boot failure flag before loading the OS, then when the OS is booted successfully it clears the boot failure flag (I check this on boot to switch between systems). The problem is that this also catches power failure between setting and clearing the flag which is undesirable.
Thanks
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#107183): https://edk2.groups.io/g/devel/message/107183
Mute This Topic: https://groups.io/mt/100333279/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
[-- Attachment #2: Type: text/html, Size: 2048 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [edk2-devel] Detecting Linux boot failure from UEFI shell (BootServices)
2023-07-24 6:41 [edk2-devel] Detecting Linux boot failure from UEFI shell (BootServices) yashren.reddi
@ 2023-07-24 17:28 ` Pedro Falcato
2023-07-25 10:06 ` Ard Biesheuvel
0 siblings, 1 reply; 3+ messages in thread
From: Pedro Falcato @ 2023-07-24 17:28 UTC (permalink / raw)
To: devel, yashren.reddi, Ard Biesheuvel
On Mon, Jul 24, 2023 at 6:07 PM <yashren.reddi@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.
--
Pedro
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#107185): https://edk2.groups.io/g/devel/message/107185
Mute This Topic: https://groups.io/mt/100333279/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [edk2-devel] Detecting Linux boot failure from UEFI shell (BootServices)
2023-07-24 17:28 ` Pedro Falcato
@ 2023-07-25 10:06 ` Ard Biesheuvel
0 siblings, 0 replies; 3+ messages in thread
From: Ard Biesheuvel @ 2023-07-25 10:06 UTC (permalink / raw)
To: Pedro Falcato; +Cc: devel, yashren.reddi
On Mon, 24 Jul 2023 at 19:28, Pedro Falcato <pedro.falcato@gmail.com> wrote:
>
> On Mon, Jul 24, 2023 at 6:07 PM <yashren.reddi@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/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-07-25 10:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-24 6:41 [edk2-devel] Detecting Linux boot failure from UEFI shell (BootServices) yashren.reddi
2023-07-24 17:28 ` Pedro Falcato
2023-07-25 10:06 ` Ard Biesheuvel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox