- umount /mnt/ubifs
- ubidetach /dev/ubi_ctrl -d 0
-else
- log "uImage is missing, skipped."
+
+ # presence of uImage* is a sign that we can wipe whole boot partition,
+ # but first get rid of potentially bad autoboot.txt
+ rm -f /mnt/ubifs/autoboot.txt
+
+ for kernel in $kernels
+ do
+ if ! cmp $kernel /mnt/ubifs/$kernel 2> /dev/null
+ then
+ log "flashing $kernel .."
+ cp -a $kernel /mnt/ubifs/$kernel || return 1
+ status_uimage="flashed"
+ log "done"
+ else
+ log "$kernel already flashed, skipped."
+ status_uimage="already there"
+ fi
+ done
+ if [ -e bootmenu.txt ]
+ then
+ if ! cmp bootmenu.txt /mnt/ubifs/bootmenu.txt 2> /dev/null
+ then
+ log "updating bootmenu.txt"
+ cp -a bootmenu.txt /mnt/ubifs/bootmenu.txt || return 1
+ fi
+ fi
+}
+
+ubiattach /dev/ubi_ctrl -m 3 || true
+if ! mount -t ubifs ubi0:boot /mnt/ubifs 2> /dev/null
+then
+ format_boot