Compiling Jetson TX1/TX2 source code: Difference between revisions

no edit summary
No edit summary
Line 3: Line 3:
= Introduction =
= Introduction =


In this wiki page you are going to find the instructions to download the source code to rebuild the Jetson TX1/TX2 images using jetpack, several parts of this wiki were based in the document called Start_L4T_Docs.html given by Nvidia in L4T. This page should be considered a work in progress. These steps were run on Jetson TX1 and TX2 and Jetpack 3.1 was used.<br>
In this wiki page you are going to find the instructions to download the source code to rebuild the Jetson TX1/TX2 images using jetpack, several parts of this wiki were based in the document called Start_L4T_Docs.html given by Nvidia in L4T. This page should be considered a work in progress. These steps were run on Jetson TX1 and TX2 and Jetpack 3.2 was used.<br>


You can get the documentation from [https://developer.nvidia.com/embedded/dlc/l4t-documentation-28-1 nvl4t_docs].
You can get the documentation from [https://developer.nvidia.com/embedded/dlc/l4t-documentation-28-2 nvl4t_docs].




Line 20: Line 20:
= Downloading the code =
= Downloading the code =


In order to be able to download the source code you should have Jetpack  installed, if you already have it, skip the next section and go to [[Compiling_Tegra_X1_source_code#Getting_bootloader_and_kernel|Getting bootloader and kernel]].
In order to be able to download the source code you should have Jetpack  installed, if you already have it, skip the next section and go to [[Compiling_Jetpack_3.2_source_code#Getting_bootloader_and_kernel|Getting bootloader and kernel]].


== Getting JetPack ==
== Getting JetPack ==
Line 26: Line 26:
Check which is [https://developer.nvidia.com/embedded/jetpack the most recent JetPack release].
Check which is [https://developer.nvidia.com/embedded/jetpack the most recent JetPack release].


'''1.''' Download Jetpack 3.1 from: https://developer.nvidia.com/embedded/dlc/jetpack-l4t-3_1
'''1.''' Download Jetpack 3.2 from: https://developer.nvidia.com/embedded/dlc/jetpack-l4t-3_2-ga


'''2.''' Move binary into installation directory, we recommend '''/home/$USER/JetPack-L4T-3.1'''
'''2.''' Move binary into installation directory, we recommend '''/home/$USER/JetPack-L4T-3.2'''


<pre>
<pre>
mkdir -p /home/$USER/JetPack-L4T-3.1
mkdir -p /home/$USER/JetPack-L4T-3.2
mv JetPack-L4T-3.1-linux-x64.run /home/$USER/JetPack-L4T-3.1/
mv JetPack-L4T-3.2-linux-x64_b196.run /home/$USER/JetPack-L4T-3.2/
</pre>
</pre>


Line 38: Line 38:


<pre>
<pre>
cd /home/$USER/JetPack-L4T-3.1
cd /home/$USER/JetPack-L4T-3.2
chmod +x JetPack-L4T-3.1-linux-x64.run
chmod +x JetPack-L4T-3.2-linux-x64_b196.run
</pre>
</pre>


Line 45: Line 45:


<pre>
<pre>
./JetPack-L4T-3.1-linux-x64.run
./JetPack-L4T-3.2-linux-x64_b196.run
</pre>
</pre>


'''5.''' Follow the instructions. You'll be prompted for a devkit to build for (TX1, TX2, TK1) just select the one you want.
'''5.''' Follow the instructions. You'll be prompted for a devkit to build for (TX1, TX2, TX2i) just select the one you want.


== Getting bootloader and kernel ==
== Getting bootloader and kernel ==
Line 57: Line 57:
* '''For TX1'''
* '''For TX1'''
<pre>
<pre>
export DEVDIR=$HOME/JetPack-L4T-3.1/64_TX1/Linux_for_Tegra_64_tx1
export DEVDIR=$HOME/JetPack-L4T-3.2/64_TX1/Linux_for_Tegra
</pre>
</pre>


Line 63: Line 63:
* '''For TX2'''
* '''For TX2'''
<pre>
<pre>
export DEVDIR=$HOME/JetPack-L4T-3.1/64_TX2/Linux_for_Tegra_tx2
export DEVDIR=$HOME/JetPack-L4T-3.2/64_TX2/Linux_for_Tegra
</pre>
</pre>


Line 80: Line 80:
This will download the bootloader and kernel.  
This will download the bootloader and kernel.  


When syncing, you'll be asked for a tag, lets use '''tegra-l4t-r28.1''' for both Kernel and uboot.
When syncing, you'll be asked for a tag, lets use '''tegra-l4t-r28.2''' for both Kernel and uboot.


= Toolchain =
= Toolchain =
Line 127: Line 127:
</pre>
</pre>


3) Create and apply the necessary patches
3) Clean your kernel and configuration
 
3.a) Go to the sources directory:
 
<pre>
cd $DEVDIR/sources/
</pre>
 
3.b) Create a patches folder:
 
<pre>
mkdir patches
cd patches
</pre>
 
3.c) Create a '''0001-fix_build_errors.patch''' file
 
<pre>
touch 0001-fix_build_errors.patch
</pre>
 
and paste the following content on it:
 
<syntaxhighlight lang=diff>
---
kernel/kernel-4.4/drivers/devfreq/governor_pod_scaling.c            |    2 +-
kernel/kernel-4.4/drivers/devfreq/governor_wmark_active.c            |    2 +-
kernel/kernel-4.4/drivers/media/platform/tegra/mipical/vmipi/vmipi.c |    2 +-
kernel/nvgpu/drivers/gpu/nvgpu/Makefile.nvgpu                        |    1 +
kernel/nvgpu/drivers/gpu/nvgpu/common/linux/kmem.c                  |    2 +-
5 files changed, 5 insertions(+), 4 deletions(-)
 
Index: sources/kernel/kernel-4.4/drivers/devfreq/governor_pod_scaling.c
===================================================================
--- sources.orig/kernel/kernel-4.4/drivers/devfreq/governor_pod_scaling.c
+++ sources/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: sources/kernel/kernel-4.4/drivers/devfreq/governor_wmark_active.c
===================================================================
--- sources.orig/kernel/kernel-4.4/drivers/devfreq/governor_wmark_active.c
+++ sources/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: sources/kernel/nvgpu/drivers/gpu/nvgpu/Makefile.nvgpu
===================================================================
--- sources.orig/kernel/nvgpu/drivers/gpu/nvgpu/Makefile.nvgpu
+++ sources/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: sources/kernel/nvgpu/drivers/gpu/nvgpu/common/linux/kmem.c
===================================================================
--- sources.orig/kernel/nvgpu/drivers/gpu/nvgpu/common/linux/kmem.c
+++ sources/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: sources/kernel/kernel-4.4/drivers/media/platform/tegra/mipical/vmipi/vmipi.c
===================================================================
--- sources.orig/kernel/kernel-4.4/drivers/media/platform/tegra/mipical/vmipi/vmipi.c
+++ sources/kernel/kernel-4.4/drivers/media/platform/tegra/mipical/vmipi/vmipi.c
@@ -24,7 +24,7 @@
#include <linux/wait.h>
#include <linux/tegra-ivc.h>
-#include "mipi_cal.h"
+#include "../mipi_cal.h"
#include "vmipi.h"
const char *tegra_vmipi_cmd[] = {
 
</syntaxhighlight>
 
3.d) Create a '''series''' file:
 
<pre>
touch series
</pre>
 
and paste the following content on it:
 
<pre>
0001-fix_build_errors.patch
 
</pre>
 
'''Note:''' Make sure you have an empty line at the end of the file
 
3.e) Apply the patch:
 
<pre>
cd $DEVDIR/sources/
quilt push -a
</pre>
 
'''Note:''' If you don't have quilt installed you can get it by running:
 
<pre>
sudo apt-get install quilt
</pre>
 
4) Clean your kernel and configuration
<pre>
<pre>
cd $DEVDIR/sources/kernel/kernel-4.4
cd $DEVDIR/sources/kernel/kernel-4.4
Line 259: Line 133:
</pre>
</pre>


5) Configure your kernel:
4) Configure your kernel:


This commands will set the default configuration and open a menu so you can change any of the setting if needed. If not, you can just hit '''exit''' after the menu opens.
This commands will set the default configuration and open a menu so you can change any of the setting if needed. If not, you can just hit '''exit''' after the menu opens.
Line 281: Line 155:
</pre>
</pre>


6) Compile kernel, device tree and modules
5) Compile kernel, device tree and modules
<pre>
<pre>
make O=$TEGRA_KERNEL_OUT zImage
make O=$TEGRA_KERNEL_OUT zImage
Line 302: Line 176:




7) Create kernel_supplements.tbz2 with kernel modules, this package is needed by Jetpack
6) Create kernel_supplements.tbz2 with kernel modules, this package is needed by Jetpack


<pre>
<pre>
Line 328: Line 202:
</pre>
</pre>


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.
7) 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>
Line 356: Line 230:




9) Create a backup of the images and packages included in Jetpack
8) Create a backup of the images and packages included in Jetpack
<pre>
<pre>
mkdir -p $DEVDIR/images/packages-backup
mkdir -p $DEVDIR/images/packages-backup
Line 363: Line 237:




10) Copy your dtb
9) Copy your dtb


*'''TX1'''
*'''TX1'''
Line 377: Line 251:
</pre>
</pre>


11) 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>
Line 385: Line 259:
</pre>
</pre>


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


<pre>
<pre>
Line 406: Line 280:
<pre>
<pre>
cd $DEVDIR/../../
cd $DEVDIR/../../
./JetPack-L4T-3.1-linux-x64.run
JetPack-L4T-3.2-linux-x64_b196.run
</pre>
</pre>


Line 492: Line 366:


<pre>
<pre>
cd $DEVDIR/TX1/Linux_for_Tegra_tx1/sources
cd $DEVDIR/sources
git clone git://git.kernel.org/pub/scm/utils/dtc/dtc.git
git clone git://git.kernel.org/pub/scm/utils/dtc/dtc.git
cd dtc
cd dtc
Line 501: Line 375:
== Build u-boot ==
== Build u-boot ==


1. Backup original uboot files. You see which platform you are using checking the file in $DEVDIR/TX1/Linux_for_Tegra_tx1/jetson-tx1.conf, it says:
1. Backup original uboot files. You see which platform you are using checking the file in $DEVDIR/jetson-tx1.conf, it says:


<pre>
<pre>
Line 511: Line 385:
<pre>
<pre>
mkdir $DEVDIR/images/packages-backup/bootloader/
mkdir $DEVDIR/images/packages-backup/bootloader/
cp -rf $DEVDIR/TX1/Linux_for_Tegra_tx1/bootloader/t210ref/p2371-2180-devkit $DEVDIR/images/packages-backup/bootloader/
cp -rf $DEVDIR/bootloader/t210ref/p2371-2180-devkit $DEVDIR/images/packages-backup/bootloader/
cd $DEVDIR/TX1/Linux_for_Tegra_tx1/bootloader/
cd $DEVDIR/bootloader/
cp nvtboot.bin nvtboot_cpu.bin u-boot-dtb.bin bpmp.bin warmboot.bin tos.img tegra210-jetson-tx1-p2597-2180-a01-devkit.dtb $DEVDIR/images/packages-backup/bootloader/
cp nvtboot.bin nvtboot_cpu.bin u-boot-dtb.bin bpmp.bin warmboot.bin tos.img tegra210-jetson-tx1-p2597-2180-a01-devkit.dtb $DEVDIR/images/packages-backup/bootloader/
cp $DEVDIR/TX1/Linux_for_Tegra_tx1/bootloader/t210ref/p2371-2180 $DEVDIR/images/packages-backup/bootloader/
cp $DEVDIR/bootloader/t210ref/p2371-2180 $DEVDIR/images/packages-backup/bootloader/
</pre>
</pre>


Line 522: Line 396:


<pre>
<pre>
cd $DEVDIR/TX1/Linux_for_Tegra_tx1/sources/u-boot_source/
cd $DEVDIR/sources/u-boot/
PATH=$DEVDIR/images:$PATH
PATH=$DEVDIR/images:$PATH
export CROSS_COMPILE=/opt/linaro/gcc-linaro-5.3-2016.02-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
export CROSS_COMPILE=/opt/linaro/gcc-linaro-5.3-2016.02-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
Line 539: Line 413:
<pre>
<pre>
mkdir $DEVDIR/images/bootloader
mkdir $DEVDIR/images/bootloader
cp $DEVDIR/TX1/Linux_for_Tegra_tx1/sources/u-boot_source/u-boot{,.bin,.dtb,-dtb.bin} $DEVDIR/images/bootloader
cp $DEVDIR/sources/u-boot/u-boot{,.bin,.dtb,-dtb.bin} $DEVDIR/images/bootloader
</pre>
</pre>


Line 554: Line 428:


<pre>
<pre>
cp  $DEVDIR/images/bootloader/u-boot{,.bin,.dtb,-dtb.bin} $DEVDIR/TX1/Linux_for_Tegra_tx1/bootloader/t210ref/p2371-2180/
cp  $DEVDIR/images/bootloader/u-boot{,.bin,.dtb,-dtb.bin} $DEVDIR/bootloader/t210ref/p2371-2180/
</pre>
</pre>