From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io0-x22a.google.com (mail-io0-x22a.google.com [IPv6:2607:f8b0:4001:c06::22a]) (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 1186E819DC for ; Fri, 20 Jan 2017 03:58:14 -0800 (PST) Received: by mail-io0-x22a.google.com with SMTP id v96so60755336ioi.0 for ; Fri, 20 Jan 2017 03:58:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=P4F6/KmHvasXi15OmcoXheYBJwOeTeJ5GVv3LSN05UY=; b=bTPy6KBEupObDrhAU+5wUjR1Zv6wwfrwL2o80LcrMPbxeJm5cvFrWicoID7QfleMO4 pCLsybXKQ7yospBMp9+kAHPMCH9ZsRnIrbcf3LTxcbby1BeO3ZTK8GZmMSRm77t+Bp+y F/M9l2Ty8zeqFNOZGTwK/QreS8tvdtdJO/GqE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=P4F6/KmHvasXi15OmcoXheYBJwOeTeJ5GVv3LSN05UY=; b=hJRxn84PFJbzpJVvpn1EPL2/E6ZryX+nyaWTQtlNNHDhpMhYyCtakyFbgQcQ0920QB lUP7/Z3Z9v3Sb9x4D3WhupR1s4SmHm6IOyFAjcQPOjtvEbdR6/X1MxzUHQ73MaiaWNel UfS20N6ITtjnicJQ6AfFv6K+wo8FQdCOnG61kFNCJV2DO0MSRzi1542AgP8XaNSeY/iR 9dtqWAdY40aRJNlKdCcqraTbLiNrDetHsNI8L31P2Ho0hPQf5N5ggDngtim0X3NjTeUI 6m7zJWskzsU8o+PzsTQ0eqQu8nqQyK0w78qQf514BDXHWTIQnRZfaKbXjCXSb6EQjI8Y Cm5w== X-Gm-Message-State: AIkVDXJzwK/iPtPwGL0V+0QfkSjjgR53k2kbdKfoJYTqDUXIOyxarS0DKd7SNIneK2sTjisX1r2RmPvAWFpYvZYt X-Received: by 10.107.12.150 with SMTP id 22mr12040056iom.138.1484913493171; Fri, 20 Jan 2017 03:58:13 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.144.135 with HTTP; Fri, 20 Jan 2017 03:58:12 -0800 (PST) In-Reply-To: References: From: Ard Biesheuvel Date: Fri, 20 Jan 2017 11:58:12 +0000 Message-ID: To: Achin Gupta Cc: "edk2-devel@lists.01.org" , Leif Lindholm , nd@arm.com Subject: Re: [PATCH] ArmPlatformPkg/NorFlashDxe: Change Flash memory attributes before writes X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Jan 2017 11:58:14 -0000 Content-Type: text/plain; charset=UTF-8 On 20 January 2017 at 11:54, wrote: > From: Achin Gupta > > In NorFlashFvbInitialize() if a valid Firmware Volume header is not found at the > start of NOR Flash, the Flash memory is written before it has been remapped with > EFI_MEMORY_UC attributes to allow write commands. Since the flash memory was > previously mapped with Normal and possibly cacheable memory attributes, the > Flash commands might never reach the device. > > This patch fixes this issue by remapping the Flash memory region with correct > memory attributes before writing to it. > > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Achin Gupta Thanks Achin! Reviewed-by: Ard Biesheuvel Pushed as 90d1f671cdad > --- > .../Drivers/NorFlashDxe/NorFlashFvbDxe.c | 45 +++++++++++----------- > 1 file changed, 23 insertions(+), 22 deletions(-) > > diff --git a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c > index 42be5c2..12a8612 100644 > --- a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c > +++ b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c > @@ -719,6 +719,29 @@ NorFlashFvbInitialize ( > UINTN RuntimeMmioRegionSize; > > DEBUG((DEBUG_BLKIO,"NorFlashFvbInitialize\n")); > + ASSERT((Instance != NULL)); > + > + // > + // Declare the Non-Volatile storage as EFI_MEMORY_RUNTIME > + // > + > + // Note: all the NOR Flash region needs to be reserved into the UEFI Runtime memory; > + // even if we only use the small block region at the top of the NOR Flash. > + // The reason is when the NOR Flash memory is set into program mode, the command > + // is written as the base of the flash region (ie: Instance->DeviceBaseAddress) > + RuntimeMmioRegionSize = (Instance->RegionBaseAddress - Instance->DeviceBaseAddress) + Instance->Size; > + > + Status = gDS->AddMemorySpace ( > + EfiGcdMemoryTypeMemoryMappedIo, > + Instance->DeviceBaseAddress, RuntimeMmioRegionSize, > + EFI_MEMORY_UC | EFI_MEMORY_RUNTIME > + ); > + ASSERT_EFI_ERROR (Status); > + > + Status = gDS->SetMemorySpaceAttributes ( > + Instance->DeviceBaseAddress, RuntimeMmioRegionSize, > + EFI_MEMORY_UC | EFI_MEMORY_RUNTIME); > + ASSERT_EFI_ERROR (Status); > > Instance->Initialized = TRUE; > mFlashNvStorageVariableBase = FixedPcdGet32 (PcdFlashNvStorageVariableBase); > @@ -757,28 +780,6 @@ NorFlashFvbInitialize ( > } > > // > - // Declare the Non-Volatile storage as EFI_MEMORY_RUNTIME > - // > - > - // Note: all the NOR Flash region needs to be reserved into the UEFI Runtime memory; > - // even if we only use the small block region at the top of the NOR Flash. > - // The reason is when the NOR Flash memory is set into program mode, the command > - // is written as the base of the flash region (ie: Instance->DeviceBaseAddress) > - RuntimeMmioRegionSize = (Instance->RegionBaseAddress - Instance->DeviceBaseAddress) + Instance->Size; > - > - Status = gDS->AddMemorySpace ( > - EfiGcdMemoryTypeMemoryMappedIo, > - Instance->DeviceBaseAddress, RuntimeMmioRegionSize, > - EFI_MEMORY_UC | EFI_MEMORY_RUNTIME > - ); > - ASSERT_EFI_ERROR (Status); > - > - Status = gDS->SetMemorySpaceAttributes ( > - Instance->DeviceBaseAddress, RuntimeMmioRegionSize, > - EFI_MEMORY_UC | EFI_MEMORY_RUNTIME); > - ASSERT_EFI_ERROR (Status); > - > - // > // Register for the virtual address change event > // > Status = gBS->CreateEventEx ( > -- > 1.9.1 >