The permission error could be a number of things, but basically, on the host, the driver package “flash.sh” command must be run with sudo, as well as the apply_binaries.sh step. Some other parts of flash must not be sudo. In the case of using JetPack or SDK Manager you would run this as non-root (non-sudo), and enter your password so that sudo can be accessed (JetPack or SDKM then takes care of which steps to do sudo or not). I’m guessing that somewhere in the steps sudo was or wasn’t used at the right time. Something became root-only which shouldn’t be, or else sudo is not working on something which mandates sudo.
You will want to start over by completely deleting the directory produced by JetPack or SDKM. Then run JetPack or SDKM without sudo, but make sure it has the correct password for sudo.
For custom images realize that the “Linux_for_Tegra/” subdirectory is actually the driver package, and this is where the flash work is done. During a regular flash (not a custom image) the “rootfs/” content has some boot content added, but is a nearly exact copy of what gets turned into an image. The raw image generated during a regular flash becomes “bootloader/system.img.raw”, and a smaller sparse image becomes “bootloader/system.img”. This command is basically what creates the images and also flashes:
sudo ./flash.sh jetson-xavier mmcblk0p1
If you want to avoid regenerating the image and use the image which already exists, then you would use the “-r” (reuse) option:
sudo ./flash.sh <b>-r</b> jetson-xavier mmcblk0p1
Any image which is placed at “bootloader/system.img” will get flashed. It doesn’t matter if this is a clone, a raw image, or a sparse image, it’ll do the job. If you have an image already generated, then put a copy at “bootloader/system.img”, and then flash with “-r”. Keep in mind that if your image is not the same size as the default, then you might need to specify size.
Look at your image’s exact byte size. Determine its size in terms of MiB or GiB. If you can evenly divide by “10241024", then that is the size in MiB. If you can divide that exact byte size evenly by "10241024*1024”, then that is the size in GiB. “flash.sh” can take the “-S #MiB” or “-S #GiB” argument as well. As an example I have an image which is “30064771072” bytes. Dividing twice by 1024 implies I can use “-S 28672MiB”. I can divide one more time by 1024, and this too is an even number, so this is also the same as “-S 28GiB”. If this were a custom image and I wanted to make sure the size is set correctly, then this would be my flash command:
sudo ./flash.sh <b>-r -S 28GiB</b> jetson-xavier mmcblk0p1
Note that you can tell SDKM to download, but not flash. This should produce the driver package “Linux_for_Tegra/” subdirectory at “~/nvidia/nvidia_sdk/JetPack_4.2_Linux_P2888/Linux_for_Tegra/”. “flash.sh” should be there, and the “bootloader/” subdirectory of that is where you place your custom image as “system.img”.
Other variations exist for flashing just a kernel or device tree. It depends on what you are doing.