# Update image on M902 from uboot
---------------------final friday----------

>> ext4load usb 0:1 $loadaddr boot/Image
ext4write mmc 0:1 $loadaddr /boot/Image 0x01378a00 0 **===>>>> NOTE Image size from usb is 20417024 it's hex value 0x01378a00**
>> ext4load usb 0:1 $loadaddr boot/cn9132-db.dtb
ext4write mmc 0:1 $loadaddr /boot/cn9132-db.dtb 0x0000a727 0 **===>>>> NOTE cn9132.dtb size from usb is 42791 it's hex value 0x0000a727**

As of now **created boot** folder in mmc 0:1 as ext4write command is **not** letting copy to partition directly without any subfolder creation.
bootcmd is modified to use Image and dtb from boot folder and rootfs from usb connected.
>> setenv bootcmd "usb reset; ext4load mmc 0:1 0x6500000 boot/Image; ext4load mmc 0:1 0x6000000 boot/cn9132-db.dtb; setenv bootargs root=/dev/sda1 rw rootwait rootfstype=ext4 $console cpuidle.off=1; booti 0x6500000 - 0x6000000"
dont save any environment vairable now just press
>> boot
next:
Marvell>> ext4write
ext4write - create a file in the root directory
Usage:
ext4write <interface> <dev[:part]> <addr> <absolute filename path>
[sizebytes] [file offset]
- create a file in / directory
ext4write mmc 0:1 $loadaddr /boot/Image 0x01378a00 0x00000800

----------------------



convert partition type to DOS and make single partition in kernel then


11th oct

tried 0 and 0x100 but emmc corrupt but 0x200 has no issues


-------------------
# Final
Marvell>> ext4load usb 0:1 $loadaddr V1.0.0_openwrt-mvebu-cortexa72-iei_puzzle-m902-ext4-sdcard.img 0x1040000 0x100000
Marvell>> setexpr fs ${filesize} + 1ff
Marvell>> setexpr fs ${fs} / 200
Marvell>> mmc write ${fileaddr} 800 ${fs}
Marvell>> mmc write ${fileaddr} 20801 ${fs}
Marvell>> ext4load usb 0:1 $loadaddr V1.0.0_openwrt-mvebu-cortexa72-iei_puzzle-m902-ext4-sdcard.img 6840000 1200000
Marvell>> setexpr fs ${filesize} + 1ff
Marvell>> setexpr fs ${fs} / 200
Marvell>> mmc write ${fileaddr} 40802 ${fs}
Marvell>> mmc write ${fileaddr} 140802 ${fs}




Reference:
Only thing helped me is, stackoverflow question which i have posted and answered my sawdust user.
https://stackoverflow.com/questions/74026658/updating-image-dtb-and-rootfs-from-uboot/74215919?noredirect=1#comment131034172_74215919
most importance comment resolved my issues is .......
To read an image into memory from the ext4 file on the USB device, use the Sectors value for that image (from the fdisk command results) converted to a byte count (i.e. multiplied by 512) and then converted to hexadecimal as the value for the bytes parameter. Use the Start value for that image (from the fdisk command results) converted to a byte count (i.e. multiplied by 512) and then converted to hexadecimal as the value for the pos parameter.
To write an image in memory to a specific MTD partition on the eMMC, use the Start LBA value for that partition (from the mmc part command results) as the value for blk# parameter.
Use the Sectors value for that image (from the fdisk command results) converted to hexadecimal as the value for cnt parameter.
As partition overlapping happened on mmc write, i used setexpr command from uboot to resolve this issue. Link is https://unix.stackexchange.com/questions/311961/uboot-write-kernel-into-mmc-partition
**Marvell>> setexpr fs ${filesize} + 1ff
Marvell>> setexpr fs ${fs} / 200**
# Final correction.
No need of using setexpr
writing Image and dtb, as there are two partitions(mmcblk0p1 and mmcblk0p2) for it in that one is back partition
> ext4load usb 0:1 $loadaddr V1.0.0_openwrt-mvebu-cortexa72-iei_puzzle-m902-ext4-sdcard.img 1040000 100000
> mmc write $loadaddr 800 8200
>
2nd parameter is sector size in hex, we should not multiply it by 512 , if multiplied then next all paritions will be corrupted.
> mmc write $loadaddr 20801 8200
writing rootfs
as there are two partitions(mmcblk0p3 and mmcblk0p4) for it in that one is back partition
> ext4load usb 0:1 $loadaddr V1.0.0_openwrt-mvebu-cortexa72-iei_puzzle-m902-ext4-sdcard.img 6840000 1200000
> mmc write $loadaddr 40802 34200
same reason here "2nd parameter is sector size in hex, we should not multiply it by 512 , if multiplied then next all paritions will be corrupted."
> mmc write $loadaddr 140802 34200