Notes for Jetson Nano
Tips, hints, and tricks when working on Jetson Nano
Last update: 2022-06-29
Table of Content
Check log#
Get system log:
dmesg
Log file:
cat /var/log/syslog
List of built-in modules#
cat /lib/modules/$(uname -r)/modules.builtin | grep spi
kernel/drivers/media/spi/imx204.ko
kernel/drivers/mtd/devices/qspi_mtd.ko
kernel/drivers/mtd/spi-nor/spi-nor.ko
kernel/drivers/spi/spi-tegra114.ko
kernel/drivers/spi/spi-tegra124-slave.ko
kernel/drivers/spi/spi-tegra210-qspi.ko
Build kernel and modules#
This is a method to build Kernel image and modules directly on the Jetson board.
Firstly, clone build scripts:
git clone https://github.com/jetsonhacks/jetson-linux-build.git && \
cd jetson-linux-build
Download kernel source. The script will automatically detect the kernel version.
./getKernelSources.sh
Kernel modules can be configured using KConfig Menu:
./editConfig.sh
Example of reviewing SPI driver for Tegra114.
-
Browse to Device Drivers → SPI support and check detail of NVIDIA Tegra114 SPI Controller by pressing
H
:.config - Linux/arm64 4.9.140 Kernel Configuration > Device Drivers > SPI support ------------ ------NVIDIA Tegra114 SPI Controller------- │ CONFIG_SPI_TEGRA114: │ │ │ │ Symbol: SPI_TEGRA114 [=y] │ │ Type : tristate │ │ Prompt: NVIDIA Tegra114 SPI Controller │ │ Location: │ │ -> Device Drivers │ │ -> SPI support (SPI [=y]) │ │ Defined at drivers/spi/Kconfig:626 │ │ Depends on:...
This driver uses the symbol
SPI_TEGRA114
which is defined atdrivers/spi/Kconfig:626
. -
Check the
Makefile
in/usr/src/kernel/$(uname -r)/drivers/spi/Makefile
:obj-$(CONFIG_SPI_MASTER) += spi.o obj-$(CONFIG_SPI_SPIDEV) += spidev.o obj-$(CONFIG_SPI_LOOPBACK_TEST) += spi-loopback-test.o obj-$(CONFIG_SPI_TEGRA114) += spi-tegra114.o
Trace to
.config
file in the kernel folder/usr/src/kernel/$(uname -r)
. Read more at Makefile.CONFIG_SPI=y CONFIG_SPI_MASTER=y CONFIG_SPI_SPIDEV=m CONFIG_SPI_TEGRA114=y
The
CONFIG_SPI_TEGRA114=y
meansspi_tegra114
is a platform driver, not a module, therefore it needs to rebuild kernel image to include change in that driver. -
Edit the source code or apply a patch
-
Rebuild kernel image
./makeKernel.sh
It takes about an hour at the first time.
-
Replace BOOT image at line
LINUX /boot/Image
by editing the boot file:cat /boot/extlinux/extlinux.conf
Should back up the kernel image first.
Reboot!
Find in file#
grep --include=\*.{c,h} -rnw '.' -e "SPI_MODE_1"
Check shared libraries#
ld -lrf24 --verbose
Wrap C lib to C++ lib#
Add wrapper to the header file
#ifdef __cplusplus
extern "C" {
#endif
... header content here...
#ifdef __cplusplus
}
#endif
Device Tree Compile#
Decompile:
dtc -I dtb -O dts <input.dtb> -o <output.dts>
Edit .dts
file, and then recompile:
dtc -I dts -O dtb <input.dts> -o <output.dtb>
Replace FDT file at line FDT /boot/xxx.dtb
by editing the boot file cat /boot/extlinux/extlinux.conf
. Should back up the kernel image first.
Fix USB Partition#
USB with wrong partition table can not be read. Erase the entire partition table is needed.
sudo dd if=/dev/zero of=/dev/sda bs=512 count=1
Then use fdisk
to create GPT partition table and add new partition.
sudo fdisk /dev/sdx
The format the partition:
sudo mkfs.ext4 /dev/sdxy
Visual Studio Code#
Visual Studio Code is far better than Sublime Text. Here is a method to install it automatically:
wget -qO- https://packages.microsoft.com/keys/microsoft.asc \
| gpg --dearmor \
> packages.microsoft.gpg \
&& \
sudo install -o root -g root -m 644 \
packages.microsoft.gpg \
/etc/apt/trusted.gpg.d/ \
&& \
rm -f packages.microsoft.gpg \
&& \
sudo sh -c \
'echo "\
deb [signed-by=/etc/apt/trusted.gpg.d/packages.microsoft.gpg] \
https://packages.microsoft.com/repos/code stable main\
" \
> /etc/apt/sources.list.d/vscode.list' \
&& \
sudo apt install -y apt-transport-https \
&& \
sudo apt update \
&& \
sudo apt install -y code
Plugins:
- Sublime Text key map
- C/C++
Configs:
{
"configurations": [
{
"browse": {
"databaseFilename": "",
"limitSymbolsToIncludedHeaders": true
},
"includePath": [
"${workspaceFolder}/devel/include",
"/opt/ros/melodic/include/**",
"/usr/include/**",
"${workspaceFolder}/**"
],
"name": "ROS",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}
Submodule in Git#
Add a new module:
git submodule add <remote_url>
Initialize submodule:
git submodule init
Download submodule after initializing:
git submodule update
Remove a module:
git submodule deinit <submodule_name>
Clone and download all submodules:
git clone --recursive <repo_url>