在TCP/IP网络协议族中有FTP协议,但是UEFI下的MTFTP4并不是对FTP协议的实现,两者虽然功能上差不多,但是实现却是不同的。FTP下层使用TCP来连接:
而MTFTP4下层却是UDP4。
MTFTP4的实现在NetworkPkg\Mtftp4Dxe\Mtftp4Dxe.inf,这里首先需要看下它的入口:
EFI_STATUS
EFIAPI
Mtftp4DriverEntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
return EfiLibInstallDriverBindingComponentName2 (
ImageHandle,
SystemTable,
&gMtftp4DriverBinding,
ImageHandle,
&gMtftp4ComponentName,
&gMtftp4ComponentName2
);
}
仅仅是安装了EFI_DRIVER_BINDING_PROTOCOL
:
EFI_DRIVER_BINDING_PROTOCOL gMtftp4DriverBinding = {
Mtftp4DriverBindingSupported,
Mtftp4DriverBindingStart,
Mtftp4DriverBindingStop,
0xa,
NULL,
NULL
};
DHCP4在UEFI网络协议栈中的关系图:
前面已经说过,MTFTP4依赖于UDP4:
EFI_STATUS
EFIAPI
Mtftp4DriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
Status = gBS->OpenProtocol (
Controller,
&gEfiUdp4ServiceBindingProtocolGuid,
NULL,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_TEST_PROTOCOL
);
}
Start函数的流程大致如下:
MTFTP4_SERVICE
。gEfiMtftp4ServiceBindingProtocolGuid
。MTFTP4_SERVICE
在Start函数中创建:
EFI_STATUS
EFIAPI
Mtftp4DriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
Status = Mtftp4CreateService (Controller, This->DriverBindingHandle, &MtftpSb);
}
其结构体如下:
struct _MTFTP4_SERVICE {
UINT32 Signature;
EFI_SERVICE_BINDING_PROTOCOL ServiceBinding;
UINT16 ChildrenNum;
LIST_ENTRY Children;
EFI_EVENT Timer; ///< Ticking timer for all the MTFTP clients to handle the packet timeout case.
EFI_EVENT TimerNotifyLevel; ///< Ticking timer for all the MTFTP clients to calculate the packet live time.
EFI_EVENT TimerToGetMap;
EFI_HANDLE Controller;
EFI_HANDLE Image;
//
// This UDP child is used to keep the connection between the UDP
// and MTFTP, so MTFTP will be notified when UDP is uninstalled.
//
UDP_IO *ConnectUdp;
};
这里的成员都比较简单,重点是如下的几个:
Timer
、TimerNotifyLevel
、TimerToGetMap
:几个不同作用的定时器,在注释中已经有说明。ConnectUdp
:与UDP4相关的结构体。MTFTP4的一个示例就是tftp命令,它位于ShellPkg\DynamicCommand\TftpDynamicCommand\TftpDynamicCommand.inf,其主要实现在RunTftp()
,它包含以下的几个部分:
-s
的blksize和-w
指定的windowsize,它们会被Mtftp4Token
的选项值传递给服务器端,它们会影响到数据传输的速度。EFI_MTFTP4_PROTOCOL
,使用其Configure
成员函数进行配置。具体的实现可以直接看代码,这里不再介绍。