Skip to content

Commit

Permalink
Replace Unit Test Device State with Fixed PCD
Browse files Browse the repository at this point in the history
Description

DeviceStateLib provides an interface to get and set various device
state indicators (secure boot, unit test mode, etc.). This change
removes the unit test mode setting from the DeviceStateLib interface
and transitions it to a fixed at build PCD so it cannot be changed
at runtime. The one instance in this repo where
DEVICE_STATE_UNIT_TEST_MODE was referenced has been updated to
reference the PCD.

- [x] Impacts functionality?
  - **Functionality** - Does the change ultimately impact how firmware functions?
  - Examples: Add a new library, publish a new PPI, update an algorithm, ...
- [x] Impacts security?
  - **Security** - Does the change have a direct security impact on an application,
    flow, or firmware?
  - Examples: Crypto algorithm change, buffer overflow fix, parameter
    validation improvement, ...
- [x] Breaking change?
  - **Breaking change** - Will anyone consuming this change experience a break
    in build or boot behavior?
  - Examples: Add a new library class, move a module to a different repo, call
    a function in a new library class in a pre-existing module, ...
- [ ] Includes tests?
  - **Tests** - Does the change include any explicit test code?
  - Examples: Unit tests, integration tests, robot tests, ...
- [ ] Includes documentation?
  - **Documentation** - Does the change contain explicit documentation additions
    outside direct code modifications (and comments)?
  - Examples: Update readme file, add feature readme file, link to documentation
    on an a separate Web page, ...

How This Was Tested

Tested on Q35

Integration Instructions

References to DEVICE_STATE_UNIT_TEST_MODE will need to be removed
from platform code and platforms which want to set unit test mode
will need to set the PCD in their platform DSC file(s).
  • Loading branch information
TaylorBeebe committed Aug 29, 2023
1 parent 4ae03a0 commit 3fadad3
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
1 change: 0 additions & 1 deletion MdeModulePkg/Include/Library/DeviceStateLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#define DEVICE_STATE_DEVELOPMENT_BUILD_ENABLED BIT2
#define DEVICE_STATE_SOURCE_DEBUG_ENABLED BIT3
#define DEVICE_STATE_UNDEFINED BIT4
#define DEVICE_STATE_UNIT_TEST_MODE BIT5

#define DEVICE_STATE_PLATFORM_MODE_0 BIT20
#define DEVICE_STATE_PLATFORM_MODE_1 BIT21
Expand Down
2 changes: 0 additions & 2 deletions MdeModulePkg/Library/DeviceStateLib/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ states or to define any of the unused bits:
* BIT 3: DEVICE_STATE_SOURCE_DEBUG_ENABLED - Source debug mode is enabled
allowing a user to connect and control the device
* BIT 4: DEVICE_STATE_UNDEFINED - Set by the platform
* BIT 5: DEVICE_STATE_UNIT_TEST_MODE - Device has a unit test build. Some
features are disabled to allow for unit tests in UEFI Shell
* BIT 24: DEVICE_STATE_PLATFORM_MODE_0
* BIT 25: DEVICE_STATE_PLATFORM_MODE_1
* BIT 26: DEVICE_STATE_PLATFORM_MODE_2
Expand Down
3 changes: 3 additions & 0 deletions MdePkg/MdePkg.dec
Original file line number Diff line number Diff line change
Expand Up @@ -2264,6 +2264,9 @@
## MU_CHANGE START: Add Stack Cookie Exception Vector
## This PCD specifies the interrupt vector for stack cookie check failures
gEfiMdePkgTokenSpaceGuid.PcdStackCookieExceptionVector|0x42|UINT8|0x30001019

## This PCD indicates if the platform is in unit test mode
gEfiMdePkgTokenSpaceGuid.PcdUnitTestModeActive|FALSE|BOOLEAN|0x3000101a
## MU_CHANGE END

[PcdsFixedAtBuild,PcdsPatchableInModule]
Expand Down
4 changes: 2 additions & 2 deletions UefiCpuPkg/CpuDxe/CpuDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "CpuDxe.h"
#include "CpuMp.h"
#include "CpuPageTable.h"
#include <Library/DeviceStateLib.h> // MU_CHANGE
#include <Library/PcdLib.h> // MU_CHANGE
#define CPU_INTERRUPT_NUM 256

//
Expand Down Expand Up @@ -1285,7 +1285,7 @@ InitializeCpu (

InitializeMpSupport ();
// MU_CHANGE START
if ((GetDeviceState () & DEVICE_STATE_UNIT_TEST_MODE) != 0) {
if (FixedPcdGetBool(PcdUnitTestModeActive)) {
InstallMemoryProtectionNonstopModeProtocol ();
}

Expand Down
2 changes: 1 addition & 1 deletion UefiCpuPkg/CpuDxe/CpuDxe.inf
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
TimerLib
PeCoffGetEntryPointLib
DxeMemoryProtectionHobLib ## MU_CHANGE
DeviceStateLib ## MU_CHANGE

[Sources]
CpuDxe.c
Expand Down Expand Up @@ -87,6 +86,7 @@
gUefiCpuPkgTokenSpaceGuid.PcdCpuStackSwitchExceptionList ## CONSUMES
gUefiCpuPkgTokenSpaceGuid.PcdCpuKnownGoodStackSize ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdTdxSharedBitMask ## CONSUMES
gEfiMdePkgTokenSpaceGuid.PcdUnitTestModeActive ## CONSUMES MU_CHANGE

[Depex]
TRUE
Expand Down

0 comments on commit 3fadad3

Please sign in to comment.