Partitioning NVIdia Jetson module

This article covering how to change the NVidia Jetson modules partition layout using yocto + meta-tegra layer, and is basically a summary of this issue. Big thank to Matt Madison!

After the default image build, the partition layout for each device can be found in tmp/work-shared/L4T-native-tegra186-32.2.0-r0/Linux_for_Tegra/bootloader/*/cfg

For TX2, make a copy of tmp/work-shared/L4T-native-tegra186-32.2.0-r0/Linux_for_Tegra/bootloader/t186ref/cfg/flash_l4t_t186.xml and name it to something else, i.e: flash_l4t_t186_custom.xml

Read https://docs.nvidia.com/jetson/archives/l4t-archived/l4t-282/index.html#page/Tegra%2520Linux%2520Driver%2520Package%2520Development%2520Guide%2Fpart_config_tx2.html and make the wanted modifications into flash_l4t_t186_custom.xml to understand the different tags, and make the modifications you need.

Next you need to tell bitbake to use the new flash_l4t_t186_custom.xml instead of flash_l4t_t186.xml and this is done by setting PARTITION_LAYOUT_TEMPLATE variable. It is defined in the MACHINE configuration for machines declared in meta-tegra or your custom ones.

Example for meta-tegra/conf/machine/jetson-tx2.conf:

#@TYPE: Machine
#@NAME: Nvidia Jetson TX2
#@DESCRIPTION: Nvidia Jetson TX2 dev board

require conf/machine/include/tegra186.inc

KERNEL_DEVICETREE ?= "_ddot_/_ddot_/_ddot_/_ddot_/nvidia/platform/t18x/quill/kernel-dts/tegra186-quill-p3310-1000-c03-00-base.dtb"
KERNEL_ARGS ?= "console=ttyS0,115200 console=tty0 OS=l4t fbcon=map:0"

MACHINE_FEATURES += "ext2 ext3 vfat"

UBOOT_MACHINE = "p2771-0000-500_defconfig"

EMMC_SIZE ?= "31276924928"
EMMC_DEVSECT_SIZE ?= "512"
BOOTPART_SIZE ?= "8388608"
BOOTPART_LIMIT ?= "10485760"
ROOTFSPART_SIZE ?= "30064771072"
ODMDATA ?= "0x1090000"
EMMC_BCT ?= "P3310_A00_8GB_Samsung_8GB_lpddr4_204Mhz_A02_l4t.cfg"
NVIDIA_BOARD ?= "t186ref"
PARTITION_LAYOUT_TEMPLATE ?= "flash_l4t_t186.xml"Code language: Bash (bash)

I didn’t want to modify the original machine definition file, so I opted for adding an include in my distro layer configuration file

include conf/machine/${MACHINE}-extra.confCode language: Bash (bash)

If you don’t have your own distro layer, you can add this to your local.conf file.

Then in your layer add conf/machine/jetson-tx2-extra.conf with

 PARTITION_LAYOUT_TEMPLATE = "flash_l4t_t186_custom.xml"Code language: Bash (bash)

Now you need to make bitbake fetch flash_l4t_t186_custom.xml and this is done by appending tegra-binaries recipe. In your layer, add …/recipes-bsp/tegra-binaries

Inside create a files folder and copy flash_l4t_t186_custom.xml into it.

Create tegra-binaries_32.%.bbappend

FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
 SRC_URI += " \
     file://flash_l4t_t186_custom.xml \
"

do_preconfigure_append() {
     mkdir -p ${S}/bootloader/${NVIDIA_BOARD}/cfg/
     cp ${WORKDIR}/flash_l4t_t186_custom.xml ${S}/bootloader/${NVIDIA_BOARD}/cfg/
 }Code language: Bash (bash)

Now you can build a new image and flash the device.

Once the device boots, check the device name for the partition you are looking for with

# lsblk --f --bytes --output NAME,FSTYPE,MOUNTPOINT,PARTLABEL,SIZE,STATE,TYPE
 NAME         FSTYPE MOUNTPOINT  PARTLABEL                SIZE STATE   TYPE
 mmcblk0                                           31268536320         disk
 |-mmcblk0p1  ext4   /           APP               12884901888         part
 |-mmcblk0p2                     mts-bootpack          4194304         part
 |-mmcblk0p3                     mts-bootpack_b        4194304         part
 |-mmcblk0p4                     cpu-bootloader         524288         part
 |-mmcblk0p5                     cpu-bootloader_b       524288         part
 |-mmcblk0p6                     bootloader-dtb         524288         part
 |-mmcblk0p7                     bootloader-dtb_b       524288         part
 |-mmcblk0p8                     secure-os             3145728         part
 |-mmcblk0p9                     secure-os_b           3145728         part
 |-mmcblk0p10                    eks                   2097152         part
 |-mmcblk0p11                    adsp-fw               4194304         part
 |-mmcblk0p12                    adsp-fw_b             4194304         part
 |-mmcblk0p13                    bpmp-fw                618496         part
 |-mmcblk0p14                    bpmp-fw_b              618496         part
 |-mmcblk0p15                    bpmp-fw-dtb            512000         part
 |-mmcblk0p16                    bpmp-fw-dtb_b          512000         part
 |-mmcblk0p17                    sce-fw                2097152         part
 |-mmcblk0p18                    sce-fw_b              2097152         part
 |-mmcblk0p19                    sc7                   6291456         part
 |-mmcblk0p20                    sc7_b                 6291456         part
 |-mmcblk0p21                    FBNAME                2097152         part
 |-mmcblk0p22                    BMP                 134217728         part
 |-mmcblk0p23                    BMP_b               134217728         part
 |-mmcblk0p24                    SOS                  33554432         part
 |-mmcblk0p25                    SOS_b                33554432         part
 |-mmcblk0p26                    kernel               67108864         part
 |-mmcblk0p27                    kernel_b             67108864         part
 |-mmcblk0p28                    kernel-dtb             524288         part
 |-mmcblk0p29                    kernel-dtb_b           524288         part
 |-mmcblk0p30                    CAC                 268435456         part
 `-mmcblk0p31                    overlay           16520130048         part
 mmcblk0boot0                                          4194304         disk
 mmcblk0boot1                                          4194304         disk
 mmcblk0rpmb                                           4194304         disk Code language: Bash (bash)

Let say you want the partition with label ‘overlay’ to have an ext4 file partition mounted at /overlay.

In your_image.bb where you have defined your custom image, add this to create a small ext4 img file, so it won’t take long to flash the device

tegraflash_custom_pre() {
     dd if=/dev/zero of=overlay.img bs=1M count=10
     /sbin/mkfs.ext4 overlay.img
 }Code language: Bash (bash)

Now go back to edit flash_l4t_t186_custom.xml and add the image name in filename tag in the partition

<partition name="overlay" type="data">
    <allocation_policy> sequential </allocation_policy>
    <filesystem_type> basic </filesystem_type>
    <size> 18432 </size>
    <file_system_attribute> 0 </file_system_attribute>
    <allocation_attribute> 0x808 </allocation_attribute>
    <percent_reserved> 0 </percent_reserved>
    <filename> overlay.img </filename>
</partition>Code language: XL (xl)

To mount this new partition edit your fstab. Create a …/recipes-core/base-files folder. Inside add a base-files folder with fstab

/dev/root            /                    auto       defaults              1  1
proc                 /proc                proc       defaults              0  0
devpts               /dev/pts             devpts     mode=0620,gid=5       0  0
tmpfs                /run                 tmpfs      mode=0755,nodev,nosuid,strictatime 0  0
tmpfs                /var/volatile        tmpfs      defaults              0  0
/dev/mmcblk0p31      /overlay             auto       defaults,x-systemd.growfs              0  0Code language: Bash (bash)

The x-systemd.growfs option tells systemd to resize the file system on /overlay to the full size of /dev/mmcblk0p31 partition. Otherwise it’ll stay 10MB.

Then create base-files_%.bbappend to create to add the path and the mount point in the image.

FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"

do_install_append() {
     install -d ${D}/overlay
}

FILES_${PN} += " \
     /overlay \
 "Code language: Bash (bash)

Build, flash and you should see the overlay partition:

# lsparts 
NAME         FSTYPE MOUNTPOINT  PARTLABEL                SIZE STATE   TYPE
sda                                              128035676160 running disk
`-sda1       ext4   /data                        128034676224         part
mmcblk0                                           31268536320         disk
|-mmcblk0p1  ext4   /           APP               12884901888         part
|-mmcblk0p2                     mts-bootpack          4194304         part
|-mmcblk0p3                     mts-bootpack_b        4194304         part
|-mmcblk0p4                     cpu-bootloader         524288         part
|-mmcblk0p5                     cpu-bootloader_b       524288         part
|-mmcblk0p6                     bootloader-dtb         524288         part
|-mmcblk0p7                     bootloader-dtb_b       524288         part
|-mmcblk0p8                     secure-os             3145728         part
|-mmcblk0p9                     secure-os_b           3145728         part
|-mmcblk0p10                    eks                   2097152         part
|-mmcblk0p11                    adsp-fw               4194304         part
|-mmcblk0p12                    adsp-fw_b             4194304         part
|-mmcblk0p13                    bpmp-fw                618496         part
|-mmcblk0p14                    bpmp-fw_b              618496         part
|-mmcblk0p15                    bpmp-fw-dtb            512000         part
|-mmcblk0p16                    bpmp-fw-dtb_b          512000         part
|-mmcblk0p17                    sce-fw                2097152         part
|-mmcblk0p18                    sce-fw_b              2097152         part
|-mmcblk0p19                    sc7                   6291456         part
|-mmcblk0p20                    sc7_b                 6291456         part
|-mmcblk0p21                    FBNAME                2097152         part
|-mmcblk0p22                    BMP                 134217728         part
|-mmcblk0p23                    BMP_b               134217728         part
|-mmcblk0p24                    SOS                  33554432         part
|-mmcblk0p25                    SOS_b                33554432         part
|-mmcblk0p26                    kernel               67108864         part
|-mmcblk0p27                    kernel_b             67108864         part
|-mmcblk0p28                    kernel-dtb             524288         part
|-mmcblk0p29                    kernel-dtb_b           524288         part
|-mmcblk0p30                    CAC                 268435456         part
`-mmcblk0p31 ext4   /overlay    overlay           16520130048         part
mmcblk0boot0                                          4194304         disk
mmcblk0boot1                                          4194304         disk
mmcblk0rpmb                                           4194304         diskCode language: Bash (bash)

And check the size matches the partition size:

# df -h
Filesystem      1K-blocks     Used Available Use% Mounted on
none              3953688        0   3953688   0% /dev
/dev/mmcblk0p1    3662748  3013736    433768  88% /
tmpfs             4024492        4   4024488   1% /dev/shm
tmpfs             4024492      832   4023660   1% /run
tmpfs             4024492        0   4024492   0% /sys/fs/cgroup
tmpfs             4024492        0   4024492   0% /tmp
tmpfs             4024492        0   4024492   0% /var/volatile
/dev/mmcblk0p31  15811428       13  15327223   1% /overlay
tmpfs              804896        0    804896   0% /run/user/0Code language: Bash (bash)

NVidia is changing the default layout with Jetpack releases and some of those are mandatory. So if you upgrade the meta-tegra layer to another branch, make sure to diff the new layout format with your custom one.

Leave a Reply

Your email address will not be published. Required fields are marked *