Jetson TX1内核kernel编译与烧写

Data: 2017.09.13

Author: cjh

Theme: Jetson TX1内核kernel编译与烧写

PS   :本人用的JetPack版本为3.0

 

1.      Getting bootloader and kernel

本文内核kernel源码是通过JetPack进行安装的,如果没安装的请首先下载JetPack。

通过运行以下命令可获得源码

cd/home/$USER/JetPack-L4T-3.0/64_TX1/Linux_for_Tegra_64_tx1

./source_sync.sh

 

下载源码需要时间

Use: source_sync.sh [options]

Available general options are,

    -h     :     help

    -e     : exit on sync error

    -d DIR : root of source is DIR

默认情况下会下载所有的源码

如果用到了一个或多个以下选项,则仅下载指定的源。

 

    -k [TAG]: Download kernel source and optionally sync to TAG

    -u [TAG]: Download u-boot source and optionally sync to TAG

 

PS:DEVDIR为JetPack的安装目录,可用export DEVDIR = /    添加临时环境变量

 

cd $ DEVDIR / 64_TX1 /Linux_for_Tegra_64_tx1 / sources / kernel_source

git branch -a

git checkout l4t / l4t-r24.2

 

cd $ DEVDIR / 64_TX1 /Linux_for_Tegra_64_tx1 / sources / u-boot_source

git branch -a

git checkout l4t / l4t-r24.2

 

此时源码下载完成

 

2.      安装Toolchain

下载:

5.3-2016.02 for 64bits PC - 64bits ARM

5.3-2016.02 for 64bits PC - 32bits ARM

 

安装:

sudo mkdir /opt/linaro

sudo chmod -R 775 /opt/linaro

sudo chown -R $USER /opt/linaro

cpgcc-linaro-5.3-2016.02-x86_64_aarch64-linux-gnu.tar.xz /opt/linaro

cpgcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf.tar.xz /opt/linaro

cd /opt/linaro/

tar -xfgcc-linaro-5.3-2016.02-x86_64_aarch64-linux-gnu.tar.xz

tar -xfgcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf.tar.xz

 

PS:USER为当前用户

 

3.      内核编译

1) 指定工具链的路径:

mkdir -p $DEVDIR/images/modules

mkdir -p $DEVDIR/images/packages

export CROSS_COMPILE=/opt/linaro/gcc-linaro-5.3-2016.02-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-

exportCROSS32CC=/opt/linaro/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc

exportKERNEL_MODULES_OUT=$DEVDIR/images/modules

export ARCH=arm64

 

2) 清理内核和配置

cd$DEVDIR/64_TX1/Linux_for_Tegra_64_tx1/sources/kernel_source/

make mrproper

 

PS:为避免错误

    error: r7 cannot beused in asm here

error: logical not is only applied to the left hand side ofcomparison

分别修改一下代码:

 

目录:kernel_source/arch/arm64/kernel/vdso32/Makefile

 

GCOV_PROFILE := n

 

注释:ccflags-y := -shared -fPIC-fno-common -fno-builtin -march=armv7-a

增加: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

 

目录:kernel_source/drivers/platform/tegra/tegra21_clocks.c

 

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)

 

3) 配置你的内核

make tegra21_defconfig

make menuconfig

 

PS:错误解决

*** Unable to find thencurses libraries or the

*** required headerfiles.

*** 'make menuconfig'requires the ncurses libraries.

***

*** Install ncurses(ncurses-devel) and try again.

方法:sudo apt-get installlibncurses5-dev

 

4) 编译内核,设备树和模块

make zImage

make dtbs

make modules

make modules_installINSTALL_MOD_PATH=$KERNEL_MODULES_OUT

 

PS:错误解决

GEN   config-host.h

     LEX convert-dtsv0-lexer.lex.c

make[1]: flex:命令未找到

     BISON dtc-parser.tab.c

make[1]: bison:命令未找到

     LEX dtc-lexer.lex.c

make[1]: flex:命令未找到

CHK version_gen.h

方法:sudo apt-get install flex

     sudo apt-get install bison

 

5) 后期准备,修改JetPack

将您的二进制文件保存在images目录中

cp arch/arm64/boot/Imagearch/arm64/boot/zImage $DEVDIR/images/

用kernel模块创建kernel_supplements.tbz2,Jetpack需要这个包

cd $DEVDIR/images/modules/lib/modules/

ls .

使用modules目录的名称定义一个变量

export KERNEL_MODULES_NAME=3.10.96+

修复内核模块目录上的符号链接

cd$DEVDIR/images/modules/lib/modules/$KERNEL_MODULES_NAME

rm build source

创建tarball

cd $DEVDIR/images/modules/

tar -cjf kernel_supplements.tbz2 *

mv kernel_supplements.tbz2$DEVDIR/images/packages

除了创建模块和内核映像之外,还需要再次创建您的kernel_headers.tbz2文件(Jetpack需要)。 默认情况下,当您修补内核代码时,您不会检查内核中的更改将为发行版本添加一个后缀(例如,检查ls $ DEVDIR / images / modules / lib / modules /)。因为这个特定的原因,你需要生成你的头文件tarball再次更改它的版本。

cd $DEVDIR/64_TX1/Linux_for_Tegra_64_tx1/kernel

tar -xf kernel_headers.tbz2

tar -cjf kernel_headers_custom.tbz2linux-headers-$KERNEL_MODULES_NAME

mv kernel_headers_custom.tbz2$DEVDIR/images/packages

rm -rf linux-headers-$KERNEL_MODULES_NAME

 

PS:KERNEL_MODULES_NAME这个后缀大家见机修改

 

创建dtb目录

mkdir -p $DEVDIR/images/dtb

cp$DEVDIR/64_TX1/Linux_for_Tegra_64_tx1/sources/kernel_source/arch/arm64/boot/dts/*.dtb$DEVDIR/images/dtb/

 

复制设备树编译器(DTC)

cp$DEVDIR/64_TX1/Linux_for_Tegra_64_tx1/sources/kernel_source/scripts/dtc/dtc$DEVDIR/images/dtc

 

创建Jetpack中包含的图像和软件包的备份

mkdir -p $DEVDIR/images/packages-backup

cp -rf$DEVDIR/64_TX1/Linux_for_Tegra_64_tx1/kernel/* $DEVDIR/images/packages-backup

 

最后使用自己的图像覆盖默认图像,以使用jetpack安装和引导它们

cd $ DEVDIR / images

cd $DEVDIR/images

rm -rf $DEVDIR/64_TX1/Linux_for_Tegra_64_tx1/kernel/dtb

cp -rf Image zImagepackages/kernel_supplements.tbz2 dtb/ dtc$DEVDIR/64_TX1/Linux_for_Tegra_64_tx1/kernel/

cp -rf packages/kernel_headers_custom.tbz2$DEVDIR/64_TX1/Linux_for_Tegra_64_tx1/kernel/kernel_headers.tbz2

 

运行应用程序脚本以生成要闪存的映像

cd $DEVDIR/64_TX1/Linux_for_Tegra_64_tx1/

sudo ./apply_binaries.sh

 

输出:

Using rootfs directory of:/home/dsoto/devdirs/tegra/Jetpack/TX1/Linux_for_Tegra_tx1/rootfs

Extracting the NVIDIA user space componentsto /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 applicationsto /home/dsoto/devdirs/tegra/Jetpack/TX1/Linux_for_Tegra_tx1/rootfs

Extracting the configuration files for thesupplied root filesystem to/home/dsoto/devdirs/tegra/Jetpack/TX1/Linux_for_Tegra_tx1/rootfs

Creating a symbolic link nvgstplayerpointing to nvgstplayer-0.10

Creating a symbolic link nvgstcapturepointing to nvgstcapture-0.10

Adding symlink libcuda.so -->libcuda.so.1.1 in target rootfs

Adding symlink libGL.so --> libGL.so.1in target rootfs

Adding symlink libcuda.so -->tegra/libcuda.so in target rootfs

Adding symlink libEGL.so --> libEGL.so.1in target rootfs

Extracting the firmwares and kernel modulesto /home/dsoto/devdirs/tegra/Jetpack/TX1/Linux_for_Tegra_tx1/rootfs

Extracting the kernel headers to /usr/srcin target rootfs

Installing zImage into /boot in targetrootfs

Installing Image into /boot in targetrootfs

Installing the board *.dtb files into /bootin target rootfs

Success!

 

6) 从新刷机,修改TX1的kernel

您可以使用Jetpack直接刷新您的图像,而不是直接使用脚本,但这需要时间(约10分钟),因为我们将需要jetpack再次生成system.img

备份你的system.img

cd$DEVDIR/64_TX1/Linux_for_Tegra_tx1/bootloader/

mv system.img.raw system.img$DEVDIR/images/packages-backup/

 

只需运行Jetpack作为您首次安装它:

cd $DEVDIR

./JetPack-L4T-2.1-linux-x64.run

具体操作可详见刷机教程

 

PS:kernel是否更改可查看串口打印信息,Jetson TX1串口调试。

    Linuxversion 3.10.96-tegra (buildbrain@mobile-u64-1072) (gcc version 4.8.2 (GCC) )#1 SMP PREEMPT Wed Nov 9 19:42:57 PST 2016日期是否被修改


参考:

http://blog.csdn.net/mantis_1984/article/details/61616541

https://developer.ridgerun.com/wiki/index.php?title=Compiling_Tegra_X1_source_code

你可能感兴趣的:(Jetson,TX1)