From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by mx.groups.io with SMTP id smtpd.web12.761.1592411658095927635 for ; Wed, 17 Jun 2020 09:34:18 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@akeo-ie.20150623.gappssmtp.com header.s=20150623 header.b=NvyEClSV; spf=none, err=permanent DNS error (domain: akeo.ie, ip: 209.85.221.66, mailfrom: pete@akeo.ie) Received: by mail-wr1-f66.google.com with SMTP id c3so2997142wru.12 for ; Wed, 17 Jun 2020 09:34:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akeo-ie.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=U3z1e0hdsYKItPYypIc7vfU73CgGkI3RDQh2vINrXl8=; b=NvyEClSVmcAO5FlxZ/vud3hI2jHdHvzrqsS7cl5+Ya6pbKNMSDMUBtMRBerXK2nwqd 1OEXMI3iWMdfLYFayTzEoSjg5trVkBzafnA6mb+x1S1z/gEWO419wi5szgyxcTjpQh6/ +YrUNtV1iPGB/VLae/aa8THAI80KIIIws+YQ92yzeqfy940XPZRFtKqH5z4+o3t65HIn O24xKPqJVoRsYMuQFxrWPRNfZDFf/MR0LPG1g/2Oqd/dXc2+ka4O53BlchRXHhwIYsvX cqFwfhBtKOkI2zKWtXsAJuuz+kUbiAfZTqPSRhDfkePdVYpTw7jECfx6XIEGtgL9EqxE fX5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=U3z1e0hdsYKItPYypIc7vfU73CgGkI3RDQh2vINrXl8=; b=oCsTxIiAjEYxDuk+6P6BNu3f/3u1OM4MpwotUlNXc8TBA0UiyUcLVcR8sl79l/vAZ9 JKqvtNg//13Yj0uDar4iJs5AQSqrnZqimDXYq2tS/hzgT/9zm72SYc3EoacCeTMrCkLi 7JcVu8yCz0mAz9iH+7ZCaR9BMKJc3lzZQDrXgSgZ6YNcEGwGRkou/ZbWEiDBwgvbXxxu iL1pJzG9z26+cTP0V85Uld99tAaeYRM8B07mg1dDIT8753eC51bIhjLQQi/joMcEIS5g MfuwuFkiNpim68R8iJSOGbYcOEsZbmQ12BjG6r8mVGNiNrYqQNClhc5oymmAoTEbkfuH JSCg== X-Gm-Message-State: AOAM531f1x3Fk0NkeN6f3REM3K/MrkEzcEtVrfOBJDIxwHItu3H+VadE 2/hfl4kDIZuGwm8lNTqE0Cz1Yg== X-Google-Smtp-Source: ABdhPJz8xi/OfA6zoLXKxdiUOt0J+jP0VOiSRAcsGoThuGZTiMbleV62Cgg1a7yMbo0GmJKWBeqo7w== X-Received: by 2002:a5d:468d:: with SMTP id u13mr90835wrq.73.1592411656541; Wed, 17 Jun 2020 09:34:16 -0700 (PDT) Return-Path: Received: from [10.0.0.122] ([84.203.48.247]) by smtp.googlemail.com with ESMTPSA id g3sm155180wrb.46.2020.06.17.09.34.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 17 Jun 2020 09:34:15 -0700 (PDT) Subject: Re: [edk2-devel] [edk2][PATCH 1/1] MdeModulePkg/UefiBootManagerLib: Signal ReadyToBoot on platform recovery To: "Wang, Sunny (HPS SW)" , "devel@edk2.groups.io" Cc: "zhichao.gao@intel.com" , "ray.ni@intel.com" , "ard.biesheuvel@arm.com" , "leif@nuviainc.com" References: <20200616095622.2820-1-pete@akeo.ie> <20200616095622.2820-2-pete@akeo.ie> <99904809-1e07-6bd8-f7ba-25e87b1fe543@akeo.ie> From: "Pete Batard" Message-ID: Date: Wed, 17 Jun 2020 17:34:14 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit On 2020.06.17 14:04, Wang, Sunny (HPS SW) wrote: > Thanks for checking my comments, Pete. > >> Or is the "one more" the issue, meaning that it would get signaled more than once? > [Sunny] Yeah, it would get signaled more than once if the PlatformRecovery option (a UEFI application) calls EfiBootManagerBoot() to launch the recovered boot option inside of the application. Okay. One element that I'm going to point out is that, with the current EDK2 code (i.e. without this proposal applied), and after a user goes into the setup to save their boot options in order for regular boot options to get executed instead of PlaformRecovery, the OnReadyToBoot event is actually called twice. So my understanding is that, while we of course want to avoid this and any patch proposal should actively try to prevent it, it seems we already have behaviour in EDK2 that can lead to OnReadyToBoot being signalled more than once. At least the current Pi 4 platform does demonstrate this behaviour. For instance, if you run DEBUG, you will see two instances of: RemoveDtStdoutPath: could not retrieve DT blob - Not Found which is a one-instance message generated from the ConsolePrefDxe's OnReadyToBoot() call. I've also confirmed more specifically that OnReadyToBoot() is indeed called twice. I don't recall us doing much of any special with regards to boot options for the Pi platform, so my guess is that it's probably not the only platform where OnReadyToBoot might be signalled more than once, and that this might be tied to a default EDK2 behaviour. Therefore I don't see having a repeated event as a major deal breaker (though, again, if we can avoid that, we of course will want to). >> I don't mind trying an alternative approach, but I don't understand how what you describe would help. Can you please be more specific about what you have in mind? > [Sunny] Sure. I added more information below. If it is still not clear enough, feel free to let me know. > 1. Create a UEFI application with the code to signal ReadyToBoot and pick /efi/boot/bootaa64.efi from either SD or USB and run it. So that would basically be adding code that duplicates, in part, what Platform Recovery already does. I have to be honest: Even outside of the extra work this would require, I don't really like the idea of having to write our own application, as it will introduce new possible points of failures and require extra maintenance (especially as we will want to be able to handle network boot and other options, and before long, I fear that we're going to have to write our own Pi specific boot manager). Doing so simply because the current Platform Recovery, which does suit our needs otherwise, is not designed to call ReadyToBoot does not seem like the best course of action in my book. Instead, I still logically believe that any option that calls a boot loader should signal ReadyToBoot, regardless of whether it was launched from Boot Manager or Platform Recovery, and that it shouldn't be left to each platform to work around that. Of course, I understand that this would require a specs change, and that it also may have ramifications for existing platforms that interpret the current specs pedantically. But to me, regardless of what the specs appear to be limiting it to right now, the logic of a "ReadyToBoot" event is that it should be signalled whenever a bootloader is about to be executed, rather than only when a bootloader happened to be launched through a formal Boot Manager option. I would therefore appreciate if other people could weigh in on this matter, to see if I'm the only one who believes that we could ultimately have more to gain from signalling ReadyToBoot with PlatformRecovery options than leaving things as they stand right now... > 2. Then, call EfiBootManagerInitializeLoadOption like the following in a DXE driver or other places before "Default PlatformRecovery" registration: > Status = EfiBootManagerInitializeLoadOption ( > &LoadOption, > 0, -> 0 is the OptionNumber to let application be load before " Default PlatformRecovery" option > LoadOptionTypePlatformRecovery, > LOAD_OPTION_ACTIVE, > L"Application for recovering boot options", > FilePath, -> FilePath is the Application's device path, > NULL, > 0 > ); > > >> My reasoning is that, if PlatformRecovery#### can execute a regular bootloader like /efi/boot/boot####.efi from installation media, then it should go through the same kind of initialization that happens for a regular boot option, and that should include signaling the ReadyToBoot event. > [Sunny] Thanks for clarifying this, and Sorry about that I missed your cover letter for this patch. I was just thinking that we may not really need to make this behavior change in both EDK II code and UEFI specification for solving the problem specific to the case that OS is loaded by "Default PlatformRecovery" option, The way I see it is that the Pi platform is unlikely to be the only one where PlatformRecovery is seen as a means to install an OS. Granted, this may seem like abusing the option, but since UEFI doesn't provide an "Initial OS Install" mode, I would assert that it as good a use of this option as any. In other words, I don't think this improvement would only benefit the Pi platform. > and I'm also not sure if it is worth making this change to affect some of the system or BIOS vendors who have implemented their PlatformRecovery option. That's a legitimate concern, and I would agree the one major potential pitfall of this proposal, if there happens to exist a system where an OnReadyToBoot even before running the recovery option can have adverse effects. I don't really believe that such a system exists, because I expect most recovery boot loaders to also work (or at least have been designed to work) as regular boot options. But I don't have enough experience with platform recovery to know if that's a correct assertion to make... > If the alternative approach I mentioned works for you, I think that would be an easier solution. Right now, even as the patch proposal has multiple issues that require it to be amended (Don't signal ReadyToBoot except for PlatformRecovery + Prevent situations where ReadyToBoot could be signalled multiple times) I still see it as both an easier solution than the alternative, as well as one that *should* benefit people who design Platform Recovery UEFI applications in the long run. So that is why I am still trying to advocate for it. But I very much hear your concerns, and I agree that specs changes are better avoided when possible. Thus, at this stage, even as I don't want to drag this discussion much further, I don't feel like I want to commit to one solution or the other before we have had a chance to hear other people, who may have their own opinion on the matter, express their views. Regards, /Pete > > Regards, > Sunny Wang > > -----Original Message----- > From: Pete Batard [mailto:pete@akeo.ie] > Sent: Wednesday, June 17, 2020 6:59 PM > To: Wang, Sunny (HPS SW) ; devel@edk2.groups.io > Cc: zhichao.gao@intel.com; ray.ni@intel.com; ard.biesheuvel@arm.com; leif@nuviainc.com > Subject: Re: [edk2-devel] [edk2][PATCH 1/1] MdeModulePkg/UefiBootManagerLib: Signal ReadyToBoot on platform recovery > > Hi Sunny, thanks for looking into this. > > On 2020.06.17 09:16, Wang, Sunny (HPS SW) wrote: >> Hi Pete. >> >> Since the EfiBootManagerProcessLoadOption is called by ProcessLoadOptions as well, your change would also cause some unexpected behavior like: >> 1. Signal one more ReadyToBoot for the PlatformRecovery option which is an application that calls EfiBootManagerBoot() to launch its recovered boot option. > > I'm not sure I understand how this part is unwanted. > > The point of this patch is to ensure that ReadyToBoot is signalled for the PlatformRecovery option, so isn't what you describe above exactly what we want? > > Or is the "one more" the issue, meaning that it would get signalled more than once? > > >> 2. Signal ReadyToBoot for SysPrep#### or Driver#### that is not really a "boot" option. > > Yes, I've been wondering about that, because BdsEntry.c's ProcessLoadOptions(), which calls EfiBootManagerProcessLoadOption(), > mentions that it will load will load and start every Driver####, SysPrep#### or PlatformRecovery####. But the comment about the while() loop in EfiBootManagerProcessLoadOption() only mentions PlatformRecovery####. > > If needed, I guess we could amend the patch to detect the type of option and only signal ReadyToBoot for PlatformRecovery####. > >> To solve your problem, creating a PlatformRecovery option with the smallest option number and using it instead of default one (with short-form File Path Media Device Path) looks like a simpler solution. > > I don't mind trying an alternative approach, but I don't understand how what you describe would help. Can you please be more specific about what you have in mind? > > Our main issue here is that we must have ReadyToBoot signalled so that the ReadyToBoot() function callback from EmbeddedPkg/Drivers/ConsolePrefDxe gets executed in order for the boot loader invoked from PlatformRecovery#### to use a properly initialized graphical console. So I'm not sure I quite get how switching from one PlatformRecovery#### option to another would improve things. > > If it helps, here is what we currently default to, in terms of boot options, on a Raspberry Pi 4 platform with a newly build firmware: > > [Bds]=============Begin Load Options Dumping ...============= > Driver Options: > SysPrep Options: > Boot Options: > Boot0000: UiApp 0x0109 > Boot0001: UEFI Shell 0x0000 > PlatformRecovery Options: > PlatformRecovery0000: Default PlatformRecovery 0x0001 > [Bds]=============End Load Options Dumping============= > > With this, PlatformRecovery0000 gets executed by default, which is what we want, since it will pick /efi/boot/bootaa64.efi from either SD or USB and run it, the only issue being that, because ReadyToBoot has not been executed, the graphical console is not operative so users can't interact with the OS installer. > > So I'm really not sure how adding an extra PlatformRecovery#### would help. And I'm also not too familiar with how one would go around to add such an entry... > >> By the way, I also checked the UEFI specification. It looks making sense to only signal ReadyToBoot for boot option (Boot####). > > That's something I considered too, but I disagree with this conclusion. > > My reasoning is that, if PlatformRecovery#### can execute a regular bootloader like /efi/boot/boot####.efi from installation media, then it should go through the same kind of initialization that happens for a regular boot option, and that should include signalling the ReadyToBoot event. > > If there was a special bootloader for PlatformRecovery#### (e.g. > /efi/boot/recovery####.efi) then I would agree with only signalling ReadyToBoot for a formal Boot#### option. But that isn't the case, so I think it is reasonable to want to have ReadyToBoot also occur when a /efi/boot/boot####.efi bootloader is executed from PlatformRecovery####., especially when we know it can be crucial to ensuring that the end user can actually use the graphical console. > >> Therefore, your change may also require specification change. > > Yes, I mentioned that in the cover letter for this patch (https://edk2.groups.io/g/devel/message/61327 ), which also describes the issue we are trying to solve in greater details. This is what I wrote: > > ------------------------------------------------------------------------ > Note however that this may require a specs update, as the current UEFI specs for EFI_BOOT_SERVICES.CreateEventEx() have: > > > EFI_EVENT_GROUP_READY_TO_BOOT > > This event group is notified by the system when the Boot Manager > > is about to load and execute a boot option. > > and, once this patch has been applied, we may want to update this section to mention that it applies to both Boot Manager and Platform Recovery. > ------------------------------------------------------------------------ > > > Again, I don't have an issue with trying to use an alternate approach to solve our problem (though I ultimately believe that, if PlatformRecovery#### can launch a /efi/boot/boot####.efi bootloader then we must update the specs and the code to have ReadyToBoot also signalled then, because that's the logical thing to do). But right now, I'm not seeing how to achieve that when PlatformRecovery#### is the option that is used to launch the OS installation the bootloader. So if you can provide mode details on how exactly you think creating an alternate PlatformRecovery option would help, I would appreciate it. > > Regards, > > /Pete > >> >> Regards, >> Sunny Wang >> >> -----Original Message----- >> From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of >> Pete Batard >> Sent: Tuesday, June 16, 2020 5:56 PM >> To: devel@edk2.groups.io >> Cc: zhichao.gao@intel.com; ray.ni@intel.com; ard.biesheuvel@arm.com; >> leif@nuviainc.com >> Subject: [edk2-devel] [edk2][PATCH 1/1] >> MdeModulePkg/UefiBootManagerLib: Signal ReadyToBoot on platform >> recovery >> >> Currently, the ReadyToBoot event is only signaled when a formal Boot Manager option is executed (in BmBoot.c -> EfiBootManagerBoot ()). >> >> However, with the introduction of Platform Recovery in UEFI 2.5, which may lead to the execution of a boot loader that has similar requirements to a regular one, yet is not launched as a Boot Manager option, it also becomes necessary to signal ReadyToBoot when a Platform Recovery boot loader runs. >> >> Especially, this can be critical to ensuring that the graphical console is actually usable during platform recovery, as some platforms do rely on the ConsolePrefDxe driver, which only performs console initialization after ReadyToBoot is triggered. >> >> This patch fixes that behaviour by calling EfiSignalEventReadyToBoot () in EfiBootManagerProcessLoadOption (), which is the function that sets up the platform recovery boot process. >> >> Signed-off-by: Pete Batard >> --- >> MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c | 9 +++++++++ >> 1 file changed, 9 insertions(+) >> >> diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c >> b/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c >> index 89372b3b97b8..117f1f5b124c 100644 >> --- a/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c >> +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c >> @@ -1376,6 +1376,15 @@ EfiBootManagerProcessLoadOption ( >> return EFI_SUCCESS; >> } >> >> + // >> + // Signal the EVT_SIGNAL_READY_TO_BOOT event when we are about to load and execute the boot option. >> + // >> + EfiSignalEventReadyToBoot (); >> + // >> + // Report Status Code to indicate ReadyToBoot was signalled // >> + REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_DXE_BS_DRIVER | >> + EFI_SW_DXE_BS_PC_READY_TO_BOOT_EVENT)); >> + >> // >> // Load and start the load option. >> // >> -- >> 2.21.0.windows.1 >> >> >> >> >