How to Flash clone image to external device in the XavierNX environment

I’m working on XavierNX based custom board.

I want to clone the App partition in NVMeSSD, so I executed the following on the xaviernx board to create a clone image file.

# img2simg /dev/nvme0n1p1 system.img.ext

You can just replace the system.img.ext during the workflow of initrd_flash.
There should be one step that you can see this image inside the folder.

Relying on the above URL description, we replaced system.img by system.img.ext.

# cp system.img.ext tools/kernel_flash/images/external/system.img

and l4t_initrd_flash.sh with --flash-only option.

$ sudo NO_ROOTFS=0 tools/kernel_flash/l4t_initrd_flash.sh --flash-only \
--external-device nvme0n1p1 -c tools/kernel_flash/flash_l4t_external.xml --showlogs p3509-0000+p3668-0000-qspi internal

As a result, the following error occurred.

error: file_write: write: No space left on device
Cannot write output file
[ 467]: l4t_flash_from_kernel: Error flashing external device
[ 467]: l4t_flash_from_kernel: nvsimg2img ...Linux_for_Tegra/tools/kernel_flash/images/external/system.img /dev/sdg1 failed
[ 467]: l4t_flash_from_kernel: The device size indicated in the partition layout xml is smaller than the actual size. This utility will try to fix the GPT.

It seems [tools/kernel_flash/images/external/flash.idx] doesn’t match the size after cloning.

12, 9:0:APP, 516857856, 15032385536, , , fixed-<reserved>-1,

Can we really write clone files to NVMeSSD by simply replacing system.img?
Do we also need to update the partition in flash.idx?
If so, could you please tell me how to update the flash.idx to the size after the clone?

Sorry for the late response, have you managed to get issue resolved or still need the support? Thanks

Hi, kayccc.
Thank you for your reply.
We still need help.

What size did you set in your flash_l4t_external.xml?

Hi,WayneWWW

APP partition definition of flash_l4t_external.xml is below.

[tools/kernel_flash/flash_l4t_external.xml]
<partition_layout version="01.00.0000">
    <device type="nvme" instance="0" sector_size="512" num_sectors="67108864">
...
        <partition name="APP" id="1" type="data">
            <allocation_policy> sequential </allocation_policy>
            <filesystem_type> basic </filesystem_type>
            <size> APPSIZE </size>
            <file_system_attribute> 0 </file_system_attribute>
            <allocation_attribute> 0x8 </allocation_attribute>
            <align_boundary> 4096 </align_boundary>
            <percent_reserved> 0 </percent_reserved>
            <filename> APPFILE </filename>
            <unique_guid> APPUUID </unique_guid>
            <description> **Required.** Contains the rootfs. This partition must be defined
              after `primary_GPT` so that it can be accessed as the fixed known special device
              `/dev/mmcblk0p1`. </description>
        </partition>
...
    </device>
</partition_layout>

And what is the partition size of your nvme?

We have M.2 256GB NVMeSSD.
APP Partition size of [System Configuration] is 228443 MB.

system.img.ext size is below.

$ ls -la 
-rw-rw-r--  1 shin shin 11868318920  8月 19 09:55 system.img.ext

$ file system.img.ext 
system.img.ext: Android sparse image, version: 1.0, Total of 58481408 4096-byte output blocks in 8716 input chunks.

To see the actual partition size (versus formatted filesystem size), assuming the partition is “/dev/nvme0n1p1”:
sudo blockdev --getsize64 /dev/nvme0n1p1

The above size should match (or exceed) the raw image to be flashed (the sparse image won’t give you that information).

Also if APP is the last partition in your xml file you can set this value to 0x808 to make it expand while flashing. This is what you should do.

Hi,linuxdev,lhoang

Thank you for your answer.

Finally, I could flash cloned system.img without error.

[ 183]: l4t_flash_from_kernel: Successfully flash the qspi
[ 183]: l4t_flash_from_kernel: Flashing success
writing item=13, 9:0:secondary_gpt, 34359721472, 16896, gpt_secondary_9_0.bin, 16896, fixed-<reserved>-0, caed51074e2c15fe60a7520afdb24daf21ac4c35
[ 853]: l4t_flash_from_kernel: Successfully flash the external device
[ 853]: l4t_flash_from_kernel: Flashing success
[ 853]: l4t_flash_from_kernel: The device size indicated in the partition layout xml is smaller than the actual size. This utility will try to fix the GPT.

However, the following error occurred from HDMI output when mounting the APP partition at startup.

mount: /mnt: can't find PARTUUID=54608003-d768-4d34-afe3-f3a3dcc1a9a1
...
/mnt/ is not a mountpoint
bash: cannot set terminal process group(-1): Inappropriate ioctl for device
bash: no job control in this shell

bash-4.4#

Perhaps the GPT partition has been re-created, causing the uuid error.

If you know how to deal with this, please let us know.

In that terminal You can

sudo mount /dev/nvme0n1p1 /mnt
chroot /mnt /bin/bash
vim /boot/extlinux/extlinux.conf

And edit PARTUUID=… part into /dev/nvme0n1p1