Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
hh5a install u-boot
#!/bin/sh
. /lib/functions.sh
CALDATA_TMP_FILE="/tmp/caldata.dd"
UBOOT_NANDSPL_FILE="/u-boot.ltq.lzo.nandspl"
echo ""
echo "This script will wipe your flash and install u-boot on your BT HH5A"
echo "WARNING: DO NOT CONTINUE unless you have backups!"
echo " (see http://wiki.openwrt.org/toh/bt/homehub_v5a how to do that)"
echo ""
echo "Continue [y/N]?"
read START
if [ "${START}" != "y" ]
then
exit 0
fi
if [ ! -s "${UBOOT_NANDSPL_FILE}" ]
then
echo "Could not find the u-boot installation file ${UBOOT_NANDSPL_FILE}" >&2
exit 1
fi
UBOOT_PART=$(find_mtd_part "u-boot")
if [ -z "${UBOOT_PART}" ]; then
echo "u-boot partition not found - are you running the install image?" >&2
exit 1
fi
OFW_UBI_PART=$(find_mtd_part "ofw_ubi")
if [ -z "${OFW_UBI_PART}" ]; then
echo "ofw_ubi partition not found - are you running the install image?" >&2
exit 1
fi
TARGET_UBI_PART=$(find_mtd_part "ubi")
if [ -z "${TARGET_UBI_PART}" ]; then
echo "ubi partition not found - are you running the install image?" >&2
exit 1
fi
TARGET_CALDATA_PART=$(find_mtd_part "caldata")
if [ -z "${TARGET_CALDATA_PART}" ]; then
echo "caldata partition not found - are you running the install image?" >&2
exit 1
fi
NANDCHIP_PART=$(find_mtd_part "nand_chip")
if [ -z "${NANDCHIP_PART}" ]; then
echo "caldatanand_chippartition not found - are you running the install image?" >&2
exit 1
fi
ubidetach -m "${OFW_UBI_PART#*mtdblock}" &> /dev/null
ubidetach -m "${TARGET_UBI_PART#*mtdblock}" &> /dev/null
set -o pipefail
ubiattach -m "${OFW_UBI_PART#*mtdblock}"
dd if=/dev/ubi0_3 of="${CALDATA_TMP_FILE}"
if [ "$(ls -s "${CALDATA_TMP_FILE}" | sed "s/[^0-9]//g")" != "128" ]
then
echo "The dumped caldata file has an incorrect size!" >&2
exit 1
fi
md5sum "${CALDATA_TMP_FILE}"
ubidetach -m "${OFW_UBI_PART#*mtdblock}" &> /dev/null
echo ""
echo "Starting to install u-boot and caldata..."
echo "Please enter YESPLEASE to continue:"
read CONFIRMATION
if [ "${CONFIRMATION}" != "YESPLEASE" ]
then
exit 0
fi
echo "DO NOT POWER OFF THE DEVICE!"
echo ""
echo "Erasing NAND chip..."
mtd erase "nand_chip"
echo "Flashing u-boot..."
mtd write "${UBOOT_NANDSPL_FILE}" "u-boot"
echo "Verifying u-boot..."
mtd verify "${UBOOT_NANDSPL_FILE}" "u-boot"
echo "Writing caldata..."
mtd write "${CALDATA_TMP_FILE}" "caldata"
echo "Verifying caldata..."
mtd verify "${CALDATA_TMP_FILE}" "caldata"
echo "Formatting new ubi partition..."
ubiformat "${TARGET_UBI_PART/block/}" -y
ubiattach -m "${TARGET_UBI_PART#*mtdblock}"
echo ""
echo "u-boot nstallation successful"
echo "Now run 'sysupgrade /tmp/openwrt-lantiq-xrx200-BTHOMEHUBV5A-ubifs-sysupgrade.tar' to install OpenWrt"
echo "Afterwards type 'reboot' and power-cycle your device"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment