[Shield Android TV Android Development] yifanlu:
Manual Build​

Download Latest (R32.7.2, 07/09/22)

Prerequisite​

Linux for Tegra R32.7.2

Linux for Tegra R32.7.2 Sources

Linux for Tegra R32.7.2 Root Filesystem

Jetson GCC Toolchain 32.2

NVIDIA SHIELD ANDROID TV 2015 Recovery OS Image 9.0.0

Utilities (apt install): simg2img, git, fastboot, abootimg

Building the kernel​

1. Install the toolchain.

$ wget -O toolchain.tar.xz https://developer.nvidia.com/embedded/dlc/l4t-gcc-7-3-1-toolchain-64-bit
$ tar xpf toolchain.tar.xz
$ sudo mv gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu /opt/l4t-toolchain

2. Fetch the SHIELD TV Android kernel sources.

$ git clone --depth 1 https://nv-tegra.nvidia.com/r/linux-4.9.git -b rel-shield-r-9.0.2-opensource-4.9 linux-4.9
$ git clone --depth 1 https://nv-tegra.nvidia.com/r/linux-nvidia.git -b rel-shield-r-9.0.2-opensource nvidia

3. Fetch the Linux For Tegra NVGPU sources.

$ wget https://developer.nvidia.com/embedded/l4t/r32_release_v7.2/sources/t210/public_sources.tbz2
$ tar xpf public_sources.tbz2
$ tar xpf Linux_for_Tegra/source/public/kernel_src.tbz2
$ mv kernel/nvgpu nvgpu

You should have three directories: linux-4.9, nvidia, and nvgpu

4. Patch the sources.

$ cat patches/kernel-4.9/*.patch | patch -p1 -dlinux-4.9
$ cat patches/nvidia/*.patch | patch -p1 -dnvidia
$ cat patches/nvgpu/*.patch | patch -p1 -dnvgpu

5. Build the kernel and install the modules.

$ export CROSS_COMPILE=/opt/l4t-toolchain/bin/aarch64-linux-gnu-
$ export ARCH=arm64
$ mkdir -p Linux_for_Tegra/rootfs/
$ pushd linux-4.9
$ make shieldtv_defconfig
$ make -j$(nproc) zImage
$ make -j$(nproc) modules
$ make modules_install INSTALL_MOD_PATH=../Linux_for_Tegra/rootfs/
$ sudo chown -R root:root ../Linux_for_Tegra/rootfs/lib
$ popd

Building Root Filesystem​

1. Extract jetson-210_linux_r32.7.2_aarch64.tbz2 and tegra_linux_sample-root-filesystem_r32.7.2_aarch64.tbz2.

$ tar xpf jetson-210_linux_r32.7.2_aarch64.tbz2
$ pushd Linux_for_Tegra/rootfs/
$ sudo tar xpf ../../tegra_linux_sample-root-filesystem_r32.7.2_aarch64.tbz2
$ sudo touch etc/nv_boot_control.conf

Note the use of sudo for the last two commands. This is required for file permissions to be correct. The touch at the end resolves a bug in NVIDIA's code that resulted in the installer not launching.

2. Install the filesystem.

$ cd ..
$ sudo ./apply_binaries.sh
$ popd

3. To enable Wifi and NVDEC, need to first convert vendor.img downlaoded from the SHIELD recovery image to an ext4 image.

$ simg2img nv-recovery-image-shield-atv-9.0.0/vendor.img vendor-raw.img

4. Next mount the image.

$ mkdir vendor
$ sudo mount -o loop vendor-raw.img vendor

5. Copy the firmware over.

$ sudo cp vendor/firmware/bcmdhd_clm_foster.blob Linux_for_Tegra/rootfs/lib/firmware/brcm/bcmdhd.clm_blob
$ sudo cp vendor/firmware/fw_bcmdhd.bin Linux_for_Tegra/rootfs/lib/firmware/brcm/fw_bcmdhd.bin
$ sudo cp vendor/firmware/nvram_foster_e_4354.txt Linux_for_Tegra/rootfs/lib/firmware/brcm/nvram.txt
$ sudo cp vendor/firmware/tegra21x/* Linux_for_Tegra/rootfs/lib/firmware/tegra21x/
$ sudo cp vendor/firmware/tegra21x/vic04_ucode.bin Linux_for_Tegra/rootfs/lib/firmware/nvidia/tegra210/
$ sudo umount vendor

6. Create and mount a new ext4 image. Note that we will create 8GiB image which should be enough to hold the root filesystem. After you flash it to your device and boot successfully, you'll want to run resize2fs.

$ dd if=/dev/zero of=rootfs.img bs=1MiB count=8196
$ mkfs.ext4 rootfs.img
$ mkdir mount
$ sudo mount -o loop rootfs.img mount

7. Copy the filesystem to the disk image.

$ sudo mv Linux_for_Tegra/rootfs/* mount/
$ sudo umount mount

Building boot image​

1. Extract the existing initramfs.

$ mkdir initramfs
$ pushd initramfs
$ cat Linux_for_Tegra/bootloader/l4t_initrd.img | gunzip -c | cpio -i

2. Patch init.

$ cp patches/initramfs/init init

3. Rebuild the image.

$ find ./ | cpio -H newc -o -R root:root | gzip -9 -c > ../initramfs.img

4. Build boot.img

$ abootimg --create boot.img -f patches/bootimg.cfg -k linux-4.9/arch/arm64/boot/zImage -r initramfs.img