2010-11-12 20:40:21 +01:00
|
|
|
/** @file
|
|
|
|
Main file for connect shell Driver1 function.
|
|
|
|
|
2015-02-04 23:25:01 +01:00
|
|
|
(C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
|
2016-04-18 09:59:58 +02:00
|
|
|
Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
|
2010-11-12 20:40:21 +01:00
|
|
|
This program and the accompanying materials
|
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include "UefiShellDriver1CommandsLib.h"
|
|
|
|
|
2014-05-14 03:47:02 +02:00
|
|
|
/**
|
|
|
|
Create all handles associate with every device path node.
|
|
|
|
|
|
|
|
@param DevicePathToConnect The device path which will be connected.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS All handles associate with every device path node
|
|
|
|
have been created.
|
|
|
|
@retval EFI_INVALID_PARAMETER DevicePathToConnect is NULL.
|
|
|
|
@retval EFI_NOT_FOUND Create the handle associate with one device path
|
|
|
|
node failed
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
ShellConnectDevicePath (
|
|
|
|
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathToConnect
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_HANDLE Handle;
|
2014-05-19 02:39:48 +02:00
|
|
|
EFI_HANDLE PreviousHandle;
|
2014-05-14 03:47:02 +02:00
|
|
|
|
|
|
|
if (DevicePathToConnect == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
2014-05-19 02:39:48 +02:00
|
|
|
|
|
|
|
PreviousHandle = NULL;
|
|
|
|
do{
|
2014-05-14 03:47:02 +02:00
|
|
|
RemainingDevicePath = DevicePathToConnect;
|
|
|
|
Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &RemainingDevicePath, &Handle);
|
2014-05-19 02:39:48 +02:00
|
|
|
|
2014-05-14 03:47:02 +02:00
|
|
|
if (!EFI_ERROR (Status) && (Handle != NULL)) {
|
2014-05-19 02:39:48 +02:00
|
|
|
if (PreviousHandle == Handle) {
|
|
|
|
Status = EFI_NOT_FOUND;
|
|
|
|
} else {
|
|
|
|
PreviousHandle = Handle;
|
|
|
|
Status = gBS->ConnectController (Handle, NULL, RemainingDevicePath, FALSE);
|
|
|
|
}
|
2014-05-14 03:47:02 +02:00
|
|
|
}
|
2014-05-19 02:39:48 +02:00
|
|
|
|
|
|
|
} while (!EFI_ERROR (Status) && !IsDevicePathEnd (RemainingDevicePath) );
|
|
|
|
|
2014-05-14 03:47:02 +02:00
|
|
|
return Status;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Connect drivers for PCI root bridge.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS Connect drivers successfully.
|
|
|
|
@retval EFI_NOT_FOUND Cannot find PCI root bridge device.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
ShellConnectPciRootBridge (
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINTN RootBridgeHandleCount;
|
|
|
|
EFI_HANDLE *RootBridgeHandleBuffer;
|
|
|
|
UINTN RootBridgeIndex;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
RootBridgeHandleCount = 0;
|
|
|
|
|
|
|
|
Status = gBS->LocateHandleBuffer (
|
|
|
|
ByProtocol,
|
|
|
|
&gEfiPciRootBridgeIoProtocolGuid,
|
|
|
|
NULL,
|
|
|
|
&RootBridgeHandleCount,
|
|
|
|
&RootBridgeHandleBuffer
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (RootBridgeIndex = 0; RootBridgeIndex < RootBridgeHandleCount; RootBridgeIndex++) {
|
|
|
|
gBS->ConnectController (RootBridgeHandleBuffer[RootBridgeIndex], NULL, NULL, FALSE);
|
|
|
|
}
|
2014-12-04 02:18:04 +01:00
|
|
|
|
|
|
|
FreePool (RootBridgeHandleBuffer);
|
2014-05-14 03:47:02 +02:00
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-12 20:40:21 +01:00
|
|
|
/**
|
2011-03-25 22:13:43 +01:00
|
|
|
Connect controller(s) and driver(s).
|
|
|
|
|
2014-05-14 03:47:02 +02:00
|
|
|
@param[in] ControllerHandle The handle to the controller. Should have driver binding on it.
|
|
|
|
@param[in] DriverHandle The handle to the driver. Should have driver binding.
|
2011-03-25 22:13:43 +01:00
|
|
|
@param[in] Recursive TRUE to connect recursively, FALSE otherwise.
|
|
|
|
@param[in] Output TRUE to have info on the screen, FALSE otherwise.
|
|
|
|
@param[in] AlwaysOutput Override Output for errors.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The operation was successful.
|
2010-11-12 20:40:21 +01:00
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
ConnectControllers (
|
|
|
|
IN CONST EFI_HANDLE ControllerHandle OPTIONAL,
|
|
|
|
IN CONST EFI_HANDLE DriverHandle OPTIONAL,
|
|
|
|
IN CONST BOOLEAN Recursive,
|
|
|
|
IN CONST BOOLEAN Output,
|
|
|
|
IN CONST BOOLEAN AlwaysOutput
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_STATUS Status2;
|
|
|
|
EFI_HANDLE *ControllerHandleList;
|
|
|
|
EFI_HANDLE *DriverHandleList;
|
|
|
|
EFI_HANDLE *HandleWalker;
|
|
|
|
|
|
|
|
ControllerHandleList = NULL;
|
|
|
|
Status = EFI_NOT_FOUND;
|
|
|
|
Status2 = EFI_NOT_FOUND;
|
|
|
|
|
|
|
|
//
|
|
|
|
// If we have a single handle to connect make that a 'list'
|
|
|
|
//
|
|
|
|
if (DriverHandle == NULL) {
|
|
|
|
DriverHandleList = NULL;
|
|
|
|
} else {
|
2011-03-25 22:13:43 +01:00
|
|
|
DriverHandleList = AllocateZeroPool(2*sizeof(EFI_HANDLE));
|
2010-11-12 20:40:21 +01:00
|
|
|
if (DriverHandleList == NULL) {
|
|
|
|
return (EFI_OUT_OF_RESOURCES);
|
|
|
|
}
|
|
|
|
DriverHandleList[0] = DriverHandle;
|
|
|
|
DriverHandleList[1] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// do we connect all controllers (with a loop) or a single one...
|
|
|
|
// This is where we call the gBS->ConnectController function.
|
|
|
|
//
|
|
|
|
if (ControllerHandle == NULL) {
|
|
|
|
ControllerHandleList = GetHandleListByProtocol(&gEfiDevicePathProtocolGuid);
|
|
|
|
for (HandleWalker = ControllerHandleList
|
|
|
|
; HandleWalker != NULL && *HandleWalker != NULL
|
|
|
|
; HandleWalker++
|
|
|
|
){
|
|
|
|
Status = gBS->ConnectController(*HandleWalker, DriverHandleList, NULL, Recursive);
|
|
|
|
if (!EFI_ERROR(Status)) {
|
|
|
|
Status2 = EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
if ((Output && !EFI_ERROR(Status)) || AlwaysOutput) {
|
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_HANDLE_RESULT), gShellDriver1HiiHandle, L"Connect", ConvertHandleToHandleIndex(*HandleWalker), Status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Status = gBS->ConnectController(ControllerHandle, DriverHandleList, NULL, Recursive);
|
|
|
|
if (!EFI_ERROR(Status)) {
|
|
|
|
Status2 = EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
if ((Output && !EFI_ERROR(Status)) || AlwaysOutput) {
|
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_HANDLE_RESULT), gShellDriver1HiiHandle, L"Connect", ConvertHandleToHandleIndex(ControllerHandle), Status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Free any memory we allocated.
|
|
|
|
//
|
|
|
|
if (ControllerHandleList != NULL) {
|
|
|
|
FreePool(ControllerHandleList);
|
|
|
|
}
|
|
|
|
if (DriverHandleList != NULL) {
|
|
|
|
FreePool(DriverHandleList);
|
|
|
|
}
|
|
|
|
return (Status2);
|
|
|
|
}
|
|
|
|
|
2011-03-25 22:13:43 +01:00
|
|
|
/**
|
|
|
|
Do a connect from an EFI variable via it's key name.
|
|
|
|
|
|
|
|
@param[in] Key The name of the EFI Variable.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The operation was successful.
|
|
|
|
**/
|
2010-11-12 20:40:21 +01:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
2014-12-04 02:18:04 +01:00
|
|
|
ShellConnectFromDevPaths (
|
2010-11-12 20:40:21 +01:00
|
|
|
IN CONST CHAR16 *Key
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_DEVICE_PATH_PROTOCOL *DevPath;
|
2014-05-19 02:39:48 +02:00
|
|
|
EFI_DEVICE_PATH_PROTOCOL *CopyOfDevPath;
|
|
|
|
EFI_DEVICE_PATH_PROTOCOL *Instance;
|
|
|
|
EFI_DEVICE_PATH_PROTOCOL *Next;
|
2010-11-12 20:40:21 +01:00
|
|
|
UINTN Length;
|
2014-05-14 03:47:02 +02:00
|
|
|
UINTN Index;
|
|
|
|
UINTN HandleArrayCount;
|
2014-05-19 02:39:48 +02:00
|
|
|
UINTN Size;
|
2014-05-14 03:47:02 +02:00
|
|
|
EFI_HANDLE *HandleArray;
|
2010-11-12 20:40:21 +01:00
|
|
|
EFI_STATUS Status;
|
2014-05-14 03:47:02 +02:00
|
|
|
BOOLEAN AtLeastOneConnected;
|
|
|
|
EFI_PCI_IO_PROTOCOL *PciIo;
|
|
|
|
UINT8 Class[3];
|
|
|
|
|
2010-11-12 20:40:21 +01:00
|
|
|
DevPath = NULL;
|
|
|
|
Length = 0;
|
2014-05-14 03:47:02 +02:00
|
|
|
AtLeastOneConnected = FALSE;
|
2014-05-19 02:39:48 +02:00
|
|
|
|
2010-11-12 20:40:21 +01:00
|
|
|
//
|
|
|
|
// Get the DevicePath buffer from the variable...
|
|
|
|
//
|
|
|
|
Status = gRT->GetVariable((CHAR16*)Key, (EFI_GUID*)&gEfiGlobalVariableGuid, NULL, &Length, DevPath);
|
|
|
|
if (Status == EFI_BUFFER_TOO_SMALL) {
|
2011-03-25 22:13:43 +01:00
|
|
|
DevPath = AllocateZeroPool(Length);
|
2014-05-14 03:47:02 +02:00
|
|
|
if (DevPath == NULL) {
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
2010-11-12 20:40:21 +01:00
|
|
|
Status = gRT->GetVariable((CHAR16*)Key, (EFI_GUID*)&gEfiGlobalVariableGuid, NULL, &Length, DevPath);
|
2014-05-19 02:39:48 +02:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
if (DevPath != NULL) {
|
|
|
|
FreePool (DevPath);
|
|
|
|
}
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
} else if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
2010-11-12 20:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Status = EFI_NOT_FOUND;
|
2014-05-19 02:39:48 +02:00
|
|
|
|
|
|
|
CopyOfDevPath = DevPath;
|
2010-11-12 20:40:21 +01:00
|
|
|
//
|
|
|
|
// walk the list of devices and connect them
|
|
|
|
//
|
2014-05-19 02:39:48 +02:00
|
|
|
do {
|
|
|
|
//
|
|
|
|
// Check every instance of the console variable
|
|
|
|
//
|
|
|
|
Instance = GetNextDevicePathInstance (&CopyOfDevPath, &Size);
|
|
|
|
if (Instance == NULL) {
|
|
|
|
if (DevPath != NULL) {
|
|
|
|
FreePool (DevPath);
|
|
|
|
}
|
|
|
|
return EFI_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
Next = Instance;
|
|
|
|
while (!IsDevicePathEndType (Next)) {
|
|
|
|
Next = NextDevicePathNode (Next);
|
|
|
|
}
|
|
|
|
|
|
|
|
SetDevicePathEndNode (Next);
|
2010-11-12 20:40:21 +01:00
|
|
|
//
|
2014-05-14 03:47:02 +02:00
|
|
|
// connect short form device path
|
2010-11-12 20:40:21 +01:00
|
|
|
//
|
2014-05-19 02:39:48 +02:00
|
|
|
if ((DevicePathType (Instance) == MESSAGING_DEVICE_PATH) &&
|
|
|
|
((DevicePathSubType (Instance) == MSG_USB_CLASS_DP)
|
|
|
|
|| (DevicePathSubType (Instance) == MSG_USB_WWID_DP)
|
2014-05-14 03:47:02 +02:00
|
|
|
)) {
|
|
|
|
|
|
|
|
Status = ShellConnectPciRootBridge ();
|
|
|
|
if (EFI_ERROR(Status)) {
|
2014-05-19 02:39:48 +02:00
|
|
|
FreePool(Instance);
|
2014-05-14 03:47:02 +02:00
|
|
|
FreePool(DevPath);
|
|
|
|
return Status;
|
2010-11-12 20:40:21 +01:00
|
|
|
}
|
2014-05-14 03:47:02 +02:00
|
|
|
|
|
|
|
Status = gBS->LocateHandleBuffer (
|
|
|
|
ByProtocol,
|
|
|
|
&gEfiPciIoProtocolGuid,
|
|
|
|
NULL,
|
|
|
|
&HandleArrayCount,
|
|
|
|
&HandleArray
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
for (Index = 0; Index < HandleArrayCount; Index++) {
|
|
|
|
Status = gBS->HandleProtocol (
|
|
|
|
HandleArray[Index],
|
|
|
|
&gEfiPciIoProtocolGuid,
|
|
|
|
(VOID **)&PciIo
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint8, 0x09, 3, &Class);
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
if ((PCI_CLASS_SERIAL == Class[2]) &&
|
|
|
|
(PCI_CLASS_SERIAL_USB == Class[1])) {
|
|
|
|
Status = gBS->ConnectController (
|
|
|
|
HandleArray[Index],
|
|
|
|
NULL,
|
|
|
|
Instance,
|
|
|
|
FALSE
|
|
|
|
);
|
|
|
|
if (!EFI_ERROR(Status)) {
|
|
|
|
AtLeastOneConnected = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HandleArray != NULL) {
|
|
|
|
FreePool (HandleArray);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// connect the entire device path
|
|
|
|
//
|
|
|
|
Status = ShellConnectDevicePath (Instance);
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
AtLeastOneConnected = TRUE;
|
|
|
|
}
|
2010-11-12 20:40:21 +01:00
|
|
|
}
|
2014-05-19 02:39:48 +02:00
|
|
|
FreePool (Instance);
|
2014-05-14 03:47:02 +02:00
|
|
|
|
2014-05-19 02:39:48 +02:00
|
|
|
} while (CopyOfDevPath != NULL);
|
2014-05-14 03:47:02 +02:00
|
|
|
|
2010-11-12 20:40:21 +01:00
|
|
|
if (DevPath != NULL) {
|
|
|
|
FreePool(DevPath);
|
|
|
|
}
|
2014-05-14 03:47:02 +02:00
|
|
|
|
|
|
|
if (AtLeastOneConnected) {
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
} else {
|
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2010-11-12 20:40:21 +01:00
|
|
|
}
|
|
|
|
|
2011-03-25 22:13:43 +01:00
|
|
|
/**
|
|
|
|
Convert the handle identifiers from strings and then connect them.
|
|
|
|
|
|
|
|
One of them should have driver binding and either can be NULL.
|
|
|
|
|
|
|
|
@param[in] Handle1 The first handle.
|
|
|
|
@param[in] Handle2 The second handle.
|
|
|
|
@param[in] Recursive TRUE to do connect recursively. FALSE otherwise.
|
|
|
|
@param[in] Output TRUE to have output to screen. FALSE otherwise.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The operation was successful.
|
|
|
|
**/
|
2010-11-12 20:40:21 +01:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
ConvertAndConnectControllers (
|
2011-03-25 22:13:43 +01:00
|
|
|
IN EFI_HANDLE *Handle1 OPTIONAL,
|
|
|
|
IN EFI_HANDLE *Handle2 OPTIONAL,
|
2010-11-12 20:40:21 +01:00
|
|
|
IN CONST BOOLEAN Recursive,
|
|
|
|
IN CONST BOOLEAN Output
|
|
|
|
)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// if only one is NULL verify it's the proper one...
|
|
|
|
//
|
|
|
|
if ( (Handle1 == NULL && Handle2 != NULL)
|
|
|
|
|| (Handle1 != NULL && Handle2 == NULL)
|
|
|
|
){
|
|
|
|
//
|
|
|
|
// Figure out which one should be NULL and move the handle to the right place.
|
|
|
|
// If Handle1 is NULL then test Handle2 and vise versa.
|
|
|
|
// The one that DOES has driver binding must be Handle2
|
|
|
|
//
|
|
|
|
if (Handle1 == NULL) {
|
|
|
|
if (EFI_ERROR(gBS->OpenProtocol(Handle2, &gEfiDriverBindingProtocolGuid, NULL, NULL, gImageHandle, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) {
|
|
|
|
// swap
|
|
|
|
Handle1 = Handle2;
|
|
|
|
Handle2 = NULL;
|
|
|
|
} else {
|
|
|
|
// We're all good...
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (EFI_ERROR(gBS->OpenProtocol(Handle1, &gEfiDriverBindingProtocolGuid, NULL, NULL, gImageHandle, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) {
|
|
|
|
// We're all good...
|
|
|
|
} else {
|
|
|
|
// swap
|
|
|
|
Handle2 = Handle1;
|
|
|
|
Handle1 = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-25 22:13:43 +01:00
|
|
|
return (ConnectControllers(Handle1, Handle2, Recursive, Output, (BOOLEAN)(Handle2 != NULL && Handle1 != NULL)));
|
2010-11-12 20:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
|
|
|
|
{L"-c", TypeFlag},
|
|
|
|
{L"-r", TypeFlag},
|
|
|
|
{NULL, TypeMax}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
Function for 'connect' command.
|
|
|
|
|
|
|
|
@param[in] ImageHandle Handle to the Image (NULL if Internal).
|
|
|
|
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
|
|
|
**/
|
|
|
|
SHELL_STATUS
|
|
|
|
EFIAPI
|
|
|
|
ShellCommandRunConnect (
|
|
|
|
IN EFI_HANDLE ImageHandle,
|
|
|
|
IN EFI_SYSTEM_TABLE *SystemTable
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
LIST_ENTRY *Package;
|
|
|
|
CHAR16 *ProblemParam;
|
|
|
|
SHELL_STATUS ShellStatus;
|
|
|
|
CONST CHAR16 *Param1;
|
|
|
|
CONST CHAR16 *Param2;
|
|
|
|
UINTN Count;
|
2011-03-25 22:13:43 +01:00
|
|
|
EFI_HANDLE Handle1;
|
|
|
|
EFI_HANDLE Handle2;
|
|
|
|
UINT64 Intermediate;
|
2010-11-12 20:40:21 +01:00
|
|
|
|
|
|
|
ShellStatus = SHELL_SUCCESS;
|
|
|
|
//
|
|
|
|
// initialize the shell lib (we must be in non-auto-init...)
|
|
|
|
//
|
|
|
|
Status = ShellInitialize();
|
|
|
|
ASSERT_EFI_ERROR(Status);
|
|
|
|
|
|
|
|
Status = CommandInit();
|
|
|
|
ASSERT_EFI_ERROR(Status);
|
|
|
|
|
|
|
|
//
|
|
|
|
// parse the command line
|
|
|
|
//
|
|
|
|
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
|
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
2015-02-03 20:04:52 +01:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, L"connect", ProblemParam);
|
2010-11-12 20:40:21 +01:00
|
|
|
FreePool(ProblemParam);
|
|
|
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
|
|
|
} else {
|
|
|
|
ASSERT(FALSE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// if more than 2 'value' parameters (plus the name one) or either -r or -c with any value parameters we have too many parameters
|
|
|
|
//
|
2011-04-12 23:55:07 +02:00
|
|
|
Count = (gInReconnect?0x4:0x3);
|
|
|
|
if ((ShellCommandLineGetCount(Package) > Count)
|
2016-04-18 09:59:58 +02:00
|
|
|
||(ShellCommandLineGetFlag(Package, L"-c") && ShellCommandLineGetCount(Package)>1)
|
|
|
|
||(ShellCommandLineGetFlag(Package, L"-r") && ShellCommandLineGetCount(Package)>2)
|
2010-11-12 20:40:21 +01:00
|
|
|
||(ShellCommandLineGetFlag(Package, L"-r") && ShellCommandLineGetFlag(Package, L"-c") )
|
2016-04-18 09:59:58 +02:00
|
|
|
){
|
2010-11-12 20:40:21 +01:00
|
|
|
//
|
|
|
|
// error for too many parameters
|
|
|
|
//
|
2015-02-03 20:04:52 +01:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle, L"connect");
|
2010-11-12 20:40:21 +01:00
|
|
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
|
|
|
} else if (ShellCommandLineGetFlag(Package, L"-c")) {
|
|
|
|
//
|
|
|
|
// do the conin and conout from EFI variables
|
|
|
|
// if the first fails dont 'loose' the error
|
|
|
|
//
|
2014-12-04 02:18:04 +01:00
|
|
|
Status = ShellConnectFromDevPaths(L"ConInDev");
|
2010-11-12 20:40:21 +01:00
|
|
|
if (EFI_ERROR(Status)) {
|
2014-12-04 02:18:04 +01:00
|
|
|
ShellConnectFromDevPaths(L"ConOutDev");
|
2010-11-12 20:40:21 +01:00
|
|
|
} else {
|
2014-12-04 02:18:04 +01:00
|
|
|
Status = ShellConnectFromDevPaths(L"ConOutDev");
|
2010-11-12 20:40:21 +01:00
|
|
|
}
|
|
|
|
if (EFI_ERROR(Status)) {
|
2014-12-04 02:18:04 +01:00
|
|
|
ShellConnectFromDevPaths(L"ErrOutDev");
|
2010-11-12 20:40:21 +01:00
|
|
|
} else {
|
2014-12-04 02:18:04 +01:00
|
|
|
Status = ShellConnectFromDevPaths(L"ErrOutDev");
|
2010-11-12 20:40:21 +01:00
|
|
|
}
|
|
|
|
if (EFI_ERROR(Status)) {
|
2014-12-04 02:18:04 +01:00
|
|
|
ShellConnectFromDevPaths(L"ErrOut");
|
2010-11-12 20:40:21 +01:00
|
|
|
} else {
|
2014-12-04 02:18:04 +01:00
|
|
|
Status = ShellConnectFromDevPaths(L"ErrOut");
|
2010-11-12 20:40:21 +01:00
|
|
|
}
|
|
|
|
if (EFI_ERROR(Status)) {
|
2014-12-04 02:18:04 +01:00
|
|
|
ShellConnectFromDevPaths(L"ConIn");
|
2010-11-12 20:40:21 +01:00
|
|
|
} else {
|
2014-12-04 02:18:04 +01:00
|
|
|
Status = ShellConnectFromDevPaths(L"ConIn");
|
2010-11-12 20:40:21 +01:00
|
|
|
}
|
|
|
|
if (EFI_ERROR(Status)) {
|
2014-12-04 02:18:04 +01:00
|
|
|
ShellConnectFromDevPaths(L"ConOut");
|
2010-11-12 20:40:21 +01:00
|
|
|
} else {
|
2014-12-04 02:18:04 +01:00
|
|
|
Status = ShellConnectFromDevPaths(L"ConOut");
|
2010-11-12 20:40:21 +01:00
|
|
|
}
|
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
ShellStatus = SHELL_DEVICE_ERROR;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// 0, 1, or 2 specific handles and possibly recursive
|
|
|
|
//
|
2011-03-25 22:13:43 +01:00
|
|
|
Param1 = ShellCommandLineGetRawValue(Package, 1);
|
|
|
|
Param2 = ShellCommandLineGetRawValue(Package, 2);
|
|
|
|
Count = ShellCommandLineGetCount(Package);
|
|
|
|
|
2011-04-12 23:55:07 +02:00
|
|
|
if (Param1 != NULL) {
|
|
|
|
Status = ShellConvertStringToUint64(Param1, &Intermediate, TRUE, FALSE);
|
|
|
|
Handle1 = ConvertHandleIndexToHandle((UINTN)Intermediate);
|
|
|
|
if (EFI_ERROR(Status)) {
|
2015-02-03 20:04:52 +01:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"connect", Param1);
|
2011-04-12 23:55:07 +02:00
|
|
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Handle1 = NULL;
|
2011-03-25 22:13:43 +01:00
|
|
|
}
|
2011-04-12 23:55:07 +02:00
|
|
|
|
|
|
|
if (Param2 != NULL) {
|
|
|
|
Status = ShellConvertStringToUint64(Param2, &Intermediate, TRUE, FALSE);
|
|
|
|
Handle2 = ConvertHandleIndexToHandle((UINTN)Intermediate);
|
|
|
|
if (EFI_ERROR(Status)) {
|
2015-02-03 20:04:52 +01:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"connect", Param2);
|
2011-04-12 23:55:07 +02:00
|
|
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Handle2 = NULL;
|
2011-03-25 22:13:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ShellStatus == SHELL_SUCCESS) {
|
|
|
|
if (Param1 != NULL && Handle1 == NULL){
|
2015-02-03 20:04:52 +01:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"connect", Param1);
|
2011-03-25 22:13:43 +01:00
|
|
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
|
|
|
} else if (Param2 != NULL && Handle2 == NULL) {
|
2015-02-03 20:04:52 +01:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"connect", Param2);
|
2011-03-25 22:13:43 +01:00
|
|
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
2011-03-30 18:36:42 +02:00
|
|
|
} else if (Handle2 != NULL && Handle1 != NULL && EFI_ERROR(gBS->OpenProtocol(Handle2, &gEfiDriverBindingProtocolGuid, NULL, gImageHandle, NULL, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) {
|
2015-02-03 20:04:52 +01:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"connect", Param2);
|
2011-03-30 18:36:42 +02:00
|
|
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
2011-03-25 22:13:43 +01:00
|
|
|
} else {
|
|
|
|
Status = ConvertAndConnectControllers(Handle1, Handle2, ShellCommandLineGetFlag(Package, L"-r"), (BOOLEAN)(Count!=0));
|
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CONNECT_NONE), gShellDriver1HiiHandle);
|
|
|
|
ShellStatus = SHELL_DEVICE_ERROR;
|
|
|
|
}
|
2010-11-12 20:40:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ShellCommandLineFreeVarList (Package);
|
|
|
|
}
|
|
|
|
return (ShellStatus);
|
|
|
|
}
|
|
|
|
|