2 The implementation for the 'http' Shell command.
4 Copyright (c) 2015, ARM Ltd. All rights reserved.<BR>
5 Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved. <BR>
6 (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
7 Copyright (c) 2020, Broadcom. All rights reserved. <BR>
9 SPDX-License-Identifier: BSD-2-Clause-Patent
14 #define IP4_CONFIG2_INTERFACE_INFO_NAME_LENGTH 32
17 // Constant strings and definitions related to the message
18 // indicating the amount of progress in the dowloading of a HTTP file.
22 // Number of steps in the progression slider.
24 #define HTTP_PROGRESS_SLIDER_STEPS \
25 ((sizeof (HTTP_PROGR_FRAME) / sizeof (CHAR16)) - 3)
28 // Size in number of characters plus one (final zero) of the message to
29 // indicate the progress of an HTTP download. The format is "[(progress slider:
30 // 40 characters)] (nb of KBytes downloaded so far: 7 characters) Kb". There
31 // are thus the number of characters in HTTP_PROGR_FRAME[] plus 11 characters
32 // (2 // spaces, "Kb" and seven characters for the number of KBytes).
34 #define HTTP_PROGRESS_MESSAGE_SIZE \
35 ((sizeof (HTTP_PROGR_FRAME) / sizeof (CHAR16)) + 12)
38 // Buffer size. Note that larger buffer does not mean better speed.
40 #define DEFAULT_BUF_SIZE SIZE_32KB
41 #define MAX_BUF_SIZE SIZE_4MB
43 #define MIN_PARAM_COUNT 2
44 #define MAX_PARAM_COUNT 4
45 #define NEED_REDIRECTION(Code) \
46 (((Code >= HTTP_STATUS_300_MULTIPLE_CHOICES) \
47 && (Code <= HTTP_STATUS_307_TEMPORARY_REDIRECT)) \
48 || (Code == HTTP_STATUS_308_PERMANENT_REDIRECT))
50 #define CLOSE_HTTP_HANDLE(ControllerHandle,HttpChildHandle) \
52 if (HttpChildHandle) { \
53 CloseProtocolAndDestroyServiceChild ( \
55 &gEfiHttpServiceBindingProtocolGuid, \
56 &gEfiHttpProtocolGuid, \
59 HttpChildHandle = NULL; \
70 #define USER_AGENT_HDR "Mozilla/5.0 (EDK2; Linux) Gecko/20100101 Firefox/79.0"
72 #define TIMER_MAX_TIMEOUT_S 10
75 // File name to use when Uri ends with "/".
77 #define DEFAULT_HTML_FILE L"index.html"
78 #define DEFAULT_HTTP_PROTO L"http"
81 // String to delete the HTTP progress message to be able to update it :
82 // (HTTP_PROGRESS_MESSAGE_SIZE-1) '\b'.
84 #define HTTP_PROGRESS_DEL \
85 L"\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\
86 \b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
88 #define HTTP_KB L"\b\b\b\b\b\b\b\b\b\b"
90 // Frame for the progression slider.
92 #define HTTP_PROGR_FRAME L"[ ]"
95 // Improve readability by using these macros.
97 #define PRINT_HII(token,...) \
99 -1, -1, NULL, token, mHttpHiiHandle, __VA_ARGS__)
101 #define PRINT_HII_APP(token,value) \
102 PRINT_HII (token, HTTP_APP_NAME, value)
105 // TimeBaseLib.h constants.
106 // These will be removed once the library gets fixed.
110 // Define EPOCH (1970-JANUARY-01) in the Julian Date representation.
112 #define EPOCH_JULIAN_DATE 2440588
117 #define SEC_PER_MIN ((UINTN) 60)
118 #define SEC_PER_HOUR ((UINTN) 3600)
119 #define SEC_PER_DAY ((UINTN) 86400)
122 // String descriptions for server errors.
124 STATIC CONST CHAR16
*ErrStatusDesc
[] =
128 L
"402 Payment required",
131 L
"405 Method not allowed",
132 L
"406 Not acceptable",
133 L
"407 Proxy authentication required",
134 L
"408 Request time out",
137 L
"411 Length required",
138 L
"412 Precondition failed",
139 L
"413 Request entity too large",
140 L
"414 Request URI to large",
141 L
"415 Unsupported media type",
142 L
"416 Requested range not satisfied",
143 L
"417 Expectation failed",
144 L
"500 Internal server error",
145 L
"501 Not implemented",
147 L
"503 Service unavailable",
148 L
"504 Gateway timeout",
149 L
"505 HTTP version not supported"
152 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
163 // Local File Handle.
165 STATIC SHELL_FILE_HANDLE mFileHandle
= NULL
;
168 // Path of the local file, Unicode encoded.
170 STATIC CONST CHAR16
*mLocalFilePath
;
172 STATIC BOOLEAN gRequestCallbackComplete
= FALSE
;
173 STATIC BOOLEAN gResponseCallbackComplete
= FALSE
;
175 STATIC BOOLEAN gHttpError
;
177 EFI_HII_HANDLE mHttpHiiHandle
;
180 // Functions declarations.
184 Check and convert the UINT16 option values of the 'http' command.
186 @param[in] ValueStr Value as an Unicode encoded string.
187 @param[out] Value UINT16 value.
189 @retval TRUE The value was returned.
190 @retval FALSE A parsing error occured.
195 IN CONST CHAR16
*ValueStr
,
200 Get the name of the NIC.
202 @param[in] ControllerHandle The network physical device handle.
203 @param[in] NicNumber The network physical device number.
204 @param[out] NicName Address where to store the NIC name.
205 The memory area has to be at least
206 IP4_CONFIG2_INTERFACE_INFO_NAME_LENGTH
209 @retval EFI_SUCCESS The name of the NIC was returned.
210 @retval Others The creation of the child for the Managed
211 Network Service failed or the opening of
212 the Managed Network Protocol failed or
213 the operational parameters for the
214 Managed Network Protocol could not be
220 IN EFI_HANDLE ControllerHandle
,
226 Create a child for the service identified by its service binding protocol GUID
227 and get from the child the interface of the protocol identified by its GUID.
229 @param[in] ControllerHandle Controller handle.
230 @param[in] ServiceBindingProtocolGuid Service binding protocol GUID of the
231 service to be created.
232 @param[in] ProtocolGuid GUID of the protocol to be open.
233 @param[out] ChildHandle Address where the handler of the
234 created child is returned. NULL is
235 returned in case of error.
236 @param[out] Interface Address where a pointer to the
237 protocol interface is returned in
240 @retval EFI_SUCCESS The child was created and the protocol opened.
241 @retval Others Either the creation of the child or the opening
242 of the protocol failed.
246 CreateServiceChildAndOpenProtocol (
247 IN EFI_HANDLE ControllerHandle
,
248 IN EFI_GUID
*ServiceBindingProtocolGuid
,
249 IN EFI_GUID
*ProtocolGuid
,
250 OUT EFI_HANDLE
*ChildHandle
,
255 Close the protocol identified by its GUID on the child handle of the service
256 identified by its service binding protocol GUID, then destroy the child
259 @param[in] ControllerHandle Controller handle.
260 @param[in] ServiceBindingProtocolGuid Service binding protocol GUID of the
261 service to be destroyed.
262 @param[in] ProtocolGuid GUID of the protocol to be closed.
263 @param[in] ChildHandle Handle of the child to be destroyed.
268 CloseProtocolAndDestroyServiceChild (
269 IN EFI_HANDLE ControllerHandle
,
270 IN EFI_GUID
*ServiceBindingProtocolGuid
,
271 IN EFI_GUID
*ProtocolGuid
,
272 IN EFI_HANDLE ChildHandle
276 Worker function that download the data of a file from an HTTP server given
277 the path of the file and its size.
279 @param[in] Context A pointer to the download context.
281 @retval EFI_SUCCESS The file was downloaded.
282 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
283 @retval Others The downloading of the file
284 from the server failed.
289 IN HTTP_DOWNLOAD_CONTEXT
*Context
,
290 IN EFI_HANDLE ControllerHandle
,
295 Cleans off leading and trailing spaces and tabs.
297 @param[in] String pointer to the string to trim them off.
299 @retval EFI_SUCCESS No errors.
300 @retval EFI_INVALID_PARAMETER String pointer is NULL.
311 ASSERT (String
!= NULL
);
313 if (String
== NULL
) {
314 return EFI_INVALID_PARAMETER
;
320 // Remove any whitespace at the beginning of the Str.
322 while (*Str
== L
' ' || *Str
== L
'\t') {
327 // Remove any whitespace at the end of the Str.
331 if (!Len
|| (Str
[Len
- 1] != L
' ' && Str
[Len
- 1] != '\t')) {
335 Str
[Len
- 1] = CHAR_NULL
;
338 CopyMem (String
, Str
, StrSize (Str
));
344 // Callbacks for request and response.
345 // We just acknowledge that operation has completed here.
349 Callback to set the request completion flag.
351 @param[in] Event: The event.
352 @param[in] Context: pointer to Notification Context.
362 gRequestCallbackComplete
= TRUE
;
366 Callback to set the response completion flag.
367 @param[in] Event: The event.
368 @param[in] Context: pointer to Notification Context.
378 gResponseCallbackComplete
= TRUE
;
382 // Set of functions from TimeBaseLib.
383 // This will be removed once TimeBaseLib is enabled for ShellPkg.
387 Calculate Epoch days.
389 @param[in] Time - a pointer to the EFI_TIME abstraction.
391 @retval Number of days elapsed since EPOCH_JULIAN_DAY.
403 // Absolute Julian Date representation of the supplied Time.
407 // Number of days elapsed since EPOCH_JULIAN_DAY.
411 a
= (14 - Time
->Month
) / 12 ;
412 y
= Time
->Year
+ 4800 - a
;
413 m
= Time
->Month
+ (12 * a
) - 3;
415 JulianDate
= Time
->Day
+ ((153 * m
+ 2) / 5) + (365 * y
) + (y
/ 4) -
416 (y
/ 100) + (y
/ 400) - 32045;
418 ASSERT (JulianDate
>= EPOCH_JULIAN_DATE
);
419 EpochDays
= JulianDate
- EPOCH_JULIAN_DATE
;
425 Converts EFI_TIME to Epoch seconds
426 (elapsed since 1970 JANUARY 01, 00:00:00 UTC).
428 @param[in] Time: a pointer to EFI_TIME abstraction.
438 // Number of days elapsed since EPOCH_JULIAN_DAY.
443 EpochDays
= EfiGetEpochDays (Time
);
445 EpochSeconds
= (EpochDays
* SEC_PER_DAY
) +
446 ((UINTN
)Time
->Hour
* SEC_PER_HOUR
) +
447 (Time
->Minute
* SEC_PER_MIN
) + Time
->Second
;
453 Function for 'http' command.
455 @param[in] ImageHandle Handle to the Image (NULL if Internal).
456 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
458 @retval SHELL_SUCCESS The 'http' command completed successfully.
459 @retval SHELL_ABORTED The Shell Library initialization failed.
460 @retval SHELL_INVALID_PARAMETER At least one of the command's arguments is
462 @retval SHELL_OUT_OF_RESOURCES A memory allocation failed.
463 @retval SHELL_NOT_FOUND Network Interface Card not found.
464 @retval SHELL_UNSUPPORTED Command was valid, but the server returned
465 a status code indicating some error.
466 Examine the file requested for error body.
470 IN EFI_HANDLE ImageHandle
,
471 IN EFI_SYSTEM_TABLE
*SystemTable
475 LIST_ENTRY
*CheckPackage
;
482 CHAR16
*ProblemParam
;
483 CHAR16 NicName
[IP4_CONFIG2_INTERFACE_INFO_NAME_LENGTH
];
486 CONST CHAR16
*UserNicName
;
487 CONST CHAR16
*ValueStr
;
488 CONST CHAR16
*RemoteFilePath
;
489 CONST CHAR16
*Walker
;
490 EFI_HTTPv4_ACCESS_POINT IPv4Node
;
492 EFI_HANDLE ControllerHandle
;
493 HTTP_DOWNLOAD_CONTEXT Context
;
497 RemoteFilePath
= NULL
;
502 // Initialize the Shell library (we must be in non-auto-init...).
507 Status
= ShellInitialize ();
508 if (EFI_ERROR (Status
)) {
509 ASSERT_EFI_ERROR (Status
);
510 return SHELL_ABORTED
;
513 ZeroMem (&Context
, sizeof (Context
));
516 // Parse the command line.
518 Status
= ShellCommandLineParse (
524 if (EFI_ERROR (Status
)) {
525 if ((Status
== EFI_VOLUME_CORRUPTED
)
526 && (ProblemParam
!= NULL
))
528 PRINT_HII_APP (STRING_TOKEN (STR_GEN_PROBLEM
), ProblemParam
);
529 SHELL_FREE_NON_NULL (ProblemParam
);
538 // Check the number of parameters.
540 Status
= EFI_INVALID_PARAMETER
;
542 ParamCount
= ShellCommandLineGetCount (CheckPackage
);
543 if (ParamCount
> MAX_PARAM_COUNT
) {
544 PRINT_HII_APP (STRING_TOKEN (STR_GEN_TOO_MANY
), NULL
);
548 if (ParamCount
< MIN_PARAM_COUNT
) {
549 PRINT_HII_APP (STRING_TOKEN (STR_GEN_TOO_FEW
), NULL
);
553 ZeroMem (&Context
.HttpConfigData
, sizeof (Context
.HttpConfigData
));
554 ZeroMem (&IPv4Node
, sizeof (IPv4Node
));
555 IPv4Node
.UseDefaultAddress
= TRUE
;
557 Context
.HttpConfigData
.HttpVersion
= HttpVersion11
;
558 Context
.HttpConfigData
.AccessPoint
.IPv4Node
= &IPv4Node
;
561 // Get the host address (not necessarily IPv4 format).
563 ValueStr
= ShellCommandLineGetRawValue (CheckPackage
, 1);
565 PRINT_HII_APP (STRING_TOKEN (STR_GEN_PARAM_INV
), ValueStr
);
569 TrimSpaces ((CHAR16
*)ValueStr
);
570 if (!StrStr (ValueStr
, L
"://")) {
571 Context
.ServerAddrAndProto
= StrnCatGrow (
572 &Context
.ServerAddrAndProto
,
575 StrLen (DEFAULT_HTTP_PROTO
)
577 Context
.ServerAddrAndProto
= StrnCatGrow (
578 &Context
.ServerAddrAndProto
,
583 VStr
= (CHAR16
*)ValueStr
;
585 VStr
= StrStr (ValueStr
, L
"://") + StrLen (L
"://");
588 for (Walker1
= VStr
; *Walker1
; Walker1
++) {
589 if (*Walker1
== L
'/') {
594 if (*Walker1
== L
'/') {
596 RemoteFilePath
= Walker1
;
599 Context
.ServerAddrAndProto
= StrnCatGrow (
600 &Context
.ServerAddrAndProto
,
603 StrLen (ValueStr
) - StrLen (Walker1
)
605 if (!Context
.ServerAddrAndProto
) {
606 Status
= EFI_OUT_OF_RESOURCES
;
611 if (!RemoteFilePath
) {
612 RemoteFilePath
= ShellCommandLineGetRawValue (CheckPackage
, 2);
613 if (!RemoteFilePath
) {
615 // If no path given, assume just "/".
617 RemoteFilePath
= L
"/";
621 TrimSpaces ((CHAR16
*)RemoteFilePath
);
623 if (ParamCount
== MAX_PARAM_COUNT
- ParamOffset
) {
624 mLocalFilePath
= ShellCommandLineGetRawValue (
626 MAX_PARAM_COUNT
- 1 - ParamOffset
629 Walker
= RemoteFilePath
+ StrLen (RemoteFilePath
);
630 while ((--Walker
) >= RemoteFilePath
) {
631 if ((*Walker
== L
'\\') ||
632 (*Walker
== L
'/' ) ) {
637 mLocalFilePath
= Walker
+ 1;
640 if (!StrLen (mLocalFilePath
)) {
641 mLocalFilePath
= DEFAULT_HTML_FILE
;
645 Context
.Uri
= StrnCatGrow (
649 StrLen (RemoteFilePath
)
652 Status
= EFI_OUT_OF_RESOURCES
;
657 // Get the name of the Network Interface Card to be used if any.
659 UserNicName
= ShellCommandLineGetValue (CheckPackage
, L
"-i");
661 ValueStr
= ShellCommandLineGetValue (CheckPackage
, L
"-l");
662 if ((ValueStr
!= NULL
)
663 && (!StringToUint16 (
665 &Context
.HttpConfigData
.AccessPoint
.IPv4Node
->LocalPort
672 Context
.BufferSize
= DEFAULT_BUF_SIZE
;
674 ValueStr
= ShellCommandLineGetValue (CheckPackage
, L
"-s");
675 if (ValueStr
!= NULL
) {
676 Context
.BufferSize
= ShellStrToUintn (ValueStr
);
677 if (!Context
.BufferSize
|| Context
.BufferSize
> MAX_BUF_SIZE
) {
678 PRINT_HII_APP (STRING_TOKEN (STR_GEN_PARAM_INV
), ValueStr
);
683 ValueStr
= ShellCommandLineGetValue (CheckPackage
, L
"-t");
684 if (ValueStr
!= NULL
) {
685 Context
.HttpConfigData
.TimeOutMillisec
= (UINT32
)ShellStrToUintn (ValueStr
);
689 // Locate all HTTP Service Binding protocols.
691 Status
= gBS
->LocateHandleBuffer (
693 &gEfiManagedNetworkServiceBindingProtocolGuid
,
698 if (EFI_ERROR (Status
) || (HandleCount
== 0)) {
699 PRINT_HII (STRING_TOKEN (STR_HTTP_ERR_NO_NIC
), NULL
);
700 if (!EFI_ERROR (Status
)) {
701 Status
= EFI_NOT_FOUND
;
707 Status
= EFI_NOT_FOUND
;
710 if (ShellCommandLineGetFlag (CheckPackage
, L
"-m")) {
711 Context
.Flags
|= DL_FLAG_TIME
;
714 if (ShellCommandLineGetFlag (CheckPackage
, L
"-k")) {
715 Context
.Flags
|= DL_FLAG_KEEP_BAD
;
719 (NicNumber
< HandleCount
) && (Status
!= EFI_SUCCESS
);
722 ControllerHandle
= Handles
[NicNumber
];
724 Status
= GetNicName (ControllerHandle
, NicNumber
, NicName
);
725 if (EFI_ERROR (Status
)) {
726 PRINT_HII (STRING_TOKEN (STR_HTTP_ERR_NIC_NAME
), NicNumber
, Status
);
730 if (UserNicName
!= NULL
) {
731 if (StrCmp (NicName
, UserNicName
) != 0) {
732 Status
= EFI_NOT_FOUND
;
739 Status
= DownloadFile (&Context
, ControllerHandle
, NicName
);
740 PRINT_HII (STRING_TOKEN (STR_GEN_CRLF
), NULL
);
742 if (EFI_ERROR (Status
)) {
744 STRING_TOKEN (STR_HTTP_ERR_DOWNLOAD
),
750 // If a user aborted the operation,
751 // do not try another controller.
753 if (Status
== EFI_ABORTED
) {
760 // This is not related to connection, so no need to repeat with
761 // another interface.
767 if ((UserNicName
!= NULL
) && (!NicFound
)) {
768 PRINT_HII (STRING_TOKEN (STR_HTTP_ERR_NIC_NOT_FOUND
), UserNicName
);
772 ShellCommandLineFreeVarList (CheckPackage
);
773 SHELL_FREE_NON_NULL (Handles
);
774 SHELL_FREE_NON_NULL (Context
.ServerAddrAndProto
);
775 SHELL_FREE_NON_NULL (Context
.Uri
);
777 return Status
& ~MAX_BIT
;
781 Check and convert the UINT16 option values of the 'http' command
783 @param[in] ValueStr Value as an Unicode encoded string
784 @param[out] Value UINT16 value
786 @retval TRUE The value was returned.
787 @retval FALSE A parsing error occured.
792 IN CONST CHAR16
*ValueStr
,
798 Val
= ShellStrToUintn (ValueStr
);
799 if (Val
> MAX_UINT16
) {
800 PRINT_HII_APP (STRING_TOKEN (STR_GEN_PARAM_INV
), ValueStr
);
804 *Value
= (UINT16
)Val
;
809 Get the name of the NIC.
811 @param[in] ControllerHandle The network physical device handle.
812 @param[in] NicNumber The network physical device number.
813 @param[out] NicName Address where to store the NIC name.
814 The memory area has to be at least
815 IP4_CONFIG2_INTERFACE_INFO_NAME_LENGTH
818 @retval EFI_SUCCESS The name of the NIC was returned.
819 @retval Others The creation of the child for the Managed
820 Network Service failed or the opening of
821 the Managed Network Protocol failed or
822 the operational parameters for the
823 Managed Network Protocol could not be
829 IN EFI_HANDLE ControllerHandle
,
835 EFI_HANDLE MnpHandle
;
836 EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
;
837 EFI_SIMPLE_NETWORK_MODE SnpMode
;
839 Status
= CreateServiceChildAndOpenProtocol (
841 &gEfiManagedNetworkServiceBindingProtocolGuid
,
842 &gEfiManagedNetworkProtocolGuid
,
846 if (EFI_ERROR (Status
)) {
850 Status
= Mnp
->GetModeData (Mnp
, NULL
, &SnpMode
);
851 if (EFI_ERROR (Status
) && (Status
!= EFI_NOT_STARTED
)) {
857 IP4_CONFIG2_INTERFACE_INFO_NAME_LENGTH
,
858 SnpMode
.IfType
== NET_IFTYPE_ETHERNET
? L
"eth%d" : L
"unk%d",
862 Status
= EFI_SUCCESS
;
866 if (MnpHandle
!= NULL
) {
867 CloseProtocolAndDestroyServiceChild (
869 &gEfiManagedNetworkServiceBindingProtocolGuid
,
870 &gEfiManagedNetworkProtocolGuid
,
879 Create a child for the service identified by its service binding protocol GUID
880 and get from the child the interface of the protocol identified by its GUID.
882 @param[in] ControllerHandle Controller handle.
883 @param[in] ServiceBindingProtocolGuid Service binding protocol GUID of the
884 service to be created.
885 @param[in] ProtocolGuid GUID of the protocol to be open.
886 @param[out] ChildHandle Address where the handler of the
887 created child is returned. NULL is
888 returned in case of error.
889 @param[out] Interface Address where a pointer to the
890 protocol interface is returned in
893 @retval EFI_SUCCESS The child was created and the protocol opened.
894 @retval Others Either the creation of the child or the opening
895 of the protocol failed.
899 CreateServiceChildAndOpenProtocol (
900 IN EFI_HANDLE ControllerHandle
,
901 IN EFI_GUID
*ServiceBindingProtocolGuid
,
902 IN EFI_GUID
*ProtocolGuid
,
903 OUT EFI_HANDLE
*ChildHandle
,
910 Status
= NetLibCreateServiceChild (
913 ServiceBindingProtocolGuid
,
916 if (!EFI_ERROR (Status
)) {
917 Status
= gBS
->OpenProtocol (
923 EFI_OPEN_PROTOCOL_GET_PROTOCOL
925 if (EFI_ERROR (Status
)) {
926 NetLibDestroyServiceChild (
929 ServiceBindingProtocolGuid
,
940 Close the protocol identified by its GUID on the child handle of the service
941 identified by its service binding protocol GUID, then destroy the child
944 @param[in] ControllerHandle Controller handle.
945 @param[in] ServiceBindingProtocolGuid Service binding protocol GUID of the
946 service to be destroyed.
947 @param[in] ProtocolGuid GUID of the protocol to be closed.
948 @param[in] ChildHandle Handle of the child to be destroyed.
952 CloseProtocolAndDestroyServiceChild (
953 IN EFI_HANDLE ControllerHandle
,
954 IN EFI_GUID
*ServiceBindingProtocolGuid
,
955 IN EFI_GUID
*ProtocolGuid
,
956 IN EFI_HANDLE ChildHandle
966 NetLibDestroyServiceChild (
969 ServiceBindingProtocolGuid
,
975 Wait until operation completes. Completion is indicated by
976 setting of an appropriate variable.
978 @param[in] Context A pointer to the HTTP download context.
979 @param[in, out] CallBackComplete A pointer to the callback completion
980 variable set by the callback.
982 @retval EFI_SUCCESS Callback signalled completion.
983 @retval EFI_TIMEOUT Timed out waiting for completion.
984 @retval Others Error waiting for completion.
989 IN HTTP_DOWNLOAD_CONTEXT
*Context
,
990 IN OUT BOOLEAN
*CallBackComplete
996 Status
= EFI_SUCCESS
;
999 // Use a timer to measure timeout. Cannot use Stall here!
1001 Status
= gBS
->CreateEvent (
1008 ASSERT_EFI_ERROR (Status
);
1010 if (!EFI_ERROR (Status
)) {
1011 Status
= gBS
->SetTimer (
1014 EFI_TIMER_PERIOD_SECONDS (TIMER_MAX_TIMEOUT_S
)
1017 ASSERT_EFI_ERROR (Status
);
1020 while (! *CallBackComplete
1021 && (!EFI_ERROR (Status
))
1022 && EFI_ERROR (gBS
->CheckEvent (WaitEvt
)))
1024 Status
= Context
->Http
->Poll (Context
->Http
);
1025 if (!Context
->ContentDownloaded
1026 && CallBackComplete
== &gResponseCallbackComplete
)
1029 // An HTTP server may just send a response redirection header.
1030 // In this case, don't wait for the event as
1031 // it might never happen and we waste 10s waiting.
1032 // Note that at this point Response may not has been populated,
1033 // so it needs to be checked first.
1035 if (Context
->ResponseToken
.Message
1036 && Context
->ResponseToken
.Message
->Data
.Response
1037 && (NEED_REDIRECTION (
1038 Context
->ResponseToken
.Message
->Data
.Response
->StatusCode
1047 gBS
->SetTimer (WaitEvt
, TimerCancel
, 0);
1048 gBS
->CloseEvent (WaitEvt
);
1050 if (*CallBackComplete
) {
1054 if (!EFI_ERROR (Status
)) {
1055 Status
= EFI_TIMEOUT
;
1062 Generate and send a request to the http server.
1064 @param[in] Context HTTP download context.
1065 @param[in] DownloadUrl Fully qualified URL to be downloaded.
1067 @retval EFI_SUCCESS Request has been sent successfully.
1068 @retval EFI_INVALID_PARAMETER Invalid URL.
1069 @retval EFI_OUT_OF_RESOURCES Out of memory.
1070 @retval EFI_DEVICE_ERROR If HTTPS is used, this probably
1071 means that TLS support either was not
1072 installed or not configured.
1073 @retval Others Error sending the request.
1078 IN HTTP_DOWNLOAD_CONTEXT
*Context
,
1079 IN CHAR16
*DownloadUrl
1082 EFI_HTTP_REQUEST_DATA RequestData
;
1083 EFI_HTTP_HEADER RequestHeader
[HdrMax
];
1084 EFI_HTTP_MESSAGE RequestMessage
;
1089 ZeroMem (&RequestData
, sizeof (RequestData
));
1090 ZeroMem (&RequestHeader
, sizeof (RequestHeader
));
1091 ZeroMem (&RequestMessage
, sizeof (RequestMessage
));
1092 ZeroMem (&Context
->RequestToken
, sizeof (Context
->RequestToken
));
1094 RequestHeader
[HdrHost
].FieldName
= "Host";
1095 RequestHeader
[HdrConn
].FieldName
= "Connection";
1096 RequestHeader
[HdrAgent
].FieldName
= "User-Agent";
1098 Host
= (CHAR16
*)Context
->ServerAddrAndProto
;
1099 while (*Host
!= CHAR_NULL
&& *Host
!= L
'/') {
1103 if (*Host
== CHAR_NULL
) {
1104 return EFI_INVALID_PARAMETER
;
1108 // Get the next slash.
1112 // And now the host name.
1116 StringSize
= StrLen (Host
) + 1;
1117 RequestHeader
[HdrHost
].FieldValue
= AllocatePool (StringSize
);
1118 if (!RequestHeader
[HdrHost
].FieldValue
) {
1119 return EFI_OUT_OF_RESOURCES
;
1122 UnicodeStrToAsciiStrS (
1124 RequestHeader
[HdrHost
].FieldValue
,
1128 RequestHeader
[HdrConn
].FieldValue
= "close";
1129 RequestHeader
[HdrAgent
].FieldValue
= USER_AGENT_HDR
;
1130 RequestMessage
.HeaderCount
= HdrMax
;
1132 RequestData
.Method
= HttpMethodGet
;
1133 RequestData
.Url
= DownloadUrl
;
1135 RequestMessage
.Data
.Request
= &RequestData
;
1136 RequestMessage
.Headers
= RequestHeader
;
1137 RequestMessage
.BodyLength
= 0;
1138 RequestMessage
.Body
= NULL
;
1139 Context
->RequestToken
.Event
= NULL
;
1142 // Completion callback event to be set when Request completes.
1144 Status
= gBS
->CreateEvent (
1149 &Context
->RequestToken
.Event
1151 ASSERT_EFI_ERROR (Status
);
1153 Context
->RequestToken
.Status
= EFI_SUCCESS
;
1154 Context
->RequestToken
.Message
= &RequestMessage
;
1155 gRequestCallbackComplete
= FALSE
;
1156 Status
= Context
->Http
->Request (Context
->Http
, &Context
->RequestToken
);
1157 if (EFI_ERROR (Status
)) {
1161 Status
= WaitForCompletion (Context
, &gRequestCallbackComplete
);
1162 if (EFI_ERROR (Status
)) {
1163 Context
->Http
->Cancel (Context
->Http
, &Context
->RequestToken
);
1167 SHELL_FREE_NON_NULL (RequestHeader
[HdrHost
].FieldValue
);
1168 if (Context
->RequestToken
.Event
) {
1169 gBS
->CloseEvent (Context
->RequestToken
.Event
);
1170 ZeroMem (&Context
->RequestToken
, sizeof (Context
->RequestToken
));
1177 Update the progress of a file download
1178 This procedure is called each time a new HTTP body portion is received.
1180 @param[in] Context HTTP download context.
1181 @param[in] DownloadLen Portion size, in bytes.
1182 @param[in] Buffer The pointer to the parsed buffer.
1184 @retval EFI_SUCCESS Portion saved.
1185 @retval Other Error saving the portion.
1191 IN HTTP_DOWNLOAD_CONTEXT
*Context
,
1192 IN UINTN DownloadLen
,
1196 CHAR16 Progress
[HTTP_PROGRESS_MESSAGE_SIZE
];
1206 ShellSetFilePosition (mFileHandle
, Context
->LastReportedNbOfBytes
);
1207 Status
= ShellWriteFile (mFileHandle
, &DownloadLen
, Buffer
);
1208 if (EFI_ERROR (Status
)) {
1209 if (Context
->ContentDownloaded
> 0) {
1210 PRINT_HII (STRING_TOKEN (STR_GEN_CRLF
), NULL
);
1213 PRINT_HII (STRING_TOKEN (STR_HTTP_ERR_WRITE
), mLocalFilePath
, Status
);
1217 if (Context
->ContentDownloaded
== 0) {
1218 ShellPrintEx (-1, -1, L
"%s 0 Kb", HTTP_PROGR_FRAME
);
1221 Context
->ContentDownloaded
+= DownloadLen
;
1222 NbOfKb
= Context
->ContentDownloaded
>> 10;
1224 Progress
[0] = L
'\0';
1225 if (Context
->ContentLength
) {
1226 LastStep
= (Context
->LastReportedNbOfBytes
* HTTP_PROGRESS_SLIDER_STEPS
) /
1227 Context
->ContentLength
;
1228 Step
= (Context
->ContentDownloaded
* HTTP_PROGRESS_SLIDER_STEPS
) /
1229 Context
->ContentLength
;
1232 Context
->LastReportedNbOfBytes
= Context
->ContentDownloaded
;
1234 if (Step
<= LastStep
) {
1235 if (!Context
->ContentLength
) {
1237 // Update downloaded size, there is no length info available.
1239 ShellPrintEx (-1, -1, L
"%s", HTTP_KB
);
1240 ShellPrintEx (-1, -1, L
"%7d Kb", NbOfKb
);
1246 ShellPrintEx (-1, -1, L
"%s", HTTP_PROGRESS_DEL
);
1248 Status
= StrCpyS (Progress
, HTTP_PROGRESS_MESSAGE_SIZE
, HTTP_PROGR_FRAME
);
1249 if (EFI_ERROR (Status
)) {
1253 for (Index
= 1; Index
< Step
; Index
++) {
1254 Progress
[Index
] = L
'=';
1258 Progress
[Step
] = L
'>';
1262 Progress
+ (sizeof (HTTP_PROGR_FRAME
) / sizeof (CHAR16
)) - 1,
1263 sizeof (Progress
) - sizeof (HTTP_PROGR_FRAME
),
1269 ShellPrintEx (-1, -1, L
"%s", Progress
);
1275 Replace the original Host and Uri with Host and Uri returned by the
1276 HTTP server in 'Location' header (redirection).
1278 @param[in] Location A pointer to the 'Location' string
1279 provided by HTTP server.
1280 @param[in] Context A pointer to HTTP download context.
1281 @param[in] DownloadUrl Fully qualified HTTP URL.
1283 @retval EFI_SUCCESS Host and Uri were successfully set.
1284 @retval EFI_OUT_OF_RESOURCES Error setting Host or Uri.
1290 IN HTTP_DOWNLOAD_CONTEXT
*Context
,
1291 IN CHAR16
*DownloadUrl
1303 BOOLEAN IsAbEmptyUrl
;
1307 IsAbEmptyUrl
= FALSE
;
1310 StringSize
= (AsciiStrSize (Location
) * sizeof (CHAR16
));
1311 Url
= AllocateZeroPool (StringSize
);
1313 return EFI_OUT_OF_RESOURCES
;
1316 Status
= AsciiStrToUnicodeStrS (
1317 (CONST CHAR8
*)Location
,
1322 if (EFI_ERROR (Status
)) {
1327 // If an HTTP server redirects to the same location more than once,
1328 // then stop attempts and tell it is not reachable.
1330 if (!StrCmp (Url
, DownloadUrl
)) {
1331 Status
= EFI_NO_MAPPING
;
1335 if (AsciiStrLen (Location
) > 2) {
1337 // Some servers return 'Location: //server/resource'
1339 IsAbEmptyUrl
= (Location
[0] == '/') && (Location
[1] == '/');
1349 if (AsciiStrStr (Location
, "://") || IsAbEmptyUrl
) {
1353 for (Step
= FirstStep
; Step
< 2; Step
++) {
1354 for (; *Walker
!= '/' && *Walker
!= '\0'; Walker
++) {
1367 Tmp
= AllocateZeroPool (Idx
+ 1);
1369 Status
= EFI_OUT_OF_RESOURCES
;
1373 CopyMem (Tmp
, Location
, Idx
);
1376 // Location now points to Uri
1379 StringSize
= (Idx
+ 1) * sizeof (CHAR16
);
1381 SHELL_FREE_NON_NULL (Context
->ServerAddrAndProto
);
1383 Temp
= AllocateZeroPool (StringSize
);
1385 Status
= EFI_OUT_OF_RESOURCES
;
1389 Status
= AsciiStrToUnicodeStrS (
1394 if (EFI_ERROR (Status
)) {
1395 SHELL_FREE_NON_NULL (Temp
);
1401 Context
->ServerAddrAndProto
= StrnCatGrow (
1402 &Context
->ServerAddrAndProto
,
1409 Context
->ServerAddrAndProto
= StrnCatGrow (
1410 &Context
->ServerAddrAndProto
,
1415 SHELL_FREE_NON_NULL (Temp
);
1416 if (!Context
->ServerAddrAndProto
) {
1417 Status
= EFI_OUT_OF_RESOURCES
;
1422 SHELL_FREE_NON_NULL (Context
->Uri
);
1424 StringSize
= AsciiStrSize (Location
) * sizeof (CHAR16
);
1425 Context
->Uri
= AllocateZeroPool (StringSize
);
1426 if (!Context
->Uri
) {
1427 Status
= EFI_OUT_OF_RESOURCES
;
1432 // Now make changes to the Uri part.
1434 Status
= AsciiStrToUnicodeStrS (
1435 (CONST CHAR8
*)Location
,
1440 SHELL_FREE_NON_NULL (Tmp
);
1441 SHELL_FREE_NON_NULL (Url
);
1447 Message parser callback.
1448 Save a portion of HTTP body.
1450 @param[in] EventType Type of event. Can be either
1451 OnComplete or OnData.
1452 @param[in] Data A pointer to the buffer with data.
1453 @param[in] Length Data length of this portion.
1454 @param[in] Context A pointer to the HTTP download context.
1456 @retval EFI_SUCCESS The portion was processed successfully.
1457 @retval Other Error returned by SavePortion.
1463 IN HTTP_BODY_PARSE_EVENT EventType
,
1470 || (EventType
== BodyParseEventOnComplete
)
1471 || (Context
== NULL
))
1476 return SavePortion (Context
, Length
, Data
);
1481 Get HTTP server response and collect the whole body as a file.
1482 Set appropriate status in Context (REQ_OK, REQ_REPEAT, REQ_ERROR).
1483 Note that even if HTTP server returns an error code, it might send
1484 the body as well. This body will be collected in the resultant file.
1486 @param[in] Context A pointer to the HTTP download context.
1487 @param[in] DownloadUrl A pointer to the fully qualified URL to download.
1489 @retval EFI_SUCCESS Valid file. Body successfully collected.
1490 @retval EFI_HTTP_ERROR Response is a valid HTTP response, but the
1492 indicated an error (HTTP code >= 400).
1493 Response body MAY contain full
1494 HTTP server response.
1495 @retval Others Error getting the reponse from the HTTP server.
1496 Response body is not collected.
1501 IN HTTP_DOWNLOAD_CONTEXT
*Context
,
1502 IN CHAR16
*DownloadUrl
1505 EFI_HTTP_RESPONSE_DATA ResponseData
;
1506 EFI_HTTP_MESSAGE ResponseMessage
;
1507 EFI_HTTP_HEADER
*Header
;
1513 UINTN ElapsedSeconds
;
1515 BOOLEAN CanMeasureTime
;
1517 ZeroMem (&ResponseData
, sizeof (ResponseData
));
1518 ZeroMem (&ResponseMessage
, sizeof (ResponseMessage
));
1519 ZeroMem (&Context
->ResponseToken
, sizeof (Context
->ResponseToken
));
1522 ResponseMessage
.Body
= Context
->Buffer
;
1523 Context
->ResponseToken
.Status
= EFI_SUCCESS
;
1524 Context
->ResponseToken
.Message
= &ResponseMessage
;
1525 Context
->ContentLength
= 0;
1526 Context
->Status
= REQ_OK
;
1528 ResponseData
.StatusCode
= HTTP_STATUS_UNSUPPORTED_STATUS
;
1529 ResponseMessage
.Data
.Response
= &ResponseData
;
1530 Context
->ResponseToken
.Event
= NULL
;
1531 CanMeasureTime
= FALSE
;
1532 if (Context
->Flags
& DL_FLAG_TIME
) {
1533 ZeroMem (&StartTime
, sizeof (StartTime
));
1534 CanMeasureTime
= !EFI_ERROR (gRT
->GetTime (&StartTime
, NULL
));
1538 SHELL_FREE_NON_NULL (ResponseMessage
.Headers
);
1539 ResponseMessage
.HeaderCount
= 0;
1540 gResponseCallbackComplete
= FALSE
;
1541 ResponseMessage
.BodyLength
= Context
->BufferSize
;
1543 if (ShellGetExecutionBreakFlag ()) {
1544 Status
= EFI_ABORTED
;
1548 if (!Context
->ContentDownloaded
&& !Context
->ResponseToken
.Event
) {
1549 Status
= gBS
->CreateEvent (
1554 &Context
->ResponseToken
.Event
1556 ASSERT_EFI_ERROR (Status
);
1558 ResponseMessage
.Data
.Response
= NULL
;
1561 if (EFI_ERROR (Status
)) {
1565 Status
= Context
->Http
->Response (Context
->Http
, &Context
->ResponseToken
);
1566 if (EFI_ERROR (Status
)) {
1570 Status
= WaitForCompletion (Context
, &gResponseCallbackComplete
);
1571 if (EFI_ERROR (Status
) && ResponseMessage
.HeaderCount
) {
1572 Status
= EFI_SUCCESS
;
1575 if (EFI_ERROR (Status
)) {
1576 Context
->Http
->Cancel (Context
->Http
, &Context
->ResponseToken
);
1580 if (!Context
->ContentDownloaded
) {
1581 if (NEED_REDIRECTION (ResponseData
.StatusCode
)) {
1583 // Need to repeat the request with new Location (server redirected).
1585 Context
->Status
= REQ_NEED_REPEAT
;
1587 Header
= HttpFindHeader (
1588 ResponseMessage
.HeaderCount
,
1589 ResponseMessage
.Headers
,
1593 Status
= SetHostURI (Header
->FieldValue
, Context
, DownloadUrl
);
1594 if (Status
== EFI_NO_MAPPING
) {
1596 STRING_TOKEN (STR_HTTP_ERR_STATUSCODE
),
1597 Context
->ServerAddrAndProto
,
1598 L
"Recursive HTTP server relocation",
1604 // Bad reply from the server. Server must specify the location.
1605 // Indicate that resource was not found, and no body collected.
1607 Status
= EFI_NOT_FOUND
;
1610 Context
->Http
->Cancel (Context
->Http
, &Context
->ResponseToken
);
1615 // Init message-body parser by header information.
1618 Status
= HttpInitMsgParser (
1619 ResponseMessage
.Data
.Request
->Method
,
1620 ResponseData
.StatusCode
,
1621 ResponseMessage
.HeaderCount
,
1622 ResponseMessage
.Headers
,
1627 if (EFI_ERROR (Status
)) {
1633 // If it is a trunked message, rely on the parser.
1635 Header
= HttpFindHeader (
1636 ResponseMessage
.HeaderCount
,
1637 ResponseMessage
.Headers
,
1640 IsTrunked
= (Header
&& !AsciiStrCmp (Header
->FieldValue
, "chunked"));
1642 HttpGetEntityLength (MsgParser
, &Context
->ContentLength
);
1644 if (ResponseData
.StatusCode
>= HTTP_STATUS_400_BAD_REQUEST
1645 && (ResponseData
.StatusCode
!= HTTP_STATUS_308_PERMANENT_REDIRECT
))
1648 // Server reported an error via Response code.
1649 // Collect the body if any.
1654 Desc
= ErrStatusDesc
[ResponseData
.StatusCode
-
1655 HTTP_STATUS_400_BAD_REQUEST
];
1657 STRING_TOKEN (STR_HTTP_ERR_STATUSCODE
),
1658 Context
->ServerAddrAndProto
,
1664 // This gives an RFC HTTP error.
1666 Context
->Status
= ShellStrToUintn (Desc
);
1667 Status
= ENCODE_ERROR (Context
->Status
);
1673 // Do NOT try to parse an empty body.
1675 if (ResponseMessage
.BodyLength
|| IsTrunked
) {
1676 Status
= HttpParseMessageBody (
1678 ResponseMessage
.BodyLength
,
1679 ResponseMessage
.Body
1682 } while (!HttpIsMessageComplete (MsgParser
)
1683 && !EFI_ERROR (Status
)
1684 && ResponseMessage
.BodyLength
);
1686 if (Context
->Status
!= REQ_NEED_REPEAT
1687 && Status
== EFI_SUCCESS
1690 if (!EFI_ERROR (gRT
->GetTime (&EndTime
, NULL
))) {
1691 ElapsedSeconds
= EfiTimeToEpoch (&EndTime
) - EfiTimeToEpoch (&StartTime
);
1694 ElapsedSeconds
? " " : " < ",
1695 ElapsedSeconds
> 1 ? (UINT64
)ElapsedSeconds
: 1
1700 SHELL_FREE_NON_NULL (MsgParser
);
1701 if (Context
->ResponseToken
.Event
) {
1702 gBS
->CloseEvent (Context
->ResponseToken
.Event
);
1703 ZeroMem (&Context
->ResponseToken
, sizeof (Context
->ResponseToken
));
1710 Worker function that downloads the data of a file from an HTTP server given
1711 the path of the file and its size.
1713 @param[in] Context A pointer to the HTTP download context.
1714 @param[in] ControllerHandle The handle of the network interface controller
1715 @param[in] NicName NIC name
1717 @retval EFI_SUCCESS The file was downloaded.
1718 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
1719 #return EFI_HTTP_ERROR The server returned a valid HTTP error.
1720 Examine the mLocalFilePath file
1722 @retval Others The downloading of the file from the server
1728 IN HTTP_DOWNLOAD_CONTEXT
*Context
,
1729 IN EFI_HANDLE ControllerHandle
,
1734 CHAR16
*DownloadUrl
;
1736 EFI_HANDLE HttpChildHandle
;
1739 if (Context
== NULL
) {
1740 return EFI_INVALID_PARAMETER
;
1744 HttpChildHandle
= NULL
;
1746 Context
->Buffer
= AllocatePool (Context
->BufferSize
);
1747 if (Context
->Buffer
== NULL
) {
1748 Status
= EFI_OUT_OF_RESOURCES
;
1755 if (!EFI_ERROR (ShellFileExists (mLocalFilePath
))) {
1756 ShellDeleteFileByName (mLocalFilePath
);
1759 Status
= ShellOpenFileByName (
1762 EFI_FILE_MODE_CREATE
|
1763 EFI_FILE_MODE_WRITE
|
1767 if (EFI_ERROR (Status
)) {
1768 PRINT_HII_APP (STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL
), mLocalFilePath
);
1773 SHELL_FREE_NON_NULL (DownloadUrl
);
1775 CLOSE_HTTP_HANDLE (ControllerHandle
, HttpChildHandle
);
1777 Status
= CreateServiceChildAndOpenProtocol (
1779 &gEfiHttpServiceBindingProtocolGuid
,
1780 &gEfiHttpProtocolGuid
,
1782 (VOID
**)&Context
->Http
1785 if (EFI_ERROR (Status
)) {
1786 PRINT_HII (STRING_TOKEN (STR_HTTP_ERR_OPEN_PROTOCOL
), NicName
, Status
);
1790 Status
= Context
->Http
->Configure (Context
->Http
, &Context
->HttpConfigData
);
1791 if (EFI_ERROR (Status
)) {
1792 PRINT_HII (STRING_TOKEN (STR_HTTP_ERR_CONFIGURE
), NicName
, Status
);
1797 DownloadUrl
= StrnCatGrow (
1800 Context
->ServerAddrAndProto
,
1801 StrLen (Context
->ServerAddrAndProto
)
1803 if (Context
->Uri
[0] != L
'/') {
1804 DownloadUrl
= StrnCatGrow (
1808 StrLen (Context
->ServerAddrAndProto
)
1812 DownloadUrl
= StrnCatGrow (
1816 StrLen (Context
->Uri
));
1818 PRINT_HII (STRING_TOKEN (STR_HTTP_DOWNLOADING
), DownloadUrl
);
1820 Status
= SendRequest (Context
, DownloadUrl
);
1825 Status
= GetResponse (Context
, DownloadUrl
);
1831 } while (Context
->Status
== REQ_NEED_REPEAT
);
1833 if (Context
->Status
) {
1834 Status
= ENCODE_ERROR (Context
->Status
);
1841 if (mFileHandle
!= NULL
) {
1842 if (EFI_ERROR (Status
) && !(Context
->Flags
& DL_FLAG_KEEP_BAD
)) {
1843 ShellDeleteFile (&mFileHandle
);
1845 ShellCloseFile (&mFileHandle
);
1849 SHELL_FREE_NON_NULL (DownloadUrl
);
1850 SHELL_FREE_NON_NULL (Context
->Buffer
);
1852 CLOSE_HTTP_HANDLE (ControllerHandle
, HttpChildHandle
);
1858 Retrive HII package list from ImageHandle and publish to HII database.
1860 @param[in] ImageHandle The image handle of the process.
1865 InitializeHiiPackage (
1866 IN EFI_HANDLE ImageHandle
1870 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
1871 EFI_HII_HANDLE HiiHandle
;
1874 // Retrieve HII package list from ImageHandle.
1876 Status
= gBS
->OpenProtocol (
1878 &gEfiHiiPackageListProtocolGuid
,
1879 (VOID
**)&PackageList
,
1882 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1884 ASSERT_EFI_ERROR (Status
);
1885 if (EFI_ERROR (Status
)) {
1890 // Publish HII package list to HII Database.
1892 Status
= gHiiDatabase
->NewPackageList (
1898 ASSERT_EFI_ERROR (Status
);
1899 if (EFI_ERROR (Status
)) {