While I answer this keep in mind that there are two different types of images, and both work when placed at “
Linux_for_Tegra/bootloader/system.img”. The raw file (which when generated would show up as “
bootloader/system.img.raw”) is an exact bit-for-bit copy of the partition. The sparse file leaves out the “empty” space as a way of making it smaller, and shows up as “
bootloader/system.img”. The smaller sparse file takes less time to flash than does the larger raw file, but both work for flash. You could rename “
system.img” to some backup location, and then rename “
system.img.raw” to “
system.img”, and then use the “
-r” option, and flash would have exactly the same result (but would take longer).
Raw images can be loopback mounted. The loopback mount makes the image appear like an actual block device (a disk partition in this case). The loopback mount point allows you to go there, examine content, edit content, so on. Then you could
umount the loopback point and flash with “
-r” using your raw image. Alternatively, you could create a sparse form of your raw image using “
mksparse”. Example of converting a raw to sparse:
sudo mksparse -v --fillpattern=0 system.img.raw system.img
(which would convert the raw image to the sparse image exactly the way
flash.sh does this)
If you have multiple flashes to perform, and if you don’t have to edit each one, then you are better off converting to sparse; if you have to edit each run, then you are better off accepting the longer flash and just directly using the raw image (you could test once to see the time difference since this depends on how much empty space is present).
As for actual details, let’s say you have your image in “
Linux_for_Tegra/bootloader/custom.img.raw” (obviously a raw image…a clone produces both raw and sparse). You could mount and work on this image as follows (mount point is traditional, but you could easily use any other mount point):
sudo mount -o loop custom.img.raw /mnt
sudo echo "1234" > my_serial.txt
sudo umount /mnt
This would alter the raw file and create a file with a serial number. If your file happens to be raw format and at “
Linux_for_Tegra/bootloader/system.img”, then flashing with “
-r” will flash with this edited image with serial number “
1234”. Or you could copy the image to that location, or you could
mksparse and copy the sparse to that location, and use “
-r” with the other version. Such files are quite large though, so you might avoid lots of file copy, but failing to use “
-r” once would destroy your original.
Note that it is also possible to place a symbolic link at “
Linux_for_Tegra/bootloader/system.img” which points at “
custom.img.raw” somewhere else. If something were to edit this sym link over loopback, then the original would be edited, but if something were to overwrite the sym link (such as flashing without “
-r”), then the original would be unharmed and you’d just need to add the sym link back in to get the custom version.