From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.789.1592329759294244057 for ; Tue, 16 Jun 2020 10:49:19 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: ard.biesheuvel@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BFB841F1; Tue, 16 Jun 2020 10:49:17 -0700 (PDT) Received: from localhost.localdomain (unknown [10.37.8.36]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 54DE83F73C; Tue, 16 Jun 2020 10:49:16 -0700 (PDT) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: leif@nuviainc.com, Ard Biesheuvel , Pete Batard , Andrei Warkentin , Samer El-Haj-Mahmoud Subject: [PATCH] ArmPkg/PlatformBootManagerLib: regenerate boot options on boot failure Date: Tue, 16 Jun 2020 19:48:34 +0200 Message-Id: <20200616174834.1110310-1-ard.biesheuvel@arm.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable One of the side effects of the recent changes to PlatformBootManagerLib changes to avoid connecting all devices on every boot is that we no longer default to network boot on a virgin boot, but end up in the UiApp menu. At this point, the autogenerated boot options that we used to rely on will be instantiated too, but it does break the unattended boot case where devices are expected to attempt a network boot on the very first power on. Let's work around this by refreshing all boot options explicitly in the UnableToBoot() handler, and rebooting the system if doing so resulted in a change to the total number of configured boot options. This way, we ultimately end up in the UiApp as before if no boot options could be started, but only after all the autogenerated ones have been attempted as well. =0D Cc: Pete Batard =0D Cc: Andrei Warkentin (awarkentin@vmware.com) =0D Cc: Samer El-Haj-Mahmoud =0D Signed-off-by: Ard Biesheuvel --- ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c | 34 ++++++++++++++++++= ++ 1 file changed, 34 insertions(+) diff --git a/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c b/ArmPkg/Li= brary/PlatformBootManagerLib/PlatformBm.c index 15c5cac1bea0..9905cad22908 100644 --- a/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c +++ b/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c @@ -820,6 +820,40 @@ PlatformBootManagerUnableToBoot ( {=0D EFI_STATUS Status;=0D EFI_BOOT_MANAGER_LOAD_OPTION BootManagerMenu;=0D + EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;=0D + UINTN OldBootOptionCount;=0D + UINTN NewBootOptionCount;=0D +=0D + //=0D + // Record the total number of boot configured boot options=0D + //=0D + BootOptions =3D EfiBootManagerGetLoadOptions (&OldBootOptionCount,=0D + LoadOptionTypeBoot);=0D + EfiBootManagerFreeLoadOptions (BootOptions, OldBootOptionCount);=0D +=0D + //=0D + // Connect all devices, and regenerate all boot options=0D + //=0D + EfiBootManagerConnectAll ();=0D + EfiBootManagerRefreshAllBootOption ();=0D +=0D + //=0D + // Record the updated number of boot configured boot options=0D + //=0D + BootOptions =3D EfiBootManagerGetLoadOptions (&NewBootOptionCount,=0D + LoadOptionTypeBoot);=0D + EfiBootManagerFreeLoadOptions (BootOptions, NewBootOptionCount);=0D +=0D + //=0D + // If the number of configured boot options has changed, reboot=0D + // the system so the new boot options will be taken into account=0D + // while executing the ordinary BDS bootflow sequence.=0D + //=0D + if (NewBootOptionCount !=3D OldBootOptionCount) {=0D + DEBUG ((DEBUG_WARN, "%a: rebooting after refreshing all boot options\n= ",=0D + __FUNCTION__));=0D + gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);=0D + }=0D =0D Status =3D EfiBootManagerGetBootManagerMenu (&BootManagerMenu);=0D if (EFI_ERROR (Status)) {=0D --=20 2.27.0