我有一个Alexa设备,我使用一个esp8266从回波点获得请求。我可以在伊恩上醒来,但这还不够。我的Pc上有windows和Linux,所以我想“我需要在引导前运行一些代码,这样我就可以与我的esp8266通信,知道应该启动女巫操作系统”。所以我开始到处寻找解决方案,我想我已经接近它了。我所做的就是把efi-shell作为主引导,让它执行startup.nsh。在这个startup.nsh中,我想启动能够与esp8266通信的efi应用程序。这是做这件事的正确方式吗?我该做点别的吗?问题是我不能对这个应用程序进行编码。我不知道如何使用协议和哪些协议是解决方案。应用程序应该向esp发送一个简单的字符,让它知道计算机已经准备好获得引导指令。esp应该回答windows的“1”或Linux的“2”。有人能给我一些关于这个任务的建议吗?这是正确的方式还是我做了很多没用的东西?也许存在一种更好的方式
发布于 2021-04-13 14:17:31
下面是一个示例,如何用EDK2加载和启动UEFI应用程序,将其移植到gnu应该是一项简单的任务,用uefi_call_wrapper包装所有gBS->调用。
根据来自esp8266的响应,您必须启动Linux或Windows应用程序。
我将UDP示例作为answer发布到您的第一个问题中。
#include <Uefi.h>
#include <Library\UefiLib.h>
#include <Protocol\LoadedImage.h>
#include <Protocol\DevicePath.h>
#include <Library\DevicePathLib.h>
#ifndef LOG
#define LOG(fmt, ...) AsciiPrint(fmt, __VA_ARGS__)
#endif
#ifndef TRACE
#define TRACE(status) LOG("Status: '%r', Function: '%a', File: '%a', Line: '%d'\r\n", status, __FUNCTION__, __FILE__, __LINE__)
#endif
extern EFI_BOOT_SERVICES *gBS;
/*
Configuration
*/
static CHAR16 gFilePath[] = L"\\Tools\\Udp4Sample.efi";
EFI_STATUS
EFIAPI
UefiMain(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable)
{
EFI_STATUS Status;
EFI_LOADED_IMAGE *LoadedImageProtocol = NULL;
EFI_DEVICE_PATH_PROTOCOL *AppDevicePath = NULL;
EFI_HANDLE AppHandle = NULL;
/*
Step 1: Handle the LoadedImageProtocol of the current application
*/
Status = gBS->HandleProtocol(
ImageHandle,
&gEfiLoadedImageProtocolGuid,
&LoadedImageProtocol);
if (EFI_ERROR(Status)) {
TRACE(Status);
// Error handling
return Status;
}
/*
Step 2: Create a device path that points to the application, the application must be located on the same device (partition) as this one
*/
AppDevicePath = FileDevicePath(LoadedImageProtocol->DeviceHandle, gFilePath);
if (!AppDevicePath) {
TRACE(EFI_INVALID_PARAMETER);
// Error handling
return EFI_INVALID_PARAMETER;
}
/*
Step 3: Load the application
*/
Status = gBS->LoadImage(
FALSE,
ImageHandle,
AppDevicePath,
NULL,
0,
&AppHandle);
gBS->FreePool(AppDevicePath);
if (EFI_ERROR(Status)) {
TRACE(Status);
// Error handling
return Status;
}
/*
Step 4: Start the application
*/
Status = gBS->StartImage(
AppHandle,
NULL,
NULL);
if (EFI_ERROR(Status)) {
TRACE(Status);
// Error handling
return Status;
}
return EFI_SUCCESS;
}https://stackoverflow.com/questions/67073808
复制相似问题