ESP32 带有 WIFI 功能,而众所周知要想让一个设备连接WIFI AP 需要告知设备对应 AP 的名称和密码,简单实验的话,可以直接在代码中写死这两个参数,但这种情况下烧写之后设备只能在固定的环境下使用。https://github.com/tzapu/wifimanager 这个项目可以解决上述问题。先说一下这个东西如何使用:
/**
External function. Initializes memory services based on the memory
descriptor HOBs. This function is responsible for priming the memory
map, so memory allocations and resource allocations can be made.
The first part of this function can not depend on any memory services
until at least one memory descriptor is provided to the memory services.
@param HobStart The start address of the HOB.
@param MemoryBaseAddress Start address of memory region found to init DXE
core.
@param MemoryLength Length of memory region found to init DXE core.
@retval EFI_SUCCESS Memory services successfully initialized.
**/
EFI_STATUS
CoreInitializeMemoryServices (
IN VOID **HobStart,
OUT EFI_PHYSICAL_ADDRESS *MemoryBaseAddress,
OUT UINT64 *MemoryLength
)
//
// Allocate the EFI System Table and EFI Runtime Service Table from EfiRuntimeServicesData
// Use the templates to initialize the contents of the EFI System Table and EFI Runtime Services Table
//
gDxeCoreST = AllocateRuntimeCopyPool (sizeof (EFI_SYSTEM_TABLE), &mEfiSystemTableTemplate);
ASSERT (gDxeCoreST != NULL);
gDxeCoreRT = AllocateRuntimeCopyPool (sizeof (EFI_RUNTIME_SERVICES), &mEfiRuntimeServicesTableTemplate);
ASSERT (gDxeCoreRT != NULL);
gDxeCoreST->RuntimeServices = gDxeCoreRT;
FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {
SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE {
#
# These firmware volumes will have files placed in them uncompressed,
# and then both firmware volumes will be compressed in a single
# compression operation in order to achieve better overall compression.
#
SECTION FV_IMAGE = PEIFV
SECTION FV_IMAGE = DXEFV
}
}
/**
Entry point of the section extraction code. Initializes an instance of the
section extraction interface and installs it on a new handle.
@param ImageHandle A handle for the image that is initializing this driver
@param SystemTable A pointer to the EFI system table
@retval EFI_SUCCESS Driver initialized successfully
@retval EFI_OUT_OF_RESOURCES Could not allocate needed resources
**/
EFI_STATUS
EFIAPI
InitializeSectionExtraction (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
(感觉是将 PEI 和 DXE打包在一起)
#elif defined(SPI_HAS_TRANSACTION)
static void init() {
//LABZDebug USB_SPI.begin(); // The SPI library with transaction will take care of setting up the pins - settings is set in beginTransaction()
//LABZDebug_Start
USB_SPI.begin(10,21,19,13); // The SPI library with transaction will take care of setting up the pins - settings is set in beginTransaction()
//LABZDebug_End
SPI_SS::SetDirWrite();
SPI_SS::Set();
}
#elif defined(STM32F4)
//LABZDebug USB_SPI.beginTransaction(SPISettings(26000000, MSBFIRST, SPI_MODE0)); // The MAX3421E can handle up to 26MHz, use MSB First and SPI mode 0
//LABZDebug_Start
USB_SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
//LABZDebug_End
2.USB_Host_Shield_Library_2.0\UsbCore.h 这里给出用到的SS 和 INT Pin编号
//
// Enter DxeIpl to load Dxe core.
//
DEBUG ((EFI_D_INFO, "DXE IPL Entry\n"));
Status = TempPtr.DxeIpl->Entry (
TempPtr.DxeIpl,
&PrivateData.Ps,
PrivateData.HobList
);
定义在 PeiMain.c 中
PEI_CORE_TEMP_POINTERS TempPtr;
PEI_CORE_TEMP_POINTERS 定义如下:
///
/// Union of temporarily used function pointers (to save stack space)
///
typedef union {
PEICORE_FUNCTION_POINTER PeiCore;
EFI_PEIM_ENTRY_POINT2 PeimEntry;
EFI_PEIM_NOTIFY_ENTRY_POINT PeimNotifyEntry;
EFI_DXE_IPL_PPI *DxeIpl;
EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;
EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor;
VOID *Raw;
} PEI_CORE_TEMP_POINTERS;
EFI_DXE_IPL_PPI 定义如下:
///
/// Final service to be invoked by the PEI Foundation.
/// The DXE IPL PPI is responsible for locating and loading the DXE Foundation.
/// The DXE IPL PPI may use PEI services to locate and load the DXE Foundation.
///
struct _EFI_DXE_IPL_PPI {
EFI_DXE_IPL_ENTRY Entry;
};
/**
The architectural PPI that the PEI Foundation invokes when
there are no additional PEIMs to invoke.
This function is invoked by the PEI Foundation.
The PEI Foundation will invoke this service when there are
no additional PEIMs to invoke in the system.
If this PPI does not exist, it is an error condition and
an ill-formed firmware set. The DXE IPL PPI should never
return after having been invoked by the PEI Foundation.
The DXE IPL PPI can do many things internally, including the following:
- Invoke the DXE entry point from a firmware volume
- Invoke the recovery processing modules
- Invoke the S3 resume modules
@param This Pointer to the DXE IPL PPI instance
@param PeiServices Pointer to the PEI Services Table.
@param HobList Pointer to the list of Hand-Off Block (HOB) entries.
@retval EFI_SUCCESS Upon this return code, the PEI Foundation should enter
some exception handling.Under normal circumstances,
the DXE IPL PPI should not return.
**/
typedef
EFI_STATUS
(EFIAPI *EFI_DXE_IPL_ENTRY)(
IN CONST EFI_DXE_IPL_PPI *This,
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_PEI_HOB_POINTERS HobList
);
对着应\MdeModulePkg\Core\DxeIplPeim\DxeLoad.c
//
// Module Globals used in the DXE to PEI hand off
// These must be module globals, so the stack can be switched
//
CONST EFI_DXE_IPL_PPI mDxeIplPpi = {
DxeLoadCore
};
/**
Main entry point to last PEIM.
This function finds DXE Core in the firmware volume and transfer the control to
DXE core.
@param This Entry point for DXE IPL PPI.
@param PeiServices General purpose services available to every PEIM.
@param HobList Address to the Pei HOB list.
@return EFI_SUCCESS DXE core was successfully loaded.
@return EFI_OUT_OF_RESOURCES There are not enough resources to load DXE core.
**/
EFI_STATUS
EFIAPI
DxeLoadCore (
IN CONST EFI_DXE_IPL_PPI *This,
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_PEI_HOB_POINTERS HobList
)
其中通过 gEfiPeiLoadFilePpiGuid 加载 DXE Core
Loading PEIM D6A2CB7F-6A18-4E2F-B43B-9920A733700A
Loading PEIM at 0x00007EA3000 EntryPoint=0x00007EA3D78 DxeCore.efi
/**
The entry point of PE/COFF Image for the DXE Core.
This function is the entry point for the DXE Core. This function is required to call
ProcessModuleEntryPointList() and ProcessModuleEntryPointList() is never expected to return.
The DXE Core is responsible for calling ProcessLibraryConstructorList() as soon as the EFI
System Table and the image handle for the DXE Core itself have been established.
If ProcessModuleEntryPointList() returns, then ASSERT() and halt the system.
@param HobStart The pointer to the beginning of the HOB List passed in from the PEI Phase.
**/
VOID
EFIAPI
_ModuleEntryPoint (
IN VOID *HobStart
)
在这个函数中通过下面的函数转入 DXE Core:
//
// Call the DXE Core entry point
//
ProcessModuleEntryPointList (HobStart);
// Main entry point to the DXE Core
//
/**
Main entry point to DXE Core.
@param HobStart Pointer to the beginning of the HOB List from PEI.
@return This function should never return.
**/
VOID
EFIAPI
DxeMain (
IN VOID *HobStart
)
/**
Entry point of DXE IPL PEIM.
This function installs DXE IPL PPI. It also reloads
itself to memory on non-S3 resume boot path.
@param FileHandle Handle of the file being invoked.
@param PeiServices Describes the list of possible PEI Services.
@retval EFI_SUCESS The entry point of DXE IPL PEIM executes successfully.
@retval Others Some error occurs during the execution of this function.
**/
EFI_STATUS
EFIAPI
PeimInitializeDxeIpl (
IN EFI_PEI_FILE_HANDLE FileHandle,
IN CONST EFI_PEI_SERVICES **PeiServices
)
/**
Main entry for S3 Resume PEIM.
This routine is to install EFI_PEI_S3_RESUME2_PPI.
@param FileHandle Handle of the file being invoked.
@param PeiServices Pointer to PEI Services table.
@retval EFI_SUCCESS S3Resume Ppi is installed successfully.
**/
EFI_STATUS
EFIAPI
PeimS3ResumeEntryPoint (
IN EFI_PEI_FILE_HANDLE FileHandle,
IN CONST EFI_PEI_SERVICES **PeiServices
)
动作是安装 EFI_PEI_S3_RESUME2_PPI_GUID 6D582DBC-DB85-4514-8FCC-5ADF6227B147 这个 PPI
if (Private->CurrentPeimCount == 0) {
//
// When going through each FV, at first, search Apriori file to
// reorder all PEIMs to ensure the PEIMs in Apriori file to get
// dispatch at first.
//
DiscoverPeimsAndOrderWithApriori (Private, CoreFvHandle);
}
查找没有找到,输入如下:
DiscoverPeimsAndOrderWithApriori(): Found 0x0 PEI FFS files in the 1th FV