DpDynamicCommand.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /** @file
  2. Produce "dp" shell dynamic command.
  3. Copyright (c) 2017, Intel Corporation. All rights reserved. <BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "Dp.h"
  7. #include <Protocol/ShellDynamicCommand.h>
  8. /**
  9. This is the shell command handler function pointer callback type. This
  10. function handles the command when it is invoked in the shell.
  11. @param[in] This The instance of the EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL.
  12. @param[in] SystemTable The pointer to the system table.
  13. @param[in] ShellParameters The parameters associated with the command.
  14. @param[in] Shell The instance of the shell protocol used in the context
  15. of processing this command.
  16. @return EFI_SUCCESS the operation was successful
  17. @return other the operation failed.
  18. **/
  19. SHELL_STATUS
  20. EFIAPI
  21. DpCommandHandler (
  22. IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *This,
  23. IN EFI_SYSTEM_TABLE *SystemTable,
  24. IN EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,
  25. IN EFI_SHELL_PROTOCOL *Shell
  26. )
  27. {
  28. gEfiShellParametersProtocol = ShellParameters;
  29. gEfiShellProtocol = Shell;
  30. return RunDp (gImageHandle, SystemTable);
  31. }
  32. /**
  33. This is the command help handler function pointer callback type. This
  34. function is responsible for displaying help information for the associated
  35. command.
  36. @param[in] This The instance of the EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL.
  37. @param[in] Language The pointer to the language string to use.
  38. @return string Pool allocated help string, must be freed by caller
  39. **/
  40. CHAR16 *
  41. EFIAPI
  42. DpCommandGetHelp (
  43. IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *This,
  44. IN CONST CHAR8 *Language
  45. )
  46. {
  47. return HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_GET_HELP_DP), Language);
  48. }
  49. EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL mDpDynamicCommand = {
  50. L"dp",
  51. DpCommandHandler,
  52. DpCommandGetHelp
  53. };
  54. /**
  55. Entry point of Tftp Dynamic Command.
  56. Produce the DynamicCommand protocol to handle "tftp" command.
  57. @param ImageHandle The image handle of the process.
  58. @param SystemTable The EFI System Table pointer.
  59. @retval EFI_SUCCESS Tftp command is executed successfully.
  60. @retval EFI_ABORTED HII package was failed to initialize.
  61. @retval others Other errors when executing tftp command.
  62. **/
  63. EFI_STATUS
  64. EFIAPI
  65. DpCommandInitialize (
  66. IN EFI_HANDLE ImageHandle,
  67. IN EFI_SYSTEM_TABLE *SystemTable
  68. )
  69. {
  70. EFI_STATUS Status;
  71. mDpHiiHandle = InitializeHiiPackage (ImageHandle);
  72. if (mDpHiiHandle == NULL) {
  73. return EFI_ABORTED;
  74. }
  75. Status = gBS->InstallProtocolInterface (
  76. &ImageHandle,
  77. &gEfiShellDynamicCommandProtocolGuid,
  78. EFI_NATIVE_INTERFACE,
  79. &mDpDynamicCommand
  80. );
  81. ASSERT_EFI_ERROR (Status);
  82. return Status;
  83. }
  84. /**
  85. Tftp driver unload handler.
  86. @param ImageHandle The image handle of the process.
  87. @retval EFI_SUCCESS The image is unloaded.
  88. @retval Others Failed to unload the image.
  89. **/
  90. EFI_STATUS
  91. EFIAPI
  92. DpUnload (
  93. IN EFI_HANDLE ImageHandle
  94. )
  95. {
  96. EFI_STATUS Status;
  97. Status = gBS->UninstallProtocolInterface (
  98. ImageHandle,
  99. &gEfiShellDynamicCommandProtocolGuid,
  100. &mDpDynamicCommand
  101. );
  102. if (EFI_ERROR (Status)) {
  103. return Status;
  104. }
  105. HiiRemovePackages (mDpHiiHandle);
  106. return EFI_SUCCESS;
  107. }