Hi,

Within EDK2 payload, I am trying to get a static IP address set, so that when I 
enter UEFI Shell, I can ping another computer.

At the moment I have the network stack elements started automatically, but 
still need to type 'ifconfig -s eth0 static 192.168.1.5 255.255.255.0 
192.168.1.1' every time to get the IP address assigned before i can ping 
192.168.1.10

I'd like to start the UEFI shell and just run the ping command, and it check if 
192.168.1.10 is available.

The current versions of EDK2 and Slimboot from github I am using are listed 
below

EDK2 - d13f31c3fe17eb532bf9016a2d8de3885642cba0 
(https://github.com/tianocore/edk2/tree/d13f31c3fe17eb532bf9016a2d8de3885642cba0)
 from September 30th (I tried a newer version, but got build errors)
Slimboot - ca00703127e34c84c3e6d3d129ebc5ef292ba963 
(https://github.com/slimbootloader/slimbootloader/tree/ca00703127e34c84c3e6d3d129ebc5ef292ba963)
 from October 25th

I've tried the following...

Creating a C and INF file,

C 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


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#120902): https://edk2.groups.io/g/devel/message/120902
Mute This Topic: https://groups.io/mt/110160546/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to