|
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 tool is 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 | +Supports L4T Releases 32.4.2 through 32.6.1 |
7 | 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.3.1. This kernel compiled using this source tree may not work with newer versions or older versions of L4T</em> |
| 8 | +This repository contains convenience scripts to: |
| 9 | +* Download Kernel and Module sources (**B**oard **S**upport **P**ackage - **BSP**) |
| 10 | +* Edit the kernel configuration |
| 11 | +* Build the kernel image |
| 12 | +* Build all of the kernel modules |
| 13 | +* Copy the Kernel Image to the /boot directory - This may not supported for newer versions of L4T - see below _**copyImage.sh deprecation (mostly)**_ |
| 14 | +* An example to build a single kernel module (most useful) |
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 | +## Scripts |
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 | +### getKernelSources.sh |
13 | 19 |
|
14 | | -<strong>getKernelSources.sh</strong> |
| 20 | +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** |
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 | +### makeKernel.sh |
17 | 23 |
|
| 24 | +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. |
18 | 25 |
|
19 | | -<strong>makeKernel.sh</strong> |
| 26 | +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. |
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 | +### makeModules.sh |
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 | +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. |
24 | 31 |
|
25 | | -<strong>makeModules.sh</strong> |
| 32 | +### copyImage.sh |
26 | 33 |
|
27 | | -Compiles the modules using make and then installs them. |
| 34 | +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. |
28 | 35 |
|
29 | | -<strong>copyImage.sh</strong> |
| 36 | +You will want to make a copy of the original Image before the copy, something like: |
| 37 | +``` |
| 38 | +$ cp /boot/Image $INSTALL_DIR/Image.orig |
| 39 | +$ ./copyImage.sh |
| 40 | +$ echo "New Image created and placed in /boot" |
| 41 | +``` |
| 42 | +You may need to modify the _/boot/extlinux/extlinux.conf_ to reflect the changes. |
30 | 43 |
|
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. |
| 44 | +### editConfig.sh |
| 45 | +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. |
32 | 46 |
|
33 | | -You will want to make a copy of the original Image before the copy, something like: |
| 47 | +### removeAllKernelSources.sh |
34 | 48 |
|
35 | | -$ cp /boot/Image $INSTALL_DIR/Image.orig<br> |
36 | | -$ ./copyImage.sh<br> |
37 | | -$ echo "New Image created and placed in /boot"<br> |
| 49 | +Removes all of the kernel sources and compressed source files. You may want to make a backup of the files before deletion. |
38 | 50 |
|
| 51 | +### Example - build-module.sh |
| 52 | +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**_ |
| 53 | +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** |
39 | 54 |
|
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. |
| 55 | +You will need to know the module flag to use this method, in this case it is: **LOGITECH_FF** |
42 | 56 |
|
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 | 57 |
|
46 | | -<h2>Notes:</h2> |
47 | | -<h3>Make sure to update the micro SD card</h3> |
| 58 | +## Background Notes |
| 59 | +Over the years, we have been maintaining several different repositories here and on https://github.com/jetsonhacks to build the Linux kernel and modules for the various NVIDIA Jetson models: |
48 | 60 |
|
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) |
| 61 | +* Jetson Nano |
| 62 | +* Jetson Nano 2GB |
| 63 | +* Jetson TX1 |
| 64 | +* Jetson TX2 |
| 65 | +* Jetson AGX Xavier |
| 66 | +* Jetson Xavier NX |
| 67 | + |
| 68 | +The main difficulty of this approach is that there are several different repositories to maintain across NVIDIA L4T releases. |
| 69 | + |
| 70 | +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. |
| 71 | + |
| 72 | +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. |
| 73 | + |
| 74 | +### copyImage.sh deprecation (mostly) |
| 75 | +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. |
53 | 76 |
|
54 | | -Sometimes it is useful to log the builds: |
| 77 | +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. |
55 | 78 |
|
56 | | -$ command 2>&1 | tee log.txt |
| 79 | +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. |
57 | 80 |
|
58 | | -so you can go back and catch errors. |
| 81 | +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. |
59 | 82 |
|
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. |
| 83 | +### So what good are these scripts? |
| 84 | +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. |
62 | 85 |
|
63 | | -### Release Notes |
64 | | -<b>December, 2019</b> |
| 86 | +## Release Notes |
| 87 | + |
| 88 | +### September, 2021 |
| 89 | +* v1.0 |
| 90 | +* Initial Release - Build 32.4.2 through 32.6.1 |
| 91 | +* Unification of build methods across Jetson platform |
| 92 | + * Jetson Nano, Nano 2GB, TX1, TX2, AGX Xavier, Xavier NX |
| 93 | +* Associative lookup of BSP source code via L4T Release name |
| 94 | +* L4T Releases 32.4.2 through 32.6.1 |
| 95 | +* Tested on Jetson Nano, Jetson Xavier NX |
| 96 | + |
| 97 | +### December, 2019 |
65 | 98 | * vL4T32.3.1 |
66 | 99 | * L4T 32.3.1 (JetPack 4.3) |
67 | 100 | * Minor version update |
68 | 101 |
|
69 | | -<b>November, 2019</b> |
| 102 | +### November, 2019 |
70 | 103 | * vL4T32.2.3 |
71 | 104 | * L4T 32.2.3 (JetPack 4.2.2) |
72 | 105 | * Minor version update |
73 | 106 |
|
74 | | -<b>October, 2019</b> |
| 107 | +### October, 2019 |
| 108 | + |
75 | 109 | * vL4T32.2.1 |
76 | 110 | * L4T 32.2.1 (JetPack 4.2.1) |
77 | 111 | * Better release version parsing |
78 | 112 |
|
79 | | -<b>July, 2019</b> |
| 113 | +### July, 2019 |
80 | 114 | * vL4T32.2 |
81 | 115 | * L4T 32.2 (JetPack 4.2.1) |
82 | 116 |
|
83 | | -<b>June, 2019</b> |
| 117 | +### June, 2019 |
84 | 118 | * vL4T32.1 |
85 | 119 | * L4T 32.1 (JetPack 4.2) |
86 | | -* Initial Release |
| 120 | +* Initial Release |
| 121 | + |
| 122 | +Special thanks to Raffaello Bonghi (https://github.com/rbonghi) for jetson_easy scripts. |
| 123 | + |
| 124 | +Special thanks to Shreeyak (https://github.com/Shreeyak) for discussing alternatives to get source directly from NVIDIA git repositories. |
| 125 | + |
| 126 | + |
0 commit comments