From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c0c::243; helo=mail-wr0-x243.google.com; envelope-from=leif.lindholm@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wr0-x243.google.com (mail-wr0-x243.google.com [IPv6:2a00:1450:400c:c0c::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7AE3E220D4BE1 for ; Fri, 17 Nov 2017 07:19:07 -0800 (PST) Received: by mail-wr0-x243.google.com with SMTP id k61so2406813wrc.4 for ; Fri, 17 Nov 2017 07:23:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=vHIk4RV228RAdW3+uR1Uml/fiDXZujt5aEdDli1iw/A=; b=cuaqlzjN6yaK6TF2f2rL5rcJvO6XGzK949I+249AskEgITC111vCLeeK72922PbLjc i1d/YPnZZGbCCrKOInTEN+6oSTYFI85IVsaHSt0CdxiP0pqU569jIhbTZAalRKOTOCN7 3EYAhofkq6/UkZ03eXg7/PIMCJ6NACeZI+ZR8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=vHIk4RV228RAdW3+uR1Uml/fiDXZujt5aEdDli1iw/A=; b=J/N344broBq6CI3gIBISNHXmUAWrMj2lwEhywd781jAeVkutUtZqlrE4zeKtWQ+Psl mz+QTy19eCdtUDLBeS2nbbcJx4HTCS+9V8i/M2bOLDVbj6XHOQyvHhdpBU60J0NwiHsw ddUoYmcVDPMVBPbPohDvAgf7PdRVUHSBOp1malfh6KmaeXdIb6ODO4+hak7i8KwQExUi A9p2+whTDVjOMiRM1eTUtrbbQ0YL+NBC1rETDsi7wxhGrKP5hd6FXIPsSZtxChqYuxJJ cex3rslqsqcPslrTqzT1d1R1Rg17yKuNTgNVRO+N85Hf5AY+nnP5saRuldkQJNcV6Bu0 XmbQ== X-Gm-Message-State: AJaThX4gkbvq843tne5RR/n2YgGq4p1zDUKgER0icd1vrMaOh7X+9evu XSibZ3uCsNEKlF2gWyPrSjzOBQ== X-Google-Smtp-Source: AGs4zMbOdD8YSkHpjXMrlwbZfTXHFKVZF13OW9SltILMqtaF0zPdqX/UtOTSO1YBQ5mYUMbRxksP4Q== X-Received: by 10.223.191.17 with SMTP id p17mr4558614wrh.184.1510932196580; Fri, 17 Nov 2017 07:23:16 -0800 (PST) Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id y15sm9241427wrc.96.2017.11.17.07.23.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 17 Nov 2017 07:23:15 -0800 (PST) Date: Fri, 17 Nov 2017 15:23:13 +0000 From: Leif Lindholm To: Ard Biesheuvel Cc: edk2-devel@lists.01.org, daniel.thompson@linaro.org, masami.hiramatsu@linaro.org, methavanitpong.pipat@socionext.com, masahisa.kojima@linaro.org Message-ID: <20171117152313.uwwq3v7ufif54cep@bivouac.eciton.net> References: <20171110142127.12018-1-ard.biesheuvel@linaro.org> <20171110142127.12018-28-ard.biesheuvel@linaro.org> MIME-Version: 1.0 In-Reply-To: <20171110142127.12018-28-ard.biesheuvel@linaro.org> User-Agent: NeoMutt/20170113 (1.7.2) Subject: Re: [PATCH edk2-platforms v4 27/34] Silicon/SynQuacerMemoryInitPeiLib: ignore capsules when clearing NVRAM X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Nov 2017 15:19:07 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Nov 10, 2017 at 02:21:20PM +0000, Ard Biesheuvel wrote: > In preparation of adding support for setting a DIP switch to clear the > EFI variable store, update the early capsule handling logic to take the > boot mode into account. > > This is necessary for two reasons: > - we override the boot mode when a capsule is detected, > - the capsule detection itself involves reading a EFI variable, which we > shouldn't be doing if the varstore may be in a bad state. > > So factor out the initial capsule check (to keep the code understandable) > and only perform it if we are not booting in 'clear NVRAM' mode. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Ard Biesheuvel Minor suggestion below, fold in if you like it. Regardless: Reviewed-by: Leif Lindholm > --- > Silicon/Socionext/SynQuacer/Library/SynQuacerMemoryInitPeiLib/SynQuacerMemoryInitPeiLib.c | 68 +++++++++++++------- > 1 file changed, 45 insertions(+), 23 deletions(-) > > diff --git a/Silicon/Socionext/SynQuacer/Library/SynQuacerMemoryInitPeiLib/SynQuacerMemoryInitPeiLib.c b/Silicon/Socionext/SynQuacer/Library/SynQuacerMemoryInitPeiLib/SynQuacerMemoryInitPeiLib.c > index b44c58d61062..63c441872da7 100644 > --- a/Silicon/Socionext/SynQuacer/Library/SynQuacerMemoryInitPeiLib/SynQuacerMemoryInitPeiLib.c > +++ b/Silicon/Socionext/SynQuacer/Library/SynQuacerMemoryInitPeiLib/SynQuacerMemoryInitPeiLib.c > @@ -170,6 +170,44 @@ DeclareDram ( > return EFI_SUCCESS; > } > > +STATIC > +BOOLEAN > +CheckCapsule ( > + IN EFI_PEI_SERVICES **PeiServices, > + IN PEI_CAPSULE_PPI *Capsule, > + IN EFI_PHYSICAL_ADDRESS UefiMemoryBase, > + OUT VOID **CapsuleBuffer, > + OUT UINTN *CapsuleBufferLength > + ) > +{ > + EFI_STATUS Status; > + > + Status = Capsule->CheckCapsuleUpdate (PeiServices); > + if (!EFI_ERROR (Status)) { > + > + // > + // Coalesce the capsule into unused memory. CreateState() below will copy > + // it to a properly allocated buffer. > + // > + *CapsuleBuffer = (VOID *)PcdGet64 (PcdSystemMemoryBase); > + *CapsuleBufferLength = UefiMemoryBase - PcdGet64 (PcdSystemMemoryBase); > + > + PeiServicesSetBootMode (BOOT_ON_FLASH_UPDATE); > + > + Status = Capsule->Coalesce (PeiServices, CapsuleBuffer, > + CapsuleBufferLength); > + if (!EFI_ERROR (Status)) { > + DEBUG ((DEBUG_INFO, "%a: Coalesced capsule @ %p (0x%lx)\n", > + __FUNCTION__, *CapsuleBuffer, *CapsuleBufferLength)); > + return TRUE; > + } else { > + DEBUG ((DEBUG_WARN, "%a: failed to coalesce() capsule (Status == %r)\n", > + __FUNCTION__, Status)); > + } > + } > + return FALSE; > +} > + > EFI_STATUS > EFIAPI > MemoryPeim ( > @@ -184,6 +222,7 @@ MemoryPeim ( > VOID *CapsuleBuffer; > UINTN CapsuleBufferLength; > BOOLEAN HaveCapsule; > + EFI_BOOT_MODE BootMode; > > Status = DeclareDram (&VirtualMemoryTable); > ASSERT_EFI_ERROR (Status); > @@ -199,31 +238,14 @@ MemoryPeim ( > ASSERT_EFI_ERROR (Status); > > // > - // Check for persistent capsules > + // Check for persistent capsules, unless we are booting with default > + // settings. > // > HaveCapsule = FALSE; > - Status = Capsule->CheckCapsuleUpdate (PeiServices); > - if (!EFI_ERROR (Status)) { > - > - // > - // Coalesce the capsule into unused memory. CreateState() below will copy > - // it to a properly allocated buffer. > - // > - CapsuleBuffer = (VOID *)PcdGet64 (PcdSystemMemoryBase); > - CapsuleBufferLength = UefiMemoryBase - PcdGet64 (PcdSystemMemoryBase); > - > - PeiServicesSetBootMode (BOOT_ON_FLASH_UPDATE); > - > - Status = Capsule->Coalesce (PeiServices, &CapsuleBuffer, > - &CapsuleBufferLength); > - if (!EFI_ERROR (Status)) { > - DEBUG ((DEBUG_INFO, "%a: Coalesced capsule @ %p (0x%lx)\n", > - __FUNCTION__, CapsuleBuffer, CapsuleBufferLength)); > - HaveCapsule = TRUE; > - } else { > - DEBUG ((DEBUG_WARN, "%a: failed to coalesce() capsule (Status == %r)\n", > - __FUNCTION__, Status)); > - } > + Status = PeiServicesGetBootMode (&BootMode); > + if (!EFI_ERROR (Status) && BootMode != BOOT_WITH_DEFAULT_SETTINGS) { > + HaveCapsule = CheckCapsule (PeiServices, Capsule, UefiMemoryBase, > + &CapsuleBuffer, &CapsuleBufferLength); You could do } else { HaveCapsule = FALSE; here instead of unconditionally before the test. / Leif > } > > Status = ArmConfigureMmu (VirtualMemoryTable, NULL, NULL); > -- > 2.11.0 >