From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.81]) by mx.groups.io with SMTP id smtpd.web12.7933.1592401461418067243 for ; Wed, 17 Jun 2020 06:44:21 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YH6QAWV6; spf=pass (domain: redhat.com, ip: 207.211.31.81, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592401460; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=weMSb4Sa6Za7xSNM4M/uaieNQHR+5lOEYjGvHFhGSUA=; b=YH6QAWV6/A5KbnMzrXcV56JxG/PP/Ch1PhtMMB8GxXuzWeUsLAXXMIxHKyTfkH+/q+7qqY LQVyqfBPC9Ldh8JpJr2uRbJ+5KN7LloyLAD8P8HHT/eDvbfQ3u11DPe9tbXAoMTa4pww4c o3sljUKRbag+KO7DkTJiHNcELNFTtag= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-379-lB5O94OePW6xKZVbZ0aDPA-1; Wed, 17 Jun 2020 09:44:18 -0400 X-MC-Unique: lB5O94OePW6xKZVbZ0aDPA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 352B4100CC88; Wed, 17 Jun 2020 13:44:17 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-115-92.ams2.redhat.com [10.36.115.92]) by smtp.corp.redhat.com (Postfix) with ESMTP id B2D61512FE; Wed, 17 Jun 2020 13:44:15 +0000 (UTC) Subject: Re: [edk2-devel] [PATCH] ArmPkg/PlatformBootManagerLib: regenerate boot options on boot failure To: devel@edk2.groups.io, ard.biesheuvel@arm.com Cc: leif@nuviainc.com, Pete Batard , Andrei Warkentin , Samer El-Haj-Mahmoud References: <20200616174834.1110310-1-ard.biesheuvel@arm.com> From: "Laszlo Ersek" Message-ID: <4caae275-e1b9-648e-453e-7ab8411fc8af@redhat.com> Date: Wed, 17 Jun 2020 15:44:14 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20200616174834.1110310-1-ard.biesheuvel@arm.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit On 06/16/20 19:48, Ard Biesheuvel wrote: > 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. > > Cc: Pete Batard > Cc: Andrei Warkentin (awarkentin@vmware.com) > Cc: Samer El-Haj-Mahmoud > 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/Library/PlatformBootManagerLib/PlatformBm.c > index 15c5cac1bea0..9905cad22908 100644 > --- a/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c > +++ b/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c > @@ -820,6 +820,40 @@ PlatformBootManagerUnableToBoot ( > { > EFI_STATUS Status; > EFI_BOOT_MANAGER_LOAD_OPTION BootManagerMenu; > + EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions; > + UINTN OldBootOptionCount; > + UINTN NewBootOptionCount; > + > + // > + // Record the total number of boot configured boot options > + // > + BootOptions = EfiBootManagerGetLoadOptions (&OldBootOptionCount, > + LoadOptionTypeBoot); > + EfiBootManagerFreeLoadOptions (BootOptions, OldBootOptionCount); > + > + // > + // Connect all devices, and regenerate all boot options > + // > + EfiBootManagerConnectAll (); > + EfiBootManagerRefreshAllBootOption (); > + > + // > + // Record the updated number of boot configured boot options > + // > + BootOptions = EfiBootManagerGetLoadOptions (&NewBootOptionCount, > + LoadOptionTypeBoot); > + EfiBootManagerFreeLoadOptions (BootOptions, NewBootOptionCount); > + > + // > + // If the number of configured boot options has changed, reboot > + // the system so the new boot options will be taken into account > + // while executing the ordinary BDS bootflow sequence. > + // > + if (NewBootOptionCount != OldBootOptionCount) { > + DEBUG ((DEBUG_WARN, "%a: rebooting after refreshing all boot options\n", > + __FUNCTION__)); > + gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL); > + } > > Status = EfiBootManagerGetBootManagerMenu (&BootManagerMenu); > if (EFI_ERROR (Status)) { > This looks like a very nice trick, and a very good utilization of the PlatformBootManagerUnableToBoot() hook, for physical machines. FWIW: Acked-by: Laszlo Ersek