[edk2] [Patch 0/3] BaseTools: Replace hardcoding VS path in tools_def.template

2016-10-27 Thread Yonghong Zhu
This series patches replace the hardcode VS path in the tools_def.template 
file.

Yonghong Zhu (3):
  BaseTools: Add a new bat file to set PREFIX envs
  BaseTools: Update toolsetup.bat to call the set_vsprefix_envs.bat
  BaseTools:introduce PREFIX env for VS tool path

 BaseTools/Conf/tools_def.template |  90 +
 BaseTools/set_vsprefix_envs.bat   | 101 ++
 BaseTools/toolsetup.bat   |   8 +++
 3 files changed, 153 insertions(+), 46 deletions(-)
 create mode 100644 BaseTools/set_vsprefix_envs.bat

-- 
2.6.1.windows.1

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


[edk2] [Patch 2/3] BaseTools: Update toolsetup.bat to call the set_vsprefix_envs.bat

2016-10-27 Thread Yonghong Zhu
Update toolsetup.bat to call the set_vsprefix_envs.bat to set the PREFIX
envs.

Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Yonghong Zhu 
---
 BaseTools/toolsetup.bat | 8 
 1 file changed, 8 insertions(+)

diff --git a/BaseTools/toolsetup.bat b/BaseTools/toolsetup.bat
index 17b7239..26b60d9 100755
--- a/BaseTools/toolsetup.bat
+++ b/BaseTools/toolsetup.bat
@@ -162,10 +162,18 @@ if not defined WORKSPACE (
  echo.
)
goto skip_reconfig
 )
 
+IF NOT exist "%EDK_TOOLS_PATH%\set_vsprefix_envs.bat" (
+  @echo.
+  @echo !!! ERROR !!! The set_vsprefix_envs.bat was not found !!!
+  @echo.
+  goto end
+)
+call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat
+
 if not defined CONF_PATH (
   set CONF_PATH=%WORKSPACE%\Conf
 )
 
 if NOT exist %CONF_PATH% (
-- 
2.6.1.windows.1

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


Re: [edk2] [PATCH] UefiCpuPkg: Move GetProcessorLocation() to SmmCpuFeaturesLib library.

2016-10-27 Thread Fan, Jeff
Leo,

Got it. Could you please create the patch to add GetProcessorLocation() in 
Local APIC Lib?

There are two library instances required to be updated
UefiCpuPkg\Library\BaseXApicLib
UefiCpuPkg\Library\BaseXApicX2ApicLib

Then you could remove the ExtractProcessorLocation() from PiSmmCpuDxeSmm.

Thanks!
Jeff

-Original Message-
From: Duran, Leo [mailto:leo.du...@amd.com] 
Sent: Friday, October 28, 2016 11:20 AM
To: Fan, Jeff; Kinney, Michael D; edk2-devel@lists.01.org
Cc: Gao, Liming
Subject: RE: [edk2] [PATCH] UefiCpuPkg: Move GetProcessorLocation() to 
SmmCpuFeaturesLib library.

Please see my reply below.
Thanks,
Leo

> -Original Message-
> From: Fan, Jeff [mailto:jeff@intel.com]
> Sent: Thursday, October 27, 2016 8:00 PM
> To: Kinney, Michael D ; Duran, Leo 
> ; edk2-devel@lists.01.org
> Cc: Gao, Liming 
> Subject: RE: [edk2] [PATCH] UefiCpuPkg: Move GetProcessorLocation() to 
> SmmCpuFeaturesLib library.
> 
> Because the CPU location information are gotten from Initial APIC ID,  
> it makes more sense to be added into Local APIC Lib.
> 
> The following is my proposal on its definition.
> /**
>   Get CPU Package/Core/Thread location information.
> 
>   @param[in]  InitialApicIdCPU APIC ID
>   @param[out] Package Pointer to Package ID
>   @param[out] Core  Pointer to Core ID
>   @param[out] Thread  Pointer to Thread ID
> **/
> VOID
> ExtractProcessorLocation (
>   IN  UINT32 InitialApicId,
>   OUT UINT32  *Package,
>   OUT UINT32  *Core,
>   OUT UINT32  *Thread
>   );
> 
> Leo,  is it OK to meet your requirement?
> 
> Thanks!
> Jeff
[Duran, Leo]
Sure thing.
The main point is to get the vendor-specific CPUID code out of the driver, and 
into a library.
> 
> -Original Message-
> From: Fan, Jeff
> Sent: Friday, October 28, 2016 8:45 AM
> To: Kinney, Michael D; Leo Duran; edk2-devel@lists.01.org
> Cc: Gao, Liming
> Subject: RE: [edk2] [PATCH] UefiCpuPkg: Move GetProcessorLocation() to 
> SmmCpuFeaturesLib library.
> 
> Leo and Mike,
> 
> GetProcessorLocation() are not only used by PiSmmCpuDxeSmm driver, it 
> is also duplicated in UefiCpuPkg\Library\MpInitLib\MpLib.c.
> 
> I suggest that we could add this API into 
> UefiCpuPkg/Include/UefiCpuLib or UefiCpuPkg/Include/ LocalApicLib.h.
> Thus, it could be consumed by modules across PEI/DXE/SMM modules.
> 
> Thanks!
> Jeff
> 
> -Original Message-
> From: Kinney, Michael D
> Sent: Friday, October 28, 2016 7:16 AM
> To: Leo Duran; edk2-devel@lists.01.org; Kinney, Michael D
> Cc: Gao, Liming; Fan, Jeff
> Subject: RE: [edk2] [PATCH] UefiCpuPkg: Move GetProcessorLocation() to 
> SmmCpuFeaturesLib library.
> 
> Leo,
> 
> This looks like a good proposed change to the SmmFeaturesLib and 
> PiSmmCpuDxeSmm module.
> 
> Adding UefiCpuPkg maintainer Jeff Fan to the Cc list.
> 
> There are 3 implementations of the SmmFeaturesLib in edk2/master.
> This patch needs to update all 3, or some of the platforms in 
> edk2/master will no longer build:
> 
> * OvmfPkg\Library\SmmCpuFeaturesLib
> * QuarkSocPkg\QuarkNorthCluster\Library\SmmCpuFeaturesLib
> * UefiCpuPkg\Library\SmmCpuFeaturesLib
> 
> Thanks,
> 
> Mike
> 
> > -Original Message-
> > From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf 
> > Of Leo Duran
> > Sent: Thursday, October 27, 2016 3:30 PM
> > To: edk2-devel@lists.01.org
> > Cc: Leo Duran ; Gao, Liming
> 
> > Subject: [edk2] [PATCH] UefiCpuPkg: Move GetProcessorLocation() to 
> > SmmCpuFeaturesLib library.
> >
> > 1) Remove SmmGetProcessorLocation() from PiSmmCpuDxeSmm driver
> > 2) Add SmmCpuFeaturesGetProcessorLocation() to SmmCpuFeaturesLib 
> > library
> >
> > Contributed-under: TianoCore Contribution Agreement 1.0
> > Signed-off-by: Leo Duran  
> > ---
> >  UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h |  17 +++
> >  .../Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c  | 118
> 
> >  UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c | 121 
> > +--
> --
> >  3 files changed, 136 insertions(+), 120 deletions(-)
> >
> > diff --git a/UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h
> > b/UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h
> > index 4478003..dd14ec5 100644
> > --- a/UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h
> > +++ b/UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h
> > @@ -398,4 +398,21 @@ SmmCpuFeaturesAllocatePageTableMemory (
> >IN UINTN   Pages
> >);
> >
> > +/**
> > +  Get Package ID/Core ID/Thread ID of a processor.
> > +
> > +  APIC ID must be an initial APIC ID.
> > +
> > +  The algorithm assumes the target system has symmetry across 
> > + physical package
> > boundaries
> > +  with respect to the number of logical processors per package, 
> > + number of cores per
> > package.
> > +
> > +  

[edk2] [Patch] BaseTools: Fix a bug for tooldef class not include the newly Env

2016-10-27 Thread Yonghong Zhu
Prebuild script may update os.environ, but the tooldef class not include
the new ENV variables. so after the Launch prebuild script, we should
re-init the tooldef class to include the new ENV variables.

Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Yonghong Zhu 
---
 BaseTools/Source/Python/build/build.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/BaseTools/Source/Python/build/build.py 
b/BaseTools/Source/Python/build/build.py
index f17b55c..35e7037 100644
--- a/BaseTools/Source/Python/build/build.py
+++ b/BaseTools/Source/Python/build/build.py
@@ -823,10 +823,12 @@ class Build():
 EdkLogger.quiet("%-16s = %s" % ("PREBUILD", self.PrebuildScript))
 if self.PostbuildScript:
 EdkLogger.quiet("%-16s = %s" % ("POSTBUILD", self.PostbuildScript))
 if self.PrebuildScript:
 self.LaunchPrebuild()
+self.TargetTxt = TargetTxtClassObject()
+self.ToolDef   = ToolDefClassObject()
 if not (self.LaunchPrebuildFlag and 
os.path.exists(self.PlatformBuildPath)):
 self.InitBuild()
 
 EdkLogger.info("")
 os.chdir(self.WorkspaceDir)
-- 
2.6.1.windows.1

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


[edk2] [Patch 1/3] BaseTools: Add a new bat file to set PREFIX envs

2016-10-27 Thread Yonghong Zhu
Add set_vsprefix_envs.bat to set PREFIX envs as the default values if
they are not set.

Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Yonghong Zhu 
---
 BaseTools/set_vsprefix_envs.bat | 101 
 1 file changed, 101 insertions(+)
 create mode 100644 BaseTools/set_vsprefix_envs.bat

diff --git a/BaseTools/set_vsprefix_envs.bat b/BaseTools/set_vsprefix_envs.bat
new file mode 100644
index 000..a860c28
--- /dev/null
+++ b/BaseTools/set_vsprefix_envs.bat
@@ -0,0 +1,101 @@
+@REM @file
+@REM   This stand-alone program is typically called by the toolsetup.bat file,
+@REM   however it may be executed directly from the BaseTools project folder
+@REM   if the file is not executed within a WORKSPACE\BaseTools folder.
+@REM
+@REM Copyright (c) 2016, Intel Corporation. All rights reserved.
+@REM
+@REM This program and the accompanying materials are licensed and made 
available
+@REM under the terms and conditions of the BSD License which accompanies this
+@REM distribution.  The full text of the license may be found at:
+@REM   http://opensource.org/licenses/bsd-license.php
+@REM
+@REM THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+@REM WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR
+@REM IMPLIED.
+@REM
+
+@echo off
+pushd .
+
+if defined VS71COMNTOOLS (
+  if not defined VS2003_PREFIX (
+set "VS2003_PREFIX=%VS71COMNTOOLS:~0,-14%"
+  )
+)
+
+if defined VS80COMNTOOLS (
+  if not defined VS2005_PREFIX (
+set "VS2005_PREFIX=%VS80COMNTOOLS:~0,-14%"
+  )
+)
+
+if defined VS90COMNTOOLS (
+  if not defined VS2008_PREFIX (
+set "VS2008_PREFIX=%VS90COMNTOOLS:~0,-14%"
+  )
+  if not defined WINSDK_PREFIX (
+set "WINSDK_PREFIX=c:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\"
+  )
+  if not defined WINSDKx86_PREFIX (
+set "WINSDKx86_PREFIX=c:\Program Files (x86)\Microsoft 
SDKs\Windows\v6.0A\bin\"
+  )
+)
+
+if defined VS100COMNTOOLS (
+  if not defined VS2010_PREFIX (
+set "VS2010_PREFIX=%VS100COMNTOOLS:~0,-14%"
+  )
+  if not defined WINSDK7_PREFIX (
+set "WINSDK7_PREFIX=c:\Program Files\Microsoft SDKs\Windows\v7.0A\Bin\"
+  )
+  if not defined WINSDK7x86_PREFIX (
+set "WINSDK7x86_PREFIX=c:\Program Files (x86)\Microsoft 
SDKs\Windows\v7.0A\Bin\"
+  )
+)
+
+if defined VS110COMNTOOLS (
+  if not defined VS2012_PREFIX (
+set "VS2012_PREFIX=%VS110COMNTOOLS:~0,-14%"
+  )
+  if not defined WINSDK71_PREFIX (
+set "WINSDK71_PREFIX=c:\Program Files\Microsoft SDKs\Windows\v7.1A\Bin\"
+  )
+  if not defined WINSDK71x86_PREFIX (
+set "WINSDK71x86_PREFIX=c:\Program Files (x86)\Microsoft 
SDKs\Windows\v7.1A\Bin\"
+  )
+)
+
+if defined VS120COMNTOOLS (
+  if not defined VS2013_PREFIX (
+set "VS2013_PREFIX=%VS120COMNTOOLS:~0,-14%"
+  )
+  if not defined WINSDK8_PREFIX (
+set "WINSDK8_PREFIX=c:\Program Files\Windows Kits\8.0\bin\"
+  )
+  if not defined WINSDK8x86_PREFIX (
+set "WINSDK8x86_PREFIX=c:\Program Files (x86)\Windows Kits\8.0\bin\"
+  )
+)
+
+if defined VS140COMNTOOLS (
+  if not defined VS2015_PREFIX (
+set "VS2015_PREFIX=%VS140COMNTOOLS:~0,-14%"
+  )
+  if not defined WINSDK81_PREFIX (
+set "WINSDK81_PREFIX=c:\Program Files\Windows Kits\8.1\bin\"
+  )
+  if not defined WINSDK81x86_PREFIX (
+set "WINSDK81x86_PREFIX=c:\Program Files (x86)\Windows Kits\8.1\bin\"
+  )
+)
+
+if not defined WINDDK3790_PREFIX (
+  set WINDDK3790_PREFIX=C:\WINDDK\3790.1830\bin\
+)
+
+if not defined IASL_PREFIX (
+  set IASL_PREFIX=C:\ASL\
+)
+
+popd
\ No newline at end of file
-- 
2.6.1.windows.1

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


[edk2] [Patch] BaseTools: Fix a bug for ExpandMacros to support mixed case ENV var

2016-10-27 Thread Yonghong Zhu
os.environ contains all environment variables uppercase on Windows which
cause the key in the self.MacroDictionary is uppercase, but the real
variable name maybe mixed case, eg:WINSDK81x86, then we can't find the
variable in the self.MacroDictionary.

Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Yonghong Zhu 
---
 BaseTools/Source/Python/Common/ToolDefClassObject.py | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/BaseTools/Source/Python/Common/ToolDefClassObject.py 
b/BaseTools/Source/Python/Common/ToolDefClassObject.py
index 5dd505c..a71c616 100644
--- a/BaseTools/Source/Python/Common/ToolDefClassObject.py
+++ b/BaseTools/Source/Python/Common/ToolDefClassObject.py
@@ -234,17 +234,20 @@ class ToolDefClassObject(object):
 # @param Value:   The string with unreplaced macros
 #
 # @retval Value:  The string which has been replaced with real value
 #
 def ExpandMacros(self, Value):
+# os.environ contains all environment variables uppercase on Windows 
which cause the key in the self.MacroDictionary is uppercase, but Ref may not
 EnvReference = gEnvRefPattern.findall(Value)
 for Ref in EnvReference:
-if Ref not in self.MacroDictionary:
+if Ref not in self.MacroDictionary and Ref.upper() not in 
self.MacroDictionary:
 Value = Value.replace(Ref, "")
 else:
-Value = Value.replace(Ref, self.MacroDictionary[Ref])
- 
+if Ref in self.MacroDictionary:
+Value = Value.replace(Ref, self.MacroDictionary[Ref])
+else:
+Value = Value.replace(Ref, 
self.MacroDictionary[Ref.upper()])
 
 MacroReference = gMacroRefPattern.findall(Value)
 for Ref in MacroReference:
 if Ref not in self.MacroDictionary:
 return False, Ref
-- 
2.6.1.windows.1

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


Re: [edk2] [PATCH] UefiCpuPkg: Move GetProcessorLocation() to SmmCpuFeaturesLib library.

2016-10-27 Thread Duran, Leo
Please see my reply below.
Thanks,
Leo

> -Original Message-
> From: Fan, Jeff [mailto:jeff@intel.com]
> Sent: Thursday, October 27, 2016 8:00 PM
> To: Kinney, Michael D ; Duran, Leo
> ; edk2-devel@lists.01.org
> Cc: Gao, Liming 
> Subject: RE: [edk2] [PATCH] UefiCpuPkg: Move GetProcessorLocation() to
> SmmCpuFeaturesLib library.
> 
> Because the CPU location information are gotten from Initial APIC ID,  it
> makes more sense to be added into Local APIC Lib.
> 
> The following is my proposal on its definition.
> /**
>   Get CPU Package/Core/Thread location information.
> 
>   @param[in]  InitialApicIdCPU APIC ID
>   @param[out] Package Pointer to Package ID
>   @param[out] Core  Pointer to Core ID
>   @param[out] Thread  Pointer to Thread ID
> **/
> VOID
> ExtractProcessorLocation (
>   IN  UINT32 InitialApicId,
>   OUT UINT32  *Package,
>   OUT UINT32  *Core,
>   OUT UINT32  *Thread
>   );
> 
> Leo,  is it OK to meet your requirement?
> 
> Thanks!
> Jeff
[Duran, Leo] 
Sure thing.
The main point is to get the vendor-specific CPUID code out of the driver, and 
into a library.
> 
> -Original Message-
> From: Fan, Jeff
> Sent: Friday, October 28, 2016 8:45 AM
> To: Kinney, Michael D; Leo Duran; edk2-devel@lists.01.org
> Cc: Gao, Liming
> Subject: RE: [edk2] [PATCH] UefiCpuPkg: Move GetProcessorLocation() to
> SmmCpuFeaturesLib library.
> 
> Leo and Mike,
> 
> GetProcessorLocation() are not only used by PiSmmCpuDxeSmm driver, it is
> also duplicated in UefiCpuPkg\Library\MpInitLib\MpLib.c.
> 
> I suggest that we could add this API into UefiCpuPkg/Include/UefiCpuLib or
> UefiCpuPkg/Include/ LocalApicLib.h.
> Thus, it could be consumed by modules across PEI/DXE/SMM modules.
> 
> Thanks!
> Jeff
> 
> -Original Message-
> From: Kinney, Michael D
> Sent: Friday, October 28, 2016 7:16 AM
> To: Leo Duran; edk2-devel@lists.01.org; Kinney, Michael D
> Cc: Gao, Liming; Fan, Jeff
> Subject: RE: [edk2] [PATCH] UefiCpuPkg: Move GetProcessorLocation() to
> SmmCpuFeaturesLib library.
> 
> Leo,
> 
> This looks like a good proposed change to the SmmFeaturesLib and
> PiSmmCpuDxeSmm module.
> 
> Adding UefiCpuPkg maintainer Jeff Fan to the Cc list.
> 
> There are 3 implementations of the SmmFeaturesLib in edk2/master.
> This patch needs to update all 3, or some of the platforms in edk2/master will
> no longer build:
> 
> * OvmfPkg\Library\SmmCpuFeaturesLib
> * QuarkSocPkg\QuarkNorthCluster\Library\SmmCpuFeaturesLib
> * UefiCpuPkg\Library\SmmCpuFeaturesLib
> 
> Thanks,
> 
> Mike
> 
> > -Original Message-
> > From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of
> > Leo Duran
> > Sent: Thursday, October 27, 2016 3:30 PM
> > To: edk2-devel@lists.01.org
> > Cc: Leo Duran ; Gao, Liming
> 
> > Subject: [edk2] [PATCH] UefiCpuPkg: Move GetProcessorLocation() to
> > SmmCpuFeaturesLib library.
> >
> > 1) Remove SmmGetProcessorLocation() from PiSmmCpuDxeSmm driver
> > 2) Add SmmCpuFeaturesGetProcessorLocation() to SmmCpuFeaturesLib
> > library
> >
> > Contributed-under: TianoCore Contribution Agreement 1.0
> > Signed-off-by: Leo Duran  
> > ---
> >  UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h |  17 +++
> >  .../Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c  | 118
> 
> >  UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c | 121 
> > +--
> --
> >  3 files changed, 136 insertions(+), 120 deletions(-)
> >
> > diff --git a/UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h
> > b/UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h
> > index 4478003..dd14ec5 100644
> > --- a/UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h
> > +++ b/UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h
> > @@ -398,4 +398,21 @@ SmmCpuFeaturesAllocatePageTableMemory (
> >IN UINTN   Pages
> >);
> >
> > +/**
> > +  Get Package ID/Core ID/Thread ID of a processor.
> > +
> > +  APIC ID must be an initial APIC ID.
> > +
> > +  The algorithm assumes the target system has symmetry across
> > + physical package
> > boundaries
> > +  with respect to the number of logical processors per package,
> > + number of cores per
> > package.
> > +
> > +  @param  ApicIdAPIC ID of the target logical processor.
> > +  @param  LocationReturns the processor location information.
> > +**/
> > +VOID
> > +SmmCpuFeaturesGetProcessorLocation (
> > +  IN UINT32 ApicId,
> > +  OUT EFI_CPU_PHYSICAL_LOCATION *Location
> > +  );
> > +
> >  #endif
> > diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
> > b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
> > index 1754f2d..1e300f3 100644
> > --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
> > +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
> > @@ -673,3 +673,121 @@ 

Re: [edk2] [Patch] QuarkSocPkg/Library: Remove extra UefiBaseType.h includes

2016-10-27 Thread Gao, Liming
Reviewed-by: Liming Gao 

> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of
> Michael Kinney
> Sent: Thursday, October 27, 2016 11:15 AM
> To: edk2-devel@lists.01.org
> Subject: [edk2] [Patch] QuarkSocPkg/Library: Remove extra UefiBaseType.h
> includes
> 
> Based on Laszlo Ersek work to add ASSERT_RETURN_ERORR():
> 
>   https://lists.01.org/pipermail/edk2-devel/2016-October/003132.html
> 
> Laszlo also discovered libraries of type BASE that include
> UefiBaseType.h that should not include that file:
> 
>   https://lists.01.org/pipermail/edk2-devel/2016-October/003308.html
> 
> This change removes the extra #include of 
> from QNCSmmLib.c.
> 
> Cc: Kelly Steele 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Michael Kinney 
> ---
>  QuarkSocPkg/QuarkNorthCluster/Library/QNCSmmLib/QNCSmmLib.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git
> a/QuarkSocPkg/QuarkNorthCluster/Library/QNCSmmLib/QNCSmmLib.c
> b/QuarkSocPkg/QuarkNorthCluster/Library/QNCSmmLib/QNCSmmLib.c
> index 075d45f..5f2722a 100644
> --- a/QuarkSocPkg/QuarkNorthCluster/Library/QNCSmmLib/QNCSmmLib.c
> +++ b/QuarkSocPkg/QuarkNorthCluster/Library/QNCSmmLib/QNCSmmLib.c
> @@ -1,7 +1,7 @@
>  /** @file
>  QNC Smm Library Services that implements SMM Region access, S/W SMI
> generation and detection.
> 
> -Copyright (c) 2013-2015 Intel Corporation.
> +Copyright (c) 2013-2016 Intel Corporation.
> 
>  This program and the accompanying materials
>  are licensed and made available under the terms and conditions of the BSD
> License
> @@ -19,7 +19,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY
> KIND, EITHER EXPRESS OR IMPLIED.
>  #include 
>  #include 
>  #include 
> -#include 
>  #include 
> 
>  #define BOOT_SERVICE_SOFTWARE_SMI_DATA  0
> --
> 2.6.3.windows.1
> 
> ___
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH v2 3/3] NetworkPkg: Update IP4 stack drivers for classless address unicast check.

2016-10-27 Thread Wu, Jiaxin
Reviewed-By: Wu Jiaxin 

Best Regards!
Jiaxin

> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Fu
> Siyuan
> Sent: Thursday, October 27, 2016 6:52 PM
> To: edk2-devel@lists.01.org
> Cc: Ye, Ting ; Zhang, Lubo ; Wu,
> Jiaxin 
> Subject: [edk2] [PATCH v2 3/3] NetworkPkg: Update IP4 stack drivers for
> classless address unicast check.
> 
> V2 update:
> Keep the zero address and broadcast check if network mask is not available.
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Fu Siyuan 
> Cc: Ye Ting 
> Cc: Zhang Lubo 
> Cc: Wu Jiaxin 
> ---
>  NetworkPkg/IScsiDxe/IScsiConfig.c  | 16 ++
>  NetworkPkg/TcpDxe/TcpMain.c|  6 ++---
>  NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c| 40 +++
> ---
>  NetworkPkg/UefiPxeBcDxe/PxeBcSupport.c |  4 +++-
>  4 files changed, 45 insertions(+), 21 deletions(-)
> 
> diff --git a/NetworkPkg/IScsiDxe/IScsiConfig.c
> b/NetworkPkg/IScsiDxe/IScsiConfig.c
> index 16a90a6..57571ad 100644
> --- a/NetworkPkg/IScsiDxe/IScsiConfig.c
> +++ b/NetworkPkg/IScsiDxe/IScsiConfig.c
> @@ -164,7 +164,10 @@ IpIsUnicast (
>)
>  {
>if (IpMode == IP_MODE_IP4) {
> -return NetIp4IsUnicast (NTOHL (Ip->Addr[0]), 0);
> +if (IP4_IS_UNSPECIFIED (NTOHL (Ip->Addr[0])) ||
> IP4_IS_LOCAL_BROADCAST (NTOHL (Ip->Addr[0])))   {
> +  return FALSE;
> +}
> +return TRUE;
>} else if (IpMode == IP_MODE_IP6) {
>  return NetIp6IsValidUnicast (>v6);
>} else {
> @@ -2349,7 +2352,9 @@ IScsiFormCallback (
> 
>  case KEY_LOCAL_IP:
>Status = NetLibStrToIp4 (IfrNvData->LocalIp, );
> -  if (EFI_ERROR (Status) || !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), 
> 0)) {
> +  if (EFI_ERROR (Status) ||
> +  ((Private->Current->SessionConfigData.SubnetMask.Addr[0] != 0) &&
> +   !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]),
> + NTOHL(*(UINT32*)Private->Current->SessionConfigData.SubnetMask.Addr)))
> + ) {
>  CreatePopUp (
>EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
>,
> @@ -2383,7 +2388,10 @@ IScsiFormCallback (
> 
>  case KEY_GATE_WAY:
>Status = NetLibStrToIp4 (IfrNvData->Gateway, );
> -  if (EFI_ERROR (Status) || ((Gateway.Addr[0] != 0) && !NetIp4IsUnicast
> (NTOHL (Gateway.Addr[0]), 0))) {
> +  if (EFI_ERROR (Status) ||
> +  ((Gateway.Addr[0] != 0) &&
> +   (Private->Current->SessionConfigData.SubnetMask.Addr[0] != 0) &&
> +   !NetIp4IsUnicast (NTOHL (Gateway.Addr[0]),
> + NTOHL(*(UINT32*)Private->Current->SessionConfigData.SubnetMask.Addr)))
> + ) {
>  CreatePopUp (
>EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
>,
> @@ -2400,7 +2408,7 @@ IScsiFormCallback (
>  case KEY_TARGET_IP:
>UnicodeStrToAsciiStrS (IfrNvData->TargetIp, IpString, sizeof 
> (IpString));
>Status = IScsiAsciiStrToIp (IpString, IfrNvData->IpMode, );
> -  if (EFI_ERROR (Status) || !IpIsUnicast (, IfrNvData->IpMode)) {
> +  if (EFI_ERROR (Status) || IP4_IS_LOCAL_BROADCAST
> + (EFI_NTOHL(HostIp.v4)) || IP4_IS_UNSPECIFIED (EFI_NTOHL(HostIp.v4))) {
>  CreatePopUp (
>EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
>,
> diff --git a/NetworkPkg/TcpDxe/TcpMain.c b/NetworkPkg/TcpDxe/TcpMain.c
> index 96a295a..03942ee 100644
> --- a/NetworkPkg/TcpDxe/TcpMain.c
> +++ b/NetworkPkg/TcpDxe/TcpMain.c
> @@ -147,10 +147,10 @@ Tcp4Configure (
>if (NULL != TcpConfigData) {
> 
>  CopyMem (, >AccessPoint.RemoteAddress, sizeof
> (IP4_ADDR));
> -if ((Ip != 0) && !NetIp4IsUnicast (NTOHL (Ip), 0)) {
> +if (IP4_IS_LOCAL_BROADCAST (NTOHL (Ip))) {
>return EFI_INVALID_PARAMETER;
>  }
> -
> +
>  if (TcpConfigData->AccessPoint.ActiveFlag && (0 == TcpConfigData-
> >AccessPoint.RemotePort || (Ip == 0))) {
>return EFI_INVALID_PARAMETER;
>  }
> @@ -159,7 +159,7 @@ Tcp4Configure (
> 
>CopyMem (, >AccessPoint.StationAddress, sizeof
> (IP4_ADDR));
>CopyMem (, >AccessPoint.SubnetMask,
> sizeof (IP4_ADDR));
> -  if (!NetIp4IsUnicast (NTOHL (Ip), 0) || !IP4_IS_VALID_NETMASK (NTOHL
> (SubnetMask))) {
> +  if (!IP4_IS_VALID_NETMASK (NTOHL (SubnetMask)) ||
> + !NetIp4IsUnicast (NTOHL (Ip), NTOHL (SubnetMask))) {
>  return EFI_INVALID_PARAMETER;
>}
>  }
> diff --git a/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c
> b/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c
> index c7c5bd6..52095c5 100644
> --- a/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c
> +++ b/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c
> @@ -856,8 +856,7 @@ EfiPxeBcMtftp (
>(BufferSize == NULL) ||
>(ServerIp == NULL) ||
>((BufferPtr == NULL) && DontUseBuffer) ||
> -  ((BlockSize != NULL) && (*BlockSize < PXE_MTFTP_DEFAULT_BLOCK_SIZE))
> ||
> -  (!NetIp4IsUnicast (NTOHL 

Re: [edk2] [PATCH v2 1/3] MdeModulePkg: Update NetLib interface to support classless addressing.

2016-10-27 Thread Wu, Jiaxin
Siyuan,

One comment for the NetIp4IsUnicast(), we should add more check for BROADCAST 
IP since the it's also not a valid unicast address.

  if (Ip == 0 || IP4_IS_LOCAL_BROADCAST (Ip)) {
return FALSE;
  }

Others is good to me.

Reviewed-By: Wu Jiaxin 

Best Regards!
Jiaxin

> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Fu
> Siyuan
> Sent: Thursday, October 27, 2016 6:52 PM
> To: edk2-devel@lists.01.org
> Cc: Ye, Ting ; Zhang, Lubo ; Wu,
> Jiaxin 
> Subject: [edk2] [PATCH v2 1/3] MdeModulePkg: Update NetLib interface to
> support classless addressing.
> 
> V2:
> Add macro IP4_IS_UNSPECIFIED.
> 
> The classful addressing (IP class A/B/C) has been deprecated according to
> RFC4632. This patch updates the NetLib NetGetIpClass() and NetIp4IsUnicast()
> accordingly.
> 
> NetGetIpClass()
> The function is kept for compatibility, while the caller of this function 
> could only
> check the returned value against with IP4_ADDR_CLASSD (multicast) or
> IP4_ADDR_CLASSE (reserved) now. The function has been updated to note this.
> 
> NetIp4IsUnicast()
> The NetMask becomes a required parameter to check the unicast address.
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Fu Siyuan 
> Cc: Ye Ting 
> Cc: Zhang Lubo 
> Cc: Wu Jiaxin 
> ---
>  MdeModulePkg/Include/Library/NetLib.h  | 23 ++-
>  MdeModulePkg/Library/DxeNetLib/DxeNetLib.c | 26 --
>  2 files changed, 26 insertions(+), 23 deletions(-)
> 
> diff --git a/MdeModulePkg/Include/Library/NetLib.h
> b/MdeModulePkg/Include/Library/NetLib.h
> index c5c0fc2..26709af 100644
> --- a/MdeModulePkg/Include/Library/NetLib.h
> +++ b/MdeModulePkg/Include/Library/NetLib.h
> @@ -43,9 +43,9 @@ typedef UINT16  TCP_PORTNO;
>  //
>  // The address classification
>  //
> -#define  IP4_ADDR_CLASSA   1
> -#define  IP4_ADDR_CLASSB   2
> -#define  IP4_ADDR_CLASSC   3
> +#define  IP4_ADDR_CLASSA   1 // Deprecated
> +#define  IP4_ADDR_CLASSB   2 // Deprecated
> +#define  IP4_ADDR_CLASSC   3 // Deprecated
>  #define  IP4_ADDR_CLASSD   4
>  #define  IP4_ADDR_CLASSE   5
> 
> @@ -231,6 +231,7 @@ typedef struct {
>  // Test the IP's attribute, All the IPs are in host byte order.
>  //
>  #define IP4_IS_MULTICAST(Ip)  (((Ip) & 0xF000) == 0xE000)
> +#define IP4_IS_UNSPECIFIED(Ip)((Ip) == 0)
>  #define IP4_IS_LOCAL_BROADCAST(Ip)((Ip) == 0x)
>  #define IP4_NET_EQUAL(Ip1, Ip2, NetMask)  (((Ip1) & (NetMask)) == ((Ip2) &
> (NetMask)))
>  #define IP4_IS_VALID_NETMASK(Ip)  (NetGetMaskLength (Ip) !=
> (IP4_MASK_MAX + 1))
> @@ -379,6 +380,11 @@ NetGetMaskLength (
>Return the class of the IP address, such as class A, B, C.
>Addr is in host byte order.
> 
> +  [ATTENTION]
> +  Classful addressing (IP class A/B/C) has been deprecated according to
> RFC4632.
> +  Caller of this function could only check the returned value against
> + IP4_ADDR_CLASSD (multicast) or IP4_ADDR_CLASSE (reserved) now.
> +
>The address of class A  starts with 0.
>If the address belong to class A, return IP4_ADDR_CLASSA.
>The address of class B  starts with 10.
> @@ -404,17 +410,16 @@ NetGetIpClass (
> 
>  /**
>Check whether the IP is a valid unicast address according to
> -  the netmask. If NetMask is zero, use the IP address's class to get the 
> default
> mask.
> +  the netmask.
> 
> -  If Ip is 0, IP is not a valid unicast address.
> -  Class D address is used for multicasting and class E address is reserved 
> for
> future. If Ip
> -  belongs to class D or class E, Ip is not a valid unicast address.
> -  If all bits of the host address of Ip are 0 or 1, Ip is not a valid 
> unicast address.
> +  ASSERT if NetMask is zero.
> +
> +  If all bits of the host address of IP are 0 or 1, IP is also not a valid 
> unicast
> address.
> 
>@param[in]  IpThe IP to check against.
>@param[in]  NetMask   The mask of the IP.
> 
> -  @return TRUE if Ip is a valid unicast address on the network, otherwise 
> FALSE.
> +  @return TRUE if IP is a valid unicast address on the network, otherwise
> FALSE.
> 
>  **/
>  BOOLEAN
> diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
> b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
> index 148bebf..f520845 100644
> --- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
> +++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
> @@ -580,6 +580,11 @@ NetGetMaskLength (
>Return the class of the IP address, such as class A, B, C.
>Addr is in host byte order.
> 
> +  [ATTENTION]
> +  Classful addressing (IP class A/B/C) has been deprecated according to
> RFC4632.
> +  Caller of this function could only check the returned value against
> + 

Re: [edk2] [PATCH v2 2/3] MdeModulePkg: Update IP4 stack drivers for classless address unicast check.

2016-10-27 Thread Wu, Jiaxin
Siyuan,

For DHCP part, I noticed you made the below code change in 
EfiDhcp4TransmitReceive() and Dhcp4InstanceConfigUdpIo():

> -  if (DhcpSb->Netmask == 0) {
> -Class = NetGetIpClass (ClientAddr);
> -ASSERT (Class < IP4_ADDR_CLASSE);
> -SubnetMask = gIp4AllMasks[Class << 3];
> -  } else {
> -SubnetMask = DhcpSb->Netmask;
> -  }
> -
> -  Ip = HTONL (SubnetMask);
> +  Ip = HTONL (DhcpSb->Netmask);

since the UEFI Spec declaims the TransmitReceive() function can be used at any 
time. If D.O.R.A is not performed, DhcpSb->Netmask will be zero, if so, 
TransmitReceive() function will be always in failure status. I suggest to keep 
the original code logical and we can add some description in TransmitReceive() 
function to note that.

Thanks,
Jiaxin

> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Fu
> Siyuan
> Sent: Thursday, October 27, 2016 6:52 PM
> To: edk2-devel@lists.01.org
> Cc: Ye, Ting ; Zhang, Lubo ; Wu,
> Jiaxin 
> Subject: [edk2] [PATCH v2 2/3] MdeModulePkg: Update IP4 stack drivers for
> classless address unicast check.
> 
> V2 update:
> Keep the zero address and broadcast check if network mask is not available.
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Fu Siyuan 
> Cc: Ye Ting 
> Cc: Zhang Lubo 
> Cc: Wu Jiaxin 
> ---
>  MdeModulePkg/Include/Library/IpIoLib.h |  4 +++-
>  MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c   |  9 ++-
>  MdeModulePkg/Universal/Network/ArpDxe/ArpImpl.c|  4 ++--
>  .../Universal/Network/Dhcp4Dxe/Dhcp4Impl.c | 28 
> +++---
>  MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c  |  6 +
>  .../Universal/Network/IScsiDxe/IScsiConfig.c   | 15 
>  .../Universal/Network/Ip4Dxe/Ip4Config2Impl.c  |  9 ---
>  .../Universal/Network/Ip4Dxe/Ip4Config2Nv.c| 24 +--
>  MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c  |  7 +-
>  .../Universal/Network/Mtftp4Dxe/Mtftp4Impl.c   |  8 ++-
>  MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Main.c  |  6 ++---
> MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c  |  9 +--
> MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Main.c  |  8 +++
>  .../Universal/Network/UefiPxeBcDxe/PxeBcImpl.c | 24 ---
>  14 files changed, 75 insertions(+), 86 deletions(-)
> 
> diff --git a/MdeModulePkg/Include/Library/IpIoLib.h
> b/MdeModulePkg/Include/Library/IpIoLib.h
> index 37cba07..aab0c68 100644
> --- a/MdeModulePkg/Include/Library/IpIoLib.h
> +++ b/MdeModulePkg/Include/Library/IpIoLib.h
> @@ -2,7 +2,7 @@
>This library is only intended to be used by UEFI network stack modules.
>It provides the combined IpIo layer on the EFI IP4 Protocol and EFI IP6
> protocol.
> 
> -Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.
> +Copyright (c) 2005 - 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 @@ -261,6 +261,8 @@ typedef
> struct _IP_IO {
>PKT_RCVD_NOTIFY   PktRcvdNotify;   ///< See
> IP_IO_OPEN_DATA::PktRcvdNotify.
>PKT_SENT_NOTIFY   PktSentNotify;   ///< See
> IP_IO_OPEN_DATA::PktSentNotify.
>UINT8 IpVersion;
> +  IP4_ADDR  StationIp;
> +  IP4_ADDR  SubnetMask;
>  } IP_IO;
> 
>  ///
> diff --git a/MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c
> b/MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c
> index 27fef71..9a70e90 100644
> --- a/MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c
> +++ b/MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c
> @@ -1029,7 +1029,9 @@ IpIoListenHandlerDpc (
> 
>if (IpIo->IpVersion == IP_VERSION_4) {
>  if ((EFI_IP4 (RxData->Ip4RxData.Header->SourceAddress) != 0) &&
> -!NetIp4IsUnicast (EFI_NTOHL (((EFI_IP4_RECEIVE_DATA *) RxData)-
> >Header->SourceAddress), 0)) {
> +(IpIo->SubnetMask != 0) &&
> +IP4_NET_EQUAL (IpIo->StationIp, EFI_NTOHL (((EFI_IP4_RECEIVE_DATA *)
> RxData)->Header->SourceAddress), IpIo->SubnetMask) &&
> +!NetIp4IsUnicast (EFI_NTOHL (((EFI_IP4_RECEIVE_DATA *)
> + RxData)->Header->SourceAddress), IpIo->SubnetMask)) {
>//
>// The source address is not zero and it's not a unicast IP address, 
> discard it.
>//
> @@ -1300,6 +1302,11 @@ IpIoOpen (
>  if (OpenData->IpConfigData.Ip4CfgData.RawData) {
>return EFI_UNSUPPORTED;
>  }
> +
> +if (!OpenData->IpConfigData.Ip4CfgData.UseDefaultAddress) {
> +  IpIo->StationIp = EFI_NTOHL (OpenData-
> >IpConfigData.Ip4CfgData.StationAddress);
> +  IpIo->SubnetMask = EFI_NTOHL (OpenData-
> 

Re: [edk2] [PATCH v2 0/3] classless address network unicast check

2016-10-27 Thread Ye, Ting
Series Reviewed-by: Ye Ting 

-Original Message-
From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Fu Siyuan
Sent: Thursday, October 27, 2016 6:52 PM
To: edk2-devel@lists.01.org
Subject: [edk2] [PATCH v2 0/3] classless address network unicast check

V2 update:
Keep the zero address and broadcast check if network mask is not available.

The classful addressing (IP class A/B/C) has been deprecated according to 
RFC4632. This patch updates the NetLib and network drivers for the unicast 
check in classless network.

Fu Siyuan (3):
  MdeModulePkg: Update NetLib interface to support classless addressing.
  MdeModulePkg: Update IP4 stack drivers for classless address unicast
check.
  NetworkPkg: Update IP4 stack drivers for classless address unicast
check.

 MdeModulePkg/Include/Library/IpIoLib.h |  4 ++-
 MdeModulePkg/Include/Library/NetLib.h  | 23 -
 MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c   |  9 -
 MdeModulePkg/Library/DxeNetLib/DxeNetLib.c | 26 +++---
 MdeModulePkg/Universal/Network/ArpDxe/ArpImpl.c|  4 +--
 .../Universal/Network/Dhcp4Dxe/Dhcp4Impl.c | 28 ++-
 MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c  |  6 +---
 .../Universal/Network/IScsiDxe/IScsiConfig.c   | 15 +---
 .../Universal/Network/Ip4Dxe/Ip4Config2Impl.c  |  9 +++--
 .../Universal/Network/Ip4Dxe/Ip4Config2Nv.c| 24 ++---
 MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c  |  7 +---
 .../Universal/Network/Mtftp4Dxe/Mtftp4Impl.c   |  8 ++---
 MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Main.c  |  6 ++--  
MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c  |  9 +++--  
MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Main.c  |  8 ++---
 .../Universal/Network/UefiPxeBcDxe/PxeBcImpl.c | 24 -
 NetworkPkg/IScsiDxe/IScsiConfig.c  | 16 ++---
 NetworkPkg/TcpDxe/TcpMain.c|  6 ++--
 NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c| 40 +++---
 NetworkPkg/UefiPxeBcDxe/PxeBcSupport.c |  4 ++-
 20 files changed, 146 insertions(+), 130 deletions(-)

--
2.7.4.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] [RFC] [MdePkg] UefiLib: CreatePopUp

2016-10-27 Thread Dong, Eric
Hi Felix,

Do you want to provide a new solution for CreatePopup or just want to split 
CreatePopup from UefiLib?  We already has a proposal to provide new API to 
replace CreatePopup. This new API will use modal form to paint the UI. Detail 
you can see the proposal in below link:
https://github.com/ydong10/doc/blob/master/Use%20Modal%20form%20for%20CreatePopup%20API.pptx

Thanks,
Eric
> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Felix 
> Poludov
> Sent: Friday, October 28, 2016 5:12 AM
> To: edk2-devel@lists.01.org
> Subject: [edk2] [RFC] [MdePkg] UefiLib: CreatePopUp
> 
> UefiLib library class (MdePkg ) includes CreatePopUp function.
> The function displays a message box.
> There is certainly more than one way to draw a message box.
> If homogenous user interface is a project requirement,
> CreatePopUp is likely to be overridden to align message box appearance with 
> the platform look and feel.
> The function can be overridden by creating a project specific UefiLib 
> instance, but this seems like an overkill
> because the rest of the UefiLib, which is quite big, would have to be 
> duplicated.
> 
> One way to solve the problem is to move CreatePopUp to a new library class, 
> however, this may break existing projects.
> I suggest changing CreatePopUp implementation to delegate pop up drawing to a 
> new
> function UiCreatePopUp provided by a new library class UiLib.h.
> 
> I would like to solicit feedback for this proposal.
> If there will be no major objections, I'll start working on a patch.
> 
> Thanks
> Felix
> 
> Please consider the environment before printing this email.
> 
> The information contained in this message may be confidential and proprietary 
> to American Megatrends, Inc.  This communication is
> intended to be read only by the individual or entity to whom it is addressed 
> or by their designee. If the reader of this message is not the
> intended recipient, you are on notice that any distribution of this message, 
> in any form, is strictly prohibited.  Please promptly notify the
> sender by reply e-mail or by telephone at 770-246-8600, and then delete or 
> destroy all copies of the transmission.
> ___
> 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] [BaseTools] Library GUIDs missing from Guid.xref file.

2016-10-27 Thread Lin, Derek (HPS UEFI Dev)
That make sense to me, I will update patch to remove it, and not change order.

Thanks,
Derek

-Original Message-
From: Gao, Liming [mailto:liming@intel.com] 
Sent: Thursday, October 27, 2016 1:53 PM
To: Lin, Derek (HPS UEFI Dev) ; af...@apple.com
Cc: edk2-devel@lists.01.org
Subject: RE: [edk2] [BaseTools] Library GUIDs missing from Guid.xref file.

I agree with Andrew to only add the missing Ppi/Protocol/Guid used in Library 
INF file. 

> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of 
> Lin, Derek (HPS UEFI Dev)
> Sent: Thursday, October 27, 2016 1:50 PM
> To: af...@apple.com
> Cc: edk2-devel@lists.01.org
> Subject: Re: [edk2] [BaseTools] Library GUIDs missing from Guid.xref file.
> 
> Andrew,
> 
> The ModuleGuidDict was not for performance, it's because Arch IA32 X64 
> have same library name/FILE_GUID pair, for not duplicate it.
> You are right the patch add library FILE_GUID but they are not end up 
> in the ROM, I'm ok remove it or not.
> 
> Feel free to update the patch.
> 
> Thanks,
> Derek
> 
> -Original Message-
> From: af...@apple.com [mailto:af...@apple.com]
> Sent: Thursday, October 27, 2016 1:25 PM
> To: Lin, Derek (HPS UEFI Dev) 
> Cc: edk2-devel@lists.01.org; Shia, Cinnamon 
> Subject: Re: [edk2] [BaseTools] Library GUIDs missing from Guid.xref file.
> 
> 
> > On Oct 26, 2016, at 9:09 PM, Lin, Derek (HPS UEFI Dev)
>  wrote:
> >
> > Hi Andrew,
> >
> > We also see this issue recently. And we have a fix. I've send email 
> > patch
> minutes ago.
> >
> 
> Derek,
> 
> Thanks for sharing the fix.
> 
> I noticed it introduced a build failure for a badly formed library INF 
> file. I assume that means this fix is pulling in libraries that are in 
> the DSC file, but not currently being built? That is not really a 
> problem as it means you have too many GUID vs. not enough.
> 
> I also noticed that your fix adds the FILE_GUID values for all the 
> libraries. The FILE_GUID values for the any PEIM, DXE/UEFI driver that 
> end up in an FV will be present in the ROM, but the library values do 
> not end up in the ROM. Also by changing the code to use a Python 
> dictionary the order of everything changed. I had a debugger command 
> that would just dump out the FILE_GUDs, so it would be good to maintain the 
> old behavior.
> 
>  GuidDict = {}
>  for Arch in ArchList:
>  PlatformDataBase =
> BuildDb.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, 
> GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]
> -for ModuleFile in PlatformDataBase.Modules:
> +for ModuleFile in [x for x in PlatformDataBase.Modules] + 
> + [x for x in
> PlatformDataBase.LibraryInstances]:
>  Module = BuildDb.BuildObject[ModuleFile, Arch, 
> GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]
> -GuidXRefFile.write("%s %s\n" % (Module.Guid, 
> Module.BaseName))
> +if ModuleFile in PlatformDataBase.Modules:
> +GuidXRefFile.write("%s %s\n" % (Module.Guid,
> Module.BaseName))
>  for key, item in Module.Protocols.items():
>  GuidDict[key] = item
>  for key, item in Module.Guids.items():
> 
> If your adding ModuleGuidDict was a performance fix, I guess I could 
> just make it a list to keep order.
> 
> Thanks,
> 
> Andrew Fish
> 
> > Thanks,
> > Derek
> >
> > From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf 
> > Of
> Andrew Fish
> > Sent: Thursday, October 27, 2016 9:08 AM
> > To: edk2-devel 
> > Subject: [edk2] [BaseTools] Library GUIDs missing from Guid.xref file.
> >
> > I noticed if a GUID (PPI & Protocol) was only used via a library it 
> > does not
> end up in the Guid.xref file.
> >
> > It looks to me like this code is only extracting the GUIDs from the 
> > Drivers
> INF file and the GUIDs defined in dependent libraries are skipped?
> >
> >
> >
> https://github.com/tianocore/edk2/blob/master/BaseTools/Source/Python/
> GenFds/GenFds.py#L701
>  n/GenFds/GenFds.py#L701>
> >
> >for Arch in ArchList:
> >PlatformDataBase =
> BuildDb.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, 
> GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]
> >for ModuleFile in PlatformDataBase.Modules:
> >Module = BuildDb.BuildObject[ModuleFile, Arch,
> GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]
> >GuidXRefFile.write("%s %s\n" % (Module.Guid,
> Module.BaseName))
> >for key, item in Module.Protocols.items():
> >GuidDict[key] = item
> >for key, item in Module.Guids.items():
> >GuidDict[key] = item
> > 

[edk2] [patch] IntelFrameworkModulePkg/BootMaint: Show "Change Boot order" page correctly

2016-10-27 Thread Dandan Bi
Some boot options may be deleted in the "Delete Boot Option page",
But the data BootOptionOrder in BmmFakeNvData may not be updated.
So when user enter the "Change Boot Order" page, we should not always
get the BootOptionOrder in BmmFakeNvData, it will result in incorrect
UI behaviors. When the Boot Options have been saved,
we should get the BootOptionOrder through function GetBootOrder.

For driver option codes need to do the same change.

This patch is to fix the issue in bugzilla:
https://bugzilla.tianocore.org/show_bug.cgi?id=39

Cc: Eric Dong 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Dandan Bi 
---
 .../Universal/BdsDxe/BootMaint/UpdatePage.c| 22 +++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/UpdatePage.c 
b/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/UpdatePage.c
index b13ed11..b7fee3a 100644
--- a/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/UpdatePage.c
+++ b/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/UpdatePage.c
@@ -1,9 +1,9 @@
 /** @file
 Dynamically update the pages.
 
-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
 http://opensource.org/licenses/bsd-license.php
 
@@ -557,18 +557,34 @@ UpdateOrderPage (
   QuestionId = 0;
   VarOffset = 0;
   switch (UpdatePageId) { 
 
   case FORM_BOOT_CHG_ID:
-//GetBootOrder (CallbackData);
+//
+// If the BootOptionOrder in the BmmFakeNvData are same with the date in 
the BmmOldFakeNVData,
+// means all Boot Options has been save in BootOptionMenu, we can get the 
date from the menu.
+// else means browser maintains some uncommitted date which are not saved 
in BootOptionMenu,
+// so we should not get the data from BootOptionMenu to show it.
+//
+if (CompareMem (CallbackData->BmmFakeNvData.BootOptionOrder, 
CallbackData->BmmOldFakeNVData.BootOptionOrder, sizeof 
(CallbackData->BmmFakeNvData.BootOptionOrder)) == 0) {
+  GetBootOrder (CallbackData);
+}
 OptionOrder = CallbackData->BmmFakeNvData.BootOptionOrder;
 QuestionId = BOOT_OPTION_ORDER_QUESTION_ID;
 VarOffset = BOOT_OPTION_ORDER_VAR_OFFSET;
 break;
 
   case FORM_DRV_CHG_ID:
-//GetDriverOrder (CallbackData);
+//
+// If the DriverOptionOrder in the BmmFakeNvData are same with the date in 
the BmmOldFakeNVData,
+// means all Driver Options has been save in DriverOptionMenu, we can get 
the DriverOptionOrder from the menu.
+// else means browser maintains some uncommitted date which are not saved 
in DriverOptionMenu,
+// so we should not get the data from DriverOptionMenu to show it.
+//
+if (CompareMem (CallbackData->BmmFakeNvData.DriverOptionOrder, 
CallbackData->BmmOldFakeNVData.DriverOptionOrder, sizeof 
(CallbackData->BmmFakeNvData.DriverOptionOrder)) == 0) {
+  GetDriverOrder (CallbackData);
+}
 OptionOrder = CallbackData->BmmFakeNvData.DriverOptionOrder;
 QuestionId = DRIVER_OPTION_ORDER_QUESTION_ID;
 VarOffset = DRIVER_OPTION_ORDER_VAR_OFFSET;
 break;
   }  
-- 
1.9.5.msysgit.1

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


Re: [edk2] [patch] NetworkPkg: Add error handling logic when using AllocateZeorPool

2016-10-27 Thread Fu, Siyuan


Reviewed-by: Fu Siyuan siyuan...@intel.com


> -Original Message-
> From: Zhang, Lubo
> Sent: Thursday, October 27, 2016 3:41 PM
> To: edk2-devel@lists.01.org
> Cc: Fu, Siyuan ; Wu, Jiaxin 
> Subject: [patch] NetworkPkg: Add error handling logic when using
> AllocateZeorPool
> 
> Add error handling logic if failed to apply new memory.
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Zhang Lubo 
> Cc: Fu Siyuan 
> Cc: Wu Jiaxin 
> ---
>  NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c | 8 ++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c
> b/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c
> index 45377e3..eba8e1d 100644
> --- a/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c
> +++ b/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c
> @@ -1296,12 +1296,13 @@ PxeBcSelectDhcp6Offer (
>  /**
>Handle the DHCPv6 offer packet.
> 
>@param[in]  Private The pointer to PXEBC_PRIVATE_DATA.
> 
> -  @retval EFI_SUCCESS Handled the DHCPv6 offer packet
> successfully.
> -  @retval EFI_NO_RESPONSE No response to the following request
> packet.
> +  @retval EFI_SUCCESS   Handled the DHCPv6 offer packet
> successfully.
> +  @retval EFI_NO_RESPONSE   No response to the following request
> packet.
> +  @retval EFI_OUT_OF_RESOURCES  Failed to allocate resources.
> 
>  **/
>  EFI_STATUS
>  PxeBcHandleDhcp6Offer (
>IN PXEBC_PRIVATE_DATA*Private
> @@ -1323,10 +1324,13 @@ PxeBcHandleDhcp6Offer (
>//
>// First try to cache DNS server address if DHCP6 offer provides.
>//
>if (Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER] != NULL) {
>  Private->DnsServer = AllocateZeroPool (NTOHS (Cache6-
> >OptList[PXEBC_DHCP6_IDX_DNS_SERVER]->OpLen));
> +if (Private->DnsServer == NULL) {
> +  return EFI_OUT_OF_RESOURCES;
> +}
>  CopyMem (Private->DnsServer, Cache6-
> >OptList[PXEBC_DHCP6_IDX_DNS_SERVER]->Data, sizeof (EFI_IPv6_ADDRESS));
>}
> 
>if (Cache6->OfferType == PxeOfferTypeDhcpBinl) {
>  //
> --
> 1.9.5.msysgit.1

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


Re: [edk2] [patch] NetworkPkg: Add error handling logic when using AllocateZeorPool

2016-10-27 Thread Wu, Jiaxin
Reviewed-By: Wu Jiaxin 

Best Regards!
Jiaxin

> -Original Message-
> From: Zhang, Lubo
> Sent: Thursday, October 27, 2016 3:41 PM
> To: edk2-devel@lists.01.org
> Cc: Fu, Siyuan ; Wu, Jiaxin 
> Subject: [patch] NetworkPkg: Add error handling logic when using
> AllocateZeorPool
> 
> Add error handling logic if failed to apply new memory.
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Zhang Lubo 
> Cc: Fu Siyuan 
> Cc: Wu Jiaxin 
> ---
>  NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c | 8 ++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c
> b/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c
> index 45377e3..eba8e1d 100644
> --- a/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c
> +++ b/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c
> @@ -1296,12 +1296,13 @@ PxeBcSelectDhcp6Offer (
>  /**
>Handle the DHCPv6 offer packet.
> 
>@param[in]  Private The pointer to PXEBC_PRIVATE_DATA.
> 
> -  @retval EFI_SUCCESS Handled the DHCPv6 offer packet 
> successfully.
> -  @retval EFI_NO_RESPONSE No response to the following request 
> packet.
> +  @retval EFI_SUCCESS   Handled the DHCPv6 offer packet 
> successfully.
> +  @retval EFI_NO_RESPONSE   No response to the following request
> packet.
> +  @retval EFI_OUT_OF_RESOURCES  Failed to allocate resources.
> 
>  **/
>  EFI_STATUS
>  PxeBcHandleDhcp6Offer (
>IN PXEBC_PRIVATE_DATA*Private
> @@ -1323,10 +1324,13 @@ PxeBcHandleDhcp6Offer (
>//
>// First try to cache DNS server address if DHCP6 offer provides.
>//
>if (Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER] != NULL) {
>  Private->DnsServer = AllocateZeroPool (NTOHS (Cache6-
> >OptList[PXEBC_DHCP6_IDX_DNS_SERVER]->OpLen));
> +if (Private->DnsServer == NULL) {
> +  return EFI_OUT_OF_RESOURCES;
> +}
>  CopyMem (Private->DnsServer, Cache6-
> >OptList[PXEBC_DHCP6_IDX_DNS_SERVER]->Data, sizeof (EFI_IPv6_ADDRESS));
>}
> 
>if (Cache6->OfferType == PxeOfferTypeDhcpBinl) {
>  //
> --
> 1.9.5.msysgit.1

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


Re: [edk2] [PATCH] UefiCpuPkg: Move GetProcessorLocation() to SmmCpuFeaturesLib library.

2016-10-27 Thread Fan, Jeff
Leo and Mike,

GetProcessorLocation() are not only used by PiSmmCpuDxeSmm driver, it is also 
duplicated in UefiCpuPkg\Library\MpInitLib\MpLib.c. 

I suggest that we could add this API into UefiCpuPkg/Include/UefiCpuLib or 
UefiCpuPkg/Include/ LocalApicLib.h.
Thus, it could be consumed by modules across PEI/DXE/SMM modules.

Thanks!
Jeff

-Original Message-
From: Kinney, Michael D 
Sent: Friday, October 28, 2016 7:16 AM
To: Leo Duran; edk2-devel@lists.01.org; Kinney, Michael D
Cc: Gao, Liming; Fan, Jeff
Subject: RE: [edk2] [PATCH] UefiCpuPkg: Move GetProcessorLocation() to 
SmmCpuFeaturesLib library.

Leo,

This looks like a good proposed change to the SmmFeaturesLib and PiSmmCpuDxeSmm 
module.

Adding UefiCpuPkg maintainer Jeff Fan to the Cc list.

There are 3 implementations of the SmmFeaturesLib in edk2/master.
This patch needs to update all 3, or some of the platforms in edk2/master will 
no longer build:

* OvmfPkg\Library\SmmCpuFeaturesLib
* QuarkSocPkg\QuarkNorthCluster\Library\SmmCpuFeaturesLib
* UefiCpuPkg\Library\SmmCpuFeaturesLib

Thanks,

Mike

> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of 
> Leo Duran
> Sent: Thursday, October 27, 2016 3:30 PM
> To: edk2-devel@lists.01.org
> Cc: Leo Duran ; Gao, Liming 
> Subject: [edk2] [PATCH] UefiCpuPkg: Move GetProcessorLocation() to 
> SmmCpuFeaturesLib library.
> 
> 1) Remove SmmGetProcessorLocation() from PiSmmCpuDxeSmm driver
> 2) Add SmmCpuFeaturesGetProcessorLocation() to SmmCpuFeaturesLib 
> library
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Leo Duran  
> ---
>  UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h |  17 +++
>  .../Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c  | 118 
>  UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c | 121 
> +
>  3 files changed, 136 insertions(+), 120 deletions(-)
> 
> diff --git a/UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h
> b/UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h
> index 4478003..dd14ec5 100644
> --- a/UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h
> +++ b/UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h
> @@ -398,4 +398,21 @@ SmmCpuFeaturesAllocatePageTableMemory (
>IN UINTN   Pages
>);
> 
> +/**
> +  Get Package ID/Core ID/Thread ID of a processor.
> +
> +  APIC ID must be an initial APIC ID.
> +
> +  The algorithm assumes the target system has symmetry across 
> + physical package
> boundaries
> +  with respect to the number of logical processors per package, 
> + number of cores per
> package.
> +
> +  @param  ApicIdAPIC ID of the target logical processor.
> +  @param  LocationReturns the processor location information.
> +**/
> +VOID
> +SmmCpuFeaturesGetProcessorLocation (
> +  IN UINT32 ApicId,
> +  OUT EFI_CPU_PHYSICAL_LOCATION *Location
> +  );
> +
>  #endif
> diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
> b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
> index 1754f2d..1e300f3 100644
> --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
> +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
> @@ -673,3 +673,121 @@ SmmCpuFeaturesAllocatePageTableMemory (
>return NULL;
>  }
> 
> +/**
> +  Get Package ID/Core ID/Thread ID of a processor.
> +
> +  APIC ID must be an initial APIC ID.
> +
> +  The algorithm below assumes the target system has symmetry across 
> + physical package
> boundaries
> +  with respect to the number of logical processors per package, 
> + number of cores per
> package.
> +
> +  @param  ApicIdAPIC ID of the target logical processor.
> +  @param  LocationReturns the processor location information.
> +**/
> +VOID
> +SmmCpuFeaturesGetProcessorLocation (
> +  IN UINT32 ApicId,
> +  OUT EFI_CPU_PHYSICAL_LOCATION *Location
> +  )
> +{
> +  UINTN   ThreadBits;
> +  UINTN   CoreBits;
> +  UINT32  RegEax;
> +  UINT32  RegEbx;
> +  UINT32  RegEcx;
> +  UINT32  RegEdx;
> +  UINT32  MaxCpuIdIndex;
> +  UINT32  SubIndex;
> +  UINTN   LevelType;
> +  UINT32  MaxLogicProcessorsPerPackage;
> +  UINT32  MaxCoresPerPackage;
> +  BOOLEAN TopologyLeafSupported;
> +
> +  ASSERT (Location != NULL);
> +
> +  ThreadBits= 0;
> +  CoreBits  = 0;
> +  TopologyLeafSupported = FALSE;
> +
> +  //
> +  // Check if the processor is capable of supporting more than one logical 
> processor.
> +  //
> +  AsmCpuid (CPUID_VERSION_INFO, NULL, NULL, NULL, );  ASSERT 
> + ((RegEdx & BIT28) != 0);
> +
> +  //
> +  // Assume three-level mapping of APIC ID: Package:Core:SMT.
> +  //
> +
> +  //
> +  // Get the max index of basic CPUID  //  AsmCpuid (CPUID_SIGNATURE, 
> + , NULL, NULL, NULL);
> +
> +  //
> +  // If the extended topology enumeration leaf is available, it  // 
> + is the preferred mechanism for enumerating topology.
> +  //
> +  if (MaxCpuIdIndex >= CPUID_EXTENDED_TOPOLOGY) {
> +

Re: [edk2] [PATCH] UefiCpuPkg: Move GetProcessorLocation() to SmmCpuFeaturesLib library.

2016-10-27 Thread Fan, Jeff
Because the CPU location information are gotten from Initial APIC ID,  it makes 
more sense to be added into Local APIC Lib. 

The following is my proposal on its definition.
/**
  Get CPU Package/Core/Thread location information.

  @param[in]  InitialApicIdCPU APIC ID
  @param[out] Package Pointer to Package ID
  @param[out] Core  Pointer to Core ID
  @param[out] Thread  Pointer to Thread ID
**/
VOID
ExtractProcessorLocation (
  IN  UINT32 InitialApicId,
  OUT UINT32  *Package,
  OUT UINT32  *Core,
  OUT UINT32  *Thread
  );

Leo,  is it OK to meet your requirement?

Thanks!
Jeff

-Original Message-
From: Fan, Jeff 
Sent: Friday, October 28, 2016 8:45 AM
To: Kinney, Michael D; Leo Duran; edk2-devel@lists.01.org
Cc: Gao, Liming
Subject: RE: [edk2] [PATCH] UefiCpuPkg: Move GetProcessorLocation() to 
SmmCpuFeaturesLib library.

Leo and Mike,

GetProcessorLocation() are not only used by PiSmmCpuDxeSmm driver, it is also 
duplicated in UefiCpuPkg\Library\MpInitLib\MpLib.c. 

I suggest that we could add this API into UefiCpuPkg/Include/UefiCpuLib or 
UefiCpuPkg/Include/ LocalApicLib.h.
Thus, it could be consumed by modules across PEI/DXE/SMM modules.

Thanks!
Jeff

-Original Message-
From: Kinney, Michael D
Sent: Friday, October 28, 2016 7:16 AM
To: Leo Duran; edk2-devel@lists.01.org; Kinney, Michael D
Cc: Gao, Liming; Fan, Jeff
Subject: RE: [edk2] [PATCH] UefiCpuPkg: Move GetProcessorLocation() to 
SmmCpuFeaturesLib library.

Leo,

This looks like a good proposed change to the SmmFeaturesLib and PiSmmCpuDxeSmm 
module.

Adding UefiCpuPkg maintainer Jeff Fan to the Cc list.

There are 3 implementations of the SmmFeaturesLib in edk2/master.
This patch needs to update all 3, or some of the platforms in edk2/master will 
no longer build:

* OvmfPkg\Library\SmmCpuFeaturesLib
* QuarkSocPkg\QuarkNorthCluster\Library\SmmCpuFeaturesLib
* UefiCpuPkg\Library\SmmCpuFeaturesLib

Thanks,

Mike

> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of 
> Leo Duran
> Sent: Thursday, October 27, 2016 3:30 PM
> To: edk2-devel@lists.01.org
> Cc: Leo Duran ; Gao, Liming 
> Subject: [edk2] [PATCH] UefiCpuPkg: Move GetProcessorLocation() to 
> SmmCpuFeaturesLib library.
> 
> 1) Remove SmmGetProcessorLocation() from PiSmmCpuDxeSmm driver
> 2) Add SmmCpuFeaturesGetProcessorLocation() to SmmCpuFeaturesLib 
> library
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Leo Duran  
> ---
>  UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h |  17 +++
>  .../Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c  | 118 
>  UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c | 121 
> +
>  3 files changed, 136 insertions(+), 120 deletions(-)
> 
> diff --git a/UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h
> b/UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h
> index 4478003..dd14ec5 100644
> --- a/UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h
> +++ b/UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h
> @@ -398,4 +398,21 @@ SmmCpuFeaturesAllocatePageTableMemory (
>IN UINTN   Pages
>);
> 
> +/**
> +  Get Package ID/Core ID/Thread ID of a processor.
> +
> +  APIC ID must be an initial APIC ID.
> +
> +  The algorithm assumes the target system has symmetry across 
> + physical package
> boundaries
> +  with respect to the number of logical processors per package, 
> + number of cores per
> package.
> +
> +  @param  ApicIdAPIC ID of the target logical processor.
> +  @param  LocationReturns the processor location information.
> +**/
> +VOID
> +SmmCpuFeaturesGetProcessorLocation (
> +  IN UINT32 ApicId,
> +  OUT EFI_CPU_PHYSICAL_LOCATION *Location
> +  );
> +
>  #endif
> diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
> b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
> index 1754f2d..1e300f3 100644
> --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
> +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
> @@ -673,3 +673,121 @@ SmmCpuFeaturesAllocatePageTableMemory (
>return NULL;
>  }
> 
> +/**
> +  Get Package ID/Core ID/Thread ID of a processor.
> +
> +  APIC ID must be an initial APIC ID.
> +
> +  The algorithm below assumes the target system has symmetry across 
> + physical package
> boundaries
> +  with respect to the number of logical processors per package, 
> + number of cores per
> package.
> +
> +  @param  ApicIdAPIC ID of the target logical processor.
> +  @param  LocationReturns the processor location information.
> +**/
> +VOID
> +SmmCpuFeaturesGetProcessorLocation (
> +  IN UINT32 ApicId,
> +  OUT EFI_CPU_PHYSICAL_LOCATION *Location
> +  )
> +{
> +  UINTN   ThreadBits;
> +  UINTN   CoreBits;
> +  UINT32  RegEax;
> +  UINT32  RegEbx;
> +  UINT32  RegEcx;
> +  UINT32  RegEdx;

Re: [edk2] [PATCH] BaseTool/Pkcs7: Add TestRoot.cer.

2016-10-27 Thread Yao, Jiewen
Yes, I am glad to.

I have a step by step internally. Will write a MD in a new patch.

From: Kinney, Michael D
Sent: Friday, October 28, 2016 6:00 AM
To: Yao, Jiewen ; edk2-devel@lists.01.org; Kinney, 
Michael D 
Cc: Gao, Liming 
Subject: RE: [edk2] [PATCH] BaseTool/Pkcs7: Add TestRoot.cer.

Jiewen,

Reviewed-by: Michael D Kinney 
>

Can you please add a Readme.MD to this directory that
provides a brief description of each file in this
directory and how each file was created/generated.

  TestCert.pem
  TestCert.pub.pem
  TestRoot.cer
  TestRoot.pem
  TestRoot.pub.pem
  TestSub.pem
  TestSub.pub.pem

Thanks,

Mike

> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Jiewen 
> Yao
> Sent: Saturday, October 22, 2016 7:26 PM
> To: edk2-devel@lists.01.org
> Cc: Kinney, Michael D 
> >; Gao, Liming 
> >
> Subject: [edk2] [PATCH] BaseTool/Pkcs7: Add TestRoot.cer.
>
> We add this binary data file for TestRoot.cer.
> So that a platform may include this default file in FDF,
> to check if the platform is using default test key,
> or different production key.
>
> Cc: Yonghong Zhu >
> Cc: Liming Gao >
> Cc: Michael D Kinney 
> >
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Jiewen Yao >
> Reviewed-by: Yonghong Zhu 
> >
> ---
>  BaseTools/Source/Python/Pkcs7Sign/TestRoot.cer | Bin 0 -> 756 bytes
>  1 file changed, 0 insertions(+), 0 deletions(-)
>  create mode 100644 BaseTools/Source/Python/Pkcs7Sign/TestRoot.cer
>
> diff --git a/BaseTools/Source/Python/Pkcs7Sign/TestRoot.cer
> b/BaseTools/Source/Python/Pkcs7Sign/TestRoot.cer
> new file mode 100644
> index
> ..e42f073d84af32513cc83f292ebc78ca6b5a6239
> GIT binary patch
> literal 756
> zcmXqLV)|gv#CT@`GZP~dlYohVdOfS{)K=#OOTO~VdVb1)lZ{oIkC{o9mBB#RP|$#%
> zjX9KsS(qavwYVfGKflC4PMp`!%)r9H#L(2h(8MB2oY(8w5wOf5| zW#iOp^Jx3d%gD%D~*j$j< zyvcjFy_vLRLSXE%{;h}GMDHgw?AuWh89n>2`lQS=r~2)ypNf^*~>Y)m)nqq
> zVO!UMm0uMv*q_~yUK?Pn_gh*=Oz!gSAyBoXL7skmz{9zc71LVkJp+Ni) z*Y^KA_~NO$?ayViWZ%q+PYTqVA*;D7yX&_zUxwz_ed!)98m|9jtpkd(4(#Tc=_}
> zd3pOcqxp7XG4IZ>?iGLG7PLN~YgwIGW^-nAp6~JV4Li<$OS9jXv*5)XwS-+OS??Bl
> z?PXZO^F3g-%Qd@pMH}5`#_Dm3>O1dPcwDoZ_E6kCHT9e=6Eh z*cw@<;fq9II5RS2^FH9Z@GjbZTd_ydi!ad+
> z-`-?6`jju@cd)TRR>H1#7SVyp1y}1>|2=Wl5>1l+bE9-}*tchFt%~0{+|_peWA$
> z6!OKA(oALZ(RwtFEJ`wDc>VYHKwneptH-3DJvz-)97@p$v>4RE*lQ56_;kM
> zy@w~z0-_Nkct8mhK8cH3A4JyZX6X@_fee7*MuW!4w#(_cKw(VzdLxc;#Co=sWN
> zTA#Bo->JW^e_=Hn+npy-jagY){m_J)IS8>JiHRdsT%L w&)Fjtxk78LRUM;B^Y;yj&-VJ?oH${*)=nPl)l(H@K9rne+9eYEaiXdh0N3>|0{{R3
>
> literal 0
> HcmV?d1
>
> --
> 2.7.4.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] UefiCpuPkg: Move GetProcessorLocation() to SmmCpuFeaturesLib library.

2016-10-27 Thread Kinney, Michael D
Leo,

This looks like a good proposed change to the SmmFeaturesLib and
PiSmmCpuDxeSmm module.

Adding UefiCpuPkg maintainer Jeff Fan to the Cc list.

There are 3 implementations of the SmmFeaturesLib in edk2/master.
This patch needs to update all 3, or some of the platforms in 
edk2/master will no longer build:

* OvmfPkg\Library\SmmCpuFeaturesLib
* QuarkSocPkg\QuarkNorthCluster\Library\SmmCpuFeaturesLib
* UefiCpuPkg\Library\SmmCpuFeaturesLib

Thanks,

Mike

> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Leo 
> Duran
> Sent: Thursday, October 27, 2016 3:30 PM
> To: edk2-devel@lists.01.org
> Cc: Leo Duran ; Gao, Liming 
> Subject: [edk2] [PATCH] UefiCpuPkg: Move GetProcessorLocation() to 
> SmmCpuFeaturesLib
> library.
> 
> 1) Remove SmmGetProcessorLocation() from PiSmmCpuDxeSmm driver
> 2) Add SmmCpuFeaturesGetProcessorLocation() to SmmCpuFeaturesLib library
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Leo Duran  
> ---
>  UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h |  17 +++
>  .../Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c  | 118 
>  UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c | 121 
> +
>  3 files changed, 136 insertions(+), 120 deletions(-)
> 
> diff --git a/UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h
> b/UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h
> index 4478003..dd14ec5 100644
> --- a/UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h
> +++ b/UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h
> @@ -398,4 +398,21 @@ SmmCpuFeaturesAllocatePageTableMemory (
>IN UINTN   Pages
>);
> 
> +/**
> +  Get Package ID/Core ID/Thread ID of a processor.
> +
> +  APIC ID must be an initial APIC ID.
> +
> +  The algorithm assumes the target system has symmetry across physical 
> package
> boundaries
> +  with respect to the number of logical processors per package, number of 
> cores per
> package.
> +
> +  @param  ApicIdAPIC ID of the target logical processor.
> +  @param  LocationReturns the processor location information.
> +**/
> +VOID
> +SmmCpuFeaturesGetProcessorLocation (
> +  IN UINT32 ApicId,
> +  OUT EFI_CPU_PHYSICAL_LOCATION *Location
> +  );
> +
>  #endif
> diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
> b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
> index 1754f2d..1e300f3 100644
> --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
> +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
> @@ -673,3 +673,121 @@ SmmCpuFeaturesAllocatePageTableMemory (
>return NULL;
>  }
> 
> +/**
> +  Get Package ID/Core ID/Thread ID of a processor.
> +
> +  APIC ID must be an initial APIC ID.
> +
> +  The algorithm below assumes the target system has symmetry across physical 
> package
> boundaries
> +  with respect to the number of logical processors per package, number of 
> cores per
> package.
> +
> +  @param  ApicIdAPIC ID of the target logical processor.
> +  @param  LocationReturns the processor location information.
> +**/
> +VOID
> +SmmCpuFeaturesGetProcessorLocation (
> +  IN UINT32 ApicId,
> +  OUT EFI_CPU_PHYSICAL_LOCATION *Location
> +  )
> +{
> +  UINTN   ThreadBits;
> +  UINTN   CoreBits;
> +  UINT32  RegEax;
> +  UINT32  RegEbx;
> +  UINT32  RegEcx;
> +  UINT32  RegEdx;
> +  UINT32  MaxCpuIdIndex;
> +  UINT32  SubIndex;
> +  UINTN   LevelType;
> +  UINT32  MaxLogicProcessorsPerPackage;
> +  UINT32  MaxCoresPerPackage;
> +  BOOLEAN TopologyLeafSupported;
> +
> +  ASSERT (Location != NULL);
> +
> +  ThreadBits= 0;
> +  CoreBits  = 0;
> +  TopologyLeafSupported = FALSE;
> +
> +  //
> +  // Check if the processor is capable of supporting more than one logical 
> processor.
> +  //
> +  AsmCpuid (CPUID_VERSION_INFO, NULL, NULL, NULL, );
> +  ASSERT ((RegEdx & BIT28) != 0);
> +
> +  //
> +  // Assume three-level mapping of APIC ID: Package:Core:SMT.
> +  //
> +
> +  //
> +  // Get the max index of basic CPUID
> +  //
> +  AsmCpuid (CPUID_SIGNATURE, , NULL, NULL, NULL);
> +
> +  //
> +  // If the extended topology enumeration leaf is available, it
> +  // is the preferred mechanism for enumerating topology.
> +  //
> +  if (MaxCpuIdIndex >= CPUID_EXTENDED_TOPOLOGY) {
> +AsmCpuidEx (CPUID_EXTENDED_TOPOLOGY, 0, , , , NULL);
> +//
> +// If CPUID.(EAX=0BH, ECX=0H):EBX returns zero and maximum input value 
> for
> +// basic CPUID information is greater than 0BH, then CPUID.0BH leaf is 
> not
> +// supported on that processor.
> +//
> +if ((RegEbx & 0x) != 0) {
> +  TopologyLeafSupported = TRUE;
> +
> +  //
> +  // Sub-leaf index 0 (ECX= 0 as input) provides enumeration parameters 
> to extract
> +  // the SMT sub-field of x2APIC ID.
> +  //
> +  LevelType = (RegEcx >> 8) & 0xff;
> +  ASSERT (LevelType == 

[edk2] [PATCH] PiSmmCpuDxeSmm

2016-10-27 Thread Leo Duran
This patch moves code that uses Intel-specific CPUID to a library.

Leo Duran (1):
  UefiCpuPkg: Move GetProcessorLocation() to SmmCpuFeaturesLib library.

 UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h |  17 +++
 .../Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c  | 118 
 UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c | 121 +
 3 files changed, 136 insertions(+), 120 deletions(-)

-- 
1.9.1

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


[edk2] [PATCH] UefiCpuPkg: Move GetProcessorLocation() to SmmCpuFeaturesLib library.

2016-10-27 Thread Leo Duran
1) Remove SmmGetProcessorLocation() from PiSmmCpuDxeSmm driver
2) Add SmmCpuFeaturesGetProcessorLocation() to SmmCpuFeaturesLib library

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Leo Duran  
---
 UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h |  17 +++
 .../Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c  | 118 
 UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c | 121 +
 3 files changed, 136 insertions(+), 120 deletions(-)

diff --git a/UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h 
b/UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h
index 4478003..dd14ec5 100644
--- a/UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h
+++ b/UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h
@@ -398,4 +398,21 @@ SmmCpuFeaturesAllocatePageTableMemory (
   IN UINTN   Pages
   );
 
+/**
+  Get Package ID/Core ID/Thread ID of a processor.
+
+  APIC ID must be an initial APIC ID.
+
+  The algorithm assumes the target system has symmetry across physical package 
boundaries
+  with respect to the number of logical processors per package, number of 
cores per package.
+
+  @param  ApicIdAPIC ID of the target logical processor.
+  @param  LocationReturns the processor location information.
+**/
+VOID
+SmmCpuFeaturesGetProcessorLocation (
+  IN UINT32 ApicId,
+  OUT EFI_CPU_PHYSICAL_LOCATION *Location
+  );
+
 #endif
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c 
b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
index 1754f2d..1e300f3 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
@@ -673,3 +673,121 @@ SmmCpuFeaturesAllocatePageTableMemory (
   return NULL;
 }
 
+/**
+  Get Package ID/Core ID/Thread ID of a processor.
+
+  APIC ID must be an initial APIC ID.
+
+  The algorithm below assumes the target system has symmetry across physical 
package boundaries
+  with respect to the number of logical processors per package, number of 
cores per package.
+
+  @param  ApicIdAPIC ID of the target logical processor.
+  @param  LocationReturns the processor location information.
+**/
+VOID
+SmmCpuFeaturesGetProcessorLocation (
+  IN UINT32 ApicId,
+  OUT EFI_CPU_PHYSICAL_LOCATION *Location
+  )
+{
+  UINTN   ThreadBits;
+  UINTN   CoreBits;
+  UINT32  RegEax;
+  UINT32  RegEbx;
+  UINT32  RegEcx;
+  UINT32  RegEdx;
+  UINT32  MaxCpuIdIndex;
+  UINT32  SubIndex;
+  UINTN   LevelType;
+  UINT32  MaxLogicProcessorsPerPackage;
+  UINT32  MaxCoresPerPackage;
+  BOOLEAN TopologyLeafSupported;
+
+  ASSERT (Location != NULL);
+
+  ThreadBits= 0;
+  CoreBits  = 0;
+  TopologyLeafSupported = FALSE;
+
+  //
+  // Check if the processor is capable of supporting more than one logical 
processor.
+  //
+  AsmCpuid (CPUID_VERSION_INFO, NULL, NULL, NULL, );
+  ASSERT ((RegEdx & BIT28) != 0);
+
+  //
+  // Assume three-level mapping of APIC ID: Package:Core:SMT.
+  //
+
+  //
+  // Get the max index of basic CPUID
+  //
+  AsmCpuid (CPUID_SIGNATURE, , NULL, NULL, NULL);
+
+  //
+  // If the extended topology enumeration leaf is available, it
+  // is the preferred mechanism for enumerating topology.
+  //
+  if (MaxCpuIdIndex >= CPUID_EXTENDED_TOPOLOGY) {
+AsmCpuidEx (CPUID_EXTENDED_TOPOLOGY, 0, , , , NULL);
+//
+// If CPUID.(EAX=0BH, ECX=0H):EBX returns zero and maximum input value for
+// basic CPUID information is greater than 0BH, then CPUID.0BH leaf is not
+// supported on that processor.
+//
+if ((RegEbx & 0x) != 0) {
+  TopologyLeafSupported = TRUE;
+
+  //
+  // Sub-leaf index 0 (ECX= 0 as input) provides enumeration parameters to 
extract
+  // the SMT sub-field of x2APIC ID.
+  //
+  LevelType = (RegEcx >> 8) & 0xff;
+  ASSERT (LevelType == CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_SMT);
+  if ((RegEbx & 0x) > 1 ) {
+ThreadBits = RegEax & 0x1f;
+  } else {
+//
+// HT is not supported
+//
+ThreadBits = 0;
+  }
+
+  //
+  // Software must not assume any "level type" encoding
+  // value to be related to any sub-leaf index, except sub-leaf 0.
+  //
+  SubIndex = 1;
+  do {
+AsmCpuidEx (CPUID_EXTENDED_TOPOLOGY, SubIndex, , NULL, , 
NULL);
+LevelType = (RegEcx >> 8) & 0xff;
+if (LevelType == CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_CORE) {
+  CoreBits = (RegEax & 0x1f) - ThreadBits;
+  break;
+}
+SubIndex++;
+  } while (LevelType != CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_INVALID);
+}
+  }
+
+  if (!TopologyLeafSupported) {
+AsmCpuid (CPUID_VERSION_INFO, NULL, , NULL, NULL);
+MaxLogicProcessorsPerPackage = (RegEbx >> 16) & 0xff;
+if (MaxCpuIdIndex >= CPUID_CACHE_PARAMS) {
+  AsmCpuidEx (CPUID_CACHE_PARAMS, 0, , NULL, NULL, NULL);
+  MaxCoresPerPackage = (RegEax >> 26) + 1;
+} else {
+  //
+  // 

Re: [edk2] [PATCH] BaseTool/Pkcs7: Add TestRoot.cer.

2016-10-27 Thread Kinney, Michael D
Jiewen,

Reviewed-by: Michael D Kinney 

Can you please add a Readme.MD to this directory that 
provides a brief description of each file in this
directory and how each file was created/generated.

  TestCert.pem
  TestCert.pub.pem
  TestRoot.cer
  TestRoot.pem
  TestRoot.pub.pem
  TestSub.pem
  TestSub.pub.pem

Thanks,

Mike

> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Jiewen 
> Yao
> Sent: Saturday, October 22, 2016 7:26 PM
> To: edk2-devel@lists.01.org
> Cc: Kinney, Michael D ; Gao, Liming 
> 
> Subject: [edk2] [PATCH] BaseTool/Pkcs7: Add TestRoot.cer.
> 
> We add this binary data file for TestRoot.cer.
> So that a platform may include this default file in FDF,
> to check if the platform is using default test key,
> or different production key.
> 
> Cc: Yonghong Zhu 
> Cc: Liming Gao 
> Cc: Michael D Kinney 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Jiewen Yao 
> Reviewed-by: Yonghong Zhu 
> ---
>  BaseTools/Source/Python/Pkcs7Sign/TestRoot.cer | Bin 0 -> 756 bytes
>  1 file changed, 0 insertions(+), 0 deletions(-)
>  create mode 100644 BaseTools/Source/Python/Pkcs7Sign/TestRoot.cer
> 
> diff --git a/BaseTools/Source/Python/Pkcs7Sign/TestRoot.cer
> b/BaseTools/Source/Python/Pkcs7Sign/TestRoot.cer
> new file mode 100644
> index
> ..e42f073d84af32513cc83f292ebc78ca6b5a6239
> GIT binary patch
> literal 756
> zcmXqLV)|gv#CT@`GZP~dlYohVdOfS{)K=#OOTO~VdVb1)lZ{oIkC{o9mBB#RP|$#%
> zjX9KsS(qavwYVfGKflC4PMp`!%)r9H#L(2h(8MB2oY(8w5wOf5| zW#iOp^Jx3d%gD%D~*j$j< zyvcjFy_vLRLSXE%{;h}GMDHgw?AuWh89n>2`lQS=r~2)ypNf^*~>Y)m)nqq
> zVO!UMm0uMv*q_~yUK?Pn_gh*=Oz!gSAyBoXL7skmz{9zc71LVkJp+Ni) z*Y^KA_~NO$?ayViWZ%q+PYTqVA*;D7yX&_zUxwz_ed!)98m|9jtpkd(4(#Tc=_}
> zd3pOcqxp7XG4IZ>?iGLG7PLN~YgwIGW^-nAp6~JV4Li<$OS9jXv*5)XwS-+OS??Bl
> z?PXZO^F3g-%Qd@pMH}5`#_Dm3>O1dPcwDoZ_E6kCHT9e=6Eh z*cw@<;fq9II5RS2^FH9Z@GjbZTd_ydi!ad+
> z-`-?6`jju@cd)TRR>H1#7SVyp1y}1>|2=Wl5>1l+bE9-}*tchFt%~0{+|_peWA$
> z6!OKA(oALZ(RwtFEJ`wDc>VYHKwneptH-3DJvz-)97@p$v>4RE*lQ56_;kM
> zy@w~z0-_Nkct8mhK8cH3A4JyZX6X@_fee7*MuW!4w#(_cKw(VzdLxc;#Co=sWN
> zTA#Bo->JW^e_=Hn+npy-jagY){m_J)IS8>JiHRdsT%L w&)Fjtxk78LRUM;B^Y;yj&-VJ?oH${*)=nPl)l(H@K9rne+9eYEaiXdh0N3>|0{{R3
> 
> literal 0
> HcmV?d1
> 
> --
> 2.7.4.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] [shell] AliasLower never used in InternalSetAlias

2016-10-27 Thread Tim Lewis
I would also note that GetAlias() has similar logic, but does, in fact use the 
AliasLower. As far as I can tell, the specification does not say anything about 
case-insensitive, so I believe this to be in error.

Tim

-Original Message-
From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Tim Lewis
Sent: Thursday, October 27, 2016 2:11 PM
To: edk2-devel@lists.01.org
Subject: [edk2] [shell] AliasLower never used in InternalSetAlias

In the function InternalSetAlias, it appears that AliasLower is duplicated 
(fromAlias), converted to lower case and freed ,but never actually used. Am I 
missing something?

  // Convert to lowercase to make aliases case-insensitive
  if (Alias != NULL) {
AliasLower = AllocateCopyPool (StrSize (Alias), Alias);
if (AliasLower == NULL) {
  return EFI_OUT_OF_RESOURCES;
}
ToLower (AliasLower);
  } else {
AliasLower = NULL;
  }

  //
  // We must be trying to remove one if Alias is NULL
  //
  if (Alias == NULL) {
//
// remove an alias (but passed in COMMAND parameter)
//
Status = (gRT->SetVariable((CHAR16*)Command, , 0, 0, NULL));
  } else {
//
// Add and replace are the same
//

// We dont check the error return on purpose since the variable may not 
exist.
gRT->SetVariable((CHAR16*)Command, , 0, 0, NULL);

Status = (gRT->SetVariable((CHAR16*)Alias, , 
EFI_VARIABLE_BOOTSERVICE_ACCESS|(Volatile?0:EFI_VARIABLE_NON_VOLATILE), 
StrSize(Command), (VOID*)Command));
  }

  if (Alias != NULL) {
FreePool (AliasLower);
  }
___
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] [shell]cd.. and cd\ are not valid alias

2016-10-27 Thread Tim Lewis
But the EDK2 registers them as a part of Level 2 supported command 
initialization.

  ShellCommandRegisterAlias(L"cd ..", L"cd..");
  ShellCommandRegisterAlias(L"cd \\", L"cd\\");

According to the SetAlias() description:

An alias is a C-style identifier

The same language is repeated in 3.6.4.


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


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

2016-10-27 Thread Felix Poludov
UefiLib library class (MdePkg ) includes CreatePopUp function.
The function displays a message box.
There is certainly more than one way to draw a message box.
If homogenous user interface is a project requirement,
CreatePopUp is likely to be overridden to align message box appearance with the 
platform look and feel.
The function can be overridden by creating a project specific UefiLib instance, 
but this seems like an overkill
because the rest of the UefiLib, which is quite big, would have to be 
duplicated.

One way to solve the problem is to move CreatePopUp to a new library class, 
however, this may break existing projects.
I suggest changing CreatePopUp implementation to delegate pop up drawing to a 
new
function UiCreatePopUp provided by a new library class UiLib.h.

I would like to solicit feedback for this proposal.
If there will be no major objections, I'll start working on a patch.

Thanks
Felix

Please consider the environment before printing this email.

The information contained in this message may be confidential and proprietary 
to American Megatrends, Inc.  This communication is intended to be read only by 
the individual or entity to whom it is addressed or by their designee. If the 
reader of this message is not the intended recipient, you are on notice that 
any distribution of this message, in any form, is strictly prohibited.  Please 
promptly notify the sender by reply e-mail or by telephone at 770-246-8600, and 
then delete or destroy all copies of the transmission.
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [shell] AliasLower never used in InternalSetAlias

2016-10-27 Thread Tim Lewis
In the function InternalSetAlias, it appears that AliasLower is duplicated 
(fromAlias), converted to lower case and freed ,but never actually used. Am I 
missing something?

  // Convert to lowercase to make aliases case-insensitive
  if (Alias != NULL) {
AliasLower = AllocateCopyPool (StrSize (Alias), Alias);
if (AliasLower == NULL) {
  return EFI_OUT_OF_RESOURCES;
}
ToLower (AliasLower);
  } else {
AliasLower = NULL;
  }

  //
  // We must be trying to remove one if Alias is NULL
  //
  if (Alias == NULL) {
//
// remove an alias (but passed in COMMAND parameter)
//
Status = (gRT->SetVariable((CHAR16*)Command, , 0, 0, NULL));
  } else {
//
// Add and replace are the same
//

// We dont check the error return on purpose since the variable may not 
exist.
gRT->SetVariable((CHAR16*)Command, , 0, 0, NULL);

Status = (gRT->SetVariable((CHAR16*)Alias, , 
EFI_VARIABLE_BOOTSERVICE_ACCESS|(Volatile?0:EFI_VARIABLE_NON_VOLATILE), 
StrSize(Command), (VOID*)Command));
  }

  if (Alias != NULL) {
FreePool (AliasLower);
  }
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH 2/3] MdeModulePkg/TerminalDxe: Optimize TtyTerm cursor motion

2016-10-27 Thread Kinney, Michael D
Committed at

https://github.com/tianocore/edk2/commit/d1b757e2cd034e32676c5cc2d542f785e74f8c5d


Mike


> -Original Message-
> From: Kinney, Michael D
> Sent: Thursday, October 27, 2016 11:14 AM
> To: Brian J. Johnson ; edk2-devel@lists.01.org; Kinney, 
> Michael D
> 
> Cc: Tian, Feng ; Zeng, Star 
> Subject: RE: [edk2] [PATCH 2/3] MdeModulePkg/TerminalDxe: Optimize TtyTerm 
> cursor
> motion
> 
> Brian,
> 
> Thanks.  I will do the commit with your rb.
> 
> Mike
> 
> > -Original Message-
> > From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of 
> > Brian J.
> Johnson
> > Sent: Thursday, October 27, 2016 11:06 AM
> > To: Kinney, Michael D ; edk2-devel@lists.01.org
> > Cc: Tian, Feng ; Zeng, Star 
> > Subject: Re: [edk2] [PATCH 2/3] MdeModulePkg/TerminalDxe: Optimize TtyTerm 
> > cursor
> > motion
> >
> > On 10/26/2016 10:09 PM, Kinney, Michael D wrote:
> > > Tian Feng,
> > >
> > > Unfortunately, this patch that was pushed to edk2/master today
> > > breaks on IA32 VS2015x86 builds with a signed/unsigned mismatch
> > > on 3 lines.  I think the right fix might be:
> > >
> > > diff --git a/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConOut.c
> > b/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConOut.c
> > > index e9b5ed0..9625f4d 100644
> > > --- a/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConOut.c
> > > +++ b/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConOut.c
> > > @@ -790,13 +790,13 @@ TerminalConOutSetCursorPosition (
> > >// it isn't necessary.
> > >//
> > >if (TerminalDevice->TerminalType == TTYTERMTYPE &&
> > > -  Mode->CursorRow == Row) {
> > > -if (Mode->CursorColumn > Column) {
> > > +  (UINTN)Mode->CursorRow == Row) {
> > > +if ((UINTN)Mode->CursorColumn > Column) {
> > >mCursorBackwardString[FW_BACK_OFFSET + 0] = (CHAR16) ('0' + ((Mode-
> > >CursorColumn - Column) / 10));
> > >mCursorBackwardString[FW_BACK_OFFSET + 1] = (CHAR16) ('0' + ((Mode-
> > >CursorColumn - Column) % 10));
> > >String = mCursorBackwardString;
> > >  }
> > > -else if (Column > Mode->CursorColumn) {
> > > +else if (Column > (UINTN)Mode->CursorColumn) {
> > >mCursorForwardString[FW_BACK_OFFSET + 0] = (CHAR16) ('0' + 
> > > ((Column - Mode-
> > >CursorColumn) / 10));
> > >mCursorForwardString[FW_BACK_OFFSET + 1] = (CHAR16) ('0' + 
> > > ((Column - Mode-
> > >CursorColumn) % 10));
> > >String = mCursorForwardString;
> > >
> > > Please see if you can reproduce this issue.
> > >
> > > Thanks,
> > >
> > > Mike
> >
> > The changes look fine to me.  Unfortunately, I don't have that compiler
> > to test with.
> >
> > If it's needed,
> > Reviewed-by: Brian Johnson 
> >
> > >
> > >> -Original Message-
> > >> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of 
> > >> Brian J.
> > Johnson
> > >> Sent: Friday, October 7, 2016 7:54 AM
> > >> To: edk2-devel@lists.01.org
> > >> Cc: Brian J. Johnson ; Tian, Feng 
> > >> ; Zeng,
> > Star
> > >> 
> > >> Subject: [edk2] [PATCH 2/3] MdeModulePkg/TerminalDxe: Optimize TtyTerm 
> > >> cursor
> motion
> > >>
> > >> For TtyTerm terminals, output a shorter escape sequence when possible
> > >> to move the cursor within the current line, and don't print any escape
> > >> sequence if the cursor is already at the correct position.  This
> > >> removes extra cursor motion activity at the EFI shell prompt,
> > >> improving performance.  It also makes it possible in many cases to
> > >> successfully use a terminal window which is taller than the driver's
> > >> mode setting (eg. 80x25.)
> > >>
> > >> Contributed-under: TianoCore Contribution Agreement 1.0
> > >> Signed-off-by: Brian Johnson 
> > >> Cc: Feng Tian 
> > >> Cc: Star Zeng 
> > >> ---
> > >>  .../Universal/Console/TerminalDxe/Terminal.h   |  2 ++
> > >>  .../Universal/Console/TerminalDxe/TerminalConOut.c | 36 
> > >> +++---
> > >>  2 files changed, 33 insertions(+), 5 deletions(-)
> > >>
> > >> diff --git a/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h
> > >> b/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h
> > >> index 269d2ae..3ee3969 100644
> > >> --- a/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h
> > >> +++ b/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h
> > >> @@ -2,6 +2,7 @@
> > >>Header file for Terminal driver.
> > >>
> > >>  Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
> > >> +Copyright (C) 2016 Silicon Graphics, Inc. All rights reserved.
> > >>  This program and the accompanying materials
> > >>  are licensed and made available under the terms and conditions of the 
> > >> BSD License
> > >>  

Re: [edk2] [PATCH 2/3] MdeModulePkg/TerminalDxe: Optimize TtyTerm cursor motion

2016-10-27 Thread Kinney, Michael D
Brian,

Thanks.  I will do the commit with your rb.

Mike

> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Brian 
> J. Johnson
> Sent: Thursday, October 27, 2016 11:06 AM
> To: Kinney, Michael D ; edk2-devel@lists.01.org
> Cc: Tian, Feng ; Zeng, Star 
> Subject: Re: [edk2] [PATCH 2/3] MdeModulePkg/TerminalDxe: Optimize TtyTerm 
> cursor
> motion
> 
> On 10/26/2016 10:09 PM, Kinney, Michael D wrote:
> > Tian Feng,
> >
> > Unfortunately, this patch that was pushed to edk2/master today
> > breaks on IA32 VS2015x86 builds with a signed/unsigned mismatch
> > on 3 lines.  I think the right fix might be:
> >
> > diff --git a/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConOut.c
> b/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConOut.c
> > index e9b5ed0..9625f4d 100644
> > --- a/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConOut.c
> > +++ b/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConOut.c
> > @@ -790,13 +790,13 @@ TerminalConOutSetCursorPosition (
> >// it isn't necessary.
> >//
> >if (TerminalDevice->TerminalType == TTYTERMTYPE &&
> > -  Mode->CursorRow == Row) {
> > -if (Mode->CursorColumn > Column) {
> > +  (UINTN)Mode->CursorRow == Row) {
> > +if ((UINTN)Mode->CursorColumn > Column) {
> >mCursorBackwardString[FW_BACK_OFFSET + 0] = (CHAR16) ('0' + ((Mode-
> >CursorColumn - Column) / 10));
> >mCursorBackwardString[FW_BACK_OFFSET + 1] = (CHAR16) ('0' + ((Mode-
> >CursorColumn - Column) % 10));
> >String = mCursorBackwardString;
> >  }
> > -else if (Column > Mode->CursorColumn) {
> > +else if (Column > (UINTN)Mode->CursorColumn) {
> >mCursorForwardString[FW_BACK_OFFSET + 0] = (CHAR16) ('0' + ((Column 
> > - Mode-
> >CursorColumn) / 10));
> >mCursorForwardString[FW_BACK_OFFSET + 1] = (CHAR16) ('0' + ((Column 
> > - Mode-
> >CursorColumn) % 10));
> >String = mCursorForwardString;
> >
> > Please see if you can reproduce this issue.
> >
> > Thanks,
> >
> > Mike
> 
> The changes look fine to me.  Unfortunately, I don't have that compiler
> to test with.
> 
> If it's needed,
> Reviewed-by: Brian Johnson 
> 
> >
> >> -Original Message-
> >> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of 
> >> Brian J.
> Johnson
> >> Sent: Friday, October 7, 2016 7:54 AM
> >> To: edk2-devel@lists.01.org
> >> Cc: Brian J. Johnson ; Tian, Feng ; 
> >> Zeng,
> Star
> >> 
> >> Subject: [edk2] [PATCH 2/3] MdeModulePkg/TerminalDxe: Optimize TtyTerm 
> >> cursor motion
> >>
> >> For TtyTerm terminals, output a shorter escape sequence when possible
> >> to move the cursor within the current line, and don't print any escape
> >> sequence if the cursor is already at the correct position.  This
> >> removes extra cursor motion activity at the EFI shell prompt,
> >> improving performance.  It also makes it possible in many cases to
> >> successfully use a terminal window which is taller than the driver's
> >> mode setting (eg. 80x25.)
> >>
> >> Contributed-under: TianoCore Contribution Agreement 1.0
> >> Signed-off-by: Brian Johnson 
> >> Cc: Feng Tian 
> >> Cc: Star Zeng 
> >> ---
> >>  .../Universal/Console/TerminalDxe/Terminal.h   |  2 ++
> >>  .../Universal/Console/TerminalDxe/TerminalConOut.c | 36 
> >> +++---
> >>  2 files changed, 33 insertions(+), 5 deletions(-)
> >>
> >> diff --git a/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h
> >> b/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h
> >> index 269d2ae..3ee3969 100644
> >> --- a/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h
> >> +++ b/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h
> >> @@ -2,6 +2,7 @@
> >>Header file for Terminal driver.
> >>
> >>  Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
> >> +Copyright (C) 2016 Silicon Graphics, Inc. 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
> >> @@ -157,6 +158,7 @@ typedef union {
> >>  #define BACKGROUND_CONTROL_OFFSET 11
> >>  #define ROW_OFFSET2
> >>  #define COLUMN_OFFSET 5
> >> +#define FW_BACK_OFFSET2
> >>
> >>  typedef struct {
> >>UINT16  Unicode;
> >> diff --git a/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConOut.c
> >> b/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConOut.c
> >> index b11e83f..e9b5ed0 100644
> >> --- a/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConOut.c
> >> +++ b/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConOut.c
> >> @@ -83,6 +83,8 @@ CHAR16 mSetModeString[] 

Re: [edk2] [PATCH 2/3] MdeModulePkg/TerminalDxe: Optimize TtyTerm cursor motion

2016-10-27 Thread Brian J. Johnson

On 10/26/2016 10:09 PM, Kinney, Michael D wrote:

Tian Feng,

Unfortunately, this patch that was pushed to edk2/master today
breaks on IA32 VS2015x86 builds with a signed/unsigned mismatch
on 3 lines.  I think the right fix might be:

diff --git a/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConOut.c 
b/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConOut.c
index e9b5ed0..9625f4d 100644
--- a/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConOut.c
+++ b/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConOut.c
@@ -790,13 +790,13 @@ TerminalConOutSetCursorPosition (
   // it isn't necessary.
   //
   if (TerminalDevice->TerminalType == TTYTERMTYPE &&
-  Mode->CursorRow == Row) {
-if (Mode->CursorColumn > Column) {
+  (UINTN)Mode->CursorRow == Row) {
+if ((UINTN)Mode->CursorColumn > Column) {
   mCursorBackwardString[FW_BACK_OFFSET + 0] = (CHAR16) ('0' + 
((Mode->CursorColumn - Column) / 10));
   mCursorBackwardString[FW_BACK_OFFSET + 1] = (CHAR16) ('0' + 
((Mode->CursorColumn - Column) % 10));
   String = mCursorBackwardString;
 }
-else if (Column > Mode->CursorColumn) {
+else if (Column > (UINTN)Mode->CursorColumn) {
   mCursorForwardString[FW_BACK_OFFSET + 0] = (CHAR16) ('0' + ((Column - 
Mode->CursorColumn) / 10));
   mCursorForwardString[FW_BACK_OFFSET + 1] = (CHAR16) ('0' + ((Column - 
Mode->CursorColumn) % 10));
   String = mCursorForwardString;

Please see if you can reproduce this issue.

Thanks,

Mike


The changes look fine to me.  Unfortunately, I don't have that compiler 
to test with.


If it's needed,
Reviewed-by: Brian Johnson 




-Original Message-
From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Brian J. 
Johnson
Sent: Friday, October 7, 2016 7:54 AM
To: edk2-devel@lists.01.org
Cc: Brian J. Johnson ; Tian, Feng ; 
Zeng, Star

Subject: [edk2] [PATCH 2/3] MdeModulePkg/TerminalDxe: Optimize TtyTerm cursor 
motion

For TtyTerm terminals, output a shorter escape sequence when possible
to move the cursor within the current line, and don't print any escape
sequence if the cursor is already at the correct position.  This
removes extra cursor motion activity at the EFI shell prompt,
improving performance.  It also makes it possible in many cases to
successfully use a terminal window which is taller than the driver's
mode setting (eg. 80x25.)

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Brian Johnson 
Cc: Feng Tian 
Cc: Star Zeng 
---
 .../Universal/Console/TerminalDxe/Terminal.h   |  2 ++
 .../Universal/Console/TerminalDxe/TerminalConOut.c | 36 +++---
 2 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h
b/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h
index 269d2ae..3ee3969 100644
--- a/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h
+++ b/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h
@@ -2,6 +2,7 @@
   Header file for Terminal driver.

 Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
+Copyright (C) 2016 Silicon Graphics, Inc. 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
@@ -157,6 +158,7 @@ typedef union {
 #define BACKGROUND_CONTROL_OFFSET 11
 #define ROW_OFFSET2
 #define COLUMN_OFFSET 5
+#define FW_BACK_OFFSET2

 typedef struct {
   UINT16  Unicode;
diff --git a/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConOut.c
b/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConOut.c
index b11e83f..e9b5ed0 100644
--- a/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConOut.c
+++ b/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConOut.c
@@ -83,6 +83,8 @@ CHAR16 mSetModeString[]= { ESC, '[', '=', '3', 
'h', 0 };
 CHAR16 mSetAttributeString[]   = { ESC, '[', '0', 'm', ESC, '[', '4', '0', 
'm',
ESC, '[', '4', '0', 'm', 0 };
 CHAR16 mClearScreenString[]= { ESC, '[', '2', 'J', 0 };
 CHAR16 mSetCursorPositionString[]  = { ESC, '[', '0', '0', ';', '0', '0', 'H', 
0 };
+CHAR16 mCursorForwardString[]  = { ESC, '[', '0', '0', 'C', 0 };
+CHAR16 mCursorBackwardString[] = { ESC, '[', '0', '0', 'D', 0 };

 //
 // Body of the ConOut functions
@@ -755,6 +757,7 @@ TerminalConOutSetCursorPosition (
   UINTN   MaxRow;
   EFI_STATUS  Status;
   TERMINAL_DEV*TerminalDevice;
+  CHAR16  *String;

   TerminalDevice = TERMINAL_CON_OUT_DEV_FROM_THIS (This);

@@ -782,13 +785,36 @@ TerminalConOutSetCursorPosition (
   //
   // control sequence to move the cursor
   //
-  mSetCursorPositionString[ROW_OFFSET + 

Re: [edk2] [PATCH v3] CorebootModulePkgPkg: Expose FindCbTag API from CbParseLib

2016-10-27 Thread Ma, Maurice
Reviewed-by: Maurice Ma 

-Original Message-
From: Dong, Guo 
Sent: Thursday, October 27, 2016 9:47 AM
To: edk2-devel@lists.01.org
Cc: Ma, Maurice; Agyeman, Prince; Dong, Guo
Subject: [edk2] [PATCH v3] CorebootModulePkgPkg: Expose FindCbTag API from 
CbParseLib

CbPlatformSupportLib might use FindCbTag() API to parse platform specific 
information. So expose this API.
And add EFIAPI to all functions in CbParseLib.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Guo Dong 
---
 CorebootModulePkg/Include/Library/CbParseLib.h| 28 ++-
 CorebootModulePkg/Library/CbParseLib/CbParseLib.c | 10 
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/CorebootModulePkg/Include/Library/CbParseLib.h 
b/CorebootModulePkg/Include/Library/CbParseLib.h
index 064baf3..12dd4fa 100644
--- a/CorebootModulePkg/Include/Library/CbParseLib.h
+++ b/CorebootModulePkg/Include/Library/CbParseLib.h
@@ -2,7 +2,7 @@
   This library will parse the coreboot table in memory and extract those 
required
   information.
 
-  Copyright (c) 2014, Intel Corporation. All rights reserved.
+  Copyright (c) 2014 - 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 @@ -18,6 +18,24 @@ typedef RETURN_STATUS \
 (*CB_MEM_INFO_CALLBACK) (UINT64 Base, UINT64 Size, UINT32 Type, VOID 
*Param);
 
 /**
+  Find coreboot record with given Tag from the memory Start in 4096  
+ bytes range.
+
+  @param  Start  The start memory to be searched in
+  @param  TagThe tag id to be found
+
+  @retval NULL  The Tag is not found.
+  @retval OthersThe poiter to the record found.
+
+**/
+VOID *
+EFIAPI
+FindCbTag (
+  IN  VOID *Start,
+  IN  UINT32   Tag
+  );
+
+/**
   Acquire the memory information from the coreboot table in memory.
 
   @param  MemInfoCallback The callback routine
@@ -28,6 +46,7 @@ typedef RETURN_STATUS \
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseMemoryInfo (
   IN  CB_MEM_INFO_CALLBACK  MemInfoCallback,
   IN  VOID  *pParam
@@ -46,6 +65,7 @@ CbParseMemoryInfo (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseCbMemTable (
   IN UINT32 TableId,
   IN VOID** pMemTable,
@@ -64,6 +84,7 @@ CbParseCbMemTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseAcpiTable (
   IN VOID** pMemTable,
   IN UINT32*pMemTableSize
@@ -81,6 +102,7 @@ CbParseAcpiTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseSmbiosTable (
   IN VOID** pMemTable,
   IN UINT32*pMemTableSize
@@ -101,6 +123,7 @@ CbParseSmbiosTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseFadtInfo (
   IN UINTN* pPmCtrlReg,
   IN UINTN* pPmTimerReg,
@@ -125,6 +148,7 @@ CbParseFadtInfo (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseSerialInfo (
   OUT UINT32 *pRegBase,
   OUT UINT32 *pRegAccessType,
@@ -145,6 +169,7 @@ CbParseSerialInfo (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseGetCbHeader (
   IN UINTN  Level,
   IN VOID** HeaderPtr
@@ -160,6 +185,7 @@ CbParseGetCbHeader (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseFbInfo (
   IN FRAME_BUFFER_INFO* pFbInfo
   );
diff --git a/CorebootModulePkg/Library/CbParseLib/CbParseLib.c 
b/CorebootModulePkg/Library/CbParseLib/CbParseLib.c
index 305e38f..0909b0f 100644
--- a/CorebootModulePkg/Library/CbParseLib/CbParseLib.c
+++ b/CorebootModulePkg/Library/CbParseLib/CbParseLib.c
@@ -94,6 +94,7 @@ CbCheckSum16 (
 
 **/
 VOID *
+EFIAPI
 FindCbTag (
   IN  VOID *Start,
   IN  UINT32   Tag
@@ -175,6 +176,7 @@ FindCbTag (
 
 **/
 RETURN_STATUS
+EFIAPI
 FindCbMemTable (
   IN  struct cbmem_root  *Root,
   IN  UINT32 TableId,
@@ -237,6 +239,7 @@ FindCbMemTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseMemoryInfo (
   IN  CB_MEM_INFO_CALLBACK  MemInfoCallback,
   IN  VOID  *pParam
@@ -287,6 +290,7 @@ CbParseMemoryInfo (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseCbMemTable (
   IN  UINT32 TableId,
   OUT VOID   **pMemTable,
@@ -343,6 +347,7 @@ CbParseCbMemTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseAcpiTable (
   OUT VOID   **pMemTable,
   OUT UINT32 *pMemTableSize
@@ -363,6 +368,7 @@ CbParseAcpiTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseSmbiosTable (
   OUT VOID   **pMemTable,
   OUT UINT32 *pMemTableSize
@@ -386,6 +392,7 @@ CbParseSmbiosTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseFadtInfo (
   OUT UINTN  *pPmCtrlReg,
   OUT UINTN  *pPmTimerReg,
@@ -533,6 +540,7 @@ CbParseFadtInfo (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseSerialInfo (
   OUT UINT32  *pRegBase,
   OUT UINT32  *pRegAccessType,
@@ -591,6 +599,7 @@ CbParseSerialInfo (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseGetCbHeader (
   IN  UINTN  Level,
   OUT VOID   **HeaderPtr
@@ -629,6 +638,7 @@ CbParseGetCbHeader (
 
 **/
 RETURN_STATUS
+EFIAPI
 

Re: [edk2] [PATCH v2] CorebootModulePkgPkg: Expose FindCbTag API from CbParseLib

2016-10-27 Thread Dong, Guo

Hi Maurice,

Thank you capture this typo. Updated patch has been sent.

Thanks,
Guo

-Original Message-
From: Ma, Maurice 
Sent: Thursday, October 27, 2016 9:38 AM
To: Dong, Guo 
Cc: edk2-devel@lists.01.org; Agyeman, Prince 
Subject: RE: [edk2] [PATCH v2] CorebootModulePkgPkg: Expose FindCbTag API from 
CbParseLib

Hi, Guo,

I think the following code will have issue on compiling.  Can you check ?

+EFIAPI
+FindCbTag
+(IN VOID * Start, IN UINT32 Tag) (
+  IN  VOID *Start,
+  IN  UINT32   Tag
+  );
+

Thanks
Maurice
-Original Message-
From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Ma, 
Maurice
Sent: Thursday, October 27, 2016 9:32 AM
To: Dong, Guo
Cc: edk2-devel@lists.01.org; Agyeman, Prince
Subject: Re: [edk2] [PATCH v2] CorebootModulePkgPkg: Expose FindCbTag API from 
CbParseLib

Reviewed-by: Maurice Ma 

-Original Message-
From: Dong, Guo
Sent: Thursday, October 27, 2016 7:59 AM
To: edk2-devel@lists.01.org
Cc: Ma, Maurice; Agyeman, Prince; Dong, Guo
Subject: [edk2] [PATCH v2] CorebootModulePkgPkg: Expose FindCbTag API from 
CbParseLib

CbPlatformSupportLib might use FindCbTag() API to parse platform specific 
information. So expose this API.
And add EFIAPI to all functions in CbParseLib.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Guo Dong 
---
 CorebootModulePkg/Include/Library/CbParseLib.h| 29 ++-
 CorebootModulePkg/Library/CbParseLib/CbParseLib.c | 10 
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/CorebootModulePkg/Include/Library/CbParseLib.h 
b/CorebootModulePkg/Include/Library/CbParseLib.h
index 064baf3..18e3d1e 100644
--- a/CorebootModulePkg/Include/Library/CbParseLib.h
+++ b/CorebootModulePkg/Include/Library/CbParseLib.h
@@ -2,7 +2,7 @@
   This library will parse the coreboot table in memory and extract those 
required
   information.
 
-  Copyright (c) 2014, Intel Corporation. All rights reserved.
+  Copyright (c) 2014 - 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 @@ -18,6 +18,25 @@ typedef RETURN_STATUS \
 (*CB_MEM_INFO_CALLBACK) (UINT64 Base, UINT64 Size, UINT32 Type, VOID 
*Param);
 
 /**
+  Find coreboot record with given Tag from the memory Start in 4096 
+ bytes range.
+
+  @param  Start  The start memory to be searched in
+  @param  TagThe tag id to be found
+
+  @retval NULL  The Tag is not found.
+  @retval OthersThe poiter to the record found.
+
+**/
+VOID *
+EFIAPI
+FindCbTag
+(IN VOID * Start, IN UINT32 Tag) (
+  IN  VOID *Start,
+  IN  UINT32   Tag
+  );
+
+/**
   Acquire the memory information from the coreboot table in memory.
 
   @param  MemInfoCallback The callback routine
@@ -28,6 +47,7 @@ typedef RETURN_STATUS \
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseMemoryInfo (
   IN  CB_MEM_INFO_CALLBACK  MemInfoCallback,
   IN  VOID  *pParam
@@ -46,6 +66,7 @@ CbParseMemoryInfo (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseCbMemTable (
   IN UINT32 TableId,
   IN VOID** pMemTable,
@@ -64,6 +85,7 @@ CbParseCbMemTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseAcpiTable (
   IN VOID** pMemTable,
   IN UINT32*pMemTableSize
@@ -81,6 +103,7 @@ CbParseAcpiTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseSmbiosTable (
   IN VOID** pMemTable,
   IN UINT32*pMemTableSize
@@ -101,6 +124,7 @@ CbParseSmbiosTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseFadtInfo (
   IN UINTN* pPmCtrlReg,
   IN UINTN* pPmTimerReg,
@@ -125,6 +149,7 @@ CbParseFadtInfo (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseSerialInfo (
   OUT UINT32 *pRegBase,
   OUT UINT32 *pRegAccessType,
@@ -145,6 +170,7 @@ CbParseSerialInfo (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseGetCbHeader (
   IN UINTN  Level,
   IN VOID** HeaderPtr
@@ -160,6 +186,7 @@ CbParseGetCbHeader (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseFbInfo (
   IN FRAME_BUFFER_INFO* pFbInfo
   );
diff --git a/CorebootModulePkg/Library/CbParseLib/CbParseLib.c 
b/CorebootModulePkg/Library/CbParseLib/CbParseLib.c
index 305e38f..0909b0f 100644
--- a/CorebootModulePkg/Library/CbParseLib/CbParseLib.c
+++ b/CorebootModulePkg/Library/CbParseLib/CbParseLib.c
@@ -94,6 +94,7 @@ CbCheckSum16 (
 
 **/
 VOID *
+EFIAPI
 FindCbTag (
   IN  VOID *Start,
   IN  UINT32   Tag
@@ -175,6 +176,7 @@ FindCbTag (
 
 **/
 RETURN_STATUS
+EFIAPI
 FindCbMemTable (
   IN  struct cbmem_root  *Root,
   IN  UINT32 TableId,
@@ -237,6 +239,7 @@ FindCbMemTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseMemoryInfo (
   IN  CB_MEM_INFO_CALLBACK  MemInfoCallback,
   IN  VOID  *pParam
@@ -287,6 +290,7 @@ CbParseMemoryInfo (
 
 **/
 RETURN_STATUS

[edk2] [PATCH v3] CorebootModulePkgPkg: Expose FindCbTag API from CbParseLib

2016-10-27 Thread gdong1
CbPlatformSupportLib might use FindCbTag() API to parse
platform specific information. So expose this API.
And add EFIAPI to all functions in CbParseLib.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Guo Dong 
---
 CorebootModulePkg/Include/Library/CbParseLib.h| 28 ++-
 CorebootModulePkg/Library/CbParseLib/CbParseLib.c | 10 
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/CorebootModulePkg/Include/Library/CbParseLib.h 
b/CorebootModulePkg/Include/Library/CbParseLib.h
index 064baf3..12dd4fa 100644
--- a/CorebootModulePkg/Include/Library/CbParseLib.h
+++ b/CorebootModulePkg/Include/Library/CbParseLib.h
@@ -2,7 +2,7 @@
   This library will parse the coreboot table in memory and extract those 
required
   information.
 
-  Copyright (c) 2014, Intel Corporation. All rights reserved.
+  Copyright (c) 2014 - 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
@@ -18,6 +18,24 @@ typedef RETURN_STATUS \
 (*CB_MEM_INFO_CALLBACK) (UINT64 Base, UINT64 Size, UINT32 Type, VOID 
*Param);
 
 /**
+  Find coreboot record with given Tag from the memory Start in 4096
+  bytes range.
+
+  @param  Start  The start memory to be searched in
+  @param  TagThe tag id to be found
+
+  @retval NULL  The Tag is not found.
+  @retval OthersThe poiter to the record found.
+
+**/
+VOID *
+EFIAPI
+FindCbTag (
+  IN  VOID *Start,
+  IN  UINT32   Tag
+  );
+
+/**
   Acquire the memory information from the coreboot table in memory.
 
   @param  MemInfoCallback The callback routine
@@ -28,6 +46,7 @@ typedef RETURN_STATUS \
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseMemoryInfo (
   IN  CB_MEM_INFO_CALLBACK  MemInfoCallback,
   IN  VOID  *pParam
@@ -46,6 +65,7 @@ CbParseMemoryInfo (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseCbMemTable (
   IN UINT32 TableId,
   IN VOID** pMemTable,
@@ -64,6 +84,7 @@ CbParseCbMemTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseAcpiTable (
   IN VOID** pMemTable,
   IN UINT32*pMemTableSize
@@ -81,6 +102,7 @@ CbParseAcpiTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseSmbiosTable (
   IN VOID** pMemTable,
   IN UINT32*pMemTableSize
@@ -101,6 +123,7 @@ CbParseSmbiosTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseFadtInfo (
   IN UINTN* pPmCtrlReg,
   IN UINTN* pPmTimerReg,
@@ -125,6 +148,7 @@ CbParseFadtInfo (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseSerialInfo (
   OUT UINT32 *pRegBase,
   OUT UINT32 *pRegAccessType,
@@ -145,6 +169,7 @@ CbParseSerialInfo (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseGetCbHeader (
   IN UINTN  Level,
   IN VOID** HeaderPtr
@@ -160,6 +185,7 @@ CbParseGetCbHeader (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseFbInfo (
   IN FRAME_BUFFER_INFO* pFbInfo
   );
diff --git a/CorebootModulePkg/Library/CbParseLib/CbParseLib.c 
b/CorebootModulePkg/Library/CbParseLib/CbParseLib.c
index 305e38f..0909b0f 100644
--- a/CorebootModulePkg/Library/CbParseLib/CbParseLib.c
+++ b/CorebootModulePkg/Library/CbParseLib/CbParseLib.c
@@ -94,6 +94,7 @@ CbCheckSum16 (
 
 **/
 VOID *
+EFIAPI
 FindCbTag (
   IN  VOID *Start,
   IN  UINT32   Tag
@@ -175,6 +176,7 @@ FindCbTag (
 
 **/
 RETURN_STATUS
+EFIAPI
 FindCbMemTable (
   IN  struct cbmem_root  *Root,
   IN  UINT32 TableId,
@@ -237,6 +239,7 @@ FindCbMemTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseMemoryInfo (
   IN  CB_MEM_INFO_CALLBACK  MemInfoCallback,
   IN  VOID  *pParam
@@ -287,6 +290,7 @@ CbParseMemoryInfo (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseCbMemTable (
   IN  UINT32 TableId,
   OUT VOID   **pMemTable,
@@ -343,6 +347,7 @@ CbParseCbMemTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseAcpiTable (
   OUT VOID   **pMemTable,
   OUT UINT32 *pMemTableSize
@@ -363,6 +368,7 @@ CbParseAcpiTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseSmbiosTable (
   OUT VOID   **pMemTable,
   OUT UINT32 *pMemTableSize
@@ -386,6 +392,7 @@ CbParseSmbiosTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseFadtInfo (
   OUT UINTN  *pPmCtrlReg,
   OUT UINTN  *pPmTimerReg,
@@ -533,6 +540,7 @@ CbParseFadtInfo (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseSerialInfo (
   OUT UINT32  *pRegBase,
   OUT UINT32  *pRegAccessType,
@@ -591,6 +599,7 @@ CbParseSerialInfo (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseGetCbHeader (
   IN  UINTN  Level,
   OUT VOID   **HeaderPtr
@@ -629,6 +638,7 @@ CbParseGetCbHeader (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseFbInfo (
   OUT FRAME_BUFFER_INFO   *pFbInfo
   )
-- 
2.7.0.windows.1

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


Re: [edk2] [PATCH v2] CorebootModulePkgPkg: Expose FindCbTag API from CbParseLib

2016-10-27 Thread Ma, Maurice
Hi, Guo,

I think the following code will have issue on compiling.  Can you check ?

+EFIAPI
+FindCbTag
+(IN VOID * Start, IN UINT32 Tag) (
+  IN  VOID *Start,
+  IN  UINT32   Tag
+  );
+

Thanks
Maurice
-Original Message-
From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Ma, 
Maurice
Sent: Thursday, October 27, 2016 9:32 AM
To: Dong, Guo
Cc: edk2-devel@lists.01.org; Agyeman, Prince
Subject: Re: [edk2] [PATCH v2] CorebootModulePkgPkg: Expose FindCbTag API from 
CbParseLib

Reviewed-by: Maurice Ma 

-Original Message-
From: Dong, Guo
Sent: Thursday, October 27, 2016 7:59 AM
To: edk2-devel@lists.01.org
Cc: Ma, Maurice; Agyeman, Prince; Dong, Guo
Subject: [edk2] [PATCH v2] CorebootModulePkgPkg: Expose FindCbTag API from 
CbParseLib

CbPlatformSupportLib might use FindCbTag() API to parse platform specific 
information. So expose this API.
And add EFIAPI to all functions in CbParseLib.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Guo Dong 
---
 CorebootModulePkg/Include/Library/CbParseLib.h| 29 ++-
 CorebootModulePkg/Library/CbParseLib/CbParseLib.c | 10 
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/CorebootModulePkg/Include/Library/CbParseLib.h 
b/CorebootModulePkg/Include/Library/CbParseLib.h
index 064baf3..18e3d1e 100644
--- a/CorebootModulePkg/Include/Library/CbParseLib.h
+++ b/CorebootModulePkg/Include/Library/CbParseLib.h
@@ -2,7 +2,7 @@
   This library will parse the coreboot table in memory and extract those 
required
   information.
 
-  Copyright (c) 2014, Intel Corporation. All rights reserved.
+  Copyright (c) 2014 - 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 @@ -18,6 +18,25 @@ typedef RETURN_STATUS \
 (*CB_MEM_INFO_CALLBACK) (UINT64 Base, UINT64 Size, UINT32 Type, VOID 
*Param);
 
 /**
+  Find coreboot record with given Tag from the memory Start in 4096 
+ bytes range.
+
+  @param  Start  The start memory to be searched in
+  @param  TagThe tag id to be found
+
+  @retval NULL  The Tag is not found.
+  @retval OthersThe poiter to the record found.
+
+**/
+VOID *
+EFIAPI
+FindCbTag
+(IN VOID * Start, IN UINT32 Tag) (
+  IN  VOID *Start,
+  IN  UINT32   Tag
+  );
+
+/**
   Acquire the memory information from the coreboot table in memory.
 
   @param  MemInfoCallback The callback routine
@@ -28,6 +47,7 @@ typedef RETURN_STATUS \
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseMemoryInfo (
   IN  CB_MEM_INFO_CALLBACK  MemInfoCallback,
   IN  VOID  *pParam
@@ -46,6 +66,7 @@ CbParseMemoryInfo (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseCbMemTable (
   IN UINT32 TableId,
   IN VOID** pMemTable,
@@ -64,6 +85,7 @@ CbParseCbMemTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseAcpiTable (
   IN VOID** pMemTable,
   IN UINT32*pMemTableSize
@@ -81,6 +103,7 @@ CbParseAcpiTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseSmbiosTable (
   IN VOID** pMemTable,
   IN UINT32*pMemTableSize
@@ -101,6 +124,7 @@ CbParseSmbiosTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseFadtInfo (
   IN UINTN* pPmCtrlReg,
   IN UINTN* pPmTimerReg,
@@ -125,6 +149,7 @@ CbParseFadtInfo (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseSerialInfo (
   OUT UINT32 *pRegBase,
   OUT UINT32 *pRegAccessType,
@@ -145,6 +170,7 @@ CbParseSerialInfo (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseGetCbHeader (
   IN UINTN  Level,
   IN VOID** HeaderPtr
@@ -160,6 +186,7 @@ CbParseGetCbHeader (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseFbInfo (
   IN FRAME_BUFFER_INFO* pFbInfo
   );
diff --git a/CorebootModulePkg/Library/CbParseLib/CbParseLib.c 
b/CorebootModulePkg/Library/CbParseLib/CbParseLib.c
index 305e38f..0909b0f 100644
--- a/CorebootModulePkg/Library/CbParseLib/CbParseLib.c
+++ b/CorebootModulePkg/Library/CbParseLib/CbParseLib.c
@@ -94,6 +94,7 @@ CbCheckSum16 (
 
 **/
 VOID *
+EFIAPI
 FindCbTag (
   IN  VOID *Start,
   IN  UINT32   Tag
@@ -175,6 +176,7 @@ FindCbTag (
 
 **/
 RETURN_STATUS
+EFIAPI
 FindCbMemTable (
   IN  struct cbmem_root  *Root,
   IN  UINT32 TableId,
@@ -237,6 +239,7 @@ FindCbMemTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseMemoryInfo (
   IN  CB_MEM_INFO_CALLBACK  MemInfoCallback,
   IN  VOID  *pParam
@@ -287,6 +290,7 @@ CbParseMemoryInfo (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseCbMemTable (
   IN  UINT32 TableId,
   OUT VOID   **pMemTable,
@@ -343,6 +347,7 @@ CbParseCbMemTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseAcpiTable (
   OUT VOID   **pMemTable,
   OUT UINT32 *pMemTableSize
@@ -363,6 +368,7 @@ CbParseAcpiTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseSmbiosTable (
   OUT VOID   **pMemTable,
   OUT UINT32 

Re: [edk2] [PATCH v2] CorebootModulePkgPkg: Expose FindCbTag API from CbParseLib

2016-10-27 Thread Ma, Maurice
Reviewed-by: Maurice Ma 

-Original Message-
From: Dong, Guo 
Sent: Thursday, October 27, 2016 7:59 AM
To: edk2-devel@lists.01.org
Cc: Ma, Maurice; Agyeman, Prince; Dong, Guo
Subject: [edk2] [PATCH v2] CorebootModulePkgPkg: Expose FindCbTag API from 
CbParseLib

CbPlatformSupportLib might use FindCbTag() API to parse platform specific 
information. So expose this API.
And add EFIAPI to all functions in CbParseLib.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Guo Dong 
---
 CorebootModulePkg/Include/Library/CbParseLib.h| 29 ++-
 CorebootModulePkg/Library/CbParseLib/CbParseLib.c | 10 
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/CorebootModulePkg/Include/Library/CbParseLib.h 
b/CorebootModulePkg/Include/Library/CbParseLib.h
index 064baf3..18e3d1e 100644
--- a/CorebootModulePkg/Include/Library/CbParseLib.h
+++ b/CorebootModulePkg/Include/Library/CbParseLib.h
@@ -2,7 +2,7 @@
   This library will parse the coreboot table in memory and extract those 
required
   information.
 
-  Copyright (c) 2014, Intel Corporation. All rights reserved.
+  Copyright (c) 2014 - 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 @@ -18,6 +18,25 @@ typedef RETURN_STATUS \
 (*CB_MEM_INFO_CALLBACK) (UINT64 Base, UINT64 Size, UINT32 Type, VOID 
*Param);
 
 /**
+  Find coreboot record with given Tag from the memory Start in 4096  
+ bytes range.
+
+  @param  Start  The start memory to be searched in
+  @param  TagThe tag id to be found
+
+  @retval NULL  The Tag is not found.
+  @retval OthersThe poiter to the record found.
+
+**/
+VOID *
+EFIAPI
+FindCbTag
+(IN VOID * Start, IN UINT32 Tag) (
+  IN  VOID *Start,
+  IN  UINT32   Tag
+  );
+
+/**
   Acquire the memory information from the coreboot table in memory.
 
   @param  MemInfoCallback The callback routine
@@ -28,6 +47,7 @@ typedef RETURN_STATUS \
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseMemoryInfo (
   IN  CB_MEM_INFO_CALLBACK  MemInfoCallback,
   IN  VOID  *pParam
@@ -46,6 +66,7 @@ CbParseMemoryInfo (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseCbMemTable (
   IN UINT32 TableId,
   IN VOID** pMemTable,
@@ -64,6 +85,7 @@ CbParseCbMemTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseAcpiTable (
   IN VOID** pMemTable,
   IN UINT32*pMemTableSize
@@ -81,6 +103,7 @@ CbParseAcpiTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseSmbiosTable (
   IN VOID** pMemTable,
   IN UINT32*pMemTableSize
@@ -101,6 +124,7 @@ CbParseSmbiosTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseFadtInfo (
   IN UINTN* pPmCtrlReg,
   IN UINTN* pPmTimerReg,
@@ -125,6 +149,7 @@ CbParseFadtInfo (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseSerialInfo (
   OUT UINT32 *pRegBase,
   OUT UINT32 *pRegAccessType,
@@ -145,6 +170,7 @@ CbParseSerialInfo (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseGetCbHeader (
   IN UINTN  Level,
   IN VOID** HeaderPtr
@@ -160,6 +186,7 @@ CbParseGetCbHeader (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseFbInfo (
   IN FRAME_BUFFER_INFO* pFbInfo
   );
diff --git a/CorebootModulePkg/Library/CbParseLib/CbParseLib.c 
b/CorebootModulePkg/Library/CbParseLib/CbParseLib.c
index 305e38f..0909b0f 100644
--- a/CorebootModulePkg/Library/CbParseLib/CbParseLib.c
+++ b/CorebootModulePkg/Library/CbParseLib/CbParseLib.c
@@ -94,6 +94,7 @@ CbCheckSum16 (
 
 **/
 VOID *
+EFIAPI
 FindCbTag (
   IN  VOID *Start,
   IN  UINT32   Tag
@@ -175,6 +176,7 @@ FindCbTag (
 
 **/
 RETURN_STATUS
+EFIAPI
 FindCbMemTable (
   IN  struct cbmem_root  *Root,
   IN  UINT32 TableId,
@@ -237,6 +239,7 @@ FindCbMemTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseMemoryInfo (
   IN  CB_MEM_INFO_CALLBACK  MemInfoCallback,
   IN  VOID  *pParam
@@ -287,6 +290,7 @@ CbParseMemoryInfo (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseCbMemTable (
   IN  UINT32 TableId,
   OUT VOID   **pMemTable,
@@ -343,6 +347,7 @@ CbParseCbMemTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseAcpiTable (
   OUT VOID   **pMemTable,
   OUT UINT32 *pMemTableSize
@@ -363,6 +368,7 @@ CbParseAcpiTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseSmbiosTable (
   OUT VOID   **pMemTable,
   OUT UINT32 *pMemTableSize
@@ -386,6 +392,7 @@ CbParseSmbiosTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseFadtInfo (
   OUT UINTN  *pPmCtrlReg,
   OUT UINTN  *pPmTimerReg,
@@ -533,6 +540,7 @@ CbParseFadtInfo (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseSerialInfo (
   OUT UINT32  *pRegBase,
   OUT UINT32  *pRegAccessType,
@@ -591,6 +599,7 @@ CbParseSerialInfo (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseGetCbHeader (
   IN  UINTN  Level,
   OUT VOID   **HeaderPtr
@@ -629,6 +638,7 @@ CbParseGetCbHeader (
 

Re: [edk2] [PATCH] OvmfPkg: Make use of ARRAY_SIZE()

2016-10-27 Thread Laszlo Ersek
On 10/27/16 12:16, Gary Lin wrote:
> Convert the remaining pieces to make the code shorter and more readable.
> 
> Cc: Justen Jordan 
> Cc: Laszlo Ersek 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Gary Lin 
> ---
>  OvmfPkg/Csm/CsmSupportLib/LegacyRegion.c| 8 
>  OvmfPkg/Library/LoadLinuxLib/Linux.c| 2 +-
>  OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 4 +---
>  OvmfPkg/VirtioGpuDxe/Gop.c  | 7 +++
>  4 files changed, 9 insertions(+), 12 deletions(-)
> 
> diff --git a/OvmfPkg/Csm/CsmSupportLib/LegacyRegion.c 
> b/OvmfPkg/Csm/CsmSupportLib/LegacyRegion.c
> index b929db0..8d5d2e5 100644
> --- a/OvmfPkg/Csm/CsmSupportLib/LegacyRegion.c
> +++ b/OvmfPkg/Csm/CsmSupportLib/LegacyRegion.c
> @@ -130,18 +130,18 @@ LegacyRegionManipulationInternal (
>// Loop to find the start PAM.
>//
>StartIndex = 0;
> -  for (Index = 0; Index < (sizeof(mSectionArray) / sizeof 
> (mSectionArray[0])); Index++) {
> +  for (Index = 0; Index < ARRAY_SIZE (mSectionArray); Index++) {
>  if ((Start >= mSectionArray[Index].Start) && (Start < 
> (mSectionArray[Index].Start + mSectionArray[Index].Length))) {
>StartIndex = Index;
>break;
>  }
>}
> -  ASSERT (Index < (sizeof(mSectionArray) / sizeof (mSectionArray[0])));
> +  ASSERT (Index < ARRAY_SIZE (mSectionArray));
>  
>//
>// Program PAM until end PAM is encountered
>//
> -  for (Index = StartIndex; Index < (sizeof(mSectionArray) / sizeof 
> (mSectionArray[0])); Index++) {
> +  for (Index = StartIndex; Index < ARRAY_SIZE (mSectionArray); Index++) {
>  if (ReadEnable != NULL) {
>if (*ReadEnable) {
>  PciOr8 (
> @@ -177,7 +177,7 @@ LegacyRegionManipulationInternal (
>break;
>  }
>}
> -  ASSERT (Index < (sizeof(mSectionArray) / sizeof (mSectionArray[0])));
> +  ASSERT (Index < ARRAY_SIZE (mSectionArray));
>  
>return EFI_SUCCESS;
>  }
> diff --git a/OvmfPkg/Library/LoadLinuxLib/Linux.c 
> b/OvmfPkg/Library/LoadLinuxLib/Linux.c
> index 9c996ad..68d1537 100644
> --- a/OvmfPkg/Library/LoadLinuxLib/Linux.c
> +++ b/OvmfPkg/Library/LoadLinuxLib/Linux.c
> @@ -357,7 +357,7 @@ SetupLinuxMemmap (
>LastE820->size += EFI_PAGES_TO_SIZE ((UINTN) MemoryMap->NumberOfPages);
>LastEndAddr += EFI_PAGES_TO_SIZE ((UINTN) MemoryMap->NumberOfPages);
>  } else {
> -  if (E820EntryCount >= (sizeof (Bp->e820_map) / sizeof 
> (Bp->e820_map[0]))) {
> +  if (E820EntryCount >= ARRAY_SIZE (Bp->e820_map)) {
>  break;
>}
>E820->type = (UINT32) E820Type;
> diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c 
> b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
> index 6ba0ca6..ff83703 100644
> --- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
> +++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
> @@ -419,9 +419,7 @@ PciHostBridgeResourceConflict (
>  DEBUG ((EFI_D_ERROR, "RootBridge[%d]:\n", RootBridgeIndex++));
>  for (; Descriptor->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR; Descriptor++) {
>ASSERT (Descriptor->ResType <
> -  (sizeof (mPciHostBridgeLibAcpiAddressSpaceTypeStr) /
> -   sizeof (mPciHostBridgeLibAcpiAddressSpaceTypeStr[0])
> -   )
> +  ARRAY_SIZE (mPciHostBridgeLibAcpiAddressSpaceTypeStr)
>);
>DEBUG ((EFI_D_ERROR, " %s: Length/Alignment = 0x%lx / 0x%lx\n",
>mPciHostBridgeLibAcpiAddressSpaceTypeStr[Descriptor->ResType],
> diff --git a/OvmfPkg/VirtioGpuDxe/Gop.c b/OvmfPkg/VirtioGpuDxe/Gop.c
> index c6ff9ed..3438bd0 100644
> --- a/OvmfPkg/VirtioGpuDxe/Gop.c
> +++ b/OvmfPkg/VirtioGpuDxe/Gop.c
> @@ -204,7 +204,7 @@ GopQueryMode (
>  {
>EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *GopModeInfo;
>  
> -  if (ModeNumber >= sizeof mGopResolutions / sizeof mGopResolutions[0]) {
> +  if (ModeNumber >= ARRAY_SIZE (mGopResolutions)) {
>  return EFI_INVALID_PARAMETER;
>}
>  
> @@ -239,7 +239,7 @@ GopSetMode (
>EFI_STATUS Status;
>EFI_STATUS Status2;
>  
> -  if (ModeNumber >= sizeof mGopResolutions / sizeof mGopResolutions[0]) {
> +  if (ModeNumber >= ARRAY_SIZE (mGopResolutions)) {
>  return EFI_UNSUPPORTED;
>}
>  
> @@ -258,8 +258,7 @@ GopSetMode (
>  //
>  VgpuGop->Gop.Mode = >GopMode;
>  
> -VgpuGop->GopMode.MaxMode = (UINT32)(sizeof mGopResolutions /
> -sizeof mGopResolutions[0]);
> +VgpuGop->GopMode.MaxMode = (UINT32)(ARRAY_SIZE 
> (mGopResolutions));
>  VgpuGop->GopMode.Info= >GopModeInfo;
>  VgpuGop->GopMode.SizeOfInfo  = sizeof VgpuGop->GopModeInfo;
>  
> 

Reviewed-by: Laszlo Ersek 
[ler...@redhat.com: tweak subject line]
Signed-off-by: Laszlo Ersek 

I changed the subject line like this:

OvmfPkg: Make more use of 

Re: [edk2] [PATCH] CorebootModulePkgPkg: Expose FindCbTag API from CbParseLib

2016-10-27 Thread Dong, Guo

Hi Maurice,

Thank you for the comments.
I have updated patch to add EFIAPI to all the APIs in CbParseLib.

Thanks,
Guo

-Original Message-
From: Ma, Maurice 
Sent: Wednesday, October 26, 2016 8:02 PM
To: Dong, Guo 
Cc: Agyeman, Prince ; edk2-devel@lists.01.org
Subject: RE: [edk2] [PATCH] CorebootModulePkgPkg: Expose FindCbTag API from 
CbParseLib

Guo,

I think it is better to add  "EFIAPI" to force the calling convention.

Thanks
Maurice

-Original Message-
From: Dong, Guo
Sent: Wednesday, October 26, 2016 5:35 PM
To: edk2-devel@lists.01.org
Cc: Ma, Maurice; Agyeman, Prince; Dong, Guo
Subject: [edk2] [PATCH] CorebootModulePkgPkg: Expose FindCbTag API from 
CbParseLib

CbPlatformSupportLib might use FindCbTag() API to parse platform specific 
information.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Guo Dong 
Reviewed-by: Maurice Ma 
---
 CorebootModulePkg/Include/Library/CbParseLib.h | 19 ++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/CorebootModulePkg/Include/Library/CbParseLib.h 
b/CorebootModulePkg/Include/Library/CbParseLib.h
index 064baf3..e1fda7e 100644
--- a/CorebootModulePkg/Include/Library/CbParseLib.h
+++ b/CorebootModulePkg/Include/Library/CbParseLib.h
@@ -2,7 +2,7 @@
   This library will parse the coreboot table in memory and extract those 
required
   information.
 
-  Copyright (c) 2014, Intel Corporation. All rights reserved.
+  Copyright (c) 2014 - 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 @@ -18,6 +18,23 @@ typedef RETURN_STATUS \
 (*CB_MEM_INFO_CALLBACK) (UINT64 Base, UINT64 Size, UINT32 Type, VOID 
*Param);
 
 /**
+  Find coreboot record with given Tag from the memory Start in 4096 
+ bytes range.
+
+  @param  Start  The start memory to be searched in
+  @param  TagThe tag id to be found
+
+  @retval NULL  The Tag is not found.
+  @retval OthersThe poiter to the record found.
+
+**/
+VOID *
+FindCbTag (
+  IN  VOID *Start,
+  IN  UINT32   Tag
+  );
+
+/**
   Acquire the memory information from the coreboot table in memory.
 
   @param  MemInfoCallback The callback routine
--
2.7.0.windows.1

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


[edk2] [PATCH v2] CorebootModulePkgPkg: Expose FindCbTag API from CbParseLib

2016-10-27 Thread gdong1
CbPlatformSupportLib might use FindCbTag() API to parse
platform specific information. So expose this API.
And add EFIAPI to all functions in CbParseLib.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Guo Dong 
---
 CorebootModulePkg/Include/Library/CbParseLib.h| 29 ++-
 CorebootModulePkg/Library/CbParseLib/CbParseLib.c | 10 
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/CorebootModulePkg/Include/Library/CbParseLib.h 
b/CorebootModulePkg/Include/Library/CbParseLib.h
index 064baf3..18e3d1e 100644
--- a/CorebootModulePkg/Include/Library/CbParseLib.h
+++ b/CorebootModulePkg/Include/Library/CbParseLib.h
@@ -2,7 +2,7 @@
   This library will parse the coreboot table in memory and extract those 
required
   information.
 
-  Copyright (c) 2014, Intel Corporation. All rights reserved.
+  Copyright (c) 2014 - 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
@@ -18,6 +18,25 @@ typedef RETURN_STATUS \
 (*CB_MEM_INFO_CALLBACK) (UINT64 Base, UINT64 Size, UINT32 Type, VOID 
*Param);
 
 /**
+  Find coreboot record with given Tag from the memory Start in 4096
+  bytes range.
+
+  @param  Start  The start memory to be searched in
+  @param  TagThe tag id to be found
+
+  @retval NULL  The Tag is not found.
+  @retval OthersThe poiter to the record found.
+
+**/
+VOID *
+EFIAPI
+FindCbTag
+(IN VOID * Start, IN UINT32 Tag) (
+  IN  VOID *Start,
+  IN  UINT32   Tag
+  );
+
+/**
   Acquire the memory information from the coreboot table in memory.
 
   @param  MemInfoCallback The callback routine
@@ -28,6 +47,7 @@ typedef RETURN_STATUS \
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseMemoryInfo (
   IN  CB_MEM_INFO_CALLBACK  MemInfoCallback,
   IN  VOID  *pParam
@@ -46,6 +66,7 @@ CbParseMemoryInfo (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseCbMemTable (
   IN UINT32 TableId,
   IN VOID** pMemTable,
@@ -64,6 +85,7 @@ CbParseCbMemTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseAcpiTable (
   IN VOID** pMemTable,
   IN UINT32*pMemTableSize
@@ -81,6 +103,7 @@ CbParseAcpiTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseSmbiosTable (
   IN VOID** pMemTable,
   IN UINT32*pMemTableSize
@@ -101,6 +124,7 @@ CbParseSmbiosTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseFadtInfo (
   IN UINTN* pPmCtrlReg,
   IN UINTN* pPmTimerReg,
@@ -125,6 +149,7 @@ CbParseFadtInfo (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseSerialInfo (
   OUT UINT32 *pRegBase,
   OUT UINT32 *pRegAccessType,
@@ -145,6 +170,7 @@ CbParseSerialInfo (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseGetCbHeader (
   IN UINTN  Level,
   IN VOID** HeaderPtr
@@ -160,6 +186,7 @@ CbParseGetCbHeader (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseFbInfo (
   IN FRAME_BUFFER_INFO* pFbInfo
   );
diff --git a/CorebootModulePkg/Library/CbParseLib/CbParseLib.c 
b/CorebootModulePkg/Library/CbParseLib/CbParseLib.c
index 305e38f..0909b0f 100644
--- a/CorebootModulePkg/Library/CbParseLib/CbParseLib.c
+++ b/CorebootModulePkg/Library/CbParseLib/CbParseLib.c
@@ -94,6 +94,7 @@ CbCheckSum16 (
 
 **/
 VOID *
+EFIAPI
 FindCbTag (
   IN  VOID *Start,
   IN  UINT32   Tag
@@ -175,6 +176,7 @@ FindCbTag (
 
 **/
 RETURN_STATUS
+EFIAPI
 FindCbMemTable (
   IN  struct cbmem_root  *Root,
   IN  UINT32 TableId,
@@ -237,6 +239,7 @@ FindCbMemTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseMemoryInfo (
   IN  CB_MEM_INFO_CALLBACK  MemInfoCallback,
   IN  VOID  *pParam
@@ -287,6 +290,7 @@ CbParseMemoryInfo (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseCbMemTable (
   IN  UINT32 TableId,
   OUT VOID   **pMemTable,
@@ -343,6 +347,7 @@ CbParseCbMemTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseAcpiTable (
   OUT VOID   **pMemTable,
   OUT UINT32 *pMemTableSize
@@ -363,6 +368,7 @@ CbParseAcpiTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseSmbiosTable (
   OUT VOID   **pMemTable,
   OUT UINT32 *pMemTableSize
@@ -386,6 +392,7 @@ CbParseSmbiosTable (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseFadtInfo (
   OUT UINTN  *pPmCtrlReg,
   OUT UINTN  *pPmTimerReg,
@@ -533,6 +540,7 @@ CbParseFadtInfo (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseSerialInfo (
   OUT UINT32  *pRegBase,
   OUT UINT32  *pRegAccessType,
@@ -591,6 +599,7 @@ CbParseSerialInfo (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseGetCbHeader (
   IN  UINTN  Level,
   OUT VOID   **HeaderPtr
@@ -629,6 +638,7 @@ CbParseGetCbHeader (
 
 **/
 RETURN_STATUS
+EFIAPI
 CbParseFbInfo (
   OUT FRAME_BUFFER_INFO   *pFbInfo
   )
-- 
2.7.0.windows.1

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


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

2016-10-27 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 5/9] Vlv2TbltDevicePkg/PlatformBootManager: Add capsule/recovery handling.

2016-10-27 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 recovery or update.
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 |   9 +
 2 files changed, 135 insertions(+), 55 deletions(-)

diff --git a/Vlv2TbltDevicePkg/Library/PlatformBdsLib/BdsPlatform.c 
b/Vlv2TbltDevicePkg/Library/PlatformBdsLib/BdsPlatform.c
index e1f3524..e4169b3 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 

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

2016-10-27 Thread Jiewen Yao
This is series 5 of the whole capsule solution. Version 5.
According to feedback, we split the big patch series to smaller one.

Series 5: Vlv2 update

The code is also in https://github.com/jyao1/edk2
V5 is at Capsule_V5 branch.
V4, V3, V2, V1 are also pushed to coresponding branch.

==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 CapsuleLib to SystemFirmwareReport.efi.
SystemFirmwareReport.efi supports SetImage() to verify and dispatch the
SystemFirmwareUpdate.efi, then pass thru SetImage() request to
SystemFirmwareUpdate.efi.

Now the DxeCapsuleLib is very clean and it does not have any EDKII
capsule format knowledge.

4) DxeCapsuleLib: Fix issue where a reset may be too soon.
Defer reset to 2nd pass.

5) DxeCapsuleLib: Boot mode check is removed. 
Capsule should be populated to system table even boot mode is not BIOS_UPDATE.

5) FmAuthenticationLib: Add zero ImageSize check.

6) FmAuthenticationLib: Remove Authentication Library Registration.
Each FMP Producer needs to carry its own auth 

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

2016-10-27 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 2/9] Vlv2TbltDevicePkg/SystemFirmwareDescriptor: Add Descriptor for capsule update.

2016-10-27 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-10-27 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 6/9] Vlv2TbltDevicePkg/dsc/fdf: Add capsule/recovery support.

2016-10-27 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   | 146 +++-
 Vlv2TbltDevicePkg/PlatformPkgConfig.dsc |   3 +-
 Vlv2TbltDevicePkg/PlatformPkgGcc.fdf| 146 +++-
 Vlv2TbltDevicePkg/PlatformPkgGccX64.dsc |  82 ++-
 Vlv2TbltDevicePkg/PlatformPkgIA32.dsc   |  82 ++-
 Vlv2TbltDevicePkg/PlatformPkgX64.dsc|  82 ++-
 6 files changed, 405 insertions(+), 136 deletions(-)

diff --git a/Vlv2TbltDevicePkg/PlatformPkg.fdf 
b/Vlv2TbltDevicePkg/PlatformPkg.fdf
index 93b4d2d..9eb3fc1 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,26 @@ FILE FREEFORM = 878AC2CC-5343-46F2-B563-51F89DAF56BA {
   !endif
 !endif
 
+!if $(CAPSULE_ENABLE)
+INF  MdeModulePkg/Universal/EsrtDxe/EsrtDxe.inf
+INF  
SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareReportDxe.inf
+INF  UefiCpuPkg/MicrocodeUpdate/MicrocodeUpdate.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"
+ }
+!endif
+
 [FV.FVMAIN_COMPACT]
 BlockSize  = $(FLASH_BLOCK_SIZE)
 FvAlignment= 16
@@ -780,31 

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

2016-10-27 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 4/9] Vlv2TbltDevicePkg/FlashDeviceLib: Add DXE flash device lib.

2016-10-27 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 7/9] Vlv2TbltDevicePkg/dsc/fdf: add capsule generation DSC/FDF.

2016-10-27 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 V5 7/7] QuarkPlatformPkg/Readme: add capsule/recovery related content.

2016-10-27 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 V5 6/7] QuarkPlatformPkg/dsc/fdf: Add capsule/recovery support.

2016-10-27 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|  72 --
 QuarkPlatformPkg/Quark.fdf| 137 
 QuarkPlatformPkg/QuarkMin.dsc |   7 +-
 3 files changed, 201 insertions(+), 15 deletions(-)

diff --git a/QuarkPlatformPkg/Quark.dsc b/QuarkPlatformPkg/Quark.dsc
index d5988da..153f6e7 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   = TRUE
+  DEFINE RECOVERY_ENABLE  = TRUE
 
   #
   # 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,11 @@
   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}
+!endif
+
 !if $(MEASURED_BOOT_ENABLE)
   #
   # TPM1.2  { 0x8b01e5b6, 0x4f19, 0x46e8, { 0xab, 0x93, 0x1c, 0x53, 0x67, 
0x1b, 0x90, 0xcc } }
@@ -540,6 +560,11 @@
 !endif
   }
 
+!if $(CAPSULE_ENABLE) || $(RECOVERY_ENABLE)
+  # FMP image decriptor
+  
QuarkPlatformPkg/Feature/Capsule/SystemFirmwareDescriptor/SystemFirmwareDescriptor.inf
+!endif
+
   #
   # PEI Core
   #
@@ -594,6 +619,7 @@
   #
   # Recovery
   #
+!if $(RECOVERY_ENABLE)
   QuarkSocPkg/QuarkSouthCluster/Usb/Common/Pei/UsbPei.inf
   

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

2016-10-27 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..9f9f71d
--- /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= AF9C9EB2-12AD-4D3E-A4D4-96F6C9966215  # 
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= AF9C9EB2-12AD-4D3E-A4D4-96F6C9966215  # 
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= AF9C9EB2-12AD-4D3E-A4D4-96F6C9966215  # 
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= AF9C9EB2-12AD-4D3E-A4D4-96F6C9966215  # 
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= AF9C9EB2-12AD-4D3E-A4D4-96F6C9966215  # 
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 V5 0/7] Add capsule support for Quark.

2016-10-27 Thread Jiewen Yao
This is series 4 of the whole capsule solution. Version 5.
According to feedback, we split the big patch series to smaller one.

Series 5: Quark update

The code is also in https://github.com/jyao1/edk2
V5 is at Capsule_V5 branch.
V4, V3, V2, V1 are also pushed to coresponding branch.

==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 CapsuleLib to SystemFirmwareReport.efi.
SystemFirmwareReport.efi supports SetImage() to verify and dispatch the
SystemFirmwareUpdate.efi, then pass thru SetImage() request to
SystemFirmwareUpdate.efi.

Now the DxeCapsuleLib is very clean and it does not have any EDKII
capsule format knowledge.

4) DxeCapsuleLib: Fix issue where a reset may be too soon.
Defer reset to 2nd pass.

5) DxeCapsuleLib: Boot mode check is removed. 
Capsule should be populated to system table even boot mode is not BIOS_UPDATE.

5) FmAuthenticationLib: Add zero ImageSize check.

6) FmAuthenticationLib: Remove Authentication Library Registration.
Each FMP Producer needs to carry its own auth 

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

2016-10-27 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 V5 5/7] QuarkPlatformPkg/PlatformBootManager: Add capsule/recovery handling.

2016-10-27 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 recovery or update.
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..f327c89 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((EFI_D_INFO, "ProcessCapsules Before EndOfDxe ..\n"));
+Status = ProcessCapsules ();
+DEBUG((EFI_D_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((EFI_D_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((EFI_D_INFO, "ProcessCapsules After ConnectAll ..\n"));
+  Status = ProcessCapsules();
+  DEBUG((EFI_D_INFO, "ProcessCapsules %r\n", Status));
+}
+break;
+
+  case BOOT_IN_RECOVERY_MODE:
+DEBUG((EFI_D_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 V5 1/7] QuarkPlatformPkg/PlatformFlashAccessLib: Add instance for capsule update.

2016-10-27 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 V5 4/7] QuarkPlatformPkg/PlatformInit: Remove recovery PPI installation.

2016-10-27 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 V5 6/7] UefiCpuPkg/MicrocodeCapsuleApp: Add MicrocodeCapsuleApp application.

2016-10-27 Thread Jiewen Yao
This MicrocodeCapsuleApp can help generate Microcode FMP capsule.
It can also dump Microcode capsule information.

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/Application/MicrocodeCapsuleApp/AppSupport.c | 443 

 UefiCpuPkg/Application/MicrocodeCapsuleApp/MicrocodeCapsuleApp.c| 268 

 UefiCpuPkg/Application/MicrocodeCapsuleApp/MicrocodeCapsuleApp.inf  |  63 
+++
 UefiCpuPkg/Application/MicrocodeCapsuleApp/MicrocodeCapsuleApp.uni  |  22 +
 UefiCpuPkg/Application/MicrocodeCapsuleApp/MicrocodeCapsuleAppExtra.uni |  19 +
 UefiCpuPkg/Application/MicrocodeCapsuleApp/MicrocodeCapsuleDump.c   | 171 

 6 files changed, 986 insertions(+)

diff --git a/UefiCpuPkg/Application/MicrocodeCapsuleApp/AppSupport.c 
b/UefiCpuPkg/Application/MicrocodeCapsuleApp/AppSupport.c
new file mode 100644
index 000..0ab016c
--- /dev/null
+++ b/UefiCpuPkg/Application/MicrocodeCapsuleApp/AppSupport.c
@@ -0,0 +1,443 @@
+/** @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 
+
+UINTN  Argc = 0;
+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 

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

2016-10-27 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 | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc
index bfe0fbd..fab87ad 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/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.inf
 
 [LibraryClasses.common.SEC]
   PlatformSecLib|UefiCpuPkg/Library/PlatformSecLibNull/PlatformSecLibNull.inf
@@ -131,6 +132,8 @@
   UefiCpuPkg/SecCore/SecCore.inf
   UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf
   UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf
+  UefiCpuPkg/MicrocodeUpdate/MicrocodeUpdate.inf
+  UefiCpuPkg/Application/MicrocodeCapsuleApp/MicrocodeCapsuleApp.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 V5 5/7] UefiCpuPkg/MicrocodeUpdate: Add MicrocodeUpdate component.

2016-10-27 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/MicrocodeUpdate/MicrocodeFmp.c  | 537 ++
 UefiCpuPkg/MicrocodeUpdate/MicrocodeUpdate.c   | 779 

 UefiCpuPkg/MicrocodeUpdate/MicrocodeUpdate.h   | 403 ++
 UefiCpuPkg/MicrocodeUpdate/MicrocodeUpdate.inf |  68 ++
 UefiCpuPkg/MicrocodeUpdate/MicrocodeUpdateDxe.uni  |  21 +
 UefiCpuPkg/MicrocodeUpdate/MicrocodeUpdateDxeExtra.uni |  20 +
 6 files changed, 1828 insertions(+)

diff --git a/UefiCpuPkg/MicrocodeUpdate/MicrocodeFmp.c 
b/UefiCpuPkg/MicrocodeUpdate/MicrocodeFmp.c
new file mode 100644
index 000..50a6632
--- /dev/null
+++ b/UefiCpuPkg/MicrocodeUpdate/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
+ that package version update is in 
progress.
+  @param[out] PackageVersionName A pointer to a pointer to a 
null-terminated string representing the
+ 

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

2016-10-27 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/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.c   
| 42 
 UefiCpuPkg/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.inf 
| 40 +++
 UefiCpuPkg/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.uni 
| 21 ++
 3 files changed, 103 insertions(+)

diff --git 
a/UefiCpuPkg/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.c 
b/UefiCpuPkg/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.c
new file mode 100644
index 000..7a5ec15
--- /dev/null
+++ 
b/UefiCpuPkg/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/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.inf
 
b/UefiCpuPkg/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.inf
new file mode 100644
index 000..a4a47e0
--- /dev/null
+++ 
b/UefiCpuPkg/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/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.uni
 
b/UefiCpuPkg/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.uni
new file mode 100644
index 000..cc4195c
--- /dev/null
+++ 
b/UefiCpuPkg/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 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 V5 1/7] UefiCpuPkg/Include: Add Microcode FMP definition.

2016-10-27 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 V5 0/7] Add MicrocodeUpdate support.

2016-10-27 Thread Jiewen Yao
This is series 3 of the whole capsule solution. Version 5.
According to feedback, we split the big patch series to smaller one.

Series 3: Microcode Update (UefiCpuPkg)
MicrocodeFlashAccessLib
MicrocodeUpdate driver.

The code is also in https://github.com/jyao1/edk2
V5 is at Capsule_V5 branch.
V4, V3, V2, V1 are also pushed to coresponding branch.

==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 CapsuleLib to SystemFirmwareReport.efi.
SystemFirmwareReport.efi supports SetImage() to verify and dispatch the
SystemFirmwareUpdate.efi, then pass thru SetImage() request to
SystemFirmwareUpdate.efi.

Now the DxeCapsuleLib is very clean and it does not have any EDKII
capsule format knowledge.

4) DxeCapsuleLib: Fix issue where a reset may be too soon.
Defer reset to 2nd pass.

5) DxeCapsuleLib: Boot mode check is removed. 
Capsule should be populated to system table even boot mode is not BIOS_UPDATE.

5) FmAuthenticationLib: Add zero ImageSize check.

6) FmAuthenticationLib: Remove 

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

2016-10-27 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 V5 2/7] UefiCpuPkg/Include: Add MicrocodeFlashAccessLib header.

2016-10-27 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 V5 12/12] SignedCapsulePkg/CapsulePkg.dsc: Add capsule related component.

2016-10-27 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..186b86e
--- /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 V5 04/12] SignedCapsulePkg/Include: Add IniParsingLib header.

2016-10-27 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 V5 07/12] SignedCapsulePkg/IniParsingLib: Add InitParsingLib instance.

2016-10-27 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..6484df7
--- /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 V5 08/12] SignedCapsulePkg/EdkiiSystemCapsuleLib: Add EdkiiSystemCapsuleLib.

2016-10-27 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..e0b8a4b
--- /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 V5 03/12] SignedCapsulePkg/Include: Add EdkiiSystemCapsuleLib definition.

2016-10-27 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 V5 06/12] SignedCapsulePkg/CapsulePkg.dec: Add capsule related definition.

2016-10-27 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..436d602
--- /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 V5 11/12] SignedCapsulePkg/RecoveryModuleLoadPei: Add RecoveryModuleLoadPei.

2016-10-27 Thread Jiewen Yao
RecoveryModuleLoadPei supports recovery system firmware via UEFI 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..40cd302
--- /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((EFI_D_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 V5 10/12] SignedCapsulePkg/SystemFirmwareUpdate: Add SystemFirmwareUpdate.

2016-10-27 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..ba57d2c
--- /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 V5 09/12] SignedCapsulePkg/PlatformFlashAccessLib: Add NULL instance.

2016-10-27 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 V5 05/12] SignedCapsulePkg/Include: Add PlatformFlashAccessLib header.

2016-10-27 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 V5 01/12] SignedCapsulePkg: Add license file.

2016-10-27 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 V5 02/12] SignedCapsulePkg/Include: Add EDKII system FMP capsule header.

2016-10-27 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 V5 00/12] Add EDKII signed capsule support.

2016-10-27 Thread Jiewen Yao
This is series 2 of the whole capsule solution. Version 5.
According to feedback, we split the big patch series to smaller one.

Series 2: EDKII Capsule (SignedCapsulePkg)
IniParsingLib
EdkiiSystemCapsuleLib
PlatformFlashAccessLib
SystemFirmwareUpdate driver
RecoveryModuleLoadPei driver

The code is also in https://github.com/jyao1/edk2
V5 is at Capsule_V5 branch.
V4, V3, V2, V1 are also pushed to coresponding branch.

==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 CapsuleLib to SystemFirmwareReport.efi.
SystemFirmwareReport.efi supports SetImage() to verify and dispatch the
SystemFirmwareUpdate.efi, then pass thru SetImage() request to
SystemFirmwareUpdate.efi.

Now the DxeCapsuleLib is very clean and it does not have any EDKII
capsule format knowledge.

4) DxeCapsuleLib: Fix issue where a reset may be too soon.
Defer reset to 2nd pass.

5) DxeCapsuleLib: Boot mode check is removed. 
Capsule should be populated to system table even boot mode is not 

[edk2] [Patch 3/3] IntelFrameworkModulePkg LzmaDecompressLib: Update LZMA to new 16.04 version

2016-10-27 Thread Liming Gao
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Liming Gao 
---
 .../LzmaCustomDecompressLib/LZMA-SDK-README.txt|   6 +-
 .../LzmaArchCustomDecompressLib.inf|  10 +-
 .../LzmaCustomDecompressLib.inf|  10 +-
 .../LzmaCustomDecompressLib/LzmaDecompress.c   |   4 +-
 .../LzmaCustomDecompressLib/Sdk/C/7zTypes.h| 260 +
 .../LzmaCustomDecompressLib/Sdk/C/7zVersion.h  |  24 +-
 .../Library/LzmaCustomDecompressLib/Sdk/C/Bra.h|   8 +-
 .../Library/LzmaCustomDecompressLib/Sdk/C/Bra86.c  |  99 ++--
 .../LzmaCustomDecompressLib/Sdk/C/Compiler.h   |  32 ++
 .../LzmaCustomDecompressLib/Sdk/C/CpuArch.h| 206 ++-
 .../Library/LzmaCustomDecompressLib/Sdk/C/LzFind.c | 534 +-
 .../Library/LzmaCustomDecompressLib/Sdk/C/LzFind.h |  40 +-
 .../Library/LzmaCustomDecompressLib/Sdk/C/LzHash.h |  47 +-
 .../LzmaCustomDecompressLib/Sdk/C/LzmaDec.c| 290 ++
 .../LzmaCustomDecompressLib/Sdk/C/LzmaDec.h|  12 +-
 .../LzmaCustomDecompressLib/Sdk/C/Precomp.h|  10 +
 .../Library/LzmaCustomDecompressLib/Sdk/C/Types.h  | 231 
 .../Sdk/DOC/lzma-history.txt   | 363 +
 .../LzmaCustomDecompressLib/Sdk/DOC/lzma-sdk.txt   | 357 +
 .../LzmaCustomDecompressLib/Sdk/history.txt| 236 
 .../Library/LzmaCustomDecompressLib/Sdk/lzma.txt   | 594 -
 21 files changed, 1937 insertions(+), 1436 deletions(-)
 create mode 100644 
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/7zTypes.h
 create mode 100644 
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Compiler.h
 create mode 100644 
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Precomp.h
 delete mode 100644 
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Types.h
 create mode 100644 
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/DOC/lzma-history.txt
 create mode 100644 
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/DOC/lzma-sdk.txt
 delete mode 100644 
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/history.txt
 delete mode 100644 
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/lzma.txt

diff --git 
a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LZMA-SDK-README.txt 
b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LZMA-SDK-README.txt
index e05b3bb..7a6a77f 100644
--- 
a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LZMA-SDK-README.txt
+++ 
b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LZMA-SDK-README.txt
@@ -1,4 +1,4 @@
-LzmaCustomDecompressLib is based on the LZMA SDK 4.65.
-LZMA SDK 4.65 was placed in the public domain on
-2009-02-03.  It was released on the
+LzmaCustomDecompressLib is based on the LZMA SDK 16.04.
+LZMA SDK 16.04 was placed in the public domain on
+2016-10-04.  It was released on the
 http://www.7-zip.org/sdk.html website.
\ No newline at end of file
diff --git 
a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaArchCustomDecompressLib.inf
 
b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaArchCustomDecompressLib.inf
index ec7585d..ccd620b 100644
--- 
a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaArchCustomDecompressLib.inf
+++ 
b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaArchCustomDecompressLib.inf
@@ -1,11 +1,11 @@
 ## @file
 #  LzmaArchCustomDecompressLib produces LZMA custom decompression algorithm 
with the converter for the different arch code.
 #
-#  It is based on the LZMA SDK 4.65.
-#  LZMA SDK 4.65 was placed in the public domain on 2009-02-03.
+#  It is based on the LZMA SDK 16.04
+#  LZMA SDK 16.04 was placed in the public domain on 2016-10-04.
 #  It was released on the http://www.7-zip.org/sdk.html website.
 #
-#  Copyright (c) 2012 - 2015, Intel Corporation. All rights reserved.
+#  Copyright (c) 2012 - 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
@@ -43,7 +43,9 @@
   Sdk/C/LzFind.h
   Sdk/C/LzHash.h
   Sdk/C/LzmaDec.h
-  Sdk/C/Types.h  
+  Sdk/C/7zTypes.h
+  Sdk/C/Precomp.h
+  Sdk/C/Compiler.h
   UefiLzma.h
   LzmaDecompressLibInternal.h
 
diff --git 
a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf
 
b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf
index f5624fd..127c7de 100644
--- 
a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf
+++ 
b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf
@@ -1,11 +1,11 @@
 ## @file
 #  LzmaCustomDecompressLib produces LZMA custom decompression algorithm.
 #
-#  It is based on the LZMA SDK 4.65.
-#  LZMA SDK 4.65 was placed in the public domain on 2009-02-03.
+#  It is based on the LZMA SDK 16.04.

[edk2] [Patch 2/3] MdeModulePkg LzmaDecompressLib: Update LZMA to new 16.04 version

2016-10-27 Thread Liming Gao
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Liming Gao 
---
 .../LzmaCustomDecompressLib/LZMA-SDK-README.txt|   6 +-
 .../LzmaArchCustomDecompressLib.inf|  10 +-
 .../LzmaCustomDecompressLib.inf|  10 +-
 .../LzmaCustomDecompressLib/LzmaDecompress.c   |   4 +-
 .../LzmaCustomDecompressLib/Sdk/C/7zTypes.h| 260 +
 .../LzmaCustomDecompressLib/Sdk/C/7zVersion.h  |  24 +-
 .../Library/LzmaCustomDecompressLib/Sdk/C/Bra.h|   8 +-
 .../Library/LzmaCustomDecompressLib/Sdk/C/Bra86.c  |  99 ++--
 .../LzmaCustomDecompressLib/Sdk/C/Compiler.h   |  32 ++
 .../LzmaCustomDecompressLib/Sdk/C/CpuArch.h| 206 ++-
 .../Library/LzmaCustomDecompressLib/Sdk/C/LzFind.c | 534 +-
 .../Library/LzmaCustomDecompressLib/Sdk/C/LzFind.h |  40 +-
 .../Library/LzmaCustomDecompressLib/Sdk/C/LzHash.h |  47 +-
 .../LzmaCustomDecompressLib/Sdk/C/LzmaDec.c| 290 ++
 .../LzmaCustomDecompressLib/Sdk/C/LzmaDec.h|  12 +-
 .../LzmaCustomDecompressLib/Sdk/C/Precomp.h|  10 +
 .../Library/LzmaCustomDecompressLib/Sdk/C/Types.h  | 231 
 .../Sdk/DOC/lzma-history.txt   | 363 +
 .../LzmaCustomDecompressLib/Sdk/DOC/lzma-sdk.txt   | 357 +
 .../LzmaCustomDecompressLib/Sdk/history.txt| 236 
 .../Library/LzmaCustomDecompressLib/Sdk/lzma.txt   | 594 -
 21 files changed, 1937 insertions(+), 1436 deletions(-)
 create mode 100644 MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/7zTypes.h
 create mode 100644 
MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Compiler.h
 create mode 100644 MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Precomp.h
 delete mode 100644 MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Types.h
 create mode 100644 
MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/DOC/lzma-history.txt
 create mode 100644 
MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/DOC/lzma-sdk.txt
 delete mode 100644 MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/history.txt
 delete mode 100644 MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/lzma.txt

diff --git a/MdeModulePkg/Library/LzmaCustomDecompressLib/LZMA-SDK-README.txt 
b/MdeModulePkg/Library/LzmaCustomDecompressLib/LZMA-SDK-README.txt
index e05b3bb..7a6a77f 100644
--- a/MdeModulePkg/Library/LzmaCustomDecompressLib/LZMA-SDK-README.txt
+++ b/MdeModulePkg/Library/LzmaCustomDecompressLib/LZMA-SDK-README.txt
@@ -1,4 +1,4 @@
-LzmaCustomDecompressLib is based on the LZMA SDK 4.65.
-LZMA SDK 4.65 was placed in the public domain on
-2009-02-03.  It was released on the
+LzmaCustomDecompressLib is based on the LZMA SDK 16.04.
+LZMA SDK 16.04 was placed in the public domain on
+2016-10-04.  It was released on the
 http://www.7-zip.org/sdk.html website.
\ No newline at end of file
diff --git 
a/MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaArchCustomDecompressLib.inf 
b/MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaArchCustomDecompressLib.inf
index ec7585d..ccd620b 100644
--- 
a/MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaArchCustomDecompressLib.inf
+++ 
b/MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaArchCustomDecompressLib.inf
@@ -1,11 +1,11 @@
 ## @file
 #  LzmaArchCustomDecompressLib produces LZMA custom decompression algorithm 
with the converter for the different arch code.
 #
-#  It is based on the LZMA SDK 4.65.
-#  LZMA SDK 4.65 was placed in the public domain on 2009-02-03.
+#  It is based on the LZMA SDK 16.04
+#  LZMA SDK 16.04 was placed in the public domain on 2016-10-04.
 #  It was released on the http://www.7-zip.org/sdk.html website.
 #
-#  Copyright (c) 2012 - 2015, Intel Corporation. All rights reserved.
+#  Copyright (c) 2012 - 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
@@ -43,7 +43,9 @@
   Sdk/C/LzFind.h
   Sdk/C/LzHash.h
   Sdk/C/LzmaDec.h
-  Sdk/C/Types.h  
+  Sdk/C/7zTypes.h
+  Sdk/C/Precomp.h
+  Sdk/C/Compiler.h
   UefiLzma.h
   LzmaDecompressLibInternal.h
 
diff --git 
a/MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf 
b/MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf
index f5624fd..127c7de 100644
--- a/MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf
+++ b/MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf
@@ -1,11 +1,11 @@
 ## @file
 #  LzmaCustomDecompressLib produces LZMA custom decompression algorithm.
 #
-#  It is based on the LZMA SDK 4.65.
-#  LZMA SDK 4.65 was placed in the public domain on 2009-02-03.
+#  It is based on the LZMA SDK 16.04.
+#  LZMA SDK 16.04 was placed in the public domain on 2016-10-04.
 #  It was released on the http://www.7-zip.org/sdk.html website.
 #
-#  Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.
+#  Copyright (c) 2009 - 

[edk2] [Patch 0/3] Update LZMA SDK to new 16.04 version

2016-10-27 Thread Liming Gao
New version LZMA improves the compression performance, and has no change on 
the compression algorithm. So, the decompression library can work with 
the old and new LZMA SDK. To be consistent, LZMA tool and library are both 
updated to new 16.04 version. 

Liming Gao (3):
  BaseTools LzmaCompress: Update LZMA to new 16.04 version
  MdeModulePkg LzmaDecompressLib: Update LZMA to new 16.04 version
  IntelFrameworkModulePkg LzmaDecompressLib: Update LZMA to new 16.04
version

 BaseTools/Source/C/LzmaCompress/GNUmakefile|   3 +-
 .../Source/C/LzmaCompress/LZMA-SDK-README.txt  |   4 +-
 BaseTools/Source/C/LzmaCompress/LzmaCompress.c |  12 +-
 BaseTools/Source/C/LzmaCompress/Makefile   |   6 +-
 BaseTools/Source/C/LzmaCompress/Sdk/C/7zFile.c |  31 +-
 BaseTools/Source/C/LzmaCompress/Sdk/C/7zFile.h |  13 +-
 BaseTools/Source/C/LzmaCompress/Sdk/C/7zStream.c   |  12 +-
 BaseTools/Source/C/LzmaCompress/Sdk/C/7zTypes.h| 256 +
 BaseTools/Source/C/LzmaCompress/Sdk/C/7zVersion.h  |  24 +-
 BaseTools/Source/C/LzmaCompress/Sdk/C/Alloc.c  |  15 +-
 BaseTools/Source/C/LzmaCompress/Sdk/C/Alloc.h  |  13 +-
 BaseTools/Source/C/LzmaCompress/Sdk/C/Bra.h|   8 +-
 BaseTools/Source/C/LzmaCompress/Sdk/C/Bra86.c  |  99 ++--
 BaseTools/Source/C/LzmaCompress/Sdk/C/Compiler.h   |  32 ++
 BaseTools/Source/C/LzmaCompress/Sdk/C/CpuArch.h| 206 ++-
 BaseTools/Source/C/LzmaCompress/Sdk/C/LzFind.c | 515 ++
 BaseTools/Source/C/LzmaCompress/Sdk/C/LzFind.h |  40 +-
 BaseTools/Source/C/LzmaCompress/Sdk/C/LzFindMt.c   | 214 
 BaseTools/Source/C/LzmaCompress/Sdk/C/LzFindMt.h   |  14 +-
 BaseTools/Source/C/LzmaCompress/Sdk/C/LzHash.h |  47 +-
 BaseTools/Source/C/LzmaCompress/Sdk/C/LzmaDec.c| 269 +++---
 BaseTools/Source/C/LzmaCompress/Sdk/C/LzmaDec.h|  12 +-
 BaseTools/Source/C/LzmaCompress/Sdk/C/LzmaEnc.c| 512 ++
 BaseTools/Source/C/LzmaCompress/Sdk/C/LzmaEnc.h|  14 +-
 BaseTools/Source/C/LzmaCompress/Sdk/C/Precomp.h|  10 +
 BaseTools/Source/C/LzmaCompress/Sdk/C/Threads.c| 116 ++--
 BaseTools/Source/C/LzmaCompress/Sdk/C/Threads.h|  95 ++--
 BaseTools/Source/C/LzmaCompress/Sdk/C/Types.h  | 208 
 .../Source/C/LzmaCompress/Sdk/DOC/lzma-history.txt | 363 +
 .../Source/C/LzmaCompress/Sdk/DOC/lzma-sdk.txt | 357 +
 BaseTools/Source/C/LzmaCompress/Sdk/history.txt| 236 
 BaseTools/Source/C/LzmaCompress/Sdk/lzma.txt   | 594 -
 .../LzmaCustomDecompressLib/LZMA-SDK-README.txt|   6 +-
 .../LzmaArchCustomDecompressLib.inf|  10 +-
 .../LzmaCustomDecompressLib.inf|  10 +-
 .../LzmaCustomDecompressLib/LzmaDecompress.c   |   4 +-
 .../LzmaCustomDecompressLib/Sdk/C/7zTypes.h| 260 +
 .../LzmaCustomDecompressLib/Sdk/C/7zVersion.h  |  24 +-
 .../Library/LzmaCustomDecompressLib/Sdk/C/Bra.h|   8 +-
 .../Library/LzmaCustomDecompressLib/Sdk/C/Bra86.c  |  99 ++--
 .../LzmaCustomDecompressLib/Sdk/C/Compiler.h   |  32 ++
 .../LzmaCustomDecompressLib/Sdk/C/CpuArch.h| 206 ++-
 .../Library/LzmaCustomDecompressLib/Sdk/C/LzFind.c | 534 +-
 .../Library/LzmaCustomDecompressLib/Sdk/C/LzFind.h |  40 +-
 .../Library/LzmaCustomDecompressLib/Sdk/C/LzHash.h |  47 +-
 .../LzmaCustomDecompressLib/Sdk/C/LzmaDec.c| 290 ++
 .../LzmaCustomDecompressLib/Sdk/C/LzmaDec.h|  12 +-
 .../LzmaCustomDecompressLib/Sdk/C/Precomp.h|  10 +
 .../Library/LzmaCustomDecompressLib/Sdk/C/Types.h  | 231 
 .../Sdk/DOC/lzma-history.txt   | 363 +
 .../LzmaCustomDecompressLib/Sdk/DOC/lzma-sdk.txt   | 357 +
 .../LzmaCustomDecompressLib/Sdk/history.txt| 236 
 .../Library/LzmaCustomDecompressLib/Sdk/lzma.txt   | 594 -
 .../LzmaCustomDecompressLib/LZMA-SDK-README.txt|   6 +-
 .../LzmaArchCustomDecompressLib.inf|  10 +-
 .../LzmaCustomDecompressLib.inf|  10 +-
 .../LzmaCustomDecompressLib/LzmaDecompress.c   |   4 +-
 .../LzmaCustomDecompressLib/Sdk/C/7zTypes.h| 260 +
 .../LzmaCustomDecompressLib/Sdk/C/7zVersion.h  |  24 +-
 .../Library/LzmaCustomDecompressLib/Sdk/C/Bra.h|   8 +-
 .../Library/LzmaCustomDecompressLib/Sdk/C/Bra86.c  |  99 ++--
 .../LzmaCustomDecompressLib/Sdk/C/Compiler.h   |  32 ++
 .../LzmaCustomDecompressLib/Sdk/C/CpuArch.h| 206 ++-
 .../Library/LzmaCustomDecompressLib/Sdk/C/LzFind.c | 534 +-
 .../Library/LzmaCustomDecompressLib/Sdk/C/LzFind.h |  40 +-
 .../Library/LzmaCustomDecompressLib/Sdk/C/LzHash.h |  47 +-
 .../LzmaCustomDecompressLib/Sdk/C/LzmaDec.c| 290 ++
 .../LzmaCustomDecompressLib/Sdk/C/LzmaDec.h|  12 +-
 .../LzmaCustomDecompressLib/Sdk/C/Precomp.h|  10 +
 .../Library/LzmaCustomDecompressLib/Sdk/C/Types.h  | 231 

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

2016-10-27 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 V5 12/15] SecurityPkg/SecurityPkg.dec: Add PcdPkcs7CertBuffer PCD.

2016-10-27 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 V5 10/15] MdeModulePkg/MdeModulePkg.dsc: Add FMP related component.

2016-10-27 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 V5 08/15] MdeModulePkg/CapsuleApp: Add CapsuleApp application.

2016-10-27 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| 847 

 MdeModulePkg/Application/CapsuleApp/CapsuleApp.inf  |  71 ++
 MdeModulePkg/Application/CapsuleApp/CapsuleApp.uni  |  22 +
 MdeModulePkg/Application/CapsuleApp/CapsuleAppExtra.uni |  19 +
 MdeModulePkg/Application/CapsuleApp/CapsuleDump.c   | 740 +
 6 files changed, 2144 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 V5 07/15] MdeModulePkg/Esrt: Add ESRT_FW_TYPE_SYSTEMFIRMWARE check.

2016-10-27 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 V5 13/15] SecurityPkg/FmpAuthenticationLibPkcs7: Add PKCS7 instance for FMP.

2016-10-27 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 V5 14/15] SecurityPkg/FmpAuthenticationLibRsa2048Sha256: Add RSA2048 instance.

2016-10-27 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 V5 11/15] IntelFrameworkModulePkg/DxeCapsuleLib: Add ProcessCapsules() interface.

2016-10-27 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 V5 03/15] MdeModulePkg/MdeModulePkg.dec: Add capsule related definition.

2016-10-27 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 | 59 
 1 file changed, 59 insertions(+)

diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index 74b8700..16844ea 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
@@ -1141,6 +1145,52 @@
   #  The default value is 0 that means infinite.
   # @Prompt MAX repair count
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxRepairCount|0x00|UINT32|0x00010076
+  
+  ## Status Code for Capsule subclass definitions.
+  #  EFI_SOFTWARE_CAPSULE  = (EFI_SOFTWARE | 0x0081) = 0x0381
+  # @Prompt Status Code for Capsule subclass definitions
+  # @ValidList  0x8003 | 0x0381
+  
gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeSubClassCapsule|0x0381|UINT32|0x0100
+
+  ## Status Code for Capsule definitions.
+  #  EFI_CAPSULE_PROCESS_CAPSULES_BEGIN  = (EFI_OEM_SPECIFIC | 0x0001) = 
0x8001
+  # @Prompt Status Code for Capsule definitions
+  # @ValidList  0x8003 | 0x00010001
+  
gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleStatusCodeProcessCapsulesBegin|0x8001|UINT32|0x0101
+
+  ## Status Code for Capsule definitions.
+  #  EFI_CAPSULE_PROCESS_CAPSULES_END= (EFI_OEM_SPECIFIC | 0x0002) = 
0x8002
+  # @Prompt Status Code for Capsule definitions
+  # @ValidList  0x8003 | 0x00010002
+  
gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleStatusCodeProcessCapsulesEnd|0x8002|UINT32|0x0102
+
+  ## Status Code for Capsule definitions.
+  #  EFI_CAPSULE_UPDATING_FIRMWARE   = (EFI_OEM_SPECIFIC | 0x0003) = 
0x8003
+  # @Prompt Status Code for Capsule definitions
+  # @ValidList  0x8003 | 0x00010003
+  
gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleStatusCodeUpdatingFirmware|0x8003|UINT32|0x0103
+
+  ## Status Code for Capsule definitions.
+  #  EFI_CAPSULE_UPDATE_FIRMWARE_SUCCESS = (EFI_OEM_SPECIFIC | 0x0004) = 
0x8004
+  # @Prompt Status Code for Capsule definitions
+  # @ValidList  0x8003 | 0x00010004
+  
gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleStatusCodeUpdateFirmwareSuccess|0x8004|UINT32|0x0104
+
+  ## Status Code for Capsule definitions.
+  #  EFI_CAPSULE_UPDATE_FIRMWARE_FAILED  = (EFI_OEM_SPECIFIC | 0x0005) = 
0x8005
+  # @Prompt Status Code for Capsule definitions
+  # @ValidList  0x8003 | 0x00010005
+  
gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleStatusCodeUpdateFirmwareFailed|0x8005|UINT32|0x0105
+
+  ## Status Code for Capsule definitions.
+  #  EFI_CAPSULE_RESETTING_SYSTEM= (EFI_OEM_SPECIFIC | 0x0006) = 
0x8006
+  # @Prompt Status Code for Capsule definitions
+  # @ValidList  0x8003 | 0x00010001
+  
gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleStatusCodeResettingSystem|0x8006|UINT32|0x0106
+
+  ## CapsuleMax value in capsule report variable.
+  # @Prompt CapsuleMax value in capsule report variable.
+  gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleMax|0x|UINT16|0x0107
 
 [PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx]
   ## This PCD defines the Console output row. The default value is 25 
according to UEFI spec.
@@ -1587,6 +1637,11 @@
   #  The PCD data must be in UNICODE format.
   
gEfiMdeModulePkgTokenSpaceGuid.PcdRecoveryFileName|L"FVMAIN.FV"|VOID*|0x30001045
 
+  ## This PCD hold a list GUIDs for the ImageTypeId to indicate the
+  #  FMP capsule is a system FMP.
+  # @Prompt A list of system FMP ImageTypeId GUIDs
+  

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

2016-10-27 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..e53af90
--- /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;
+}
\ No newline at end of file
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 

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

2016-10-27 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..e5dbb74
--- /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 V5 05/15] MdeModulePkg/DxeCapsuleLibNull: Add ProcessCapsules() interface.

2016-10-27 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 V5 00/15] Add capsule update and recovery sample.

2016-10-27 Thread Jiewen Yao
This is series 1 of the whole capsule solution. Version 5.
According to feedback, we split the big patch series to smaller one.

Series 1: Generic Update (MdeModulePkg/SecurityPkg)
DxeCapsuleLib
FmAuthenticationLib (*)
CapsuleApp (*)

The code is also in https://github.com/jyao1/edk2
V5 is at Capsule_V5 branch.
V4, V3, V2, V1 are also pushed to coresponding branch.

==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 CapsuleLib to SystemFirmwareReport.efi.
SystemFirmwareReport.efi supports SetImage() to verify and dispatch the
SystemFirmwareUpdate.efi, then pass thru SetImage() request to
SystemFirmwareUpdate.efi.

Now the DxeCapsuleLib is very clean and it does not have any EDKII
capsule format knowledge.

4) DxeCapsuleLib: Fix issue where a reset may be too soon.
Defer reset to 2nd pass.

5) DxeCapsuleLib: Boot mode check is removed. 
Capsule should be populated to system table even boot mode is not BIOS_UPDATE.

5) FmAuthenticationLib: Add zero ImageSize check.

6) 

Re: [edk2] [Patch 2/3] MdeModulePkg: Update IP4 stack drivers for classless address unicast check.

2016-10-27 Thread Fu, Siyuan
Hi, Ting

Yes you are right, I have made the v2 patch to keep the zero address and 
broadcast address check, thanks.

BestRegards
Fu Siyuan

> -Original Message-
> From: Ye, Ting
> Sent: Thursday, October 27, 2016 3:18 PM
> To: Fu, Siyuan ; edk2-devel@lists.01.org
> Cc: Zhang, Lubo ; Wu, Jiaxin 
> Subject: RE: [edk2] [Patch 2/3] MdeModulePkg: Update IP4 stack drivers for
> classless address unicast check.
> 
> Hi Siyuan,
> 
> When checking IPv4 address without subnet mask, do you think we need keep
> ALL-ZERO address check? I see the patch removes all checking, for example,
> when user input local IP/Gateway from UI in Ip4Config2Nv.c.
> 
> Best Regards,
> Ye Ting
> 
> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Fu
> Siyuan
> Sent: Thursday, October 27, 2016 9:29 AM
> To: edk2-devel@lists.01.org
> Cc: Ye, Ting ; Zhang, Lubo ; Wu,
> Jiaxin 
> Subject: [edk2] [Patch 2/3] MdeModulePkg: Update IP4 stack drivers for
> classless address unicast check.
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Fu Siyuan 
> Cc: Ye Ting 
> Cc: Zhang Lubo 
> Cc: Wu Jiaxin 
> ---
>  MdeModulePkg/Include/Library/IpIoLib.h |  4 ++-
>  MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c   |  9 ++-
>  MdeModulePkg/Universal/Network/ArpDxe/ArpImpl.c|  7 -
>  .../Universal/Network/Dhcp4Dxe/Dhcp4Impl.c | 29 ++---
> 
>  MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c  |  6 +
>  .../Universal/Network/IScsiDxe/IScsiConfig.c   | 18 ++---
>  .../Universal/Network/Ip4Dxe/Ip4Config2Impl.c  | 15 +++
>  .../Universal/Network/Ip4Dxe/Ip4Config2Nv.c| 30 -
> -
>  MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c  |  7 +
>  .../Universal/Network/Mtftp4Dxe/Mtftp4Impl.c   |  9 +--
>  MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Main.c  |  7 ++---
> MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c  |  9 +--
> MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Main.c  |  5 ++--
>  .../Universal/Network/UefiPxeBcDxe/PxeBcImpl.c | 27 +
> --
>  14 files changed, 61 insertions(+), 121 deletions(-)
> 
> diff --git a/MdeModulePkg/Include/Library/IpIoLib.h
> b/MdeModulePkg/Include/Library/IpIoLib.h
> index 37cba07..aab0c68 100644
> --- a/MdeModulePkg/Include/Library/IpIoLib.h
> +++ b/MdeModulePkg/Include/Library/IpIoLib.h
> @@ -2,7 +2,7 @@
>This library is only intended to be used by UEFI network stack modules.
>It provides the combined IpIo layer on the EFI IP4 Protocol and EFI IP6
> protocol.
> 
> -Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.
> +Copyright (c) 2005 - 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 @@ -261,6 +261,8 @@ typedef
> struct _IP_IO {
>PKT_RCVD_NOTIFY   PktRcvdNotify;   ///< See
> IP_IO_OPEN_DATA::PktRcvdNotify.
>PKT_SENT_NOTIFY   PktSentNotify;   ///< See
> IP_IO_OPEN_DATA::PktSentNotify.
>UINT8 IpVersion;
> +  IP4_ADDR  StationIp;
> +  IP4_ADDR  SubnetMask;
>  } IP_IO;
> 
>  ///
> diff --git a/MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c
> b/MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c
> index ab4df80..d4e9dc1 100644
> --- a/MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c
> +++ b/MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c
> @@ -1029,7 +1029,9 @@ IpIoListenHandlerDpc (
> 
>if (IpIo->IpVersion == IP_VERSION_4) {
>  if ((EFI_IP4 (RxData->Ip4RxData.Header->SourceAddress) != 0) &&
> -!NetIp4IsUnicast (EFI_NTOHL (((EFI_IP4_RECEIVE_DATA *) RxData)-
> >Header->SourceAddress), 0)) {
> +(IpIo->SubnetMask != 0) &&
> +IP4_NET_EQUAL (IpIo->StationIp, EFI_NTOHL (((EFI_IP4_RECEIVE_DATA
> *) RxData)->Header->SourceAddress), IpIo->SubnetMask) &&
> +!NetIp4IsUnicast (EFI_NTOHL (((EFI_IP4_RECEIVE_DATA *)
> + RxData)->Header->SourceAddress), IpIo->SubnetMask)) {
>//
>// The source address is not zero and it's not a unicast IP address,
> discard it.
>//
> @@ -1300,6 +1302,11 @@ IpIoOpen (
>  if (OpenData->IpConfigData.Ip4CfgData.RawData) {
>return EFI_UNSUPPORTED;
>  }
> +
> +if (!OpenData->IpConfigData.Ip4CfgData.UseDefaultAddress) {
> +  IpIo->StationIp = EFI_NTOHL (OpenData-
> >IpConfigData.Ip4CfgData.StationAddress);
> +  IpIo->SubnetMask = EFI_NTOHL (OpenData-
> >IpConfigData.Ip4CfgData.SubnetMask);
> +}
> 
>  Status = IpIo->Ip.Ip4->Configure (
>   

[edk2] [PATCH v2 2/3] MdeModulePkg: Update IP4 stack drivers for classless address unicast check.

2016-10-27 Thread Fu Siyuan
V2 update:
Keep the zero address and broadcast check if network mask is not available.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Fu Siyuan 
Cc: Ye Ting 
Cc: Zhang Lubo 
Cc: Wu Jiaxin 
---
 MdeModulePkg/Include/Library/IpIoLib.h |  4 +++-
 MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c   |  9 ++-
 MdeModulePkg/Universal/Network/ArpDxe/ArpImpl.c|  4 ++--
 .../Universal/Network/Dhcp4Dxe/Dhcp4Impl.c | 28 +++---
 MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c  |  6 +
 .../Universal/Network/IScsiDxe/IScsiConfig.c   | 15 
 .../Universal/Network/Ip4Dxe/Ip4Config2Impl.c  |  9 ---
 .../Universal/Network/Ip4Dxe/Ip4Config2Nv.c| 24 +--
 MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c  |  7 +-
 .../Universal/Network/Mtftp4Dxe/Mtftp4Impl.c   |  8 ++-
 MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Main.c  |  6 ++---
 MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c  |  9 +--
 MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Main.c  |  8 +++
 .../Universal/Network/UefiPxeBcDxe/PxeBcImpl.c | 24 ---
 14 files changed, 75 insertions(+), 86 deletions(-)

diff --git a/MdeModulePkg/Include/Library/IpIoLib.h 
b/MdeModulePkg/Include/Library/IpIoLib.h
index 37cba07..aab0c68 100644
--- a/MdeModulePkg/Include/Library/IpIoLib.h
+++ b/MdeModulePkg/Include/Library/IpIoLib.h
@@ -2,7 +2,7 @@
   This library is only intended to be used by UEFI network stack modules.
   It provides the combined IpIo layer on the EFI IP4 Protocol and EFI IP6 
protocol.
 
-Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.
+Copyright (c) 2005 - 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
@@ -261,6 +261,8 @@ typedef struct _IP_IO {
   PKT_RCVD_NOTIFY   PktRcvdNotify;   ///< See 
IP_IO_OPEN_DATA::PktRcvdNotify.
   PKT_SENT_NOTIFY   PktSentNotify;   ///< See 
IP_IO_OPEN_DATA::PktSentNotify.
   UINT8 IpVersion;
+  IP4_ADDR  StationIp;
+  IP4_ADDR  SubnetMask;
 } IP_IO;
 
 ///
diff --git a/MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c 
b/MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c
index 27fef71..9a70e90 100644
--- a/MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c
+++ b/MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c
@@ -1029,7 +1029,9 @@ IpIoListenHandlerDpc (
 
   if (IpIo->IpVersion == IP_VERSION_4) {
 if ((EFI_IP4 (RxData->Ip4RxData.Header->SourceAddress) != 0) &&
-!NetIp4IsUnicast (EFI_NTOHL (((EFI_IP4_RECEIVE_DATA *) 
RxData)->Header->SourceAddress), 0)) {
+(IpIo->SubnetMask != 0) &&
+IP4_NET_EQUAL (IpIo->StationIp, EFI_NTOHL (((EFI_IP4_RECEIVE_DATA *) 
RxData)->Header->SourceAddress), IpIo->SubnetMask) &&
+!NetIp4IsUnicast (EFI_NTOHL (((EFI_IP4_RECEIVE_DATA *) 
RxData)->Header->SourceAddress), IpIo->SubnetMask)) {
   //
   // The source address is not zero and it's not a unicast IP address, 
discard it.
   //
@@ -1300,6 +1302,11 @@ IpIoOpen (
 if (OpenData->IpConfigData.Ip4CfgData.RawData) {
   return EFI_UNSUPPORTED;
 }
+
+if (!OpenData->IpConfigData.Ip4CfgData.UseDefaultAddress) {
+  IpIo->StationIp = EFI_NTOHL 
(OpenData->IpConfigData.Ip4CfgData.StationAddress);
+  IpIo->SubnetMask = EFI_NTOHL 
(OpenData->IpConfigData.Ip4CfgData.SubnetMask);
+}
 
 Status = IpIo->Ip.Ip4->Configure (
  IpIo->Ip.Ip4,
diff --git a/MdeModulePkg/Universal/Network/ArpDxe/ArpImpl.c 
b/MdeModulePkg/Universal/Network/ArpDxe/ArpImpl.c
index afe4929..a02de20 100644
--- a/MdeModulePkg/Universal/Network/ArpDxe/ArpImpl.c
+++ b/MdeModulePkg/Universal/Network/ArpDxe/ArpImpl.c
@@ -943,9 +943,9 @@ ArpConfigureInstance (
   if (ConfigData->SwAddressType == IPV4_ETHER_PROTO_TYPE) {
 CopyMem (, ConfigData->StationAddress, sizeof (IP4_ADDR));
 
-if (!NetIp4IsUnicast (NTOHL (Ip), 0)) {
+if (IP4_IS_UNSPECIFIED (Ip) || IP4_IS_LOCAL_BROADCAST (Ip)) {
   //
-  // The station address is not a valid IPv4 unicast address.
+  // The station address should not be zero or broadcast address.
   //
   return EFI_INVALID_PARAMETER;
 }
diff --git a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c 
b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c
index 79f7cde..11a536d 100644
--- a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c
+++ b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c
@@ -660,9 +660,7 @@ EfiDhcp4Configure (
 }
 
 CopyMem (, >ClientAddress, sizeof (IP4_ADDR));
-
-if ((Ip != 0) && !NetIp4IsUnicast (NTOHL (Ip), 0)) {
-
+if 

[edk2] [PATCH v2 0/3] classless address network unicast check

2016-10-27 Thread Fu Siyuan
V2 update:
Keep the zero address and broadcast check if network mask is not available.

The classful addressing (IP class A/B/C) has been deprecated according to
RFC4632. This patch updates the NetLib and network drivers for the unicast
check in classless network.

Fu Siyuan (3):
  MdeModulePkg: Update NetLib interface to support classless addressing.
  MdeModulePkg: Update IP4 stack drivers for classless address unicast
check.
  NetworkPkg: Update IP4 stack drivers for classless address unicast
check.

 MdeModulePkg/Include/Library/IpIoLib.h |  4 ++-
 MdeModulePkg/Include/Library/NetLib.h  | 23 -
 MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c   |  9 -
 MdeModulePkg/Library/DxeNetLib/DxeNetLib.c | 26 +++---
 MdeModulePkg/Universal/Network/ArpDxe/ArpImpl.c|  4 +--
 .../Universal/Network/Dhcp4Dxe/Dhcp4Impl.c | 28 ++-
 MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c  |  6 +---
 .../Universal/Network/IScsiDxe/IScsiConfig.c   | 15 +---
 .../Universal/Network/Ip4Dxe/Ip4Config2Impl.c  |  9 +++--
 .../Universal/Network/Ip4Dxe/Ip4Config2Nv.c| 24 ++---
 MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c  |  7 +---
 .../Universal/Network/Mtftp4Dxe/Mtftp4Impl.c   |  8 ++---
 MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Main.c  |  6 ++--
 MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c  |  9 +++--
 MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Main.c  |  8 ++---
 .../Universal/Network/UefiPxeBcDxe/PxeBcImpl.c | 24 -
 NetworkPkg/IScsiDxe/IScsiConfig.c  | 16 ++---
 NetworkPkg/TcpDxe/TcpMain.c|  6 ++--
 NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c| 40 +++---
 NetworkPkg/UefiPxeBcDxe/PxeBcSupport.c |  4 ++-
 20 files changed, 146 insertions(+), 130 deletions(-)

-- 
2.7.4.windows.1

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


[edk2] [PATCH v2 1/3] MdeModulePkg: Update NetLib interface to support classless addressing.

2016-10-27 Thread Fu Siyuan
V2:
Add macro IP4_IS_UNSPECIFIED.

The classful addressing (IP class A/B/C) has been deprecated according to
RFC4632. This patch updates the NetLib NetGetIpClass() and NetIp4IsUnicast()
accordingly.

NetGetIpClass()
The function is kept for compatibility, while the caller of this function
could only check the returned value against with IP4_ADDR_CLASSD (multicast)
or IP4_ADDR_CLASSE (reserved) now. The function has been updated to note this.

NetIp4IsUnicast()
The NetMask becomes a required parameter to check the unicast address.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Fu Siyuan 
Cc: Ye Ting 
Cc: Zhang Lubo 
Cc: Wu Jiaxin 
---
 MdeModulePkg/Include/Library/NetLib.h  | 23 ++-
 MdeModulePkg/Library/DxeNetLib/DxeNetLib.c | 26 --
 2 files changed, 26 insertions(+), 23 deletions(-)

diff --git a/MdeModulePkg/Include/Library/NetLib.h 
b/MdeModulePkg/Include/Library/NetLib.h
index c5c0fc2..26709af 100644
--- a/MdeModulePkg/Include/Library/NetLib.h
+++ b/MdeModulePkg/Include/Library/NetLib.h
@@ -43,9 +43,9 @@ typedef UINT16  TCP_PORTNO;
 //
 // The address classification
 //
-#define  IP4_ADDR_CLASSA   1
-#define  IP4_ADDR_CLASSB   2
-#define  IP4_ADDR_CLASSC   3
+#define  IP4_ADDR_CLASSA   1 // Deprecated
+#define  IP4_ADDR_CLASSB   2 // Deprecated
+#define  IP4_ADDR_CLASSC   3 // Deprecated
 #define  IP4_ADDR_CLASSD   4
 #define  IP4_ADDR_CLASSE   5
 
@@ -231,6 +231,7 @@ typedef struct {
 // Test the IP's attribute, All the IPs are in host byte order.
 //
 #define IP4_IS_MULTICAST(Ip)  (((Ip) & 0xF000) == 0xE000)
+#define IP4_IS_UNSPECIFIED(Ip)((Ip) == 0)
 #define IP4_IS_LOCAL_BROADCAST(Ip)((Ip) == 0x)
 #define IP4_NET_EQUAL(Ip1, Ip2, NetMask)  (((Ip1) & (NetMask)) == ((Ip2) & 
(NetMask)))
 #define IP4_IS_VALID_NETMASK(Ip)  (NetGetMaskLength (Ip) != 
(IP4_MASK_MAX + 1))
@@ -379,6 +380,11 @@ NetGetMaskLength (
   Return the class of the IP address, such as class A, B, C.
   Addr is in host byte order.
 
+  [ATTENTION]
+  Classful addressing (IP class A/B/C) has been deprecated according to 
RFC4632.
+  Caller of this function could only check the returned value against
+  IP4_ADDR_CLASSD (multicast) or IP4_ADDR_CLASSE (reserved) now.
+
   The address of class A  starts with 0.
   If the address belong to class A, return IP4_ADDR_CLASSA.
   The address of class B  starts with 10.
@@ -404,17 +410,16 @@ NetGetIpClass (
 
 /**
   Check whether the IP is a valid unicast address according to
-  the netmask. If NetMask is zero, use the IP address's class to get the 
default mask.
+  the netmask. 
 
-  If Ip is 0, IP is not a valid unicast address.
-  Class D address is used for multicasting and class E address is reserved for 
future. If Ip
-  belongs to class D or class E, Ip is not a valid unicast address.
-  If all bits of the host address of Ip are 0 or 1, Ip is not a valid unicast 
address.
+  ASSERT if NetMask is zero.
+  
+  If all bits of the host address of IP are 0 or 1, IP is also not a valid 
unicast address.
 
   @param[in]  IpThe IP to check against.
   @param[in]  NetMask   The mask of the IP.
 
-  @return TRUE if Ip is a valid unicast address on the network, otherwise 
FALSE.
+  @return TRUE if IP is a valid unicast address on the network, otherwise 
FALSE.
 
 **/
 BOOLEAN
diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c 
b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
index 148bebf..f520845 100644
--- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
+++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
@@ -580,6 +580,11 @@ NetGetMaskLength (
   Return the class of the IP address, such as class A, B, C.
   Addr is in host byte order.
 
+  [ATTENTION]
+  Classful addressing (IP class A/B/C) has been deprecated according to 
RFC4632.
+  Caller of this function could only check the returned value against
+  IP4_ADDR_CLASSD (multicast) or IP4_ADDR_CLASSE (reserved) now.
+
   The address of class A  starts with 0.
   If the address belong to class A, return IP4_ADDR_CLASSA.
   The address of class B  starts with 10.
@@ -628,11 +633,10 @@ NetGetIpClass (
 
 /**
   Check whether the IP is a valid unicast address according to
-  the netmask. If NetMask is zero, use the IP address's class to get the 
default mask.
+  the netmask. 
 
-  If Ip is 0, IP is not a valid unicast address.
-  Class D address is used for multicasting and class E address is reserved for 
future. If Ip
-  belongs to class D or class E, IP is not a valid unicast address.
+  ASSERT if NetMask is zero.
+  
   If all bits of the host address of IP are 0 or 1, IP is also not a valid 
unicast address.
 
   @param[in]  IpThe IP to check against.
@@ -648,18 +652,12 @@ NetIp4IsUnicast (
   IN IP4_ADDR   NetMask
   )
 {
-  

[edk2] [PATCH v2 3/3] NetworkPkg: Update IP4 stack drivers for classless address unicast check.

2016-10-27 Thread Fu Siyuan
V2 update:
Keep the zero address and broadcast check if network mask is not available.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Fu Siyuan 
Cc: Ye Ting 
Cc: Zhang Lubo 
Cc: Wu Jiaxin 
---
 NetworkPkg/IScsiDxe/IScsiConfig.c  | 16 ++
 NetworkPkg/TcpDxe/TcpMain.c|  6 ++---
 NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c| 40 +++---
 NetworkPkg/UefiPxeBcDxe/PxeBcSupport.c |  4 +++-
 4 files changed, 45 insertions(+), 21 deletions(-)

diff --git a/NetworkPkg/IScsiDxe/IScsiConfig.c 
b/NetworkPkg/IScsiDxe/IScsiConfig.c
index 16a90a6..57571ad 100644
--- a/NetworkPkg/IScsiDxe/IScsiConfig.c
+++ b/NetworkPkg/IScsiDxe/IScsiConfig.c
@@ -164,7 +164,10 @@ IpIsUnicast (
   )
 {
   if (IpMode == IP_MODE_IP4) {
-return NetIp4IsUnicast (NTOHL (Ip->Addr[0]), 0);
+if (IP4_IS_UNSPECIFIED (NTOHL (Ip->Addr[0])) || IP4_IS_LOCAL_BROADCAST 
(NTOHL (Ip->Addr[0])))   {
+  return FALSE;
+}
+return TRUE;
   } else if (IpMode == IP_MODE_IP6) {
 return NetIp6IsValidUnicast (>v6);
   } else {
@@ -2349,7 +2352,9 @@ IScsiFormCallback (
 
 case KEY_LOCAL_IP:
   Status = NetLibStrToIp4 (IfrNvData->LocalIp, );
-  if (EFI_ERROR (Status) || !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {
+  if (EFI_ERROR (Status) || 
+  ((Private->Current->SessionConfigData.SubnetMask.Addr[0] != 0) && 
+   !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), 
NTOHL(*(UINT32*)Private->Current->SessionConfigData.SubnetMask.Addr {
 CreatePopUp (
   EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
   ,
@@ -2383,7 +2388,10 @@ IScsiFormCallback (
 
 case KEY_GATE_WAY:
   Status = NetLibStrToIp4 (IfrNvData->Gateway, );
-  if (EFI_ERROR (Status) || ((Gateway.Addr[0] != 0) && !NetIp4IsUnicast 
(NTOHL (Gateway.Addr[0]), 0))) {
+  if (EFI_ERROR (Status) || 
+  ((Gateway.Addr[0] != 0) && 
+   (Private->Current->SessionConfigData.SubnetMask.Addr[0] != 0) && 
+   !NetIp4IsUnicast (NTOHL (Gateway.Addr[0]), 
NTOHL(*(UINT32*)Private->Current->SessionConfigData.SubnetMask.Addr {
 CreatePopUp (
   EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
   ,
@@ -2400,7 +2408,7 @@ IScsiFormCallback (
 case KEY_TARGET_IP:
   UnicodeStrToAsciiStrS (IfrNvData->TargetIp, IpString, sizeof (IpString));
   Status = IScsiAsciiStrToIp (IpString, IfrNvData->IpMode, );
-  if (EFI_ERROR (Status) || !IpIsUnicast (, IfrNvData->IpMode)) {
+  if (EFI_ERROR (Status) || IP4_IS_LOCAL_BROADCAST (EFI_NTOHL(HostIp.v4)) 
|| IP4_IS_UNSPECIFIED (EFI_NTOHL(HostIp.v4))) {
 CreatePopUp (
   EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
   ,
diff --git a/NetworkPkg/TcpDxe/TcpMain.c b/NetworkPkg/TcpDxe/TcpMain.c
index 96a295a..03942ee 100644
--- a/NetworkPkg/TcpDxe/TcpMain.c
+++ b/NetworkPkg/TcpDxe/TcpMain.c
@@ -147,10 +147,10 @@ Tcp4Configure (
   if (NULL != TcpConfigData) {
 
 CopyMem (, >AccessPoint.RemoteAddress, sizeof 
(IP4_ADDR));
-if ((Ip != 0) && !NetIp4IsUnicast (NTOHL (Ip), 0)) {
+if (IP4_IS_LOCAL_BROADCAST (NTOHL (Ip))) {
   return EFI_INVALID_PARAMETER;
 }
-
+
 if (TcpConfigData->AccessPoint.ActiveFlag && (0 == 
TcpConfigData->AccessPoint.RemotePort || (Ip == 0))) {
   return EFI_INVALID_PARAMETER;
 }
@@ -159,7 +159,7 @@ Tcp4Configure (
 
   CopyMem (, >AccessPoint.StationAddress, sizeof 
(IP4_ADDR));
   CopyMem (, >AccessPoint.SubnetMask, sizeof 
(IP4_ADDR));
-  if (!NetIp4IsUnicast (NTOHL (Ip), 0) || !IP4_IS_VALID_NETMASK (NTOHL 
(SubnetMask))) {
+  if (!IP4_IS_VALID_NETMASK (NTOHL (SubnetMask)) || !NetIp4IsUnicast 
(NTOHL (Ip), NTOHL (SubnetMask))) {
 return EFI_INVALID_PARAMETER;
   }
 }
diff --git a/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c 
b/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c
index c7c5bd6..52095c5 100644
--- a/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c
+++ b/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c
@@ -856,8 +856,7 @@ EfiPxeBcMtftp (
   (BufferSize == NULL) ||
   (ServerIp == NULL) ||
   ((BufferPtr == NULL) && DontUseBuffer) ||
-  ((BlockSize != NULL) && (*BlockSize < PXE_MTFTP_DEFAULT_BLOCK_SIZE)) ||
-  (!NetIp4IsUnicast (NTOHL (ServerIp->Addr[0]), 0) && 
!NetIp6IsValidUnicast (>v6))) {
+  ((BlockSize != NULL) && (*BlockSize < PXE_MTFTP_DEFAULT_BLOCK_SIZE))) {
 return EFI_INVALID_PARAMETER;
   }
 
@@ -867,6 +866,16 @@ EfiPxeBcMtftp (
   Mode  = Private->PxeBc.Mode;
 
   if (Mode->UsingIpv6) {
+if (!NetIp6IsValidUnicast (>v6)) {
+  return EFI_INVALID_PARAMETER;
+}
+  } else {
+if (IP4_IS_UNSPECIFIED (NTOHL (ServerIp->Addr[0])) || 
IP4_IS_LOCAL_BROADCAST (NTOHL (ServerIp->Addr[0])))   {
+  return EFI_INVALID_PARAMETER;
+}
+  }
+
+  if (Mode->UsingIpv6) {
 //
 // Set configuration data for Mtftp6 instance.
 //
@@ -1076,7 +1085,7 @@ EfiPxeBcUdpWrite (
 DoNotFragment = 

[edk2] [PATCH] OvmfPkg: Make use of ARRAY_SIZE()

2016-10-27 Thread Gary Lin
Convert the remaining pieces to make the code shorter and more readable.

Cc: Justen Jordan 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Gary Lin 
---
 OvmfPkg/Csm/CsmSupportLib/LegacyRegion.c| 8 
 OvmfPkg/Library/LoadLinuxLib/Linux.c| 2 +-
 OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 4 +---
 OvmfPkg/VirtioGpuDxe/Gop.c  | 7 +++
 4 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/OvmfPkg/Csm/CsmSupportLib/LegacyRegion.c 
b/OvmfPkg/Csm/CsmSupportLib/LegacyRegion.c
index b929db0..8d5d2e5 100644
--- a/OvmfPkg/Csm/CsmSupportLib/LegacyRegion.c
+++ b/OvmfPkg/Csm/CsmSupportLib/LegacyRegion.c
@@ -130,18 +130,18 @@ LegacyRegionManipulationInternal (
   // Loop to find the start PAM.
   //
   StartIndex = 0;
-  for (Index = 0; Index < (sizeof(mSectionArray) / sizeof (mSectionArray[0])); 
Index++) {
+  for (Index = 0; Index < ARRAY_SIZE (mSectionArray); Index++) {
 if ((Start >= mSectionArray[Index].Start) && (Start < 
(mSectionArray[Index].Start + mSectionArray[Index].Length))) {
   StartIndex = Index;
   break;
 }
   }
-  ASSERT (Index < (sizeof(mSectionArray) / sizeof (mSectionArray[0])));
+  ASSERT (Index < ARRAY_SIZE (mSectionArray));
 
   //
   // Program PAM until end PAM is encountered
   //
-  for (Index = StartIndex; Index < (sizeof(mSectionArray) / sizeof 
(mSectionArray[0])); Index++) {
+  for (Index = StartIndex; Index < ARRAY_SIZE (mSectionArray); Index++) {
 if (ReadEnable != NULL) {
   if (*ReadEnable) {
 PciOr8 (
@@ -177,7 +177,7 @@ LegacyRegionManipulationInternal (
   break;
 }
   }
-  ASSERT (Index < (sizeof(mSectionArray) / sizeof (mSectionArray[0])));
+  ASSERT (Index < ARRAY_SIZE (mSectionArray));
 
   return EFI_SUCCESS;
 }
diff --git a/OvmfPkg/Library/LoadLinuxLib/Linux.c 
b/OvmfPkg/Library/LoadLinuxLib/Linux.c
index 9c996ad..68d1537 100644
--- a/OvmfPkg/Library/LoadLinuxLib/Linux.c
+++ b/OvmfPkg/Library/LoadLinuxLib/Linux.c
@@ -357,7 +357,7 @@ SetupLinuxMemmap (
   LastE820->size += EFI_PAGES_TO_SIZE ((UINTN) MemoryMap->NumberOfPages);
   LastEndAddr += EFI_PAGES_TO_SIZE ((UINTN) MemoryMap->NumberOfPages);
 } else {
-  if (E820EntryCount >= (sizeof (Bp->e820_map) / sizeof 
(Bp->e820_map[0]))) {
+  if (E820EntryCount >= ARRAY_SIZE (Bp->e820_map)) {
 break;
   }
   E820->type = (UINT32) E820Type;
diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c 
b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
index 6ba0ca6..ff83703 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
+++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
@@ -419,9 +419,7 @@ PciHostBridgeResourceConflict (
 DEBUG ((EFI_D_ERROR, "RootBridge[%d]:\n", RootBridgeIndex++));
 for (; Descriptor->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR; Descriptor++) {
   ASSERT (Descriptor->ResType <
-  (sizeof (mPciHostBridgeLibAcpiAddressSpaceTypeStr) /
-   sizeof (mPciHostBridgeLibAcpiAddressSpaceTypeStr[0])
-   )
+  ARRAY_SIZE (mPciHostBridgeLibAcpiAddressSpaceTypeStr)
   );
   DEBUG ((EFI_D_ERROR, " %s: Length/Alignment = 0x%lx / 0x%lx\n",
   mPciHostBridgeLibAcpiAddressSpaceTypeStr[Descriptor->ResType],
diff --git a/OvmfPkg/VirtioGpuDxe/Gop.c b/OvmfPkg/VirtioGpuDxe/Gop.c
index c6ff9ed..3438bd0 100644
--- a/OvmfPkg/VirtioGpuDxe/Gop.c
+++ b/OvmfPkg/VirtioGpuDxe/Gop.c
@@ -204,7 +204,7 @@ GopQueryMode (
 {
   EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *GopModeInfo;
 
-  if (ModeNumber >= sizeof mGopResolutions / sizeof mGopResolutions[0]) {
+  if (ModeNumber >= ARRAY_SIZE (mGopResolutions)) {
 return EFI_INVALID_PARAMETER;
   }
 
@@ -239,7 +239,7 @@ GopSetMode (
   EFI_STATUS Status;
   EFI_STATUS Status2;
 
-  if (ModeNumber >= sizeof mGopResolutions / sizeof mGopResolutions[0]) {
+  if (ModeNumber >= ARRAY_SIZE (mGopResolutions)) {
 return EFI_UNSUPPORTED;
   }
 
@@ -258,8 +258,7 @@ GopSetMode (
 //
 VgpuGop->Gop.Mode = >GopMode;
 
-VgpuGop->GopMode.MaxMode = (UINT32)(sizeof mGopResolutions /
-sizeof mGopResolutions[0]);
+VgpuGop->GopMode.MaxMode = (UINT32)(ARRAY_SIZE (mGopResolutions));
 VgpuGop->GopMode.Info= >GopModeInfo;
 VgpuGop->GopMode.SizeOfInfo  = sizeof VgpuGop->GopModeInfo;
 
-- 
2.10.1

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


  1   2   >