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::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-Google-Smtp-Source: AGs4zMZuBawNXqUjvB3ZP+vFIt/zHZ9cMd5p+uBZr1vFwoOFwwuBlAemKWN+LCuubTAeqOZjwPpRMQ== 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 Cc: masami.hiramatsu@linaro.org, methavanitpong.pipat@socionext.com, masahisa.kojima@linaro.org, Ard Biesheuvel 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: [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, 10 Nov 2017 14:18:56 -0000 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(-) 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); -- 2.11.0