From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=none, err=SPF record not found (domain: fensystems.co.uk, ip: 212.13.204.60, mailfrom: mbrown@fensystems.co.uk) Received: from duck.fensystems.co.uk (duck.fensystems.co.uk [212.13.204.60]) by groups.io with SMTP; Wed, 24 Jul 2019 07:31:34 -0700 Received: from pudding.home (pudding.qs.unipart.io [IPv6:2001:470:1dbe:1:ffff::c5f1]) by duck.fensystems.co.uk (Postfix) with ESMTPSA id 82D5715FBD; Wed, 24 Jul 2019 15:31:32 +0100 (BST) From: Michael Brown To: devel@edk2.groups.io Cc: ard.biesheuvel@linaro.org, leif.lindholm@linaro.org, pete@akeo.ie, Michael Brown Subject: [edk2-platforms: PATCHv2 1/1] Platform/RPi3: Provide "ethernet[0]" aliases in device tree Date: Wed, 24 Jul 2019 15:31:14 +0100 Message-Id: <20190724143114.468304-2-mbrown@fensystems.co.uk> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190723111727.GG11541@bivouac.eciton.net> References: <20190723111727.GG11541@bivouac.eciton.net> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Older device trees tend to use the alias "ethernet". Newer device trees tend to use "ethernet0" since older versions of U-Boot would skip aliases that do not include an index number. See, for example, Linux kernel commit 10b6c0c ("ARM: dts: bcm2835: add index to the ethernet alias") and U-Boot commit f8e57c6 ("fdt_support: Fixup 'ethernet' aliases not ending in digits"). Ensure that both "ethernet" and "ethernet0" aliases are present within the device tree, to provide compatibility with operating systems that expect either alias, and with device trees that contain either (or both) aliases. Signed-off-by: Michael Brown --- .../RaspberryPi/RPi3/Drivers/FdtDxe/FdtDxe.c | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/Platform/RaspberryPi/RPi3/Drivers/FdtDxe/FdtDxe.c b/Platform= /RaspberryPi/RPi3/Drivers/FdtDxe/FdtDxe.c index 83446e3e45..57e4bee8da 100644 --- a/Platform/RaspberryPi/RPi3/Drivers/FdtDxe/FdtDxe.c +++ b/Platform/RaspberryPi/RPi3/Drivers/FdtDxe/FdtDxe.c @@ -23,6 +23,69 @@ STATIC VOID *mFdtImage; =20 STATIC RASPBERRY_PI_FIRMWARE_PROTOCOL *mFwProtocol; =20 +STATIC +VOID +FixEthernetAliases ( + VOID +) +{ + INTN Aliases; + CONST CHAR8 *Ethernet; + CONST CHAR8 *Ethernet0; + CONST CHAR8 *Alias; + UINTN CopySize; + CHAR8 *Copy; + INTN Retval; + + // + // Look up the 'ethernet[0]' aliases + // + Aliases =3D fdt_path_offset (mFdtImage, "/aliases"); + if (Aliases < 0) { + DEBUG ((DEBUG_ERROR, "%a: failed to locate '/aliases'\n", __FUNCTION= __)); + return; + } + Ethernet =3D fdt_getprop (mFdtImage, Aliases, "ethernet", NULL); + Ethernet0 =3D fdt_getprop (mFdtImage, Aliases, "ethernet0", NULL); + Alias =3D Ethernet ? Ethernet : Ethernet0; + if (!Alias) { + DEBUG ((DEBUG_ERROR, "%a: failed to locate 'ethernet[0]' alias\n", _= _FUNCTION__)); + return; + } + + // + // Create copy for fdt_setprop + // + CopySize =3D AsciiStrSize (Alias); + Copy =3D AllocateCopyPool (CopySize, Alias); + if (!Copy) { + DEBUG ((DEBUG_ERROR, "%a: failed to copy '%a'\n", __FUNCTION__, Alia= s)); + return; + } + + // + // Create missing aliases + // + if (!Ethernet) { + Retval =3D fdt_setprop (mFdtImage, Aliases, "ethernet", Copy, CopySi= ze); + if (Retval !=3D 0) { + DEBUG ((DEBUG_ERROR, "%a: failed to create 'ethernet' alias (%d)\n= ", + __FUNCTION__, Retval)); + } + DEBUG ((DEBUG_INFO, "%a: created 'ethernet' alias '%a'\n", __FUNCTIO= N__, Copy)); + } + if (!Ethernet0) { + Retval =3D fdt_setprop (mFdtImage, Aliases, "ethernet0", Copy, CopyS= ize); + if (Retval !=3D 0) { + DEBUG ((DEBUG_ERROR, "%a: failed to create 'ethernet0' alias (%d)\= n", + __FUNCTION__, Retval)); + } + DEBUG ((DEBUG_INFO, "%a: created 'ethernet0' alias '%a'\n", __FUNCTI= ON__, Copy)); + } + + FreePool (Copy); +} + STATIC VOID UpdateMacAddress ( @@ -342,6 +405,7 @@ FdtDxeInitialize ( SanitizePSCI (); CleanMemoryNodes (); CleanSimpleFramebuffer (); + FixEthernetAliases (); UpdateMacAddress (); if (Internal) { /* --=20 2.21.0