|
1 | | -# buildKernelAndModules |
2 | | -Build the Linux Kernel and Modules on board the NVIDIA Jetson Nano Developer Kit |
| 1 | +## jetson-linux-build |
| 2 | +Tools to build the Linux kernel and modules on board Jetson Developer Kits |
3 | 3 |
|
4 | | -These scripts are for JetPack 4.3, L4T 32.3.1 |
| 4 | +This is a tool for meant for intermediate+ users. Please read this entire document before proceeding. |
5 | 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. |
| 6 | +This repository contains convenience scripts to: |
| 7 | +* Download Kernel and Module sources (**B**oard **S**upport **P**ackage - **BSP**) |
| 8 | +* Edit the kernel configuration |
| 9 | +* Build the kernel image |
| 10 | +* Build all of the kernel modules |
| 11 | +* Copy the Kernel Image to the /boot directory - This may not supported for newer versions of L4T - see below _**copyImage.sh deprecation (mostly)**_ |
| 12 | +* An example to build a single kernel module (most useful) |
7 | 13 |
|
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.3.1. This kernel compiled using this source tree may not work with newer versions or older versions of L4T</em> |
| 14 | +## Scripts |
9 | 15 |
|
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. |
| 16 | +### getKernelSources.sh |
11 | 17 |
|
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: |
| 18 | +Downloads the kernel sources for L4T from the NVIDIA website and decompresses them into _/usr/src/_ . Note that this also sets the .config file to that of the current system, and sets the LOCALVERSION to the current local version, i.e., **-tegra** |
13 | 19 |
|
14 | | -<strong>getKernelSources.sh</strong> |
| 20 | +### makeKernel.sh |
15 | 21 |
|
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 |
| 22 | +Please read the notes below about installing the kernel using copyImage.sh. Compiles the kernel using make. The script commands builds the kernel Image file. Installing the Image file on to the system is a separate step. |
17 | 23 |
|
| 24 | +This and other parts of the kernel build, such as building the device tree, may require that the result be 'signed' and flashed from the the NVIDIA tools on a host PC. |
18 | 25 |
|
19 | | -<strong>makeKernel.sh</strong> |
| 26 | +### makeModules.sh |
20 | 27 |
|
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. |
| 28 | +Compiles all of the the modules on the system using make and then installs them. You more than likely not want to do this. Instead, look at the script **build-module.sh** in the _example_ directory for an outline on how to build a single module. |
22 | 29 |
|
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. |
| 30 | +### copyImage.sh |
24 | 31 |
|
25 | | -<strong>makeModules.sh</strong> |
| 32 | +Please read the notes below under _**Background Notes**_ about installing the kernel image. This script 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. |
26 | 33 |
|
27 | | -Compiles the modules using make and then installs them. |
28 | | - |
29 | | -<strong>copyImage.sh</strong> |
| 34 | +You will want to make a copy of the original Image before the copy, something like: |
| 35 | +``` |
| 36 | +$ cp /boot/Image $INSTALL_DIR/Image.orig |
| 37 | +$ ./copyImage.sh |
| 38 | +$ echo "New Image created and placed in /boot" |
| 39 | +``` |
| 40 | +### editConfig.sh |
| 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. |
30 | 42 |
|
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. |
| 43 | +### removeAllKernelSources.sh |
32 | 44 |
|
33 | | -You will want to make a copy of the original Image before the copy, something like: |
| 45 | +Removes all of the kernel sources and compressed source files. You may want to make a backup of the files before deletion. |
34 | 46 |
|
35 | | -$ cp /boot/Image $INSTALL_DIR/Image.orig<br> |
36 | | -$ ./copyImage.sh<br> |
37 | | -$ echo "New Image created and placed in /boot"<br> |
| 47 | +### Example - build-module.sh |
| 48 | +The most likely use for these scripts is to build kernel module(s). In the example folder, there is a script named _**build-module.sh**_ |
| 49 | +You should open the script, read through it, and modify to meet your needs. The script builds a module for the Logitech F710 game controller. The module name is **hid-logitech.ko** |
38 | 50 |
|
| 51 | +You will need to know the module flag to use this method, in this case it is: **LOGITECH_FF** |
39 | 52 |
|
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 | 53 |
|
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. |
| 54 | +## Background Notes |
| 55 | +Over the years, we have been maintaining several different repositories here and on https://github.com/jetsonhacksnano to build the Linux kernel and modules for the various NVIDIA Jetson models: |
45 | 56 |
|
46 | | -<h2>Notes:</h2> |
47 | | -<h3>Make sure to update the micro SD card</h3> |
| 57 | +* Jetson Nano |
| 58 | +* Jetson Nano 2GB |
| 59 | +* Jetson TX1 |
| 60 | +* Jetson TX2 |
| 61 | +* Jetson AGX Xavier |
| 62 | +* Jetson Xavier NX |
48 | 63 |
|
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) |
| 64 | +The main difficulty of this approach is that there are several different repositories to maintain across NVIDIA L4T releases. |
53 | 65 |
|
54 | | -Sometimes it is useful to log the builds: |
| 66 | +There are two different versions of BSP source code for each NVIDIA L4T release. One version is for the Jetson Nano, Nano 2GB and TX1 named **T210**. The other version is for the Jetson TX2, AGX Xavier, and Xavier NX named **T186**. The only difference in building the kernel from machine to machine is where to download the BSP sources from for a given release. The idea of this repository is to place these URLs into an associative array to lookup given the L4T release version. |
55 | 67 |
|
56 | | -$ command 2>&1 | tee log.txt |
| 68 | +The other procedures have remained the same over the years, except for placing items in the _**/boot**_ directory. The placement of the Linux kernel image, device tree and extlinux.conf may be different based on the Jetson model and L4T release. |
57 | 69 |
|
58 | | -so you can go back and catch errors. |
| 70 | +### copyImage.sh deprecation (mostly) |
| 71 | +There has been an architectural shift on different Jetson models to provide better security. These changes are implemented differently on each model, depending on hardware capabilities and bootloaders of the Jetson module in question. Several system files, such as but not limited to the Linux kernel and device tree, may now be signed. |
59 | 72 |
|
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. |
| 73 | +For example, on the Jetson Xaviers the kernel is PKC Signed and has SBK encryption in the newer releases. Currently, the NVIDIA approved application to sign these files is an x86 app running on the host machine. |
62 | 74 |
|
63 | | -### Release Notes |
64 | | -<b>December, 2019</b> |
65 | | -* vL4T32.3.1 |
66 | | -* L4T 32.3.1 (JetPack 4.3) |
67 | | -* Minor version update |
| 75 | +Additionally, there are Jetsons which place the **/boot** folder into the onboard QSPI-NOR flash memory to be read at boot time, rather than reading it from the **APP** partition. Consequently the developer needs to know where/how to place a newly created kernel and support code. |
68 | 76 |
|
69 | | -<b>November, 2019</b> |
70 | | -* vL4T32.2.3 |
71 | | -* L4T 32.2.3 (JetPack 4.2.2) |
72 | | -* Minor version update |
| 77 | +The copyImage.sh script may be helpful depending on the Jetson model and L4T release it is being used with. However, on some releases or Jetson models it may not work, or give a false sense of hope of actually doing something. |
73 | 78 |
|
74 | | -<b>October, 2019</b> |
75 | | -* vL4T32.2.1 |
76 | | -* L4T 32.2.1 (JetPack 4.2.1) |
77 | | -* Better release version parsing |
| 79 | +### So what good are these scripts? |
| 80 | +One thing that the scripts are useful for is building external kernel modules. People can build the modules on the device without having to go through the steps of setting up a development environment on the host, building the module, and transferring it to the Jetson. Instead, build the module on the Jetson and then install it. |
78 | 81 |
|
79 | | -<b>July, 2019</b> |
80 | | -* vL4T32.2 |
81 | | -* L4T 32.2 (JetPack 4.2.1) |
| 82 | +## Release Notes |
82 | 83 |
|
83 | | -<b>June, 2019</b> |
84 | | -* vL4T32.1 |
85 | | -* L4T 32.1 (JetPack 4.2) |
86 | | -* Initial Release |
| 84 | +### September, 2021 |
| 85 | +* Initial Release |
| 86 | +* Unification of build methods across Jetson platform |
| 87 | + * Jetson Nano, Nano 2GB, TX1, TX2, AGX Xavier, Xavier NX |
| 88 | +* Associative lookup of BSP source code via L4T Release name |
| 89 | +* L4T Releases 32.4.2 through 32.6.1 |
| 90 | +* Tested on Jetson Nano, Jetson Xavier NX |
0 commit comments