开发环境

jetpack安装

准备工作

主机环境:

  • 推荐Ubuntu Linux x64 v14.04 or v16.04
  • 至少10G存储空间
  • 有效的网络链接

下载jetpack3.1版本,获取脚本文件: JetPack-L4T-3.1-linux-x64.run
官网下载 | 百度网盘

创建目录并执行jetpack脚本

mkdir jetpack3.1
cd jetpack3.1
mv <dldir>/JetPack-L4T-3.1-linux-x64.run ./
chmod +x JetPack-L4T-3.1-linux-x64.run
./JetPack-L4T-3.1-linux-x64.run

0_1524475209834_jetpack3.1_install.png

执行脚本后,启动jetpack安装引导程序。详细安装过程,请参考 安装指导

0_1524475246544_jetpack3.1.png

获取kernel代码

#<Jetpack> jetpack目录
<Jetpack>/64_TX1/Linux_for_Tegra_64_tx1/source_sync.sh

镜像编译

下载工具链

gcc-linaro-5.3-2016.02-x86_64_aarch64-linux-gnu.tar.xz
官网下载 | 百度网盘

gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf.tar.xz
官网下载 | 百度网盘

安装工具链和依赖包

sudo mkdir /opt/linaro
sudo chmod -R 775 /opt/linaro
sudo chown -R $USER /opt/linaro
mv gcc-linaro-5.3-2016.02-x86_64_aarch64-linux-gnu.tar.xz /opt/linaro
mv gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf.tar.xz /opt/linaro
cd /opt/linaro
tar -xf gcc-linaro-5.3-2016.02-x86_64_aarch64-linux-gnu.tar.xz
tar -xf gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf.tar.xz
#Note:If you don't have quilt installed you can get it by running:
sudo apt-get install quilt
sudo apt-get install libncurses5 libncurses5-dev

配置环境变量

export DEVDIR=<Jetpack>/64_TX1/Linux_for_Tegra_64_tx1
export CROSS_COMPILE=/opt/linaro/gcc-linaro-5.3-2016.02-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
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 TEGRA_KERNEL_OUT=$DEVDIR/images
export ARCH=arm64
export KERNEL_MODULES_NAME=4.4.38+
export KERNEL_HEADERS_NAME=linux-headers-4.4.38+

mkdir -p $DEVDIR/images/modules 
mkdir -p $DEVDIR/images/packages

打补丁

cd $DEVDIR/sources/
mkdir patches
cd patches
touch 0001-fix_build_errors.patch

补丁: 0001-fix_build_errors.patch

---
 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[] = {
echo '0001-fix_build_errors.patch' > series
cd $DEVDIR/sources/
quilt push -a

内核编译

cd $DEVDIR/sources/kernel/kernel-4.4
make mrproper

make O=$TEGRA_KERNEL_OUT tegra21_defconfig
make O=$TEGRA_KERNEL_OUT menuconfig
make O=$TEGRA_KERNEL_OUT zImage
make O=$TEGRA_KERNEL_OUT dtbs
make O=$TEGRA_KERNEL_OUT modules
make O=$TEGRA_KERNEL_OUT modules_install INSTALL_MOD_PATH=$KERNEL_MODULES_OUT
# kernel image file will be under: $DEVDIR/images/arch/arm64/boot/Image
# the devicetree under: $DEVDIR/images/arch/arm64/boot/dts/*.dtb

生成镜像

cd $DEVDIR/images/modules/lib/modules/$KERNEL_MODULES_NAME
rm build source
cd $DEVDIR/images/modules/
tar -cjf kernel_supplements.tbz2 *
mv kernel_supplements.tbz2 $DEVDIR/images/packages

cd $DEVDIR/kernel
tar -xf kernel_headers.tbz2
mv $KERNEL_HEADERS_NAME linux-headers-$KERNEL_MODULES_NAME
tar -cjf kernel_headers_custom.tbz2 linux-headers-$KERNEL_MODULES_NAME
mv kernel_headers_custom.tbz2 $DEVDIR/images/packages
rm -rf linux-headers-$KERNEL_MODULES_NAME

mkdir -p $DEVDIR/images/packages-backup
cp -rf $DEVDIR/kernel/* $DEVDIR/images/packages-backup

# copy dtb
cp $DEVDIR/images/arch/arm64/boot/dts/tegra210-jetson-tx1-p2597-2180-a01-devkit.dtb $DEVDIR/kernel/dtb

cd $DEVDIR/images
cp -rf arch/arm64/boot/Image arch/arm64/boot/zImage packages/kernel_supplements.tbz2 $DEVDIR/kernel/
cp -rf packages/kernel_headers_custom.tbz2 $DEVDIR/kernel/kernel_headers.tbz2

cd $DEVDIR/
sudo ./apply_binaries.sh

flash烧写

注意:通过上述编译过程生成的img文件为原生系统,烧写操作会清除设备中的系统。恢复请参考[上手教程->固件升级]。

方法一:

cd $DEVDIR
sudo ./flash.sh jetson-tx1 mmcblk0p1

烧写过程打印输出

方法二:(详细请参考 Jetson Developer Kit User Guide

cd $DEVDIR/../../
./JetPack-L4T-3.1-linux-x64.run

参考: