Orin System can't be restored

Downloaded JP 5.0.2. Still totally same issue as this one, please advise Orin System Image Restore failure

The only difference from last time is that if I wait for like 40 mins, I’ll get such error. But i’m not sure if this is a different cus for the old one I probably never waited it for more than 40 mins.
image

Is this really an Orin? I see a reference to a t186 which is older tech a TX2). Only Xavier and Orin are supported for that particular release.

I’m sure this is an Orin. This is the picture of the hardware. we bought them from official channels. i don’t think people can easily fake this lol.

Hi ysyyork,

Please share your detail steps. (restore and backup command)
Thanks!

Hi @carolyuu , please check the original post link i shared. The steps are totally the same. The only difference is the L4T version. The only difference is in this screenshot. I changed the R34.1.1 to R35.1

Is there any updates on this issue? sorry my project timeline is a bit tight here and it’s depending on this right now. Really appreciate

Hi ysyyork,

Please apply below patch on R35.1 to get full fixed.

Sorry, once i updated the file with this patch, i need to backup the image again with this new script and then I flash correct?

Hi ysyyork,

Yes, please use new script with patch and backup again.
Thanks!

I backup the image again with the patch added into the script, but it’s still the same.

I observed the two clone.img file size and it seems they are the same. Not sure if this is correct.

image
so clone.img is the old one. clone1.img is the one i backed up after I added the patch.

And here is the modified script. could you help to see if it’s correct too?

#!/bin/bash

# Copyright (c) 2019-2021, NVIDIA CORPORATION. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#  * Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#  * Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#  * Neither the name of NVIDIA CORPORATION nor the names of its
#    contributors may be used to endorse or promote products derived
#    from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# This is a script to resize partition and filesystem on the root partition
# This will consume all un-allocated sapce on SD card after boot.

set -e

function usage()
{
	if [ -n "${1}" ]; then
		echo "${1}"
	fi

	echo "Usage:"
	echo "${script_name} [options]"
	echo ""
	echo "Available options are:"
	echo ""
	echo "	-h | --help"
	echo "		Show this usage"
	echo ""
	echo "	-c | --check"
	echo "		Check whether ${script_name} can be used on current platform"
	echo ""
	echo "	-g | --get"
	echo "		Show APP partition size in MB"
	echo ""
	echo "	-m | --max"
	echo "		Show APP partition maximum available size in MB"
	echo ""
	echo "	-s <app_size> | --size <app_size>"
	echo "		Set APP partition size in MB"
	echo ""
	echo "Without any option means consume all unallocated"
	echo "space on SD card."
	echo ""
	echo "Example:"
	echo "${script_name}"
	echo "${script_name} -s 16384"
}

function check_pre_req()
{
	root_dev="$(sed -ne 's/.*\broot=\([^ ]*\)\b.*/\1/p' < /proc/cmdline)"

	if [[ "${root_dev}" == *UUID* ]]; then
		root_dev="$(/sbin/findfs ${root_dev})"
	fi

	if [[ "${root_dev}" == /dev/mmcblk* ]] || [[ "${root_dev}" == /dev/sd* ]] \
		|| [[ "${root_dev}" == /dev/nvme* ]]; then
		block_dev="$(/bin/lsblk -no pkname ${root_dev})"
		root_dev="$(echo $root_dev | sed 's/^.....//g')"
	fi

	if [ "${block_dev}" != "" ]; then
		# Check whether APP partition is located at the end of the disk
		if ! cat /sys/block/${block_dev}/${root_dev}/start > /dev/null 2>&1 ; then
			support_resizefs="false"
			return
		fi
		root_start_sector="$(cat /sys/block/${block_dev}/${root_dev}/start)"
		all_start_sectors="$(cat /sys/block/${block_dev}/*/start)"

		is_last="true"
		for start_sector in ${all_start_sectors}; do
			if [[ "${start_sector}" -gt "${root_start_sector}" ]]; then
				is_last="false"
				break
			fi
		done
		support_resizefs="${is_last}"
	fi

	if [ "${is_last}" == "true" ]; then
		get_app_size
		max_available_app_size
		size="+${max_app_size}M"
	fi
}

function get_app_size()
{
	partition_size="$(cat /sys/block/${block_dev}/${root_dev}/size)"
	cur_app_size="$((partition_size/2/1024))"
}

function max_available_app_size()
{
	# Move backup GPT header to end of disk
	sgdisk --move-second-header "/dev/${block_dev}" > /dev/null 2>&1
	app_start_sector="$(cat /sys/block/${block_dev}/${root_dev}/start)"
	last_usable_sector="$(sgdisk -p /dev/${block_dev} | \
				grep "last usable sector" | \
				awk '{print $10}')"

	max_app_size="$(((last_usable_sector - app_start_sector + 1)/2/1024))"
}

function parse_args()
{
	while [ -n "${1}" ]; do
		case "${1}" in
		-h | --help)
			usage
			exit 0
			;;
		-c | --check)
			echo "${support_resizefs}"
			exit 0
			;;
		-g | --get)
			if [ "${support_resizefs}" = "false" ]; then
				echo "ERROR: ${script_name} doesn't support this platform."
				exit 1
			fi
			echo "${cur_app_size}"
			exit 0
			;;
		-m | --max)
			if [ "${support_resizefs}" = "false" ]; then
				echo "ERROR: ${script_name} doesn't support this platform."
				exit 1
			fi
			echo "${max_app_size}"
			exit 0
			;;
		-s | --size)
			[ -n "${2}" ] || usage "Not enough parameters"
			size="+${2}M"
			shift 2
			;;
		*)
			usage "Unknown option: ${1}"
			exit 1
			;;
		esac
	done
}

script_name="$(basename "${0}")"
support_resizefs="false"
size="0"
cur_app_size="0"
max_app_size="0"
root_dev=""
block_dev=""

check_pre_req
parse_args "${@}"

if [ "${support_resizefs}" = "false" ]; then
	echo "ERROR: ${script_name} doesn't support this platform."
	exit 1
fi

# Move backup GPT header to end of disk
sgdisk --move-second-header "/dev/${block_dev}"

# Get partition information for root partition
partition_num="$(cat /sys/block/${block_dev}/${root_dev}/partition)"
partition_name="$(sgdisk -i ${partition_num} /dev/${block_dev} | \
	grep "Partition name" | cut -d\' -f2)"

partition_type="$(sgdisk -i ${partition_num} /dev/${block_dev} | \
	grep "Partition GUID code:" | cut -d' ' -f4)"

partition_uuid="$(sgdisk -i ${partition_num} /dev/${block_dev} | \
	grep "Partition unique GUID:" | cut -d' ' -f4)"

partition_attr="$(sgdisk -i ${partition_num} /dev/${block_dev} | \
	grep "Attribute flags:" | cut -d' ' -f3)"

# Get start sector of the root partition
start_sector="$(cat /sys/block/${block_dev}/${root_dev}/start)"

# Delete and re-create the root partition
# This will resize the root partition.
sgdisk -d "${partition_num}" \
	-n "${partition_num}":"${start_sector}":"${size}" \
	-c "${partition_num}":"${partition_name}" \
	-t "${partition_num}":"${partition_type}" \
	-u "${partition_num}":"${partition_uuid}" \
	-A "${partition_num}":=:"${partition_attr}" \
	"/dev/${block_dev}"

# Inform kernel and OS about change in partition table and root
# partition size
partprobe "/dev/${block_dev}"

# Resize filesystem on root partition to consume all un-allocated
# space on disk
resize2fs "/dev/${root_dev}"

Some more details. After modifying this script, i rerun

sudo ./apply_binaries.sh

Then I ran this to backup again

sudo ./flash.sh -r -k APP -G clone1.img jetson-agx-orin-devkit mmcblk0p1

Then I copy this clone1.img to bootloader/system.img

Then i ran

sudo ./flash.sh -r jetson-agx-orin-devkit mmcblk0p1

Finally it hangs in the same place

Hi @carolyuu

can you help provide more insight? Thanks

Hi ysyyork,

After apply the patch, please full flash your Orin device first.
Then start backup and restore image.

$ sudo ./flash.sh -r -k APP -G clone.img jetson-xavier mmcblk0p1
$ cd bootloader/
$ mv system.img system.img-backup
$ cp ../clone.img system.img
$ sudo ./flash.sh -r -k APP jetson-xavier mmcblk0p1

ok let me try

sorry, i tested wrongly just now. Actually there is still problem (i didn’t copy paste the backup clone image to system.img, that’s why i thought it worked.)

To make it more clear, this is what I did

  1. Modify the patch
  2. Run sudo ./apply_binaries.sh
  3. sudo ./flash.sh jetson-agx-orin-devkit mmcblk0p1 to flash the original system
  4. After flash, setup ubuntu with username passwd, etc till i can see a normal desktop show up.
  5. reboot device into recovery mode
  6. sudo ./flash.sh -r -k APP -G clone3.img jetson-agx-orin-devkit mmcblk0p1 to back up
  7. sudo cp clone3.img bootloader/system.img
  8. sudo ./flash.sh -r jetson-agx-orin-devkit mmcblk0p1

Then it gets stucked.

@carolyuu

@carolyuu

Did more experiment. Right now there is one setup that can work but it’s still not working perfectly for my use case.

There were some mistakes above.

  1. I shouldn’t run ./apply_binaries.sh after i modify the patch because this script will actually regenerate that patch file.
  2. When flashing back the backup image, I use add -k APP. Otherwise it will still stuck.

Now i can make it work only in one scenario:

  1. Install the original version of system first
  2. use the backup image and run sudo ./flash.sh -r -k APP jetson-agx-orin-devkit mmcblk0p1

If i don’t have one system already on the device, if I just run sudo ./flash.sh -r jetson-agx-orin-devkit mmcblk0p1 or sudo ./flash.sh -r -k APP jetson-agx-orin-devkit mmcblk0p1. None of them works. Both of them will stuck at the place where the script tried to flash the system.img into the device forever. This is still not ideal in my case cus this means I need to flash twice for mass production for each device. Please advise.

Another finding on top of this. The patch actually doesn’t help anything. I tried again without this patched file and it’s the same as the above reply. I can only use -k APP to flash with a pre-flashed device and that can work. Other than that, nothing works.

Hi ysyyork,
please check your clone.img size, how much of it?

Do the exact sizes of “clone.img.raw” and “clone1.img.raw” match?
ls -l clone.img.raw clone1.img.raw

I want to add that although if you copy the raw image to “system.img” for flash the flash will take much longer, but doing so bypasses any raw->sparse->raw conversion, and might be useful as the source of flash. This flash takes longer, but is the simplest case, so it is worth testing if it differs.

This is the clone.img with that patched file:
image

This is the clone.img without that patched file:
image

Hi @Jeffli , any new advice? Thanks