I've tried the following...
Creating a C and INF file,
#include <Library/DebugLib.h>
#include <Uefi.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Protocol/Ip4Config2.h>
//#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
//#include <Library/PrintLib.h>
EFI_STATUS
EFIAPI
StaticIpDriverEntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
EFI_IP4_CONFIG2_PROTOCOL *Ip4Config2;
EFI_IP4_CONFIG2_MANUAL_ADDRESS Address;
EFI_HANDLE *HandleBuffer;
UINTN HandleCount;
UINTN Index;
// Print(L"GREG - Setting Static IP Address - Using StaticIpDriverEntryPoint\n");
DEBUG ((DEBUG_INFO, "GREG - - Setting Static IP Address - Using StaticIpDriverEntryPoint\n"));
// Locate all handles that support the EFI_IP4_CONFIG2_PROTOCOL
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiIp4Config2ProtocolGuid, NULL, &HandleCount, &HandleBuffer);
if (EFI_ERROR(Status)) {
return Status;
}
for (Index = 0; Index < HandleCount; Index++) {
Status = gBS->HandleProtocol(HandleBuffer[Index], &gEfiIp4Config2ProtocolGuid, (VOID **)&Ip4Config2);
if (EFI_ERROR(Status)) {
continue;
}
// Set the manual IP address
Address.Address.Addr[0] = 192;
Address.Address.Addr[1] = 168;
Address.Address.Addr[2] = 1;
Address.Address.Addr[3] = 5;
Address.SubnetMask.Addr[0] = 255;
Address.SubnetMask.Addr[1] = 255;
Address.SubnetMask.Addr[2] = 255;
Address.SubnetMask.Addr[3] = 0;
Status = Ip4Config2->SetData(Ip4Config2, Ip4Config2DataTypeManualAddress, sizeof(Address), &Address);
if (EFI_ERROR(Status)) {
continue;
}
// Optionally, set the gateway and DNS server addresses here
// Break after setting the IP on the first interface
break;
}
// Free the handle buffer
if (HandleBuffer != NULL) {
FreePool(HandleBuffer);
}
return Status;
}
//VOID
EFI_STATUS
EFIAPI
_ModuleEntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
EFI_IP4_CONFIG2_PROTOCOL *Ip4Config2;
EFI_IP4_CONFIG2_MANUAL_ADDRESS Address;
EFI_HANDLE *HandleBuffer;
UINTN HandleCount;
UINTN Index;
// Print(L"GREG - Setting Static IP Address - Using _ModuleEntryPoint\n");
DEBUG ((DEBUG_INFO, "GREG - - Setting Static IP Address - Using _ModuleEntryPoint\n"));
// Locate all handles that support the EFI_IP4_CONFIG2_PROTOCOL
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiIp4Config2ProtocolGuid, NULL, &HandleCount, &HandleBuffer);
if (EFI_ERROR(Status)) {
return Status;
}
for (Index = 0; Index < HandleCount; Index++) {
Status = gBS->HandleProtocol(HandleBuffer[Index], &gEfiIp4Config2ProtocolGuid, (VOID **)&Ip4Config2);
if (EFI_ERROR(Status)) {
continue;
}
// Set the manual IP address
Address.Address.Addr[0] = 192;
Address.Address.Addr[1] = 168;
Address.Address.Addr[2] = 1;
Address.Address.Addr[3] = 100;
Address.SubnetMask.Addr[0] = 255;
Address.SubnetMask.Addr[1] = 255;
Address.SubnetMask.Addr[2] = 255;
Address.SubnetMask.Addr[3] = 0;
Status = Ip4Config2->SetData(Ip4Config2, Ip4Config2DataTypeManualAddress, sizeof(Address), &Address);
if (EFI_ERROR(Status)) {
continue;
}
// Optionally, set the gateway and DNS server addresses here
// Break after setting the IP on the first interface
break;
}
// Free the handle buffer
if (HandleBuffer != NULL) {
FreePool(HandleBuffer);
}
return Status;
}
and INF File
[Defines]
INF_VERSION = 0x00010017
BASE_NAME = StaticIpConfigDxe
FILE_GUID = 7283e2fb-eeca-47d8-8576-5d55225ec820
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
ENTRY_POINT = StaticIpDriverEntryPoint
[Sources]
StaticIpConfigDxe.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
UefiPayloadPkg/UefiPayloadPkg.dec
[LibraryClasses]
UefiLib
UefiBootServicesTableLib
DebugLib
MemoryAllocationLib
PrintLib
[Protocols]
gEfiIp4Config2ProtocolGuid
[Depex]
gEfiIp4Config2ProtocolGuid
but loading the INF file into sbl_02\edk2\UefiPayloadPkg\UefiPayloadPkg.dsc and sbl_02\edk2\UefiPayloadPkg\UefiPayloadPkg.fdf caused the build binary to not load.
I commented out the above entries and then modified sbl_02\edk2\UefiPayloadPkg\UefiPayloadPkg.dsc and sbl_02\edk2\UefiPayloadPkg\UefiPayloadPkg.dec
I added into the dsc the following
# Disable DHCP
gUefiPayloadPkgTokenSpaceGuid.PcdIPv4Enable|TRUE
gUefiPayloadPkgTokenSpaceGuid.PcdDhcp|FALSE
# Static IP configuration for eth0
gUefiPayloadPkgTokenSpaceGuid.PcdIp4Address0|192.168.1.5
gUefiPayloadPkgTokenSpaceGuid.PcdIp4SubnetMask0|255.255.255.0
gUefiPayloadPkgTokenSpaceGuid.PcdIp4Gateway0|192.168.1.1
In the dec I added
[PcdsFixedAtBuild]
gUefiPayloadPkgTokenSpaceGuid.PcdIPv4Enable|TRUE|BOOLEAN|0x00000001
gUefiPayloadPkgTokenSpaceGuid.PcdDhcp|FALSE|BOOLEAN|0x00000002
gUefiPayloadPkgTokenSpaceGuid.PcdIp4Address0|192.168.1.5|VOID*|0x00000042
gUefiPayloadPkgTokenSpaceGuid.PcdIp4SubnetMask0|255.255.255.0|VOID*|0x00000043
gUefiPayloadPkgTokenSpaceGuid.PcdIp4Gateway0|192.168.1.1|VOID*|0x00000044
This booted into UEFI shell, but didn't assign the IP address.
I will have multiple interfaces i need to set static IP addresses to, but eth0 is of course the first :-)
Any help gratefully received.
Kind regards