[edk2] ArmVirtPkg Build Failure

2016-11-02 Thread Sajjan, Vikas C
 Hi All,

I get below build error when I tried building EDK2 for ArmVirtPkg

$ build -a AARCH64 -t GCC49 -p ArmVirtPkg/ArmVirtQemu.dsc

/home/vikas/tianacore/edk2/MdeModulePkg/Logo/Logo.c:34:5: error: ‘IMG_LOGO’ 
undeclared here (not in a function)
 IMAGE_TOKEN (IMG_LOGO),
 ^
make: *** 
[/home/vikas/tianacore/Build/ArmVirtQemu-AARCH64/DEBUG_GCC49/AARCH64/MdeModulePkg/Logo/LogoDxe/OUTPUT/Logo.obj]
 Error 1


build.py...
 : error 7000: Failed to execute command
make tbuild 
[/home/vikas/tianacore/Build/ArmVirtQemu-AARCH64/DEBUG_GCC49/AARCH64/MdeModulePkg/Logo/LogoDxe]


build.py...
 : error F002: Failed to build module
/home/vikas/tianacore/edk2/MdeModulePkg/Logo/LogoDxe.inf [AARCH64, 
GCC49, DEBUG]

- Failed -
Build end time: 10:12:42, Nov.03 2016
Build total time: 00:03:13

Let me I am missing something here.

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


Re: [edk2] [PATCH] BaseTools/Pkcs7: Add readme.md

2016-11-02 Thread Yao, Jiewen
Agree. Thanks!

From: Long, Qin
Sent: Thursday, November 3, 2016 11:19 AM
To: Yao, Jiewen ; edk2-devel@lists.01.org
Cc: Zhu, Yonghong ; Gao, Liming ; 
Kinney, Michael D 
Subject: RE: [PATCH] BaseTools/Pkcs7: Add readme.md

Hi, Jiewen,

Please update the "PKCS7 certificate chain" to "X.509 certificate chain".  The 
P7 certificate chain may be used as some different scope (e.g. .p7b for cert 
chain encapsulation.

For example:
"Step by step to generate PKCS7 certificate chain"  --> "Step by step to 
generate sample X.509 certificate chain and sign data with PKCS7 structure".
"How to generate PKCS7 certificate chain via OPENSSL" --> "How to generate 
X.509 certificate chain via OPENSSL"

The other steps looks good to me.

Reviewed-by: Qin Long >


Best Regards & Thanks,
LONG, Qin

> -Original Message-
> From: Yao, Jiewen
> Sent: Thursday, November 03, 2016 10:59 AM
> To: edk2-devel@lists.01.org
> Cc: Zhu, Yonghong; Gao, Liming; Kinney, Michael D; Long, Qin
> Subject: [PATCH] BaseTools/Pkcs7: Add readme.md
>
> Add readme.md to describe the PKCS7 certificate generation.
>
> Cc: Yonghong Zhu >
> Cc: Liming Gao >
> Cc: Michael D Kinney 
> >
> Cc: Qin Long >
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Jiewen Yao >
> ---
>  BaseTools/Source/Python/Pkcs7Sign/Readme.md | 84
> 
>  1 file changed, 84 insertions(+)
>
> diff --git a/BaseTools/Source/Python/Pkcs7Sign/Readme.md
> b/BaseTools/Source/Python/Pkcs7Sign/Readme.md
> new file mode 100644
> index 000..be5e63b
> --- /dev/null
> +++ b/BaseTools/Source/Python/Pkcs7Sign/Readme.md
> @@ -0,0 +1,84 @@
> +# Step by step to generate PKCS7 certificate chain

> +
> +This readme provides some samples to generate PKCS7 certificate chain
> step by step.
> +
> +## How to generate PKCS7 certificate chain via OPENSSL
> +* Set OPENSSL environment.
> +
> +NOTE: Below steps are required for Windows. Linux may already have the
> OPENSSL environment correctly.
> +
> +set OPENSSL_HOME=c:\home\openssl\openssl-[version]
> +set OPENSSL_CONF=%OPENSSL_HOME%\apps\openssl.cnf
> +
> +When a user uses OpenSSL (req or ca command) to generate the
> certificates, OpenSSL will use the openssl.cnf file as the configuration data
> (can use “-config path/to/openssl.cnf” to describe the specific config file).
> +
> +The user need check the openssl.cnf file, to find your CA path setting, e.g.
> check if the path exists in [ CA_default ] section.
> +
> +[ CA_default ]
> +dir = ./demoCA  # Where everything is kept
> +
> +You may need the following steps for initialization:
> +
> +rd ./demoCA /S/Q
> +mkdir ./demoCA
> +echo "" > ./demoCA/index.txt
> +echo 01 > ./demoCA/serial
> +mkdir ./demoCA/newcerts
> +
> +* Generate the certificate chain:
> +
> +NOTE: User MUST set a UNIQUE "Common Name" on the different
> certificate
> +
> +1) Test Root CA certificate:
> +
> +Generate key:
> +
> +openssl genrsa -aes256 -out TestRoot.key 2048
> +
> +Generate certificate:
> +
> +openssl req -new -x509 -days 3650 -key TestRoot.key -out TestRoot.crt
> +openssl x509 -in TestRoot.crt -out TestRoot.cer -outform DER
> +openssl x509 -inform DER -in TestRoot.cer -outform PEM -out
> TestRoot.pub.pem
> +
> +2) Test Sub certificate:
> +
> +Generate key:
> +
> +openssl genrsa -aes256 -out TestSub.key 2048
> +
> +Generate certificate:
> +
> +openssl req -new -days 3650 -key TestSub.key -out TestSub.csr
> +openssl ca -extensions v3_ca -in TestSub.csr -days 3650 -out TestSub.crt 
> -
> cert TestRoot.crt -keyfile TestRoot.key
> +openssl x509 -in TestSub.crt -out TestSub.cer -outform DER
> +openssl x509 -inform DER -in TestSub.cer -outform PEM -out
> TestSub.pub.pem
> +
> +3) Test user certificate:
> +
> +Generate key:
> +
> +openssl genrsa -aes256 -out TestCert.key 2048
> +
> +Generate certificate:
> +
> +openssl req -new -days 3650 -key TestCert.key -out TestCert.csr
> +openssl ca -in TestCert.csr -days 3650 -out TestCert.crt -cert 
> TestSub.crt -
> keyfile TestSub.key`
> +openssl x509 -in TestCert.crt -out TestCert.cer -outform DER
> +openssl x509 -inform DER -in TestCert.cer -outform PEM -out
> TestCert.pub.pem
> +
> +Convert Key and Certificate for signing (password is removed here via "-
> nodes")
> +
> +openssl pkcs12 -export -out TestCert.pfx -inkey TestCert.key -in
> TestCert.crt
> +openssl pkcs12 -in TestCert.pfx -nodes -out TestCert.pem
> +
> +* Verify
> +
> +1) Sign:
> +
> +openssl smime -sign -binary -signer 

Re: [edk2] [PATCH] BaseTools/Pkcs7: Add readme.md

2016-11-02 Thread Long, Qin
Hi, Jiewen,

Please update the "PKCS7 certificate chain" to "X.509 certificate chain".  The 
P7 certificate chain may be used as some different scope (e.g. .p7b for cert 
chain encapsulation. 

For example:
"Step by step to generate PKCS7 certificate chain"  --> "Step by step to 
generate sample X.509 certificate chain and sign data with PKCS7 structure". 
"How to generate PKCS7 certificate chain via OPENSSL" --> "How to generate 
X.509 certificate chain via OPENSSL"

The other steps looks good to me.

Reviewed-by: Qin Long 


Best Regards & Thanks,
LONG, Qin

> -Original Message-
> From: Yao, Jiewen
> Sent: Thursday, November 03, 2016 10:59 AM
> To: edk2-devel@lists.01.org
> Cc: Zhu, Yonghong; Gao, Liming; Kinney, Michael D; Long, Qin
> Subject: [PATCH] BaseTools/Pkcs7: Add readme.md
> 
> Add readme.md to describe the PKCS7 certificate generation.
> 
> Cc: Yonghong Zhu 
> Cc: Liming Gao 
> Cc: Michael D Kinney 
> Cc: Qin Long 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Jiewen Yao 
> ---
>  BaseTools/Source/Python/Pkcs7Sign/Readme.md | 84
> 
>  1 file changed, 84 insertions(+)
> 
> diff --git a/BaseTools/Source/Python/Pkcs7Sign/Readme.md
> b/BaseTools/Source/Python/Pkcs7Sign/Readme.md
> new file mode 100644
> index 000..be5e63b
> --- /dev/null
> +++ b/BaseTools/Source/Python/Pkcs7Sign/Readme.md
> @@ -0,0 +1,84 @@
> +# Step by step to generate PKCS7 certificate chain
  
> +
> +This readme provides some samples to generate PKCS7 certificate chain
> step by step.
> +
> +## How to generate PKCS7 certificate chain via OPENSSL
> +* Set OPENSSL environment.
> +
> +NOTE: Below steps are required for Windows. Linux may already have the
> OPENSSL environment correctly.
> +
> +set OPENSSL_HOME=c:\home\openssl\openssl-[version]
> +set OPENSSL_CONF=%OPENSSL_HOME%\apps\openssl.cnf
> +
> +When a user uses OpenSSL (req or ca command) to generate the
> certificates, OpenSSL will use the openssl.cnf file as the configuration data
> (can use “-config path/to/openssl.cnf” to describe the specific config file).
> +
> +The user need check the openssl.cnf file, to find your CA path setting, e.g.
> check if the path exists in [ CA_default ] section.
> +
> +[ CA_default ]
> +dir = ./demoCA  # Where everything is kept
> +
> +You may need the following steps for initialization:
> +
> +rd ./demoCA /S/Q
> +mkdir ./demoCA
> +echo "" > ./demoCA/index.txt
> +echo 01 > ./demoCA/serial
> +mkdir ./demoCA/newcerts
> +
> +* Generate the certificate chain:
> +
> +NOTE: User MUST set a UNIQUE "Common Name" on the different
> certificate
> +
> +1) Test Root CA certificate:
> +
> +Generate key:
> +
> +openssl genrsa -aes256 -out TestRoot.key 2048
> +
> +Generate certificate:
> +
> +openssl req -new -x509 -days 3650 -key TestRoot.key -out TestRoot.crt
> +openssl x509 -in TestRoot.crt -out TestRoot.cer -outform DER
> +openssl x509 -inform DER -in TestRoot.cer -outform PEM -out
> TestRoot.pub.pem
> +
> +2) Test Sub certificate:
> +
> +Generate key:
> +
> +openssl genrsa -aes256 -out TestSub.key 2048
> +
> +Generate certificate:
> +
> +openssl req -new -days 3650 -key TestSub.key -out TestSub.csr
> +openssl ca -extensions v3_ca -in TestSub.csr -days 3650 -out TestSub.crt 
> -
> cert TestRoot.crt -keyfile TestRoot.key
> +openssl x509 -in TestSub.crt -out TestSub.cer -outform DER
> +openssl x509 -inform DER -in TestSub.cer -outform PEM -out
> TestSub.pub.pem
> +
> +3) Test user certificate:
> +
> +Generate key:
> +
> +openssl genrsa -aes256 -out TestCert.key 2048
> +
> +Generate certificate:
> +
> +openssl req -new -days 3650 -key TestCert.key -out TestCert.csr
> +openssl ca -in TestCert.csr -days 3650 -out TestCert.crt -cert 
> TestSub.crt -
> keyfile TestSub.key`
> +openssl x509 -in TestCert.crt -out TestCert.cer -outform DER
> +openssl x509 -inform DER -in TestCert.cer -outform PEM -out
> TestCert.pub.pem
> +
> +Convert Key and Certificate for signing (password is removed here via "-
> nodes")
> +
> +openssl pkcs12 -export -out TestCert.pfx -inkey TestCert.key -in
> TestCert.crt
> +openssl pkcs12 -in TestCert.pfx -nodes -out TestCert.pem
> +
> +* Verify
> +
> +1) Sign:
> +
> +openssl smime -sign -binary -signer TestCert.pem -outform DER -md
> sha256 -certfile TestSub.pub.pem -out test.bin.p7 -in test.bin
> +
> +2) Verify:
> +
> +openssl smime -verify -inform DER -in test.bin.p7 -content test.bin 
> -CAfile
> TestRoot.pub.pem -out test.org.bin
> +
> --
> 2.7.4.windows.1

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


Re: [edk2] [PATCH] MdeModulePkg/PCD: Fix PcdGetNextToken may get a wrong PCD token

2016-11-02 Thread Zeng, Star
Reviewed-by: Star Zeng 
And pushed at bfb4c2ba3742b61ef778e07957ff1b26b5a159b5.

Thanks for the contribution.
Star
-Original Message-
From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Cinnamon 
Shia
Sent: Wednesday, November 2, 2016 10:41 AM
To: edk2-devel@lists.01.org
Cc: Tian, Feng ; Zeng, Star 
Subject: [edk2] [PATCH] MdeModulePkg/PCD: Fix PcdGetNextToken may get a wrong 
PCD token

If there are two DynamicEx PCDs have the same PCD token number but in different 
PCD token spaces, the PcdGetNextToken function may get the wrong PCD token.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Cinnamon Shia 
---
 MdeModulePkg/Universal/PCD/Dxe/Service.c |  3 ++-
 MdeModulePkg/Universal/PCD/Pei/Pcd.c | 21 +
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/MdeModulePkg/Universal/PCD/Dxe/Service.c 
b/MdeModulePkg/Universal/PCD/Dxe/Service.c
index 6d0b0f8..bf77130 100644
--- a/MdeModulePkg/Universal/PCD/Dxe/Service.c
+++ b/MdeModulePkg/Universal/PCD/Dxe/Service.c
@@ -3,6 +3,7 @@
 
 Copyright (c) 2014, Hewlett-Packard Development Company, L.P.  Copyright 
(c) 2006 - 2016, Intel Corporation. All rights reserved.
+(C) Copyright 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  which accompanies this 
distribution.  The full text of the license may be found at @@ -715,7 +716,7 @@ 
ExGetNextTokeNumber (
 }
 
 for ( ; Index < ExMapTableCount; Index++) {
-  if (ExMapTable[Index].ExTokenNumber == *TokenNumber) {
+  if ((ExMapTable[Index].ExTokenNumber == *TokenNumber) && 
+ (ExMapTable[Index].ExGuidIndex == GuidTableIdx)) {
 break;
   }
 }
diff --git a/MdeModulePkg/Universal/PCD/Pei/Pcd.c 
b/MdeModulePkg/Universal/PCD/Pei/Pcd.c
index 7a486b7..668860b 100644
--- a/MdeModulePkg/Universal/PCD/Pei/Pcd.c
+++ b/MdeModulePkg/Universal/PCD/Pei/Pcd.c
@@ -2,13 +2,14 @@
   All Pcd Ppi services are implemented here.
   
 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.  
   
+(C) Copyright 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 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.
 
 **/
 
@@ -1116,13 +1117,17 @@ PeiPcdGetNextToken (
 }
 
 if (Found) {
+  //
+  // If given token number is PCD_INVALID_TOKEN_NUMBER, then return the 
first
+  // token number in found token space.
+  //
   if (*TokenNumber == PCD_INVALID_TOKEN_NUMBER) {
 *TokenNumber = ExMapTable[Index].ExTokenNumber;
  return EFI_SUCCESS;
   }
 
   for ( ; Index < PeiPcdDb->ExTokenCount; Index++) {
-if (ExMapTable[Index].ExTokenNumber == *TokenNumber) {
+if ((ExMapTable[Index].ExTokenNumber == *TokenNumber) && 
+ (ExMapTable[Index].ExGuidIndex == GuidTableIdx)) {
   break;
 }
   }
--
2.10.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] BaseTools/Pkcs7: Add readme.md

2016-11-02 Thread Jiewen Yao
Add readme.md to describe the PKCS7 certificate generation.

Cc: Yonghong Zhu 
Cc: Liming Gao 
Cc: Michael D Kinney 
Cc: Qin Long 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
---
 BaseTools/Source/Python/Pkcs7Sign/Readme.md | 84 
 1 file changed, 84 insertions(+)

diff --git a/BaseTools/Source/Python/Pkcs7Sign/Readme.md 
b/BaseTools/Source/Python/Pkcs7Sign/Readme.md
new file mode 100644
index 000..be5e63b
--- /dev/null
+++ b/BaseTools/Source/Python/Pkcs7Sign/Readme.md
@@ -0,0 +1,84 @@
+# Step by step to generate PKCS7 certificate chain
+
+This readme provides some samples to generate PKCS7 certificate chain step by 
step.
+
+## How to generate PKCS7 certificate chain via OPENSSL
+* Set OPENSSL environment.
+
+NOTE: Below steps are required for Windows. Linux may already have the OPENSSL 
environment correctly.
+
+set OPENSSL_HOME=c:\home\openssl\openssl-[version]
+set OPENSSL_CONF=%OPENSSL_HOME%\apps\openssl.cnf
+
+When a user uses OpenSSL (req or ca command) to generate the certificates, 
OpenSSL will use the openssl.cnf file as the configuration data (can use 
“-config path/to/openssl.cnf” to describe the specific config file).
+
+The user need check the openssl.cnf file, to find your CA path setting, e.g. 
check if the path exists in [ CA_default ] section.
+
+[ CA_default ]
+dir = ./demoCA  # Where everything is kept
+
+You may need the following steps for initialization:
+
+rd ./demoCA /S/Q
+mkdir ./demoCA
+echo "" > ./demoCA/index.txt
+echo 01 > ./demoCA/serial
+mkdir ./demoCA/newcerts
+
+* Generate the certificate chain:
+
+NOTE: User MUST set a UNIQUE "Common Name" on the different certificate
+
+1) Test Root CA certificate:
+
+Generate key:
+
+openssl genrsa -aes256 -out TestRoot.key 2048
+
+Generate certificate:
+
+openssl req -new -x509 -days 3650 -key TestRoot.key -out TestRoot.crt
+openssl x509 -in TestRoot.crt -out TestRoot.cer -outform DER
+openssl x509 -inform DER -in TestRoot.cer -outform PEM -out 
TestRoot.pub.pem
+
+2) Test Sub certificate:
+
+Generate key:
+
+openssl genrsa -aes256 -out TestSub.key 2048
+
+Generate certificate:
+
+openssl req -new -days 3650 -key TestSub.key -out TestSub.csr
+openssl ca -extensions v3_ca -in TestSub.csr -days 3650 -out TestSub.crt 
-cert TestRoot.crt -keyfile TestRoot.key
+openssl x509 -in TestSub.crt -out TestSub.cer -outform DER
+openssl x509 -inform DER -in TestSub.cer -outform PEM -out TestSub.pub.pem
+
+3) Test user certificate:
+
+Generate key:
+
+openssl genrsa -aes256 -out TestCert.key 2048
+
+Generate certificate:
+
+openssl req -new -days 3650 -key TestCert.key -out TestCert.csr
+openssl ca -in TestCert.csr -days 3650 -out TestCert.crt -cert TestSub.crt 
-keyfile TestSub.key`
+openssl x509 -in TestCert.crt -out TestCert.cer -outform DER
+openssl x509 -inform DER -in TestCert.cer -outform PEM -out 
TestCert.pub.pem
+
+Convert Key and Certificate for signing (password is removed here via "-nodes")
+
+openssl pkcs12 -export -out TestCert.pfx -inkey TestCert.key -in 
TestCert.crt
+openssl pkcs12 -in TestCert.pfx -nodes -out TestCert.pem
+
+* Verify
+
+1) Sign:
+
+openssl smime -sign -binary -signer TestCert.pem -outform DER -md sha256 
-certfile TestSub.pub.pem -out test.bin.p7 -in test.bin
+
+2) Verify:
+
+openssl smime -verify -inform DER -in test.bin.p7 -content test.bin 
-CAfile TestRoot.pub.pem -out test.org.bin
+
-- 
2.7.4.windows.1

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


Re: [edk2] [PATCH V3] MdePkg/BaseLib: Move CHAR_NULL definition to Base.h in BaseLib

2016-11-02 Thread Gao, Liming
Reviewed-by: Liming Gao 

> -Original Message-
> From: Song, BinX
> Sent: Thursday, November 03, 2016 10:33 AM
> To: edk2-devel@lists.01.org
> Cc: Gao, Liming 
> Subject: [PATCH V3] MdePkg/BaseLib: Move CHAR_NULL definition to
> Base.h in BaseLib
> 
> - Required unicode control chars -> Null character
> - Remove CHAR_NULL definition in SimpleTextIn.h
> - https://bugzilla.tianocore.org/show_bug.cgi?id=172
> 
> Cc: Liming Gao 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Bell Song 
> ---
>  MdePkg/Include/Base.h  | 5 +
>  MdePkg/Include/Protocol/SimpleTextIn.h | 1 -
>  MdePkg/Library/BaseLib/FilePaths.c | 2 --
>  3 files changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h
> index 2217058..5e24b5d 100644
> --- a/MdePkg/Include/Base.h
> +++ b/MdePkg/Include/Base.h
> @@ -338,6 +338,11 @@ struct _LIST_ENTRY {
>  ///
>  #define NULL  ((VOID *) 0)
> 
> +//
> +// Null character
> +//
> +#define CHAR_NULL 0x
> +
>  ///
>  /// Maximum values for common UEFI Data Types
>  ///
> diff --git a/MdePkg/Include/Protocol/SimpleTextIn.h
> b/MdePkg/Include/Protocol/SimpleTextIn.h
> index 71dcb0b..ebe1c7e 100644
> --- a/MdePkg/Include/Protocol/SimpleTextIn.h
> +++ b/MdePkg/Include/Protocol/SimpleTextIn.h
> @@ -46,7 +46,6 @@ typedef struct {
>  //
>  // Required unicode control chars
>  //
> -#define CHAR_NULL 0x
>  #define CHAR_BACKSPACE0x0008
>  #define CHAR_TAB  0x0009
>  #define CHAR_LINEFEED 0x000A
> diff --git a/MdePkg/Library/BaseLib/FilePaths.c
> b/MdePkg/Library/BaseLib/FilePaths.c
> index c8da6bb..183b323 100644
> --- a/MdePkg/Library/BaseLib/FilePaths.c
> +++ b/MdePkg/Library/BaseLib/FilePaths.c
> @@ -10,10 +10,8 @@
>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  
> 
>  /**
>Removes the last directory or file entry in a path by changing the last
> --
> 2.7.2.windows.1

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


[edk2] [PATCH V3] MdePkg/BaseLib: Move CHAR_NULL definition to Base.h in BaseLib

2016-11-02 Thread Song, BinX
- Required unicode control chars -> Null character
- Remove CHAR_NULL definition in SimpleTextIn.h
- https://bugzilla.tianocore.org/show_bug.cgi?id=172

Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Bell Song 
---
 MdePkg/Include/Base.h  | 5 +
 MdePkg/Include/Protocol/SimpleTextIn.h | 1 -
 MdePkg/Library/BaseLib/FilePaths.c | 2 --
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h
index 2217058..5e24b5d 100644
--- a/MdePkg/Include/Base.h
+++ b/MdePkg/Include/Base.h
@@ -338,6 +338,11 @@ struct _LIST_ENTRY {
 ///
 #define NULL  ((VOID *) 0)
 
+//
+// Null character
+//
+#define CHAR_NULL 0x
+
 ///
 /// Maximum values for common UEFI Data Types
 ///
diff --git a/MdePkg/Include/Protocol/SimpleTextIn.h 
b/MdePkg/Include/Protocol/SimpleTextIn.h
index 71dcb0b..ebe1c7e 100644
--- a/MdePkg/Include/Protocol/SimpleTextIn.h
+++ b/MdePkg/Include/Protocol/SimpleTextIn.h
@@ -46,7 +46,6 @@ typedef struct {
 //
 // Required unicode control chars
 //
-#define CHAR_NULL 0x
 #define CHAR_BACKSPACE0x0008
 #define CHAR_TAB  0x0009
 #define CHAR_LINEFEED 0x000A
diff --git a/MdePkg/Library/BaseLib/FilePaths.c 
b/MdePkg/Library/BaseLib/FilePaths.c
index c8da6bb..183b323 100644
--- a/MdePkg/Library/BaseLib/FilePaths.c
+++ b/MdePkg/Library/BaseLib/FilePaths.c
@@ -10,10 +10,8 @@
   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  
 
 /**
   Removes the last directory or file entry in a path by changing the last
-- 
2.7.2.windows.1

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


Re: [edk2] [PATCH] MdePkg/BaseLib: Move CHAR_NULL definition to Base.h in BaseLib

2016-11-02 Thread Song, BinX
Hi Liming,

Got it, I will update again.

Best Regards,
Bell Song

> -Original Message-
> From: Gao, Liming
> Sent: Thursday, November 3, 2016 9:56 AM
> To: Song, BinX ; edk2-devel@lists.01.org
> Subject: RE: [PATCH] MdePkg/BaseLib: Move CHAR_NULL definition to
> Base.h in BaseLib
> 
> Bin:
>   On CHAR_NULL definition in Base.h, its comment should be Null character.
> And, for the second version patch, you need change title to PATCH V2, and
> describe what changes in V2.
> 
> > +//
> > +// Required unicode control chars  ==> Null character
> > +//
> > +#define CHAR_NULL 0x
> 
> Thanks
> Liming
> > -Original Message-
> > From: Song, BinX
> > Sent: Thursday, November 03, 2016 9:31 AM
> > To: edk2-devel@lists.01.org
> > Cc: Gao, Liming 
> > Subject: [PATCH] MdePkg/BaseLib: Move CHAR_NULL definition to Base.h
> in
> > BaseLib
> >
> > - https://bugzilla.tianocore.org/show_bug.cgi?id=172
> >
> > Cc: Liming Gao 
> > Contributed-under: TianoCore Contribution Agreement 1.0
> > Signed-off-by: Bell Song 
> > ---
> >  MdePkg/Include/Base.h  | 5 +
> >  MdePkg/Include/Protocol/SimpleTextIn.h | 1 -
> >  MdePkg/Library/BaseLib/FilePaths.c | 2 --
> >  3 files changed, 5 insertions(+), 3 deletions(-)
> >
> > diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h
> > index 2217058..2441875 100644
> > --- a/MdePkg/Include/Base.h
> > +++ b/MdePkg/Include/Base.h
> > @@ -338,6 +338,11 @@ struct _LIST_ENTRY {
> >  ///
> >  #define NULL  ((VOID *) 0)
> >
> > +//
> > +// Required unicode control chars
> > +//
> > +#define CHAR_NULL 0x
> > +
> >  ///
> >  /// Maximum values for common UEFI Data Types
> >  ///
> > diff --git a/MdePkg/Include/Protocol/SimpleTextIn.h
> > b/MdePkg/Include/Protocol/SimpleTextIn.h
> > index 71dcb0b..ebe1c7e 100644
> > --- a/MdePkg/Include/Protocol/SimpleTextIn.h
> > +++ b/MdePkg/Include/Protocol/SimpleTextIn.h
> > @@ -46,7 +46,6 @@ typedef struct {
> >  //
> >  // Required unicode control chars
> >  //
> > -#define CHAR_NULL 0x
> >  #define CHAR_BACKSPACE0x0008
> >  #define CHAR_TAB  0x0009
> >  #define CHAR_LINEFEED 0x000A
> > diff --git a/MdePkg/Library/BaseLib/FilePaths.c
> > b/MdePkg/Library/BaseLib/FilePaths.c
> > index c8da6bb..183b323 100644
> > --- a/MdePkg/Library/BaseLib/FilePaths.c
> > +++ b/MdePkg/Library/BaseLib/FilePaths.c
> > @@ -10,10 +10,8 @@
> >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  
> >
> >  /**
> >Removes the last directory or file entry in a path by changing the last
> > --
> > 2.7.2.windows.1

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


Re: [edk2] [PATCH] MdePkg/BaseLib: Move CHAR_NULL definition to Base.h in BaseLib

2016-11-02 Thread Gao, Liming
Bin:
  On CHAR_NULL definition in Base.h, its comment should be Null character. And, 
for the second version patch, you need change title to PATCH V2, and describe 
what changes in V2. 

> +//
> +// Required unicode control chars  ==> Null character
> +//
> +#define CHAR_NULL 0x

Thanks
Liming
> -Original Message-
> From: Song, BinX
> Sent: Thursday, November 03, 2016 9:31 AM
> To: edk2-devel@lists.01.org
> Cc: Gao, Liming 
> Subject: [PATCH] MdePkg/BaseLib: Move CHAR_NULL definition to Base.h in
> BaseLib
> 
> - https://bugzilla.tianocore.org/show_bug.cgi?id=172
> 
> Cc: Liming Gao 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Bell Song 
> ---
>  MdePkg/Include/Base.h  | 5 +
>  MdePkg/Include/Protocol/SimpleTextIn.h | 1 -
>  MdePkg/Library/BaseLib/FilePaths.c | 2 --
>  3 files changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h
> index 2217058..2441875 100644
> --- a/MdePkg/Include/Base.h
> +++ b/MdePkg/Include/Base.h
> @@ -338,6 +338,11 @@ struct _LIST_ENTRY {
>  ///
>  #define NULL  ((VOID *) 0)
> 
> +//
> +// Required unicode control chars
> +//
> +#define CHAR_NULL 0x
> +
>  ///
>  /// Maximum values for common UEFI Data Types
>  ///
> diff --git a/MdePkg/Include/Protocol/SimpleTextIn.h
> b/MdePkg/Include/Protocol/SimpleTextIn.h
> index 71dcb0b..ebe1c7e 100644
> --- a/MdePkg/Include/Protocol/SimpleTextIn.h
> +++ b/MdePkg/Include/Protocol/SimpleTextIn.h
> @@ -46,7 +46,6 @@ typedef struct {
>  //
>  // Required unicode control chars
>  //
> -#define CHAR_NULL 0x
>  #define CHAR_BACKSPACE0x0008
>  #define CHAR_TAB  0x0009
>  #define CHAR_LINEFEED 0x000A
> diff --git a/MdePkg/Library/BaseLib/FilePaths.c
> b/MdePkg/Library/BaseLib/FilePaths.c
> index c8da6bb..183b323 100644
> --- a/MdePkg/Library/BaseLib/FilePaths.c
> +++ b/MdePkg/Library/BaseLib/FilePaths.c
> @@ -10,10 +10,8 @@
>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  
> 
>  /**
>Removes the last directory or file entry in a path by changing the last
> --
> 2.7.2.windows.1

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


[edk2] [PATCH] MdePkg/BaseLib: Move CHAR_NULL definition to Base.h in BaseLib

2016-11-02 Thread Song, BinX
- https://bugzilla.tianocore.org/show_bug.cgi?id=172

Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Bell Song 
---
 MdePkg/Include/Base.h  | 5 +
 MdePkg/Include/Protocol/SimpleTextIn.h | 1 -
 MdePkg/Library/BaseLib/FilePaths.c | 2 --
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h
index 2217058..2441875 100644
--- a/MdePkg/Include/Base.h
+++ b/MdePkg/Include/Base.h
@@ -338,6 +338,11 @@ struct _LIST_ENTRY {
 ///
 #define NULL  ((VOID *) 0)
 
+//
+// Required unicode control chars
+//
+#define CHAR_NULL 0x
+
 ///
 /// Maximum values for common UEFI Data Types
 ///
diff --git a/MdePkg/Include/Protocol/SimpleTextIn.h 
b/MdePkg/Include/Protocol/SimpleTextIn.h
index 71dcb0b..ebe1c7e 100644
--- a/MdePkg/Include/Protocol/SimpleTextIn.h
+++ b/MdePkg/Include/Protocol/SimpleTextIn.h
@@ -46,7 +46,6 @@ typedef struct {
 //
 // Required unicode control chars
 //
-#define CHAR_NULL 0x
 #define CHAR_BACKSPACE0x0008
 #define CHAR_TAB  0x0009
 #define CHAR_LINEFEED 0x000A
diff --git a/MdePkg/Library/BaseLib/FilePaths.c 
b/MdePkg/Library/BaseLib/FilePaths.c
index c8da6bb..183b323 100644
--- a/MdePkg/Library/BaseLib/FilePaths.c
+++ b/MdePkg/Library/BaseLib/FilePaths.c
@@ -10,10 +10,8 @@
   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  
 
 /**
   Removes the last directory or file entry in a path by changing the last
-- 
2.7.2.windows.1

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


Re: [edk2] [PATCH] MdePkg/BaseLib: Re-define CHAR_NULL in BaseLib

2016-11-02 Thread Song, BinX
Hi Liming,

Thanks for your info, I will update.

Best Regards,
Bell Song

> -Original Message-
> From: Gao, Liming
> Sent: Wednesday, November 2, 2016 4:44 PM
> To: Song, BinX ; edk2-devel@lists.01.org
> Subject: RE: [PATCH] MdePkg/BaseLib: Re-define CHAR_NULL in BaseLib
> 
> Bin:
>   I suggest move CHAR_NULL definition from Protocol\SimpleTextIn.h to
> Base.h
> 
> Thanks
> Liming
> -Original Message-
> From: Song, BinX
> Sent: Wednesday, November 2, 2016 4:27 PM
> To: edk2-devel@lists.01.org
> Cc: Gao, Liming 
> Subject: [PATCH] MdePkg/BaseLib: Re-define CHAR_NULL in BaseLib
> 
> - https://bugzilla.tianocore.org/show_bug.cgi?id=172
> 
> Cc: Liming Gao 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Bell Song 
> ---
>  MdePkg/Include/Base.h  | 7 +++
>  MdePkg/Library/BaseLib/FilePaths.c | 2 --
>  2 files changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h
> index 2217058..0c3318f 100644
> --- a/MdePkg/Include/Base.h
> +++ b/MdePkg/Include/Base.h
> @@ -338,6 +338,13 @@ struct _LIST_ENTRY {
>  ///
>  #define NULL  ((VOID *) 0)
> 
> +//
> +// Required unicode control chars
> +//
> +#ifndef CHAR_NULL
> +#define CHAR_NULL  0x
> +#endif
> +
>  ///
>  /// Maximum values for common UEFI Data Types
>  ///
> diff --git a/MdePkg/Library/BaseLib/FilePaths.c
> b/MdePkg/Library/BaseLib/FilePaths.c
> index c8da6bb..183b323 100644
> --- a/MdePkg/Library/BaseLib/FilePaths.c
> +++ b/MdePkg/Library/BaseLib/FilePaths.c
> @@ -10,10 +10,8 @@
>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  
> 
>  /**
>Removes the last directory or file entry in a path by changing the last
> --
> 2.7.2.windows.1

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


Re: [edk2] [PATCH v1 1/1] OvmfPkg/ResetVector: Depend on PCD values of the page tables.

2016-11-02 Thread Laszlo Ersek
On 11/03/16 00:26, Laszlo Ersek wrote:
> On 11/02/16 23:31, Jordan Justen wrote:
>> The "v1 1/1" isn't needed in the subject. For the first version of a
>> single patch series, I would expect to just see [PATCH]. (Obviously
>> this is not too important.)
> 
> (I think the "v1" implies that Marvin expects to send a v2.)
> 
>> Email headers seem to indicate that you aren't using git send-email.
>> This will cause troubles if someday you have a multi-patch series.
>>
>> On 2016-11-02 11:00:34, Marvin Häuser wrote:
>>>
>>> diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm 
>>> b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
>>>  
>>>  ;
>>>  ; Top level Page Directory Pointers (1 * 512GB entry)
>>>  ;
>>> -mov dword[0x80], 0x801000 + PAGE_PDP_ATTR
>>> +mov dword[OVMF_SEC_PAGE_TABLES_BASE], OVMF_SEC_PAGE_TABLES_BASE + 
>>> 0x1000 + PAGE_PDP_ATTR
>>>  
>>>  ;
>>>  ; Next level Page Directory Pointers (4 * 1GB entries => 4GB)
>>>  ;
>>> -mov dword[0x801000], 0x802000 + PAGE_PDP_ATTR
>>> -mov dword[0x801008], 0x803000 + PAGE_PDP_ATTR
>>> -mov dword[0x801010], 0x804000 + PAGE_PDP_ATTR
>>> -mov dword[0x801018], 0x805000 + PAGE_PDP_ATTR
>>> +mov dword[OVMF_SEC_PAGE_TABLES_BASE + 0x1000], 
>>> OVMF_SEC_PAGE_TABLES_BASE + 0x2000 + PAGE_PDP_ATTR
>>> +mov dword[OVMF_SEC_PAGE_TABLES_BASE + 0x1008], 
>>> OVMF_SEC_PAGE_TABLES_BASE + 0x3000 + PAGE_PDP_ATTR
>>> +mov dword[OVMF_SEC_PAGE_TABLES_BASE + 0x1010], 
>>> OVMF_SEC_PAGE_TABLES_BASE + 0x4000 + PAGE_PDP_ATTR
>>> +mov dword[OVMF_SEC_PAGE_TABLES_BASE + 0x1018], 
>>> OVMF_SEC_PAGE_TABLES_BASE + 0x5000 + PAGE_PDP_ATTR
>>
>> These line are too long. I guess you can use '\' at the end of a line
>> to continue it, or maybe add a PT_ADDR() macro that adds in
>> OVMF_SEC_PAGE_TABLES_BASE.
>>
>>> diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb 
>>> b/OvmfPkg/ResetVector/ResetVector.nasmb
>>> index 31ac06a..b47f647 100644
>>> --- a/OvmfPkg/ResetVector/ResetVector.nasmb
>>> +++ b/OvmfPkg/ResetVector/ResetVector.nasmb
>>> @@ -53,6 +53,12 @@
>>>  %include "Ia32/SearchForSecEntry.asm"
>>>  
>>>  %ifdef ARCH_X64
>>> +  %ifndef OVMF_SEC_PAGE_TABLES_BASE
>>> +#include 
>>> +%define OVMF_SEC_PAGE_TABLES_BASE FixedPcdGet32 
>>> (PcdOvmfSecPageTablesBase)
>>> +%define OVMF_SEC_PAGE_TABLES_SIZE FixedPcdGet32 
>>> (PcdOvmfSecPageTablesSize)
>>> +  %endif
>>> +
>>>  %include "Ia32/Flat32ToFlat64.asm"
>>>  %include "Ia32/PageTables64.asm"
>>>  %endif
>>> diff --git a/OvmfPkg/ResetVector/ResetVectorCode.asm 
>>> b/OvmfPkg/ResetVector/ResetVectorCode.asm
>>> index 052c821..5b49387 100644
>>> --- a/OvmfPkg/ResetVector/ResetVectorCode.asm
>>> +++ b/OvmfPkg/ResetVector/ResetVectorCode.asm
>>> @@ -40,6 +40,15 @@
>>>  %include "Ia32/SearchForSecEntry.asm"
>>>  
>>>  %ifdef ARCH_X64
>>> +  %ifndef OVMF_SEC_PAGE_TABLES_BASE
>>> +;
>>> +; This range should match with PcdOvmfSecPageTablesBase and
>>> +; PcdOvmfSecPageTablesSize which are declared in the FDF files.
>>> +   ;
>>> +%define OVMF_SEC_PAGE_TABLES_BASE 0x80
>>> +%define OVMF_SEC_PAGE_TABLES_SIZE 6 * 0x1000
>>
>> I thought we were using the PCDs?
> 
> We were, yes, except where we couldn't. For the reset vector, our "root"
> file is
> 
>   OvmfPkg/ResetVector/ResetVector.nasmb
> 
> (referenced by
> 
>   OvmfPkg/ResetVector/ResetVector.inf
> 
> )
> 
> That nasmb file %include's a bunch of other files; among those,
> 
>   OvmfPkg/ResetVector/Ia32/PageTables64.asm
> 
> Notice that the %include and %define directives in these files are
> NASM-native directives; they aren't C preprocessor directives. So we
> couldn't use FixedPcdGetXX() in the source code.
> 
> If I remember correctly, in commit b382ede3864e ("OvmfPkg X64
> ResetVector: Move page tables from 512KB to 8MB"), you added the PCD
> references in a source code comment because this way at least a "grep"
> would find them, and then the programmer could update the constants (if
> necessary).
> 
> Note that in the era of commit b382ede3864e (2014-Jan-21), we used to
> compile the reset vector manually, with the utility
> 
>   OvmfPkg/ResetVector/Build.py
> 
> On 2014-Aug-19 however, you added native NASMB support to BaseTools, and
> adapted OvmfPkg/ResetVector:
> 
>   abb158ded41f BaseTools: Add rules to build NASM source file into a binary
>   5a1f324d946c UefiCpuPkg: Support building VTF0 ResetVector during the EDK 
> II build
>   eee1d2ca9078 UefiCpuPkg VTF0 X64: Build page tables in NASM code
>   9b9fdbfa7059 OvmfPkg: Support building OVMF's ResetVector during the EDK II 
> build
>   497cbb530a58 OvmfPkg: Build OVMF ResetVector during EDK II build process
>   70e46f44cd13 OvmfPkg/ResetVector: Remove pre-built binaries
>   3449f56dac9c UefiCpuPkg: Add ResetVector/FixupVtf
> 
> The BaseTools support would imply automatic preprocessing (with the C
> preprocessor, $(PP)) for *.nasmb files.
> 
> We both failed to notice :) that this enabled us to 

Re: [edk2] [PATCH v1 1/1] OvmfPkg/ResetVector: Depend on PCD values of the page tables.

2016-11-02 Thread Laszlo Ersek
On 11/02/16 23:31, Jordan Justen wrote:
> The "v1 1/1" isn't needed in the subject. For the first version of a
> single patch series, I would expect to just see [PATCH]. (Obviously
> this is not too important.)

(I think the "v1" implies that Marvin expects to send a v2.)

> Email headers seem to indicate that you aren't using git send-email.
> This will cause troubles if someday you have a multi-patch series.
> 
> On 2016-11-02 11:00:34, Marvin Häuser wrote:
>>
>> diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm 
>> b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
>>  
>>  ;
>>  ; Top level Page Directory Pointers (1 * 512GB entry)
>>  ;
>> -mov dword[0x80], 0x801000 + PAGE_PDP_ATTR
>> +mov dword[OVMF_SEC_PAGE_TABLES_BASE], OVMF_SEC_PAGE_TABLES_BASE + 
>> 0x1000 + PAGE_PDP_ATTR
>>  
>>  ;
>>  ; Next level Page Directory Pointers (4 * 1GB entries => 4GB)
>>  ;
>> -mov dword[0x801000], 0x802000 + PAGE_PDP_ATTR
>> -mov dword[0x801008], 0x803000 + PAGE_PDP_ATTR
>> -mov dword[0x801010], 0x804000 + PAGE_PDP_ATTR
>> -mov dword[0x801018], 0x805000 + PAGE_PDP_ATTR
>> +mov dword[OVMF_SEC_PAGE_TABLES_BASE + 0x1000], 
>> OVMF_SEC_PAGE_TABLES_BASE + 0x2000 + PAGE_PDP_ATTR
>> +mov dword[OVMF_SEC_PAGE_TABLES_BASE + 0x1008], 
>> OVMF_SEC_PAGE_TABLES_BASE + 0x3000 + PAGE_PDP_ATTR
>> +mov dword[OVMF_SEC_PAGE_TABLES_BASE + 0x1010], 
>> OVMF_SEC_PAGE_TABLES_BASE + 0x4000 + PAGE_PDP_ATTR
>> +mov dword[OVMF_SEC_PAGE_TABLES_BASE + 0x1018], 
>> OVMF_SEC_PAGE_TABLES_BASE + 0x5000 + PAGE_PDP_ATTR
> 
> These line are too long. I guess you can use '\' at the end of a line
> to continue it, or maybe add a PT_ADDR() macro that adds in
> OVMF_SEC_PAGE_TABLES_BASE.
> 
>> diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb 
>> b/OvmfPkg/ResetVector/ResetVector.nasmb
>> index 31ac06a..b47f647 100644
>> --- a/OvmfPkg/ResetVector/ResetVector.nasmb
>> +++ b/OvmfPkg/ResetVector/ResetVector.nasmb
>> @@ -53,6 +53,12 @@
>>  %include "Ia32/SearchForSecEntry.asm"
>>  
>>  %ifdef ARCH_X64
>> +  %ifndef OVMF_SEC_PAGE_TABLES_BASE
>> +#include 
>> +%define OVMF_SEC_PAGE_TABLES_BASE FixedPcdGet32 
>> (PcdOvmfSecPageTablesBase)
>> +%define OVMF_SEC_PAGE_TABLES_SIZE FixedPcdGet32 
>> (PcdOvmfSecPageTablesSize)
>> +  %endif
>> +
>>  %include "Ia32/Flat32ToFlat64.asm"
>>  %include "Ia32/PageTables64.asm"
>>  %endif
>> diff --git a/OvmfPkg/ResetVector/ResetVectorCode.asm 
>> b/OvmfPkg/ResetVector/ResetVectorCode.asm
>> index 052c821..5b49387 100644
>> --- a/OvmfPkg/ResetVector/ResetVectorCode.asm
>> +++ b/OvmfPkg/ResetVector/ResetVectorCode.asm
>> @@ -40,6 +40,15 @@
>>  %include "Ia32/SearchForSecEntry.asm"
>>  
>>  %ifdef ARCH_X64
>> +  %ifndef OVMF_SEC_PAGE_TABLES_BASE
>> +;
>> +; This range should match with PcdOvmfSecPageTablesBase and
>> +; PcdOvmfSecPageTablesSize which are declared in the FDF files.
>> +   ;
>> +%define OVMF_SEC_PAGE_TABLES_BASE 0x80
>> +%define OVMF_SEC_PAGE_TABLES_SIZE 6 * 0x1000
> 
> I thought we were using the PCDs?

We were, yes, except where we couldn't. For the reset vector, our "root"
file is

  OvmfPkg/ResetVector/ResetVector.nasmb

(referenced by

  OvmfPkg/ResetVector/ResetVector.inf

)

That nasmb file %include's a bunch of other files; among those,

  OvmfPkg/ResetVector/Ia32/PageTables64.asm

Notice that the %include and %define directives in these files are
NASM-native directives; they aren't C preprocessor directives. So we
couldn't use FixedPcdGetXX() in the source code.

If I remember correctly, in commit b382ede3864e ("OvmfPkg X64
ResetVector: Move page tables from 512KB to 8MB"), you added the PCD
references in a source code comment because this way at least a "grep"
would find them, and then the programmer could update the constants (if
necessary).

Note that in the era of commit b382ede3864e (2014-Jan-21), we used to
compile the reset vector manually, with the utility

  OvmfPkg/ResetVector/Build.py

On 2014-Aug-19 however, you added native NASMB support to BaseTools, and
adapted OvmfPkg/ResetVector:

  abb158ded41f BaseTools: Add rules to build NASM source file into a binary
  5a1f324d946c UefiCpuPkg: Support building VTF0 ResetVector during the EDK II 
build
  eee1d2ca9078 UefiCpuPkg VTF0 X64: Build page tables in NASM code
  9b9fdbfa7059 OvmfPkg: Support building OVMF's ResetVector during the EDK II 
build
  497cbb530a58 OvmfPkg: Build OVMF ResetVector during EDK II build process
  70e46f44cd13 OvmfPkg/ResetVector: Remove pre-built binaries
  3449f56dac9c UefiCpuPkg: Add ResetVector/FixupVtf

The BaseTools support would imply automatic preprocessing (with the C
preprocessor, $(PP)) for *.nasmb files.

We both failed to notice :) that this enabled us to #include 
in the assembly source -- despite the fact that commit 9b9fdbfa7059
#included !

So, we forgot to take advantage of the preprocessor, and to replace the
open-coded constants with FixedPcdGetXX().

I think 

[edk2] Minimum RAM requirements for UEFI (AARCH64)

2016-11-02 Thread Vladimir Olovyannikov
Hello,

I could not find this in the spec, but what is the minimum RAM required
for the UEFI?
We are at the very early stage right now, and DDR will not be available
for a while. The platform is AARCH64-based.
Can I fit UEFI into 8MB of RAM (actually I might get 64MB, so can I fit it
into 64MB)?

Because the target platform is not yet available,  I experimented with an
ref. platform (also AARCH64, slightly older)
shrinking SystemMemorySize.
I tried to cut off as many things as possible (no Shell, very limited set
of drivers),
tried to replace real libraries with NULL "stubs", yet  I cannot get UEFI
running with less than 128MB of RAM...

I would appreciate any  advice...

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


Re: [edk2] [RFC] [MdePkg] UefiLib: CreatePopUp

2016-11-02 Thread Felix Poludov
Eric,

See my comments below

-Original Message-
From: Dong, Eric [mailto:eric.d...@intel.com] 
Sent: Tuesday, November 01, 2016 2:55 AM
To: Felix Poludov; edk2-devel@lists.01.org
Cc: Bi, Dandan; Gao, Liming
Subject: RE: [RFC] [MdePkg] UefiLib: CreatePopUp

Felix,

Add my comments below.

-Original Message-
From: Felix Poludov [mailto:fel...@ami.com] 
Sent: Tuesday, November 1, 2016 4:22 AM
To: Dong, Eric ; edk2-devel@lists.01.org
Cc: Bi, Dandan ; Gao, Liming 
Subject: RE: [RFC] [MdePkg] UefiLib: CreatePopUp

Eric,

1. If you are not changing CretePopUp, your proposal does not really solve my 
problem.
It means my proposal still has merit.
Do you have problem with moving CreatePopUp implementation into a new library 
class?
Once again, the function will stay in UefiLib, but the implementation will be 
changed to call a new function UiCreatePopUp from the new library class UiLib.
[[Eric]] My proposal bases on modal form to show the popup dialog.  The modal 
form
is painted by the browser. So the UI will changed in different browser. I think 
you can 
update your browser to show the different UI.
I not prefer your solution because this is an incompatible change and we must 
avoid it.
It will impact a lot of core codes which use CreatePopup API.

[[[Felix]]] Since you have no plans to change CreatePopUp implementation, 
existing code that uses CreatePopUp will like to keep using it, which means
popup box will keep looking "strange".
As far as my proposal, I'm not sure why you are saying that it's backward 
compatible.
Let me explain one more time, what I propose:
1. No changes to UefiLib.h (CreatePopUp is still there)
2.  A single line change in [LibraryClasses] section of 
MdePkg/Library/UefiLib/UefiLib.inf. New library class UiLib is added there.
3.  CreatePopUp implementation in MdePkg/Library/UefiLib/Console.c is replaced 
with:
VOID
EFIAPI
CreatePopUp (
  IN  UINTN  Attribute,
  OUT EFI_INPUT_KEY  *Key,  OPTIONAL
  ...
  )
{
  VA_LIST  Args;
  VA_START (Args, Key);
  UiCreatePopUp(Attribute,Ket,Args);
}
4. New library class UiLib.h is added. New library instance for the class is 
added. The library contains UiCreatePopUp function.
Function implementation is copied from original CreatePopUp implementation in 
MdePkg/Library/UefiLib/Console.c.

To summarize:
- There is no need to change code that consumes CreatePopUp because the 
function is still there
- CreatePopUp consumers see no difference in look-and-feel and behavior because 
default CreatePopUp implementation is the same as the current one.
- Project owners that strive unified UI can override UiLib library class.
I agree that creating a new library class for a single function does not feel 
right, but we may have other functions that deal with presentation in the 
future.
See continuation of my answer below...

2. In my opinion, adding HiiGetUserSelection to HiiLib is a bad idea because it 
will create the same problem as with CretePopUp.
The rest of HiiLib is generic. It operates within the scope of HII database 
definitions from UEFI specification.
The new HiiGetUserSelection you are proposing deals with presentation, which 
means it is may get changed to match project UI.
HiiGetUserSelection can be added to the same new UiLib that I'm proposing.
[[Eric]] My proposal bases on modal form defined in UEFI Spec. Modal form UI 
decides 
by the browser. Base on this reason, so I put this new API to the HiiLib. I 
only add one 
new API and related to HII, so I prefer not add new library class.

I think you want to split the API to new library just want to reduce the 
override code size? Or other reason? 
[[[Felix]]] 1. I agree, if new function is based on standard HII Modal form, 
HiiLib is a good place for it.
2. Yes, the main reason is a clean project porting.
Today I have two options:  
Option 1: replace CreatePopUp implementation in Console.c with my custom 
implementation
Option 2: create custom instance of UefiLib
With both options, I'm deviating from standard EDKII code base, which means I 
will have to merge my changes whenever I want to upgrade EDKII tree.
Also I will have to manually migrate the patch from project to project.


-Original Message-
From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Dong, 
Eric
Sent: Monday, October 31, 2016 4:26 AM
To: Felix Poludov; edk2-devel@lists.01.org
Cc: Bi, Dandan; Gao, Liming
Subject: Re: [edk2] [RFC] [MdePkg] UefiLib: CreatePopUp

Hi Felix,

Add my comments below.

> -Original Message-
> From: Felix Poludov [mailto:fel...@ami.com]
> Sent: Friday, October 28, 2016 9:52 PM
> To: Dong, Eric; edk2-devel@lists.01.org
> Cc: Gao, Liming; Bi, Dandan
> Subject: RE: [RFC] [MdePkg] UefiLib: CreatePopUp
> 
> Hi Eric,
> 
> My goal is to facilitate CreatePopUp customization.
> Since UI is one of the most customizable areas in the firmware projects, 

Re: [edk2] [PATCH v1 1/1] OvmfPkg/ResetVector: Depend on PCD values of the page tables.

2016-11-02 Thread Marvin Häuser
Hey Jordan,

1) I have used git send-mail, but due to a corruption of my edk2 clone I did 
some 'funky' stuff to get it working. I expect stuff to be better with the next 
patch.
2) Will submit a V2 with line-breaks hopefully today, though might be tomorrow.
3) As said in the commit message, as far as I am aware, C preprocessing is not 
available for ASM (non-NASM), hence the values are hard-coded there still. Is 
there a way to use PCDs in ASM?
4) Can't the ASM file actually be removed? I don't see it referenced anywhere 
anymore. Is it kept for the case external packages expect it to be present? 
Should I clarify the commit message, such as using 'NASM ResetVector'?

Thanks for your input!

Regards,
Marvin.

> -Original Message-
> From: Jordan Justen [mailto:jordan.l.jus...@intel.com]
> Sent: Wednesday, November 2, 2016 11:31 PM
> To: Marvin Häuser ; edk2-
> de...@lists.01.org
> Cc: ler...@redhat.com
> Subject: Re: [PATCH v1 1/1] OvmfPkg/ResetVector: Depend on PCD values of
> the page tables.
> 
> The "v1 1/1" isn't needed in the subject. For the first version of a single 
> patch
> series, I would expect to just see [PATCH]. (Obviously this is not too
> important.)
> 
> Email headers seem to indicate that you aren't using git send-email.
> This will cause troubles if someday you have a multi-patch series.
> 
> On 2016-11-02 11:00:34, Marvin Häuser wrote:
> >
> > diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm
> > b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
> >
> >  ;
> >  ; Top level Page Directory Pointers (1 * 512GB entry)
> >  ;
> > -mov dword[0x80], 0x801000 + PAGE_PDP_ATTR
> > +mov dword[OVMF_SEC_PAGE_TABLES_BASE],
> OVMF_SEC_PAGE_TABLES_BASE + 0x1000 + PAGE_PDP_ATTR
> >
> >  ;
> >  ; Next level Page Directory Pointers (4 * 1GB entries => 4GB)
> >  ;
> > -mov dword[0x801000], 0x802000 + PAGE_PDP_ATTR
> > -mov dword[0x801008], 0x803000 + PAGE_PDP_ATTR
> > -mov dword[0x801010], 0x804000 + PAGE_PDP_ATTR
> > -mov dword[0x801018], 0x805000 + PAGE_PDP_ATTR
> > +mov dword[OVMF_SEC_PAGE_TABLES_BASE + 0x1000],
> OVMF_SEC_PAGE_TABLES_BASE + 0x2000 + PAGE_PDP_ATTR
> > +mov dword[OVMF_SEC_PAGE_TABLES_BASE + 0x1008],
> OVMF_SEC_PAGE_TABLES_BASE + 0x3000 + PAGE_PDP_ATTR
> > +mov dword[OVMF_SEC_PAGE_TABLES_BASE + 0x1010],
> OVMF_SEC_PAGE_TABLES_BASE + 0x4000 + PAGE_PDP_ATTR
> > +mov dword[OVMF_SEC_PAGE_TABLES_BASE + 0x1018],
> OVMF_SEC_PAGE_TABLES_BASE + 0x5000 + PAGE_PDP_ATTR
> 
> These line are too long. I guess you can use '\' at the end of a line to 
> continue
> it, or maybe add a PT_ADDR() macro that adds in
> OVMF_SEC_PAGE_TABLES_BASE.
> 
> > diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb
> > b/OvmfPkg/ResetVector/ResetVector.nasmb
> > index 31ac06a..b47f647 100644
> > --- a/OvmfPkg/ResetVector/ResetVector.nasmb
> > +++ b/OvmfPkg/ResetVector/ResetVector.nasmb
> > @@ -53,6 +53,12 @@
> >  %include "Ia32/SearchForSecEntry.asm"
> >
> >  %ifdef ARCH_X64
> > +  %ifndef OVMF_SEC_PAGE_TABLES_BASE
> > +#include 
> > +%define OVMF_SEC_PAGE_TABLES_BASE FixedPcdGet32
> (PcdOvmfSecPageTablesBase)
> > +%define OVMF_SEC_PAGE_TABLES_SIZE FixedPcdGet32
> > + (PcdOvmfSecPageTablesSize)  %endif
> > +
> >  %include "Ia32/Flat32ToFlat64.asm"
> >  %include "Ia32/PageTables64.asm"
> >  %endif
> > diff --git a/OvmfPkg/ResetVector/ResetVectorCode.asm
> > b/OvmfPkg/ResetVector/ResetVectorCode.asm
> > index 052c821..5b49387 100644
> > --- a/OvmfPkg/ResetVector/ResetVectorCode.asm
> > +++ b/OvmfPkg/ResetVector/ResetVectorCode.asm
> > @@ -40,6 +40,15 @@
> >  %include "Ia32/SearchForSecEntry.asm"
> >
> >  %ifdef ARCH_X64
> > +  %ifndef OVMF_SEC_PAGE_TABLES_BASE
> > +;
> > +; This range should match with PcdOvmfSecPageTablesBase and
> > +; PcdOvmfSecPageTablesSize which are declared in the FDF files.
> > +   ;
> > +%define OVMF_SEC_PAGE_TABLES_BASE 0x80
> > +%define OVMF_SEC_PAGE_TABLES_SIZE 6 * 0x1000
> 
> I thought we were using the PCDs?
> 
> -Jordan
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH v1 1/1] OvmfPkg/ResetVector: Depend on PCD values of the page tables.

2016-11-02 Thread Jordan Justen
The "v1 1/1" isn't needed in the subject. For the first version of a
single patch series, I would expect to just see [PATCH]. (Obviously
this is not too important.)

Email headers seem to indicate that you aren't using git send-email.
This will cause troubles if someday you have a multi-patch series.

On 2016-11-02 11:00:34, Marvin Häuser wrote:
> 
> diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm 
> b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
>  
>  ;
>  ; Top level Page Directory Pointers (1 * 512GB entry)
>  ;
> -mov dword[0x80], 0x801000 + PAGE_PDP_ATTR
> +mov dword[OVMF_SEC_PAGE_TABLES_BASE], OVMF_SEC_PAGE_TABLES_BASE + 
> 0x1000 + PAGE_PDP_ATTR
>  
>  ;
>  ; Next level Page Directory Pointers (4 * 1GB entries => 4GB)
>  ;
> -mov dword[0x801000], 0x802000 + PAGE_PDP_ATTR
> -mov dword[0x801008], 0x803000 + PAGE_PDP_ATTR
> -mov dword[0x801010], 0x804000 + PAGE_PDP_ATTR
> -mov dword[0x801018], 0x805000 + PAGE_PDP_ATTR
> +mov dword[OVMF_SEC_PAGE_TABLES_BASE + 0x1000], 
> OVMF_SEC_PAGE_TABLES_BASE + 0x2000 + PAGE_PDP_ATTR
> +mov dword[OVMF_SEC_PAGE_TABLES_BASE + 0x1008], 
> OVMF_SEC_PAGE_TABLES_BASE + 0x3000 + PAGE_PDP_ATTR
> +mov dword[OVMF_SEC_PAGE_TABLES_BASE + 0x1010], 
> OVMF_SEC_PAGE_TABLES_BASE + 0x4000 + PAGE_PDP_ATTR
> +mov dword[OVMF_SEC_PAGE_TABLES_BASE + 0x1018], 
> OVMF_SEC_PAGE_TABLES_BASE + 0x5000 + PAGE_PDP_ATTR

These line are too long. I guess you can use '\' at the end of a line
to continue it, or maybe add a PT_ADDR() macro that adds in
OVMF_SEC_PAGE_TABLES_BASE.

> diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb 
> b/OvmfPkg/ResetVector/ResetVector.nasmb
> index 31ac06a..b47f647 100644
> --- a/OvmfPkg/ResetVector/ResetVector.nasmb
> +++ b/OvmfPkg/ResetVector/ResetVector.nasmb
> @@ -53,6 +53,12 @@
>  %include "Ia32/SearchForSecEntry.asm"
>  
>  %ifdef ARCH_X64
> +  %ifndef OVMF_SEC_PAGE_TABLES_BASE
> +#include 
> +%define OVMF_SEC_PAGE_TABLES_BASE FixedPcdGet32 
> (PcdOvmfSecPageTablesBase)
> +%define OVMF_SEC_PAGE_TABLES_SIZE FixedPcdGet32 
> (PcdOvmfSecPageTablesSize)
> +  %endif
> +
>  %include "Ia32/Flat32ToFlat64.asm"
>  %include "Ia32/PageTables64.asm"
>  %endif
> diff --git a/OvmfPkg/ResetVector/ResetVectorCode.asm 
> b/OvmfPkg/ResetVector/ResetVectorCode.asm
> index 052c821..5b49387 100644
> --- a/OvmfPkg/ResetVector/ResetVectorCode.asm
> +++ b/OvmfPkg/ResetVector/ResetVectorCode.asm
> @@ -40,6 +40,15 @@
>  %include "Ia32/SearchForSecEntry.asm"
>  
>  %ifdef ARCH_X64
> +  %ifndef OVMF_SEC_PAGE_TABLES_BASE
> +;
> +; This range should match with PcdOvmfSecPageTablesBase and
> +; PcdOvmfSecPageTablesSize which are declared in the FDF files.
> +   ;
> +%define OVMF_SEC_PAGE_TABLES_BASE 0x80
> +%define OVMF_SEC_PAGE_TABLES_SIZE 6 * 0x1000

I thought we were using the PCDs?

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


Re: [edk2] Why does build output appear in RELEASE_VS2012x86\X64\blah blah\DEBUG rather than OUTPUT ?

2016-11-02 Thread Andrew Fish

> On Nov 2, 2016, at 10:12 AM, Shubha Ramani  wrote:
> 
> Seems like DEBUG and OUTPUT got switched somehow and I don't know how. The 
> stuff used to appear in OUTPUT but somehow they got switched.
> Where do I configure this ?

Shudha,

I think the DEBUG dir is for things that are saved for debugging and OUTPUT is 
for things not needed for debug so it is just a generic policy in the tools. I 
think the original concept is you need to save things in DEBUG for future 
source level debugging and things in OUTPUT can be discarded. 

Thanks,

Andrew Fish


> Thanks,
> Shubha Shubha D. ramanishubharam...@gmail.com
> shubharam...@yahoo.com
> ___
> 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 v1 1/1] OvmfPkg/ResetVector: Depend on PCD values of the page tables.

2016-11-02 Thread Marvin Häuser
Currently, the values of the page tables' address and size are
hard-coded in the ResetVector. This patch replaces this with a PCD
dependency for the NASM Reset Vector. The ASM Reset Vector remains
using a hard-coded value due to the lack of C preprocessing.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Marvin Haeuser 
---
 OvmfPkg/ResetVector/Ia32/PageTables64.asm | 21 +---
 OvmfPkg/ResetVector/ResetVector.inf   |  5 +
 OvmfPkg/ResetVector/ResetVector.nasmb |  6 ++
 OvmfPkg/ResetVector/ResetVectorCode.asm   |  9 +
 4 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm 
b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
index b5a4cf8..8410553 100644
--- a/OvmfPkg/ResetVector/Ia32/PageTables64.asm
+++ b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
@@ -46,31 +46,28 @@ SetCr3ForPageTables64:
 ;
 ; For OVMF, build some initial page tables at 0x80-0x806000.
 ;
-; This range should match with PcdOvmfSecPageTablesBase and
-; PcdOvmfSecPageTablesSize which are declared in the FDF files.
-;
 ; At the end of PEI, the pages tables will be rebuilt into a
 ; more permanent location by DxeIpl.
 ;
 
-mov ecx, 6 * 0x1000 / 4
+mov ecx, OVMF_SEC_PAGE_TABLES_SIZE / 4
 xor eax, eax
 clearPageTablesMemoryLoop:
-mov dword[ecx * 4 + 0x80 - 4], eax
+mov dword[ecx * 4 + OVMF_SEC_PAGE_TABLES_BASE - 4], eax
 loopclearPageTablesMemoryLoop
 
 ;
 ; Top level Page Directory Pointers (1 * 512GB entry)
 ;
-mov dword[0x80], 0x801000 + PAGE_PDP_ATTR
+mov dword[OVMF_SEC_PAGE_TABLES_BASE], OVMF_SEC_PAGE_TABLES_BASE + 
0x1000 + PAGE_PDP_ATTR
 
 ;
 ; Next level Page Directory Pointers (4 * 1GB entries => 4GB)
 ;
-mov dword[0x801000], 0x802000 + PAGE_PDP_ATTR
-mov dword[0x801008], 0x803000 + PAGE_PDP_ATTR
-mov dword[0x801010], 0x804000 + PAGE_PDP_ATTR
-mov dword[0x801018], 0x805000 + PAGE_PDP_ATTR
+mov dword[OVMF_SEC_PAGE_TABLES_BASE + 0x1000], 
OVMF_SEC_PAGE_TABLES_BASE + 0x2000 + PAGE_PDP_ATTR
+mov dword[OVMF_SEC_PAGE_TABLES_BASE + 0x1008], 
OVMF_SEC_PAGE_TABLES_BASE + 0x3000 + PAGE_PDP_ATTR
+mov dword[OVMF_SEC_PAGE_TABLES_BASE + 0x1010], 
OVMF_SEC_PAGE_TABLES_BASE + 0x4000 + PAGE_PDP_ATTR
+mov dword[OVMF_SEC_PAGE_TABLES_BASE + 0x1018], 
OVMF_SEC_PAGE_TABLES_BASE + 0x5000 + PAGE_PDP_ATTR
 
 ;
 ; Page Table Entries (2048 * 2MB entries => 4GB)
@@ -81,13 +78,13 @@ pageTableEntriesLoop:
 dec eax
 shl eax, 21
 add eax, PAGE_2M_PDE_ATTR
-mov [ecx * 8 + 0x802000 - 8], eax
+mov [ecx * 8 + OVMF_SEC_PAGE_TABLES_BASE + 0x2000 - 8], eax
 looppageTableEntriesLoop
 
 ;
 ; Set CR3 now that the paging structures are available
 ;
-mov eax, 0x80
+mov eax, OVMF_SEC_PAGE_TABLES_BASE
 mov cr3, eax
 
 OneTimeCallRet SetCr3ForPageTables64
diff --git a/OvmfPkg/ResetVector/ResetVector.inf 
b/OvmfPkg/ResetVector/ResetVector.inf
index 46610d2..d1e5d4d 100644
--- a/OvmfPkg/ResetVector/ResetVector.inf
+++ b/OvmfPkg/ResetVector/ResetVector.inf
@@ -29,9 +29,14 @@
   ResetVector.nasmb
 
 [Packages]
+  OvmfPkg/OvmfPkg.dec
   MdePkg/MdePkg.dec
   UefiCpuPkg/UefiCpuPkg.dec
 
 [BuildOptions]
*_*_IA32_NASMB_FLAGS = -I$(WORKSPACE)/UefiCpuPkg/ResetVector/Vtf0/
*_*_X64_NASMB_FLAGS = -I$(WORKSPACE)/UefiCpuPkg/ResetVector/Vtf0/
+
+[Pcd]
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesSize
diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb 
b/OvmfPkg/ResetVector/ResetVector.nasmb
index 31ac06a..b47f647 100644
--- a/OvmfPkg/ResetVector/ResetVector.nasmb
+++ b/OvmfPkg/ResetVector/ResetVector.nasmb
@@ -53,6 +53,12 @@
 %include "Ia32/SearchForSecEntry.asm"
 
 %ifdef ARCH_X64
+  %ifndef OVMF_SEC_PAGE_TABLES_BASE
+#include 
+%define OVMF_SEC_PAGE_TABLES_BASE FixedPcdGet32 (PcdOvmfSecPageTablesBase)
+%define OVMF_SEC_PAGE_TABLES_SIZE FixedPcdGet32 (PcdOvmfSecPageTablesSize)
+  %endif
+
 %include "Ia32/Flat32ToFlat64.asm"
 %include "Ia32/PageTables64.asm"
 %endif
diff --git a/OvmfPkg/ResetVector/ResetVectorCode.asm 
b/OvmfPkg/ResetVector/ResetVectorCode.asm
index 052c821..5b49387 100644
--- a/OvmfPkg/ResetVector/ResetVectorCode.asm
+++ b/OvmfPkg/ResetVector/ResetVectorCode.asm
@@ -40,6 +40,15 @@
 %include "Ia32/SearchForSecEntry.asm"
 
 %ifdef ARCH_X64
+  %ifndef OVMF_SEC_PAGE_TABLES_BASE
+;
+; This range should match with PcdOvmfSecPageTablesBase and
+; PcdOvmfSecPageTablesSize which are declared in the FDF files.
+   ;
+%define OVMF_SEC_PAGE_TABLES_BASE 0x80
+%define OVMF_SEC_PAGE_TABLES_SIZE 6 * 0x1000
+  %endif
+
 %include "Ia32/Flat32ToFlat64.asm"
 %include "Ia32/PageTables64.asm"
 %endif
-- 
2.7.4

___
edk2-devel 

[edk2] Why does build output appear in RELEASE_VS2012x86\X64\blah blah\DEBUG rather than OUTPUT ?

2016-11-02 Thread Shubha Ramani
Seems like DEBUG and OUTPUT got switched somehow and I don't know how. The 
stuff used to appear in OUTPUT but somehow they got switched.
Where do I configure this ?
Thanks,
Shubha Shubha D. ramanishubharam...@gmail.com
shubharam...@yahoo.com
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH] MdePkg/BaseLib: Re-define CHAR_NULL in BaseLib

2016-11-02 Thread Kinney, Michael D
Liming,

I agree.  That is better than having to use #ifndef.

The UEFI Specification does not have the #defines for the CHAR_x values,
so we can move the subset of these character values required by libraries
of type BASE into Base.h starting with CHAR_NULL.

Thanks,

Mike

> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Gao, 
> Liming
> Sent: Wednesday, November 2, 2016 1:44 AM
> To: Song, BinX ; edk2-devel@lists.01.org
> Subject: Re: [edk2] [PATCH] MdePkg/BaseLib: Re-define CHAR_NULL in BaseLib
> 
> Bin:
>   I suggest move CHAR_NULL definition from Protocol\SimpleTextIn.h to Base.h
> 
> Thanks
> Liming
> -Original Message-
> From: Song, BinX
> Sent: Wednesday, November 2, 2016 4:27 PM
> To: edk2-devel@lists.01.org
> Cc: Gao, Liming 
> Subject: [PATCH] MdePkg/BaseLib: Re-define CHAR_NULL in BaseLib
> 
> - https://bugzilla.tianocore.org/show_bug.cgi?id=172
> 
> Cc: Liming Gao 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Bell Song 
> ---
>  MdePkg/Include/Base.h  | 7 +++
>  MdePkg/Library/BaseLib/FilePaths.c | 2 --
>  2 files changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h
> index 2217058..0c3318f 100644
> --- a/MdePkg/Include/Base.h
> +++ b/MdePkg/Include/Base.h
> @@ -338,6 +338,13 @@ struct _LIST_ENTRY {
>  ///
>  #define NULL  ((VOID *) 0)
> 
> +//
> +// Required unicode control chars
> +//
> +#ifndef CHAR_NULL
> +#define CHAR_NULL  0x
> +#endif
> +
>  ///
>  /// Maximum values for common UEFI Data Types
>  ///
> diff --git a/MdePkg/Library/BaseLib/FilePaths.c 
> b/MdePkg/Library/BaseLib/FilePaths.c
> index c8da6bb..183b323 100644
> --- a/MdePkg/Library/BaseLib/FilePaths.c
> +++ b/MdePkg/Library/BaseLib/FilePaths.c
> @@ -10,10 +10,8 @@
>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  
> 
>  /**
>Removes the last directory or file entry in a path by changing the last
> --
> 2.7.2.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 4/5] ArmPkg/CpuDxe: set DmaBufferAlignment according to CWG

2016-11-02 Thread Ard Biesheuvel
On 2 November 2016 at 16:21, Leif Lindholm  wrote:
> On Wed, Nov 02, 2016 at 04:17:03PM +, Ard Biesheuvel wrote:
>> On 2 November 2016 at 16:10, Leif Lindholm  wrote:
>> > On Wed, Nov 02, 2016 at 01:40:17PM +, Ard Biesheuvel wrote:
>> >> On 1 November 2016 at 22:32, Leif Lindholm  
>> >> wrote:
>> >> > On Mon, Oct 31, 2016 at 06:13:09PM +, Ard Biesheuvel wrote:
>> >> >> The DmaBufferAlignment currently defaults to 4, which is dangerously
>> >> >> small and may result in lost data on platform that perform non-coherent
>> >> >> DMA. So instead, take the CWG value from the cache info registers.
>> >> >>
>> >> >> Contributed-under: TianoCore Contribution Agreement 1.0
>> >> >> Signed-off-by: Ard Biesheuvel 
>> >> >> ---
>> >> >>  ArmPkg/Drivers/CpuDxe/CpuDxe.c | 4 +++-
>> >> >>  1 file changed, 3 insertions(+), 1 deletion(-)
>> >> >>
>> >> >> diff --git a/ArmPkg/Drivers/CpuDxe/CpuDxe.c 
>> >> >> b/ArmPkg/Drivers/CpuDxe/CpuDxe.c
>> >> >> index d089cb2d119f..ddc64fd255a0 100644
>> >> >> --- a/ArmPkg/Drivers/CpuDxe/CpuDxe.c
>> >> >> +++ b/ArmPkg/Drivers/CpuDxe/CpuDxe.c
>> >> >> @@ -225,7 +225,7 @@ EFI_CPU_ARCH_PROTOCOL mCpu = {
>> >> >>CpuGetTimerValue,
>> >> >>CpuSetMemoryAttributes,
>> >> >>0,  // NumberOfTimers
>> >> >> -  4,  // DmaBufferAlignment
>> >> >> +  2048,   // DmaBufferAlignment
>> >> >>  };
>> >> >>
>> >> >>  EFI_STATUS
>> >> >> @@ -239,6 +239,8 @@ CpuDxeInitialize (
>> >> >>
>> >> >>InitializeExceptions ();
>> >> >>
>> >> >> +  mCpu.DmaBufferAlignment = ArmCacheWritebackGranule ();
>> >> >> +
>> >> >
>> >> > Could we hide the internal structure of mCpu here by moving this to a
>> >> > helper function and calling
>> >> >   InitializeDma ();
>> >> > (or something)?
>> >> >
>> >>
>> >> We could, but why? The actual struct is defined 10 lines up
>> >
>> > It's just that it's the only place in this function we're prodding the
>> > internals of the object directly. Messes slightly with my zen.
>> > Not a strong opinion, just a preference.
>> >
>>
>> Sure, if you want.
>>
>> In fact, I will break this out as a separate patch, considering that
>> it fixes a serious bug.
>
> Agreed.
>
>> So you are happy with the patch if I fold the following into it?
>
> Super happy - thanks!
> Reviewed-by: Leif Lindholm 
>

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


Re: [edk2] [PATCH 4/5] ArmPkg/CpuDxe: set DmaBufferAlignment according to CWG

2016-11-02 Thread Leif Lindholm
On Wed, Nov 02, 2016 at 04:17:03PM +, Ard Biesheuvel wrote:
> On 2 November 2016 at 16:10, Leif Lindholm  wrote:
> > On Wed, Nov 02, 2016 at 01:40:17PM +, Ard Biesheuvel wrote:
> >> On 1 November 2016 at 22:32, Leif Lindholm  
> >> wrote:
> >> > On Mon, Oct 31, 2016 at 06:13:09PM +, Ard Biesheuvel wrote:
> >> >> The DmaBufferAlignment currently defaults to 4, which is dangerously
> >> >> small and may result in lost data on platform that perform non-coherent
> >> >> DMA. So instead, take the CWG value from the cache info registers.
> >> >>
> >> >> Contributed-under: TianoCore Contribution Agreement 1.0
> >> >> Signed-off-by: Ard Biesheuvel 
> >> >> ---
> >> >>  ArmPkg/Drivers/CpuDxe/CpuDxe.c | 4 +++-
> >> >>  1 file changed, 3 insertions(+), 1 deletion(-)
> >> >>
> >> >> diff --git a/ArmPkg/Drivers/CpuDxe/CpuDxe.c 
> >> >> b/ArmPkg/Drivers/CpuDxe/CpuDxe.c
> >> >> index d089cb2d119f..ddc64fd255a0 100644
> >> >> --- a/ArmPkg/Drivers/CpuDxe/CpuDxe.c
> >> >> +++ b/ArmPkg/Drivers/CpuDxe/CpuDxe.c
> >> >> @@ -225,7 +225,7 @@ EFI_CPU_ARCH_PROTOCOL mCpu = {
> >> >>CpuGetTimerValue,
> >> >>CpuSetMemoryAttributes,
> >> >>0,  // NumberOfTimers
> >> >> -  4,  // DmaBufferAlignment
> >> >> +  2048,   // DmaBufferAlignment
> >> >>  };
> >> >>
> >> >>  EFI_STATUS
> >> >> @@ -239,6 +239,8 @@ CpuDxeInitialize (
> >> >>
> >> >>InitializeExceptions ();
> >> >>
> >> >> +  mCpu.DmaBufferAlignment = ArmCacheWritebackGranule ();
> >> >> +
> >> >
> >> > Could we hide the internal structure of mCpu here by moving this to a
> >> > helper function and calling
> >> >   InitializeDma ();
> >> > (or something)?
> >> >
> >>
> >> We could, but why? The actual struct is defined 10 lines up
> >
> > It's just that it's the only place in this function we're prodding the
> > internals of the object directly. Messes slightly with my zen.
> > Not a strong opinion, just a preference.
> >
> 
> Sure, if you want.
> 
> In fact, I will break this out as a separate patch, considering that
> it fixes a serious bug.

Agreed.

> So you are happy with the patch if I fold the following into it?

Super happy - thanks!
Reviewed-by: Leif Lindholm 

> 
> """
> --- a/ArmPkg/Drivers/CpuDxe/CpuDxe.c
> +++ b/ArmPkg/Drivers/CpuDxe/CpuDxe.c
> @@ -228,6 +228,15 @@ EFI_CPU_ARCH_PROTOCOL mCpu = {
>2048,   // DmaBufferAlignment
>  };
> 
> +STATIC
> +VOID
> +InitializeDma (
> +  IN OUT  EFI_CPU_ARCH_PROTOCOL   *CpuArchProtocol
> +  )
> +{
> +  CpuArchProtocol->DmaBufferAlignment = ArmCacheWritebackGranule ();
> +}
> +
>  EFI_STATUS
>  CpuDxeInitialize (
>IN EFI_HANDLE ImageHandle,
> @@ -239,7 +248,7 @@ CpuDxeInitialize (
> 
>InitializeExceptions ();
> 
> -  mCpu.DmaBufferAlignment = ArmCacheWritebackGranule ();
> +  InitializeDma ();
> 
>Status = gBS->InstallMultipleProtocolInterfaces (
>  ,
> """
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH 5/5] EmbeddedPkg/PlatformPciIoDxe: add support for non-coherent DMA

2016-11-02 Thread Leif Lindholm
On Wed, Nov 02, 2016 at 01:43:42PM +, Ard Biesheuvel wrote:
> On 1 November 2016 at 22:43, Leif Lindholm  wrote:
> > On Mon, Oct 31, 2016 at 06:13:10PM +, Ard Biesheuvel wrote:
> >> Add support for bounce buffering using uncached mappings when DMA mappings
> >> are not aligned to the CPU's DMA buffer alignment.
> >
> > This description does not appear to match the subject line?
> > And the contents of the patch seems to do both.
> >
> 
> Yes, I was a bit sloppy with this one. The subject line needs to be
> duplicated into the long log.
> 
> > Anyway, I'll pass on a proper technical review until my head is a bit
> > clearer, but a few comments/questions below.
> >
> >>
> >> Contributed-under: TianoCore Contribution Agreement 1.0
> >> Signed-off-by: Ard Biesheuvel 
> >> ---
> >>  EmbeddedPkg/Drivers/PlatformPciIoDxe/PlatformPciIo.c  | 204 
> >> 
> >>  EmbeddedPkg/Drivers/PlatformPciIoDxe/PlatformPciIo.h  |   5 +
> >>  EmbeddedPkg/Drivers/PlatformPciIoDxe/PlatformPciIoDxe.c   |  17 +-
> >>  EmbeddedPkg/Drivers/PlatformPciIoDxe/PlatformPciIoDxe.inf |   2 +
> >>  4 files changed, 221 insertions(+), 7 deletions(-)
> >>
> >> diff --git a/EmbeddedPkg/Drivers/PlatformPciIoDxe/PlatformPciIo.c 
> >> b/EmbeddedPkg/Drivers/PlatformPciIoDxe/PlatformPciIo.c
> >> index 97ed19353347..658d096c73c1 100644
> >> --- a/EmbeddedPkg/Drivers/PlatformPciIoDxe/PlatformPciIo.c
> >> +++ b/EmbeddedPkg/Drivers/PlatformPciIoDxe/PlatformPciIo.c
> >> @@ -15,6 +15,8 @@
> >>
> >>  #include "PlatformPciIo.h"
> >>
> >> +#include 
> >> +
> >>  #include 
> >>
> >>  typedef struct {
> >> @@ -454,6 +456,201 @@ CoherentPciIoFreeBuffer (
> >>return EFI_SUCCESS;
> >>  }
> >>
> >> +STATIC
> >> +EFI_STATUS
> >> +NonCoherentPciIoFreeBuffer (
> >> +  IN  EFI_PCI_IO_PROTOCOL *This,
> >> +  IN  UINTN   Pages,
> >> +  IN  VOID*HostAddress
> >> +  )
> >> +{
> >> +  EFI_STATUSStatus;
> >> +
> >> +  Status = gDS->SetMemorySpaceAttributes (
> >> +  (EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress,
> >> +  EFI_PAGES_TO_SIZE (Pages),
> >> +  EFI_MEMORY_WB);
> >> +  if (EFI_ERROR (Status)) {
> >> +return Status;
> >> +  }
> >> +
> >> +  FreePages (HostAddress, Pages);
> >> +  return EFI_SUCCESS;
> >> +}
> >> +
> >> +STATIC
> >> +EFI_STATUS
> >> +NonCoherentPciIoAllocateBuffer (
> >> +  IN  EFI_PCI_IO_PROTOCOL *This,
> >> +  IN  EFI_ALLOCATE_TYPE   Type,
> >> +  IN  EFI_MEMORY_TYPE MemoryType,
> >> +  IN  UINTN   Pages,
> >> +  OUT VOID**HostAddress,
> >> +  IN  UINT64  Attributes
> >> +  )
> >> +{
> >> +  EFI_STATUSStatus;
> >> +
> >> +  Status = CoherentPciIoAllocateBuffer (This, Type, MemoryType, Pages,
> >> + HostAddress, Attributes);
> >> +  if (EFI_ERROR (Status)) {
> >> +return Status;
> >> +  }
> >> +
> >> +  Status = gDS->SetMemorySpaceAttributes (
> >> +  (EFI_PHYSICAL_ADDRESS)(UINTN)*HostAddress,
> >> +  EFI_PAGES_TO_SIZE (Pages),
> >> +  EFI_MEMORY_WC);
> >> +  if (EFI_ERROR (Status)) {
> >> +return Status;
> >> +  }
> >> +
> >> +  Status = gCpu->FlushDataCache (
> >> +   gCpu,
> >> +   (EFI_PHYSICAL_ADDRESS)(UINTN)*HostAddress,
> >> +   EFI_PAGES_TO_SIZE (Pages),
> >> +   EfiCpuFlushTypeInvalidate);
> >> +  if (EFI_ERROR (Status)) {
> >> +NonCoherentPciIoFreeBuffer (This, Pages, *HostAddress);
> >> +  }
> >> +  return Status;
> >> +}
> >> +
> >> +STATIC
> >> +EFI_STATUS
> >> +NonCoherentPciIoMap (
> >> +  IN EFI_PCI_IO_PROTOCOL*This,
> >> +  IN EFI_PCI_IO_PROTOCOL_OPERATION  Operation,
> >> +  IN VOID   *HostAddress,
> >> +  IN OUT UINTN  *NumberOfBytes,
> >> +  OUTEFI_PHYSICAL_ADDRESS   *DeviceAddress,
> >> +  OUTVOID   **Mapping
> >> +  )
> >> +{
> >> +  PLATFORM_PCI_IO_DEV   *Dev;
> >> +  EFI_STATUSStatus;
> >> +  PLATFORM_PCI_IO_MAP_INFO  *MapInfo;
> >> +  UINTN AlignMask;
> >> +  VOID  *AllocAddress;
> >> +  EFI_GCD_MEMORY_SPACE_DESCRIPTOR   GcdDescriptor;
> >> +  BOOLEAN   UncachedMapping;
> >> +
> >> +  MapInfo = (PLATFORM_PCI_IO_MAP_INFO *)AllocatePool (sizeof *MapInfo);
> >> +  if (MapInfo == NULL) {
> >> +return EFI_OUT_OF_RESOURCES;
> >> +  }
> >> +
> >> +  MapInfo->HostAddress = HostAddress;
> >> +  MapInfo->Operation = Operation;
> >> +  MapInfo->NumberOfBytes = *NumberOfBytes;
> >> +
> >> +  //
> >> +  // Bounce buffering is not possible for consistent mappings, so
> >> +  // check we are mapping a cached buffer for consistent DMA
> >> +  //
> >> +  if (Operation == 

Re: [edk2] [PATCH 4/5] ArmPkg/CpuDxe: set DmaBufferAlignment according to CWG

2016-11-02 Thread Ard Biesheuvel
On 2 November 2016 at 16:10, Leif Lindholm  wrote:
> On Wed, Nov 02, 2016 at 01:40:17PM +, Ard Biesheuvel wrote:
>> On 1 November 2016 at 22:32, Leif Lindholm  wrote:
>> > On Mon, Oct 31, 2016 at 06:13:09PM +, Ard Biesheuvel wrote:
>> >> The DmaBufferAlignment currently defaults to 4, which is dangerously
>> >> small and may result in lost data on platform that perform non-coherent
>> >> DMA. So instead, take the CWG value from the cache info registers.
>> >>
>> >> Contributed-under: TianoCore Contribution Agreement 1.0
>> >> Signed-off-by: Ard Biesheuvel 
>> >> ---
>> >>  ArmPkg/Drivers/CpuDxe/CpuDxe.c | 4 +++-
>> >>  1 file changed, 3 insertions(+), 1 deletion(-)
>> >>
>> >> diff --git a/ArmPkg/Drivers/CpuDxe/CpuDxe.c 
>> >> b/ArmPkg/Drivers/CpuDxe/CpuDxe.c
>> >> index d089cb2d119f..ddc64fd255a0 100644
>> >> --- a/ArmPkg/Drivers/CpuDxe/CpuDxe.c
>> >> +++ b/ArmPkg/Drivers/CpuDxe/CpuDxe.c
>> >> @@ -225,7 +225,7 @@ EFI_CPU_ARCH_PROTOCOL mCpu = {
>> >>CpuGetTimerValue,
>> >>CpuSetMemoryAttributes,
>> >>0,  // NumberOfTimers
>> >> -  4,  // DmaBufferAlignment
>> >> +  2048,   // DmaBufferAlignment
>> >>  };
>> >>
>> >>  EFI_STATUS
>> >> @@ -239,6 +239,8 @@ CpuDxeInitialize (
>> >>
>> >>InitializeExceptions ();
>> >>
>> >> +  mCpu.DmaBufferAlignment = ArmCacheWritebackGranule ();
>> >> +
>> >
>> > Could we hide the internal structure of mCpu here by moving this to a
>> > helper function and calling
>> >   InitializeDma ();
>> > (or something)?
>> >
>>
>> We could, but why? The actual struct is defined 10 lines up
>
> It's just that it's the only place in this function we're prodding the
> internals of the object directly. Messes slightly with my zen.
> Not a strong opinion, just a preference.
>

Sure, if you want.

In fact, I will break this out as a separate patch, considering that
it fixes a serious bug.

So you are happy with the patch if I fold the following into it?

"""
--- a/ArmPkg/Drivers/CpuDxe/CpuDxe.c
+++ b/ArmPkg/Drivers/CpuDxe/CpuDxe.c
@@ -228,6 +228,15 @@ EFI_CPU_ARCH_PROTOCOL mCpu = {
   2048,   // DmaBufferAlignment
 };

+STATIC
+VOID
+InitializeDma (
+  IN OUT  EFI_CPU_ARCH_PROTOCOL   *CpuArchProtocol
+  )
+{
+  CpuArchProtocol->DmaBufferAlignment = ArmCacheWritebackGranule ();
+}
+
 EFI_STATUS
 CpuDxeInitialize (
   IN EFI_HANDLE ImageHandle,
@@ -239,7 +248,7 @@ CpuDxeInitialize (

   InitializeExceptions ();

-  mCpu.DmaBufferAlignment = ArmCacheWritebackGranule ();
+  InitializeDma ();

   Status = gBS->InstallMultipleProtocolInterfaces (
 ,
"""
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH 4/5] ArmPkg/CpuDxe: set DmaBufferAlignment according to CWG

2016-11-02 Thread Leif Lindholm
On Wed, Nov 02, 2016 at 01:40:17PM +, Ard Biesheuvel wrote:
> On 1 November 2016 at 22:32, Leif Lindholm  wrote:
> > On Mon, Oct 31, 2016 at 06:13:09PM +, Ard Biesheuvel wrote:
> >> The DmaBufferAlignment currently defaults to 4, which is dangerously
> >> small and may result in lost data on platform that perform non-coherent
> >> DMA. So instead, take the CWG value from the cache info registers.
> >>
> >> Contributed-under: TianoCore Contribution Agreement 1.0
> >> Signed-off-by: Ard Biesheuvel 
> >> ---
> >>  ArmPkg/Drivers/CpuDxe/CpuDxe.c | 4 +++-
> >>  1 file changed, 3 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/ArmPkg/Drivers/CpuDxe/CpuDxe.c 
> >> b/ArmPkg/Drivers/CpuDxe/CpuDxe.c
> >> index d089cb2d119f..ddc64fd255a0 100644
> >> --- a/ArmPkg/Drivers/CpuDxe/CpuDxe.c
> >> +++ b/ArmPkg/Drivers/CpuDxe/CpuDxe.c
> >> @@ -225,7 +225,7 @@ EFI_CPU_ARCH_PROTOCOL mCpu = {
> >>CpuGetTimerValue,
> >>CpuSetMemoryAttributes,
> >>0,  // NumberOfTimers
> >> -  4,  // DmaBufferAlignment
> >> +  2048,   // DmaBufferAlignment
> >>  };
> >>
> >>  EFI_STATUS
> >> @@ -239,6 +239,8 @@ CpuDxeInitialize (
> >>
> >>InitializeExceptions ();
> >>
> >> +  mCpu.DmaBufferAlignment = ArmCacheWritebackGranule ();
> >> +
> >
> > Could we hide the internal structure of mCpu here by moving this to a
> > helper function and calling
> >   InitializeDma ();
> > (or something)?
> >
> 
> We could, but why? The actual struct is defined 10 lines up

It's just that it's the only place in this function we're prodding the
internals of the object directly. Messes slightly with my zen.
Not a strong opinion, just a preference.

/
Leif


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


Re: [edk2] [PATCH 3/5] EmbeddedPkg: implement generic platform PCI I/O driver

2016-11-02 Thread Leif Lindholm
On Wed, Nov 02, 2016 at 01:39:26PM +, Ard Biesheuvel wrote:
> On 1 November 2016 at 22:22, Leif Lindholm  wrote:
> > On Mon, Oct 31, 2016 at 06:13:08PM +, Ard Biesheuvel wrote:
> >> This implements support for platform PCI I/O devices, i.e, devices that
> >> are not on a PCI bus but that can be drived by generic PCI drivers in
> >
> > drived->driven? (or substitute "controlled")
> >
> 
> That's a typo, not a speako. But yes, let me clean that up
>
> >> EDK2.
> >>
> >> This is implemented as a UEFI driver, which means we take full advantage
> >> of the UEFI driver model, and only instantiate those devices that are
> >> necessary for booting.
> >>
> >> Care is taken to deal with DMA addressing limitations: DMA mappings and
> >> allocations are moved below 4 GB if the PCI driver has not informed us
> >> that the device being driven is 64-bit DMA capable.
> >
> > How do we deal with these devices if there is no RAM below 4GB?
> > (Signalling an error and aborting is fine, but worth calling out even
> > here in the commit message.)
> >
> 
> The same thing the normal PCI I/O implementations do: return an error.
> If you plug in a EHCI controller on Seattle that does not support
> 64-bit DMA, calls to AllocateBuffer() and Map() will fail in exactly
> the same way.

OK - if it's that straightforward, please ignore all of my other
comments on that topic.

> >>
> >> For now, this driver supports coherent DMA only, but support for
> >> non-coherent DMA is planned as well.
> >>
> >> Contributed-under: TianoCore Contribution Agreement 1.0
> >> Signed-off-by: Ard Biesheuvel 
> >> ---
> >>  EmbeddedPkg/Drivers/PlatformPciIoDxe/PlatformPciIo.c  | 649 
> >> 
> >>  EmbeddedPkg/Drivers/PlatformPciIoDxe/PlatformPciIo.h  |  67 ++
> >>  EmbeddedPkg/Drivers/PlatformPciIoDxe/PlatformPciIoDxe.c   | 268 
> >>  EmbeddedPkg/Drivers/PlatformPciIoDxe/PlatformPciIoDxe.inf |  41 ++
> >>  EmbeddedPkg/EmbeddedPkg.dsc   |   1 +
> >>  5 files changed, 1026 insertions(+)
> >>
> >> diff --git a/EmbeddedPkg/Drivers/PlatformPciIoDxe/PlatformPciIo.c 
> >> b/EmbeddedPkg/Drivers/PlatformPciIoDxe/PlatformPciIo.c
> >> new file mode 100644
> >> index ..97ed19353347
> >> --- /dev/null
> >> +++ b/EmbeddedPkg/Drivers/PlatformPciIoDxe/PlatformPciIo.c
> >> @@ -0,0 +1,649 @@
> >> +/** @file
> >> +
> >> +  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
> >> +  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 "PlatformPciIo.h"
> >> +
> >> +#include 
> >> +
> >> +typedef struct {
> >> +  EFI_PHYSICAL_ADDRESSAllocAddress;
> >> +  VOID*HostAddress;
> >> +  EFI_PCI_IO_PROTOCOL_OPERATION   Operation;
> >> +  UINTN   NumberOfBytes;
> >> +} PLATFORM_PCI_IO_MAP_INFO;
> >> +
> >> +STATIC
> >> +EFI_STATUS
> >> +PciIoPollMem (
> >> +  IN  EFI_PCI_IO_PROTOCOL  *This,
> >> +  IN  EFI_PCI_IO_PROTOCOL_WIDTHWidth,
> >> +  IN  UINT8BarIndex,
> >> +  IN  UINT64   Offset,
> >> +  IN  UINT64   Mask,
> >> +  IN  UINT64   Value,
> >> +  IN  UINT64   Delay,
> >> +  OUT UINT64   *Result
> >> +  )
> >> +{
> >> +  ASSERT (FALSE);
> >> +  return EFI_UNSUPPORTED;
> >> +}
> >> +
> >> +STATIC
> >> +EFI_STATUS
> >> +PciIoPollIo (
> >> +  IN  EFI_PCI_IO_PROTOCOL  *This,
> >> +  IN  EFI_PCI_IO_PROTOCOL_WIDTHWidth,
> >> +  IN  UINT8BarIndex,
> >> +  IN  UINT64   Offset,
> >> +  IN  UINT64   Mask,
> >> +  IN  UINT64   Value,
> >> +  IN  UINT64   Delay,
> >> +  OUT UINT64   *Result
> >> +  )
> >> +{
> >> +  ASSERT (FALSE);
> >> +  return EFI_UNSUPPORTED;
> >> +}
> >> +
> >> +STATIC
> >> +EFI_STATUS
> >> +PciIoMemRW (
> >> +  INEFI_PCI_IO_PROTOCOL_WIDTH Width,
> >> +  INUINTN Count,
> >> +  INUINTN DstStride,
> >> +  INVOID  *Dst,
> >> +  INUINTN SrcStride,
> >> +  OUT   CONST VOID*Src
> >> +  )
> >> +{
> >> +  UINT8 *Dst8;
> >> +  UINT16*Dst16;
> >> +  UINT32*Dst32;
> >> +  CONST UINT8   *Src8;
> >> +  CONST UINT16  *Src16;
> >> +  CONST UINT32  *Src32;
> >
> > 

Re: [edk2] [PATCH 1/5] EmbeddedPkg: introduce platform PCI I/O protocol

2016-11-02 Thread Leif Lindholm
On Wed, Nov 02, 2016 at 01:29:06PM +, Ard Biesheuvel wrote:
> >> +//
> >> +// Data Types
> >> +//
> >> +typedef enum {
> >> +  PlatformPciIoDeviceOhci,
> >> +  PlatformPciIoDeviceUhci,
> >> +  PlatformPciIoDeviceEhci,
> >> +  PlatformPciIoDeviceXhci,
> >> +  PlatformPciIoDeviceAhci,
> >
> > SdMmc and Ufs?
> >
> 
> Indeed. I have added both: SDHCI works in QEMU but I can't really test UFS.

Haojian - are you able to help out with testing UFS?

Regards,

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


Re: [edk2] [PATCH 2/5] EmbeddedPkg: introduce platform PCI I/O registration library

2016-11-02 Thread Leif Lindholm
On Wed, Nov 02, 2016 at 01:30:22PM +, Ard Biesheuvel wrote:
> On 1 November 2016 at 21:57, Leif Lindholm  wrote:
> > On Mon, Oct 31, 2016 at 06:13:07PM +, Ard Biesheuvel wrote:
> >> diff --git 
> >> a/EmbeddedPkg/Library/PlatformPciIoDeviceRegistrationLib/PlatformPciIoDeviceRegistrationLib.inf
> >>  
> >> b/EmbeddedPkg/Library/PlatformPciIoDeviceRegistrationLib/PlatformPciIoDeviceRegistrationLib.inf
> >> new file mode 100644
> >> index ..282db3ab59ab
> >> --- /dev/null
> >> +++ 
> >> b/EmbeddedPkg/Library/PlatformPciIoDeviceRegistrationLib/PlatformPciIoDeviceRegistrationLib.inf
> >> @@ -0,0 +1,34 @@
> >> +# @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.
> >> +#
> >> +
> >> +[Defines]
> >> +  INF_VERSION= 0x00010017
> >
> > Not 0019?
> >
> 
> What can I say, I'm old school :-)
> 
> On the one hand, I'm happy to change it, but on the other hand, I
> think it is good practice to expose the lowest version number you are
> compatible with, in case anyone wants to backport this.

That's a good point - and something that would be useful to have
official guidelines for.

Andrew, Mike - what's your take on this? Should we have a recommended
"maximum INF_VERSION" for core protocols/libraries?

Regards,

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


[edk2] [PATCH V8 3/7] UefiCpuPkg/UefiCpuPkg.dec: Add Microcode capsule related definition.

2016-11-02 Thread Jiewen Yao
1) Add Microcode capsule related GUID.
   gMicrocodeFmpImageTypeIdGuid
2) Add Microcode capsule related library.
   MicrocodeFlashAccessLib

Cc: Jeff Fan 
Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: Jeff Fan 
---
 UefiCpuPkg/UefiCpuPkg.dec | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec
index 8674533..542704b 100644
--- a/UefiCpuPkg/UefiCpuPkg.dec
+++ b/UefiCpuPkg/UefiCpuPkg.dec
@@ -54,9 +54,16 @@
   ##
   MpInitLib|Include/Library/MpInitLib.h
 
+  ## @libraryclass  Provides services to access Microcode region on flash 
device.
+  #
+  MicrocodeFlashAccessLib|Include/Library/MicrocodeFlashAccessLib.h
+
 [Guids]
   gUefiCpuPkgTokenSpaceGuid  = { 0xac05bf33, 0x995a, 0x4ed4, { 0xaa, 0xb8, 
0xef, 0x7a, 0xe8, 0xf, 0x5c, 0xb0 }}
 
+  ## Include/Guid/MicrocodeFmp.h
+  gMicrocodeFmpImageTypeIdGuid  = { 0x96d4fdcd, 0x1502, 0x424d, { 0x9d, 
0x4c, 0x9b, 0x12, 0xd2, 0xdc, 0xae, 0x5c } }
+
 [Protocols]
   ## Include/Protocol/SmmCpuService.h
   gEfiSmmCpuServiceProtocolGuid  = { 0x1d202cab, 0xc8ab, 0x4d5c, { 0x94, 0xf7, 
0x3c, 0xfc, 0xc0, 0xd3, 0xd3, 0x35 }}
-- 
2.7.4.windows.1

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


[edk2] [PATCH V8 7/7] UefiCpuPkg/UefiCpuPkg.dsc: Add MicrocodeCapsule related component.

2016-11-02 Thread Jiewen Yao
Add Microcode capsule related component to check build.

Cc: Jeff Fan 
Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: Jeff Fan 
---
 UefiCpuPkg/UefiCpuPkg.dsc | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc
index bfe0fbd..624641f 100644
--- a/UefiCpuPkg/UefiCpuPkg.dsc
+++ b/UefiCpuPkg/UefiCpuPkg.dsc
@@ -61,6 +61,7 @@
   SmmCpuFeaturesLib|UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
   
PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf
   
PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeCoffExtraActionLibNull.inf
+  
MicrocodeFlashAccessLib|UefiCpuPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.inf
 
 [LibraryClasses.common.SEC]
   PlatformSecLib|UefiCpuPkg/Library/PlatformSecLibNull/PlatformSecLibNull.inf
@@ -131,6 +132,7 @@
   UefiCpuPkg/SecCore/SecCore.inf
   UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf
   UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf
+  UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdateDxe.inf
 
 [BuildOptions]
   *_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES
-- 
2.7.4.windows.1

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


[edk2] [PATCH V8 7/7] QuarkPlatformPkg/Readme: add capsule/recovery related content.

2016-11-02 Thread Jiewen Yao
Cc: Michael D Kinney 
Cc: Kelly Steele 
Cc: Feng Tian 
Cc: Star Zeng 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
---
 QuarkPlatformPkg/Readme.md | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/QuarkPlatformPkg/Readme.md b/QuarkPlatformPkg/Readme.md
index 8f5b898..f925f9e 100644
--- a/QuarkPlatformPkg/Readme.md
+++ b/QuarkPlatformPkg/Readme.md
@@ -146,6 +146,8 @@ features on the build command line using ```-D``` flags.
 | ```SECURE_BOOT_ENABLE```   | FALSE | TRUE, FALSE  |
 | ```MEASURED_BOOT_ENABLE``` | FALSE | TRUE, FALSE  |
 | ```TPM_12_HARDWARE```  |  NONE | NONE, LPC, ATMEL_I2C, 
INFINEON_I2C |
+| ```CAPSULE_ENABLE```   | FALSE | TRUE, FALSE  |
+| ```RECOVERY_ENABLE```  | FALSE | TRUE, FALSE  |
 
 * ```GALILEO``` - Used to specify the type of Intel(R) Galileo board type.  The
   default is ```GEN2``` for the [Intel(R) Galileo Gen 2 Development Board](
@@ -199,6 +201,22 @@ features on the build command line using ```-D``` flags.
   has been tested with the 
[CryptoShield](https://www.sparkfun.com/products/13183)
   available from [SparkFun](https://www.sparkfun.com/).
 
+* ```CAPSULE_ENABLE``` - Used to enable/disable capsule update features.
+  The default is FALSE for disabled.  Add ```-D CAPSULE_ENABLE``` to the
+  build command line to enable capsule update features.
+  The build process generate capsule update image - 
QUARKFIRMWAREUPDATECAPSULEFMPPKCS7.Cap.
+  The user need copy QUARKFIRMWAREUPDATECAPSULEFMPPKCS7.Cap and CapsuleApp.efi
+  to a storage media attached to the Quark Board.
+  Then the user can boot to shell and run ```CapsuleApp 
QUARKFIRMWAREUPDATECAPSULEFMPPKCS7.Cap```.
+  In next reboot, the system firmware is updated.
+
+* ```RECOVERY_ENABLE``` - Used to enable/disable recovery features.
+  The default is FALSE for disabled.  Add ```-D RECOVERY_ENABLE``` to the
+  build command line to enable recovery features.
+  The build process generates the recovery capsule image - QUARKREC.Cap.
+  Then the user need copy QUARKREC.Cap to a USB KEY, plug the USB KEY to the 
Quark Board.
+  In next boot, if a user runs ForceRecovery.efi in shell, or if a user 
presses the RESET button during power on, warm reset or REBOOT,
+  or if the FvMain is corrupted in flash, the system will boot into recovery 
mode.
 
 ### **Example Build Commands**
 
-- 
2.7.4.windows.1

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


[edk2] [PATCH V8 5/7] QuarkPlatformPkg/PlatformBootManager: Add capsule/recovery handling.

2016-11-02 Thread Jiewen Yao
1) Add capsule and recovery boot path handling in platform BDS.
2) Add check if the platform is using default test key for capsule.
Produce PcdTestKeyUsed to indicate if there is any
test key used in current BIOS, such as recovery key,
or capsule update key.
Then the generic UI may consume this PCD to show warning information.

Cc: Michael D Kinney 
Cc: Kelly Steele 
Cc: Feng Tian 
Cc: Star Zeng 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
---
 QuarkPlatformPkg/Library/PlatformBootManagerLib/PlatformBootManager.c  | 
131 +++-
 QuarkPlatformPkg/Library/PlatformBootManagerLib/PlatformBootManager.h  |   
9 +-
 QuarkPlatformPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf |  
17 ++-
 3 files changed, 152 insertions(+), 5 deletions(-)

diff --git 
a/QuarkPlatformPkg/Library/PlatformBootManagerLib/PlatformBootManager.c 
b/QuarkPlatformPkg/Library/PlatformBootManagerLib/PlatformBootManager.c
index 19ff3d0..7cb9628 100644
--- a/QuarkPlatformPkg/Library/PlatformBootManagerLib/PlatformBootManager.c
+++ b/QuarkPlatformPkg/Library/PlatformBootManagerLib/PlatformBootManager.c
@@ -2,7 +2,7 @@
 This file include all platform action which can be customized
 by IBV/OEM.
 
-Copyright (c) 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2015 - 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
@@ -205,6 +205,8 @@ PlatformBootManagerBeforeConsole (
   EFI_INPUT_KEY Enter;
   EFI_INPUT_KEY F2;
   EFI_BOOT_MANAGER_LOAD_OPTION  BootOption;
+  ESRT_MANAGEMENT_PROTOCOL  *EsrtManagement;
+  EFI_BOOT_MODE BootMode;
   EFI_ACPI_S3_SAVE_PROTOCOL *AcpiS3Save;
   EFI_HANDLEHandle;
   EFI_EVENT EndOfDxeEvent;
@@ -246,6 +248,40 @@ PlatformBootManagerBeforeConsole (
   //
   PlatformRegisterFvBootOption (, L"UEFI Shell", 
LOAD_OPTION_ACTIVE);
 
+  Status = gBS->LocateProtocol(, NULL, (VOID 
**));
+  if (EFI_ERROR(Status)) {
+EsrtManagement = NULL;
+  }
+
+  BootMode = GetBootModeHob();
+  switch (BootMode) {
+  case BOOT_ON_FLASH_UPDATE:
+DEBUG((DEBUG_INFO, "ProcessCapsules Before EndOfDxe ..\n"));
+Status = ProcessCapsules ();
+DEBUG((DEBUG_INFO, "ProcessCapsules %r\n", Status));
+break;
+  case BOOT_IN_RECOVERY_MODE:
+break;
+  case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES:
+  case BOOT_WITH_MINIMAL_CONFIGURATION:
+  case BOOT_ON_S4_RESUME:
+if (EsrtManagement != NULL) {
+  //
+  // Lock ESRT cache repository before EndofDxe if ESRT sync is not needed
+  //
+  EsrtManagement->LockEsrtRepository();
+}
+break;
+  default:
+//
+// Require to sync ESRT from FMP in a new boot
+//
+if (EsrtManagement != NULL) {
+  EsrtManagement->SyncEsrtFmp();
+}
+break;
+  }
+
   //
   // Prepare for S3
   //
@@ -303,7 +339,64 @@ PlatformBootManagerAfterConsole (
   VOID
   )
 {
-  EFI_STATUS  Status;
+  EFI_STATUS Status;
+  EFI_BOOT_MODE  BootMode;
+  ESRT_MANAGEMENT_PROTOCOL   *EsrtManagement;
+  VOID   *Buffer;
+  UINTN  Size;
+
+  Status = gBS->LocateProtocol(, NULL, (VOID 
**));
+  if (EFI_ERROR(Status)) {
+EsrtManagement = NULL;
+  }
+
+  BootMode = GetBootModeHob();
+  switch (BootMode) {
+  case BOOT_ON_FLASH_UPDATE:
+DEBUG((DEBUG_INFO, "Capsule Mode detected\n"));
+if (FeaturePcdGet(PcdSupportUpdateCapsuleReset)) {
+  EfiBootManagerConnectAll ();
+  EfiBootManagerRefreshAllBootOption ();
+
+  //
+  // Always sync ESRT Cache from FMP Instances after connect all and 
before capsule process
+  //
+  if (EsrtManagement != NULL) {
+EsrtManagement->SyncEsrtFmp();
+  }
+
+  DEBUG((DEBUG_INFO, "ProcessCapsules After ConnectAll ..\n"));
+  Status = ProcessCapsules();
+  DEBUG((DEBUG_INFO, "ProcessCapsules %r\n", Status));
+}
+break;
+
+  case BOOT_IN_RECOVERY_MODE:
+DEBUG((DEBUG_INFO, "Recovery Mode detected\n"));
+// Passthrough
+
+  case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES:
+  case BOOT_WITH_MINIMAL_CONFIGURATION:
+  case BOOT_WITH_FULL_CONFIGURATION:
+  case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS:
+  case BOOT_WITH_DEFAULT_SETTINGS:
+  default:
+EfiBootManagerConnectAll ();
+EfiBootManagerRefreshAllBootOption ();
+
+//
+// Sync ESRT Cache from FMP Instance on demand after Connect All
+//
+if ((BootMode != BOOT_ASSUMING_NO_CONFIGURATION_CHANGES) &&
+(BootMode != 

[edk2] [PATCH V8 2/7] QuarkPlatformPkg/SystemFirmwareDescriptor: Add Descriptor for capsule.

2016-11-02 Thread Jiewen Yao
Add SystemFirmwareDescriptor for capsule update.
The PEIM extracts SystemFirmwareDescriptor info from FFS and reports
it via PCD.

Cc: Michael D Kinney 
Cc: Kelly Steele 
Cc: Feng Tian 
Cc: Star Zeng 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
---
 
QuarkPlatformPkg/Feature/Capsule/SystemFirmwareDescriptor/SystemFirmwareDescriptor.aslc
 | 89 
 
QuarkPlatformPkg/Feature/Capsule/SystemFirmwareDescriptor/SystemFirmwareDescriptor.inf
  | 46 ++
 
QuarkPlatformPkg/Feature/Capsule/SystemFirmwareDescriptor/SystemFirmwareDescriptorPei.c
 | 66 +++
 3 files changed, 201 insertions(+)

diff --git 
a/QuarkPlatformPkg/Feature/Capsule/SystemFirmwareDescriptor/SystemFirmwareDescriptor.aslc
 
b/QuarkPlatformPkg/Feature/Capsule/SystemFirmwareDescriptor/SystemFirmwareDescriptor.aslc
new file mode 100644
index 000..693a632
--- /dev/null
+++ 
b/QuarkPlatformPkg/Feature/Capsule/SystemFirmwareDescriptor/SystemFirmwareDescriptor.aslc
@@ -0,0 +1,89 @@
+/** @file
+  System Firmware descriptor.
+
+  Copyright (c) 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 
+
+#define PACKAGE_VERSION 0x
+#define PACKAGE_VERSION_STRING  L"Unknown"
+
+#define CURRENT_FIRMWARE_VERSION0x0002
+#define CURRENT_FIRMWARE_VERSION_STRING L"0x0002"
+#define LOWEST_SUPPORTED_FIRMWARE_VERSION   0x0001
+
+#define IMAGE_IDSIGNATURE_64('Q', 'U', 'A', 'R', 
'K', '_', 'F', 'd')
+#define IMAGE_ID_STRING L"QuarkPlatformFd"
+
+// PcdSystemFmpCapsuleImageTypeIdGuid
+#define IMAGE_TYPE_ID_GUID  { 0x62af20c0, 0x7016, 0x424a, { 
0x9b, 0xf8, 0x9c, 0xcc, 0x86, 0x58, 0x40, 0x90 } }
+
+typedef struct {
+  EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR  Descriptor;
+  // real string data
+  CHAR16  ImageIdNameStr[16];
+  CHAR16  VersionNameStr[16];
+  CHAR16  PackageVersionNameStr[16];
+} IMAGE_DESCRIPTOR;
+
+IMAGE_DESCRIPTOR mImageDescriptor =
+{
+  {
+EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR_SIGNATURE,
+sizeof(EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR),
+sizeof(IMAGE_DESCRIPTOR),
+PACKAGE_VERSION,   // PackageVersion
+OFFSET_OF (IMAGE_DESCRIPTOR, PackageVersionNameStr),   // 
PackageVersionName
+1, // ImageIndex;
+{0x0}, // Reserved
+IMAGE_TYPE_ID_GUID,// ImageTypeId;
+IMAGE_ID,  // ImageId;
+OFFSET_OF (IMAGE_DESCRIPTOR, ImageIdNameStr),  // ImageIdName;
+CURRENT_FIRMWARE_VERSION,  // Version;
+OFFSET_OF (IMAGE_DESCRIPTOR, VersionNameStr),  // VersionName;
+{0x0}, // Reserved2
+FixedPcdGet32(PcdFlashAreaSize),   // Size;
+IMAGE_ATTRIBUTE_IMAGE_UPDATABLE |
+  IMAGE_ATTRIBUTE_RESET_REQUIRED |
+  IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED |
+  IMAGE_ATTRIBUTE_IN_USE,  // 
AttributesSupported;
+IMAGE_ATTRIBUTE_IMAGE_UPDATABLE |
+  IMAGE_ATTRIBUTE_RESET_REQUIRED |
+  IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED |
+  IMAGE_ATTRIBUTE_IN_USE,  // 
AttributesSetting;
+0x0,   // Compatibilities;
+LOWEST_SUPPORTED_FIRMWARE_VERSION, // 
LowestSupportedImageVersion;
+0x,// 
LastAttemptVersion;
+0, // 
LastAttemptStatus;
+{0x0}, // Reserved3
+0, // HardwareInstance;
+  },
+  // real string data
+  {IMAGE_ID_STRING},
+  {CURRENT_FIRMWARE_VERSION_STRING},
+  {PACKAGE_VERSION_STRING},
+};
+
+
+VOID*
+ReferenceAcpiTable (
+  VOID
+  )
+{
+  //
+  // Reference the table being generated to prevent the optimizer from
+  // removing the data structure from the executable
+  //
+  return (VOID*)
+}
diff --git 

[edk2] [PATCH V8 2/7] UefiCpuPkg/Include: Add MicrocodeFlashAccessLib header.

2016-11-02 Thread Jiewen Yao
This library is used to abstract microcode flash region access.
This library is consumed by a microcode capsule update module.

Cc: Jeff Fan 
Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: Jeff Fan 
---
 UefiCpuPkg/Include/Library/MicrocodeFlashAccessLib.h | 39 
 1 file changed, 39 insertions(+)

diff --git a/UefiCpuPkg/Include/Library/MicrocodeFlashAccessLib.h 
b/UefiCpuPkg/Include/Library/MicrocodeFlashAccessLib.h
new file mode 100644
index 000..0dfc3ef
--- /dev/null
+++ b/UefiCpuPkg/Include/Library/MicrocodeFlashAccessLib.h
@@ -0,0 +1,39 @@
+/** @file
+  Microcode flash device access library.
+
+  Copyright (c) 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.
+
+**/
+
+
+#ifndef __MICROCODE_FLASH_ACCESS_LIB_H__
+#define __MICROCODE_FLASH_ACCESS_LIB_H__
+
+/**
+  Perform microcode write opreation.
+
+  @param[in] FlashAddress  The address of flash device to be accessed.
+  @param[in] BufferThe pointer to the data buffer.
+  @param[in] LengthThe length of data buffer in bytes.
+
+  @retval EFI_SUCCESS   The operation returns successfully.
+  @retval EFI_WRITE_PROTECTED   The flash device is read only.
+  @retval EFI_UNSUPPORTED   The flash device access is unsupported.
+  @retval EFI_INVALID_PARAMETER The input parameter is not valid.
+**/
+EFI_STATUS
+EFIAPI
+MicrocodeFlashWrite (
+  IN EFI_PHYSICAL_ADDRESS FlashAddress,
+  IN VOID *Buffer,
+  IN UINTNLength
+  );
+
+#endif
-- 
2.7.4.windows.1

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


[edk2] [PATCH V8 4/7] UefiCpuPkg/MicrocodeFlashAccessLib: Add NULL MicrocodeFlashAccessLib.

2016-11-02 Thread Jiewen Yao
Add NULL instance to pass build.

Cc: Jeff Fan 
Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: Jeff Fan 
---
 
UefiCpuPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.c
   | 42 
 
UefiCpuPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.inf
 | 40 +++
 
UefiCpuPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.uni
 | 21 ++
 3 files changed, 103 insertions(+)

diff --git 
a/UefiCpuPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.c
 
b/UefiCpuPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.c
new file mode 100644
index 000..7a5ec15
--- /dev/null
+++ 
b/UefiCpuPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.c
@@ -0,0 +1,42 @@
+/** @file
+  Microcode flash device access library NULL instance.
+
+  Copyright (c) 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 
+
+/**
+  Perform microcode write opreation.
+
+  @param[in] FlashAddress  The address of flash device to be accessed.
+  @param[in] BufferThe pointer to the data buffer.
+  @param[in] LengthThe length of data buffer in bytes.
+
+  @retval EFI_SUCCESS   The operation returns successfully.
+  @retval EFI_WRITE_PROTECTED   The flash device is read only.
+  @retval EFI_UNSUPPORTED   The flash device access is unsupported.
+  @retval EFI_INVALID_PARAMETER The input parameter is not valid.
+**/
+EFI_STATUS
+EFIAPI
+MicrocodeFlashWrite (
+  IN EFI_PHYSICAL_ADDRESS FlashAddress,
+  IN VOID *Buffer,
+  IN UINTNLength
+  )
+{
+  CopyMem((VOID *)(UINTN)(FlashAddress), Buffer, Length);
+  return EFI_SUCCESS;
+}
diff --git 
a/UefiCpuPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.inf
 
b/UefiCpuPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.inf
new file mode 100644
index 000..a4a47e0
--- /dev/null
+++ 
b/UefiCpuPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.inf
@@ -0,0 +1,40 @@
+## @file
+#  Microcode flash device access library.
+#
+#  Microcode flash device access library NULL instance.
+#
+#  Copyright (c) 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.
+#
+##
+
+[Defines]
+  INF_VERSION= 0x00010005
+  BASE_NAME  = MicrocodeFlashAccessLibNull
+  MODULE_UNI_FILE= MicrocodeFlashAccessLibNull.uni
+  FILE_GUID  = 6F871ADD-9D86-4676-8BAD-68E2E451FC5B
+  MODULE_TYPE= BASE
+  VERSION_STRING = 1.0
+  LIBRARY_CLASS  = MicrocodeFlashAccessLib
+
+#
+# The following information is for reference only and not required by the 
build tools.
+#
+#  VALID_ARCHITECTURES   = IA32 X64 IPF EBC
+#
+
+[Sources]
+  MicrocodeFlashAccessLibNull.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  UefiCpuPkg/UefiCpuPkg.dec
+
+[LibraryClasses]
+  BaseMemoryLib
diff --git 
a/UefiCpuPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.uni
 
b/UefiCpuPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.uni
new file mode 100644
index 000..cc4195c
--- /dev/null
+++ 
b/UefiCpuPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.uni
@@ -0,0 +1,21 @@
+// /** @file
+//  Microcode flash device access library.
+//
+//  Microcode flash device access library NULL instance.
+//
+// Copyright (c) 2016, Intel Corporation. All rights reserved.
+//
+// This program and the accompanying materials
+// are licensed and made available under the terms and 

[edk2] [PATCH V8 6/7] UefiCpuPkg/MicrocodeUpdate: Add Microcode FMP build sample

2016-11-02 Thread Jiewen Yao
This folder provides the sample build for Microcode FMP.
The DSC/FDF is to convert the Microcode binary/text to Microcode FMP.

Cc: Jeff Fan 
Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
---
 UefiCpuPkg/Feature/Capsule/MicrocodeCapsulePdb/MicrocodeCapsulePdb.dsc | 32 
+
 UefiCpuPkg/Feature/Capsule/MicrocodeCapsulePdb/MicrocodeCapsulePdb.fdf | 32 
+
 UefiCpuPkg/Feature/Capsule/MicrocodeCapsulePdb/Readme.md   | 20 
+++
 UefiCpuPkg/Feature/Capsule/MicrocodeCapsuleTxt/Microcode/Microcode.inf | 27 
++
 UefiCpuPkg/Feature/Capsule/MicrocodeCapsuleTxt/MicrocodeCapsuleTxt.dsc | 38 

 UefiCpuPkg/Feature/Capsule/MicrocodeCapsuleTxt/MicrocodeCapsuleTxt.fdf | 32 
+
 UefiCpuPkg/Feature/Capsule/MicrocodeCapsuleTxt/Readme.md   | 33 
+
 7 files changed, 214 insertions(+)

diff --git 
a/UefiCpuPkg/Feature/Capsule/MicrocodeCapsulePdb/MicrocodeCapsulePdb.dsc 
b/UefiCpuPkg/Feature/Capsule/MicrocodeCapsulePdb/MicrocodeCapsulePdb.dsc
new file mode 100644
index 000..b8ab08d
--- /dev/null
+++ b/UefiCpuPkg/Feature/Capsule/MicrocodeCapsulePdb/MicrocodeCapsulePdb.dsc
@@ -0,0 +1,32 @@
+## @file
+#
+# Copyright (c) 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.
+#
+##
+
+[Defines]
+#
+# Uncomment the following line and update with your platform pkg name
+#
+#  PLATFORM_NAME  = 
+  PLATFORM_GUID  = 6875FD33-602E-4EF9-9DF2-8BA7D8B7A7AF
+  PLATFORM_VERSION   = 0.1
+#
+# Uncomment the following line and update with your platform pkg name
+#
+#  FLASH_DEFINITION   = 
/MicrocodeCapsulePdb/MicrocodeCapsulePdb.fdf
+#
+# Uncomment the following line and update with your platform pkg name
+#
+#  OUTPUT_DIRECTORY   = Build/
+  SUPPORTED_ARCHITECTURES= IA32|X64
+  BUILD_TARGETS  = DEBUG|RELEASE
+  SKUID_IDENTIFIER   = DEFAULT
diff --git 
a/UefiCpuPkg/Feature/Capsule/MicrocodeCapsulePdb/MicrocodeCapsulePdb.fdf 
b/UefiCpuPkg/Feature/Capsule/MicrocodeCapsulePdb/MicrocodeCapsulePdb.fdf
new file mode 100644
index 000..f171604
--- /dev/null
+++ b/UefiCpuPkg/Feature/Capsule/MicrocodeCapsulePdb/MicrocodeCapsulePdb.fdf
@@ -0,0 +1,32 @@
+## @file
+#
+# Copyright (c) 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.
+#
+##
+
+[FmpPayload.FmpPayloadMicrocode1]
+IMAGE_HEADER_INIT_VERSION = 0x02
+IMAGE_TYPE_ID = 96d4fdcd-1502-424d-9d4c-9b12d2dcae5c # Microcode 
GUID (do not change it)
+IMAGE_INDEX   = 0x1
+HARDWARE_INSTANCE = 0x0
+
+#
+# Uncomment the following line and update with path to Microcode PDB file
+#
+#FILE DATA = $(WORKSPACE)//Microcode/Microcode.pdb
+
+[Capsule.MicrocodeCapsule]
+CAPSULE_GUID= 6dcbd5ed-e82d-4c44-bda1-7194199ad92a # FMP 
special Guid (do not change it)
+CAPSULE_FLAGS   = PersistAcrossReset,InitiateReset
+CAPSULE_HEADER_SIZE = 0x20
+CAPSULE_HEADER_INIT_VERSION = 0x1
+
+FMP_PAYLOAD = FmpPayloadMicrocode1
diff --git a/UefiCpuPkg/Feature/Capsule/MicrocodeCapsulePdb/Readme.md 
b/UefiCpuPkg/Feature/Capsule/MicrocodeCapsulePdb/Readme.md
new file mode 100644
index 000..9f81373
--- /dev/null
+++ b/UefiCpuPkg/Feature/Capsule/MicrocodeCapsulePdb/Readme.md
@@ -0,0 +1,20 @@
+# How to generate Microcode FMP from Microcode PDB file
+
+1) Copy directory `UefiCpuPkg/Feature/Capsule/MicrocodeUpdatePdb` to `/MicrocodeUpdatePdb`.
+
+2) Uncomment and update `FILE DATA` statement in `/MicrocodeUpdatePdb/MicrocodeCapsulePdb.fdf` with path to a Microcode 
PDB file.  The PDB file can placed in `/MicrocodeUpdatePdb` or any other path.
+
+`FILE DATA = `
+
+Uncomment and update `PLATFORM_NAME`, `FLASH_DEFINITION`, `OUTPUT_DIRECTORY` 
section in `/MicrocodeUpdatePdb/MicrocodeCapsulePdb.dsc` 
with .
+
+

[edk2] [PATCH V8 12/12] SignedCapsulePkg/CapsulePkg.dsc: Add capsule related component.

2016-11-02 Thread Jiewen Yao
Add capsule related component to check build.

Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: Liming Gao 
---
 SignedCapsulePkg/SignedCapsulePkg.dsc | 210 
 1 file changed, 210 insertions(+)

diff --git a/SignedCapsulePkg/SignedCapsulePkg.dsc 
b/SignedCapsulePkg/SignedCapsulePkg.dsc
new file mode 100644
index 000..7ea74d7
--- /dev/null
+++ b/SignedCapsulePkg/SignedCapsulePkg.dsc
@@ -0,0 +1,210 @@
+## @file
+# This package provides EDKII capsule related support.
+#
+# Copyright (c) 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.
+#
+##
+
+[Defines]
+  PLATFORM_NAME  = SignedCapsulePkg
+  PLATFORM_GUID  = 164E16D7-B56A-416D-92FF-0A63983733F6
+  PLATFORM_VERSION   = 0.96
+  DSC_SPECIFICATION  = 0x00010005
+  OUTPUT_DIRECTORY   = Build/SignedCapsulePkg
+  SUPPORTED_ARCHITECTURES= IA32|X64
+  BUILD_TARGETS  = DEBUG|RELEASE|NOOPT
+  SKUID_IDENTIFIER   = DEFAULT
+
+[LibraryClasses]
+  #
+  # Entry point
+  #
+  PeiCoreEntryPoint|MdePkg/Library/PeiCoreEntryPoint/PeiCoreEntryPoint.inf
+  PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf
+  DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf
+  
UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
+  
UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf
+  #
+  # Basic
+  #
+  BaseLib|MdePkg/Library/BaseLib/BaseLib.inf
+  BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
+  
SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf
+  PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf
+  IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
+  PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf
+  PciCf8Lib|MdePkg/Library/BasePciCf8Lib/BasePciCf8Lib.inf
+  PciSegmentLib|MdePkg/Library/BasePciSegmentLibPci/BasePciSegmentLibPci.inf
+  
CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf
+  PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
+  
PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf
+  SortLib|MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf
+  #
+  # UEFI & PI
+  #
+  
UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
+  
UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
+  UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf
+  UefiLib|MdePkg/Library/UefiLib/UefiLib.inf
+  
UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf
+  HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf
+  DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
+  
UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf
+  
PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf
+  PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf
+  DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf
+  
DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf
+  #
+  # Generic Modules
+  #
+  UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf
+  UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf
+  NetLib|MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf
+  IpIoLib|MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.inf
+  UdpIoLib|MdeModulePkg/Library/DxeUdpIoLib/DxeUdpIoLib.inf
+  TcpIoLib|MdeModulePkg/Library/DxeTcpIoLib/DxeTcpIoLib.inf
+  DpcLib|MdeModulePkg/Library/DxeDpcLib/DxeDpcLib.inf
+  
SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.inf
+  TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf
+  SerialPortLib|MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.inf
+  CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf
+  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
+  PalLib|MdePkg/Library/BasePalLibNull/BasePalLibNull.inf
+  
CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf
+  #
+  # Misc
+  

[edk2] [PATCH V8 5/9] Vlv2TbltDevicePkg/PlatformBootManager: Add capsule/recovery handling.

2016-11-02 Thread Jiewen Yao
1) Add capsule and recovery boot path handling in platform BDS.
2) Add check if the platform is using default test key for capsule.
Produce PcdTestKeyUsed to indicate if there is any
test key used in current BIOS, such as recovery key,
or capsule update key.
Then the generic UI may consume this PCD to show warning information.

Cc: David Wei 
Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: David Wei 
---
 Vlv2TbltDevicePkg/Library/PlatformBdsLib/BdsPlatform.c  | 181 
++--
 Vlv2TbltDevicePkg/Library/PlatformBdsLib/PlatformBdsLib.inf |   8 +
 2 files changed, 134 insertions(+), 55 deletions(-)

diff --git a/Vlv2TbltDevicePkg/Library/PlatformBdsLib/BdsPlatform.c 
b/Vlv2TbltDevicePkg/Library/PlatformBdsLib/BdsPlatform.c
index e1f3524..004c5f5 100644
--- a/Vlv2TbltDevicePkg/Library/PlatformBdsLib/BdsPlatform.c
+++ b/Vlv2TbltDevicePkg/Library/PlatformBdsLib/BdsPlatform.c
@@ -1,15 +1,15 @@
 /** @file
 
   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 that 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.

-   


+   

+  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 

+  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.
+   

 
 
 Module Name:
@@ -45,6 +45,9 @@ Abstract:
 #include 
 #include 
 
+#include 
+#include 
+
 EFI_GUID *ConnectDriverTable[] = {
   ,
   ,
@@ -1585,7 +1588,7 @@ EFIAPI
 PlatformBdsPolicyBehavior (
   IN OUT LIST_ENTRY  *DriverOptionList,
   IN OUT LIST_ENTRY  *BootOptionList,
-  IN PROCESS_CAPSULESProcessCapsules,
+  IN PROCESS_CAPSULESBdsProcessCapsules,
   IN BASEM_MEMORY_TEST   BaseMemoryTest
   )
 {
@@ -1594,11 +1597,8 @@ PlatformBdsPolicyBehavior (
   EFI_BOOT_MODE  BootMode;
   BOOLEANDeferredImageExist;
   UINTN  Index;
-  CHAR16 CapsuleVarName[36];
-  CHAR16 *TempVarName;
   SYSTEM_CONFIGURATION   SystemConfiguration;
   UINTN  VarSize;
-  BOOLEANSetVariableFlag;
   PLATFORM_PCI_DEVICE_PATH   *EmmcBootDevPath;
   EFI_GLOBAL_NVS_AREA_PROTOCOL   *GlobalNvsArea;
   EFI_HANDLE FvProtocolHandle;
@@ -1612,13 +1612,14 @@ PlatformBdsPolicyBehavior (
   BOOLEANIsFirstBoot;
   UINT16 *BootOrder;
   UINTN  BootOrderSize;
+  ESRT_MANAGEMENT_PROTOCOL   *EsrtManagement;
 
   Timeout = PcdGet16 (PcdPlatformBootTimeOut);
   if (Timeout > 10 ) {
 //we think the Timeout variable is corrupted
 Timeout = 10;
   }
-   
+
   VarSize = sizeof(SYSTEM_CONFIGURATION);
   Status = gRT->GetVariable(
   NORMAL_SETUP_NAME,
@@ -1639,7 +1640,7 @@ PlatformBdsPolicyBehavior (
   
   );
 ASSERT_EFI_ERROR (Status);
-  }  
+  }
 
   //
   // Load the driver option as the driver option list
@@ -1652,37 +1653,6 @@ PlatformBdsPolicyBehavior (
   BootMode = GetBootModeHob();
 
   //
-  // Clear all the capsule variables CapsuleUpdateData, CapsuleUpdateData1, 
CapsuleUpdateData2...
-  // as early as possible which will avoid the next time boot after the 
capsule update
-  

[edk2] [PATCH V8 9/9] Vlv2TbltDevicePkg/Build: Add capsule/recovery in help info.

2016-11-02 Thread Jiewen Yao
Cc: David Wei 
Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: David Wei 
---
 Vlv2TbltDevicePkg/Build_IFWI.bat | 5 +
 1 file changed, 5 insertions(+)

diff --git a/Vlv2TbltDevicePkg/Build_IFWI.bat b/Vlv2TbltDevicePkg/Build_IFWI.bat
index e33a3bd..0b50b79 100644
--- a/Vlv2TbltDevicePkg/Build_IFWI.bat
+++ b/Vlv2TbltDevicePkg/Build_IFWI.bat
@@ -169,6 +169,11 @@ echoIFWI Suffix:  Suffix to append to end of 
IFWI filename (default:
 echo.
 echoSee  Stitch/Stitch_Config.txt  for additional stitching settings.
 echo.
+echoIf capsule update is needed, please update CAPSULE_ENABLE = TRUE 
in Config.dsc.
+echoIf recovery is needed, please update RECOVERY_ENABLE = TRUE in 
Config.dsc.
+echoIf either of above is TRUE, please set OPENSSL_PATH in windows 
evironment
+echoand put openssl.exe there, to generate final capsule image.
+echo.
 set exitCode=1
 
 :Exit
-- 
2.7.4.windows.1

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


[edk2] [PATCH V8 6/9] Vlv2TbltDevicePkg/dsc/fdf: Add capsule/recovery support.

2016-11-02 Thread Jiewen Yao
Add capsule and recovery support module in platform dsc and fdf.

Cc: David Wei 
Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: David Wei 
---
 Vlv2TbltDevicePkg/PlatformPkg.fdf   | 149 ++-
 Vlv2TbltDevicePkg/PlatformPkgConfig.dsc |   4 +-
 Vlv2TbltDevicePkg/PlatformPkgGcc.fdf| 150 +++-
 Vlv2TbltDevicePkg/PlatformPkgGccX64.dsc |  85 ++-
 Vlv2TbltDevicePkg/PlatformPkgIA32.dsc   |  85 ++-
 Vlv2TbltDevicePkg/PlatformPkgX64.dsc|  85 ++-
 6 files changed, 422 insertions(+), 136 deletions(-)

diff --git a/Vlv2TbltDevicePkg/PlatformPkg.fdf 
b/Vlv2TbltDevicePkg/PlatformPkg.fdf
index 93b4d2d..907c6bd 100644
--- a/Vlv2TbltDevicePkg/PlatformPkg.fdf
+++ b/Vlv2TbltDevicePkg/PlatformPkg.fdf
@@ -82,6 +82,9 @@ NumBlocks = $(FLASH_NUM_BLOCKS)  #The number of 
blocks in 3Mb FLASH
 SET gPlatformModuleTokenSpaceGuid.PcdFlashAreaBaseAddress= 
$(FLASH_AREA_BASE_ADDRESS)
 SET gPlatformModuleTokenSpaceGuid.PcdFlashAreaSize   = 
$(FLASH_AREA_SIZE)
 
+SET gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchAddress = 
$(FLASH_REGION_VLVMICROCODE_BASE) + 0x60
+SET gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchRegionSize = 
$(FLASH_REGION_VLVMICROCODE_SIZE) - 0x60
+
 !if $(MINNOW2_FSP_BUILD) == TRUE
 # put below PCD value setting into dsc file
 #SET gFspWrapperTokenSpaceGuid.PcdCpuMicrocodePatchAddress= 
$(FLASH_REGION_VLVMICROCODE_BASE)
@@ -242,6 +245,34 @@ FILE RAW = 197DB236-F856-4924-90F8-CDF12FB875F3 {
   
$(OUTPUT_DIRECTORY)\$(TARGET)_$(TOOL_CHAIN_TAG)\$(DXE_ARCHITECTURE)\MicrocodeUpdates.bin
 }
 
+!if $(RECOVERY_ENABLE)
+[FV.FVRECOVERY_COMPONENTS]
+FvAlignment= 16 #FV alignment and FV attributes setting.
+ERASE_POLARITY = 1
+MEMORY_MAPPED  = TRUE
+STICKY_WRITE   = TRUE
+LOCK_CAP   = TRUE
+LOCK_STATUS= TRUE
+WRITE_DISABLED_CAP = TRUE
+WRITE_ENABLED_CAP  = TRUE
+WRITE_STATUS   = TRUE
+WRITE_LOCK_CAP = TRUE
+WRITE_LOCK_STATUS  = TRUE
+READ_DISABLED_CAP  = TRUE
+READ_ENABLED_CAP   = TRUE
+READ_STATUS= TRUE
+READ_LOCK_CAP  = TRUE
+READ_LOCK_STATUS   = TRUE
+
+INF  RuleOverride = BINARY 
$(PLATFORM_BINARY_PACKAGE)/$(DXE_ARCHITECTURE)$(TARGET)/IA32/PchUsb.inf
+INF  MdeModulePkg/Bus/Pci/EhciPei/EhciPei.inf
+INF  MdeModulePkg/Bus/Usb/UsbBusPei/UsbBusPei.inf
+INF  MdeModulePkg/Bus/Usb/UsbBotPei/UsbBotPei.inf
+INF  FatPkg/FatPei/FatPei.inf
+INF  MdeModulePkg/Universal/Disk/CdExpressPei/CdExpressPei.inf
+INF  SignedCapsulePkg/Universal/RecoveryModuleLoadPei/RecoveryModuleLoadPei.inf
+!endif
+
 

 #
 # FV Section
@@ -306,6 +337,15 @@ INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf
 INF 
MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.inf
 !endif
 
+!if $(RECOVERY_ENABLE)
+FILE FV_IMAGE = 1E9D7604-EF45-46a0-BD8A-71AC78C17AC1 {
+  SECTION PEI_DEPEX_EXP = {gEfiPeiMemoryDiscoveredPpiGuid AND 
gEfiPeiBootInRecoveryModePpiGuid}
+  SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF {# LZMA COMPRESS GUID
+SECTION FV_IMAGE = FVRECOVERY_COMPONENTS
+  }
+}
+!endif
+
 [FV.FVRECOVERY]
 BlockSize  = $(FLASH_BLOCK_SIZE)
 FvAlignment= 16 #FV alignment and FV attributes setting.
@@ -373,6 +413,11 @@ INF RuleOverride = BINARY 
$(PLATFORM_BINARY_PACKAGE)/$(DXE_ARCHITECTURE)$(TARGET
 
 INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf
 
+!if $(CAPSULE_ENABLE) || $(RECOVERY_ENABLE)
+  # FMP image decriptor
+INF RuleOverride = FMP_IMAGE_DESC 
Vlv2TbltDevicePkg/Feature/Capsule/SystemFirmwareDescriptor/SystemFirmwareDescriptor.inf
+!endif
+
 [FV.FVMAIN]
 BlockSize  = $(FLASH_BLOCK_SIZE)
 FvAlignment= 16
@@ -717,6 +762,30 @@ FILE FREEFORM = 878AC2CC-5343-46F2-B563-51F89DAF56BA {
   !endif
 !endif
 
+!if $(CAPSULE_ENABLE) || $(MICOCODE_CAPSULE_ENABLE)
+INF  MdeModulePkg/Universal/EsrtDxe/EsrtDxe.inf
+!endif
+!if $(CAPSULE_ENABLE)
+INF  
SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareReportDxe.inf
+!endif
+!if $(MICOCODE_CAPSULE_ENABLE)
+INF  UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdateDxe.inf
+!endif
+
+!if $(RECOVERY_ENABLE)
+FILE FREEFORM = 
PCD(gEfiSignedCapsulePkgTokenSpaceGuid.PcdEdkiiRsa2048Sha256TestPublicKeyFileGuid)
 {
+ SECTION RAW = 
BaseTools/Source/Python/Rsa2048Sha256Sign/TestSigningPublicKey.bin
+ SECTION UI = "Rsa2048Sha256TestSigningPublicKey"
+ }
+!endif
+
+!if $(CAPSULE_ENABLE)
+FILE FREEFORM = 
PCD(gEfiSignedCapsulePkgTokenSpaceGuid.PcdEdkiiPkcs7TestPublicKeyFileGuid) {
+ SECTION RAW = BaseTools/Source/Python/Pkcs7Sign/TestRoot.cer
+ SECTION UI = "Pkcs7TestRoot"
+   

[edk2] [PATCH V8 8/9] Vlv2TbltDevicePkg/bat: add capsule generation in bat.

2016-11-02 Thread Jiewen Yao
If OPENSSL_PATH is set, the build process generates capsule.

Cc: David Wei 
Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: David Wei 
---
 Vlv2TbltDevicePkg/bld_vlv.bat | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/Vlv2TbltDevicePkg/bld_vlv.bat b/Vlv2TbltDevicePkg/bld_vlv.bat
index 547b2b1..e02a605 100644
--- a/Vlv2TbltDevicePkg/bld_vlv.bat
+++ b/Vlv2TbltDevicePkg/bld_vlv.bat
@@ -1,7 +1,7 @@
 @REM @file
 @REM   Windows batch file to build BIOS ROM
 @REM
-@REM Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
+@REM Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
 @REM This program and the accompanying materials
 @REM are licensed and made available under the terms and conditions of the BSD 
License
 @REM which accompanies this distribution.  The full text of the license may be 
found at
@@ -234,6 +234,7 @@ del /f/q ver_strings >nul
 
 set 
BIOS_Name=%BOARD_ID%_%Arch%_%BUILD_TYPE%_%VERSION_MAJOR%_%VERSION_MINOR%.ROM
 copy /y/b %BUILD_PATH%\FV\Vlv%Arch%.fd  %WORKSPACE%\%BIOS_Name% >nul
+copy /y/b %BUILD_PATH%\FV\Vlv%Arch%.fd  %BUILD_PATH%\FV\Vlv.ROM >nul
 
 echo.
 echo Build location: %BUILD_PATH%
@@ -241,6 +242,12 @@ echo BIOS ROM Created:   %BIOS_Name%
 echo.
 echo  The EDKII BIOS build has successfully completed. 

 echo.
+
+@REM build capsule here
+if "%openssl_path%" == "" goto Exit
+echo > %BUILD_PATH%\FV\SYSTEMFIRMWAREUPDATECARGO.Fv
+build -p %PLATFORM_PACKAGE%\PlatformCapsule.dsc
+
 goto Exit
 
 :Usage
-- 
2.7.4.windows.1

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


[edk2] [PATCH V8 7/9] Vlv2TbltDevicePkg/dsc/fdf: add capsule generation DSC/FDF.

2016-11-02 Thread Jiewen Yao
Add DSC/FDF to generate capsule image.
It is separated from normal DSC/FDF, because the FDF file need use
the result of final build.

Cc: David Wei 
Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: David Wei 
---
 Vlv2TbltDevicePkg/PlatformCapsule.dsc| 44 +++
 Vlv2TbltDevicePkg/PlatformCapsule.fdf| 81 
 Vlv2TbltDevicePkg/PlatformCapsuleGcc.fdf | 81 
 3 files changed, 206 insertions(+)

diff --git a/Vlv2TbltDevicePkg/PlatformCapsule.dsc 
b/Vlv2TbltDevicePkg/PlatformCapsule.dsc
new file mode 100644
index 000..a619ed8
--- /dev/null
+++ b/Vlv2TbltDevicePkg/PlatformCapsule.dsc
@@ -0,0 +1,44 @@
+#/** @file
+# Platform capsule description.
+#
+# Copyright (c) 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 that 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]
+  PLATFORM_NAME  = Vlv2TbltDevicePkg
+  PLATFORM_GUID  = EE87F258-6ECC-4415-B1D8-23771BEE26E7
+  PLATFORM_VERSION   = 0.1
+  FLASH_DEFINITION   = Vlv2TbltDevicePkg/PlatformCapsule.fdf
+  OUTPUT_DIRECTORY   = Build/Vlv2TbltDevicePkg
+  SUPPORTED_ARCHITECTURES= IA32|X64
+  BUILD_TARGETS  = DEBUG|RELEASE
+  SKUID_IDENTIFIER   = DEFAULT
+
+###
+#
+# Components Section - list of the modules and components that will be 
processed by compilation
+#  tools and the EDK II tools to generate PE32/PE32+/Coff 
image files.
+#
+# Note: The EDK II DSC file is not used to specify how compiled binary images 
get placed
+#   into firmware volume images. This section is just a list of modules to 
compile from
+#   source into UEFI-compliant binaries.
+#   It is the FDF file that contains information on combining binary files 
into firmware
+#   volume images, whose concept is beyond UEFI and is described in PI 
specification.
+#   Binary modules do not need to be listed in this section, as they 
should be
+#   specified in the FDF file. For example: Shell binary, FAT binary 
(Fat.efi),
+#   Logo (Logo.bmp), and etc.
+#   There may also be modules listed in this section that are not required 
in the FDF file,
+#   When a module listed here is excluded from FDF file, then 
UEFI-compliant binary will be
+#   generated for it, but the binary will not be put into any firmware 
volume.
+#
+###
diff --git a/Vlv2TbltDevicePkg/PlatformCapsule.fdf 
b/Vlv2TbltDevicePkg/PlatformCapsule.fdf
new file mode 100644
index 000..a80a75c
--- /dev/null
+++ b/Vlv2TbltDevicePkg/PlatformCapsule.fdf
@@ -0,0 +1,81 @@
+## @file
+# FDF file of Platform capsule.
+#
+# Copyright (c) 2016 Intel Corporation.
+#
+# 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.
+#
+##
+
+[FV.SystemFirmwareUpdateCargo]
+FvAlignment= 16
+ERASE_POLARITY = 1
+MEMORY_MAPPED  = TRUE
+STICKY_WRITE   = TRUE
+LOCK_CAP   = TRUE
+LOCK_STATUS= TRUE
+WRITE_DISABLED_CAP = TRUE
+WRITE_ENABLED_CAP  = TRUE
+WRITE_STATUS   = TRUE
+WRITE_LOCK_CAP = TRUE
+WRITE_LOCK_STATUS  = TRUE
+READ_DISABLED_CAP  = TRUE
+READ_ENABLED_CAP   = TRUE
+READ_STATUS= TRUE
+READ_LOCK_CAP  = TRUE
+READ_LOCK_STATUS   = TRUE
+
+FILE RAW = AF9C9EB2-12AD-4D3E-A4D4-96F6C9966215 { # 
PcdEdkiiSystemFirmwareFileGuid
+$(WORKSPACE)/$(OUTPUT_DIRECTORY)/$(TARGET)_$(TOOL_CHAIN_TAG)/FV/Vlv.ROM
+  }
+
+FILE RAW = ce57b167-b0e4-41e8-a897-5f4feb781d40 { # 
gEdkiiSystemFmpCapsuleDriverFvFileGuid
+
$(WORKSPACE)/$(OUTPUT_DIRECTORY)/$(TARGET)_$(TOOL_CHAIN_TAG)/FV/CAPSULEDISPATCHFV.Fv
+  }
+
+FILE RAW = 812136D3-4D3A-433A-9418-29BB9BF78F6E { # 
gEdkiiSystemFmpCapsuleConfigFileGuid
+

[edk2] [PATCH V8 4/9] Vlv2TbltDevicePkg/FlashDeviceLib: Add DXE flash device lib.

2016-11-02 Thread Jiewen Yao
Previous FlashDeviceLib only supports DxeRuntime and Smm.
It cannot be linked with SystemBiosUpdateDxe driver.

So we separate DxeRuntime related code into a standalone file,
and create FlashDeviceLibDxe.inf.

Cc: David Wei 
Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: David Wei 
---
 Vlv2TbltDevicePkg/Library/FlashDeviceLib/FlashDeviceLib.c  | 156 
+---
 Vlv2TbltDevicePkg/Library/FlashDeviceLib/FlashDeviceLib.inf|   8 +-
 Vlv2TbltDevicePkg/Library/FlashDeviceLib/FlashDeviceLibDxe.c   |  62 
+++
 Vlv2TbltDevicePkg/Library/FlashDeviceLib/FlashDeviceLibDxe.inf |  49 
+
 Vlv2TbltDevicePkg/Library/FlashDeviceLib/FlashDeviceLibDxeRuntimeSmm.c | 188 

 Vlv2TbltDevicePkg/Library/FlashDeviceLib/SpiChipDefinitions.h  |   5 +-
 6 files changed, 312 insertions(+), 156 deletions(-)

diff --git a/Vlv2TbltDevicePkg/Library/FlashDeviceLib/FlashDeviceLib.c 
b/Vlv2TbltDevicePkg/Library/FlashDeviceLib/FlashDeviceLib.c
index afb12c9..d964aa5 100644
--- a/Vlv2TbltDevicePkg/Library/FlashDeviceLib/FlashDeviceLib.c
+++ b/Vlv2TbltDevicePkg/Library/FlashDeviceLib/FlashDeviceLib.c
@@ -1,6 +1,6 @@
 /** @file
 
-  Copyright (c) 2004  - 2014, Intel Corporation. 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 that accompanies this 
distribution.  

@@ -19,14 +19,13 @@
 #include 
 #include 
 #include 
-#include 
-#include 
 #include 
-#include 
-#include 
 #include 
-#include "SpiChipDefinitions.h"
+#include 
 
+#define FLASH_SIZE  0x40
+
+#define FLASH_DEVICE_BASE_ADDRESS (0x-FLASH_SIZE+1)
 UINTN FlashDeviceBase = FLASH_DEVICE_BASE_ADDRESS;
 
 EFI_SPI_PROTOCOL *mSpiProtocol = NULL;
@@ -320,148 +319,3 @@ LibFvbFlashDeviceBlockLock (
   return Status;
 }
 
-VOID
-EFIAPI
-LibFvbFlashDeviceVirtualAddressChangeNotifyEvent (
-  IN EFI_EVENTEvent,
-  IN VOID *Context
-  )
-{
-  gRT->ConvertPointer (0, (VOID **) );
-  gRT->ConvertPointer (0, (VOID **) );
-}
-
-
-/**
-  The library constructuor.
-
-  The function does the necessary initialization work for this library
-  instance. Please put all initialization works in it.
-
-  @param[in]  ImageHandle   The firmware allocated handle for the UEFI 
image.
-  @param[in]  SystemTable   A pointer to the EFI system table.
-
-  @retval EFI_SUCCESS   The function always return EFI_SUCCESS for now.
-It will ASSERT on error for debug version.
-  @retval EFI_ERROR Please reference LocateProtocol for error code 
details.
-
-**/
-EFI_STATUS
-EFIAPI
-LibFvbFlashDeviceSupportInit (
-  IN EFI_HANDLE ImageHandle,
-  IN EFI_SYSTEM_TABLE   *SystemTable
-  )
-{
-  EFI_STATUS Status;
-  EFI_EVENT  Event;
-  UINT8 SfId[3];
-  UINT8 FlashIndex;
-  UINT8 SpiReadError;
-  UINT8 SpiNotMatchError;
-  EFI_SMM_BASE2_PROTOCOL   *SmmBase;
-  BOOLEAN   InSmm;
-
-  SpiReadError = 0x00;
-  SpiNotMatchError = 0x00;
-
-  InSmm = FALSE;
-  Status = gBS->LocateProtocol (
-  ,
-  NULL,
-  (void **)
-  );
-  if (!EFI_ERROR(Status)) {
-Status = SmmBase->InSmm(SmmBase, );
-if (EFI_ERROR(Status)) {
-  InSmm = FALSE;
-}
-  }
-
-  if (!InSmm) {
-Status = gBS->LocateProtocol (
-  ,
-  NULL,
-  (VOID **)
-  );
-ASSERT_EFI_ERROR (Status);
-
-Status = gBS->CreateEventEx (
-  EVT_NOTIFY_SIGNAL,
-  TPL_NOTIFY,
-  LibFvbFlashDeviceVirtualAddressChangeNotifyEvent,
-  NULL,
-  ,
-  
-  );
-ASSERT_EFI_ERROR (Status);
-  } else {
-Status = gBS->LocateProtocol (
-,
-NULL,
-(VOID **)
-);
-ASSERT_EFI_ERROR (Status);
-  }
-
-
-  for (FlashIndex = EnumSpiFlashW25Q64; FlashIndex < EnumSpiFlashMax; 
FlashIndex++) {
-Status = mSpiProtocol->Init (mSpiProtocol, &(mInitTable[FlashIndex]));
-if (!EFI_ERROR (Status)) {
-  //
-  // Read Vendor/Device IDs to check if the driver supports the Serial 
Flash device.
-  //
-  Status = mSpiProtocol->Execute (
-   mSpiProtocol,
- 

[edk2] [PATCH V8 3/9] Vlv2TbltDevicePkg/SystemFirmwareUpdateConfig: Add capsule config file.

2016-11-02 Thread Jiewen Yao
Add SystemFirmwareUpdateConfig as capsule configuration file.

Cc: David Wei 
Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: David Wei 
---
 
Vlv2TbltDevicePkg/Feature/Capsule/SystemFirmwareUpdateConfig/SystemFirmwareUpdateConfig.ini
| 72 
 
Vlv2TbltDevicePkg/Feature/Capsule/SystemFirmwareUpdateConfig/SystemFirmwareUpdateConfigGcc.ini
 | 72 
 2 files changed, 144 insertions(+)

diff --git 
a/Vlv2TbltDevicePkg/Feature/Capsule/SystemFirmwareUpdateConfig/SystemFirmwareUpdateConfig.ini
 
b/Vlv2TbltDevicePkg/Feature/Capsule/SystemFirmwareUpdateConfig/SystemFirmwareUpdateConfig.ini
new file mode 100644
index 000..a468753
--- /dev/null
+++ 
b/Vlv2TbltDevicePkg/Feature/Capsule/SystemFirmwareUpdateConfig/SystemFirmwareUpdateConfig.ini
@@ -0,0 +1,72 @@
+## @file
+#
+#  Copyright (c) 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.
+#
+##
+
+[Head]
+NumOfUpdate = 6
+NumOfRecovery = 1
+Update0 = Vlv2FvMicrocode
+Update1 = Vlv2FvBinary
+Update2 = Vlv2FvMain
+Update3 = Vlv2FvRecovery2
+Update4 = Vlv2FvRecovery
+Update5 = Vlv2FvNvRam
+Recovery0 = Vlv2FvMain
+
+[Vlv2FvMicrocode]
+FirmwareType = 0# SystemFirmware
+AddressType = 0 # 0 - relative address, 1 - absolute address.
+BaseAddress = 0x# Base address offset on flash
+Length  = 0x0004# Length
+ImageOffset = 0x# Image offset of this SystemFirmware image
+FileGuid= AF9C9EB2-12AD-4D3E-A4D4-96F6C9966215  # 
PcdEdkiiSystemFirmwareFileGuid
+
+[Vlv2FvNvRam]
+FirmwareType = 1# NvRam
+AddressType = 0 # 0 - relative address, 1 - absolute address.
+BaseAddress = 0x0004# Base address offset on flash
+Length  = 0x0008# Length
+ImageOffset = 0x0004# Image offset of this SystemFirmware image
+FileGuid= AF9C9EB2-12AD-4D3E-A4D4-96F6C9966215  # 
PcdEdkiiSystemFirmwareFileGuid
+
+[Vlv2FvBinary]
+FirmwareType = 0# SystemFirmware
+AddressType = 0 # 0 - relative address, 1 - absolute address.
+BaseAddress = 0x000C# Base address offset on flash
+Length  = 0x0005# Length
+ImageOffset = 0x000C# Image offset of this SystemFirmware image
+FileGuid= AF9C9EB2-12AD-4D3E-A4D4-96F6C9966215  # 
PcdEdkiiSystemFirmwareFileGuid
+
+[Vlv2FvMain]
+FirmwareType = 0# SystemFirmware
+AddressType = 0 # 0 - relative address, 1 - absolute address.
+BaseAddress = 0x0011# Base address offset on flash
+Length  = 0x0021# Length
+ImageOffset = 0x0011# Image offset of this SystemFirmware image
+FileGuid= AF9C9EB2-12AD-4D3E-A4D4-96F6C9966215  # 
PcdEdkiiSystemFirmwareFileGuid
+
+[Vlv2FvRecovery2]
+FirmwareType = 0# SystemFirmware
+AddressType = 0 # 0 - relative address, 1 - absolute address.
+BaseAddress = 0x0032# Base address offset on flash
+Length  = 0x0007# Length
+ImageOffset = 0x0032# Image offset of this SystemFirmware image
+FileGuid= AF9C9EB2-12AD-4D3E-A4D4-96F6C9966215  # 
PcdEdkiiSystemFirmwareFileGuid
+
+[Vlv2FvRecovery]
+FirmwareType = 0# SystemFirmware
+AddressType = 0 # 0 - relative address, 1 - absolute address.
+BaseAddress = 0x0039# Base address offset on flash
+Length  = 0x0007# Length
+ImageOffset = 0x0039# Image offset of this SystemFirmware image
+FileGuid= AF9C9EB2-12AD-4D3E-A4D4-96F6C9966215  # 
PcdEdkiiSystemFirmwareFileGuid
+
diff --git 
a/Vlv2TbltDevicePkg/Feature/Capsule/SystemFirmwareUpdateConfig/SystemFirmwareUpdateConfigGcc.ini
 
b/Vlv2TbltDevicePkg/Feature/Capsule/SystemFirmwareUpdateConfig/SystemFirmwareUpdateConfigGcc.ini
new file mode 100644
index 000..cc169c4
--- /dev/null
+++ 
b/Vlv2TbltDevicePkg/Feature/Capsule/SystemFirmwareUpdateConfig/SystemFirmwareUpdateConfigGcc.ini
@@ -0,0 +1,72 @@
+## @file
+#
+#  Copyright (c) 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 

[edk2] [PATCH V8 0/9] Add capsule support for Vlv2.

2016-11-02 Thread Jiewen Yao
==Below is V8 description==
1) MdeModulePkg/dec: 
set gEfiMdeModulePkgTokenSpaceGuid.PcdSystemFmpCapsuleImageTypeIdGuid
to 0 as default.
2) SignedCapsulePkg/dec:
set gEfiSignedCapsulePkgTokenSpaceGuid.PcdEdkiiSystemFirmwareFileGuid
to 0 as default.
3) QuarkPlatformPkg: Set CAPSULE_ENABLE/RECOVERY_ENABLE to FALSE as default.
4) All: rename EFI_D_* => DEBUG_*

==Below is V7 description==
1) MdeModulePkg/MdeModulePkg.dec: refine status code comment.
2) UefiCpuPkg: Move Microcode capsule related conent to Feature/capsule dir.
3) Vlv2TbltDevicePkg: Add MICOCODE_CAPSULE_ENABLE macro.

Only series 1, 3, 5 are sent for update review.
The other series are unchanged.

==Below is V6 description==
1) MdeModulePkg/CapsuleApp: Fix -D issue.
2) MdeModulePkg/DEC: Cleanup Capsule related StatusCode.
3) UefiCpuPkg: Remove MicrocodeUpdateApp
4) UefiCpuPkg: Add Microcode FMP build sample

Only series 1 and 3 are sent for update review.
The other series are unchanged.

==Below is V5 description==
1) MdeModulePkg/CapsuleApp: Remove [NR]. Add more description.
2) MdeModulePkg/DEC: Update StatusCode to OEM region.
3) MdeModulePkg/DxeCapsuleLib: Use NULL ProcessCapsules()
for runtime lib, because it is not needed for runtime.
4) MdeModulePkg/FmpAuthenticationLib: Add more description.
5) SignedCapsulePkg/DEC: Add data structure description
for PcdEdkiiSystemFirmwareImageDescriptor.
6) SignedCapsulePkg/DEC: Add Pkcs7 and Rsa2048 Key file PCD.
These 2 PCD are moved from platform pkg to SignedCapsulePkg.
7) QuarkPlatformPkg/FDF: Refine order of capsule section.
8) Fix typo and coding style issue.

Below items are defered to other patch series, because
the tool and library are not ready yet.

A) MdeModulePkg/DxeCapsuleLib: separate BMP parsing logic
to another library.
That is very good suggestion, and we agree it is a right direction.
I discussed with the owner of image decoder.
We prefer adding a generic library class to convert
the image data to GOP BLT buffer. It supports *any* image format,
not only BMP. The owner of image decoder will drive the new design.
I filed https://bugzilla.tianocore.org/show_bug.cgi?id=175 to track that.
I suggest we just keep the current solution as a temp solution and
migrate to the new one once it is ready later.

B) PlatformPkg/Bds: Move test key check logic to generic part.
This is very good suggestion and we are discussing with Tool
team to add such detection at build time and set a PCD to indicate that.
The generic code can use this PCD to know if there is a test key.
I filed https://bugzilla.tianocore.org/show_bug.cgi?id=185 to track that.
Adding such check in the generic code is very complicated, so current
temporary solution is to let platform BDS do such check.
The platform BDS will be cleaned up, once the tool is ready.

==Below is V4 description==
1) SecurityPkg - Refine AuthenticateFmpImage() API to let caller
input PublicKeyData and PublicKeyDataLength, instead of PCD.
The benefit is that then this API can be used for a platform
which stores PublicKeyData in anywhere other than PCD.
2) SecurityPkg - Use OFFSET_OF(WIN_CERTIFICATE_UEFI_GUID, CertData)
for better understanding the code.
3) MdeModulePkg - Update CapsuleApp to let it consume
ShellParameters protocol to get Argc and Argv.
4) UefiCpuPkg - Update MicrocodeCapsuleApp to let it consume
ShellParameters protocol to get Argc and Argv.
5) QuarkPlatformPkg - Merge QuarkCapsule.fdf to Quark.fdf.

==Below is V3 description==
1) We move all EDKII related capsule definition to SignedCapsulePkg.
MdeModulePkg only contains FmAuthenticationLib and CapsuleApp,
because they are generic and follow UEFI specification on FMP/ESRT
and Microsoft platform firmware update document.
Any capsule implementation can use them.

Here is full library classes:
MdeModulePkg:
FmpAuthenticationLib.h: new lib - follow UEFI spec. (*)
Verify FMP signature of FMP Capsule
CapsuleLib.h: new API ¨C ProcessCapsules()
It processes all the capsules. Remove duplicated code in 
platform BDS.
UefiCpuPkg:
MicrocodeFlashAccessLib.h: Update Microcode region.
SignedCapsulePkg:
EdkiiSystemCapsuleLib.h ¨C Library for EDKII system FMP.
IniParsingLib.h ¨C Library for INI file parsing.
PlatformFlashAccessLib.h ¨C Library for write flash.

2) We will submit 5 series.
Series 1: Generic Update (MdeModulePkg/SecurityPkg)
DxeCapsuleLib
FmAuthenticationLib (*)
CapsuleApp (*)
Series 2: EDKII Capsule (SignedCapsulePkg)
IniParsingLib
EdkiiSystemCapsuleLib
PlatformFlashAccessLib
SystemFirmwareUpdate driver
RecoveryModuleLoadPei driver
Series 3: Microcode Update (UefiCpuPkg)
MicrocodeFlashAccessLib
MicrocodeUpdate driver.
Series 4: Quark update
Series 5: Vlv2 update

3) DxeCapsuleLib: Move code that performs authentication and parsing of
the capsule format into the implementation of the FMP Protocol.
We move the dispatch FV code from 

[edk2] [PATCH V8 2/9] Vlv2TbltDevicePkg/SystemFirmwareDescriptor: Add Descriptor for capsule.

2016-11-02 Thread Jiewen Yao
Add SystemFirmwareDescriptor for capsule update.
The PEIM extracts SystemFirmwareDescriptor info from FFS and reports
it via PCD.

Cc: David Wei 
Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: David Wei 
---
 
Vlv2TbltDevicePkg/Feature/Capsule/SystemFirmwareDescriptor/SystemFirmwareDescriptor.aslc
 | 89 
 
Vlv2TbltDevicePkg/Feature/Capsule/SystemFirmwareDescriptor/SystemFirmwareDescriptor.inf
  | 46 ++
 
Vlv2TbltDevicePkg/Feature/Capsule/SystemFirmwareDescriptor/SystemFirmwareDescriptorPei.c
 | 66 +++
 3 files changed, 201 insertions(+)

diff --git 
a/Vlv2TbltDevicePkg/Feature/Capsule/SystemFirmwareDescriptor/SystemFirmwareDescriptor.aslc
 
b/Vlv2TbltDevicePkg/Feature/Capsule/SystemFirmwareDescriptor/SystemFirmwareDescriptor.aslc
new file mode 100644
index 000..4c9b63e
--- /dev/null
+++ 
b/Vlv2TbltDevicePkg/Feature/Capsule/SystemFirmwareDescriptor/SystemFirmwareDescriptor.aslc
@@ -0,0 +1,89 @@
+/** @file
+  System Firmware descriptor.
+
+  Copyright (c) 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 
+
+#define PACKAGE_VERSION 0x
+#define PACKAGE_VERSION_STRING  L"Unknown"
+
+#define CURRENT_FIRMWARE_VERSION0x0002
+#define CURRENT_FIRMWARE_VERSION_STRING L"0x0002"
+#define LOWEST_SUPPORTED_FIRMWARE_VERSION   0x0001
+
+#define IMAGE_IDSIGNATURE_64('V', 'L', 'V', '2', 
'_', '_', 'F', 'd')
+#define IMAGE_ID_STRING L"Vlv2Fd"
+
+// PcdSystemFmpCapsuleImageTypeIdGuid
+#define IMAGE_TYPE_ID_GUID  { 0x4096267b, 0xda0a, 0x42eb, { 
0xb5, 0xeb, 0xfe, 0xf3, 0x1d, 0x20, 0x7c, 0xb4 } }
+
+typedef struct {
+  EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR  Descriptor;
+  // real string data
+  CHAR16  ImageIdNameStr[16];
+  CHAR16  VersionNameStr[16];
+  CHAR16  PackageVersionNameStr[16];
+} IMAGE_DESCRIPTOR;
+
+IMAGE_DESCRIPTOR mImageDescriptor =
+{
+  {
+EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR_SIGNATURE,
+sizeof(EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR),
+sizeof(IMAGE_DESCRIPTOR),
+PACKAGE_VERSION,   // PackageVersion
+OFFSET_OF (IMAGE_DESCRIPTOR, PackageVersionNameStr),   // 
PackageVersionName
+1, // ImageIndex;
+{0x0}, // Reserved
+IMAGE_TYPE_ID_GUID,// ImageTypeId;
+IMAGE_ID,  // ImageId;
+OFFSET_OF (IMAGE_DESCRIPTOR, ImageIdNameStr),  // ImageIdName;
+CURRENT_FIRMWARE_VERSION,  // Version;
+OFFSET_OF (IMAGE_DESCRIPTOR, VersionNameStr),  // VersionName;
+{0x0}, // Reserved2
+FixedPcdGet32(PcdFlashAreaSize),   // Size;
+IMAGE_ATTRIBUTE_IMAGE_UPDATABLE |
+  IMAGE_ATTRIBUTE_RESET_REQUIRED |
+  IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED |
+  IMAGE_ATTRIBUTE_IN_USE,  // 
AttributesSupported;
+IMAGE_ATTRIBUTE_IMAGE_UPDATABLE |
+  IMAGE_ATTRIBUTE_RESET_REQUIRED |
+  IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED |
+  IMAGE_ATTRIBUTE_IN_USE,  // 
AttributesSetting;
+0x0,   // Compatibilities;
+LOWEST_SUPPORTED_FIRMWARE_VERSION, // 
LowestSupportedImageVersion;
+0x,// 
LastAttemptVersion;
+0, // 
LastAttemptStatus;
+{0x0}, // Reserved3
+0, // HardwareInstance;
+  },
+  // real string data
+  {IMAGE_ID_STRING},
+  {CURRENT_FIRMWARE_VERSION_STRING},
+  {PACKAGE_VERSION_STRING},
+};
+
+
+VOID*
+ReferenceAcpiTable (
+  VOID
+  )
+{
+  //
+  // Reference the table being generated to prevent the optimizer from
+  // removing the data structure from the executable
+  

[edk2] [PATCH 1/9] Vlv2TbltDevicePkg/PlatformFlashAccessLib: Add instance for capsule update.

2016-11-02 Thread Jiewen Yao
Add PlatformFlashAccessLib for capsule update.

Cc: David Wei 
Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: David Wei 
---
 
Vlv2TbltDevicePkg/Feature/Capsule/Library/PlatformFlashAccessLib/PlatformFlashAccessLib.c
   | 190 
 
Vlv2TbltDevicePkg/Feature/Capsule/Library/PlatformFlashAccessLib/PlatformFlashAccessLib.inf
 |  48 +
 2 files changed, 238 insertions(+)

diff --git 
a/Vlv2TbltDevicePkg/Feature/Capsule/Library/PlatformFlashAccessLib/PlatformFlashAccessLib.c
 
b/Vlv2TbltDevicePkg/Feature/Capsule/Library/PlatformFlashAccessLib/PlatformFlashAccessLib.c
new file mode 100644
index 000..982741e
--- /dev/null
+++ 
b/Vlv2TbltDevicePkg/Feature/Capsule/Library/PlatformFlashAccessLib/PlatformFlashAccessLib.c
@@ -0,0 +1,190 @@
+/** @file
+  Platform Flash Access library.
+
+  Copyright (c) 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 
+
+#define SECTOR_SIZE_64KB  0x1  // Common 64kBytes sector size
+#define ALINGED_SIZE  SECTOR_SIZE_64KB
+
+STATIC EFI_PHYSICAL_ADDRESS mInternalFdAddress;
+
+/**
+  Perform flash write opreation.
+
+  @param[in] FirmwareType  The type of firmware.
+  @param[in] FlashAddress  The address of flash device to be accessed.
+  @param[in] FlashAddressType  The type of flash device address.
+  @param[in] BufferThe pointer to the data buffer.
+  @param[in] LengthThe length of data buffer in bytes.
+
+  @retval EFI_SUCCESS   The operation returns successfully.
+  @retval EFI_WRITE_PROTECTED   The flash device is read only.
+  @retval EFI_UNSUPPORTED   The flash device access is unsupported.
+  @retval EFI_INVALID_PARAMETER The input parameter is not valid.
+**/
+EFI_STATUS
+EFIAPI
+PerformFlashWrite (
+  IN PLATFORM_FIRMWARE_TYPE   FirmwareType,
+  IN EFI_PHYSICAL_ADDRESS FlashAddress,
+  IN FLASH_ADDRESS_TYPE   FlashAddressType,
+  IN VOID *Buffer,
+  IN UINTNLength
+  )
+{
+  EFI_STATUS  Status;
+
+  DEBUG((EFI_D_INFO, "PerformFlashWrite - 0x%x(%x) - 0x%x\n", 
(UINTN)FlashAddress, (UINTN)FlashAddressType, Length));
+  if (FlashAddressType == FlashAddressTypeRelativeAddress) {
+FlashAddress = FlashAddress + mInternalFdAddress;
+  }
+
+  DEBUG((EFI_D_INFO, "  - 0x%x(%x) - 0x%x\n", 
(UINTN)FlashAddress, (UINTN)FlashAddressType, Length));
+  LibFvbFlashDeviceBlockLock(FlashAddress, Length, FALSE);
+
+  //
+  // Erase & Write
+  //
+  Status = LibFvbFlashDeviceBlockErase((UINTN)FlashAddress, Length);
+  ASSERT_EFI_ERROR(Status);
+  if (EFI_ERROR(Status)) {
+LibFvbFlashDeviceBlockLock(FlashAddress, Length, TRUE);
+DEBUG((EFI_D_ERROR, "Flash Erase error\n"));
+return Status;
+  }
+
+  Status = LibFvbFlashDeviceWrite((UINTN)FlashAddress, , Buffer);
+  ASSERT_EFI_ERROR(Status);
+  if (EFI_ERROR(Status)) {
+LibFvbFlashDeviceBlockLock(FlashAddress, Length, TRUE);
+DEBUG((EFI_D_ERROR, "Flash write error\n"));
+return Status;
+  }
+
+  LibFvbFlashDeviceBlockLock(FlashAddress, Length, TRUE);
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Perform microcode write opreation.
+
+  @param[in] FlashAddress  The address of flash device to be accessed.
+  @param[in] BufferThe pointer to the data buffer.
+  @param[in] LengthThe length of data buffer in bytes.
+
+  @retval EFI_SUCCESS   The operation returns successfully.
+  @retval EFI_WRITE_PROTECTED   The flash device is read only.
+  @retval EFI_UNSUPPORTED   The flash device access is unsupported.
+  @retval EFI_INVALID_PARAMETER The input parameter is not valid.
+**/
+EFI_STATUS
+EFIAPI
+MicrocodeFlashWrite (
+  IN EFI_PHYSICAL_ADDRESS FlashAddress,
+  IN VOID *Buffer,
+  IN UINTNLength
+  )
+{
+  EFI_PHYSICAL_ADDRESS AlignedFlashAddress;
+  VOID *AlignedBuffer;
+  UINTNAlignedLength;
+  UINTNOffsetHead;
+  UINTNOffsetTail;
+  EFI_STATUS   Status;
+
+  DEBUG((EFI_D_INFO, "MicrocodeFlashWrite - 0x%x - 0x%x\n", 

[edk2] [PATCH V8 4/7] QuarkPlatformPkg/PlatformInit: Remove recovery PPI installation.

2016-11-02 Thread Jiewen Yao
The QuarkPlatform will use MdeModulePkg/RecoveryModuleLoadPei for recovery.
There is no need to produce recovery PPI in platform module.

Cc: Michael D Kinney 
Cc: Kelly Steele 
Cc: Feng Tian 
Cc: Star Zeng 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
---
 QuarkPlatformPkg/Platform/Pei/PlatformInit/MemoryCallback.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/QuarkPlatformPkg/Platform/Pei/PlatformInit/MemoryCallback.c 
b/QuarkPlatformPkg/Platform/Pei/PlatformInit/MemoryCallback.c
index d5fb941..f9b769d 100644
--- a/QuarkPlatformPkg/Platform/Pei/PlatformInit/MemoryCallback.c
+++ b/QuarkPlatformPkg/Platform/Pei/PlatformInit/MemoryCallback.c
@@ -222,8 +222,7 @@ MemoryDiscoveredPpiNotifyCallback (
   QNCPortWrite (QUARK_NC_HOST_BRIDGE_SB_PORT_ID, QNC_MSG_FSBIC_REG_HMISC, 
RegData32);
 
   if (BootMode == BOOT_IN_RECOVERY_MODE) {
-Status = PeimInitializeRecovery (PeiServices);
-ASSERT_EFI_ERROR (Status);
+// Do nothing here. A generic RecoveryModule will handle it.
   } else if (BootMode == BOOT_ON_S3_RESUME) {
 return EFI_SUCCESS;
   } else {
-- 
2.7.4.windows.1

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


[edk2] [PATCH V8 6/7] QuarkPlatformPkg/dsc/fdf: Add capsule/recovery support.

2016-11-02 Thread Jiewen Yao
Add capsule and recovery support module in platform dsc and fdf.

Cc: Michael D Kinney 
Cc: Kelly Steele 
Cc: Feng Tian 
Cc: Star Zeng 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
---
 QuarkPlatformPkg/Quark.dsc|  73 +--
 QuarkPlatformPkg/Quark.fdf| 137 
 QuarkPlatformPkg/QuarkMin.dsc |   7 +-
 3 files changed, 202 insertions(+), 15 deletions(-)

diff --git a/QuarkPlatformPkg/Quark.dsc b/QuarkPlatformPkg/Quark.dsc
index d5988da..0bd9120 100644
--- a/QuarkPlatformPkg/Quark.dsc
+++ b/QuarkPlatformPkg/Quark.dsc
@@ -39,6 +39,8 @@
   DEFINE SOURCE_DEBUG_ENABLE  = FALSE
   DEFINE PERFORMANCE_ENABLE   = FALSE
   DEFINE LOGGING  = FALSE
+  DEFINE CAPSULE_ENABLE   = FALSE
+  DEFINE RECOVERY_ENABLE  = FALSE
 
   #
   # Galileo board.  Options are [GEN1, GEN2]
@@ -160,11 +162,9 @@
   
PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf
 !endif
 
-!if $(SECURE_BOOT_ENABLE) || $(MEASURED_BOOT_ENABLE)
   OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf
   IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
-!endif
 
 !if $(SECURE_BOOT_ENABLE)
   
PlatformSecureLib|QuarkPlatformPkg/Library/PlatformSecureLib/PlatformSecureLib.inf
@@ -225,6 +225,17 @@
   
PlatformPcieHelperLib|QuarkPlatformPkg/Library/PlatformPcieHelperLib/PlatformPcieHelperLib.inf
   
PlatformHelperLib|QuarkPlatformPkg/Library/PlatformHelperLib/DxePlatformHelperLib.inf
 
+!if $(CAPSULE_ENABLE)
+  CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf
+!else
+  CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf
+!endif
+
+  
EdkiiSystemCapsuleLib|SignedCapsulePkg/Library/EdkiiSystemCapsuleLib/EdkiiSystemCapsuleLib.inf
+  
FmpAuthenticationLib|MdeModulePkg/Library/FmpAuthenticationLibNull/FmpAuthenticationLibNull.inf
+  IniParsingLib|SignedCapsulePkg/Library/IniParsingLib/IniParsingLib.inf
+  
PlatformFlashAccessLib|QuarkPlatformPkg/Feature/Capsule/Library/PlatformFlashAccessLib/PlatformFlashAccessLibDxe.inf
+
 [LibraryClasses.common.SEC]
   #
   # SEC specific phase
@@ -250,9 +261,7 @@
   
PlatformHelperLib|QuarkPlatformPkg/Library/PlatformHelperLib/PeiPlatformHelperLib.inf
   
CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf
   MpInitLib|UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf
-!if $(SECURE_BOOT_ENABLE) || $(MEASURED_BOOT_ENABLE)
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
-!endif
 !if $(PERFORMANCE_ENABLE)
   PerformanceLib|MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.inf
 !endif
@@ -273,9 +282,7 @@
   PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf
   
CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf
   SmmMemLib|MdePkg/Library/SmmMemLib/SmmMemLib.inf
-!if $(SECURE_BOOT_ENABLE) || $(MEASURED_BOOT_ENABLE)
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf
-!endif
 !if $(PERFORMANCE_ENABLE)
   PerformanceLib|MdeModulePkg/Library/SmmPerformanceLib/SmmPerformanceLib.inf
 !endif
@@ -301,6 +308,10 @@
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf
 !endif
 
+!if $(CAPSULE_ENABLE)
+  CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf
+!endif
+
 [LibraryClasses.IA32.UEFI_DRIVER,LibraryClasses.IA32.UEFI_APPLICATION]
   PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
 
@@ -431,6 +442,10 @@
 
   gEfiMdeModulePkgTokenSpaceGuid.PcdConInConnectOnDemand|FALSE
 
+!if $(RECOVERY_ENABLE)
+  gEfiMdeModulePkgTokenSpaceGuid.PcdRecoveryFileName|L"QUARKREC.Cap"
+!endif
+
 [PcdsPatchableInModule]
   gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x803000C7
   gEfiMdeModulePkgTokenSpaceGuid.PcdVpdBaseAddress|0x0
@@ -449,6 +464,12 @@
   gQuarkPlatformTokenSpaceGuid.PcdUserIsPhysicallyPresent|FALSE
   gQuarkPlatformTokenSpaceGuid.PcdSpiFlashDeviceSize|0
 
+!if $(CAPSULE_ENABLE) || $(RECOVERY_ENABLE)
+  
gEfiSignedCapsulePkgTokenSpaceGuid.PcdEdkiiSystemFirmwareImageDescriptor|{0x0}|VOID*|0x100
+  gEfiMdeModulePkgTokenSpaceGuid.PcdSystemFmpCapsuleImageTypeIdGuid|{0xc0, 
0x20, 0xaf, 0x62, 0x16, 0x70, 0x4a, 0x42, 0x9b, 0xf8, 0x9c, 0xcc, 0x86, 0x58, 
0x40, 0x90}
+  gEfiSignedCapsulePkgTokenSpaceGuid.PcdEdkiiSystemFirmwareFileGuid|{0x59, 
0x3A, 0xD8, 0x14, 0x10, 0xA8, 0x56, 0x45, 0x81, 0x92, 0x1C, 0x0A, 0x59, 0x3C, 
0x06, 0x5C}
+!endif
+
 !if $(MEASURED_BOOT_ENABLE)
   #
   # TPM1.2  { 0x8b01e5b6, 0x4f19, 0x46e8, { 0xab, 0x93, 0x1c, 0x53, 0x67, 
0x1b, 0x90, 0xcc } }
@@ -540,6 +561,11 @@
 !endif
   }
 
+!if $(CAPSULE_ENABLE) || $(RECOVERY_ENABLE)
+  # FMP image decriptor
+  

[edk2] [PATCH 1/7] QuarkPlatformPkg/PlatformFlashAccessLib: Add instance for capsule update.

2016-11-02 Thread Jiewen Yao
Add PlatformFlashAccessLib for capsule update.

Cc: Michael D Kinney 
Cc: Kelly Steele 
Cc: Feng Tian 
Cc: Star Zeng 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
---
 
QuarkPlatformPkg/Feature/Capsule/Library/PlatformFlashAccessLib/PlatformFlashAccessLibDxe.c
   | 206 
 
QuarkPlatformPkg/Feature/Capsule/Library/PlatformFlashAccessLib/PlatformFlashAccessLibDxe.inf
 |  53 +++
 
QuarkPlatformPkg/Feature/Capsule/Library/PlatformFlashAccessLib/SpiFlashDevice.c
  | 336 
 
QuarkPlatformPkg/Feature/Capsule/Library/PlatformFlashAccessLib/SpiFlashDevice.h
  | 186 +++
 4 files changed, 781 insertions(+)

diff --git 
a/QuarkPlatformPkg/Feature/Capsule/Library/PlatformFlashAccessLib/PlatformFlashAccessLibDxe.c
 
b/QuarkPlatformPkg/Feature/Capsule/Library/PlatformFlashAccessLib/PlatformFlashAccessLibDxe.c
new file mode 100644
index 000..85e30fd
--- /dev/null
+++ 
b/QuarkPlatformPkg/Feature/Capsule/Library/PlatformFlashAccessLib/PlatformFlashAccessLibDxe.c
@@ -0,0 +1,206 @@
+/** @file
+  Platform Flash Access library.
+
+  Copyright (c) 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 
+
+//
+// SPI default opcode slots
+//
+#define SPI_OPCODE_JEDEC_ID_INDEX0
+#define SPI_OPCODE_READ_ID_INDEX 1
+#define SPI_OPCODE_WRITE_S_INDEX 2
+#define SPI_OPCODE_WRITE_INDEX   3
+#define SPI_OPCODE_READ_INDEX4
+#define SPI_OPCODE_ERASE_INDEX   5
+#define SPI_OPCODE_READ_S_INDEX  6
+#define SPI_OPCODE_CHIP_ERASE_INDEX  7
+
+#define SPI_ERASE_SECTOR_SIZESIZE_4KB  //This is the chipset 
requirement
+
+STATIC EFI_PHYSICAL_ADDRESS mInternalFdAddress;
+EFI_SPI_PROTOCOL*mSpiProtocol;
+
+/**
+  Writes specified number of bytes from the input buffer to the address
+
+  @param[in]  WriteAddress  The flash address to be written.
+  @param[in, out] NumBytes  The number of bytes.
+  @param[in]  BufferThe data buffer to be written.
+
+  @return The status of flash write.
+**/
+EFI_STATUS
+FlashFdWrite (
+  IN  UINTN   WriteAddress,
+  IN OUT UINTN*NumBytes,
+  IN  UINT8   *Buffer
+  )
+{
+  EFI_STATUS  Status;
+
+  Status = EFI_SUCCESS;
+
+  Status = mSpiProtocol->Execute (
+   mSpiProtocol,
+   SPI_OPCODE_WRITE_INDEX, // OpcodeIndex
+   0,  // PrefixOpcodeIndex
+   TRUE,   // DataCycle
+   TRUE,   // Atomic
+   TRUE,   // ShiftOut
+   WriteAddress,   // Address
+   (UINT32) (*NumBytes),   // Data Number
+   Buffer,
+   EnumSpiRegionBios
+   );
+  DEBUG((EFI_D_INFO, "FlashFdWrite - 0x%x - %r\n", (UINTN)WriteAddress, 
Status));
+
+  AsmWbinvd ();
+
+  return Status;
+}
+
+/**
+  Erase a certain block from address LbaWriteAddress
+
+  @param[in] WriteAddress  The flash address to be erased.
+
+  @return The status of flash erase.
+**/
+EFI_STATUS
+FlashFdErase (
+  IN UINTNWriteAddress
+  )
+{
+  EFI_STATUS  Status;
+
+  Status = mSpiProtocol->Execute (
+   mSpiProtocol,
+   SPI_OPCODE_ERASE_INDEX, // OpcodeIndex
+   0,  // PrefixOpcodeIndex
+   FALSE,  // DataCycle
+   TRUE,   // Atomic
+   FALSE,  // ShiftOut
+   WriteAddress,   // Address
+   0,  // Data Number
+   NULL,
+   EnumSpiRegionBios   // SPI_REGION_TYPE
+   );
+  DEBUG((EFI_D_INFO, "FlashFdErase - 0x%x - %r\n", (UINTN)WriteAddress, 
Status));
+
+  AsmWbinvd ();
+
+  return Status;
+}
+
+/**
+  Perform flash write opreation.
+
+  @param[in] FirmwareType  The 

[edk2] [PATCH V8 3/7] QuarkPlatformPkg/SystemFirmwareUpdateConfig: Add capsule config file.

2016-11-02 Thread Jiewen Yao
Add SystemFirmwareUpdateConfig as capsule configuration file.

Cc: Michael D Kinney 
Cc: Kelly Steele 
Cc: Feng Tian 
Cc: Star Zeng 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
---
 
QuarkPlatformPkg/Feature/Capsule/SystemFirmwareUpdateConfig/SystemFirmwareUpdateConfig.ini
 | 62 
 1 file changed, 62 insertions(+)

diff --git 
a/QuarkPlatformPkg/Feature/Capsule/SystemFirmwareUpdateConfig/SystemFirmwareUpdateConfig.ini
 
b/QuarkPlatformPkg/Feature/Capsule/SystemFirmwareUpdateConfig/SystemFirmwareUpdateConfig.ini
new file mode 100644
index 000..bf4ef94
--- /dev/null
+++ 
b/QuarkPlatformPkg/Feature/Capsule/SystemFirmwareUpdateConfig/SystemFirmwareUpdateConfig.ini
@@ -0,0 +1,62 @@
+## @file
+#
+#  Copyright (c) 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.
+#
+##
+
+[Head]
+NumOfUpdate = 4
+NumOfRecovery = 1
+Update0 = QuarkFvMain
+Update1 = QuarkFvBinary
+Update2 = QuarkFvRecovery
+Update3 = QuarkFvNvRam
+Recovery0 = QuarkFvMain
+
+[QuarkFvPayload]
+FirmwareType = 0# SystemFirmware
+AddressType = 0 # 0 - relative address, 1 - absolute address.
+BaseAddress = 0x0040# Base address offset on flash
+Length  = 0x0010# Length
+ImageOffset = 0x0040# Image offset of this SystemFirmware image
+FileGuid= 14D83A59-A810-4556-8192-1C0A593C065C  # 
PcdEdkiiSystemFirmwareFileGuid
+
+[QuarkFvMain]
+FirmwareType = 0# SystemFirmware
+AddressType = 0 # 0 - relative address, 1 - absolute address.
+BaseAddress = 0x0050# Base address offset on flash
+Length  = 0x001E# Length
+ImageOffset = 0x0050# Image offset of this SystemFirmware image
+FileGuid= 14D83A59-A810-4556-8192-1C0A593C065C  # 
PcdEdkiiSystemFirmwareFileGuid
+
+[QuarkFvNvRam]
+FirmwareType = 1# NvRam
+AddressType = 0 # 0 - relative address, 1 - absolute address.
+BaseAddress = 0x006E# Base address offset on flash
+Length  = 0x0002# Length
+ImageOffset = 0x006E# Image offset of this SystemFirmware image
+FileGuid= 14D83A59-A810-4556-8192-1C0A593C065C  # 
PcdEdkiiSystemFirmwareFileGuid
+
+[QuarkFvBinary]
+FirmwareType = 0# SystemFirmware
+AddressType = 0 # 0 - relative address, 1 - absolute address.
+BaseAddress = 0x0070# Base address offset on flash
+Length  = 0x0001# Length
+ImageOffset = 0x0070# Image offset of this SystemFirmware image
+FileGuid= 14D83A59-A810-4556-8192-1C0A593C065C  # 
PcdEdkiiSystemFirmwareFileGuid
+
+[QuarkFvRecovery]
+FirmwareType = 0# SystemFirmware
+AddressType = 0 # 0 - relative address, 1 - absolute address.
+BaseAddress = 0x0071# Base address offset on flash
+Length  = 0x000F# Length
+ImageOffset = 0x0071# Image offset of this SystemFirmware image
+FileGuid= 14D83A59-A810-4556-8192-1C0A593C065C  # 
PcdEdkiiSystemFirmwareFileGuid
+
-- 
2.7.4.windows.1

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


[edk2] [PATCH V8 0/7] Add capsule support for Quark.

2016-11-02 Thread Jiewen Yao
==Below is V8 description==
1) MdeModulePkg/dec: 
set gEfiMdeModulePkgTokenSpaceGuid.PcdSystemFmpCapsuleImageTypeIdGuid
to 0 as default.
2) SignedCapsulePkg/dec:
set gEfiSignedCapsulePkgTokenSpaceGuid.PcdEdkiiSystemFirmwareFileGuid
to 0 as default.
3) QuarkPlatformPkg: Set CAPSULE_ENABLE/RECOVERY_ENABLE to FALSE as default.
4) All: rename EFI_D_* => DEBUG_*

==Below is V7 description==
1) MdeModulePkg/MdeModulePkg.dec: refine status code comment.
2) UefiCpuPkg: Move Microcode capsule related conent to Feature/capsule dir.
3) Vlv2TbltDevicePkg: Add MICOCODE_CAPSULE_ENABLE macro.

Only series 1, 3, 5 are sent for update review.
The other series are unchanged.

==Below is V6 description==
1) MdeModulePkg/CapsuleApp: Fix -D issue.
2) MdeModulePkg/DEC: Cleanup Capsule related StatusCode.
3) UefiCpuPkg: Remove MicrocodeUpdateApp
4) UefiCpuPkg: Add Microcode FMP build sample

Only series 1 and 3 are sent for update review.
The other series are unchanged.

==Below is V5 description==
1) MdeModulePkg/CapsuleApp: Remove [NR]. Add more description.
2) MdeModulePkg/DEC: Update StatusCode to OEM region.
3) MdeModulePkg/DxeCapsuleLib: Use NULL ProcessCapsules()
for runtime lib, because it is not needed for runtime.
4) MdeModulePkg/FmpAuthenticationLib: Add more description.
5) SignedCapsulePkg/DEC: Add data structure description
for PcdEdkiiSystemFirmwareImageDescriptor.
6) SignedCapsulePkg/DEC: Add Pkcs7 and Rsa2048 Key file PCD.
These 2 PCD are moved from platform pkg to SignedCapsulePkg.
7) QuarkPlatformPkg/FDF: Refine order of capsule section.
8) Fix typo and coding style issue.

Below items are defered to other patch series, because
the tool and library are not ready yet.

A) MdeModulePkg/DxeCapsuleLib: separate BMP parsing logic
to another library.
That is very good suggestion, and we agree it is a right direction.
I discussed with the owner of image decoder.
We prefer adding a generic library class to convert
the image data to GOP BLT buffer. It supports *any* image format,
not only BMP. The owner of image decoder will drive the new design.
I filed https://bugzilla.tianocore.org/show_bug.cgi?id=175 to track that.
I suggest we just keep the current solution as a temp solution and
migrate to the new one once it is ready later.

B) PlatformPkg/Bds: Move test key check logic to generic part.
This is very good suggestion and we are discussing with Tool
team to add such detection at build time and set a PCD to indicate that.
The generic code can use this PCD to know if there is a test key.
I filed https://bugzilla.tianocore.org/show_bug.cgi?id=185 to track that.
Adding such check in the generic code is very complicated, so current
temporary solution is to let platform BDS do such check.
The platform BDS will be cleaned up, once the tool is ready.

==Below is V4 description==
1) SecurityPkg - Refine AuthenticateFmpImage() API to let caller
input PublicKeyData and PublicKeyDataLength, instead of PCD.
The benefit is that then this API can be used for a platform
which stores PublicKeyData in anywhere other than PCD.
2) SecurityPkg - Use OFFSET_OF(WIN_CERTIFICATE_UEFI_GUID, CertData)
for better understanding the code.
3) MdeModulePkg - Update CapsuleApp to let it consume
ShellParameters protocol to get Argc and Argv.
4) UefiCpuPkg - Update MicrocodeCapsuleApp to let it consume
ShellParameters protocol to get Argc and Argv.
5) QuarkPlatformPkg - Merge QuarkCapsule.fdf to Quark.fdf.

==Below is V3 description==
1) We move all EDKII related capsule definition to SignedCapsulePkg.
MdeModulePkg only contains FmAuthenticationLib and CapsuleApp,
because they are generic and follow UEFI specification on FMP/ESRT
and Microsoft platform firmware update document.
Any capsule implementation can use them.

Here is full library classes:
MdeModulePkg:
FmpAuthenticationLib.h: new lib - follow UEFI spec. (*)
Verify FMP signature of FMP Capsule
CapsuleLib.h: new API ¨C ProcessCapsules()
It processes all the capsules. Remove duplicated code in 
platform BDS.
UefiCpuPkg:
MicrocodeFlashAccessLib.h: Update Microcode region.
SignedCapsulePkg:
EdkiiSystemCapsuleLib.h ¨C Library for EDKII system FMP.
IniParsingLib.h ¨C Library for INI file parsing.
PlatformFlashAccessLib.h ¨C Library for write flash.

2) We will submit 5 series.
Series 1: Generic Update (MdeModulePkg/SecurityPkg)
DxeCapsuleLib
FmAuthenticationLib (*)
CapsuleApp (*)
Series 2: EDKII Capsule (SignedCapsulePkg)
IniParsingLib
EdkiiSystemCapsuleLib
PlatformFlashAccessLib
SystemFirmwareUpdate driver
RecoveryModuleLoadPei driver
Series 3: Microcode Update (UefiCpuPkg)
MicrocodeFlashAccessLib
MicrocodeUpdate driver.
Series 4: Quark update
Series 5: Vlv2 update

3) DxeCapsuleLib: Move code that performs authentication and parsing of
the capsule format into the implementation of the FMP Protocol.
We move the dispatch FV code from 

[edk2] [PATCH V8 5/7] UefiCpuPkg/MicrocodeUpdate: Add MicrocodeUpdate component.

2016-11-02 Thread Jiewen Yao
MicrocodeUpdate supports update Microcode region via UEFI FMP capsule.

MicrocodeUpdate SetImage() will perform the Microcode version,
ProcessorSignature/ProcessorFlag, and try to load microcode.
If and only if the Microcode is loaded successfully, and new Microcode
will be updated to system flash region.

Cc: Jeff Fan 
Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: Jeff Fan 
---
 UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeFmp.c  | 
537 ++
 UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdate.c   | 
779 
 UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdate.h   | 
403 ++
 UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdateDxe.inf  |  
68 ++
 UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdateDxe.uni  |  
21 +
 UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdateDxeExtra.uni |  
20 +
 6 files changed, 1828 insertions(+)

diff --git a/UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeFmp.c 
b/UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeFmp.c
new file mode 100644
index 000..df3563d
--- /dev/null
+++ b/UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeFmp.c
@@ -0,0 +1,537 @@
+/** @file
+  Produce FMP instance for Microcode.
+
+  Copyright (c) 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 "MicrocodeUpdate.h"
+
+//
+// MicrocodeFmp driver private data
+//
+MICROCODE_FMP_PRIVATE_DATA *mMicrocodeFmpPrivate = NULL;
+
+EFI_FIRMWARE_MANAGEMENT_PROTOCOL mFirmwareManagementProtocol = {
+  FmpGetImageInfo,
+  FmpGetImage,
+  FmpSetImage,
+  FmpCheckImage,
+  FmpGetPackageInfo,
+  FmpSetPackageInfo
+};
+
+/**
+  Initialize Microcode Descriptor.
+
+  @param[in] MicrocodeFmpPrivate private data structure to be initialized.
+
+  @return EFI_SUCCESS Microcode Descriptor is initialized.
+**/
+EFI_STATUS
+InitializeMicrocodeDescriptor (
+  IN MICROCODE_FMP_PRIVATE_DATA  *MicrocodeFmpPrivate
+  );
+
+/**
+  Returns information about the current firmware image(s) of the device.
+
+  This function allows a copy of the current firmware image to be created and 
saved.
+  The saved copy could later been used, for example, in firmware image 
recovery or rollback.
+
+  @param[in]  This   A pointer to the 
EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
+  @param[in, out] ImageInfoSize  A pointer to the size, in bytes, of the 
ImageInfo buffer.
+ On input, this is the size of the buffer 
allocated by the caller.
+ On output, it is the size of the buffer 
returned by the firmware
+ if the buffer was large enough, or the 
size of the buffer needed
+ to contain the image(s) information if 
the buffer was too small.
+  @param[in, out] ImageInfo  A pointer to the buffer in which firmware 
places the current image(s)
+ information. The information is an array 
of EFI_FIRMWARE_IMAGE_DESCRIPTORs.
+  @param[out] DescriptorVersion  A pointer to the location in which 
firmware returns the version number
+ associated with the 
EFI_FIRMWARE_IMAGE_DESCRIPTOR.
+  @param[out] DescriptorCountA pointer to the location in which 
firmware returns the number of
+ descriptors or firmware images within 
this device.
+  @param[out] DescriptorSize A pointer to the location in which 
firmware returns the size, in bytes,
+ of an individual 
EFI_FIRMWARE_IMAGE_DESCRIPTOR.
+  @param[out] PackageVersion A version number that represents all the 
firmware images in the device.
+ The format is vendor specific and new 
version must have a greater value
+ than the old version. If PackageVersion 
is not supported, the value is
+ 0x. A value of 0xFFFE 
indicates that package version comparison
+ is to be performed using 
PackageVersionName. A value of 0xFFFD indicates
+   

[edk2] [PATCH V8 0/7] Add MicrocodeUpdate support.

2016-11-02 Thread Jiewen Yao
==Below is V8 description==
1) MdeModulePkg/dec: 
set gEfiMdeModulePkgTokenSpaceGuid.PcdSystemFmpCapsuleImageTypeIdGuid
to 0 as default.
2) SignedCapsulePkg/dec:
set gEfiSignedCapsulePkgTokenSpaceGuid.PcdEdkiiSystemFirmwareFileGuid
to 0 as default.
3) QuarkPlatformPkg: Set CAPSULE_ENABLE/RECOVERY_ENABLE to FALSE as default.
4) All: rename EFI_D_* => DEBUG_*

==Below is V7 description==
1) MdeModulePkg/MdeModulePkg.dec: refine status code comment.
2) UefiCpuPkg: Move Microcode capsule related conent to Feature/capsule dir.
3) Vlv2TbltDevicePkg: Add MICOCODE_CAPSULE_ENABLE macro.

Only series 1, 3, 5 are sent for update review.
The other series are unchanged.

==Below is V6 description==
1) MdeModulePkg/CapsuleApp: Fix -D issue.
2) MdeModulePkg/DEC: Cleanup Capsule related StatusCode.
3) UefiCpuPkg: Remove MicrocodeUpdateApp
4) UefiCpuPkg: Add Microcode FMP build sample

Only series 1 and 3 are sent for update review.
The other series are unchanged.

==Below is V5 description==
1) MdeModulePkg/CapsuleApp: Remove [NR]. Add more description.
2) MdeModulePkg/DEC: Update StatusCode to OEM region.
3) MdeModulePkg/DxeCapsuleLib: Use NULL ProcessCapsules()
for runtime lib, because it is not needed for runtime.
4) MdeModulePkg/FmpAuthenticationLib: Add more description.
5) SignedCapsulePkg/DEC: Add data structure description
for PcdEdkiiSystemFirmwareImageDescriptor.
6) SignedCapsulePkg/DEC: Add Pkcs7 and Rsa2048 Key file PCD.
These 2 PCD are moved from platform pkg to SignedCapsulePkg.
7) QuarkPlatformPkg/FDF: Refine order of capsule section.
8) Fix typo and coding style issue.

Below items are defered to other patch series, because
the tool and library are not ready yet.

A) MdeModulePkg/DxeCapsuleLib: separate BMP parsing logic
to another library.
That is very good suggestion, and we agree it is a right direction.
I discussed with the owner of image decoder.
We prefer adding a generic library class to convert
the image data to GOP BLT buffer. It supports *any* image format,
not only BMP. The owner of image decoder will drive the new design.
I filed https://bugzilla.tianocore.org/show_bug.cgi?id=175 to track that.
I suggest we just keep the current solution as a temp solution and
migrate to the new one once it is ready later.

B) PlatformPkg/Bds: Move test key check logic to generic part.
This is very good suggestion and we are discussing with Tool
team to add such detection at build time and set a PCD to indicate that.
The generic code can use this PCD to know if there is a test key.
I filed https://bugzilla.tianocore.org/show_bug.cgi?id=185 to track that.
Adding such check in the generic code is very complicated, so current
temporary solution is to let platform BDS do such check.
The platform BDS will be cleaned up, once the tool is ready.

==Below is V4 description==
1) SecurityPkg - Refine AuthenticateFmpImage() API to let caller
input PublicKeyData and PublicKeyDataLength, instead of PCD.
The benefit is that then this API can be used for a platform
which stores PublicKeyData in anywhere other than PCD.
2) SecurityPkg - Use OFFSET_OF(WIN_CERTIFICATE_UEFI_GUID, CertData)
for better understanding the code.
3) MdeModulePkg - Update CapsuleApp to let it consume
ShellParameters protocol to get Argc and Argv.
4) UefiCpuPkg - Update MicrocodeCapsuleApp to let it consume
ShellParameters protocol to get Argc and Argv.
5) QuarkPlatformPkg - Merge QuarkCapsule.fdf to Quark.fdf.

==Below is V3 description==
1) We move all EDKII related capsule definition to SignedCapsulePkg.
MdeModulePkg only contains FmAuthenticationLib and CapsuleApp,
because they are generic and follow UEFI specification on FMP/ESRT
and Microsoft platform firmware update document.
Any capsule implementation can use them.

Here is full library classes:
MdeModulePkg:
FmpAuthenticationLib.h: new lib - follow UEFI spec. (*)
Verify FMP signature of FMP Capsule
CapsuleLib.h: new API ¨C ProcessCapsules()
It processes all the capsules. Remove duplicated code in 
platform BDS.
UefiCpuPkg:
MicrocodeFlashAccessLib.h: Update Microcode region.
SignedCapsulePkg:
EdkiiSystemCapsuleLib.h ¨C Library for EDKII system FMP.
IniParsingLib.h ¨C Library for INI file parsing.
PlatformFlashAccessLib.h ¨C Library for write flash.

2) We will submit 5 series.
Series 1: Generic Update (MdeModulePkg/SecurityPkg)
DxeCapsuleLib
FmAuthenticationLib (*)
CapsuleApp (*)
Series 2: EDKII Capsule (SignedCapsulePkg)
IniParsingLib
EdkiiSystemCapsuleLib
PlatformFlashAccessLib
SystemFirmwareUpdate driver
RecoveryModuleLoadPei driver
Series 3: Microcode Update (UefiCpuPkg)
MicrocodeFlashAccessLib
MicrocodeUpdate driver.
Series 4: Quark update
Series 5: Vlv2 update

3) DxeCapsuleLib: Move code that performs authentication and parsing of
the capsule format into the implementation of the FMP Protocol.
We move the dispatch FV code from 

[edk2] [PATCH V8 1/7] UefiCpuPkg/Include: Add Microcode FMP definition.

2016-11-02 Thread Jiewen Yao
It defined ImageTypeId for Microcode.

Cc: Jeff Fan 
Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: Jeff Fan 
---
 UefiCpuPkg/Include/Guid/MicrocodeFmp.h | 21 
 1 file changed, 21 insertions(+)

diff --git a/UefiCpuPkg/Include/Guid/MicrocodeFmp.h 
b/UefiCpuPkg/Include/Guid/MicrocodeFmp.h
new file mode 100644
index 000..88a1953
--- /dev/null
+++ b/UefiCpuPkg/Include/Guid/MicrocodeFmp.h
@@ -0,0 +1,21 @@
+/** @file
+
+  Copyright (c) 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.
+
+**/
+
+#ifndef __MICROCODE_FMP_GUID_H__
+#define __MICROCODE_FMP_GUID_H__
+
+#define MICROCODE_FMP_IMAGE_TYPE_ID_GUID { 0x96d4fdcd, 0x1502, 0x424d, { 0x9d, 
0x4c, 0x9b, 0x12, 0xd2, 0xdc, 0xae, 0x5c } }
+
+extern EFI_GUID gMicrocodeFmpImageTypeIdGuid;
+
+#endif
-- 
2.7.4.windows.1

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


[edk2] [PATCH V8 06/12] SignedCapsulePkg/CapsulePkg.dec: Add capsule related definition.

2016-11-02 Thread Jiewen Yao
1) Add capsule related GUID.
   EdkiiSystemFmpCapsule
2) Add capsule related library.
   EdkiiSystemCapsuleLib
   IniParsingLib
   PlatformFlashAccessLib
3) Add EDKII system capsule related DynamicEx PCD
   PcdEdkiiSystemFirmwareImageDescriptor
   PcdEdkiiSystemFirmwareFileGuid
   NOTE: We use DynamicEx here because the update driver may be in
   the capsule FMP, instead of system firmware.
   The update driver MUST use the PCD info produced system firmware.
4) Add Test key file PCD
   These PCDs indicate the GUID of FFS which contains test key file.

Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: Liming Gao 
---
 SignedCapsulePkg/SignedCapsulePkg.dec | 76 
 1 file changed, 76 insertions(+)

diff --git a/SignedCapsulePkg/SignedCapsulePkg.dec 
b/SignedCapsulePkg/SignedCapsulePkg.dec
new file mode 100644
index 000..b27e874
--- /dev/null
+++ b/SignedCapsulePkg/SignedCapsulePkg.dec
@@ -0,0 +1,76 @@
+## @file
+# This package provides EDKII capsule related support.
+#
+# Copyright (c) 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 that 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  = 0x00010005
+  PACKAGE_NAME   = SignedCapsulePkg
+  PACKAGE_GUID   = 75AA5D82-7BC4-44A9-82FB-0820EBC79BED
+  PACKAGE_VERSION= 0.1
+
+[Includes]
+  Include
+
+[LibraryClasses]
+  ## @libraryclass  Provides services for EDKII system FMP capsule.
+  #
+  EdkiiSystemCapsuleLib|Include/Library/EdkiiSystemCapsuleLib.h
+
+  ## @libraryclass  Provides services to parse the INI configuration file.
+  #
+  IniParsingLib|Include/Library/IniParsingLib.h
+
+  ## @libraryclass  Provides services to access flash device.
+  #
+  PlatformFlashAccessLib|Include/Library/PlatformFlashAccessLib.h
+
+[Guids]
+  gEfiSignedCapsulePkgTokenSpaceGuid  = { 0xe1eb612f, 0x1c6c, 0x485d, { 
0x9d, 0x6, 0x65, 0x8, 0x44, 0x88, 0x15, 0x69 }}
+
+  ## Include/Guid/EdkiiSystemFmpCapsule.h
+  gEdkiiSystemFirmwareImageDescriptorFileGuid = {0x90b2b846, 0xca6d, 0x4d6e, 
{0xa8, 0xd3, 0xc1, 0x40, 0xa8, 0xe1, 0x10, 0xac}}
+  gEdkiiSystemFmpCapsuleConfigFileGuid= {0x812136d3, 0x4d3a, 0x433a, 
{0x94, 0x18, 0x29, 0xbb, 0x9b, 0xf7, 0x8f, 0x6e}}
+  gEdkiiSystemFmpCapsuleDriverFvFileGuid  = {0xce57b167, 0xb0e4, 0x41e8, 
{0xa8, 0x97, 0x5f, 0x4f, 0xeb, 0x78, 0x1d, 0x40}}
+
+[PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx]
+  ## This is the GUID of the FFS which contains the 
Rsa2048Sha256TestPublicKeyFile as a RAW section.
+  # @Prompt GUID of the FFS which contains the Rsa2048Sha256TestPublicKeyFile.
+  
gEfiSignedCapsulePkgTokenSpaceGuid.PcdEdkiiRsa2048Sha256TestPublicKeyFileGuid|{0x04,
 0xe1, 0xfe, 0xc4, 0x57, 0x66, 0x36, 0x49, 0xa6, 0x11, 0x13, 0x8d, 0xbc, 0x2a, 
0x76, 0xad}|VOID*|0xA0010001
+
+  ## This is the GUID of the FFS which contains the Pkcs7TestPublicKeyFile as 
a RAW section.
+  # @Prompt GUID of the FFS which contains the Pkcs7TestPublicKeyFile.
+  gEfiSignedCapsulePkgTokenSpaceGuid.PcdEdkiiPkcs7TestPublicKeyFileGuid|{0xba, 
0xf5, 0x93, 0xf0, 0x37, 0x6f, 0x16, 0x48, 0x9e, 0x52, 0x91, 0xbe, 0xa0, 0xf7, 
0xe0, 0xb8}|VOID*|0xA0010002
+
+[PcdsDynamicEx]
+  ## This dynamic PCD holds the EDKII system firmware image descriptor.
+  #  This information can be used for version check in EDKII system FMP 
capsule.
+  #  Only if the new EdkiiSystemFrimwareImageDescriptor.Version is not less 
than
+  #  the current PcdEdkiiSystemFirmwareImageDescriptor.LowestSupportedVersion,
+  #  the EDKII system FmpCapsule will be processed.
+  #  The data structure of this PCD is EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR,
+  #  SignedCapsulePkg/Include/Guid/EdkiiSystemFmpCapsule.h.
+  #  It must be in [PcdsDynamicEx], because the EDKII system firmware update 
module may
+  #  consume the PCD produced in current system firmware.
+  # @Prompt EDKII system firmware image descriptor.
+  
gEfiSignedCapsulePkgTokenSpaceGuid.PcdEdkiiSystemFirmwareImageDescriptor|{0x0}|VOID*|0x0037
+
+  ## This dynamic PCD hold the GUID of a firmware FFS which includes EDKII
+  #  system firmware image.
+  #  An EDKII system firmware udpate module need consume this PCD to extract
+  #  the EDKII system firmware from the capsule image.
+  #  It must be in [PcdsDynamicEx], because the EDKII system firmware 

[edk2] [PATCH V8 05/12] SignedCapsulePkg/Include: Add PlatformFlashAccessLib header.

2016-11-02 Thread Jiewen Yao
This library is used to abstract platform flash access.
This library is consumed by a capsule update module.
It may cover SystemFirmware region and/or non-SystemFirmware region.

Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: Liming Gao 
---
 SignedCapsulePkg/Include/Library/PlatformFlashAccessLib.h | 57 

 1 file changed, 57 insertions(+)

diff --git a/SignedCapsulePkg/Include/Library/PlatformFlashAccessLib.h 
b/SignedCapsulePkg/Include/Library/PlatformFlashAccessLib.h
new file mode 100644
index 000..0a8858e
--- /dev/null
+++ b/SignedCapsulePkg/Include/Library/PlatformFlashAccessLib.h
@@ -0,0 +1,57 @@
+/** @file
+  Platform flash device access library.
+
+  Copyright (c) 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.
+
+**/
+
+
+#ifndef __PLATFORM_FLASH_ACCESS_LIB_H__
+#define __PLATFORM_FLASH_ACCESS_LIB_H__
+
+typedef enum {
+  FlashAddressTypeRelativeAddress,
+  FlashAddressTypeAbsoluteAddress,
+} FLASH_ADDRESS_TYPE;
+
+//
+// Type 0 ~ 0x7FFF is defined in this library.
+// Type 0x8000 ~ 0x is reserved for OEM.
+//
+typedef enum {
+  PlatformFirmwareTypeSystemFirmware,
+  PlatformFirmwareTypeNvRam,
+} PLATFORM_FIRMWARE_TYPE;
+
+/**
+  Perform flash write opreation.
+
+  @param[in] FirmwareType  The type of firmware.
+  @param[in] FlashAddress  The address of flash device to be accessed.
+  @param[in] FlashAddressType  The type of flash device address.
+  @param[in] BufferThe pointer to the data buffer.
+  @param[in] LengthThe length of data buffer in bytes.
+
+  @retval EFI_SUCCESS   The operation returns successfully.
+  @retval EFI_WRITE_PROTECTED   The flash device is read only.
+  @retval EFI_UNSUPPORTED   The flash device access is unsupported.
+  @retval EFI_INVALID_PARAMETER The input parameter is not valid.
+**/
+EFI_STATUS
+EFIAPI
+PerformFlashWrite (
+  IN PLATFORM_FIRMWARE_TYPE   FirmwareType,
+  IN EFI_PHYSICAL_ADDRESS FlashAddress,
+  IN FLASH_ADDRESS_TYPE   FlashAddressType,
+  IN VOID *Buffer,
+  IN UINTNLength
+  );
+
+#endif
-- 
2.7.4.windows.1

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


[edk2] [PATCH V8 14/15] SecurityPkg/FmpAuthenticationLibRsa2048Sha256: Add RSA2048 instance.

2016-11-02 Thread Jiewen Yao
It provides Rsa2048Sha256 based FMP authentication.

Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: Chao Zhang 
---
 
SecurityPkg/Library/FmpAuthenticationLibRsa2048Sha256/FmpAuthenticationLibRsa2048Sha256.c
   | 355 
 
SecurityPkg/Library/FmpAuthenticationLibRsa2048Sha256/FmpAuthenticationLibRsa2048Sha256.inf
 |  53 +++
 
SecurityPkg/Library/FmpAuthenticationLibRsa2048Sha256/FmpAuthenticationLibRsa2048Sha256.uni
 |  26 ++
 3 files changed, 434 insertions(+)

diff --git 
a/SecurityPkg/Library/FmpAuthenticationLibRsa2048Sha256/FmpAuthenticationLibRsa2048Sha256.c
 
b/SecurityPkg/Library/FmpAuthenticationLibRsa2048Sha256/FmpAuthenticationLibRsa2048Sha256.c
new file mode 100644
index 000..d113d58
--- /dev/null
+++ 
b/SecurityPkg/Library/FmpAuthenticationLibRsa2048Sha256/FmpAuthenticationLibRsa2048Sha256.c
@@ -0,0 +1,355 @@
+/** @file
+  FMP Authentication RSA2048SHA256 handler.
+  Provide generic FMP authentication functions for DXE/PEI post memory phase.
+
+  Caution: This module requires additional review when modified.
+  This module will have external input - capsule image.
+  This external input must be validated carefully to avoid security issue like
+  buffer overflow, integer overflow.
+
+  FmpAuthenticatedHandlerRsa2048Sha256(), AuthenticateFmpImage() will receive
+  untrusted input and do basic validation.
+
+  Copyright (c) 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 
+
+///
+/// Public Exponent of RSA Key.
+///
+STATIC CONST UINT8 mRsaE[] = { 0x01, 0x00, 0x01 };
+
+/**
+  The handler is used to do the authentication for FMP capsule based upon
+  EFI_FIRMWARE_IMAGE_AUTHENTICATION.
+
+  Caution: This function may receive untrusted input.
+
+  This function assumes the caller AuthenticateFmpImage()
+  already did basic validation for EFI_FIRMWARE_IMAGE_AUTHENTICATION.
+
+  @param[in]  Image   Points to an FMP authentication image, 
started from EFI_FIRMWARE_IMAGE_AUTHENTICATION.
+  @param[in]  ImageSize   Size of the authentication image in 
bytes.
+  @param[in]  PublicKeyData   The public key data used to validate the 
signature.
+  @param[in]  PublicKeyDataLength The length of the public key data.
+
+  @retval RETURN_SUCCESSAuthentication pass.
+The LastAttemptStatus should be 
LAST_ATTEMPT_STATUS_SUCCESS.
+  @retval RETURN_SECURITY_VIOLATION Authentication fail.
+The LastAttemptStatus should be 
LAST_ATTEMPT_STATUS_ERROR_AUTH_ERROR.
+  @retval RETURN_INVALID_PARAMETER  The image is in an invalid format.
+The LastAttemptStatus should be 
LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT.
+  @retval RETURN_OUT_OF_RESOURCES   No Authentication handler associated with 
CertType.
+The LastAttemptStatus should be 
LAST_ATTEMPT_STATUS_ERROR_INSUFFICIENT_RESOURCES.
+**/
+RETURN_STATUS
+FmpAuthenticatedHandlerRsa2048Sha256 (
+  IN EFI_FIRMWARE_IMAGE_AUTHENTICATION  *Image,
+  IN UINTN  ImageSize,
+  IN CONST UINT8*PublicKeyData,
+  IN UINTN  PublicKeyDataLength
+  )
+{
+  RETURN_STATUS Status;
+  EFI_CERT_BLOCK_RSA_2048_SHA256*CertBlockRsa2048Sha256;
+  BOOLEAN   CryptoStatus;
+  UINT8 Digest[SHA256_DIGEST_SIZE];
+  UINT8 *PublicKey;
+  UINTN PublicKeyBufferSize;
+  VOID  *HashContext;
+  VOID  *Rsa;
+
+  DEBUG ((DEBUG_INFO, "FmpAuthenticatedHandlerRsa2048Sha256 - Image: 0x%08x - 
0x%08x\n", (UINTN)Image, (UINTN)ImageSize));
+
+  if (Image->AuthInfo.Hdr.dwLength != OFFSET_OF(WIN_CERTIFICATE_UEFI_GUID, 
CertData) + sizeof(EFI_CERT_BLOCK_RSA_2048_SHA256)) {
+DEBUG((DEBUG_ERROR, "FmpAuthenticatedHandlerRsa2048Sha256 - dwLength: 
0x%04x, dwLength - 0x%04x\n", (UINTN)Image->AuthInfo.Hdr.dwLength, 

[edk2] [PATCH V8 01/15] MdeModulePkg/Include: Add FmpAuthenticationLib header.

2016-11-02 Thread Jiewen Yao
This library is used to authenticate a UEFI defined FMP Capsule.

Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: Liming Gao 
---
 MdeModulePkg/Include/Library/FmpAuthenticationLib.h | 66 
 1 file changed, 66 insertions(+)

diff --git a/MdeModulePkg/Include/Library/FmpAuthenticationLib.h 
b/MdeModulePkg/Include/Library/FmpAuthenticationLib.h
new file mode 100644
index 000..2910c91
--- /dev/null
+++ b/MdeModulePkg/Include/Library/FmpAuthenticationLib.h
@@ -0,0 +1,66 @@
+/** @file
+  FMP capsule authenitcation Library.
+
+Copyright (c) 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.
+
+**/
+
+
+#ifndef __FMP_AUTHENTICATION_LIB_H__
+#define __FMP_AUTHENTICATION_LIB_H__
+
+#include 
+
+/**
+  The function is used to do the authentication for FMP capsule based upon
+  EFI_FIRMWARE_IMAGE_AUTHENTICATION.
+
+  The FMP capsule image should start with EFI_FIRMWARE_IMAGE_AUTHENTICATION,
+  followed by the payload.
+
+  If the return status is RETURN_SUCCESS, the caller may continue the rest
+  FMP update process.
+  If the return status is NOT RETURN_SUCCESS, the caller should stop the FMP
+  update process and convert the return status to LastAttemptStatus
+  to indicate that FMP update fails.
+  The LastAttemptStatus can be got from ESRT table or via
+  EFI_FIRMWARE_MANAGEMENT_PROTOCOL.GetImageInfo().
+
+  Caution: This function may receive untrusted input.
+
+  @param[in]  Image   Points to an FMP authentication image, 
started from EFI_FIRMWARE_IMAGE_AUTHENTICATION.
+  @param[in]  ImageSize   Size of the authentication image in 
bytes.
+  @param[in]  PublicKeyData   The public key data used to validate the 
signature.
+  @param[in]  PublicKeyDataLength The length of the public key data.
+
+  @retval RETURN_SUCCESSAuthentication pass.
+The LastAttemptStatus should be 
LAST_ATTEMPT_STATUS_SUCCESS.
+  @retval RETURN_SECURITY_VIOLATION Authentication fail.
+The LastAttemptStatus should be 
LAST_ATTEMPT_STATUS_ERROR_AUTH_ERROR.
+  @retval RETURN_INVALID_PARAMETER  The image is in an invalid format.
+The LastAttemptStatus should be 
LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT.
+  @retval RETURN_UNSUPPORTEDNo Authentication handler associated with 
CertType.
+The LastAttemptStatus should be 
LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT.
+  @retval RETURN_UNSUPPORTEDImage or ImageSize is invalid.
+The LastAttemptStatus should be 
LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT.
+  @retval RETURN_OUT_OF_RESOURCES   No Authentication handler associated with 
CertType.
+The LastAttemptStatus should be 
LAST_ATTEMPT_STATUS_ERROR_INSUFFICIENT_RESOURCES.
+**/
+RETURN_STATUS
+EFIAPI
+AuthenticateFmpImage (
+  IN EFI_FIRMWARE_IMAGE_AUTHENTICATION  *Image,
+  IN UINTN  ImageSize,
+  IN CONST UINT8*PublicKeyData,
+  IN UINTN  PublicKeyDataLength
+  );
+
+#endif
+
-- 
2.7.4.windows.1

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


[edk2] [PATCH V8 11/12] SignedCapsulePkg/RecoveryModuleLoadPei: Add RecoveryModuleLoadPei.

2016-11-02 Thread Jiewen Yao
RecoveryModuleLoadPei supports recovery system firmware via FMP capsule.

RecoveryModuleLoadPei produces EFI_PEI_RECOVERY_MODULE_PPI. It is invoked
by DxeIpl in recovery boot mode.

LoadRecoveryCapsule() will scan all possible
gEfiPeiDeviceRecoveryModulePpiGuid and get EDKII system FMP capsule there.

LoadRecoveryCapsule() will perform the FMP authentication and version
check. If and only if the FMP authentication passes, and EDKII system FMP
capsule version is equal to the current system firmware Version, the
recovery will be performed. Or this capsule image is discard.

Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: Liming Gao 
---
 SignedCapsulePkg/Universal/RecoveryModuleLoadPei/ParseConfigProfile.c  
 | 176 +
 SignedCapsulePkg/Universal/RecoveryModuleLoadPei/RecoveryModuleLoadPei.c   
 | 748 
 SignedCapsulePkg/Universal/RecoveryModuleLoadPei/RecoveryModuleLoadPei.h   
 |  44 ++
 SignedCapsulePkg/Universal/RecoveryModuleLoadPei/RecoveryModuleLoadPei.inf 
 |  70 ++
 SignedCapsulePkg/Universal/RecoveryModuleLoadPei/RecoveryModuleLoadPei.uni 
 |  21 +
 
SignedCapsulePkg/Universal/RecoveryModuleLoadPei/RecoveryModuleLoadPeiExtra.uni 
|  20 +
 6 files changed, 1079 insertions(+)

diff --git 
a/SignedCapsulePkg/Universal/RecoveryModuleLoadPei/ParseConfigProfile.c 
b/SignedCapsulePkg/Universal/RecoveryModuleLoadPei/ParseConfigProfile.c
new file mode 100644
index 000..331683a
--- /dev/null
+++ b/SignedCapsulePkg/Universal/RecoveryModuleLoadPei/ParseConfigProfile.c
@@ -0,0 +1,176 @@
+/** @file
+  Parse the INI configuration file and pass the information to the recovery 
driver
+  so that the driver can perform recovery accordingly.
+
+  The Config file format is below:
+
+  [Head]
+  NumOfRecovery =  # Decimal
+  Recovery0 =# String
+  Recovery1 =# String
+  Recovery =  # String
+
+  [Name?]
+  Length  =  # Fv Length (HEX)
+  ImageOffset = # Fv offset of this SystemFirmware image (HEX)
+  FileGuid= ----  # 
PcdEdkiiSystemFirmwareFileGuid
+
+  Copyright (c) 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 "RecoveryModuleLoadPei.h"
+#include 
+#include 
+
+#define MAX_LINE_LENGTH   512
+
+/**
+  Parse Config data file to get the updated data array.
+
+  @param[in]  DataBuffer  Config raw file buffer.
+  @param[in]  BufferSize  Size of raw buffer.
+  @param[in, out] ConfigHeaderPointer to the config header.
+  @param[in, out] RecoveryArray   Pointer to the config of recovery data.
+
+  @retval EFI_NOT_FOUND No config data is found.
+  @retval EFI_OUT_OF_RESOURCES  No enough memory is allocated.
+  @retval EFI_SUCCESS   Parse the config file successfully.
+
+**/
+EFI_STATUS
+ParseRecoveryDataFile (
+  IN  UINT8 *DataBuffer,
+  IN  UINTN BufferSize,
+  IN OUT  CONFIG_HEADER *ConfigHeader,
+  IN OUT  RECOVERY_CONFIG_DATA  **RecoveryArray
+  )
+{
+  EFI_STATUSStatus;
+  CHAR8 *SectionName;
+  CHAR8 Entry[MAX_LINE_LENGTH];
+  UINTN Num;
+  UINTN Index;
+  EFI_GUID  FileGuid;
+  VOID  *Context;
+
+  //
+  // First process the data buffer and get all sections and entries
+  //
+  Context = OpenIniFile(DataBuffer, BufferSize);
+  if (Context == NULL) {
+return EFI_INVALID_PARAMETER;
+  }
+
+  //
+  // Now get NumOfUpdate
+  //
+  Status = GetDecimalUintnFromDataFile(
+ Context,
+ "Head",
+ "NumOfRecovery",
+ 
+ );
+  if (EFI_ERROR(Status) || (Num == 0)) {
+DEBUG((DEBUG_ERROR, "NumOfRecovery not found\n"));
+CloseIniFile(Context);
+return EFI_NOT_FOUND;
+  }
+
+  ConfigHeader->NumOfRecovery = Num;
+  *RecoveryArray = AllocateZeroPool ((sizeof (RECOVERY_CONFIG_DATA) * Num));
+  if (*RecoveryArray == NULL) {
+CloseIniFile(Context);
+return EFI_OUT_OF_RESOURCES;
+  }
+
+  for (Index = 0 ; Index < ConfigHeader->NumOfRecovery; Index++) {
+//
+// Get the 

[edk2] [PATCH V8 10/12] SignedCapsulePkg/SystemFirmwareUpdate: Add SystemFirmwareUpdate.

2016-11-02 Thread Jiewen Yao
SystemFirmwareUpdate supports update system firmware via UEFI FMP capsule.

SystemFirmwareReportDxe.inf can be included in system BIOS. It is a
lightweight FMP protocol implementation and it only reports FMP
information, so that ESRT table can report the system firmware
information. SetImage() will dispatch the driver FV in the EDKII system
FMP image (SystemFirmwareUpdateDxe),
then pass thru the SetImage() request to latter.

SystemFirmwareUpdateDxe.inf can be included in EDKII system capsule image.
It is a full feature FMP protocol implementation and supports SetImage().
It can be used to update the system firmware.
SystemFirmwareUpdateDxe.inf can also be included in system firmware.
If so SystemFirmwareReportDxe.inf is not needed.

SystemFirmwareUpdateDxe SetImage() will perform the FMP authentication and
version check. If and only if the FMP authentication passes, and new
EDKII system capsule version is no less than current system firmware
LowestSupportedVersion, the system firmware will be updated.

Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: Liming Gao 
---
 SignedCapsulePkg/Universal/SystemFirmwareUpdate/ParseConfigProfile.c   
  | 244 +
 SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareCommonDxe.c  
  | 385 +++
 SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareDxe.h
  | 409 +++
 SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareReportDxe.c  
  | 262 ++
 SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareReportDxe.inf
  |  69 +++
 SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareReportDxe.uni
  |  21 +
 
SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareReportDxeExtra.uni
 |  20 +
 SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareUpdateDxe.c  
  | 522 
 SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareUpdateDxe.inf
  |  71 +++
 SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareUpdateDxe.uni
  |  21 +
 
SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareUpdateDxeExtra.uni
 |  20 +
 11 files changed, 2044 insertions(+)

diff --git 
a/SignedCapsulePkg/Universal/SystemFirmwareUpdate/ParseConfigProfile.c 
b/SignedCapsulePkg/Universal/SystemFirmwareUpdate/ParseConfigProfile.c
new file mode 100644
index 000..68db2c6
--- /dev/null
+++ b/SignedCapsulePkg/Universal/SystemFirmwareUpdate/ParseConfigProfile.c
@@ -0,0 +1,244 @@
+/** @file
+  Parse the INI configuration file and pass the information to the update 
driver
+  so that the driver can perform update accordingly.
+
+  The Config file format is below:
+
+  [Head]
+  NumOfUpdate =  # Decimal
+  Update0 =# String
+  Update1 =# String
+  Update =  # String
+
+  [Name?]
+  FirmwareType = 0   # 0 - SystemFirmware, 1 - NvRam
+  AddressType = 0# 0 - relative address, 1 - absolute address.
+  BaseAddress = # Base address offset on flash (HEX)
+  Length  =  # Image Length (HEX)
+  ImageOffset = # Image offset of this SystemFirmware image 
(HEX)
+  FileGuid= ----  # 
PcdEdkiiSystemFirmwareFileGuid
+
+  Copyright (c) 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 "SystemFirmwareDxe.h"
+#include 
+#include 
+
+#define MAX_LINE_LENGTH   512
+
+/**
+  Parse Config data file to get the updated data array.
+
+  @param[in]  DataBuffer  Config raw file buffer.
+  @param[in]  BufferSize  Size of raw buffer.
+  @param[in, out] ConfigHeaderPointer to the config header.
+  @param[in, out] UpdateArray Pointer to the config of update data.
+
+  @retval EFI_NOT_FOUND No config data is found.
+  @retval EFI_OUT_OF_RESOURCES  No enough memory is allocated.
+  @retval EFI_SUCCESS   Parse the config file successfully.
+
+**/
+EFI_STATUS
+ParseUpdateDataFile (
+  IN  UINT8 *DataBuffer,
+  IN  UINTN BufferSize,
+  IN OUT  CONFIG_HEADER *ConfigHeader,
+  IN OUT  UPDATE_CONFIG_DATA**UpdateArray
+  )
+{
+  EFI_STATUSStatus;
+  CHAR8 

[edk2] [PATCH V8 08/12] SignedCapsulePkg/EdkiiSystemCapsuleLib: Add EdkiiSystemCapsuleLib.

2016-11-02 Thread Jiewen Yao
This library is used to abstract the action for EDKII system FMP capsule,
such as extracting a component from capsule, or authenticate the capsule.

Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: Liming Gao 
---
 SignedCapsulePkg/Library/EdkiiSystemCapsuleLib/EdkiiSystemCapsuleLib.c   | 671 

 SignedCapsulePkg/Library/EdkiiSystemCapsuleLib/EdkiiSystemCapsuleLib.inf |  61 
++
 SignedCapsulePkg/Library/EdkiiSystemCapsuleLib/EdkiiSystemCapsuleLib.uni |  22 
+
 3 files changed, 754 insertions(+)

diff --git 
a/SignedCapsulePkg/Library/EdkiiSystemCapsuleLib/EdkiiSystemCapsuleLib.c 
b/SignedCapsulePkg/Library/EdkiiSystemCapsuleLib/EdkiiSystemCapsuleLib.c
new file mode 100644
index 000..27c6f4c
--- /dev/null
+++ b/SignedCapsulePkg/Library/EdkiiSystemCapsuleLib/EdkiiSystemCapsuleLib.c
@@ -0,0 +1,671 @@
+/** @file
+  EDKII System Capsule library.
+
+  EDKII System Capsule library instance.
+
+  CapsuleAuthenticateSystemFirmware(), ExtractAuthenticatedImage() will receive
+  untrusted input and do basic validation.
+
+  Copyright (c) 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 
+
+EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR   *mImageFmpInfo;
+UINTNmImageFmpInfoSize;
+EFI_GUID mEdkiiSystemFirmwareFileGuid;
+
+/**
+  Check if a block of buffer is erased.
+
+  @param[in] ErasePolarity  Erase polarity attribute of the firmware volume
+  @param[in] InBuffer   The buffer to be checked
+  @param[in] BufferSize Size of the buffer in bytes
+
+  @retvalTRUE   The block of buffer is erased
+  @retvalFALSE  The block of buffer is not erased
+**/
+BOOLEAN
+IsBufferErased (
+  IN UINT8ErasePolarity,
+  IN VOID *InBuffer,
+  IN UINTNBufferSize
+  )
+{
+  UINTN   Count;
+  UINT8   EraseByte;
+  UINT8   *Buffer;
+
+  if(ErasePolarity == 1) {
+EraseByte = 0xFF;
+  } else {
+EraseByte = 0;
+  }
+
+  Buffer = InBuffer;
+  for (Count = 0; Count < BufferSize; Count++) {
+if (Buffer[Count] != EraseByte) {
+  return FALSE;
+}
+  }
+
+  return TRUE;
+}
+
+/**
+  Get Section buffer pointer by SectionType and SectionInstance.
+
+  @param[in]   SectionBuffer The buffer of section
+  @param[in]   SectionBufferSize The size of SectionBuffer in bytes
+  @param[in]   SectionType   The SectionType of Section to be found
+  @param[in]   SectionInstance   The Instance of Section to be found
+  @param[out]  OutSectionBuffer  The section found, including SECTION_HEADER
+  @param[out]  OutSectionSizeThe size of section found, including 
SECTION_HEADER
+
+  @retval TRUE  The FFS buffer is found.
+  @retval FALSE The FFS buffer is not found.
+**/
+BOOLEAN
+GetSectionByType (
+  IN VOID  *SectionBuffer,
+  IN UINT32SectionBufferSize,
+  IN EFI_SECTION_TYPE  SectionType,
+  IN UINTN SectionInstance,
+  OUT VOID **OutSectionBuffer,
+  OUT UINTN*OutSectionSize
+  )
+{
+  EFI_COMMON_SECTION_HEADER *SectionHeader;
+  UINTN SectionSize;
+  UINTN Instance;
+
+  DEBUG ((DEBUG_INFO, "GetSectionByType - Buffer: 0x%08x - 0x%08x\n", 
SectionBuffer, SectionBufferSize));
+
+  //
+  // Find Section
+  //
+  SectionHeader = SectionBuffer;
+
+  Instance = 0;
+  while ((UINTN)SectionHeader < (UINTN)SectionBuffer + SectionBufferSize) {
+DEBUG ((DEBUG_INFO, "GetSectionByType - Section: 0x%08x\n", 
SectionHeader));
+if (IS_SECTION2(SectionHeader)) {
+  SectionSize = SECTION2_SIZE(SectionHeader);
+} else {
+  SectionSize = SECTION_SIZE(SectionHeader);
+}
+
+if (SectionHeader->Type == SectionType) {
+  if (Instance == SectionInstance) {
+*OutSectionBuffer = (UINT8 *)SectionHeader;
+*OutSectionSize = SectionSize;
+DEBUG((DEBUG_INFO, "GetSectionByType - 0x%x - 0x%x\n", 
*OutSectionBuffer, *OutSectionSize));
+return TRUE;
+  } else {
+DEBUG((DEBUG_INFO, "GetSectionByType - find section instance %x\n", 
Instance));
+   

[edk2] [PATCH V8 09/12] SignedCapsulePkg/PlatformFlashAccessLib: Add NULL instance.

2016-11-02 Thread Jiewen Yao
Add NULL instance to pass build.

Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: Liming Gao 
---
 
SignedCapsulePkg/Library/PlatformFlashAccessLibNull/PlatformFlashAccessLibNull.c
   | 51 
 
SignedCapsulePkg/Library/PlatformFlashAccessLibNull/PlatformFlashAccessLibNull.inf
 | 40 +++
 
SignedCapsulePkg/Library/PlatformFlashAccessLibNull/PlatformFlashAccessLibNull.uni
 | 21 
 3 files changed, 112 insertions(+)

diff --git 
a/SignedCapsulePkg/Library/PlatformFlashAccessLibNull/PlatformFlashAccessLibNull.c
 
b/SignedCapsulePkg/Library/PlatformFlashAccessLibNull/PlatformFlashAccessLibNull.c
new file mode 100644
index 000..b34ebbb
--- /dev/null
+++ 
b/SignedCapsulePkg/Library/PlatformFlashAccessLibNull/PlatformFlashAccessLibNull.c
@@ -0,0 +1,51 @@
+/** @file
+  Platform flash device access library NULL instance.
+
+  Copyright (c) 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 
+
+UINT64 mInternalFdAddress;
+
+/**
+  Perform flash write opreation.
+
+  @param[in] FirmwareType  The type of firmware.
+  @param[in] FlashAddress  The address of flash device to be accessed.
+  @param[in] FlashAddressType  The type of flash device address.
+  @param[in] BufferThe pointer to the data buffer.
+  @param[in] LengthThe length of data buffer in bytes.
+
+  @retval EFI_SUCCESS   The operation returns successfully.
+  @retval EFI_WRITE_PROTECTED   The flash device is read only.
+  @retval EFI_UNSUPPORTED   The flash device access is unsupported.
+  @retval EFI_INVALID_PARAMETER The input parameter is not valid.
+**/
+EFI_STATUS
+EFIAPI
+PerformFlashWrite (
+  IN PLATFORM_FIRMWARE_TYPE   FirmwareType,
+  IN EFI_PHYSICAL_ADDRESS FlashAddress,
+  IN FLASH_ADDRESS_TYPE   FlashAddressType,
+  IN VOID *Buffer,
+  IN UINTNLength
+  )
+{
+  if (FlashAddressType == FlashAddressTypeRelativeAddress) {
+FlashAddress = FlashAddress + mInternalFdAddress;
+  }
+  CopyMem((VOID *)(UINTN)(FlashAddress), Buffer, Length);
+  return EFI_SUCCESS;
+}
diff --git 
a/SignedCapsulePkg/Library/PlatformFlashAccessLibNull/PlatformFlashAccessLibNull.inf
 
b/SignedCapsulePkg/Library/PlatformFlashAccessLibNull/PlatformFlashAccessLibNull.inf
new file mode 100644
index 000..f3a7a6c
--- /dev/null
+++ 
b/SignedCapsulePkg/Library/PlatformFlashAccessLibNull/PlatformFlashAccessLibNull.inf
@@ -0,0 +1,40 @@
+## @file
+#  Platform flash device access library.
+#
+#  Platform flash device access library NULL instance.
+#
+#  Copyright (c) 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.
+#
+##
+
+[Defines]
+  INF_VERSION= 0x00010005
+  BASE_NAME  = PlatformFlashAccessLibNull
+  MODULE_UNI_FILE= PlatformFlashAccessLibNull.uni
+  FILE_GUID  = A0534D92-9776-4E4E-9234-C9DC1849DBB5
+  MODULE_TYPE= BASE
+  VERSION_STRING = 1.0
+  LIBRARY_CLASS  = PlatformFlashAccessLib
+
+#
+# The following information is for reference only and not required by the 
build tools.
+#
+#  VALID_ARCHITECTURES   = IA32 X64 IPF EBC
+#
+
+[Sources]
+  PlatformFlashAccessLibNull.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  SignedCapsulePkg/SignedCapsulePkg.dec
+
+[LibraryClasses]
+  BaseMemoryLib
diff --git 
a/SignedCapsulePkg/Library/PlatformFlashAccessLibNull/PlatformFlashAccessLibNull.uni
 
b/SignedCapsulePkg/Library/PlatformFlashAccessLibNull/PlatformFlashAccessLibNull.uni
new file mode 100644
index 000..ae2648e
--- /dev/null
+++ 
b/SignedCapsulePkg/Library/PlatformFlashAccessLibNull/PlatformFlashAccessLibNull.uni
@@ -0,0 +1,21 @@
+// /** @file
+//  Platform flash device access library.
+//
+//  Platform flash device access library 

[edk2] [PATCH V8 07/12] SignedCapsulePkg/IniParsingLib: Add InitParsingLib instance.

2016-11-02 Thread Jiewen Yao
This library is used to parse the INI configuration file.
The INI configuration file is used in EDKII capsule image to describe
the capsule information.

Detail format is documented in header file.

Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: Liming Gao 
---
 SignedCapsulePkg/Library/IniParsingLib/IniParsingLib.c   | 1420 

 SignedCapsulePkg/Library/IniParsingLib/IniParsingLib.inf |   43 +
 SignedCapsulePkg/Library/IniParsingLib/IniParsingLib.uni |   22 +
 3 files changed, 1485 insertions(+)

diff --git a/SignedCapsulePkg/Library/IniParsingLib/IniParsingLib.c 
b/SignedCapsulePkg/Library/IniParsingLib/IniParsingLib.c
new file mode 100644
index 000..8a33cbe
--- /dev/null
+++ b/SignedCapsulePkg/Library/IniParsingLib/IniParsingLib.c
@@ -0,0 +1,1420 @@
+/** @file
+  This library parses the INI configuration file.
+
+  The INI file format is:
+
+[SectionName]
+EntryName=EntryValue
+
+
+Where:
+  1) SectionName is an ASCII string. The valid format is [A-Za-z0-9_]+
+  2) EntryName is an ASCII string. The valid format is [A-Za-z0-9_]+
+  3) EntryValue can be:
+ 3.1) an ASCII String. The valid format is [A-Za-z0-9_]+
+ 3.2) a GUID. The valid format is 
----, where x is [A-Fa-f0-9]
+ 3.3) a decimal value. The valid format is [0-9]+
+ 3.4) a heximal value. The valid format is 0x[A-Fa-f0-9]+
+  4) '#' or ';' can be used as comment at anywhere.
+  5) TAB(0x20) or SPACE(0x9) can be used as separator.
+  6) LF(\n, 0xA) or CR(\r, 0xD) can be used as line break.
+
+  Caution: This module requires additional review when modified.
+  This driver will have external input - INI data file.
+
+  OpenIniFile(), PreProcessDataFile(), ProfileGetSection(), ProfileGetEntry()
+  will receive untrusted input and do basic validation.
+
+  Copyright (c) 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 
+
+#define IS_HYPHEN(a)   ((a) == '-')
+#define IS_NULL(a) ((a) == '\0')
+
+// This is default allocation. Reallocation will happen if it is not enough.
+#define MAX_LINE_LENGTH   512
+
+typedef struct _SECTION_ITEM SECTION_ITEM;
+struct _SECTION_ITEM {
+  CHAR8   *PtrSection;
+  UINTN   SecNameLen;
+  CHAR8   *PtrEntry;
+  CHAR8   *PtrValue;
+  SECTION_ITEM*PtrNext;
+};
+
+typedef struct _COMMENT_LINE COMMENT_LINE;
+struct _COMMENT_LINE {
+  CHAR8   *PtrComment;
+  COMMENT_LINE*PtrNext;
+};
+
+typedef struct {
+  SECTION_ITEM  *SectionHead;
+  COMMENT_LINE  *CommentHead;
+} INI_PARSING_LIB_CONTEXT;
+
+/**
+  Return if the digital char is valid.
+
+  @param[in] DigitalCharThe digital char to be checked.
+  @param[in] IncludeHex If it include HEX char.
+
+  @retval TRUE   The digital char is valid.
+  @retval FALSE  The digital char is invalid.
+**/
+BOOLEAN
+IsValidDigitalChar (
+  IN CHAR8DigitalChar,
+  IN BOOLEAN  IncludeHex
+  )
+{
+  if (DigitalChar >= '0' && DigitalChar <= '9') {
+return TRUE;
+  }
+  if (IncludeHex) {
+if (DigitalChar >= 'a' && DigitalChar <= 'f') {
+  return TRUE;
+}
+if (DigitalChar >= 'A' && DigitalChar <= 'F') {
+  return TRUE;
+}
+  }
+  return FALSE;
+}
+
+/**
+  Return if the name char is valid.
+
+  @param[in] NameCharThe name char to be checked.
+
+  @retval TRUE   The name char is valid.
+  @retval FALSE  The name char is invalid.
+**/
+BOOLEAN
+IsValidNameChar (
+  IN CHAR8  NameChar
+  )
+{
+  if (NameChar >= 'a' && NameChar <= 'z') {
+return TRUE;
+  }
+  if (NameChar >= 'A' && NameChar <= 'Z') {
+return TRUE;
+  }
+  if (NameChar >= '0' && NameChar <= '9') {
+return TRUE;
+  }
+  if (NameChar == '_') {
+return TRUE;
+  }
+  return FALSE;
+}
+
+/**
+  Return if the digital string is valid.
+
+  @param[in] DigitalThe digital to be checked.
+  @param[in] Length The length of digital string in bytes.
+  @param[in] IncludeHex If it include HEX char.
+
+  @retval TRUE   The 

[edk2] [PATCH V8 02/12] SignedCapsulePkg/Include: Add EDKII system FMP capsule header.

2016-11-02 Thread Jiewen Yao
Add EDKII system FMP capsule header file.
This describes the EDKII system FMP capsule format.

Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: Liming Gao 
---
 SignedCapsulePkg/Include/Guid/EdkiiSystemFmpCapsule.h | 110 

 1 file changed, 110 insertions(+)

diff --git a/SignedCapsulePkg/Include/Guid/EdkiiSystemFmpCapsule.h 
b/SignedCapsulePkg/Include/Guid/EdkiiSystemFmpCapsule.h
new file mode 100644
index 000..4d99aee
--- /dev/null
+++ b/SignedCapsulePkg/Include/Guid/EdkiiSystemFmpCapsule.h
@@ -0,0 +1,110 @@
+/** @file
+  Guid & data structure used for Delivering Capsules Containing Updates to
+  EDKII System Firmware Management Protocol
+
+  Copyright (c) 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.
+
+**/
+
+
+#ifndef __EDKII_SYSTEM_FMP_CAPSULE_GUID_H__
+#define __EDKII_SYSTEM_FMP_CAPSULE_GUID_H__
+
+/**
+
+  Capsule Layout is below:
+  +--+
+  |Capsule Header (OPTIONAL, WFU)| <== ESRT.FwClass (Optional)
+  +--+
+  |  FMP Capsule Header  | <== 
EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID
+  +--+
+  | FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER | <== 
PcdSystemFmpCapsuleImageTypeIdGuid
+  +--+
+  | EFI_FIRMWARE_IMAGE_AUTHENTICATION|
+  +--+
+  | FMP Payload  |
+  +--+
+
+  System FMP Payload is below:
+  +--+
+  |EFI_FIRMWARE_VOLUME   |
+  |  ++  |
+  |  |   FFS (Configure File) |  | <== 
gEdkiiSystemFmpCapsuleConfigFileGuid
+  |  ++  |
+  |  | FFS (Driver FV)|  | <== 
gEdkiiSystemFmpCapsuleDriverFvFileGuid
+  |  ++  |
+  |  |FFS (System Firmware Image) |  | <== 
PcdEdkiiSystemFirmwareFileGuid
+  |  |  +--+  |  |
+  |  |  |  FV Recovery |  |  |
+  |  |  |--|  |  |
+  |  |  |   Fv Main|  |  |
+  |  |  +--+  |  |
+  |  ++  |
+  +--+
+
+**/
+
+#define EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR_SIGNATURE  SIGNATURE_32('S', 
'F', 'I', 'D')
+
+#pragma pack(1)
+typedef struct {
+  UINT32Signature;
+  UINT32HeaderLength; // Length of 
EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR, excluding NameString
+  UINT32Length;   // Length of the data 
structure, including NameString
+  // Below structure is similar as UEFI 
EFI_FIRMWARE_MANAGEMENT_PROTOCOL.GetPackageInfo()
+  UINT32PackageVersion;
+  UINT32PackageVersionNameStringOffset; // 
Offset from head, CHAR16 string including NULL terminate char
+  // Below structure is similar as UEFI EFI_FIRMWARE_IMAGE_DESCRIPTOR
+  UINT8 ImageIndex;
+  UINT8 Reserved[3];
+  EFI_GUID  ImageTypeId;
+  UINT64ImageId;
+  UINT32ImageIdNameStringOffset; // Offset 
from head, CHAR16 string including NULL terminate char
+  UINT32Version;
+  UINT32VersionNameStringOffset; // Offset 
from head, CHAR16 string including NULL terminate char
+  UINT8 Reserved2[4];
+  UINT64Size;
+  UINT64AttributesSupported;
+  UINT64AttributesSetting;
+  UINT64Compatibilities;
+  UINT32LowestSupportedImageVersion;
+  UINT32LastAttemptVersion;
+  UINT32LastAttemptStatus;
+  UINT8 Reserved3[4];
+  UINT64

[edk2] [PATCH V8 04/12] SignedCapsulePkg/Include: Add IniParsingLib header.

2016-11-02 Thread Jiewen Yao
This library is used to parse the INI configuration file.
The INI configuration file is used in EDKII capsule image to describe
the capsule information.

Detail format is documented in header file.

Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: Liming Gao 
---
 SignedCapsulePkg/Include/Library/IniParsingLib.h | 166 
 1 file changed, 166 insertions(+)

diff --git a/SignedCapsulePkg/Include/Library/IniParsingLib.h 
b/SignedCapsulePkg/Include/Library/IniParsingLib.h
new file mode 100644
index 000..e964dd2
--- /dev/null
+++ b/SignedCapsulePkg/Include/Library/IniParsingLib.h
@@ -0,0 +1,166 @@
+/** @file
+  INI configuration parsing library.
+
+  The INI file format is:
+
+[SectionName]
+EntryName=EntryValue
+
+
+Where:
+  1) SectionName is an ASCII string. The valid format is [A-Za-z0-9_]+
+  2) EntryName is an ASCII string. The valid format is [A-Za-z0-9_]+
+  3) EntryValue can be:
+ 3.1) an ASCII String. The valid format is [A-Za-z0-9_]+
+ 3.2) a GUID. The valid format is 
----, where x is [A-Fa-f0-9]
+ 3.3) a decimal value. The valid format is [0-9]+
+ 3.4) a heximal value. The valid format is 0x[A-Fa-f0-9]+
+  4) '#' or ';' can be used as comment at anywhere.
+  5) TAB(0x20) or SPACE(0x9) can be used as separator.
+  6) LF(\n, 0xA) or CR(\r, 0xD) can be used as line break.
+
+Copyright (c) 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.
+
+**/
+
+
+#ifndef __INI_PARSING_LIB_H__
+#define __INI_PARSING_LIB_H__
+
+/**
+  Open an INI config file and return a context.
+
+  @param[in] DataBuffer  Config raw file buffer.
+  @param[in] BufferSize  Size of raw buffer.
+
+  @return   Config data buffer is opened and context is returned.
+  @retval NULL  No enough memory is allocated.
+  @retval NULL  Config data buffer is invalid.
+**/
+VOID *
+EFIAPI
+OpenIniFile (
+  IN  UINT8 *DataBuffer,
+  IN  UINTN BufferSize
+  );
+
+/**
+  Get section entry string value.
+
+  @param[in]  Context INI Config file context.
+  @param[in]  SectionName Section name.
+  @param[in]  EntryName   Section entry name.
+  @param[out] EntryValue  Point to the got entry string value.
+
+  @retval EFI_SUCCESSSection entry string value is got.
+  @retval EFI_NOT_FOUND  Section is not found.
+**/
+EFI_STATUS
+EFIAPI
+GetStringFromDataFile (
+  IN  VOID  *Context,
+  IN  CHAR8 *SectionName,
+  IN  CHAR8 *EntryName,
+  OUT CHAR8 **EntryValue
+  );
+
+/**
+  Get section entry GUID value.
+
+  @param[in]  Context INI Config file context.
+  @param[in]  SectionName Section name.
+  @param[in]  EntryName   Section entry name.
+  @param[out] GuidPoint to the got GUID value.
+
+  @retval EFI_SUCCESSSection entry GUID value is got.
+  @retval EFI_NOT_FOUND  Section is not found.
+**/
+EFI_STATUS
+EFIAPI
+GetGuidFromDataFile (
+  IN  VOID  *Context,
+  IN  CHAR8 *SectionName,
+  IN  CHAR8 *EntryName,
+  OUT EFI_GUID  *Guid
+  );
+
+/**
+  Get section entry decimal UINTN value.
+
+  @param[in]  Context INI Config file context.
+  @param[in]  SectionName Section name.
+  @param[in]  EntryName   Section entry name.
+  @param[out] DataPoint to the got decimal UINTN value.
+
+  @retval EFI_SUCCESSSection entry decimal UINTN value is got.
+  @retval EFI_NOT_FOUND  Section is not found.
+**/
+EFI_STATUS
+EFIAPI
+GetDecimalUintnFromDataFile (
+  IN  VOID  *Context,
+  IN  CHAR8 *SectionName,
+  IN  CHAR8 *EntryName,
+  OUT UINTN *Data
+  );
+
+/**
+  Get section entry heximal UINTN value.
+
+  @param[in]  Context INI Config file context.
+  @param[in]  SectionName Section name.
+  @param[in]  EntryName   Section entry name.
+  @param[out] DataPoint to the got heximal UINTN value.
+
+  @retval 

[edk2] [PATCH V8 03/12] SignedCapsulePkg/Include: Add EdkiiSystemCapsuleLib definition.

2016-11-02 Thread Jiewen Yao
This library is used to abstract the action for EDKII system FMP capsule,
such as extracting a component from capsule, or authenticate the capsule.

Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: Liming Gao 
---
 SignedCapsulePkg/Include/Library/EdkiiSystemCapsuleLib.h | 154 

 1 file changed, 154 insertions(+)

diff --git a/SignedCapsulePkg/Include/Library/EdkiiSystemCapsuleLib.h 
b/SignedCapsulePkg/Include/Library/EdkiiSystemCapsuleLib.h
new file mode 100644
index 000..11958e2
--- /dev/null
+++ b/SignedCapsulePkg/Include/Library/EdkiiSystemCapsuleLib.h
@@ -0,0 +1,154 @@
+/** @file
+  EDKII System Capsule library.
+
+Copyright (c) 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.
+
+**/
+
+
+#ifndef __EDKII_SYSTEM_CAPSULE_LIB_H__
+#define __EDKII_SYSTEM_CAPSULE_LIB_H__
+
+#include 
+
+/**
+  Extract ImageFmpInfo from system firmware.
+
+  @param[in]  SystemFirmwareImage The System Firmware image.
+  @param[in]  SystemFirmwareImageSize The size of the System Firmware image in 
bytes.
+  @param[out] ImageFmpInfoThe ImageFmpInfo.
+  @param[out] ImageFmpInfoSizeThe size of the ImageFmpInfo in bytes.
+
+  @retval TRUE  The ImageFmpInfo is extracted.
+  @retval FALSE The ImageFmpInfo is not extracted.
+**/
+BOOLEAN
+EFIAPI
+ExtractSystemFirmwareImageFmpInfo (
+  IN VOID  *SystemFirmwareImage,
+  IN UINTN SystemFirmwareImageSize,
+  OUT EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR   **ImageFmpInfo,
+  OUT UINTN*ImageFmpInfoSize
+  );
+
+/**
+  Extract the driver FV from an authenticated image.
+
+  @param[in]  AuthenticatedImage  The authenticated capsule image.
+  @param[in]  AuthenticatedImageSize  The size of the authenticated capsule 
image in bytes.
+  @param[out] DriverFvImage   The driver FV image.
+  @param[out] DriverFvImageSize   The size of the driver FV image in bytes.
+
+  @retval TRUE  The driver Fv is extracted.
+  @retval FALSE The driver Fv is not extracted.
+**/
+BOOLEAN
+EFIAPI
+ExtractDriverFvImage (
+  IN VOID *AuthenticatedImage,
+  IN UINTNAuthenticatedImageSize,
+  OUT VOID**DriverFvImage,
+  OUT UINTN   *DriverFvImageSize
+  );
+
+/**
+  Extract the config image from an authenticated image.
+
+  @param[in]  AuthenticatedImage  The authenticated capsule image.
+  @param[in]  AuthenticatedImageSize  The size of the authenticated capsule 
image in bytes.
+  @param[out] ConfigImage The config image.
+  @param[out] ConfigImageSize The size of the config image in bytes.
+
+  @retval TRUE  The config image is extracted.
+  @retval FALSE The config image is not extracted.
+**/
+BOOLEAN
+EFIAPI
+ExtractConfigImage (
+  IN VOID *AuthenticatedImage,
+  IN UINTNAuthenticatedImageSize,
+  OUT VOID**ConfigImage,
+  OUT UINTN   *ConfigImageSize
+  );
+
+/**
+  Extract the System Firmware image from an authenticated image.
+
+  @param[in]  AuthenticatedImage  The authenticated capsule image.
+  @param[in]  AuthenticatedImageSize  The size of the authenticated capsule 
image in bytes.
+  @param[out] SystemFirmwareImage The System Firmware image.
+  @param[out] SystemFirmwareImageSize The size of the System Firmware image in 
bytes.
+
+  @retval TRUE  The System Firmware image is extracted.
+  @retval FALSE The System Firmware image is not extracted.
+**/
+BOOLEAN
+EFIAPI
+ExtractSystemFirmwareImage (
+  IN VOID *AuthenticatedImage,
+  IN UINTNAuthenticatedImageSize,
+  OUT VOID**SystemFirmwareImage,
+  OUT UINTN   *SystemFirmwareImageSize
+  );
+
+/**
+  Extract the authenticated image from an FMP capsule image.
+
+  @param[in]  Image   The FMP capsule image, including 
EFI_FIRMWARE_IMAGE_AUTHENTICATION.
+  @param[in]  ImageSize   The size of FMP capsule image in bytes.
+  @param[out] LastAttemptStatus   The last attempt status, which will be 
recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.
+  @param[out] 

[edk2] [PATCH 01/12] SignedCapsulePkg: Add license file.

2016-11-02 Thread Jiewen Yao
Add license file for SignedCapsulePkg.
This package contains sample drivers to do system firmware update
and recovery.
It also includes a capsule library to support system FMP and device FMP.

Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
---
 SignedCapsulePkg/Contributions.txt | 218 
 SignedCapsulePkg/License.txt   |  25 +++
 2 files changed, 243 insertions(+)

diff --git a/SignedCapsulePkg/Contributions.txt 
b/SignedCapsulePkg/Contributions.txt
new file mode 100644
index 000..f87cbd7
--- /dev/null
+++ b/SignedCapsulePkg/Contributions.txt
@@ -0,0 +1,218 @@
+
+==
+= Code Contributions =
+==
+
+To make a contribution to a TianoCore project, follow these steps.
+1. Create a change description in the format specified below to
+   use in the source control commit log.
+2. Your commit message must include your "Signed-off-by" signature,
+   and "Contributed-under" message.
+3. Your "Contributed-under" message explicitly states that the
+   contribution is made under the terms of the specified
+   contribution agreement.  Your "Contributed-under" message
+   must include the name of contribution agreement and version.
+   For example: Contributed-under: TianoCore Contribution Agreement 1.0
+   The "TianoCore Contribution Agreement" is included below in
+   this document.
+4. Submit your code to the TianoCore project using the process
+   that the project documents on its web page.  If the process is
+   not documented, then submit the code on development email list
+   for the project.
+5. It is preferred that contributions are submitted using the same
+   copyright license as the base project. When that is not possible,
+   then contributions using the following licenses can be accepted:
+   * BSD (2-clause): http://opensource.org/licenses/BSD-2-Clause
+   * BSD (3-clause): http://opensource.org/licenses/BSD-3-Clause
+   * MIT: http://opensource.org/licenses/MIT
+   * Python-2.0: http://opensource.org/licenses/Python-2.0
+   * Zlib: http://opensource.org/licenses/Zlib
+
+   Contributions of code put into the public domain can also be
+   accepted.
+
+   Contributions using other licenses might be accepted, but further
+   review will be required.
+
+=
+= Change Description / Commit Message / Patch Email =
+=
+
+Your change description should use the standard format for a
+commit message, and must include your "Signed-off-by" signature
+and the "Contributed-under" message.
+
+== Sample Change Description / Commit Message =
+
+=== Start of sample patch email message ===
+
+From: Contributor Name 
+Subject: [PATCH] CodeModule: Brief-single-line-summary
+
+Full-commit-message
+
+Contributed-under: TianoCore Contribution Agreement 1.0
+Signed-off-by: Contributor Name 
+---
+
+An extra message for the patch email which will not be considered part
+of the commit message can be added here.
+
+Patch content inline or attached
+
+=== End of sample patch email message ===
+
+=== Notes for sample patch email ===
+
+* The first line of commit message is taken from the email's subject
+  line following [PATCH]. The remaining portion of the commit message
+  is the email's content until the '---' line.
+* git format-patch is one way to create this format
+
+=== Definitions for sample patch email ===
+
+* "CodeModule" is a short idenfier for the affected code.  For
+  example MdePkg, or MdeModulePkg UsbBusDxe.
+* "Brief-single-line-summary" is a short summary of the change.
+* The entire first line should be less than ~70 characters.
+* "Full-commit-message" a verbose multiple line comment describing
+  the change.  Each line should be less than ~70 characters.
+* "Contributed-under" explicitely states that the contribution is
+  made under the terms of the contribtion agreement.  This
+  agreement is included below in this document.
+* "Signed-off-by" is the contributor's signature identifying them
+  by their real/legal name and their email address.
+
+
+= TianoCore Contribution Agreement 1.0 =
+
+
+INTEL CORPORATION ("INTEL") MAKES AVAILABLE SOFTWARE, DOCUMENTATION,
+INFORMATION AND/OR OTHER MATERIALS FOR USE IN THE TIANOCORE OPEN SOURCE
+PROJECT (COLLECTIVELY "CONTENT"). USE OF THE CONTENT IS GOVERNED BY THE
+TERMS AND CONDITIONS OF THIS AGREEMENT BETWEEN YOU AND INTEL AND/OR THE
+TERMS AND CONDITIONS OF LICENSE AGREEMENTS OR NOTICES INDICATED OR
+REFERENCED BELOW. BY USING THE CONTENT, YOU AGREE THAT YOUR USE OF THE
+CONTENT IS GOVERNED BY THIS AGREEMENT AND/OR THE TERMS 

[edk2] [PATCH V8 00/12] Add EDKII signed capsule support.

2016-11-02 Thread Jiewen Yao
==Below is V8 description==
1) MdeModulePkg/dec: 
set gEfiMdeModulePkgTokenSpaceGuid.PcdSystemFmpCapsuleImageTypeIdGuid
to 0 as default.
2) SignedCapsulePkg/dec:
set gEfiSignedCapsulePkgTokenSpaceGuid.PcdEdkiiSystemFirmwareFileGuid
to 0 as default.
3) QuarkPlatformPkg: Set CAPSULE_ENABLE/RECOVERY_ENABLE to FALSE as default.
4) All: rename EFI_D_* => DEBUG_*

==Below is V7 description==
1) MdeModulePkg/MdeModulePkg.dec: refine status code comment.
2) UefiCpuPkg: Move Microcode capsule related conent to Feature/capsule dir.
3) Vlv2TbltDevicePkg: Add MICOCODE_CAPSULE_ENABLE macro.

Only series 1, 3, 5 are sent for update review.
The other series are unchanged.

==Below is V6 description==
1) MdeModulePkg/CapsuleApp: Fix -D issue.
2) MdeModulePkg/DEC: Cleanup Capsule related StatusCode.
3) UefiCpuPkg: Remove MicrocodeUpdateApp
4) UefiCpuPkg: Add Microcode FMP build sample

Only series 1 and 3 are sent for update review.
The other series are unchanged.

==Below is V5 description==
1) MdeModulePkg/CapsuleApp: Remove [NR]. Add more description.
2) MdeModulePkg/DEC: Update StatusCode to OEM region.
3) MdeModulePkg/DxeCapsuleLib: Use NULL ProcessCapsules()
for runtime lib, because it is not needed for runtime.
4) MdeModulePkg/FmpAuthenticationLib: Add more description.
5) SignedCapsulePkg/DEC: Add data structure description
for PcdEdkiiSystemFirmwareImageDescriptor.
6) SignedCapsulePkg/DEC: Add Pkcs7 and Rsa2048 Key file PCD.
These 2 PCD are moved from platform pkg to SignedCapsulePkg.
7) QuarkPlatformPkg/FDF: Refine order of capsule section.
8) Fix typo and coding style issue.

Below items are defered to other patch series, because
the tool and library are not ready yet.

A) MdeModulePkg/DxeCapsuleLib: separate BMP parsing logic
to another library.
That is very good suggestion, and we agree it is a right direction.
I discussed with the owner of image decoder.
We prefer adding a generic library class to convert
the image data to GOP BLT buffer. It supports *any* image format,
not only BMP. The owner of image decoder will drive the new design.
I filed https://bugzilla.tianocore.org/show_bug.cgi?id=175 to track that.
I suggest we just keep the current solution as a temp solution and
migrate to the new one once it is ready later.

B) PlatformPkg/Bds: Move test key check logic to generic part.
This is very good suggestion and we are discussing with Tool
team to add such detection at build time and set a PCD to indicate that.
The generic code can use this PCD to know if there is a test key.
I filed https://bugzilla.tianocore.org/show_bug.cgi?id=185 to track that.
Adding such check in the generic code is very complicated, so current
temporary solution is to let platform BDS do such check.
The platform BDS will be cleaned up, once the tool is ready.

==Below is V4 description==
1) SecurityPkg - Refine AuthenticateFmpImage() API to let caller
input PublicKeyData and PublicKeyDataLength, instead of PCD.
The benefit is that then this API can be used for a platform
which stores PublicKeyData in anywhere other than PCD.
2) SecurityPkg - Use OFFSET_OF(WIN_CERTIFICATE_UEFI_GUID, CertData)
for better understanding the code.
3) MdeModulePkg - Update CapsuleApp to let it consume
ShellParameters protocol to get Argc and Argv.
4) UefiCpuPkg - Update MicrocodeCapsuleApp to let it consume
ShellParameters protocol to get Argc and Argv.
5) QuarkPlatformPkg - Merge QuarkCapsule.fdf to Quark.fdf.

==Below is V3 description==
1) We move all EDKII related capsule definition to SignedCapsulePkg.
MdeModulePkg only contains FmAuthenticationLib and CapsuleApp,
because they are generic and follow UEFI specification on FMP/ESRT
and Microsoft platform firmware update document.
Any capsule implementation can use them.

Here is full library classes:
MdeModulePkg:
FmpAuthenticationLib.h: new lib - follow UEFI spec. (*)
Verify FMP signature of FMP Capsule
CapsuleLib.h: new API ¨C ProcessCapsules()
It processes all the capsules. Remove duplicated code in 
platform BDS.
UefiCpuPkg:
MicrocodeFlashAccessLib.h: Update Microcode region.
SignedCapsulePkg:
EdkiiSystemCapsuleLib.h ¨C Library for EDKII system FMP.
IniParsingLib.h ¨C Library for INI file parsing.
PlatformFlashAccessLib.h ¨C Library for write flash.

2) We will submit 5 series.
Series 1: Generic Update (MdeModulePkg/SecurityPkg)
DxeCapsuleLib
FmAuthenticationLib (*)
CapsuleApp (*)
Series 2: EDKII Capsule (SignedCapsulePkg)
IniParsingLib
EdkiiSystemCapsuleLib
PlatformFlashAccessLib
SystemFirmwareUpdate driver
RecoveryModuleLoadPei driver
Series 3: Microcode Update (UefiCpuPkg)
MicrocodeFlashAccessLib
MicrocodeUpdate driver.
Series 4: Quark update
Series 5: Vlv2 update

3) DxeCapsuleLib: Move code that performs authentication and parsing of
the capsule format into the implementation of the FMP Protocol.
We move the dispatch FV code from 

[edk2] [PATCH V8 13/15] SecurityPkg/FmpAuthenticationLibPkcs7: Add PKCS7 instance for FMP.

2016-11-02 Thread Jiewen Yao
It provides PKCS7 based FMP authentication.

Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: Chao Zhang 
---
 SecurityPkg/Library/FmpAuthenticationLibPkcs7/FmpAuthenticationLibPkcs7.c   | 
222 
 SecurityPkg/Library/FmpAuthenticationLibPkcs7/FmpAuthenticationLibPkcs7.inf |  
49 +
 SecurityPkg/Library/FmpAuthenticationLibPkcs7/FmpAuthenticationLibPkcs7.uni |  
26 +++
 3 files changed, 297 insertions(+)

diff --git 
a/SecurityPkg/Library/FmpAuthenticationLibPkcs7/FmpAuthenticationLibPkcs7.c 
b/SecurityPkg/Library/FmpAuthenticationLibPkcs7/FmpAuthenticationLibPkcs7.c
new file mode 100644
index 000..d79f270
--- /dev/null
+++ b/SecurityPkg/Library/FmpAuthenticationLibPkcs7/FmpAuthenticationLibPkcs7.c
@@ -0,0 +1,222 @@
+/** @file
+  FMP Authentication PKCS7 handler.
+  Provide generic FMP authentication functions for DXE/PEI post memory phase.
+
+  Caution: This module requires additional review when modified.
+  This module will have external input - capsule image.
+  This external input must be validated carefully to avoid security issue like
+  buffer overflow, integer overflow.
+
+  FmpAuthenticatedHandlerPkcs7(), AuthenticateFmpImage() will receive
+  untrusted input and do basic validation.
+
+  Copyright (c) 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 
+
+/**
+  The handler is used to do the authentication for FMP capsule based upon
+  EFI_FIRMWARE_IMAGE_AUTHENTICATION.
+
+  Caution: This function may receive untrusted input.
+
+  This function assumes the caller AuthenticateFmpImage()
+  already did basic validation for EFI_FIRMWARE_IMAGE_AUTHENTICATION.
+
+  @param[in]  Image   Points to an FMP authentication image, 
started from EFI_FIRMWARE_IMAGE_AUTHENTICATION.
+  @param[in]  ImageSize   Size of the authentication image in 
bytes.
+  @param[in]  PublicKeyData   The public key data used to validate the 
signature.
+  @param[in]  PublicKeyDataLength The length of the public key data.
+
+  @retval RETURN_SUCCESSAuthentication pass.
+The LastAttemptStatus should be 
LAST_ATTEMPT_STATUS_SUCCESS.
+  @retval RETURN_SECURITY_VIOLATION Authentication fail.
+The LastAttemptStatus should be 
LAST_ATTEMPT_STATUS_ERROR_AUTH_ERROR.
+  @retval RETURN_INVALID_PARAMETER  The image is in an invalid format.
+The LastAttemptStatus should be 
LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT.
+  @retval RETURN_OUT_OF_RESOURCES   No Authentication handler associated with 
CertType.
+The LastAttemptStatus should be 
LAST_ATTEMPT_STATUS_ERROR_INSUFFICIENT_RESOURCES.
+**/
+RETURN_STATUS
+FmpAuthenticatedHandlerPkcs7 (
+  IN EFI_FIRMWARE_IMAGE_AUTHENTICATION  *Image,
+  IN UINTN  ImageSize,
+  IN CONST UINT8*PublicKeyData,
+  IN UINTN  PublicKeyDataLength
+  )
+{
+  RETURN_STATUS Status;
+  BOOLEAN   CryptoStatus;
+  VOID  *P7Data;
+  UINTN P7Length;
+  VOID  *TempBuffer;
+
+  DEBUG((DEBUG_INFO, "FmpAuthenticatedHandlerPkcs7 - Image: 0x%08x - 
0x%08x\n", (UINTN)Image, (UINTN)ImageSize));
+
+  P7Length = Image->AuthInfo.Hdr.dwLength - 
(OFFSET_OF(WIN_CERTIFICATE_UEFI_GUID, CertData));
+  P7Data = Image->AuthInfo.CertData;
+
+  // It is a signature across the variable data and the Monotonic Count value.
+  TempBuffer = AllocatePool(ImageSize - Image->AuthInfo.Hdr.dwLength);
+  if (TempBuffer == NULL) {
+DEBUG((DEBUG_ERROR, "FmpAuthenticatedHandlerPkcs7: TempBuffer == NULL\n"));
+Status = RETURN_OUT_OF_RESOURCES;
+goto Done;
+  }
+
+  CopyMem(
+TempBuffer,
+(UINT8 *)Image + sizeof(Image->MonotonicCount) + 
Image->AuthInfo.Hdr.dwLength,
+ImageSize - sizeof(Image->MonotonicCount) - Image->AuthInfo.Hdr.dwLength
+);
+  CopyMem(
+(UINT8 *)TempBuffer + ImageSize - 

[edk2] [PATCH V8 15/15] SecurityPkg/SecurityPkg.dsc: Add FmpAuthenticationLib*.

2016-11-02 Thread Jiewen Yao
Add FmpAuthenticationLib* to check build.

Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: Chao Zhang 
---
 SecurityPkg/SecurityPkg.dsc | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc
index 2ebd0a4..e5cce21 100644
--- a/SecurityPkg/SecurityPkg.dsc
+++ b/SecurityPkg/SecurityPkg.dsc
@@ -212,6 +212,9 @@
   
SecurityPkg/Library/DxeRsa2048Sha256GuidedSectionExtractLib/DxeRsa2048Sha256GuidedSectionExtractLib.inf
   
SecurityPkg/Library/PeiRsa2048Sha256GuidedSectionExtractLib/PeiRsa2048Sha256GuidedSectionExtractLib.inf
 
+  SecurityPkg/Library/FmpAuthenticationLibPkcs7/FmpAuthenticationLibPkcs7.inf
+  
SecurityPkg/Library/FmpAuthenticationLibRsa2048Sha256/FmpAuthenticationLibRsa2048Sha256.inf
+
   SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf
 
 [Components.IA32, Components.X64, Components.IPF]
-- 
2.7.4.windows.1

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


[edk2] [PATCH V8 03/15] MdeModulePkg/MdeModulePkg.dec: Add capsule related definition.

2016-11-02 Thread Jiewen Yao
1) Add capsule related library.
   FmpAuthenticationLib
2) Add capsule related status code PCD.
   PcdStatusCodeSubClassCapsule
   PcdCapsuleStatusCodeProcessCapsulesBegin
   PcdCapsuleStatusCodeProcessCapsulesEnd
   PcdCapsuleStatusCodeUpdatingFirmware
   PcdCapsuleStatusCodeUpdateFirmwareSuccess
   PcdCapsuleStatusCodeUpdateFirmwareFailed
   PcdCapsuleStatusCodeResettingSystem
3) Add capsule status variable PCD - CapsuleMax value.
   PcdCapsuleMax
4) Add system FMP indicator PCD - used by ESRT.
   PcdSystemFmpCapsuleImageTypeIdGuid
5) Add PcdTestKeyUsed PCD.
This PCD can be set by platform to indicate if there is any
test key used in current BIOS, such as recovery key,
or capsule update key.
Then the generic UI may consume this PCD to show warning information.
Other platform driver may also consume this PCD to know such info,
and report it via platform specific way.

Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: Liming Gao 
---
 MdeModulePkg/MdeModulePkg.dec | 73 
 1 file changed, 73 insertions(+)

diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index 74b8700..9fe9e26 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -157,6 +157,10 @@
   ##
   FrameBufferBltLib|Include/Library/FrameBufferBltLib.h
 
+  ## @libraryclass  Provides services to authenticate a UEFI defined FMP 
Capsule.
+  #
+  FmpAuthenticationLib|Include/Library/FmpAuthenticationLib.h
+
 [Guids]
   ## MdeModule package token space guid
   # Include/Guid/MdeModulePkgTokenSpace.h
@@ -1142,6 +1146,66 @@
   # @Prompt MAX repair count
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxRepairCount|0x00|UINT32|0x00010076
 
+  ## Status Code for Capsule subclass definitions.
+  #  EFI_OEM_SPECIFIC_SUBCLASS_CAPSULE  = 0x0081
+  #  NOTE: The default value of this PCD may collide with other OEM specific 
status codes.
+  #Override the value of this PCD in the platform DSC file as needed.
+  # @Prompt Status Code for Capsule subclass definitions
+  # @ValidList  0x8003 | 0x0081
+  
gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeSubClassCapsule|0x0081|UINT32|0x0100
+
+  ## Status Code for Capsule Process Begin.
+  #  EFI_CAPSULE_PROCESS_CAPSULES_BEGIN  = (EFI_OEM_SPECIFIC | 0x0001) = 
0x8001
+  #  NOTE: The default value of this PCD may collide with other OEM specific 
status codes.
+  #Override the value of this PCD in the platform DSC file as needed.
+  # @Prompt Status Code for Capsule Process Begin
+  # @ValidList  0x8003 | 0x8001
+  
gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleStatusCodeProcessCapsulesBegin|0x8001|UINT32|0x0101
+
+  ## Status Code for Capsule Process End.
+  #  EFI_CAPSULE_PROCESS_CAPSULES_END= (EFI_OEM_SPECIFIC | 0x0002) = 
0x8002
+  #  NOTE: The default value of this PCD may collide with other OEM specific 
status codes.
+  #Override the value of this PCD in the platform DSC file as needed.
+  # @Prompt Status Code for Capsule Process End
+  # @ValidList  0x8003 | 0x8002
+  
gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleStatusCodeProcessCapsulesEnd|0x8002|UINT32|0x0102
+
+  ## Status Code for Capsule Process Updating Firmware.
+  #  EFI_CAPSULE_UPDATING_FIRMWARE   = (EFI_OEM_SPECIFIC | 0x0003) = 
0x8003
+  #  NOTE: The default value of this PCD may collide with other OEM specific 
status codes.
+  #Override the value of this PCD in the platform DSC file as needed.
+  # @Prompt Status Code for Capsule Process Updating Firmware
+  # @ValidList  0x8003 | 0x8003
+  
gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleStatusCodeUpdatingFirmware|0x8003|UINT32|0x0103
+
+  ## Status Code for Capsule Process Update Firmware Success.
+  #  EFI_CAPSULE_UPDATE_FIRMWARE_SUCCESS = (EFI_OEM_SPECIFIC | 0x0004) = 
0x8004
+  #  NOTE: The default value of this PCD may collide with other OEM specific 
status codes.
+  #Override the value of this PCD in the platform DSC file as needed.
+  # @Prompt Status Code for Capsule Process Update Firmware Success
+  # @ValidList  0x8003 | 0x8004
+  
gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleStatusCodeUpdateFirmwareSuccess|0x8004|UINT32|0x0104
+
+  ## Status Code for Capsule Process Update Firmware Failed.
+  #  EFI_CAPSULE_UPDATE_FIRMWARE_FAILED  = (EFI_OEM_SPECIFIC | 0x0005) = 
0x8005
+  #  NOTE: The default value of this PCD may collide with other OEM specific 
status codes.
+  #Override the value of this PCD in the platform DSC file as needed.
+  # @Prompt Status Code for Capsule Process Update Firmware Failed
+  # @ValidList  0x8003 | 0x8005
+  

[edk2] [PATCH V8 04/15] MdeModulePkg/FmpAuthenticationLibNull: Add NULL instance FMP.

2016-11-02 Thread Jiewen Yao
Add NULL instance to pass build.

Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: Liming Gao 
---
 MdeModulePkg/Library/FmpAuthenticationLibNull/FmpAuthenticationLibNull.c   | 
66 
 MdeModulePkg/Library/FmpAuthenticationLibNull/FmpAuthenticationLibNull.inf | 
40 
 MdeModulePkg/Library/FmpAuthenticationLibNull/FmpAuthenticationLibNull.uni | 
22 +++
 3 files changed, 128 insertions(+)

diff --git 
a/MdeModulePkg/Library/FmpAuthenticationLibNull/FmpAuthenticationLibNull.c 
b/MdeModulePkg/Library/FmpAuthenticationLibNull/FmpAuthenticationLibNull.c
new file mode 100644
index 000..02ff504
--- /dev/null
+++ b/MdeModulePkg/Library/FmpAuthenticationLibNull/FmpAuthenticationLibNull.c
@@ -0,0 +1,66 @@
+/** @file
+  NULL FMP authentication library.
+
+  Copyright (c) 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 
+
+/**
+  The function is used to do the authentication for FMP capsule based upon
+  EFI_FIRMWARE_IMAGE_AUTHENTICATION.
+
+  The FMP capsule image should start with EFI_FIRMWARE_IMAGE_AUTHENTICATION,
+  followed by the payload.
+
+  If the return status is RETURN_SUCCESS, the caller may continue the rest
+  FMP update process.
+  If the return status is NOT RETURN_SUCCESS, the caller should stop the FMP
+  update process and convert the return status to LastAttemptStatus
+  to indicate that FMP update fails.
+  The LastAttemptStatus can be got from ESRT table or via
+  EFI_FIRMWARE_MANAGEMENT_PROTOCOL.GetImageInfo().
+
+  Caution: This function may receive untrusted input.
+
+  @param[in]  Image   Points to an FMP authentication image, 
started from EFI_FIRMWARE_IMAGE_AUTHENTICATION.
+  @param[in]  ImageSize   Size of the authentication image in 
bytes.
+  @param[in]  PublicKeyData   The public key data used to validate the 
signature.
+  @param[in]  PublicKeyDataLength The length of the public key data.
+
+  @retval RETURN_SUCCESSAuthentication pass.
+The LastAttemptStatus should be 
LAST_ATTEMPT_STATUS_SUCCESS.
+  @retval RETURN_SECURITY_VIOLATION Authentication fail.
+The LastAttemptStatus should be 
LAST_ATTEMPT_STATUS_ERROR_AUTH_ERROR.
+  @retval RETURN_INVALID_PARAMETER  The image is in an invalid format.
+The LastAttemptStatus should be 
LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT.
+  @retval RETURN_UNSUPPORTEDNo Authentication handler associated with 
CertType.
+The LastAttemptStatus should be 
LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT.
+  @retval RETURN_UNSUPPORTEDImage or ImageSize is invalid.
+The LastAttemptStatus should be 
LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT.
+  @retval RETURN_OUT_OF_RESOURCES   No Authentication handler associated with 
CertType.
+The LastAttemptStatus should be 
LAST_ATTEMPT_STATUS_ERROR_INSUFFICIENT_RESOURCES.
+**/
+RETURN_STATUS
+EFIAPI
+AuthenticateFmpImage (
+  IN EFI_FIRMWARE_IMAGE_AUTHENTICATION  *Image,
+  IN UINTN  ImageSize,
+  IN CONST UINT8*PublicKeyData,
+  IN UINTN  PublicKeyDataLength
+  )
+{
+  ASSERT(FALSE);
+  return RETURN_UNSUPPORTED;
+}
diff --git 
a/MdeModulePkg/Library/FmpAuthenticationLibNull/FmpAuthenticationLibNull.inf 
b/MdeModulePkg/Library/FmpAuthenticationLibNull/FmpAuthenticationLibNull.inf
new file mode 100644
index 000..f9b87ca
--- /dev/null
+++ b/MdeModulePkg/Library/FmpAuthenticationLibNull/FmpAuthenticationLibNull.inf
@@ -0,0 +1,40 @@
+## @file
+# FmpAuthentication Library
+#
+# NULL Instance of FmpAuthentication Library.
+#
+# Copyright (c) 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 

[edk2] [PATCH V8 12/15] SecurityPkg/SecurityPkg.dec: Add PcdPkcs7CertBuffer PCD.

2016-11-02 Thread Jiewen Yao
This PCD is similar to PcdRsa2048Sha256PublicKeyBuffer.
It provides trusted cert for PKCS7 verification.
It can be used for Recovery and Capsule Update images.

We added warning message for both PcdPkcs7CertBuffer and
PcdRsa2048Sha256PublicKeyBuffer. The default value is only for
test purpose.

Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: Chao Zhang 
---
 SecurityPkg/SecurityPkg.dec | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/SecurityPkg/SecurityPkg.dec b/SecurityPkg/SecurityPkg.dec
index f4f4d19..dab332a 100644
--- a/SecurityPkg/SecurityPkg.dec
+++ b/SecurityPkg/SecurityPkg.dec
@@ -400,11 +400,17 @@
   gEfiSecurityPkgTokenSpaceGuid.PcdTcg2NumberOfPCRBanks|0x0|UINT32|0x00010015
   
   ## Provides one or more SHA 256 Hashes of the RSA 2048 public keys used to 
verify Recovery and Capsule Update images
-  #
+  #  WARNING: The default value is treated as test key. Please do not use 
default value in the production.
   # @Prompt One or more SHA 256 Hashes of RSA 2048 bit public keys used to 
verify Recovery and Capsule Update images
   #
   gEfiSecurityPkgTokenSpaceGuid.PcdRsa2048Sha256PublicKeyBuffer|{0x91, 0x29, 
0xc4, 0xbd, 0xea, 0x6d, 0xda, 0xb3, 0xaa, 0x6f, 0x50, 0x16, 0xfc, 0xdb, 0x4b, 
0x7e, 0x3c, 0xd6, 0xdc, 0xa4, 0x7a, 0x0e, 0xdd, 0xe6, 0x15, 0x8c, 0x73, 0x96, 
0xa2, 0xd4, 0xa6, 0x4d}|VOID*|0x00010013
 
+  ## Provides one PKCS7 cert used to verify Recovery and Capsule Update images
+  #  WARNING: The default value is treated as test key. Please do not use 
default value in the production.
+  # @Prompt One PKCS7 cert used to verify Recovery and Capsule Update images
+  #
+  gEfiSecurityPkgTokenSpaceGuid.PcdPkcs7CertBuffer|{0x30, 0x82, 0x02, 0xf0, 
0x30, 0x82, 0x01, 0xdc, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x10, 0x34, 0x30, 
0x27, 0x7f, 0x05, 0x3d, 0x95, 0x85, 0x43, 0xa0, 0xa4, 0xf5, 0x0c, 0x9a, 0xe7, 
0xca, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1d, 0x05, 0x00, 0x30, 
0x13, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x08, 0x54, 
0x65, 0x73, 0x74, 0x52, 0x6f, 0x6f, 0x74, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x36, 
0x30, 0x38, 0x30, 0x34, 0x31, 0x35, 0x30, 0x31, 0x34, 0x38, 0x5a, 0x17, 0x0d, 
0x33, 0x39, 0x31, 0x32, 0x33, 0x31, 0x32, 0x33, 0x35, 0x39, 0x35, 0x39, 0x5a, 
0x30, 0x13, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x08, 
0x54, 0x65, 0x73, 0x74, 0x52, 0x6f, 0x6f, 0x74, 0x30, 0x82, 0x01, 0x22, 0x30, 
0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 
0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 
0x01, 0x00, 0x94, 0xe6, 0x33, 0x4f, 0x56, 0xc3, 0x07, 0xa0, 0xd
 0, 0x99, 0x57, 0xc3, 0xe1, 0x56, 0x42, 0x01, 0x70, 0x59, 0x1c, 0x2f, 0x4a, 
0x66, 0x8f, 0x34, 0x9e, 0x93, 0xbd, 0xb6, 0xec, 0x92, 0xa4, 0x90, 0x51, 0x5d, 
0xc6, 0x8f, 0xb5, 0xc3, 0x86, 0x15, 0xdf, 0x60, 0x80, 0xbe, 0xb8, 0x78, 0x59, 
0x5b, 0x9b, 0xfd, 0x27, 0x92, 0x69, 0xcc, 0xca, 0x8e, 0x3e, 0x9e, 0x81, 0x47, 
0x5b, 0x84, 0xef, 0x5c, 0x9b, 0xb3, 0x4a, 0x43, 0x5b, 0x8d, 0x0b, 0x31, 0x04, 
0x00, 0xb6, 0x8a, 0xc0, 0xa9, 0xf5, 0x21, 0xd0, 0x3f, 0xcd, 0xb0, 0x67, 0x7d, 
0x50, 0x33, 0x2e, 0xfb, 0x1b, 0x2c, 0x16, 0x2e, 0xee, 0x56, 0x01, 0x87, 0xf6, 
0xc8, 0xd4, 0x53, 0x07, 0x67, 0x99, 0x0b, 0x46, 0xbf, 0x1d, 0x90, 0xc6, 0xdb, 
0x7f, 0x6d, 0x62, 0x0c, 0x4a, 0xac, 0xa8, 0xa2, 0x3c, 0x79, 0x0f, 0xad, 0x8f, 
0xfe, 0xc1, 0xe8, 0xe5, 0x27, 0x3d, 0xf9, 0xa6, 0x9a, 0x1d, 0xec, 0x9a, 0x5f, 
0x62, 0x51, 0x2e, 0x98, 0x1d, 0x29, 0xba, 0x6b, 0x8a, 0xfb, 0x43, 0x0e, 0x68, 
0x29, 0xf5, 0xbe, 0x67, 0x48, 0x44, 0x28, 0x45, 0xfe, 0x1d, 0x3b, 0x50, 0x72, 
0x6a, 0xc0, 0xbb, 0x0c, 0x9f, 0x02, 0x61, 0xad, 0x63, 0xa7, 0x87
 , 0xf6, 0x32, 0x9f, 0x3e, 0x16, 0x5c, 0xee, 0xcc, 0x05, 0xbd, 0x17, 0xe8, 
0x46, 0x52, 0xaf, 0x50, 0x8a, 0xa6, 0x7e, 0x16, 0x69, 0x83, 0x69, 0x5b, 0x6e, 
0x4d, 0xc7, 0xcf, 0x80, 0xb8, 0xcd, 0xf6, 0x66, 0x3f, 0xbe, 0x6c, 0xa0, 0xe8, 
0x9c, 0x26, 0x60, 0xba, 0xa9, 0x05, 0xdd, 0x71, 0x4a, 0xbd, 0x00, 0xa8, 0x0c, 
0xf7, 0x50, 0xab, 0x44, 0xd6, 0x3e, 0x87, 0x21, 0x3c, 0x2d, 0xe6, 0x33, 0x27, 
0x5e, 0x21, 0x27, 0xb9, 0xdc, 0x38, 0x48, 0xd6, 0x3a, 0x96, 0xe1, 0x17, 0x47, 
0x65, 0x65, 0xce, 0x3d, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x48, 0x30, 0x46, 
0x30, 0x44, 0x06, 0x03, 0x55, 0x1d, 0x01, 0x04, 0x3d, 0x30, 0x3b, 0x80, 0x10, 
0xce, 0xb5, 0x7a, 0xcf, 0xe5, 0x21, 0xc7, 0x6b, 0xf3, 0xec, 0x92, 0xd4, 0xbf, 
0x65, 0x2a, 0x35, 0xa1, 0x15, 0x30, 0x13, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 
0x55, 0x04, 0x03, 0x13, 0x08, 0x54, 0x65, 0x73, 0x74, 0x52, 0x6f, 0x6f, 0x74, 
0x82, 0x10, 0x34, 0x30, 0x27, 0x7f, 0x05, 0x3d, 0x95, 0x85, 0x43, 0xa0, 0xa4, 
0xf5, 0x0c, 0x9a, 0xe7, 0xca, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e,
  0x03, 0x02, 0x1d, 0x05, 0x00, 

[edk2] [PATCH V8 11/15] IntelFrameworkModulePkg/DxeCapsuleLib: Add ProcessCapsules() interface.

2016-11-02 Thread Jiewen Yao
Add NULL ProcessCapsules() interface for DxeCapsuleLib.
IntelFrameworkModulePkg is under maintenance phase.
We stop adding new feature there.
Just add NULL function to make it pass build.

Cc: Jeff Fan 
Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: Jeff Fan 
---
 IntelFrameworkModulePkg/Library/DxeCapsuleLib/DxeCapsuleLib.c | 40 
+++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/IntelFrameworkModulePkg/Library/DxeCapsuleLib/DxeCapsuleLib.c 
b/IntelFrameworkModulePkg/Library/DxeCapsuleLib/DxeCapsuleLib.c
index fc9b533..eaed06e 100644
--- a/IntelFrameworkModulePkg/Library/DxeCapsuleLib/DxeCapsuleLib.c
+++ b/IntelFrameworkModulePkg/Library/DxeCapsuleLib/DxeCapsuleLib.c
@@ -1,7 +1,7 @@
 /** @file
   Capsule Library instance to process capsule images.
 
-  Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.
+  Copyright (c) 2007 - 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
@@ -515,4 +515,42 @@ ProcessCapsuleImage (
   return Status;
 }
 
+/**
+
+  This routine is called to process capsules.
+
+  Caution: This function may receive untrusted input.
+
+  The capsules reported in EFI_HOB_UEFI_CAPSULE are processed.
+  If there is no EFI_HOB_UEFI_CAPSULE, this routine does nothing.
+
+  This routine should be called twice in BDS.
+  1) The first call must be before EndOfDxe. The system capsules is processed.
+ If device capsule FMP protocols are exposted at this time and device FMP
+ capsule has zero EmbeddedDriverCount, the device capsules are processed.
+ Each individual capsule result is recorded in capsule record variable.
+ System may reset in this function, if reset is required by capsule and
+ all capsules are processed.
+ If not all capsules are processed, reset will be defered to second call.
+
+  2) The second call must be after EndOfDxe and after ConnectAll, so that all
+ device capsule FMP protocols are exposed.
+ The system capsules are skipped. If the device capsules are NOT processed
+ in first call, they are processed here.
+ Each individual capsule result is recorded in capsule record variable.
+ System may reset in this function, if reset is required by capsule
+ processed in first call and second call.
+
+  @retval EFI_SUCCESS There is no error when processing capsules.
+  @retval EFI_OUT_OF_RESOURCESNo enough resource to process capsules.
+
+**/
+EFI_STATUS
+EFIAPI
+ProcessCapsules (
+  VOID
+  )
+{
+  return EFI_UNSUPPORTED;
+}
 
-- 
2.7.4.windows.1

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


[edk2] [PATCH V8 08/15] MdeModulePkg/CapsuleApp: Add CapsuleApp application.

2016-11-02 Thread Jiewen Yao
This CapsuleApp can help perform capsule update in UEFI shell environment.
It can also dump capsule information, capsule status variable, ESRT and FMP.

Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: Liming Gao 
---
 MdeModulePkg/Application/CapsuleApp/AppSupport.c| 445 ++
 MdeModulePkg/Application/CapsuleApp/CapsuleApp.c| 849 

 MdeModulePkg/Application/CapsuleApp/CapsuleApp.inf  |  71 ++
 MdeModulePkg/Application/CapsuleApp/CapsuleApp.uni  |  22 +
 MdeModulePkg/Application/CapsuleApp/CapsuleAppExtra.uni |  19 +
 MdeModulePkg/Application/CapsuleApp/CapsuleDump.c   | 732 +
 6 files changed, 2138 insertions(+)

diff --git a/MdeModulePkg/Application/CapsuleApp/AppSupport.c 
b/MdeModulePkg/Application/CapsuleApp/AppSupport.c
new file mode 100644
index 000..c2fc3c1
--- /dev/null
+++ b/MdeModulePkg/Application/CapsuleApp/AppSupport.c
@@ -0,0 +1,445 @@
+/** @file
+  A shell application that triggers capsule update process.
+
+  Copyright (c) 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 
+
+#define MAX_ARG_NUM 11
+
+UINTN  Argc;
+CHAR16 **Argv;
+
+/**
+
+  This function parse application ARG.
+
+  @return Status
+**/
+EFI_STATUS
+GetArg (
+  VOID
+  )
+{
+  EFI_STATUSStatus;
+  EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters;
+
+  Status = gBS->HandleProtocol (
+  gImageHandle,
+  ,
+  (VOID**)
+  );
+  if (EFI_ERROR(Status)) {
+return Status;
+  }
+
+  Argc = ShellParameters->Argc;
+  Argv = ShellParameters->Argv;
+  return EFI_SUCCESS;
+}
+
+/**
+  Return File System Volume containing this shell application.
+
+  @return File System Volume containing this shell application.
+**/
+EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *
+GetMyVol (
+  VOID
+  )
+{
+  EFI_STATUSStatus;
+  EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
+  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL   *Vol;
+
+  Status = gBS->HandleProtocol (
+  gImageHandle,
+  ,
+  (VOID **)
+  );
+  ASSERT_EFI_ERROR (Status);
+
+  Status = gBS->HandleProtocol (
+  LoadedImage->DeviceHandle,
+  ,
+  (VOID **)
+  );
+  if (!EFI_ERROR (Status)) {
+return Vol;
+  }
+
+  return NULL;
+}
+
+/**
+  Read a file from this volume.
+
+  @param[in]  Vol File System Volume
+  @param[in]  FileNameThe file to be read.
+  @param[out] BufferSize  The file buffer size
+  @param[out] Buffer  The file buffer
+
+  @retval EFI_SUCCESSRead file successfully
+  @retval EFI_NOT_FOUND  File not found
+**/
+EFI_STATUS
+ReadFileFromVol (
+  IN  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL   *Vol,
+  IN  CHAR16*FileName,
+  OUT UINTN *BufferSize,
+  OUT VOID  **Buffer
+  )
+{
+  EFI_STATUSStatus;
+  EFI_FILE_HANDLE   RootDir;
+  EFI_FILE_HANDLE   Handle;
+  UINTN FileInfoSize;
+  EFI_FILE_INFO *FileInfo;
+  UINTN TempBufferSize;
+  VOID  *TempBuffer;
+
+  //
+  // Open the root directory
+  //
+  Status = Vol->OpenVolume (Vol, );
+  if (EFI_ERROR (Status)) {
+return Status;
+  }
+
+  //
+  // Open the file
+  //
+  Status = RootDir->Open (
+  RootDir,
+  ,
+  FileName,
+  EFI_FILE_MODE_READ,
+  0
+  );
+  if (EFI_ERROR (Status)) {
+RootDir->Close (RootDir);
+return Status;
+  }
+
+  RootDir->Close (RootDir);
+
+  //
+  // Get the file information
+  //
+  FileInfoSize = sizeof(EFI_FILE_INFO) + 1024;
+
+  FileInfo = AllocateZeroPool (FileInfoSize);
+  if (FileInfo == NULL) {
+Handle->Close (Handle);
+return Status;
+  }
+
+  Status = Handle->GetInfo (
+ Handle,
+ ,
+ 

[edk2] [PATCH V8 10/15] MdeModulePkg/MdeModulePkg.dsc: Add FMP related component.

2016-11-02 Thread Jiewen Yao
Add FMP related component to check build.

Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: Liming Gao 
---
 MdeModulePkg/MdeModulePkg.dsc | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc
index 71505d3..a058009 100644
--- a/MdeModulePkg/MdeModulePkg.dsc
+++ b/MdeModulePkg/MdeModulePkg.dsc
@@ -103,6 +103,9 @@
   VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf
   FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf
 
+  
FmpAuthenticationLib|MdeModulePkg/Library/FmpAuthenticationLibNull/FmpAuthenticationLibNull.inf
+  CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf
+
 [LibraryClasses.EBC.PEIM]
   IoLib|MdePkg/Library/PeiIoLibCpuIo/PeiIoLibCpuIo.inf
 
@@ -126,12 +129,14 @@
   LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf
   
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
   
ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf
+  CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf
 
 [LibraryClasses.common.DXE_RUNTIME_DRIVER]
   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
   
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
   DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
   LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf
+  CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf
 
 [LibraryClasses.common.SMM_CORE]
   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
@@ -408,6 +413,11 @@
   MdeModulePkg/Universal/SerialDxe/SerialDxe.inf
   MdeModulePkg/Universal/LoadFileOnFv2/LoadFileOnFv2.inf
 
+  MdeModulePkg/Application/CapsuleApp/CapsuleApp.inf
+  MdeModulePkg/Library/FmpAuthenticationLibNull/FmpAuthenticationLibNull.inf
+  MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf
+  MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf
+
 [Components.IA32, Components.X64, Components.IPF]  
   MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.inf
   MdeModulePkg/Universal/DebugSupportDxe/DebugSupportDxe.inf
-- 
2.7.4.windows.1

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


[edk2] [PATCH V8 06/15] MdeModulePkg/DxeCapsuleLibFmp: Add DxeCapsuleLibFmp instance.

2016-11-02 Thread Jiewen Yao
This instance handles Microsoft UX capsule, UEFI defined FMP capsule.
This instance should not assume any capsule image format.

Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: Liming Gao 
---
 MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c| 1363 

 MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf  |   80 ++
 MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.uni  |   22 +
 MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleProcessLib.c |  475 +++
 MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleProcessLibNull.c |   57 +
 MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleReportLib.c  |  489 +++
 MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleReportLibNull.c  |   91 ++
 MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c|  112 ++
 MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf   |   83 ++
 MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.uni   |   22 +
 10 files changed, 2794 insertions(+)

diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c 
b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c
new file mode 100644
index 000..1ac9e89
--- /dev/null
+++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c
@@ -0,0 +1,1363 @@
+/** @file
+  DXE capsule library.
+
+  Caution: This module requires additional review when modified.
+  This module will have external input - capsule image.
+  This external input must be validated carefully to avoid security issue like
+  buffer overflow, integer overflow.
+
+  SupportCapsuleImage(), ProcessCapsuleImage(), IsValidCapsuleHeader(),
+  ValidateFmpCapsule(), DisplayCapsuleImage(), ConvertBmpToGopBlt() will
+  receive untrusted input and do basic validation.
+
+  Copyright (c) 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 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+BOOLEANmAreAllImagesProcessed;
+
+EFI_SYSTEM_RESOURCE_TABLE *mEsrtTable  = NULL;
+BOOLEAN   mIsVirtualAddrConverted  = FALSE;
+BOOLEAN   mDxeCapsuleLibEndOfDxe   = FALSE;
+
+/**
+  Initialize capsule related variables.
+**/
+VOID
+InitCapsuleVariable (
+  VOID
+  );
+
+/**
+  Check if this FMP capsule is processed.
+
+  @param[in] CapsuleHeader  The capsule image header
+  @param[in] PayloadIndex   FMP payload index
+  @param[in] ImageHeaderFMP image header
+
+  @retval TRUE  This FMP capsule is processed.
+  @retval FALSE This FMP capsule is not processed.
+**/
+BOOLEAN
+IsFmpCapsuleProcessed (
+  IN EFI_CAPSULE_HEADER*CapsuleHeader,
+  IN UINTN PayloadIndex,
+  IN EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER  *ImageHeader
+  );
+
+/**
+  Record capsule status variable.
+
+  @param[in] CapsuleHeader  The capsule image header
+  @param[in] CapsuleStatus  The capsule process stauts
+
+  @retval EFI_SUCCESS  The capsule status variable is recorded.
+  @retval EFI_OUT_OF_RESOURCES No resource to record the capsule status 
variable.
+**/
+EFI_STATUS
+RecordCapsuleStatusVariable (
+  IN EFI_CAPSULE_HEADER   *CapsuleHeader,
+  IN EFI_STATUS   CapsuleStatus
+  );
+
+/**
+  Record FMP capsule status variable.
+
+  @param[in] CapsuleHeader  The capsule image header
+  @param[in] CapsuleStatus  The capsule process stauts
+  @param[in] PayloadIndex   FMP payload index
+  @param[in] ImageHeaderFMP image header
+
+  @retval EFI_SUCCESS  The capsule status variable is recorded.
+  @retval EFI_OUT_OF_RESOURCES No resource to record the capsule status 
variable.
+**/
+EFI_STATUS
+RecordFmpCapsuleStatusVariable (
+  IN EFI_CAPSULE_HEADER*CapsuleHeader,
+  IN EFI_STATUSCapsuleStatus,
+  IN UINTN PayloadIndex,
+  IN EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER  *ImageHeader
+  );
+
+/**
+  Function indicate the current completion progress of the firmware
+  update. Platform may 

[edk2] [PATCH V8 07/15] MdeModulePkg/Esrt: Add ESRT_FW_TYPE_SYSTEMFIRMWARE check.

2016-11-02 Thread Jiewen Yao
The previous ESRT driver unconditionally treat FMP to be
ESRT_FW_TYPE_DEVICEFIRMWARE.
EDKII System Capsule reuses FMP, but it is ESRT_FW_TYPE_SYSTEMFIRMWARE.

Add check to ImageTypeId check to see if it is ESRT_FW_TYPE_SYSTEMFIRMWARE.

Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: Liming Gao 
---
 MdeModulePkg/Universal/EsrtDxe/EsrtDxe.inf |  3 +-
 MdeModulePkg/Universal/EsrtDxe/EsrtImpl.c  | 37 ++--
 2 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/MdeModulePkg/Universal/EsrtDxe/EsrtDxe.inf 
b/MdeModulePkg/Universal/EsrtDxe/EsrtDxe.inf
index 8fbc75b..2c66f15 100644
--- a/MdeModulePkg/Universal/EsrtDxe/EsrtDxe.inf
+++ b/MdeModulePkg/Universal/EsrtDxe/EsrtDxe.inf
@@ -4,7 +4,7 @@
 #  This driver produces EsrtManagement protocol to manage cache ESRT 
repository for FMP/Non-FMP instances.
 #  ESRT table based on repository is published on gEfiEventReadyToBootGuid.
 #
-#  Copyright (c) 2015, Intel Corporation. All rights reserved.
+#  Copyright (c) 2015 - 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
@@ -64,6 +64,7 @@
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxFmpEsrtCacheNum  ## 
CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxNonFmpEsrtCacheNum   ## 
CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdSystemRebootAfterCapsuleProcessFlag ## 
CONSUMES
+  gEfiMdeModulePkgTokenSpaceGuid.PcdSystemFmpCapsuleImageTypeIdGuid ## 
CONSUMES
 
 [Depex]
   gEfiVariableArchProtocolGuid AND gEfiVariableWriteArchProtocolGuid
diff --git a/MdeModulePkg/Universal/EsrtDxe/EsrtImpl.c 
b/MdeModulePkg/Universal/EsrtDxe/EsrtImpl.c
index f6d1e97..35a237e 100644
--- a/MdeModulePkg/Universal/EsrtDxe/EsrtImpl.c
+++ b/MdeModulePkg/Universal/EsrtDxe/EsrtImpl.c
@@ -1,7 +1,7 @@
 /** @file
   Esrt management implementation.
 
-Copyright (c) 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2015 - 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
@@ -391,6 +391,35 @@ EXIT:
 }
 
 /**
+  Return if this FMP is a system FMP or a device FMP, based upon FmpImageInfo.
+
+  @param[in] FmpImageInfo A pointer to EFI_FIRMWARE_IMAGE_DESCRIPTOR
+
+  @return TRUE  It is a system FMP.
+  @return FALSE It is a device FMP.
+**/
+BOOLEAN
+IsSystemFmp (
+  IN EFI_FIRMWARE_IMAGE_DESCRIPTOR   *FmpImageInfo
+  )
+{
+  GUID  *Guid;
+  UINTN Count;
+  UINTN Index;
+
+  Guid = PcdGetPtr(PcdSystemFmpCapsuleImageTypeIdGuid);
+  Count = PcdGetSize(PcdSystemFmpCapsuleImageTypeIdGuid)/sizeof(GUID);
+
+  for (Index = 0; Index < Count; Index++, Guid++) {
+if (CompareGuid(>ImageTypeId, Guid)) {
+  return TRUE;
+}
+  }
+
+  return FALSE;
+}
+
+/**
   Init one ESRT entry according to input FmpImageInfo (V1, V2, V3) .
 
   @param[in, out] EsrtEntryEsrt entry to be Init
@@ -407,7 +436,11 @@ SetEsrtEntryFromFmpInfo (
 {
   EsrtEntry->FwVersion= FmpImageInfo->Version;
   EsrtEntry->FwClass  = FmpImageInfo->ImageTypeId;
-  EsrtEntry->FwType   = ESRT_FW_TYPE_DEVICEFIRMWARE;
+  if (IsSystemFmp(FmpImageInfo)) {
+EsrtEntry->FwType   = ESRT_FW_TYPE_SYSTEMFIRMWARE;
+  } else {
+EsrtEntry->FwType   = ESRT_FW_TYPE_DEVICEFIRMWARE;
+  }
   EsrtEntry->LowestSupportedFwVersion = 0;
   EsrtEntry->CapsuleFlags = 0;
   EsrtEntry->LastAttemptVersion   = 0;
-- 
2.7.4.windows.1

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


[edk2] [PATCH V8 09/15] MdeModulePkg/UiApp: Show test key warning info in FrontPage.

2016-11-02 Thread Jiewen Yao
The UiApp is updated to consume PcdTestKeyUsed to know if there is any
test key used in current BIOS, such as recovery key,
or capsule update key.
Then UiApp show warning information in front page.

Cc: Eric Dong 
Cc: Ruiyu Ni 
Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
---
 MdeModulePkg/Application/UiApp/FrontPageCustomizedUi.c | 13 +
 MdeModulePkg/Application/UiApp/FrontPageStrings.uni|  4 +++-
 MdeModulePkg/Application/UiApp/UiApp.inf   |  3 ++-
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Application/UiApp/FrontPageCustomizedUi.c 
b/MdeModulePkg/Application/UiApp/FrontPageCustomizedUi.c
index 6e4f7b5..a9d2269 100644
--- a/MdeModulePkg/Application/UiApp/FrontPageCustomizedUi.c
+++ b/MdeModulePkg/Application/UiApp/FrontPageCustomizedUi.c
@@ -16,8 +16,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER 
EXPRESS OR IMPLIED.
 #include 
 #include 
 #include 
+#include "FrontPage.h"
 #include "FrontPageCustomizedUiSupport.h"
 
+extern FRONT_PAGE_CALLBACK_DATA  gFrontPagePrivate;
+
 /**
   Customize menus in the page.
 
@@ -129,4 +132,14 @@ UiCustomizeFrontPageBanner (
   IN OUT EFI_STRING *BannerStr
   )
 {
+  if ((LineIndex == 5) && LeftOrRight) {
+// Update STR_CUSTOMIZE_BANNER_LINE5_LEFT
+if (PcdGetBool(PcdTestKeyUsed)) {
+  if (BannerStr != NULL) {
+FreePool(*BannerStr);
+  }
+  *BannerStr = HiiGetString(gFrontPagePrivate.HiiHandle, 
STRING_TOKEN(STR_TEST_KEY_USED), NULL);
+}
+  }
+  return;
 }
diff --git a/MdeModulePkg/Application/UiApp/FrontPageStrings.uni 
b/MdeModulePkg/Application/UiApp/FrontPageStrings.uni
index 71cb788..8080a20 100644
--- a/MdeModulePkg/Application/UiApp/FrontPageStrings.uni
+++ b/MdeModulePkg/Application/UiApp/FrontPageStrings.uni
@@ -2,7 +2,7 @@
 //
 //  String definitions for BdsPlatform formset.
 //
-//  Copyright (c) 2004 - 2015, Intel Corporation. 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
@@ -68,5 +68,7 @@
  #language fr-FR  ""
 #string STR_CUSTOMIZE_BANNER_LINE5_RIGHT #language en-US  ""
  #language fr-FR  ""
+#string STR_TEST_KEY_USED#language en-US  "WARNING: Test key 
detected."
+ #language fr-FR  "WARNING: Test key 
detected."
 #string STR_NULL_STRING#language en-US  " "
#language fr-FR  " "
diff --git a/MdeModulePkg/Application/UiApp/UiApp.inf 
b/MdeModulePkg/Application/UiApp/UiApp.inf
index 6df6e47..d144462 100644
--- a/MdeModulePkg/Application/UiApp/UiApp.inf
+++ b/MdeModulePkg/Application/UiApp/UiApp.inf
@@ -1,7 +1,7 @@
 ## @file
 #  UiApp module is driver for BDS phase.
 #
-#  Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.
+#  Copyright (c) 2011 - 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
@@ -82,6 +82,7 @@
   gEfiMdeModulePkgTokenSpaceGuid.PcdSetupVideoHorizontalResolution  ## CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdSetupVideoVerticalResolution## CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString   ## CONSUMES
+  gEfiMdeModulePkgTokenSpaceGuid.PcdTestKeyUsed ## CONSUMES
 
 [UserExtensions.TianoCore."ExtraFiles"]
   UiAppExtra.uni
-- 
2.7.4.windows.1

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


[edk2] [PATCH V8 05/15] MdeModulePkg/DxeCapsuleLibNull: Add ProcessCapsules() interface.

2016-11-02 Thread Jiewen Yao
Add ProcessCapsules() interface for DxeCapsuleLibNull.

Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: Liming Gao 
---
 MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.c | 48 
++--
 1 file changed, 45 insertions(+), 3 deletions(-)

diff --git a/MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.c 
b/MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.c
index fb5c255..b064240 100644
--- a/MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.c
+++ b/MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.c
@@ -1,7 +1,7 @@
 /** @file
   Null Dxe Capsule Library instance does nothing and returns unsupport status.
 
-Copyright (c) 2007 - 2008, Intel Corporation. All rights reserved.
+Copyright (c) 2007 - 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
@@ -17,7 +17,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER 
EXPRESS OR IMPLIED.
 /**
   The firmware checks whether the capsule image is supported 
   by the CapsuleGuid in CapsuleHeader or other specific information in capsule 
image.
-  
+
+  Caution: This function may receive untrusted input.
+
   @param  CapsuleHeaderPoint to the UEFI capsule image to be checked.
   
   @retval EFI_UNSUPPORTED  Input capsule is not supported by the firmware.
@@ -34,7 +36,9 @@ SupportCapsuleImage (
 /**
   The firmware specific implementation processes the capsule image
   if it recognized the format of this capsule image.
-  
+
+  Caution: This function may receive untrusted input.
+
   @param  CapsuleHeaderPoint to the UEFI capsule image to be processed. 

   @retval EFI_UNSUPPORTED  Capsule image is not supported by the firmware.
@@ -48,4 +52,42 @@ ProcessCapsuleImage (
   return EFI_UNSUPPORTED;
 }
 
+/**
+
+  This routine is called to process capsules.
+
+  Caution: This function may receive untrusted input.
+
+  The capsules reported in EFI_HOB_UEFI_CAPSULE are processed.
+  If there is no EFI_HOB_UEFI_CAPSULE, this routine does nothing.
+
+  This routine should be called twice in BDS.
+  1) The first call must be before EndOfDxe. The system capsules is processed.
+ If device capsule FMP protocols are exposted at this time and device FMP
+ capsule has zero EmbeddedDriverCount, the device capsules are processed.
+ Each individual capsule result is recorded in capsule record variable.
+ System may reset in this function, if reset is required by capsule and
+ all capsules are processed.
+ If not all capsules are processed, reset will be defered to second call.
+
+  2) The second call must be after EndOfDxe and after ConnectAll, so that all
+ device capsule FMP protocols are exposed.
+ The system capsules are skipped. If the device capsules are NOT processed
+ in first call, they are processed here.
+ Each individual capsule result is recorded in capsule record variable.
+ System may reset in this function, if reset is required by capsule
+ processed in first call and second call.
+
+  @retval EFI_SUCCESS There is no error when processing capsules.
+  @retval EFI_OUT_OF_RESOURCESNo enough resource to process capsules.
+
+**/
+EFI_STATUS
+EFIAPI
+ProcessCapsules (
+  VOID
+  )
+{
+  return EFI_UNSUPPORTED;
+}
 
-- 
2.7.4.windows.1

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


[edk2] [PATCH V8 02/15] MdeModulePkg/CapsuleLib: Add ProcessCapsules() API.

2016-11-02 Thread Jiewen Yao
ProcessCapsules() API can be used by platform BDS to process all capsules.

Cc: Feng Tian 
Cc: Star Zeng 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao 
Reviewed-by: Liming Gao 
---
 MdeModulePkg/Include/Library/CapsuleLib.h | 46 ++--
 1 file changed, 43 insertions(+), 3 deletions(-)

diff --git a/MdeModulePkg/Include/Library/CapsuleLib.h 
b/MdeModulePkg/Include/Library/CapsuleLib.h
index 487cb0f..26c14a0 100644
--- a/MdeModulePkg/Include/Library/CapsuleLib.h
+++ b/MdeModulePkg/Include/Library/CapsuleLib.h
@@ -2,7 +2,7 @@
 
   This library class defines a set of interfaces for how to process capsule 
image updates.
 
-Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.
+Copyright (c) 2007 - 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 that accompanies this 
distribution.  
 The full text of the license may be found at
@@ -20,7 +20,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER 
EXPRESS OR IMPLIED.
   The firmware checks whether the capsule image is supported 
   by the CapsuleGuid in CapsuleHeader or if there is other specific 
information in 
   the capsule image.
-  
+
+  Caution: This function may receive untrusted input.
+
   @param  CapsuleHeaderPointer to the UEFI capsule image to be checked.
   
   @retval EFI_SUCESS   Input capsule is supported by firmware.
@@ -35,7 +37,9 @@ SupportCapsuleImage (
 /**
   The firmware-specific implementation processes the capsule image
   if it recognized the format of this capsule image.
-  
+
+  Caution: This function may receive untrusted input.
+
   @param  CapsuleHeaderPointer to the UEFI capsule image to be processed. 

   @retval EFI_SUCESS   Capsule Image processed successfully. 
@@ -47,4 +51,40 @@ ProcessCapsuleImage (
   IN EFI_CAPSULE_HEADER *CapsuleHeader
   );
 
+/**
+
+  This routine is called to process capsules.
+
+  Caution: This function may receive untrusted input.
+
+  The capsules reported in EFI_HOB_UEFI_CAPSULE are processed.
+  If there is no EFI_HOB_UEFI_CAPSULE, this routine does nothing.
+
+  This routine should be called twice in BDS.
+  1) The first call must be before EndOfDxe. The system capsules is processed.
+ If device capsule FMP protocols are exposted at this time and device FMP
+ capsule has zero EmbeddedDriverCount, the device capsules are processed.
+ Each individual capsule result is recorded in capsule record variable.
+ System may reset in this function, if reset is required by capsule and
+ all capsules are processed.
+ If not all capsules are processed, reset will be defered to second call.
+
+  2) The second call must be after EndOfDxe and after ConnectAll, so that all
+ device capsule FMP protocols are exposed.
+ The system capsules are skipped. If the device capsules are NOT processed
+ in first call, they are processed here.
+ Each individual capsule result is recorded in capsule record variable.
+ System may reset in this function, if reset is required by capsule
+ processed in first call and second call.
+
+  @retval EFI_SUCCESS There is no error when processing capsules.
+  @retval EFI_OUT_OF_RESOURCESNo enough resource to process capsules.
+
+**/
+EFI_STATUS
+EFIAPI
+ProcessCapsules (
+  VOID
+  );
+
 #endif
-- 
2.7.4.windows.1

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


[edk2] [PATCH V8 00/15] Add capsule support lib and app.

2016-11-02 Thread Jiewen Yao
==Below is V8 description==
1) MdeModulePkg/dec: 
set gEfiMdeModulePkgTokenSpaceGuid.PcdSystemFmpCapsuleImageTypeIdGuid
to 0 as default.
2) SignedCapsulePkg/dec:
set gEfiSignedCapsulePkgTokenSpaceGuid.PcdEdkiiSystemFirmwareFileGuid
to 0 as default.
3) QuarkPlatformPkg: Set CAPSULE_ENABLE/RECOVERY_ENABLE to FALSE as default.
4) All: rename EFI_D_* => DEBUG_*

==Below is V7 description==
1) MdeModulePkg/MdeModulePkg.dec: refine status code comment.
2) UefiCpuPkg: Move Microcode capsule related conent to Feature/capsule dir.
3) Vlv2TbltDevicePkg: Add MICOCODE_CAPSULE_ENABLE macro.

Only series 1, 3, 5 are sent for update review.
The other series are unchanged.

==Below is V6 description==
1) MdeModulePkg/CapsuleApp: Fix -D issue.
2) MdeModulePkg/DEC: Cleanup Capsule related StatusCode.
3) UefiCpuPkg: Remove MicrocodeUpdateApp
4) UefiCpuPkg: Add Microcode FMP build sample

Only series 1 and 3 are sent for update review.
The other series are unchanged.

==Below is V5 description==
1) MdeModulePkg/CapsuleApp: Remove [NR]. Add more description.
2) MdeModulePkg/DEC: Update StatusCode to OEM region.
3) MdeModulePkg/DxeCapsuleLib: Use NULL ProcessCapsules()
for runtime lib, because it is not needed for runtime.
4) MdeModulePkg/FmpAuthenticationLib: Add more description.
5) SignedCapsulePkg/DEC: Add data structure description
for PcdEdkiiSystemFirmwareImageDescriptor.
6) SignedCapsulePkg/DEC: Add Pkcs7 and Rsa2048 Key file PCD.
These 2 PCD are moved from platform pkg to SignedCapsulePkg.
7) QuarkPlatformPkg/FDF: Refine order of capsule section.
8) Fix typo and coding style issue.

Below items are defered to other patch series, because
the tool and library are not ready yet.

A) MdeModulePkg/DxeCapsuleLib: separate BMP parsing logic
to another library.
That is very good suggestion, and we agree it is a right direction.
I discussed with the owner of image decoder.
We prefer adding a generic library class to convert
the image data to GOP BLT buffer. It supports *any* image format,
not only BMP. The owner of image decoder will drive the new design.
I filed https://bugzilla.tianocore.org/show_bug.cgi?id=175 to track that.
I suggest we just keep the current solution as a temp solution and
migrate to the new one once it is ready later.

B) PlatformPkg/Bds: Move test key check logic to generic part.
This is very good suggestion and we are discussing with Tool
team to add such detection at build time and set a PCD to indicate that.
The generic code can use this PCD to know if there is a test key.
I filed https://bugzilla.tianocore.org/show_bug.cgi?id=185 to track that.
Adding such check in the generic code is very complicated, so current
temporary solution is to let platform BDS do such check.
The platform BDS will be cleaned up, once the tool is ready.

==Below is V4 description==
1) SecurityPkg - Refine AuthenticateFmpImage() API to let caller
input PublicKeyData and PublicKeyDataLength, instead of PCD.
The benefit is that then this API can be used for a platform
which stores PublicKeyData in anywhere other than PCD.
2) SecurityPkg - Use OFFSET_OF(WIN_CERTIFICATE_UEFI_GUID, CertData)
for better understanding the code.
3) MdeModulePkg - Update CapsuleApp to let it consume
ShellParameters protocol to get Argc and Argv.
4) UefiCpuPkg - Update MicrocodeCapsuleApp to let it consume
ShellParameters protocol to get Argc and Argv.
5) QuarkPlatformPkg - Merge QuarkCapsule.fdf to Quark.fdf.

==Below is V3 description==
1) We move all EDKII related capsule definition to SignedCapsulePkg.
MdeModulePkg only contains FmAuthenticationLib and CapsuleApp,
because they are generic and follow UEFI specification on FMP/ESRT
and Microsoft platform firmware update document.
Any capsule implementation can use them.

Here is full library classes:
MdeModulePkg:
FmpAuthenticationLib.h: new lib - follow UEFI spec. (*)
Verify FMP signature of FMP Capsule
CapsuleLib.h: new API ¨C ProcessCapsules()
It processes all the capsules. Remove duplicated code in 
platform BDS.
UefiCpuPkg:
MicrocodeFlashAccessLib.h: Update Microcode region.
SignedCapsulePkg:
EdkiiSystemCapsuleLib.h ¨C Library for EDKII system FMP.
IniParsingLib.h ¨C Library for INI file parsing.
PlatformFlashAccessLib.h ¨C Library for write flash.

2) We will submit 5 series.
Series 1: Generic Update (MdeModulePkg/SecurityPkg)
DxeCapsuleLib
FmAuthenticationLib (*)
CapsuleApp (*)
Series 2: EDKII Capsule (SignedCapsulePkg)
IniParsingLib
EdkiiSystemCapsuleLib
PlatformFlashAccessLib
SystemFirmwareUpdate driver
RecoveryModuleLoadPei driver
Series 3: Microcode Update (UefiCpuPkg)
MicrocodeFlashAccessLib
MicrocodeUpdate driver.
Series 4: Quark update
Series 5: Vlv2 update

3) DxeCapsuleLib: Move code that performs authentication and parsing of
the capsule format into the implementation of the FMP Protocol.
We move the dispatch FV code from 

Re: [edk2] [PATCH 5/5] EmbeddedPkg/PlatformPciIoDxe: add support for non-coherent DMA

2016-11-02 Thread Ard Biesheuvel
On 1 November 2016 at 22:43, Leif Lindholm  wrote:
> On Mon, Oct 31, 2016 at 06:13:10PM +, Ard Biesheuvel wrote:
>> Add support for bounce buffering using uncached mappings when DMA mappings
>> are not aligned to the CPU's DMA buffer alignment.
>
> This description does not appear to match the subject line?
> And the contents of the patch seems to do both.
>

Yes, I was a bit sloppy with this one. The subject line needs to be
duplicated into the long log.

> Anyway, I'll pass on a proper technical review until my head is a bit
> clearer, but a few comments/questions below.
>
>>
>> Contributed-under: TianoCore Contribution Agreement 1.0
>> Signed-off-by: Ard Biesheuvel 
>> ---
>>  EmbeddedPkg/Drivers/PlatformPciIoDxe/PlatformPciIo.c  | 204 
>> 
>>  EmbeddedPkg/Drivers/PlatformPciIoDxe/PlatformPciIo.h  |   5 +
>>  EmbeddedPkg/Drivers/PlatformPciIoDxe/PlatformPciIoDxe.c   |  17 +-
>>  EmbeddedPkg/Drivers/PlatformPciIoDxe/PlatformPciIoDxe.inf |   2 +
>>  4 files changed, 221 insertions(+), 7 deletions(-)
>>
>> diff --git a/EmbeddedPkg/Drivers/PlatformPciIoDxe/PlatformPciIo.c 
>> b/EmbeddedPkg/Drivers/PlatformPciIoDxe/PlatformPciIo.c
>> index 97ed19353347..658d096c73c1 100644
>> --- a/EmbeddedPkg/Drivers/PlatformPciIoDxe/PlatformPciIo.c
>> +++ b/EmbeddedPkg/Drivers/PlatformPciIoDxe/PlatformPciIo.c
>> @@ -15,6 +15,8 @@
>>
>>  #include "PlatformPciIo.h"
>>
>> +#include 
>> +
>>  #include 
>>
>>  typedef struct {
>> @@ -454,6 +456,201 @@ CoherentPciIoFreeBuffer (
>>return EFI_SUCCESS;
>>  }
>>
>> +STATIC
>> +EFI_STATUS
>> +NonCoherentPciIoFreeBuffer (
>> +  IN  EFI_PCI_IO_PROTOCOL *This,
>> +  IN  UINTN   Pages,
>> +  IN  VOID*HostAddress
>> +  )
>> +{
>> +  EFI_STATUSStatus;
>> +
>> +  Status = gDS->SetMemorySpaceAttributes (
>> +  (EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress,
>> +  EFI_PAGES_TO_SIZE (Pages),
>> +  EFI_MEMORY_WB);
>> +  if (EFI_ERROR (Status)) {
>> +return Status;
>> +  }
>> +
>> +  FreePages (HostAddress, Pages);
>> +  return EFI_SUCCESS;
>> +}
>> +
>> +STATIC
>> +EFI_STATUS
>> +NonCoherentPciIoAllocateBuffer (
>> +  IN  EFI_PCI_IO_PROTOCOL *This,
>> +  IN  EFI_ALLOCATE_TYPE   Type,
>> +  IN  EFI_MEMORY_TYPE MemoryType,
>> +  IN  UINTN   Pages,
>> +  OUT VOID**HostAddress,
>> +  IN  UINT64  Attributes
>> +  )
>> +{
>> +  EFI_STATUSStatus;
>> +
>> +  Status = CoherentPciIoAllocateBuffer (This, Type, MemoryType, Pages,
>> + HostAddress, Attributes);
>> +  if (EFI_ERROR (Status)) {
>> +return Status;
>> +  }
>> +
>> +  Status = gDS->SetMemorySpaceAttributes (
>> +  (EFI_PHYSICAL_ADDRESS)(UINTN)*HostAddress,
>> +  EFI_PAGES_TO_SIZE (Pages),
>> +  EFI_MEMORY_WC);
>> +  if (EFI_ERROR (Status)) {
>> +return Status;
>> +  }
>> +
>> +  Status = gCpu->FlushDataCache (
>> +   gCpu,
>> +   (EFI_PHYSICAL_ADDRESS)(UINTN)*HostAddress,
>> +   EFI_PAGES_TO_SIZE (Pages),
>> +   EfiCpuFlushTypeInvalidate);
>> +  if (EFI_ERROR (Status)) {
>> +NonCoherentPciIoFreeBuffer (This, Pages, *HostAddress);
>> +  }
>> +  return Status;
>> +}
>> +
>> +STATIC
>> +EFI_STATUS
>> +NonCoherentPciIoMap (
>> +  IN EFI_PCI_IO_PROTOCOL*This,
>> +  IN EFI_PCI_IO_PROTOCOL_OPERATION  Operation,
>> +  IN VOID   *HostAddress,
>> +  IN OUT UINTN  *NumberOfBytes,
>> +  OUTEFI_PHYSICAL_ADDRESS   *DeviceAddress,
>> +  OUTVOID   **Mapping
>> +  )
>> +{
>> +  PLATFORM_PCI_IO_DEV   *Dev;
>> +  EFI_STATUSStatus;
>> +  PLATFORM_PCI_IO_MAP_INFO  *MapInfo;
>> +  UINTN AlignMask;
>> +  VOID  *AllocAddress;
>> +  EFI_GCD_MEMORY_SPACE_DESCRIPTOR   GcdDescriptor;
>> +  BOOLEAN   UncachedMapping;
>> +
>> +  MapInfo = (PLATFORM_PCI_IO_MAP_INFO *)AllocatePool (sizeof *MapInfo);
>> +  if (MapInfo == NULL) {
>> +return EFI_OUT_OF_RESOURCES;
>> +  }
>> +
>> +  MapInfo->HostAddress = HostAddress;
>> +  MapInfo->Operation = Operation;
>> +  MapInfo->NumberOfBytes = *NumberOfBytes;
>> +
>> +  //
>> +  // Bounce buffering is not possible for consistent mappings, so
>> +  // check we are mapping a cached buffer for consistent DMA
>> +  //
>> +  if (Operation == EfiPciIoOperationBusMasterCommonBuffer) {
>> +Status = gDS->GetMemorySpaceDescriptor (
>> +(EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress,
>> +);
>> +if (!EFI_ERROR (Status)) {
>> +  UncachedMapping = (GcdDescriptor.Attributes & EFI_MEMORY_WC) != 0;
>> +} else {
>> +  UncachedMapping = FALSE;

Re: [edk2] [PATCH 3/5] EmbeddedPkg: implement generic platform PCI I/O driver

2016-11-02 Thread Ard Biesheuvel
On 1 November 2016 at 22:22, Leif Lindholm  wrote:
> On Mon, Oct 31, 2016 at 06:13:08PM +, Ard Biesheuvel wrote:
>> This implements support for platform PCI I/O devices, i.e, devices that
>> are not on a PCI bus but that can be drived by generic PCI drivers in
>
> drived->driven? (or substitute "controlled")
>

That's a typo, not a speako. But yes, let me clean that up

>> EDK2.
>>
>> This is implemented as a UEFI driver, which means we take full advantage
>> of the UEFI driver model, and only instantiate those devices that are
>> necessary for booting.
>>
>> Care is taken to deal with DMA addressing limitations: DMA mappings and
>> allocations are moved below 4 GB if the PCI driver has not informed us
>> that the device being driven is 64-bit DMA capable.
>
> How do we deal with these devices if there is no RAM below 4GB?
> (Signalling an error and aborting is fine, but worth calling out even
> here in the commit message.)
>

The same thing the normal PCI I/O implementations do: return an error.
If you plug in a EHCI controller on Seattle that does not support
64-bit DMA, calls to AllocateBuffer() and Map() will fail in exactly
the same way.

>>
>> For now, this driver supports coherent DMA only, but support for
>> non-coherent DMA is planned as well.
>>
>> Contributed-under: TianoCore Contribution Agreement 1.0
>> Signed-off-by: Ard Biesheuvel 
>> ---
>>  EmbeddedPkg/Drivers/PlatformPciIoDxe/PlatformPciIo.c  | 649 
>> 
>>  EmbeddedPkg/Drivers/PlatformPciIoDxe/PlatformPciIo.h  |  67 ++
>>  EmbeddedPkg/Drivers/PlatformPciIoDxe/PlatformPciIoDxe.c   | 268 
>>  EmbeddedPkg/Drivers/PlatformPciIoDxe/PlatformPciIoDxe.inf |  41 ++
>>  EmbeddedPkg/EmbeddedPkg.dsc   |   1 +
>>  5 files changed, 1026 insertions(+)
>>
>> diff --git a/EmbeddedPkg/Drivers/PlatformPciIoDxe/PlatformPciIo.c 
>> b/EmbeddedPkg/Drivers/PlatformPciIoDxe/PlatformPciIo.c
>> new file mode 100644
>> index ..97ed19353347
>> --- /dev/null
>> +++ b/EmbeddedPkg/Drivers/PlatformPciIoDxe/PlatformPciIo.c
>> @@ -0,0 +1,649 @@
>> +/** @file
>> +
>> +  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
>> +  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 "PlatformPciIo.h"
>> +
>> +#include 
>> +
>> +typedef struct {
>> +  EFI_PHYSICAL_ADDRESSAllocAddress;
>> +  VOID*HostAddress;
>> +  EFI_PCI_IO_PROTOCOL_OPERATION   Operation;
>> +  UINTN   NumberOfBytes;
>> +} PLATFORM_PCI_IO_MAP_INFO;
>> +
>> +STATIC
>> +EFI_STATUS
>> +PciIoPollMem (
>> +  IN  EFI_PCI_IO_PROTOCOL  *This,
>> +  IN  EFI_PCI_IO_PROTOCOL_WIDTHWidth,
>> +  IN  UINT8BarIndex,
>> +  IN  UINT64   Offset,
>> +  IN  UINT64   Mask,
>> +  IN  UINT64   Value,
>> +  IN  UINT64   Delay,
>> +  OUT UINT64   *Result
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return EFI_UNSUPPORTED;
>> +}
>> +
>> +STATIC
>> +EFI_STATUS
>> +PciIoPollIo (
>> +  IN  EFI_PCI_IO_PROTOCOL  *This,
>> +  IN  EFI_PCI_IO_PROTOCOL_WIDTHWidth,
>> +  IN  UINT8BarIndex,
>> +  IN  UINT64   Offset,
>> +  IN  UINT64   Mask,
>> +  IN  UINT64   Value,
>> +  IN  UINT64   Delay,
>> +  OUT UINT64   *Result
>> +  )
>> +{
>> +  ASSERT (FALSE);
>> +  return EFI_UNSUPPORTED;
>> +}
>> +
>> +STATIC
>> +EFI_STATUS
>> +PciIoMemRW (
>> +  INEFI_PCI_IO_PROTOCOL_WIDTH Width,
>> +  INUINTN Count,
>> +  INUINTN DstStride,
>> +  INVOID  *Dst,
>> +  INUINTN SrcStride,
>> +  OUT   CONST VOID*Src
>> +  )
>> +{
>> +  UINT8 *Dst8;
>> +  UINT16*Dst16;
>> +  UINT32*Dst32;
>> +  CONST UINT8   *Src8;
>> +  CONST UINT16  *Src16;
>> +  CONST UINT32  *Src32;
>
> Do any or all of these need to be volatile to ensure retaining access
> order and size (and if not, could we call that out explicitly)?
>

Good question. But perhaps it is better to put a MemoryFence() at the
end of each loop iteration?

>> +
>> +  //
>> +  // Loop for each iteration and move the data
>> +  //
>> +  switch (Width & 0x3) {
>> +  case EfiPciWidthUint8:
>> +Dst8 = (UINT8 *)Dst;
>> +Src8 = (UINT8 

Re: [edk2] [PATCH 4/5] ArmPkg/CpuDxe: set DmaBufferAlignment according to CWG

2016-11-02 Thread Ard Biesheuvel
On 1 November 2016 at 22:32, Leif Lindholm  wrote:
> On Mon, Oct 31, 2016 at 06:13:09PM +, Ard Biesheuvel wrote:
>> The DmaBufferAlignment currently defaults to 4, which is dangerously
>> small and may result in lost data on platform that perform non-coherent
>> DMA. So instead, take the CWG value from the cache info registers.
>>
>> Contributed-under: TianoCore Contribution Agreement 1.0
>> Signed-off-by: Ard Biesheuvel 
>> ---
>>  ArmPkg/Drivers/CpuDxe/CpuDxe.c | 4 +++-
>>  1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/ArmPkg/Drivers/CpuDxe/CpuDxe.c b/ArmPkg/Drivers/CpuDxe/CpuDxe.c
>> index d089cb2d119f..ddc64fd255a0 100644
>> --- a/ArmPkg/Drivers/CpuDxe/CpuDxe.c
>> +++ b/ArmPkg/Drivers/CpuDxe/CpuDxe.c
>> @@ -225,7 +225,7 @@ EFI_CPU_ARCH_PROTOCOL mCpu = {
>>CpuGetTimerValue,
>>CpuSetMemoryAttributes,
>>0,  // NumberOfTimers
>> -  4,  // DmaBufferAlignment
>> +  2048,   // DmaBufferAlignment
>>  };
>>
>>  EFI_STATUS
>> @@ -239,6 +239,8 @@ CpuDxeInitialize (
>>
>>InitializeExceptions ();
>>
>> +  mCpu.DmaBufferAlignment = ArmCacheWritebackGranule ();
>> +
>
> Could we hide the internal structure of mCpu here by moving this to a
> helper function and calling
>   InitializeDma ();
> (or something)?
>

We could, but why? The actual struct is defined 10 lines up
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH 1/5] EmbeddedPkg: introduce platform PCI I/O protocol

2016-11-02 Thread Ard Biesheuvel
On 1 November 2016 at 21:54, Leif Lindholm  wrote:
> On Mon, Oct 31, 2016 at 06:13:06PM +, Ard Biesheuvel wrote:
>> Introduce a protocol that can be exposed by a platform for devices that
>> can be driven by a PCI driver, (e.g., AHCI, XHCI), but do not live on a
>> PCI bus. This used to be called 'PCI emulation' but given that we only
>> emulate the PCI config space and nothing else, it tends to be a bit
>> confusing so this introduces the term 'platform PCI I/O' instead.
>>
>> Contributed-under: TianoCore Contribution Agreement 1.0
>> Signed-off-by: Ard Biesheuvel 
>> ---
>>  EmbeddedPkg/EmbeddedPkg.dec  |  1 +
>>  EmbeddedPkg/Include/Protocol/PlatformPciIo.h | 74 
>
> OK, so perhaps I should have commented on this already on 0/5, but I
> think this belongs in MdeModulePkg. The closest thing to an "embedded"
> user of this code is Juno.
>
>>  2 files changed, 75 insertions(+)
>>
>> diff --git a/EmbeddedPkg/EmbeddedPkg.dec b/EmbeddedPkg/EmbeddedPkg.dec
>> index 2c2cf41103c2..84a6f4d01077 100644
>> --- a/EmbeddedPkg/EmbeddedPkg.dec
>> +++ b/EmbeddedPkg/EmbeddedPkg.dec
>> @@ -69,6 +69,7 @@ [Protocols.common]
>>gAndroidFastbootPlatformProtocolGuid =  { 0x524685a0, 0x89a0, 0x11e3, 
>> {0x9d, 0x4d, 0xbf, 0xa9, 0xf6, 0xa4, 0x03, 0x08}}
>>gUsbDeviceProtocolGuid =  { 0x021bd2ca, 0x51d2, 0x11e3, {0x8e, 0x56, 
>> 0xb7, 0x54, 0x17, 0xc7,  0x0b, 0x44 }}
>>gPlatformGpioProtocolGuid = { 0x52ce9845, 0x5af4, 0x43e2, {0xba, 0xfd, 
>> 0x23, 0x08, 0x12, 0x54, 0x7a, 0xc2 }}
>> +  gPlatformPciIoProtocolGuid = { 0x0d51905b, 0xb77e, 0x452a, {0xa2, 0xc0, 
>> 0xec, 0xa0, 0xcc, 0x8d, 0x51, 0x4a }}
>>
>>  [PcdsFeatureFlag.common]
>>gEmbeddedTokenSpaceGuid.PcdEmbeddedMacBoot|FALSE|BOOLEAN|0x0001
>> diff --git a/EmbeddedPkg/Include/Protocol/PlatformPciIo.h 
>> b/EmbeddedPkg/Include/Protocol/PlatformPciIo.h
>> new file mode 100644
>> index ..a7bd584049ac
>> --- /dev/null
>> +++ b/EmbeddedPkg/Include/Protocol/PlatformPciIo.h
>> @@ -0,0 +1,74 @@
>> +/** @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.
>> +
>> +**/
>> +
>> +#ifndef __PLATFORM_PCI_IO_H__
>> +#define __PLATFORM_PCI_IO_H__
>> +
>> +#define PLATFORM_PCI_IO_PROTOCOL_GUID \
>> +  { 0x0d51905b, 0xb77e, 0x452a, {0xa2, 0xc0, 0xec, 0xa0, 0xcc, 0x8d, 0x51, 
>> 0x4a } }
>> +
>> +//
>> +// Protocol interface structure
>> +//
>> +typedef struct _PLATFORM_PCI_IO PLATFORM_PCI_IO;
>> +
>> +//
>> +// Data Types
>> +//
>> +typedef enum {
>> +  PlatformPciIoDeviceOhci,
>> +  PlatformPciIoDeviceUhci,
>> +  PlatformPciIoDeviceEhci,
>> +  PlatformPciIoDeviceXhci,
>> +  PlatformPciIoDeviceAhci,
>
> SdMmc and Ufs?
>

Indeed. I have added both: SDHCI works in QEMU but I can't really test UFS.
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH] ArmPkg/Library/ArmDmaLib: Deallocate Map buffer in case of error

2016-11-02 Thread Ryan Harkin
On 1 November 2016 at 17:58, Ryan Harkin  wrote:
> Hi Leif,
>
> Is this waiting for a Tested-by or something else?
>

Either way, I tested it on Juno R0/1/2 while I was testing the MAC
address change...


> Cheers,
> Ryan.
>
> On 23 September 2016 at 09:00, Ard Biesheuvel  
> wrote:
>> On 22 September 2016 at 23:37, Daniil Egranov  wrote:
>>> The patch is fixing memory leak in case of errors.
>>>
>>> Contributed-under: TianoCore Contribution Agreement 1.0
>>> Signed-off-by: Daniil Egranov 
>>
>> Reviewed-by: Ard Biesheuvel 
>>

Tested-by; Ryan Harkin 

>>> ---
>>>  ArmPkg/Library/ArmDmaLib/ArmDmaLib.c | 7 +--
>>>  1 file changed, 5 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c 
>>> b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c
>>> index d48d6ff..e0006c0 100644
>>> --- a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c
>>> +++ b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c
>>> @@ -90,14 +90,13 @@ DmaMap (
>>>  return  EFI_OUT_OF_RESOURCES;
>>>}
>>>
>>> -  *Mapping = Map;
>>> -
>>>if UINTN)HostAddress & (gCacheAlignment - 1)) != 0) ||
>>>((*NumberOfBytes & (gCacheAlignment - 1)) != 0)) {
>>>
>>>  // Get the cacheability of the region
>>>  Status = gDS->GetMemorySpaceDescriptor (*DeviceAddress, 
>>> );
>>>  if (EFI_ERROR(Status)) {
>>> +  FreePool(Map);
>>>return Status;
>>>  }
>>>
>>> @@ -112,6 +111,7 @@ DmaMap (
>>>"%a: Operation type 'MapOperationBusMasterCommonBuffer' is only 
>>> supported\n"
>>>"on memory regions that were allocated using DmaAllocateBuffer 
>>> ()\n",
>>>__FUNCTION__));
>>> +FreePool(Map);
>>>  return EFI_UNSUPPORTED;
>>>}
>>>
>>> @@ -122,6 +122,7 @@ DmaMap (
>>>Map->DoubleBuffer  = TRUE;
>>>Status = DmaAllocateBuffer (EfiBootServicesData, EFI_SIZE_TO_PAGES 
>>> (*NumberOfBytes), );
>>>if (EFI_ERROR (Status)) {
>>> +FreePool(Map);
>>>  return Status;
>>>}
>>>
>>> @@ -162,6 +163,8 @@ DmaMap (
>>>Map->NumberOfBytes = *NumberOfBytes;
>>>Map->Operation = Operation;
>>>
>>> +  *Mapping = Map;
>>> +
>>>return EFI_SUCCESS;
>>>  }
>>>
>>> --
>>> 2.7.4
>>>
>>> ___
>>> 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-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH] ArmPlatformPkg/ArmJunoPkg/Drivers/ArmJunoDxe: Set Marvell Yukon MAC address

2016-11-02 Thread Ryan Harkin
On 1 November 2016 at 21:05, Leif Lindholm  wrote:
> On Tue, Nov 01, 2016 at 05:55:11PM +, Ryan Harkin wrote:
>> Hi Daniil,
>>
>> While looking for another patch, I found this on the maillist...
>>
>> On 6 October 2016 at 02:42, Daniil Egranov  wrote:
>> > The patch reads a valid MAC address form the Juno IOFPGA registers
>> > and pushes it into onboard Marvell Yukon NIC.
>> >
>> > Contributed-under: TianoCore Contribution Agreement 1.0
>> > Signed-off-by: Daniil Egranov 

Tested on Juno R0/1/2.

Tested-by; Ryan Harkin 


>> > ---
>> >  .../ArmJunoPkg/Drivers/ArmJunoDxe/ArmJunoDxe.c | 141 
>> > +
>> >  .../Drivers/ArmJunoDxe/ArmJunoDxeInternal.h|  12 ++
>> >  2 files changed, 153 insertions(+)
>> >
>> > diff --git a/ArmPlatformPkg/ArmJunoPkg/Drivers/ArmJunoDxe/ArmJunoDxe.c 
>> > b/ArmPlatformPkg/ArmJunoPkg/Drivers/ArmJunoDxe/ArmJunoDxe.c
>> > index b97f044..0c5fbd0 100644
>> > --- a/ArmPlatformPkg/ArmJunoPkg/Drivers/ArmJunoDxe/ArmJunoDxe.c
>> > +++ b/ArmPlatformPkg/ArmJunoPkg/Drivers/ArmJunoDxe/ArmJunoDxe.c
>> > @@ -17,6 +17,8 @@
>> >
>> >  #include 
>> >  #include 
>> > +#include 
>> > +#include 
>> >
>> >  #include 
>> >  #include 
>> > @@ -68,6 +70,142 @@ STATIC CONST EFI_PCI_ROOT_BRIDGE_DEVICE_PATH 
>> > mPciRootComplexDevicePath = {
>> >
>> >  EFI_EVENT mAcpiRegistration = NULL;
>> >
>> > +UINT32 SwapUINT32(UINT32 value)
>> > +{
>> > +  value = ((value << 8) & 0xFF00FF00 ) | ((value >> 8) & 0xFF00FF );
>> > +  return (value << 16) | (value >> 16);
>> > +}
>> > +
>> > +/**
>> > +  The function reads MAC address from Juno IOFPGA registers and writes it
>> > +  into Marvell Yukon NIC.
>> > +**/
>> > +STATIC
>> > +EFI_STATUS
>> > +ArmJunoSetNetworkMAC()
>> > +{
>> > +
>> > +  EFI_STATUS  Status;
>> > +  UINTN   HandleCount;
>> > +  EFI_HANDLE  *HandleBuffer;
>> > +  UINTN   HIndex;
>> > +  EFI_PCI_IO_PROTOCOL*PciIo;
>> > +  UINT64  PciID;
>> > +  UINT32  MacHigh;
>> > +  UINT32  MacLow;
>> > +  UINT32  PciRegBase;
>> > +  UINT64  OldPciAttributes;
>> > +  UINT64  AttrSupports;
>> > +  UINT8   *PciBarAttributes;
>> > +
>> > +  Status = gBS->LocateHandleBuffer (ByProtocol,
>> > +,
>> > +NULL, , );
>> > +
>> > +  if (!EFI_ERROR (Status)) {
>> > +for (HIndex = 0; HIndex < HandleCount; ++HIndex) {
>> > +  Status = gBS->OpenProtocol (
>> > +  HandleBuffer[HIndex],
>> > +  ,
>> > +  (VOID **) ,
>> > +  NULL,
>> > +  NULL,
>> > +  EFI_OPEN_PROTOCOL_GET_PROTOCOL);
>> > +
>> > +  if (EFI_ERROR (Status)) {
>> > +continue;
>> > +  }
>> > +
>> > +  Status = PciIo->Pci.Read (
>> > +PciIo,
>> > +EfiPciIoWidthUint32,
>> > +PCI_VENDOR_ID_OFFSET,
>> > +1,
>> > +
>> > +);
>> > +
>> > +  if (EFI_ERROR (Status)) {
>> > +continue;
>> > +  }
>> > +
>> > +  if ((PciID & 0x) == JUNO_MARVELL_YUKON_ID) {
>> > +
>> > +// Read MAC address from IOFPGA
>> > +MacHigh= MmioRead32 (ARM_JUNO_SYS_PCIGBE_H);
>> > +MacLow = MmioRead32 (ARM_JUNO_SYS_PCIGBE_L);
>> > +
>> > +Status = PciIo->Attributes (
>> > +  PciIo,
>> > +  EfiPciIoAttributeOperationGet,
>> > +  0,
>> > +  
>> > +  );
>> > +
>> > +if (EFI_ERROR (Status)) {
>> > +  continue;
>> > +}
>> > +
>> > +Status = PciIo->Attributes (
>> > +  PciIo,
>> > +  EfiPciIoAttributeOperationSupported,
>> > +  0,
>> > +  
>> > +  );
>> > +
>> > +if (!EFI_ERROR (Status)) {
>> > +  AttrSupports &= EFI_PCI_DEVICE_ENABLE;
>> > +  Status = PciIo->Attributes (
>> > +PciIo,
>> > +EfiPciIoAttributeOperationEnable,
>> > +AttrSupports,
>> > +NULL
>> > +);
>> > +
>> > +  Status = PciIo->GetBarAttributes (PciIo, 0, , 
>> > (VOID**));
>> > +  if (!EFI_ERROR (Status) && (((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR 
>> > *)PciBarAttributes)->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR)) {
>> > +if (((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR 
>> > *)PciBarAttributes)->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM) {
>> > +  if (!(((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR 
>> > *)PciBarAttributes)->SpecificFlag & ACPI_SPECFLAG_PREFETCHABLE)) {
>> > +

Re: [edk2] OvmfPkg: hang in SetInterruptState with git 245cda6641ade1f1013c2d5c9c838f2706636828

2016-11-02 Thread Laszlo Ersek
On 11/01/16 17:02, Bruce Cran wrote:
> On 10/18/2016 1:43 AM, Laszlo Ersek wrote:
>> On 10/18/16 02:06, Bruce Cran wrote:
>>> I've just built both OVMF _and_ Qemu from the latest git sources, so I
>>> don't know which is at fault - but I'm seeing a hang in:
>>>
>>> #0  0x7f9dc030 in SetInterruptState (InterruptState=104 'h')
>>>  at /home/bcran/workspace/edk2/MdePkg/Library/BaseLib/Cpu.c:60
>>>
>>> It's at line 60 when it calls EnableInterrupts().
>> Introduced when? :)
>>
>> It's been a while since we committed anything to OvmfPkg that could
>> cause this. Similarly, I don't recall anything risky like this going
>> into UefiCpuPkg. I rebuild OVMF every few days, against current master,
>> and I'm not seeing this. (Just retested at aaba2a44c24e.)
> 
> Just to follow up, I've just got around to re-trying it after a couple
> of weeks of new OpenSUSE Tumleweed kernels coming through, along with a
> new build of qemu and OVMF - and the problem has disappeared.
> 

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


Re: [edk2] [PATCH] MdePkg/BaseLib: Re-define CHAR_NULL in BaseLib

2016-11-02 Thread Gao, Liming
Bin:
  I suggest move CHAR_NULL definition from Protocol\SimpleTextIn.h to Base.h

Thanks
Liming
-Original Message-
From: Song, BinX 
Sent: Wednesday, November 2, 2016 4:27 PM
To: edk2-devel@lists.01.org
Cc: Gao, Liming 
Subject: [PATCH] MdePkg/BaseLib: Re-define CHAR_NULL in BaseLib

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

Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Bell Song 
---
 MdePkg/Include/Base.h  | 7 +++
 MdePkg/Library/BaseLib/FilePaths.c | 2 --
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h
index 2217058..0c3318f 100644
--- a/MdePkg/Include/Base.h
+++ b/MdePkg/Include/Base.h
@@ -338,6 +338,13 @@ struct _LIST_ENTRY {
 ///
 #define NULL  ((VOID *) 0)
 
+//
+// Required unicode control chars
+//
+#ifndef CHAR_NULL
+#define CHAR_NULL  0x
+#endif
+
 ///
 /// Maximum values for common UEFI Data Types
 ///
diff --git a/MdePkg/Library/BaseLib/FilePaths.c 
b/MdePkg/Library/BaseLib/FilePaths.c
index c8da6bb..183b323 100644
--- a/MdePkg/Library/BaseLib/FilePaths.c
+++ b/MdePkg/Library/BaseLib/FilePaths.c
@@ -10,10 +10,8 @@
   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  
 
 /**
   Removes the last directory or file entry in a path by changing the last
-- 
2.7.2.windows.1

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


Re: [edk2] [Patch] CryptoPkg: Add HMAC-SHA256 cipher support

2016-11-02 Thread Ye, Ting
Looks good to me.
Reviewed-by: Ye Ting  

-Original Message-
From: Long, Qin 
Sent: Monday, October 31, 2016 4:30 PM
To: edk2-devel@lists.01.org
Cc: Ye, Ting 
Subject: [Patch] CryptoPkg: Add HMAC-SHA256 cipher support

Add new HMAC-SHA256 cipher support in CryptoPkg to meet more security and 
industry requirements,

and update Cryptest utility to include new HMAC-SHA256 test case.

Cc: Ting Ye 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Qin Long 
---
 CryptoPkg/Application/Cryptest/HmacVerify.c|  61 ++-
 CryptoPkg/Include/Library/BaseCryptLib.h   | 118 
 CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf|   3 +-
 .../Library/BaseCryptLib/Hmac/CryptHmacSha256.c| 197 +
 .../BaseCryptLib/Hmac/CryptHmacSha256Null.c| 127 +
 CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf |   5 +-
 CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf |   5 +-
 CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf |   3 +-
 8 files changed, 510 insertions(+), 9 deletions(-)  create mode 100644 
CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmacSha256.c
 create mode 100644 CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmacSha256Null.c

diff --git a/CryptoPkg/Application/Cryptest/HmacVerify.c 
b/CryptoPkg/Application/Cryptest/HmacVerify.c
index 73b38f3..9a91295 100644
--- a/CryptoPkg/Application/Cryptest/HmacVerify.c
+++ b/CryptoPkg/Application/Cryptest/HmacVerify.c
@@ -1,7 +1,7 @@
 /** @file  
   Application for HMAC Primitives Validation.
 
-Copyright (c) 2010, Intel Corporation. All rights reserved.
+Copyright (c) 2010 - 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 @@ -54,6 +54,22 @@ 
GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 HmacSha1Digest[] = {
   0xf1, 0x46, 0xbe, 0x00
   };
 
+//
+// Key value for HMAC-SHA-256 validation. (From "4. Test Vectors" of 
+IETF RFC4231) // GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 
+HmacSha256Key[20] = {
+  0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 
+0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
+  0x0b, 0x0b, 0x0b, 0x0b
+  };
+
+//
+// Result for HMAC-SHA-256 ("Hi There"). (From "4. Test Vectors" of 
+IETF RFC4231) // GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 
+HmacSha256Digest[] = {
+  0xb0, 0x34, 0x4c, 0x61, 0xd8, 0xdb, 0x38, 0x53, 0x5c, 0xa8, 0xaf, 
+0xce, 0xaf, 0x0b, 0xf1, 0x2b,
+  0x88, 0x1d, 0xc2, 0x00, 0xc9, 0x83, 0x3d, 0xa7, 0x26, 0xe9, 0x37, 
+0x6c, 0x2e, 0x32, 0xcf, 0xf7
+  };
+
 /**
   Validate UEFI-OpenSSL Message Authentication Codes Interfaces.
 
@@ -73,7 +89,7 @@ ValidateCryptHmac (
 
   Print (L" \nUEFI-OpenSSL HMAC Engine Testing:\n");
 
-  Print (L"- HMAC-MD5:  ");
+  Print (L"- HMAC-MD5:");
 
   //
   // HMAC-MD5 Digest Validation
@@ -113,7 +129,7 @@ ValidateCryptHmac (
 
   Print (L"[Pass]\n");
 
-  Print (L"- HMAC-SHA1: ");
+  Print (L"- HMAC-SHA1:   ");
 
   //
   // HMAC-SHA1 Digest Validation
@@ -153,5 +169,44 @@ ValidateCryptHmac (
 
   Print (L"[Pass]\n");
 
+  Print (L"- HMAC-SHA256: ");
+  //
+  // HMAC-SHA-256 Digest Validation
+  //
+  ZeroMem (Digest, MAX_DIGEST_SIZE);
+  CtxSize = HmacSha256GetContextSize ();  HmacCtx = AllocatePool 
+ (CtxSize);
+
+  Print (L"Init... ");
+  Status  = HmacSha256Init (HmacCtx, HmacSha256Key, sizeof 
+ (HmacSha256Key));  if (!Status) {
+Print (L"[Fail]");
+return EFI_ABORTED;
+  }
+
+  Print (L"Update... ");
+  Status  = HmacSha256Update (HmacCtx, HmacData, 8);  if (!Status) {
+Print (L"[Fail]");
+return EFI_ABORTED;
+  }
+
+  Print (L"Finalize... ");
+  Status  = HmacSha256Final (HmacCtx, Digest);  if (!Status) {
+Print (L"[Fail]");
+return EFI_ABORTED;
+  }
+
+  FreePool (HmacCtx);
+
+  Print (L"Check Value... ");
+  if (CompareMem (Digest, HmacSha256Digest, SHA256_DIGEST_SIZE) != 0) {
+Print (L"[Fail]");
+return EFI_ABORTED;
+  }
+
+  Print (L"[Pass]\n");
+
   return EFI_SUCCESS;
 }
diff --git a/CryptoPkg/Include/Library/BaseCryptLib.h 
b/CryptoPkg/Include/Library/BaseCryptLib.h
index 3463626..9693793 100644
--- a/CryptoPkg/Include/Library/BaseCryptLib.h
+++ b/CryptoPkg/Include/Library/BaseCryptLib.h
@@ -1131,6 +1131,124 @@ HmacSha1Final (
   OUT UINT8  *HmacValue
   );
 
+/**
+  Retrieves the size, in bytes, of the context buffer required for HMAC-SHA256 
operations.
+
+  If this interface is not supported, then return zero.
+
+  @return  The size, in bytes, of the context buffer required for HMAC-SHA256 
operations.
+  @retval  0   This interface is not supported.
+
+**/
+UINTN
+EFIAPI
+HmacSha256GetContextSize (
+  VOID
+  );
+
+/**
+  Initializes user-supplied memory pointed by HmacSha256Context as 
+HMAC-SHA256 context for
+  subsequent use.
+
+  If HmacSha256Context is NULL, then return 

Re: [edk2] [Patch] CryptoPkg: Add PKCS5 PBKDF2 interface for password derivation.

2016-11-02 Thread Ye, Ting
Looks good to me.
Reviewed-by: Ye Ting 


-Original Message-
From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Qin Long
Sent: Tuesday, November 01, 2016 10:59 AM
To: edk2-devel@lists.01.org
Cc: Ye, Ting 
Subject: [edk2] [Patch] CryptoPkg: Add PKCS5 PBKDF2 interface for password 
derivation.

Add one new API (Pkcs5HashPassword) to provide PKCS#5 v2.0 PBKDF2 support 
(Password based encryption key derivation function, specified in RFC 2898).
Also update the Cryptest utility to include the new API testing (with the test 
vector from RFC6070).

Cc: Ting Ye 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Qin Long 
---
 CryptoPkg/Application/Cryptest/Cryptest.c  |   9 +-
 CryptoPkg/Application/Cryptest/Cryptest.h  |  16 +++-
 CryptoPkg/Application/Cryptest/Cryptest.inf|   5 +-
 CryptoPkg/Application/Cryptest/Pkcs5Pbkdf2Verify.c |  94 +++
 CryptoPkg/Include/Library/BaseCryptLib.h   |  40 
 CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf|   1 +
 CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf |   1 +
 .../Library/BaseCryptLib/Pk/CryptPkcs5Pbkdf2.c | 101 +
 .../Library/BaseCryptLib/Pk/CryptPkcs5Pbkdf2Null.c |  56 
 CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf |   1 +
 CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf |   1 +
 11 files changed, 319 insertions(+), 6 deletions(-)  create mode 100644 
CryptoPkg/Application/Cryptest/Pkcs5Pbkdf2Verify.c
 create mode 100644 CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs5Pbkdf2.c
 create mode 100644 CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs5Pbkdf2Null.c

diff --git a/CryptoPkg/Application/Cryptest/Cryptest.c 
b/CryptoPkg/Application/Cryptest/Cryptest.c
index 79c1850..13b7073 100644
--- a/CryptoPkg/Application/Cryptest/Cryptest.c
+++ b/CryptoPkg/Application/Cryptest/Cryptest.c
@@ -1,7 +1,7 @@
 /** @file
   Application for Cryptographic Primitives Validation.
 
-Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.
+Copyright (c) 2009 - 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 @@ -63,6 +63,11 @@ 
CryptestMain (
 return Status;
   }
 
+  Status = ValidateCryptPkcs5Pbkdf2 ();  if (EFI_ERROR (Status)) {
+return Status;
+  }
+
   Status = ValidateCryptPkcs7 ();
   if (EFI_ERROR (Status)) {
 return Status;
@@ -89,4 +94,4 @@ CryptestMain (
   }
 
   return EFI_SUCCESS;
-}
\ No newline at end of file
+}
diff --git a/CryptoPkg/Application/Cryptest/Cryptest.h 
b/CryptoPkg/Application/Cryptest/Cryptest.h
index 17b4224..9e3e0fb 100644
--- a/CryptoPkg/Application/Cryptest/Cryptest.h
+++ b/CryptoPkg/Application/Cryptest/Cryptest.h
@@ -1,7 +1,7 @@
 /** @file
   Application for Cryptographic Primitives Validation.
 
-Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.
+Copyright (c) 2009 - 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 @@ -85,6 +85,18 @@ 
ValidateCryptRsa2 (
   );
 
 /**
+  Validate UEFI-OpenSSL PKCS#5 PBKDF2 Interface.
+
+  @retval  EFI_SUCCESS  Validation succeeded.
+  @retval  EFI_ABORTED  Validation failed.
+
+**/
+EFI_STATUS
+ValidateCryptPkcs5Pbkdf2 (
+  VOID
+  );
+
+/**
   Validate UEFI-OpenSSL PKCS#7 Signing & Verification Interfaces.
 
   @retval  EFI_SUCCESS  Validation succeeded.
@@ -144,4 +156,4 @@ ValidateCryptPrng (
   VOID
   );
 
-#endif
\ No newline at end of file
+#endif
diff --git a/CryptoPkg/Application/Cryptest/Cryptest.inf 
b/CryptoPkg/Application/Cryptest/Cryptest.inf
index 11175e5..b7f779c 100644
--- a/CryptoPkg/Application/Cryptest/Cryptest.inf
+++ b/CryptoPkg/Application/Cryptest/Cryptest.inf
@@ -1,9 +1,9 @@
 ## @file
 #  Shell application that will test the crypto library.
 #
-#  UEFI Application for the Validation of cryptography library (based on 
OpenSSL 0.9.8zb).
+#  UEFI Application for the Validation of cryptography library (based on 
OpenSSL-1.0.2j).
 #
-#  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.
+#  Copyright (c) 2009 - 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 @@ 
-37,6 +37,7 @@
   BlockCipherVerify.c
   RsaVerify.c
   RsaVerify2.c
+  Pkcs5Pbkdf2Verify.c
   AuthenticodeVerify.c
   TSVerify.c
   DhVerify.c
diff --git a/CryptoPkg/Application/Cryptest/Pkcs5Pbkdf2Verify.c 

[edk2] [PATCH] MdePkg/BaseLib: Re-define CHAR_NULL in BaseLib

2016-11-02 Thread Song, BinX
- https://bugzilla.tianocore.org/show_bug.cgi?id=172

Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Bell Song 
---
 MdePkg/Include/Base.h  | 7 +++
 MdePkg/Library/BaseLib/FilePaths.c | 2 --
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h
index 2217058..0c3318f 100644
--- a/MdePkg/Include/Base.h
+++ b/MdePkg/Include/Base.h
@@ -338,6 +338,13 @@ struct _LIST_ENTRY {
 ///
 #define NULL  ((VOID *) 0)
 
+//
+// Required unicode control chars
+//
+#ifndef CHAR_NULL
+#define CHAR_NULL  0x
+#endif
+
 ///
 /// Maximum values for common UEFI Data Types
 ///
diff --git a/MdePkg/Library/BaseLib/FilePaths.c 
b/MdePkg/Library/BaseLib/FilePaths.c
index c8da6bb..183b323 100644
--- a/MdePkg/Library/BaseLib/FilePaths.c
+++ b/MdePkg/Library/BaseLib/FilePaths.c
@@ -10,10 +10,8 @@
   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  
 
 /**
   Removes the last directory or file entry in a path by changing the last
-- 
2.7.2.windows.1

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


Re: [edk2] [PATCH V5 06/12] SignedCapsulePkg/CapsulePkg.dec: Add capsule related definition.

2016-11-02 Thread Yao, Jiewen
If the board layout is different, we can use different FileGuid in the 
config.ini file.

The format is defined in 
SignedCapsulePkg\Universal\SystemFirmwareUpdate\ParseConfigProfile.c

  [Head]
  NumOfUpdate =  # Decimal
  Update0 =# String
  Update1 =# String
  Update =  # String

  [Name?]
  FirmwareType = 0   # 0 - SystemFirmware, 1 - NvRam
  AddressType = 0# 0 - relative address, 1 - absolute address.
  BaseAddress = # Base address offset on flash (HEX)
  Length  =  # Image Length (HEX)
  ImageOffset = # Image offset of this SystemFirmware image 
(HEX)
  FileGuid= ----  # 
PcdEdkiiSystemFirmwareFileGuid

So the OEM can use below:

  [Head]
  NumOfUpdate = 2 # Decimal
  Update0 = ROM1   # String
  Update1 = ROM2   # String

  [ROM1]
  FirmwareType = 0   # 0 - SystemFirmware, 1 - NvRam
  AddressType = 0# 0 - relative address, 1 - absolute address.
  BaseAddress = # Base address offset on flash (HEX)
  Length  =  # Image Length (HEX)
  ImageOffset = # Image offset of this SystemFirmware image 
(HEX)
  FileGuid= SystemFirmwareFileGuid1   # PcdEdkiiSystemFirmwareFileGuid

  [ROM2]
  FirmwareType = 0   # 0 - SystemFirmware, 1 - NvRam
  AddressType = 0# 0 - relative address, 1 - absolute address.
  BaseAddress = # Base address offset on flash (HEX)
  Length  =  # Image Length (HEX)
  ImageOffset = # Image offset of this SystemFirmware image 
(HEX)
  FileGuid= SystemFirmwareFileGuid2   # PcdEdkiiSystemFirmwareFileGuid

Then it will be filtered by UpdateImage().

if (IsZeroGuid(>ImageTypeId) || 
CompareGuid(>ImageTypeId, )) {
  Status = PerformUpdate (
 SystemFirmwareImage,
 SystemFirmwareImageSize,
 UpdateConfigData,
 LastAttemptVersion,
 LastAttemptStatus
 );




From: Yao, Jiewen
Sent: Wednesday, November 2, 2016 3:02 PM
To: Kinney, Michael D ; edk2-devel@lists.01.org
Cc: Tian, Feng ; Zeng, Star ; Gao, 
Liming ; Zhang, Chao B 
Subject: RE: [PATCH V5 06/12] SignedCapsulePkg/CapsulePkg.dec: Add capsule 
related definition.

Yes. You are right.

From: Kinney, Michael D
Sent: Wednesday, November 2, 2016 2:17 PM
To: Yao, Jiewen >; 
edk2-devel@lists.01.org; Kinney, Michael D 
>
Cc: Tian, Feng >; Zeng, Star 
>; Gao, Liming 
>; Zhang, Chao B 
>
Subject: RE: [PATCH V5 06/12] SignedCapsulePkg/CapsulePkg.dec: Add capsule 
related definition.

Jiewen,

I did think about your use case some more.  It does require that multiple 
boards uses the exact same nvstorage layout using the same INI file and same 
System Firmware Update driver.  If the boards have different nvstorage layout 
or require different PlatformFlashAccessLib instances to update nvstorage than 
each board would require its own capsule.

Mike

From: Kinney, Michael D
Sent: Tuesday, November 1, 2016 8:41 PM
To: Yao, Jiewen >; 
edk2-devel@lists.01.org; Kinney, Michael D 
>
Cc: Tian, Feng >; Zeng, Star 
>; Gao, Liming 
>; Zhang, Chao B 
>
Subject: RE: [PATCH V5 06/12] SignedCapsulePkg/CapsulePkg.dec: Add capsule 
related definition.

Jiewen,

Thanks for providing the detailed use case.  That makes a lot of sense.  I 
agree we should keep current design with a PCD that is one FFS file GUID.

Thanks,

Mike

From: Yao, Jiewen
Sent: Tuesday, November 1, 2016 7:04 PM
To: Kinney, Michael D 
>; 
edk2-devel@lists.01.org
Cc: Tian, Feng >; Zeng, Star 
>; Gao, Liming 
>; Zhang, Chao B 
>
Subject: RE: [PATCH V5 06/12] SignedCapsulePkg/CapsulePkg.dec: Add capsule 
related definition.

Yes, this PCD is a single FFS GUID.

A real example blow:
The Capsule may contain below data:
FILE RAW = SystemFirmwareFileGuid1 { # PcdEdkiiSystemFirmwareFileGuid


Re: [edk2] [PATCH v2] CryptoPkg: Add xxxxHashAll APIs to facilitate the digest computation

2016-11-02 Thread Ye, Ting
Reviewed-by: Ye Ting  

-Original Message-
From: Long, Qin 
Sent: Tuesday, November 01, 2016 10:34 AM
To: edk2-devel@lists.01.org
Cc: Ye, Ting 
Subject: [PATCH v2] CryptoPkg: Add HashAll APIs to facilitate the digest 
computation

Add new HashAll APIs to facilitate the digest computation of blob data. New 
APIs include: Md4HashAll(), Md5HashAll(), Sha1HashAll(), Sha256HashAll(), 
Sha384HashAll(), and Sha512HashAll().

The corresponding test cases were added in Cryptest utility.

Cc: Ting Ye 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Qin Long 
---
 CryptoPkg/Application/Cryptest/HashVerify.c|  76 +-
 CryptoPkg/Include/Library/BaseCryptLib.h   | 158 -
 CryptoPkg/Library/BaseCryptLib/Hash/CryptMd4.c |  48 ++-
 CryptoPkg/Library/BaseCryptLib/Hash/CryptMd4Null.c |  27 +++-
 CryptoPkg/Library/BaseCryptLib/Hash/CryptMd5.c |  48 ++-
 CryptoPkg/Library/BaseCryptLib/Hash/CryptSha1.c|  48 ++-
 CryptoPkg/Library/BaseCryptLib/Hash/CryptSha256.c  |  48 ++-  
CryptoPkg/Library/BaseCryptLib/Hash/CryptSha512.c  |  94 +++-
 .../Library/BaseCryptLib/Hash/CryptSha512Null.c|  52 ++-
 9 files changed, 589 insertions(+), 10 deletions(-)

diff --git a/CryptoPkg/Application/Cryptest/HashVerify.c 
b/CryptoPkg/Application/Cryptest/HashVerify.c
index ca64361..a35cad5 100644
--- a/CryptoPkg/Application/Cryptest/HashVerify.c
+++ b/CryptoPkg/Application/Cryptest/HashVerify.c
@@ -1,7 +1,7 @@
 /** @file
   Application for Hash Primitives Validation.
 
-Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.
+Copyright (c) 2010 - 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 @@ -127,7 +127,19 
@@ ValidateCryptDigest (
   FreePool (HashCtx);
 
   Print (L"Check Value... ");
-  if (CompareMem (Digest, Md4Digest, MD5_DIGEST_SIZE) != 0) {
+  if (CompareMem (Digest, Md4Digest, MD4_DIGEST_SIZE) != 0) {
+Print (L"[Fail]");
+return EFI_ABORTED;
+  }
+
+  Print (L"HashAll... ");
+  ZeroMem (Digest, MD5_DIGEST_SIZE);
+  Status  = Md4HashAll (HashData, DataSize, Digest);  if (!Status) {
+Print (L"[Fail]");
+return EFI_ABORTED;
+  }
+  if (CompareMem (Digest, Md4Digest, MD4_DIGEST_SIZE) != 0) {
 Print (L"[Fail]");
 return EFI_ABORTED;
   }
@@ -172,6 +184,18 @@ ValidateCryptDigest (
 return EFI_ABORTED;
   }
 
+  Print (L"HashAll... ");
+  ZeroMem (Digest, MD5_DIGEST_SIZE);
+  Status  = Md5HashAll (HashData, DataSize, Digest);  if (!Status) {
+Print (L"[Fail]");
+return EFI_ABORTED;
+  }
+  if (CompareMem (Digest, Md5Digest, MD5_DIGEST_SIZE) != 0) {
+Print (L"[Fail]");
+return EFI_ABORTED;
+  }
+
   Print (L"[Pass]\n");
 
   Print (L"- SHA1:   ");
@@ -212,6 +236,18 @@ ValidateCryptDigest (
 return EFI_ABORTED;
   }
 
+  Print (L"HashAll... ");
+  ZeroMem (Digest, SHA1_DIGEST_SIZE);
+  Status  = Sha1HashAll (HashData, DataSize, Digest);  if (!Status) {
+Print (L"[Fail]");
+return EFI_ABORTED;
+  }
+  if (CompareMem (Digest, Sha1Digest, SHA1_DIGEST_SIZE) != 0) {
+Print (L"[Fail]");
+return EFI_ABORTED;
+  }
+
   Print (L"[Pass]\n");
 
   Print (L"- SHA256: ");
@@ -252,6 +288,18 @@ ValidateCryptDigest (
 return EFI_ABORTED;
   }
 
+  Print (L"HashAll... ");
+  ZeroMem (Digest, SHA256_DIGEST_SIZE);  Status  = Sha256HashAll 
+ (HashData, DataSize, Digest);  if (!Status) {
+Print (L"[Fail]");
+return EFI_ABORTED;
+  }
+  if (CompareMem (Digest, Sha256Digest, SHA256_DIGEST_SIZE) != 0) {
+Print (L"[Fail]");
+return EFI_ABORTED;
+  }
+
   Print (L"[Pass]\n");
 
   Print (L"- SHA384: ");
@@ -292,6 +340,18 @@ ValidateCryptDigest (
 return EFI_ABORTED;
   }
 
+  Print (L"HashAll... ");
+  ZeroMem (Digest, SHA384_DIGEST_SIZE);  Status  = Sha384HashAll 
+ (HashData, DataSize, Digest);  if (!Status) {
+Print (L"[Fail]");
+return EFI_ABORTED;
+  }
+  if (CompareMem (Digest, Sha384Digest, SHA384_DIGEST_SIZE) != 0) {
+Print (L"[Fail]");
+return EFI_ABORTED;
+  }
+
   Print (L"[Pass]\n");
 
   Print (L"- SHA512: ");
@@ -332,6 +392,18 @@ ValidateCryptDigest (
 return EFI_ABORTED;
   }
 
+  Print (L"HashAll... ");
+  ZeroMem (Digest, SHA512_DIGEST_SIZE);  Status  = Sha512HashAll 
+ (HashData, DataSize, Digest);  if (!Status) {
+Print (L"[Fail]");
+return EFI_ABORTED;
+  }
+  if (CompareMem (Digest, Sha512Digest, SHA512_DIGEST_SIZE) != 0) {
+Print (L"[Fail]");
+return EFI_ABORTED;
+  }
+
   Print (L"[Pass]\n");
 
   return EFI_SUCCESS;
diff --git a/CryptoPkg/Include/Library/BaseCryptLib.h 
b/CryptoPkg/Include/Library/BaseCryptLib.h
index 0371d73..3463626 100644
--- a/CryptoPkg/Include/Library/BaseCryptLib.h
+++ 

Re: [edk2] [PATCH V5 06/12] SignedCapsulePkg/CapsulePkg.dec: Add capsule related definition.

2016-11-02 Thread Yao, Jiewen
Yes. You are right.

From: Kinney, Michael D
Sent: Wednesday, November 2, 2016 2:17 PM
To: Yao, Jiewen ; edk2-devel@lists.01.org; Kinney, 
Michael D 
Cc: Tian, Feng ; Zeng, Star ; Gao, 
Liming ; Zhang, Chao B 
Subject: RE: [PATCH V5 06/12] SignedCapsulePkg/CapsulePkg.dec: Add capsule 
related definition.

Jiewen,

I did think about your use case some more.  It does require that multiple 
boards uses the exact same nvstorage layout using the same INI file and same 
System Firmware Update driver.  If the boards have different nvstorage layout 
or require different PlatformFlashAccessLib instances to update nvstorage than 
each board would require its own capsule.

Mike

From: Kinney, Michael D
Sent: Tuesday, November 1, 2016 8:41 PM
To: Yao, Jiewen >; 
edk2-devel@lists.01.org; Kinney, Michael D 
>
Cc: Tian, Feng >; Zeng, Star 
>; Gao, Liming 
>; Zhang, Chao B 
>
Subject: RE: [PATCH V5 06/12] SignedCapsulePkg/CapsulePkg.dec: Add capsule 
related definition.

Jiewen,

Thanks for providing the detailed use case.  That makes a lot of sense.  I 
agree we should keep current design with a PCD that is one FFS file GUID.

Thanks,

Mike

From: Yao, Jiewen
Sent: Tuesday, November 1, 2016 7:04 PM
To: Kinney, Michael D 
>; 
edk2-devel@lists.01.org
Cc: Tian, Feng >; Zeng, Star 
>; Gao, Liming 
>; Zhang, Chao B 
>
Subject: RE: [PATCH V5 06/12] SignedCapsulePkg/CapsulePkg.dec: Add capsule 
related definition.

Yes, this PCD is a single FFS GUID.

A real example blow:
The Capsule may contain below data:
FILE RAW = SystemFirmwareFileGuid1 { # PcdEdkiiSystemFirmwareFileGuid

$(WORKSPACE)/$(OUTPUT_DIRECTORY)/$(TARGET)_$(TOOL_CHAIN_TAG)/FV/BIOS_BOARD1.ROM
  }

FILE RAW = SystemFirmwareFileGuid2 { # PcdEdkiiSystemFirmwareFileGuid
$(WORKSPACE)/$(OUTPUT_DIRECTORY)/$(TARGET)_$(TOOL_CHAIN_TAG)/FV/ 
BIOS_BOARD2.ROM
  }

FILE RAW = ce57b167-b0e4-41e8-a897-5f4feb781d40 { # 
gEdkiiSystemFmpCapsuleDriverFvFileGuid

$(WORKSPACE)/$(OUTPUT_DIRECTORY)/$(TARGET)_$(TOOL_CHAIN_TAG)/FV/CAPSULEDISPATCHFV.Fv
## It contains a generic SystemFirmwareUpdate.efi
  }

FILE RAW = 812136D3-4D3A-433A-9418-29BB9BF78F6E { # 
gEdkiiSystemFmpCapsuleConfigFileGuid

PlatformPkg/Feature/Capsule/SystemFirmwareUpdateConfig/SystemFirmwareUpdateConfig.ini
  }
During system boot, if current BIOS is BOARD1.ROM, it sets 
PcdEdkiiSystemFirmwareFileGuid to be SystemFirmwareFileGuid1.
if current BIOS is BOARD2.ROM, it sets PcdEdkiiSystemFirmwareFileGuid to be 
SystemFirmwareFileGuid2.

The generic SystemFirmwareUpdate.efi can determine which ROM should be used for 
current firmware.

The benefit is that the OEM can provide one big capsule contains multiple ROM 
images, which can be used for multiple boards.


Thank you
Yao Jiewen


From: Kinney, Michael D
Sent: Wednesday, November 2, 2016 9:10 AM
To: Yao, Jiewen >; 
edk2-devel@lists.01.org; Kinney, Michael D 
>
Cc: Tian, Feng >; Zeng, Star 
>; Gao, Liming 
>; Zhang, Chao B 
>
Subject: RE: [PATCH V5 06/12] SignedCapsulePkg/CapsulePkg.dec: Add capsule 
related definition.

Jiewen,

The description of this PCD says it is a single FFS file GUID.

How would multiple FFS files with data contents be supported with the INI file 
format used in these FMP patch series?

Mike

From: Yao, Jiewen
Sent: Tuesday, November 1, 2016 5:46 PM
To: Kinney, Michael D 
>; 
edk2-devel@lists.01.org
Cc: Tian, Feng >; Zeng, Star 
>; Gao, Liming 
>; Zhang, Chao B 
>
Subject: RE: [PATCH V5 06/12] SignedCapsulePkg/CapsulePkg.dec: Add capsule 
related definition.


1)  That is a good question.

We designed to use PCD instead of fixed GUID 

Re: [edk2] [PATCH V5 06/12] SignedCapsulePkg/CapsulePkg.dec: Add capsule related definition.

2016-11-02 Thread Kinney, Michael D
Jiewen,

I did think about your use case some more.  It does require that multiple 
boards uses the exact same nvstorage layout using the same INI file and same 
System Firmware Update driver.  If the boards have different nvstorage layout 
or require different PlatformFlashAccessLib instances to update nvstorage than 
each board would require its own capsule.

Mike

From: Kinney, Michael D
Sent: Tuesday, November 1, 2016 8:41 PM
To: Yao, Jiewen ; edk2-devel@lists.01.org; Kinney, 
Michael D 
Cc: Tian, Feng ; Zeng, Star ; Gao, 
Liming ; Zhang, Chao B 
Subject: RE: [PATCH V5 06/12] SignedCapsulePkg/CapsulePkg.dec: Add capsule 
related definition.

Jiewen,

Thanks for providing the detailed use case.  That makes a lot of sense.  I 
agree we should keep current design with a PCD that is one FFS file GUID.

Thanks,

Mike

From: Yao, Jiewen
Sent: Tuesday, November 1, 2016 7:04 PM
To: Kinney, Michael D 
>; 
edk2-devel@lists.01.org
Cc: Tian, Feng >; Zeng, Star 
>; Gao, Liming 
>; Zhang, Chao B 
>
Subject: RE: [PATCH V5 06/12] SignedCapsulePkg/CapsulePkg.dec: Add capsule 
related definition.

Yes, this PCD is a single FFS GUID.

A real example blow:
The Capsule may contain below data:
FILE RAW = SystemFirmwareFileGuid1 { # PcdEdkiiSystemFirmwareFileGuid

$(WORKSPACE)/$(OUTPUT_DIRECTORY)/$(TARGET)_$(TOOL_CHAIN_TAG)/FV/BIOS_BOARD1.ROM
  }

FILE RAW = SystemFirmwareFileGuid2 { # PcdEdkiiSystemFirmwareFileGuid
$(WORKSPACE)/$(OUTPUT_DIRECTORY)/$(TARGET)_$(TOOL_CHAIN_TAG)/FV/ 
BIOS_BOARD2.ROM
  }

FILE RAW = ce57b167-b0e4-41e8-a897-5f4feb781d40 { # 
gEdkiiSystemFmpCapsuleDriverFvFileGuid

$(WORKSPACE)/$(OUTPUT_DIRECTORY)/$(TARGET)_$(TOOL_CHAIN_TAG)/FV/CAPSULEDISPATCHFV.Fv
## It contains a generic SystemFirmwareUpdate.efi
  }

FILE RAW = 812136D3-4D3A-433A-9418-29BB9BF78F6E { # 
gEdkiiSystemFmpCapsuleConfigFileGuid

PlatformPkg/Feature/Capsule/SystemFirmwareUpdateConfig/SystemFirmwareUpdateConfig.ini
  }
During system boot, if current BIOS is BOARD1.ROM, it sets 
PcdEdkiiSystemFirmwareFileGuid to be SystemFirmwareFileGuid1.
if current BIOS is BOARD2.ROM, it sets PcdEdkiiSystemFirmwareFileGuid to be 
SystemFirmwareFileGuid2.

The generic SystemFirmwareUpdate.efi can determine which ROM should be used for 
current firmware.

The benefit is that the OEM can provide one big capsule contains multiple ROM 
images, which can be used for multiple boards.


Thank you
Yao Jiewen


From: Kinney, Michael D
Sent: Wednesday, November 2, 2016 9:10 AM
To: Yao, Jiewen >; 
edk2-devel@lists.01.org; Kinney, Michael D 
>
Cc: Tian, Feng >; Zeng, Star 
>; Gao, Liming 
>; Zhang, Chao B 
>
Subject: RE: [PATCH V5 06/12] SignedCapsulePkg/CapsulePkg.dec: Add capsule 
related definition.

Jiewen,

The description of this PCD says it is a single FFS file GUID.

How would multiple FFS files with data contents be supported with the INI file 
format used in these FMP patch series?

Mike

From: Yao, Jiewen
Sent: Tuesday, November 1, 2016 5:46 PM
To: Kinney, Michael D 
>; 
edk2-devel@lists.01.org
Cc: Tian, Feng >; Zeng, Star 
>; Gao, Liming 
>; Zhang, Chao B 
>
Subject: RE: [PATCH V5 06/12] SignedCapsulePkg/CapsulePkg.dec: Add capsule 
related definition.


1)   That is a good question.

We designed to use PCD instead of fixed GUID purposely.

There is requirement that the value should be determined at runtime, because 
different board may use different system firmware file name value and the 
capsule may contain multiple system BIOS firmware images.


2)   I am OK to make default value to be {0x0}

Thank you
Yao Jiewen

From: Kinney, Michael D
Sent: Wednesday, November 2, 2016 5:57 AM
To: Yao, Jiewen >; 
edk2-devel@lists.01.org; Kinney, Michael D 
>
Cc: Tian, Feng >; Zeng, Star 

Re: [edk2] [PATCH] EdkCompatibilityPkg/PrintLite: Fix ErrorPrint() wrong NULL char check

2016-11-02 Thread Gao, Liming
Reviewed-by: Liming Gao 

-Original Message-
From: Song, BinX 
Sent: Wednesday, November 2, 2016 10:09 AM
To: edk2-devel@lists.01.org
Cc: Gao, Liming 
Subject: [PATCH] EdkCompatibilityPkg/PrintLite: Fix ErrorPrint() wrong NULL 
char check

- '\0' -> NULL
- https://bugzilla.tianocore.org/show_bug.cgi?id=47

Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Bell Song 
---
 EdkCompatibilityPkg/Foundation/Library/Dxe/PrintLite/StdErr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/EdkCompatibilityPkg/Foundation/Library/Dxe/PrintLite/StdErr.c 
b/EdkCompatibilityPkg/Foundation/Library/Dxe/PrintLite/StdErr.c
index e48cbe8..4abe14f 100644
--- a/EdkCompatibilityPkg/Foundation/Library/Dxe/PrintLite/StdErr.c
+++ b/EdkCompatibilityPkg/Foundation/Library/Dxe/PrintLite/StdErr.c
@@ -101,7 +101,7 @@ Returns:
 return 0;
   }
 
-  if (ErrorString != '\0') {
+  if (ErrorString != NULL) {
 if (gST->StdErr != NULL) {
   //
   // To be extra safe make sure StdErr has been initialized
-- 
2.7.2.windows.1

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


  1   2   >