sd_fuse() {
  if [ ! -b /dev/mmcblk0 ]; then
    echo "No MMC device to flash, exiting."
    exit 0
  fi

  echo "BL1 fusing"
  dd if=/boot/bl1.bin.hardkernel of=/dev/mmcblk0 conv=fsync bs=1 count=442
  dd if=/boot/bl1.bin.hardkernel of=/dev/mmcblk0 conv=fsync bs=512 skip=1 seek=1
  echo "u-boot fusing"
  dd if=/boot/u-boot.bin of=/dev/mmcblk0 conv=fsync bs=512 seek=97
}

flash_uboot() {
  echo "A new U-Boot version needs to be flashed onto /dev/mmcblk0."
  echo "Do you want to do this now? [y|N]"
  read -r shouldwe
  if [[ $shouldwe =~ ^([yY][eE][sS]|[yY])$ ]]; then
    sd_fuse
  else
    echo "You can do this later by running:"
    echo "# cd /boot; ./sd_fusing.sh /dev/mmcblk0"
  fi
}

post_install() {
  flash_uboot
}

post_upgrade() {
  flash_uboot
}