Skip to content

Commit 5046b64

Browse files
Merge pull request JetsonHacksNano#1 from JetsonHacksNano/vL4T32.2-dev
Update to L4T 32.2
2 parents 05c380a + 86261a9 commit 5046b64

File tree

9 files changed

+136
-29
lines changed

9 files changed

+136
-29
lines changed

README.md

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,70 @@
11
# buildKernelAndModules
22
Build the Linux Kernel and Modules on board the NVIDIA Jetson Nano Developer Kit
33

4-
Work in progress
4+
These scripts are for JetPack 4.2.1, L4T 32.2
5+
6+
Scripts to help build the 4.9.140 kernel and modules onboard the Jetson Nano Developer Kit Previous versions may be available in releases.
7+
8+
<em><strong>Note:</strong> The kernel source version must match the version of firmware flashed on the Jetson. For example, the source for the 4.9.140 kernel here is matched with L4T 32.2. This kernel compiled using this source tree may not work with newer versions or older versions of L4T</em>
9+
10+
As of this writing, the "official" way to build the Jetson Nano kernel is to use a cross compiler on a Linux PC. This is an alternative which builds the kernel onboard the Jetson itself. These scripts will download the kernel source to the Jetson Nano, and then compile the kernel and selected modules. The newly compiled kernel can then be installed. We recommend a SD card size of 32GB, 64GB preferred.
11+
12+
The scripts should be run directly after flashing the Jetson, or copying the SD card image from a host PC. There are several scripts:
13+
14+
<strong>getKernelSources.sh</strong>
15+
16+
Downloads the kernel sources for L4T from the NVIDIA website, decompresses them and opens a graphical editor on the .config file. Note that this also sets the .config file to the current system, and also sets the local version to the current local version, i.e., -tegra
17+
18+
19+
<strong>makeKernel.sh</strong>
20+
21+
Compiles the kernel using make. The script commands make the kernel Image file. Installing the Image file on to the system is a separate step. Note that the make is limited to the Image and modules.
22+
23+
The other parts of the kernel build, such as building the device tree, require that the result be 'signed' and flashed from the the NVIDIA tools on a host PC.
24+
25+
<strong>makeKernel.sh</strong>
26+
27+
Compiles the modules using make and then installs them.
28+
29+
<strong>copyImage.sh</strong>
30+
31+
Copies the Image file created by compiling the kernel to the /boot directory. Note that while developing you will want to be more conservative than this: You will probably want to copy the new kernel Image to a different name in the boot directory, and modify /boot/extlinux/extlinux.conf to have entry points at the old image, or the new image. This way, if things go sideways you can still boot the machine using the serial console.
32+
33+
You will want to make a copy of the original Image before the copy, something like:
34+
35+
$ cp /boot/Image $INSTALL_DIR/Image.orig<br>
36+
$ ./copyImage.sh<br>
37+
$ echo "New Image created and placed in /boot"<br>
38+
39+
40+
<strong>editConfig.sh</strong>
41+
Edit the .config file located in /usr/src/kernel/kernel-4.9 This file must be present (from the getKernelSources.sh script) before launching the file. Note that if you change the local version, you will need to make both the kernel and modules and install them.
42+
43+
<strong>removeAllKernelSources.sh</strong>
44+
Removes all of the kernel sources and compressed source files. You may want to make a backup of the files before deletion.
45+
46+
<h2>Notes:</h2>
47+
<h3>Make sure to update the micro SD card</h3>
48+
49+
The copyImage.sh script copies the Image to the current device. If you are building the kernel on an external device, for example a USB drive, you will probably want to copy the Image file over to the micro SD card in the micro SD's /boot directory.
50+
Special thanks to Raffaello Bonghi (https://github.com/rbonghi) for jetson_easy scripts.
51+
Special thanks to Shreeyak (https://github.com/Shreeyak) for discussing alternatives to get source directly from NVIDIA git repositories.
52+
Special thanks to Dustin Franklin (https://github.com/dusty-nv/) for how to correctly determine the correct L4T version. (https://github.com/dusty-nv/jetson-inference/blob/7e81381a96c1ac5f57f1728afbfdec7f1bfeffc2/tools/install-pytorch.sh#L296)
53+
54+
Sometimes it is useful to log the builds:
55+
56+
$ command 2>&1 | tee log.txt
57+
58+
so you can go back and catch errors.
59+
60+
<h4>Intended Use</h4>
61+
The intended use of this repository is to help automate building known configurations of the kernel and build modules. You should use the kernel-4.9/scripts/config script to set the kernel configuration that you desire. See the 'rootOnUSB' repository on the JetsonHacksNano Github account for an example.
62+
63+
### Release Notes
64+
July, 2019
65+
* vL4T32.2
66+
* L4T 32.2 (JetPack 4.2.1)
67+
* Initial Release
68+
69+
70+
command 2>&1 | tee log.txt

getKernelSources.sh

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,49 @@
33
# Copyright (c) 2016-19 Jetsonhacks
44
# MIT License
55

6-
JETSON_MODEL="jetson-nano"
7-
L4T_TARGET="32.1.0"
6+
JETSON_MODEL="NVIDIA Jetson Nano Developer Kit"
7+
L4T_TARGET="32.2"
88
SOURCE_TARGET="/usr/src"
99
KERNEL_RELEASE="4.9"
1010

1111
# < is more efficient than cat command
1212
# NULL byte at end of board description gets bash upset; strip it out
1313
JETSON_BOARD=$(tr -d '\0' </proc/device-tree/model)
14+
echo "Jetson Model: "$JETSON_BOARD
1415

1516
JETSON_L4T=""
16-
if [ -f /etc/nv_tegra_release ]; then
17-
# L4T string
18-
JETSON_L4T_STRING=$(head -n 1 /etc/nv_tegra_release)
19-
20-
# Load release and revision
21-
JETSON_L4T_RELEASE=$(echo $JETSON_L4T_STRING | cut -f 1 -d ',' | sed 's/\# R//g' | cut -d ' ' -f1)
22-
JETSON_L4T_REVISION=$(echo $JETSON_L4T_STRING | cut -f 2 -d ',' | sed 's/\ REVISION: //g' )
23-
# unset variable
24-
unset JETSON_L4T_STRING
25-
26-
# Write Jetson description
27-
JETSON_L4T="$JETSON_L4T_RELEASE.$JETSON_L4T_REVISION"
28-
fi
29-
echo "Jetson Model: "$JETSON_BOARD
30-
echo "Jetson L4T: "$JETSON_L4T
17+
18+
# Starting with L4T 32.2, the recommended way to find the L4T Release Number
19+
# is to use dpkg
20+
function check_L4T_version()
21+
{
22+
if [ -f /etc/nv_tegra_release ]; then
23+
JETSON_L4T_STRING=$(head -n 1 /etc/nv_tegra_release)
24+
JETSON_L4T_RELEASE=$(echo $JETSON_L4T_STRING | cut -f 2 -d ' ' | grep -Po '(?<=R)[^;]+')
25+
JETSON_L4T_REVISION=$(echo $JETSON_L4T_STRING | cut -f 2 -d ',' | grep -Po '(?<=REVISION: )[^;]+')
26+
27+
else
28+
echo "$LOG Reading L4T version from \"dpkg-query --show nvidia-l4t-core\""
29+
30+
JETSON_L4T_STRING=$(dpkg-query --showformat='${Version}' --show nvidia-l4t-core)
31+
local JETSON_L4T_ARRAY=(${JETSON_L4T_STRING//./ })
32+
33+
#echo ${JETSON_L4T_ARRAY[@]}
34+
#echo ${#JETSON_L4T_ARRAY[@]}
35+
36+
JETSON_L4T_RELEASE=${JETSON_L4T_ARRAY[0]}
37+
JETSON_L4T_REVISION=${JETSON_L4T_ARRAY[1]}
38+
fi
39+
40+
JETSON_L4T_VERSION="$JETSON_L4T_RELEASE.$JETSON_L4T_REVISION"
41+
echo "$LOG Jetson BSP Version: L4T R$JETSON_L4T_VERSION"
42+
43+
}
44+
45+
echo "Getting L4T Version"
46+
check_L4T_version
47+
JETSON_L4T="$JETSON_L4T_VERSION"
48+
echo "Jetson_L4T="$JETSON_L4T
3149

3250
function usage
3351
{

removeAllKernelSources.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
# Remove all of the kernel sources that were downloaded and built during the kernel build process
3+
# Note that this will also remove the possibly changed .config file in:
4+
# /usr/src/kernel/kernel-4.9
5+
echo "Removing All Kernel Sources"
6+
sudo ./scripts/removeAllKernelSources.sh
7+
echo "Kernel sources removed"
8+

sample-extlinux.conf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
TIMEOUT 30
2+
DEFAULT primary
3+
4+
MENU TITLE p3450-porg eMMC boot options
5+
6+
LABEL primary
7+
MENU LABEL primary kernel
8+
LINUX /boot/Image
9+
INITRD /boot/initrd
10+
APPEND ${cbootargs} rootfstype=ext4 root=/dev/sda1 rw rootwait
11+
12+
LABEL emmc
13+
MENU LABEL primary kernel
14+
LINUX /boot/Image
15+
INITRD /boot/initrd
16+
APPEND ${cbootargs} rootfstype=ext4 root=/dev/mmcblk0p1 rw rootwait

scripts/copyImage.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ echo "Source Target: ""$SOURCE_TARGET"kernel/kernel-$KERNEL_RELEASE/arch/arm64/b
44
echo "Boot Path: ""$BOOT_TARGET"Image
55

66
cd "$SOURCE_TARGET"kernel/kernel-$KERNEL_RELEASE
7-
# On the stock Jetson TX2 install, there is no zImage in the boot directory
7+
# On the stock Jetson Nano install, there is no zImage in the boot directory
88
# So we just copy the Image file over
99
# If the zImage is needed, you must either
1010
# $ make zImage
1111
# or
1212
# $ make
13-
# Both of these commands must be executed in /usr/src/kernel/kernel-4.4
13+
# Both of these commands must be executed in /usr/src/kernel/kernel-4.9
1414
# sudo cp arch/arm64/boot/zImage /boot/zImage
15-
# Note that if you are compiling on an external device, like a SSD, you should probably
16-
# copy this over to the internal eMMC if that is where the Jetson boots
15+
# Note that if you are compiling on an external device, like a SSD, you should
16+
# copy this over to the boot device (i.e SD Card) where the Jetson boots
1717
sudo cp arch/arm64/boot/Image "$BOOT_TARGET"Image
1818

1919

scripts/getKernelSources.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ apt-add-repository universe
44
apt-get update
55
apt-get install pkg-config -y
66
# We use 'make menuconfig' to edit the .config file; install dependencies
7-
apt-get install libncurses5-dev
7+
apt-get install libncurses5-dev -y
88
echo "Installing kernel sources in: ""$SOURCE_TARGET"
99
if [ ! -d "$SOURCE_TARGET" ]; then
1010
# Target directory does not exist; create
@@ -15,9 +15,9 @@ fi
1515
cd "$SOURCE_TARGET"
1616
echo "$PWD"
1717

18-
wget -N https://developer.nvidia.com/embedded/dlc/l4t-sources-32-1-jetson-nano
18+
wget -N https://developer.download.nvidia.com/embedded/L4T/r32-2_Release_v1.0/Nano-TX1/public_sources.tbz2
1919
# l4t-sources is a tbz2 file
20-
tar -xvf l4t-sources-32-1-jetson-nano public_sources/kernel_src.tbz2
20+
tar -xvf public_sources.tbz2 public_sources/kernel_src.tbz2
2121
tar -xvf public_sources/kernel_src.tbz2
2222
# Space is tight; get rid of the compressed kernel source
2323
rm -r public_sources
@@ -28,7 +28,7 @@ zcat /proc/config.gz > .config
2828
cp .config config.orig
2929
# Default to the current local version
3030
KERNEL_VERSION=$(uname -r)
31-
# For L4T 32.1.0 the kernel is 4.9.140-tegra ;
31+
# For L4T 32.2 the kernel is 4.9.140-tegra ;
3232
# Everything after '4.9.140' is the local version
3333
# This removes the suffix
3434
LOCAL_VERSION=${KERNEL_VERSION#$"4.9.140"}

scripts/makeKernel.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ echo "Source Target: "$SOURCE_TARGET
88
MAKE_DIRECTORY="$SOURCE_TARGET"kernel/kernel-4.9
99

1010
cd "$SOURCE_TARGET"kernel/kernel-4.9
11-
make prepare
11+
# make prepare
1212
# Get the number of CPUs
1313
NUM_CPU=$(nproc)
1414

scripts/makeModules.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ echo "Source Target: "$SOURCE_TARGET
88
MAKE_DIRECTORY="$SOURCE_TARGET"kernel/kernel-4.9
99

1010
cd "$SOURCE_TARGET"kernel/kernel-4.9
11-
make modules_prepare
1211
# Get the number of CPUs
1312
NUM_CPU=$(nproc)
1413

scripts/removeAllKernelSources.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
cd /usr/src
44
rm -r kernel
55
rm -r hardware
6-
rm l4t-sources-32-1-jetson-nano
6+
rm public_sources.tbz2
77

0 commit comments

Comments
 (0)