Skip to content

Commit

Permalink
board: add nvidia jetson nano support
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Stewart <christian@paral.in>
  • Loading branch information
paralin committed Nov 18, 2020
1 parent 886d60f commit 4082a22
Show file tree
Hide file tree
Showing 4 changed files with 280 additions and 0 deletions.
167 changes: 167 additions & 0 deletions board/jetson/nano/format-sd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
#!/bin/bash
set -eo pipefail

# NOTE: The following copyright applies to linux4tegra and associated tools:

# Copyright (c) 2019-2020, NVIDIA Corporation. All Rights Reserved.
#
# NVIDIA Corporation and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA Corporation is strictly prohibited.

if [ $EUID != 0 ]; then
echo "This script requires root."
fi

if [ -z "$NVIDIA_SD" ]; then
echo "Please set NVIDIA_SD and try again."
exit 1
fi

if [ ! -b "$NVIDIA_SD" ]; then
echo "$NVIDIA_SD is not a block device or doesn't exist."
exit 1
fi

IMAGES_DIR=$1
if [ -z $IMAGES_DIR ]; then
echo "usage: $0 path/to/images/dir"
exit 1
fi

uimg_path=$IMAGES_DIR/Image
if [ ! -f "$uimg_path" ]; then
echo "Image not found, make sure Buildroot is done compiling."
exit 1
fi

l4t_tools_path=$IMAGES_DIR/linux4tegra/tools
if [ ! -d $l4t_tools_path ]; then
echo "linux4tegra tools not found, ensure buildroot is done compiling."
exit 1
fi

# jetson-nano
boardid="3448"
target="jetson-nano-qspi-sd"
storage="sdcard"
rev="300" # from 100, 200, 300
chipid="0x21"

l4t_dir=${IMAGES_DIR}/linux4tegra
rootfs_img=$IMAGES_DIR/rootfs.ext2

# TODO: dynamic rootfs size: the following /almost/ works:
#rootfs_size=$(du -ms ${rootfs_img} | awk '{print $1}')
#rootfs_size=$((rootfs_size + (rootfs_size / 10)))

rootfs_size=2048

echo "creating signed images"
pushd ${l4t_dir}
export BOARDID="${boardid}"
export FAB="${rev}"

${l4t_dir}/flash.sh \
--no-flash \
--sign \
--no-systemimg \
-x ${chipid} \
-B ${boardid} \
-S "${rootfs_size}MiB" \
-I $IMAGES_DIR/rootfs.ext2 \
-K $IMAGES_DIR/u-boot-dtb.bin \
-d $IMAGES_DIR/tegra210-p3448-0000-p3449-0000-b00.dtb \
"${target}" "mmcblk0p1"
popd

bootloader_dir=${l4t_dir}/bootloader
if [ ! -f "${bootloader_dir}/flashcmd.txt" ]; then
echo "ERROR: ${bootloader_dir}/flashcmd.txt not found"
exit 1
fi

signed_image_dir=${bootloader_dir}/signed
if [ ! -d "${signed_image_dir}" ]; then
echo "ERROR: ${signed_image_dir} not found"
exit 1
fi

chipid=$(sed -nr 's/.*chip ([^ ]*).*/\1/p' "${bootloader_dir}/flashcmd.txt")
if [ "${chipid}" = "0x21" ]; then
signed_cfg="flash.xml"
else
signed_cfg="flash.xml.tmp"
fi

if [ ! -f "${signed_image_dir}/${signed_cfg}" ]; then
echo "ERROR: ${signed_image_dir}/${signed_cfg} not found"
exit 1
fi

echo "create partitions"
partitions=($(${l4t_tools_path}/nvptparser.py "${signed_image_dir}/${signed_cfg}" "${storage}"))
part_type=8300 # Linux Filesystem

sgdisk -og "${NVIDIA_SD}"
for part in "${partitions[@]}"; do
eval "${part}"
if [ "${part_name}" = "master_boot_record" ]; then
continue
fi
part_size=$((${part_size} / 512)) # convert to sectors
sgdisk -n "${part_num}":0:+"${part_size}" \
-c "${part_num}":"${part_name}" \
-t "${part_num}":"${part_type}" "${NVIDIA_SD}"
done

# prefer root partprobe
PARTPROBE=partprobe
if [ -f /usr/sbin/partprobe ]; then
PARTPROBE=/usr/sbin/partprobe
fi

$PARTPROBE ${NVIDIA_SD} || true
sleep 1
if $PARTPROBE ${NVIDIA_SD}; then
# wait for partitions to settle
sleep 1
fi

echo "write partitions"
for part in "${partitions[@]}"; do
eval "${part}"
target_file=""
if [ "${part_name}" = "APP" ]; then
target_file="${IMAGES_DIR}/rootfs.ext2" # Buildroot target system.
elif [ -e "${signed_image_dir}/${part_file}" ]; then
target_file="${signed_image_dir}/${part_file}"
elif [ -e "${bootloader_dir}/${part_file}" ]; then
target_file="${bootloader_dir}/${part_file}"
fi

echo "writing partition ${part_name}"
if [ "${part_name}" = "master_boot_record" ]; then
echo "writing ${part_file}"
dd conv=notrunc conv=fsync if="${signed_image_dir}/${part_file}" of="${NVIDIA_SD}" bs="${part_size}" count=1
continue
fi

if [ "${target_file}" != "" ] && [ "${part_file}" != "" ]; then
echo "writing ${target_file}"
target_part=${NVIDIA_SD}p${part_num}
if [ ! -b ${target_part} ]; then
target_part=${NVIDIA_SD}${part_num}
fi
if [ ! -b ${target_part} ]; then
echo "Partition block device ${target_part} or ${NVIDIA_SD}p${part_num} does not exist!"
exit 1
fi
sudo dd conv=fsync if="${target_file}" of="${target_part}"
fi
done

echo "Successfully flashed $NVIDIA_SD"

57 changes: 57 additions & 0 deletions board/jetson/nano/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
NVIDIA Jetson Nano

Intro
=====

This configuration adds support for the Jetson Nano devkit.

Building
========

Configure Buildroot
-------------------

For Jetson Nano:

$ make jetsonnano_defconfig

Build the rootfs
----------------

You may now build your rootfs with:

$ make


Flashing
========

Once the build process is finished you will have the target binaries in the
output/images directory with a copy of linux4tegra.

To format your SD card with the required partition layout, use the
"format-sd.sh" script located under board/jetson/nano/format-sd.sh:

sudo \
NVIDIA_SD=/dev/sdX \
PATH=$(pwd)/output/host/sbin:$PATH \
bash board/jetson/nano/format-sd.sh ./output/images

This will also flash the ext4 rootfs image to the SD card.

Bootup Process
==============

The Jetson Nano can boot to a SD card.

A "secure boot" process is used, with multiple bootloaders:

- BootROM -> MB1 (TrustZone)
- MB2/BPMP -> (Non-Trustzone)
- Cboot (uses Little Kernel)
- Uboot
- Kernel

Cboot could be compiled from source, and the source is available from the
official sources, however, we do not (yet) compile cboot.

1 change: 1 addition & 0 deletions board/jetsonnano
55 changes: 55 additions & 0 deletions configs/jetsonnano_defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
BR2_aarch64=y
BR2_cortex_a57=y

# enable specific optimizations
BR2_TARGET_OPTIMIZATION="-march=armv8-a+crypto -mcpu=cortex-a57+crypto"

# Toolchain reference: docs.nvidia.com: "Jetson Linux Driver Package Toolchain"
BR2_TOOLCHAIN_BUILDROOT_CXX=y
BR2_BINUTILS_VERSION_2_32_X=y

BR2_SYSTEM_DHCP="eth0"

# Linux headers same as kernel, a 4.9 series
BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_9=y
BR2_KERNEL_HEADERS_AS_KERNEL=y

BR2_LINUX_KERNEL=y
BR2_LINUX_KERNEL_CUSTOM_TARBALL=y
BR2_LINUX_KERNEL_CUSTOM_TARBALL_LOCATION="$(call github,madisongh,linux-tegra-4.9,0be1a57448010ae60505acf4e2153638455cee7c)/linux-tegra-4.9.140-r1.tar.gz"
BR2_LINUX_KERNEL_DEFCONFIG="tegra"

# Build the DTB from the kernel sources
BR2_LINUX_KERNEL_DTS_SUPPORT=y
BR2_LINUX_KERNEL_INTREE_DTS_NAME="_ddot_/_ddot_/_ddot_/_ddot_/nvidia/platform/t210/porg/kernel-dts/tegra210-p3448-0000-p3449-0000-a02 _ddot_/_ddot_/_ddot_/_ddot_/nvidia/platform/t210/porg/kernel-dts/tegra210-p3448-0000-p3449-0000-b00"

BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y

BR2_PACKAGE_LINUX4TEGRA=y
BR2_PACKAGE_LINUX4TEGRA_PLATFORM_T210REF=y

# TODO: NVIDIA_CONTAINER_TOOLKIT requires a go-module integration.
# BR2_PACKAGE_NVIDIA_CONTAINER_TOOLKIT=y

BR2_PACKAGE_LINUX_FIRMWARE=y
BR2_PACKAGE_LINUX_FIRMWARE_RTL_88XX=y

# Required tools to create the image
BR2_PACKAGE_HOST_DOSFSTOOLS=y
BR2_PACKAGE_HOST_JQ=y
BR2_PACKAGE_HOST_PARTED=y

# Filesystem / image
BR2_TARGET_ROOTFS_EXT2=y
BR2_TARGET_ROOTFS_EXT2_4=y
BR2_TARGET_ROOTFS_EXT2_SIZE="1024M"
# BR2_TARGET_ROOTFS_TAR is not set

# Uboot
BR2_TARGET_UBOOT=y
BR2_TARGET_UBOOT_BOARD_DEFCONFIG="p3450-porg"
BR2_TARGET_UBOOT_BUILD_SYSTEM_KCONFIG=y
BR2_TARGET_UBOOT_CUSTOM_TARBALL=y
BR2_TARGET_UBOOT_CUSTOM_TARBALL_LOCATION="$(call github,paralin,u-boot-tegra,45dfa3dff43f880243a9fe68f3d911e99a240654)/u-boot-tegra-l4t-r32.4.2-v2016.07.tar.gz"
BR2_TARGET_UBOOT_FORMAT_DTB_BIN=y
BR2_TARGET_UBOOT_NEEDS_DTC=y

0 comments on commit 4082a22

Please sign in to comment.