]> git.proxmox.com Git - mirror_edk2.git/commitdiff
EmulatorPkg/Application: Publish Redfish Host Interface Record
authorAbner Chang <abner.chang@hpe.com>
Thu, 3 Dec 2020 05:05:27 +0000 (13:05 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Thu, 3 Dec 2020 07:54:44 +0000 (07:54 +0000)
BZ:
https://bugzilla.tianocore.org/show_bug.cgi?id=3102

The EFI application to configure the network information of
Redfish service.
The configurations are stored in EFI variables.

Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com>
Signed-off-by: Ting Ye <ting.ye@intel.com>
Signed-off-by: Siyuan Fu <siyuan.fu@intel.com>
Signed-off-by: Fan Wang <fan.wang@intel.com>
Signed-off-by: Abner Chang <abner.chang@hpe.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Andrew Fish <afish@apple.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Nickle Wang <nickle.wang@hpe.com>
Cc: Peter O'Hanley <peter.ohanley@hpe.com>
Acked-by: Ray Ni <ray.ni@intel.com>
EmulatorPkg/Application/RedfishPlatformConfig/RedfishPlatformConfig.c [new file with mode: 0644]
EmulatorPkg/Application/RedfishPlatformConfig/RedfishPlatformConfig.inf [new file with mode: 0644]

diff --git a/EmulatorPkg/Application/RedfishPlatformConfig/RedfishPlatformConfig.c b/EmulatorPkg/Application/RedfishPlatformConfig/RedfishPlatformConfig.c
new file mode 100644 (file)
index 0000000..89d4c76
--- /dev/null
@@ -0,0 +1,298 @@
+/** @file\r
+  The implementation for Redfish Platform Configuration application.\r
+\r
+  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
+  (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>\r
+\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include <Uefi.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/NetLib.h>\r
+#include <Library/UefiApplicationEntryPoint.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Protocol/ShellParameters.h>\r
+\r
+UINTN  Argc;\r
+CHAR16 **Argv;\r
+\r
+/**\r
+\r
+  This function parse application ARG.\r
+\r
+  @return Status\r
+**/\r
+EFI_STATUS\r
+GetArg (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS                    Status;\r
+  EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters;\r
+\r
+  Status = gBS->HandleProtocol (\r
+                  gImageHandle,\r
+                  &gEfiShellParametersProtocolGuid,\r
+                  (VOID**)&ShellParameters\r
+                  );\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Argc = ShellParameters->Argc;\r
+  Argv = ShellParameters->Argv;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+\r
+  This function print the help message.\r
+\r
+**/\r
+VOID\r
+PrintHelp (\r
+  VOID\r
+  )\r
+{\r
+  Print (L"\n");\r
+  Print (L"Format (Only Ipv4 Address is supported):\n");\r
+  Print (L"RedfishPlatformConfig.efi -s HostIpAddress HostIpMask RedfishServiceIpAddress RedfishServiceIpMask RedfishServiceIpPort\n");\r
+  Print (L"OR:\n");\r
+  Print (L"RedfishPlatformConfig.efi -a RedfishServiceIpAddress RedfishServiceIpMask RedfishServiceIpPort\n");\r
+  Print (L"\n");\r
+}\r
+\r
+/**\r
+  The user Entry Point for Application. The user code starts with this function\r
+  as the real entry point for the application.\r
+\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.\r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+\r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+UefiMain (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS    Status;\r
+  RETURN_STATUS ReturnStatus;\r
+\r
+  UINT8             HostIpAssignmentType;\r
+  EFI_IPv4_ADDRESS  HostIpAddress;\r
+  EFI_IPv4_ADDRESS  HostIpMask;\r
+  EFI_IPv4_ADDRESS  RedfishServiceIpAddress;\r
+  EFI_IPv4_ADDRESS  RedfishServiceIpMask;\r
+  UINTN             RedfishServiceIpPort;\r
+\r
+  Status = GetArg();\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Format is like :\r
+  // RedfishPlatformConfig.efi -s HostIpAddress HostIpMask RedfishServiceIpAddress RedfishServiceIpMask RedfishServiceIpPort\r
+  // RedfishPlatformConfig.efi -a RedfishServiceIpAddress RedfishServiceIpMask RedfishServiceIpPort\r
+  //\r
+  if (Argc != 7 && Argc != 5) {\r
+\r
+    PrintHelp();\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (StrCmp(Argv[1], L"-s") == 0) {\r
+\r
+    HostIpAssignmentType = 1;\r
+\r
+    Status = NetLibStrToIp4 (Argv[2], &HostIpAddress);\r
+    if (EFI_ERROR (Status)) {\r
+      PrintHelp();\r
+      return Status;\r
+    }\r
+    Status = NetLibStrToIp4 (Argv[3], &HostIpMask);\r
+    if (EFI_ERROR (Status)) {\r
+      PrintHelp();\r
+      return Status;\r
+    }\r
+    Status = NetLibStrToIp4 (Argv[4], &RedfishServiceIpAddress);\r
+    if (EFI_ERROR (Status)) {\r
+      PrintHelp();\r
+      return Status;\r
+    }\r
+    Status = NetLibStrToIp4 (Argv[5], &RedfishServiceIpMask);\r
+    if (EFI_ERROR (Status)) {\r
+      PrintHelp();\r
+      return Status;\r
+    }\r
+    ReturnStatus = StrDecimalToUintnS (Argv[6], NULL, &RedfishServiceIpPort);\r
+    if (RETURN_ERROR (ReturnStatus)) {\r
+      PrintHelp();\r
+      return Status;\r
+    }\r
+\r
+    Status = gRT->SetVariable (\r
+                    L"HostIpAssignmentType",\r
+                    &gEmuRedfishServiceGuid,\r
+                    EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
+                    sizeof (UINT8),\r
+                    &HostIpAssignmentType\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+    Status = gRT->SetVariable (\r
+                    L"HostIpAddress",\r
+                    &gEmuRedfishServiceGuid,\r
+                    EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
+                    sizeof (EFI_IPv4_ADDRESS),\r
+                    &HostIpAddress\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+    Status = gRT->SetVariable (\r
+                    L"HostIpMask",\r
+                    &gEmuRedfishServiceGuid,\r
+                    EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
+                    sizeof (EFI_IPv4_ADDRESS),\r
+                    &HostIpMask\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+    Status = gRT->SetVariable (\r
+                    L"RedfishServiceIpAddress",\r
+                    &gEmuRedfishServiceGuid,\r
+                    EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
+                    sizeof (EFI_IPv4_ADDRESS),\r
+                    &RedfishServiceIpAddress\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+    Status = gRT->SetVariable (\r
+                    L"RedfishServiceIpMask",\r
+                    &gEmuRedfishServiceGuid,\r
+                    EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
+                    sizeof (EFI_IPv4_ADDRESS),\r
+                    &RedfishServiceIpMask\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+    Status = gRT->SetVariable (\r
+                    L"RedfishServiceIpPort",\r
+                    &gEmuRedfishServiceGuid,\r
+                    EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
+                    sizeof (UINT16),\r
+                    &RedfishServiceIpPort\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+    Print (L"\n");\r
+    Print (L"HostIpAssignmentType is Static!\n");\r
+    Print (L"HostIpAddress: %s has been set Successfully!\n", Argv[2]);\r
+    Print (L"HostIpMask: %s has been set Successfully!\n", Argv[3]);\r
+    Print (L"RedfishServiceIpAddress: %s has been set Successfully!\n", Argv[4]);\r
+    Print (L"RedfishServiceIpMask: %s has been set Successfully!\n", Argv[5]);\r
+    Print (L"RedfishServiceIpPort: %s has been set Successfully!\n", Argv[6]);\r
+    Print (L"Please Restart!\n");\r
+\r
+  } else if (StrCmp(Argv[1], L"-a") == 0) {\r
+\r
+    HostIpAssignmentType = 3;\r
+\r
+    Status = NetLibStrToIp4 (Argv[2], &RedfishServiceIpAddress);\r
+    if (EFI_ERROR (Status)) {\r
+      PrintHelp();\r
+      return Status;\r
+    }\r
+    Status = NetLibStrToIp4 (Argv[3], &RedfishServiceIpMask);\r
+    if (EFI_ERROR (Status)) {\r
+      PrintHelp();\r
+      return Status;\r
+    }\r
+    ReturnStatus = StrDecimalToUintnS (Argv[4], NULL, &RedfishServiceIpPort);\r
+    if (RETURN_ERROR (ReturnStatus)) {\r
+      PrintHelp();\r
+      return Status;\r
+    }\r
+\r
+    Status = gRT->SetVariable (\r
+                    L"HostIpAssignmentType",\r
+                    &gEmuRedfishServiceGuid,\r
+                    EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
+                    sizeof (UINT8),\r
+                    &HostIpAssignmentType\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+    Status = gRT->SetVariable (\r
+                    L"RedfishServiceIpAddress",\r
+                    &gEmuRedfishServiceGuid,\r
+                    EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
+                    sizeof (EFI_IPv4_ADDRESS),\r
+                    &RedfishServiceIpAddress\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+    Status = gRT->SetVariable (\r
+                    L"RedfishServiceIpMask",\r
+                    &gEmuRedfishServiceGuid,\r
+                    EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
+                    sizeof (EFI_IPv4_ADDRESS),\r
+                    &RedfishServiceIpMask\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+    Status = gRT->SetVariable (\r
+                    L"RedfishServiceIpPort",\r
+                    &gEmuRedfishServiceGuid,\r
+                    EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
+                    sizeof (UINT16),\r
+                    &RedfishServiceIpPort\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+    Print (L"\n");\r
+    Print (L"HostIpAssignmentType is Auto!\n");\r
+    Print (L"RedfishServiceIpAddress: %s has been set Successfully!\n", Argv[2]);\r
+    Print (L"RedfishServiceIpMask: %s has been set Successfully!\n", Argv[3]);\r
+    Print (L"RedfishServiceIpPort: %s has been set Successfully!\n", Argv[4]);\r
+    Print (L"Please Restart!\n");\r
+  } else if (StrCmp(Argv[1], L"-h") == 0 || StrCmp(Argv[1], L"-help") == 0) {\r
+\r
+    PrintHelp();\r
+  } else {\r
+\r
+    PrintHelp();\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/EmulatorPkg/Application/RedfishPlatformConfig/RedfishPlatformConfig.inf b/EmulatorPkg/Application/RedfishPlatformConfig/RedfishPlatformConfig.inf
new file mode 100644 (file)
index 0000000..121d45a
--- /dev/null
@@ -0,0 +1,43 @@
+## @file\r
+#  Sample UEFI Application Reference EDKII Module.\r
+#\r
+#  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
+# (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>\r
+#\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x0001000b\r
+  BASE_NAME                      = RedfishPlatformConfig\r
+  FILE_GUID                      = C02B67BB-3D19-4ACC-A080-1BDB575F8F36\r
+  MODULE_TYPE                    = UEFI_APPLICATION\r
+  VERSION_STRING                 = 1.0\r
+  ENTRY_POINT                    = UefiMain\r
+\r
+[Sources]\r
+  RedfishPlatformConfig.c\r
+\r
+[Packages]\r
+  EmulatorPkg/EmulatorPkg.dec\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  NetworkPkg/NetworkPkg.dec\r
+  RedfishPkg/RedfishPkg.dec\r
+\r
+[LibraryClasses]\r
+  DebugLib\r
+  NetLib\r
+  UefiApplicationEntryPoint\r
+  UefiLib\r
+  UefiBootServicesTableLib\r
+  UefiRuntimeServicesTableLib\r
+\r
+[Protocols]\r
+  gEfiShellParametersProtocolGuid        ## CONSUMES\r
+  gEfiShellProtocolGuid                  ## CONSUMES\r
+\r
+[Guids]\r
+  gEmuRedfishServiceGuid\r