From patchwork Tue May 5 11:17:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 48022 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 65FB92121F for ; Tue, 5 May 2015 11:17:43 +0000 (UTC) Received: by lbbqq2 with SMTP id qq2sf49417208lbb.0 for ; Tue, 05 May 2015 04:17:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:reply-to:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :content-type:content-transfer-encoding:errors-to:x-original-sender :x-original-authentication-results:mailing-list; bh=ylKguoiUNRoS/qGZN8fArPdjhIOVBBUxio45GWLK5XY=; b=FmbCo/UHzV3diCk54eBiL+hiYieVFyFPmkcWk/KbF5KrNLw0b25wS2F9CUyAwPcl74 /x9nDDklz0ghGTVyjpezTQ4+hm6dfZuNzlajRJ2BjEx76UKRbvG7eT6TgmxmayoyKzgX Sso/C5T9Amme0Ol+E0fAwklNrtmOoucnGF6A7hL+j7fZ6aArCn23+hKdFYaZ4Ljv/h4H wlpgA4iIn2Cl8hXenKdCmTVKZC9iNXXRdfDQXtsgmlMcFIN215Bvn8m+ADjkR6wosLL7 841xT8bAv30ikeoFDAI9WpXqh8sp2fsuNXI5c4LkMRQf21B/qNZ1KGQdtxPWDuP3CI+h ce0A== X-Gm-Message-State: ALoCoQnEZJ0CMK5q0ITAO6E2DWP5BobG2sXkaWB5RTolLHMwg4YdZ6m4viWOtXSxBMKJftFer9ay X-Received: by 10.180.86.226 with SMTP id s2mr362823wiz.0.1430824662298; Tue, 05 May 2015 04:17:42 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.2.9 with SMTP id 9ls978860laq.89.gmail; Tue, 05 May 2015 04:17:42 -0700 (PDT) X-Received: by 10.152.2.227 with SMTP id 3mr23231459lax.73.1430824662130; Tue, 05 May 2015 04:17:42 -0700 (PDT) Received: from mail-la0-f52.google.com (mail-la0-f52.google.com. [209.85.215.52]) by mx.google.com with ESMTPS id et1si12212356lac.11.2015.05.05.04.17.42 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 May 2015 04:17:42 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.52 as permitted sender) client-ip=209.85.215.52; Received: by laat2 with SMTP id t2so124660471laa.1 for ; Tue, 05 May 2015 04:17:42 -0700 (PDT) X-Received: by 10.112.16.196 with SMTP id i4mr23184181lbd.72.1430824662022; Tue, 05 May 2015 04:17:42 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.67.65 with SMTP id l1csp2179444lbt; Tue, 5 May 2015 04:17:41 -0700 (PDT) X-Received: by 10.50.88.71 with SMTP id be7mr1220112igb.20.1430824658664; Tue, 05 May 2015 04:17:38 -0700 (PDT) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id m3si12428763iod.50.2015.05.05.04.17.37 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 05 May 2015 04:17:38 -0700 (PDT) Received-SPF: pass (google.com: domain of edk2-devel-bounces@lists.sourceforge.net designates 216.34.181.88 as permitted sender) client-ip=216.34.181.88; Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1Ypaqs-0003On-Ab; Tue, 05 May 2015 11:17:26 +0000 Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1Ypaqr-0003Oh-3H for edk2-devel@lists.sourceforge.net; Tue, 05 May 2015 11:17:25 +0000 Received-SPF: pass (sog-mx-2.v43.ch3.sourceforge.com: domain of linaro.org designates 74.125.82.50 as permitted sender) client-ip=74.125.82.50; envelope-from=ard.biesheuvel@linaro.org; helo=mail-wg0-f50.google.com; Received: from mail-wg0-f50.google.com ([74.125.82.50]) by sog-mx-2.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1Ypaqp-0003i6-TZ for edk2-devel@lists.sourceforge.net; Tue, 05 May 2015 11:17:25 +0000 Received: by wgso17 with SMTP id o17so179138232wgs.1 for ; Tue, 05 May 2015 04:17:17 -0700 (PDT) X-Received: by 10.194.77.180 with SMTP id t20mr51301417wjw.115.1430824637915; Tue, 05 May 2015 04:17:17 -0700 (PDT) Received: from localhost.localdomain (cag06-7-83-153-85-71.fbx.proxad.net. [83.153.85.71]) by mx.google.com with ESMTPSA id g8sm17443092wjn.18.2015.05.05.04.17.16 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 05 May 2015 04:17:17 -0700 (PDT) From: Ard Biesheuvel To: olivier.martin@arm.com, leif.lindholm@linaro.org, roy.franz@linaro.org, edk2-devel@lists.sourceforge.net Date: Tue, 5 May 2015 13:17:04 +0200 Message-Id: <1430824625-26772-4-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1430824625-26772-1-git-send-email-ard.biesheuvel@linaro.org> References: <1430824625-26772-1-git-send-email-ard.biesheuvel@linaro.org> X-Spam-Score: -1.5 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_PASS SPF: sender matches SPF record -0.0 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1Ypaqp-0003i6-TZ Subject: [edk2] [PATCH 3/4] ArmPlatformPkg: add support for FV embedded device tree blobs X-BeenThere: edk2-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list Reply-To: edk2-devel@lists.sourceforge.net List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.sourceforge.net X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.52 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 This adds support to the ArmVExpressPkg platforms to load their device tree binary from a Firmware Volume if one is found that matches the current platform. If none is found, the existing logic to find a FDT by name from a file system is retained as a fallback. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmFvpDxe.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmFvpDxe.inf | 5 ++++ 2 files changed, 118 insertions(+), 6 deletions(-) diff --git a/ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmFvpDxe.c b/ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmFvpDxe.c index 9a60f1d611d4..95d292084e1f 100644 --- a/ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmFvpDxe.c +++ b/ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmFvpDxe.c @@ -14,9 +14,14 @@ #include "ArmVExpressInternal.h" +#include +#include #include #include #include +#include + +#include #define ARM_FVP_BASE_VIRTIO_BLOCK_BASE 0x1c130000 @@ -50,6 +55,96 @@ VIRTIO_BLK_DEVICE_PATH mVirtioBlockDevicePath = } }; +STATIC +EFI_STATUS +InternalFindFdtByGuid ( + IN OUT EFI_DEVICE_PATH **FdtDevicePath, + IN CONST EFI_GUID *FdtGuid + ) +{ + MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileDevicePath; + EFI_HANDLE *HandleBuffer; + UINTN HandleCount; + UINTN Index; + EFI_FIRMWARE_VOLUME2_PROTOCOL *FvProtocol; + EFI_GUID NameGuid; + UINTN Size; + VOID *Key; + EFI_FV_FILETYPE FileType; + EFI_FV_FILE_ATTRIBUTES Attributes; + EFI_DEVICE_PATH *FvDevicePath; + EFI_STATUS Status; + + if (FdtGuid == NULL) { + return EFI_NOT_FOUND; + } + + *FdtDevicePath = NULL; + EfiInitializeFwVolDevicepathNode (&FileDevicePath, FdtGuid); + + HandleBuffer = NULL; + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiFirmwareVolume2ProtocolGuid, + NULL, + &HandleCount, + &HandleBuffer + ); + if (EFI_ERROR (Status)) { + return Status; + } + + for (Index = 0; Index < HandleCount; Index++) { + Status = gBS->HandleProtocol ( + HandleBuffer[Index], + &gEfiFirmwareVolume2ProtocolGuid, + (VOID **) &FvProtocol + ); + if (EFI_ERROR (Status)) { + return Status; + } + + // Allocate Key + Key = AllocatePool (FvProtocol->KeySize); + ASSERT (Key != NULL); + ZeroMem (Key, FvProtocol->KeySize); + + do { + FileType = EFI_FV_FILETYPE_RAW; + Status = FvProtocol->GetNextFile (FvProtocol, Key, &FileType, &NameGuid, &Attributes, &Size); + if (Status == EFI_NOT_FOUND) { + break; + } + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Check whether this file is the one we are looking for. If so, + // create a device path for it and return it to the caller. + // + if (CompareGuid (&NameGuid, FdtGuid)) { + Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiDevicePathProtocolGuid, (VOID **)&FvDevicePath); + if (!EFI_ERROR (Status)) { + *FdtDevicePath = AppendDevicePathNode (FvDevicePath, + (EFI_DEVICE_PATH_PROTOCOL *)&FileDevicePath); + } + goto Done; + } + } while (TRUE); + FreePool (Key); + } + + if (Index == HandleCount) { + Status = EFI_NOT_FOUND; + } + return Status; + +Done: + FreePool (Key); + return Status; +} + /** * Generic UEFI Entrypoint for 'ArmFvpDxe' driver * See UEFI specification for the details of the parameters @@ -66,6 +161,7 @@ ArmFvpInitialise ( CHAR16 *TextDevicePath; UINTN TextDevicePathSize; VOID *Buffer; + EFI_DEVICE_PATH *FdtDevicePath; Status = gBS->InstallProtocolInterface (&ImageHandle, &gEfiDevicePathProtocolGuid, EFI_NATIVE_INTERFACE, @@ -76,13 +172,24 @@ ArmFvpInitialise ( Status = ArmVExpressGetPlatform (&Platform); if (!EFI_ERROR (Status)) { - TextDevicePathSize = StrSize ((CHAR16*)PcdGetPtr (PcdFvpFdtDevicePathsBase)) - sizeof (CHAR16); - TextDevicePathSize += StrSize (Platform->FdtName); - - TextDevicePath = AllocatePool (TextDevicePathSize); + Status = InternalFindFdtByGuid (&FdtDevicePath, Platform->FdtGuid); + if (!EFI_ERROR (Status)) { + TextDevicePath = ConvertDevicePathToText (FdtDevicePath, FALSE, FALSE); + if (TextDevicePath != NULL) { + TextDevicePathSize = StrSize (TextDevicePath); + } + FreePool (FdtDevicePath); + } else { + TextDevicePathSize = StrSize ((CHAR16*)PcdGetPtr (PcdFvpFdtDevicePathsBase)) - sizeof (CHAR16); + TextDevicePathSize += StrSize (Platform->FdtName); + + TextDevicePath = AllocatePool (TextDevicePathSize); + if (TextDevicePath != NULL) { + StrCpy (TextDevicePath, ((CHAR16*)PcdGetPtr (PcdFvpFdtDevicePathsBase))); + StrCat (TextDevicePath, Platform->FdtName); + } + } if (TextDevicePath != NULL) { - StrCpy (TextDevicePath, ((CHAR16*)PcdGetPtr (PcdFvpFdtDevicePathsBase))); - StrCat (TextDevicePath, Platform->FdtName); Buffer = PcdSetPtr (PcdFdtDevicePaths, &TextDevicePathSize, TextDevicePath); if (Buffer == NULL) { DEBUG (( diff --git a/ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmFvpDxe.inf b/ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmFvpDxe.inf index ec7a66552deb..dec627a38251 100644 --- a/ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmFvpDxe.inf +++ b/ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmFvpDxe.inf @@ -48,10 +48,15 @@ UefiDriverEntryPoint UefiBootServicesTableLib VirtioMmioDeviceLib + DevicePathLib [LibraryClasses.AARCH64] ArmGicLib +[Protocols] + gEfiFirmwareVolume2ProtocolGuid + gEfiDevicePathProtocolGuid + [FixedPcd] gArmVExpressTokenSpaceGuid.PcdFvpFdtDevicePathsBase