public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH edk2-platforms v2 0/2]DeveloperBox: prepare for expanding the capsule payload
@ 2018-06-13 16:28 Ard Biesheuvel
  2018-06-13 16:28 ` [PATCH edk2-platforms v2 1/2] Silicon/SynQuacerPlatformFlashAccessLib: relax FV address check Ard Biesheuvel
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Ard Biesheuvel @ 2018-06-13 16:28 UTC (permalink / raw)
  To: edk2-devel; +Cc: leif.lindholm, Ard Biesheuvel

We intend to start distributing firmware update capsules that include the SCP
firmware partition. In order to allow for more flexibility regarding whether
a capsule contains this piece or not, update the flash access routines and
the flash partition descriptions so we can update any part of the first
4 MB, consisting of the CM3 bootstrap code, emergency flasher, pseudo
EEPROM, SCP firmware, ARM-TF and UEFI.

Note that this means we can drop the 'TEMPORARY' patch I proposed a while
ago to hack around this limitation.

Changes since v1:
- use more parentheses in if () condition expression (#1)
- use symbolic constants for code and env NOR regions (#2)

Ard Biesheuvel (2):
  Silicon/SynQuacerPlatformFlashAccessLib: relax FV address check
  Silicon/NorFlashSynQuacerLib: describe entire firmware region as FV

 .../NorFlashSynQuacerLib/NorFlashSynQuacer.c  | 18 ++++--
 .../SynQuacerPlatformFlashAccessLib.c         | 56 +++++++++----------
 2 files changed, 39 insertions(+), 35 deletions(-)

-- 
2.17.1



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH edk2-platforms v2 1/2] Silicon/SynQuacerPlatformFlashAccessLib: relax FV address check
  2018-06-13 16:28 [PATCH edk2-platforms v2 0/2]DeveloperBox: prepare for expanding the capsule payload Ard Biesheuvel
@ 2018-06-13 16:28 ` Ard Biesheuvel
  2018-06-13 16:28 ` [PATCH edk2-platforms v2 2/2] Silicon/NorFlashSynQuacerLib: describe entire firmware region as FV Ard Biesheuvel
  2018-06-13 18:56 ` [PATCH edk2-platforms v2 0/2]DeveloperBox: prepare for expanding the capsule payload Leif Lindholm
  2 siblings, 0 replies; 5+ messages in thread
From: Ard Biesheuvel @ 2018-06-13 16:28 UTC (permalink / raw)
  To: edk2-devel; +Cc: leif.lindholm, Ard Biesheuvel

In commit 913fdda9f4b9 ("Silicon/SynQuacerPlatformFlashAccessLib: don't
dereference FVB header fields"), we dropped all accesses to FVB header
field, which was necessary because the flash partition may not in fact
contain such a header. Instead, only an exact match on the base address
of the FV compared to the base address of the capsule payload would
result in a match, making it difficult to create capsules that only
update a subset of the flash contents.

Given that the FVB protocol provides a GetBlockSize() method that also
returns the number of consecutive blocks of that size, and does not rely
on the FVB header contents, we can actually infer the size of the flash
partition, and use it to decide whether a capsule payload targets an
area that is covered by this partition entirely.

This optimization allows us to extend the FV description to include the
SCP firmware partition without requiring us to actually provide a
payload for that partition immediately, which is useful as a preparatory
step.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 Silicon/Socionext/SynQuacer/Library/SynQuacerPlatformFlashAccessLib/SynQuacerPlatformFlashAccessLib.c | 56 ++++++++++----------
 1 file changed, 27 insertions(+), 29 deletions(-)

diff --git a/Silicon/Socionext/SynQuacer/Library/SynQuacerPlatformFlashAccessLib/SynQuacerPlatformFlashAccessLib.c b/Silicon/Socionext/SynQuacer/Library/SynQuacerPlatformFlashAccessLib/SynQuacerPlatformFlashAccessLib.c
index 48d385993b38..51bf9f62457f 100644
--- a/Silicon/Socionext/SynQuacer/Library/SynQuacerPlatformFlashAccessLib/SynQuacerPlatformFlashAccessLib.c
+++ b/Silicon/Socionext/SynQuacer/Library/SynQuacerPlatformFlashAccessLib/SynQuacerPlatformFlashAccessLib.c
@@ -45,8 +45,10 @@ STATIC
 EFI_STATUS
 GetFvbByAddress (
   IN  EFI_PHYSICAL_ADDRESS                Address,
+  IN  UINTN                               Length,
   OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL  **OutFvb,
-  OUT EFI_PHYSICAL_ADDRESS                *FvbBaseAddress
+  OUT EFI_LBA                             *Lba,
+  OUT UINTN                               *BlockSize
   )
 {
   EFI_STATUS                          Status;
@@ -55,6 +57,8 @@ GetFvbByAddress (
   UINTN                               Index;
   EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL  *Fvb;
   EFI_FVB_ATTRIBUTES_2                Attributes;
+  EFI_PHYSICAL_ADDRESS                FvbBaseAddress;
+  UINTN                               NumberOfBlocks;
 
   //
   // Locate all handles with Firmware Volume Block protocol
@@ -85,7 +89,7 @@ GetFvbByAddress (
     //
     // Checks if the address range of this handle contains parameter Address
     //
-    Status = Fvb->GetPhysicalAddress (Fvb, FvbBaseAddress);
+    Status = Fvb->GetPhysicalAddress (Fvb, &FvbBaseAddress);
     if (EFI_ERROR (Status)) {
       continue;
     }
@@ -103,9 +107,27 @@ GetFvbByAddress (
       continue;
     }
 
-    if (Address == *FvbBaseAddress) {
+    Status = Fvb->GetBlockSize (Fvb, 0, BlockSize, &NumberOfBlocks);
+    if (EFI_ERROR (Status)) {
+      DEBUG ((DEBUG_INFO, "%a: failed to get FVB blocksize - %r, ignoring\n",
+        __FUNCTION__, Status));
+      continue;
+    }
+
+    if ((Length % *BlockSize) != 0) {
+      DEBUG ((DEBUG_INFO,
+        "%a: Length 0x%lx is not a multiple of the blocksize 0x%lx, ignoring\n",
+        __FUNCTION__, Length, *BlockSize));
+      Status = EFI_INVALID_PARAMETER;
+      continue;
+    }
+
+    if ((Address >= FvbBaseAddress) &&
+        ((Address + Length) <=
+         (FvbBaseAddress + (*BlockSize * NumberOfBlocks)))) {
       *OutFvb  = Fvb;
-      Status   = EFI_SUCCESS;
+      *Lba = (Address - FvbBaseAddress) / *BlockSize;
+      Status = EFI_SUCCESS;
       break;
     }
 
@@ -191,9 +213,7 @@ PerformFlashWriteWithProgress (
   EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL  *Fvb;
   EFI_STATUS                          Status;
   UINTN                               BlockSize;
-  UINTN                               NumberOfBlocks;
   EFI_LBA                             Lba;
-  EFI_PHYSICAL_ADDRESS                FvbBaseAddress;
   UINTN                               NumBytes;
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Black;
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION White;
@@ -227,7 +247,7 @@ PerformFlashWriteWithProgress (
   // that covers the system firmware
   //
   Fvb = NULL;
-  Status = GetFvbByAddress (FlashAddress, &Fvb, &FvbBaseAddress);
+  Status = GetFvbByAddress (FlashAddress, Length, &Fvb, &Lba, &BlockSize);
   if (EFI_ERROR (Status)) {
     DEBUG ((DEBUG_ERROR,
       "%a: failed to locate FVB handle for address 0x%llx - %r\n",
@@ -235,28 +255,6 @@ PerformFlashWriteWithProgress (
     return Status;
   }
 
-  Status = Fvb->GetBlockSize(Fvb, 0, &BlockSize, &NumberOfBlocks);
-  if (EFI_ERROR (Status)) {
-    DEBUG ((DEBUG_ERROR, "%a: failed to get FVB blocksize - %r\n",
-      __FUNCTION__, Status));
-    return Status;
-  }
-
-  if ((Length % BlockSize) != 0) {
-    DEBUG ((DEBUG_ERROR,
-      "%a: Length 0x%lx is not a multiple of the blocksize 0x%lx\n",
-      __FUNCTION__, Length, BlockSize));
-    return EFI_INVALID_PARAMETER;
-  }
-
-  Lba = (FlashAddress - FvbBaseAddress) / BlockSize;
-  if (Lba > NumberOfBlocks - 1) {
-    DEBUG ((DEBUG_ERROR,
-      "%a: flash device with non-uniform blocksize not supported\n",
-      __FUNCTION__));
-    return EFI_UNSUPPORTED;
-  }
-
   //
   // Remap the region as device rather than uncached.
   //
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH edk2-platforms v2 2/2] Silicon/NorFlashSynQuacerLib: describe entire firmware region as FV
  2018-06-13 16:28 [PATCH edk2-platforms v2 0/2]DeveloperBox: prepare for expanding the capsule payload Ard Biesheuvel
  2018-06-13 16:28 ` [PATCH edk2-platforms v2 1/2] Silicon/SynQuacerPlatformFlashAccessLib: relax FV address check Ard Biesheuvel
@ 2018-06-13 16:28 ` Ard Biesheuvel
  2018-06-13 18:56 ` [PATCH edk2-platforms v2 0/2]DeveloperBox: prepare for expanding the capsule payload Leif Lindholm
  2 siblings, 0 replies; 5+ messages in thread
From: Ard Biesheuvel @ 2018-06-13 16:28 UTC (permalink / raw)
  To: edk2-devel; +Cc: leif.lindholm, Ard Biesheuvel

In order to allow for more flexibility when updating parts of the
firmware via capsule update, expand the description of the code FV
to cover the entire 4 MB region at the base of the NOR flash.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 Silicon/Socionext/SynQuacer/Library/NorFlashSynQuacerLib/NorFlashSynQuacer.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/Silicon/Socionext/SynQuacer/Library/NorFlashSynQuacerLib/NorFlashSynQuacer.c b/Silicon/Socionext/SynQuacer/Library/NorFlashSynQuacerLib/NorFlashSynQuacer.c
index 816d8ba33f8c..d44fe3e4e94c 100644
--- a/Silicon/Socionext/SynQuacer/Library/NorFlashSynQuacerLib/NorFlashSynQuacer.c
+++ b/Silicon/Socionext/SynQuacer/Library/NorFlashSynQuacerLib/NorFlashSynQuacer.c
@@ -19,12 +19,20 @@
 
 #include <Platform/MemoryMap.h>
 
+#define FW_CODE_REGION_BASE SYNQUACER_SPI_NOR_BASE
+#define FW_CODE_REGION_SIZE (FW_ENV_REGION_BASE - FW_CODE_REGION_BASE)
+
+#define FW_ENV_REGION_BASE  FixedPcdGet32 (PcdFlashNvStorageVariableBase)
+#define FW_ENV_REGION_SIZE  (FixedPcdGet32 (PcdFlashNvStorageVariableSize) + \
+                             FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) + \
+                             FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize))
+
 STATIC NOR_FLASH_DESCRIPTION mNorFlashDevices[] = {
   {
     // UEFI code region
     SYNQUACER_SPI_NOR_BASE,                             // device base
-    FixedPcdGet64 (PcdFdBaseAddress),                   // region base
-    FixedPcdGet32 (PcdFdSize),                          // region size
+    FW_CODE_REGION_BASE,                                // region base
+    FW_CODE_REGION_SIZE,                                // region size
     SIZE_64KB,                                          // block size
     {
       0x19c118b0, 0xc423, 0x42be, { 0xb8, 0x0f, 0x70, 0x6f, 0x1f, 0xcb, 0x59, 0x9a }
@@ -33,10 +41,8 @@ STATIC NOR_FLASH_DESCRIPTION mNorFlashDevices[] = {
   {
     // Environment variable region
     SYNQUACER_SPI_NOR_BASE,                             // device base
-    FixedPcdGet32 (PcdFlashNvStorageVariableBase),      // region base
-    FixedPcdGet32 (PcdFlashNvStorageVariableSize) +
-    FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) +
-    FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize),      // region size
+    FW_ENV_REGION_BASE,                                 // region base
+    FW_ENV_REGION_SIZE,                                 // region size
     SIZE_64KB,                                          // block size
     {
       0x3105bd7a, 0x82c3, 0x486f, { 0xb1, 0x03, 0x1e, 0x09, 0x54, 0xec, 0x85, 0x75 }
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH edk2-platforms v2 0/2]DeveloperBox: prepare for expanding the capsule payload
  2018-06-13 16:28 [PATCH edk2-platforms v2 0/2]DeveloperBox: prepare for expanding the capsule payload Ard Biesheuvel
  2018-06-13 16:28 ` [PATCH edk2-platforms v2 1/2] Silicon/SynQuacerPlatformFlashAccessLib: relax FV address check Ard Biesheuvel
  2018-06-13 16:28 ` [PATCH edk2-platforms v2 2/2] Silicon/NorFlashSynQuacerLib: describe entire firmware region as FV Ard Biesheuvel
@ 2018-06-13 18:56 ` Leif Lindholm
  2018-06-15 10:51   ` Ard Biesheuvel
  2 siblings, 1 reply; 5+ messages in thread
From: Leif Lindholm @ 2018-06-13 18:56 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: edk2-devel

On Wed, Jun 13, 2018 at 06:28:24PM +0200, Ard Biesheuvel wrote:
> We intend to start distributing firmware update capsules that include the SCP
> firmware partition. In order to allow for more flexibility regarding whether
> a capsule contains this piece or not, update the flash access routines and
> the flash partition descriptions so we can update any part of the first
> 4 MB, consisting of the CM3 bootstrap code, emergency flasher, pseudo
> EEPROM, SCP firmware, ARM-TF and UEFI.
> 
> Note that this means we can drop the 'TEMPORARY' patch I proposed a while
> ago to hack around this limitation.
> 
> Changes since v1:
> - use more parentheses in if () condition expression (#1)
> - use symbolic constants for code and env NOR regions (#2)

For the series:
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>


> Ard Biesheuvel (2):
>   Silicon/SynQuacerPlatformFlashAccessLib: relax FV address check
>   Silicon/NorFlashSynQuacerLib: describe entire firmware region as FV
> 
>  .../NorFlashSynQuacerLib/NorFlashSynQuacer.c  | 18 ++++--
>  .../SynQuacerPlatformFlashAccessLib.c         | 56 +++++++++----------
>  2 files changed, 39 insertions(+), 35 deletions(-)
> 
> -- 
> 2.17.1
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH edk2-platforms v2 0/2]DeveloperBox: prepare for expanding the capsule payload
  2018-06-13 18:56 ` [PATCH edk2-platforms v2 0/2]DeveloperBox: prepare for expanding the capsule payload Leif Lindholm
@ 2018-06-15 10:51   ` Ard Biesheuvel
  0 siblings, 0 replies; 5+ messages in thread
From: Ard Biesheuvel @ 2018-06-15 10:51 UTC (permalink / raw)
  To: Leif Lindholm; +Cc: edk2-devel@lists.01.org

On 13 June 2018 at 20:56, Leif Lindholm <leif.lindholm@linaro.org> wrote:
> On Wed, Jun 13, 2018 at 06:28:24PM +0200, Ard Biesheuvel wrote:
>> We intend to start distributing firmware update capsules that include the SCP
>> firmware partition. In order to allow for more flexibility regarding whether
>> a capsule contains this piece or not, update the flash access routines and
>> the flash partition descriptions so we can update any part of the first
>> 4 MB, consisting of the CM3 bootstrap code, emergency flasher, pseudo
>> EEPROM, SCP firmware, ARM-TF and UEFI.
>>
>> Note that this means we can drop the 'TEMPORARY' patch I proposed a while
>> ago to hack around this limitation.
>>
>> Changes since v1:
>> - use more parentheses in if () condition expression (#1)
>> - use symbolic constants for code and env NOR regions (#2)
>
> For the series:
> Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
>

Thanks

Pushed as 1cd14dea5fc1..fff2e99a5ee6

>
>> Ard Biesheuvel (2):
>>   Silicon/SynQuacerPlatformFlashAccessLib: relax FV address check
>>   Silicon/NorFlashSynQuacerLib: describe entire firmware region as FV
>>
>>  .../NorFlashSynQuacerLib/NorFlashSynQuacer.c  | 18 ++++--
>>  .../SynQuacerPlatformFlashAccessLib.c         | 56 +++++++++----------
>>  2 files changed, 39 insertions(+), 35 deletions(-)
>>
>> --
>> 2.17.1
>>


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-06-15 10:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-13 16:28 [PATCH edk2-platforms v2 0/2]DeveloperBox: prepare for expanding the capsule payload Ard Biesheuvel
2018-06-13 16:28 ` [PATCH edk2-platforms v2 1/2] Silicon/SynQuacerPlatformFlashAccessLib: relax FV address check Ard Biesheuvel
2018-06-13 16:28 ` [PATCH edk2-platforms v2 2/2] Silicon/NorFlashSynQuacerLib: describe entire firmware region as FV Ard Biesheuvel
2018-06-13 18:56 ` [PATCH edk2-platforms v2 0/2]DeveloperBox: prepare for expanding the capsule payload Leif Lindholm
2018-06-15 10:51   ` Ard Biesheuvel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox