[edk2] [PATCH v3 4/4] MdeModulePkg/CapsuleApp: Enhance CapsuleApp to support Capsule-on-Disk

2019-01-28 Thread Chen A Chen
BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=1482

CapsuleApp is used for trigger capsule update.
Add -OD option in CapsuleApp to support doing capsule update via storage.
Add -F and -L options to support dumping information feature.
Finish unit test for -F and -L options.
Already verify this feature on Denlow platform, success to update capsule
via hard disk with -OD option.

Cc: Jian J Wang 
Cc: Hao Wu 
Cc: Zhang Chao B 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
---
 MdeModulePkg/Application/CapsuleApp/CapsuleApp.c   | 155 +-
 MdeModulePkg/Application/CapsuleApp/CapsuleApp.inf |   8 +
 MdeModulePkg/Application/CapsuleApp/CapsuleDump.c  | 538 -
 3 files changed, 684 insertions(+), 17 deletions(-)

diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c 
b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
index 4d907242f3..258e6995bc 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
@@ -1,7 +1,7 @@
 /** @file
   A shell application that triggers capsule update process.
 
-  Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.
+  Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD 
License
   which accompanies this distribution.  The full text of the license may be 
found at
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -105,6 +106,44 @@ DumpEsrtData (
   VOID
   );
 
+/**
+  Dump Provisioned Capsule.
+
+  @param[in]  DumpCapsuleInfo  The flag to indicate whether to dump the 
capsule inforomation.
+**/
+VOID
+DumpProvisionedCapsule (
+  IN BOOLEAN  DumpCapsuleInfo
+  );
+
+/**
+  Dump all EFI System Partition.
+**/
+VOID
+DumpAllEfiSysPartition (
+  VOID
+  );
+
+/**
+  Process Capsule On Disk.
+
+  @param[in]  CapsuleBufferAn array of pointer to capsule images
+  @param[in]  FileSize An array of UINTN to capsule images size
+  @param[in]  OrgFileName  An array of orginal capsule images name
+  @param[in]  NewFileName  An array of new capsule images name
+  @param[in]  CapsuleNum   The count of capsule images
+
+  @retval EFI_SUCCESS   Capsule on disk success.
+**/
+EFI_STATUS
+ProcessCapsuleOnDisk (
+  IN VOID  **CapsuleBuffer,
+  IN UINTN *CapsuleBufferSize,
+  IN CHAR16**FilePath,
+  IN CHAR16*Map,
+  IN UINTN CapsuleNum
+  );
+
 /**
   Read a file.
 
@@ -799,19 +838,22 @@ PrintUsage (
   )
 {
   Print(L"CapsuleApp:  usage\n");
-  Print(L"  CapsuleApp  [-NR]\n");
+  Print(L"  CapsuleApp  [-NR] [-OD [FSx]]\n");
   Print(L"  CapsuleApp -S\n");
   Print(L"  CapsuleApp -C\n");
   Print(L"  CapsuleApp -P\n");
   Print(L"  CapsuleApp -E\n");
+  Print(L"  CapsuleApp -L\n");
+  Print(L"  CapsuleApp -L INFO\n");
+  Print(L"  CapsuleApp -F\n");
   Print(L"  CapsuleApp -G  -O \n");
   Print(L"  CapsuleApp -N  -O \n");
   Print(L"  CapsuleApp -D \n");
   Print(L"  CapsuleApp -P GET   -O \n");
   Print(L"Parameter:\n");
-  Print(L"  -NR: No reset will be triggered for the capsule with\n");
-  Print(L"   CAPSULE_FLAGS_PERSIST_ACROSS_RESET and without\n");
-  Print(L"   CAPSULE_FLAGS_INITIATE_RESET.\n");
+  Print(L"  -NR: No reset will be triggered for the capsule\n");
+  Print(L"   with CAPSULE_FLAGS_PERSIST_ACROSS_RESET and without 
CAPSULE_FLAGS_INITIATE_RESET.\n");
+  Print(L"  -OD: Delivery of Capsules via file on Mass Storage device.");
   Print(L"  -S:  Dump capsule report variable (EFI_CAPSULE_REPORT_GUID),\n");
   Print(L"   which is defined in UEFI specification.\n");
   Print(L"  -C:  Clear capsule report variable (EFI_CAPSULE_REPORT_GUID),\n");
@@ -820,6 +862,8 @@ PrintUsage (
   Print(L"   ImageTypeId and Index (decimal format) to a file if 'GET'\n");
   Print(L"   option is used.\n");
   Print(L"  -E:  Dump UEFI ESRT table info.\n");
+  Print(L"  -L:  Dump provisioned capsule image information.\n");
+  Print(L"  -F:  Dump all EFI System Partition.\n");
   Print(L"  -G:  Convert a BMP file to be an UX capsule,\n");
   Print(L"   according to Windows Firmware Update document\n");
   Print(L"  -N:  Append a Capsule Header to an existing FMP capsule image\n");
@@ -851,7 +895,7 @@ UefiMain (
 {
   EFI_STATUSStatus;
   RETURN_STATUS RStatus;
-  UINTN FileSize[MAX_CAPSULE_NUM];
+  UINTN CapsuleBufferSize[MAX_CAPSULE_NUM];
   VOID  *CapsuleBuffer[MAX_CAPSULE_NUM];
   EFI_CAPSULE_BLOCK_DESCRIPTOR  *BlockDescriptors;
   EFI_CAPSULE_HEADER*CapsuleHeaderArray[MAX_CAPSULE_NUM + 1];
@@ -859,9 +903,14 @@ UefiMain (
   EFI_RESET_TYPEResetType;
   BOOLEAN

[edk2] [PATCH v3 0/4] Introduce CapsuleApp patch v3

2019-01-28 Thread Chen A Chen
Fix Typo and code style issue, no any function change.
According to package owner's input, Split this patch to smaller granularity.

Chen A Chen (4):
  MdePkg/UefiSpec.h: Add definition to support Capsule-on-Disk feature
  MdeModulePkg/CapsuleApp: Add a function used to get next DevicePath
  MdeModulePkg/CapsuleApp: Add functions to support Capsule-on-Disk
  MdeModulePkg/CapsuleApp: Enhance CapsuleApp to support Capsule-on-Disk

 MdeModulePkg/Application/CapsuleApp/CapsuleApp.c   | 155 +++-
 MdeModulePkg/Application/CapsuleApp/CapsuleApp.inf |   8 +
 MdeModulePkg/Application/CapsuleApp/CapsuleDump.c  | 538 +-
 .../Application/CapsuleApp/CapsuleOnDisk.c | 806 +
 MdeModulePkg/Include/Library/UefiBootManagerLib.h  |  21 +-
 MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c   |  24 +-
 MdePkg/Include/Uefi/UefiSpec.h |   5 +
 7 files changed, 1538 insertions(+), 19 deletions(-)
 create mode 100644 MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c

-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH v3 3/4] MdeModulePkg/CapsuleApp: Add functions to support Capsule-on-Disk

2019-01-28 Thread Chen A Chen
BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=1482

This file provide some basic function to support Capsule-on-Disk.

Cc: Jian J Wang 
Cc: Hao Wu 
Cc: Zhang Chao B 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
---
 .../Application/CapsuleApp/CapsuleOnDisk.c | 806 +
 1 file changed, 806 insertions(+)
 create mode 100644 MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c

diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c 
b/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c
new file mode 100644
index 00..16ce9519b2
--- /dev/null
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c
@@ -0,0 +1,806 @@
+/** @file
+  Process Capsule On Disk.
+
+  Copyright (c) 2019, Intel Corporation. All rights reserved.
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD 
License
+  which accompanies this distribution.  The full text of the license may be 
found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+EFI_GUID mCapsuleOnDiskBootOptionGuid = { 0x4CC29BB7, 0x2413, 0x40A2, { 0xB0, 
0x6D, 0x25, 0x3E, 0x37, 0x10, 0xF5, 0x32 } };
+
+/**
+  Get shell protocol.
+
+  @return Pointer to shell protocol.
+
+**/
+EFI_SHELL_PROTOCOL *
+GetShellProtocol (
+  VOID
+  );
+
+/**
+  Get file name from file path.
+
+  @param  FilePathFile path.
+
+  @return Pointer to file name.
+
+**/
+CHAR16 *
+GetFileNameFromPath (
+  CHAR16*FilePath
+  )
+{
+  EFI_STATUSStatus;
+  EFI_SHELL_PROTOCOL*ShellProtocol;
+  SHELL_FILE_HANDLE Handle;
+  EFI_FILE_INFO *FileInfo;
+
+  ShellProtocol = GetShellProtocol ();
+  if (ShellProtocol == NULL) {
+return NULL;
+  }
+
+  //
+  // Open file by FileName.
+  //
+  Status = ShellProtocol->OpenFileByName (
+FilePath,
+&Handle,
+EFI_FILE_MODE_READ
+);
+  if (EFI_ERROR (Status)) {
+return NULL;
+  }
+
+  //
+  // Get file name from EFI_FILE_INFO.
+  //
+  FileInfo = ShellProtocol->GetFileInfo (Handle);
+  ShellProtocol->CloseFile (Handle);
+  if (FileInfo == NULL) {
+return NULL;
+  }
+
+  return FileInfo->FileName;
+}
+
+/**
+  Check if the device path is EFI system Partition.
+
+  @param  DevicePathThe ESP device path.
+
+  @retval TRUEDevicePath is a device path for ESP.
+  @retval FALSE   DevicePath is not a device path for ESP.
+
+**/
+BOOLEAN
+IsEfiSysPartitionDevicePath (
+  EFI_DEVICE_PATH_PROTOCOL   *DevicePath
+  )
+{
+  EFI_STATUS Status;
+  EFI_DEVICE_PATH_PROTOCOL   *TempDevicePath;
+  HARDDRIVE_DEVICE_PATH  *Hd;
+  EFI_HANDLE Handle;
+
+  //
+  // Check if the device path contains GPT node
+  //
+  TempDevicePath = DevicePath;
+
+  while (!IsDevicePathEnd (TempDevicePath)) {
+if ((DevicePathType (TempDevicePath) == MEDIA_DEVICE_PATH) &&
+  (DevicePathSubType (TempDevicePath) == MEDIA_HARDDRIVE_DP)) {
+  Hd = (HARDDRIVE_DEVICE_PATH *)TempDevicePath;
+  if (Hd->MBRType == MBR_TYPE_EFI_PARTITION_TABLE_HEADER) {
+break;
+  }
+}
+TempDevicePath = NextDevicePathNode (TempDevicePath);
+  }
+
+  if (!IsDevicePathEnd (TempDevicePath)) {
+//
+// Search for EFI system partition protocol on full device path in Boot 
Option
+//
+Status = gBS->LocateDevicePath (&gEfiPartTypeSystemPartGuid, &DevicePath, 
&Handle);
+return EFI_ERROR (Status) ? FALSE : TRUE;
+  } else {
+return FALSE;
+  }
+}
+
+/**
+  Dump all EFI System Partition.
+
+**/
+VOID
+DumpAllEfiSysPartition (
+  VOID
+  )
+{
+  EFI_HANDLE *SimpleFileSystemHandles;
+  UINTN  NumberSimpleFileSystemHandles;
+  UINTN  Index;
+  EFI_DEVICE_PATH_PROTOCOL   *DevicePath;
+  UINTN  NumberEfiSystemPartitions;
+  EFI_SHELL_PROTOCOL *ShellProtocol;
+
+  ShellProtocol = GetShellProtocol ();
+  NumberEfiSystemPartitions = 0;
+
+  Print (L"EFI System Partition list:\n");
+
+  gBS->LocateHandleBuffer (
+ ByProtocol,
+ &gEfiSimpleFileSystemProtocolGuid,
+ NULL,
+ &NumberSimpleFileSystemHandles,
+ &SimpleFileSystemHandles
+ );
+
+  for (Index = 0; Index < NumberSimpleFileSystemHandles; Index++) {
+DevicePath = DevicePathFromHandle (SimpleFileSystemHandles[Index]);
+if (IsEfiSysPartitionDevicePath (DevicePath)) {
+  NumberEfiSystemPartitions++;
+  Print(L"%s\n%s\n",

[edk2] [PATCH v3 1/4] MdePkg/UefiSpec.h: Add definition to support Capsule-on-Disk feature

2019-01-28 Thread Chen A Chen
BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=1482

UEFI Spec define this definition to support Capsule-on-Disk.

Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Zhang Chao B 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
---
 MdePkg/Include/Uefi/UefiSpec.h | 5 +
 1 file changed, 5 insertions(+)

diff --git a/MdePkg/Include/Uefi/UefiSpec.h b/MdePkg/Include/Uefi/UefiSpec.h
index 75af99de50..9d3d7a9a63 100644
--- a/MdePkg/Include/Uefi/UefiSpec.h
+++ b/MdePkg/Include/Uefi/UefiSpec.h
@@ -2201,6 +2201,11 @@ typedef struct {
   #error Unknown Processor Type
 #endif
 
+//
+// The directory within the active EFI System Partition defined for delivery 
of capsule to firmware
+//
+#define EFI_CAPSULE_FROM_FILE_DIRL"\\EFI\\UpdateCapsule\\"
+
 #include 
 #include 
 #include 
-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH v3 2/4] MdeModulePkg/CapsuleApp: Add a function used to get next DevicePath

2019-01-28 Thread Chen A Chen
BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=1482

Add a new function to support Capsule-on-Disk feature.
This function is used to get next full DevicePath from a load option.

Cc: Jian J Wang 
Cc: Hao Wu 
Cc: Zhang Chao B 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
---
 MdeModulePkg/Include/Library/UefiBootManagerLib.h | 21 +++-
 MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c  | 24 ++-
 2 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Include/Library/UefiBootManagerLib.h 
b/MdeModulePkg/Include/Library/UefiBootManagerLib.h
index bfc0cb86f8..64347ff160 100644
--- a/MdeModulePkg/Include/Library/UefiBootManagerLib.h
+++ b/MdeModulePkg/Include/Library/UefiBootManagerLib.h
@@ -1,7 +1,7 @@
 /** @file
   Provide Boot Manager related library APIs.
 
-Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) 2011 - 2019, Intel Corporation. All rights reserved.
 (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD 
License
@@ -445,6 +445,25 @@ EfiBootManagerGetBootManagerMenu (
   EFI_BOOT_MANAGER_LOAD_OPTION *BootOption
   );
 
+/**
+  Get the next possible full path pointing to the load option.
+  The routine doesn't guarantee the returned full path points to an existing
+  file, and it also doesn't guarantee the existing file is a valid load option.
+  BmGetNextLoadOptionBuffer() guarantees.
+
+  @param FilePath  The device path pointing to a load option.
+   It could be a short-form device path.
+  @param FullPath  The full path returned by the routine in last call.
+   Set to NULL in first call.
+
+  @return The next possible full path pointing to the load option.
+  Caller is responsible to free the memory.
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EfiBootManagerGetNextFullDevicePath (
+  IN  EFI_DEVICE_PATH_PROTOCOL  *FilePath,
+  IN  EFI_DEVICE_PATH_PROTOCOL  *FullPath
+  );
 
 /**
   Get the load option by its device path.
diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c 
b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
index 6a23477eb8..684d7b8b1b 100644
--- a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
@@ -1,7 +1,7 @@
 /** @file
   Library functions which relates with booting.
 
-Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) 2011 - 2019, Intel Corporation. All rights reserved.
 (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD 
License
@@ -2461,3 +2461,25 @@ EfiBootManagerGetBootManagerMenu (
   }
 }
 
+/**
+  Get the next possible full path pointing to the load option.
+  The routine doesn't guarantee the returned full path points to an existing
+  file, and it also doesn't guarantee the existing file is a valid load option.
+  BmGetNextLoadOptionBuffer() guarantees.
+
+  @param FilePath  The device path pointing to a load option.
+   It could be a short-form device path.
+  @param FullPath  The full path returned by the routine in last call.
+   Set to NULL in first call.
+
+  @return The next possible full path pointing to the load option.
+  Caller is responsible to free the memory.
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EfiBootManagerGetNextFullDevicePath (
+  IN  EFI_DEVICE_PATH_PROTOCOL  *FilePath,
+  IN  EFI_DEVICE_PATH_PROTOCOL  *FullPath
+  )
+{
+  return BmGetNextLoadOptionDevicePath(FilePath, FullPath);
+}
-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH v4 2/7] MdePkg/BaseLib: Introduce CharToUpper and AsciiToUpper publicly

2019-01-28 Thread Ni, Ruiyu

On 12/25/2018 4:17 PM, Shenglei Zhang wrote:

Introduce two public functions CharToUpper and AsciiToUpper.
They have the same functions as InternalCharToUpper and
InternalBaseLibAsciiToUpper.Considering the internal functions will
be removed,so directly I change their function names to the public ones'.
https://bugzilla.tianocore.org/show_bug.cgi?id=1369

Cc: Leif Lindholm 
Cc: Laszlo Ersek 
Cc: Michael D Kinney 
Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Shenglei Zhang 
---
  MdePkg/Include/Library/BaseLib.h| 40 +
  MdePkg/Library/BaseLib/SafeString.c |  8 +++---
  MdePkg/Library/BaseLib/String.c | 16 ++--
  3 files changed, 52 insertions(+), 12 deletions(-)

diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/BaseLib.h
index 1eb842384e..e8cc121ddd 100644
--- a/MdePkg/Include/Library/BaseLib.h
+++ b/MdePkg/Include/Library/BaseLib.h
@@ -2720,6 +2720,46 @@ AsciiStrnToUnicodeStrS (
OUT UINTN *DestinationLength
);
  
+/**

+  Convert a Unicode character to upper case only if
+  it maps to a valid small-case ASCII character.
+
+  This internal function only deal with Unicode character
+  which maps to a valid small-case ASCII character, i.e.
+  L'a' to L'z'. For other Unicode character, the input character
+  is returned directly.
+
+  @param  Char  The character to convert.
+
+  @retval LowerCharacter   If the Char is with range L'a' to L'z'.
+  @retval UnchangedOtherwise.
+
+**/
+CHAR16
+EFIAPI
+CharToUpper (
+  IN  CHAR16Char
+  );
+
+/**
+  Converts a lowercase Ascii character to upper one.
+
+  If Chr is lowercase Ascii character, then converts it to upper one.
+
+  If Value >= 0xA0, then ASSERT().
+  If (Value & 0x0F) >= 0x0A, then ASSERT().
+
+  @param  Chr   one Ascii character
+
+  @return The uppercase value of Ascii character
+
+**/
+CHAR8
+EFIAPI
+AsciiToUpper (
+  IN  CHAR8 Chr
+  );
+
  /**
Converts an 8-bit value to an 8-bit BCD value.
  
diff --git a/MdePkg/Library/BaseLib/SafeString.c b/MdePkg/Library/BaseLib/SafeString.c

index 417497cbc9..17f88b46d8 100644
--- a/MdePkg/Library/BaseLib/SafeString.c
+++ b/MdePkg/Library/BaseLib/SafeString.c
@@ -905,7 +905,7 @@ StrHexToUintnS (
  String++;
}
  
-  if (InternalCharToUpper (*String) == L'X') {

+  if (CharToUpper (*String) == L'X') {
  if (*(String - 1) != L'0') {
*Data = 0;
return RETURN_SUCCESS;
@@ -1036,7 +1036,7 @@ StrHexToUint64S (
  String++;
}
  
-  if (InternalCharToUpper (*String) == L'X') {

+  if (CharToUpper (*String) == L'X') {
  if (*(String - 1) != L'0') {
*Data = 0;
return RETURN_SUCCESS;
@@ -2459,7 +2459,7 @@ AsciiStrHexToUintnS (
  String++;
}
  
-  if (InternalBaseLibAsciiToUpper (*String) == 'X') {

+  if (AsciiToUpper (*String) == 'X') {
  if (*(String - 1) != '0') {
*Data = 0;
return RETURN_SUCCESS;
@@ -2586,7 +2586,7 @@ AsciiStrHexToUint64S (
  String++;
}
  
-  if (InternalBaseLibAsciiToUpper (*String) == 'X') {

+  if (AsciiToUpper (*String) == 'X') {
  if (*(String - 1) != '0') {
*Data = 0;
return RETURN_SUCCESS;
diff --git a/MdePkg/Library/BaseLib/String.c b/MdePkg/Library/BaseLib/String.c
index e6df12797d..dba53779c9 100644
--- a/MdePkg/Library/BaseLib/String.c
+++ b/MdePkg/Library/BaseLib/String.c
@@ -552,7 +552,7 @@ InternalIsDecimalDigitCharacter (
  **/
  CHAR16
  EFIAPI
-InternalCharToUpper (
+CharToUpper (
IN  CHAR16Char
)
  {
@@ -586,7 +586,7 @@ InternalHexCharToUintn (
  return Char - L'0';
}
  
-  return (10 + InternalCharToUpper (Char) - L'A');

+  return (10 + CharToUpper (Char) - L'A');
  }
  
  /**

@@ -1181,7 +1181,7 @@ AsciiStrCmp (
  **/
  CHAR8
  EFIAPI
-InternalBaseLibAsciiToUpper (
+AsciiToUpper (
IN  CHAR8 Chr
)
  {
@@ -1211,7 +1211,7 @@ InternalAsciiHexCharToUintn (
  return Char - '0';
}
  
-  return (10 + InternalBaseLibAsciiToUpper (Char) - 'A');

+  return (10 + AsciiToUpper (Char) - 'A');
  }
  
  
@@ -1260,13 +1260,13 @@ AsciiStriCmp (

ASSERT (AsciiStrSize (FirstString));
ASSERT (AsciiStrSize (SecondString));
  
-  UpperFirstString  = InternalBaseLibAsciiToUpper (*FirstString);

-  UpperSecondString = InternalBaseLibAsciiToUpper (*SecondString);
+  UpperFirstString  = AsciiToUpper (*FirstString);
+  UpperSecondString = AsciiToUpper (*SecondString);
while ((*FirstString != '\0') && (*SecondString != '\0') && 
(UpperFirstString == UpperSecondString)) {
  FirstString++;
  SecondString++;
-UpperFirstString  = InternalBaseLibAsciiToUpper (*FirstString);
-UpperSecondString = InternalBaseLibAsciiToUpper (*SecondString);
+UpperFirstString  = AsciiToUpper (*FirstString);
+UpperSecondString = AsciiToUpper (*SecondString);
}
  
return UpperFirstString - UpperSecondString;



Re: [edk2] [PATCH v3] MdePkg/BaseLib: Add Base64Encode() and Base64Decode()

2019-01-28 Thread Ni, Ruiyu

On 1/29/2019 2:53 PM, Shenglei Zhang wrote:

From: Mike Turner 

Introduce public functions Base64Encode and Base64Decode.
https://bugzilla.tianocore.org/show_bug.cgi?id=1370

v2:1.Remove some white space.
2.Add unit test with test vectors in RFC 4648.
  https://github.com/shenglei10/edk2/tree/encode_test
  https://github.com/shenglei10/edk2/tree/decode_test

v3:1.Align white space.
2.Update comments of Base64Encode and Base64Decode.
3.Change the use of macro RETURN_DEVICE_ERROR to
  RETURN_INVALID_PARAMETER in string.c.

Cc: Michael D Kinney 
Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Shenglei Zhang 
---
  MdePkg/Include/Library/BaseLib.h |  56 +
  MdePkg/Library/BaseLib/String.c  | 344 +++
  2 files changed, 400 insertions(+)

diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/BaseLib.h
index e8cc121ddd..1d0751c2fc 100644
--- a/MdePkg/Include/Library/BaseLib.h
+++ b/MdePkg/Include/Library/BaseLib.h
@@ -2760,6 +2760,62 @@ AsciiToUpper (
IN  CHAR8 Chr
);
  
+/**

+  Convert binary data to a Base64 encoded ascii string based on RFC4648.
+
+  Produce a Null-terminated Ascii string in the output buffer specified by 
AsciiPtr and AsciiSize.
+  The Ascii string is produced by converting the data string specified by 
DataPtr and DataLen.
+
+  @param DataPtr Input UINT8 data
+  @param DataLen Number of UINT8 bytes of data
+  @param AsciiPtrPointer to output string buffer
+  @param AsciiSize   Size of ascii buffer. Set to 0 to get the size needed.
+ Caller is responsible for passing in buffer of AsciiSize
+
+  @retval RETURN_SUCCESS When ascii buffer is filled in.
+  @retval RETURN_INVALID_PARAMETER   If DataPtr is NULL or AsciiSize is NULL.
+  @retval RETURN_INVALID_PARAMETER   If DataLen or AsciiSize is bigger than 
(MAX_ADDRESS - (UINTN)DataPtr/AsciiPtr).
+  @retval RETURN_BUFFER_TOO_SMALLIf DataLen is 0 and AsciiSize is <1.
+  @retval RETURN_BUFFER_TOO_SMALLIf AsciiPtr is NULL or AsciiSize is 
smaller than required buffersize.
+
+**/
+RETURN_STATUS
+EFIAPI
+Base64Encode (
+  IN  CONST UINT8  *DataPtr,
+  INUINTN   DataLen,
+  OUT   CHAR8  *AsciiPtr  OPTIONAL,
+  IN OUTUINTN  *AsciiSize
+  );
+
+/**
+  Convert Base64 ascii string to binary data based on RFC4648.
+
+  Produce Null-terminated binary data in the output buffer specified by BinPtr 
and BinSize.
+  The binary data is produced by converting the Base64 ascii string specified 
by DataPtr and DataLen.
+
+  @param DataPtr  Input ASCII characters
+  @param DataLen  Number of ASCII characters
+  @param BinPtr   Pointer to output buffer
+  @param BinSize  Caller is responsible for passing in buffer of at least 
BinSize.
+  Set 0 to get the size needed. Set to bytes stored on 
return.
+
+  @retval RETURN_SUCCESS When binary buffer is filled in.
+  @retval RETURN_INVALID_PARAMETER   If DataPtr is NULL or BinSize is NULL.
+  @retval RETURN_INVALID_PARAMETER   If DataLen or BinSize is bigger than 
(MAX_ADDRESS -(UINTN)DataPtr/BinPtr ).
+  @retval RETURN_INVALID_PARAMETER   If there is any invalid character in 
input stream.
+  @retval RETURN_BUFFER_TOO_SMALLIf buffer length is smaller than required 
buffer size.
+
+ **/
+RETURN_STATUS
+EFIAPI
+Base64Decode (
+  IN  CONST CHAR8  *DataPtr,
+  INUINTN   DataLen,
+  OUT   UINT8  *BinPtr  OPTIONAL,
+  IN OUTUINTN  *BinSize
+  );
+
  /**
Converts an 8-bit value to an 8-bit BCD value.
  
diff --git a/MdePkg/Library/BaseLib/String.c b/MdePkg/Library/BaseLib/String.c

index dba53779c9..2a5c03db04 100644
--- a/MdePkg/Library/BaseLib/String.c
+++ b/MdePkg/Library/BaseLib/String.c
@@ -1188,6 +1188,350 @@ AsciiToUpper (
return (UINT8) ((Chr >= 'a' && Chr <= 'z') ? Chr - ('a' - 'A') : Chr);
  }
  
+//

+// The basis for Base64 encoding is RFC 4686 
https://tools.ietf.org/html/rfc4648
+//
+// RFC 4686 has a number of MAY and SHOULD cases.  This implementation chooses
+// the more restrictive versions for security concerns (see RFC 4686 section 
3.3).
+//
+// A invalid character, if encountered during the decode operation, causes the 
data
+// to be rejected. In addition, the '=' padding character is only allowed at 
the end
+// of the Base64 encoded string.
+//
+#define BAD_V  99
+
+STATIC CHAR8 Encoding_table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+"abcdefghijklmnopqrstuvwxyz"
+"0123456789+/";
+
+STATIC UINT8 Decoding_table[] = {
+  //
+  // Valid characters 
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
+  // Also, set '=' as a zero for decoding
+  // 0  ,1,   2,   3,4,   5,   
 6,   7,   8,9,   a,b,  
  c,   d,e,f
+

[edk2] [PATCH v3] MdePkg/BaseLib: Add Base64Encode() and Base64Decode()

2019-01-28 Thread Shenglei Zhang
From: Mike Turner 

Introduce public functions Base64Encode and Base64Decode.
https://bugzilla.tianocore.org/show_bug.cgi?id=1370

v2:1.Remove some white space.
   2.Add unit test with test vectors in RFC 4648.
 https://github.com/shenglei10/edk2/tree/encode_test
 https://github.com/shenglei10/edk2/tree/decode_test

v3:1.Align white space.
   2.Update comments of Base64Encode and Base64Decode.
   3.Change the use of macro RETURN_DEVICE_ERROR to
 RETURN_INVALID_PARAMETER in string.c.

Cc: Michael D Kinney 
Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Shenglei Zhang 
---
 MdePkg/Include/Library/BaseLib.h |  56 +
 MdePkg/Library/BaseLib/String.c  | 344 +++
 2 files changed, 400 insertions(+)

diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/BaseLib.h
index e8cc121ddd..1d0751c2fc 100644
--- a/MdePkg/Include/Library/BaseLib.h
+++ b/MdePkg/Include/Library/BaseLib.h
@@ -2760,6 +2760,62 @@ AsciiToUpper (
   IN  CHAR8 Chr
   );
 
+/**
+  Convert binary data to a Base64 encoded ascii string based on RFC4648.
+
+  Produce a Null-terminated Ascii string in the output buffer specified by 
AsciiPtr and AsciiSize.
+  The Ascii string is produced by converting the data string specified by 
DataPtr and DataLen.
+
+  @param DataPtr Input UINT8 data
+  @param DataLen Number of UINT8 bytes of data
+  @param AsciiPtrPointer to output string buffer
+  @param AsciiSize   Size of ascii buffer. Set to 0 to get the size needed.
+ Caller is responsible for passing in buffer of AsciiSize
+
+  @retval RETURN_SUCCESS When ascii buffer is filled in.
+  @retval RETURN_INVALID_PARAMETER   If DataPtr is NULL or AsciiSize is NULL.
+  @retval RETURN_INVALID_PARAMETER   If DataLen or AsciiSize is bigger than 
(MAX_ADDRESS - (UINTN)DataPtr/AsciiPtr).
+  @retval RETURN_BUFFER_TOO_SMALLIf DataLen is 0 and AsciiSize is <1.
+  @retval RETURN_BUFFER_TOO_SMALLIf AsciiPtr is NULL or AsciiSize is 
smaller than required buffersize.
+
+**/
+RETURN_STATUS
+EFIAPI
+Base64Encode (
+  IN  CONST UINT8  *DataPtr,
+  INUINTN   DataLen,
+  OUT   CHAR8  *AsciiPtr  OPTIONAL,
+  IN OUTUINTN  *AsciiSize
+  );
+
+/**
+  Convert Base64 ascii string to binary data based on RFC4648.
+
+  Produce Null-terminated binary data in the output buffer specified by BinPtr 
and BinSize.
+  The binary data is produced by converting the Base64 ascii string specified 
by DataPtr and DataLen.
+
+  @param DataPtr  Input ASCII characters
+  @param DataLen  Number of ASCII characters
+  @param BinPtr   Pointer to output buffer
+  @param BinSize  Caller is responsible for passing in buffer of at least 
BinSize.
+  Set 0 to get the size needed. Set to bytes stored on 
return.
+
+  @retval RETURN_SUCCESS When binary buffer is filled in.
+  @retval RETURN_INVALID_PARAMETER   If DataPtr is NULL or BinSize is NULL.
+  @retval RETURN_INVALID_PARAMETER   If DataLen or BinSize is bigger than 
(MAX_ADDRESS -(UINTN)DataPtr/BinPtr ).
+  @retval RETURN_INVALID_PARAMETER   If there is any invalid character in 
input stream.
+  @retval RETURN_BUFFER_TOO_SMALLIf buffer length is smaller than required 
buffer size.
+
+ **/
+RETURN_STATUS
+EFIAPI
+Base64Decode (
+  IN  CONST CHAR8  *DataPtr,
+  INUINTN   DataLen,
+  OUT   UINT8  *BinPtr  OPTIONAL,
+  IN OUTUINTN  *BinSize
+  );
+
 /**
   Converts an 8-bit value to an 8-bit BCD value.
 
diff --git a/MdePkg/Library/BaseLib/String.c b/MdePkg/Library/BaseLib/String.c
index dba53779c9..2a5c03db04 100644
--- a/MdePkg/Library/BaseLib/String.c
+++ b/MdePkg/Library/BaseLib/String.c
@@ -1188,6 +1188,350 @@ AsciiToUpper (
   return (UINT8) ((Chr >= 'a' && Chr <= 'z') ? Chr - ('a' - 'A') : Chr);
 }
 
+//
+// The basis for Base64 encoding is RFC 4686 
https://tools.ietf.org/html/rfc4648
+//
+// RFC 4686 has a number of MAY and SHOULD cases.  This implementation chooses
+// the more restrictive versions for security concerns (see RFC 4686 section 
3.3).
+//
+// A invalid character, if encountered during the decode operation, causes the 
data
+// to be rejected. In addition, the '=' padding character is only allowed at 
the end
+// of the Base64 encoded string.
+//
+#define BAD_V  99
+
+STATIC CHAR8 Encoding_table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+"abcdefghijklmnopqrstuvwxyz"
+"0123456789+/";
+
+STATIC UINT8 Decoding_table[] = {
+  //
+  // Valid characters 
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
+  // Also, set '=' as a zero for decoding
+  // 0  ,1,   2,   3,4,   5,   
 6,   7,   8,9,   a,b,  
  c,   d,e,f
+  BAD_V,  BAD_V,  BAD_V,  BAD_V,  BAD_V,  BAD_V,  BAD_V,  BAD_V,  B

[edk2] [RFC] Proposal to split Pkgs

2019-01-28 Thread Ni, Ray
Hello,
I'd like to propose to split today's BIG packages in following ways:

==Overview =

1. Separate Industry standard definitions from UEFI and PI interfaces.
2. Separate UEFI and PI interfaces from implementations.
a. Separate UEFI and PI interfaces to different packages
b. Separate PI PEI, DXE and MM phase interfaces to different packages
3. Separate different features into feature packages.
Feature interface may be in the feature package to provide minimal
common interface packages.

The POC code is in https://github.com/jyao1/edk2/tree/ReOrg.
It basically split the EDKII common code to three directories:
Core/, Device/, and Feature/.
The code is in very early POC phase and only code in Core/ directory
can pass the build.
I would like to gather feedbacks through this RFC to see whether
this splitting direction makes sense.
Is there any other better ways of splitting?
Or perhaps do not split in such a small granularity?
Or perhaps Mike's work to move lib-c content to edk2-libc repo,
to move real platform code to edk2-platform repo is enough for
now?

==More explanations =

There are 9 packages inside Core/ directory:
1. BasePkg
Contains industry standard definitions (exclude UEFI and PI) and base
libraries that non-UEFI and non-PI development can depend on.
UEFI or PI development can also depend on this package.
2. UefiPkg
Contains UEFI interfaces and libraries that UEFI driver-model driver
development can depend on.
3. PiPeiPkg
Contains PI interfaces and libraries for PEI phase that PEI module
development can depend on.
4. PiDxePkg
Contains PI interfaces and libraries for DXE phase that DXE module
development can depend on.
5. PiMmPkg
Contains PI interfaces and libraries for MM phase that MM/SMM
module development can depend on.
6. MdeModulePkg (TianoPkg? Name is still TBD)
Contains Tiano implementation specific interfaces and libraries.
Developing modules for pure UEFI or PI should not depend on this package.
7. PeiFoundationPkg
Contains the PEI foundation modules (PeiCore and DxeIpl) and supported
libraries.
8. DxeFoundationPkg
Contains the DXE foundation modules (DxeCore and RuntimeDxe) and
supported libraries.
9. SmmFoundationPkg
Contains the SMM foundation modules (SmmCore, SmmIpl and
SmmCommunicationBuffer) and supported libraries.

These packages are positioned in different layers. The package in higher
layer depends on all packages that are in lower layers.
Layer 0: BasePkg.
Layer 1: UefiPkg.
Layer 2: PiPeiPkg 
Layer 3: PiDxePkg
Layer 4: PiMmPkg
Layer 5: MdeModulePkg (TianoPkg?)

All other modules are put to small packages under Device/ or Feature/.

== Benefit of this proposal =

This helps to reduce the size of each package, especially the very BIG
MdeModulePkg which contains almost all edk2 modules (except
CPU, network, etc). So platform can use git sparse checkout feature
to only clone the needed code still in package granularity.
This also helps to separate the code maintenance to more expert
developers. MdeModulePkg is just too huge to be maintained by 2 or 3
developers.

Thanks,
Ray
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH edk2-platforms 02/41] Silicon/NXP : Add support for Watchdog driver

2019-01-28 Thread Meenakshi Aggarwal



> -Original Message-
> From: Leif Lindholm 
> Sent: Monday, December 17, 2018 11:06 PM
> To: Meenakshi Aggarwal 
> Cc: ard.biesheu...@linaro.org; michael.d.kin...@intel.com; edk2-
> de...@lists.01.org; Udit Kumar ; Varun Sethi
> 
> Subject: Re: [PATCH edk2-platforms 02/41] Silicon/NXP : Add support for
> Watchdog driver
> 
> Starting with this one, since that was the biggest pain point last time 
> around.
> 
> On Wed, Nov 28, 2018 at 08:31:16PM +0530, Meenakshi Aggarwal wrote:
> > Installs watchdog timer arch protocol
> 
> As per the email I just cc:d you on: unless the hardware supports 
> configuration in
> a mode where it could be used for a compliant
> EFI_WATCHDOG_TIMER_ARCH_PROTOCOL (i.e., trigger a software event rather
> than a hardware reset), please rewrite this driver such that it does not 
> register as
> that protocol.
> 
Decided to use watchdog driver from MdeModulePkg.

> > Contributed-under: TianoCore Contribution Agreement 1.1
> > Signed-off-by: Meenakshi Aggarwal 
> > ---
> >  Silicon/NXP/Drivers/WatchDog/WatchDog.c  | 402
> +++
> >  Silicon/NXP/Drivers/WatchDog/WatchDog.h  |  39 +++
> >  Silicon/NXP/Drivers/WatchDog/WatchDogDxe.inf |  47 
> >  3 files changed, 488 insertions(+)
> >  create mode 100644 Silicon/NXP/Drivers/WatchDog/WatchDog.c
> >  create mode 100644 Silicon/NXP/Drivers/WatchDog/WatchDog.h
> >  create mode 100644 Silicon/NXP/Drivers/WatchDog/WatchDogDxe.inf
> 
> I would appreciate if you could follow
> https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.
> com%2Ftianocore%2Ftianocore.github.io%2Fwiki%2FLaszlo%27s-unkempt-git-
> guide-for-edk2-contributors-and-maintainers%23contrib-
> 23&data=02%7C01%7Cmeenakshi.aggarwal%40nxp.com%7Cc5cb603bead
> b4855f07608d6644624a1%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0
> %7C636806649758902154&sdata=NSs8taX%2F4oV0yhHmNEWVR%2Btzp3
> TqzuLnIy97t2R8dvs%3D&reserved=0
> when submitting the next revision. It greatly assists with reviewing.
> 
Ok, will do.

> > diff --git a/Silicon/NXP/Drivers/WatchDog/WatchDog.c
> > b/Silicon/NXP/Drivers/WatchDog/WatchDog.c
> > new file mode 100644
> > index 000..1b1a3b5
> > --- /dev/null
> > +++ b/Silicon/NXP/Drivers/WatchDog/WatchDog.c
> > @@ -0,0 +1,402 @@
> > +/** WatchDog.c
> > +*
> > +*  Based on Watchdog driver implemenation available in
> > +*  ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805Watchdog.c
> > +*
> > +*  Copyright 2017 NXP
> 
> May want to change this to 2017-2018
> Also, format should be
> Copyright (c) ... NXP. All rights reserved.
> 
Will change the year to 2017-2019,
but I cant add (c) as it will not be approved by NXP's TAs.
 
> > +*
> > +*  This program and the accompanying materials
> > +*  are licensed and made available under the terms and conditions of
> > +the BSD License
> > +*  which accompanies this distribution.  The full text of the license
> > +may be found at
> > +*
> > +https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fope
> > +nsource.org%2Flicenses%2Fbsd-
> license.php&data=02%7C01%7Cmeenakshi
> >
> +.aggarwal%40nxp.com%7Cc5cb603beadb4855f07608d6644624a1%7C686ea1d
> 3bc2b
> >
> +4c6fa92cd99c5c301635%7C0%7C0%7C636806649758902154&sdata=RLV
> E%2Bxi
> > +qQaQnHRKR7Spc6QYdx1pHPnKyqheLBqIinU4%3D&reserved=0
> > +*
> > +*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
> > +BASIS,
> > +*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
> EXPRESS OR IMPLIED.
> > +*
> > +**/
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include "WatchDog.h"
> > +
> > +STATIC EFI_EVENT  EfiExitBootServicesEvent; STATIC EFI_EVENT
> > +WdogFeedEvent;
> 
> m-prefix for both above please.
> 
> Can you do a search-and-replace Wdog -> Watchdog and WDOG -> WATCHDOG
> please?
> 
> > +STATIC MMIO_OPERATIONS_16 *mMmioOps;
> > +
> > +
> > +STATIC
> > +VOID
> > +WdogPing (
> > +  VOID
> > +  )
> > +{
> > +  //
> > +  // To reload a timeout value to the counter the proper service
> > +sequence begins by
> > +  // writing 0x_ followed by 0x_ to the Watchdog Service Register
> (WDOG_WSR).
> > +  // This service sequence will reload the counter with the timeout
> > +value WT[7:0] of
> > +  // Watchdog Control Register (WDOG_WCR).
> > +  //
> > +
> > +  mMmioOps->Write (PcdGet64 (PcdWdog1BaseAddr) +
> WDOG_WSR_OFFSET,
> > + WDOG_SERVICE_SEQ1);
> 
> The memory access operations really need to encode size.
> I would strongly prefer mMmioOps->Write16.
> 
> You could also tidy the call sites up with something like
> 
> #define WATCHDOG_ADDRESS(register) (PcdGet64 (PcdWdog1BaseAddr),
> WATCHDOG_ ## register ## _OFFSET)
> 
> So the invocation becomes
> 
>   mMmioOps->Write16 (WATCHDOG_ADDRESS (WSR),
> WATCHDOG_SERVICE_SEQ1);
> 
> 
> > +  mMmioOps->Write (PcdGet64 (PcdWdog1BaseAddr) +
> WDOG_WSR_OFFSET,
> > + WDOG_SERVICE_SEQ2); }
> > +
> > +/**
> > +  Stop the Wdog watchdog timer f

Re: [edk2] [PATCH 0/2] Add sanity check for FilePath device path

2019-01-28 Thread Wang, Jian J
Miss the test info:
- Boot shell
- Boot to Fedora 26 (Qemu/x64)
- Boot to Ubuntu 18.04 (Qemu/x64)
- Boot to Windows 10 (Qemu/x64)
- Boot to Windows 7 (Qemu/x64)

Regards,
Jian


> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Jian J
> Wang
> Sent: Tuesday, January 29, 2019 1:10 PM
> To: edk2-devel@lists.01.org
> Subject: [edk2] [PATCH 0/2] Add sanity check for FilePath device path
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1497
> 
> Jian J Wang (2):
>   MdePkg/UefiDevicePathLib: Add sanity check for FilePath device path
>   MdePkg/UefiDevicePathLibDevicePathProtocol: Add sanity check for
> FilePath device path
> 
>  MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c| 8 
>  .../UefiDevicePathLib.c   | 8 
>  2 files changed, 16 insertions(+)
> 
> --
> 2.19.0.windows.1
> 
> ___
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH v3 3/3] FatPkg: Add GPT check in FatPei to support Capsule-on-Disk feature.

2019-01-28 Thread Chen A Chen
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1470
This feature is used for finding GPT partition.
Follow the following step to check.
1) Check Protective MBR.
2) Check GPT primary/backup header.
3) Check GPT primary/backup entry array.

Cc: Ruiyu Ni 
Cc: Zhang Chao B 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
Reviewed-by: Hao Wu 
---
 FatPkg/FatPei/FatLitePeim.h |   3 +-
 FatPkg/FatPei/FatPei.inf|   3 +
 FatPkg/FatPei/Gpt.c | 548 
 FatPkg/FatPei/Part.c|  36 ++-
 4 files changed, 585 insertions(+), 5 deletions(-)
 create mode 100644 FatPkg/FatPei/Gpt.c

diff --git a/FatPkg/FatPei/FatLitePeim.h b/FatPkg/FatPei/FatLitePeim.h
index fbf887da5f..82ab045f2a 100644
--- a/FatPkg/FatPei/FatLitePeim.h
+++ b/FatPkg/FatPei/FatLitePeim.h
@@ -1,7 +1,7 @@
 /** @file
   Data structures for FAT recovery PEIM
 
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
 
 This program and the accompanying materials are licensed and made available
 under the terms and conditions of the BSD License which accompanies this
@@ -27,6 +27,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER 
EXPRESS OR IMPLIED.
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/FatPkg/FatPei/FatPei.inf b/FatPkg/FatPei/FatPei.inf
index 57312a9047..050bc4e157 100644
--- a/FatPkg/FatPei/FatPei.inf
+++ b/FatPkg/FatPei/FatPei.inf
@@ -31,6 +31,7 @@
 
 [Sources]
   Mbr.c
+  Gpt.c
   Eltorito.c
   Part.c
   FatLiteApi.c
@@ -49,6 +50,7 @@
 [LibraryClasses]
   PcdLib
   BaseMemoryLib
+  MemoryAllocationLib
   PeimEntryPoint
   BaseLib
   DebugLib
@@ -61,6 +63,7 @@
   gRecoveryOnFatIdeDiskGuid   ## SOMETIMES_CONSUMES   ## 
UNDEFINED
   gRecoveryOnFatFloppyDiskGuid## SOMETIMES_CONSUMES   ## 
UNDEFINED
   gRecoveryOnFatNvmeDiskGuid  ## SOMETIMES_CONSUMES   ## 
UNDEFINED
+  gEfiPartTypeUnusedGuid  ## SOMETIMES_CONSUMES   ## 
UNDEFINED
 
 
 [Ppis]
diff --git a/FatPkg/FatPei/Gpt.c b/FatPkg/FatPei/Gpt.c
new file mode 100644
index 00..c3afb668d7
--- /dev/null
+++ b/FatPkg/FatPei/Gpt.c
@@ -0,0 +1,548 @@
+/** @file
+  Routines supporting partition discovery and
+  logical device reading
+
+Copyright (c) 2019 Intel Corporation. All rights reserved.
+
+This program and the accompanying materials are licensed and made available
+under the terms and conditions of the BSD License which accompanies this
+distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include 
+#include 
+#include 
+#include "FatLitePeim.h"
+
+//
+// Assumption: 'a' and 'blocksize' are all UINT32 or UINT64.
+// If 'a' and 'blocksize' are not the same type, should use DivU64xU32 to 
calculate.
+//
+#define EFI_SIZE_TO_BLOCKS(a, blocksize)  (((a) / (blocksize)) + (((a) % 
(blocksize)) ? 1 : 0))
+
+//
+// GPT Partition Entry Status
+//
+typedef struct {
+  BOOLEAN OutOfRange;
+  BOOLEAN Overlap;
+  BOOLEAN OsSpecific;
+} EFI_PARTITION_ENTRY_STATUS;
+
+/**
+  Check if the CRC field in the Partition table header is valid.
+
+  @param[in]  PartHeader  Partition table header structure
+
+  @retval TRUE  the CRC is valid
+  @retval FALSE the CRC is invalid
+
+**/
+BOOLEAN
+PartitionCheckGptHeaderCRC (
+  IN  EFI_PARTITION_TABLE_HEADER  *PartHeader
+  )
+{
+  UINT32  GptHdrCrc;
+  UINT32  Crc;
+
+  GptHdrCrc = PartHeader->Header.CRC32;
+
+  //
+  // Set CRC field to zero when doing calcuation
+  //
+  PartHeader->Header.CRC32 = 0;
+
+  Crc = CalculateCrc32 (PartHeader, PartHeader->Header.HeaderSize);
+
+  //
+  // Restore Header CRC
+  //
+  PartHeader->Header.CRC32 = GptHdrCrc;
+
+  return (GptHdrCrc == Crc);
+}
+
+
+/**
+  Check if the CRC field in the Partition table header is valid
+  for Partition entry array.
+
+  @param[in]  PartHeader  Partition table header structure
+  @param[in]  PartEntry   The partition entry array
+
+  @retval TRUE  the CRC is valid
+  @retval FALSE the CRC is invalid
+
+**/
+BOOLEAN
+PartitionCheckGptEntryArrayCRC (
+  IN  EFI_PARTITION_TABLE_HEADER *PartHeader,
+  IN  EFI_PARTITION_ENTRY*PartEntry
+  )
+{
+  UINT32  Crc;
+  UINTN   Size;
+
+  Size = (UINTN)MultU64x32(PartHeader->NumberOfPartitionEntries, 
PartHeader->SizeOfPartitionEntry);
+  Crc  = CalculateCrc32 (PartEntry, Size);
+
+  return (BOOLEAN) (PartHeader->PartitionEntryArrayCRC32 == Crc);
+}
+
+/**
+  The function is used for valid GPT table. Both for Primary and Backup GPT 
header.
+
+  @param[in]  PrivateData   The global memory map
+  @param[in]  ParentBlockDevNo  The parent block device
+  @param[in]  IsPrimaryHeader   Indicate to which header will 

[edk2] [PATCH v2 0/3] FatPkg/GPT: Introduce GPT patch v3

2019-01-28 Thread Chen A Chen
No function change, fix code style issue.

Chen A Chen (3):
  FatPkg: Break down Part.c file.
  MdePkg/UefiGpt.h: Add new definition for enable GPT support
  FatPkg: Add GPT check in FatPei to support Capsule-on-Disk feature.

 FatPkg/FatPei/Eltorito.c  | 239 ++
 FatPkg/FatPei/FatLitePeim.h   |   3 +-
 FatPkg/FatPei/FatPei.inf  |   7 +-
 FatPkg/FatPei/Gpt.c   | 548 ++
 FatPkg/FatPei/Mbr.c   | 181 ++
 FatPkg/FatPei/Part.c  | 434 +++--
 MdePkg/Include/Uefi/UefiGpt.h |   6 +-
 7 files changed, 1020 insertions(+), 398 deletions(-)
 create mode 100644 FatPkg/FatPei/Eltorito.c
 create mode 100644 FatPkg/FatPei/Gpt.c
 create mode 100644 FatPkg/FatPei/Mbr.c

-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH v3 2/3] MdePkg/UefiGpt.h: Add new definition for enable GPT support

2019-01-28 Thread Chen A Chen
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1470

This definition comes from UEFI Spec to support GPT in FatPei driver.

Cc: Liming Gao 
Cc: Michael D Kinney 
Cc: Zhang Chao B 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
Reviewed-by: Liming Gao 
---
 MdePkg/Include/Uefi/UefiGpt.h | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/MdePkg/Include/Uefi/UefiGpt.h b/MdePkg/Include/Uefi/UefiGpt.h
index f635b05390..e4e919beaf 100644
--- a/MdePkg/Include/Uefi/UefiGpt.h
+++ b/MdePkg/Include/Uefi/UefiGpt.h
@@ -1,7 +1,7 @@
 /** @file
   EFI Guid Partition Table Format Definition.
 
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
 This program and the accompanying materials are licensed and made available 
under
 the terms and conditions of the BSD License that accompanies this distribution.
 The full text of the license may be found at
@@ -24,6 +24,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER 
EXPRESS OR IMPLIED.
 /// EFI Partition Table Signature: "EFI PART".
 ///
 #define EFI_PTAB_HEADER_ID  SIGNATURE_64 ('E','F','I',' ','P','A','R','T')
+///
+/// Minimum bytes reserve for EFI entry array buffer.
+///
+#define EFI_GPT_PART_ENTRY_MIN_SIZE 16384
 
 #pragma pack(1)
 
-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH v3 1/3] FatPkg: Break down Part.c file.

2019-01-28 Thread Chen A Chen
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1470
Break down partition parsing logic to 2 parts, Eltorito and MBR.

Cc: Ruiyu Ni 
Cc: Zhang Chao B 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
Reviewed-by: Hao Wu 
---
 FatPkg/FatPei/Eltorito.c | 239 
 FatPkg/FatPei/FatPei.inf |   4 +-
 FatPkg/FatPei/Mbr.c  | 181 +
 FatPkg/FatPei/Part.c | 402 ++-
 4 files changed, 432 insertions(+), 394 deletions(-)
 create mode 100644 FatPkg/FatPei/Eltorito.c
 create mode 100644 FatPkg/FatPei/Mbr.c

diff --git a/FatPkg/FatPei/Eltorito.c b/FatPkg/FatPei/Eltorito.c
new file mode 100644
index 00..a350237bd3
--- /dev/null
+++ b/FatPkg/FatPei/Eltorito.c
@@ -0,0 +1,239 @@
+/** @file
+  Routines supporting partition discovery and
+  logical device reading
+
+Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
+
+This program and the accompanying materials are licensed and made available
+under the terms and conditions of the BSD License which accompanies this
+distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include 
+#include "FatLitePeim.h"
+
+/**
+  This function finds Eltorito partitions. Main algorithm
+  is ported from DXE partition driver.
+
+  @param[in]  PrivateData   The global memory map
+  @param[in]  ParentBlockDevNo  The parent block device
+
+  @retval TRUE  New partitions are detected and logical block 
devices
+are added to block device array
+  @retval FALSE No new partitions are added
+
+**/
+BOOLEAN
+FatFindEltoritoPartitions (
+  IN  PEI_FAT_PRIVATE_DATA *PrivateData,
+  IN  UINTNParentBlockDevNo
+  )
+{
+  EFI_STATUS  Status;
+  BOOLEAN Found;
+  PEI_FAT_BLOCK_DEVICE*BlockDev;
+  PEI_FAT_BLOCK_DEVICE*ParentBlockDev;
+  UINT32  VolDescriptorLba;
+  UINT32  Lba;
+  CDROM_VOLUME_DESCRIPTOR *VolDescriptor;
+  ELTORITO_CATALOG*Catalog;
+  UINTN   Check;
+  UINTN   Index;
+  UINTN   MaxIndex;
+  UINT16  *CheckBuffer;
+  UINT32  SubBlockSize;
+  UINT32  SectorCount;
+  UINT32  VolSpaceSize;
+
+  if (ParentBlockDevNo > PEI_FAT_MAX_BLOCK_DEVICE - 1) {
+return FALSE;
+  }
+
+  Found   = FALSE;
+  ParentBlockDev  = &(PrivateData->BlockDevice[ParentBlockDevNo]);
+  VolSpaceSize= 0;
+
+  //
+  // CD_ROM has the fixed block size as 2048 bytes
+  //
+  if (ParentBlockDev->BlockSize != 2048) {
+return FALSE;
+  }
+
+  VolDescriptor = (CDROM_VOLUME_DESCRIPTOR *) PrivateData->BlockData;
+  Catalog   = (ELTORITO_CATALOG *) VolDescriptor;
+
+  //
+  // the ISO-9660 volume descriptor starts at 32k on the media
+  // and CD_ROM has the fixed block size as 2048 bytes, so...
+  //
+  VolDescriptorLba = 15;
+  //
+  // ((16*2048) / Media->BlockSize) - 1;
+  //
+  // Loop: handle one volume descriptor per time
+  //
+  while (TRUE) {
+
+VolDescriptorLba += 1;
+if (VolDescriptorLba > ParentBlockDev->LastBlock) {
+  //
+  // We are pointing past the end of the device so exit
+  //
+  break;
+}
+
+Status = FatReadBlock (
+  PrivateData,
+  ParentBlockDevNo,
+  VolDescriptorLba,
+  ParentBlockDev->BlockSize,
+  VolDescriptor
+  );
+if (EFI_ERROR (Status)) {
+  break;
+}
+//
+// Check for valid volume descriptor signature
+//
+if (VolDescriptor->Unknown.Type == CDVOL_TYPE_END ||
+CompareMem (VolDescriptor->Unknown.Id, CDVOL_ID, sizeof 
(VolDescriptor->Unknown.Id)) != 0
+) {
+  //
+  // end of Volume descriptor list
+  //
+  break;
+}
+//
+// Read the Volume Space Size from Primary Volume Descriptor 81-88 byte
+//
+if (VolDescriptor->Unknown.Type == CDVOL_TYPE_CODED) {
+  VolSpaceSize = VolDescriptor->PrimaryVolume.VolSpaceSize[1];
+}
+//
+// Is it an El Torito volume descriptor?
+//
+if (CompareMem (
+  VolDescriptor->BootRecordVolume.SystemId,
+  CDVOL_ELTORITO_ID,
+  sizeof (CDVOL_ELTORITO_ID) - 1
+  ) != 0) {
+  continue;
+}
+//
+// Read in the boot El Torito boot catalog
+//
+Lba = UNPACK_INT32 (VolDescriptor->BootRecordVolume.EltCatalog);
+if (Lba > ParentBlockDev->LastBlock) {
+  continue;
+}
+
+Status = FatReadBlock (
+  PrivateData,
+  ParentBlockDevNo,
+  Lba,
+  ParentBlockDev->BlockSize,
+  Catalog
+  );
+if (EFI_ERROR

Re: [edk2] [PATCH] MdePkg/BasePeCoffLib: skip runtime relocation if relocation info is invalid.

2019-01-28 Thread Bi, Dandan
Hi Neo,

Thank you very much for the patch.

Some minor comments
1) Besides the skip check in this patch, could you help to add additional  
check for RelocDir->Size before calling PeCoffLoaderImageAddress to calculate 
the RelocBase and RelocBaseEnd?
Since when RelocDir->Size==0, we can just return, don't need to do the 
calculation.

2) Please use the PatchCheck.py in edk2\BaseTools\Scripts to check the patch 
format before committing  the patch.
Can refer following link for more info:
https://github.com/tianocore/tianocore.github.io/wiki/Commit-Message-Format


Thanks,
Dandan

> -Original Message-
> From: Hsueh, Hong-chihX
> Sent: Tuesday, January 29, 2019 2:41 AM
> To: edk2-devel@lists.01.org
> Cc: Kinney, Michael D ; Gao, Liming
> ; Bi, Dandan ; Laszlo Ersek
> 
> Subject: [PATCH] MdePkg/BasePeCoffLib: skip runtime relocation if
> relocation info is invalid.
> 
> Skip runtime relocation for PE images that provide invalid relocation
> infomation
> (ex: RelocDir->Size = 0) to fix a hang observed while booting Windows.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> 
> Signed-off-by: Neo Hsueh 
> Cc: Michael D Kinney 
> Cc: Liming Gao 
> Cc: Dandan Bi 
> Cc: Laszlo Ersek 
> ---
>  MdePkg/Library/BasePeCoffLib/BasePeCoff.c | 6 ++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
> b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
> index 1bd079ad6a..f01c691dea 100644
> --- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
> +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
> @@ -1746,6 +1746,12 @@ PeCoffLoaderRelocateImageForRuntime (
>  
> RelocDir->VirtualAddress + RelocDir-
> >Size - 1,
>  0
>  
> );
> +if (RelocBase == NULL || RelocBaseEnd == NULL || RelocBaseEnd <
> RelocBase) {
> +  //
> +  // relocation block is not valid, just return
> +  //
> +  return;
> +}
>} else {
>  //
>  // Cannot find relocations, cannot continue to relocate the image, ASSERT
> for this invalid image.
> --
> 2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH 0/2] Add sanity check for FilePath device path

2019-01-28 Thread Jian J Wang
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1497

Jian J Wang (2):
  MdePkg/UefiDevicePathLib: Add sanity check for FilePath device path
  MdePkg/UefiDevicePathLibDevicePathProtocol: Add sanity check for
FilePath device path

 MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c| 8 
 .../UefiDevicePathLib.c   | 8 
 2 files changed, 16 insertions(+)

-- 
2.19.0.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH 1/2] MdePkg/UefiDevicePathLib: Add sanity check for FilePath device path

2019-01-28 Thread Jian J Wang
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1497

Current implementation of IsDevicePathValid() is not enough for type
of MEDIA_FILEPATH_DP, which has NULL-terminated string in the device
path. This patch add a simple NULL character check at Length position.

Cc: Liming Gao 
Cc: Ray Ni 
Cc: Michael D Kinney 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang 
---
 MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c 
b/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c
index 665e5a4adc..6d87744510 100644
--- a/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c
+++ b/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c
@@ -96,6 +96,14 @@ IsDevicePathValid (
 return FALSE;
   }
 }
+
+//
+// FilePath must be a NULL-terminated string.
+//
+if (DevicePathType (DevicePath) == MEDIA_FILEPATH_DP &&
+*(CHAR16 *)((UINT8 *)DevicePath + NodeLength - 2) != 0) {
+  return FALSE;
+}
   }
 
   //
-- 
2.19.0.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH 2/2] MdePkg/UefiDevicePathLibDevicePathProtocol: Add sanity check for FilePath device path

2019-01-28 Thread Jian J Wang
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1497

Current implementation of IsDevicePathValid() is not enough for type
of MEDIA_FILEPATH_DP, which has NULL-terminated string in the device
path. This patch add a simple NULL character check at Length position.

Cc: Liming Gao 
Cc: Ray Ni 
Cc: Michael D Kinney 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang 
---
 .../UefiDevicePathLib.c   | 8 
 1 file changed, 8 insertions(+)

diff --git 
a/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c 
b/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c
index 9a0ee42fd1..5dc413de44 100644
--- a/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c
+++ b/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c
@@ -138,6 +138,14 @@ IsDevicePathValid (
 return FALSE;
   }
 }
+
+//
+// FilePath must be a NULL-terminated string.
+//
+if (DevicePathType (DevicePath) == MEDIA_FILEPATH_DP &&
+*(CHAR16 *)((UINT8 *)DevicePath + NodeLength - 2) != 0) {
+  return FALSE;
+}
   }
 
   //
-- 
2.19.0.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH v2] SD/eMMC : Fix Command Argument for SD/eMMC R/W operation.

2019-01-28 Thread Meenakshi Aggarwal
Hi,

Please share review comments.

Thanks,
Meenakshi

> -Original Message-
> From: Meenakshi Aggarwal 
> Sent: Thursday, January 24, 2019 7:35 PM
> To: ard.biesheu...@linaro.org; leif.lindh...@linaro.org; edk2-
> de...@lists.01.org; jun@linaro.org; haojian.zhu...@linaro.org
> Cc: Meenakshi Aggarwal 
> Subject: [PATCH v2] SD/eMMC : Fix Command Argument for SD/eMMC R/W
> operation.
> 
> Issue : SD read failure for high capacity cards e.g. 64 GB i Reason : Command
> argument value exceeds 32 bit for block number 0x3787FFF and cant be fit into
> 32 bit wide SD host controller register.
> 
> Fix :
> AccessMode bits [29:30] of OCR is a valid definition to calculate data 
> address for
> eMMC cards.
> 
> For SD cards, data address is calculated on the basis of card capacity status
> bit[30] of OCR.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Meenakshi Aggarwal 
> ---
>  EmbeddedPkg/Universal/MmcDxe/Mmc.h|  2 ++
>  EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c | 21 -
>  2 files changed, 18 insertions(+), 5 deletions(-)
> 
> diff --git a/EmbeddedPkg/Universal/MmcDxe/Mmc.h
> b/EmbeddedPkg/Universal/MmcDxe/Mmc.h
> index a77ba41..62de2c8 100644
> --- a/EmbeddedPkg/Universal/MmcDxe/Mmc.h
> +++ b/EmbeddedPkg/Universal/MmcDxe/Mmc.h
> @@ -70,6 +70,8 @@
>  #define SD_HIGH_SPEED   5000
>  #define SWITCH_CMD_SUCCESS_MASK 0x0f00
> 
> +#define SD_CARD_CAPACITY0x0002
> +
>  #define BUSWIDTH_4  4
> 
>  typedef enum {
> diff --git a/EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c
> b/EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c
> index a2b9232..1dea7d3 100644
> --- a/EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c
> +++ b/EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c
> @@ -148,12 +148,23 @@ MmcTransferBlock (
>MmcHostInstance = MMC_HOST_INSTANCE_FROM_BLOCK_IO_THIS (This);
>MmcHost = MmcHostInstance->MmcHost;
> 
> -  //Set command argument based on the card access mode (Byte mode or Block
> mode)
> -  if ((MmcHostInstance->CardInfo.OCRData.AccessMode &
> MMC_OCR_ACCESS_MASK) ==
> -  MMC_OCR_ACCESS_SECTOR) {
> -CmdArg = Lba;
> +  if (MmcHostInstance->CardInfo.CardType != EMMC_CARD) {
> +//Set command argument based on the card capacity
> +//if 0 : SDSC card
> +//if 1 : SDXC/SDHC
> +if (MmcHostInstance->CardInfo.OCRData.AccessMode &
> SD_CARD_CAPACITY) {
> +  CmdArg = Lba;
> +} else {
> +  CmdArg = Lba * This->Media->BlockSize;
> +}
>} else {
> -CmdArg = Lba * This->Media->BlockSize;
> +//Set command argument based on the card access mode (Byte mode or
> Block mode)
> +if ((MmcHostInstance->CardInfo.OCRData.AccessMode &
> MMC_OCR_ACCESS_MASK) ==
> +MMC_OCR_ACCESS_SECTOR) {
> +  CmdArg = Lba;
> +} else {
> +  CmdArg = Lba * This->Media->BlockSize;
> +}
>}
> 
>Status = MmcHost->SendCommand (MmcHost, Cmd, CmdArg);
> --
> 1.9.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH v2] MdePkg/BaseLib: Add Base64Encode() and Base64Decode()

2019-01-28 Thread Ni, Ray
Minor comments regarding the parameter name.

> -Original Message-
> From: edk2-devel  On Behalf Of Shenglei
> Zhang
> Sent: Thursday, January 10, 2019 8:44 PM
> To: edk2-devel@lists.01.org
> Cc: Kinney, Michael D ; Gao, Liming
> 
> Subject: [edk2] [PATCH v2] MdePkg/BaseLib: Add Base64Encode() and
> Base64Decode()
> 
> Introduce public functions Base64Encode and Base64Decode.
> https://bugzilla.tianocore.org/show_bug.cgi?id=1370
> 
> v2:1.Remove some white space.
>2.Add unit test with test vectors in RFC 4648.
>  https://github.com/shenglei10/edk2/tree/encode_test
>  https://github.com/shenglei10/edk2/tree/decode_test
> 
> Cc: Michael D Kinney 
> Cc: Liming Gao 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Shenglei Zhang 
> ---
>  MdePkg/Include/Library/BaseLib.h |  56 +
> MdePkg/Library/BaseLib/String.c  | 345
> +++
>  2 files changed, 401 insertions(+)
> 
> diff --git a/MdePkg/Include/Library/BaseLib.h
> b/MdePkg/Include/Library/BaseLib.h
> index 1eb842384e..9317888a7e 100644
> --- a/MdePkg/Include/Library/BaseLib.h
> +++ b/MdePkg/Include/Library/BaseLib.h
> @@ -2720,6 +2720,62 @@ AsciiStrnToUnicodeStrS (
>OUT UINTN *DestinationLength
>);
> 
> +/**
> +  Convert binary data to a Base64 encoded ascii string based on RFC4648.
> +
> +  Produce a Null-terminated Ascii string in the output buffer specified by
> AsciiPtr and AsciiSize.
> +  The Ascii string is produced by converting the data string specified by
> DataPtr and DataLen.
> +
> +  @param DataPtr Input UINT8 data
> +  @param DataLenNumber of UINT8 bytes of data
> +  @param AsciiPtr  Pointer to output string buffer
> +  @param AsciiSize   Size of ascii buffer. Set to 0 to get the size needed.
> +   Caller is responsible for passing in
> + buffer of AsciiSize
> +
> +  @retval RETURN_SUCCESSWhen ascii buffer is filled in.
> +  @retval RETURN_INVALID_PARAMETER   If DataPtr is NULL or AsciiSize is
> NULL.
> +  @retval RETURN_INVALID_PARAMETER   If DataLen or AsciiSize is too big.
> +  @retval RETURN_BUFFER_TOO_SMALL   If DataLen is 0 and AsciiSize is <1.
> +  @retval RETURN_BUFFER_TOO_SMALL   If AsciiPtr is NULL or too small.
> +
> +**/
> +RETURN_STATUS
> +EFIAPI
> +Base64Encode (
> +  IN  CONST UINT8  *DataPtr,
1. Data or Source?
> +  INUINTN   DataLen,
2. DataLength or SourceLength?
> +  OUT   CHAR8  *AsciiPtr  OPTIONAL,
3. AsciiString or Destination?
> +  IN OUTUINTN  *AsciiSize
4. AsciiStringSize or DestinationSize?
> +  );
> +
> +/**
> +  Convert Base64 ascii string to binary data based on RFC4648.
> +
> +  Produce Null-terminated binary data in the output buffer specified by
> BinPtr and BinSize.
> +  The binary data is produced by converting the Base64 ascii string specified
> by DataPtr and DataLen.
> +
> +  @param DataPtr  Input ASCII characters
> +  @param DataLen Number of ASCII characters
> +  @param BinPtrPointer to output buffer
> +  @param BinSize  Caller is responsible for passing in buffer of at least
> BinSize.
> +Set 0 to get the size needed. Set to bytes 
> stored on return.
> +
> +  @retval RETURN_SUCCESSWhen binary buffer is filled in.
> +  @retval RETURN_INVALID_PARAMETER   If DataPtr is NULL or BinSize is
> NULL.
> +  @retval RETURN_INVALID_PARAMETER   If DataLen or BinSize is too big.
> +  @retval RETURN_INVALID_PARAMETER   If BinPtr NULL and BinSize != 0.
> +  @retval RETURN_INVALID_PARAMETER   If there is any Invalid character in
> input stream.
> +  @retval RETURN_BUFFER_TOO_SMALL   If Buffer length is too small.
> + **/
> +RETURN_STATUS
> +EFIAPI
> +Base64Decode (
> +  IN  CONST CHAR8  *DataPtr,
5. AsciiString or Source? At least I don't think "DataPtr" is proper here. It's 
not the same "DataPtr" in Encode() API.
> +  INUINTN   DataLen,
6. AsciiStringLength or SourceLength?
> +  OUT   UINT8  *BinPtr  OPTIONAL,
7. Data or Destination?
> +  IN OUTUINTN  *BinSize
8. DataSize or DestinationSize?
> +  );
> +
>  /**
>Converts an 8-bit value to an 8-bit BCD value.
> 
> diff --git a/MdePkg/Library/BaseLib/String.c
> b/MdePkg/Library/BaseLib/String.c index e6df12797d..761ff6830a 100644
> --- a/MdePkg/Library/BaseLib/String.c
> +++ b/MdePkg/Library/BaseLib/String.c
> @@ -1763,6 +1763,351 @@ AsciiStrToUnicodeStr (
> 
>  #endif
> 
> +//
> +// The basis for Base64 encoding is RFC 4686
> +https://tools.ietf.org/html/rfc4648
> +//
> +// RFC 4686 has a number of MAY and SHOULD cases.  This implementation
> +chooses // the more restrictive versions for security concerns (see RFC 4686
> section 3.3).
> +//
> +// A invalid character, if encountered during the decode operation,
> +causes the data // to be rejected. In addition, the '=' padding
> +character is only allowed at the end // of the Base64 encoded string.
> +//
> +#define BAD_V  99
> +
> +STATIC CHAR8 Encodin

Re: [edk2] [PATCH v2 2/2] MdePkg/UefiDevicePathLib: Add a checking step

2019-01-28 Thread Ni, Ray
Reviewed-by: Ruiyu Ni 

> -Original Message-
> From: edk2-devel  On Behalf Of Shenglei
> Zhang
> Sent: Wednesday, December 12, 2018 11:10 AM
> To: edk2-devel@lists.01.org
> Cc: Kinney, Michael D ; Gao, Liming
> 
> Subject: [edk2] [PATCH v2 2/2] MdePkg/UefiDevicePathLib: Add a checking
> step
> 
> Add a checking step in DevicePathUtilities.c to verify the DevicePath.
> https://bugzilla.tianocore.org/show_bug.cgi?id=1372
> 
> v2: Remove ASSERT() and the redundant checking step.
> Update related description in DevicePathLib.h
> 
> Cc: Liming Gao 
> Cc: Michael D Kinney 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Shenglei Zhang 
> ---
>  MdePkg/Include/Library/DevicePathLib.h |  2 +-
>  .../UefiDevicePathLib/DevicePathUtilities.c| 14 ++
>  2 files changed, 7 insertions(+), 9 deletions(-)
> 
> diff --git a/MdePkg/Include/Library/DevicePathLib.h
> b/MdePkg/Include/Library/DevicePathLib.h
> index 959299704a..717d4db42f 100644
> --- a/MdePkg/Include/Library/DevicePathLib.h
> +++ b/MdePkg/Include/Library/DevicePathLib.h
> @@ -22,7 +22,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY
> KIND, EITHER EXPRESS OR IMPLIED.
> 
>  /**
>Determine whether a given device path is valid.
> -  If DevicePath is NULL, then ASSERT().
> +  If DevicePath is NULL or the size is not suitable, then return false.
> 
>@param  DevicePath  A pointer to a device path data structure.
>@param  MaxSize The maximum size of the device path data structure.
> diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c
> b/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c
> index 665e5a4adc..05f82c1313 100644
> --- a/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c
> +++ b/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c
> @@ -59,19 +59,17 @@ IsDevicePathValid (
>UINTN Size;
>UINTN NodeLength;
> 
> -  ASSERT (DevicePath != NULL);
> -
> -  if (MaxSize == 0) {
> -MaxSize = MAX_UINTN;
> -  }
> -
>//
> -  // Validate the input size big enough to touch the first node.
> +  //Validate the input whether exists and its size big enough to touch the
> first node
>//
> -  if (MaxSize < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {
> +  if (DevicePath == NULL || (MaxSize > 0 && MaxSize <
> END_DEVICE_PATH_LENGTH)) {
>  return FALSE;
>}
> 
> +  if (MaxSize == 0) {
> +MaxSize = MAX_UINTN;
> +  }
> +
>for (Count = 0, Size = 0; !IsDevicePathEnd (DevicePath); DevicePath =
> NextDevicePathNode (DevicePath)) {
>  NodeLength = DevicePathNodeLength (DevicePath);
>  if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {
> --
> 2.18.0.windows.1
> 
> ___
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [Patch V2] BaseTools: Enable CODE format in DEC file

2019-01-28 Thread Gao, Liming
Bob:
  I have no comments on this patch. Reviewed-by: Liming Gao 

  
  Besides, please make sure the build report list the value from DEC file when 
the value is specified in DEC file.

Thanks
Liming
> -Original Message-
> From: Feng, Bob C
> Sent: Friday, January 25, 2019 5:45 PM
> To: edk2-devel@lists.01.org
> Cc: Feng, Bob C ; Gao, Liming 
> Subject: [Patch V2] BaseTools: Enable CODE format in DEC file
> 
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1292.
> Enable CODE format in DEC File.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Bob Feng 
> Cc: Liming Gao 
> ---
>  .../Source/Python/Workspace/DscBuildData.py   | 38 +++
>  .../Source/Python/Workspace/MetaFileParser.py | 99 ---
>  BaseTools/Source/Python/build/BuildReport.py  |  2 +-
>  3 files changed, 86 insertions(+), 53 deletions(-)
> 
> diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py 
> b/BaseTools/Source/Python/Workspace/DscBuildData.py
> index 0dad04212e..4c3c9b8d34 100644
> --- a/BaseTools/Source/Python/Workspace/DscBuildData.py
> +++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
> @@ -1786,20 +1786,21 @@ class DscBuildData(PlatformBuildClassObject):
>  Value = 
> ValueExpressionEx(FieldList[FieldName.strip(".")][0], TAB_VOID, 
> self._GuidDict)(True)
>  except BadExpression:
>  EdkLogger.error('Build', FORMAT_INVALID, "Invalid 
> value format for %s. From %s Line %d " %
>  (".".join((Pcd.TokenSpaceGuidCName, 
> Pcd.TokenCName, FieldName.strip('.'))),
> FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2]))
>  Value, ValueSize = ParseFieldValue(Value)
> -CApp = CApp + '  __FLEXIBLE_SIZE(*Size, %s, %s, %d / 
> __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %%
> __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0));  // From %s Line %d Value %s \n' % 
> (Pcd.DatumType, FieldName.strip("."), ValueSize,
> Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, 
> FieldName.strip("."), FieldList[FieldName.strip(".")][1],
> FieldList[FieldName.strip(".")][2], FieldList[FieldName.strip(".")][0]);
> +if not Pcd.IsArray:
> +CApp = CApp + '  __FLEXIBLE_SIZE(*Size, %s, %s, %d / 
> __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %%
> __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0));  // From %s Line %d Value %s \n' % 
> (Pcd.DatumType, FieldName.strip("."), ValueSize,
> Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, 
> FieldName.strip("."), FieldList[FieldName.strip(".")][1],
> FieldList[FieldName.strip(".")][2], FieldList[FieldName.strip(".")][0]);
>  else:
>  NewFieldName = ''
>  FieldName_ori = FieldName.strip('.')
>  while '[' in  FieldName:
>  NewFieldName = NewFieldName + FieldName.split('[', 
> 1)[0] + '[0]'
>  ArrayIndex = int(FieldName.split('[', 
> 1)[1].split(']', 1)[0])
>  FieldName = FieldName.split(']', 1)[1]
>  FieldName = NewFieldName + FieldName
> -while '[' in FieldName:
> +while '[' in FieldName and not Pcd.IsArray:
>  FieldName = FieldName.rsplit('[', 1)[0]
>  CApp = CApp + '  __FLEXIBLE_SIZE(*Size, %s, %s, %d); 
> // From %s Line %d Value %s\n' % (Pcd.DatumType,
> FieldName.strip("."), ArrayIndex + 1, FieldList[FieldName_ori][1], 
> FieldList[FieldName_ori][2], FieldList[FieldName_ori][0])
>  for skuname in Pcd.SkuOverrideValues:
>  if skuname == TAB_COMMON:
>  continue
> @@ -1817,20 +1818,21 @@ class DscBuildData(PlatformBuildClassObject):
>  Value = 
> ValueExpressionEx(FieldList[FieldName.strip(".")][0], TAB_VOID, 
> self._GuidDict)(True)
>  except BadExpression:
>  EdkLogger.error('Build', FORMAT_INVALID, 
> "Invalid value format for %s. From %s Line %d " %
>  
> (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName.strip('.'))),
> FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2]))
>  Value, ValueSize = ParseFieldValue(Value)
> -CApp = CApp + '  __FLEXIBLE_SIZE(*Size, %s, 
> %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %%
> __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0)); // From %s Line %d Value %s\n' % 
> (Pcd.DatumType, FieldName.strip("."), ValueSize,
> Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, 
> FieldName.strip("."), FieldList[FieldName.strip(".")][1],
> FieldList[FieldName.strip(".")][2], FieldList[FieldName.strip(".")][0]);
> +if not Pcd.IsArray:
> + 

Re: [edk2] [PATCH] MdeModulePkg/SdMmcPciHcDxe: Update comment for spec compliance status

2019-01-28 Thread Wu, Hao A
> -Original Message-
> From: Wang, Jian J
> Sent: Tuesday, January 29, 2019 11:28 AM
> To: Wu, Hao A; edk2-devel@lists.01.org
> Cc: Ni, Ray
> Subject: RE: [PATCH] MdeModulePkg/SdMmcPciHcDxe: Update comment for
> spec compliance status
> 
> Just two typos (see below). With them addressed,
> 
> Reviewed-by: Jian J Wang 

Thanks for the catch.
I will handle them before pushing the patch.

Best Regards,
Hao Wu

> 
> > -Original Message-
> > From: Wu, Hao A
> > Sent: Tuesday, January 29, 2019 11:14 AM
> > To: edk2-devel@lists.01.org
> > Cc: Wu, Hao A ; Wang, Jian J ;
> > Ni, Ray 
> > Subject: [PATCH] MdeModulePkg/SdMmcPciHcDxe: Update comment for
> spec
> > compliance status
> >
> > REF:https://bugzilla.tianocore.org/show_bug.cgi?id=1441
> >
> > This commit will update the file-level comments within the SdMmcPciHcDxe
> > to reflect the latest specification compliance status of the driver.
> >
> > Cc: Jian J Wang 
> > Cc: Ray Ni 
> > Contributed-under: TianoCore Contribution Agreement 1.1
> > Signed-off-by: Hao Wu 
> > ---
> >  MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.inf | 5 +++--
> >  MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c   | 6 --
> >  MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c | 6 --
> >  MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.uni | 5 +++--
> >  4 files changed, 14 insertions(+), 8 deletions(-)
> >
> > diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.inf
> > b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.inf
> > index 1246e1d88d..025fb7faba 100644
> > --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.inf
> > +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.inf
> > @@ -1,11 +1,12 @@
> >  ## @file
> >  #  SdMmcPciHcDxe driver is used to manage those host controllers which
> > comply with SD
> > -#  Host Controller Simplified Specifiction version 3.0.
> > +#  Host Controller Simplified Specifiction version 3.0 plus the 64-bit 
> > System
> 
> Typo: Specifiction
> 
> > Addressing
> > +#  support in SD Host Controller Simplified Specification version 4.20.
> >  #
> >  #  It will produce EFI_SD_MMC_PASS_THRU_PROTOCOL to allow sending
> > SD/MMC/eMMC cmds
> >  #  to specified devices from upper layer.
> >  #
> > -#  Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.
> > +#  Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.
> >  #
> >  #  This program and the accompanying materials
> >  #  are licensed and made available under the terms and conditions of the
> BSD
> > License
> > diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
> > b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
> > index 76c32a4dcd..b474f8decd 100644
> > --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
> > +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
> > @@ -1,11 +1,13 @@
> >  /** @file
> >This driver is used to manage SD/MMC PCI host controllers which are
> > compliance
> > -  with SD Host Controller Simplified Specification version 3.00.
> > +  with SD Host Controller Simplified Specification version 3.00 plus the 
> > 64-bit
> > +  System Addressing support in SD Host Controller Simplified Specification
> > version
> > +  4.20.
> >
> >It would expose EFI_SD_MMC_PASS_THRU_PROTOCOL for upper layer use.
> >
> >Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
> > -  Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
> > +  Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.
> >This program and the accompanying materials
> >are licensed and made available under the terms and conditions of the BSD
> > License
> >which accompanies this distribution.  The full text of the license may be
> found
> > at
> > diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
> > b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
> > index 5aec8c6992..4c64da3b20 100644
> > --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
> > +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
> > @@ -1,11 +1,13 @@
> >  /** @file
> >This driver is used to manage SD/MMC PCI host controllers which are
> > compliance
> > -  with SD Host Controller Simplified Specification version 3.00.
> > +  with SD Host Controller Simplified Specification version 3.00 plus the 
> > 64-bit
> > +  System Addressing support in SD Host Controller Simplified Specification
> > version
> > +  4.20.
> >
> >It would expose EFI_SD_MMC_PASS_THRU_PROTOCOL for upper layer use.
> >
> >Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
> > -  Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.
> > +  Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.
> >This program and the accompanying materials
> >are licensed and made available under the terms and conditions of the BSD
> > License
> >which accompanies this distribution.  The full text of the license may be
> found
> > at
> > diff --git a/MdeModulePkg/Bus/Pci/S

Re: [edk2] [PATCH] MdeModulePkg/SdMmcPciHcDxe: Update comment for spec compliance status

2019-01-28 Thread Wang, Jian J
Just two typos (see below). With them addressed,

Reviewed-by: Jian J Wang 

> -Original Message-
> From: Wu, Hao A
> Sent: Tuesday, January 29, 2019 11:14 AM
> To: edk2-devel@lists.01.org
> Cc: Wu, Hao A ; Wang, Jian J ;
> Ni, Ray 
> Subject: [PATCH] MdeModulePkg/SdMmcPciHcDxe: Update comment for spec
> compliance status
> 
> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=1441
> 
> This commit will update the file-level comments within the SdMmcPciHcDxe
> to reflect the latest specification compliance status of the driver.
> 
> Cc: Jian J Wang 
> Cc: Ray Ni 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Hao Wu 
> ---
>  MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.inf | 5 +++--
>  MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c   | 6 --
>  MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c | 6 --
>  MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.uni | 5 +++--
>  4 files changed, 14 insertions(+), 8 deletions(-)
> 
> diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.inf
> b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.inf
> index 1246e1d88d..025fb7faba 100644
> --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.inf
> +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.inf
> @@ -1,11 +1,12 @@
>  ## @file
>  #  SdMmcPciHcDxe driver is used to manage those host controllers which
> comply with SD
> -#  Host Controller Simplified Specifiction version 3.0.
> +#  Host Controller Simplified Specifiction version 3.0 plus the 64-bit System

Typo: Specifiction

> Addressing
> +#  support in SD Host Controller Simplified Specification version 4.20.
>  #
>  #  It will produce EFI_SD_MMC_PASS_THRU_PROTOCOL to allow sending
> SD/MMC/eMMC cmds
>  #  to specified devices from upper layer.
>  #
> -#  Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.
> +#  Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.
>  #
>  #  This program and the accompanying materials
>  #  are licensed and made available under the terms and conditions of the BSD
> License
> diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
> b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
> index 76c32a4dcd..b474f8decd 100644
> --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
> +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
> @@ -1,11 +1,13 @@
>  /** @file
>This driver is used to manage SD/MMC PCI host controllers which are
> compliance
> -  with SD Host Controller Simplified Specification version 3.00.
> +  with SD Host Controller Simplified Specification version 3.00 plus the 
> 64-bit
> +  System Addressing support in SD Host Controller Simplified Specification
> version
> +  4.20.
> 
>It would expose EFI_SD_MMC_PASS_THRU_PROTOCOL for upper layer use.
> 
>Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
> -  Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
> +  Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.
>This program and the accompanying materials
>are licensed and made available under the terms and conditions of the BSD
> License
>which accompanies this distribution.  The full text of the license may be 
> found
> at
> diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
> b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
> index 5aec8c6992..4c64da3b20 100644
> --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
> +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
> @@ -1,11 +1,13 @@
>  /** @file
>This driver is used to manage SD/MMC PCI host controllers which are
> compliance
> -  with SD Host Controller Simplified Specification version 3.00.
> +  with SD Host Controller Simplified Specification version 3.00 plus the 
> 64-bit
> +  System Addressing support in SD Host Controller Simplified Specification
> version
> +  4.20.
> 
>It would expose EFI_SD_MMC_PASS_THRU_PROTOCOL for upper layer use.
> 
>Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
> -  Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.
> +  Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.
>This program and the accompanying materials
>are licensed and made available under the terms and conditions of the BSD
> License
>which accompanies this distribution.  The full text of the license may be 
> found
> at
> diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.uni
> b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.uni
> index 57f9fa76a1..497d2cc9f0 100644
> --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.uni
> +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.uni
> @@ -1,11 +1,12 @@
>  // /** @file
>  // SdMmcPciHcDxe driver is used to manage those host controllers which
> comply with SD
> -// Host Controller Simplified Specifiction version 3.0.
> +// Host Controller Simplified Specifiction version 3.0 plus the 64-bit System

Typo: Specifiction

> Addressing
> +//

Re: [edk2] [PATCH v2 2/2] MdeModulePkg/CapsuleApp: Enhance CapsuleApp to support Capsule-on-Disk.

2019-01-28 Thread Wang, Jian J
Hi Chen,

Here're some overall comments:
1. Update all copyright year to 2019
2. Split this patch to smaller granularity (in public standalone file unit or 
module unit),
and keep in mind that the patch order also matters. This patch can be split 
into 3
patches.
3. Provide test information you've done.

See my other comments below.


> -Original Message-
> From: Chen, Chen A
> Sent: Monday, January 28, 2019 9:21 AM
> To: edk2-devel@lists.01.org
> Cc: Chen, Chen A ; Wang, Jian J
> ; Wu, Hao A ; Zhang, Chao B
> 
> Subject: [PATCH v2 2/2] MdeModulePkg/CapsuleApp: Enhance CapsuleApp to
> support Capsule-on-Disk.
> 
> BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=1482
> 
> CapsuleApp is used for trigger capsule update.
> Add -OD option in CapsuleApp to support doing capsule update via storage.
> Add -F and -L options to support dumping information feature.
> 
> Cc: Jian J Wang 
> Cc: Hao Wu 
> Cc: Zhang Chao B 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Chen A Chen 
> ---
>  MdeModulePkg/Application/CapsuleApp/CapsuleApp.c   | 153 +++-
>  MdeModulePkg/Application/CapsuleApp/CapsuleApp.inf |   8 +
>  MdeModulePkg/Application/CapsuleApp/CapsuleDump.c  | 535
> +-
>  .../Application/CapsuleApp/CapsuleOnDisk.c | 802
> +
>  MdeModulePkg/Include/Library/UefiBootManagerLib.h  |  19 +
>  MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c   |  22 +
>  6 files changed, 1524 insertions(+), 15 deletions(-)
>  create mode 100644 MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c
> 
> diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
> b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
> index 4d907242f3..ca9baa0a6a 100644
> --- a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
> +++ b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
> @@ -23,6 +23,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -105,6 +106,44 @@ DumpEsrtData (
>VOID
>);
> 
> +/**
> +  Dump Provisioned Capsule.
> +
> +  @param[in]  DumpCapsuleInfo  The flag to indicate whether to dump the
> capsule inforomation.
> +**/
> +VOID
> +DumpProvisionedCapsule (
> +  IN BOOLEAN  DumpCapsuleInfo
> +  );
> +
> +/**
> +  Dump all EFI System Parition.
> +**/
> +VOID
> +DumpAllEfiSysPartition (
> +  VOID
> +  );
> +
> +/**
> +  Process Capsule On Disk.
> +
> +  @param[in]  CapsuleBufferAn array of pointer to capsule images
> +  @param[in]  FileSize An array of UINTN to capsule images size
> +  @param[in]  OrgFileName  An array of orginal capsule images name
> +  @param[in]  NewFileName  An array of new capsule images name
> +  @param[in]  CapsuleNum   The count of capsule images
> +
> +  @retval EFI_SUCCESS   Capsule on disk secceed.
> +**/
> +EFI_STATUS
> +ProcessCapsuleOnDisk (
> +  IN VOID  **CapsuleBuffer,
> +  IN UINTN *CapsuleBufferSize,
> +  IN CHAR16**FilePath,
> +  IN CHAR16*Map,
> +  IN UINTN CapsuleNum
> +  );
> +
>  /**
>Read a file.
> 
> @@ -799,19 +838,22 @@ PrintUsage (
>)
>  {
>Print(L"CapsuleApp:  usage\n");
> -  Print(L"  CapsuleApp  [-NR]\n");
> +  Print(L"  CapsuleApp  [-NR] [-OD [FSx]]\n");
>Print(L"  CapsuleApp -S\n");
>Print(L"  CapsuleApp -C\n");
>Print(L"  CapsuleApp -P\n");
>Print(L"  CapsuleApp -E\n");
> +  Print(L"  CapsuleApp -L\n");
> +  Print(L"  CapsuleApp -L INFO\n");
> +  Print(L"  CapsuleApp -F\n");
>Print(L"  CapsuleApp -G  -O \n");
>Print(L"  CapsuleApp -N  -O \n");
>Print(L"  CapsuleApp -D \n");
>Print(L"  CapsuleApp -P GET   -O \n");
>Print(L"Parameter:\n");
> -  Print(L"  -NR: No reset will be triggered for the capsule with\n");
> -  Print(L"   CAPSULE_FLAGS_PERSIST_ACROSS_RESET and without\n");
> -  Print(L"   CAPSULE_FLAGS_INITIATE_RESET.\n");
> +  Print(L"  -NR: No reset will be triggered for the capsule\n");
> +  Print(L"   with CAPSULE_FLAGS_PERSIST_ACROSS_RESET and without
> CAPSULE_FLAGS_INITIATE_RESET.\n");
> +  Print(L"  -OD: Delivery of Capsules via file on Mass Storage device.");
>Print(L"  -S:  Dump capsule report variable (EFI_CAPSULE_REPORT_GUID),\n");
>Print(L"   which is defined in UEFI specification.\n");
>Print(L"  -C:  Clear capsule report variable 
> (EFI_CAPSULE_REPORT_GUID),\n");
> @@ -820,6 +862,8 @@ PrintUsage (
>Print(L"   ImageTypeId and Index (decimal format) to a file if 
> 'GET'\n");
>Print(L"   option is used.\n");
>Print(L"  -E:  Dump UEFI ESRT table info.\n");
> +  Print(L"  -L:  Dump provisioned capsule image information.\n");
> +  Print(L"  -F:  Dump all EFI System Partition.\n");
>Print(L"  -G:  Convert a BMP file to be an UX capsule,\n");
>Print(L"   according to Windows Firmware Update document\n");
>Print(L"  -N:  Append a Capsule Header to an existing FMP c

Re: [edk2] Network Stack Budgeting

2019-01-28 Thread Fu, Siyuan
Hi, Tomas

> -Original Message-
> From: Tomas Pilar (tpilar) [mailto:tpi...@solarflare.com]
> Sent: Monday, January 28, 2019 7:24 PM
> To: Fu, Siyuan ; Wu, Jiaxin ; Laszlo
> Ersek ; edk2-devel@lists.01.org
> Cc: Ye, Ting 
> Subject: Re: [edk2] Network Stack Budgeting
> 
> Hi Siyuan,
> 
> I had to do some tweaks due to the fact that people in the wild want to PXE
> boot whole WDS installations which are upwards of 300MB.
> 
> I have an internal set of queues where the NIC receives into. Snp.Receive()
> will get a packet from this store. I had to implement a separate queue for
> unicast/multicast/broadcast traffic so that I could reprioritise and deliver
> unicast traffic while under ARP spam. I tied internal poll to receive and
> transmit, so Snp.Receive() will poll the NIC and then dequeue a packet while
> Snp.Transmit() will transmit the packet and then poll the NIC to get a
> completion. I also implemented a busy poll for 100us or until the next packet
> comes in when the NIC is polled.

I see some problems here. Both Snp.Receive() and Snp.Transmit() should be 
non-blocking
interface in current design and UEFI spec, but it's not true in your driver.
For Receive(), it could poll the NIC only once and return either a received 
packet
or an error, it should not do any blocking poll to wait for a packet.
For Transmit(), it just need to put the packet into the TX queue and return 
directly,
without checking if the TX is completed. Instead of that, Snp.GetStatus() 
should be
used to check if the packet has really been sent out.

May I know how did you control the 100us timeout of the busy poll (by which 
API?),
and what's the TPL of this busy poll?

> 
> Otherwise I have seen a pathological case where the TFTP client would pull one
> packet per second but the TFTP_RETRANSMIT interval on the server was also one
> second and everything was awful.

Why TFTP client just pull one packet per second? I think it’s not correct and it
could use the poll() function to accelerate the receive. Why you trying to 
solve a
TFTP layer problem in SNP layer? It breaks the design principle of network 
layer model.
> 
> In theory the busy poll moderator might cause an issue in a pathological case,
> if it stalls the machine for 100us for each packet - with 100 packets per
> second this would eat only 10ms.

Not only 10ms, it's at least 10ms, and in theory. If you have multiple NICs in 
the
system, this time will double. If someone tries to poll the NIC, the time will 
increase
significantly. It also depends on who you measure the 100us timeout, I did see 
some
platform which has a minimum timer interval limitation, that you thought you 
are using
a 100us timeout but it’s actually 1ms or even 10ms.

So my suggestion is do NOT add any busy wait in SNP layer API, keep it as 
unblocking,
and the try to solve the application layer problem in application layer.

Best Regards,
Siyuan

> 
> Cheers,
> Tom
> 
> On 27/01/2019 14:28, Fu, Siyuan wrote:
> > Hi, Tom
> >
> >> -Original Message-
> >> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of
> Tomas
> >> Pilar (tpilar)
> >> Sent: Friday, January 25, 2019 8:09 PM
> >> To: Wu, Jiaxin ; Laszlo Ersek ;
> edk2-
> >> de...@lists.01.org
> >> Cc: Ye, Ting 
> >> Subject: Re: [edk2] Network Stack Budgeting
> >>
> >> Yeah, that makes sense I suppose. The end result is however that the
> network
> >> device is 'opened' as soon as ConnectController() is called rather than
> when
> >> someone wants to do networking. This seems wrong and directly leads to a
> DoS
> >> of a platform in case of heavy network load (unless we implement budgeting
> in
> >> the network driver, which is a really not what it should be doing).
> > It's true that a configured MNP will start a background system poll to
> receive
> > network packets, but normally it won't lead to a DoS, because the receive
> frequency
> > is actually very low. The MNP driver only tries to receive 1 packet from SNP
> for every
> > 10 milliseconds (see MNP_SYS_POLL_INTERVAL, MnpSystemPoll() and related
> timer event).
> > So no matter how heavy the network is, MNP driver (and upper layer stack)
> will
> > only process at most 100 packets per second, all other packets should be
> dropped
> > by UNDI driver directly.
> >
> > So if there is nobody doing busy network receiving, the network stack cost
> will be
> > at most 100 packets per NIC device and per second.
> >
> > In your first email you mentioned "some performance improvements to my
> network driver",
> > may I know what's the improvement method you are using?
> >
> > Best Regards,
> > Siyuan
> >
> >> How do you suggest we solve this problem?
> >>
> >> Cheers,
> >> Tom
> >>
> >> On 25/01/2019 08:44, Wu, Jiaxin wrote:
> >>> Hi Tom,
> >>>
> >>> One thing I want to highlight is that our design of network stack is not
> >> only for the PXE/HTTP boot trigged in BootManager, but also to make sure
> it's
> >> workable once there is any MNP instance configured by uppe

[edk2] [PATCH] MdeModulePkg/SdMmcPciHcDxe: Update comment for spec compliance status

2019-01-28 Thread Hao Wu
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=1441

This commit will update the file-level comments within the SdMmcPciHcDxe
to reflect the latest specification compliance status of the driver.

Cc: Jian J Wang 
Cc: Ray Ni 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Hao Wu 
---
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.inf | 5 +++--
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c   | 6 --
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c | 6 --
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.uni | 5 +++--
 4 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.inf 
b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.inf
index 1246e1d88d..025fb7faba 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.inf
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.inf
@@ -1,11 +1,12 @@
 ## @file
 #  SdMmcPciHcDxe driver is used to manage those host controllers which comply 
with SD
-#  Host Controller Simplified Specifiction version 3.0.
+#  Host Controller Simplified Specifiction version 3.0 plus the 64-bit System 
Addressing
+#  support in SD Host Controller Simplified Specification version 4.20.
 #
 #  It will produce EFI_SD_MMC_PASS_THRU_PROTOCOL to allow sending SD/MMC/eMMC 
cmds
 #  to specified devices from upper layer.
 #
-#  Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.
+#  Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.
 #
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD 
License
diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c 
b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
index 76c32a4dcd..b474f8decd 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
@@ -1,11 +1,13 @@
 /** @file
   This driver is used to manage SD/MMC PCI host controllers which are 
compliance
-  with SD Host Controller Simplified Specification version 3.00.
+  with SD Host Controller Simplified Specification version 3.00 plus the 64-bit
+  System Addressing support in SD Host Controller Simplified Specification 
version
+  4.20.
 
   It would expose EFI_SD_MMC_PASS_THRU_PROTOCOL for upper layer use.
 
   Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
-  Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
+  Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD 
License
   which accompanies this distribution.  The full text of the license may be 
found at
diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c 
b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
index 5aec8c6992..4c64da3b20 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
@@ -1,11 +1,13 @@
 /** @file
   This driver is used to manage SD/MMC PCI host controllers which are 
compliance
-  with SD Host Controller Simplified Specification version 3.00.
+  with SD Host Controller Simplified Specification version 3.00 plus the 64-bit
+  System Addressing support in SD Host Controller Simplified Specification 
version
+  4.20.
 
   It would expose EFI_SD_MMC_PASS_THRU_PROTOCOL for upper layer use.
 
   Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
-  Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.
+  Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD 
License
   which accompanies this distribution.  The full text of the license may be 
found at
diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.uni 
b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.uni
index 57f9fa76a1..497d2cc9f0 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.uni
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.uni
@@ -1,11 +1,12 @@
 // /** @file
 // SdMmcPciHcDxe driver is used to manage those host controllers which comply 
with SD
-// Host Controller Simplified Specifiction version 3.0.
+// Host Controller Simplified Specifiction version 3.0 plus the 64-bit System 
Addressing
+// support in SD Host Controller Simplified Specification version 4.20.
 //
 // It will produce EFI_SD_MMC_PASS_THRU_PROTOCOL to allow sending SD/MMC/eMMC 
cmds
 // to specified devices from upper layer.
 //
-// Copyright (c) 2015, Intel Corporation. All rights reserved.
+// Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.
 //
 // This program and the accompanying materials
 // are licensed and made available under the terms and conditions of the BSD 
License
-- 
2.12.0.windows.1

___
edk2-devel mailing list

Re: [edk2] [PATCH v4 0/7] Introduce two public functions and remove internal ones

2019-01-28 Thread Gao, Liming
Reviewed-by: Liming Gao  for this patch set.

> -Original Message-
> From: Zhang, Shenglei
> Sent: Tuesday, December 25, 2018 4:17 PM
> To: edk2-devel@lists.01.org
> Cc: Kinney, Michael D ; Gao, Liming 
> ; Leif Lindholm ;
> Laszlo Ersek ; Wang, Jian J ; Wu, 
> Hao A ; Zeng, Star
> ; Ni, Ruiyu ; Carsey, Jaben 
> 
> Subject: [PATCH v4 0/7] Introduce two public functions and remove internal 
> ones
> 
> Introduce public functions CharToUpper and AsciiToUpper.
> Remove internal functions InternalCharToUpper and InternalBaseLibAsciiToUpper.
> 
> v2: Update the title and commit message of 1/3.
> 
> v3: 1.Add a patch to remove AsciiToUpper in EdbSupportString.c.
> 2.Revert the changes in Basetools.
> 
> v4: 1.Add1/7: Change function names in EdbSupportString.c.
> 2.Update the title of 4/7.
> 3.Add 5/7: Use BaseLib api AsciiToUpper in DxeHttpLib.c.
> 4.Add 6/7: Use BaseLib api CharToUpper in ShellManParser.c.
> 5.Add 7/7: Use BaseLib api CharToUpper in UefiShellLib.c.
> 
> Cc: Michael D Kinney 
> Cc: Liming Gao 
> Cc: Leif Lindholm 
> Cc: Laszlo Ersek 
> Cc: Jian J Wang 
> Cc: Hao Wu 
> Cc: Star Zeng 
> Cc: Ruiyu Ni 
> Cc: Jaben Carsey 
> Shenglei Zhang (7):
>   MdeModulePkg/EbcDebugger: Change function names
>   MdePkg/BaseLib: Introduce CharToUpper and AsciiToUpper publicly
>   MdePkg/BaseLib: Remove InternalCharToUpper and
> InternalBaseLibAsciiToUpper
>   MdeModulePkg/EbcDebugger: Use BaseLib apis AsciiToUpper and
> CharToUpper
>   MdeModulePkg/DxeHttpLib: Use BaseLib api AsciiToUpper
>   ShellPkg/Shell: Use BaseLib api CharToUpper
>   ShellPkg/UefiShellLib: Use BaseLib api CharToUpper
> 
>  MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c  | 23 +-
>  .../EbcDxe/EbcDebugger/EdbSupportString.c | 39 ++---
>  MdePkg/Include/Library/BaseLib.h  | 40 ++
>  MdePkg/Library/BaseLib/BaseLibInternals.h | 42 ---
>  MdePkg/Library/BaseLib/SafeString.c   |  8 ++--
>  MdePkg/Library/BaseLib/String.c   | 16 +++
>  ShellPkg/Application/Shell/ShellManParser.c   | 23 +-
>  ShellPkg/Library/UefiShellLib/UefiShellLib.c  | 31 +-
>  8 files changed, 60 insertions(+), 162 deletions(-)
> 
> --
> 2.18.0.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH v2 0/3] Fix an incorrectly spelled Marco

2019-01-28 Thread Gao, Liming
Reviewed-by: Liming Gao 

> -Original Message-
> From: Zhang, Shenglei
> Sent: Wednesday, December 19, 2018 4:55 PM
> To: edk2-devel@lists.01.org
> Cc: Leif Lindholm ; Laszlo Ersek 
> ; Kinney, Michael D ; Gao,
> Liming ; Wang, Jian J ; Wu, Hao 
> A ; Zeng, Star
> ; Philippe Mathieu-Daud� 
> Subject: [PATCH v2 0/3] Fix an incorrectly spelled Marco
> 
> EFI_RETURNING_FROM_EFI_APPLICATOIN is not spelled correctly and
> change it to EFI_RETURNING_FROM_EFI_APPLICATION.
> 
> v2
> In v1 EFI_RETURNING_FROM_EFI_APPLICATOIN is changed into
> EFI_RETURNING_FROM_EFI_APPLICATION directly in one patch,
> which may lead to unbisectability.
> To solve this problem, the correct one is introduced in 1/3 and
> remove the incorrect one in 3/3.
> 
> Cc: Leif Lindholm 
> Cc: Laszlo Ersek 
> Cc: Michael D Kinney 
> Cc: Liming Gao 
> Cc: Jian J Wang 
> Cc: Hao Wu 
> Cc: Star Zeng 
> Cc: Philippe Mathieu-Daudé 
> Shenglei Zhang (3):
>   MdePkg/IndustryStandard: Introduce a correctly spelled Marco
>   SecurityPkg/Tcg: Fix typos in TcgDxe.c and Tcg2Dxe.c
>   MdePkg/IndustryStandard: Remove an incorrectly spelled Marco
> 
>  MdePkg/Include/IndustryStandard/UefiTcgPlatform.h | 2 +-
>  SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c | 4 ++--
>  SecurityPkg/Tcg/TcgDxe/TcgDxe.c   | 4 ++--
>  3 files changed, 5 insertions(+), 5 deletions(-)
> 
> --
> 2.18.0.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH v2 2/2] BaseTools/DevicePath: Add a checking step

2019-01-28 Thread Gao, Liming
Reviewed-by: Liming Gao 

> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of 
> Shenglei Zhang
> Sent: Wednesday, December 12, 2018 11:10 AM
> To: edk2-devel@lists.01.org
> Cc: Gao, Liming 
> Subject: [edk2] [PATCH v2 2/2] BaseTools/DevicePath: Add a checking step
> 
> Add a checking step in DevicePathUtilities.c
> to verify DevicePath.
> https://bugzilla.tianocore.org/show_bug.cgi?id=1372
> 
> v2: Remove ASSERT() and the redundant checking step.
> Update related description.
> 
> Cc: Bob Feng 
> Cc: Liming Gao 
> Cc: Yonghong Zhu 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Shenglei Zhang 
> ---
>  .../Source/C/DevicePath/DevicePathUtilities.c   | 17 -
>  1 file changed, 8 insertions(+), 9 deletions(-)
> 
> diff --git a/BaseTools/Source/C/DevicePath/DevicePathUtilities.c 
> b/BaseTools/Source/C/DevicePath/DevicePathUtilities.c
> index f8a41ff97d..e0399cfea7 100644
> --- a/BaseTools/Source/C/DevicePath/DevicePathUtilities.c
> +++ b/BaseTools/Source/C/DevicePath/DevicePathUtilities.c
> @@ -36,12 +36,13 @@ CONST EFI_DEVICE_PATH_PROTOCOL  
> mUefiDevicePathLibEndDevicePath = {
> 
>  /**
>Determine whether a given device path is valid.
> -  If DevicePath is NULL, then ASSERT().
> 
>@param  DevicePath  A pointer to a device path data structure.
>@param  MaxSize The maximum size of the device path data structure.
> 
>@retval TRUEDevicePath is valid.
> +  @retval FALSE   DevicePath is NULL.
> +  @retval FALSE   Maxsize is less than sizeof(EFI_DEVICE_PATH_PROTOCOL).
>@retval FALSE   The length of any node node in the DevicePath is less
>than sizeof (EFI_DEVICE_PATH_PROTOCOL).
>@retval FALSE   If MaxSize is not zero, the size of the DevicePath
> @@ -59,17 +60,15 @@ IsDevicePathValid (
>UINTN Size;
>UINTN NodeLength;
> 
> -  ASSERT (DevicePath != NULL);
> +  //
> +  //  Validate the input whether exists and its size big enough to touch the 
> first node
> +  //
> +  if (DevicePath == NULL || (MaxSize > 0 && MaxSize < 
> END_DEVICE_PATH_LENGTH)) {
> + return FALSE;
> +  }
> 
>if (MaxSize == 0) {
>  MaxSize = MAX_UINT32;
> - }
> -
> -  //
> -  // Validate the input size big enough to touch the first node.
> -  //
> -  if (MaxSize < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {
> -return FALSE;
>}
> 
>for (Count = 0, Size = 0; !IsDevicePathEnd (DevicePath); DevicePath = 
> NextDevicePathNode (DevicePath)) {
> --
> 2.18.0.windows.1
> 
> ___
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH] MdePkg/UefiLib: Add a new API GetVariable3

2019-01-28 Thread Gao, Liming
Jiansong:
  The patch is good. Reviewed-by: Liming Gao 
  
  Besides, this patch is from MS Mu, please keep original patch author. Don't 
need to send the patch again. 

Thanks
LIming
> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of 
> Jiansong Xu
> Sent: Monday, January 7, 2019 12:09 PM
> To: edk2-devel@lists.01.org
> Cc: Xu, JiansongX 
> Subject: [edk2] [PATCH] MdePkg/UefiLib: Add a new API GetVariable3
> 
> From: jiansonx 
> 
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1396
> Add a new API GetVariable3, which can return the attributes of a variable 
> during reading it.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Jiansong Xu 
> Cc: Liming Gao  ---
>  MdePkg/Include/Library/UefiLib.h | 33 
>  MdePkg/Library/UefiLib/UefiLib.c | 81 
> 
>  2 files changed, 114 insertions(+)
> 
> diff --git a/MdePkg/Include/Library/UefiLib.h 
> b/MdePkg/Include/Library/UefiLib.h
> index 468bffc3cb..929ee8afb7 100644
> --- a/MdePkg/Include/Library/UefiLib.h
> +++ b/MdePkg/Include/Library/UefiLib.h
> @@ -777,6 +777,39 @@ GetEfiGlobalVariable2 (
>OUT UINTN  *Size OPTIONAL
>);
> 
> +/** Return the attributes of the variable.
> +
> +  Returns the status whether get the variable success. The function retrieves
> +  variable  through the UEFI Runtime Service GetVariable().  The
> +  returned buffer is allocated using AllocatePool().  The caller is 
> responsible
> +  for freeing this buffer with FreePool().  The attributes are returned if
> +  the caller provides a valid Attribute parameter.
> +
> +  If Name  is NULL, then ASSERT().
> +  If Guid  is NULL, then ASSERT().
> +  If Value is NULL, then ASSERT().
> +
> +  @param[in]  Name  The pointer to a Null-terminated Unicode string.
> +  @param[in]  Guid  The pointer to an EFI_GUID structure
> +  @param[out] Value The buffer point saved the variable info.
> +  @param[out] Size  The buffer size of the variable.
> +  @param[out] Attr  The pointer to the variable attributes as found in var 
> store
> +
> +  @retval EFI_OUT_OF_RESOURCES  Allocate buffer failed.
> +  @retval EFI_SUCCESS   Find the specified variable.
> +  @retval Others Errors Return errors from call to 
> gRT->GetVariable.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +GetVariable3(
> +  IN CONST CHAR16   *Name,
> +  IN CONST EFI_GUID *Guid,
> + OUT VOID   **Value,
> + OUT UINTN  *Size OPTIONAL,
> + OUT UINT32 *Attr OPTIONAL
> +  );
> +
>  /**
>Returns a pointer to an allocated buffer that contains the best matching 
> language
>from a set of supported languages.
> diff --git a/MdePkg/Library/UefiLib/UefiLib.c 
> b/MdePkg/Library/UefiLib/UefiLib.c
> index 39d0ce2b21..475017690c 100644
> --- a/MdePkg/Library/UefiLib/UefiLib.c
> +++ b/MdePkg/Library/UefiLib/UefiLib.c
> @@ -1439,6 +1439,87 @@ GetVariable2 (
>return Status;
>  }
> 
> +/** Return the attributes of the variable.
> +
> +  Returns the status whether get the variable success. The function retrieves
> +  variable  through the UEFI Runtime Service GetVariable().  The
> +  returned buffer is allocated using AllocatePool().  The caller is 
> responsible
> +  for freeing this buffer with FreePool().  The attributes are returned if
> +  the caller provides a valid Attribute parameter.
> +
> +  If Name  is NULL, then ASSERT().
> +  If Guid  is NULL, then ASSERT().
> +  If Value is NULL, then ASSERT().
> +
> +  @param[in]  Name  The pointer to a Null-terminated Unicode string.
> +  @param[in]  Guid  The pointer to an EFI_GUID structure
> +  @param[out] Value The buffer point saved the variable info.
> +  @param[out] Size  The buffer size of the variable.
> +  @param[out] Attr  The pointer to the variable attributes as found in var 
> store
> +
> +  @retval EFI_OUT_OF_RESOURCES  Allocate buffer failed.
> +  @retval EFI_SUCCESS   Find the specified variable.
> +  @retval Others Errors Return errors from call to 
> gRT->GetVariable.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +GetVariable3(
> +  IN CONST CHAR16   *Name,
> +  IN CONST EFI_GUID *Guid,
> + OUT VOID   **Value,
> + OUT UINTN  *Size OPTIONAL,
> + OUT UINT32 *Attr OPTIONAL
> +  )
> +{
> +  EFI_STATUS  Status;
> +  UINTN   BufferSize;
> +
> +  ASSERT(Name != NULL && Guid != NULL && Value != NULL);
> +
> +  //
> +  // Try to get the variable size.
> +  //
> +  BufferSize = 0;
> +  *Value = NULL;
> +  if (Size != NULL) {
> +*Size = 0;
> +  }
> +
> +  if (Attr != NULL) {
> +*Attr = 0;
> +  }
> +
> +  Status = gRT->GetVariable((CHAR16 *)Name, (EFI_GUID *)Guid, Attr, 
> &BufferSize, *Value);
> +  if (Status != EFI_BUFFER_TOO_SMALL) {
> +return Status;
> +  }
> +
> +  //
> +  // Allocate buffer to get the variable.
> +  //
> +  *Value = AllocatePool(BufferSize);
> +  ASSERT(*Value != NULL);
> +  if (*V

Re: [edk2] [PATCH] patch1_add_support_bh720_emmc_chip

2019-01-28 Thread Wu, Hao A
> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Mike
> Li (WH)
> Sent: Monday, January 28, 2019 3:36 PM
> To: edk2-devel@lists.01.org
> Subject: [edk2] [PATCH] patch1_add_support_bh720_emmc_chip

Hi,

Thanks for the contribution. I saw you sent out a total of 3 patches for
the SdMmcPciHcDxe driver, and they seem to be related.

Could you please help to do the below things that will help for reviewing
your patches:

* Rebase your changes to the latest mater branch of the edk2;
* Generate a patch series rather than separate patch files if you think
  they are related;
* Help to provide detailed information on the purpose of the patches or
  the issue you met in the log message of each commit.

You may get some help by referring:
https://github.com/tianocore/tianocore.github.io/wiki/EDK-II-Development-Process

Thanks in advance.

Best Regards,
Hao Wu

> 
> ---
>  .../Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c| 253 --
>  .../Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h |  47 +---
>  2 files changed, 178 insertions(+), 122 deletions(-)
> 
> diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c
> b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c
> index 4ef849fd09..ac79a2f791 100644
> --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c
> +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c
> @@ -527,17 +527,35 @@ EmmcTuningClkForHs200 (
>if (EFI_ERROR (Status)) {
>  return Status;
>}
> +
> +  if(BhtHostPciSupport(PciIo)){
> + //set data transfer with 4bit
> + Status = SdMmcHcSetBusWidth (PciIo, Slot, 4);
> + //enable hardware tuning
> + HostCtrl2 = (~0x10);
> + Status = SdMmcHcAndMmio (PciIo, Slot, 0x110,sizeof
> (HostCtrl2), &HostCtrl2);
> +
> +   Status = EmmcSendTuningBlk (PassThru, Slot, 4);
> +   if (EFI_ERROR (Status)) {
> + DEBUG ((DEBUG_ERROR, "EmmcTuningClkForHs200: Send
> tuning block fails with %r\n", Status));
> + return Status;
> +   }
> +
> +  }
>//
>// Ask the device to send a sequence of tuning blocks till the tuning 
> procedure
> is done.
>//
>Retry = 0;
>do {
> -Status = EmmcSendTuningBlk (PassThru, Slot, BusWidth);
> -if (EFI_ERROR (Status)) {
> -  DEBUG ((DEBUG_ERROR, "EmmcTuningClkForHs200: Send tuning block
> fails with %r\n", Status));
> -  return Status;
> -}
> -
> + if(!BhtHostPciSupport(PciIo)){
> + Status = EmmcSendTuningBlk (PassThru, Slot, BusWidth);
> + if (EFI_ERROR (Status)) {
> +   DEBUG ((DEBUG_ERROR, "EmmcTuningClkForHs200: Send tuning
> block fails with %r\n", Status));
> +   return Status;
> + }
> + } else {
> + gBS->Stall(5000);
> + }
>  Status = SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2, TRUE,
> sizeof (HostCtrl2), &HostCtrl2);
>  if (EFI_ERROR (Status)) {
>return Status;
> @@ -548,6 +566,10 @@ EmmcTuningClkForHs200 (
>  }
> 
>  if ((HostCtrl2 & (BIT6 | BIT7)) == BIT7) {
> +   if(BhtHostPciSupport(PciIo)){
> + //set data transfer with default
> + Status = SdMmcHcSetBusWidth (PciIo, Slot, BusWidth);
> + }
>return EFI_SUCCESS;
>  }
>} while (++Retry < 40);
> @@ -652,7 +674,6 @@ EmmcSwitchBusWidth (
>@param[in] Slot   The slot number of the SD card to send the 
> command
> to.
>@param[in] RcaThe relative device address to be assigned.
>@param[in] HsTiming   The value to be written to HS_TIMING field of
> EXT_CSD register.
> -  @param[in] Timing The bus mode timing indicator.
>@param[in] ClockFreq  The max clock frequency to be set, the unit is 
> MHz.
> 
>@retval EFI_SUCCESS   The operation is done correctly.
> @@ -666,7 +687,6 @@ EmmcSwitchClockFreq (
>IN UINT8  Slot,
>IN UINT16 Rca,
>IN UINT8  HsTiming,
> -  IN SD_MMC_BUS_MODETiming,
>IN UINT32 ClockFreq
>)
>  {
> @@ -708,28 +728,7 @@ EmmcSwitchClockFreq (
>//
>// Convert the clock freq unit from MHz to KHz.
>//
> -  Status = SdMmcHcClockSupply (PciIo, Slot, ClockFreq * 1000, Private-
> >BaseClkFreq[Slot], Private->ControllerVersion[Slot]);
> -  if (EFI_ERROR (Status)) {
> -return Status;
> -  }
> -
> -  if (mOverride != NULL && mOverride->NotifyPhase != NULL) {
> -Status = mOverride->NotifyPhase (
> -  Private->ControllerHandle,
> -  Slot,
> -  EdkiiSdMmcSwitchClockFreqPost,
> -  &Timing
> -  );
> -if (EFI_ERROR (Status)) {
> -  DEBUG ((
> -DEBUG_ERROR,
> -"%a: SD/MMC switch clock freq post notifier callback failed - %r\n",
> -__FUNCTION__,
> -Status
> -));
> - 

Re: [edk2] [Patch 00/33] BaseTools python3 migration patch set

2019-01-28 Thread Feng, Bob C
Hi Laszlo,

Thanks for your suggestion. I re-sent the patch set and pushed the new patch 
set into branch py3basetools_v2.

Thanks,
Bob

-Original Message-
From: Laszlo Ersek [mailto:ler...@redhat.com] 
Sent: Monday, January 28, 2019 9:48 PM
To: Feng, Bob C 
Cc: edk2-devel@lists.01.org; Gao, Liming 
Subject: Re: [edk2] [Patch 00/33] BaseTools python3 migration patch set

Hi Bob,

On 01/28/19 11:35, Feng, Bob C wrote:
> Hi Laszlo,
> 
> I sent out 2 patches to fix this issue. And I also pushed the patches 
> to the repo https://github.com/BobCF/edk2.git branch py3basetools

I fetched your branch, and I found two new (fast-forward-able) commits:

$ git log --oneline --reverse 41c0616fc081..ec9e63692453

fb566a8835fa BaseTools: Fixed Eot python2 incompatible issue.
ec9e63692453 BaseTools: Fixed Ecc python2 incompatible issue.

However, the patches that you sent out:

[edk2] [Patch v2 32/33] BaseTools: ECC tool Python3 adaption [edk2] [Patch v2 
33/33] BaseTools: Eot tool Python3 adaption

appear different; I think you squashed the above incremental fixes into the 
corresponding original (v1) patches. Is that correct?

I prefer to test a series in the same exact state as it would be committed; 
otherwise there could be an issue with the rebase / squashing (possibly further 
tweaks), and it wouldn't be correct to apply my Tested-by to such a version.

In addition, you didn't post the updated (v2) patches #32 and #33 in response 
to the v1 blurb:

  [edk2] [Patch 00/33] BaseTools python3 migration patch set

and as a result they will drift apart on the list, from each other and also 
from the containing set.

In addition, it's a good practice to keep branches unchanged once they've been 
posted to the list; further iterations should be named py3basetools_v2, 
py3basetools_v3 etc. This lets people return to earlier iterations, compare 
versions, associate branches with postings, and so on.

Assuming the v2 32/33, v2 33/33 on-list series is what I should test, please 
push *precisely* that series to your repo, under branch name "py3basetools_v2". 
I'd also suggest resetting branch "py3basetools" to the original v1 posting 
status, that is, commit 41c0616fc081.

Thanks
Laszlo


> -Original Message-
> From: Feng, Bob C
> Sent: Monday, January 28, 2019 10:33 AM
> To: 'Laszlo Ersek' 
> Cc: edk2-devel@lists.01.org; Gao, Liming 
> Subject: RE: [edk2] [Patch 00/33] BaseTools python3 migration patch 
> set
> 
> Hi Laszlo,
> 
> Thanks for your testing and detailed testing result. I'll check the issue 
> happened in (a2) and provide a patch for it.
> 
> Thanks,
> Bob
> 
> -Original Message-
> From: Laszlo Ersek [mailto:ler...@redhat.com]
> Sent: Saturday, January 26, 2019 2:18 AM
> To: Feng, Bob C 
> Cc: edk2-devel@lists.01.org; Gao, Liming 
> Subject: Re: [edk2] [Patch 00/33] BaseTools python3 migration patch 
> set
> 
> On 01/25/19 10:42, Feng, Bob C wrote:
>> [...]
>>
>> -Original Message-
>> From: Laszlo Ersek [mailto:ler...@redhat.com]
>> Sent: Friday, January 25, 2019 4:57 PM
>> To: Feng, Bob C 
>> Cc: edk2-devel@lists.01.org; Gao, Liming 
>> Subject: Re: [edk2] [Patch 00/33] BaseTools python3 migration patch 
>> set
>>
>> [...]
>>
>> On 01/25/19 05:55, Feng, Bob C wrote:
>>> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=55
>>>
>>> This patch set is to enable python3 on BaseTools. Basetools code 
>>> will be compatible with both python3 and python2.
>>>
>>> We will have two envs PYTHON3_ENABLE and PYTHON_COMMAND. The 
>>> behavior can be combined as the below to support this usage.
>>> If user wants the specific python interpreter, he only needs to set 
>>> PYTHON_COMMAND env.
>>> If PYTHON3_ENABLE is set, PYTHON_COMMAND will be set to the found 
>>> one by edk2 scripts based on PYTHON3_ENABLE value.
>>> If PYTHON3_ENABLE is not set, but PYTHON_COMMAND is set, then 
>>> PYTHON_COMMAND will be used to run python script. No version check 
>>> here.
>>> If PYTHON3_ENABLE is not set, but PYTHON_COMMAND is not set, 
>>> PYTHON_COMMAND will be set to the high version python installed in 
>>> OS.
> 
> I ran the following tests, at commit 41c0616fc081 ("BaseTools: Eot 
> tool
> Python3 adaption", 2019-01-25). Each test was performed in a clean tree 
> (after running "git clean -ffdx") and clean environment (I re-sourced 
> "edksetup.sh" for each test in separation). In addition, the base tools were 
> rebuilt (again from a clean tree) for each test, with the following command 
> [1]:
> 
>   nice make -C "$EDK_TOOLS_PATH" -j $(getconf _NPROCESSORS_ONLN)
> 
> (a) On my RHEL7.5 Workstation laptop, I have both the system-level 
> python packages installed (python-2.7.5-69.el7_5.x86_64), and the 
> extra
> python-3.4 stuff from EPEL-7 (python34-3.4.9-1.el7.x86_64).
> 
> (a1) Didn't set either PYTHON3_ENABLE or PYTHON_COMMAND. The build 
> utility picked
> 
>   PYTHON_COMMAND   = /usr/bin/python3.4
> 
> and I successfully built OvmfPkg for IA32, IA32X64, and X64; also ArmVirtQemu 
> for AARCH64. 

[edk2] [Patch 31/33] BaseTools: Handle the bytes and str difference

2019-01-28 Thread Feng, Bob C
Deal with bytes and str is different, remove the unicode(),
correct open file parameter.
Using utcfromtimestamp instead of fromtimestamp.

Cc: Bob Feng 
Cc: Liming Gao 
Cc: Yonghong Zhu 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhiju.Fan 
---
 BaseTools/Source/Python/AutoGen/AutoGen.py | 42 
--
 BaseTools/Source/Python/AutoGen/GenC.py|  6 
+++---
 BaseTools/Source/Python/AutoGen/GenMake.py | 14 
+-
 BaseTools/Source/Python/AutoGen/GenPcdDb.py| 29 
+++--
 BaseTools/Source/Python/AutoGen/GenVar.py  | 34 
++
 BaseTools/Source/Python/AutoGen/InfSectionParser.py|  2 +-
 BaseTools/Source/Python/AutoGen/StrGather.py   |  5 
-
 BaseTools/Source/Python/AutoGen/UniClassObject.py  |  4 
++--
 BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py |  2 +-
 BaseTools/Source/Python/BPDG/GenVpd.py |  8 

 BaseTools/Source/Python/Common/LongFilePathOs.py   |  3 +--
 BaseTools/Source/Python/Common/LongFilePathSupport.py  | 12 

 BaseTools/Source/Python/Common/Misc.py | 48 

 BaseTools/Source/Python/Common/StringUtils.py  | 10 
++
 BaseTools/Source/Python/Common/VpdInfoFile.py  | 10 
+-
 BaseTools/Source/Python/GenFds/AprioriSection.py   |  2 +-
 BaseTools/Source/Python/GenFds/Capsule.py  | 15 
+++
 BaseTools/Source/Python/GenFds/CapsuleData.py  |  2 +-
 BaseTools/Source/Python/GenFds/Fd.py   |  4 
++--
 BaseTools/Source/Python/GenFds/FdfParser.py|  4 
++--
 BaseTools/Source/Python/GenFds/FfsFileStatement.py | 16 

 BaseTools/Source/Python/GenFds/FfsInfStatement.py  | 12 
+---
 BaseTools/Source/Python/GenFds/Fv.py   | 48 

 BaseTools/Source/Python/GenFds/FvImageSection.py   |  2 +-
 BaseTools/Source/Python/GenFds/GenFds.py   | 22 
+++---
 BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py |  4 
++--
 BaseTools/Source/Python/GenFds/Region.py   |  6 
+++---
 BaseTools/Source/Python/Pkcs7Sign/Pkcs7Sign.py |  2 +-
 BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256GenerateKeys.py | 14 
+++---
 BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py |  7 
---
 BaseTools/Source/Python/Trim/Trim.py   | 18 
--
 BaseTools/Source/Python/UPT/Library/StringUtils.py |  4 
+---
 BaseTools/Source/Python/Workspace/BuildClassObject.py  |  4 
++--
 BaseTools/Source/Python/Workspace/DscBuildData.py  | 13 
++---
 BaseTools/Source/Python/Workspace/MetaFileParser.py|  4 
++--
 BaseTools/Source/Python/build/BuildReport.py   | 15 
+++
 BaseTools/Source/Python/build/build.py | 44 
+---
 37 files changed, 247 insertions(+), 244 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py 
b/BaseTools/Source/Python/AutoGen/AutoGen.py
index baa1842667..a95d2c710e 100644
--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
@@ -724,15 +724,15 @@ class WorkspaceAutoGen(AutoGen):
 if GlobalData.gUseHashCache:
 m = hashlib.md5()
 for files in AllWorkSpaceMetaFiles:
 if files.endswith('.dec'):
 continue
-f = open(files, 'r')
+f = open(files, 'rb')
 Content = f.read()
 f.close()
 m.update(Content)
-SaveFileOnChange(os.path.join(self.BuildDir, 'AutoGen.hash'), 
m.hexdigest(), True)
+SaveFileOnChange(os.path.join(self.BuildDir, 'AutoGen.hash'), 
m.hexdigest(), False)
 GlobalData.gPlatformHash = m.hexdigest()
 
 #
 # Write metafile list to build directory
 #
@@ -753,25 +753,25 @@ class WorkspaceAutoGen(AutoGen):
 PkgDir = os.path.join(self.BuildDir, Pkg.Arch, Pkg.PackageName)
 CreateDirectory(PkgDir)
 HashFile = os.path.join(PkgDir, Pkg.PackageName + '.hash')
 m = hashlib.md5()
 # Get .dec file's

[edk2] [Patch 27/33] BaseTools: Update PYTHON env to PYTHON_COMMAND

2019-01-28 Thread Feng, Bob C
From: Liming Gao 

Update PYTHON env to PYTHON_COMMAND.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Liming Gao 
---
 BaseTools/Bin/CYGWIN_NT-5.1-i686/Ecc|  6 +++---
 BaseTools/Bin/CYGWIN_NT-5.1-i686/GenDepex   |  6 +++---
 BaseTools/Bin/CYGWIN_NT-5.1-i686/GenFds |  6 +++---
 BaseTools/Bin/CYGWIN_NT-5.1-i686/TargetTool |  6 +++---
 BaseTools/Bin/CYGWIN_NT-5.1-i686/Trim   |  6 +++---
 BaseTools/Bin/CYGWIN_NT-5.1-i686/build  |  6 +++---
 BaseTools/BinWrappers/PosixLike/BPDG|  6 +++---
 BaseTools/BinWrappers/PosixLike/Ecc |  6 +++---
 BaseTools/BinWrappers/PosixLike/GenDepex|  6 +++---
 BaseTools/BinWrappers/PosixLike/GenFds  |  6 +++---
 BaseTools/BinWrappers/PosixLike/GenPatchPcdTable|  6 +++---
 BaseTools/BinWrappers/PosixLike/GenerateCapsule |  6 +++---
 BaseTools/BinWrappers/PosixLike/PatchPcdValue   |  6 +++---
 BaseTools/BinWrappers/PosixLike/Pkcs7Sign   |  6 +++---
 BaseTools/BinWrappers/PosixLike/Rsa2048Sha256GenerateKeys   |  6 +++---
 BaseTools/BinWrappers/PosixLike/Rsa2048Sha256Sign   |  6 +++---
 BaseTools/BinWrappers/PosixLike/TargetTool  |  6 +++---
 BaseTools/BinWrappers/PosixLike/Trim|  6 +++---
 BaseTools/BinWrappers/PosixLike/UPT |  6 +++---
 BaseTools/BinWrappers/PosixLike/build   |  6 +++---
 BaseTools/BinWrappers/WindowsLike/BPDG.bat  |  2 +-
 BaseTools/BinWrappers/WindowsLike/Ecc.bat   |  2 +-
 BaseTools/BinWrappers/WindowsLike/GenDepex.bat  |  2 +-
 BaseTools/BinWrappers/WindowsLike/GenFds.bat|  2 +-
 BaseTools/BinWrappers/WindowsLike/GenPatchPcdTable.bat  |  2 +-
 BaseTools/BinWrappers/WindowsLike/GenerateCapsule.bat   |  2 +-
 BaseTools/BinWrappers/WindowsLike/PatchPcdValue.bat |  2 +-
 BaseTools/BinWrappers/WindowsLike/Pkcs7Sign.bat |  2 +-
 BaseTools/BinWrappers/WindowsLike/Rsa2048Sha256GenerateKeys.bat |  2 +-
 BaseTools/BinWrappers/WindowsLike/Rsa2048Sha256Sign.bat |  2 +-
 BaseTools/BinWrappers/WindowsLike/TargetTool.bat|  2 +-
 BaseTools/BinWrappers/WindowsLike/Trim.bat  |  2 +-
 BaseTools/BinWrappers/WindowsLike/UPT.bat   |  2 +-
 BaseTools/BinWrappers/WindowsLike/build.bat |  2 +-
 BaseTools/Makefile  | 12 

 BaseTools/Source/C/Makefile | 12 

 BaseTools/Source/Python/build/build.py  |  3 ++-
 BaseTools/Tests/GNUmakefile |  2 +-
 BaseTools/Tests/PythonTest.py   | 15 
+++
 BaseTools/toolsetup.bat | 80 

 edksetup.sh | 42 
++
 41 files changed, 194 insertions(+), 120 deletions(-)

diff --git a/BaseTools/Bin/CYGWIN_NT-5.1-i686/Ecc 
b/BaseTools/Bin/CYGWIN_NT-5.1-i686/Ecc
index 8532fe510d..1ba451cf5e 100755
--- a/BaseTools/Bin/CYGWIN_NT-5.1-i686/Ecc
+++ b/BaseTools/Bin/CYGWIN_NT-5.1-i686/Ecc
@@ -1,11 +1,11 @@
 #!/usr/bin/env bash
 #python `dirname $0`/RunToolFromSource.py `basename $0` $*
 
-# If a ${PYTHON} command is available, use it in preference to python
-if command -v ${PYTHON} >/dev/null 2>&1; then
-python_exe=${PYTHON}
+# If a ${PYTHON_COMMAND} command is available, use it in preference to python
+if command -v ${PYTHON_COMMAND} >/dev/null 2>&1; then
+python_exe=${PYTHON_COMMAND}
 fi
 
 full_cmd=${BASH_SOURCE:-$0} # see http://mywiki.wooledge.org/BashFAQ/028 for a 
discussion of why $0 is not a good choice here
 dir=$(dirname "$full_cmd")
 cmd=${full_cmd##*/}
diff --git a/BaseTools/Bin/CYGWIN_NT-5.1-i686/GenDepex 
b/BaseTools/Bin/CYGWIN_NT-5.1-i686/GenDepex
index 8532fe510d..1ba451cf5e 100755
--- a/BaseTools/Bin/CYGWIN_NT-5.1-i686/GenDepex
+++ b/BaseTools/Bin/CYGWIN_NT-5.1-i686/GenDepex
@@ -1,11 +1,11 @@
 #!/usr/bin/env bash
 #python `dirname $0`/RunToolFromSource.py `basename $0` $*
 
-# If a ${PYTHON} command is available, use it in preference to python
-if command -v ${PYTHON} >/dev/null 2>&1; then
-python_exe=${PYTHON}
+# If a ${PYTHON_COMMAND} command is available, use it in preference to python
+if command -v ${PYTHON_COMMAND} >/dev/null 2>&1; then
+python_exe=${PYTHON_COMMAND}
 fi
 
 full_cmd=${BASH_SOURCE:-$0} # see http://mywiki.wooledge.org/BashFAQ/028 for a 
discussion of why $0 is not a

[edk2] [Patch 28/33] BaseTools:Fixed Rsa issue and a set define issue.

2019-01-28 Thread Feng, Bob C
ValueError: non-hexadecimal number found in
 fromhex() arg at position 0

Cc: Bob Feng 
Cc: Liming Gao 
Cc: Yonghong Zhu 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhiju.Fan 
---
 BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py 
b/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py
index d2bb0c998c..c285a69ec0 100644
--- a/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py
+++ b/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py
@@ -154,11 +154,11 @@ if __name__ == '__main__':
   #
   Process = subprocess.Popen('%s rsa -in "%s" -modulus -noout' % 
(OpenSslCommand, args.PrivateKeyFileName), stdout=subprocess.PIPE, 
stderr=subprocess.PIPE, shell=True)
   PublicKeyHexString = Process.communicate()[0].split('=')[1].strip()
   PublicKey = ''
   while len(PublicKeyHexString) > 0:
-PublicKey = PublicKey + chr(int(PublicKeyHexString[0:2], 16))
+PublicKey = PublicKey + PublicKeyHexString[0:2]
 PublicKeyHexString=PublicKeyHexString[2:]
   if Process.returncode != 0:
 sys.exit(Process.returncode)
 
   if args.MonotonicCountStr:
@@ -186,11 +186,11 @@ if __name__ == '__main__':
 #
 # Write output file that contains hash GUID, Public Key, Signature, and 
Input data
 #
 args.OutputFile = open(args.OutputFileName, 'wb')
 args.OutputFile.write(EFI_HASH_ALGORITHM_SHA256_GUID.bytes_le)
-args.OutputFile.write(PublicKey)
+args.OutputFile.write(bytearray.fromhex(str(PublicKey)))
 args.OutputFile.write(Signature)
 args.OutputFile.write(args.InputFileBuffer)
 args.OutputFile.close()
 
   if args.Decode:
-- 
2.20.1.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [Patch 26/33] BaseTools:Linux Python highest version check.

2019-01-28 Thread Feng, Bob C
From: Zhijux Fan 

Linux Python highest version check.
The path of Python interpreter assign values to PYTHON_COMMAND

Cc: Bob Feng 
Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhiju.Fan 
---
 edksetup.sh | 16 +++-
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/edksetup.sh b/edksetup.sh
index 06f95f4b9c..bfa54ddf70 100755
--- a/edksetup.sh
+++ b/edksetup.sh
@@ -113,15 +113,18 @@ function SetupEnv()
 
 function SetupPython()
 {
   if [ $PYTHON3_ENABLE ] && [ $PYTHON3_ENABLE == TRUE ]
   then
-for python in $(which python3)
+if [ $origin_version ];then
+  origin_version=
+fi
+for python in $(whereis python3)
 do
   python=$(echo $python | grep "[[:digit:]]$" || true)
   python_version=${python##*python}
-  if [ -z "${python_version}" ];then
+  if [ -z "${python_version}" ] || (! command -v $python >/dev/null 
2>&1);then
 continue
   fi
   if [ -z $origin_version ];then
 origin_version=$python_version
 export PYTHON=$python
@@ -135,18 +138,21 @@ function SetupPython()
 done
   fi
   
   if [ -z $PYTHON3_ENABLE ] || [ $PYTHON3_ENABLE != TRUE ]
   then
-for python in $(which python2)
+if [ $origin_version ];then
+  origin_version=
+fi
+for python in $(whereis python2)
 do
   python=$(echo $python | grep "[[:digit:]]$" || true)
   python_version=${python##*python}
-  if [ -z "${python_version}" ];then
+  if [ -z "${python_version}" ] || (! command -v $python >/dev/null 
2>&1);then
 continue
   fi
-  if [ -z $origin_version ] || [ $origin_version -ge 3 ]
+  if [ -z $origin_version ]
   then
 origin_version=$python_version
 export PYTHON=$python
 continue
   fi
-- 
2.20.1.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [Patch 30/33] BaseTools: the list and iterator translation

2019-01-28 Thread Feng, Bob C
In python3,The keys of the dictionary not a list,It needs to be converted

Cc: Bob Feng 
Cc: Liming Gao 
Cc: Yonghong Zhu 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhiju.Fan 
---
 BaseTools/Source/Python/AutoGen/AutoGen.py | 26 
+-
 BaseTools/Source/Python/AutoGen/GenC.py|  2 +-
 BaseTools/Source/Python/AutoGen/GenMake.py | 16 
 BaseTools/Source/Python/AutoGen/GenPcdDb.py|  4 ++--
 BaseTools/Source/Python/AutoGen/StrGather.py   |  4 ++--
 BaseTools/Source/Python/Common/Misc.py |  5 +++--
 BaseTools/Source/Python/Common/StringUtils.py  |  6 +++---
 BaseTools/Source/Python/GenFds/FfsInfStatement.py  |  2 +-
 BaseTools/Source/Python/Workspace/DscBuildData.py  | 16 
 BaseTools/Source/Python/Workspace/InfBuildData.py  |  4 ++--
 BaseTools/Source/Python/Workspace/MetaDataTable.py |  2 +-
 BaseTools/Source/Python/build/BuildReport.py   |  4 ++--
 BaseTools/Source/Python/build/build.py |  2 +-
 13 files changed, 47 insertions(+), 46 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py 
b/BaseTools/Source/Python/AutoGen/AutoGen.py
index 5f0da5a815..baa1842667 100644
--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
@@ -927,11 +927,11 @@ class WorkspaceAutoGen(AutoGen):
 # @return  None
 #
 def _CheckAllPcdsTokenValueConflict(self):
 for Pa in self.AutoGenObjectList:
 for Package in Pa.PackageList:
-PcdList = Package.Pcds.values()
+PcdList = list(Package.Pcds.values())
 PcdList.sort(key=lambda x: int(x.TokenValue, 0))
 Count = 0
 while (Count < len(PcdList) - 1) :
 Item = PcdList[Count]
 ItemNext = PcdList[Count + 1]
@@ -973,11 +973,11 @@ class WorkspaceAutoGen(AutoGen):
 )
 SameTokenValuePcdListCount += 1
 Count += SameTokenValuePcdListCount
 Count += 1
 
-PcdList = Package.Pcds.values()
+PcdList = list(Package.Pcds.values())
 PcdList.sort(key=lambda x: "%s.%s" % (x.TokenSpaceGuidCName, 
x.TokenCName))
 Count = 0
 while (Count < len(PcdList) - 1) :
 Item = PcdList[Count]
 ItemNext = PcdList[Count + 1]
@@ -1298,11 +1298,11 @@ class PlatformAutoGen(AutoGen):
 
 if PcdNvStoreDfBuffer:
 if os.path.exists(VpdMapFilePath):
 OrgVpdFile.Read(VpdMapFilePath)
 PcdItems = OrgVpdFile.GetOffset(PcdNvStoreDfBuffer[0])
-NvStoreOffset = PcdItems.values()[0].strip() if PcdItems 
else '0'
+NvStoreOffset = list(PcdItems.values())[0].strip() if 
PcdItems else '0'
 else:
 EdkLogger.error("build", FILE_READ_FAILURE, "Can not find 
VPD map file %s to fix up VPD offset." % VpdMapFilePath)
 
 NvStoreOffset = int(NvStoreOffset, 16) if 
NvStoreOffset.upper().startswith("0X") else int(NvStoreOffset)
 default_skuobj = 
PcdNvStoreDfBuffer[0].SkuInfoList.get(TAB_DEFAULT)
@@ -1497,11 +1497,11 @@ class PlatformAutoGen(AutoGen):
 self._PlatformPcds[item].DatumType = TAB_VOID
 
 if (self.Workspace.ArchList[-1] == self.Arch):
 for Pcd in self._DynamicPcdList:
 # just pick the a value to determine whether is unicode string 
type
-Sku = Pcd.SkuInfoList.values()[0]
+Sku = Pcd.SkuInfoList.get(TAB_DEFAULT)
 Sku.VpdOffset = Sku.VpdOffset.strip()
 
 if Pcd.DatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, 
TAB_UINT64, TAB_VOID, "BOOLEAN"]:
 Pcd.DatumType = TAB_VOID
 
@@ -1603,11 +1603,11 @@ class PlatformAutoGen(AutoGen):
 
 # Not found, it should be signature
 if not FoundFlag :
 # just pick the a value to determine whether is 
unicode string type
 SkuValueMap = {}
-SkuObjList = DscPcdEntry.SkuInfoList.items()
+SkuObjList = list(DscPcdEntry.SkuInfoList.items())
 DefaultSku = 
DscPcdEntry.SkuInfoList.get(TAB_DEFAULT)
 if DefaultSku:
 defaultindex = SkuObjList.index((TAB_DEFAULT, 
DefaultSku))
 SkuObjList[0], SkuObjList[defaultindex] = 
SkuObjList[defaultindex], SkuObjList[0]
 for (SkuName, Sku) in SkuObjList:
@@ -1629,11 +1629,11 @@ class PlatformAutoGen(AutoGen):
 DscPcdEntry.DefaultValue = 
DecPcdE

[edk2] [Patch 25/33] BaseTools:Update build tool to print python version information

2019-01-28 Thread Feng, Bob C
From: Zhijux Fan 

print PYTHON3_ENABLE and PYTHON_COMMAND in build tool

Cc: Bob Feng 
Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhiju.Fan 
---
 BaseTools/Source/Python/build/build.py | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/BaseTools/Source/Python/build/build.py 
b/BaseTools/Source/Python/build/build.py
index 139a1dfe29..b5b969e876 100644
--- a/BaseTools/Source/Python/build/build.py
+++ b/BaseTools/Source/Python/build/build.py
@@ -789,10 +789,16 @@ class Build():
 EdkLogger.quiet("%-16s = %s" % ("EDK_TOOLS_PATH", 
os.environ["EDK_TOOLS_PATH"]))
 if "EDK_TOOLS_BIN" in os.environ:
 # Print the same path style with WORKSPACE env.
 EdkLogger.quiet("%-16s = %s" % ("EDK_TOOLS_BIN", 
os.path.normcase(os.path.normpath(os.environ["EDK_TOOLS_BIN"]
 EdkLogger.quiet("%-16s = %s" % ("CONF_PATH", 
GlobalData.gConfDirectory))
+if "PYTHON3_ENABLE" in os.environ:
+PYTHON3_ENABLE = os.environ["PYTHON3_ENABLE"]
+if PYTHON3_ENABLE != "TRUE":
+PYTHON3_ENABLE = "FALSE"
+EdkLogger.quiet("%-16s = %s" % ("PYTHON3_ENABLE", PYTHON3_ENABLE))
+EdkLogger.quiet("%-16s = %s" % ("PYTHON", os.environ["PYTHON"]))
 self.InitPreBuild()
 self.InitPostBuild()
 if self.Prebuild:
 EdkLogger.quiet("%-16s = %s" % ("PREBUILD", self.Prebuild))
 if self.Postbuild:
-- 
2.20.1.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [Patch 22/33] BaseTools:There is extra blank line in datalog

2019-01-28 Thread Feng, Bob C
From: Zhiju Fan 

There should be no blank line across every
line in datalog if open it with Notepad++.

Cc: Bob Feng 
Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhiju.Fan 
---
 BaseTools/Source/Python/build/BuildReport.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/BaseTools/Source/Python/build/BuildReport.py 
b/BaseTools/Source/Python/build/BuildReport.py
index b940de1c90..ff632b6759 100644
--- a/BaseTools/Source/Python/build/BuildReport.py
+++ b/BaseTools/Source/Python/build/BuildReport.py
@@ -248,11 +248,11 @@ def FileLinesSplit(Content=None, MaxLength=None):
 if Line:
 NewContentList.append(Line)
 for NewLine in NewContentList:
 NewContent += NewLine + TAB_LINE_BREAK
 
-NewContent = NewContent.replace(TAB_LINE_BREAK, 
gEndOfLine).replace('\r\r\n', gEndOfLine)
+NewContent = NewContent.replace(gEndOfLine, 
TAB_LINE_BREAK).replace('\r\r\n', gEndOfLine)
 return NewContent
 
 
 
 ##
-- 
2.20.1.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [Patch 24/33] BaseTools: Update windows and linux run scripts file to use Python3

2019-01-28 Thread Feng, Bob C
From: Zhijux Fan 

Modify windows script, PosixLike script, edksetup.sh, edksetup.bat to
use Python3 based on PYTHON3_ENABLE environment.

Cc: Bob Feng 
Cc: Liming Gao 
Cc: Yonghong Zhu 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhiju.Fan 
---
 BaseTools/Bin/CYGWIN_NT-5.1-i686/Ecc|  6 +++---
 BaseTools/Bin/CYGWIN_NT-5.1-i686/GenDepex   |  6 +++---
 BaseTools/Bin/CYGWIN_NT-5.1-i686/GenFds |  6 +++---
 BaseTools/Bin/CYGWIN_NT-5.1-i686/TargetTool |  6 +++---
 BaseTools/Bin/CYGWIN_NT-5.1-i686/Trim   |  6 +++---
 BaseTools/Bin/CYGWIN_NT-5.1-i686/build  |  6 +++---
 BaseTools/BinWrappers/PosixLike/BPDG|  6 +++---
 BaseTools/BinWrappers/PosixLike/Ecc |  6 +++---
 BaseTools/BinWrappers/PosixLike/GenDepex|  6 +++---
 BaseTools/BinWrappers/PosixLike/GenFds  |  6 +++---
 BaseTools/BinWrappers/PosixLike/GenPatchPcdTable|  6 +++---
 BaseTools/BinWrappers/PosixLike/GenerateCapsule |  6 +++---
 BaseTools/BinWrappers/PosixLike/PatchPcdValue   |  6 +++---
 BaseTools/BinWrappers/PosixLike/Pkcs7Sign   |  6 +++---
 BaseTools/BinWrappers/PosixLike/Rsa2048Sha256GenerateKeys   |  6 +++---
 BaseTools/BinWrappers/PosixLike/Rsa2048Sha256Sign   |  6 +++---
 BaseTools/BinWrappers/PosixLike/TargetTool  |  6 +++---
 BaseTools/BinWrappers/PosixLike/Trim|  6 +++---
 BaseTools/BinWrappers/PosixLike/UPT |  6 +++---
 BaseTools/BinWrappers/PosixLike/build   |  6 +++---
 BaseTools/BinWrappers/WindowsLike/BPDG.bat  |  2 +-
 BaseTools/BinWrappers/WindowsLike/Ecc.bat   |  2 +-
 BaseTools/BinWrappers/WindowsLike/GenDepex.bat  |  2 +-
 BaseTools/BinWrappers/WindowsLike/GenFds.bat|  2 +-
 BaseTools/BinWrappers/WindowsLike/GenPatchPcdTable.bat  |  2 +-
 BaseTools/BinWrappers/WindowsLike/GenerateCapsule.bat   |  2 +-
 BaseTools/BinWrappers/WindowsLike/PatchPcdValue.bat |  2 +-
 BaseTools/BinWrappers/WindowsLike/Pkcs7Sign.bat |  2 +-
 BaseTools/BinWrappers/WindowsLike/Rsa2048Sha256GenerateKeys.bat |  2 +-
 BaseTools/BinWrappers/WindowsLike/Rsa2048Sha256Sign.bat |  2 +-
 BaseTools/BinWrappers/WindowsLike/TargetTool.bat|  2 +-
 BaseTools/BinWrappers/WindowsLike/Trim.bat  |  2 +-
 BaseTools/BinWrappers/WindowsLike/UPT.bat   |  2 +-
 BaseTools/BinWrappers/WindowsLike/build.bat |  2 +-
 BaseTools/Makefile  |  8 
 BaseTools/Source/C/Makefile |  8 
 BaseTools/Tests/GNUmakefile |  2 +-
 BaseTools/toolsetup.bat | 53 
-
 edksetup.sh | 51 
++-
 39 files changed, 177 insertions(+), 93 deletions(-)

diff --git a/BaseTools/Bin/CYGWIN_NT-5.1-i686/Ecc 
b/BaseTools/Bin/CYGWIN_NT-5.1-i686/Ecc
index 214d88fff1..8532fe510d 100755
--- a/BaseTools/Bin/CYGWIN_NT-5.1-i686/Ecc
+++ b/BaseTools/Bin/CYGWIN_NT-5.1-i686/Ecc
@@ -1,11 +1,11 @@
 #!/usr/bin/env bash
 #python `dirname $0`/RunToolFromSource.py `basename $0` $*
 
-# If a python2 command is available, use it in preference to python
-if command -v python2 >/dev/null 2>&1; then
-python_exe=python2
+# If a ${PYTHON} command is available, use it in preference to python
+if command -v ${PYTHON} >/dev/null 2>&1; then
+python_exe=${PYTHON}
 fi
 
 full_cmd=${BASH_SOURCE:-$0} # see http://mywiki.wooledge.org/BashFAQ/028 for a 
discussion of why $0 is not a good choice here
 dir=$(dirname "$full_cmd")
 cmd=${full_cmd##*/}
diff --git a/BaseTools/Bin/CYGWIN_NT-5.1-i686/GenDepex 
b/BaseTools/Bin/CYGWIN_NT-5.1-i686/GenDepex
index 214d88fff1..8532fe510d 100755
--- a/BaseTools/Bin/CYGWIN_NT-5.1-i686/GenDepex
+++ b/BaseTools/Bin/CYGWIN_NT-5.1-i686/GenDepex
@@ -1,11 +1,11 @@
 #!/usr/bin/env bash
 #python `dirname $0`/RunToolFromSource.py `basename $0` $*
 
-# If a python2 command is available, use it in preference to python
-if command -v python2 >/dev/null 2>&1; then
-python_exe=python2
+# If a ${PYTHON} command is available, use it in preference to python
+if command -v ${PYTHON} >/dev/null 2>&1; then
+python_exe=${PYTHON}
 fi
 
 full_cmd=${BASH_SOURCE:-$0} # see http://mywiki.wooledge.org/BashFAQ/028 for a 
discussion of why $0 is not a good choice here
 dir=$(dirname "$full_cmd")
 cmd=${full_cmd##*/}
diff --git a/BaseTools/Bin/CYGWIN_NT-5.1-i686/GenFds 

[edk2] [Patch 29/33] BaseTools:ord() don't match in py2 and py3

2019-01-28 Thread Feng, Bob C
In python2, the FvHeaderBuffer Type is a str
In python3, the FvHeaderBuffer Type is a bytes

Cc: Bob Feng 
Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhiju.Fan 
---
 BaseTools/Source/Python/GenFds/FvImageSection.py | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/BaseTools/Source/Python/GenFds/FvImageSection.py 
b/BaseTools/Source/Python/GenFds/FvImageSection.py
index 535b86ab5e..7ea931e1b5 100644
--- a/BaseTools/Source/Python/GenFds/FvImageSection.py
+++ b/BaseTools/Source/Python/GenFds/FvImageSection.py
@@ -69,11 +69,14 @@ class FvImageSection(FvImageSectionClassObject):
 FvFileObj = open (FvFileName, 'rb')
 FvFileObj.seek(0)
 # PI FvHeader is 0x48 byte
 FvHeaderBuffer = FvFileObj.read(0x48)
 # FV alignment position.
-FvAlignmentValue = 1 << (FvHeaderBuffer[0x2E] & 0x1F)
+if isinstance(FvHeaderBuffer[0x2E], str):
+FvAlignmentValue = 1 << (ord(FvHeaderBuffer[0x2E]) & 
0x1F)
+else:
+FvAlignmentValue = 1 << (FvHeaderBuffer[0x2E] & 0x1F)
 FvFileObj.close()
 if FvAlignmentValue > MaxFvAlignment:
 MaxFvAlignment = FvAlignmentValue
 
 OutputFile = os.path.join(OutputPath, ModuleName + 
SUP_MODULE_SEC + Num + SectionSuffix.get("FV_IMAGE"))
@@ -119,11 +122,14 @@ class FvImageSection(FvImageSectionClassObject):
 FvFileObj = open (FvFileName, 'rb')
 FvFileObj.seek(0)
 # PI FvHeader is 0x48 byte
 FvHeaderBuffer = FvFileObj.read(0x48)
 # FV alignment position.
-FvAlignmentValue = 1 << (ord (FvHeaderBuffer[0x2E]) & 
0x1F)
+if isinstance(FvHeaderBuffer[0x2E], str):
+FvAlignmentValue = 1 << (ord(FvHeaderBuffer[0x2E]) 
& 0x1F)
+else:
+FvAlignmentValue = 1 << (FvHeaderBuffer[0x2E] & 
0x1F)
 # FvAlignmentValue is larger than or equal to 1K
 if FvAlignmentValue >= 0x400:
 if FvAlignmentValue >= 0x10:
 #The max alignment supported by FFS is 16M.
 if FvAlignmentValue >= 0x100:
-- 
2.20.1.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [Patch 23/33] BaseTools: Similar to octal data rectification

2019-01-28 Thread Feng, Bob C
From: Zhijux Fan 

In python3, if Value is octal data, the int(Value, 0) report an error

Cc: Bob Feng 
Cc: Liming Gao 
Cc: Yonghong Zhu 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhiju.Fan 
---
 BaseTools/Source/Python/AutoGen/GenC.py  |  2 +-
 BaseTools/Source/Python/Common/Misc.py   |  2 +-
 BaseTools/Source/Python/build/BuildReport.py | 17 +++--
 3 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/GenC.py 
b/BaseTools/Source/Python/AutoGen/GenC.py
index e46942a3e2..f1f3b6f359 100644
--- a/BaseTools/Source/Python/AutoGen/GenC.py
+++ b/BaseTools/Source/Python/AutoGen/GenC.py
@@ -1008,11 +1008,11 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
 
 if Pcd.DatumType in TAB_PCD_CLEAN_NUMERIC_TYPES:
 try:
 if Value.upper().endswith('L'):
 Value = Value[:-1]
-if Value.startswith('0') and not 
Value.lower().startswith('0x') and len(Value) > 2:
+if Value.startswith('0') and not 
Value.lower().startswith('0x') and len(Value) > 1 and Value.lstrip('0'):
 Value = Value.lstrip('0')
 ValueNumber = int (Value, 0)
 except:
 EdkLogger.error("build", AUTOGEN_ERROR,
 "PCD value is not valid dec or hex number for 
datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, 
TokenCName),
diff --git a/BaseTools/Source/Python/Common/Misc.py 
b/BaseTools/Source/Python/Common/Misc.py
index bd7c2812e8..e0e355286b 100644
--- a/BaseTools/Source/Python/Common/Misc.py
+++ b/BaseTools/Source/Python/Common/Misc.py
@@ -1308,11 +1308,11 @@ def CheckPcdDatum(Type, Value):
 elif Type == 'BOOLEAN':
 if Value not in ['TRUE', 'True', 'true', '0x1', '0x01', '1', 'FALSE', 
'False', 'false', '0x0', '0x00', '0']:
 return False, "Invalid value [%s] of type [%s]; must be one of 
TRUE, True, true, 0x1, 0x01, 1"\
   ", FALSE, False, false, 0x0, 0x00, 0" % (Value, Type)
 elif Type in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64]:
-if Value.startswith('0') and not Value.lower().startswith('0x') and 
len(Value) > 2:
+if Value.startswith('0') and not Value.lower().startswith('0x') and 
len(Value) > 1 and Value.lstrip('0'):
 Value = Value.lstrip('0')
 try:
 if Value and int(Value, 0) < 0:
 return False, "PCD can't be set to negative value[%s] for 
datum type [%s]" % (Value, Type)
 Value = int(Value, 0)
diff --git a/BaseTools/Source/Python/build/BuildReport.py 
b/BaseTools/Source/Python/build/BuildReport.py
index ff632b6759..9483262dd1 100644
--- a/BaseTools/Source/Python/build/BuildReport.py
+++ b/BaseTools/Source/Python/build/BuildReport.py
@@ -1024,33 +1024,37 @@ class PcdReport(object):
 FileWrite(File, Key)
 First = False
 
 
 if Pcd.DatumType in TAB_PCD_NUMERIC_TYPES:
-if PcdValue.startswith('0') and not 
PcdValue.lower().startswith('0x') and len(PcdValue) > 2:
+if PcdValue.startswith('0') and not 
PcdValue.lower().startswith('0x') and \
+len(PcdValue) > 1 and PcdValue.lstrip('0'):
 PcdValue = PcdValue.lstrip('0')
 PcdValueNumber = int(PcdValue.strip(), 0)
 if DecDefaultValue is None:
 DecMatch = True
 else:
-if DecDefaultValue.startswith('0') and not 
DecDefaultValue.lower().startswith('0x') and len(DecDefaultValue) > 2:
+if DecDefaultValue.startswith('0') and not 
DecDefaultValue.lower().startswith('0x') and \
+len(DecDefaultValue) > 1 and 
DecDefaultValue.lstrip('0'):
 DecDefaultValue = DecDefaultValue.lstrip('0')
 DecDefaultValueNumber = int(DecDefaultValue.strip(), 0)
 DecMatch = (DecDefaultValueNumber == PcdValueNumber)
 
 if InfDefaultValue is None:
 InfMatch = True
 else:
-if InfDefaultValue.startswith('0') and not 
InfDefaultValue.lower().startswith('0x') and len(InfDefaultValue) > 2:
+if InfDefaultValue.startswith('0') and not 
InfDefaultValue.lower().startswith('0x') and \
+len(InfDefaultValue) > 1 and 
InfDefaultValue.lstrip('0'):
 InfDefaultValue = InfDefaultValue.lstrip('0')
 InfDefaultValueNumber = int(InfDefaultValue.strip(), 0)
 InfMatch = (InfDefaultValueNumber == PcdValueNumber)
 
 if DscDefaultValue is None:
 DscMatch = True
 else:
- 

[edk2] [Patch 18/33] BaseTools:TestTools character encoding issue

2019-01-28 Thread Feng, Bob C
From: Zhiju Fan 

Specifies encoding when opening a file using codecs

Cc: Bob Feng 
Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhiju.Fan 
---
 BaseTools/Tests/TestTools.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/BaseTools/Tests/TestTools.py b/BaseTools/Tests/TestTools.py
index 4332dcdaac..ace92992fc 100644
--- a/BaseTools/Tests/TestTools.py
+++ b/BaseTools/Tests/TestTools.py
@@ -22,10 +22,11 @@ import os.path
 import random
 import shutil
 import subprocess
 import sys
 import unittest
+import codecs
 
 TestsDir = os.path.realpath(os.path.split(sys.argv[0])[0])
 BaseToolsDir = os.path.realpath(os.path.join(TestsDir, '..'))
 CSourceDir = os.path.join(BaseToolsDir, 'Source', 'C')
 PythonSourceDir = os.path.join(BaseToolsDir, 'Source', 'Python')
@@ -148,11 +149,11 @@ class BaseToolsTest(unittest.TestCase):
 def WriteTmpFile(self, fileName, data):
 if isinstance(data, bytes):
 with open(self.GetTmpFilePath(fileName), 'wb') as f:
 f.write(data)
 else:
-with open(self.GetTmpFilePath(fileName), 'w') as f:
+with codecs.open(self.GetTmpFilePath(fileName), 'w', 
encoding='utf-8') as f:
 f.write(data)
 
 def GenRandomFileData(self, fileName, minlen = None, maxlen = None):
 if maxlen is None: maxlen = minlen
 f = self.OpenTmpFile(fileName, 'w')
-- 
2.20.1.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [Patch 19/33] BaseTools:Double carriage return inserted from Trim.py on Python3

2019-01-28 Thread Feng, Bob C
From: Zhiju Fan 

https://bugzilla.tianocore.org/show_bug.cgi?id=1379

Line 208 of BaseTools/Source/Python/Trim/Trim.py uses
'NewLines.append(os.linesep)' to insert a new line into
the list that will be written to the output file.
This causes the '\r\n' inserted with os.linesep to be
written as '\r\r\n', causing some assemblers to error.

Cc: Bob Feng 
Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhiju.Fan 
---
 BaseTools/Source/Python/Trim/Trim.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/BaseTools/Source/Python/Trim/Trim.py 
b/BaseTools/Source/Python/Trim/Trim.py
index 4b3091bec3..51010bf326 100644
--- a/BaseTools/Source/Python/Trim/Trim.py
+++ b/BaseTools/Source/Python/Trim/Trim.py
@@ -203,11 +203,11 @@ def TrimPreprocessedFile(Source, Target, ConvertHex, 
TrimLong):
 # possible?
 NewLines[LineNumber - 1] = Line
 else:
 if LineNumber > (len(NewLines) + 1):
 for LineIndex in range(len(NewLines), LineNumber-1):
-NewLines.append(os.linesep)
+NewLines.append(TAB_LINE_BREAK)
 NewLines.append(Line)
 LineNumber = None
 EdkLogger.verbose("Now we have lines: %d" % len(NewLines))
 else:
 NewLines.append(Line)
-- 
2.20.1.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [Patch 20/33] BaseTools:File open failed for VPD MapFile

2019-01-28 Thread Feng, Bob C
correct open MapFile support python2 and python3

Cc: Bob Feng 
Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhiju.Fan 
---
 BaseTools/Source/Python/BPDG/GenVpd.py | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/BaseTools/Source/Python/BPDG/GenVpd.py 
b/BaseTools/Source/Python/BPDG/GenVpd.py
index b91837d3d6..71fcfc5ac3 100644
--- a/BaseTools/Source/Python/BPDG/GenVpd.py
+++ b/BaseTools/Source/Python/BPDG/GenVpd.py
@@ -649,11 +649,11 @@ class GenVPD :
 except:
 # Open failed
 EdkLogger.error("BPDG", BuildToolError.FILE_OPEN_FAILURE, "File 
open failed for %s" % self.VpdFileName, None)
 
 try :
-fMapFile = open(MapFileName, "w", 0)
+fMapFile = open(MapFileName, "w")
 except:
 # Open failed
 EdkLogger.error("BPDG", BuildToolError.FILE_OPEN_FAILURE, "File 
open failed for %s" % self.MapFileName, None)
 
 # Use a instance of BytesIO to cache data
@@ -673,12 +673,16 @@ class GenVPD :
 EdkLogger.error("BPDG", BuildToolError.FILE_WRITE_FAILURE, 
"Write data to file %s failed, please check whether the file been locked or 
using by other applications." % self.MapFileName, None)
 
 # Write Vpd binary file
 fStringIO.seek (eachPcd.PcdBinOffset)
 if isinstance(eachPcd.PcdValue, list):
-ValueList = [chr(Item) for Item in eachPcd.PcdValue]
-fStringIO.write(''.join(ValueList))
+for i in range(len(eachPcd.PcdValue)):
+Value = eachPcd.PcdValue[i:i + 1]
+if isinstance(bytes(Value), str):
+fStringIO.write(chr(Value[0]))
+else:
+fStringIO.write(bytes(Value))
 else:
 fStringIO.write (eachPcd.PcdValue)
 
 try :
 fVpdFile.write (fStringIO.getvalue())
-- 
2.20.1.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [Patch 15/33] Basetools: It went wrong when use os.linesep

2019-01-28 Thread Feng, Bob C
From: Zhijux Fan 

in python2 and python3,use of line breaks

Cc: Bob Feng 
Cc: Liming Gao 
Cc: Yonghong Zhu 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhiju.Fan 
---
 BaseTools/Source/Python/AutoGen/AutoGen.py | 10 +-
 BaseTools/Source/Python/AutoGen/GenMake.py |  4 ++--
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py 
b/BaseTools/Source/Python/AutoGen/AutoGen.py
index 0bed416c52..00ed804e62 100644
--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
@@ -679,31 +679,31 @@ class WorkspaceAutoGen(AutoGen):
 #
 # Create BuildOptions Macro & PCD metafile, also add the Active 
Platform and FDF file.
 #
 content = 'gCommandLineDefines: '
 content += str(GlobalData.gCommandLineDefines)
-content += os.linesep
+content += TAB_LINE_BREAK
 content += 'BuildOptionPcd: '
 content += str(GlobalData.BuildOptionPcd)
-content += os.linesep
+content += TAB_LINE_BREAK
 content += 'Active Platform: '
 content += str(self.Platform)
-content += os.linesep
+content += TAB_LINE_BREAK
 if self.FdfFile:
 content += 'Flash Image Definition: '
 content += str(self.FdfFile)
-content += os.linesep
+content += TAB_LINE_BREAK
 SaveFileOnChange(os.path.join(self.BuildDir, 'BuildOptions'), content, 
False)
 
 #
 # Create PcdToken Number file for Dynamic/DynamicEx Pcd.
 #
 PcdTokenNumber = 'PcdTokenNumber: '
 if Pa.PcdTokenNumber:
 if Pa.DynamicPcdList:
 for Pcd in Pa.DynamicPcdList:
-PcdTokenNumber += os.linesep
+PcdTokenNumber += TAB_LINE_BREAK
 PcdTokenNumber += str((Pcd.TokenCName, 
Pcd.TokenSpaceGuidCName))
 PcdTokenNumber += ' : '
 PcdTokenNumber += str(Pa.PcdTokenNumber[Pcd.TokenCName, 
Pcd.TokenSpaceGuidCName])
 SaveFileOnChange(os.path.join(self.BuildDir, 'PcdTokenNumber'), 
PcdTokenNumber, False)
 
diff --git a/BaseTools/Source/Python/AutoGen/GenMake.py 
b/BaseTools/Source/Python/AutoGen/GenMake.py
index 0e886967cc..3094a555e0 100644
--- a/BaseTools/Source/Python/AutoGen/GenMake.py
+++ b/BaseTools/Source/Python/AutoGen/GenMake.py
@@ -546,12 +546,12 @@ cleanlib:
 NewStr.append(Str)
 UnexpandMacroStr = ' '.join(UnexpandMacro)
 NewRespStr = ' '.join(NewStr)
 SaveFileOnChange(RespFile, NewRespStr, False)
 ToolsDef.append("%s = %s" % (Resp, UnexpandMacroStr + ' @' + 
RespFile))
-RespFileListContent += '@' + RespFile + os.linesep
-RespFileListContent += NewRespStr + os.linesep
+RespFileListContent += '@' + RespFile + TAB_LINE_BREAK
+RespFileListContent += NewRespStr + TAB_LINE_BREAK
 SaveFileOnChange(RespFileList, RespFileListContent, False)
 else:
 if os.path.exists(RespFileList):
 os.remove(RespFileList)
 
-- 
2.20.1.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [Patch 21/33] BaseTools: change the Division Operator

2019-01-28 Thread Feng, Bob C
From: Zhijux Fan 

PEP 238 -- Changing the Division Operator
x/y to return a reasonable approximation of the mathematical result
of the division ("true division")
x//y to return the floor ("floor division")

Cc: Bob Feng 
Cc: Liming Gao 
Cc: Yonghong Zhu 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhiju.Fan 
---
 BaseTools/Source/Python/AutoGen/AutoGen.py |  2 +-
 BaseTools/Source/Python/AutoGen/GenC.py|  8 
 BaseTools/Source/Python/BPDG/GenVpd.py |  8 
 BaseTools/Source/Python/Common/Expression.py   |  9 -
 BaseTools/Source/Python/Common/Misc.py |  6 +++---
 BaseTools/Source/Python/GenFds/DataSection.py  |  4 ++--
 BaseTools/Source/Python/GenFds/EfiSection.py   |  4 ++--
 BaseTools/Source/Python/GenFds/FfsInfStatement.py  |  8 
 BaseTools/Source/Python/GenFds/Fv.py   |  4 ++--
 BaseTools/Source/Python/GenFds/FvImageSection.py   | 10 +-
 BaseTools/Source/Python/GenFds/GenFds.py   |  2 +-
 BaseTools/Source/Python/GenFds/Region.py   |  4 ++--
 BaseTools/Source/Python/PatchPcdValue/PatchPcdValue.py |  4 ++--
 BaseTools/Source/Python/build/build.py | 18 +-
 14 files changed, 49 insertions(+), 42 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py 
b/BaseTools/Source/Python/AutoGen/AutoGen.py
index f9ce17cf77..5f0da5a815 100644
--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
@@ -3812,11 +3812,11 @@ class ModuleAutoGen(AutoGen):
 else:
 NewValue = NewValue + '0x%02x' % 
(ord(PcdValue[Index]) % 0x100) + ', '
 Padding = '0x00, '
 if Unicode:
 Padding = Padding * 2
-ArraySize = ArraySize / 2
+ArraySize = ArraySize // 2
 if ArraySize < (len(PcdValue) + 1):
 if Pcd.MaxSizeUserSet:
 EdkLogger.error("build", AUTOGEN_ERROR,
 "The maximum size of VOID* type 
PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, 
TokenCName)
 )
diff --git a/BaseTools/Source/Python/AutoGen/GenC.py 
b/BaseTools/Source/Python/AutoGen/GenC.py
index 915ba2e235..e46942a3e2 100644
--- a/BaseTools/Source/Python/AutoGen/GenC.py
+++ b/BaseTools/Source/Python/AutoGen/GenC.py
@@ -1051,21 +1051,21 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
 if Unicode:
 NewValue = NewValue + str(ord(Value[Index]) % 0x1) 
+ ', '
 else:
 NewValue = NewValue + str(ord(Value[Index]) % 0x100) + 
', '
 if Unicode:
-ArraySize = ArraySize / 2
+ArraySize = ArraySize // 2
 Value = NewValue + '0 }'
 if ArraySize < ValueSize:
 if Pcd.MaxSizeUserSet:
 EdkLogger.error("build", AUTOGEN_ERROR,
 "The maximum size of VOID* type PCD '%s.%s' is 
less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, TokenCName),
 ExtraData="[%s]" % str(Info))
 else:
 ArraySize = Pcd.GetPcdSize()
 if Unicode:
-ArraySize = ArraySize / 2
+ArraySize = ArraySize // 2
 Array = '[%d]' % ArraySize
 #
 # skip casting for fixed at build since it breaks ARM assembly.
 # Long term we need PCD macros that work in assembly
 #
@@ -1904,20 +1904,20 @@ def BmpImageDecoder(File, Buffer, PaletteIndex, 
TransParent):
 if TransParent:
 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_1BIT_TRANS)
 else:
 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_1BIT)
 ImageBuffer += pack('B', PaletteIndex)
-Width = (BmpHeader.biWidth + 7)/8
+Width = (BmpHeader.biWidth + 7)//8
 if BmpHeader.bfOffBits > BMP_IMAGE_HEADER_STRUCT.size + 2:
 PaletteBuffer = Buffer[BMP_IMAGE_HEADER_STRUCT.size + 2 : 
BmpHeader.bfOffBits]
 elif BmpHeader.biBitCount == 4:
 if TransParent:
 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_4BIT_TRANS)
 else:
 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_4BIT)
 ImageBuffer += pack('B', PaletteIndex)
-Width = (BmpHeader.biWidth + 1)/2
+Width = (BmpHeader.biWidth + 1)//2
 if BmpHeader.bfOffBits > BMP_IMAGE_HEADER_STRUCT.size + 2:
 PaletteBuffer = Buffer[BMP_IMAGE_HEADER_STRUCT.size + 2 : 
BmpHeader.bfOffBits]
 elif BmpHeader.biBitCount == 8

[edk2] [Patch 11/33] BaseTools:Similar to octal data rectification

2019-01-28 Thread Feng, Bob C
From: Zhijux Fan 

In python3, if Value is octal data, the int(Value, 0) report an error

Cc: Bob Feng 
Cc: Liming Gao 
Cc: Yonghong Zhu 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhiju.Fan 
---
 BaseTools/Source/Python/AutoGen/GenC.py   |  2 ++
 BaseTools/Source/Python/Common/Misc.py|  6 --
 BaseTools/Source/Python/Workspace/DscBuildData.py |  3 ++-
 BaseTools/Source/Python/build/BuildReport.py  | 12 
 4 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/GenC.py 
b/BaseTools/Source/Python/AutoGen/GenC.py
index 500a78f058..915ba2e235 100644
--- a/BaseTools/Source/Python/AutoGen/GenC.py
+++ b/BaseTools/Source/Python/AutoGen/GenC.py
@@ -1008,10 +1008,12 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
 
 if Pcd.DatumType in TAB_PCD_CLEAN_NUMERIC_TYPES:
 try:
 if Value.upper().endswith('L'):
 Value = Value[:-1]
+if Value.startswith('0') and not 
Value.lower().startswith('0x') and len(Value) > 2:
+Value = Value.lstrip('0')
 ValueNumber = int (Value, 0)
 except:
 EdkLogger.error("build", AUTOGEN_ERROR,
 "PCD value is not valid dec or hex number for 
datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, 
TokenCName),
 ExtraData="[%s]" % str(Info))
diff --git a/BaseTools/Source/Python/Common/Misc.py 
b/BaseTools/Source/Python/Common/Misc.py
index 1b8a4bef2e..d23a075f43 100644
--- a/BaseTools/Source/Python/Common/Misc.py
+++ b/BaseTools/Source/Python/Common/Misc.py
@@ -1308,13 +1308,15 @@ def CheckPcdDatum(Type, Value):
 elif Type == 'BOOLEAN':
 if Value not in ['TRUE', 'True', 'true', '0x1', '0x01', '1', 'FALSE', 
'False', 'false', '0x0', '0x00', '0']:
 return False, "Invalid value [%s] of type [%s]; must be one of 
TRUE, True, true, 0x1, 0x01, 1"\
   ", FALSE, False, false, 0x0, 0x00, 0" % (Value, Type)
 elif Type in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64]:
-if Value and int(Value, 0) < 0:
-return False, "PCD can't be set to negative value[%s] for datum 
type [%s]" % (Value, Type)
+if Value.startswith('0') and not Value.lower().startswith('0x') and 
len(Value) > 2:
+Value = Value.lstrip('0')
 try:
+if Value and int(Value, 0) < 0:
+return False, "PCD can't be set to negative value[%s] for 
datum type [%s]" % (Value, Type)
 Value = int(Value, 0)
 if Value > MAX_VAL_TYPE[Type]:
 return False, "Too large PCD value[%s] for datum type [%s]" % 
(Value, Type)
 except:
 return False, "Invalid value [%s] of type [%s];"\
diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py 
b/BaseTools/Source/Python/Workspace/DscBuildData.py
index 9c5596927f..c2bc705091 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -37,10 +37,11 @@ from Common.Misc import ProcessDuplicatedInf,RemoveCComments
 import re
 from Common.Parsing import IsValidWord
 from Common.VariableAttributes import VariableAttributes
 import Common.GlobalData as GlobalData
 import subprocess
+from functools import reduce
 from Common.Misc import SaveFileOnChange
 from Workspace.BuildClassObject import PlatformBuildClassObject, StructurePcd, 
PcdClassObject, ModuleBuildClassObject
 from collections import OrderedDict, defaultdict
 from .BuildClassObject import ArrayIndex
 
@@ -1926,11 +1927,11 @@ class DscBuildData(PlatformBuildClassObject):
 index_elements = ArrayIndex.findall(index)
 pcd_capacity = Pcd.Capacity
 if index:
 indicator = "(Pcd"
 if len(pcd_capacity)>2:
-for i in xrange(0,len(index_elements)):
+for i in range(0,len(index_elements)):
 index_ele = index_elements[i]
 index_num = index_ele.strip("[").strip("]").strip()
 if i == len(index_elements) -2:
 indicator += "+ %d*Size/sizeof(%s)/%d + %s)" 
%(int(cleanupindex(index_elements[i+1])),Pcd.BaseDatumType,reduce(lambda x,y: 
int(x)*int(y),pcd_capacity[:-1]), cleanupindex(index_elements[i]))
 break
diff --git a/BaseTools/Source/Python/build/BuildReport.py 
b/BaseTools/Source/Python/build/BuildReport.py
index 6c9a20b373..b940de1c90 100644
--- a/BaseTools/Source/Python/build/BuildReport.py
+++ b/BaseTools/Source/Python/build/BuildReport.py
@@ -1024,26 +1024,34 @@ class PcdReport(object):
 FileWrite(File, Key)
 First = False
 
 
 if Pcd.DatumType in TAB_PCD_NUMERIC_TYPES:
+if PcdValue.startswith('0') and not 
PcdValue.lower().startswith('0x') and le

[edk2] [Patch 10/33] BaseTools: Update argparse arguments since it not have version now

2019-01-28 Thread Feng, Bob C
From: Zhijux Fan 

argparse.ArgumentParser not have version parameter

Cc: Bob Feng 
Cc: Liming Gao 
Cc: Yonghong Zhu 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhiju.Fan 
---
 BaseTools/Source/Python/Pkcs7Sign/Pkcs7Sign.py | 3 ++-
 BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256GenerateKeys.py | 3 ++-
 BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py | 3 ++-
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/BaseTools/Source/Python/Pkcs7Sign/Pkcs7Sign.py 
b/BaseTools/Source/Python/Pkcs7Sign/Pkcs7Sign.py
index c5c99d94ef..2a7c308895 100644
--- a/BaseTools/Source/Python/Pkcs7Sign/Pkcs7Sign.py
+++ b/BaseTools/Source/Python/Pkcs7Sign/Pkcs7Sign.py
@@ -74,14 +74,15 @@ TEST_TRUSTED_PUBLIC_CERT_FILENAME = 'TestRoot.pub.pem'
 
 if __name__ == '__main__':
   #
   # Create command line argument parser object
   #
-  parser = argparse.ArgumentParser(prog=__prog__, version=__version__, 
usage=__usage__, description=__copyright__, conflict_handler='resolve')
+  parser = argparse.ArgumentParser(prog=__prog__, usage=__usage__, 
description=__copyright__, conflict_handler='resolve')
   group = parser.add_mutually_exclusive_group(required=True)
   group.add_argument("-e", action="store_true", dest='Encode', help='encode 
file')
   group.add_argument("-d", action="store_true", dest='Decode', help='decode 
file')
+  group.add_argument("--version", action='version', version=__version__)
   parser.add_argument("-o", "--output", dest='OutputFile', type=str, 
metavar='filename', help="specify the output filename", required=True)
   parser.add_argument("--signer-private-cert", dest='SignerPrivateCertFile', 
type=argparse.FileType('rb'), help="specify the signer private cert filename.  
If not specified, a test signer private cert is used.")
   parser.add_argument("--other-public-cert", dest='OtherPublicCertFile', 
type=argparse.FileType('rb'), help="specify the other public cert filename.  If 
not specified, a test other public cert is used.")
   parser.add_argument("--trusted-public-cert", dest='TrustedPublicCertFile', 
type=argparse.FileType('rb'), help="specify the trusted public cert filename.  
If not specified, a test trusted public cert is used.")
   parser.add_argument("--monotonic-count", dest='MonotonicCountStr', type=str, 
help="specify the MonotonicCount in FMP capsule.  If not specified, 0 is used.")
diff --git 
a/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256GenerateKeys.py 
b/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256GenerateKeys.py
index a34dac423b..f96ceb2637 100644
--- a/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256GenerateKeys.py
+++ b/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256GenerateKeys.py
@@ -41,12 +41,13 @@ __usage__ = '%s [options]' % (__prog__)
 
 if __name__ == '__main__':
   #
   # Create command line argument parser object
   #
-  parser = argparse.ArgumentParser(prog=__prog__, version=__version__, 
usage=__usage__, description=__copyright__, conflict_handler='resolve')
+  parser = argparse.ArgumentParser(prog=__prog__, usage=__usage__, 
description=__copyright__, conflict_handler='resolve')
   group = parser.add_mutually_exclusive_group(required=True)
+  group.add_argument("--version", action='version', version=__version__)
   group.add_argument("-o", "--output", dest='OutputFile', 
type=argparse.FileType('wb'), metavar='filename', nargs='*', help="specify the 
output private key filename in PEM format")
   group.add_argument("-i", "--input", dest='InputFile', 
type=argparse.FileType('rb'), metavar='filename', nargs='*', help="specify the 
input private key filename in PEM format")
   parser.add_argument("--public-key-hash", dest='PublicKeyHashFile', 
type=argparse.FileType('wb'), help="specify the public key hash filename that 
is SHA 256 hash of 2048 bit RSA public key in binary format")
   parser.add_argument("--public-key-hash-c", dest='PublicKeyHashCFile', 
type=argparse.FileType('wb'), help="specify the public key hash filename that 
is SHA 256 hash of 2048 bit RSA public key in C structure format")
   parser.add_argument("-v", "--verbose", dest='Verbose', action="store_true", 
help="increase output messages")
diff --git a/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py 
b/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py
index 3a1a2dff00..d2bb0c998c 100644
--- a/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py
+++ b/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py
@@ -60,14 +60,15 @@ TEST_SIGNING_PRIVATE_KEY_FILENAME = 
'TestSigningPrivateKey.pem'
 
 if __name__ == '__main__':
   #
   # Create command line argument parser object
   #
-  parser = argparse.ArgumentParser(prog=__prog__, version=__version__, 
usage=__usage__, description=__copyright__, conflict_handler='resolve')
+  parser = argparse.ArgumentParser(prog=__prog__, usage=__usage__, 
description=__copyright__, conflict_handler='resolve'

[edk2] [Patch 16/33] BaseTools:Fv BaseAddress must set If it not set

2019-01-28 Thread Feng, Bob C
From: Zhijux Fan 

If ForceRebase is not set, and FV is specified in FD region,
 it should have FvBaseAddress

Cc: Bob Feng 
Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhiju.Fan 
---
 BaseTools/Source/Python/GenFds/FvImageSection.py | 2 ++
 BaseTools/Source/Python/GenFds/GenFds.py | 5 +
 2 files changed, 7 insertions(+)

diff --git a/BaseTools/Source/Python/GenFds/FvImageSection.py 
b/BaseTools/Source/Python/GenFds/FvImageSection.py
index d6e1f3315b..7f277ddef2 100644
--- a/BaseTools/Source/Python/GenFds/FvImageSection.py
+++ b/BaseTools/Source/Python/GenFds/FvImageSection.py
@@ -101,10 +101,12 @@ class FvImageSection(FvImageSectionClassObject):
 if self.FvName is not None:
 Buffer = BytesIO('')
 Fv = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.FvName)
 if Fv is not None:
 self.Fv = Fv
+if not self.FvAddr and self.Fv.BaseAddress:
+self.FvAddr = self.Fv.BaseAddress
 FvFileName = Fv.AddToBuffer(Buffer, self.FvAddr, MacroDict = 
Dict, Flag=IsMakefile)
 if Fv.FvAlignment is not None:
 if self.Alignment is None:
 self.Alignment = Fv.FvAlignment
 else:
diff --git a/BaseTools/Source/Python/GenFds/GenFds.py 
b/BaseTools/Source/Python/GenFds/GenFds.py
index ae5d7fd26d..f1ce527f88 100644
--- a/BaseTools/Source/Python/GenFds/GenFds.py
+++ b/BaseTools/Source/Python/GenFds/GenFds.py
@@ -360,10 +360,12 @@ def GenFdsApi(FdsCommandDict, WorkSpaceDataBase=None):
 for RegionObj in FdObj.RegionList:
 if RegionObj.RegionType != BINARY_FILE_TYPE_FV:
 continue
 for RegionData in RegionObj.RegionDataList:
 if FvObj.UiFvName.upper() == RegionData.upper():
+if not FvObj.BaseAddress:
+FvObj.BaseAddress = '0x%x' % 
(int(FdObj.BaseAddress, 0) + RegionObj.Offset)
 if FvObj.FvRegionInFD:
 if FvObj.FvRegionInFD != RegionObj.Size:
 EdkLogger.error("GenFds", 
FORMAT_INVALID, "The FV %s's region is specified in multiple FD with different 
value." %FvObj.UiFvName)
 else:
 FvObj.FvRegionInFD = RegionObj.Size
@@ -674,20 +676,23 @@ class GenFds(object):
 GuidXRefFile = BytesIO('')
 PkgGuidDict = {}
 GuidDict = {}
 ModuleList = []
 FileGuidList = []
+VariableGuidSet = set()
 for Arch in ArchList:
 PlatformDataBase = 
BuildDb.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, 
GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]
 PkgList = 
GenFdsGlobalVariable.WorkSpace.GetPackageList(GenFdsGlobalVariable.ActivePlatform,
 Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag)
 for P in PkgList:
 PkgGuidDict.update(P.Guids)
 for Name, Guid in PlatformDataBase.Pcds:
 Pcd = PlatformDataBase.Pcds[Name, Guid]
 if Pcd.Type in [TAB_PCDS_DYNAMIC_HII, TAB_PCDS_DYNAMIC_EX_HII]:
 for SkuId in Pcd.SkuInfoList:
 Sku = Pcd.SkuInfoList[SkuId]
+if Sku.VariableGuid in VariableGuidSet:continue
+VariableGuidSet.add(Sku.VariableGuid)
 if Sku.VariableGuid and Sku.VariableGuid in 
PkgGuidDict.keys():
 GuidDict[Sku.VariableGuid] = 
PkgGuidDict[Sku.VariableGuid]
 for ModuleFile in PlatformDataBase.Modules:
 Module = BuildDb.BuildObject[ModuleFile, Arch, 
GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]
 if Module in ModuleList:
-- 
2.20.1.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [Patch 17/33] BaseTools: Make sure AllPcdList valid.

2019-01-28 Thread Feng, Bob C
This patch is to make sure the AllPcdList is always evaluated.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Bob Feng 
Cc: Liming Gao 
---
 BaseTools/Source/Python/AutoGen/AutoGen.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py 
b/BaseTools/Source/Python/AutoGen/AutoGen.py
index 00ed804e62..f9ce17cf77 100644
--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
@@ -1142,11 +1142,10 @@ class PlatformAutoGen(AutoGen):
 self.Arch = Arch
 self.SourceDir = PlatformFile.SubDir
 self.SourceOverrideDir = None
 self.FdTargetList = self.Workspace.FdTargetList
 self.FvTargetList = self.Workspace.FvTargetList
-self.AllPcdList = []
 # get the original module/package/platform objects
 self.BuildDatabase = Workspace.BuildDatabase
 self.DscBuildDataObj = Workspace.Platform
 
 # flag indicating if the makefile/C-code file has been created or not
@@ -1223,10 +1222,13 @@ class PlatformAutoGen(AutoGen):
 self.LibraryBuildDirectoryList = 
Makefile.GetLibraryBuildDirectoryList()
 self.ModuleBuildDirectoryList = Makefile.GetModuleBuildDirectoryList()
 
 self.IsMakeFileCreated = True
 
+@property
+def AllPcdList(self):
+return self.DynamicPcdList + self.NonDynamicPcdList
 ## Deal with Shared FixedAtBuild Pcds
 #
 def CollectFixedAtBuildPcds(self):
 for LibAuto in self.LibraryAutoGenList:
 FixedAtBuildPcds = {}
@@ -1737,11 +1739,10 @@ class PlatformAutoGen(AutoGen):
 if type(SkuId) in (str, unicode) and eval(SkuId) == 0 or 
SkuId == 0:
 continue
 pcd.SkuInfoList[SkuName] = 
copy.deepcopy(pcd.SkuInfoList[TAB_DEFAULT])
 pcd.SkuInfoList[SkuName].SkuId = SkuId
 pcd.SkuInfoList[SkuName].SkuIdName = SkuName
-self.AllPcdList = self._NonDynamicPcdList + self._DynamicPcdList
 
 def FixVpdOffset(self, VpdFile ):
 FvPath = os.path.join(self.BuildDir, TAB_FV_DIRECTORY)
 if not os.path.exists(FvPath):
 try:
-- 
2.20.1.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [Patch 14/33] BaseTools/Scripts: Porting PackageDocumentTools code to use Python3

2019-01-28 Thread Feng, Bob C
From: Zhijux Fan 

Porting PackageDocumentTools code to support python2 and python3

Cc: Bob Feng 
Cc: Liming Gao 
Cc: Yonghong Zhu 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhiju.Fan 
---
 BaseTools/Scripts/ConvertFceToStructurePcd.py  
 |  2 +-
 BaseTools/Scripts/PackageDocumentTools/packagedoc_cli.py   
 |  6 +++---
 BaseTools/Scripts/PackageDocumentTools/packagedocapp.pyw   
 | 14 +++---
 BaseTools/Scripts/PackageDocumentTools/plugins/EdkPlugins/basemodel/doxygen.py 
 |  4 ++--
 
BaseTools/Scripts/PackageDocumentTools/plugins/EdkPlugins/edk2/model/baseobject.py
  | 16 
 BaseTools/Scripts/PackageDocumentTools/plugins/EdkPlugins/edk2/model/dec.py
 |  4 ++--
 
BaseTools/Scripts/PackageDocumentTools/plugins/EdkPlugins/edk2/model/doxygengen.py
  | 12 ++--
 
BaseTools/Scripts/PackageDocumentTools/plugins/EdkPlugins/edk2/model/doxygengen_spec.py
 | 12 ++--
 BaseTools/Scripts/PackageDocumentTools/plugins/EdkPlugins/edk2/model/dsc.py
 |  4 ++--
 BaseTools/Scripts/PackageDocumentTools/plugins/EdkPlugins/edk2/model/inf.py
 |  4 ++--
 10 files changed, 39 insertions(+), 39 deletions(-)

diff --git a/BaseTools/Scripts/ConvertFceToStructurePcd.py 
b/BaseTools/Scripts/ConvertFceToStructurePcd.py
index 59eec28d5e..1495ac34d6 100644
--- a/BaseTools/Scripts/ConvertFceToStructurePcd.py
+++ b/BaseTools/Scripts/ConvertFceToStructurePcd.py
@@ -133,11 +133,11 @@ class parser_lst(object):
   offset = int(offset, 10)
   tmp_name = pcdname2_re.findall(t_name)[0] + '[0]'
   tmp_dict[offset] = tmp_name
   pcdname_num = int(pcdname_num_re.findall(t_name)[0],10)
   uint = int(unit_num.findall(uint)[0],10)
-  bit = uint / 8
+  bit = uint // 8
   for i in range(1, pcdname_num):
 offset += bit
 tmp_name = pcdname2_re.findall(t_name)[0] + '[%s]' % i
 tmp_dict[offset] = tmp_name
 else:
diff --git a/BaseTools/Scripts/PackageDocumentTools/packagedoc_cli.py 
b/BaseTools/Scripts/PackageDocumentTools/packagedoc_cli.py
index 4d01a5..e404a07cd7 100644
--- a/BaseTools/Scripts/PackageDocumentTools/packagedoc_cli.py
+++ b/BaseTools/Scripts/PackageDocumentTools/packagedoc_cli.py
@@ -14,12 +14,12 @@
 
 from __future__ import print_function
 import os, sys, logging, traceback, subprocess
 from optparse import OptionParser
 
-import plugins.EdkPlugins.edk2.model.baseobject as baseobject
-import plugins.EdkPlugins.edk2.model.doxygengen as doxygengen
+from .plugins.EdkPlugins.edk2.model import baseobject
+from .plugins.EdkPlugins.edk2.model import doxygengen
 
 gArchMarcoDict = {'ALL'  : 'MDE_CPU_IA32 MDE_CPU_X64 MDE_CPU_EBC 
MDE_CPU_IPF _MSC_EXTENSIONS __GNUC__ __INTEL_COMPILER',
   'IA32_MSFT': 'MDE_CPU_IA32 _MSC_EXTENSIONS',
   'IA32_GNU' : 'MDE_CPU_IA32 __GNUC__',
   'X64_MSFT' : 'MDE_CPU_X64 _MSC_EXTENSIONS  ASM_PFX= 
OPTIONAL= ',
@@ -36,11 +36,11 @@ def parseCmdArgs():
   help='Specify the absolute path for package DEC file. 
For example: c:\\tianocore\\MdePkg\\MdePkg.dec')
 parser.add_option('-x', '--doxygen', action='store', dest='DoxygenPath',
   help='Specify the absolute path of doxygen tools 
installation. For example: C:\\Program Files\\doxygen\bin\doxygen.exe')
 parser.add_option('-o', '--output', action='store', dest='OutputPath',
   help='Specify the document output path. For example: 
c:\\docoutput')
-parser.add_option('-a', '--arch', action='store', dest='Arch', 
choices=gArchMarcoDict.keys(),
+parser.add_option('-a', '--arch', action='store', dest='Arch', 
choices=list(gArchMarcoDict.keys()),
   help='Specify the architecture used in preprocess 
package\'s source. For example: -a IA32_MSFT')
 parser.add_option('-m', '--mode', action='store', dest='DocumentMode', 
choices=['CHM', 'HTML'],
   help='Specify the document mode from : CHM or HTML')
 parser.add_option('-i', '--includeonly', action='store_true', 
dest='IncludeOnly',
   help='Only generate document for package\'s public 
interfaces produced by include folder. ')
diff --git a/BaseTools/Scripts/PackageDocumentTools/packagedocapp.pyw 
b/BaseTools/Scripts/PackageDocumentTools/packagedocapp.pyw
index 28f6f9bf5c..2998db3915 100644
--- a/BaseTools/Scripts/PackageDocumentTools/packagedocapp.pyw
+++ b/BaseTools/Scripts/PackageDocumentTools/packagedocapp.pyw
@@ -16,12 +16,12 @@
 import os, sys, wx, logging
 
 import wx.stc
 import wx.lib.newevent
 import wx.lib.agw.genericmessagedialog as GMD
-import plugins.EdkPlugins.edk2.mode

[edk2] [Patch 13/33] BaseTools: update Test scripts support python3

2019-01-28 Thread Feng, Bob C
From: Zhijux Fan 

update Test scripts support python2 and python3

Cc: Bob Feng 
Cc: Liming Gao 
Cc: Yonghong Zhu 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhiju.Fan 
---
 BaseTools/Tests/CToolsTests.py |  2 +-
 BaseTools/Tests/CheckUnicodeSourceFiles.py |  6 +++---
 BaseTools/Tests/TestTools.py   | 13 -
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/BaseTools/Tests/CToolsTests.py b/BaseTools/Tests/CToolsTests.py
index ab75d9a7dc..f0de44b141 100644
--- a/BaseTools/Tests/CToolsTests.py
+++ b/BaseTools/Tests/CToolsTests.py
@@ -24,11 +24,11 @@ modules = (
 TianoCompress,
 )
 
 
 def TheTestSuite():
-suites = map(lambda module: module.TheTestSuite(), modules)
+suites = list(map(lambda module: module.TheTestSuite(), modules))
 return unittest.TestSuite(suites)
 
 if __name__ == '__main__':
 allTests = TheTestSuite()
 unittest.TextTestRunner().run(allTests)
diff --git a/BaseTools/Tests/CheckUnicodeSourceFiles.py 
b/BaseTools/Tests/CheckUnicodeSourceFiles.py
index 6ae62f180a..c76b2bc20e 100644
--- a/BaseTools/Tests/CheckUnicodeSourceFiles.py
+++ b/BaseTools/Tests/CheckUnicodeSourceFiles.py
@@ -108,11 +108,11 @@ class Tests(TestTools.BaseToolsTest):
 # with the Surrogate Pair code point.
 #
 # This test makes sure that BaseTools rejects these characters
 # if seen in a .uni file.
 #
-data = codecs.BOM_UTF16_LE + '//\x01\xd8 '
+data = codecs.BOM_UTF16_LE + b'//\x01\xd8 '
 
 self.CheckFile(encoding=None, shouldPass=False, string=data)
 
 def testValidUtf8File(self):
 self.CheckFile(encoding='utf_8', shouldPass=True)
@@ -159,20 +159,20 @@ class Tests(TestTools.BaseToolsTest):
 # UTF-16 Surrogate Pairs.
 #
 # This test makes sure that BaseTools rejects these characters
 # if seen in a .uni file.
 #
-data = '\xed\xa0\x81'
+data = b'\xed\xa0\x81'
 
 self.CheckFile(encoding=None, shouldPass=False, string=data)
 
 def testSurrogatePairUnicodeCharInUtf8FileWithBom(self):
 #
 # Same test as testSurrogatePairUnicodeCharInUtf8File, but add
 # the UTF-8 BOM
 #
-data = codecs.BOM_UTF8 + '\xed\xa0\x81'
+data = codecs.BOM_UTF8 + b'\xed\xa0\x81'
 
 self.CheckFile(encoding=None, shouldPass=False, string=data)
 
 TheTestSuite = TestTools.MakeTheTestSuite(locals())
 
diff --git a/BaseTools/Tests/TestTools.py b/BaseTools/Tests/TestTools.py
index e16e993048..4332dcdaac 100644
--- a/BaseTools/Tests/TestTools.py
+++ b/BaseTools/Tests/TestTools.py
@@ -38,11 +38,11 @@ if PythonSourceDir not in sys.path:
 #
 sys.path.append(PythonSourceDir)
 
 def MakeTheTestSuite(localItems):
 tests = []
-for name, item in localItems.iteritems():
+for name, item in localItems.items():
 if isinstance(item, type):
 if issubclass(item, unittest.TestCase):
 tests.append(unittest.TestLoader().loadTestsFromTestCase(item))
 elif issubclass(item, unittest.TestSuite):
 tests.append(item())
@@ -144,13 +144,16 @@ class BaseToolsTest(unittest.TestCase):
 data = f.read()
 f.close()
 return data
 
 def WriteTmpFile(self, fileName, data):
-f = open(self.GetTmpFilePath(fileName), 'w')
-f.write(data)
-f.close()
+if isinstance(data, bytes):
+with open(self.GetTmpFilePath(fileName), 'wb') as f:
+f.write(data)
+else:
+with open(self.GetTmpFilePath(fileName), 'w') as f:
+f.write(data)
 
 def GenRandomFileData(self, fileName, minlen = None, maxlen = None):
 if maxlen is None: maxlen = minlen
 f = self.OpenTmpFile(fileName, 'w')
 f.write(self.GetRandomString(minlen, maxlen))
@@ -159,11 +162,11 @@ class BaseToolsTest(unittest.TestCase):
 def GetRandomString(self, minlen = None, maxlen = None):
 if minlen is None: minlen = 1024
 if maxlen is None: maxlen = minlen
 return ''.join(
 [chr(random.randint(0, 255))
- for x in xrange(random.randint(minlen, maxlen))
+ for x in range(random.randint(minlen, maxlen))
 ])
 
 def setUp(self):
 self.savedEnvPath = os.environ['PATH']
 self.savedSysPath = sys.path[:]
-- 
2.20.1.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [Patch 12/33] BaseTools/UPT:merge UPT Tool use Python2 and Python3

2019-01-28 Thread Feng, Bob C
From: Zhijux Fan 

In UPT Tool,merge python2 and python3

Cc: Bob Feng 
Cc: Liming Gao 
Cc: Yonghong Zhu 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhiju.Fan 
---
 BaseTools/Source/Python/UPT/Core/IpiDb.py |   4 ++--
 BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py |   6 +++---
 BaseTools/Source/Python/UPT/Library/CommentGenerating.py  |   6 ++
 BaseTools/Source/Python/UPT/Library/CommentParsing.py |  10 --
 BaseTools/Source/Python/UPT/Library/Misc.py   | 190 
++
 BaseTools/Source/Python/UPT/Library/ParserValidate.py |   2 +-
 BaseTools/Source/Python/UPT/Library/Parsing.py|   2 +-
 BaseTools/Source/Python/UPT/Library/StringUtils.py|  36 
++--
 BaseTools/Source/Python/UPT/Library/UniClassObject.py |   6 --
 BaseTools/Source/Python/UPT/Library/Xml/XmlRoutines.py|   2 +-
 BaseTools/Source/Python/UPT/Logger/StringTable.py |   2 +-
 BaseTools/Source/Python/UPT/Parser/DecParser.py   |   4 ++--
 BaseTools/Source/Python/UPT/Parser/DecParserMisc.py   |  30 
+-
 BaseTools/Source/Python/UPT/Parser/InfAsBuiltProcess.py   |   4 ++--
 BaseTools/Source/Python/UPT/Parser/InfParser.py   |   4 ++--
 BaseTools/Source/Python/UPT/Parser/InfSectionParser.py|   4 ++--
 BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignment.py |   2 +-
 BaseTools/Source/Python/UPT/UPT.py|   1 +
 BaseTools/Source/Python/UPT/Xml/IniToXml.py   |   2 +-
 BaseTools/Source/Python/UPT/Xml/XmlParserMisc.py  |   2 +-
 20 files changed, 84 insertions(+), 235 deletions(-)

diff --git a/BaseTools/Source/Python/UPT/Core/IpiDb.py 
b/BaseTools/Source/Python/UPT/Core/IpiDb.py
index a781d358c8..48defeac7e 100644
--- a/BaseTools/Source/Python/UPT/Core/IpiDb.py
+++ b/BaseTools/Source/Python/UPT/Core/IpiDb.py
@@ -42,11 +42,11 @@ import platform as pf
 class IpiDatabase(object):
 def __init__(self, DbPath, Workspace):
 Dir = os.path.dirname(DbPath)
 if not os.path.isdir(Dir):
 os.mkdir(Dir)
-self.Conn = sqlite3.connect(unicode(DbPath), 
isolation_level='DEFERRED')
+self.Conn = sqlite3.connect(u''.join(DbPath), 
isolation_level='DEFERRED')
 self.Conn.execute("PRAGMA page_size=4096")
 self.Conn.execute("PRAGMA synchronous=OFF")
 self.Cur = self.Conn.cursor()
 self.DpTable = 'DpInfo'
 self.PkgTable = 'PkgInfo'
@@ -919,10 +919,10 @@ class IpiDatabase(object):
 # @param StringList:  A list for strings to be converted
 #
 def __ConvertToSqlString(self, StringList):
 if self.DpTable:
 pass
-return map(lambda s: s.replace("'", "''"), StringList)
+return list(map(lambda s: s.replace("'", "''"), StringList))
 
 
 
 
diff --git a/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py 
b/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py
index c2a240a884..1f8b3f163e 100644
--- a/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py
+++ b/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py
@@ -272,11 +272,11 @@ def GenDefines(ModuleObject):
 for UserExtension in ModuleObject.GetUserExtensionList():
 DefinesDict = UserExtension.GetDefinesDict()
 if not DefinesDict:
 continue
 for Statement in DefinesDict:
-if Statement.split(DT.TAB_EQUAL_SPLIT) > 1:
+if len(Statement.split(DT.TAB_EQUAL_SPLIT)) > 1:
 Statement = (u'%s ' % Statement.split(DT.TAB_EQUAL_SPLIT, 
1)[0]).ljust(LeftOffset) \
  + u'= %s' % Statement.split(DT.TAB_EQUAL_SPLIT, 
1)[1].lstrip()
 SortedArch = DT.TAB_ARCH_COMMON
 if 
Statement.strip().startswith(DT.TAB_INF_DEFINES_CUSTOM_MAKEFILE):
 pos = Statement.find(DT.TAB_VALUE_SPLIT)
@@ -407,11 +407,11 @@ def GenLibraryClasses(ModuleObject):
 Statement += Name
 if FFE:
 Statement += '|' + FFE
 ModuleList = LibraryClass.GetSupModuleList()
 ArchList = LibraryClass.GetSupArchList()
-for Index in xrange(0, len(ArchList)):
+for Index in range(0, len(ArchList)):
 ArchList[Index] = ConvertArchForInstall(ArchList[Index])
 ArchList.sort()
 SortedArch = ' '.join(ArchList)
 KeyList = []
 if not ModuleList or IsAllModuleList(ModuleList):
@@ -570,11 +570,11 @@ def GenUserExtensions(ModuleObject):
 Statement = UserExtension.GetStatement()
 # Comment the code to support user extension without any statement just the 
section header in []
 # if not Statement:
 # continue
 ArchList = UserE

[edk2] [Patch 09/33] BaseTools:Solve the data sorting problem use python3

2019-01-28 Thread Feng, Bob C
From: Zhijux Fan 

set PYTHONHASHSEED
Specifying the value 0 will disable hash randomization.

Cc: Bob Feng 
Cc: Liming Gao 
Cc: Yonghong Zhu 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhiju.Fan 
---
 BaseTools/toolsetup.bat | 1 +
 edksetup.sh | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/BaseTools/toolsetup.bat b/BaseTools/toolsetup.bat
index b58560d4d7..1cac3105c2 100755
--- a/BaseTools/toolsetup.bat
+++ b/BaseTools/toolsetup.bat
@@ -272,10 +272,11 @@ goto check_build_environment
   echo.
   echo !!! ERROR !!! Binary C tools are missing. They are requried to be built 
from BaseTools Source.
   echo.
 
 :check_build_environment
+  set PYTHONHASHSEED=0
   if defined BASETOOLS_PYTHON_SOURCE goto VisualStudioAvailable
 
   if not defined BASE_TOOLS_PATH (
  if not exist "Source\C\Makefile" (
if not exist "%EDK_TOOLS_PATH%\Source\C\Makefile" goto no_source_files
diff --git a/edksetup.sh b/edksetup.sh
index 93d6525758..3dee8c5d61 100755
--- a/edksetup.sh
+++ b/edksetup.sh
@@ -75,11 +75,11 @@ function SetWorkspace()
 
   #
   # Set $WORKSPACE
   #
   export WORKSPACE=`pwd`
-
+  export PYTHONHASHSEED=0
   return 0
 }
 
 function SetupEnv()
 {
-- 
2.20.1.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [Patch v2 00/33] BaseTools python3 migration patch set

2019-01-28 Thread Feng, Bob C
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=55

V2:
The python files under CParser4 folder of ECC/Eot tool
are generated by antlr4 and forpython3 usage. 
They have python3 specific syntax, for example
the data type declaration for the arguments of a function. That
is not compitable with python2. this patch is to remove these syntax.

The version2 patch set is commit to https://github.com/BobCF/edk2.git branch 
py3basetools_v2

V1:
This patch set is to enable python3 on BaseTools. Basetools code will be
compatible with both python3 and python2.

We will have two envs PYTHON3_ENABLE and PYTHON_COMMAND. The behavior can be 
combined as the below to support this usage.
If user wants the specific python interpreter, he only needs to set 
PYTHON_COMMAND env.
If PYTHON3_ENABLE is set, PYTHON_COMMAND will be set to the found one by edk2 
scripts based on PYTHON3_ENABLE value. 
If PYTHON3_ENABLE is not set, but PYTHON_COMMAND is set, then PYTHON_COMMAND 
will be used to run python script. No version check here. 
If PYTHON3_ENABLE is not set, but PYTHON_COMMAND is not set, PYTHON_COMMAND 
will be set to the high version python installed in OS. 

This patch set is verified by basic testing on Ovmf, MinKabylake and MinPurley 
platform with Python3.7.1 and 
minimal testing on Ovmf, MinKabylake and MinPurley with Python2.7.15. 

After this change, we will focus on the Python3 validation.

You can also review and try the patch set at https://github.com/BobCF/edk2.git 
branch py3basetools


Feng, Bob C (9):
  BaseTools: use OrderedDict instead of sdict
  BaseTools: Make sure AllPcdList valid.
  BaseTools:File open failed for VPD MapFile
  BaseTools:Fixed Rsa issue and a set define issue.
  BaseTools:ord() don't match in py2 and py3
  BaseTools: the list and iterator translation
  BaseTools: Handle the bytes and str difference
  BaseTools: ECC tool Python3 adaption
  BaseTools: Eot tool Python3 adaption

Liming Gao (1):
  BaseTools: Update PYTHON env to PYTHON_COMMAND

Yunhua Feng (3):
  BaseTools: nametuple not have verbose parameter in python3
  BaseTools: Remove unnecessary super function
  BaseTools: replace long by int

Zhiju Fan (3):
  BaseTools:TestTools character encoding issue
  BaseTools:Double carriage return inserted from Trim.py on Python3
  BaseTools:There is extra blank line in datalog

Zhijux Fan (17):
  BaseTool:Rename xrange() to range()
  BaseTools:use iterate list to replace the itertools
  BaseTools: Rename iteritems to items
  BaseTools: replace get_bytes_le() to bytes_le
  BaseTools:Solve the data sorting problem use python3
  BaseTools: Update argparse arguments since it not have version now
  BaseTools:Similar to octal data rectification
  BaseTools/UPT:merge UPT Tool use Python2 and Python3
  BaseTools: update Test scripts support python3
  BaseTools/Scripts: Porting PackageDocumentTools code to use Python3
  Basetools: It went wrong when use os.linesep
  BaseTools:Fv BaseAddress must set If it not set
  BaseTools: change the Division Operator
  BaseTools: Similar to octal data rectification
  BaseTools: Update windows and linux run scripts file to use Python3
  BaseTools:Update build tool to print python version information
  BaseTools:Linux Python highest version check.

 BaseTools/Bin/CYGWIN_NT-5.1-i686/Ecc   
 |6 +-
 BaseTools/Bin/CYGWIN_NT-5.1-i686/GenDepex  
 |6 +-
 BaseTools/Bin/CYGWIN_NT-5.1-i686/GenFds
 |6 +-
 BaseTools/Bin/CYGWIN_NT-5.1-i686/TargetTool
 |6 +-
 BaseTools/Bin/CYGWIN_NT-5.1-i686/Trim  
 |6 +-
 BaseTools/Bin/CYGWIN_NT-5.1-i686/build 
 |6 +-
 BaseTools/BinWrappers/PosixLike/BPDG   
 |6 +-
 BaseTools/BinWrappers/PosixLike/Ecc
 |6 +-
 BaseTools/BinWrappers/PosixLike/GenDepex   
 |6 +-
 BaseTools/BinWrappers/PosixLike/GenFds 
 |6 +-
 BaseTools/BinWrappers/PosixLike/GenPatchPcdTable   
 |6 +-
 BaseTools/BinWrappers/PosixLike/GenerateCapsule
 |6 +-
 BaseTools/BinWrappers/PosixLike/PatchPcdValue  
 |6 +-
 BaseTools/BinWrappers/PosixLike/Pkcs7Sign  
 |6 +-
 BaseTools/BinWrappers/PosixLike/Rsa2048Sha256GenerateKeys  
 |6 +-
 BaseTools/BinWrappers/PosixLike/Rsa2048Sha256Sign  
 |6 +-
 BaseTools/BinWrappers/PosixLike/TargetTool 
 |6 +-
 BaseTools/BinWrappers/PosixLike/Trim  

[edk2] [Patch 07/33] BaseTools: Remove unnecessary super function

2019-01-28 Thread Feng, Bob C
From: Yunhua Feng 

Remove unnecessary super function

Cc: Bob Feng 
Cc: Liming Gao 
Cc: Yonghong Zhu 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng 
---
 BaseTools/Source/Python/AutoGen/AutoGen.py | 5 -
 1 file changed, 5 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py 
b/BaseTools/Source/Python/AutoGen/AutoGen.py
index f4cfb0830d..0bed416c52 100644
--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
@@ -267,12 +267,10 @@ class AutoGen(object):
 return cls.__ObjectCache[Key]
 # it didnt exist. create it, cache it, then return it
 RetVal = cls.__ObjectCache[Key] = super(AutoGen, cls).__new__(cls)
 return RetVal
 
-def __init__ (self, Workspace, MetaFile, Target, Toolchain, Arch, *args, 
**kwargs):
-super(AutoGen, self).__init__(self, Workspace, MetaFile, Target, 
Toolchain, Arch, *args, **kwargs)
 
 ## hash() operator
 #
 #  The file path of platform file will be used to represent hash value of 
this object
 #
@@ -301,11 +299,10 @@ class AutoGen(object):
 #
 class WorkspaceAutoGen(AutoGen):
 # call super().__init__ then call the worker function with different 
parameter count
 def __init__(self, Workspace, MetaFile, Target, Toolchain, Arch, *args, 
**kwargs):
 if not hasattr(self, "_Init"):
-super(WorkspaceAutoGen, self).__init__(Workspace, MetaFile, 
Target, Toolchain, Arch, *args, **kwargs)
 self._InitWorker(Workspace, MetaFile, Target, Toolchain, Arch, 
*args, **kwargs)
 self._Init = True
 
 ## Initialize WorkspaceAutoGen
 #
@@ -1092,11 +1089,10 @@ class WorkspaceAutoGen(AutoGen):
 #
 class PlatformAutoGen(AutoGen):
 # call super().__init__ then call the worker function with different 
parameter count
 def __init__(self, Workspace, MetaFile, Target, Toolchain, Arch, *args, 
**kwargs):
 if not hasattr(self, "_Init"):
-super(PlatformAutoGen, self).__init__(self, Workspace, MetaFile, 
Target, Toolchain, Arch, *args, **kwargs)
 self._InitWorker(Workspace, MetaFile, Target, Toolchain, Arch)
 self._Init = True
 #
 # Used to store all PCDs for both PEI and DXE phase, in order to generate
 # correct PCD database
@@ -2524,11 +2520,10 @@ def _MakeDir(PathList):
 #
 class ModuleAutoGen(AutoGen):
 # call super().__init__ then call the worker function with different 
parameter count
 def __init__(self, Workspace, MetaFile, Target, Toolchain, Arch, *args, 
**kwargs):
 if not hasattr(self, "_Init"):
-super(ModuleAutoGen, self).__init__(Workspace, MetaFile, Target, 
Toolchain, Arch, *args, **kwargs)
 self._InitWorker(Workspace, MetaFile, Target, Toolchain, Arch, 
*args)
 self._Init = True
 
 ## Cache the timestamps of metafiles of every module in a class attribute
 #
-- 
2.20.1.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [Patch 02/33] BaseTools:use iterate list to replace the itertools

2019-01-28 Thread Feng, Bob C
From: Zhijux Fan 

itertools.imap() replace map(), itertools.ifilter() replace filter

Cc: Bob Feng 
Cc: Liming Gao 
Cc: Yonghong Zhu 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhiju.Fan 
---
 BaseTools/Source/Python/build/build.py | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/BaseTools/Source/Python/build/build.py 
b/BaseTools/Source/Python/build/build.py
index e79949fa28..d07c8f84d6 100644
--- a/BaseTools/Source/Python/build/build.py
+++ b/BaseTools/Source/Python/build/build.py
@@ -25,11 +25,10 @@ import sys
 import glob
 import time
 import platform
 import traceback
 import encodings.ascii
-import itertools
 import multiprocessing
 
 from struct import *
 from threading import *
 import threading
@@ -1100,13 +1099,12 @@ class Build():
 
 if os.path.exists(PrebuildEnvFile):
 f = open(PrebuildEnvFile)
 envs = f.readlines()
 f.close()
-envs = itertools.imap(lambda l: l.split('=', 1), envs)
-envs = itertools.ifilter(lambda l: len(l) == 2, envs)
-envs = itertools.imap(lambda l: [i.strip() for i in l], envs)
+envs = [l.split("=", 1) for l in envs ]
+envs = [[I.strip() for I in item] for item in envs if 
len(item) == 2]
 os.environ.update(dict(envs))
 EdkLogger.info("\n- Prebuild Done -\n")
 
 def LaunchPostbuild(self):
 if self.Postbuild:
-- 
2.20.1.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [Patch 06/33] BaseTools: nametuple not have verbose parameter in python3

2019-01-28 Thread Feng, Bob C
From: Yunhua Feng 

nametuple not have verbose parameter in python3

Cc: Bob Feng 
Cc: Liming Gao 
Cc: Yonghong Zhu 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng 
---
 BaseTools/Source/Python/Workspace/BuildClassObject.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/BaseTools/Source/Python/Workspace/BuildClassObject.py 
b/BaseTools/Source/Python/Workspace/BuildClassObject.py
index 73920c5153..b67414b930 100644
--- a/BaseTools/Source/Python/Workspace/BuildClassObject.py
+++ b/BaseTools/Source/Python/Workspace/BuildClassObject.py
@@ -353,11 +353,11 @@ class StructurePcd(PcdClassObject):
 new_pcd.PcdFieldValueFromComm = CopyDict(self.PcdFieldValueFromComm)
 new_pcd.PcdFieldValueFromFdf = CopyDict(self.PcdFieldValueFromFdf)
 new_pcd.ValueChain = {item for item in self.ValueChain}
 return new_pcd
 
-LibraryClassObject = namedtuple('LibraryClassObject', 
['LibraryClass','SupModList'], verbose=False)
+LibraryClassObject = namedtuple('LibraryClassObject', 
['LibraryClass','SupModList'])
 
 ## ModuleBuildClassObject
 #
 # This Class defines ModuleBuildClass
 #
-- 
2.20.1.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH 3/3] patch3_add_support_bh720_chip

2019-01-28 Thread Mike Li (WH)
---
 .../Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c   | 918 +-
 .../Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h   | 159 ++-
 2 files changed, 519 insertions(+), 558 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c 
b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
index 5aec8c6992..371c2640f4 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
@@ -4,7 +4,6 @@
 
   It would expose EFI_SD_MMC_PASS_THRU_PROTOCOL for upper layer use.
 
-  Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
   Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD 
License
@@ -17,6 +16,8 @@
 **/
 
 #include "SdMmcPciHcDxe.h"
+int g_deviceId = 0;
+
 
 /**
   Dump the content of SD/MMC host controller's Capability Register.
@@ -46,8 +47,7 @@ DumpCapabilityReg (
   DEBUG ((DEBUG_INFO, "   Voltage 3.3   %a\n", Capability->Voltage33 ? 
"TRUE" : "FALSE"));
   DEBUG ((DEBUG_INFO, "   Voltage 3.0   %a\n", Capability->Voltage30 ? 
"TRUE" : "FALSE"));
   DEBUG ((DEBUG_INFO, "   Voltage 1.8   %a\n", Capability->Voltage18 ? 
"TRUE" : "FALSE"));
-  DEBUG ((DEBUG_INFO, "   V4 64-bit Sys Bus %a\n", Capability->SysBus64V4 ? 
"TRUE" : "FALSE"));
-  DEBUG ((DEBUG_INFO, "   V3 64-bit Sys Bus %a\n", Capability->SysBus64V3 ? 
"TRUE" : "FALSE"));
+  DEBUG ((DEBUG_INFO, "   64-bit Sys Bus%a\n", Capability->SysBus64 ? 
"TRUE" : "FALSE"));
   DEBUG ((DEBUG_INFO, "   Async Interrupt   %a\n", Capability->AsyncInt ? 
"TRUE" : "FALSE"));
   DEBUG ((DEBUG_INFO, "   SlotType  "));
   if (Capability->SlotType == 0x00) {
@@ -418,40 +418,10 @@ SdMmcHcWaitMmioSet (
   return EFI_TIMEOUT;
 }
 
-/**
-  Get the controller version information from the specified slot.
-
-  @param[in]  PciIo   The PCI IO protocol instance.
-  @param[in]  SlotThe slot number of the SD card to send the 
command to.
-  @param[out] Version The buffer to store the version information.
-
-  @retval EFI_SUCCESS The operation executes successfully.
-  @retval Others  The operation fails.
-
-**/
-EFI_STATUS
-SdMmcHcGetControllerVersion (
-  IN EFI_PCI_IO_PROTOCOL  *PciIo,
-  IN UINT8Slot,
-  OUTUINT16   *Version
-  )
-{
-  EFI_STATUSStatus;
-
-  Status = SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_CTRL_VER, TRUE, sizeof 
(UINT16), Version);
-  if (EFI_ERROR (Status)) {
-return Status;
-  }
-
-  *Version &= 0xFF;
-
-  return EFI_SUCCESS;
-}
-
 /**
   Software reset the specified SD/MMC host controller and enable all 
interrupts.
 
-  @param[in] PrivateA pointer to the SD_MMC_HC_PRIVATE_DATA instance.
+  @param[in] PciIo  The PCI IO protocol instance.
   @param[in] Slot   The slot number of the SD card to send the command 
to.
 
   @retval EFI_SUCCESS   The software reset executes successfully.
@@ -460,38 +430,18 @@ SdMmcHcGetControllerVersion (
 **/
 EFI_STATUS
 SdMmcHcReset (
-  IN SD_MMC_HC_PRIVATE_DATA *Private,
+  IN EFI_PCI_IO_PROTOCOL*PciIo,
   IN UINT8  Slot
   )
 {
   EFI_STATUSStatus;
   UINT8 SwReset;
-  EFI_PCI_IO_PROTOCOL   *PciIo;
 
-  //
-  // Notify the SD/MMC override protocol that we are about to reset
-  // the SD/MMC host controller.
-  //
-  if (mOverride != NULL && mOverride->NotifyPhase != NULL) {
-Status = mOverride->NotifyPhase (
-  Private->ControllerHandle,
-  Slot,
-  EdkiiSdMmcResetPre,
-  NULL);
-if (EFI_ERROR (Status)) {
-  DEBUG ((DEBUG_WARN,
-"%a: SD/MMC pre reset notifier callback failed - %r\n",
-__FUNCTION__, Status));
-  return Status;
-}
-  }
-
-  PciIo   = Private->PciIo;
-  SwReset = BIT0;
-  Status  = SdMmcHcOrMmio (PciIo, Slot, SD_MMC_HC_SW_RST, sizeof (SwReset), 
&SwReset);
+  SwReset = 0xFF;
+  Status  = SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_SW_RST, FALSE, sizeof 
(SwReset), &SwReset);
 
   if (EFI_ERROR (Status)) {
-DEBUG ((DEBUG_ERROR, "SdMmcHcReset: write SW Reset for All fails: %r\n", 
Status));
+DEBUG ((DEBUG_ERROR, "SdMmcHcReset: write full 1 fails: %r\n", Status));
 return Status;
   }
 
@@ -500,7 +450,7 @@ SdMmcHcReset (
  Slot,
  SD_MMC_HC_SW_RST,
  sizeof (SwReset),
- BIT0,
+ 0xFF,
  0x00,
  SD_MMC_HC_GENERIC_TIMEOUT
  );
@@ -508,33 +458,10 @@ SdMmcHcReset (
 DEBUG ((DEBUG_INFO, "SdMmcHcReset: reset done with %r\n", Status));
 return Status;
   }
-
   //
   // Enable all interrupt after reset all.
   //
   Status = SdMmcHcEnableInterrupt (PciIo, Slot);
-  if (EFI_ERROR (Status)) {
-DEBUG ((DEBUG_INFO, "SdMmcHcReset: SdMmcHcEnableInterrupt done

[edk2] [Patch 08/33] BaseTools: replace long by int

2019-01-28 Thread Feng, Bob C
From: Yunhua Feng 

replace long by int
Because the long() was not exist in Python3

Cc: Bob Feng 
Cc: Liming Gao 
Cc: Yonghong Zhu 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng 
---
 BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py |  4 ++--
 BaseTools/Source/Python/Common/Misc.py |  2 +-
 BaseTools/Source/Python/GenFds/AprioriSection.py   |  2 +-
 BaseTools/Source/Python/GenFds/FdfParser.py| 18 
+-
 BaseTools/Source/Python/GenFds/GenFds.py   |  8 
 BaseTools/Source/Python/Pkcs7Sign/Pkcs7Sign.py | 10 +-
 BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py |  4 ++--
 BaseTools/Source/Python/UPT/Parser/DecParser.py|  6 +++---
 8 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py 
b/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py
index edd40a1498..6ddf38fd0d 100644
--- a/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py
+++ b/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py
@@ -55,11 +55,11 @@ class VAR_CHECK_PCD_VARIABLE_TAB_CONTAINER(object):
 itemIndex = 0
 for item in var_check_tab.validtab:
 itemIndex += 1
 realLength += 5
 for v_data in item.data:
-if type(v_data) in (int, long):
+if isinstance(v_data, int):
 realLength += item.StorageWidth
 else:
 realLength += item.StorageWidth
 realLength += item.StorageWidth
 if (index == len(self.var_check_info)) :
@@ -135,11 +135,11 @@ class VAR_CHECK_PCD_VARIABLE_TAB_CONTAINER(object):
 
 b = pack("=B", item.StorageWidth)
 Buffer += b
 realLength += 1
 for v_data in item.data:
-if type(v_data) in (int, long):
+if isinstance(v_data, int):
 b = pack(PACK_CODE_BY_SIZE[item.StorageWidth], v_data)
 Buffer += b
 realLength += item.StorageWidth
 else:
 b = pack(PACK_CODE_BY_SIZE[item.StorageWidth], 
v_data[0])
diff --git a/BaseTools/Source/Python/Common/Misc.py 
b/BaseTools/Source/Python/Common/Misc.py
index 9967ac470c..1b8a4bef2e 100644
--- a/BaseTools/Source/Python/Common/Misc.py
+++ b/BaseTools/Source/Python/Common/Misc.py
@@ -1311,11 +1311,11 @@ def CheckPcdDatum(Type, Value):
   ", FALSE, False, false, 0x0, 0x00, 0" % (Value, Type)
 elif Type in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64]:
 if Value and int(Value, 0) < 0:
 return False, "PCD can't be set to negative value[%s] for datum 
type [%s]" % (Value, Type)
 try:
-Value = long(Value, 0)
+Value = int(Value, 0)
 if Value > MAX_VAL_TYPE[Type]:
 return False, "Too large PCD value[%s] for datum type [%s]" % 
(Value, Type)
 except:
 return False, "Invalid value [%s] of type [%s];"\
   " must be a hexadecimal, decimal or octal in C 
language format." % (Value, Type)
diff --git a/BaseTools/Source/Python/GenFds/AprioriSection.py 
b/BaseTools/Source/Python/GenFds/AprioriSection.py
index e7b856a115..55d99320c7 100644
--- a/BaseTools/Source/Python/GenFds/AprioriSection.py
+++ b/BaseTools/Source/Python/GenFds/AprioriSection.py
@@ -95,11 +95,11 @@ class AprioriSection (object):
 EdkLoggerError("GenFds", RESOURCE_NOT_AVAILABLE,
 "INF %s not found in build ARCH %s!" \
 % (InfFileName, 
GenFdsGlobalVariable.ArchList))
 
 GuidPart = Guid.split('-')
-Buffer.write(pack('I', long(GuidPart[0], 16)))
+Buffer.write(pack('I', int(GuidPart[0], 16)))
 Buffer.write(pack('H', int(GuidPart[1], 16)))
 Buffer.write(pack('H', int(GuidPart[2], 16)))
 
 for Num in range(2):
 Char = GuidPart[3][Num*2:Num*2+2]
diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py 
b/BaseTools/Source/Python/GenFds/FdfParser.py
index 3bcfd2d42a..69cb7de8e5 100644
--- a/BaseTools/Source/Python/GenFds/FdfParser.py
+++ b/BaseTools/Source/Python/GenFds/FdfParser.py
@@ -1560,11 +1560,11 @@ class FdfParser:
 Obj.SizePcd = pcdPair
 self.Profile.PcdDict[pcdPair] = Size
 self.SetPcdLocalation(pcdPair)
 FileLineTuple = GetRealFileLine(self.FileName, 
self.CurrentLineNumber)
 self.Profile.PcdFileLineDict[pcdPair] = FileLineTuple
-Obj.Size = long(Size, 0)
+Obj.Size = int(Size, 0)
 return

[edk2] [Patch 03/33] BaseTools: Rename iteritems to items

2019-01-28 Thread Feng, Bob C
From: Zhijux Fan 

replace the list iteritems by items in Python3.

Cc: Bob Feng 
Cc: Liming Gao 
Cc: Yonghong Zhu 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhiju.Fan 
---
 BaseTools/Source/Python/AutoGen/GenMake.py| 6 +++---
 BaseTools/Source/Python/Workspace/DscBuildData.py | 2 +-
 BaseTools/Source/Python/build/build.py| 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/GenMake.py 
b/BaseTools/Source/Python/AutoGen/GenMake.py
index 4da10e3950..0e886967cc 100644
--- a/BaseTools/Source/Python/AutoGen/GenMake.py
+++ b/BaseTools/Source/Python/AutoGen/GenMake.py
@@ -483,11 +483,11 @@ cleanlib:
 ImageEntryPoint = "EfiStart"
 else:
 # EdkII modules always use "_ModuleEntryPoint" as entry point
 ImageEntryPoint = "_ModuleEntryPoint"
 
-for k, v in MyAgo.Module.Defines.iteritems():
+for k, v in MyAgo.Module.Defines.items():
 if k not in MyAgo.Macros:
 MyAgo.Macros[k] = v
 
 if 'MODULE_ENTRY_POINT' not in MyAgo.Macros:
 MyAgo.Macros['MODULE_ENTRY_POINT'] = ModuleEntryPoint
@@ -495,11 +495,11 @@ cleanlib:
 MyAgo.Macros['ARCH_ENTRY_POINT'] = ArchEntryPoint
 if 'IMAGE_ENTRY_POINT' not in MyAgo.Macros:
 MyAgo.Macros['IMAGE_ENTRY_POINT'] = ImageEntryPoint
 
 PCI_COMPRESS_Flag = False
-for k, v in MyAgo.Module.Defines.iteritems():
+for k, v in MyAgo.Module.Defines.items():
 if 'PCI_COMPRESS' == k and 'TRUE' == v:
 PCI_COMPRESS_Flag = True
 
 # tools definitions
 ToolsDef = []
@@ -659,11 +659,11 @@ cleanlib:
 "module_file"   : MyAgo.MetaFile.Name,
 "module_file_base_name" : MyAgo.MetaFile.BaseName,
 "module_relative_directory" : MyAgo.SourceDir,
 "module_dir": mws.join (self.Macros["WORKSPACE"], 
MyAgo.SourceDir),
 "package_relative_directory": package_rel_dir,
-"module_extra_defines"  : ["%s = %s" % (k, v) for k, v in 
MyAgo.Module.Defines.iteritems()],
+"module_extra_defines"  : ["%s = %s" % (k, v) for k, v in 
MyAgo.Module.Defines.items()],
 
 "architecture"  : MyAgo.Arch,
 "toolchain_tag" : MyAgo.ToolChain,
 "build_target"  : MyAgo.BuildTarget,
 
diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py 
b/BaseTools/Source/Python/Workspace/DscBuildData.py
index 0dad04212e..9c5596927f 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -1674,11 +1674,11 @@ class DscBuildData(PlatformBuildClassObject):
 if (PcdCName, TokenSpaceGuid) in PcdValueDict:
 PcdValueDict[PcdCName, TokenSpaceGuid][SkuName] = (PcdValue, 
DatumType, MaxDatumSize)
 else:
 PcdValueDict[PcdCName, TokenSpaceGuid] = {SkuName:(PcdValue, 
DatumType, MaxDatumSize)}
 
-for ((PcdCName, TokenSpaceGuid), PcdSetting) in 
PcdValueDict.iteritems():
+for ((PcdCName, TokenSpaceGuid), PcdSetting) in PcdValueDict.items():
 if self.SkuIdMgr.SystemSkuId in PcdSetting:
 PcdValue, DatumType, MaxDatumSize = 
PcdSetting[self.SkuIdMgr.SystemSkuId]
 elif TAB_DEFAULT in PcdSetting:
 PcdValue, DatumType, MaxDatumSize = PcdSetting[TAB_DEFAULT]
 elif TAB_COMMON in PcdSetting:
diff --git a/BaseTools/Source/Python/build/build.py 
b/BaseTools/Source/Python/build/build.py
index d07c8f84d6..94074b89b4 100644
--- a/BaseTools/Source/Python/build/build.py
+++ b/BaseTools/Source/Python/build/build.py
@@ -2086,11 +2086,11 @@ class Build():
 # Build up the list of supported architectures for this 
build
 prefix = '%s_%s_%s_' % (BuildTarget, ToolChain, Arch)
 
 # Look through the tool definitions for GUIDed tools
 guidAttribs = []
-for (attrib, value) in 
self.ToolDef.ToolsDefTxtDictionary.iteritems():
+for (attrib, value) in 
self.ToolDef.ToolsDefTxtDictionary.items():
 if attrib.upper().endswith('_GUID'):
 split = attrib.split('_')
 thisPrefix = '_'.join(split[0:3]) + '_'
 if thisPrefix == prefix:
 guid = 
self.ToolDef.ToolsDefTxtDictionary[attrib]
-- 
2.20.1.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [Patch 04/33] BaseTools: replace get_bytes_le() to bytes_le

2019-01-28 Thread Feng, Bob C
From: Zhijux Fan 

UUID does not have the get_bytes_le() in python3

Cc: Bob Feng 
Cc: Liming Gao 
Cc: Yonghong Zhu 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhiju.Fan 
---
 BaseTools/Source/Python/Common/Misc.py | 2 +-
 BaseTools/Source/Python/GenFds/CapsuleData.py  | 2 +-
 BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/BaseTools/Source/Python/Common/Misc.py 
b/BaseTools/Source/Python/Common/Misc.py
index 01bd62a9e2..2ef8e07839 100644
--- a/BaseTools/Source/Python/Common/Misc.py
+++ b/BaseTools/Source/Python/Common/Misc.py
@@ -1178,11 +1178,11 @@ def ParseFieldValue (Value):
 raise BadExpression("Invalid GUID value string %s" % Value)
 Value = TmpValue
 if Value[0] == '"' and Value[-1] == '"':
 Value = Value[1:-1]
 try:
-Value = "'" + uuid.UUID(Value).get_bytes_le() + "'"
+Value = "'" + uuid.UUID(Value).bytes_le + "'"
 except ValueError as Message:
 raise BadExpression(Message)
 Value, Size = ParseFieldValue(Value)
 return Value, 16
 if Value.startswith('L"') and Value.endswith('"'):
diff --git a/BaseTools/Source/Python/GenFds/CapsuleData.py 
b/BaseTools/Source/Python/GenFds/CapsuleData.py
index 6071e9f4a5..db201c074b 100644
--- a/BaseTools/Source/Python/GenFds/CapsuleData.py
+++ b/BaseTools/Source/Python/GenFds/CapsuleData.py
@@ -227,11 +227,11 @@ class CapsulePayload(CapsuleData):
VendorFileSize,
int(self.HardwareInstance, 16)
)
 if AuthData:
 Buffer += pack('QIHH', AuthData[0], AuthData[1], AuthData[2], 
AuthData[3])
-Buffer += uuid.UUID(AuthData[4]).get_bytes_le()
+Buffer += uuid.UUID(AuthData[4]).bytes_le
 
 #
 # Append file content to the structure
 #
 ImageFile = open(self.ImageFile, 'rb')
diff --git a/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py 
b/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py
index 3fd7eefd6a..370ae2e3fa 100644
--- a/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py
+++ b/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py
@@ -184,11 +184,11 @@ if __name__ == '__main__':
 
 #
 # Write output file that contains hash GUID, Public Key, Signature, and 
Input data
 #
 args.OutputFile = open(args.OutputFileName, 'wb')
-args.OutputFile.write(EFI_HASH_ALGORITHM_SHA256_GUID.get_bytes_le())
+args.OutputFile.write(EFI_HASH_ALGORITHM_SHA256_GUID.bytes_le)
 args.OutputFile.write(PublicKey)
 args.OutputFile.write(Signature)
 args.OutputFile.write(args.InputFileBuffer)
 args.OutputFile.close()
 
-- 
2.20.1.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [Patch 01/33] BaseTool:Rename xrange() to range()

2019-01-28 Thread Feng, Bob C
From: Zhijux Fan 

Because the xrange() was not exist in Python3

Cc: Bob Feng 
Cc: Liming Gao 
Cc: Yonghong Zhu 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhiju.Fan 
---
 BaseTools/Source/Python/AutoGen/GenPcdDb.py | 22 +++---
 BaseTools/Source/Python/BPDG/GenVpd.py  |  6 +++---
 BaseTools/Source/Python/Common/Misc.py  |  2 +-
 BaseTools/Source/Python/GenFds/Region.py|  2 +-
 4 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/GenPcdDb.py 
b/BaseTools/Source/Python/AutoGen/GenPcdDb.py
index a9068d2d7a..d3e85293d2 100644
--- a/BaseTools/Source/Python/AutoGen/GenPcdDb.py
+++ b/BaseTools/Source/Python/AutoGen/GenPcdDb.py
@@ -259,11 +259,11 @@ class DbItemList:
 if self.ItemSize == 0:
 #
 # Variable length, need to calculate one by one
 #
 assert(Index < len(self.RawDataList))
-for ItemIndex in xrange(Index):
+for ItemIndex in range(Index):
 Offset += len(self.RawDataList[ItemIndex])
 else:
 Offset = self.ItemSize * Index
 
 return Offset
@@ -346,11 +346,11 @@ class DbComItemList (DbItemList):
 # The only variable table is stringtable, it is not Composite 
item, should not reach here
 #
 assert(False)
 else:
 assert(Index < len(self.RawDataList))
-for ItemIndex in xrange(Index):
+for ItemIndex in range(Index):
 Offset += len(self.RawDataList[ItemIndex]) * self.ItemSize
 
 return Offset
 
 def GetListSize(self):
@@ -412,11 +412,11 @@ class DbStringHeadTableItemList(DbItemList):
 if self.ItemSize == 0:
 #
 # Variable length, need to calculate one by one
 #
 assert(Index < len(self.RawDataList))
-for ItemIndex in xrange(Index):
+for ItemIndex in range(Index):
 Offset += len(self.RawDataList[ItemIndex])
 else:
 for innerIndex in range(Index):
 if type(self.RawDataList[innerIndex]) in (list, tuple):
 Offset += len(self.RawDataList[innerIndex]) * self.ItemSize
@@ -496,27 +496,27 @@ class DbStringItemList (DbComItemList):
 LenList = []
 
 assert(len(RawDataList) == len(LenList))
 DataList = []
 # adjust DataList according to the LenList
-for Index in xrange(len(RawDataList)):
+for Index in range(len(RawDataList)):
 Len = LenList[Index]
 RawDatas = RawDataList[Index]
 assert(Len >= len(RawDatas))
 ActualDatas = []
-for i in xrange(len(RawDatas)):
+for i in range(len(RawDatas)):
 ActualDatas.append(RawDatas[i])
-for i in xrange(len(RawDatas), Len):
+for i in range(len(RawDatas), Len):
 ActualDatas.append(0)
 DataList.append(ActualDatas)
 self.LenList = LenList
 DbComItemList.__init__(self, ItemSize, DataList, RawDataList)
 def GetInterOffset(self, Index):
 Offset = 0
 
 assert(Index < len(self.LenList))
-for ItemIndex in xrange(Index):
+for ItemIndex in range(Index):
 Offset += self.LenList[ItemIndex]
 
 return Offset
 
 def GetListSize(self):
@@ -700,11 +700,11 @@ def BuildExDataBase(Dict):
 # The FixedHeader length of the PCD_DATABASE_INIT, from Signature to Pad
 FixedHeaderLen = 80
 
 # Get offset of SkuId table in the database
 SkuIdTableOffset = FixedHeaderLen
-for DbIndex in xrange(len(DbTotal)):
+for DbIndex in range(len(DbTotal)):
 if DbTotal[DbIndex] is SkuidValue:
 break
 SkuIdTableOffset += DbItemTotal[DbIndex].GetListSize()
 
 
@@ -712,11 +712,11 @@ def BuildExDataBase(Dict):
 
 # Fix up the LocalTokenNumberTable, SkuHeader table
 for (LocalTokenNumberTableIndex, (Offset, Table)) in 
enumerate(LocalTokenNumberTable):
 DbIndex = 0
 DbOffset = FixedHeaderLen
-for DbIndex in xrange(len(DbTotal)):
+for DbIndex in range(len(DbTotal)):
 if DbTotal[DbIndex] is Table:
 DbOffset += DbItemTotal[DbIndex].GetInterOffset(Offset)
 break
 DbOffset += DbItemTotal[DbIndex].GetListSize()
 if DbIndex + 1 == InitTableNum:
@@ -738,11 +738,11 @@ def BuildExDataBase(Dict):
 skuindex = 0
 for VariableEntryPerSku in VariableEntries:
 (VariableHeadGuidIndex, VariableHeadStringIndex, 
SKUVariableOffset, VariableOffset, VariableRefTable, VariableAttribute) = 
VariableEntryPerSku[:]
 DbIndex = 0
 DbOffset = FixedHeaderLen
-for DbIndex in xrange(len(DbTotal)):
+for DbIndex in range(len(DbTotal)):
 if DbTotal[DbIndex] is VariableRefTable:
   

[edk2] [Patch 05/33] BaseTools: use OrderedDict instead of sdict

2019-01-28 Thread Feng, Bob C
use OrderedDict instead of sdict, and delete sdict

Cc: Bob Feng 
Cc: Liming Gao 
Cc: Yonghong Zhu 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng 
---
 BaseTools/Source/Python/Common/Misc.py | 123 
+--
 1 file changed, 1 insertion(+), 122 deletions(-)

diff --git a/BaseTools/Source/Python/Common/Misc.py 
b/BaseTools/Source/Python/Common/Misc.py
index 2ef8e07839..9967ac470c 100644
--- a/BaseTools/Source/Python/Common/Misc.py
+++ b/BaseTools/Source/Python/Common/Misc.py
@@ -820,131 +820,10 @@ class Progressor:
 Progressor._StopFlag.set()
 if Progressor._ProgressThread is not None:
 Progressor._ProgressThread.join()
 Progressor._ProgressThread = None
 
-## A dict which can access its keys and/or values orderly
-#
-#  The class implements a new kind of dict which its keys or values can be
-#  accessed in the order they are added into the dict. It guarantees the order
-#  by making use of an internal list to keep a copy of keys.
-#
-class sdict(dict):
-## Constructor
-def __init__(self):
-dict.__init__(self)
-self._key_list = []
-
-## [] operator
-def __setitem__(self, key, value):
-if key not in self._key_list:
-self._key_list.append(key)
-dict.__setitem__(self, key, value)
-
-## del operator
-def __delitem__(self, key):
-self._key_list.remove(key)
-dict.__delitem__(self, key)
-
-## used in "for k in dict" loop to ensure the correct order
-def __iter__(self):
-return self.iterkeys()
-
-## len() support
-def __len__(self):
-return len(self._key_list)
-
-## "in" test support
-def __contains__(self, key):
-return key in self._key_list
-
-## indexof support
-def index(self, key):
-return self._key_list.index(key)
-
-## insert support
-def insert(self, key, newkey, newvalue, order):
-index = self._key_list.index(key)
-if order == 'BEFORE':
-self._key_list.insert(index, newkey)
-dict.__setitem__(self, newkey, newvalue)
-elif order == 'AFTER':
-self._key_list.insert(index + 1, newkey)
-dict.__setitem__(self, newkey, newvalue)
-
-## append support
-def append(self, sdict):
-for key in sdict:
-if key not in self._key_list:
-self._key_list.append(key)
-dict.__setitem__(self, key, sdict[key])
-
-def has_key(self, key):
-return key in self._key_list
-
-## Empty the dict
-def clear(self):
-self._key_list = []
-dict.clear(self)
-
-## Return a copy of keys
-def keys(self):
-keys = []
-for key in self._key_list:
-keys.append(key)
-return keys
-
-## Return a copy of values
-def values(self):
-values = []
-for key in self._key_list:
-values.append(self[key])
-return values
-
-## Return a copy of (key, value) list
-def items(self):
-items = []
-for key in self._key_list:
-items.append((key, self[key]))
-return items
-
-## Iteration support
-def iteritems(self):
-return iter(self.items())
-
-## Keys interation support
-def iterkeys(self):
-return iter(self.keys())
-
-## Values interation support
-def itervalues(self):
-return iter(self.values())
-
-## Return value related to a key, and remove the (key, value) from the dict
-def pop(self, key, *dv):
-value = None
-if key in self._key_list:
-value = self[key]
-self.__delitem__(key)
-elif len(dv) != 0 :
-value = kv[0]
-return value
-
-## Return (key, value) pair, and remove the (key, value) from the dict
-def popitem(self):
-key = self._key_list[-1]
-value = self[key]
-self.__delitem__(key)
-return key, value
-
-def update(self, dict=None, **kwargs):
-if dict is not None:
-for k, v in dict.items():
-self[k] = v
-if len(kwargs):
-for k, v in kwargs.items():
-self[k] = v
 
 ## Dictionary using prioritized list as key
 #
 class tdict:
 _ListType = type([])
@@ -1744,11 +1623,11 @@ class SkuClass():
 if skuid_num > 0x:
 EdkLogger.error("build", PARAMETER_INVALID,
 ExtraData = "SKU-ID [%s] value %s exceeds the max 
value of UINT64"
   % (SkuName, SkuId))
 
-self.AvailableSkuIds = sdict()
+self.AvailableSkuIds = OrderedDict()
 self.SkuIdSet = []
 self.SkuIdNumberSet = []
 self.SkuData = SkuIds
 self._SkuInherit = {}
 self._SkuIdentifier = SkuIdentif

[edk2] [PATCH 2/2] add support bh720+emmc chip

2019-01-28 Thread Mike Li (WH)
---
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c | 147 ++
 .../Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c | 130 +++-
 2 files changed, 174 insertions(+), 103 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c 
b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c
index 83e6bf0c90..4f38eca199 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c
@@ -319,9 +319,116 @@ SdCardSetRca (
   return Status;
 }
 
+/**
+  Send command SEND_CSD to the SD device to get the data of the CSD register.
+
+  Refer to SD Physical Layer Simplified Spec 4.1 Section 4.7 for details.
+
+  @param[in]  PassThru  A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL 
instance.
+  @param[in]  Slot  The slot number of the SD card to send the command 
to.
+  @param[in]  Rca   The relative device address of selected device.
+  @param[out] Csd   The buffer to store the content of the CSD 
register.
+Note the caller should ignore the lowest byte of 
this
+buffer as the content of this byte is meaningless 
even
+if the operation succeeds.
+
+  @retval EFI_SUCCESS   The operation is done correctly.
+  @retval OthersThe operation fails.
+
+**/
+EFI_STATUS
+SdCardGetCsd (
+  IN EFI_SD_MMC_PASS_THRU_PROTOCOL  *PassThru,
+  IN UINT8  Slot,
+  IN UINT16 Rca,
+ OUT SD_CSD *Csd
+  )
+{
+  EFI_SD_MMC_COMMAND_BLOCK  SdMmcCmdBlk;
+  EFI_SD_MMC_STATUS_BLOCK   SdMmcStatusBlk;
+  EFI_SD_MMC_PASS_THRU_COMMAND_PACKET   Packet;
+  EFI_STATUSStatus;
+
+  ZeroMem (&SdMmcCmdBlk, sizeof (SdMmcCmdBlk));
+  ZeroMem (&SdMmcStatusBlk, sizeof (SdMmcStatusBlk));
+  ZeroMem (&Packet, sizeof (Packet));
 
+  Packet.SdMmcCmdBlk= &SdMmcCmdBlk;
+  Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
+  Packet.Timeout= SD_MMC_HC_GENERIC_TIMEOUT;
 
+  SdMmcCmdBlk.CommandIndex = SD_SEND_CSD;
+  SdMmcCmdBlk.CommandType  = SdMmcCommandTypeAc;
+  SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR2;
+  SdMmcCmdBlk.CommandArgument = (UINT32)Rca << 16;
 
+  Status = SdMmcPassThruPassThru (PassThru, Slot, &Packet, NULL);
+  if (!EFI_ERROR (Status)) {
+//
+// For details, refer to SD Host Controller Simplified Spec 3.0 Table 2-12.
+//
+CopyMem (((UINT8*)Csd) + 1, &SdMmcStatusBlk.Resp0, sizeof (SD_CSD) - 1);
+  }
+
+  return Status;
+}
+
+/**
+  Send command SEND_CSD to the SD device to get the data of the CSD register.
+
+  Refer to SD Physical Layer Simplified Spec 4.1 Section 4.7 for details.
+
+  @param[in]  PassThru  A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL 
instance.
+  @param[in]  Slot  The slot number of the SD card to send the command 
to.
+  @param[in]  Rca   The relative device address of selected device.
+  @param[out] Scr   The buffer to store the content of the SCR 
register.
+
+  @retval EFI_SUCCESS   The operation is done correctly.
+  @retval OthersThe operation fails.
+
+**/
+EFI_STATUS
+SdCardGetScr (
+  IN EFI_SD_MMC_PASS_THRU_PROTOCOL  *PassThru,
+  IN UINT8  Slot,
+  IN UINT16 Rca,
+ OUT SD_SCR *Scr
+  )
+{
+  EFI_SD_MMC_COMMAND_BLOCK  SdMmcCmdBlk;
+  EFI_SD_MMC_STATUS_BLOCK   SdMmcStatusBlk;
+  EFI_SD_MMC_PASS_THRU_COMMAND_PACKET   Packet;
+  EFI_STATUSStatus;
+
+  ZeroMem (&SdMmcCmdBlk, sizeof (SdMmcCmdBlk));
+  ZeroMem (&SdMmcStatusBlk, sizeof (SdMmcStatusBlk));
+  ZeroMem (&Packet, sizeof (Packet));
+
+  Packet.SdMmcCmdBlk= &SdMmcCmdBlk;
+  Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
+  Packet.Timeout= SD_MMC_HC_GENERIC_TIMEOUT;
+
+  SdMmcCmdBlk.CommandIndex = SD_APP_CMD;
+  SdMmcCmdBlk.CommandType  = SdMmcCommandTypeAc;
+  SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1;
+  SdMmcCmdBlk.CommandArgument = (UINT32)Rca << 16;
+
+  Status = SdMmcPassThruPassThru (PassThru, Slot, &Packet, NULL);
+  if (EFI_ERROR (Status)) {
+return Status;
+  }
+
+  SdMmcCmdBlk.CommandIndex = SD_SEND_SCR;
+  SdMmcCmdBlk.CommandType  = SdMmcCommandTypeAdtc;
+  SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1;
+
+  Packet.InDataBuffer = Scr;
+  Packet.InTransferLength = sizeof (SD_SCR);
+
+  Status = SdMmcPassThruPassThru (PassThru, Slot, &Packet, NULL);
+
+  return Status;
+}
 
 /**
   Send command SELECT_DESELECT_CARD to the SD device to select/deselect it.
@@ -785,8 +892,8 @@ SdCardSetBusMode (
   UINT8BusWidth;
   UINT8AccessMode;
   UINT8HostCtrl1;
+  UINT8HostCtrl2;
   UINT8SwitchResp[64];
-  SD_MMC_BUS_MODE  Timing;
   SD_MMC_HC_PRIVATE_DATA   *Private;
 
   Private = SD_MM

Re: [edk2] [PATCH v2 2/2] MdePkg/UefiDevicePathLib: Add a checking step

2019-01-28 Thread Gao, Liming
Shenglei:
  The patch is good. Reviewed-by: Liming Gao 
  
  Besides, this patch is from MS Mu project. Please keep original patch author. 
You don't need to send this patch again. 

Thanks
Liming
> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of 
> Shenglei Zhang
> Sent: Wednesday, December 12, 2018 11:10 AM
> To: edk2-devel@lists.01.org
> Cc: Kinney, Michael D ; Gao, Liming 
> 
> Subject: [edk2] [PATCH v2 2/2] MdePkg/UefiDevicePathLib: Add a checking step
> 
> Add a checking step in DevicePathUtilities.c to verify the DevicePath.
> https://bugzilla.tianocore.org/show_bug.cgi?id=1372
> 
> v2: Remove ASSERT() and the redundant checking step.
> Update related description in DevicePathLib.h
> 
> Cc: Liming Gao 
> Cc: Michael D Kinney 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Shenglei Zhang 
> ---
>  MdePkg/Include/Library/DevicePathLib.h |  2 +-
>  .../UefiDevicePathLib/DevicePathUtilities.c| 14 ++
>  2 files changed, 7 insertions(+), 9 deletions(-)
> 
> diff --git a/MdePkg/Include/Library/DevicePathLib.h 
> b/MdePkg/Include/Library/DevicePathLib.h
> index 959299704a..717d4db42f 100644
> --- a/MdePkg/Include/Library/DevicePathLib.h
> +++ b/MdePkg/Include/Library/DevicePathLib.h
> @@ -22,7 +22,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER 
> EXPRESS OR IMPLIED.
> 
>  /**
>Determine whether a given device path is valid.
> -  If DevicePath is NULL, then ASSERT().
> +  If DevicePath is NULL or the size is not suitable, then return false.
> 
>@param  DevicePath  A pointer to a device path data structure.
>@param  MaxSize The maximum size of the device path data structure.
> diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c 
> b/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c
> index 665e5a4adc..05f82c1313 100644
> --- a/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c
> +++ b/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c
> @@ -59,19 +59,17 @@ IsDevicePathValid (
>UINTN Size;
>UINTN NodeLength;
> 
> -  ASSERT (DevicePath != NULL);
> -
> -  if (MaxSize == 0) {
> -MaxSize = MAX_UINTN;
> -  }
> -
>//
> -  // Validate the input size big enough to touch the first node.
> +  //Validate the input whether exists and its size big enough to touch the 
> first node
>//
> -  if (MaxSize < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {
> +  if (DevicePath == NULL || (MaxSize > 0 && MaxSize < 
> END_DEVICE_PATH_LENGTH)) {
>  return FALSE;
>}
> 
> +  if (MaxSize == 0) {
> +MaxSize = MAX_UINTN;
> +  }
> +
>for (Count = 0, Size = 0; !IsDevicePathEnd (DevicePath); DevicePath = 
> NextDevicePathNode (DevicePath)) {
>  NodeLength = DevicePathNodeLength (DevicePath);
>  if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {
> --
> 2.18.0.windows.1
> 
> ___
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH] MdePkg/BasePeCoffLib: skip runtime relocation if relocation info is invalid.

2019-01-28 Thread Hsueh, Hong-chihX
> -Original Message-
> From: Laszlo Ersek [mailto:ler...@redhat.com]
> Sent: Monday, January 28, 2019 2:17 PM
> To: Hsueh, Hong-chihX ; edk2-devel@lists.01.org
> Cc: Kinney, Michael D ; Gao, Liming
> ; Bi, Dandan 
> Subject: Re: [PATCH] MdePkg/BasePeCoffLib: skip runtime relocation if
> relocation info is invalid.
> 
> On 01/28/19 19:40, Neo Hsueh wrote:
> > Skip runtime relocation for PE images that provide invalid relocation
> > infomation
> > (ex: RelocDir->Size = 0) to fix a hang observed while booting Windows.
> >
> > Contributed-under: TianoCore Contribution Agreement 1.1
> >
> > Signed-off-by: Neo Hsueh 
> > Cc: Michael D Kinney 
> > Cc: Liming Gao 
> > Cc: Dandan Bi 
> > Cc: Laszlo Ersek 
> > ---
> >  MdePkg/Library/BasePeCoffLib/BasePeCoff.c | 6 ++
> >  1 file changed, 6 insertions(+)
> >
> > diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
> > b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
> > index 1bd079ad6a..f01c691dea 100644
> > --- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
> > +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
> > @@ -1746,6 +1746,12 @@ PeCoffLoaderRelocateImageForRuntime (
> > 
> >  RelocDir->VirtualAddress +
> RelocDir->Size - 1,
> > 
> >  0
> >
> > );
> > +if (RelocBase == NULL || RelocBaseEnd == NULL || RelocBaseEnd <
> RelocBase) {
> > +  //
> > +  // relocation block is not valid, just return
> > +  //
> > +  return;
> > +}
> >} else {
> >  //
> >  // Cannot find relocations, cannot continue to relocate the image, 
> > ASSERT
> for this invalid image.
> >
> 
> Thank you for the update.
> 
> ... Originally I meant to respond with an Acked-by (purely from a formal 
> point-
> of-view); however I figured the patch wasn't large and I could check it for a
> Reviewed-by as well.
> 
> I'm noticing the comparison (RelocBaseEnd < RelocBase) is supposed to catch
> invalid relocation info. These variables are pointers, declared as
> follows:
> 
>   EFI_IMAGE_BASE_RELOCATION *RelocBase;
>   EFI_IMAGE_BASE_RELOCATION *RelocBaseEnd;
> 
> According to the C standard, the relational operators can only be applied to a
> pair of pointers if each of those points into the same array, or one past the 
> last
> element. In this case, given that you intend to catch invalid relocation info,
> that's exactly *not* the case. In other words, in the only case when the
> relational operator would evaluate to true, it would also invoke undefined
> behavior. Furthermore, the byte distance between the pointed-to-objects might
> not even be a whole multiple of sizeof (EFI_IMAGE_BASE_RELOCATION).
> 
> Normally I would suggest changing the return type of
> PeCoffLoaderImageAddress() to UINTN -- that would be fitting because the
> internal computation is already performed in UINTN, and only cast to
> (CHAR8 *) as last step. This way we could move the cast to the callers, and
> perform the sanity checks before the conversion to (VOID*) (or to other 
> pointer
> types).
> 
> I do see the function is called from many places, so this change might be too
> costly. Can we at least write in this patch,
> 
>   if (RelocBase == NULL ||
>   RelocBaseEnd == NULL ||
>   (UINTN)RelocBaseEnd < (UINTN)RelocBase ||
>   (((UINTN)RelocBaseEnd - (UINTN)RelocBase) %
>sizeof (EFI_IMAGE_BASE_RELOCATION) != 0)) {
> return;
>   }
> 
> ?
> 
> Perhaps we should even extract this logic to a helper function, because I see
> another spot with the same condition. That's in PeCoffLoaderRelocateImage(),
> from the top of commit a8d8d430510d ("Support load 64 bit image from 32 bit
> core. Add more enhancement to check invalid PE format.", 2014-03-25).
> 
> I'm sorry that I didn't manage to make these suggestions under the v1 posting.
> 
> Thanks,
> Laszlo

Hi Laszlo,
Thank you. I agree the pointer comparison is not optimal especially in this 
case.
However I didn't add multiple of size (EFI_IMAGE_BASE_RELOCATION) check because 
from the commit eb76b762, we actually check the address range between Base to 
RelocDir->Size - 1.

Here is the updated patch :
https://lists.01.org/pipermail/edk2-devel/2019-January/035810.html

Regards,
Neo
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH] MdePkg/BasePeCoffLib: skip runtime relocation if relocation info is invalid.

2019-01-28 Thread Neo Hsueh
Skip runtime relocation for PE images that provide invalid relocation infomation
(ex: RelocDir->Size = 0) to fix a hang observed while booting Windows.

Contributed-under: TianoCore Contribution Agreement 1.1

Signed-off-by: Neo Hsueh 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Dandan Bi 
Cc: Laszlo Ersek 
---
 MdePkg/Library/BasePeCoffLib/BasePeCoff.c | 16 +++-
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c 
b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
index 1bd079ad6a..6d6c37bd61 100644
--- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
+++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
@@ -1002,7 +1002,7 @@ PeCoffLoaderRelocateImage (
 
RelocDir->VirtualAddress + RelocDir->Size - 1,
 
TeStrippedOffset
 );
-if (RelocBase == NULL || RelocBaseEnd == NULL || RelocBaseEnd < RelocBase) 
{
+if (RelocBase == NULL || RelocBaseEnd == NULL || (UINTN) RelocBaseEnd < 
(UINTN) RelocBase) {
   ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION;
   return RETURN_LOAD_ERROR;
 }
@@ -1022,7 +1022,7 @@ PeCoffLoaderRelocateImage (
 // Run the relocation information and apply the fixups
 //
 FixupData = ImageContext->FixupData;
-while (RelocBase < RelocBaseEnd) {
+while ((UINTN) RelocBase < (UINTN) RelocBaseEnd) {
 
   Reloc = (UINT16 *) ((CHAR8 *) RelocBase + sizeof 
(EFI_IMAGE_BASE_RELOCATION));
   //
@@ -1051,7 +1051,7 @@ PeCoffLoaderRelocateImage (
   //
   // Run this relocation record
   //
-  while (Reloc < RelocEnd) {
+  while ((UINTN) Reloc < (UINTN) RelocEnd) {
 Fixup = PeCoffLoaderImageAddress (ImageContext, 
RelocBase->VirtualAddress + (*Reloc & 0xFFF), TeStrippedOffset);
 if (Fixup == NULL) {
   ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION;
@@ -1746,6 +1746,12 @@ PeCoffLoaderRelocateImageForRuntime (
 
RelocDir->VirtualAddress + RelocDir->Size - 1,
 0
 );
+if (RelocBase == NULL || RelocBaseEnd == NULL || (UINTN) RelocBaseEnd < 
(UINTN) RelocBase) {
+  //
+  // relocation block is not valid, just return
+  //
+  return;
+}
   } else {
 //
 // Cannot find relocations, cannot continue to relocate the image, ASSERT 
for this invalid image.
@@ -1769,7 +1775,7 @@ PeCoffLoaderRelocateImageForRuntime (
 //
 FixupData = RelocationData;
 RelocBaseOrig = RelocBase;
-while (RelocBase < RelocBaseEnd) {
+while ((UINTN) RelocBase < (UINTN) RelocBaseEnd) {
   //
   // Add check for RelocBase->SizeOfBlock field.
   //
@@ -1794,7 +1800,7 @@ PeCoffLoaderRelocateImageForRuntime (
   //
   // Run this relocation record
   //
-  while (Reloc < RelocEnd) {
+  while ((UINTN) Reloc < (UINTN) RelocEnd) {
 
 Fixup = PeCoffLoaderImageAddress (&ImageContext, 
RelocBase->VirtualAddress + (*Reloc & 0xFFF), 0);
 if (Fixup == NULL) {
-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH] MdePkg/BasePeCoffLib: skip runtime relocation if relocation info is invalid.

2019-01-28 Thread Laszlo Ersek
On 01/28/19 19:40, Neo Hsueh wrote:
> Skip runtime relocation for PE images that provide invalid relocation 
> infomation
> (ex: RelocDir->Size = 0) to fix a hang observed while booting
> Windows.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> 
> Signed-off-by: Neo Hsueh 
> Cc: Michael D Kinney 
> Cc: Liming Gao 
> Cc: Dandan Bi 
> Cc: Laszlo Ersek 
> ---
>  MdePkg/Library/BasePeCoffLib/BasePeCoff.c | 6 ++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c 
> b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
> index 1bd079ad6a..f01c691dea 100644
> --- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
> +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
> @@ -1746,6 +1746,12 @@ PeCoffLoaderRelocateImageForRuntime (
>  
> RelocDir->VirtualAddress + RelocDir->Size - 1,
>  0
>  
> );
> +if (RelocBase == NULL || RelocBaseEnd == NULL || RelocBaseEnd < 
> RelocBase) {
> +  //
> +  // relocation block is not valid, just return
> +  //
> +  return;
> +}
>} else {
>  //
>  // Cannot find relocations, cannot continue to relocate the image, 
> ASSERT for this invalid image.
> 

Thank you for the update.

... Originally I meant to respond with an Acked-by (purely from a formal
point-of-view); however I figured the patch wasn't large and I could
check it for a Reviewed-by as well.

I'm noticing the comparison (RelocBaseEnd < RelocBase) is supposed to
catch invalid relocation info. These variables are pointers, declared as
follows:

  EFI_IMAGE_BASE_RELOCATION *RelocBase;
  EFI_IMAGE_BASE_RELOCATION *RelocBaseEnd;

According to the C standard, the relational operators can only be
applied to a pair of pointers if each of those points into the same
array, or one past the last element. In this case, given that you intend
to catch invalid relocation info, that's exactly *not* the case. In
other words, in the only case when the relational operator would
evaluate to true, it would also invoke undefined behavior. Furthermore,
the byte distance between the pointed-to-objects might not even be a
whole multiple of sizeof (EFI_IMAGE_BASE_RELOCATION).

Normally I would suggest changing the return type of
PeCoffLoaderImageAddress() to UINTN -- that would be fitting because the
internal computation is already performed in UINTN, and only cast to
(CHAR8 *) as last step. This way we could move the cast to the callers,
and perform the sanity checks before the conversion to (VOID*) (or to
other pointer types).

I do see the function is called from many places, so this change might
be too costly. Can we at least write in this patch,

  if (RelocBase == NULL ||
  RelocBaseEnd == NULL ||
  (UINTN)RelocBaseEnd < (UINTN)RelocBase ||
  (((UINTN)RelocBaseEnd - (UINTN)RelocBase) %
   sizeof (EFI_IMAGE_BASE_RELOCATION) != 0)) {
return;
  }

?

Perhaps we should even extract this logic to a helper function, because
I see another spot with the same condition. That's in
PeCoffLoaderRelocateImage(), from the top of commit a8d8d430510d
("Support load 64 bit image from 32 bit core. Add more enhancement to
check invalid PE format.", 2014-03-25).

I'm sorry that I didn't manage to make these suggestions under the v1
posting.

Thanks,
Laszlo
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH] ArmPkg/ArmMmuLib ARM: trim high memory regions instead of rejecting them

2019-01-28 Thread Ard Biesheuvel
On Mon, 28 Jan 2019 at 19:11, Leif Lindholm  wrote:
>
> On Mon, Jan 28, 2019 at 05:23:32PM +0100, Ard Biesheuvel wrote:
> > ArmSetMemoryAttributes() still chokes in some cases, i.e., when the
> > length of the region exceeds 4 GB, the subtraction overflows, which
> > results in the region being misidentified as being 32-bit addressable.
> >
> > Let's update the logic to trim the length to what we can address with
> > 32 bits. This fixes the issue, and also deals with the issue where an
> > entire region is disregarded if part of it exceeds beyond what we can
> > map with 32 bits.
> >
> > Contributed-under: TianoCore Contribution Agreement 1.1
> > Signed-off-by: Ard Biesheuvel 
>
> Reviewed-by: Leif Lindholm 
>

Thanks

Pushed as 9a00a7164a39..66509f90fc66

> > ---
> >  ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibCore.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibCore.c 
> > b/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibCore.c
> > index bffab83d4fd0..baa085c3849a 100644
> > --- a/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibCore.c
> > +++ b/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibCore.c
> > @@ -744,10 +744,11 @@ ArmSetMemoryAttributes (
> >UINT64ChunkLength;
> >BOOLEAN   FlushTlbs;
> >
> > -  if (BaseAddress > (UINT64)MAX_ADDRESS - Length + 1) {
> > +  if (BaseAddress > (UINT64)MAX_ADDRESS) {
> >  return EFI_UNSUPPORTED;
> >}
> >
> > +  Length = MIN (Length, (UINT64)MAX_ADDRESS - BaseAddress + 1);
> >if (Length == 0) {
> >  return EFI_SUCCESS;
> >}
> > --
> > 2.20.1
> >
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH] MdePkg/BasePeCoffLib: skip runtime relocation if relocation info is invalid.

2019-01-28 Thread Hsueh, Hong-chihX
Hi Laszlo,
Thank you for your comment.
I've sent an updated patch for review.
https://lists.01.org/pipermail/edk2-devel/2019-January/035806.html

Regards,
Neo

> -Original Message-
> From: Laszlo Ersek [mailto:ler...@redhat.com]
> Sent: Friday, January 25, 2019 1:07 AM
> To: Hsueh, Hong-chihX ; edk2-devel@lists.01.org
> Cc: Kinney, Michael D ; Bi, Dandan
> ; Gao, Liming 
> Subject: Re: [edk2] [PATCH] MdePkg/BasePeCoffLib: skip runtime relocation if
> relocation info is invalid.
> 
> On 01/25/19 00:18, Neo Hsueh wrote:
> > 1.Skip runtime relocation for PE images that provide invalid relocation
> >   infomation (ex: RelocDir->Size = 0) to fix a hang observed while booting
> >   Windows.
> > 2.Add a magic number check for PE32+ image.
> >
> > Contributed-under: TianoCore Contribution Agreement 1.1
> > Signed-off-by: Neo Hsueh 
> > Cc: Michael D Kinney 
> > Cc: Liming Gao 
> > Cc: Dandan Bi 
> > ---
> >  MdePkg/Library/BasePeCoffLib/BasePeCoff.c | 19 ---
> >  1 file changed, 16 insertions(+), 3 deletions(-)
> 
> I can't comment on the technical details of the patch, but I have some
> comments on the organization of the patch.
> 
> First, the two changes that it implements should be separate patches.
> 
> > diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
> > b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
> > index 1bd079ad6a..6477ef0759 100644
> > --- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
> > +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
> > @@ -1725,11 +1725,18 @@ PeCoffLoaderRelocateImageForRuntime (
> >  NumberOfRvaAndSizes = Hdr.Pe32-
> >OptionalHeader.NumberOfRvaAndSizes;
> >  DataDirectory = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32-
> >OptionalHeader.DataDirectory[0]);
> >} else {
> > +if (Hdr.Pe32Plus->OptionalHeader.Magic ==
> EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
> > +  //
> > +  // Use PE32+ offset
> > +  //
> > +  NumberOfRvaAndSizes = Hdr.Pe32Plus-
> >OptionalHeader.NumberOfRvaAndSizes;
> > +  DataDirectory = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32Plus-
> >OptionalHeader.DataDirectory[0]);
> > +} else {
> >  //
> > -// Use PE32+ offset
> > +// Not a valid PE image so Exit
> >  //
> > -NumberOfRvaAndSizes = Hdr.Pe32Plus-
> >OptionalHeader.NumberOfRvaAndSizes;
> > -DataDirectory = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32Plus-
> >OptionalHeader.DataDirectory[0]);
> > +return;
> > +}
> >}
> >
> >//
> 
> Second, my understanding is that in edk2, we don't do
> 
>   if (Condition1) {
>   } else {
> if (Condition2) {
> } else {
> }
>   }
> 
> Instead, we prefer
> 
>   if (Condition1) {
>   } else if (Condition2) {
>   } else {
>   }
> 
> As far as I know, this is the only construct where we don't require braces 
> after
> an "else". See:
> 
> https://edk2-docs.gitbooks.io/edk-ii-c-coding-standards-
> specification/content/5_source_files/57_c_programming.html#57342-when-
> an-else-is-used-it-may-start-on-the-same-line-as-the-close-brace-of-the-if-or-
> be-on-the-following-line-and-aligned-with-the-closing-brace
> 
> 
> Third, the return statement and the comment are not properly indented in the
> last branch.
> 
> Thanks
> Laszlo
> 
> > @@ -1746,6 +1753,12 @@ PeCoffLoaderRelocateImageForRuntime (
> > 
> >  RelocDir->VirtualAddress +
> RelocDir->Size - 1,
> > 
> >  0
> >
> > );
> > +if (RelocBase == NULL || RelocBaseEnd == NULL || RelocBaseEnd <
> RelocBase) {
> > +  //
> > +  // relocation block is not valid, just return
> > +  //
> > +  return;
> > +}
> >} else {
> >  //
> >  // Cannot find relocations, cannot continue to relocate the image, 
> > ASSERT
> for this invalid image.
> >

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH] MdePkg/BasePeCoffLib: skip runtime relocation if relocation info is invalid.

2019-01-28 Thread Neo Hsueh
Skip runtime relocation for PE images that provide invalid relocation infomation
(ex: RelocDir->Size = 0) to fix a hang observed while booting
Windows.

Contributed-under: TianoCore Contribution Agreement 1.1

Signed-off-by: Neo Hsueh 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Dandan Bi 
Cc: Laszlo Ersek 
---
 MdePkg/Library/BasePeCoffLib/BasePeCoff.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c 
b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
index 1bd079ad6a..f01c691dea 100644
--- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
+++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
@@ -1746,6 +1746,12 @@ PeCoffLoaderRelocateImageForRuntime (
 
RelocDir->VirtualAddress + RelocDir->Size - 1,
 0
 );
+if (RelocBase == NULL || RelocBaseEnd == NULL || RelocBaseEnd < RelocBase) 
{
+  //
+  // relocation block is not valid, just return
+  //
+  return;
+}
   } else {
 //
 // Cannot find relocations, cannot continue to relocate the image, ASSERT 
for this invalid image.
-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH] ArmPkg/ArmMmuLib ARM: trim high memory regions instead of rejecting them

2019-01-28 Thread Leif Lindholm
On Mon, Jan 28, 2019 at 05:23:32PM +0100, Ard Biesheuvel wrote:
> ArmSetMemoryAttributes() still chokes in some cases, i.e., when the
> length of the region exceeds 4 GB, the subtraction overflows, which
> results in the region being misidentified as being 32-bit addressable.
> 
> Let's update the logic to trim the length to what we can address with
> 32 bits. This fixes the issue, and also deals with the issue where an
> entire region is disregarded if part of it exceeds beyond what we can
> map with 32 bits.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Ard Biesheuvel 

Reviewed-by: Leif Lindholm 

> ---
>  ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibCore.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibCore.c 
> b/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibCore.c
> index bffab83d4fd0..baa085c3849a 100644
> --- a/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibCore.c
> +++ b/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibCore.c
> @@ -744,10 +744,11 @@ ArmSetMemoryAttributes (
>UINT64ChunkLength;
>BOOLEAN   FlushTlbs;
>  
> -  if (BaseAddress > (UINT64)MAX_ADDRESS - Length + 1) {
> +  if (BaseAddress > (UINT64)MAX_ADDRESS) {
>  return EFI_UNSUPPORTED;
>}
>  
> +  Length = MIN (Length, (UINT64)MAX_ADDRESS - BaseAddress + 1);
>if (Length == 0) {
>  return EFI_SUCCESS;
>}
> -- 
> 2.20.1
> 
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH 2/5] ArmPkg/ArmMmuLib AARCH64: get rid of needless TLB invalidation

2019-01-28 Thread Leif Lindholm
On Mon, Jan 28, 2019 at 01:29:54PM +0100, Ard Biesheuvel wrote:
> > > > > > > @@ -296,7 +297,8 @@ GetBlockEntryListFromAddress (
> > > > > > >
> > > > > > >  // Fill the BlockEntry with the new TranslationTable
> > > > > > >  ReplaceLiveEntry (BlockEntry,
> > > > > > > -  ((UINTN)TranslationTable & 
> > > > > > > TT_ADDRESS_MASK_DESCRIPTION_TABLE) | TableAttributes | 
> > > > > > > TT_TYPE_TABLE_ENTRY);
> > > > > > > +  (UINTN)TranslationTable | TableAttributes | 
> > > > > > > TT_TYPE_TABLE_ENTRY,
> > > > > > > +  RegionStart);
> > > > > >
> > > > >
> > > > > /me pages in the data ...
> > > > >
> > > > > > OK, this whole patch took a few times around the loop before I 
> > > > > > think I
> > > > > > caught on what was happening.
> > > > > >
> > > > > > I think I'm down to the only things confusing me being:
> > > > > > - The name "Address" to refer to something that is always the start
> > > > > >   address of a 4KB-aligned translation region.
> > > > > >   Is this because the function will be usable in other contexts in
> > > > > >   later patches?
> > > > >
> > > > > I could change it to VirtualAddress if you prefer.
> > > > > It is only passed
> > > > > for TLB maintenance which is only needed at page granularity, and the
> > > > > low bits are shifted out anyway.
> > > >
> > > > Yeah, exactly. It would just be nice if the name reflected that. Not
> > > > sure VirtualAddress does. VirtualBase? PageBase?
> > > >
> > >
> > > Well, the argument passed in is called RegionStart, so let's just
> > > stick with that.
> >
> > Sure. With that:
> > Reviewed-by: Leif Lindholm 
> >
> 
> Thanks
> 
> GIven the discussion in the other thread regarding shareability
> upgrades of barriers and TLB maintenance instructions when running
> under virt, mind if I fold in the hunk below? (and add a mention to
> the commit log)
> 
> --- a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibReplaceEntry.S
> +++ b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibReplaceEntry.S
> @@ -35,7 +35,7 @@
>// flush translations for the target address from the TLBs
>lsr   x2, x2, #12
>tlbi  vae\el, x2
> -  dsb   sy
> +  dsb   nsh

So, this one, definitely. MMU is off, shareability is a shady concept
at best, so it's arguably a fix.

>// re-enable the MMU
>msr   sctlr_el\el, x8
> @@ -58,7 +58,7 @@ ASM_FUNC(ArmReplaceLiveTranslationEntry)
>// clean and invalidate first so that we don't clobber
>// adjacent entries that are dirty in the caches
>dccivac, x0
> -  dsb   ish
> +  dsb   nsh

This one I guess is safe because we know we're never going to get
pre-empted or migrated (because interrupts are disabled and we don't
do that sort of thing)?

If that's the rationale:
Reviewed-by: Leif Lindholm 

/
Leif

>EL1_OR_EL2_OR_EL3(x3)
>  1:__replace_entry 1
> 
> The first one reduces the scope of the tlb maintenance of a live entry
> to the current CPU (and when running under virt, the hypervisor will
> upgrade this to inner shareable)
> The second one prevents the cache maintenance from being broadcast
> unnecessarily, and will be upgraded back to ish in the same way when
> running under virt.
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH] ArmPkg/ArmMmuLib ARM: trim high memory regions instead of rejecting them

2019-01-28 Thread Ard Biesheuvel
ArmSetMemoryAttributes() still chokes in some cases, i.e., when the
length of the region exceeds 4 GB, the subtraction overflows, which
results in the region being misidentified as being 32-bit addressable.

Let's update the logic to trim the length to what we can address with
32 bits. This fixes the issue, and also deals with the issue where an
entire region is disregarded if part of it exceeds beyond what we can
map with 32 bits.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel 
---
 ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibCore.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibCore.c 
b/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibCore.c
index bffab83d4fd0..baa085c3849a 100644
--- a/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibCore.c
+++ b/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibCore.c
@@ -744,10 +744,11 @@ ArmSetMemoryAttributes (
   UINT64ChunkLength;
   BOOLEAN   FlushTlbs;
 
-  if (BaseAddress > (UINT64)MAX_ADDRESS - Length + 1) {
+  if (BaseAddress > (UINT64)MAX_ADDRESS) {
 return EFI_UNSUPPORTED;
   }
 
+  Length = MIN (Length, (UINT64)MAX_ADDRESS - BaseAddress + 1);
   if (Length == 0) {
 return EFI_SUCCESS;
   }
-- 
2.20.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH] ArmPkg: update InvalidateInstructionCacheRange to flush only to PoU

2019-01-28 Thread Mark Rutland
On Mon, Jan 28, 2019 at 09:09:26PM +0800, Tan Xiaojun wrote:
> On 2019/1/28 19:54, Laszlo Ersek wrote:
> > On 01/28/19 11:46, Mark Rutland wrote:
> >> On Wed, Jan 23, 2019 at 10:54:56AM +0100, Laszlo Ersek wrote:
> >>> And even on the original (unspecified) hardware, the same binary works
> >>> frequently. My understanding is that there are five VMs executing reboot
> >>> loops in parallel, on the same host, and 4 out of 5 may hit the issue in
> >>> a reasonable time period (300 reboots or so).
> >>
> >> Interesting.
> >>
> >> Do you happen to know how many VMID bits the host has? If it has an 8-bit 
> >> VMID,
> >> this could be indicative of some problem upon overflow.
> > 
> > I'll let Tan Xiaojun (CC'd) answer this questions.
> > 
> >> Can you point us at the host kernel?
> > 
> > In the report, Tan Xiaojun wrote "4.18.0-48.el8.aarch64"; I guess that
> > information is mostly useless in an upstream discussion. Unfortunately,
> > I couldn't reproduce the symptom at all (I know nothing about the
> > hardware in question), so I can't myself retest with an upstream host
> > kernel.
> 
> I don't understand, what do you want me to do? What is the specific problem?

Could you let us know which CPU/system you've seen this issue with?

... and what the value of ID_AA64MMFR1_EL1.VMIDBits is?

Thanks,
Mark.
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH] ArmPkg: update InvalidateInstructionCacheRange to flush only to PoU

2019-01-28 Thread Laszlo Ersek
On 01/28/19 14:09, Tan Xiaojun wrote:
> On 2019/1/28 19:54, Laszlo Ersek wrote:
>> On 01/28/19 11:46, Mark Rutland wrote:
>>> On Wed, Jan 23, 2019 at 10:54:56AM +0100, Laszlo Ersek wrote:
 On 01/23/19 10:26, Ard Biesheuvel wrote:
> On Wed, 23 Jan 2019 at 10:14, Laszlo Ersek  wrote:
>> On 01/22/19 16:37, Ard Biesheuvel wrote:

>>> Is SetUefiImageMemoryAttributes() being
>>> called to remap the memory R-X ?
>>
>> No, it is not; the grub binary in question doesn't have the required
>> section alignment (... I hope at least that that's what your question
>> refers to):
>>
>>> ProtectUefiImageCommon - 0x3E6C54C0
>>>   - 0x00013BEEF000 - 0x00030600
>>>   ProtectUefiImageCommon - Section Alignment(0x200) is
>> incorrect  
>
> This is puzzling, given that the exact same binary works on Mustang.

 And even on the original (unspecified) hardware, the same binary works
 frequently. My understanding is that there are five VMs executing reboot
 loops in parallel, on the same host, and 4 out of 5 may hit the issue in
 a reasonable time period (300 reboots or so).
>>>
>>> Interesting.
>>>
>>> Do you happen to know how many VMID bits the host has? If it has an 8-bit 
>>> VMID,
>>> this could be indicative of some problem upon overflow.
>>
>> I'll let Tan Xiaojun (CC'd) answer this questions.
>>
>>> Can you point us at the host kernel?
>>
>> In the report, Tan Xiaojun wrote "4.18.0-48.el8.aarch64"; I guess that
>> information is mostly useless in an upstream discussion. Unfortunately,
>> I couldn't reproduce the symptom at all (I know nothing about the
>> hardware in question), so I can't myself retest with an upstream host
>> kernel.
>>
> 
> I don't understand, what do you want me to do? What is the specific problem?

Sorry, I was unclear. Primarily, please see Mark's explanation.

Secondarily, my point was that the upstream community could help more if
the symptom reproduced on a pristine upstream host kernel. Given that I
don't have access to your hardware that presents the symptom, plus that
the symptom doesn't reproduce on hardware that I do have access to,
using the downstream kernel that you reported, only you can attempt to
repro the issue with an upstream kernel (and then please report the
findings here).

Thanks,
Laszlo
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [Patch 00/33] BaseTools python3 migration patch set

2019-01-28 Thread Laszlo Ersek
Hi Bob,

On 01/28/19 11:35, Feng, Bob C wrote:
> Hi Laszlo,
> 
> I sent out 2 patches to fix this issue. And I also pushed the patches to the 
> repo https://github.com/BobCF/edk2.git branch py3basetools

I fetched your branch, and I found two new (fast-forward-able) commits:

$ git log --oneline --reverse 41c0616fc081..ec9e63692453

fb566a8835fa BaseTools: Fixed Eot python2 incompatible issue.
ec9e63692453 BaseTools: Fixed Ecc python2 incompatible issue.

However, the patches that you sent out:

[edk2] [Patch v2 32/33] BaseTools: ECC tool Python3 adaption
[edk2] [Patch v2 33/33] BaseTools: Eot tool Python3 adaption

appear different; I think you squashed the above incremental fixes into
the corresponding original (v1) patches. Is that correct?

I prefer to test a series in the same exact state as it would be
committed; otherwise there could be an issue with the rebase / squashing
(possibly further tweaks), and it wouldn't be correct to apply my
Tested-by to such a version.

In addition, you didn't post the updated (v2) patches #32 and #33 in
response to the v1 blurb:

  [edk2] [Patch 00/33] BaseTools python3 migration patch set

and as a result they will drift apart on the list, from each other and
also from the containing set.

In addition, it's a good practice to keep branches unchanged once
they've been posted to the list; further iterations should be named
py3basetools_v2, py3basetools_v3 etc. This lets people return to earlier
iterations, compare versions, associate branches with postings, and so on.

Assuming the v2 32/33, v2 33/33 on-list series is what I should test,
please push *precisely* that series to your repo, under branch name
"py3basetools_v2". I'd also suggest resetting branch "py3basetools" to
the original v1 posting status, that is, commit 41c0616fc081.

Thanks
Laszlo


> -Original Message-
> From: Feng, Bob C 
> Sent: Monday, January 28, 2019 10:33 AM
> To: 'Laszlo Ersek' 
> Cc: edk2-devel@lists.01.org; Gao, Liming 
> Subject: RE: [edk2] [Patch 00/33] BaseTools python3 migration patch set
> 
> Hi Laszlo,
> 
> Thanks for your testing and detailed testing result. I'll check the issue 
> happened in (a2) and provide a patch for it.
> 
> Thanks,
> Bob 
> 
> -Original Message-
> From: Laszlo Ersek [mailto:ler...@redhat.com]
> Sent: Saturday, January 26, 2019 2:18 AM
> To: Feng, Bob C 
> Cc: edk2-devel@lists.01.org; Gao, Liming 
> Subject: Re: [edk2] [Patch 00/33] BaseTools python3 migration patch set
> 
> On 01/25/19 10:42, Feng, Bob C wrote:
>> [...]
>>
>> -Original Message-
>> From: Laszlo Ersek [mailto:ler...@redhat.com]
>> Sent: Friday, January 25, 2019 4:57 PM
>> To: Feng, Bob C 
>> Cc: edk2-devel@lists.01.org; Gao, Liming 
>> Subject: Re: [edk2] [Patch 00/33] BaseTools python3 migration patch 
>> set
>>
>> [...]
>>
>> On 01/25/19 05:55, Feng, Bob C wrote:
>>> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=55
>>>
>>> This patch set is to enable python3 on BaseTools. Basetools code will 
>>> be compatible with both python3 and python2.
>>>
>>> We will have two envs PYTHON3_ENABLE and PYTHON_COMMAND. The behavior 
>>> can be combined as the below to support this usage.
>>> If user wants the specific python interpreter, he only needs to set 
>>> PYTHON_COMMAND env.
>>> If PYTHON3_ENABLE is set, PYTHON_COMMAND will be set to the found one 
>>> by edk2 scripts based on PYTHON3_ENABLE value.
>>> If PYTHON3_ENABLE is not set, but PYTHON_COMMAND is set, then 
>>> PYTHON_COMMAND will be used to run python script. No version check 
>>> here.
>>> If PYTHON3_ENABLE is not set, but PYTHON_COMMAND is not set, 
>>> PYTHON_COMMAND will be set to the high version python installed in 
>>> OS.
> 
> I ran the following tests, at commit 41c0616fc081 ("BaseTools: Eot tool
> Python3 adaption", 2019-01-25). Each test was performed in a clean tree 
> (after running "git clean -ffdx") and clean environment (I re-sourced 
> "edksetup.sh" for each test in separation). In addition, the base tools were 
> rebuilt (again from a clean tree) for each test, with the following command 
> [1]:
> 
>   nice make -C "$EDK_TOOLS_PATH" -j $(getconf _NPROCESSORS_ONLN)
> 
> (a) On my RHEL7.5 Workstation laptop, I have both the system-level python 
> packages installed (python-2.7.5-69.el7_5.x86_64), and the extra
> python-3.4 stuff from EPEL-7 (python34-3.4.9-1.el7.x86_64).
> 
> (a1) Didn't set either PYTHON3_ENABLE or PYTHON_COMMAND. The build utility 
> picked
> 
>   PYTHON_COMMAND   = /usr/bin/python3.4
> 
> and I successfully built OvmfPkg for IA32, IA32X64, and X64; also ArmVirtQemu 
> for AARCH64. The built firmware images passed a smoke test too.
> 
> (a2) I removed all the python34 packages (and the dependent packages) from my 
> laptop. Didn't set either of PYTHON3_ENABLE and PYTHON_COMMAND.
> (This is the configuration what a "normal" RHEL7 environment would
> provide.)
> 
> In this case, rebuilding the base tools [1] failed, in the testing
> phase:
> 
>> ===

Re: [edk2] [patch] ShellPkg/UefiShellAcpiViewCommandLib: Fix VS tool chain build failure

2019-01-28 Thread Carsey, Jaben
Reviewed-by: Jaben Carsey 

> -Original Message-
> From: Bi, Dandan
> Sent: Sunday, January 27, 2019 7:29 PM
> To: edk2-devel@lists.01.org
> Cc: Krzysztof Koch ; Carsey, Jaben
> ; Ni, Ray 
> Subject: [patch] ShellPkg/UefiShellAcpiViewCommandLib: Fix VS tool chain
> build failure
> Importance: High
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1491
> 
> This patch is to update the data type of variable "Offset"
> from UINT8 to UINT32 to fix following build issue.
> 
> ...\Parsers\Pptt\PpttParser.c(193): error C2220:
> warning treated as error - no 'object' file generated
> ...\Parsers\Pptt\PpttParser.c(193): warning C4244: '=':
> conversion from 'UINT32' to 'UINT8', possible loss of data
> 
> Cc: Krzysztof Koch 
> Cc: Jaben Carsey 
> Cc: Ray Ni 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Dandan Bi 
> ---
>  .../UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c   | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git
> a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.
> c
> b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.
> c
> index d97ddf8e92..bc56fe9ea1 100644
> ---
> a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.
> c
> +++
> b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.
> c
> @@ -176,11 +176,11 @@ VOID
>  DumpProcessorHierarchyNodeStructure (
>IN UINT8* Ptr,
>IN UINT8  Length
>)
>  {
> -  UINT8  Offset;
> +  UINT32 Offset;
>UINT8* PrivateResourcePtr;
>UINT32 Index;
>CHAR16 Buffer[OUTPUT_FIELD_COLUMN_WIDTH];
> 
>Offset = ParseAcpi (
> --
> 2.18.0.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH v3 edk2-platforms 03/23] Platform/Raspberry/Pi3: Add ACPI tables

2019-01-28 Thread Ard Biesheuvel
Hi Pete,

A couple of general remarks on these tables.

- AFAICT (but is is difficult to tell from the binary dumps), these
are based on ACPI 5.0, which predates the introduction of ARM support
into the spec. That essentially makes them Windows-only, and not spec
based, which is unfortunate. However, since this SoC does not have an
interrupt controller permitted by ACPI, that actually does not matter
a lot in practice.
- _CID fields should be properly formatted ACPI or PNP handles, you
can't put arbitrary strings in there (like BCMAUXSPI or VC4)



On Mon, 28 Jan 2019 at 13:45, Pete Batard  wrote:
>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Pete Batard 
> ---
>  Platform/Raspberry/Pi3/AcpiTables/AcpiTables.h   |  82 
>  Platform/Raspberry/Pi3/AcpiTables/AcpiTables.inf |  51 ++
>  Platform/Raspberry/Pi3/AcpiTables/Csrt.aslc  | 332 +
>  Platform/Raspberry/Pi3/AcpiTables/Dbg2.aslc  |  34 ++
>  Platform/Raspberry/Pi3/AcpiTables/Dsdt.asl   | 511 
>  Platform/Raspberry/Pi3/AcpiTables/Fadt.aslc  |  52 ++
>  Platform/Raspberry/Pi3/AcpiTables/Gtdt.aslc  |  33 ++
>  Platform/Raspberry/Pi3/AcpiTables/Madt.aslc  |  62 +++
>  Platform/Raspberry/Pi3/AcpiTables/Pep.asl|  95 
>  Platform/Raspberry/Pi3/AcpiTables/Pep.c  |  84 
>  Platform/Raspberry/Pi3/AcpiTables/Pep.h  | 126 +
>  Platform/Raspberry/Pi3/AcpiTables/Rhpx.asl   | 201 
>  Platform/Raspberry/Pi3/AcpiTables/Sdhc.asl   | 105 
>  Platform/Raspberry/Pi3/AcpiTables/Spcr.asl   |  53 ++
>  Platform/Raspberry/Pi3/AcpiTables/Uart.asl   | 158 ++
>  15 files changed, 1979 insertions(+)
>
> diff --git a/Platform/Raspberry/Pi3/AcpiTables/AcpiTables.h 
> b/Platform/Raspberry/Pi3/AcpiTables/AcpiTables.h
> new file mode 100644
> index ..be28b6decefd
> --- /dev/null
> +++ b/Platform/Raspberry/Pi3/AcpiTables/AcpiTables.h
> @@ -0,0 +1,82 @@
> +/** @file
> + *
> + *  RPi3 defines for constructing ACPI tables
> + *
> + *  Copyright (c) 2018, Andrei Warkentin 
> + *  Copyright (c) Microsoft Corporation. All rights reserved.
> + *
> + *  This program and the accompanying materials
> + *  are licensed and made available under the terms and conditions of the 
> BSD License
> + *  which accompanies this distribution.  The full text of the license may 
> be found at
> + *  http://opensource.org/licenses/bsd-license.php
> + *
> + *  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> + *  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
> IMPLIED.
> + *
> + **/
> +
> +#ifndef __ACPITABLES_H__
> +#define __ACPITABLES_H__
> +
> +#include 
> +
> +#define EFI_ACPI_OEM_ID   {'M','C','R','S','F','T'} // 
> OEMID 6 bytes long
> +#define EFI_ACPI_OEM_TABLE_ID SIGNATURE_64 
> ('R','P','I','3','E','D','K','2') // OEM table id 8 bytes long
> +#define EFI_ACPI_OEM_REVISION 0x02000820
> +#define EFI_ACPI_CREATOR_ID   SIGNATURE_32 ('R','P','I','3')
> +#define EFI_ACPI_CREATOR_REVISION 0x0097
> +
> +#define EFI_ACPI_VENDOR_IDSIGNATURE_32 ('M','S','F','T')
> +#define EFI_ACPI_CSRT_REVISION0x0005
> +#define EFI_ACPI_CSRT_DEVICE_ID_DMA   0x0009 // Fixed id
> +#define EFI_ACPI_CSRT_RESOURCE_ID_IN_DMA_GRP  0x0 // Count up from 0
> +
> +#define RPI3_DMA_CHANNEL_COUNT10 // All 10 DMA channels are 
> listed, including the reserved ones
> +#define RPI3_DMA_USED_CHANNEL_COUNT   5  // Use 5 DMA channels
> +
> +#define EFI_ACPI_5_0_CSRT_REVISION0x
> +
> +typedef enum
> +{
> +  EFI_ACPI_CSRT_RESOURCE_TYPE_RESERVED,   // 0
> +  EFI_ACPI_CSRT_RESOURCE_TYPE_INTERRUPT,  // 1
> +  EFI_ACPI_CSRT_RESOURCE_TYPE_TIMER,  // 2
> +  EFI_ACPI_CSRT_RESOURCE_TYPE_DMA,// 3
> +  EFI_ACPI_CSRT_RESOURCE_TYPE_CACHE,  // 4
> +}
> +CSRT_RESOURCE_TYPE;
> +
> +typedef enum
> +{
> +  EFI_ACPI_CSRT_RESOURCE_SUBTYPE_DMA_CHANNEL, // 0
> +  EFI_ACPI_CSRT_RESOURCE_SUBTYPE_DMA_CONTROLLER   // 1
> +}
> +CSRT_DMA_SUBTYPE;
> +
> +//
> +// CSRT Resource Group header 24 bytes long
> +//
> +typedef struct
> +{
> +  UINT32 Length;  // Length
> +  UINT32 VendorID;// 4 bytes
> +  UINT32 SubVendorId; // 4 bytes
> +  UINT16 DeviceId;// 2 bytes
> +  UINT16 SubdeviceId; // 2 bytes
> +  UINT16 Revision;// 2 bytes
> +  UINT16 Reserved;// 2 bytes
> +  UINT32 SharedInfoLength;// 4 bytes
> +} EFI_ACPI_5_0_CSRT_RESOURCE_GROUP_HEADER;
> +
> +//
> +// CSRT Resource Descriptor 12 bytes total
> +//

Re: [edk2] [PATCH v3 edk2-platforms 19/23] Platform/Raspberry/Pi3: Add platform

2019-01-28 Thread Ard Biesheuvel
On Mon, 28 Jan 2019 at 13:45, Pete Batard  wrote:
>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Pete Batard 
> ---
>  Platform/Raspberry/Pi3/RPi3.dec |  60 ++
>  Platform/Raspberry/Pi3/RPi3.dsc | 637 
>  Platform/Raspberry/Pi3/RPi3.fdf | 449 ++
>  3 files changed, 1146 insertions(+)
>
> diff --git a/Platform/Raspberry/Pi3/RPi3.dec b/Platform/Raspberry/Pi3/RPi3.dec
> new file mode 100644
> index ..d65a4adc8eeb
> --- /dev/null
> +++ b/Platform/Raspberry/Pi3/RPi3.dec
> @@ -0,0 +1,60 @@
> +## @file
> +#
> +#  Copyright (c) 2016, Linaro, Ltd. All rights reserved.
> +#  Copyright (c) 2017-2018, Andrei Warkentin 
> +#
> +#  This program and the accompanying materials are licensed and made 
> available
> +#  under the terms and conditions of the BSD License which accompanies this
> +#  distribution. The full text of the license may be found at
> +#  http://opensource.org/licenses/bsd-license.php
> +#
> +#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR
> +#  IMPLIED.
> +#
> +##
> +
> +[Defines]
> +  DEC_SPECIFICATION  = 0x0001001A
> +  PACKAGE_NAME   = RPi3Pkg
> +  PACKAGE_GUID   = DFA0CA8B-F3AC-4607-96AC-46FA04B84DCC
> +  PACKAGE_VERSION= 1.0
> +
> +[Includes]
> +  Include
> +  Silicon/Broadcom/Include
> +

Please drop this include. If doing so breaks anything, the affected
modules are missing a reference to the Bcm283x package

> +[Protocols]
> +  gRaspberryPiFirmwareProtocolGuid = { 0x0ACA9535, 0x7AD0, 0x4286, { 0xB0, 
> 0x2E, 0x87, 0xFA, 0x7E, 0x2A, 0x57, 0x11 } }
> +  gRaspberryPiConfigAppliedProtocolGuid = { 0x0ACA, 0x7AD0, 0x4286, { 
> 0xB0, 0x2E, 0x87, 0xFA, 0x7E, 0x2A, 0x57, 0x11 } }
> +  gRaspberryPiMmcHostProtocolGuid = { 0x3e591c00, 0x9e4a, 0x11df, {0x92, 
> 0x44, 0x00, 0x02, 0xA5, 0xF5, 0xF5, 0x1B } }
> +  gExtendedTextOutputProtocolGuid = { 0x387477ff, 0xffc7, 0xffd2, {0x8e, 
> 0x39, 0x0, 0xff, 0xc9, 0x69, 0x72, 0x3b } }
> +
> +[Guids]
> +  gRaspberryPiTokenSpaceGuid = {0xCD7CC258, 0x31DB, 0x11E6, {0x9F, 0xD3, 
> 0x63, 0xB0, 0xB8, 0xEE, 0xD6, 0xB5}}
> +  gRaspberryPiFdtFileGuid = {0xDF5DA223, 0x1D27, 0x47C3, { 0x8D, 0x1B, 0x9A, 
> 0x41, 0xB5, 0x5A, 0x18, 0xBC}}
> +  gRaspberryPiEventResetGuid = {0xCD7CC258, 0x31DB, 0x11E6, {0x9F, 0xD3, 
> 0x63, 0xB4, 0xB4, 0xE4, 0xD4, 0xB4}}
> +  gConfigDxeFormSetGuid = {0xCD7CC258, 0x31DB, 0x22E6, {0x9F, 0x22, 0x63, 
> 0xB0, 0xB8, 0xEE, 0xD6, 0xB5}}
> +
> +[PcdsFixedAtBuild.common]
> +  gRaspberryPiTokenSpaceGuid.PcdFdtBaseAddress|0x1|UINT32|0x0001
> +  gRaspberryPiTokenSpaceGuid.PcdFirmwareBlockSize|0x0|UINT32|0x0002
> +  gRaspberryPiTokenSpaceGuid.PcdNvStorageEventLogBase|0x0|UINT32|0x0003
> +  gRaspberryPiTokenSpaceGuid.PcdNvStorageEventLogSize|0x0|UINT32|0x0004
> +  gRaspberryPiTokenSpaceGuid.PcdNvStorageVariableBase|0x0|UINT32|0x0005
> +  gRaspberryPiTokenSpaceGuid.PcdNvStorageFtwSpareBase|0x0|UINT32|0x0006
> +  gRaspberryPiTokenSpaceGuid.PcdNvStorageFtwWorkingBase|0x0|UINT32|0x0007
> +  gRaspberryPiTokenSpaceGuid.PcdBootEpochSeconds|0x0|UINT64|0x0008
> +
> +[PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx]
> +  gRaspberryPiTokenSpaceGuid.PcdCpuClock|0|UINT32|0x000d
> +  gRaspberryPiTokenSpaceGuid.PcdSdIsArasan|0|UINT32|0x000e
> +  gRaspberryPiTokenSpaceGuid.PcdMmcForce1Bit|0|UINT32|0x000f
> +  gRaspberryPiTokenSpaceGuid.PcdMmcForceDefaultSpeed|0|UINT32|0x0010
> +  gRaspberryPiTokenSpaceGuid.PcdMmcSdDefaultSpeedMHz|0|UINT32|0x0011
> +  gRaspberryPiTokenSpaceGuid.PcdMmcSdHighSpeedMHz|0|UINT32|0x0012
> +  gRaspberryPiTokenSpaceGuid.PcdMmcDisableMulti|0|UINT32|0x0013
> +  gRaspberryPiTokenSpaceGuid.PcdDebugEnableJTAG|0|UINT32|0x0014
> +  gRaspberryPiTokenSpaceGuid.PcdDebugShowUEFIExit|0|UINT32|0x0015
> +  gRaspberryPiTokenSpaceGuid.PcdDisplayEnableVModes|0|UINT32|0x0017
> +  gRaspberryPiTokenSpaceGuid.PcdDisplayEnableSShot|0|UINT32|0x0018
> diff --git a/Platform/Raspberry/Pi3/RPi3.dsc b/Platform/Raspberry/Pi3/RPi3.dsc
> new file mode 100644
> index ..effe9d243209
> --- /dev/null
> +++ b/Platform/Raspberry/Pi3/RPi3.dsc
> @@ -0,0 +1,637 @@
> +# @file
> +#
> +#  Copyright (c) 2011-2015, ARM Limited. All rights reserved.
> +#  Copyright (c) 2014, Linaro Limited. All rights reserved.
> +#  Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
> +#  Copyright (c) 2017 - 2018, Andrei Warkentin 
> +#
> +#  This program and the accompanying materials are licensed and made 
> available
> +#  under the terms and conditions of the BSD License which accompanies this
> +#  distribution. The full text of the license may be found at
> +#  http://opensource.org/licenses/bsd-license.php
> +#
> +#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITH

Re: [edk2] [PATCH v3 edk2-platforms 01/23] Silicon/Broadcom/Bcm282x: Add interrupt driver

2019-01-28 Thread Ard Biesheuvel
Hi Pete,

On Mon, 28 Jan 2019 at 13:44, Pete Batard  wrote:
>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Pete Batard 
> ---
>  Silicon/Broadcom/Bcm283x/Bcm283x.dec   |  23 ++
>  Silicon/Broadcom/Bcm283x/Drivers/InterruptDxe/InterruptDxe.c   | 367 
> 
>  Silicon/Broadcom/Bcm283x/Drivers/InterruptDxe/InterruptDxe.inf |  48 +++
>  Silicon/Broadcom/Include/IndustryStandard/Bcm2836.h|  72 
>  4 files changed, 510 insertions(+)
>
> diff --git a/Silicon/Broadcom/Bcm283x/Bcm283x.dec 
> b/Silicon/Broadcom/Bcm283x/Bcm283x.dec
> new file mode 100644
> index ..8ead5ca87f5d
> --- /dev/null
> +++ b/Silicon/Broadcom/Bcm283x/Bcm283x.dec
> @@ -0,0 +1,23 @@
> +## @file
> +#
> +#  Copyright (c) 2019, Pete Batard 
> +#
> +#  This program and the accompanying materials are licensed and made 
> available
> +#  under the terms and conditions of the BSD License which accompanies this
> +#  distribution. The full text of the license may be found at
> +#  http://opensource.org/licenses/bsd-license.php
> +#
> +#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR
> +#  IMPLIED.
> +#
> +##
> +
> +[Defines]
> +  DEC_SPECIFICATION  = 0x0001001A
> +  PACKAGE_NAME   = Bcm283xPkg

Please remove the 'Pkg'

> +  PACKAGE_GUID   = 900C0F44-1152-4FF9-B9C5-933E2918C831
> +  PACKAGE_VERSION= 1.0
> +
> +[Includes]
> +  Silicon/Broadcom/Include

Please change this to 'Include', and move whatever resides in
Silicon/Broadcom/Include to Silicon/Broadcom/Bcm283x/Include
This ensures that the package itself does not depend on the directory
structure of the repository it resides in.

With that,

Reviewed-by: Ard Biesheuvel 

> diff --git a/Silicon/Broadcom/Bcm283x/Drivers/InterruptDxe/InterruptDxe.c 
> b/Silicon/Broadcom/Bcm283x/Drivers/InterruptDxe/InterruptDxe.c
> new file mode 100644
> index ..9058aa94ffb9
> --- /dev/null
> +++ b/Silicon/Broadcom/Bcm283x/Drivers/InterruptDxe/InterruptDxe.c
> @@ -0,0 +1,367 @@
> +/** @file
> + *
> + *  Copyright (c) 2016, Linaro, Ltd. All rights reserved.
> + *
> + *  This program and the accompanying materials
> + *  are licensed and made available under the terms and conditions of the 
> BSD License
> + *  which accompanies this distribution.  The full text of the license may 
> be found at
> + *  http://opensource.org/licenses/bsd-license.php
> + *
> + *  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> + *  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
> IMPLIED.
> + *
> + **/
> +
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +
> +#include 
> +#include 
> +
> +//
> +// This currently only implements support for the architected timer 
> interrupts
> +// on the per-CPU interrupt controllers.
> +//
> +#define NUM_IRQS(4)
> +
> +#ifdef MDE_CPU_AARCH64
> +#define ARM_ARCH_EXCEPTION_IRQ  EXCEPT_AARCH64_IRQ
> +#else
> +#define ARM_ARCH_EXCEPTION_IRQ  EXCEPT_ARM_IRQ
> +#endif
> +
> +STATIC CONST
> +EFI_PHYSICAL_ADDRESS RegBase = FixedPcdGet32 (PcdInterruptBaseAddress);
> +
> +//
> +// Notifications
> +//
> +STATIC EFI_EVENTmExitBootServicesEvent;
> +STATIC HARDWARE_INTERRUPT_HANDLER   mRegisteredInterruptHandlers[NUM_IRQS];
> +
> +/**
> +  Shutdown our hardware
> +
> +  DXE Core will disable interrupts and turn off the timer and disable 
> interrupts
> +  after all the event handlers have run.
> +
> +  @param[in]  Event   The Event that is being processed
> +  @param[in]  Context Event Context
> +**/
> +STATIC
> +VOID
> +EFIAPI
> +ExitBootServicesEvent (
> +  IN EFI_EVENT  Event,
> +  IN VOID   *Context
> +  )
> +{
> +  // Disable all interrupts
> +  MmioWrite32 (RegBase + BCM2836_INTC_TIMER_CONTROL_OFFSET, 0);
> +}
> +
> +/**
> +  Enable interrupt source Source.
> +
> +  @param This Instance pointer for this protocol
> +  @param Source   Hardware source of the interrupt
> +
> +  @retval EFI_SUCCESS   Source interrupt enabled.
> +  @retval EFI_DEVICE_ERROR  Hardware could not be programmed.
> +
> +**/
> +STATIC
> +EFI_STATUS
> +EFIAPI
> +EnableInterruptSource (
> +  IN EFI_HARDWARE_INTERRUPT_PROTOCOL*This,
> +  IN HARDWARE_INTERRUPT_SOURCE  Source
> +  )
> +{
> +  if (Source >= NUM_IRQS) {
> +ASSERT (FALSE);
> +return EFI_UNSUPPORTED;
> +  }
> +
> +  MmioOr32 (RegBase + BCM2836_INTC_TIMER_CONTROL_OFFSET, 1 << Source);
> +
> +  return EFI_SUCCESS;
> +}
> +
> +
> +/**
> +  Disable interrupt source Source.
> +
> +  @param This Instance pointer for this protocol
> +  @param Source   Hardware source of the interrupt
> +
> +  @retval EFI_SUCCESS   Source interrupt disabled.
> +  @retval EFI_DEVICE_ERROR  Hardware could not be programmed.
> +
> +**/
> +STATIC
> +EFI_STATUS
> +E

Re: [edk2] [PATCH v3 edk2-platforms 02/23] Silicon/Broadcom/Bcm283x: Add GpioLib

2019-01-28 Thread Ard Biesheuvel
On Mon, 28 Jan 2019 at 13:45, Pete Batard  wrote:
>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Pete Batard 
> ---
>  Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.c  | 88 
> 
>  Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.inf| 39 +
>  Silicon/Broadcom/Include/IndustryStandard/Bcm2836Gpio.h | 60 +
>  3 files changed, 187 insertions(+)
>
> diff --git a/Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.c 
> b/Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.c
> new file mode 100644
> index ..eb6accafb01e
> --- /dev/null
> +++ b/Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.c
> @@ -0,0 +1,88 @@
> +/** @file
> + *
> + *  GPIO manipulation.
> + *
> + *  Copyright (c) 2018, Andrei Warkentin 
> + *
> + *  This program and the accompanying materials
> + *  are licensed and made available under the terms and conditions of the 
> BSD License
> + *  which accompanies this distribution.  The full text of the license may 
> be found at
> + *  http://opensource.org/licenses/bsd-license.php
> + *
> + *  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> + *  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
> IMPLIED.
> + *
> + **/
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +STATIC
> +VOID
> +GpioFSELModify (
> +  IN  UINTN RegIndex,
> +  IN  UINT32 ModifyMask,
> +  IN  UINT32 FunctionMask
> +  )
> +{
> +  UINT32 Val;
> +  EFI_PHYSICAL_ADDRESS Reg;
> +
> +  Reg = RegIndex * sizeof (UINT32) + GPIO_GPFSEL0;
> +
> +  ASSERT (Reg <= GPIO_GPFSEL5);
> +  ASSERT ((~ModifyMask & FunctionMask) == 0);
> +
> +  Val = MmioRead32 (Reg);
> +  Val &= ~ModifyMask;
> +  Val |= FunctionMask;
> +  MmioWrite32 (Reg, Val);
> +}
> +
> +VOID
> +GpioPinFuncSet (
> +  IN  UINTN Pin,
> +  IN  UINTN Function
> +  )
> +{
> +  UINTN RegIndex;
> +  UINTN SelIndex;
> +  UINT32 ModifyMask;
> +  UINT32 FunctionMask;
> +
> +  ASSERT (Pin < GPIO_PINS);
> +  ASSERT (Function <= GPIO_FSEL_MASK);
> +
> +  RegIndex = Pin / 10;
> +  SelIndex = Pin % 10;
> +
> +  ModifyMask = GPIO_FSEL_MASK << (SelIndex * GPIO_FSEL_BITS_PER_PIN);
> +  FunctionMask = Function << (SelIndex * GPIO_FSEL_BITS_PER_PIN);
> +  GpioFSELModify (RegIndex, ModifyMask, FunctionMask);
> +}
> +
> +UINTN
> +GpioPinFuncGet (
> +  IN  UINTN Pin
> +  )
> +{
> +  UINT32 Val;
> +  UINTN RegIndex;
> +  UINTN SelIndex;
> +  EFI_PHYSICAL_ADDRESS Reg;
> +
> +  ASSERT (Pin < GPIO_PINS);
> +
> +  RegIndex = Pin / 10;
> +  SelIndex = Pin % 10;
> +  Reg = RegIndex * sizeof (UINT32) + GPIO_GPFSEL0;
> +
> +  Val = MmioRead32 (Reg);
> +  Val >>= SelIndex * GPIO_FSEL_BITS_PER_PIN;
> +  Val &= GPIO_FSEL_MASK;
> +  return Val;
> +}
> diff --git a/Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.inf 
> b/Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.inf
> new file mode 100644
> index ..68ebe44e3d1c
> --- /dev/null
> +++ b/Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.inf
> @@ -0,0 +1,39 @@
> +#/** @file
> +#
> +#  Manipulate GPIOs.
> +#
> +#  Copyright (c) 2018, Andrei Warkentin 
> +#
> +#  This program and the accompanying materials
> +#  are licensed and made available under the terms and conditions of the BSD 
> License
> +#  which accompanies this distribution.  The full text of the license may be 
> found at
> +#  http://opensource.org/licenses/bsd-license.php
> +#
> +#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
> IMPLIED.
> +#
> +#**/
> +
> +[Defines]
> +  INF_VERSION= 0x0001001A
> +  BASE_NAME  = GpioLib
> +  FILE_GUID  = B9F59B6B-B105-41C7-8F5A-2C60DD7FD7AB
> +  MODULE_TYPE= BASE
> +  VERSION_STRING = 1.0
> +  LIBRARY_CLASS  = GpioLib
> +
> +[Sources]
> +  GpioLib.c
> +
> +[Packages]
> +  ArmPkg/ArmPkg.dec
> +  MdePkg/MdePkg.dec
> +  EmbeddedPkg/EmbeddedPkg.dec
> +  Silicon/Broadcom/Bcm283x/Bcm283x.dec
> +
> +[LibraryClasses]
> +  BaseLib
> +  DebugLib
> +  IoLib
> +
> +[Guids]
> diff --git a/Silicon/Broadcom/Include/IndustryStandard/Bcm2836Gpio.h 
> b/Silicon/Broadcom/Include/IndustryStandard/Bcm2836Gpio.h

Please move this header to Silicon/Broadcom/Bcm283x/...

> new file mode 100644
> index ..45774b639ca8
> --- /dev/null
> +++ b/Silicon/Broadcom/Include/IndustryStandard/Bcm2836Gpio.h
> @@ -0,0 +1,60 @@
> +/** @file
> + *
> + *  Copyright (c) 2018, Andrei Warkentin 
> + *  Copyright (c) Microsoft Corporation. All rights reserved.
> + *
> + *  This program and the accompanying materials
> + *  are licensed and made available under the terms and conditions of the 
> BSD License
> + *  which accompanies this distribution.  The full text of the license may 
> be found at
> + *  http://opensource.org/licenses/bsd-license.php
> + *
> + *  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICE

[edk2] [PATCH v3 edk2-platforms 2/23] Platform/Raspberry/Pi3 *NON-OSI*: Add Device Tree binaries

2019-01-28 Thread Pete Batard
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Pete Batard 
---
 Platform/Raspberry/Pi3/DeviceTree/License.txt  |  340 ++
 Platform/Raspberry/Pi3/DeviceTree/bcm2710-rpi-3-b-plus.dtb |  Bin 0 -> 25617 
bytes
 Platform/Raspberry/Pi3/DeviceTree/bcm2710-rpi-3-b-plus.dts | 1263 

 Platform/Raspberry/Pi3/DeviceTree/bcm2710-rpi-3-b.dtb  |  Bin 0 -> 25354 
bytes
 Platform/Raspberry/Pi3/DeviceTree/bcm2710-rpi-3-b.dts  | 1259 
+++
 5 files changed, 2862 insertions(+)

diff --git a/Platform/Raspberry/Pi3/DeviceTree/License.txt 
b/Platform/Raspberry/Pi3/DeviceTree/License.txt
new file mode 100644
index ..1603937dad82
--- /dev/null
+++ b/Platform/Raspberry/Pi3/DeviceTree/License.txt
@@ -0,0 +1,340 @@
+GNU GENERAL PUBLIC LICENSE
+   Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+   51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.  This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it.  (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.)  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have.  You must make sure that they, too, receive or can get the
+source code.  And you must show them these terms so they know their
+rights.
+
+  We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+  Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software.  If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary.  To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+GNU GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License.  The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language.  (Hereinafter, translation is included without limitation in
+the term "modification".)  Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+  1. You may copy and distribute verbatim copies of the Program's
+source code as you rece

[edk2] [PATCH v3 edk2-platforms 21/23] Platform/Raspberry/Pi3 *NON-OSI*: Add ATF binaries

2019-01-28 Thread Pete Batard
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Pete Batard 
---
 Platform/Raspberry/Pi3/TrustedFirmware/License.txt |  26 
 Platform/Raspberry/Pi3/TrustedFirmware/README.md   |  42 
 Platform/Raspberry/Pi3/TrustedFirmware/bl1.bin | Bin 0 -> 18801 bytes
 Platform/Raspberry/Pi3/TrustedFirmware/fip.bin | Bin 0 -> 41714 bytes
 4 files changed, 68 insertions(+)

diff --git a/Platform/Raspberry/Pi3/TrustedFirmware/License.txt 
b/Platform/Raspberry/Pi3/TrustedFirmware/License.txt
new file mode 100644
index ..b98dc643227e
--- /dev/null
+++ b/Platform/Raspberry/Pi3/TrustedFirmware/License.txt
@@ -0,0 +1,26 @@
+Copyright (c) 2013-2018, ARM Limited and Contributors. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without 
modification,
+are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+  list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright notice, 
this
+  list of conditions and the following disclaimer in the documentation and/or
+  other materials provided with the distribution.
+
+* Neither the name of ARM nor the names of its contributors may be used to
+  endorse or promote products derived from this software without specific prior
+  written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 
FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/Platform/Raspberry/Pi3/TrustedFirmware/README.md 
b/Platform/Raspberry/Pi3/TrustedFirmware/README.md
new file mode 100644
index ..862933f6f2ba
--- /dev/null
+++ b/Platform/Raspberry/Pi3/TrustedFirmware/README.md
@@ -0,0 +1,42 @@
+ARM Trusted Firmware for Raspberry Pi 3
+===
+
+The `bl1` and `fip` ATF binaries, found in this directory, were built from
+the [latest ATF](https://github.com/ARM-software/arm-trusted-firmware)
+(commit c3859557) using Linaro's GCC 5.5 compiler with:
+
+```
+export 
CROSS_COMPILE=/usr/src/gcc-linaro-5.5.0-2017.10-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
+make PLAT=rpi3 PRELOADED_BL33_BASE=0x3 RPI3_PRELOADED_DTB_BASE=0x1 
SUPPORT_VFP=1 RPI3_USE_UEFI_MAP=1 fip all
+```
+
+This results in the following memory mapping:
+
+```
+0x +-+
+   |   ROM   | BL1
+0x0001 +-+
+   |   DTB   | (Loaded by the VideoCore)
+0x0002 +-+
+   |   FIP   |
+0x0003 +-+
+   | |
+   |  UEFI PAYLOAD   |
+   | |
+0x0020 +-+
+   |   Secure SRAM   | BL2, BL31
+0x0030 +-+
+   |   Secure DRAM   | BL32 (Secure payload)
+0x0040 +-+
+   | |
+   | |
+   | Non-secure DRAM | BL33
+   | |
+   | |
+0x0100 +-+
+   | |
+   |   ...   |
+   | |
+0x3F00 +-+
+   |   I/O   |
+```
diff --git a/Platform/Raspberry/Pi3/TrustedFirmware/bl1.bin 
b/Platform/Raspberry/Pi3/TrustedFirmware/bl1.bin
new file mode 100644
index 
..e25138828d0a4ddb24772abb1a60eefc334666b5
GIT binary patch
literal 18801
zcmeHud2|%#mG7;pmedFVtpy|tJ-S*z4DF582<)+{TLO%YF^IMyw%@2*ivhC;Enpe2
zRTADp&Ya2NoOkF$@l}1x-M+hhw@Q@U820D96C>N0$f-gpvNVO-6r%k^_LFjhV53f>
zzYYB^p(#wZhayBm(40?m)v%ZRF-jkU{?@RJdpUDVq_0@Qvl>>=KM8BSMAN6D9c2X^
zv}!gTC9-IZXdThl_aE5oz6A)Ol0}J=O^M4yanPmrUEBE6z%_}qi$f`XQKFzu
zlVZ_?G$rnX41{DgYzORyWMj?6p-TMP#*g+gylWdj3`8X%sIOlv1lmB)R$NV@Mf2q+
zY4d>}JWrcSYDNxGR%4SA-?^DI?>kETG0>;<^-cF@D)C*r!0X4PiJ}^Q9sQugsR%T^
zW2zF8L8m(ZKusahN`})&mx1t%~~5>0PQR^krEJ6wr3iAo6aZSmWc_!Ag6
z`56X&xUWmf4DJH$r=?NBrxUaj_-e#D|7a!d7m4LPR23=2^S_NbBGxi5Ce4?hcK6f$
z3TXVu>I#)XZeBsnU^%~vzTYcJS`*qLzY-q@C2Lj%?d)EP7gLhfKy+cZh2moYa~$X{
zx3%XUwhAHXdf#-#Z|vK6?76XLKQ{Io`^9@z>$YethdSW8QZ5C&;8{(g13fpB7t2Z#
zv}wTee+aU&&~*P;CC>ZC@)`!-q9RS70s5}E1#N

[edk2] [PATCH v3 edk2-platforms 20/23] Platform/Raspberry/Pi3: Add platform readme

2019-01-28 Thread Pete Batard
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Pete Batard 
---
 Platform/Raspberry/Pi3/Readme.md | 259 
 Readme.md|   3 +
 2 files changed, 262 insertions(+)

diff --git a/Platform/Raspberry/Pi3/Readme.md b/Platform/Raspberry/Pi3/Readme.md
new file mode 100644
index ..7fb59ccdc321
--- /dev/null
+++ b/Platform/Raspberry/Pi3/Readme.md
@@ -0,0 +1,259 @@
+Raspberry Pi 3 EDK2 Platform Support
+
+
+# Summary
+
+This is a port of 64-bit Tiano Core UEFI firmware for the Raspberry Pi 3/3B+ 
platforms,
+based on [Ard Bisheuvel's 
64-bit](http://www.workofard.com/2017/02/uefi-on-the-pi/)
+and [Microsoft's 
32-bit](https://github.com/ms-iot/RPi-UEFI/tree/ms-iot/Pi3BoardPkg)
+implementations, as maintained by [Andrei 
Warkentin](https://github.com/andreiw/RaspberryPiPkg).
+
+This is meant as a generally useful 64-bit ATF + UEFI implementation for the 
Raspberry
+Pi 3/3B+ which should be good enough for most kind of UEFI development, as 
well as for
+running consummer Operating Systems in such as Linux or Windows.
+
+Raspberry Pi is a trademark of the [Raspberry Pi 
Foundation](http://www.raspberrypi.org).
+
+# Status
+
+This firmware, that has been validated to compile against the current
+[edk2](https://github.com/tianocore/edk2)/[edk2-platforms](https://github.com/tianocore/edk2-platforms),
+should be able to boot Linux (SUSE, Ubuntu), NetBSD, FreeBSD as well as 
Windows 10 ARM64
+(full GUI version).
+
+It also provides support for ATF ([Arm Trusted 
Platform](https://github.com/ARM-software/arm-trusted-firmware)).
+
+HDMI and the mini-UART serial port can be used for output devices, with 
mirrored output.
+USB keyboards and the mini-UART serial port can be used as input.
+
+The boot order is currently hardcoded, first to the USB ports and then to the 
uSD card.
+If there no bootable media media is found, the UEFI Shell is launched.
+Esc enters platform setup. F1 boots the UEFI Shell.
+
+# Building
+
+(These instructions were validated against the latest edk2 / edk2-platforms /
+edk2-non-osi as of 2019.01.27, on a Debian 9.6 x64 system).
+
+You may need to install the relevant compilation tools. Especially you should 
have the
+ACPI Source Language (ASL) compiler, `nasm` as well as a native compiler 
installed.
+On a Debian system, you can get these prerequisites installed with:
+```
+sudo apt-get install build-essential acpica-tools nasm uuid-dev
+```
+
+**IMPORTANT:** We recommend the use of the Linaro GCC for compilation instead 
of
+your system's native ARM64 GCC cross compiler.
+
+You can then build the firmware as follows:
+
+* Standalone instructions
+
+```
+mkdir ~/workspace
+cd ~/workspace
+git clone https://github.com/tianocore/edk2.git
+# The following is only needed once, after you cloned edk2
+make -C edk2/BaseTools
+git clone https://github.com/tianocore/edk2-platforms.git
+git clone https://github.com/tianocore/edk2-non-osi.git
+wget 
https://releases.linaro.org/components/toolchain/binaries/7.4-2019.02/aarch64-linux-gnu/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu.tar.xz
+tar -xJvf gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu.tar.xz
+# If you have multiple AARCH64 toolchains, make sure the above one comes first 
in your path
+export PATH=$PWD/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/bin:$PATH
+export GCC5_AARCH64_PREFIX=aarch64-linux-gnu-
+export WORKSPACE=$PWD
+export 
PACKAGES_PATH=$WORKSPACE/edk2:$WORKSPACE/edk2-platforms:$WORKSPACE/edk2-non-osi
+. edk2/edksetup.sh
+build -a AARCH64 -t GCC5 -p edk2-platforms/Platform/Raspberry/Pi3/RPi3.dsc 
-DBUILD_EPOCH=`date +%s` -b RELEASE
+```
+
+# Booting the firmware
+
+1. Format a uSD card as FAT32
+2. Copy the generated `RPI_EFI.fd` firmware onto the partition
+3. Download and copy the following files from 
https://github.com/raspberrypi/firmware/tree/master/boot
+  - `bootcode.bin`
+  - `fixup.dat`
+  - `start.elf`
+4. Create a `config.txt` with the following content:
+  ```
+  arm_control=0x200
+  enable_uart=1
+  armstub=RPI_EFI.fd
+  disable_commandline_tags=1
+  ```
+5. Insert the uSD card and power up the Pi.
+
+Note that if you have a model 3+ or a model 3 where you enabled USB boot 
through OTP
+(see 
[here](https://www.raspberrypi.org/documentation/hardware/raspberrypi/bootmodes/msd.md))
+you may also be able to boot from a FAT32 USB driver rather than uSD.
+
+# Notes
+
+## ARM Trusted Firmware (ATF)
+
+The ATF binaries being used were compiled from the ATF mainline.
+
+For more details on the ATF compilation, see the [README](./Binary/README.md) 
in the `Binary/` directory.
+
+## Custom Device Tree
+
+The default Device Tree included in the firmware is the one for a Raspberry Pi 
3 Model B (not B+).
+If you want to use a different Device Tree, to boot a Pi 3 Model B+ for 
instance (for which a
+DTB is also provided under `DeviceTree/`), you should copy the relevant `.dtb` 
into the root of
+the SD or USB, and then

[edk2] [PATCH v3 edk2-platforms 19/23] Platform/Raspberry/Pi3: Add platform

2019-01-28 Thread Pete Batard
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Pete Batard 
---
 Platform/Raspberry/Pi3/RPi3.dec |  60 ++
 Platform/Raspberry/Pi3/RPi3.dsc | 637 
 Platform/Raspberry/Pi3/RPi3.fdf | 449 ++
 3 files changed, 1146 insertions(+)

diff --git a/Platform/Raspberry/Pi3/RPi3.dec b/Platform/Raspberry/Pi3/RPi3.dec
new file mode 100644
index ..d65a4adc8eeb
--- /dev/null
+++ b/Platform/Raspberry/Pi3/RPi3.dec
@@ -0,0 +1,60 @@
+## @file
+#
+#  Copyright (c) 2016, Linaro, Ltd. All rights reserved.
+#  Copyright (c) 2017-2018, Andrei Warkentin 
+#
+#  This program and the accompanying materials are licensed and made available
+#  under the terms and conditions of the BSD License which accompanies this
+#  distribution. The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php
+#
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR
+#  IMPLIED.
+#
+##
+
+[Defines]
+  DEC_SPECIFICATION  = 0x0001001A
+  PACKAGE_NAME   = RPi3Pkg
+  PACKAGE_GUID   = DFA0CA8B-F3AC-4607-96AC-46FA04B84DCC
+  PACKAGE_VERSION= 1.0
+
+[Includes]
+  Include
+  Silicon/Broadcom/Include
+
+[Protocols]
+  gRaspberryPiFirmwareProtocolGuid = { 0x0ACA9535, 0x7AD0, 0x4286, { 0xB0, 
0x2E, 0x87, 0xFA, 0x7E, 0x2A, 0x57, 0x11 } }
+  gRaspberryPiConfigAppliedProtocolGuid = { 0x0ACA, 0x7AD0, 0x4286, { 
0xB0, 0x2E, 0x87, 0xFA, 0x7E, 0x2A, 0x57, 0x11 } }
+  gRaspberryPiMmcHostProtocolGuid = { 0x3e591c00, 0x9e4a, 0x11df, {0x92, 0x44, 
0x00, 0x02, 0xA5, 0xF5, 0xF5, 0x1B } }
+  gExtendedTextOutputProtocolGuid = { 0x387477ff, 0xffc7, 0xffd2, {0x8e, 0x39, 
0x0, 0xff, 0xc9, 0x69, 0x72, 0x3b } }
+
+[Guids]
+  gRaspberryPiTokenSpaceGuid = {0xCD7CC258, 0x31DB, 0x11E6, {0x9F, 0xD3, 0x63, 
0xB0, 0xB8, 0xEE, 0xD6, 0xB5}}
+  gRaspberryPiFdtFileGuid = {0xDF5DA223, 0x1D27, 0x47C3, { 0x8D, 0x1B, 0x9A, 
0x41, 0xB5, 0x5A, 0x18, 0xBC}}
+  gRaspberryPiEventResetGuid = {0xCD7CC258, 0x31DB, 0x11E6, {0x9F, 0xD3, 0x63, 
0xB4, 0xB4, 0xE4, 0xD4, 0xB4}}
+  gConfigDxeFormSetGuid = {0xCD7CC258, 0x31DB, 0x22E6, {0x9F, 0x22, 0x63, 
0xB0, 0xB8, 0xEE, 0xD6, 0xB5}}
+
+[PcdsFixedAtBuild.common]
+  gRaspberryPiTokenSpaceGuid.PcdFdtBaseAddress|0x1|UINT32|0x0001
+  gRaspberryPiTokenSpaceGuid.PcdFirmwareBlockSize|0x0|UINT32|0x0002
+  gRaspberryPiTokenSpaceGuid.PcdNvStorageEventLogBase|0x0|UINT32|0x0003
+  gRaspberryPiTokenSpaceGuid.PcdNvStorageEventLogSize|0x0|UINT32|0x0004
+  gRaspberryPiTokenSpaceGuid.PcdNvStorageVariableBase|0x0|UINT32|0x0005
+  gRaspberryPiTokenSpaceGuid.PcdNvStorageFtwSpareBase|0x0|UINT32|0x0006
+  gRaspberryPiTokenSpaceGuid.PcdNvStorageFtwWorkingBase|0x0|UINT32|0x0007
+  gRaspberryPiTokenSpaceGuid.PcdBootEpochSeconds|0x0|UINT64|0x0008
+
+[PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx]
+  gRaspberryPiTokenSpaceGuid.PcdCpuClock|0|UINT32|0x000d
+  gRaspberryPiTokenSpaceGuid.PcdSdIsArasan|0|UINT32|0x000e
+  gRaspberryPiTokenSpaceGuid.PcdMmcForce1Bit|0|UINT32|0x000f
+  gRaspberryPiTokenSpaceGuid.PcdMmcForceDefaultSpeed|0|UINT32|0x0010
+  gRaspberryPiTokenSpaceGuid.PcdMmcSdDefaultSpeedMHz|0|UINT32|0x0011
+  gRaspberryPiTokenSpaceGuid.PcdMmcSdHighSpeedMHz|0|UINT32|0x0012
+  gRaspberryPiTokenSpaceGuid.PcdMmcDisableMulti|0|UINT32|0x0013
+  gRaspberryPiTokenSpaceGuid.PcdDebugEnableJTAG|0|UINT32|0x0014
+  gRaspberryPiTokenSpaceGuid.PcdDebugShowUEFIExit|0|UINT32|0x0015
+  gRaspberryPiTokenSpaceGuid.PcdDisplayEnableVModes|0|UINT32|0x0017
+  gRaspberryPiTokenSpaceGuid.PcdDisplayEnableSShot|0|UINT32|0x0018
diff --git a/Platform/Raspberry/Pi3/RPi3.dsc b/Platform/Raspberry/Pi3/RPi3.dsc
new file mode 100644
index ..effe9d243209
--- /dev/null
+++ b/Platform/Raspberry/Pi3/RPi3.dsc
@@ -0,0 +1,637 @@
+# @file
+#
+#  Copyright (c) 2011-2015, ARM Limited. All rights reserved.
+#  Copyright (c) 2014, Linaro Limited. All rights reserved.
+#  Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
+#  Copyright (c) 2017 - 2018, Andrei Warkentin 
+#
+#  This program and the accompanying materials are licensed and made available
+#  under the terms and conditions of the BSD License which accompanies this
+#  distribution. The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php
+#
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR
+#  IMPLIED.
+#
+##
+
+
+#
+# Defines Section - statements that will be processed to create a Makefile.
+#
+
+[Defines]
+  PLATFORM_NAME  = RPi3
+  PLATFORM_GUID  = 5d30c4fc-93cf-4

[edk2] [PATCH v3 edk2-platforms 18/23] Platform/Raspberry/Pi3: Add USB host driver

2019-01-28 Thread Pete Batard
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Pete Batard 
---
 Platform/Raspberry/Pi3/Drivers/DwUsbHostDxe/ComponentName.c  |  226 +++
 Platform/Raspberry/Pi3/Drivers/DwUsbHostDxe/DriverBinding.c  |  275 
 Platform/Raspberry/Pi3/Drivers/DwUsbHostDxe/DwUsbHostDxe.c   | 1637 

 Platform/Raspberry/Pi3/Drivers/DwUsbHostDxe/DwUsbHostDxe.h   |  165 ++
 Platform/Raspberry/Pi3/Drivers/DwUsbHostDxe/DwUsbHostDxe.inf |   52 +
 Platform/Raspberry/Pi3/Drivers/DwUsbHostDxe/DwcHw.h  |  791 ++
 Platform/Raspberry/Pi3/Include/Protocol/DwUsb.h  |   53 +
 7 files changed, 3199 insertions(+)

diff --git a/Platform/Raspberry/Pi3/Drivers/DwUsbHostDxe/ComponentName.c 
b/Platform/Raspberry/Pi3/Drivers/DwUsbHostDxe/ComponentName.c
new file mode 100644
index ..0f4db4e21204
--- /dev/null
+++ b/Platform/Raspberry/Pi3/Drivers/DwUsbHostDxe/ComponentName.c
@@ -0,0 +1,226 @@
+/** @file
+ *
+ *  Copyright (c) 2018, Andrey Warkentin 
+ *
+ *
+ *  This program and the accompanying materials
+ *  are licensed and made available under the terms and conditions of the BSD 
License
+ *  which accompanies this distribution.  The full text of the license may be 
found at
+ *  http://opensource.org/licenses/bsd-license.php
+ *
+ *  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
IMPLIED.
+ *
+ **/
+
+#include "DwUsbHostDxe.h"
+
+STATIC
+EFI_STATUS
+EFIAPI
+ComponentNameGetDriverName (
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,
+  IN  CHAR8*Language,
+  OUT CHAR16   **DriverName
+  );
+
+STATIC
+EFI_STATUS
+EFIAPI
+ComponentNameGetControllerName (
+  IN  EFI_COMPONENT_NAME_PROTOCOL *This,
+  IN  EFI_HANDLE  ControllerHandle,
+  IN  EFI_HANDLE  ChildHandle,
+  IN  CHAR8   *Language,
+  OUT CHAR16  **ControllerName
+  );
+
+//
+// EFI Component Name Protocol
+//
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gComponentName = {
+  ComponentNameGetDriverName,
+  ComponentNameGetControllerName,
+  "eng"
+};
+
+//
+// EFI Component Name 2 Protocol
+//
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gComponentName2 = {
+  (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)ComponentNameGetDriverName,
+  (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)ComponentNameGetControllerName,
+  "en"
+};
+
+
+STATIC EFI_UNICODE_STRING_TABLE mDriverName[] = {
+  {
+"eng;en",
+(CHAR16*)L"Raspberry Pi USB Host Driver"
+  },
+  {
+NULL,
+NULL
+  }
+};
+
+STATIC EFI_UNICODE_STRING_TABLE mDeviceName[] = {
+  {
+"eng;en",
+(CHAR16*)L"Raspberry Pi USB Host"
+  },
+  {
+NULL,
+NULL
+  }
+};
+
+/**
+  Retrieves a Unicode string that is the user readable name of the driver.
+
+  This function retrieves the user readable name of a driver in the form of a
+  Unicode string. If the driver specified by This has a user readable name in
+  the language specified by Language, then a pointer to the driver name is
+  returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
+  by This does not support the language specified by Language,
+  then EFI_UNSUPPORTED is returned.
+
+  @param  This[in]  A pointer to the EFI_COMPONENT_NAME2_PROTOCOL 
or
+EFI_COMPONENT_NAME_PROTOCOL instance.
+
+  @param  Language[in]  A pointer to a Null-terminated ASCII string
+array indicating the language. This is the
+language of the driver name that the caller is
+requesting, and it must match one of the
+languages specified in SupportedLanguages. The
+number of languages supported by a driver is up
+to the driver writer. Language is specified
+in RFC 4646 or ISO 639-2 language code format.
+
+  @param  DriverName[out]   A pointer to the Unicode string to return.
+This Unicode string is the name of the
+driver specified by This in the language
+specified by Language.
+
+  @retval EFI_SUCCESS   The Unicode string for the Driver specified by
+This and the language specified by Language was
+returned in DriverName.
+
+  @retval EFI_INVALID_PARAMETER Language is NULL.
+
+  @retval EFI_INVALID_PARAMETER DriverName is NULL.
+
+  @retval EFI_UNSUPPORTED   The driver specified by This does not support
+the language specified by Language.
+
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+ComponentNameGetDriverName (
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,
+  IN  CHAR8*Language,
+

[edk2] [PATCH v3 edk2-platforms 17/23] Platform/Raspberry/Pi3: Add platform boot manager and helper libraries

2019-01-28 Thread Pete Batard
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Pete Batard 
---
 Platform/Raspberry/Pi3/Library/PlatformBootManagerLib/PlatformBm.c 
  | 793 
 Platform/Raspberry/Pi3/Library/PlatformBootManagerLib/PlatformBm.h 
  |  60 ++
 
Platform/Raspberry/Pi3/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
 |  90 +++
 Platform/Raspberry/Pi3/Library/PlatformUiAppLib/PlatformUiAppLib.c 
  | 120 +++
 Platform/Raspberry/Pi3/Library/PlatformUiAppLib/PlatformUiAppLib.inf   
  |  34 +
 5 files changed, 1097 insertions(+)

diff --git a/Platform/Raspberry/Pi3/Library/PlatformBootManagerLib/PlatformBm.c 
b/Platform/Raspberry/Pi3/Library/PlatformBootManagerLib/PlatformBm.c
new file mode 100644
index ..9bbe0db64950
--- /dev/null
+++ b/Platform/Raspberry/Pi3/Library/PlatformBootManagerLib/PlatformBm.c
@@ -0,0 +1,793 @@
+/** @file
+ *
+ *  Copyright (c) 2018, Pete Batard 
+ *  Copyright (c) 2017-2018, Andrei Warkentin 
+ *  Copyright (c) 2016, Linaro Ltd. All rights reserved.
+ *  Copyright (c) 2015-2016, Red Hat, Inc.
+ *  Copyright (c) 2014, ARM Ltd. All rights reserved.
+ *  Copyright (c) 2004-2016, Intel Corporation. All rights reserved.
+ *
+ *  This program and the accompanying materials
+ *  are licensed and made available under the terms and conditions of the BSD 
License
+ *  which accompanies this distribution.  The full text of the license may be 
found at
+ *  http://opensource.org/licenses/bsd-license.php
+ *
+ *  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
IMPLIED.
+ *
+ **/
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "PlatformBm.h"
+
+#define BOOT_PROMPT L"ESC (setup), F1 (shell), ENTER (boot)"
+
+#define DP_NODE_LEN(Type) { (UINT8)sizeof (Type), (UINT8)(sizeof (Type) >> 8) }
+
+#pragma pack (1)
+typedef struct {
+  VENDOR_DEVICE_PATH SerialDxe;
+  UART_DEVICE_PATH   Uart;
+  VENDOR_DEFINED_DEVICE_PATH TermType;
+  EFI_DEVICE_PATH_PROTOCOL   End;
+} PLATFORM_SERIAL_CONSOLE;
+#pragma pack ()
+
+typedef struct {
+  VENDOR_DEVICE_PATH Custom;
+  USB_DEVICE_PATHHub;
+  USB_DEVICE_PATHDev;
+  EFI_DEVICE_PATH_PROTOCOL   EndDevicePath;
+} PLATFORM_USB_DEV;
+
+typedef struct {
+  VENDOR_DEVICE_PATH Custom;
+  EFI_DEVICE_PATH_PROTOCOL   EndDevicePath;
+} PLATFORM_SD_DEV;
+
+#define ARASAN_MMC_DXE_FILE_GUID  \
+  { 0x100c2cfa, 0xb586, 0x4198, { 0x9b, 0x4c, 0x16, 0x83, 0xd1, 0x95, 0xb1, 
0xda } }
+
+#define SDHOST_MMC_DXE_FILE_GUID  \
+  { 0x58abd787, 0xf64d, 0x4ca2, { 0xa0, 0x34, 0xb9, 0xac, 0x2d, 0x5a, 0xd0, 
0xcf } }
+
+#define SERIAL_DXE_FILE_GUID  \
+  { 0xD3987D4B, 0x971A, 0x435F, { 0x8C, 0xAF, 0x49, 0x67, 0xEB, 0x62, 0x72, 
0x41 } }
+
+STATIC PLATFORM_SD_DEV mArasan = {
+  //
+  // VENDOR_DEVICE_PATH ArasanMMCHostDxe
+  //
+  {
+{ HARDWARE_DEVICE_PATH, HW_VENDOR_DP, DP_NODE_LEN (VENDOR_DEVICE_PATH) },
+ARASAN_MMC_DXE_FILE_GUID
+  },
+
+  //
+  // EFI_DEVICE_PATH_PROTOCOL End
+  //
+  {
+END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE,
+DP_NODE_LEN (EFI_DEVICE_PATH_PROTOCOL)
+  }
+};
+
+STATIC PLATFORM_SD_DEV mSDHost = {
+  //
+  // VENDOR_DEVICE_PATH SdHostDxe
+  //
+  {
+{ HARDWARE_DEVICE_PATH, HW_VENDOR_DP, DP_NODE_LEN (VENDOR_DEVICE_PATH) },
+SDHOST_MMC_DXE_FILE_GUID
+  },
+
+  //
+  // EFI_DEVICE_PATH_PROTOCOL End
+  //
+  {
+END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE,
+DP_NODE_LEN (EFI_DEVICE_PATH_PROTOCOL)
+  }
+};
+
+STATIC PLATFORM_SERIAL_CONSOLE mSerialConsole = {
+  //
+  // VENDOR_DEVICE_PATH SerialDxe
+  //
+  {
+{ HARDWARE_DEVICE_PATH, HW_VENDOR_DP, DP_NODE_LEN (VENDOR_DEVICE_PATH) },
+SERIAL_DXE_FILE_GUID
+  },
+
+  //
+  // UART_DEVICE_PATH Uart
+  //
+  {
+{ MESSAGING_DEVICE_PATH, MSG_UART_DP, DP_NODE_LEN (UART_DEVICE_PATH) },
+0,  // Reserved
+FixedPcdGet64 (PcdUartDefaultBaudRate), // BaudRate
+FixedPcdGet8 (PcdUartDefaultDataBits),  // DataBits
+FixedPcdGet8 (PcdUartDefaultParity),// Parity
+FixedPcdGet8 (PcdUartDefaultStopBits)   // StopBits
+  },
+
+  //
+  // VENDOR_DEFINED_DEVICE_PATH TermType
+  //
+  {
+{
+  MESSAGING_DEVICE_PATH, MSG_VENDOR_DP,
+  DP_NODE_LEN (VENDOR_DEFINED_DEVICE_PATH)
+}
+//
+// Guid to be filled in dynamically
+//
+  },
+
+  //
+  // EFI_DEVICE_PATH_PROTOCOL End
+  //
+  {
+END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE,
+DP_NODE_LEN (EFI_DEVICE_PATH_PROTOCOL)
+  }
+};
+
+
+#pragma pack (1)
+typedef struct {
+  USB_CLASS_DEVICE_PATHKeyboard;
+  EFI_DEVICE_PATH_PROTOCOL End;
+} PLATFORM_USB_KEYBOARD;
+#pragma pack ()
+
+STATIC PLATFORM_USB_KEYBOARD mUsbKeyboard = {
+  //
+  // USB_CLASS_DEVICE_PATH Keyboard
+  //
+  

[edk2] [PATCH v3 edk2-platforms 16/23] Platform/Raspberry/Pi3: Add SD Host driver

2019-01-28 Thread Pete Batard
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Pete Batard 
---
 Platform/Raspberry/Pi3/Drivers/SdHostDxe/SdHostDxe.c  | 787 

 Platform/Raspberry/Pi3/Drivers/SdHostDxe/SdHostDxe.inf|  54 ++
 Silicon/Broadcom/Include/IndustryStandard/Bcm2836SdHost.h |  92 +++
 3 files changed, 933 insertions(+)

diff --git a/Platform/Raspberry/Pi3/Drivers/SdHostDxe/SdHostDxe.c 
b/Platform/Raspberry/Pi3/Drivers/SdHostDxe/SdHostDxe.c
new file mode 100644
index ..3bf789f96b27
--- /dev/null
+++ b/Platform/Raspberry/Pi3/Drivers/SdHostDxe/SdHostDxe.c
@@ -0,0 +1,787 @@
+/** @file
+ *
+ *  Copyright (c) 2017, Andrei Warkentin 
+ *  Copyright (c) Microsoft Corporation. All rights reserved.
+ *
+ *  This program and the accompanying materials
+ *  are licensed and made available under the terms and conditions of the BSD 
License
+ *  which accompanies this distribution.  The full text of the license may be 
found at
+ *  http://opensource.org/licenses/bsd-license.php
+ *
+ *  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
IMPLIED.
+ *
+ **/
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#define SDHOST_BLOCK_BYTE_LENGTH512
+
+// Driver Timing Parameters
+#define CMD_STALL_AFTER_POLL_US 1
+#define CMD_MIN_POLL_TOTAL_TIME_US  10 // 100ms
+#define CMD_MAX_POLL_COUNT  (CMD_MIN_POLL_TOTAL_TIME_US / 
CMD_STALL_AFTER_POLL_US)
+#define CMD_MAX_RETRY_COUNT 3
+#define CMD_STALL_AFTER_RETRY_US20 // 20us
+#define FIFO_MAX_POLL_COUNT 100
+#define STALL_TO_STABILIZE_US   1 // 10ms
+
+#define IDENT_MODE_SD_CLOCK_FREQ_HZ 40 // 400KHz
+
+// Macros adopted from MmcDxe internal header
+#define SDHOST_R0_READY_FOR_DATABIT8
+#define SDHOST_R0_CURRENTSTATE(Response)((Response >> 9) & 0xF)
+
+#define DEBUG_MMCHOST_SD   DEBUG_VERBOSE
+#define DEBUG_MMCHOST_SD_INFO  DEBUG_INFO
+#define DEBUG_MMCHOST_SD_ERROR DEBUG_ERROR
+
+STATIC RASPBERRY_PI_FIRMWARE_PROTOCOL   *mFwProtocol;
+
+// Per Physical Layer Simplified Specs
+#ifndef NDEBUG
+STATIC CONST CHAR8* mStrSdState[] = { "idle", "ready", "ident", "stby",
+  "tran", "data", "rcv", "prg", "dis",
+  "ina" };
+STATIC CONST CHAR8 *mFsmState[] = { "identmode", "datamode", "readdata",
+"writedata", "readwait", "readcrc",
+"writecrc", "writewait1", "powerdown",
+"powerup", "writestart1", "writestart2",
+"genpulses", "writewait2", "?",
+"startpowdown" };
+#endif /* NDEBUG */
+STATIC UINT32 mLastGoodCmd = MMC_GET_INDX (MMC_CMD0);
+
+STATIC inline BOOLEAN
+IsAppCmd (
+  VOID
+  )
+{
+  return mLastGoodCmd == MMC_CMD55;
+}
+
+STATIC BOOLEAN
+IsBusyCmd (
+  IN  UINT32 MmcCmd
+  )
+{
+  if (IsAppCmd ()) {
+return FALSE;
+  }
+
+  return MmcCmd == MMC_CMD7 || MmcCmd == MMC_CMD12;
+}
+
+STATIC BOOLEAN
+IsWriteCmd (
+  IN  UINT32 MmcCmd
+  )
+{
+  if (IsAppCmd ()) {
+return FALSE;
+  }
+
+  return MmcCmd == MMC_CMD24 || MmcCmd == MMC_CMD25;
+}
+
+STATIC BOOLEAN
+IsReadCmd (
+  IN  UINT32 MmcCmd,
+  IN  UINT32 Argument
+  )
+{
+  if (MmcCmd == MMC_CMD8 && !IsAppCmd ()) {
+if (Argument == CMD8_MMC_ARG) {
+  DEBUG ((DEBUG_MMCHOST_SD, "Sending MMC CMD8 variant\n"));
+  return TRUE;
+} else {
+  ASSERT (Argument == CMD8_SD_ARG);
+  DEBUG ((DEBUG_MMCHOST_SD, "Sending SD CMD8 variant\n"));
+  return FALSE;
+}
+  }
+
+  return
+(MmcCmd == MMC_CMD6 && !IsAppCmd ()) ||
+(MmcCmd == MMC_CMD17 && !IsAppCmd ()) ||
+(MmcCmd == MMC_CMD18 && !IsAppCmd ()) ||
+(MmcCmd == MMC_CMD13 && IsAppCmd ()) ||
+(MmcCmd == MMC_ACMD22 && IsAppCmd ()) ||
+(MmcCmd == MMC_ACMD51 && IsAppCmd ());
+}
+
+STATIC VOID
+SdHostDumpRegisters (
+  VOID
+  )
+{
+  DEBUG ((DEBUG_MMCHOST_SD, "SdHost: Registers Dump:\n"));
+  DEBUG ((DEBUG_MMCHOST_SD, "  CMD:  0x%8.8X\n", MmioRead32 (SDHOST_CMD)));
+  DEBUG ((DEBUG_MMCHOST_SD, "  ARG:  0x%8.8X\n", MmioRead32 (SDHOST_ARG)));
+  DEBUG ((DEBUG_MMCHOST_SD, "  TOUT: 0x%8.8X\n", MmioRead32 (SDHOST_TOUT)));
+  DEBUG ((DEBUG_MMCHOST_SD, "  CDIV: 0x%8.8X\n", MmioRead32 (SDHOST_CDIV)));
+  DEBUG ((DEBUG_MMCHOST_SD, "  RSP0: 0x%8.8X\n", MmioRead32 (SDHOST_RSP0)));
+  DEBUG ((DEBUG_MMCHOST_SD, "  RSP1: 0x%8.8X\n", MmioRead32 (SDHOST_RSP1)));
+  DEBUG ((DEBUG_MMCHOST_SD, "  RSP2: 0x%8.8X\n", MmioRead32 (SDHOST_RSP2)));
+  DEBUG ((DEBUG_MMCHOST_SD, "  RSP3: 0x%8.8X\n", MmioRead32 (SDHOST_RSP3)));
+  DEBUG ((DEBUG_MMCHOST_SD, "  HSTS: 0x%8.8X\n", MmioRea

[edk2] [PATCH v3 edk2-platforms 15/23] Platform/Raspberry/Pi3: Add Arasan MMC driver

2019-01-28 Thread Pete Batard
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Pete Batard 
---
 Platform/Raspberry/Pi3/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.c   | 723 

 Platform/Raspberry/Pi3/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.h   |  50 ++
 Platform/Raspberry/Pi3/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.inf |  51 ++
 Silicon/Broadcom/Include/IndustryStandard/Bcm2836Sdio.h  | 199 
++
 4 files changed, 1023 insertions(+)

diff --git a/Platform/Raspberry/Pi3/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.c 
b/Platform/Raspberry/Pi3/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.c
new file mode 100644
index ..828b40f82a5f
--- /dev/null
+++ b/Platform/Raspberry/Pi3/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.c
@@ -0,0 +1,723 @@
+/** @file
+ *
+ *  Copyright (c) 2017, Andrei Warkentin 
+ *  Copyright (c) Microsoft Corporation. All rights reserved.
+ *
+ *  This program and the accompanying materials
+ *  are licensed and made available under the terms and conditions of the BSD 
License
+ *  which accompanies this distribution.  The full text of the license may be 
found at
+ *  http://opensource.org/licenses/bsd-license.php
+ *
+ *  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
IMPLIED.
+ *
+ **/
+
+#include "ArasanMmcHostDxe.h"
+
+#define DEBUG_MMCHOST_SD DEBUG_VERBOSE
+
+BOOLEAN PreviousIsCardPresent = FALSE;
+UINT32 LastExecutedCommand = (UINT32) -1;
+
+STATIC RASPBERRY_PI_FIRMWARE_PROTOCOL *mFwProtocol;
+
+/**
+   These SD commands are optional, according to the SD Spec
+**/
+BOOLEAN
+IgnoreCommand (
+  UINT32 Command
+  )
+{
+  switch (Command) {
+  case MMC_CMD20:
+return TRUE;
+  default:
+return FALSE;
+  }
+}
+
+/**
+   Translates a generic SD command into the format used by the Arasan SD Host 
Controller
+**/
+UINT32
+TranslateCommand (
+  UINT32 Command,
+  UINT32 Argument
+  )
+{
+  UINT32 Translation = 0x;
+
+  if (LastExecutedCommand == CMD55) {
+switch (Command) {
+case MMC_CMD6:
+  Translation = ACMD6;
+  DEBUG ((DEBUG_MMCHOST_SD, "ACMD6\n"));
+  break;
+case MMC_ACMD22:
+  Translation = ACMD22;
+  DEBUG ((DEBUG_MMCHOST_SD, "ACMD22\n"));
+  break;
+case MMC_ACMD41:
+  Translation = ACMD41;
+  DEBUG ((DEBUG_MMCHOST_SD, "ACMD41\n"));
+  break;
+case MMC_ACMD51:
+  Translation = ACMD51;
+  DEBUG ((DEBUG_MMCHOST_SD, "ACMD51\n"));
+  break;
+default:
+  DEBUG ((DEBUG_ERROR, "ArasanMMCHost: TranslateCommand(): Unrecognized 
App command: %d\n", Command));
+}
+  } else {
+switch (Command) {
+case MMC_CMD0:
+  Translation = CMD0;
+  break;
+case MMC_CMD1:
+  Translation = CMD1;
+  break;
+case MMC_CMD2:
+  Translation = CMD2;
+  break;
+case MMC_CMD3:
+  Translation = CMD3;
+  break;
+case MMC_CMD5:
+  Translation = CMD5;
+  break;
+case MMC_CMD6:
+  Translation = CMD6;
+  break;
+case MMC_CMD7:
+  Translation = CMD7;
+  break;
+case MMC_CMD8: {
+  if (Argument == CMD8_SD_ARG) {
+Translation = CMD8_SD;
+DEBUG ((DEBUG_MMCHOST_SD, "Sending SD CMD8 variant\n"));
+  } else {
+ASSERT (Argument == CMD8_MMC_ARG);
+Translation = CMD8_MMC;
+DEBUG ((DEBUG_MMCHOST_SD, "Sending MMC CMD8 variant\n"));
+  }
+  break;
+}
+case MMC_CMD9:
+  Translation = CMD9;
+  break;
+case MMC_CMD11:
+  Translation = CMD11;
+  break;
+case MMC_CMD12:
+  Translation = CMD12;
+  break;
+case MMC_CMD13:
+  Translation = CMD13;
+  break;
+case MMC_CMD16:
+  Translation = CMD16;
+  break;
+case MMC_CMD17:
+  Translation = CMD17;
+  break;
+case MMC_CMD18:
+  Translation = CMD18;
+  break;
+case MMC_CMD23:
+  Translation = CMD23;
+  break;
+case MMC_CMD24:
+  Translation = CMD24;
+  break;
+case MMC_CMD25:
+  Translation = CMD25;
+  break;
+case MMC_CMD55:
+  Translation = CMD55;
+  break;
+default:
+  DEBUG ((DEBUG_ERROR, "ArasanMMCHost: TranslateCommand(): Unrecognized 
Command: %d\n", Command));
+}
+  }
+
+  return Translation;
+}
+
+/**
+   Repeatedly polls a register until its value becomes correct, or until 
MAX_RETRY_COUNT polls is reached
+**/
+EFI_STATUS
+PollRegisterWithMask (
+  IN UINTN Register,
+  IN UINTN Mask,
+  IN UINTN ExpectedValue
+  )
+{
+  UINTN RetryCount = 0;
+
+  while (RetryCount < MAX_RETRY_COUNT) {
+if ((MmioRead32 (Register) & Mask) != ExpectedValue) {
+  RetryCount++;
+  gBS->Stall (STALL_AFTER_RETRY_US);
+} else {
+  break;
+}
+  }
+
+  if (RetryCount == MAX_RETRY_COUNT) {
+return EFI_TIMEOUT;
+  }
+
+  return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
+SoftReset (
+  IN UINT32 Mask
+  )
+{
+  MmioOr32 (MMCHS_SYSCTL, Mask);
+  if (PollRegisterWithMask (MMCHS_SYSCT

[edk2] [PATCH v3 edk2-platforms 14/23] Platform/Raspberry/Pi3: Add base MMC driver

2019-01-28 Thread Pete Batard
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Pete Batard 
---
 Platform/Raspberry/Pi3/Drivers/MmcDxe/ComponentName.c | 163 
 Platform/Raspberry/Pi3/Drivers/MmcDxe/Diagnostics.c   | 263 ++
 Platform/Raspberry/Pi3/Drivers/MmcDxe/Mmc.c   | 460 +
 Platform/Raspberry/Pi3/Drivers/MmcDxe/Mmc.h   | 533 +++
 Platform/Raspberry/Pi3/Drivers/MmcDxe/MmcBlockIo.c| 469 ++
 Platform/Raspberry/Pi3/Drivers/MmcDxe/MmcDebug.c  | 170 
 Platform/Raspberry/Pi3/Drivers/MmcDxe/MmcDxe.inf  |  58 ++
 Platform/Raspberry/Pi3/Drivers/MmcDxe/MmcIdentification.c | 980 

 Platform/Raspberry/Pi3/Include/Protocol/RpiMmcHost.h  | 206 
 9 files changed, 3302 insertions(+)

diff --git a/Platform/Raspberry/Pi3/Drivers/MmcDxe/ComponentName.c 
b/Platform/Raspberry/Pi3/Drivers/MmcDxe/ComponentName.c
new file mode 100644
index ..034da778cae2
--- /dev/null
+++ b/Platform/Raspberry/Pi3/Drivers/MmcDxe/ComponentName.c
@@ -0,0 +1,163 @@
+/** @file
+ *
+ *  Component Name Protocol implementation for the MMC DXE driver
+ *
+ *  Copyright (c) 2011, ARM Limited. All rights reserved.
+ *
+ *  This program and the accompanying materials
+ *  are licensed and made available under the terms and conditions of the BSD 
License
+ *  which accompanies this distribution.  The full text of the license may be 
found at
+ *  http://opensource.org/licenses/bsd-license.php
+ *
+ *  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
IMPLIED.
+ *
+ **/
+
+#include "Mmc.h"
+
+//
+// EFI Component Name Protocol
+//
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL  gMmcComponentName = 
{
+  MmcGetDriverName,
+  MmcGetControllerName,
+  "eng"
+};
+
+//
+// EFI Component Name 2 Protocol
+//
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gMmcComponentName2 
= {
+  (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)MmcGetDriverName,
+  (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)MmcGetControllerName,
+  "en"
+};
+
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE
+mMmcDriverNameTable[] = {
+  {"eng;en", L"MMC/SD Card Interface Driver"},
+  {NULL,  NULL}
+};
+
+/**
+  Retrieves a Unicode string that is the user readable name of the driver.
+
+  This function retrieves the user readable name of a driver in the form of a
+  Unicode string. If the driver specified by This has a user readable name in
+  the language specified by Language, then a pointer to the driver name is
+  returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
+  by This does not support the language specified by Language,
+  then EFI_UNSUPPORTED is returned.
+
+  @param  This  A pointer to the EFI_COMPONENT_NAME2_PROTOCOL 
or
+EFI_COMPONENT_NAME_PROTOCOL instance.
+  @param  Language  A pointer to a Null-terminated ASCII string
+array indicating the language. This is the
+language of the driver name that the caller is
+requesting, and it must match one of the
+languages specified in SupportedLanguages. The
+number of languages supported by a driver is up
+to the driver writer. Language is specified
+in RFC 4646 or ISO 639-2 language code format.
+  @param  DriverNameA pointer to the Unicode string to return.
+This Unicode string is the name of the
+driver specified by This in the language
+specified by Language.
+
+  @retval EFI_SUCCESS   The Unicode string for the Driver specified by
+This and the language specified by Language was
+returned in DriverName.
+  @retval EFI_INVALID_PARAMETER Language is NULL.
+  @retval EFI_INVALID_PARAMETER DriverName is NULL.
+  @retval EFI_UNSUPPORTED   The driver specified by This does not support
+the language specified by Language.
+
+**/
+EFI_STATUS
+EFIAPI
+MmcGetDriverName (
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,
+  IN  CHAR8*Language,
+  OUT CHAR16   **DriverName
+  )
+{
+  return LookupUnicodeString2 (
+   Language,
+   This->SupportedLanguages,
+   mMmcDriverNameTable,
+   DriverName,
+   (BOOLEAN)(This == &gMmcComponentName)
+ );
+}
+
+/**
+  Retrieves a Unicode string that is the user readable name of the controller
+  that is being managed by a driver.
+
+  This function retrieves the user readable name of the controller specified by
+  ControllerHandle and ChildHandle in the form of a Unicode string.

[edk2] [PATCH v3 edk2-platforms 13/23] Platform/Raspberry/Pi3: Add Device Tree driver

2019-01-28 Thread Pete Batard
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Pete Batard 
---
 Platform/Raspberry/Pi3/Drivers/FdtDxe/FdtDxe.c   | 364 
 Platform/Raspberry/Pi3/Drivers/FdtDxe/FdtDxe.inf |  53 +++
 2 files changed, 417 insertions(+)

diff --git a/Platform/Raspberry/Pi3/Drivers/FdtDxe/FdtDxe.c 
b/Platform/Raspberry/Pi3/Drivers/FdtDxe/FdtDxe.c
new file mode 100644
index ..eb5698cb505b
--- /dev/null
+++ b/Platform/Raspberry/Pi3/Drivers/FdtDxe/FdtDxe.c
@@ -0,0 +1,364 @@
+/** @file
+ *
+ *  Copyright (c) 2017, Andrey Warkentin 
+ *  Copyright (c) 2016, Linaro, Ltd. All rights reserved.
+ *
+ *  This program and the accompanying materials
+ *  are licensed and made available under the terms and conditions of the BSD 
License
+ *  which accompanies this distribution.  The full text of the license may be 
found at
+ *  http://opensource.org/licenses/bsd-license.php
+ *
+ *  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
IMPLIED.
+ *
+ **/
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+
+STATIC VOID *mFdtImage;
+
+STATIC RASPBERRY_PI_FIRMWARE_PROTOCOL   *mFwProtocol;
+
+STATIC
+VOID
+UpdateMacAddress (
+  VOID
+  )
+{
+  INTN  Node;
+  INTN  Retval;
+  EFI_STATUSStatus;
+  UINT8 MacAddress[6];
+
+  //
+  // Locate the node that the 'ethernet' alias refers to
+  //
+  Node = fdt_path_offset (mFdtImage, "ethernet");
+  if (Node < 0) {
+DEBUG ((DEBUG_ERROR, "%a: failed to locate 'ethernet' alias\n", 
__FUNCTION__));
+return;
+  }
+
+  //
+  // Get the MAC address from the firmware
+  //
+  Status = mFwProtocol->GetMacAddress (MacAddress);
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, "%a: failed to retrieve MAC address\n", 
__FUNCTION__));
+return;
+  }
+
+  Retval = fdt_setprop (mFdtImage, Node, "mac-address", MacAddress,
+sizeof MacAddress);
+  if (Retval != 0) {
+DEBUG ((DEBUG_ERROR, "%a: failed to create 'mac-address' property (%d)\n",
+  __FUNCTION__, Retval));
+return;
+  }
+
+  DEBUG ((DEBUG_INFO, "%a: setting MAC address to 
%02x:%02x:%02x:%02x:%02x:%02x\n",
+__FUNCTION__, MacAddress[0], MacAddress[1], MacAddress[2], MacAddress[3],
+MacAddress[4], MacAddress[5]));
+}
+
+STATIC
+VOID
+CleanMemoryNodes (
+  VOID
+  )
+{
+  INTN Node;
+  INT32 Retval;
+
+  Node = fdt_path_offset (mFdtImage, "/memory");
+  if (Node < 0) {
+return;
+  }
+
+  /*
+   * Remove bogus memory nodes which can make the booted
+   * OS go crazy and ignore the UEFI map.
+   */
+  DEBUG ((DEBUG_INFO, "Removing bogus /memory\n"));
+  Retval = fdt_del_node (mFdtImage, Node);
+  if (Retval != 0) {
+DEBUG ((DEBUG_ERROR, "Failed to remove /memory\n"));
+  }
+}
+
+STATIC
+VOID
+SanitizePSCI (
+  VOID
+  )
+{
+  INTN Node;
+  INTN Root;
+  INT32 Retval;
+
+  Root = fdt_path_offset (mFdtImage, "/");
+  ASSERT (Root >= 0);
+  if (Root < 0) {
+return;
+  }
+
+  Node = fdt_path_offset (mFdtImage, "/psci");
+  if (Node < 0) {
+Node = fdt_add_subnode (mFdtImage, Root, "psci");
+  }
+
+  ASSERT (Node >= 0);
+  if (Node < 0) {
+DEBUG ((DEBUG_ERROR, "Couldn't find/create /psci\n"));
+return;
+  }
+
+  Retval = fdt_setprop_string (mFdtImage, Node, "compatible", "arm,psci-1.0");
+  if (Retval != 0) {
+DEBUG ((DEBUG_ERROR, "Couldn't set /psci compatible property\n"));
+return;
+  }
+
+  Retval = fdt_setprop_string (mFdtImage, Node, "method", "smc");
+  if (Retval != 0) {
+DEBUG ((DEBUG_ERROR, "Couldn't set /psci method property\n"));
+return;
+  }
+
+  Root = fdt_path_offset (mFdtImage, "/cpus");
+  if (Root < 0) {
+DEBUG ((DEBUG_ERROR, "No CPUs to update with PSCI enable-method?\n"));
+return;
+  }
+
+  Node = fdt_first_subnode (mFdtImage, Root);
+  while (Node >= 0) {
+if (fdt_setprop_string (mFdtImage, Node, "enable-method", "psci") != 0) {
+  DEBUG ((DEBUG_ERROR, "Failed to update enable-method for a CPU\n"));
+  return;
+}
+
+fdt_delprop (mFdtImage, Node, "cpu-release-addr");
+Node = fdt_next_subnode (mFdtImage, Node);
+  }
+}
+
+STATIC
+VOID
+CleanSimpleFramebuffer (
+  VOID
+  )
+{
+  INTN Node;
+  INT32 Retval;
+
+  /*
+   * Should look for nodes by kind and remove aliases
+   * by matching against device.
+   */
+  Node = fdt_path_offset (mFdtImage, "display0");
+  if (Node < 0) {
+return;
+  }
+
+  /*
+   * Remove bogus GPU-injected simple-framebuffer, which
+   * doesn't reflect the framebuffer built by UEFI.
+   */
+  DEBUG ((DEBUG_INFO, "Removing bogus display0\n"));
+  Retval = fdt_del_node (mFdtImage, Node);
+  if (Retval != 0) {
+DEBUG ((DEBUG_ERROR, "Failed to remove display0\n"));
+return;
+  }
+
+  Node = fdt_path_offset (mFdtImage, "/aliases");
+  if (Node < 0) {
+DEBUG ((DEBUG_ERROR, "Couldn't find /aliases to remove display0\n"));
+return;
+  }
+
+  Retval 

[edk2] [PATCH v3 edk2-platforms 12/23] Platform/Raspberry/Pi3: Add NV storage driver

2019-01-28 Thread Pete Batard
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Pete Batard 
---
 Platform/Raspberry/Pi3/Drivers/VarBlockServiceDxe/FileIo.c   | 196 

 Platform/Raspberry/Pi3/Drivers/VarBlockServiceDxe/FvbInfo.c  | 115 
+++
 Platform/Raspberry/Pi3/Drivers/VarBlockServiceDxe/VarBlockService.c  | 971 

 Platform/Raspberry/Pi3/Drivers/VarBlockServiceDxe/VarBlockService.h  | 217 
+
 Platform/Raspberry/Pi3/Drivers/VarBlockServiceDxe/VarBlockServiceDxe.c   | 331 
+++
 Platform/Raspberry/Pi3/Drivers/VarBlockServiceDxe/VarBlockServiceDxe.inf |  93 
++
 6 files changed, 1923 insertions(+)

diff --git a/Platform/Raspberry/Pi3/Drivers/VarBlockServiceDxe/FileIo.c 
b/Platform/Raspberry/Pi3/Drivers/VarBlockServiceDxe/FileIo.c
new file mode 100644
index ..0e8cd516f65e
--- /dev/null
+++ b/Platform/Raspberry/Pi3/Drivers/VarBlockServiceDxe/FileIo.c
@@ -0,0 +1,196 @@
+/** @file
+ *
+ *  Copyright (c) 2018, Andrei Warkentin 
+ *  Copyright (c) 2007-2009, Intel Corporation. All rights reserved.
+ *
+ *  This program and the accompanying materials
+ *  are licensed and made available under the terms and conditions of the BSD 
License
+ *  which accompanies this distribution.  The full text of the license may be 
found at
+ *  http://opensource.org/licenses/bsd-license.php
+ *
+ *  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
IMPLIED.
+ *
+ **/
+
+#include "VarBlockService.h"
+
+
+EFI_STATUS
+FileWrite (
+  IN EFI_FILE_PROTOCOL *File,
+  IN UINTN Offset,
+  IN UINTN Buffer,
+  IN UINTN Size
+  )
+{
+  EFI_STATUS Status;
+
+  Status = File->SetPosition (File, Offset);
+  ASSERT_EFI_ERROR (Status);
+  if (!EFI_ERROR (Status)) {
+Status = File->Write (File, &Size, (VOID*)Buffer);
+ASSERT_EFI_ERROR (Status);
+  }
+  return Status;
+}
+
+
+VOID
+FileClose (
+  IN  EFI_FILE_PROTOCOL *File
+  )
+{
+  File->Flush (File);
+  File->Close (File);
+}
+
+
+EFI_STATUS
+FileOpen (
+  IN  EFI_DEVICE_PATH_PROTOCOL *Device,
+  IN  CHAR16 *MappedFile,
+  OUT EFI_FILE_PROTOCOL **File,
+  IN  UINT64 OpenMode
+  )
+{
+  EFI_HANDLEHandle;
+  EFI_FILE_HANDLE   Root;
+  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL   *Volume;
+  EFI_STATUSStatus;
+
+  *File = NULL;
+
+  Status = gBS->LocateDevicePath (
+  &gEfiSimpleFileSystemProtocolGuid,
+  &Device,
+  &Handle
+);
+
+  if (EFI_ERROR (Status)) {
+return Status;
+  }
+
+  Status = gBS->HandleProtocol (
+  Handle,
+  &gEfiSimpleFileSystemProtocolGuid,
+  (VOID**)&Volume
+);
+  ASSERT_EFI_ERROR (Status);
+  if (EFI_ERROR (Status)) {
+return Status;
+  }
+
+  //
+  // Open the root directory of the volume
+  //
+  Root = NULL;
+  Status = Volume->OpenVolume (
+ Volume,
+ &Root
+   );
+  ASSERT_EFI_ERROR (Status);
+  ASSERT (Root != NULL);
+
+  //
+  // Open file
+  //
+  Status = Root->Open (
+   Root,
+   File,
+   MappedFile,
+   OpenMode,
+   0
+ );
+  if (EFI_ERROR (Status)) {
+*File = NULL;
+  }
+
+  //
+  // Close the Root directory
+  //
+  Root->Close (Root);
+  return Status;
+}
+
+
+EFI_STATUS
+CheckStore (
+  IN  EFI_HANDLE SimpleFileSystemHandle,
+  OUT EFI_DEVICE_PATH_PROTOCOL **Device
+  )
+{
+  EFI_STATUS Status;
+  EFI_BLOCK_IO_PROTOCOL *BlkIo;
+  EFI_FILE_PROTOCOL *File;
+
+  *Device = NULL;
+  Status = gBS->HandleProtocol (
+  SimpleFileSystemHandle,
+  &gEfiBlockIoProtocolGuid,
+  (VOID*)&BlkIo
+);
+
+  if (EFI_ERROR (Status)) {
+goto ErrHandle;
+  }
+  if (!BlkIo->Media->MediaPresent) {
+DEBUG ((DEBUG_ERROR, "FwhMappedFile: Media not present!\n"));
+Status = EFI_NO_MEDIA;
+goto ErrHandle;
+  }
+  if (BlkIo->Media->ReadOnly) {
+DEBUG ((DEBUG_ERROR, "FwhMappedFile: Media is read-only!\n"));
+Status = EFI_ACCESS_DENIED;
+goto ErrHandle;
+  }
+
+  Status = FileOpen (DevicePathFromHandle (SimpleFileSystemHandle),
+ mFvInstance->MappedFile, &File,
+ EFI_FILE_MODE_READ);
+  if (EFI_ERROR (Status)) {
+goto ErrHandle;
+  }
+
+  /* We found it! Maybe do more checks...? */
+
+  FileClose (File);
+  *Device = DuplicateDevicePath (DevicePathFromHandle 
(SimpleFileSystemHandle));
+
+  ASSERT (*Device != NULL);
+
+ErrHandle:
+  return Status;
+}
+
+
+EFI_STATUS
+CheckStoreExists (
+  IN  EFI_DEVICE_PATH_PROTOCOL *Device
+  )
+{
+  EFI_HANDLE Handle;
+  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Volume;
+  EFI_STATUS Status;
+
+  Status = gBS->LocateDevicePath (
+  &gEfiSimpleFileSystemProtocolGuid,
+  &Device,
+  &Handle
+ 

[edk2] [PATCH v3 edk2-platforms 11/23] Platform/Raspberry/Pi3: Add console driver

2019-01-28 Thread Pete Batard
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Pete Batard 
---
 Platform/Raspberry/Pi3/Drivers/GraphicsConsoleDxe/ComponentName.c 
|  183 ++
 Platform/Raspberry/Pi3/Drivers/GraphicsConsoleDxe/GraphicsConsole.c   
| 1837 
 Platform/Raspberry/Pi3/Drivers/GraphicsConsoleDxe/GraphicsConsole.h   
|  591 +++
 Platform/Raspberry/Pi3/Drivers/GraphicsConsoleDxe/GraphicsConsoleDxe.inf  
|   74 +
 Platform/Raspberry/Pi3/Drivers/GraphicsConsoleDxe/GraphicsConsoleDxe.uni  
|   18 +
 Platform/Raspberry/Pi3/Drivers/GraphicsConsoleDxe/GraphicsConsoleDxeExtra.uni 
|   18 +
 Platform/Raspberry/Pi3/Drivers/GraphicsConsoleDxe/NewFont.c   
|  287 +++
 Platform/Raspberry/Pi3/Include/Protocol/ExtendedTextOut.h 
|   36 +
 8 files changed, 3044 insertions(+)

diff --git a/Platform/Raspberry/Pi3/Drivers/GraphicsConsoleDxe/ComponentName.c 
b/Platform/Raspberry/Pi3/Drivers/GraphicsConsoleDxe/ComponentName.c
new file mode 100644
index ..3ae639ad3d97
--- /dev/null
+++ b/Platform/Raspberry/Pi3/Drivers/GraphicsConsoleDxe/ComponentName.c
@@ -0,0 +1,183 @@
+/** @file
+ *
+ *  Copyright (c) 2018, Andrei Warkentin 
+ *  Copyright (c) 2006-2016, Intel Corporation. All rights reserved.
+ *
+ *  This program and the accompanying materials
+ *  are licensed and made available under the terms and conditions of the BSD 
License
+ *  which accompanies this distribution.  The full text of the license may be 
found at
+ *  http://opensource.org/licenses/bsd-license.php
+ *
+ *  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
IMPLIED.
+ *
+ **/
+
+#include "GraphicsConsole.h"
+
+//
+// EFI Component Name Protocol
+//
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL  
gGraphicsConsoleComponentName = {
+  GraphicsConsoleComponentNameGetDriverName,
+  GraphicsConsoleComponentNameGetControllerName,
+  "eng"
+};
+
+//
+// EFI Component Name 2 Protocol
+//
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL 
gGraphicsConsoleComponentName2 = {
+  
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME)GraphicsConsoleComponentNameGetDriverName,
+  
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)GraphicsConsoleComponentNameGetControllerName,
+  "en"
+};
+
+
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE 
mGraphicsConsoleDriverNameTable[] = {
+  {
+"eng;en",
+(CHAR16*)L"Graphics Console Driver"
+  },
+  {
+NULL,
+NULL
+  }
+};
+
+/**
+  Retrieves a Unicode string that is the user readable name of the driver.
+
+  This function retrieves the user readable name of a driver in the form of a
+  Unicode string. If the driver specified by This has a user readable name in
+  the language specified by Language, then a pointer to the driver name is
+  returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
+  by This does not support the language specified by Language,
+  then EFI_UNSUPPORTED is returned.
+
+  @param  This[in]  A pointer to the EFI_COMPONENT_NAME2_PROTOCOL 
or
+EFI_COMPONENT_NAME_PROTOCOL instance.
+
+  @param  Language[in]  A pointer to a Null-terminated ASCII string
+array indicating the language. This is the
+language of the driver name that the caller is
+requesting, and it must match one of the
+languages specified in SupportedLanguages. The
+number of languages supported by a driver is up
+to the driver writer. Language is specified
+in RFC 4646 or ISO 639-2 language code format.
+
+  @param  DriverName[out]   A pointer to the Unicode string to return.
+This Unicode string is the name of the
+driver specified by This in the language
+specified by Language.
+
+  @retval EFI_SUCCESS   The Unicode string for the Driver specified by
+This and the language specified by Language was
+returned in DriverName.
+
+  @retval EFI_INVALID_PARAMETER Language is NULL.
+
+  @retval EFI_INVALID_PARAMETER DriverName is NULL.
+
+  @retval EFI_UNSUPPORTED   The driver specified by This does not support
+the language specified by Language.
+
+**/
+EFI_STATUS
+EFIAPI
+GraphicsConsoleComponentNameGetDriverName (
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,
+  IN  CHAR8*Language,
+  OUT CHAR16   **DriverName
+  )
+{
+  return LookupUnicodeString2 (
+   Language,
+   This->SupportedLanguages,
+   mGraphicsConsoleDriverNameTable,
+   DriverName,
+   (BO

[edk2] [PATCH v3 edk2-platforms 10/23] Platform/Raspberry/Pi3: Add display driver

2019-01-28 Thread Pete Batard
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Pete Batard 
---
 Platform/Raspberry/Pi3/Drivers/DisplayDxe/ComponentName.c | 222 +++
 Platform/Raspberry/Pi3/Drivers/DisplayDxe/DisplayDxe.c| 606 

 Platform/Raspberry/Pi3/Drivers/DisplayDxe/DisplayDxe.h|  42 ++
 Platform/Raspberry/Pi3/Drivers/DisplayDxe/DisplayDxe.inf  |  71 +++
 Platform/Raspberry/Pi3/Drivers/DisplayDxe/Screenshot.c| 375 
 5 files changed, 1316 insertions(+)

diff --git a/Platform/Raspberry/Pi3/Drivers/DisplayDxe/ComponentName.c 
b/Platform/Raspberry/Pi3/Drivers/DisplayDxe/ComponentName.c
new file mode 100644
index ..9a84aea511f4
--- /dev/null
+++ b/Platform/Raspberry/Pi3/Drivers/DisplayDxe/ComponentName.c
@@ -0,0 +1,222 @@
+/** @file
+ *
+ *  Copyright (c) 2018, Andrei Warkentin 
+ *  Copyright (c) 2006-2016, Intel Corporation. All rights reserved.
+ *
+ *  This program and the accompanying materials
+ *  are licensed and made available under the terms and conditions of the BSD 
License
+ *  which accompanies this distribution.  The full text of the license may be 
found at
+ *  http://opensource.org/licenses/bsd-license.php
+ *
+ *  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
IMPLIED.
+ *
+ **/
+
+#include "DisplayDxe.h"
+
+STATIC
+EFI_STATUS
+EFIAPI
+ComponentNameGetDriverName (
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,
+  IN  CHAR8*Language,
+  OUT CHAR16   **DriverName
+  );
+
+STATIC
+EFI_STATUS
+EFIAPI
+ComponentNameGetControllerName (
+  IN  EFI_COMPONENT_NAME_PROTOCOL *This,
+  IN  EFI_HANDLE  ControllerHandle,
+  IN  EFI_HANDLE  ChildHandle,
+  IN  CHAR8   *Language,
+  OUT CHAR16  **ControllerName
+  );
+
+//
+// EFI Component Name Protocol
+//
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gComponentName = {
+  ComponentNameGetDriverName,
+  ComponentNameGetControllerName,
+  "eng"
+};
+
+//
+// EFI Component Name 2 Protocol
+//
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gComponentName2 = {
+  (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)ComponentNameGetDriverName,
+  (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)ComponentNameGetControllerName,
+  "en"
+};
+
+
+STATIC EFI_UNICODE_STRING_TABLE mDriverName[] = {
+  {
+"eng;en",
+(CHAR16*)L"Raspberry Pi Display Driver"
+  },
+  {
+NULL,
+NULL
+  }
+};
+
+STATIC EFI_UNICODE_STRING_TABLE mDeviceName[] = {
+  {
+"eng;en",
+(CHAR16*)L"Raspberry Pi Framebuffer"
+  },
+  {
+NULL,
+NULL
+  }
+};
+
+/**
+  Retrieves a Unicode string that is the user readable name of the driver.
+
+  This function retrieves the user readable name of a driver in the form of a
+  Unicode string. If the driver specified by This has a user readable name in
+  the language specified by Language, then a pointer to the driver name is
+  returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
+  by This does not support the language specified by Language,
+  then EFI_UNSUPPORTED is returned.
+
+  @param  This[in]  A pointer to the EFI_COMPONENT_NAME2_PROTOCOL 
or
+EFI_COMPONENT_NAME_PROTOCOL instance.
+
+  @param  Language[in]  A pointer to a Null-terminated ASCII string
+array indicating the language. This is the
+language of the driver name that the caller is
+requesting, and it must match one of the
+languages specified in SupportedLanguages. The
+number of languages supported by a driver is up
+to the driver writer. Language is specified
+in RFC 4646 or ISO 639-2 language code format.
+
+  @param  DriverName[out]   A pointer to the Unicode string to return.
+This Unicode string is the name of the
+driver specified by This in the language
+specified by Language.
+
+  @retval EFI_SUCCESS   The Unicode string for the Driver specified by
+This and the language specified by Language was
+returned in DriverName.
+
+  @retval EFI_INVALID_PARAMETER Language is NULL.
+
+  @retval EFI_INVALID_PARAMETER DriverName is NULL.
+
+  @retval EFI_UNSUPPORTED   The driver specified by This does not support
+the language specified by Language.
+
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+ComponentNameGetDriverName (
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,
+  IN  CHAR8*Language,
+  OUT CHAR16   **DriverName
+  )
+{
+  return LookupUnicodeString2 (
+   

[edk2] [PATCH v3 edk2-platforms 09/23] Platform/Raspberry/Pi3: Add SMBIOS driver

2019-01-28 Thread Pete Batard
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Pete Batard 
---
 Platform/Raspberry/Pi3/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.c   | 903 

 Platform/Raspberry/Pi3/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.inf |  56 ++
 2 files changed, 959 insertions(+)

diff --git 
a/Platform/Raspberry/Pi3/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.c 
b/Platform/Raspberry/Pi3/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.c
new file mode 100644
index ..7707763e4332
--- /dev/null
+++ b/Platform/Raspberry/Pi3/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.c
@@ -0,0 +1,903 @@
+/** @file
+ *
+ *  Static SMBIOS Table for ARM platform
+ *  Derived from EmulatorPkg package
+ *
+ *  Note SMBIOS 2.7.1 Required structures:
+ *  BIOS Information (Type 0)
+ *  System Information (Type 1)
+ *  Board Information (Type 2)
+ *  System Enclosure (Type 3)
+ *  Processor Information (Type 4) - CPU Driver
+ *  Cache Information (Type 7) - For cache that is external to processor
+ *  System Slots (Type 9) - If system has slots
+ *  Physical Memory Array (Type 16)
+ *  Memory Device (Type 17) - For each socketed system-memory Device
+ *  Memory Array Mapped Address (Type 19) - One per contiguous block per 
Physical Memroy Array
+ *  System Boot Information (Type 32)
+ *
+ *  Copyright (c) 2017-2018, Andrey Warkentin 
+ *  Copyright (c) 2013, Linaro.org
+ *  Copyright (c) 2012, Apple Inc. All rights reserved.
+ *  Copyright (c) Microsoft Corporation. All rights reserved.
+ *
+ *  This program and the accompanying materials
+ *  are licensed and made available under the terms and conditions of the BSD 
License
+ *  which accompanies this distribution.  The full text of the license may be 
found at
+ *  http://opensource.org/licenses/bsd-license.php
+ *
+ *  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
IMPLIED.
+ *
+ **/
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+STATIC RASPBERRY_PI_FIRMWARE_PROTOCOL *mFwProtocol;
+
+/***
+SMBIOS data definition  TYPE0  BIOS Information
+/
+SMBIOS_TABLE_TYPE0 mBIOSInfoType0 = {
+  { EFI_SMBIOS_TYPE_BIOS_INFORMATION, sizeof (SMBIOS_TABLE_TYPE0), 0 },
+  1,// Vendor String
+  2,// BiosVersion String
+  0x0,  // BiosSegment
+  3,// BiosReleaseDate String
+  0x1F, // BiosSize
+  { // BiosCharacteristics
+0,//  Reserved  :2;  ///< Bits 0-1.
+0,//  Unknown   :1;
+0,//  BiosCharacteristicsNotSupported   :1;
+0,//  IsaIsSupported:1;
+0,//  McaIsSupported:1;
+0,//  EisaIsSupported   :1;
+0,//  PciIsSupported:1;
+0,//  PcmciaIsSupported :1;
+0,//  PlugAndPlayIsSupported:1;
+0,//  ApmIsSupported:1;
+0,//  BiosIsUpgradable  :1;
+0,//  BiosShadowingAllowed  :1;
+0,//  VlVesaIsSupported :1;
+0,//  EscdSupportIsAvailable:1;
+0,//  BootFromCdIsSupported :1;
+1,//  SelectableBootIsSupported :1;
+0,//  RomBiosIsSocketed :1;
+0,//  BootFromPcmciaIsSupported :1;
+0,//  EDDSpecificationIsSupported   :1;
+0,//  JapaneseNecFloppyIsSupported  :1;
+0,//  JapaneseToshibaFloppyIsSupported  :1;
+0,//  Floppy525_360IsSupported  :1;
+0,//  Floppy525_12IsSupported   :1;
+0,//  Floppy35_720IsSupported   :1;
+0,//  Floppy35_288IsSupported   :1;
+0,//  PrintScreenIsSupported:1;
+0,//  Keyboard8042IsSupported   :1;
+0,//  SerialIsSupported :1;
+0,//  PrinterIsSupported:1;
+0,//  CgaMonoIsSupported:1;
+0,//  NecPc98   :1;
+0 //  ReservedForVendor :32; ///< Bits 32-63. Bits 
32-47 reserved for BIOS vendor
+///< and bits 48-63 reserved for System Vendor.
+  },
+  {   // BIOSCharacteristicsExtensionBytes[]
+0x01, //  AcpiIsSupported   :1;
+  //  UsbLegacyIsSupported  :1;
+  //  AgpIsSupported:1;
+  //  I2OBootIsSupported:1;
+  //  Ls120BootIsSupported  :1;
+  //  AtapiZipDriveBootIsSupported  :1;
+  //  Boot1394IsSupported 

  1   2   >