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; Thu, 25 Jul 2019 03:27:22 -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 3F77F15B53; Thu, 25 Jul 2019 11:27:20 +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: PATCH 1/1] Platform/RPi3: Report device tree modification errors using Print() Date: Thu, 25 Jul 2019 11:27:15 +0100 Message-Id: <20190725102715.572560-2-mbrown@fensystems.co.uk> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190724214342.GZ11541@bivouac.eciton.net> References: <20190724214342.GZ11541@bivouac.eciton.net> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Most functions in FdtDxe currently return VOID and report errors using only DEBUG. Update functions to return EFI_STATUS and report errors using Print() so that errors are at least visible in non-debug builds. Signed-off-by: Michael Brown --- .../RaspberryPi/RPi3/Drivers/FdtDxe/FdtDxe.c | 102 ++++++++++++------ 1 file changed, 70 insertions(+), 32 deletions(-) diff --git a/Platform/RaspberryPi/RPi3/Drivers/FdtDxe/FdtDxe.c b/Platform= /RaspberryPi/RPi3/Drivers/FdtDxe/FdtDxe.c index 57e4bee8da..17d3bbd82d 100644 --- a/Platform/RaspberryPi/RPi3/Drivers/FdtDxe/FdtDxe.c +++ b/Platform/RaspberryPi/RPi3/Drivers/FdtDxe/FdtDxe.c @@ -13,6 +13,7 @@ #include #include #include +#include #include =20 #include @@ -24,7 +25,7 @@ STATIC VOID *mFdtImage; STATIC RASPBERRY_PI_FIRMWARE_PROTOCOL *mFwProtocol; =20 STATIC -VOID +EFI_STATUS FixEthernetAliases ( VOID ) @@ -36,6 +37,7 @@ FixEthernetAliases ( UINTN CopySize; CHAR8 *Copy; INTN Retval; + EFI_STATUS Status; =20 // // Look up the 'ethernet[0]' aliases @@ -43,14 +45,14 @@ FixEthernetAliases ( Aliases =3D fdt_path_offset (mFdtImage, "/aliases"); if (Aliases < 0) { DEBUG ((DEBUG_ERROR, "%a: failed to locate '/aliases'\n", __FUNCTION= __)); - return; + return EFI_NOT_FOUND; } 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; + return EFI_NOT_FOUND; } =20 // @@ -60,15 +62,17 @@ FixEthernetAliases ( Copy =3D AllocateCopyPool (CopySize, Alias); if (!Copy) { DEBUG ((DEBUG_ERROR, "%a: failed to copy '%a'\n", __FUNCTION__, Alia= s)); - return; + return EFI_OUT_OF_RESOURCES; } =20 // // Create missing aliases // + Status =3D EFI_SUCCESS; if (!Ethernet) { Retval =3D fdt_setprop (mFdtImage, Aliases, "ethernet", Copy, CopySi= ze); if (Retval !=3D 0) { + Status =3D EFI_DEVICE_ERROR; DEBUG ((DEBUG_ERROR, "%a: failed to create 'ethernet' alias (%d)\n= ", __FUNCTION__, Retval)); } @@ -77,6 +81,7 @@ FixEthernetAliases ( if (!Ethernet0) { Retval =3D fdt_setprop (mFdtImage, Aliases, "ethernet0", Copy, CopyS= ize); if (Retval !=3D 0) { + Status =3D EFI_DEVICE_ERROR; DEBUG ((DEBUG_ERROR, "%a: failed to create 'ethernet0' alias (%d)\= n", __FUNCTION__, Retval)); } @@ -84,10 +89,11 @@ FixEthernetAliases ( } =20 FreePool (Copy); + return Status; } =20 STATIC -VOID +EFI_STATUS UpdateMacAddress ( VOID ) @@ -103,7 +109,7 @@ UpdateMacAddress ( Node =3D fdt_path_offset (mFdtImage, "ethernet"); if (Node < 0) { DEBUG ((DEBUG_ERROR, "%a: failed to locate 'ethernet' alias\n", __FU= NCTION__)); - return; + return EFI_NOT_FOUND; } =20 // @@ -112,7 +118,7 @@ UpdateMacAddress ( Status =3D mFwProtocol->GetMacAddress (MacAddress); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a: failed to retrieve MAC address\n", __FUNCT= ION__)); - return; + return Status; } =20 Retval =3D fdt_setprop (mFdtImage, Node, "mac-address", MacAddress, @@ -120,16 +126,17 @@ UpdateMacAddress ( if (Retval !=3D 0) { DEBUG ((DEBUG_ERROR, "%a: failed to create 'mac-address' property (%= d)\n", __FUNCTION__, Retval)); - return; + return EFI_DEVICE_ERROR; } =20 DEBUG ((DEBUG_INFO, "%a: setting MAC address to %02x:%02x:%02x:%02x:%0= 2x:%02x\n", __FUNCTION__, MacAddress[0], MacAddress[1], MacAddress[2], MacAddres= s[3], MacAddress[4], MacAddress[5])); + return EFI_SUCCESS; } =20 STATIC -VOID +EFI_STATUS CleanMemoryNodes ( VOID ) @@ -139,7 +146,7 @@ CleanMemoryNodes ( =20 Node =3D fdt_path_offset (mFdtImage, "/memory"); if (Node < 0) { - return; + return EFI_SUCCESS; } =20 /* @@ -150,11 +157,14 @@ CleanMemoryNodes ( Retval =3D fdt_del_node (mFdtImage, Node); if (Retval !=3D 0) { DEBUG ((DEBUG_ERROR, "Failed to remove /memory\n")); + return EFI_DEVICE_ERROR; } + + return EFI_SUCCESS; } =20 STATIC -VOID +EFI_STATUS SanitizePSCI ( VOID ) @@ -166,7 +176,7 @@ SanitizePSCI ( Root =3D fdt_path_offset (mFdtImage, "/"); ASSERT (Root >=3D 0); if (Root < 0) { - return; + return EFI_NOT_FOUND; } =20 Node =3D fdt_path_offset (mFdtImage, "/psci"); @@ -177,41 +187,42 @@ SanitizePSCI ( ASSERT (Node >=3D 0); if (Node < 0) { DEBUG ((DEBUG_ERROR, "Couldn't find/create /psci\n")); - return; + return EFI_DEVICE_ERROR; } =20 Retval =3D fdt_setprop_string (mFdtImage, Node, "compatible", "arm,psc= i-1.0"); if (Retval !=3D 0) { DEBUG ((DEBUG_ERROR, "Couldn't set /psci compatible property\n")); - return; + return EFI_DEVICE_ERROR; } =20 Retval =3D fdt_setprop_string (mFdtImage, Node, "method", "smc"); if (Retval !=3D 0) { DEBUG ((DEBUG_ERROR, "Couldn't set /psci method property\n")); - return; + return EFI_DEVICE_ERROR; } =20 Root =3D fdt_path_offset (mFdtImage, "/cpus"); if (Root < 0) { DEBUG ((DEBUG_ERROR, "No CPUs to update with PSCI enable-method?\n")= ); - return; + return EFI_NOT_FOUND; } =20 Node =3D fdt_first_subnode (mFdtImage, Root); while (Node >=3D 0) { if (fdt_setprop_string (mFdtImage, Node, "enable-method", "psci") !=3D= 0) { DEBUG ((DEBUG_ERROR, "Failed to update enable-method for a CPU\n")= ); - return; + return EFI_DEVICE_ERROR; } =20 fdt_delprop (mFdtImage, Node, "cpu-release-addr"); Node =3D fdt_next_subnode (mFdtImage, Node); } + return EFI_SUCCESS; } =20 STATIC -VOID +EFI_STATUS CleanSimpleFramebuffer ( VOID ) @@ -225,7 +236,7 @@ CleanSimpleFramebuffer ( */ Node =3D fdt_path_offset (mFdtImage, "display0"); if (Node < 0) { - return; + return EFI_SUCCESS; } =20 /* @@ -236,25 +247,28 @@ CleanSimpleFramebuffer ( Retval =3D fdt_del_node (mFdtImage, Node); if (Retval !=3D 0) { DEBUG ((DEBUG_ERROR, "Failed to remove display0\n")); - return; + return EFI_DEVICE_ERROR; } =20 Node =3D fdt_path_offset (mFdtImage, "/aliases"); if (Node < 0) { DEBUG ((DEBUG_ERROR, "Couldn't find /aliases to remove display0\n"))= ; - return; + return EFI_NOT_FOUND; } =20 Retval =3D fdt_delprop (mFdtImage, Node, "display0"); if (Retval !=3D 0) { DEBUG ((DEBUG_ERROR, "Failed to remove display0 alias\n")); + return EFI_DEVICE_ERROR; } + + return EFI_SUCCESS; } =20 #define MAX_CMDLINE_SIZE 512 =20 STATIC -VOID +EFI_STATUS UpdateBootArgs ( VOID ) @@ -270,7 +284,7 @@ UpdateBootArgs ( Node =3D fdt_path_offset (mFdtImage, "/chosen"); if (Node < 0) { DEBUG ((DEBUG_ERROR, "%a: failed to locate /chosen node\n", __FUNCTI= ON__)); - return; + return EFI_NOT_FOUND; } =20 // @@ -282,7 +296,7 @@ UpdateBootArgs ( CommandLine =3D AllocatePool (MAX_CMDLINE_SIZE) + 4; if (!CommandLine) { DEBUG ((DEBUG_ERROR, "%a: failed to allocate memory\n", __FUNCTION__= )); - return; + return EFI_OUT_OF_RESOURCES; } =20 // @@ -291,12 +305,12 @@ UpdateBootArgs ( Status =3D mFwProtocol->GetCommandLine (MAX_CMDLINE_SIZE, CommandLine = + 4); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a: failed to retrieve command line\n", __FUNC= TION__)); - return; + return Status; } =20 if (AsciiStrLen (CommandLine + 4) =3D=3D 0) { DEBUG ((DEBUG_INFO, "%a: empty command line received\n", __FUNCTION_= _)); - return; + return EFI_SUCCESS; } =20 CommandLine[3] =3D ' '; @@ -331,6 +345,7 @@ UpdateBootArgs ( DEBUG_CODE_END (); =20 FreePool (CommandLine - 4); + return EFI_SUCCESS; } =20 =20 @@ -402,16 +417,39 @@ FdtDxeInitialize ( Retval =3D fdt_open_into (FdtImage, mFdtImage, FdtSize); ASSERT (Retval =3D=3D 0); =20 - SanitizePSCI (); - CleanMemoryNodes (); - CleanSimpleFramebuffer (); - FixEthernetAliases (); - UpdateMacAddress (); + Status =3D SanitizePSCI (); + if (EFI_ERROR (Status)) { + Print (L"Failed to sanitize PSCI (error %d)\n", Status); + } + + Status =3D CleanMemoryNodes (); + if (EFI_ERROR (Status)) { + Print (L"Failed to clean memory nodes (error %d)\n", Status); + } + + Status =3D CleanSimpleFramebuffer (); + if (EFI_ERROR (Status)) { + Print (L"Failed to clean frame buffer (error %d)\n", Status); + } + + Status =3D FixEthernetAliases (); + if (EFI_ERROR (Status)) { + Print (L"Failed to fix ethernet aliases (error %d)\n", Status); + } + + Status =3D UpdateMacAddress (); + if (EFI_ERROR (Status)) { + Print (L"Failed to update MAC address (error %d)\n", Status); + } + if (Internal) { /* * A GPU-provided DTB already has the full command line. */ - UpdateBootArgs (); + Status =3D UpdateBootArgs (); + if (EFI_ERROR (Status)) { + Print (L"Failed to update boot arguments (error %d)\n", Status); + } } =20 DEBUG ((DEBUG_INFO, "Installed FDT is at %p\n", mFdtImage)); --=20 2.21.0