From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fb.mail.gandi.net (spool8.mail.gandi.net [217.70.178.217]) by nmboxes206.sd4.0x35.net (Postfix) with ESMTPS id 6DDB760BB1 for ; Tue, 25 Jul 2023 10:09:31 +0000 (UTC) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by fb.mail.gandi.net (Postfix) with ESMTPS id C6E8D60855 for ; Tue, 25 Jul 2023 10:09:30 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=cipwm+ioVNCCyWqtm+6pKYKNXB0FQGQGs7XHcIpj64k=; c=relaxed/simple; d=groups.io; h=X-Received:X-Received:X-Received:X-Received:X-Received:X-Gm-Message-State:X-Google-Smtp-Source:X-Received:MIME-Version:References:In-Reply-To:From:Date:X-Gmail-Original-Message-ID:Message-ID:Subject:To:Cc:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type:Content-Transfer-Encoding; s=20140610; t=1690279769; v=1; b=OiJrrg96gH86znt7wy7xbytOtFGNfkHRwSlp+UreFg9g5ZnSoVy56fESy2StjVJyvTTGDNtj DhHHYHWTbagxJbkVSqQi/M3KVsVjukEcJgGKSGhbVB5c3ku84zy9vtU2A2HVQfri56J6vvUcmx4 Q3gNNJtcQqjGghOt6zua/3D4= X-Received: by 127.0.0.2 with SMTP id ildPYY7687511xHhto2xUJai; Tue, 25 Jul 2023 03:09:29 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web10.16858.1690279588555482526 for ; Tue, 25 Jul 2023 03:06:28 -0700 X-Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D3EA8615ED for ; Tue, 25 Jul 2023 10:06:27 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43D44C433C7 for ; Tue, 25 Jul 2023 10:06:27 +0000 (UTC) X-Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2b9540031acso75195121fa.3 for ; Tue, 25 Jul 2023 03:06:27 -0700 (PDT) X-Gm-Message-State: CuiieMaBnYIS5fdhuKhLij3Hx7686176AA= X-Google-Smtp-Source: APBJJlFSxhvRJlxdi33RtAx8BTo6H7CyXJVj4a1EsyG6yQrA684Tl65my9WOxVbdHpLid0IDyXQppSPFZ1Hn7z4zPRg= X-Received: by 2002:a2e:9e96:0:b0:2b7:3f6b:a6e1 with SMTP id f22-20020a2e9e96000000b002b73f6ba6e1mr7035869ljk.41.1690279585173; Tue, 25 Jul 2023 03:06:25 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: "Ard Biesheuvel" Date: Tue, 25 Jul 2023 12:06:13 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [edk2-devel] Detecting Linux boot failure from UEFI shell (BootServices) To: Pedro Falcato Cc: devel@edk2.groups.io, yashren.reddi@gmail.com Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ardb@kernel.org List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: fb.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=OiJrrg96; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=pass (fb.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io On Mon, 24 Jul 2023 at 19:28, Pedro Falcato wrote= : > > On Mon, Jul 24, 2023 at 6:07=E2=80=AFPM wrote: > > > > I am developing a UEFI application which functions as a bootloader. It = is required to handle loading between two Linux kernels dependending on whi= ch one failed last (A/B system). > > Is there a way to detect if the kernel failed to load/start successfull= y 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 i= nformation 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 i= s called? I'm trying to figure out what actual Linux boot failures I can de= tect with the ExitBootService return code. > > 1) ExitBootServices !=3D 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. -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- 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] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-