public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel] [edk2-redfish-client][PATCH 4/4] RedfishClientPkg/Features: introduce boot option
@ 2024-01-04  5:09 Nickle Wang via groups.io
  2024-01-04  8:16 ` Chang, Abner via groups.io
  0 siblings, 1 reply; 2+ messages in thread
From: Nickle Wang via groups.io @ 2024-01-04  5:09 UTC (permalink / raw)
  To: devel; +Cc: Abner Chang, Igor Kulchytskyy, Nick Ramirez

- Introduce Redfish boot option driver and library.
This is to support Redfish resource at:
/redfish/v1/Systems/SYSTEM_ID/BootOptions
- Make ETag parameter as optional parameter in
CreatePayloadToPatchResource function.

Signed-off-by: Nickle Wang <nicklew@nvidia.com>
Cc: Abner Chang <abner.chang@amd.com>
Cc: Igor Kulchytskyy <igork@ami.com>
Cc: Nick Ramirez <nramirez@nvidia.com>
---
 .../RedfishClientComponents.dsc.inc           |   2 +
 RedfishClientPkg/RedfishClientLibs.dsc.inc    |   1 +
 .../BootOption/v1_0_4/Dxe/BootOptionDxe.inf   |  56 ++
 .../v1_0_4/Common/BootOptionCommon.h          |  33 +
 .../v1_0_4/Common/BootOptionCommon.c          | 799 ++++++++++++++++++
 .../BootOption/v1_0_4/Dxe/BootOptionDxe.c     | 701 +++++++++++++++
 .../RedfishFeatureUtilityLib.c                |   4 +-
 RedfishClientPkg/RedfishClient.fdf.inc        |   2 +
 8 files changed, 1596 insertions(+), 2 deletions(-)
 create mode 100644 RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.inf
 create mode 100644 RedfishClientPkg/Features/BootOption/v1_0_4/Common/BootOptionCommon.h
 create mode 100644 RedfishClientPkg/Features/BootOption/v1_0_4/Common/BootOptionCommon.c
 create mode 100644 RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.c

diff --git a/RedfishClientPkg/RedfishClientComponents.dsc.inc b/RedfishClientPkg/RedfishClientComponents.dsc.inc
index 300f2e21..ae2a4b02 100644
--- a/RedfishClientPkg/RedfishClientComponents.dsc.inc
+++ b/RedfishClientPkg/RedfishClientComponents.dsc.inc
@@ -33,6 +33,7 @@
   RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSystemCollectionDxe.inf
   RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.inf
   RedfishClientPkg/Features/BootOptionCollection/BootOptionCollectionDxe.inf
+  RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.inf
 
   !include RedfishClientPkg/RedfishJsonStructureDxe.dsc.inc
 
@@ -45,3 +46,4 @@
   RedfishClientPkg/Converter/ComputerSystemCollection/RedfishComputerSystemCollection_Dxe.inf
   RedfishClientPkg/Converter/Bios/v1_0_9/RedfishBios_V1_0_9_Dxe.inf
   RedfishClientPkg/Converter/BootOptionCollection/RedfishBootOptionCollection_Dxe.inf
+  RedfishClientPkg/Converter/BootOption/v1_0_4/RedfishBootOption_V1_0_4_Dxe.inf
diff --git a/RedfishClientPkg/RedfishClientLibs.dsc.inc b/RedfishClientPkg/RedfishClientLibs.dsc.inc
index f961d697..9c7889d2 100644
--- a/RedfishClientPkg/RedfishClientLibs.dsc.inc
+++ b/RedfishClientPkg/RedfishClientLibs.dsc.inc
@@ -24,6 +24,7 @@
   ComputerSystemCollectionLib|RedfishClientPkg/ConverterLib/edk2library/ComputerSystemCollection/Lib.inf
   BiosV1_0_9Lib|RedfishClientPkg/ConverterLib/edk2library/Bios/v1_0_9/Lib.inf
   BootOptionCollectionLib|RedfishClientPkg/ConverterLib/edk2library/BootOptionCollection/Lib.inf
+  BootOptionV1_0_4Lib|RedfishClientPkg/ConverterLib/edk2library/BootOption/v1_0_4/Lib.inf
   #
   # Above modules should be pulled in by build tool.
   #
diff --git a/RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.inf b/RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.inf
new file mode 100644
index 00000000..00c1c5bb
--- /dev/null
+++ b/RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.inf
@@ -0,0 +1,56 @@
+## @file
+#
+#  (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP<BR>
+#  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+
+[Defines]
+  INF_VERSION               = 0x00010005
+  BASE_NAME                 = BootOptionDxe
+  FILE_GUID                 = 66F61747-ECF2-48E6-A221-D210C6382195
+  MODULE_TYPE               = DXE_DRIVER
+  VERSION_STRING            = 1.0
+  ENTRY_POINT               = RedfishResourceEntryPoint
+  UNLOAD_IMAGE              = RedfishResourceUnload
+
+[Packages]
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  RedfishPkg/RedfishPkg.dec
+  RedfishClientPkg/RedfishClientPkg.dec
+
+[Sources]
+  ../Common/BootOptionCommon.h
+  ../Common/BootOptionCommon.c
+  BootOptionDxe.c
+
+[LibraryClasses]
+  BaseMemoryLib
+  DebugLib
+  EdkIIRedfishResourceConfigLib
+  RedfishLib
+  RedfishFeatureUtilityLib
+  RedfishResourceIdentifyLib
+  UefiLib
+  UefiDriverEntryPoint
+  RedfishAddendumLib
+  RedfishHttpCacheLib
+  UefiBootManagerLib
+  DevicePathLib
+  BaseLib
+
+[Protocols]
+  gEdkIIRedfishConfigHandlerProtocolGuid          ## PRODUCED
+  gEfiRestJsonStructureProtocolGuid               ## CONSUMED
+  gEdkIIRedfishResourceConfigProtocolGuid         ## PRODUCED
+
+[Pcd]
+  gEfiRedfishClientPkgTokenSpaceGuid.PcdMaxRedfishSchemaStringSize
+  gEfiRedfishClientPkgTokenSpaceGuid.PcdMaxRedfishSchemaVersionSize
+
+[Depex]
+  TRUE
diff --git a/RedfishClientPkg/Features/BootOption/v1_0_4/Common/BootOptionCommon.h b/RedfishClientPkg/Features/BootOption/v1_0_4/Common/BootOptionCommon.h
new file mode 100644
index 00000000..83babf16
--- /dev/null
+++ b/RedfishClientPkg/Features/BootOption/v1_0_4/Common/BootOptionCommon.h
@@ -0,0 +1,33 @@
+/** @file
+
+  Redfish feature driver implementation - internal header file
+  (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP<BR>
+  Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef EFI_REDFISH_BOOT_OPTION_COMMON_H_
+#define EFI_REDFISH_BOOT_OPTION_COMMON_H_
+
+#include <Library/UefiBootManagerLib.h>
+#include <Library/DevicePathLib.h>
+#include <Library/BaseLib.h>
+#include <RedfishJsonStructure/BootOption/v1_0_4/EfiBootOptionV1_0_4.h>
+#include <RedfishResourceCommon.h>
+
+//
+// Schema information.
+//
+#define RESOURCE_SCHEMA                  "BootOption"
+#define RESOURCE_SCHEMA_MAJOR            "1"
+#define RESOURCE_SCHEMA_MINOR            "0"
+#define RESOURCE_SCHEMA_ERRATA           "4"
+#define RESOURCE_SCHEMA_VERSION          "v1_0_4"
+#define REDPATH_ARRAY_PATTERN            L"/BootOptions/\\{.*\\}/"
+#define REDPATH_ARRAY_PREFIX             L"/BootOptions/"
+#define RESOURCE_SCHEMA_FULL             "x-uefi-redfish-BootOption.v1_0_4"
+#define REDFISH_BOOT_OPTION_PARAMETER    L"?name="
+#define REDFISH_BOOT_OPTION_DEBUG_TRACE  DEBUG_INFO
+#endif
diff --git a/RedfishClientPkg/Features/BootOption/v1_0_4/Common/BootOptionCommon.c b/RedfishClientPkg/Features/BootOption/v1_0_4/Common/BootOptionCommon.c
new file mode 100644
index 00000000..0d4c2162
--- /dev/null
+++ b/RedfishClientPkg/Features/BootOption/v1_0_4/Common/BootOptionCommon.c
@@ -0,0 +1,799 @@
+/** @file
+  Redfish feature driver implementation - common functions
+
+  (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP<BR>
+  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "BootOptionCommon.h"
+
+CHAR8  BootOptionEmptyJson[] = "{\"@odata.id\": \"\", \"@odata.type\": \"#BootOption.v1_0_4.BootOption\", \"Id\": \"\", \"Name\": \"\", \"BootOptionEnabled\": false, \"BootOptionReference\": \"\", \"Description\":\"\", \"DisplayName\": \"\", \"UefiDevicePath\":\"\"}";
+
+REDFISH_RESOURCE_COMMON_PRIVATE  *mRedfishResourcePrivate = NULL;
+
+/**
+  Get boot option variable name from BootOptionReference attribute in Boot Option resource.
+  It's caller's responsibility to release BootOptionName by calling FreePool().
+
+  @param[in]   BootOptionCs   Pointer to boot option structure.
+  @param[in]   BootOptionName Boot option name read from boot option resource.
+
+  @retval EFI_SUCCESS         Boot option name is read successfully.
+  @retval Others              Some error happened.
+
+**/
+EFI_STATUS
+GetBootOptionNameFromRedfish (
+  IN EFI_REDFISH_BOOTOPTION_V1_0_4_CS  *BootOptionCs,
+  OUT EFI_STRING                       *BootOptionName
+  )
+{
+  if ((BootOptionCs == NULL) || (BootOptionName == NULL)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  *BootOptionName = NULL;
+
+  if (BootOptionCs->BootOptionReference == NULL) {
+    DEBUG ((DEBUG_ERROR, "%a: Missing BootOptionReference attribute which is mandatory attribute, ignore this!\n", __func__));
+    return EFI_PROTOCOL_ERROR;
+  }
+
+  *BootOptionName = StrAsciiToUnicode (BootOptionCs->BootOptionReference);
+  if (*BootOptionName == NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Consume resource from given URI.
+
+  @param[in]   This                Pointer to REDFISH_RESOURCE_COMMON_PRIVATE instance.
+  @param[in]   Json                The JSON to consume.
+  @param[in]   HeaderEtag          The Etag string returned in HTTP header.
+
+  @retval EFI_SUCCESS              Value is returned successfully.
+  @retval Others                   Some error happened.
+
+**/
+EFI_STATUS
+RedfishConsumeResourceCommon (
+  IN  REDFISH_RESOURCE_COMMON_PRIVATE  *Private,
+  IN  CHAR8                            *Json,
+  IN  CHAR8                            *HeaderEtag OPTIONAL
+  )
+{
+  EFI_STATUS                        Status;
+  EFI_REDFISH_BOOTOPTION_V1_0_4     *BootOption;
+  EFI_REDFISH_BOOTOPTION_V1_0_4_CS  *BootOptionCs;
+  EFI_BOOT_MANAGER_LOAD_OPTION      LoadOption;
+  BOOLEAN                           LoadOptionEnabled;
+  EFI_STRING                        BootOptionName;
+
+  if ((Private == NULL) || IS_EMPTY_STRING (Json)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  BootOption     = NULL;
+  BootOptionCs   = NULL;
+  BootOptionName = NULL;
+
+  Status = Private->JsonStructProtocol->ToStructure (
+                                          Private->JsonStructProtocol,
+                                          NULL,
+                                          Json,
+                                          (EFI_REST_JSON_STRUCTURE_HEADER **)&BootOption
+                                          );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: ToStructure() failed: %r\n", __func__, Status));
+    return Status;
+  }
+
+  BootOptionCs = BootOption->BootOption;
+
+  //
+  // Check ETAG to see if we need to consume it
+  //
+  if (CheckEtag (Private->Uri, HeaderEtag, NULL)) {
+    //
+    // No change
+    //
+    DEBUG ((REDFISH_BOOT_OPTION_DEBUG_TRACE, "%a: ETAG: %s has no change, ignore consume action\n", __func__, Private->Uri));
+    Status = EFI_SUCCESS;
+    goto ON_RELEASE;
+  }
+
+  //
+  // Get boot option variable name from Redfish.
+  //
+  Status = GetBootOptionNameFromRedfish (BootOptionCs, &BootOptionName);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: can not get boot option name: %r\n", __func__, Status));
+    goto ON_RELEASE;
+  }
+
+  //
+  // Find corresponding Boot#### boot option.
+  //
+  Status = EfiBootManagerVariableToLoadOption (BootOptionName, &LoadOption);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: can not load boot option: %s\n", __func__, BootOptionName));
+    goto ON_RELEASE;
+  }
+
+  //
+  // BootOptionEnabled is the only attribute that is not read-only.
+  //
+  if (BootOptionCs->BootOptionEnabled != NULL) {
+    LoadOptionEnabled = ((LoadOption.Attributes & LOAD_OPTION_ACTIVE) == LOAD_OPTION_ACTIVE);
+
+    if (*BootOptionCs->BootOptionEnabled != LoadOptionEnabled) {
+      if (*BootOptionCs->BootOptionEnabled) {
+        LoadOption.Attributes |= LOAD_OPTION_ACTIVE;
+      } else {
+        LoadOption.Attributes &= ~LOAD_OPTION_ACTIVE;
+      }
+
+      //
+      // Save to variable.
+      //
+      Status = EfiBootManagerLoadOptionToVariable (&LoadOption);
+      if (EFI_ERROR (Status)) {
+        DEBUG ((DEBUG_ERROR, "%a: can not %a boot option: %s: %r", __func__, (*BootOptionCs->BootOptionEnabled ? "enable" : "disable"), BootOptionName, Status));
+      }
+    }
+  }
+
+  EfiBootManagerFreeLoadOption (&LoadOption);
+
+ON_RELEASE:
+
+  //
+  // Release resource.
+  //
+  Private->JsonStructProtocol->DestoryStructure (
+                                 Private->JsonStructProtocol,
+                                 (EFI_REST_JSON_STRUCTURE_HEADER *)BootOption
+                                 );
+
+  if (BootOptionName != NULL) {
+    FreePool (BootOptionName);
+  }
+
+  return EFI_SUCCESS;
+}
+
+EFI_STATUS
+ProvisioningBootOptionProperties (
+  IN  EFI_REST_JSON_STRUCTURE_PROTOCOL  *JsonStructProtocol,
+  IN  CHAR8                             *InputJson,
+  IN  CHAR8                             *ResourceId OPTIONAL,
+  IN  EFI_STRING                        ConfigureLang,
+  IN  BOOLEAN                           ProvisionMode,
+  OUT CHAR8                             **ResultJson
+  )
+{
+  EFI_REDFISH_BOOTOPTION_V1_0_4     *BootOption;
+  EFI_REDFISH_BOOTOPTION_V1_0_4_CS  *BootOptionCs;
+  EFI_STATUS                        Status;
+  BOOLEAN                           PropertyChanged;
+  EFI_BOOT_MANAGER_LOAD_OPTION      LoadOption;
+  EFI_STRING                        DevicePathString;
+  BOOLEAN                           LoadOptionEnabled;
+  CHAR8                             *AsciiStringValue;
+
+  if ((JsonStructProtocol == NULL) || (ResultJson == NULL) || IS_EMPTY_STRING (InputJson) || IS_EMPTY_STRING (ConfigureLang)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  DEBUG ((REDFISH_BOOT_OPTION_DEBUG_TRACE, "%a: provision for %s with: %s\n", __func__, ConfigureLang, (ProvisionMode ? L"Provision resource" : L"Update resource")));
+
+  *ResultJson      = NULL;
+  PropertyChanged  = FALSE;
+  DevicePathString = NULL;
+  AsciiStringValue = NULL;
+  BootOption       = NULL;
+
+  Status = JsonStructProtocol->ToStructure (
+                                 JsonStructProtocol,
+                                 NULL,
+                                 InputJson,
+                                 (EFI_REST_JSON_STRUCTURE_HEADER **)&BootOption
+                                 );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: ToStructure failure: %r\n", __func__, Status));
+    return Status;
+  }
+
+  BootOptionCs = BootOption->BootOption;
+
+  //
+  // Find corresponding Boot#### boot option.
+  //
+  Status = EfiBootManagerVariableToLoadOption (ConfigureLang, &LoadOption);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: can not load boot option: %s\n", __func__, ConfigureLang));
+    goto ON_RELEASE;
+  }
+
+  //
+  // ID
+  //
+  if (BootOptionCs->Id != NULL) {
+    BootOptionCs->Id = NULL;
+  }
+
+  //
+  // Name
+  //
+  if (BootOptionCs->Name != NULL) {
+    BootOptionCs->Name = NULL;
+  }
+
+  //
+  // BootOptionEnabled
+  //
+  if (PropertyChecker (BootOptionCs->BootOptionEnabled, ProvisionMode)) {
+    LoadOptionEnabled = ((LoadOption.Attributes & LOAD_OPTION_ACTIVE) == LOAD_OPTION_ACTIVE);
+    if (*BootOptionCs->BootOptionEnabled != LoadOptionEnabled) {
+      *BootOptionCs->BootOptionEnabled = LoadOptionEnabled;
+      PropertyChanged                  = TRUE;
+    }
+  }
+
+  //
+  // BootOptionReference
+  //
+  if (PropertyChecker (BootOptionCs->BootOptionReference, ProvisionMode)) {
+    AsciiStringValue = StrUnicodeToAscii (ConfigureLang);
+    if (AsciiStringValue != NULL) {
+      if ((BootOptionCs->BootOptionReference == NULL) || (AsciiStrCmp (AsciiStringValue, BootOptionCs->BootOptionReference) != 0)) {
+        BootOptionCs->BootOptionReference = AsciiStringValue;
+        PropertyChanged                   = TRUE;
+      } else {
+        FreePool (AsciiStringValue);
+        AsciiStringValue                  = NULL;
+        BootOptionCs->BootOptionReference = NULL;
+      }
+    }
+  }
+
+  //
+  // Description
+  //
+  if (PropertyChecker (BootOptionCs->Description, ProvisionMode)) {
+    AsciiStringValue = StrUnicodeToAscii (LoadOption.Description);
+    if (AsciiStringValue != NULL) {
+      if ((BootOptionCs->Description == NULL) || (AsciiStrCmp (AsciiStringValue, BootOptionCs->Description) != 0)) {
+        BootOptionCs->Description = AsciiStringValue;
+        PropertyChanged           = TRUE;
+      } else {
+        FreePool (AsciiStringValue);
+        AsciiStringValue          = NULL;
+        BootOptionCs->Description = NULL;
+      }
+    }
+  }
+
+  //
+  // DisplayName
+  //
+  if (PropertyChecker (BootOptionCs->DisplayName, ProvisionMode)) {
+    AsciiStringValue = StrUnicodeToAscii (LoadOption.Description);
+    if (AsciiStringValue != NULL) {
+      if ((BootOptionCs->DisplayName == NULL) || (AsciiStrCmp (AsciiStringValue, BootOptionCs->DisplayName) != 0)) {
+        BootOptionCs->DisplayName = AsciiStringValue;
+        PropertyChanged           = TRUE;
+      } else {
+        FreePool (AsciiStringValue);
+        AsciiStringValue          = NULL;
+        BootOptionCs->DisplayName = NULL;
+      }
+    }
+  }
+
+  //
+  // UefiDevicePath
+  //
+  if (PropertyChecker (BootOptionCs->UefiDevicePath, ProvisionMode)) {
+    DevicePathString = ConvertDevicePathToText (LoadOption.FilePath, TRUE, FALSE);
+    if (DevicePathString != NULL) {
+      AsciiStringValue = StrUnicodeToAscii (DevicePathString);
+      if (AsciiStringValue != NULL) {
+        if ((BootOptionCs->UefiDevicePath == NULL) || (AsciiStrCmp (AsciiStringValue, BootOptionCs->UefiDevicePath) != 0)) {
+          BootOptionCs->UefiDevicePath = AsciiStringValue;
+          PropertyChanged              = TRUE;
+        } else {
+          FreePool (AsciiStringValue);
+          AsciiStringValue             = NULL;
+          BootOptionCs->UefiDevicePath = NULL;
+        }
+      }
+
+      FreePool (DevicePathString);
+    }
+  }
+
+  EfiBootManagerFreeLoadOption (&LoadOption);
+
+ON_RELEASE:
+
+  //
+  // Convert C structure back to JSON text.
+  //
+  Status = JsonStructProtocol->ToJson (
+                                 JsonStructProtocol,
+                                 (EFI_REST_JSON_STRUCTURE_HEADER *)BootOption,
+                                 ResultJson
+                                 );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: ToJson() failed: %r\n", __func__, Status));
+    return Status;
+  }
+
+  //
+  // Release resource.
+  //
+  JsonStructProtocol->DestoryStructure (
+                        JsonStructProtocol,
+                        (EFI_REST_JSON_STRUCTURE_HEADER *)BootOption
+                        );
+
+  return (PropertyChanged ? EFI_SUCCESS : EFI_NOT_FOUND);
+}
+
+/**
+  Provisioning redfish resource by given URI.
+
+  @param[in]   This                Pointer to EFI_HP_REDFISH_HII_PROTOCOL instance.
+  @param[in]   ResourceExist       TRUE if resource exists, PUT method will be used.
+                                   FALSE if resource does not exist POST method is used.
+
+  @retval EFI_SUCCESS              Value is returned successfully.
+  @retval Others                   Some error happened.
+
+**/
+EFI_STATUS
+RedfishProvisioningResourceCommon (
+  IN     REDFISH_RESOURCE_COMMON_PRIVATE  *Private,
+  IN     BOOLEAN                          ResourceExist
+  )
+{
+  CHAR8             *Json;
+  CHAR8             *JsonWithAddendum;
+  EFI_STATUS        Status;
+  EFI_STRING        NewResourceLocation;
+  EFI_STRING        BootOptionName;
+  REDFISH_RESPONSE  Response;
+
+  if (Private == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  Json                = NULL;
+  JsonWithAddendum    = NULL;
+  NewResourceLocation = NULL;
+  BootOptionName      = NULL;
+  ZeroMem (&Response, sizeof (REDFISH_RESPONSE));
+
+  if (ResourceExist) {
+    DEBUG ((DEBUG_ERROR, "%a: dose not support the exist boot option resource\n"));
+    return EFI_UNSUPPORTED;
+  }
+
+  //
+  // Get boot option name from URI. The name is in the query parameter: "?name="
+  //
+  BootOptionName = StrStr (Private->Uri, REDFISH_BOOT_OPTION_PARAMETER);
+  if (BootOptionName == NULL) {
+    DEBUG ((DEBUG_ERROR, "%a: can not get boot option name in: %s\n", __func__, Private->Uri));
+    return EFI_DEVICE_ERROR;
+  }
+
+  BootOptionName[0] = '\0';
+
+  BootOptionName += StrLen (REDFISH_BOOT_OPTION_PARAMETER);
+  if (BootOptionName[0] == '\0') {
+    DEBUG ((DEBUG_ERROR, "%a: empty boot option name in: %s\n", __func__, Private->Uri));
+    return EFI_DEVICE_ERROR;
+  }
+
+  Status = ProvisioningBootOptionProperties (
+             Private->JsonStructProtocol,
+             BootOptionEmptyJson,
+             NULL,
+             BootOptionName,
+             TRUE,
+             &Json
+             );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: provisioning resource for %s failed: %r\n", __func__, BootOptionName, Status));
+    return Status;
+  }
+
+  //
+  // Check and see if platform has OEM data or not
+  //
+  Status = RedfishGetOemData (
+             Private->Uri,
+             RESOURCE_SCHEMA,
+             RESOURCE_SCHEMA_VERSION,
+             Json,
+             &JsonWithAddendum
+             );
+  if (!EFI_ERROR (Status) && (JsonWithAddendum != NULL)) {
+    FreePool (Json);
+    Json             = JsonWithAddendum;
+    JsonWithAddendum = NULL;
+  }
+
+  //
+  // Check and see if platform has addendum data or not
+  //
+  Status = RedfishGetAddendumData (
+             Private->Uri,
+             RESOURCE_SCHEMA,
+             RESOURCE_SCHEMA_VERSION,
+             Json,
+             &JsonWithAddendum
+             );
+  if (!EFI_ERROR (Status) && (JsonWithAddendum != NULL)) {
+    FreePool (Json);
+    Json             = JsonWithAddendum;
+    JsonWithAddendum = NULL;
+  }
+
+  Status = CreatePayloadToPostResource (Private->RedfishService, Private->Payload, Json, NULL, NULL);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: post BootOption resource for %s failed: %r\n", __func__, BootOptionName, Status));
+    goto RELEASE_RESOURCE;
+  }
+
+  //
+  // per Redfish spec. the URL of new resource will be returned in "Location" header.
+  //
+  Status = GetEtagAndLocation (&Response, NULL, &NewResourceLocation);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: cannot find new location: %r\n", __func__, Status));
+    goto RELEASE_RESOURCE;
+  }
+
+  //
+  // Keep location of new resource.
+  //
+  if (NewResourceLocation != NULL) {
+    DEBUG ((REDFISH_BOOT_OPTION_DEBUG_TRACE, "%a: Location: %s\n", __func__, NewResourceLocation));
+    RedfishSetRedfishUri (BootOptionName, NewResourceLocation);
+  }
+
+RELEASE_RESOURCE:
+
+  if (NewResourceLocation != NULL) {
+    FreePool (NewResourceLocation);
+  }
+
+  if (Json != NULL) {
+    FreePool (Json);
+  }
+
+  RedfishFreeResponse (
+    Response.StatusCode,
+    Response.HeaderCount,
+    Response.Headers,
+    Response.Payload
+    );
+
+  return Status;
+}
+
+/**
+  Check resource from given URI.
+
+  @param[in]   This                Pointer to REDFISH_RESOURCE_COMMON_PRIVATE instance.
+  @param[in]   Json                The JSON to consume.
+  @param[in]   HeaderEtag          The Etag string returned in HTTP header.
+
+  @retval EFI_SUCCESS              Value is returned successfully.
+  @retval Others                   Some error happened.
+
+**/
+EFI_STATUS
+RedfishCheckResourceCommon (
+  IN     REDFISH_RESOURCE_COMMON_PRIVATE  *Private,
+  IN     CHAR8                            *Json,
+  IN     CHAR8                            *HeaderEtag OPTIONAL
+  )
+{
+  EFI_STATUS                        Status;
+  EFI_REDFISH_BOOTOPTION_V1_0_4     *BootOption;
+  EFI_REDFISH_BOOTOPTION_V1_0_4_CS  *BootOptionCs;
+  EFI_STRING                        BootOptionName;
+  EFI_BOOT_MANAGER_LOAD_OPTION      LoadOption;
+  REDFISH_RESPONSE                  Response;
+  BOOLEAN                           DeleteResourceRequired;
+  EFI_STRING                        DevicePathString;
+  CHAR8                             *DevicePathAsciiString;
+  CHAR8                             *AsciiUri;
+
+  if ((Private == NULL) || IS_EMPTY_STRING (Json)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  ZeroMem (&Response, sizeof (REDFISH_RESPONSE));
+  DevicePathString       = NULL;
+  DevicePathAsciiString  = NULL;
+  DeleteResourceRequired = FALSE;
+  BootOptionName         = NULL;
+  BootOption             = NULL;
+  AsciiUri               = NULL;
+  Response.Payload       = NULL;
+  Status                 = Private->JsonStructProtocol->ToStructure (
+                                                          Private->JsonStructProtocol,
+                                                          NULL,
+                                                          Json,
+                                                          (EFI_REST_JSON_STRUCTURE_HEADER **)&BootOption
+                                                          );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: ToStructure() failed: %r\n", __func__, Status));
+    return Status;
+  }
+
+  BootOptionCs = BootOption->BootOption;
+
+  //
+  // Get boot option variable name from Redfish.
+  //
+  Status = GetBootOptionNameFromRedfish (BootOptionCs, &BootOptionName);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: can not get boot option name: %r\n", __func__, Status));
+    goto ON_RELEASE;
+  }
+
+  //
+  // Find corresponding Boot#### boot option.
+  //
+  Status = EfiBootManagerVariableToLoadOption (BootOptionName, &LoadOption);
+  if (!EFI_ERROR (Status)) {
+    //
+    // Check the UefiDevicePath
+    //
+    if (BootOptionCs->UefiDevicePath != NULL) {
+      DevicePathString = ConvertDevicePathToText (LoadOption.FilePath, TRUE, FALSE);
+      if (DevicePathString != NULL) {
+        DevicePathAsciiString = StrUnicodeToAscii (DevicePathString);
+        if (DevicePathAsciiString != NULL) {
+          if (AsciiStrCmp (DevicePathAsciiString, BootOptionCs->UefiDevicePath) != 0) {
+            //
+            // The device path of this boot option is not the one in system.
+            //
+            DeleteResourceRequired = TRUE;
+          }
+
+          FreePool (DevicePathAsciiString);
+        }
+
+        FreePool (DevicePathString);
+      } else {
+        DeleteResourceRequired = TRUE;
+      }
+    }
+
+    EfiBootManagerFreeLoadOption (&LoadOption);
+  } else {
+    DeleteResourceRequired = TRUE;
+  }
+
+  //
+  // This boot option is deleted in system. Remove it from BMC too.
+  //
+  if (DeleteResourceRequired) {
+    DEBUG ((REDFISH_BOOT_OPTION_DEBUG_TRACE, "%a: boot option %s is deleted in system. Delete %s\n", __func__, BootOptionName, Private->Uri));
+    AsciiUri = StrUnicodeToAscii (Private->Uri);
+    if (AsciiUri == NULL) {
+      Status = EFI_OUT_OF_RESOURCES;
+      goto ON_RELEASE;
+    }
+
+    Status = RedfishDeleteByUri (Private->RedfishService, AsciiUri, &Response);
+    if (EFI_ERROR (Status)) {
+      DEBUG ((DEBUG_ERROR, "%a: can not delete %s: %r\n", __func__, Private->Uri, Status));
+    }
+
+    //
+    // We delete this resource. So this is not the resource that we supported.
+    // Return EFI_UNSUPPORTED and caller will ignore this resource.
+    //
+    Status = EFI_UNSUPPORTED;
+  } else {
+    //
+    // This is the boot option in system and we need further processing to it.
+    //
+    Status = EFI_SUCCESS;
+
+    //
+    // If configure language is missing due to default settings,
+    // create the record because this is the boot option that we
+    // handle.
+    //
+    if (RedfishGetConfigLanguage (Private->Uri) == NULL) {
+      RedfishSetRedfishUri (BootOptionName, Private->Uri);
+    }
+  }
+
+ON_RELEASE:
+
+  //
+  // Release resource
+  //
+  RedfishFreeResponse (
+    Response.StatusCode,
+    Response.HeaderCount,
+    Response.Headers,
+    Response.Payload
+    );
+
+  //
+  // Release resource.
+  //
+  Private->JsonStructProtocol->DestoryStructure (
+                                 Private->JsonStructProtocol,
+                                 (EFI_REST_JSON_STRUCTURE_HEADER *)BootOption
+                                 );
+
+  if (BootOptionName != NULL) {
+    FreePool (BootOptionName);
+  }
+
+  if (AsciiUri != NULL) {
+    FreePool (AsciiUri);
+  }
+
+  return Status;
+}
+
+/**
+  Update resource to given URI.
+
+  @param[in]   This                Pointer to REDFISH_RESOURCE_COMMON_PRIVATE instance.
+  @param[in]   Json                The JSON to consume.
+
+  @retval EFI_SUCCESS              Value is returned successfully.
+  @retval Others                   Some error happened.
+
+**/
+EFI_STATUS
+RedfishUpdateResourceCommon (
+  IN     REDFISH_RESOURCE_COMMON_PRIVATE  *Private,
+  IN     CHAR8                            *InputJson
+  )
+{
+  EFI_STATUS        Status;
+  CHAR8             *Json;
+  CHAR8             *JsonWithAddendum;
+  EFI_STRING        ConfigureLang;
+  REDFISH_RESPONSE  Response;
+
+  if ((Private == NULL) || IS_EMPTY_STRING (InputJson)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  Json          = NULL;
+  ConfigureLang = NULL;
+  ZeroMem (&Response, sizeof (REDFISH_RESPONSE));
+
+  ConfigureLang = RedfishGetConfigLanguage (Private->Uri);
+  if (ConfigureLang == NULL) {
+    return EFI_NOT_FOUND;
+  }
+
+  Status = ProvisioningBootOptionProperties (
+             Private->JsonStructProtocol,
+             InputJson,
+             NULL,
+             ConfigureLang,
+             FALSE,
+             &Json
+             );
+  if (EFI_ERROR (Status)) {
+    if (Status == EFI_NOT_FOUND) {
+      DEBUG ((REDFISH_BOOT_OPTION_DEBUG_TRACE, "%a: update resource for %s ignored. Nothing changed\n", __func__, ConfigureLang));
+      Status = EFI_SUCCESS;
+    } else {
+      DEBUG ((DEBUG_ERROR, "%a: update resource for %s failed: %r\n", __func__, ConfigureLang, Status));
+    }
+
+    goto ON_RELEASE;
+  }
+
+  //
+  // Check and see if platform has OEM data or not
+  //
+  Status = RedfishGetOemData (
+             Private->Uri,
+             RESOURCE_SCHEMA,
+             RESOURCE_SCHEMA_VERSION,
+             Json,
+             &JsonWithAddendum
+             );
+  if (!EFI_ERROR (Status) && (JsonWithAddendum != NULL)) {
+    FreePool (Json);
+    Json             = JsonWithAddendum;
+    JsonWithAddendum = NULL;
+  }
+
+  //
+  // Check and see if platform has addendum data or not
+  //
+  Status = RedfishGetAddendumData (
+             Private->Uri,
+             RESOURCE_SCHEMA,
+             RESOURCE_SCHEMA_VERSION,
+             Json,
+             &JsonWithAddendum
+             );
+  if (!EFI_ERROR (Status) && (JsonWithAddendum != NULL)) {
+    FreePool (Json);
+    Json             = JsonWithAddendum;
+    JsonWithAddendum = NULL;
+  }
+
+  DEBUG ((REDFISH_BOOT_OPTION_DEBUG_TRACE, "%a: update resource for %s\n", __func__, ConfigureLang));
+
+  //
+  // PATCH back to instance
+  //
+  Status = CreatePayloadToPatchResource (Private->RedfishService, Private->Payload, Json, NULL);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: patch resource for %s failed: %r\n", __func__, ConfigureLang, Status));
+  }
+
+ON_RELEASE:
+
+  if (Json != NULL) {
+    FreePool (Json);
+  }
+
+  if (ConfigureLang != NULL) {
+    FreePool (ConfigureLang);
+  }
+
+  RedfishFreeResponse (
+    Response.StatusCode,
+    Response.HeaderCount,
+    Response.Headers,
+    Response.Payload
+    );
+
+  return Status;
+}
+
+/**
+  Identify resource from given URI.
+
+  @param[in]   This                Pointer to REDFISH_RESOURCE_COMMON_PRIVATE instance.
+  @param[in]   Json                The JSON to consume.
+
+  @retval EFI_SUCCESS              Value is returned successfully.
+  @retval Others                   Some error happened.
+
+**/
+EFI_STATUS
+RedfishIdentifyResourceCommon (
+  IN     REDFISH_RESOURCE_COMMON_PRIVATE  *Private,
+  IN     CHAR8                            *Json
+  )
+{
+  BOOLEAN  Supported;
+
+  Supported = RedfishIdentifyResource (Private->Uri, Private->Json);
+  if (Supported) {
+    return EFI_SUCCESS;
+  }
+
+  return EFI_UNSUPPORTED;
+}
diff --git a/RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.c b/RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.c
new file mode 100644
index 00000000..ba090c51
--- /dev/null
+++ b/RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.c
@@ -0,0 +1,701 @@
+/** @file
+  Redfish feature driver implementation - BootOption
+
+  (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP<BR>
+  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "../Common/BootOptionCommon.h"
+
+extern REDFISH_RESOURCE_COMMON_PRIVATE  *mRedfishResourcePrivate;
+
+EFI_HANDLE  mRedfishResourceConfigProtocolHandle;
+
+/**
+  Provision redfish resource by given URI.
+
+  @param[in]   This                Pointer to EFI_HP_REDFISH_HII_PROTOCOL instance.
+  @param[in]   Uri                 Target URI to create resource.
+  @param[in]   PostMode            TRUE if the resource does not exist, post method is used.
+                                   FALSE if the resource exist but property is missing, put method is used.
+
+  @retval EFI_SUCCESS              Value is returned successfully.
+  @retval Others                   Some error happened.
+
+**/
+EFI_STATUS
+EFIAPI
+RedfishResourceProvisioningResource (
+  IN     EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL  *This,
+  IN     EFI_STRING                              Uri,
+  IN     BOOLEAN                                 PostMode
+  )
+{
+  REDFISH_RESOURCE_COMMON_PRIVATE  *Private;
+  EFI_STATUS                       Status;
+  REDFISH_RESPONSE                 Response;
+
+  if ((This == NULL) || IS_EMPTY_STRING (Uri)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  DEBUG ((REDFISH_BOOT_OPTION_DEBUG_TRACE, "%a: provisioning in %s mode\n", __func__, (PostMode ? L"POST" : L"PATCH")));
+  ZeroMem (&Response, sizeof (REDFISH_RESPONSE));
+  Private = REDFISH_RESOURCE_COMMON_PRIVATE_DATA_FROM_RESOURCE_PROTOCOL (This);
+
+  if (Private->RedfishService == NULL) {
+    return EFI_NOT_READY;
+  }
+
+  Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: get resource from: %s failed\n", __func__, Uri));
+    return Status;
+  }
+
+  Private->Uri     = Uri;
+  Private->Payload = Response.Payload;
+  ASSERT (Private->Payload != NULL);
+
+  Status = RedfishProvisioningResourceCommon (Private, !PostMode);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: failed to provision resource to: %s: %r\n", __func__, Uri, Status));
+  } else {
+    //
+    // Get latest ETag on URI and keep it in variable.
+    //
+    RedfishHttpResetResource (Private->Uri);
+    SetEtagFromUri (Private->RedfishService, Private->Uri, TRUE);
+  }
+
+  if (Private->Payload != NULL) {
+    RedfishFreeResponse (
+      Response.StatusCode,
+      Response.HeaderCount,
+      Response.Headers,
+      Response.Payload
+      );
+    Private->Payload = NULL;
+  }
+
+  return Status;
+}
+
+/**
+  Consume resource from given URI.
+
+  @param[in]   This                Pointer to EFI_HP_REDFISH_HII_PROTOCOL instance.
+  @param[in]   Uri                 The target URI to consume.
+
+  @retval EFI_SUCCESS              Value is returned successfully.
+  @retval Others                   Some error happened.
+
+**/
+EFI_STATUS
+EFIAPI
+RedfishResourceConsumeResource (
+  IN     EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL  *This,
+  IN     EFI_STRING                              Uri
+  )
+{
+  REDFISH_RESOURCE_COMMON_PRIVATE  *Private;
+  EFI_STATUS                       Status;
+  REDFISH_RESPONSE                 Response;
+  EFI_STRING                       PendingSettingUri;
+  REDFISH_RESPONSE                 PendingSettingResponse;
+  REDFISH_RESPONSE                 *ExpectedResponse;
+  CHAR8                            *Etag;
+
+  if ((This == NULL) || IS_EMPTY_STRING (Uri)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  Private = REDFISH_RESOURCE_COMMON_PRIVATE_DATA_FROM_RESOURCE_PROTOCOL (This);
+  ZeroMem (&Response, sizeof (REDFISH_RESPONSE));
+  ZeroMem (&PendingSettingResponse, sizeof (REDFISH_RESPONSE));
+
+  if (Private->RedfishService == NULL) {
+    return EFI_NOT_READY;
+  }
+
+  Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: get resource from: %s failed\n", __func__, Uri));
+    return Status;
+  }
+
+  //
+  // Check and see if "@Redfish.Settings" exist or not.
+  //
+  Status = GetPendingSettings (
+             Private->RedfishService,
+             Response.Payload,
+             &PendingSettingResponse,
+             &PendingSettingUri
+             );
+  if (!EFI_ERROR (Status)) {
+    DEBUG ((REDFISH_BOOT_OPTION_DEBUG_TRACE, "%a: @Redfish.Settings found: %s\n", __func__, PendingSettingUri));
+    Private->Uri     = PendingSettingUri;
+    ExpectedResponse = &PendingSettingResponse;
+  } else {
+    Private->Uri     = Uri;
+    ExpectedResponse = &Response;
+  }
+
+  Private->Payload = ExpectedResponse->Payload;
+  ASSERT (Private->Payload != NULL);
+
+  Private->Json = JsonDumpString (RedfishJsonInPayload (Private->Payload), EDKII_JSON_COMPACT);
+  ASSERT (Private->Json != NULL);
+
+  //
+  // Find etag in HTTP response header
+  //
+  Etag   = NULL;
+  Status = GetEtagAndLocation (ExpectedResponse, &Etag, NULL);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: failed to get ETag from HTTP header\n", __func__));
+  }
+
+  Status = RedfishConsumeResourceCommon (Private, Private->Json, Etag);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: failed to consume resource from: %s: %r\n", __func__, Private->Uri, Status));
+  }
+
+  //
+  // Release resource
+  //
+  if (Etag != NULL) {
+    FreePool (Etag);
+  }
+
+  if (Private->Payload != NULL) {
+    RedfishFreeResponse (
+      Response.StatusCode,
+      Response.HeaderCount,
+      Response.Headers,
+      Response.Payload
+      );
+
+    if (PendingSettingResponse.Payload != NULL) {
+      RedfishFreeResponse (
+        PendingSettingResponse.StatusCode,
+        PendingSettingResponse.HeaderCount,
+        PendingSettingResponse.Headers,
+        PendingSettingResponse.Payload
+        );
+    }
+
+    Private->Payload = NULL;
+  }
+
+  if (Private->Json != NULL) {
+    FreePool (Private->Json);
+    Private->Json = NULL;
+  }
+
+  return Status;
+}
+
+/**
+  Get information about this protocol.
+
+  @param[in]   This                Pointer to EFI_HP_REDFISH_HII_PROTOCOL instance.
+  @param[out]  Schema              Supported schema.
+  @param[out]  Major               Supported major number.
+  @param[out]  Minor               Supported minor number.
+  @param[out]  Errata              Supported errata number.
+
+  @retval EFI_SUCCESS              Value is returned successfully.
+  @retval Others                   Some error happened.
+
+**/
+EFI_STATUS
+EFIAPI
+RedfishResourceGetInfo (
+  IN     EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL  *This,
+  OUT    REDFISH_SCHEMA_INFO                     *Info
+  )
+{
+  if ((This == NULL) || (Info == NULL)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  AsciiStrCpyS (Info->Schema, REDFISH_SCHEMA_STRING_SIZE, RESOURCE_SCHEMA);
+  AsciiStrCpyS (Info->Major, REDFISH_SCHEMA_VERSION_SIZE, RESOURCE_SCHEMA_MAJOR);
+  AsciiStrCpyS (Info->Minor, REDFISH_SCHEMA_VERSION_SIZE, RESOURCE_SCHEMA_MINOR);
+  AsciiStrCpyS (Info->Errata, REDFISH_SCHEMA_VERSION_SIZE, RESOURCE_SCHEMA_ERRATA);
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Update resource to given URI.
+
+  @param[in]   This                Pointer to EFI_HP_REDFISH_HII_PROTOCOL instance.
+  @param[in]   Uri                 The target URI to consume.
+
+  @retval EFI_SUCCESS              Value is returned successfully.
+  @retval Others                   Some error happened.
+
+**/
+EFI_STATUS
+EFIAPI
+RedfishResourceUpdate (
+  IN     EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL  *This,
+  IN     EFI_STRING                              Uri
+  )
+{
+  REDFISH_RESOURCE_COMMON_PRIVATE  *Private;
+  EFI_STATUS                       Status;
+  REDFISH_RESPONSE                 Response;
+
+  if ((This == NULL) || IS_EMPTY_STRING (Uri)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  ZeroMem (&Response, sizeof (REDFISH_RESPONSE));
+  Private = REDFISH_RESOURCE_COMMON_PRIVATE_DATA_FROM_RESOURCE_PROTOCOL (This);
+
+  if (Private->RedfishService == NULL) {
+    return EFI_NOT_READY;
+  }
+
+  Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: get resource from: %s failed\n", __func__, Uri));
+    return Status;
+  }
+
+  Private->Uri     = Uri;
+  Private->Payload = Response.Payload;
+  ASSERT (Private->Payload != NULL);
+
+  Private->Json = JsonDumpString (RedfishJsonInPayload (Private->Payload), EDKII_JSON_COMPACT);
+  ASSERT (Private->Json != NULL);
+
+  Status = RedfishUpdateResourceCommon (Private, Private->Json);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: failed to update resource to: %s: %r\n", __func__, Uri, Status));
+  } else {
+    //
+    // Get latest ETag on URI and keep it in variable.
+    //
+    RedfishHttpResetResource (Private->Uri);
+    SetEtagFromUri (Private->RedfishService, Private->Uri, TRUE);
+  }
+
+  //
+  // Release resource
+  //
+  if (Private->Payload != NULL) {
+    RedfishFreeResponse (
+      Response.StatusCode,
+      Response.HeaderCount,
+      Response.Headers,
+      Response.Payload
+      );
+    Private->Payload = NULL;
+  }
+
+  if (Private->Json != NULL) {
+    FreePool (Private->Json);
+    Private->Json = NULL;
+  }
+
+  return Status;
+}
+
+/**
+  Check resource on given URI.
+
+  @param[in]   This                Pointer to EFI_HP_REDFISH_HII_PROTOCOL instance.
+  @param[in]   Uri                 The target URI to consume.
+
+  @retval EFI_SUCCESS              Value is returned successfully.
+  @retval Others                   Some error happened.
+
+**/
+EFI_STATUS
+EFIAPI
+RedfishResourceCheck (
+  IN     EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL  *This,
+  IN     EFI_STRING                              Uri
+  )
+{
+  REDFISH_RESOURCE_COMMON_PRIVATE  *Private;
+  EFI_STATUS                       Status;
+  REDFISH_RESPONSE                 Response;
+  CHAR8                            *Etag;
+
+  if ((This == NULL) || IS_EMPTY_STRING (Uri)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  ZeroMem (&Response, sizeof (REDFISH_RESPONSE));
+  Private = REDFISH_RESOURCE_COMMON_PRIVATE_DATA_FROM_RESOURCE_PROTOCOL (This);
+
+  if (Private->RedfishService == NULL) {
+    return EFI_NOT_READY;
+  }
+
+  Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: get resource from: %s failed\n", __func__, Uri));
+    return Status;
+  }
+
+  Private->Uri     = Uri;
+  Private->Payload = Response.Payload;
+  ASSERT (Private->Payload != NULL);
+
+  Private->Json = JsonDumpString (RedfishJsonInPayload (Private->Payload), EDKII_JSON_COMPACT);
+  ASSERT (Private->Json != NULL);
+
+  //
+  // Find etag in HTTP response header
+  //
+  Etag   = NULL;
+  Status = GetEtagAndLocation (&Response, &Etag, NULL);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: failed to get ETag from HTTP header\n", __func__));
+  }
+
+  Status = RedfishCheckResourceCommon (Private, Private->Json, Etag);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((REDFISH_BOOT_OPTION_DEBUG_TRACE, "%a: failed to check resource from: %s: %r\n", __func__, Uri, Status));
+  }
+
+  //
+  // Release resource
+  //
+  if (Etag != NULL) {
+    FreePool (Etag);
+  }
+
+  if (Private->Payload != NULL) {
+    RedfishFreeResponse (
+      Response.StatusCode,
+      Response.HeaderCount,
+      Response.Headers,
+      Response.Payload
+      );
+    Private->Payload = NULL;
+  }
+
+  if (Private->Json != NULL) {
+    FreePool (Private->Json);
+    Private->Json = NULL;
+  }
+
+  return Status;
+}
+
+/**
+  Identify resource on given URI.
+
+  @param[in]   This                Pointer to EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL instance.
+  @param[in]   Uri                 The target URI to consume.
+
+  @retval EFI_SUCCESS              This is target resource which we want to handle.
+  @retval EFI_UNSUPPORTED          This is not the target resource.
+  @retval Others                   Some error happened.
+
+**/
+EFI_STATUS
+EFIAPI
+RedfishResourceIdentify (
+  IN     EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL  *This,
+  IN     EFI_STRING                              Uri
+  )
+{
+  REDFISH_RESOURCE_COMMON_PRIVATE  *Private;
+  EFI_STATUS                       Status;
+  REDFISH_RESPONSE                 Response;
+
+  if ((This == NULL) || IS_EMPTY_STRING (Uri)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  ZeroMem (&Response, sizeof (REDFISH_RESPONSE));
+  Private = REDFISH_RESOURCE_COMMON_PRIVATE_DATA_FROM_RESOURCE_PROTOCOL (This);
+
+  if (Private->RedfishService == NULL) {
+    return EFI_NOT_READY;
+  }
+
+  Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: get resource from: %s failed\n", __func__, Uri));
+    return Status;
+  }
+
+  Private->Uri     = Uri;
+  Private->Payload = Response.Payload;
+  ASSERT (Private->Payload != NULL);
+
+  Private->Json = JsonDumpString (RedfishJsonInPayload (Private->Payload), EDKII_JSON_COMPACT);
+  ASSERT (Private->Json != NULL);
+
+  Status = RedfishIdentifyResourceCommon (Private, Private->Json);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((REDFISH_BOOT_OPTION_DEBUG_TRACE, "%a: identify %s failed: %r\n", __func__, Uri, Status));
+  }
+
+  //
+  // Release resource
+  //
+  if (Private->Payload != NULL) {
+    RedfishFreeResponse (
+      Response.StatusCode,
+      Response.HeaderCount,
+      Response.Headers,
+      Response.Payload
+      );
+    Private->Payload = NULL;
+  }
+
+  if (Private->Json != NULL) {
+    FreePool (Private->Json);
+    Private->Json = NULL;
+  }
+
+  return Status;
+}
+
+EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL  mRedfishResourceConfig = {
+  RedfishResourceProvisioningResource,
+  RedfishResourceConsumeResource,
+  RedfishResourceUpdate,
+  RedfishResourceCheck,
+  RedfishResourceIdentify,
+  RedfishResourceGetInfo
+};
+
+/**
+  Initialize a Redfish configure handler.
+
+  This function will be called by the Redfish config driver to initialize each Redfish configure
+  handler.
+
+  @param[in]   This                     Pointer to EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL instance.
+  @param[in]   RedfishConfigServiceInfo Redfish service information.
+
+  @retval EFI_SUCCESS                  The handler has been initialized successfully.
+  @retval EFI_DEVICE_ERROR             Failed to create or configure the REST EX protocol instance.
+  @retval EFI_ALREADY_STARTED          This handler has already been initialized.
+  @retval Other                        Error happens during the initialization.
+
+**/
+EFI_STATUS
+EFIAPI
+RedfishResourceInit (
+  IN  EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL  *This,
+  IN  REDFISH_CONFIG_SERVICE_INFORMATION     *RedfishConfigServiceInfo
+  )
+{
+  REDFISH_RESOURCE_COMMON_PRIVATE  *Private;
+
+  Private = REDFISH_RESOURCE_COMMON_PRIVATE_DATA_FROM_CONFIG_PROTOCOL (This);
+
+  Private->RedfishService = RedfishCreateService (RedfishConfigServiceInfo);
+  if (Private->RedfishService == NULL) {
+    return EFI_DEVICE_ERROR;
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Stop a Redfish configure handler.
+
+  @param[in]   This                Pointer to EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL instance.
+
+  @retval EFI_SUCCESS              This handler has been stoped successfully.
+  @retval Others                   Some error happened.
+
+**/
+EFI_STATUS
+EFIAPI
+RedfishResourceStop (
+  IN  EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL  *This
+  )
+{
+  REDFISH_RESOURCE_COMMON_PRIVATE  *Private;
+
+  Private = REDFISH_RESOURCE_COMMON_PRIVATE_DATA_FROM_CONFIG_PROTOCOL (This);
+
+  if (Private->Event != NULL) {
+    gBS->CloseEvent (Private->Event);
+    Private->Event = NULL;
+  }
+
+  if (Private->RedfishService != NULL) {
+    RedfishCleanupService (Private->RedfishService);
+    Private->RedfishService = NULL;
+  }
+
+  if (Private->Payload != NULL) {
+    RedfishCleanupPayload (Private->Payload);
+    Private->Payload = NULL;
+  }
+
+  return EFI_SUCCESS;
+}
+
+EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL  mRedfishConfigHandler = {
+  RedfishResourceInit,
+  RedfishResourceStop
+};
+
+/**
+  Callback function when gEfiRestJsonStructureProtocolGuid is installed.
+
+  @param[in] Event    Event whose notification function is being invoked.
+  @param[in] Context  Pointer to the notification function's context.
+**/
+VOID
+EFIAPI
+EfiRestJasonStructureProtocolIsReady (
+  IN  EFI_EVENT  Event,
+  IN  VOID       *Context
+  )
+{
+  EFI_STATUS  Status;
+
+  if (mRedfishResourcePrivate == NULL) {
+    return;
+  }
+
+  if (mRedfishResourcePrivate->JsonStructProtocol != NULL) {
+    return;
+  }
+
+  Status = gBS->LocateProtocol (
+                  &gEfiRestJsonStructureProtocolGuid,
+                  NULL,
+                  (VOID **)&mRedfishResourcePrivate->JsonStructProtocol
+                  );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: failed to locate gEfiRestJsonStructureProtocolGuid: %r\n", __func__, Status));
+  }
+
+  gBS->CloseEvent (Event);
+}
+
+/**
+  Unloads an image.
+
+  @param  ImageHandle           Handle that identifies the image to be unloaded.
+
+  @retval EFI_SUCCESS           The image has been unloaded.
+  @retval EFI_INVALID_PARAMETER ImageHandle is not a valid image handle.
+
+**/
+EFI_STATUS
+EFIAPI
+RedfishResourceUnload (
+  IN EFI_HANDLE  ImageHandle
+  )
+{
+  EFI_STATUS                             Status;
+  EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL  *ConfigHandler;
+
+  if (mRedfishResourcePrivate == NULL) {
+    return EFI_NOT_READY;
+  }
+
+  ConfigHandler = NULL;
+
+  //
+  // Firstly, find ConfigHandler Protocol interface in this ImageHandle.
+  //
+  Status = gBS->OpenProtocol (
+                  ImageHandle,
+                  &gEdkIIRedfishConfigHandlerProtocolGuid,
+                  (VOID **)&ConfigHandler,
+                  NULL,
+                  NULL,
+                  EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
+                  );
+  if (EFI_ERROR (Status) || (ConfigHandler == NULL)) {
+    return Status;
+  }
+
+  ConfigHandler->Stop (ConfigHandler);
+
+  //
+  // Last, uninstall ConfigHandler Protocol and resource protocol.
+  //
+  Status = gBS->UninstallMultipleProtocolInterfaces (
+                  ImageHandle,
+                  &gEdkIIRedfishConfigHandlerProtocolGuid,
+                  ConfigHandler,
+                  &gEdkIIRedfishResourceConfigProtocolGuid,
+                  &mRedfishResourcePrivate->RedfishResourceConfig,
+                  NULL
+                  );
+
+  FreePool (mRedfishResourcePrivate);
+  mRedfishResourcePrivate = NULL;
+
+  return Status;
+}
+
+/**
+  This is the declaration of an EFI image entry point. This entry point is
+  the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
+  both device drivers and bus drivers. It initialize the global variables and
+  publish the driver binding protocol.
+
+  @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 operation completed successfully.
+  @retval Others                Other errors as indicated.
+**/
+EFI_STATUS
+EFIAPI
+RedfishResourceEntryPoint (
+  IN EFI_HANDLE        ImageHandle,
+  IN EFI_SYSTEM_TABLE  *SystemTable
+  )
+{
+  EFI_STATUS  Status;
+  VOID        *Registration;
+
+  if (mRedfishResourcePrivate != NULL) {
+    return EFI_ALREADY_STARTED;
+  }
+
+  mRedfishResourceConfigProtocolHandle = ImageHandle;
+
+  mRedfishResourcePrivate = AllocateZeroPool (sizeof (REDFISH_RESOURCE_COMMON_PRIVATE));
+  CopyMem (&mRedfishResourcePrivate->ConfigHandler, &mRedfishConfigHandler, sizeof (EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL));
+  CopyMem (&mRedfishResourcePrivate->RedfishResourceConfig, &mRedfishResourceConfig, sizeof (EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL));
+
+  //
+  // Publish config handler protocol and resource protocol.
+  //
+  Status = gBS->InstallMultipleProtocolInterfaces (
+                  &ImageHandle,
+                  &gEdkIIRedfishConfigHandlerProtocolGuid,
+                  &mRedfishResourcePrivate->ConfigHandler,
+                  &gEdkIIRedfishResourceConfigProtocolGuid,
+                  &mRedfishResourcePrivate->RedfishResourceConfig,
+                  NULL
+                  );
+
+  EfiCreateProtocolNotifyEvent (
+    &gEfiRestJsonStructureProtocolGuid,
+    TPL_CALLBACK,
+    EfiRestJasonStructureProtocolIsReady,
+    NULL,
+    &Registration
+    );
+
+  return Status;
+}
diff --git a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c
index cad91a41..1c2d40f6 100644
--- a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c
+++ b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c
@@ -1856,7 +1856,7 @@ CreatePayloadToPatchResource (
   IN  REDFISH_SERVICE  *Service,
   IN  REDFISH_PAYLOAD  *TargetPayload,
   IN  CHAR8            *Json,
-  OUT CHAR8            **Etag
+  OUT CHAR8            **Etag OPTIONAL
   )
 {
   REDFISH_PAYLOAD   Payload;
@@ -1864,7 +1864,7 @@ CreatePayloadToPatchResource (
   REDFISH_RESPONSE  PostResponse;
   EFI_STATUS        Status;
 
-  if ((Service == NULL) || (TargetPayload == NULL) || IS_EMPTY_STRING (Json) || (Etag == NULL)) {
+  if ((Service == NULL) || (TargetPayload == NULL) || IS_EMPTY_STRING (Json)) {
     return EFI_INVALID_PARAMETER;
   }
 
diff --git a/RedfishClientPkg/RedfishClient.fdf.inc b/RedfishClientPkg/RedfishClient.fdf.inc
index b8619417..59b8acba 100644
--- a/RedfishClientPkg/RedfishClient.fdf.inc
+++ b/RedfishClientPkg/RedfishClient.fdf.inc
@@ -24,6 +24,7 @@
   INF RedfishClientPkg/HiiToRedfishBootDxe/HiiToRedfishBootDxe.inf
   INF RedfishClientPkg/HiiToRedfishBiosDxe/HiiToRedfishBiosDxe.inf
   INF RedfishClientPkg/Features/BootOptionCollection/BootOptionCollectionDxe.inf
+  INF RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.inf
 
   !include RedfishClientPkg/RedfishJsonStructureDxe.fdf.inc
   #
@@ -35,4 +36,5 @@
   INF RedfishClientPkg/Converter/ComputerSystemCollection/RedfishComputerSystemCollection_Dxe.inf
   INF RedfishClientPkg/Converter/Bios/v1_0_9/RedfishBios_V1_0_9_Dxe.inf
   INF RedfishClientPkg/Converter/BootOptionCollection/RedfishBootOptionCollection_Dxe.inf
+  INF RedfishClientPkg/Converter/BootOption/v1_0_4/RedfishBootOption_V1_0_4_Dxe.inf
 !endif
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#113135): https://edk2.groups.io/g/devel/message/113135
Mute This Topic: https://groups.io/mt/103517656/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



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

end of thread, other threads:[~2024-01-04  8:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-04  5:09 [edk2-devel] [edk2-redfish-client][PATCH 4/4] RedfishClientPkg/Features: introduce boot option Nickle Wang via groups.io
2024-01-04  8:16 ` Chang, Abner via groups.io

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