From patchwork Sun Jan 18 12:11:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yann E. MORIN" X-Patchwork-Id: 430191 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from whitealder.osuosl.org (whitealder.osuosl.org [140.211.166.138]) by ozlabs.org (Postfix) with ESMTP id 68C5B1401DA for ; Sun, 18 Jan 2015 23:13:09 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id AD38F927D5; Sun, 18 Jan 2015 12:13:08 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id BQRTwLb9eZ7S; Sun, 18 Jan 2015 12:13:05 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by whitealder.osuosl.org (Postfix) with ESMTP id 9467C927DD; Sun, 18 Jan 2015 12:12:02 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from whitealder.osuosl.org (whitealder.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id 740051C2209 for ; Sun, 18 Jan 2015 12:11:57 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 6C20B927CB for ; Sun, 18 Jan 2015 12:11:57 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CC2an4hjBkov for ; Sun, 18 Jan 2015 12:11:53 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-wg0-f46.google.com (mail-wg0-f46.google.com [74.125.82.46]) by whitealder.osuosl.org (Postfix) with ESMTPS id D475A92799 for ; Sun, 18 Jan 2015 12:11:47 +0000 (UTC) Received: by mail-wg0-f46.google.com with SMTP id x13so27346576wgg.5 for ; Sun, 18 Jan 2015 04:11:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=FxDvSw/W2CebiZrwKgzs+ciSc+zcL5fV88WkMzpaE7I=; b=NjUz5KrRk5gfJ9oJlCvR2SA4nRKsMCe+m52/a1Wrv6aXJgPU24gU095IRCzGYqiClz 0WvW/lXHI71aCaJiZWpD88DyHL1SdxVrgXSW3Vb0ucxy5s+QPXIkJnMFxrI3r2SKwxAi qN83MpiORJGqL5vfQW/KMdqZzcpRMzfE1Cc6HA9T+T9KhFzkk7pWVvFnvQh6cxZhx0r0 QxXOlGzc21IrE7HU6CwSc4QnZPiEf01KRnl2Pau4SqrRS9j9TueUGwZsepz4yp8vIELA Okrs5SEYi4ub6gpmfJ1EqBkEkY6T7nvbYAPEUTBPZSNE4nhLk6G+EN/MX/Wxm4ABih17 FBxA== X-Received: by 10.194.92.116 with SMTP id cl20mr49131014wjb.71.1421583106540; Sun, 18 Jan 2015 04:11:46 -0800 (PST) Received: from gourin.bzh.lan (ks3095497.kimsufi.com. [94.23.60.27]) by mx.google.com with ESMTPSA id l9sm10070685wic.21.2015.01.18.04.11.44 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 18 Jan 2015 04:11:45 -0800 (PST) From: "Yann E. MORIN" To: buildroot@buildroot.org Date: Sun, 18 Jan 2015 13:11:29 +0100 Message-Id: <5f4728834d3e57ab22f10d1c2042a1b4e94f4628.1421582718.git.yann.morin.1998@free.fr> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: Cc: "Yann E. MORIN" Subject: [Buildroot] [PATCH 07/11 v4] package/nvidia-driver: build the kernel module X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" Add option to build the nvidia.ko module. If CUDA is enabled on x86_64, also build the nvidia-uvm.ko kernel module (for Unified Memory access), which is required by the CUDA user-land library. Substancially inspired by the corresponding Gentoo ebuild: http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/x11-drivers/nvidia-drivers/nvidia-drivers-340.32.ebuild?revision=1.2&view=markup Signed-off-by: "Yann E. MORIN" --- package/nvidia-driver/Config.in | 14 ++++++++++ package/nvidia-driver/nvidia-driver.mk | 50 ++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/package/nvidia-driver/Config.in b/package/nvidia-driver/Config.in index 071e85e..845746e 100644 --- a/package/nvidia-driver/Config.in +++ b/package/nvidia-driver/Config.in @@ -48,4 +48,18 @@ config BR2_PACKAGE_NVIDIA_DRIVER_PRIVATE_LIBS Say 'y' here if you plan on running a program that uses those private libraries. +comment "nvidia kernel module needs a kernel to be built" + depends on !BR2_LINUX_KERNEL + +config BR2_PACKAGE_NVIDIA_DRIVER_MODULE + bool "nvidia kernel module" + depends on BR2_LINUX_KERNEL + help + Build the nvidia.ko kernel module. + + If CUDA support (above) is set, and the target is x86_64, then + this will also build the nvidia-uvm.ko kernel module, which + provides Unified Memory access to the GPU and CPU memories for + CUDA programs. + endif # BR2_PACKAGE_NVIDIA_DRIVER diff --git a/package/nvidia-driver/nvidia-driver.mk b/package/nvidia-driver/nvidia-driver.mk index a2e3500..32715e4 100644 --- a/package/nvidia-driver/nvidia-driver.mk +++ b/package/nvidia-driver/nvidia-driver.mk @@ -65,6 +65,55 @@ define NVIDIA_DRIVER_EXTRACT_CMDS rm -rf $(@D)/tmp-extract endef +# Build and install the kernel modules if needed +ifeq ($(BR2_PACKAGE_NVIDIA_DRIVER_MODULE),y) + +NVIDIA_DRIVER_DEPENDENCIES += linux + +# NVidia uses the legacy naming scheme for the x86 architecture, when i386 +# and x86_64 were still considered two separate architectures in the Linux +# kernel. +NVIDIA_DRIVER_ARCH = $(if $(BR2_i386),i386,$(BR2_ARCH)) + +NVIDIA_DRIVER_MOD_DIRS = kernel +NVIDIA_DRIVER_MOD_FILES = kernel/nvidia.ko +# nvidia-uvm.ko only available for x86_64 +ifeq ($(BR2_x86_64)$(BR2_PACKAGE_NVIDIA_DRIVER_CUDA),yy) +NVIDIA_DRIVER_MOD_DIRS += kernel/uvm +NVIDIA_DRIVER_MOD_FILES += kernel/uvm/nvidia-uvm.ko +endif + +# We can not use '$(MAKE) -C $(@D)/$${dir}' because NVidia's uses its own +# Makefile to build a kernel module, which includes a lot of assumptions +# on where to find its own sub-Makefile fragments, and fails if make is +# not run from the directory where the module's source files are. Hence +# our little trick to cd in there first. +# That's also the reason why we do not use LINUX_MAKE_FLAGS or the other +# linux-specific variables, since NVidia's Makefile does not understand +# them. +define NVIDIA_DRIVER_BUILD_CMDS + for dir in $(NVIDIA_DRIVER_MOD_DIRS); do \ + ( cd $(@D)/$${dir} && \ + $(MAKE) SYSSRC=$(LINUX_DIR) SYSOUT=$(LINUX_DIR) \ + CC=$(TARGET_CC) LD=$(TARGET_LD) HOSTCC=$(HOSTCC) \ + ARCH=$(NVIDIA_DRIVER_ARCH) module ) || exit 1; \ + done +endef + +# We do not use module-install because NVidia's Makefile requires root. +# Also, we do not install it in the expected location (in nvidia/ rather +# than in kernel/drivers/video/ ) +define NVIDIA_DRIVER_INSTALL_KERNEL_MODULE + for mod in $(NVIDIA_DRIVER_MOD_FILES); do \ + $(INSTALL) -D -m 0644 $(@D)/$${mod} \ + $(TARGET_DIR)/lib/modules/$(LINUX_VERSION_PROBED)/nvidia/$${mod##*/} \ + || exit 1; \ + done + $(HOST_DIR)/sbin/depmod -a -b $(TARGET_DIR) $(LINUX_VERSION_PROBED) +endef + +endif # BR2_PACKAGE_NVIDIA_DRIVER_MODULE == y + # Helper to install libraries # $1: destination directory (target or staging) # @@ -105,6 +154,7 @@ define NVIDIA_DRIVER_INSTALL_TARGET_CMDS $(INSTALL) -D -m 0644 $(@D)/$${m##*/} \ $(TARGET_DIR)/usr/lib/xorg/modules/$${m}; \ done + $(NVIDIA_DRIVER_INSTALL_KERNEL_MODULE) endef $(eval $(generic-package))