From patchwork Fri Nov 10 14:21:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 118561 Delivered-To: patch@linaro.org Received: by 10.80.225.132 with SMTP id k4csp2259968edl; Fri, 10 Nov 2017 06:24:03 -0800 (PST) X-Google-Smtp-Source: AGs4zMZbbjcME45bbUQxFCAMcAEJfCZyguqSGRW+S6s1M6hsNClYo+xv4upuCW49ojRTOIqCVNjv X-Received: by 10.99.111.67 with SMTP id k64mr518348pgc.234.1510323843049; Fri, 10 Nov 2017 06:24:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510323843; cv=none; d=google.com; s=arc-20160816; b=EjfeXDOyJ9oM9PjuCkJ4u7HP70J8sQucPYzsqn7XAmwenZbYvrqfWfoz4p8+DjWpZ7 G/tPuDcpMcDF1xcgTM9eLd6TIZeHKi8AUChXiyLUCJ+0WvgoWeiT3IGymB7/Gjg+d27u Pk5uP4046PL7zboBkekMWJhxpxwgLo3+ohhIAoTsXzZzlkjFiA3VOFiyv8JpqC/xzT7O oAZB907OHRyBydB7NrwJOpTZ7B2mK7ANZUlV4eFiS+b45ZgVQEvh+LgPlti1MaU/4EBe mSp7d4tcO2TzYFlcirMt9htsislLFs6j9crRwTW4MwZz7z+UswVGByAxa22YEngeV6sV zYRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=neQWtWlZj1ZvAzV3AC7Q5TzAbUnv7cTi+IwTTSfhW2k=; b=rv5beBTY/FReaDRwFcWesKGT2H2d4DtGVf9W0bCS5ya4iyMIIKYZJaAny8o8hDjZz3 CjCyk+ZPdq8QwArnbT19WDc/5ghWDfzOjGZ1Di89hHmcic7WTm83H4ps9wmOSyuX4zgm 64Y1ZeUXGPrrpufgEcNa2lAgMBXvQ5mo1tJFfhK+gwaCO2nvAaLxCXnPhnEzB1bWNbh3 rro/SyyJ5rdm683MbY35jQaL+xAhNvGQekJJ2JwNZQqQAwDwDUef5Y8e4SYztotyr3we hWOg3kdCsnOfdf0WHEZX4ZtaDqwrNSnl6N9APfHues0YLpuatpP9AYABHlkGyrD9HPPS FLSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=J360xsYi; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id s188si8536832pgb.646.2017.11.10.06.24.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Nov 2017 06:24:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=J360xsYi; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 9D2C72035D11E; Fri, 10 Nov 2017 06:18:56 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c0c::242; helo=mail-wr0-x242.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wr0-x242.google.com (mail-wr0-x242.google.com [IPv6:2a00:1450:400c:c0c::242]) (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 C262A2035521F for ; Fri, 10 Nov 2017 06:18:55 -0800 (PST) Received: by mail-wr0-x242.google.com with SMTP id u40so8734492wrf.10 for ; Fri, 10 Nov 2017 06:22:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=hXUK7Wt8oFn9cCETSDa4FUJWSJBLAiRuW2w82ob6f0U=; b=J360xsYi2Fd2eBGOBqPfaSSS2/IKBxDAAj5EIOVZEZi2Q0HGXR1GcBC+H1Wj68otQB 66ZPs6nsjqycCyCvTYy9109t9oDa1xI7zBcyI7maWM2E/20iCNJy+4S/AfwDxMoMaqbS acy2QyIBVbcKf7FO0Gq/EcdWnxNGuFaDIoLZk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=hXUK7Wt8oFn9cCETSDa4FUJWSJBLAiRuW2w82ob6f0U=; b=Pz5w5A5Cny4LgyTN4lK5ge8IBVFperbzcqDejhaSeI7sZXfOM6D3J0wfChMouY0bYm h3HLFiO1f0rlcVb9hvZrmKB8h674ecVkHC4a+twBRJSlKduA9/O8V23QwszHOA7ypV9N wUfCdGH72NJ1ww/f3VMBacJK3r+yWdAfKN0twveYAO9C/yl0WSH9poNlOGQjLiy6tgNf W4wflG+gcfIX7zln8Iyx498PWV5wjEC1pze0Avl0N1vWuR7kECWVkpZ2LwjVMSn0OpTi QFjp7SFWuZZfijQ7xk6CK2StNZBVolWtvasm6YXC3x2IG242/quvduQDJ6eEAM8LwPeP RT4A== X-Gm-Message-State: AJaThX6r07bwfEMXupyouRKHn8RbNF+0bhk+/fRC02Oju2Ty3OJ+ZGQO OYdO2eF4k1Ix7sTGLzF0GYnHaT5jjZA= X-Received: by 10.223.182.73 with SMTP id i9mr484010wre.113.1510323777118; Fri, 10 Nov 2017 06:22:57 -0800 (PST) Received: from localhost.localdomain ([160.167.170.128]) by smtp.gmail.com with ESMTPSA id e131sm1036477wmg.15.2017.11.10.06.22.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Nov 2017 06:22:56 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org, leif.lindholm@linaro.org, daniel.thompson@linaro.org Date: Fri, 10 Nov 2017 14:21:20 +0000 Message-Id: <20171110142127.12018-28-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171110142127.12018-1-ard.biesheuvel@linaro.org> References: <20171110142127.12018-1-ard.biesheuvel@linaro.org> Subject: [edk2] [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: , Cc: masahisa.kojima@linaro.org, masami.hiramatsu@linaro.org, Ard Biesheuvel MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" 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 --- Silicon/Socionext/SynQuacer/Library/SynQuacerMemoryInitPeiLib/SynQuacerMemoryInitPeiLib.c | 68 +++++++++++++------- 1 file changed, 45 insertions(+), 23 deletions(-) -- 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Reviewed-by: Leif Lindholm 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); } Status = ArmConfigureMmu (VirtualMemoryTable, NULL, NULL);