Copy U-Boot + U-Boot vars using dd

I know that it’s possible to copy the complete boot area and transfer to another machine using the following dd commands:

// Save to file
dd if=/dev/mmcblk0boot0 of=/boot.img

// Restore from file
echo 0 > /sys/block/mmcblk0boot0/force_ro
dd if=/boot.img of=/dev/mmcblk0boot0

But as described in this copies the Toradex factory configuration block too. How can I restrict this copy to U-Boot imx and U-Boot vars?


The mmcblk0boot0 layout is currently as follows

0x400 u-boot.imx binary
block device end - 0x200 - 0x2000 : u-boot environment
block device end - 0x200 : config block

The config block is stored in the last block of mmcblk0boot0. The size of mmcblk0boot0 depends on the stuffed eMMC and might change in future revisions.

So one could:

root@colibri-imx6:~# cat /sys/class/block/mmcblk0boot0/size
root@colibri-imx6:~# dd if=/dev/mmcblk0boot0 of=/boot.img count=4095
4095+0 records in
4095+0 records out
root@colibri-imx6:~# ls -l /boot.img
-rw-r--r--    1 root     root       2096640 Dec  1 09:29 boot.img
root@colibri-imx6:~# echo 0 > /sys/block/mmcblk0boot0/force_ro
root@colibri-imx6:~# dd if=/boot.img of=/dev/mmcblk0boot0
4095+0 records in
4095+0 records out

P.S. Probably a better solution would be to copy only the U-Boot environment from the module and use your original u-boot.imx binary for U-Boot.

root@colibri-imx6:~# dd if=/dev/mmcblk0boot0 of=/env.img count=16 skip=4079
16+0 records in
16+0 records out
root@colibri-imx6:~# echo 0 > /sys/block/mmcblk0boot0/force_ro
root@colibri-imx6:~# dd if=/u-boot.imx of=/dev/mmcblk0boot0 seek=2
614+0 records in
614+0 records out
root@colibri-imx6:~# dd if=/env.img of=/dev/mmcblk0boot0 seek=4079
16+0 records in
16+0 records out

P.P.S: We are currently working on using U-Boot with SPL.
The SPL binary would then start at 0x400 while u-boot.img would then start at 0x11400.