public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "greg.wilson via groups.io" <greg.wilson=gd-ms.uk@groups.io>
To: devel@edk2.groups.io
Subject: [edk2-devel] Setting a static IP address in EDK2 Payload prior to UEFI Shell
Date: Tue, 17 Dec 2024 02:14:57 -0800	[thread overview]
Message-ID: <rOXg.1734430497123281356.CwVt@groups.io> (raw)

[-- Attachment #1: Type: text/plain, Size: 6957 bytes --]

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/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



[-- Attachment #2: Type: text/html, Size: 13871 bytes --]

                 reply	other threads:[~2024-12-17 10:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=rOXg.1734430497123281356.CwVt@groups.io \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox