From patchwork Tue May 5 14:48:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 48042 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 15B5E20553 for ; Tue, 5 May 2015 14:49:09 +0000 (UTC) Received: by lbbqq2 with SMTP id qq2sf51248311lbb.0 for ; Tue, 05 May 2015 07:49:06 -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=KtXRNfaCplO+aR0og//UDkeho/6NlhHiHk+NMe+WMEU=; b=EgotBHEqSUvj5cPdnqJ70PuIle9JOVXRLWcMD9Tr4ApysghO3PwH2oBFT8sYj0qLUa vYwHr5QM4+LFJKRf+QFY6EhT0mHd7yUuVVCfLvNGeLdkT///UF3sifI1cvp6/Q6KgrPs 0IXg5IRplKsXsTVnApAoBkC/9MPyjwnnAjv2GSFttrzEUXRkjputR4xvVn8vtLC+lv/L C6IQj/NN/ts/udw1qXactlDsCft1IyUhIJXEcEd5l8LtjK4v99N395xlp6HR/AwU8PgI IPxnVtmJvYPHc6fl0hCHpYfOS6MD+K2yJU3TPnkCYqA0AzsqX8i/ZTd0O75mURYdxaHH yvkg== X-Gm-Message-State: ALoCoQlELokem/m3PWVb68aA/Xzm5qsaSEbwa2oWaVyPHe/Quqk01PzXFMkWweomX7gSexpQ5qkc X-Received: by 10.112.189.131 with SMTP id gi3mr22461800lbc.6.1430837346579; Tue, 05 May 2015 07:49:06 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.44.135 with SMTP id e7ls1001341lam.79.gmail; Tue, 05 May 2015 07:49:06 -0700 (PDT) X-Received: by 10.152.5.39 with SMTP id p7mr24180350lap.18.1430837346432; Tue, 05 May 2015 07:49:06 -0700 (PDT) Received: from mail-lb0-f175.google.com (mail-lb0-f175.google.com. [209.85.217.175]) by mx.google.com with ESMTPS id i6si12626795lbj.60.2015.05.05.07.49.06 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 May 2015 07:49:06 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.175 as permitted sender) client-ip=209.85.217.175; Received: by lbbzk7 with SMTP id zk7so130443455lbb.0 for ; Tue, 05 May 2015 07:49:06 -0700 (PDT) X-Received: by 10.152.2.227 with SMTP id 3mr24024665lax.73.1430837346260; Tue, 05 May 2015 07:49:06 -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 l1csp2294660lbt; Tue, 5 May 2015 07:49:05 -0700 (PDT) X-Received: by 10.42.129.73 with SMTP id p9mr32698953ics.48.1430837344578; Tue, 05 May 2015 07:49:04 -0700 (PDT) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id dp6si13078207icb.85.2015.05.05.07.49.03 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 05 May 2015 07:49:04 -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 1Ype9Y-0006Hm-2i; Tue, 05 May 2015 14:48:56 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1Ype9W-0006Hg-Hr for edk2-devel@lists.sourceforge.net; Tue, 05 May 2015 14:48:54 +0000 Received-SPF: pass (sog-mx-1.v43.ch3.sourceforge.com: domain of linaro.org designates 209.85.212.174 as permitted sender) client-ip=209.85.212.174; envelope-from=ard.biesheuvel@linaro.org; helo=mail-wi0-f174.google.com; Received: from mail-wi0-f174.google.com ([209.85.212.174]) by sog-mx-1.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1Ype9V-0002PA-6y for edk2-devel@lists.sourceforge.net; Tue, 05 May 2015 14:48:54 +0000 Received: by wief7 with SMTP id f7so103180347wie.0 for ; Tue, 05 May 2015 07:48:47 -0700 (PDT) X-Received: by 10.180.82.135 with SMTP id i7mr4936575wiy.68.1430837327225; Tue, 05 May 2015 07:48:47 -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 fs9sm25926124wjc.34.2015.05.05.07.48.45 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 05 May 2015 07:48:46 -0700 (PDT) From: Ard Biesheuvel To: olivier.martin@arm.com, edk2-devel@lists.sourceforge.net, ronald.cron@arm.com Date: Tue, 5 May 2015 16:48:34 +0200 Message-Id: <1430837315-7388-5-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1430837315-7388-1-git-send-email-ard.biesheuvel@linaro.org> References: <1430837315-7388-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: 1Ype9V-0002PA-6y Subject: [edk2] [PATCH 4/5] 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.217.175 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..8c42814a04dc 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,95 @@ 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; + } + + 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 +160,7 @@ ArmFvpInitialise ( CHAR16 *TextDevicePath; UINTN TextDevicePathSize; VOID *Buffer; + EFI_DEVICE_PATH *FdtDevicePath; Status = gBS->InstallProtocolInterface (&ImageHandle, &gEfiDevicePathProtocolGuid, EFI_NATIVE_INTERFACE, @@ -76,13 +171,25 @@ ArmFvpInitialise ( Status = ArmVExpressGetPlatform (&Platform); if (!EFI_ERROR (Status)) { - TextDevicePathSize = StrSize ((CHAR16*)PcdGetPtr (PcdFvpFdtDevicePathsBase)) - sizeof (CHAR16); - TextDevicePathSize += StrSize (Platform->FdtName); - - TextDevicePath = AllocatePool (TextDevicePathSize); + FdtDevicePath = NULL; + 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