Jump to content

Compiling Jetson TX1/TX2 source code: Difference between revisions

Line 114: Line 114:


*[[Compiling_Tegra_X1_source_code#Getting_bootloader_and_kernel | Getting bootloader and kernel]]
*[[Compiling_Tegra_X1_source_code#Getting_bootloader_and_kernel | Getting bootloader and kernel]]
*[[Compiling_Tegra_X1_source_code#Toolchain | Getting Linaro toolchain]]


1) Specify the path to the toolchain:
2) Configure environment:


<pre>
<pre>
Line 123: Line 124:
export CROSS32CC=/opt/linaro/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc
export CROSS32CC=/opt/linaro/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc
export KERNEL_MODULES_OUT=$DEVDIR/images/modules
export KERNEL_MODULES_OUT=$DEVDIR/images/modules
export TEGRA_KERNEL_OUT=$DEVDIR/images
export ARCH=arm64
export ARCH=arm64
</pre>
</pre>


2) Clean your kernel and configuration
3) Clean your kernel and configuration
<pre>
<pre>
cd $DEVDIR/64_TX1/Linux_for_Tegra_64_tx1/sources/kernel_source/
cd $DEVDIR/sources/kernel/kernel-4.4
make mrproper
make mrproper
</pre>
</pre>


3) Apply following change to avoid [https://tls.mbed.org/kb/development/arm-thumb-error-r7-cannot-be-used-in-asm-here error: r7 cannot be used in asm here]
4) Apply the following patch from '''$DEVDIR/sources/kernel''' to fix build errors:


<pre>
<syntaxhighlight lang=diff>
Index: kernel_source/arch/arm64/kernel/vdso32/Makefile
---
kernel-4.4/drivers/devfreq/governor_pod_scaling.c            |    2 +-
kernel-4.4/drivers/devfreq/governor_wmark_active.c            |    2 +-
kernel-4.4/drivers/media/platform/tegra/mipical/vmipi/vmipi.c |    2 +-
nvgpu/drivers/gpu/nvgpu/Makefile.nvgpu                        |    1 +
nvgpu/drivers/gpu/nvgpu/common/linux/kmem.c                  |    2 +-
5 files changed, 5 insertions(+), 4 deletions(-)
 
Index: kernel/kernel-4.4/drivers/devfreq/governor_pod_scaling.c
===================================================================
--- kernel.orig/kernel-4.4/drivers/devfreq/governor_pod_scaling.c
+++ kernel/kernel-4.4/drivers/devfreq/governor_pod_scaling.c
@@ -51,7 +51,7 @@
#define CREATE_TRACE_POINTS
#include <trace/events/nvhost_podgov.h>
-#include <governor.h>
+#include "governor.h"
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
Index: kernel/kernel-4.4/drivers/devfreq/governor_wmark_active.c
===================================================================
--- kernel.orig/kernel-4.4/drivers/devfreq/governor_wmark_active.c
+++ kernel/kernel-4.4/drivers/devfreq/governor_wmark_active.c
@@ -23,7 +23,7 @@
#include <linux/platform_device.h>
#include <linux/module.h>
-#include <governor.h>
+#include "governor.h"
struct wmark_gov_info {
/* probed from the devfreq */
Index: kernel/nvgpu/drivers/gpu/nvgpu/Makefile.nvgpu
===================================================================
--- kernel.orig/nvgpu/drivers/gpu/nvgpu/Makefile.nvgpu
+++ kernel/nvgpu/drivers/gpu/nvgpu/Makefile.nvgpu
@@ -1,5 +1,6 @@
GCOV_PROFILE := y
+ccflags-y += -I$(srctree)/../nvgpu/drivers/gpu/nvgpu/
ccflags-y += -Idrivers/gpu/nvgpu/include
ccflags-y += -Idrivers/video/tegra/host
ccflags-y += -Idrivers/devfreq
Index: kernel/nvgpu/drivers/gpu/nvgpu/common/linux/kmem.c
===================================================================
--- kernel.orig/nvgpu/drivers/gpu/nvgpu/common/linux/kmem.c
+++ kernel/nvgpu/drivers/gpu/nvgpu/common/linux/kmem.c
@@ -27,7 +27,7 @@
#include <nvgpu/kmem.h>
-#include "gk20a/gk20a.h"
+#include <gk20a/gk20a.h>
#include "kmem_priv.h"
Index: kernel/kernel-4.4/drivers/media/platform/tegra/mipical/vmipi/vmipi.c
===================================================================
===================================================================
--- kernel_source.orig/arch/arm64/kernel/vdso32/Makefile        2016-04-08 21:28:52.651992663 -0600
--- kernel.orig/kernel-4.4/drivers/media/platform/tegra/mipical/vmipi/vmipi.c
+++ kernel_source/arch/arm64/kernel/vdso32/Makefile    2016-04-11 12:20:03.377388110 -0600
+++ kernel/kernel-4.4/drivers/media/platform/tegra/mipical/vmipi/vmipi.c
@@ -11,7 +11,7 @@
@@ -24,7 +24,7 @@
#include <linux/wait.h>
#include <linux/tegra-ivc.h>
   
   
  GCOV_PROFILE := n
-#include "mipi_cal.h"
+#include "../mipi_cal.h"
  #include "vmipi.h"
   
   
-ccflags-y := -shared -fPIC -fno-common -fno-builtin -march=armv7-a
  const char *tegra_vmipi_cmd[] = {
+ccflags-y := -shared -fPIC -fomit-frame-pointer -fno-common -fno-builtin -march=armv7-a
ccflags-y += -nostdlib -Wl,-soname=linux-vdso32.so.1 \
                $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
  asflags-y := -D__VDSO32__ -s


</pre>
</syntaxhighlight>


4) Apply following change to avoid [https://devtalk.nvidia.com/default/topic/894945/jetson-tx1/jetson-tx1/11 error: logical not is only applied to the left hand side of comparison]
5) Configure your kernel


* '''For TX1'''
<pre>
<pre>
Index: kernel_source/drivers/platform/tegra/tegra21_clocks.c
make O=$TEGRA_KERNEL_OUT tegra21_defconfig
===================================================================
make O=$TEGRA_KERNEL_OUT menuconfig
--- kernel_source.orig/drivers/platform/tegra/tegra21_clocks.c  2016-04-08 21:28:58.755992489 -0600
+++ kernel_source/drivers/platform/tegra/tegra21_clocks.c      2016-04-11 12:49:59.561337028 -0600
@@ -1062,7 +1062,7 @@
  */
static void tegra21_cpu_clk_init(struct clk *c)
{
-      c->state = (!is_lp_cluster() == (c->u.cpu.mode == MODE_G)) ? ON : OFF;
+      c->state = ((!is_lp_cluster()) == (c->u.cpu.mode == MODE_G)) ? ON : OFF;
}
static int tegra21_cpu_clk_enable(struct clk *c)
</pre>
</pre>


5) Configure your kernel
* '''For TX2'''
 
<pre>
<pre>
make tegra21_defconfig
make O=$TEGRA_KERNEL_OUT tegra18_defconfig
make menuconfig
make O=$TEGRA_KERNEL_OUT menuconfig
</pre>
</pre>


6) Compile kernel, device tree and modules
6) Compile kernel, device tree and modules
<pre>
<pre>
make zImage
make O=$TEGRA_KERNEL_OUT zImage
make dtbs
make O=$TEGRA_KERNEL_OUT dtbs
make modules
make O=$TEGRA_KERNEL_OUT modules
make modules_install INSTALL_MOD_PATH=$KERNEL_MODULES_OUT
make O=$TEGRA_KERNEL_OUT modules_install INSTALL_MOD_PATH=$KERNEL_MODULES_OUT
</pre>
</pre>


7) Save your binaries in the images directory
After this the kernel image will be under:
 
<pre>
<pre>
cp arch/arm64/boot/Image arch/arm64/boot/zImage $DEVDIR/images/
$DEVDIR/images/arch/arm64/boot/Image
</pre>
</pre>


8) Create kernel_supplements.tbz2 with kernel modules, this package is needed by Jetpack
And the devicetree under:
 
<pre>
$DEVDIR/images/arch/arm64/boot/dts/*.dtb
</pre>
 
 
7) Create kernel_supplements.tbz2 with kernel modules, this package is needed by Jetpack


<pre>
<pre>
Line 199: Line 256:


<pre>
<pre>
export KERNEL_MODULES_NAME=3.10.96+
export KERNEL_MODULES_NAME=4.4.38+
</pre>
</pre>


Line 215: Line 272:
</pre>
</pre>


9) Besides creating the modules and the kernel image you need to create again your kernel_headers.tbz2 file (needed by Jetpack). By default when you patch the kernel code and you don't check your changes in the kernel will add a -dirty suffix to the release version (check ls $DEVDIR/images/modules/lib/modules/ for example). For this specific reason you need to generate your headers tarball again changing it the release version.
8) Besides creating the modules and the kernel image you need to create again your kernel_headers.tbz2 file (needed by Jetpack). By default when you patch the kernel code and you don't check your changes in the kernel will add a -dirty suffix to the release version (check ls $DEVDIR/images/modules/lib/modules/ for example). For this specific reason you need to generate your headers tarball again changing it the release version.


<pre>
<pre>
cd $DEVDIR/64_TX1/Linux_for_Tegra_64_tx1/kernel
cd $DEVDIR/kernel
tar -xf kernel_headers.tbz2
tar -xf kernel_headers.tbz2
tar -cjf kernel_headers_custom.tbz2 linux-headers-$KERNEL_MODULES_NAME
tar -cjf kernel_headers_custom.tbz2 linux-headers-$KERNEL_MODULES_NAME
Line 225: Line 282:
</pre>
</pre>


10) Create the dtb directory


9) Create a backup of the images and packages included in Jetpack
<pre>
<pre>
mkdir -p $DEVDIR/images/dtb
mkdir -p $DEVDIR/images/packages-backup
cp $DEVDIR/64_TX1/Linux_for_Tegra_64_tx1/sources/kernel_source/arch/arm64/boot/dts/*.dtb $DEVDIR/images/dtb/
cp -rf $DEVDIR/kernel/* $DEVDIR/images/packages-backup
</pre>
</pre>


11) Copy the Device Tree Compiler (DTC)
 
9) Copy your dtb
 
*'''TX1'''


<pre>
<pre>
cp $DEVDIR/64_TX1/Linux_for_Tegra_64_tx1/sources/kernel_source/scripts/dtc/dtc $DEVDIR/images/dtc
cp $DEVDIR/images/arch/arm64/boot/dts/tegra210-jetson-tx1-p2597-2180-a01-devkit.dtb $DEVDIR/kernel/dtb
</pre>
</pre>


12) Create a backup of the images and packages included in Jetpack
*'''TX2'''
 
<pre>
<pre>
mkdir -p $DEVDIR/images/packages-backup
cp $DEVDIR/images/arch/arm64/boot/dts/tegra186-quill-p3310-1000-c03-00-base.dtb $DEVDIR/kernel/dtb
cp -rf $DEVDIR/64_TX1/Linux_for_Tegra_64_tx1/kernel/* $DEVDIR/images/packages-backup
</pre>
</pre>


13) Finally overwrite the default images with your own images to install and boot them using jetpack
10) Finally overwrite the default images with your own images to install and boot them using jetpack


<pre>
<pre>
cd $DEVDIR/images
cd $DEVDIR/images
rm -rf $DEVDIR/64_TX1/Linux_for_Tegra_64_tx1/kernel/dtb
cp -rf arch/arm64/boot/Image arch/arm64/boot/zImage packages/kernel_supplements.tbz2 $DEVDIR/kernel/
cp -rf Image zImage packages/kernel_supplements.tbz2 dtb/ dtc $DEVDIR/64_TX1/Linux_for_Tegra_64_tx1/kernel/
cp -rf packages/kernel_headers_custom.tbz2 $DEVDIR/kernel/kernel_headers.tbz2
cp -rf packages/kernel_headers_custom.tbz2 $DEVDIR/64_TX1/Linux_for_Tegra_64_tx1/kernel/kernel_headers.tbz2
</pre>
</pre>


14) Run the applybinaries script to generate the image to flash
11) Run the applybinaries script to generate the image to flash


<pre>
<pre>
cd $DEVDIR/64_TX1/Linux_for_Tegra_64_tx1/
cd $DEVDIR/
sudo ./apply_binaries.sh  
sudo ./apply_binaries.sh  
</pre>
Output:
<pre>
Using rootfs directory of: /home/dsoto/devdirs/tegra/Jetpack/TX1/Linux_for_Tegra_tx1/rootfs
Extracting the NVIDIA user space components to /home/dsoto/devdirs/tegra/Jetpack/TX1/Linux_for_Tegra_tx1/rootfs
Extracting the BSP test tools to /home/dsoto/devdirs/tegra/Jetpack/TX1/Linux_for_Tegra_tx1/rootfs
Extracting the NVIDIA gst test applications to /home/dsoto/devdirs/tegra/Jetpack/TX1/Linux_for_Tegra_tx1/rootfs
Extracting the configuration files for the supplied root filesystem to /home/dsoto/devdirs/tegra/Jetpack/TX1/Linux_for_Tegra_tx1/rootfs
Creating a symbolic link nvgstplayer pointing to nvgstplayer-0.10
Creating a symbolic link nvgstcapture pointing to nvgstcapture-0.10
Adding symlink libcuda.so --> libcuda.so.1.1 in target rootfs
Adding symlink libGL.so --> libGL.so.1 in target rootfs
Adding symlink libcuda.so --> tegra/libcuda.so in target rootfs
Adding symlink libEGL.so --> libEGL.so.1 in target rootfs
Extracting the firmwares and kernel modules to /home/dsoto/devdirs/tegra/Jetpack/TX1/Linux_for_Tegra_tx1/rootfs
Extracting the kernel headers to /usr/src in target rootfs
Installing zImage into /boot in target rootfs
Installing Image into /boot in target rootfs
Installing the board *.dtb files into /boot in target rootfs
Success!
</pre>
</pre>


Cookies help us deliver our services. By using our services, you agree to our use of cookies.