| #!/bin/bash |
| |
| BOOT_PART=mmcblk0p2 |
| |
| BOOT_PACKAGE=/boot/boot.img |
| BOOT_PACKAGE_SIZE=$(stat -c%s ${BOOT_PACKAGE}) |
| |
| function check_emmc_matches { |
| local BOOT_CURRENT=$(mktemp) |
| dd if=/dev/${BOOT_PART} of=${BOOT_CURRENT} \ |
| count=${BOOT_PACKAGE_SIZE} \ |
| bs=512 \ |
| iflag=count_bytes |
| diff ${BOOT_CURRENT} ${BOOT_PACKAGE} |
| local DIFF_RETURN_CODE=$? |
| rm ${BOOT_CURRENT} |
| return ${DIFF_RETURN_CODE} |
| } |
| |
| # Check if the image on eMMC is the same as from the package |
| check_emmc_matches |
| |
| if [[ $? -eq 0 ]]; then |
| exit 0 |
| fi |
| |
| UPDATE_SUCCESS=false |
| # Write the boot image into the block device |
| for i in `seq 1 5` |
| do |
| dd if=${BOOT_PACKAGE} of=/dev/${BOOT_PART} bs=512 |
| check_emmc_matches |
| if [[ $? -eq 0 ]]; then |
| UPDATE_SUCCESS=true |
| break |
| fi |
| done |
| |
| if [[ "${UPDATE_SUCCESS}" != true ]]; then |
| echo "Failed to update Linux! Rebooting is unsafe!" |
| exit 1 |
| fi |